A question refers to the comment ! And if not Ooopsy
This commit is contained in:
@@ -9,15 +9,19 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
/*
|
||||
* ProcessingResource is a struct that represents a processing resource
|
||||
* it defines the resource processing
|
||||
*/
|
||||
type ProcessingResource struct {
|
||||
resource_model.AbstractResource
|
||||
CPUs []*datacenter.CPU `bson:"cpus,omitempty" json:"cp_us,omitempty"`
|
||||
GPUs []*datacenter.GPU `bson:"gpus,omitempty" json:"gp_us,omitempty"`
|
||||
RAM *datacenter.RAM `bson:"ram,omitempty" json:"ram,omitempty"`
|
||||
Storage uint `bson:"storage,omitempty" json:"storage,omitempty"`
|
||||
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"`
|
||||
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"`
|
||||
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"`
|
||||
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
|
||||
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
|
||||
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"` // DiskIO is the disk IO
|
||||
}
|
||||
|
||||
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
@@ -40,7 +44,7 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
|
||||
}
|
||||
|
||||
func (d *ProcessingResource) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New()
|
||||
data.Init(utils.PROCESSING_RESOURCE, caller)
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(utils.PROCESSING_RESOURCE, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||
return data
|
||||
}
|
||||
|
@@ -8,13 +8,18 @@ import (
|
||||
)
|
||||
|
||||
type processingMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the processingMongoAccessor
|
||||
func New() *processingMongoAccessor {
|
||||
return &processingMongoAccessor{}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
|
||||
func (pma *processingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return pma.GenericDeleteOne(id, pma)
|
||||
}
|
||||
@@ -69,16 +74,17 @@ func (wfa processingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
||||
// Search searches for processing resources in the database, given some filters OR a search string
|
||||
func (wfa *processingMongoAccessor) 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{
|
||||
Or: map[string][]dbs.Filter{
|
||||
Or: map[string][]dbs.Filter{ // filter by like name, short_description, description, owner, url if no filters are provided
|
||||
"abstractresource.abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.short_description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
"abstractresource.description": {{Operator: dbs.LIKE.String(), Value: search}},
|
||||
@@ -102,7 +108,7 @@ func (wfa *processingMongoAccessor) Search(filters *dbs.Filters, search string)
|
||||
if err == nil && len(resources) > 0 {
|
||||
r.ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
objs = append(objs, &r.AbstractResource)
|
||||
objs = append(objs, &r.AbstractResource) // only get the abstract resource !
|
||||
}
|
||||
return objs, 200, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user