lib
This commit is contained in:
@@ -15,7 +15,8 @@ type ResourceSet struct {
|
||||
Services []string `bson:"services,omitempty" json:"services,omitempty"`
|
||||
Dynamics []string `bson:"dynamics,omitempty" json:"dynamics,omitempty"`
|
||||
|
||||
// DynamicResources are stored inline — no DB collection, resolved at runtime via SetAllowedInstances.
|
||||
// Runtime-only resource objects — not persisted. Populated by Fill() from the ID lists above.
|
||||
// Use WorkspaceResourceSet when full object persistence is needed (workspace fluid catalog).
|
||||
DynamicResources []*DynamicResource `bson:"-" json:"dynamic_resources,omitempty"`
|
||||
DataResources []*DataResource `bson:"-" json:"data_resources,omitempty"`
|
||||
StorageResources []*StorageResource `bson:"-" json:"storage_resources,omitempty"`
|
||||
@@ -26,6 +27,98 @@ type ResourceSet struct {
|
||||
ServiceResources []*ServiceResource `bson:"-" json:"service_resources,omitempty"`
|
||||
}
|
||||
|
||||
// WorkspaceResourceSet mirrors ResourceSet but persists complete resource objects to MongoDB.
|
||||
// Use this in workspace documents where the workspace acts as a fluid resource catalog.
|
||||
// The *Resource fields are loaded from bson on read; Fill() skips catalog lookup when they are
|
||||
// already populated.
|
||||
type WorkspaceResourceSet 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"`
|
||||
NativeTool []string `bson:"native,omitempty" json:"native,omitempty"`
|
||||
Services []string `bson:"services,omitempty" json:"services,omitempty"`
|
||||
Dynamics []string `bson:"dynamics,omitempty" json:"dynamics,omitempty"`
|
||||
|
||||
DynamicResources []*DynamicResource `bson:"dynamic_resources,omitempty" json:"dynamic_resources,omitempty"`
|
||||
DataResources []*DataResource `bson:"data_resources,omitempty" json:"data_resources,omitempty"`
|
||||
StorageResources []*StorageResource `bson:"storage_resources,omitempty" json:"storage_resources,omitempty"`
|
||||
ProcessingResources []*ProcessingResource `bson:"processing_resources,omitempty" json:"processing_resources,omitempty"`
|
||||
ComputeResources []*ComputeResource `bson:"compute_resources,omitempty" json:"compute_resources,omitempty"`
|
||||
WorkflowResources []*WorkflowResource `bson:"workflow_resources,omitempty" json:"workflow_resources,omitempty"`
|
||||
NativeTools []*NativeTool `bson:"native_tools,omitempty" json:"native_tools,omitempty"`
|
||||
ServiceResources []*ServiceResource `bson:"service_resources,omitempty" json:"service_resources,omitempty"`
|
||||
}
|
||||
|
||||
func (r *WorkspaceResourceSet) Clear() {
|
||||
r.DataResources = nil
|
||||
r.StorageResources = nil
|
||||
r.ProcessingResources = nil
|
||||
r.ComputeResources = nil
|
||||
r.WorkflowResources = nil
|
||||
r.ServiceResources = nil
|
||||
r.DynamicResources = nil
|
||||
r.NativeTools = nil
|
||||
}
|
||||
|
||||
// Fill populates *Resource fields from their ID lists. When a field is already non-nil
|
||||
// (loaded from the workspace MongoDB document), the catalog lookup is skipped for that type.
|
||||
func (r *WorkspaceResourceSet) Fill(request *tools.APIRequest) {
|
||||
if r.DataResources == nil {
|
||||
for _, id := range r.Datas {
|
||||
if d, _, e := (&DataResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.DataResources = append(r.DataResources, d.(*DataResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.ComputeResources == nil {
|
||||
for _, id := range r.Computes {
|
||||
if d, _, e := (&ComputeResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.ComputeResources = append(r.ComputeResources, d.(*ComputeResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.StorageResources == nil {
|
||||
for _, id := range r.Storages {
|
||||
if d, _, e := (&StorageResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.StorageResources = append(r.StorageResources, d.(*StorageResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.ProcessingResources == nil {
|
||||
for _, id := range r.Processings {
|
||||
if d, _, e := (&ProcessingResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.ProcessingResources = append(r.ProcessingResources, d.(*ProcessingResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.WorkflowResources == nil {
|
||||
for _, id := range r.Workflows {
|
||||
if d, _, e := (&WorkflowResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.WorkflowResources = append(r.WorkflowResources, d.(*WorkflowResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.ServiceResources == nil {
|
||||
for _, id := range r.Services {
|
||||
if d, _, e := (&ServiceResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.ServiceResources = append(r.ServiceResources, d.(*ServiceResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
if r.DynamicResources == nil {
|
||||
for _, id := range r.Dynamics {
|
||||
if d, _, e := (&DynamicResource{}).GetAccessor(request).LoadOne(id); e == nil {
|
||||
r.DynamicResources = append(r.DynamicResources, d.(*DynamicResource))
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, d := range r.DynamicResources {
|
||||
d.SetAllowedInstances(request)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *ResourceSet) Clear() {
|
||||
r.DataResources = nil
|
||||
r.StorageResources = nil
|
||||
|
||||
Reference in New Issue
Block a user