This commit is contained in:
mr 2024-07-18 15:02:39 +02:00
parent 4fab0cb153
commit e345204851
8 changed files with 39 additions and 66 deletions

View File

@ -7,29 +7,36 @@ import (
"cloud.o-forge.io/core/oc-lib/utils"
)
type LibData resources.ResourceType
const (
INVALID = resources.INVALID
DATA = resources.DATA
PROCESSING = resources.PROCESSING
STORAGE = resources.STORAGE
DATACENTER = resources.DATACENTER
WORKFLOW = resources.WORKFLOW
)
const (
WORKFLOW LibData = 5
MONGO = utils.MONGO
)
func Init() {
mongo.MONGOService.Init(models.GetModelsNames(), GetConfig())
}
func LoadOne(name string, driver utils.Driver, id string) interface{} {
return models.Model(name).GetAccessor(driver).LoadOne(id)
func LoadOne(name string, id string) interface{} {
return models.Model(name).GetAccessor().LoadOne(id)
}
func UpdateOne(name string, driver utils.Driver, set map[string]interface{}, id string) interface{} {
return models.Model(name).GetAccessor(driver).UpdateOne(set, id)
func UpdateOne(name string, set map[string]interface{}, id string) interface{} {
return models.Model(name).GetAccessor().UpdateOne(set, id)
}
func DeleteOne(name string, driver utils.Driver, id string) interface{} {
return models.Model(name).GetAccessor(driver).DeleteOne(id)
func DeleteOne(name string, id string) interface{} {
return models.Model(name).GetAccessor().DeleteOne(id)
}
func StoreOne(name string, driver utils.Driver, object map[string]interface{}) interface{} {
func StoreOne(name string, object map[string]interface{}) interface{} {
model := models.Model(name)
return model.GetAccessor(driver).StoreOne(model.Deserialize(object))
return model.GetAccessor().StoreOne(model.Deserialize(object))
}

View File

@ -5,7 +5,6 @@ import (
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
tool "cloud.o-forge.io/core/oc-lib/utils"
)
type Data struct {
@ -28,14 +27,8 @@ func (d *Data) GetType() resources.ResourceType {
return resources.DATA
}
func (d *Data) GetAccessor(driver tool.Driver) utils.Accessor {
var data utils.Accessor
switch driver {
case tool.MONGO:
data = &DataMongoAccessor{}
default:
data = &DataMongoAccessor{}
}
func (d *Data) GetAccessor() utils.Accessor {
data := &DataMongoAccessor{}
data.SetLogger()
return data
}

View File

@ -1,9 +1,10 @@
package datacenter
import (
"encoding/json"
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
tool "cloud.o-forge.io/core/oc-lib/utils"
)
type Datacenter struct {
@ -36,18 +37,21 @@ type DatacenterGpuModel struct {
TensorCores uint `bson:"tensor_cores,omitempty" json:"tensor_cores,omitempty"`
}
func (dma *Datacenter) Deserialize(j map[string]interface{}) utils.DBObject {
b, err := json.Marshal(j)
if err != nil {
return nil
}
json.Unmarshal(b, dma)
return dma
}
func (d *Datacenter) GetType() resources.ResourceType {
return resources.DATACENTER
}
func (d *Datacenter) GetAccessor(driver tool.Driver) utils.Accessor {
var data utils.Accessor
switch driver {
case tool.MONGO:
data = &DatacenterMongoAccessor{}
default:
data = &DatacenterMongoAccessor{}
}
func (d *Datacenter) GetAccessor() utils.Accessor {
data := &DatacenterMongoAccessor{}
data.SetLogger()
return data
}

View File

@ -5,7 +5,6 @@ import (
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
tool "cloud.o-forge.io/core/oc-lib/utils"
)
type Processing struct {
@ -45,14 +44,8 @@ func (p *Processing) GetType() resources.ResourceType {
return resources.PROCESSING
}
func (d *Processing) GetAccessor(driver tool.Driver) utils.Accessor {
var data utils.Accessor
switch driver {
case tool.MONGO:
data = &ProcessingMongoAccessor{}
default:
data = &ProcessingMongoAccessor{}
}
func (d *Processing) GetAccessor() utils.Accessor {
data := &ProcessingMongoAccessor{}
data.SetLogger()
return data
}

View File

@ -5,7 +5,6 @@ import (
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
tool "cloud.o-forge.io/core/oc-lib/utils"
)
type URL struct {
@ -38,14 +37,8 @@ func (s *Storage) GetType() resources.ResourceType {
return resources.STORAGE
}
func (d *Storage) GetAccessor(driver tool.Driver) utils.Accessor {
var data utils.Accessor
switch driver {
case tool.MONGO:
data = &StorageMongoAccessor{}
default:
data = &StorageMongoAccessor{}
}
func (d *Storage) GetAccessor() utils.Accessor {
data := &StorageMongoAccessor{}
data.SetLogger()
return data
}

View File

@ -1,11 +1,9 @@
package utils
import "cloud.o-forge.io/core/oc-lib/utils"
type DBObject interface {
GetName() string
Deserialize(j map[string]interface{}) DBObject
GetAccessor(driver utils.Driver) Accessor
GetAccessor() Accessor
}
type Accessor interface {

View File

@ -10,7 +10,6 @@ import (
"cloud.o-forge.io/core/oc-lib/models/resources/storage"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/models/workflow/graph"
tool "cloud.o-forge.io/core/oc-lib/utils"
)
const WORKFLOW = "workflow"
@ -25,14 +24,8 @@ type Workflow struct {
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
}
func (d *Workflow) GetAccessor(driver tool.Driver) utils.Accessor {
var data utils.Accessor
switch driver {
case tool.MONGO:
data = &WorkflowMongoAccessor{}
default:
data = &WorkflowMongoAccessor{}
}
func (d *Workflow) GetAccessor() utils.Accessor {
data := &WorkflowMongoAccessor{}
data.SetLogger()
return data
}

View File

@ -1,8 +0,0 @@
package utils
type Driver int
const (
INVALID Driver = iota
MONGO
)