massive draft for payment process (UNCOMPLETE)
This commit is contained in:
92
models/resources/models.go
Normal file
92
models/resources/models.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type ExploitedResourceSet struct {
|
||||
DataResources []*CustomizedDataResource `bson:"-" json:"data_resources,omitempty"`
|
||||
StorageResources []*CustomizedStorageResource `bson:"-" json:"storage_resources,omitempty"`
|
||||
ProcessingResources []*CustomizedProcessingResource `bson:"-" json:"processing_resources,omitempty"`
|
||||
ComputeResources []*CustomizedComputeResource `bson:"-" json:"compute_resources,omitempty"`
|
||||
WorkflowResources []*CustomizedWorkflowResource `bson:"-" json:"workflow_resources,omitempty"`
|
||||
}
|
||||
|
||||
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"`
|
||||
Computes []string `bson:"computes,omitempty" json:"computes,omitempty"`
|
||||
Workflows []string `bson:"workflows,omitempty" json:"workflows,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(request *tools.APIRequest) {
|
||||
for k, v := range map[utils.DBObject][]string{
|
||||
(&DataResource{}): r.Datas,
|
||||
(&ComputeResource{}): r.Computes,
|
||||
(&StorageResource{}): r.Storages,
|
||||
(&ProcessingResource{}): r.Processings,
|
||||
(&WorkflowResource{}): r.Workflows,
|
||||
} {
|
||||
for _, id := range v {
|
||||
d, _, e := k.GetAccessor(request).LoadOne(id)
|
||||
if e == nil {
|
||||
switch k.(type) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ItemExploitedResource struct {
|
||||
Data *CustomizedDataResource `bson:"data,omitempty" json:"data,omitempty"`
|
||||
Processing *CustomizedProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
|
||||
Storage *CustomizedStorageResource `bson:"storage,omitempty" json:"storage,omitempty"`
|
||||
Compute *CustomizedComputeResource `bson:"compute,omitempty" json:"compute,omitempty"`
|
||||
Workflow *CustomizedWorkflowResource `bson:"workflow,omitempty" json:"workflow,omitempty"`
|
||||
}
|
||||
|
||||
func (w *ItemExploitedResource) SetItemEndUsage(end time.Time) {
|
||||
for _, item := range []ShallowResourceInterface{w.Data, w.Processing, w.Storage, w.Compute, w.Workflow} {
|
||||
if item != nil {
|
||||
item.SetItemEndUsage(end)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (w *ItemExploitedResource) SetItemStartUsage(start time.Time) {
|
||||
for _, item := range []ShallowResourceInterface{w.Data, w.Processing, w.Storage, w.Compute, w.Workflow} {
|
||||
if item != nil {
|
||||
item.SetItemStartUsage(start)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user