private accessor

This commit is contained in:
mr 2024-07-31 10:07:55 +02:00
parent d6a2a416c1
commit 7ae1399a9a
21 changed files with 121 additions and 87 deletions

View File

@ -34,7 +34,7 @@ func (dma *DataResource) Serialize() map[string]interface{} {
}
func (d *DataResource) GetAccessor() utils.Accessor {
data := &DataMongoAccessor{}
data := New()
data.SetLogger(utils.DATA_RESOURCE)
return data
}

View File

@ -6,29 +6,33 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type DataMongoAccessor struct {
type dataMongoAccessor struct {
utils.AbstractAccessor
}
func (dma *DataMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *dataMongoAccessor {
return &dataMongoAccessor{}
}
func (dma *dataMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return dma.GenericDeleteOne(id, dma)
}
func (dma *DataMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (dma *dataMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*DataResource).ResourceModel = nil
return dma.GenericUpdateOne(set, id, dma, &DataResource{})
}
func (dma *DataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (dma *dataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*DataResource).ResourceModel = nil
return dma.GenericStoreOne(data, dma)
}
func (dma *DataMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (dma *dataMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return dma.GenericStoreOne(data, dma)
}
func (dma *DataMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (dma *dataMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var data DataResource
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dma.GetType())
if err != nil {
@ -44,7 +48,7 @@ func (dma *DataMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
return &data, 200, nil
}
func (wfa DataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa dataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -66,7 +70,7 @@ func (wfa DataMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
return objs, 200, nil
}
func (wfa *DataMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *dataMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"},
wfa.GetType())

View File

@ -21,7 +21,7 @@ func TestStoreOneData(t *testing.T) {
},
}
dma := DataMongoAccessor{}
dma := New()
id, _, _ := dma.StoreOne(&d)
assert.NotEmpty(t, id)
@ -39,7 +39,7 @@ func TestLoadOneDate(t *testing.T) {
},
}
dma := DataMongoAccessor{}
dma := New()
new_d, _, _ := dma.StoreOne(&d)
assert.Equal(t, d, new_d)
}

View File

@ -34,7 +34,7 @@ func (dma *DatacenterResource) Serialize() map[string]interface{} {
}
func (d *DatacenterResource) GetAccessor() utils.Accessor {
data := &DatacenterMongoAccessor{}
data := New()
data.SetLogger(utils.DATACENTER_RESOURCE)
return data
}

View File

@ -6,29 +6,33 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type DatacenterMongoAccessor struct {
type datacenterMongoAccessor struct {
utils.AbstractAccessor
}
func (dca *DatacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *datacenterMongoAccessor {
return &datacenterMongoAccessor{}
}
func (dca *datacenterMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return dca.GenericDeleteOne(id, dca)
}
func (dca *DatacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (dca *datacenterMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*DatacenterResource).ResourceModel = nil
return dca.GenericUpdateOne(set, id, dca, &DatacenterResource{})
}
func (dca *DatacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (dca *datacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*DatacenterResource).ResourceModel = nil
return dca.GenericStoreOne(data, dca)
}
func (dca *DatacenterMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (dca *datacenterMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return dca.GenericStoreOne(data, dca)
}
func (dca *DatacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (dca *datacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var datacenter DatacenterResource
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dca.GetType())
@ -46,7 +50,7 @@ func (dca *DatacenterMongoAccessor) LoadOne(id string) (utils.DBObject, int, err
return &datacenter, 200, nil
}
func (wfa DatacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa datacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -68,7 +72,7 @@ func (wfa DatacenterMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
return objs, 200, nil
}
func (wfa *DatacenterMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *datacenterMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}, wfa.GetType())
if err != nil {

View File

@ -21,7 +21,7 @@ func TestStoreOneDatacenter(t *testing.T) {
},
}
dcma := DatacenterMongoAccessor{}
dcma := New()
id, _, _ := dcma.StoreOne(&dc)
assert.NotEmpty(t, id)
@ -39,7 +39,7 @@ func TestLoadOneDatacenter(t *testing.T) {
},
}
dcma := DatacenterMongoAccessor{}
dcma := New()
new_dc, _, _ := dcma.StoreOne(&dc)
assert.Equal(t, dc, new_dc)

View File

@ -17,9 +17,6 @@ type ProcessingResource struct {
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"`
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"`
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"`
// Price uint `bson:"price,omitempty" json:"price,omitempty"`
// License string `bson:"license,omitempty" json:"license,omitempty"`
}
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
@ -42,7 +39,7 @@ func (dma *ProcessingResource) Serialize() map[string]interface{} {
}
func (d *ProcessingResource) GetAccessor() utils.Accessor {
data := &ProcessingMongoAccessor{}
data := New()
data.SetLogger(utils.PROCESSING_RESOURCE)
return data
}

View File

@ -6,29 +6,33 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type ProcessingMongoAccessor struct {
type processingMongoAccessor struct {
utils.AbstractAccessor
}
func (pma *ProcessingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *processingMongoAccessor {
return &processingMongoAccessor{}
}
func (pma *processingMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return pma.GenericDeleteOne(id, pma)
}
func (pma *ProcessingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (pma *processingMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*ProcessingResource).ResourceModel = nil
return pma.GenericUpdateOne(set, id, pma, &ProcessingResource{})
}
func (pma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (pma *processingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*ProcessingResource).ResourceModel = nil
return pma.GenericStoreOne(data, pma)
}
func (pma *ProcessingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (pma *processingMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return pma.GenericStoreOne(data, pma)
}
func (pma *ProcessingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (pma *processingMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var processing ProcessingResource
@ -47,7 +51,7 @@ func (pma *ProcessingMongoAccessor) LoadOne(id string) (utils.DBObject, int, err
return &processing, 200, nil
}
func (wfa ProcessingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa processingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -69,7 +73,7 @@ func (wfa ProcessingMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, erro
return objs, 200, nil
}
func (wfa *ProcessingMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *processingMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}, wfa.GetType())
if err != nil {

View File

@ -44,7 +44,7 @@ func (dma *StorageResource) Serialize() map[string]interface{} {
}
func (d *StorageResource) GetAccessor() utils.Accessor {
data := &StorageMongoAccessor{}
data := New()
data.SetLogger(utils.STORAGE_RESOURCE)
return data
}

View File

@ -6,29 +6,33 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type StorageMongoAccessor struct {
type storageMongoAccessor struct {
utils.AbstractAccessor
}
func (sma *StorageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *storageMongoAccessor {
return &storageMongoAccessor{}
}
func (sma *storageMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return sma.GenericDeleteOne(id, sma)
}
func (sma *StorageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*StorageResource).ResourceModel = nil
return sma.GenericUpdateOne(set, id, sma, &StorageResource{})
}
func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*StorageResource).ResourceModel = nil
return sma.GenericStoreOne(data, sma)
}
func (sma *StorageMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return sma.GenericStoreOne(data, sma)
}
func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (sma *storageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var storage StorageResource
@ -47,7 +51,7 @@ func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, int, error)
return &storage, 200, nil
}
func (wfa StorageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa storageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -69,7 +73,7 @@ func (wfa StorageMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
return objs, 200, nil
}
func (wfa *StorageMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *storageMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}, wfa.GetType())
if err != nil {

View File

@ -21,7 +21,7 @@ func TestStoreOneStorage(t *testing.T) {
},
}
sma := StorageMongoAccessor{}
sma := New()
id, _, _ := sma.StoreOne(&s)
assert.NotEmpty(t, id)
@ -39,7 +39,7 @@ func TestLoadOneStorage(t *testing.T) {
},
}
sma := StorageMongoAccessor{}
sma := New()
new_s, _, _ := sma.StoreOne(&s)
assert.Equal(t, s, new_s)

View File

@ -13,7 +13,7 @@ type WorkflowResource struct {
}
func (d *WorkflowResource) GetAccessor() utils.Accessor {
data := &WorkflowResourceMongoAccessor{}
data := New()
data.SetLogger(utils.WORKFLOW_RESOURCE)
return data
}

View File

@ -6,25 +6,29 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type WorkflowResourceMongoAccessor struct {
type workflowResourceMongoAccessor struct {
utils.AbstractAccessor
}
func (wfa *WorkflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *workflowResourceMongoAccessor {
return &workflowResourceMongoAccessor{}
}
func (wfa *workflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return wfa.GenericDeleteOne(id, wfa)
}
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (wfa *workflowResourceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
set.(*WorkflowResource).ResourceModel = nil
return wfa.GenericUpdateOne(set, id, wfa, &WorkflowResource{})
}
func (wfa *WorkflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
data.(*WorkflowResource).ResourceModel = nil
return wfa.GenericStoreOne(data, wfa)
}
func (wfa *WorkflowResourceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workflowResourceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
res, _, _ := wfa.LoadOne(data.GetID())
data.(*WorkflowResource).WorkflowID = data.GetID()
if res == nil {
@ -35,7 +39,7 @@ func (wfa *WorkflowResourceMongoAccessor) CopyOne(data utils.DBObject) (utils.DB
}
}
func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (wfa *workflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var workflow WorkflowResource
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil {
@ -51,7 +55,7 @@ func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, in
return &workflow, 200, nil
}
func (wfa WorkflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa workflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -73,7 +77,7 @@ func (wfa WorkflowResourceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int
return objs, 200, nil
}
func (wfa *WorkflowResourceMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *workflowResourceMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}, wfa.GetType())
if err != nil {

View File

@ -20,7 +20,7 @@ func TestStoreOneWorkflow(t *testing.T) {
},
}
wma := WorkflowResourceMongoAccessor{}
wma := New()
id, _, _ := wma.StoreOne(&w)
assert.NotEmpty(t, id)
@ -37,7 +37,7 @@ func TestLoadOneWorkflow(t *testing.T) {
},
}
wma := WorkflowResourceMongoAccessor{}
wma := New()
new_w, _, _ := wma.StoreOne(&w)
assert.Equal(t, w, new_w)
}

View File

@ -32,7 +32,7 @@ func (d *Workflow) GetName() string {
}
func (d *Workflow) GetAccessor() utils.Accessor {
data := &WorkflowMongoAccessor{}
data := New()
data.SetLogger(utils.WORKFLOW)
return data
}

View File

@ -12,15 +12,19 @@ import (
"github.com/vk496/cron"
)
type WorkflowMongoAccessor struct {
type workflowMongoAccessor struct {
utils.AbstractAccessor
}
func (wfa *WorkflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *workflowMongoAccessor {
return &workflowMongoAccessor{}
}
func (wfa *workflowMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return wfa.GenericDeleteOne(id, wfa)
}
func (wfa *WorkflowMongoAccessor) execution(realData *Workflow, delete bool) (int, error) {
func (wfa *workflowMongoAccessor) execution(realData *Workflow, delete bool) (int, error) {
if delete {
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
"workflow_id": realData.UUID,
@ -65,7 +69,7 @@ func (wfa *WorkflowMongoAccessor) execution(realData *Workflow, delete bool) (in
return 200, nil
}
func (wfa *WorkflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (wfa *workflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
fmt.Println(set.Serialize())
if code, err := wfa.execution(set.(*Workflow), true); err != nil {
return nil, code, err
@ -73,7 +77,7 @@ func (wfa *WorkflowMongoAccessor) UpdateOne(set utils.DBObject, id string) (util
return wfa.GenericUpdateOne(set, id, wfa, &Workflow{})
}
func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
res, code, err := wfa.GenericStoreOne(data, wfa)
if err != nil {
return nil, code, err
@ -84,11 +88,11 @@ func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
return res, code, err
}
func (wfa *WorkflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workflowMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return wfa.GenericStoreOne(data, wfa)
}
func (wfa *WorkflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (wfa *workflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var workflow Workflow
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil {
@ -138,7 +142,7 @@ func (wfa *WorkflowMongoAccessor) LoadOne(id string) (utils.DBObject, int, error
return &workflow, 200, nil
}
func (wfa WorkflowMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa workflowMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -155,7 +159,7 @@ func (wfa WorkflowMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error)
return objs, 200, nil
}
func (wfa *WorkflowMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *workflowMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractobject.name"}, wfa.GetType())
if err != nil {

View File

@ -12,7 +12,7 @@ func TestStoreOneWorkflow(t *testing.T) {
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
}
wma := WorkflowMongoAccessor{}
wma := New()
id, _, _ := wma.StoreOne(&w)
assert.NotEmpty(t, id)
@ -23,7 +23,7 @@ func TestLoadOneWorkflow(t *testing.T) {
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
}
wma := WorkflowMongoAccessor{}
wma := New()
new_w, _, _ := wma.StoreOne(&w)
assert.Equal(t, w, new_w)
}

View File

@ -58,7 +58,7 @@ func (d *WorkflowExecution) GetName() string {
}
func (d *WorkflowExecution) GetAccessor() utils.Accessor {
data := &WorkflowExecutionMongoAccessor{}
data := New()
data.SetLogger(utils.WORKFLOW_EXECUTION)
return data
}

View File

@ -5,27 +5,31 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type WorkflowExecutionMongoAccessor struct {
type workflowExecutionMongoAccessor struct {
utils.AbstractAccessor
}
func (wfa *WorkflowExecutionMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *workflowExecutionMongoAccessor {
return &workflowExecutionMongoAccessor{}
}
func (wfa *workflowExecutionMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return wfa.GenericDeleteOne(id, wfa)
}
func (wfa *WorkflowExecutionMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (wfa *workflowExecutionMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
return wfa.GenericUpdateOne(set, id, wfa, &WorkflowExecution{})
}
func (wfa *WorkflowExecutionMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workflowExecutionMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
return wfa.GenericStoreOne(data, wfa)
}
func (wfa *WorkflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workflowExecutionMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return wfa.GenericStoreOne(data, wfa)
}
func (wfa *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (wfa *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var workflow WorkflowExecution
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil {
@ -36,7 +40,7 @@ func (wfa *WorkflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, i
return &workflow, 200, nil
}
func (wfa WorkflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa workflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -53,7 +57,7 @@ func (wfa WorkflowExecutionMongoAccessor) LoadAll() ([]utils.ShallowDBObject, in
return objs, 200, nil
}
func (wfa *WorkflowExecutionMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *workflowExecutionMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{}, wfa.GetType())
if err != nil {

View File

@ -27,7 +27,7 @@ func (d *Workspace) GetName() string {
}
func (d *Workspace) GetAccessor() utils.Accessor {
data := &WorkspaceMongoAccessor{}
data := New()
data.SetLogger(utils.WORKSPACE)
return data
}

View File

@ -1,6 +1,8 @@
package workspace
import (
"errors"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/models/resources/data"
"cloud.o-forge.io/core/oc-lib/models/resources/datacenter"
@ -10,15 +12,19 @@ import (
"cloud.o-forge.io/core/oc-lib/models/utils"
)
type WorkspaceMongoAccessor struct {
type workspaceMongoAccessor struct {
utils.AbstractAccessor
}
func (wfa *WorkspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
func New() *workspaceMongoAccessor {
return &workspaceMongoAccessor{}
}
func (wfa *workspaceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
return wfa.GenericDeleteOne(id, wfa)
}
func (wfa *WorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
func (wfa *workspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
d := set.(*Workspace)
d.DataResources = nil
d.DatacenterResources = nil
@ -39,21 +45,24 @@ func (wfa *WorkspaceMongoAccessor) UpdateOne(set utils.DBObject, id string) (uti
return wfa.GenericUpdateOne(set, id, wfa, &Workspace{})
}
func (wfa *WorkspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
d := data.(*Workspace)
d.DataResources = nil
d.DatacenterResources = nil
d.StorageResources = nil
d.ProcessingResources = nil
d.WorkflowResources = nil
if res, _, _ := wfa.Search(d.Name); len(res) > 0 {
return nil, 409, errors.New("Workspace with name " + d.Name + " already exists")
}
return wfa.GenericStoreOne(d, wfa)
}
func (wfa *WorkspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
func (wfa *workspaceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
return wfa.GenericStoreOne(data, wfa)
}
func (wfa *WorkspaceMongoAccessor) fill(workflow *Workspace) *Workspace {
func (wfa *workspaceMongoAccessor) fill(workflow *Workspace) *Workspace {
if workflow.Datas != nil && len(workflow.Datas) > 0 {
dataAccessor := (&data.DataResource{}).GetAccessor()
for _, id := range workflow.Datas {
@ -102,7 +111,7 @@ func (wfa *WorkspaceMongoAccessor) fill(workflow *Workspace) *Workspace {
return workflow
}
func (wfa *WorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
func (wfa *workspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
var workflow Workspace
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
if err != nil {
@ -114,7 +123,7 @@ func (wfa *WorkspaceMongoAccessor) LoadOne(id string) (utils.DBObject, int, erro
return wfa.fill(&workflow), 200, nil
}
func (wfa WorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
func (wfa workspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.LoadAll(wfa.GetType())
if err != nil {
@ -131,7 +140,7 @@ func (wfa WorkspaceMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, error
return objs, 200, nil
}
func (wfa *WorkspaceMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *workspaceMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractobject.name"}, wfa.GetType())
if err != nil {