lightest + clearest code
This commit is contained in:
@@ -1,12 +1,7 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/compute"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/data"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/processing"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
|
||||
w "cloud.o-forge.io/core/oc-lib/models/resources/workflow"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
@@ -15,6 +10,12 @@ import (
|
||||
// Resource is the interface to be implemented by all classes inheriting from Resource to have the same behavior
|
||||
|
||||
// http://www.inanzzz.com/index.php/post/wqbs/a-basic-usage-of-int-and-string-enum-types-in-golang
|
||||
type ResourceInterface interface {
|
||||
utils.DBObject
|
||||
Trim() *resource_model.AbstractResource
|
||||
SetResourceModel(model *resource_model.ResourceModel)
|
||||
}
|
||||
|
||||
type ResourceSet struct {
|
||||
Datas []string `bson:"datas,omitempty" json:"datas,omitempty"`
|
||||
Storages []string `bson:"storages,omitempty" json:"storages,omitempty"`
|
||||
@@ -22,35 +23,43 @@ type ResourceSet struct {
|
||||
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"`
|
||||
ComputeResources []*compute.ComputeResource `bson:"-" json:"compute_resources,omitempty"`
|
||||
WorkflowResources []*w.WorkflowResource `bson:"-" json:"workflow_resources,omitempty"`
|
||||
DataResources []*DataResource `bson:"-" json:"data_resources,omitempty"`
|
||||
StorageResources []*StorageResource `bson:"-" json:"storage_resources,omitempty"`
|
||||
ProcessingResources []*ProcessingResource `bson:"-" json:"processing_resources,omitempty"`
|
||||
ComputeResources []*ComputeResource `bson:"-" json:"compute_resources,omitempty"`
|
||||
WorkflowResources []*WorkflowResource `bson:"-" json:"workflow_resources,omitempty"`
|
||||
}
|
||||
|
||||
func (r *ResourceSet) Clear() {
|
||||
r.DataResources = nil
|
||||
r.StorageResources = nil
|
||||
r.ProcessingResources = nil
|
||||
r.ComputeResources = nil
|
||||
r.WorkflowResources = nil
|
||||
}
|
||||
|
||||
func (r *ResourceSet) Fill(peerID string, groups []string) {
|
||||
for k, v := range map[utils.DBObject][]string{
|
||||
(&data.DataResource{}): r.Datas,
|
||||
(&compute.ComputeResource{}): r.Computes,
|
||||
(&storage.StorageResource{}): r.Storages,
|
||||
(&processing.ProcessingResource{}): r.Processings,
|
||||
(&w.WorkflowResource{}): r.Workflows,
|
||||
(&DataResource{}): r.Datas,
|
||||
(&ComputeResource{}): r.Computes,
|
||||
(&StorageResource{}): r.Storages,
|
||||
(&ProcessingResource{}): r.Processings,
|
||||
(&WorkflowResource{}): r.Workflows,
|
||||
} {
|
||||
for _, id := range v {
|
||||
d, _, e := k.GetAccessor(peerID, groups, nil).LoadOne(id)
|
||||
if e == nil {
|
||||
switch k.(type) {
|
||||
case *data.DataResource:
|
||||
r.DataResources = append(r.DataResources, d.(*data.DataResource))
|
||||
case *compute.ComputeResource:
|
||||
r.ComputeResources = append(r.ComputeResources, d.(*compute.ComputeResource))
|
||||
case *storage.StorageResource:
|
||||
r.StorageResources = append(r.StorageResources, d.(*storage.StorageResource))
|
||||
case *processing.ProcessingResource:
|
||||
r.ProcessingResources = append(r.ProcessingResources, d.(*processing.ProcessingResource))
|
||||
case *w.WorkflowResource:
|
||||
r.WorkflowResources = append(r.WorkflowResources, d.(*w.WorkflowResource))
|
||||
case *DataResource:
|
||||
r.DataResources = append(r.DataResources, d.(*DataResource))
|
||||
case *ComputeResource:
|
||||
r.ComputeResources = append(r.ComputeResources, d.(*ComputeResource))
|
||||
case *StorageResource:
|
||||
r.StorageResources = append(r.StorageResources, d.(*StorageResource))
|
||||
case *ProcessingResource:
|
||||
r.ProcessingResources = append(r.ProcessingResources, d.(*ProcessingResource))
|
||||
case *WorkflowResource:
|
||||
r.WorkflowResources = append(r.WorkflowResources, d.(*WorkflowResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,11 +67,11 @@ func (r *ResourceSet) Fill(peerID string, groups []string) {
|
||||
}
|
||||
|
||||
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"`
|
||||
Compute *compute.ComputeResource `bson:"compute,omitempty" json:"compute,omitempty"`
|
||||
Workflow *w.WorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
|
||||
Data *DataResource `bson:"data,omitempty" json:"data,omitempty"`
|
||||
Processing *ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
|
||||
Storage *StorageResource `bson:"storage,omitempty" json:"storage,omitempty"`
|
||||
Compute *ComputeResource `bson:"compute,omitempty" json:"compute,omitempty"`
|
||||
Workflow *WorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
|
||||
}
|
||||
|
||||
func (i *ItemResource) GetAbstractRessource() *resource_model.AbstractResource {
|
||||
|
||||
Reference in New Issue
Block a user