Live x Resource Synergy
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/live"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
@@ -46,14 +47,6 @@ func (abs *ComputeResource) ConvertToPricedResource(t tools.DataType, selectedIn
|
||||
}, nil
|
||||
}
|
||||
|
||||
type ComputeNode struct {
|
||||
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||
Quantity int64 `json:"quantity" bson:"quantity" default:"1"`
|
||||
RAM *models.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
||||
CPUs map[string]int64 `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs key is model
|
||||
GPUs map[string]int64 `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs key is model
|
||||
}
|
||||
|
||||
type ComputeResourceInstance struct {
|
||||
ResourceInstance[*ComputeResourcePartnership]
|
||||
Source string `json:"source,omitempty" bson:"source,omitempty"`
|
||||
@@ -62,7 +55,7 @@ type ComputeResourceInstance struct {
|
||||
AnnualCO2Emissions float64 `json:"annual_co2_emissions,omitempty" bson:"co2_emissions,omitempty"`
|
||||
CPUs map[string]*models.CPU `bson:"cpus,omitempty" json:"cpus,omitempty"`
|
||||
GPUs map[string]*models.GPU `bson:"gpus,omitempty" json:"gpus,omitempty"`
|
||||
Nodes []*ComputeNode `json:"nodes,omitempty" bson:"nodes,omitempty"`
|
||||
Nodes []*live.ComputeNode `json:"nodes,omitempty" bson:"nodes,omitempty"`
|
||||
// AvailableStorages lists storage capabilities activatable on this compute unit (e.g. Minio, local volumes).
|
||||
// These are shallow StorageResource entries — not independent catalog items — but carry full pricing structure.
|
||||
AvailableStorages []*StorageResource `json:"available_storages,omitempty" bson:"available_storages,omitempty"`
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/live"
|
||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
@@ -250,17 +251,12 @@ func VerifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.AP
|
||||
return instances
|
||||
}
|
||||
|
||||
type GeoPoint struct {
|
||||
Latitude float64 `json:"latitude,omitempty" bson:"latitude,omitempty"`
|
||||
Longitude float64 `json:"longitude,omitempty" bson:"longitude,omitempty"`
|
||||
}
|
||||
|
||||
type ResourceInstance[T ResourcePartnerITF] struct {
|
||||
utils.AbstractObject
|
||||
ContentType string `json:"content_type,omitempty" bson:"content_type,omitempty"`
|
||||
LastUpdate time.Time `json:"last_update,omitempty" bson:"last_update,omitempty"`
|
||||
Origin OriginMeta `json:"origin,omitempty" bson:"origin,omitempty"`
|
||||
Location GeoPoint `json:"location,omitempty" bson:"location,omitempty"`
|
||||
Location live.GeoPoint `json:"location,omitempty" bson:"location,omitempty"`
|
||||
Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"`
|
||||
AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"`
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/live"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
@@ -68,7 +69,12 @@ func (dca *ResourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, er
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, int, error) {
|
||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
||||
return nil, 404, errors.New("can't update a non existing computing units resource not reported onto compute units catalog")
|
||||
delete(set, "architecture")
|
||||
delete(set, "infrastructure")
|
||||
} else if dca.GetType() == tools.SERVICE_RESOURCE {
|
||||
delete(set, "infrastructure")
|
||||
} else if dca.GetType() == tools.STORAGE_RESOURCE {
|
||||
delete(set, "storage_type")
|
||||
}
|
||||
return utils.GenericUpdateOne(set, id, dca)
|
||||
}
|
||||
@@ -78,16 +84,66 @@ func (dca *ResourceMongoAccessor[T]) ShouldVerifyAuth() bool {
|
||||
}
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
var i string
|
||||
idsToUpdate := []string{}
|
||||
var a utils.Accessor
|
||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
||||
return nil, 404, errors.New("can't create a non existing computing units resource not reported onto compute units catalog")
|
||||
r := data.(*ComputeResource)
|
||||
if len(r.Instances) == 0 {
|
||||
return nil, 404, errors.New("can't create a non existing computing units resource with no instances")
|
||||
}
|
||||
a = live.NewAccessor[*live.LiveDatacenter](tools.LIVE_DATACENTER, &tools.APIRequest{Admin: true})
|
||||
res, _, _ := a.LoadOne(r.Instances[0].GetID())
|
||||
if res == nil {
|
||||
return nil, 404, errors.New("can't create a non existing computing units resource not reported onto compute units catalog")
|
||||
}
|
||||
if !res.(*live.LiveDatacenter).IsCompatible(data.Serialize(data)) {
|
||||
return nil, 404, errors.New("live computing units target is not compatible")
|
||||
}
|
||||
i = res.GetID()
|
||||
idsToUpdate = res.(*live.LiveDatacenter).ResourcesID
|
||||
} else if dca.GetType() == tools.SERVICE_RESOURCE {
|
||||
r := data.(*ServiceResource)
|
||||
if len(r.Instances) == 0 {
|
||||
return nil, 404, errors.New("can't create a non existing service resource with no instances")
|
||||
}
|
||||
a = live.NewAccessor[*live.LiveService](tools.LIVE_SERVICE, &tools.APIRequest{Admin: true})
|
||||
res, _, _ := a.LoadOne(r.Instances[0].GetID())
|
||||
if res == nil {
|
||||
return nil, 404, errors.New("can't create a non existing service resource not reported onto compute units catalog")
|
||||
}
|
||||
if !res.(*live.LiveService).IsCompatible(data.Serialize(data)) {
|
||||
return nil, 404, errors.New("live service target is not compatible")
|
||||
}
|
||||
i = res.GetID()
|
||||
idsToUpdate = res.(*live.LiveService).ResourcesID
|
||||
} else if dca.GetType() == tools.STORAGE_RESOURCE {
|
||||
r := data.(*StorageResource)
|
||||
if len(r.Instances) == 0 {
|
||||
return nil, 404, errors.New("can't create a non existing storage resource with no instances")
|
||||
}
|
||||
a = live.NewAccessor[*live.LiveStorage](tools.LIVE_STORAGE, &tools.APIRequest{Admin: true})
|
||||
res, _, _ := a.LoadOne(r.Instances[0].GetID())
|
||||
if res == nil {
|
||||
return nil, 404, errors.New("can't create a non existing storage resource not reported onto compute units catalog")
|
||||
}
|
||||
if !res.(*live.LiveStorage).IsCompatible(data.Serialize(data)) {
|
||||
return nil, 404, errors.New("live storage target is not compatible")
|
||||
}
|
||||
i = res.GetID()
|
||||
idsToUpdate = res.(*live.LiveStorage).ResourcesID
|
||||
}
|
||||
return utils.GenericStoreOne(data, dca)
|
||||
res, code, err := utils.GenericStoreOne(data, dca)
|
||||
if res != nil && i != "" {
|
||||
idsToUpdate = append(idsToUpdate, res.GetID())
|
||||
a.UpdateOne(map[string]interface{}{
|
||||
"resources_id": idsToUpdate,
|
||||
}, i)
|
||||
}
|
||||
return res, code, err
|
||||
}
|
||||
|
||||
func (dca *ResourceMongoAccessor[T]) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
if dca.GetType() == tools.COMPUTE_RESOURCE {
|
||||
return nil, 404, errors.New("can't copy/publish a non existing computing units resource not reported onto compute units catalog")
|
||||
}
|
||||
return dca.StoreOne(data)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/live"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
"github.com/google/uuid"
|
||||
@@ -23,19 +24,6 @@ func (m ServiceMode) String() string {
|
||||
return [...]string{"DEPLOYMENT", "HOSTED"}[m]
|
||||
}
|
||||
|
||||
type ServiceProtocol int
|
||||
|
||||
const (
|
||||
HTTP ServiceProtocol = iota
|
||||
GRPC
|
||||
WEBSOCKET
|
||||
TCP
|
||||
)
|
||||
|
||||
func (p ServiceProtocol) String() string {
|
||||
return [...]string{"HTTP", "GRPC", "WEBSOCKET", "TCP"}[p]
|
||||
}
|
||||
|
||||
type ServiceUsage struct {
|
||||
CPUs map[string]*models.CPU `bson:"cpus,omitempty" json:"cpus,omitempty"`
|
||||
GPUs map[string]*models.GPU `bson:"gpus,omitempty" json:"gpus,omitempty"`
|
||||
@@ -48,10 +36,10 @@ type ServiceUsage struct {
|
||||
// ServiceResourceAccess describes how to reach the service once running.
|
||||
// Populated for HOSTED instances (endpoint already known) and as a template for DEPLOYMENT.
|
||||
type ServiceResourceAccess struct {
|
||||
Container *models.Container `json:"container,omitempty" bson:"container,omitempty"`
|
||||
Protocol ServiceProtocol `json:"protocol" bson:"protocol" default:"0"`
|
||||
EndpointPattern string `json:"endpoint_pattern,omitempty" bson:"endpoint_pattern,omitempty"`
|
||||
HealthCheckPath string `json:"health_check_path,omitempty" bson:"health_check_path,omitempty"`
|
||||
Container *models.Container `json:"container,omitempty" bson:"container,omitempty"`
|
||||
Protocol live.ServiceProtocol `json:"protocol" bson:"protocol" default:"0"`
|
||||
EndpointPattern string `json:"endpoint_pattern,omitempty" bson:"endpoint_pattern,omitempty"`
|
||||
HealthCheckPath string `json:"health_check_path,omitempty" bson:"health_check_path,omitempty"`
|
||||
}
|
||||
|
||||
type ServiceResource struct {
|
||||
|
||||
Reference in New Issue
Block a user