2024-07-18 11:51:12 +02:00
package processing
import (
2024-07-18 14:39:54 +02:00
"encoding/json"
2024-07-18 13:35:14 +02:00
resources "cloud.o-forge.io/core/oc-lib/models/resources"
"cloud.o-forge.io/core/oc-lib/models/utils"
2024-07-18 11:51:12 +02:00
)
2024-07-19 10:54:58 +02:00
type ProcessingResource struct {
2024-07-18 11:51:12 +02:00
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" `
}
2024-07-19 10:54:58 +02:00
func ( dma * ProcessingResource ) Deserialize ( j map [ string ] interface { } ) utils . DBObject {
2024-07-18 14:39:54 +02:00
b , err := json . Marshal ( j )
if err != nil {
return nil
}
json . Unmarshal ( b , dma )
2024-07-19 13:15:51 +02:00
dma . AbstractResource . ObjDeserialize ( j )
2024-07-18 14:39:54 +02:00
return dma
}
2024-07-19 10:54:58 +02:00
func ( dma * ProcessingResource ) Serialize ( ) map [ string ] interface { } {
2024-07-19 09:32:58 +02:00
var m map [ string ] interface { }
b , err := json . Marshal ( dma )
if err != nil {
return nil
}
json . Unmarshal ( b , dma )
2024-07-19 13:15:51 +02:00
dma . AbstractResource . ObjSerialize ( )
2024-07-19 09:32:58 +02:00
return m
}
2024-07-19 10:54:58 +02:00
func ( d * ProcessingResource ) GetAccessor ( ) utils . Accessor {
2024-07-18 15:02:39 +02:00
data := & ProcessingMongoAccessor { }
2024-07-19 10:54:58 +02:00
data . SetLogger ( utils . PROCESSING_RESOURCE )
2024-07-18 11:51:12 +02:00
return data
}