resource as resource named
This commit is contained in:
@@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user