some
This commit is contained in:
@@ -53,9 +53,7 @@ type ComputeResource struct {
|
||||
}
|
||||
|
||||
func (d *ComputeResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New(peerID, groups)
|
||||
data.Init(tools.COMPUTE_RESOURCE, peerID, groups, caller)
|
||||
return data
|
||||
return New(tools.COMPUTE_RESOURCE, peerID, groups, caller)
|
||||
}
|
||||
|
||||
// CPU is a struct that represents a CPU
|
||||
|
||||
@@ -2,8 +2,10 @@ package compute
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type computeMongoAccessor struct {
|
||||
@@ -11,10 +13,15 @@ type computeMongoAccessor struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the computeMongoAccessor
|
||||
func New(peerID string, groups []string) *computeMongoAccessor {
|
||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *computeMongoAccessor {
|
||||
return &computeMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups, // Set the caller
|
||||
Type: t.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -53,12 +60,11 @@ func (dca *computeMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
|
||||
|
||||
func (wfa *computeMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
|
||||
resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType())
|
||||
return utils.GenericLoadAll[*ComputeResource](func(d utils.DBObject, a []utils.ShallowDBObject) []utils.ShallowDBObject {
|
||||
return utils.GenericLoadAll[*ComputeResource](func(d utils.DBObject) utils.ShallowDBObject {
|
||||
if err == nil && len(resources) > 0 {
|
||||
d.(*ComputeResource).ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
a = append(a, d) // only get the abstract resource !
|
||||
return a
|
||||
return d
|
||||
}, wfa)
|
||||
}
|
||||
|
||||
@@ -66,11 +72,10 @@ func (wfa *computeMongoAccessor) Search(filters *dbs.Filters, search string) ([]
|
||||
root := &ComputeResource{}
|
||||
resources, _, err := wfa.ResourceModelAccessor.Search(nil, wfa.GetType())
|
||||
return utils.GenericSearch[*ComputeResource](filters, search, root.GetResourceFilter(search),
|
||||
func(d utils.DBObject, a []utils.ShallowDBObject) []utils.ShallowDBObject {
|
||||
func(d utils.DBObject) utils.ShallowDBObject {
|
||||
if err == nil && len(resources) > 0 {
|
||||
d.(*ComputeResource).ResourceModel = resources[0].(*resource_model.ResourceModel)
|
||||
}
|
||||
a = append(a, d) // only get the abstract resource !
|
||||
return a
|
||||
return d
|
||||
}, wfa)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func TestStoreOneCompute(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
dcma := New("", nil)
|
||||
dcma := New(tools.COMPUTE_RESOURCE, "", nil, nil)
|
||||
id, _, _ := dcma.StoreOne(&dc)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
@@ -39,7 +40,7 @@ func TestLoadOneCompute(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
dcma := New("", nil)
|
||||
dcma := New(tools.COMPUTE_RESOURCE, "", nil, nil)
|
||||
new_dc, _, _ := dcma.StoreOne(&dc)
|
||||
|
||||
assert.Equal(t, dc, new_dc)
|
||||
|
||||
@@ -38,7 +38,5 @@ type DataResource struct {
|
||||
}
|
||||
|
||||
func (d *DataResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.DATA_RESOURCE, peerID, groups, caller) // Initialize the accessor with the DATA_RESOURCE model type
|
||||
return data
|
||||
return New(tools.DATA_RESOURCE, peerID, groups, caller) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
mongo "cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type dataMongoAccessor struct {
|
||||
@@ -14,10 +16,15 @@ type dataMongoAccessor struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the dataMongoAccessor
|
||||
func New() *dataMongoAccessor {
|
||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *dataMongoAccessor {
|
||||
return &dataMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups, // Set the caller
|
||||
Type: t.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -25,7 +26,7 @@ func TestStoreOneData(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
dma := New()
|
||||
dma := New(tools.DATA_RESOURCE, "", nil, nil)
|
||||
id, _, _ := dma.StoreOne(&d)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
@@ -47,7 +48,7 @@ func TestLoadOneDate(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
dma := New()
|
||||
dma := New(tools.DATA_RESOURCE, "", nil, nil)
|
||||
new_d, _, _ := dma.StoreOne(&d)
|
||||
assert.Equal(t, d, new_d)
|
||||
}
|
||||
|
||||
@@ -40,7 +40,5 @@ type ProcessingResource struct {
|
||||
}
|
||||
|
||||
func (d *ProcessingResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.PROCESSING_RESOURCE, peerID, groups, caller) // Initialize the accessor with the PROCESSING_RESOURCE model type
|
||||
return data
|
||||
return New(tools.PROCESSING_RESOURCE, peerID, groups, caller) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -5,19 +5,26 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type processingMongoAccessor struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the processingMongoAccessor
|
||||
func New() *processingMongoAccessor {
|
||||
// New creates a new instance of the storageMongoAccessor
|
||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *processingMongoAccessor {
|
||||
return &processingMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups, // Set the caller
|
||||
Type: t.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,9 +144,14 @@ func (abs *ResourceModel) VerifyAuth(peerID string, groups []string) bool {
|
||||
}
|
||||
|
||||
func (d *ResourceModel) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := &ResourceModelMongoAccessor{}
|
||||
data.Init(tools.RESOURCE_MODEL, peerID, groups, caller)
|
||||
return data
|
||||
return &ResourceModelMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
Type: tools.RESOURCE_MODEL.String(),
|
||||
PeerID: peerID,
|
||||
Groups: groups,
|
||||
Caller: caller,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (dma *ResourceModel) Deserialize(j map[string]interface{}, obj utils.DBObject) utils.DBObject {
|
||||
|
||||
@@ -57,7 +57,5 @@ type StorageResource struct {
|
||||
}
|
||||
|
||||
func (d *StorageResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.STORAGE_RESOURCE, peerID, groups, caller) // Initialize the accessor with the STORAGE_RESOURCE model type
|
||||
return data
|
||||
return New(tools.STORAGE_RESOURCE, peerID, groups, caller) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type storageMongoAccessor struct {
|
||||
@@ -14,10 +16,15 @@ type storageMongoAccessor struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the storageMongoAccessor
|
||||
func New() *storageMongoAccessor {
|
||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *storageMongoAccessor {
|
||||
return &storageMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups, // Set the caller
|
||||
Type: t.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -21,7 +22,7 @@ func TestStoreOneStorage(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
sma := New()
|
||||
sma := New(tools.STORAGE_RESOURCE, "peerID", []string{}, nil)
|
||||
id, _, _ := sma.StoreOne(&s)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
@@ -39,7 +40,7 @@ func TestLoadOneStorage(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
sma := New()
|
||||
sma := New(tools.STORAGE_RESOURCE, "peerID", []string{}, nil)
|
||||
new_s, _, _ := sma.StoreOne(&s)
|
||||
|
||||
assert.Equal(t, s, new_s)
|
||||
|
||||
@@ -14,7 +14,5 @@ type WorkflowResource struct {
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
data := New() // Create a new instance of the accessor
|
||||
data.Init(tools.WORKFLOW_RESOURCE, peerID, groups, caller) // Initialize the accessor with the WORKFLOW_RESOURCE model type
|
||||
return data
|
||||
return New(tools.WORKFLOW_RESOURCE, peerID, groups, caller) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -5,18 +5,25 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type workflowResourceMongoAccessor struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
func New() *workflowResourceMongoAccessor {
|
||||
func New(t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller) *workflowResourceMongoAccessor {
|
||||
return &workflowResourceMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups, // Set the caller
|
||||
Type: t.String(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
@@ -20,7 +21,7 @@ func TestStoreOneWorkflow(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
wma := New()
|
||||
wma := New(tools.WORKFLOW_RESOURCE, "peerID", []string{}, nil)
|
||||
id, _, _ := wma.StoreOne(&w)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
@@ -37,7 +38,7 @@ func TestLoadOneWorkflow(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
wma := New()
|
||||
wma := New(tools.WORKFLOW_RESOURCE, "peerID", []string{}, nil)
|
||||
new_w, _, _ := wma.StoreOne(&w)
|
||||
assert.Equal(t, w, new_w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user