resource as resource named
This commit is contained in:
@@ -7,14 +7,14 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type Data struct {
|
||||
type DataResource struct {
|
||||
resources.AbstractResource
|
||||
Protocols []string `json:"protocol,omitempty" bson:"protocol,omitempty"` //TODO Enum type
|
||||
DataType string `json:"datatype" required:"true" bson:"datatype"`
|
||||
Example string `json:"example" bson:"example" required:"true" validate:"required" description:"base64 encoded data"`
|
||||
}
|
||||
|
||||
func (dma *Data) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *DataResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -23,7 +23,7 @@ func (dma *Data) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *Data) Serialize() map[string]interface{} {
|
||||
func (dma *DataResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
@@ -33,12 +33,8 @@ func (dma *Data) Serialize() map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *Data) GetType() resources.ResourceType {
|
||||
return resources.DATA
|
||||
}
|
||||
|
||||
func (d *Data) GetAccessor() utils.Accessor {
|
||||
func (d *DataResource) GetAccessor() utils.Accessor {
|
||||
data := &DataMongoAccessor{}
|
||||
data.SetLogger(resources.DATA)
|
||||
data.SetLogger(utils.DATACENTER_RESOURCE)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -18,20 +18,11 @@ func (dma *DataMongoAccessor) UpdateOne(set map[string]interface{}, id string) (
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
err := utils.Validate.Struct(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, err := mongo.MONGOService.StoreOne(data.(*Data), dma.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return dma.LoadOne(id)
|
||||
return dma.GenericStoreOne(data, dma)
|
||||
}
|
||||
|
||||
func (dma *DataMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
var data Data
|
||||
var data DataResource
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, dma.GetType())
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
|
||||
@@ -4,20 +4,20 @@ import (
|
||||
"testing"
|
||||
|
||||
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneData(t *testing.T) {
|
||||
d := Data{DataType: "jpeg", Example: "123456",
|
||||
d := DataResource{DataType: "jpeg", Example: "123456",
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,15 +28,14 @@ func TestStoreOneData(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadOneDate(t *testing.T) {
|
||||
d := Data{DataType: "jpeg", Example: "123456",
|
||||
d := DataResource{DataType: "jpeg", Example: "123456",
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type Datacenter struct {
|
||||
type DatacenterResource struct {
|
||||
resources.AbstractResource
|
||||
Owner string `bson:"owner" json:"owner" required:"true"`
|
||||
BookingPrice int `bson:"booking_price" json:"booking_price" required:"true"`
|
||||
@@ -37,7 +37,7 @@ type DatacenterGpuModel struct {
|
||||
TensorCores uint `bson:"tensor_cores,omitempty" json:"tensor_cores,omitempty"`
|
||||
}
|
||||
|
||||
func (dma *Datacenter) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *DatacenterResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -46,7 +46,7 @@ func (dma *Datacenter) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *Datacenter) Serialize() map[string]interface{} {
|
||||
func (dma *DatacenterResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
@@ -56,12 +56,8 @@ func (dma *Datacenter) Serialize() map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *Datacenter) GetType() resources.ResourceType {
|
||||
return resources.DATACENTER
|
||||
}
|
||||
|
||||
func (d *Datacenter) GetAccessor() utils.Accessor {
|
||||
func (d *DatacenterResource) GetAccessor() utils.Accessor {
|
||||
data := &DatacenterMongoAccessor{}
|
||||
data.SetLogger(resources.DATACENTER)
|
||||
data.SetLogger(utils.DATACENTER_RESOURCE)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -18,20 +18,11 @@ func (dca *DatacenterMongoAccessor) UpdateOne(set map[string]interface{}, id str
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
err := utils.Validate.Struct(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, err := mongo.MONGOService.StoreOne(data.(*Datacenter), dca.GetType())
|
||||
if err != nil {
|
||||
dca.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return dca.LoadOne(id)
|
||||
return dca.GenericStoreOne(data, dca)
|
||||
}
|
||||
|
||||
func (dca *DatacenterMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
var datacenter Datacenter
|
||||
var datacenter DatacenterResource
|
||||
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, dca.GetType())
|
||||
if err != nil {
|
||||
|
||||
@@ -4,20 +4,20 @@ import (
|
||||
"testing"
|
||||
|
||||
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneDatacenter(t *testing.T) {
|
||||
dc := Datacenter{Owner: "toto", BookingPrice: 123,
|
||||
dc := DatacenterResource{Owner: "toto", BookingPrice: 123,
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testDatacenter",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,15 +28,14 @@ func TestStoreOneDatacenter(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadOneDatacenter(t *testing.T) {
|
||||
dc := Datacenter{Owner: "toto", BookingPrice: 123,
|
||||
dc := DatacenterResource{Owner: "toto", BookingPrice: 123,
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testDatacenter",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testDatacenter"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type Processing struct {
|
||||
type ProcessingResource struct {
|
||||
resources.AbstractResource
|
||||
Container string `bson:"container,omitempty" json:"container,omitempty"` // We could create a specific class for container, that could check if the name exists/is available
|
||||
Repository string `bson:"repository,omitempty" json:"repository,omitempty"` // Indicate where to find the container image => Could add a struct handling authentication to the repo
|
||||
@@ -31,7 +31,7 @@ type ExecutionRequirementsModel struct {
|
||||
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"`
|
||||
}
|
||||
|
||||
func (dma *Processing) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *ProcessingResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -40,7 +40,7 @@ func (dma *Processing) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *Processing) Serialize() map[string]interface{} {
|
||||
func (dma *ProcessingResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
@@ -50,12 +50,8 @@ func (dma *Processing) Serialize() map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func (p *Processing) GetType() resources.ResourceType {
|
||||
return resources.PROCESSING
|
||||
}
|
||||
|
||||
func (d *Processing) GetAccessor() utils.Accessor {
|
||||
func (d *ProcessingResource) GetAccessor() utils.Accessor {
|
||||
data := &ProcessingMongoAccessor{}
|
||||
data.SetLogger(resources.PROCESSING)
|
||||
data.SetLogger(utils.PROCESSING_RESOURCE)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -18,21 +18,12 @@ func (pma *ProcessingMongoAccessor) UpdateOne(set map[string]interface{}, id str
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
err := utils.Validate.Struct(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, err := mongo.MONGOService.StoreOne(data.(*Processing), pma.GetType())
|
||||
if err != nil {
|
||||
pma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return pma.LoadOne(id)
|
||||
return pma.GenericStoreOne(data, pma)
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
|
||||
var processing Processing
|
||||
var processing ProcessingResource
|
||||
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, pma.GetType())
|
||||
if err != nil {
|
||||
|
||||
@@ -4,20 +4,20 @@ import (
|
||||
"testing"
|
||||
|
||||
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneProcessing(t *testing.T) {
|
||||
p := Processing{Container: "totoCont",
|
||||
p := ProcessingResource{Container: "totoCont",
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,15 +28,14 @@ func TestStoreOneProcessing(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadOneProcessing(t *testing.T) {
|
||||
p := Processing{Container: "totoCont",
|
||||
p := ProcessingResource{Container: "totoCont",
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -1,51 +1,21 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
// AbstractResource is the struct containing all of the attributes commons to all ressources
|
||||
|
||||
// Resource is the interface to be implemented by all classes inheriting from Resource to have the same behavior
|
||||
|
||||
//http://www.inanzzz.com/index.php/post/wqbs/a-basic-usage-of-int-and-string-enum-types-in-golang
|
||||
|
||||
type ResourceType int
|
||||
|
||||
const (
|
||||
INVALID ResourceType = iota
|
||||
DATA
|
||||
PROCESSING
|
||||
STORAGE
|
||||
DATACENTER
|
||||
WORKFLOW
|
||||
)
|
||||
|
||||
var str = [...]string{
|
||||
"invalid",
|
||||
"data",
|
||||
"processing",
|
||||
"storage",
|
||||
"datacenter",
|
||||
"workflow",
|
||||
}
|
||||
|
||||
func FromInt(i int) string {
|
||||
return str[i]
|
||||
}
|
||||
|
||||
func (d ResourceType) String() string {
|
||||
return str[d]
|
||||
}
|
||||
|
||||
// EnumIndex - Creating common behavior - give the type a EnumIndex functio
|
||||
func (d ResourceType) EnumIndex() int {
|
||||
return int(d)
|
||||
}
|
||||
|
||||
type Resource interface {
|
||||
GetType() ResourceType
|
||||
GetType() utils.DataType
|
||||
}
|
||||
|
||||
type AbstractResource struct {
|
||||
Uuid string `json:"uuid" required:"true" bson:"uuid" validate:"required"`
|
||||
Name string `json:"name" required:"true" bson:"name" validate:"required"`
|
||||
utils.AbstractObject
|
||||
ShortDescription string `json:"short_description" required:"true" bson:"short_description" validate:"required"`
|
||||
Description string `json:"description,omitempty" bson:"description"`
|
||||
Logo string `json:"logo" required:"true" bson:"logo" validate:"required"`
|
||||
@@ -55,7 +25,7 @@ type AbstractResource struct {
|
||||
}
|
||||
|
||||
func (r *AbstractResource) GetID() string {
|
||||
return r.Uuid
|
||||
return r.UUID
|
||||
}
|
||||
|
||||
func (r *AbstractResource) GetName() string {
|
||||
|
||||
@@ -12,7 +12,7 @@ type URL struct {
|
||||
Path string `bson:"path" json:"path"`
|
||||
}
|
||||
|
||||
type Storage struct {
|
||||
type StorageResource struct {
|
||||
resources.AbstractResource
|
||||
|
||||
Capacity uint `bson:"capacity,omitempty" json:"capacity,omitempty"`
|
||||
@@ -24,7 +24,7 @@ type Storage struct {
|
||||
BookingPrice uint `bson:"booking_price,omitempty" json:"booking_price,omitempty"`
|
||||
}
|
||||
|
||||
func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
func (dma *StorageResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
@@ -33,7 +33,7 @@ func (dma *Storage) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *Storage) Serialize() map[string]interface{} {
|
||||
func (dma *StorageResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
@@ -43,8 +43,8 @@ func (dma *Storage) Serialize() map[string]interface{} {
|
||||
return m
|
||||
}
|
||||
|
||||
func (d *Storage) GetAccessor() utils.Accessor {
|
||||
func (d *StorageResource) GetAccessor() utils.Accessor {
|
||||
data := &StorageMongoAccessor{}
|
||||
data.SetLogger(resources.STORAGE)
|
||||
data.SetLogger(utils.STORAGE_RESOURCE)
|
||||
return data
|
||||
}
|
||||
|
||||
@@ -18,21 +18,12 @@ func (sma *StorageMongoAccessor) UpdateOne(set map[string]interface{}, id string
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
err := utils.Validate.Struct(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, err := mongo.MONGOService.StoreOne(data.(*Storage), sma.GetType())
|
||||
if err != nil {
|
||||
sma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return sma.LoadOne(id)
|
||||
return sma.GenericStoreOne(data, sma)
|
||||
}
|
||||
|
||||
func (sma *StorageMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
|
||||
var storage Storage
|
||||
var storage StorageResource
|
||||
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, sma.GetType())
|
||||
if err != nil {
|
||||
|
||||
@@ -4,20 +4,20 @@ import (
|
||||
"testing"
|
||||
|
||||
resources "cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneStorage(t *testing.T) {
|
||||
s := Storage{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"},
|
||||
s := StorageResource{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"},
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -28,15 +28,14 @@ func TestStoreOneStorage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoadOneStorage(t *testing.T) {
|
||||
s := Storage{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"},
|
||||
s := StorageResource{Capacity: 123, Url: URL{Protocol: "http", Path: "azerty.fr"},
|
||||
AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
AbstractObject: utils.AbstractObject{Name: "testData"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -12,42 +12,17 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type Workflow struct {
|
||||
resources.AbstractResource
|
||||
Graph graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
|
||||
Datas map[string]data.Data `bson:"datas,omitempty" json:"datas,omitempty"`
|
||||
Storages map[string]storage.Storage `bson:"storages,omitempty" json:"storages,omitempty"`
|
||||
Processing map[string]processing.Processing `bson:"processing,omitempty" json:"processing,omitempty"`
|
||||
Datacenters map[string]datacenter.Datacenter `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
|
||||
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
|
||||
type AbstractWorkflow struct {
|
||||
Graph graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"`
|
||||
Datas map[string]data.DataResource `bson:"datas,omitempty" json:"datas,omitempty"`
|
||||
Storages map[string]storage.StorageResource `bson:"storages,omitempty" json:"storages,omitempty"`
|
||||
ProcessingResource map[string]processing.ProcessingResource `bson:"processing,omitempty" json:"processing,omitempty"`
|
||||
Datacenters map[string]datacenter.DatacenterResource `bson:"datacenters,omitempty" json:"datacenters,omitempty"`
|
||||
Workflows map[string]WorkflowResource `bson:"workflows,omitempty" json:"workflows,omitempty"`
|
||||
Schedule WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"`
|
||||
}
|
||||
|
||||
func (d *Workflow) GetAccessor() utils.Accessor {
|
||||
data := &WorkflowMongoAccessor{}
|
||||
data.SetLogger(resources.WORKFLOW)
|
||||
return data
|
||||
}
|
||||
|
||||
func (dma *Workflow) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(b, dma)
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *Workflow) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(b, dma)
|
||||
return m
|
||||
}
|
||||
|
||||
func (w *Workflow) isDCLink(link graph.GraphLink) bool {
|
||||
func (w *AbstractWorkflow) isDCLink(link graph.GraphLink) bool {
|
||||
if _, exists := w.Datacenters[link.Destination.ID]; exists {
|
||||
return true
|
||||
} else if _, exists := w.Datacenters[link.Source.ID]; exists {
|
||||
@@ -56,3 +31,34 @@ func (w *Workflow) isDCLink(link graph.GraphLink) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
type WorkflowResource struct {
|
||||
resources.AbstractResource
|
||||
AbstractWorkflow
|
||||
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"`
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) GetAccessor() utils.Accessor {
|
||||
data := &WorkflowResourceMongoAccessor{}
|
||||
data.SetLogger(utils.WORKFLOW_RESOURCE)
|
||||
return data
|
||||
}
|
||||
|
||||
func (dma *WorkflowResource) Deserialize(j map[string]interface{}) utils.DBObject {
|
||||
b, err := json.Marshal(j)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(b, dma)
|
||||
return dma
|
||||
}
|
||||
|
||||
func (dma *WorkflowResource) Serialize() map[string]interface{} {
|
||||
var m map[string]interface{}
|
||||
b, err := json.Marshal(dma)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
json.Unmarshal(b, dma)
|
||||
return m
|
||||
}
|
||||
|
||||
@@ -5,34 +5,24 @@ import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type WorkflowMongoAccessor struct {
|
||||
type WorkflowResourceMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) DeleteOne(id string) (utils.DBObject, error) {
|
||||
return wfa.GenericDeleteOne(id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
func (wfa *WorkflowResourceMongoAccessor) UpdateOne(set map[string]interface{}, id string) (utils.DBObject, error) {
|
||||
return wfa.GenericUpdateOne(set, id, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
err := utils.Validate.Struct(data)
|
||||
wfa.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
id, err := mongo.MONGOService.StoreOne(data.(*Workflow), wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return nil, err
|
||||
}
|
||||
return wfa.LoadOne(id)
|
||||
func (wfa *WorkflowResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, error) {
|
||||
return wfa.GenericStoreOne(data, wfa)
|
||||
}
|
||||
|
||||
func (wfa *WorkflowMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
var workflow Workflow
|
||||
func (wfa *WorkflowResourceMongoAccessor) LoadOne(id string) (utils.DBObject, error) {
|
||||
var workflow WorkflowResource
|
||||
res_mongo, err := mongo.MONGOService.LoadOne(id, wfa.GetType())
|
||||
if err != nil {
|
||||
wfa.Logger.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
|
||||
@@ -4,41 +4,40 @@ import (
|
||||
"testing"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneWorkflow(t *testing.T) {
|
||||
w := Workflow{AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testWorkflow",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
w := WorkflowResource{AbstractResource: resources.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
wma := WorkflowMongoAccessor{}
|
||||
wma := WorkflowResourceMongoAccessor{}
|
||||
id, _ := wma.StoreOne(&w)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
|
||||
func TestLoadOneWorkflow(t *testing.T) {
|
||||
w := Workflow{AbstractResource: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testWorkflow",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
w := WorkflowResource{AbstractResource: resources.AbstractResource{
|
||||
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
wma := WorkflowMongoAccessor{}
|
||||
wma := WorkflowResourceMongoAccessor{}
|
||||
new_w, _ := wma.StoreOne(&w)
|
||||
assert.Equal(t, w, new_w)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user