Files
oc-lib/models/live/live_service.go

43 lines
1.5 KiB
Go
Raw Normal View History

2026-04-27 11:16:50 +02:00
package live
import (
2026-04-28 11:48:23 +02:00
"cloud.o-forge.io/core/oc-lib/models/common/enum"
2026-04-27 11:16:50 +02:00
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
2026-04-28 11:48:23 +02:00
type ServiceProtocol int
const (
HTTP ServiceProtocol = iota
GRPC
WEBSOCKET
TCP
)
func (p ServiceProtocol) String() string {
return [...]string{"HTTP", "GRPC", "WEBSOCKET", "TCP"}[p]
}
2026-04-27 11:16:50 +02:00
// LiveService is the authoritative description of a hosted service run by the peer.
// MaxConcurrent is the only capacity dimension that matters for scheduling:
// it caps the number of simultaneous callers the service can accept.
// All other service metadata (endpoint, protocol) is live-verified here
// rather than trusted from the ServiceResource, which may be stale.
type LiveService struct {
AbstractLive
MaxConcurrent int `json:"max_concurrent" bson:"max_concurrent"`
2026-04-28 11:48:23 +02:00
Protocol ServiceProtocol `json:"protocol" bson:"protocol" default:"0"`
2026-04-27 11:16:50 +02:00
EndpointPattern string `json:"endpoint_pattern,omitempty" bson:"endpoint_pattern,omitempty"`
HealthCheckPath string `json:"health_check_path,omitempty" bson:"health_check_path,omitempty"`
2026-04-28 11:48:23 +02:00
Infrastructure enum.InfrastructureType `json:"infrastructure" bson:"infrastructure" default:"-1"` // Infrastructure is the infrastructure
2026-04-27 11:16:50 +02:00
}
func (d *LiveService) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*LiveService](tools.LIVE_SERVICE, request)
}
2026-04-28 11:48:23 +02:00
func (r *LiveService) IsCompatible(service map[string]interface{}) bool {
return service["infrastructure"] == r.Infrastructure
2026-04-27 11:16:50 +02:00
}