2024-11-28 16:49:41 +01:00
package resources
import (
2024-12-12 16:25:47 +01:00
"time"
"cloud.o-forge.io/core/oc-lib/models/common"
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
2024-11-28 16:49:41 +01:00
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
2024-12-12 16:25:47 +01:00
type ProcessingUsage struct {
CPUs map [ string ] * common . CPU ` bson:"cpus,omitempty" json:"cpus,omitempty" ` // CPUs is the list of CPUs key is model
GPUs map [ string ] * common . GPU ` bson:"gpus,omitempty" json:"gpus,omitempty" ` // GPUs is the list of GPUs key is model
RAM * common . RAM ` bson:"ram,omitempty" json:"ram,omitempty" ` // RAM is the RAM
StorageGb float64 ` bson:"storage,omitempty" json:"storage,omitempty" ` // Storage is the storage
Hypothesis string ` bson:"hypothesis,omitempty" json:"hypothesis,omitempty" `
ScalingModel string ` bson:"scaling_model,omitempty" json:"scaling_model,omitempty" ` // ScalingModel is the scaling model
2024-11-28 16:49:41 +01:00
}
2024-12-12 16:25:47 +01:00
type abstractProcessingResource struct {
Infrastructure common . InfrastructureType ` json:"infrastructure,omitempty" bson:"infrastructure,omitempty" `
Service bool ` json:"is_service,omitempty" bson:"is_service,omitempty" ` // IsService is a flag that indicates if the processing is a service
Usage * ProcessingUsage ` bson:"usage,omitempty" json:"usage,omitempty" ` // Usage is the usage of the processing
2024-11-28 16:49:41 +01:00
}
/ *
* ProcessingResource is a struct that represents a processing resource
* it defines the resource processing
* /
type ProcessingResource struct {
2024-12-12 16:25:47 +01:00
AbstractResource [ * ResourceInstance [ * ResourcePartnerShip [ * ProcessingResourcePricingProfile ] ] ]
abstractProcessingResource
OpenSource bool ` json:"open_source" bson:"open_source" default:"false" `
License string ` json:"license,omitempty" bson:"license,omitempty" `
Maturity string ` json:"maturity,omitempty" bson:"maturity,omitempty" `
}
type CustomizedProcessingResource struct {
AbstractCustomizedResource [ * ResourceInstance [ * ResourcePartnerShip [ * ProcessingResourcePricingProfile ] ] ]
abstractProcessingResource
Container common . Container ` json:"container,omitempty" bson:"container,omitempty" ` // Container is the container
}
func ( r * CustomizedProcessingResource ) GetType ( ) tools . DataType {
return tools . PROCESSING_RESOURCE
}
func ( a * CustomizedProcessingResource ) GetExplicitDurationInS ( ) float64 {
if a . ExplicitBookingDurationS == 0 {
if a . UsageEnd == nil || a . UsageStart == nil {
if a . Service {
return - 1
}
return time . Duration ( 1 * time . Hour ) . Seconds ( )
}
return a . UsageEnd . Sub ( * a . UsageStart ) . Seconds ( )
}
return a . ExplicitBookingDurationS
}
func ( d * ProcessingResource ) GetAccessor ( request * tools . APIRequest ) utils . Accessor {
return NewAccessor [ * ProcessingResource ] ( tools . PROCESSING_RESOURCE , request , func ( ) utils . DBObject { return & ProcessingResource { } } ) // Create a new instance of the accessor
}
type ProcessingResourcePricingProfile struct {
Pricing * pricing . PricingStrategy [ pricing . TimePricingStrategy ] ` json:"cpus_prices,omitempty" bson:"cpus_prices,omitempty" ` // CPUsPrices is the prices of the CPUs
pricing . AccessPricingProfile // AccessPricingProfile is the pricing profile of a data it means that we can access the data for an amount of time
}
func ( p * ProcessingResourcePricingProfile ) IsBuying ( ) bool {
return p . Pricing . BuyingStrategy != pricing . PAY_PER_USE
}
func ( p * ProcessingResourcePricingProfile ) GetPrice ( amountOfData float64 , val float64 , start time . Time , end time . Time , request * tools . APIRequest , params ... string ) ( float64 , error ) {
return p . Pricing . GetPrice ( amountOfData , val , start , & end )
2024-11-28 16:49:41 +01:00
}