Improved models' structure

This commit is contained in:
pb 2024-07-17 17:17:37 +02:00
parent f0eec45836
commit 3732187678
6 changed files with 69 additions and 65 deletions

10
data.go
View File

@ -1,11 +1,12 @@
package oclib
type Data struct {
AbstractResource
Protocols []string `json:"protocol"` //TODO Enum type
DataType string `json:"datatype"`
Example string `json:"example" required:"true" validate:"required" description:"base64 encoded data"`
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"`
}
@ -14,3 +15,6 @@ func (d *Data) GetType() ResourceType{
return DATA
}

View File

@ -1,36 +1,34 @@
package oclib
type Datacenter struct {
Resource
ID string `json:"ID", required: "true"`
Name string `json:"Name", required: "true" `
AbstractResource `json:"resource" required:"true"`
Owner string `json:"owner" `
BookingPrice int `json:"bookingPrice" `
Owner string `json:"owner" required:"true"`
BookingPrice int `json:"booking_price" required:"true"`
CPU DatacenterCpuModel `json:"cpu" required:"true"`
RAM DatacenterMemoryModel `json:"ram" required:"true"`
GPU []DatacenterGpuModel `json:"gpu" required:"true"`
CPU DatacenterCpuModel `json:"cpu,omitempty"`
RAM DatacenterMemoryModel `json:"ram,omitempty"`
GPU []DatacenterGpuModel `json:"gpu,omitempty"`
}
type DatacenterCpuModel struct {
Cores uint `json:"cores" required:"true"` //TODO: validate
Architecture string `json:"architecture"` //TOOD: enum
Shared bool `json:"shared"`
MinimumMemory uint `json:"minimum_memory"`
Platform string `json:"platform"`
Cores uint `json:"cores,omitempty"` //TODO: validate
Architecture string `json:"architecture,omitempty"` //TOOD: enum
Shared bool `json:"shared,omitempty"`
MinimumMemory uint `json:"minimum_memory,omitempty"`
Platform string `json:"platform,omitempty"`
}
type DatacenterMemoryModel struct {
Size uint `json:"size" description:"Units in MB"`
Ecc bool `json:"ecc"`
Size uint `json:"size,omitempty" description:"Units in MB"`
Ecc bool `json:"ecc,omitempty"`
}
type DatacenterGpuModel struct {
CudaCores uint `json:"cuda_cores"`
Model string `json:"model"`
Memory uint `json:"memory" description:"Units in MB"`
TensorCores uint `json:"tensor_cores"`
CudaCores uint `json:"cuda_cores,omitempty"`
Model string `json:"model,omitempty"`
Memory uint `json:"memory,omitempty" description:"Units in MB"`
TensorCores uint `json:"tensor_cores,omitempty"`
}

View File

@ -1,28 +1,28 @@
package oclib
type Processing struct {
Resource
Container string `json:"Container"` // We could create a specific class for container, that could check if the name exists/is available
Repository string `json:"Repository"` // Indicate where to find the container image => Could add a struct handling authentication to the repo
Command string `json:"Command"`
Arguments []string `json:"Arguments"`
Environment []map[string]string `json:"Environment"` // a key/value struct is what ressembles the most a NAME=VALUE struct
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:"ExecutionRequirements"`
ExecutionRequirements ExecutionRequirementsModel `json:"execution_requirements,omitempty"`
Price uint `json:"Price"`
License string `json:"License"`
Price uint `json:"price,omitempty"`
License string `json:"license,omitempty"`
}
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"`
CPUs uint `json:"cp_us,omitempty"`
GPUs uint `json:"gp_us,omitempty"`
RAM uint `json:"ram,omitempty"`
Parallel bool `json:"parallel"`
ScalingModel uint `json:"scaling_model"`
DiskIO string `json:"disk_io"`
Parallel bool `json:"parallel,omitempty"`
ScalingModel uint `json:"scaling_model,omitempty"`
DiskIO string `json:"disk_io,omitempty"`
}
func (p *Processing) GetType() ResourceType{

View File

@ -34,19 +34,20 @@ var extensions = [...]string{
type Resource interface{
GetType() ResourceType
getOneResourceByID() Resource
StoreOne() Resource
}
type AbstractResource struct {
Uuid string `json:"Id" required:"true" `
Name string `json:"Name" required:"true" `
ShortDescription string
Description string
Logo string
Owner string
OwnerLogo string
SourceUrl string
Uuid string `json:"uuid" required:"true" bson:"uuid"`
Name string `json:"name" required:"true" bson:"name"`
ShortDescription string `json:"short_description" required:"true" bson:"short_description"`
Description string `json:"description,omitempty" bson:"description"`
Logo string `json:"logo" required:"true" bson:"logo"`
Owner string `json:"owner" required:"true" bson:"owner"`
OwnerLogo string `json:"owner_logo" required:"true" bson:"owner_logo"`
SourceUrl string `json:"source_url" required:"true" bson:"source_url"`
Graphic GraphicElement `json:"GraphicElement" `
Graphic GraphicElement `json:"graphic,omitempty" bson:"protocol"`
}
@ -92,3 +93,4 @@ func (r *AbstractResource) isLinked(){
// func (r *Resource) GetType() ResourceType {
// return INVALID
// }

View File

@ -6,17 +6,17 @@ type URL struct {
}
type Storage struct {
Resource `json:"resource" required:"true"`
AbstractResource `json:"resource" required:"true" bson:"resource"`
Capacity uint `json:"capacity" required:"true"`
Url URL `json:"URL" ` // Will allow to select between several protocols
Capacity uint `json:"capacity,omitempty"`
Url URL `json:"url,omitempty"` // Will allow to select between several protocols
Encryption bool `json:"encryption" `
Redundancy string `json:"redundancy" `
Throughput string `json:"throughput" `
BookingPrice uint `json:"bookingPrice" `
Encryption bool `json:"encryption,omitempty"`
Redundancy string `json:"redundancy,omitempty"`
Throughput string `json:"throughput,omitempty"`
BookingPrice uint `json:"booking_price,omitempty"`
}
func (s *Storage) GetType() ResourceType{
func (s *Storage) GetType() ResourceType {
return STORAGE
}

View File

@ -1,14 +1,14 @@
package oclib
type Workflow struct{
Resource
Datas map[string]Data
Storages map[string]Storage
Processing map[string]Processing
Datacenters map[string]Datacenter
Links map[string]Link
type Workflow struct {
AbstractResource `json:"abstract_resource" required:"true"`
Datas map[string]Data `json:"datas,omitempty"`
Storages map[string]Storage `json:"storages,omitempty"`
Processing map[string]Processing `json:"processing,omitempty"`
Datacenters map[string]Datacenter `json:"datacenters,omitempty"`
Links map[string]Link `json:"links,omitempty"`
Schedule WorkflowSchedule
Schedule WorkflowSchedule `json:"schedule,omitempty"`
}
func (w *Workflow) isDCLink(link Link) bool {