Simplify & Live Bug

This commit is contained in:
mr
2026-04-08 15:40:44 +02:00
parent dbbad79480
commit 284533ad1d
12 changed files with 38 additions and 19 deletions

View File

@@ -33,7 +33,7 @@ func (d *LiveDatacenter) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*LiveDatacenter](tools.LIVE_DATACENTER, request) // Create a new instance of the accessor return NewAccessor[*LiveDatacenter](tools.LIVE_DATACENTER, request) // Create a new instance of the accessor
} }
func (d *LiveDatacenter) GetResourceAccessor(request *tools.APIRequest) utils.Accessor { func (d *LiveDatacenter) GetResourceAccessor(request *tools.APIRequest) utils.Accessor {
return resources.NewAccessor[*resources.ComputeResource](tools.COMPUTE_RESOURCE, request, func() utils.DBObject { return &resources.ComputeResource{} }) return resources.NewAccessor[*resources.ComputeResource](tools.COMPUTE_RESOURCE, request)
} }
func (d *LiveDatacenter) GetResource() resources.ResourceInterface { func (d *LiveDatacenter) GetResource() resources.ResourceInterface {

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"cloud.o-forge.io/core/oc-lib/dbs"
"cloud.o-forge.io/core/oc-lib/logs" "cloud.o-forge.io/core/oc-lib/logs"
"cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools" "cloud.o-forge.io/core/oc-lib/tools"
@@ -89,3 +90,25 @@ func (a *liveMongoAccessor[T]) CopyOne(data utils.DBObject) (utils.DBObject, int
} }
} }
} }
func (wfa *liveMongoAccessor[T]) LoadAll(isDraft bool, offset int64, limit int64) ([]utils.ShallowDBObject, int, error) {
return utils.GenericLoadAll[T](wfa.GetExec(isDraft), isDraft, wfa, offset, limit)
}
func (wfa *liveMongoAccessor[T]) Search(filters *dbs.Filters, search string, isDraft bool, offset int64, limit int64) ([]utils.ShallowDBObject, int, error) {
if filters == nil && search == "*" {
return utils.GenericLoadAll[T](func(d utils.DBObject) utils.ShallowDBObject {
return d
}, isDraft, wfa, offset, limit)
}
return utils.GenericSearch[T](filters, search, wfa.New().GetObjectFilters(search),
func(d utils.DBObject) utils.ShallowDBObject {
return d
}, isDraft, wfa, offset, limit)
}
func (a *liveMongoAccessor[T]) GetExec(isDraft bool) func(utils.DBObject) utils.ShallowDBObject {
return func(d utils.DBObject) utils.ShallowDBObject {
return d
}
}

View File

@@ -29,7 +29,7 @@ func (d *LiveStorage) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*LiveStorage](tools.LIVE_STORAGE, request) // Create a new instance of the accessor return NewAccessor[*LiveStorage](tools.LIVE_STORAGE, request) // Create a new instance of the accessor
} }
func (d *LiveStorage) GetResourceAccessor(request *tools.APIRequest) utils.Accessor { func (d *LiveStorage) GetResourceAccessor(request *tools.APIRequest) utils.Accessor {
return resources.NewAccessor[*resources.ComputeResource](tools.STORAGE_RESOURCE, request, func() utils.DBObject { return &resources.StorageResource{} }) return resources.NewAccessor[*resources.StorageResource](tools.STORAGE_RESOURCE, request)
} }
func (d *LiveStorage) GetResource() resources.ResourceInterface { func (d *LiveStorage) GetResource() resources.ResourceInterface {

View File

@@ -25,7 +25,7 @@ type ComputeResource struct {
} }
func (d *ComputeResource) GetAccessor(request *tools.APIRequest) utils.Accessor { func (d *ComputeResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*ComputeResource](tools.COMPUTE_RESOURCE, request, func() utils.DBObject { return &ComputeResource{} }) return NewAccessor[*ComputeResource](tools.COMPUTE_RESOURCE, request)
} }
func (r *ComputeResource) GetType() string { func (r *ComputeResource) GetType() string {

View File

@@ -30,7 +30,7 @@ type DataResource struct {
} }
func (d *DataResource) GetAccessor(request *tools.APIRequest) utils.Accessor { func (d *DataResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*DataResource](tools.DATA_RESOURCE, request, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor return NewAccessor[*DataResource](tools.DATA_RESOURCE, request) // Create a new instance of the accessor
} }
func (r *DataResource) GetType() string { func (r *DataResource) GetType() string {

View File

@@ -23,7 +23,7 @@ func (d *NativeTool) SetName(name string) {
} }
func (d *NativeTool) GetAccessor(request *tools.APIRequest) utils.Accessor { func (d *NativeTool) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*NativeTool](tools.NATIVE_TOOL, request, func() utils.DBObject { return &NativeTool{} }) return NewAccessor[*NativeTool](tools.NATIVE_TOOL, request)
} }
func (r *NativeTool) AddInstances(instance ResourceInstanceITF) { func (r *NativeTool) AddInstances(instance ResourceInstanceITF) {

View File

@@ -114,7 +114,7 @@ func (a *PricedProcessingResource) GetExplicitDurationInS() float64 {
} }
func (d *ProcessingResource) GetAccessor(request *tools.APIRequest) utils.Accessor { func (d *ProcessingResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*ProcessingResource](tools.PROCESSING_RESOURCE, request, func() utils.DBObject { return &ProcessingResource{} }) // Create a new instance of the accessor return NewAccessor[*ProcessingResource](tools.PROCESSING_RESOURCE, request) // Create a new instance of the accessor
} }
func (abs *ProcessingResource) ConvertToPricedResource(t tools.DataType, selectedInstance *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, selectedBookingModeIndex *int, request *tools.APIRequest) (pricing.PricedItemITF, error) { func (abs *ProcessingResource) ConvertToPricedResource(t tools.DataType, selectedInstance *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, selectedBookingModeIndex *int, request *tools.APIRequest) (pricing.PricedItemITF, error) {

View File

@@ -12,11 +12,10 @@ import (
type ResourceMongoAccessor[T ResourceInterface] struct { type ResourceMongoAccessor[T ResourceInterface] struct {
utils.AbstractAccessor[ResourceInterface] // AbstractAccessor contains the basic fields of an accessor (model, caller) utils.AbstractAccessor[ResourceInterface] // AbstractAccessor contains the basic fields of an accessor (model, caller)
generateData func() utils.DBObject
} }
// New creates a new instance of the computeMongoAccessor // New creates a new instance of the computeMongoAccessor
func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIRequest, g func() utils.DBObject) *ResourceMongoAccessor[T] { func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIRequest) *ResourceMongoAccessor[T] {
if !slices.Contains([]tools.DataType{ if !slices.Contains([]tools.DataType{
tools.COMPUTE_RESOURCE, tools.STORAGE_RESOURCE, tools.COMPUTE_RESOURCE, tools.STORAGE_RESOURCE,
tools.PROCESSING_RESOURCE, tools.WORKFLOW_RESOURCE, tools.PROCESSING_RESOURCE, tools.WORKFLOW_RESOURCE,
@@ -47,7 +46,6 @@ func NewAccessor[T ResourceInterface](t tools.DataType, request *tools.APIReques
return nil return nil
}, },
}, },
generateData: g,
} }
} }

View File

@@ -23,7 +23,7 @@ type StorageResource struct {
} }
func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor { func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*StorageResource](tools.STORAGE_RESOURCE, request, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor return NewAccessor[*StorageResource](tools.STORAGE_RESOURCE, request) // Create a new instance of the accessor
} }
func (r *StorageResource) GetType() string { func (r *StorageResource) GetType() string {

View File

@@ -114,8 +114,6 @@ func (f *FakeResource) ConvertToPricedResource(t tools.DataType, a *int, b *int,
func (f *FakeResource) VerifyAuth(string, *tools.APIRequest) bool { return true } func (f *FakeResource) VerifyAuth(string, *tools.APIRequest) bool { return true }
func TestNewAccessor_ReturnsValid(t *testing.T) { func TestNewAccessor_ReturnsValid(t *testing.T) {
acc := resources.NewAccessor[*FakeResource](tools.COMPUTE_RESOURCE, &tools.APIRequest{}, func() utils.DBObject { acc := resources.NewAccessor[*FakeResource](tools.COMPUTE_RESOURCE, &tools.APIRequest{})
return &FakeResource{}
})
assert.NotNil(t, acc) assert.NotNil(t, acc)
} }

View File

@@ -16,7 +16,7 @@ type WorkflowResource struct {
} }
func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor { func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} }) return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request)
} }
func (r *WorkflowResource) AddInstances(instance ResourceInstanceITF) { func (r *WorkflowResource) AddInstances(instance ResourceInstanceITF) {

View File

@@ -210,15 +210,15 @@ func (a *workflowMongoAccessor) verifyResource(obj utils.DBObject) utils.DBObjec
var access utils.Accessor var access utils.Accessor
switch t { switch t {
case tools.COMPUTE_RESOURCE: case tools.COMPUTE_RESOURCE:
access = resources.NewAccessor[*resources.ComputeResource](t, a.GetRequest(), func() utils.DBObject { return &resources.ComputeResource{} }) access = resources.NewAccessor[*resources.ComputeResource](t, a.GetRequest())
case tools.PROCESSING_RESOURCE: case tools.PROCESSING_RESOURCE:
access = resources.NewAccessor[*resources.ProcessingResource](t, a.GetRequest(), func() utils.DBObject { return &resources.ProcessingResource{} }) access = resources.NewAccessor[*resources.ProcessingResource](t, a.GetRequest())
case tools.STORAGE_RESOURCE: case tools.STORAGE_RESOURCE:
access = resources.NewAccessor[*resources.StorageResource](t, a.GetRequest(), func() utils.DBObject { return &resources.StorageResource{} }) access = resources.NewAccessor[*resources.StorageResource](t, a.GetRequest())
case tools.WORKFLOW_RESOURCE: case tools.WORKFLOW_RESOURCE:
access = resources.NewAccessor[*resources.WorkflowResource](t, a.GetRequest(), func() utils.DBObject { return &resources.WorkflowResource{} }) access = resources.NewAccessor[*resources.WorkflowResource](t, a.GetRequest())
case tools.DATA_RESOURCE: case tools.DATA_RESOURCE:
access = resources.NewAccessor[*resources.DataResource](t, a.GetRequest(), func() utils.DBObject { return &resources.DataResource{} }) access = resources.NewAccessor[*resources.DataResource](t, a.GetRequest())
default: default:
wf.Graph.Clear(resource.GetID()) wf.Graph.Clear(resource.GetID())
} }