initial commit
This commit is contained in:
164
models/computing.go
Normal file
164
models/computing.go
Normal file
@@ -0,0 +1,164 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-catalog/models/rtype"
|
||||
"cloud.o-forge.io/core/oc-catalog/services"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type ExecutionRequirementsModel struct {
|
||||
CPUs uint `json:"cpus" required:"true"`
|
||||
GPUs uint `json:"gpus" description:"Amount of GPUs needed"`
|
||||
RAM uint `json:"ram" required:"true" description:"Units in MB"`
|
||||
|
||||
// We should check closely how to deal with storage, since they are independent models
|
||||
// but also part of a DataCenter
|
||||
// Storage uint `json:"storage" description:"Units in MB"`
|
||||
|
||||
Parallel bool `json:"parallel"`
|
||||
ScalingModel uint `json:"scaling_model"`
|
||||
DiskIO string `json:"disk_io"`
|
||||
}
|
||||
|
||||
type RepositoryModel struct {
|
||||
Credentials string `json:"credentials"`
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
type ComputingNEWModel struct {
|
||||
Description string `json:"description" required:"true"`
|
||||
Name string `json:"name,omitempty" required:"true" validate:"required" description:"Name of the computing"`
|
||||
ShortDescription string `json:"short_description" required:"true" validate:"required"`
|
||||
Logo string `json:"logo" required:"true" validate:"required"`
|
||||
|
||||
Type string `json:"type,omitempty" required:"true"`
|
||||
Owner string `json:"owner"`
|
||||
License string `json:"license"`
|
||||
Price uint `json:"price"`
|
||||
|
||||
ExecutionRequirements ExecutionRequirementsModel `json:"execution_requirements"`
|
||||
|
||||
Dinputs []string
|
||||
Doutputs []string
|
||||
|
||||
Repository RepositoryModel `json:"repository"`
|
||||
}
|
||||
|
||||
type ComputingModel struct {
|
||||
ID string `json:"ID" bson:"_id" required:"true" example:"5099803df3f4948bd2f98391"`
|
||||
ComputingNEWModel `bson:",inline"`
|
||||
}
|
||||
|
||||
func (model ComputingModel) getRtype() rtype.Rtype {
|
||||
return rtype.COMPUTING
|
||||
}
|
||||
|
||||
func (model ComputingModel) getName() string {
|
||||
return model.Name
|
||||
}
|
||||
|
||||
// A user can have multiple workload project with the same model. We must distinguish what is
|
||||
// the model and what is the user object
|
||||
|
||||
type ComputingObject struct {
|
||||
ReferenceID primitive.ObjectID `json:"referenceID" description:"Computing model ID"`
|
||||
|
||||
Inputs []string `json:"inputs"`
|
||||
Outputs []string `json:"outputs"`
|
||||
|
||||
DataCenterID string `json:"datacenterID" description:"Datacenter where the computing will be executed"`
|
||||
}
|
||||
|
||||
func (obj ComputingObject) getHost() *string {
|
||||
return nil // Host is DC only attribute
|
||||
}
|
||||
|
||||
func (obj *ComputingObject) setReference(rID primitive.ObjectID) {
|
||||
obj.ReferenceID = rID
|
||||
}
|
||||
|
||||
func (obj ComputingObject) getReference() primitive.ObjectID {
|
||||
return obj.ReferenceID
|
||||
}
|
||||
|
||||
func (obj ComputingObject) getRtype() rtype.Rtype {
|
||||
return rtype.COMPUTING
|
||||
}
|
||||
|
||||
func (obj ComputingObject) getModel() (ret ResourceModel, err error) {
|
||||
var ret2 ComputingModel
|
||||
res := services.MngoCollComputing.FindOne(services.MngoCtx,
|
||||
primitive.M{"_id": obj.ReferenceID},
|
||||
)
|
||||
|
||||
if err = res.Err(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = res.Decode(&ret2)
|
||||
return ret2, err
|
||||
}
|
||||
|
||||
func (obj ComputingObject) getName() (name *string) {
|
||||
|
||||
aa, err := obj.getModel()
|
||||
|
||||
if err != nil {
|
||||
logs.Warn(err)
|
||||
return
|
||||
}
|
||||
|
||||
name2 := aa.getName()
|
||||
|
||||
return &name2
|
||||
}
|
||||
|
||||
func (obj ComputingObject) isLinked(rObjID string) LinkingState {
|
||||
if contains(obj.Inputs, rObjID) {
|
||||
return INPUT
|
||||
}
|
||||
|
||||
if contains(obj.Outputs, rObjID) {
|
||||
return OUTPUT
|
||||
}
|
||||
|
||||
return NO_LINK
|
||||
}
|
||||
|
||||
func (obj *ComputingObject) addLink(direction LinkingState, rID string) {
|
||||
switch direction {
|
||||
case INPUT:
|
||||
obj.Inputs = append(obj.Inputs, rID)
|
||||
case OUTPUT:
|
||||
obj.Outputs = append(obj.Outputs, rID)
|
||||
}
|
||||
}
|
||||
|
||||
func GetOneComputing(ID string) (object *ComputingModel, err error) {
|
||||
obj, err := getOneResourceByID(ID, rtype.COMPUTING)
|
||||
|
||||
if err != nil {
|
||||
return object, err
|
||||
}
|
||||
|
||||
object = obj.(*ComputingModel)
|
||||
|
||||
return object, err
|
||||
}
|
||||
|
||||
func GetMultipleComputing(IDs []string) (object *[]ComputingModel, err error) {
|
||||
objArray, err := getMultipleResourceByIDs(IDs, rtype.COMPUTING)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
object = objArray.(*[]ComputingModel)
|
||||
|
||||
return object, err
|
||||
}
|
||||
|
||||
func PostOneComputing(obj ComputingNEWModel) (ID string, err error) {
|
||||
return postOneResource(obj, rtype.COMPUTING)
|
||||
}
|
||||
Reference in New Issue
Block a user