organize + graph
This commit is contained in:
46
models/resources/processing/processing.go
Normal file
46
models/resources/processing/processing.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
resources "oc-lib/models/resources"
|
||||
"oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type Processing 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
|
||||
Command string `bson:"command,omitempty" json:"command,omitempty"`
|
||||
Arguments []string `bson:"arguments,omitempty" json:"arguments,omitempty"`
|
||||
Environment []map[string]string `bson:"environment,omitempty" json:"environment,omitempty"` // a key/value struct is what ressembles the most a NAME=VALUE struct
|
||||
|
||||
ExecutionRequirements ExecutionRequirementsModel `json:"execution_requirements,omitempty"`
|
||||
|
||||
Price uint `bson:"price,omitempty" json:"price,omitempty"`
|
||||
License string `bson:"license,omitempty" json:"license,omitempty"`
|
||||
}
|
||||
|
||||
type ExecutionRequirementsModel struct {
|
||||
CPUs uint `bson:"cp_us,omitempty" json:"cp_us,omitempty"`
|
||||
GPUs uint `bson:"gp_us,omitempty" json:"gp_us,omitempty"`
|
||||
RAM uint `bson:"ram,omitempty" json:"ram,omitempty"`
|
||||
|
||||
Parallel bool `bson:"parallel,omitempty" json:"parallel,omitempty"`
|
||||
ScalingModel uint `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"`
|
||||
DiskIO string `bson:"disk_io,omitempty" json:"disk_io,omitempty"`
|
||||
}
|
||||
|
||||
func (p *Processing) GetType() resources.ResourceType {
|
||||
return resources.PROCESSING
|
||||
}
|
||||
|
||||
func (d *Processing) GetAccessor(driver utils.Driver) utils.Accessor {
|
||||
var data utils.Accessor
|
||||
switch driver {
|
||||
case utils.MONGO:
|
||||
data = &ProcessingMongoAccessor{}
|
||||
default:
|
||||
data = &ProcessingMongoAccessor{}
|
||||
}
|
||||
data.SetLogger()
|
||||
return data
|
||||
}
|
44
models/resources/processing/processing_mongo_accessor.go
Normal file
44
models/resources/processing/processing_mongo_accessor.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
"oc-lib/dbs/mongo"
|
||||
"oc-lib/logs"
|
||||
"oc-lib/models/utils"
|
||||
)
|
||||
|
||||
type ProcessingMongoAccessor struct {
|
||||
utils.AbstractAccessor
|
||||
}
|
||||
|
||||
func (dma *ProcessingMongoAccessor) DeleteOne(id string) utils.DBObject {
|
||||
return dma.GenericDeleteOne(id, dma)
|
||||
}
|
||||
|
||||
func (dma *ProcessingMongoAccessor) UpdateOne(set map[string]interface{}, id string) utils.DBObject {
|
||||
return dma.GenericUpdateOne(set, id, dma)
|
||||
}
|
||||
|
||||
func (dma *ProcessingMongoAccessor) StoreOne(data utils.DBObject) utils.DBObject {
|
||||
id, err := mongo.StoreOne(data.(*Processing), "data")
|
||||
if err != nil {
|
||||
dma.Logger.Error().Msg("Could not store " + data.GetName() + " to db. Error: " + err.Error())
|
||||
return &Processing{}
|
||||
}
|
||||
return dma.LoadOne(id)
|
||||
}
|
||||
|
||||
func (pma *ProcessingMongoAccessor) LoadOne(id string) utils.DBObject {
|
||||
|
||||
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
|
||||
}
|
45
models/resources/processing/processing_test.go
Normal file
45
models/resources/processing/processing_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package processing
|
||||
|
||||
import (
|
||||
resources "oc-lib/models/resources"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStoreOneProcessing(t *testing.T) {
|
||||
p := Processing{Container: "totoCont",
|
||||
AbstractResource: resources.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: resources.AbstractResource{
|
||||
Uuid: "123",
|
||||
Name: "testData",
|
||||
Description: "Lorem Ipsum",
|
||||
Logo: "azerty.com",
|
||||
Owner: "toto",
|
||||
OwnerLogo: "totoLogo",
|
||||
SourceUrl: "azerty.fr",
|
||||
},
|
||||
}
|
||||
|
||||
sma := ProcessingMongoAccessor{}
|
||||
new_s := sma.StoreOne(&p)
|
||||
assert.Equal(t, p, new_s)
|
||||
}
|
Reference in New Issue
Block a user