test copy
This commit is contained in:
parent
3f9814e649
commit
e89b5aae84
@ -30,10 +30,6 @@ type LibData struct {
|
||||
Err string `bson:"error" json:"error"`
|
||||
}
|
||||
|
||||
func (lb LibData) BindID(id string) {
|
||||
lb.DataResource.BindID(id)
|
||||
}
|
||||
|
||||
func Init(appName string) {
|
||||
logs.SetAppName(appName)
|
||||
logs.SetLogger(logs.CreateLogger("main", ""))
|
||||
@ -61,6 +57,12 @@ func DeleteOne(collection LibDataEnum, id string) LibData {
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func CopyOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor().CopyOne(model.Deserialize(object))
|
||||
return LibData{DataResource: d, Code: code, Err: err.Error()}
|
||||
}
|
||||
|
||||
func StoreOne(collection LibDataEnum, object map[string]interface{}) LibData {
|
||||
model := models.Model(collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor().StoreOne(model.Deserialize(object))
|
||||
|
@ -14,8 +14,6 @@ type DataResource struct {
|
||||
Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"`
|
||||
}
|
||||
|
||||
func (d *DataResource) BindID(id string) {}
|
||||
|
||||
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,10 @@ func (dma *DataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int
|
||||
return dma.GenericStoreOne(data, dma)
|
||||
}
|
||||
|
||||
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) {
|
||||
var data DataResource
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, dma.GetType())
|
||||
|
@ -37,8 +37,6 @@ type DatacenterGpuModel struct {
|
||||
TensorCores uint `bson:"tensor_cores,omitempty" json:"tensor_cores,omitempty"`
|
||||
}
|
||||
|
||||
func (d *DatacenterResource) BindID(id string) {}
|
||||
|
||||
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,10 @@ func (dca *DatacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObjec
|
||||
return dca.GenericStoreOne(data, dca)
|
||||
}
|
||||
|
||||
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) {
|
||||
var datacenter DatacenterResource
|
||||
|
||||
|
@ -31,8 +31,6 @@ type ExecutionRequirementsModel struct {
|
||||
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"`
|
||||
}
|
||||
|
||||
func (d *ProcessingResource) BindID(id string) {}
|
||||
|
||||
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,10 @@ func (pma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObjec
|
||||
return pma.GenericStoreOne(data, pma)
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
var processing ProcessingResource
|
||||
|
@ -24,8 +24,6 @@ type StorageResource struct {
|
||||
BookingPrice uint `bson:"booking_price,omitempty" json:"booking_price,omitempty"`
|
||||
}
|
||||
|
||||
func (d *StorageResource) BindID(id string) {}
|
||||
|
||||
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
|
@ -21,6 +21,10 @@ func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
|
||||
return sma.GenericStoreOne(data, sma)
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
var storage StorageResource
|
||||
|
@ -57,8 +57,6 @@ type WorkflowResource struct {
|
||||
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"`
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) BindID(id string) { d.WorkflowID = id }
|
||||
|
||||
func (d *WorkflowResource) GetAccessor() utils.Accessor {
|
||||
data := &WorkflowResourceMongoAccessor{}
|
||||
data.SetLogger(utils.WORKFLOW_RESOURCE)
|
||||
|
@ -21,6 +21,17 @@ func (wfa *WorkflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.D
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
res, _, _ := wfa.LoadOne(data.GetID())
|
||||
data.(*WorkflowResource).WorkflowID = data.GetID()
|
||||
if res == nil {
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
} else {
|
||||
data.(*WorkflowResource).UUID = res.GetID()
|
||||
return wfa.GenericUpdateOne(data.Serialize(), res.GetID(), wfa)
|
||||
}
|
||||
}
|
||||
|
||||
func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
var workflow WorkflowResource
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
|
@ -3,7 +3,6 @@ package utils
|
||||
type DBObject interface {
|
||||
GenerateID()
|
||||
GetID() string
|
||||
BindID(id string)
|
||||
GetName() string
|
||||
Deserialize(j map[string]interface{}) DBObject
|
||||
Serialize() map[string]interface{}
|
||||
@ -15,6 +14,7 @@ type Accessor interface {
|
||||
GetType() string
|
||||
LoadOne(id string) (DBObject, int, error)
|
||||
DeleteOne(id string) (DBObject, int, error)
|
||||
CopyOne(data DBObject) (DBObject, int, error)
|
||||
StoreOne(data DBObject) (DBObject, int, error)
|
||||
UpdateOne(set map[string]interface{}, id string) (DBObject, int, error)
|
||||
}
|
||||
|
@ -13,8 +13,6 @@ type Workflow struct {
|
||||
w.AbstractWorkflow
|
||||
}
|
||||
|
||||
func (d *Workflow) BindID(id string) {}
|
||||
|
||||
func (d *Workflow) GetName() string {
|
||||
return d.Name
|
||||
}
|
||||
|
@ -21,6 +21,10 @@ func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject,
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
}
|
||||
|
||||
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) {
|
||||
var workflow Workflow
|
||||
res_mongo, code, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
|
Loading…
Reference in New Issue
Block a user