packaged every model
This commit is contained in:
32
processing/processing.go
Normal file
32
processing/processing.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package processing
|
||||
|
||||
import oclib "oc-lib"
|
||||
|
||||
type Processing struct {
|
||||
oclib.AbstractResource `json:"resource" required:"true"`
|
||||
Container string `json:"container,omitempty"` // We could create a specific class for container, that could check if the name exists/is available
|
||||
Repository string `json:"repository,omitempty"` // Indicate where to find the container image => Could add a struct handling authentication to the repo
|
||||
Command string `json:"command,omitempty"`
|
||||
Arguments []string `json:"arguments,omitempty"`
|
||||
Environment []map[string]string `json:"environment,omitempty"` // a key/value struct is what ressembles the most a NAME=VALUE struct
|
||||
|
||||
ExecutionRequirements ExecutionRequirementsModel `json:"execution_requirements,omitempty"`
|
||||
|
||||
Price uint `json:"price,omitempty"`
|
||||
License string `json:"license,omitempty"`
|
||||
|
||||
}
|
||||
|
||||
type ExecutionRequirementsModel struct {
|
||||
CPUs uint `json:"cp_us,omitempty"`
|
||||
GPUs uint `json:"gp_us,omitempty"`
|
||||
RAM uint `json:"ram,omitempty"`
|
||||
|
||||
Parallel bool `json:"parallel,omitempty"`
|
||||
ScalingModel uint `json:"scaling_model,omitempty"`
|
||||
DiskIO string `json:"disk_io,omitempty"`
|
||||
}
|
||||
|
||||
func (p *Processing) GetType() oclib.ResourceType{
|
||||
return oclib.PROCESSING
|
||||
}
|
||||
38
processing/processing_mongo_accessor.go
Normal file
38
processing/processing_mongo_accessor.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"oc-lib/logs"
|
||||
"oc-lib/mongo"
|
||||
)
|
||||
|
||||
type ProcessingMongoAccessor struct{
|
||||
|
||||
}
|
||||
|
||||
|
||||
func (pma *ProcessingMongoAccessor) StoreOne(processing Processing) string {
|
||||
|
||||
id, err := mongo.StoreOne(processing,"processing")
|
||||
if err != nil{
|
||||
l := logs.CreateLogger("oclib","")
|
||||
l.Error().Msg("Could not store " + processing.Name + " to db. Error: " + err.Error())
|
||||
return ""
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) LoadOne(id string) Processing {
|
||||
|
||||
var processing Processing
|
||||
|
||||
res_mongo, err := mongo.LoadOne(id,"processing")
|
||||
if err != nil{
|
||||
l := logs.CreateLogger("oclib","")
|
||||
l.Error().Msg("Could not retrieve " + id + " from db. Error: " + err.Error())
|
||||
return Processing{}
|
||||
}
|
||||
|
||||
res_mongo.Decode(&processing)
|
||||
|
||||
return processing
|
||||
}
|
||||
48
processing/processing_test.go
Normal file
48
processing/processing_test.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
oclib "oc-lib"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneProcessing(t *testing.T){
|
||||
p := Processing{ Container: "totoCont",
|
||||
AbstractResource: oclib.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo : "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
sma := ProcessingMongoAccessor{}
|
||||
id := sma.StoreOne(p)
|
||||
|
||||
assert.NotEmpty(t, id)
|
||||
}
|
||||
|
||||
func TestLoadOneProcessing(t *testing.T){
|
||||
p := Processing{ Container: "totoCont",
|
||||
AbstractResource: oclib.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo : "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
sma := ProcessingMongoAccessor{}
|
||||
id := sma.StoreOne(p)
|
||||
new_s := sma.LoadOne(id)
|
||||
|
||||
assert.Equal(t,p, new_s)
|
||||
}
|
||||
Reference in New Issue
Block a user