private accessor

This commit is contained in:
mr 2024-07-31 10:35:03 +02:00
parent 7ae1399a9a
commit 00fe19083b
10 changed files with 49 additions and 36 deletions

View File

@ -53,9 +53,12 @@ func (wfa ResourceModelMongoAccessor) LoadAll() ([]utils.ShallowDBObject, int, e
return objs, 200, nil
}
func (wfa *ResourceModelMongoAccessor) Search(word string) ([]utils.ShallowDBObject, int, error) {
func (wfa *ResourceModelMongoAccessor) Search(word string, options ...string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"resource_type"}, wfa.GetType())
if len(options) == 0 {
options = []string{"resource_type"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -70,10 +70,12 @@ 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, options ...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 len(options) == 0 {
options = []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -72,9 +72,12 @@ 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, options ...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 len(options) == 0 {
options = []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -73,9 +73,12 @@ 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, options ...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 len(options) == 0 {
options = []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -73,9 +73,12 @@ 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, options ...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 len(options) == 0 {
options = []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -77,9 +77,12 @@ 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, options ...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 len(options) == 0 {
options = []string{"abstractresource.abstractobject.name", "abstractresource.short_description", "abstractresource.description", "abstractresource.owner", "abstractresource.source_url"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -1,7 +1,7 @@
package utils
import (
"fmt"
"errors"
"cloud.o-forge.io/core/oc-lib/dbs/mongo"
"cloud.o-forge.io/core/oc-lib/logs"
@ -45,7 +45,9 @@ func (dma *AbstractAccessor) SetLogger(t DataType) {
func (wfa *AbstractAccessor) GenericStoreOne(data DBObject, accessor Accessor) (DBObject, int, error) {
data.GenerateID()
fmt.Println(data.Serialize())
if cursor, _, _ := accessor.Search(data.GetName(), "abstractresource.abstractobject.name", "abstractobject.name"); len(cursor) > 0 {
return nil, 409, errors.New(accessor.GetType() + " with name " + data.GetName() + " already exists")
}
err := validate.Struct(data)
if err != nil {
return nil, 422, err
@ -90,13 +92,3 @@ func (dma *AbstractAccessor) GenericUpdateOne(set DBObject, id string, accessor
}
return accessor.LoadOne(id)
}
/*
type ResourceProxy struct {
Host string `json:"host,omitempty" bson:"host,omitempty"`
Port int `json:"port,omitempty" bson:"port,omitempty"`
Command string `json:"command,omitempty" bson:"command,omitempty"`
Args []string `json:"args,omitempty" bson:"args,omitempty"`
EnvArgs map[string]interface{} `json:"env_args,omitempty" bson:"env_args,omitempty"`
}
*/

View File

@ -159,9 +159,12 @@ 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, options ...string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractobject.name"}, wfa.GetType())
if len(options) == 0 {
options = []string{"abstractobject.name"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -57,9 +57,12 @@ 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, options ...string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{}, wfa.GetType())
if len(options) == 0 {
options = []string{}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err

View File

@ -1,8 +1,6 @@
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"
@ -52,9 +50,6 @@ func (wfa *workspaceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject
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)
}
@ -140,9 +135,12 @@ 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, options ...string) ([]utils.ShallowDBObject, int, error) {
objs := []utils.ShallowDBObject{}
res_mongo, code, err := mongo.MONGOService.Search(word, []string{"abstractobject.name"}, wfa.GetType())
if len(options) == 0 {
options = []string{"abstractobject.name"}
}
res_mongo, code, err := mongo.MONGOService.Search(word, options, wfa.GetType())
if err != nil {
wfa.Logger.Error().Msg("Could not store to db. Error: " + err.Error())
return nil, code, err