rebrand oc-datacenter in oc-compute

This commit is contained in:
mr
2024-11-07 11:05:24 +01:00
parent d249bcdf94
commit 1d6b9db5f9
18 changed files with 121 additions and 93 deletions

View File

@@ -1,4 +1,4 @@
package datacenter
package compute
import (
"encoding/json"
@@ -9,17 +9,17 @@ import (
)
/*
* DatacenterResource is a struct that represents a datacenter resource
* it defines the resource datacenter
* ComputeResource is a struct that represents a compute resource
* it defines the resource compute
*/
type DatacenterResource struct {
type ComputeResource struct {
resource_model.AbstractResource
CPUs []*CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs
RAM *RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
}
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
func (dma *ComputeResource) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
@@ -28,7 +28,7 @@ func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObj
return dma
}
func (dma *DatacenterResource) Serialize() map[string]interface{} {
func (dma *ComputeResource) Serialize() map[string]interface{} {
var m map[string]interface{}
b, err := json.Marshal(dma)
if err != nil {
@@ -38,9 +38,9 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
return m
}
func (d *DatacenterResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
func (d *ComputeResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New()
data.Init(tools.DATACENTER_RESOURCE, caller)
data.Init(tools.COMPUTE_RESOURCE, caller)
return data
}

View File

@@ -1,4 +1,4 @@
package datacenter
package compute
import (
"cloud.o-forge.io/core/oc-lib/dbs"
@@ -7,39 +7,39 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type datacenterMongoAccessor struct {
type computeMongoAccessor struct {
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
}
// New creates a new instance of the datacenterMongoAccessor
func New() *datacenterMongoAccessor {
return &datacenterMongoAccessor{}
// New creates a new instance of the computeMongoAccessor
func New() *computeMongoAccessor {
return &computeMongoAccessor{}
}
/*
* Nothing special here, just the basic CRUD operations
*/
func (dca *datacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func (dca *computeMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return dca.GenericDeleteOne(id, dca)
}
func (dca *datacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*DatacenterResource).ResourceModel = nil
return dca.GenericUpdateOne(set, id, dca, &DatacenterResource{})
func (dca *computeMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*ComputeResource).ResourceModel = nil
return dca.GenericUpdateOne(set, id, dca, &ComputeResource{})
}
func (dca *datacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*DatacenterResource).ResourceModel = nil
func (dca *computeMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*ComputeResource).ResourceModel = nil
return dca.GenericStoreOne(data, dca)
}
func (dca *datacenterMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return dca.GenericStoreOne(data, dca)
func (dca *computeMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return dca.computeMongoAccessor(data, dca)
}
func (dca *datacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var datacenter DatacenterResource
func (dca *computeMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var compute ComputeResource
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dca.GetType())
if err != nil {
@@ -47,23 +47,23 @@ func (dca *datacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, err
return nil, code, err
}
res_mongo.Decode(&datacenter)
res_mongo.Decode(&compute)
accessor := (&resource_model.ResourceModel{}).GetAccessor(nil)
resources, _, err := accessor.Search(nil, dca.GetType())
if err == nil && len(resources) > 0 {
datacenter.ResourceModel = resources[0].(*resource_model.ResourceModel)
compute.ResourceModel = resources[0].(*resource_model.ResourceModel)
}
return &datacenter, 200, nil
return &compute, 200, nil
}
func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa computeMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not retrieve any from db. Error: " + err.Error())
return nil, code, err
}
var results []DatacenterResource
var results []ComputeResource
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err
}
@@ -78,7 +78,7 @@ func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
return objs, 200, nil
}
func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
func (wfa *computeMongoAccessor) Search(filters *dbs.Filters, search string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
if (filters == nil || len(filters.And) == 0 || len(filters.Or) == 0) && search != "" {
filters = &dbs.Filters{
@@ -96,7 +96,7 @@ func (wfa *datacenterMongoAccessor) Search(filters *dbs.Filters, search string)
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err
}
var results []DatacenterResource
var results []ComputeResource
if err = res_mongo.All(mongo.MngoCtx, &results); err != nil {
return nil, 404, err
}

View File

@@ -1,4 +1,4 @@
package datacenter
package compute
import (
"testing"
@@ -9,10 +9,10 @@ import (
"github.com/stretchr/testify/assert"
)
func TestStoreOneDatacenter(t *testing.T) {
dc := DatacenterResource{
func TestStoreOneCompute(t *testing.T) {
dc := ComputeResource{
AbstractResource: resource_model.AbstractResource{
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
AbstractObject: utils.AbstractObject{Name: "testCompute"},
Description: "Lorem Ipsum",
Logo: "azerty.com",
Owner: "toto",
@@ -27,10 +27,10 @@ func TestStoreOneDatacenter(t *testing.T) {
assert.NotEmpty(t, id)
}
func TestLoadOneDatacenter(t *testing.T) {
dc := DatacenterResource{
func TestLoadOneCompute(t *testing.T) {
dc := ComputeResource{
AbstractResource: resource_model.AbstractResource{
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
AbstractObject: utils.AbstractObject{Name: "testCompute"},
Description: "Lorem Ipsum",
Logo: "azerty.com",
Owner: "toto",

View File

@@ -7,7 +7,20 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
// enum of public private or licenced data
type DataLicense string
const (
PUBLIC = "public"
PRIVATE = "private"
LICENCED = "licenced"
)
/*
* Struct of Usage Conditions
*/
type UsageConditions struct {
Usage string `json:"usage,omitempty" bson:"usage,omitempty" description:"usage of the data"` // Usage is the usage of the data
Actors []string `json:"actors,omitempty" bson:"actors,omitempty" description:"actors of the data"` // Actors is the actors of the data
}
/*
* DataResource is a struct that represents a data resource
* it defines the resource data
@@ -15,6 +28,10 @@ import (
type DataResource struct {
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
resource_model.WebResource
Type string `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
UsageConditions UsageConditions `json:"usage_conditions,omitempty" bson:"usage_conditions,omitempty" description:"usage conditions of the data"` // UsageConditions is the usage conditions of the data
License DataLicense `json:"license,omitempty" bson:"license,omitempty" description:"license of the data"` // License is the license of the data
Interest DataLicense `json:"interest,omitempty" bson:"interest,omitempty" description:"interest of the data"` // Interest is the interest of the data
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
}

View File

@@ -4,7 +4,7 @@ import (
"encoding/json"
"cloud.o-forge.io/core/oc-lib/models/resource_model"
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
@@ -29,9 +29,9 @@ type Expose struct {
*/
type ProcessingResource struct {
resource_model.AbstractResource
CPUs []*datacenter.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
GPUs []*datacenter.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"` // GPUs is the list of GPUs
RAM *datacenter.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
CPUs []*compute.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"` // CPUs is the list of CPUs
GPUs []*compute.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"` // GPUs is the list of GPUs
RAM *compute.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
Storage uint `bson:"storage,omitempty" json:"storage,omitempty"` // Storage is the storage
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"` // Parallel is a flag that indicates if the processing is parallel
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model

View File

@@ -3,7 +3,7 @@ package resources
import (
"cloud.o-forge.io/core/oc-lib/models/resource_model"
"cloud.o-forge.io/core/oc-lib/models/resources/data"
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
@@ -18,13 +18,13 @@ type ResourceSet struct {
Datas []string `bson:"datas,omitempty" json:"datas,omitempty"`
Storages []string `bson:"storages,omitempty" json:"storages,omitempty"`
Processings []string `bson:"processings,omitempty" json:"processings,omitempty"`
Datacenters []string `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
Computes []string `bson:"computes,omitempty" json:"computes,omitempty"`
Workflows []string `bson:"workflows,omitempty" json:"workflows,omitempty"`
DataResources []*data.DataResource `bson:"-" json:"data_resources,omitempty"`
StorageResources []*storage.StorageResource `bson:"-" json:"storage_resources,omitempty"`
ProcessingResources []*processing.ProcessingResource `bson:"-" json:"processing_resources,omitempty"`
DatacenterResources []*datacenter.DatacenterResource `bson:"-" json:"datacenter_resources,omitempty"`
ComputeResources []*compute.ComputeResource `bson:"-" json:"compute_resources,omitempty"`
WorkflowResources []*w.WorkflowResource `bson:"-" json:"workflow_resources,omitempty"`
}
@@ -32,7 +32,7 @@ type ItemResource struct {
Data *data.DataResource `bson:"data,omitempty" json:"data,omitempty"`
Processing *processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
Storage *storage.StorageResource `bson:"storage,omitempty" json:"storage,omitempty"`
Datacenter *datacenter.DatacenterResource `bson:"datacenter,omitempty" json:"datacenter,omitempty"`
Compute *compute.ComputeResource `bson:"compute,omitempty" json:"compute,omitempty"`
Workflow *w.WorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
}
@@ -47,12 +47,11 @@ func (i *ItemResource) GetAbstractRessource() *resource_model.AbstractResource {
if(i.Storage != nil){
return &i.Storage.AbstractResource
}
if(i.Datacenter != nil){
return &i.Datacenter.AbstractResource
if(i.Compute != nil){
return &i.Compute.AbstractResource
}
if(i.Workflow != nil){
return &i.Workflow.AbstractResource
}
return nil
}

View File

@@ -28,6 +28,18 @@ func (dma StorageType) ToArgo() string {
return argoType[dma]
}
// enum of a data type
type StorageType string
const (
FILE = "file"
STREAM = "stream"
API = "api"
DATABASE = "database"
S3 = "s3"
MEMORY = "memory"
HARDWARE = "hardware"
)
/*
* StorageResource is a struct that represents a storage resource
* it defines the resource storage
@@ -35,6 +47,7 @@ func (dma StorageType) ToArgo() string {
type StorageResource struct {
resource_model.AbstractResource // AbstractResource contains the basic fields of an object (id, name)
resource_model.WebResource
Type DataType `bson:"type,omitempty" json:"type,omitempty"` // Type is the type of the storage
Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage
SizeType StorageType `bson:"size_type" json:"size_type" default:"0"` // SizeType is the type of the storage size
Size uint `bson:"size,omitempty" json:"size,omitempty"` // Size is the size of the storage

View File

@@ -17,8 +17,8 @@ func (g *Graph) GetResource(id string) (string, utils.DBObject) {
if item, ok := g.Items[id]; ok {
if item.Data != nil {
return tools.DATA_RESOURCE.String(), item.Data
} else if item.Datacenter != nil {
return tools.DATACENTER_RESOURCE.String(), item.Datacenter
} else if item.Compute != nil {
return tools.COMPUTE_RESOURCE.String(), item.Compute
} else if item.Workflow != nil {
return tools.WORKFLOW_RESOURCE.String(), item.Workflow
} else if item.Processing != nil {