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" "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 ( const (
WORKFLOW LibData = 5 MONGO = utils.MONGO
) )
func Init() { func Init() {
mongo.MONGOService.Init(models.GetModelsNames(), GetConfig()) mongo.MONGOService.Init(models.GetModelsNames(), GetConfig())
} }
func LoadOne(name string, driver utils.Driver, id string) interface{} { func LoadOne(name string, id string) interface{} {
return models.Model(name).GetAccessor(driver).LoadOne(id) return models.Model(name).GetAccessor().LoadOne(id)
} }
func UpdateOne(name string, driver utils.Driver, set map[string]interface{}, id string) interface{} { func UpdateOne(name string, set map[string]interface{}, id string) interface{} {
return models.Model(name).GetAccessor(driver).UpdateOne(set, id) return models.Model(name).GetAccessor().UpdateOne(set, id)
} }
func DeleteOne(name string, driver utils.Driver, id string) interface{} { func DeleteOne(name string, id string) interface{} {
return models.Model(name).GetAccessor(driver).DeleteOne(id) 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) 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" resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/models/utils"
tool "cloud.o-forge.io/core/oc-lib/utils"
) )
type Data struct { type Data struct {
@ -28,14 +27,8 @@ func (d *Data) GetType() resources.ResourceType {
return resources.DATA return resources.DATA
} }
func (d *Data) GetAccessor(driver tool.Driver) utils.Accessor { func (d *Data) GetAccessor() utils.Accessor {
var data utils.Accessor data := &DataMongoAccessor{}
switch driver {
case tool.MONGO:
data = &DataMongoAccessor{}
default:
data = &DataMongoAccessor{}
}
data.SetLogger() data.SetLogger()
return data return data
} }

View File

@ -1,9 +1,10 @@
package datacenter package datacenter
import ( import (
"encoding/json"
resources "cloud.o-forge.io/core/oc-lib/models/resources" resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/models/utils"
tool "cloud.o-forge.io/core/oc-lib/utils"
) )
type Datacenter struct { type Datacenter struct {
@ -36,18 +37,21 @@ type DatacenterGpuModel struct {
TensorCores uint `bson:"tensor_cores,omitempty" json:"tensor_cores,omitempty"` 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 { func (d *Datacenter) GetType() resources.ResourceType {
return resources.DATACENTER return resources.DATACENTER
} }
func (d *Datacenter) GetAccessor(driver tool.Driver) utils.Accessor { func (d *Datacenter) GetAccessor() utils.Accessor {
var data utils.Accessor data := &DatacenterMongoAccessor{}
switch driver {
case tool.MONGO:
data = &DatacenterMongoAccessor{}
default:
data = &DatacenterMongoAccessor{}
}
data.SetLogger() data.SetLogger()
return data return data
} }

View File

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

View File

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

View File

@ -1,11 +1,9 @@
package utils package utils
import "cloud.o-forge.io/core/oc-lib/utils"
type DBObject interface { type DBObject interface {
GetName() string GetName() string
Deserialize(j map[string]interface{}) DBObject Deserialize(j map[string]interface{}) DBObject
GetAccessor(driver utils.Driver) Accessor GetAccessor() Accessor
} }
type Accessor interface { 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/resources/storage"
"cloud.o-forge.io/core/oc-lib/models/utils" "cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/models/workflow/graph" "cloud.o-forge.io/core/oc-lib/models/workflow/graph"
tool "cloud.o-forge.io/core/oc-lib/utils"
) )
const WORKFLOW = "workflow" const WORKFLOW = "workflow"
@ -25,14 +24,8 @@ type Workflow struct {
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"` Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
} }
func (d *Workflow) GetAccessor(driver tool.Driver) utils.Accessor { func (d *Workflow) GetAccessor() utils.Accessor {
var data utils.Accessor data := &WorkflowMongoAccessor{}
switch driver {
case tool.MONGO:
data = &WorkflowMongoAccessor{}
default:
data = &WorkflowMongoAccessor{}
}
data.SetLogger() data.SetLogger()
return data return data
} }

View File

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