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)
|
||||
|
Reference in New Issue
Block a user