modelling

This commit is contained in:
mr
2024-12-16 12:17:20 +01:00
parent 02d1e93c78
commit 7696f065f8
9 changed files with 383 additions and 74 deletions

View File

@@ -3,7 +3,6 @@ package pricing
import (
"time"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
@@ -22,33 +21,38 @@ const (
REFUND_ON_EARLY_END
)
type AccessPricingProfile struct { // only use for acces such as : DATA && PROCESSING
utils.DBObject
DefaultRefund RefundType `json:"default_refund" bson:"default_refund"` // DefaultRefund is the default refund type of the pricing
RefundRatio int32 `json:"refund_ratio" bson:"refund_ratio" default:"0"` // RefundRatio is the refund ratio if missing
type AccessPricingProfile[T Strategy] struct { // only use for acces such as : DATA && PROCESSING
ID string `json:"id,omitempty" bson:"id,omitempty"` // ID is the ID of the pricing
Pricing PricingStrategy[T] `json:"price,omitempty" bson:"price,omitempty"` // Price is the price of the resource
DefaultRefund RefundType `json:"default_refund" bson:"default_refund"` // DefaultRefund is the default refund type of the pricing
RefundRatio int32 `json:"refund_ratio" bson:"refund_ratio" default:"0"` // RefundRatio is the refund ratio if missing
}
func (b *AccessPricingProfile) GetOverrideStrategyValue() int {
func (b *AccessPricingProfile[T]) GetID() string {
return b.ID
}
func (b *AccessPricingProfile[T]) GetOverrideStrategyValue() int {
return -1
}
type ExploitPricingStrategy int
type ExploitPrivilegeStrategy int
const (
BASIC ExploitPricingStrategy = iota
BASIC ExploitPrivilegeStrategy = iota
GARANTED_ON_DELAY
GARANTED
)
func (t ExploitPricingStrategy) String() string {
func (t ExploitPrivilegeStrategy) String() string {
return [...]string{"BASIC", "GARANTED_ON_DELAY", "GARANTED"}[t]
}
type ExploitPricingProfile struct { // only use for exploit such as : STORAGE, COMPUTE, WORKFLOW
AccessPricingProfile
type ExploitPricingProfile[T Strategy] struct { // only use for exploit such as : STORAGE, COMPUTE, WORKFLOW
AccessPricingProfile[T]
AdditionnalRefundTypes []RefundType `json:"refund_types" bson:"refund_types"` // RefundTypes is the refund types of the pricing
PrivilegeStrategy ExploitPricingStrategy `json:"privilege_strategy,omitempty" bson:"privilege_strategy,omitempty"` // Strategy is the strategy of the pricing
PrivilegeStrategy ExploitPrivilegeStrategy `json:"privilege_strategy,omitempty" bson:"privilege_strategy,omitempty"` // Strategy is the strategy of the pricing
GarantedDelaySecond uint
Exceeding bool

View File

@@ -41,24 +41,6 @@ type ComputeResourcePartnership struct {
MaxAllowedRAMSize float64 `json:"allowed_ram,omitempty" bson:"allowed_ram,omitempty"`
}
func (r *ComputeResourceInstance) VerifyPartnerships() bool {
peersMultiple := map[string]int{}
for _, p := range r.Partnerships {
for k, g := range p.PeerGroups {
for _, v := range g {
if _, ok := peersMultiple[k+"_"+v]; !ok {
peersMultiple[k + "_" + v] = 0
}
peersMultiple[k+"_"+v]++
}
}
for k, p := range peersMultiple {
if p > 1 {
return false
}
}
}
type ComputeResourcePricingProfileOptions struct {
CPUCore int `json:"cpu_core" bson:"cpu_core" default:"1"`
GPUMemoryGB float64 `json:"gpu_memory_gb" bson:"gpu_memory_gb" default:"1"`
@@ -66,9 +48,8 @@ type ComputeResourcePricingProfileOptions struct {
}
type ComputeResourcePricingProfile struct {
pricing.ExploitPricingProfile
Pricing pricing.PricingStrategy[pricing.TimePricingStrategy] `json:"price,omitempty" bson:"price,omitempty"` // Price is the price of the resource
Options ComputeResourcePricingProfileOptions `json:"options,omitempty" bson:"options,omitempty"` // Options is the options of the pricing profile
pricing.ExploitPricingProfile[pricing.TimePricingStrategy]
Options ComputeResourcePricingProfileOptions `json:"options,omitempty" bson:"options,omitempty"` // Options is the options of the pricing profile
// ExploitPricingProfile is the pricing profile of a compute it means that we exploit the resource for an amount of continuous time
OverrideCPUsPrices map[string]float64 `json:"cpus_prices,omitempty" bson:"cpus_prices,omitempty"` // CPUsPrices is the prices of the CPUs
OverrideGPUsPrices map[string]float64 `json:"gpus_prices,omitempty" bson:"gpus_prices,omitempty"` // GPUsPrices is the prices of the GPUs

View File

@@ -91,8 +91,7 @@ func (t DataResourcePricingStrategy) GetQuantity(amountOfDataGB float64) (float6
}
type DataResourcePricingProfile struct {
Pricing *pricing.PricingStrategy[DataResourcePricingStrategy] `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
pricing.AccessPricingProfile[DataResourcePricingStrategy] // AccessPricingProfile is the pricing profile of a data it means that we can access the data for an amount of time
}
func (p *DataResourcePricingProfile) GetOverrideStrategyValue() int {

View File

@@ -65,8 +65,7 @@ func (d *ProcessingResource) GetAccessor(request *tools.APIRequest) utils.Access
}
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
pricing.AccessPricingProfile[pricing.TimePricingStrategy] // 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 {

View File

@@ -85,6 +85,30 @@ func (abs *AbstractResource[T]) GetPartnership(request *tools.APIRequest) Resour
return nil
}
func (abs *AbstractResource[T]) VerifyPartnerships() bool {
// a peer can be part of only one partnership by instance
// may we need to define partnership in a different DB
for _, instance := range abs.Instances {
if !instance.VerifyPartnerships() {
return false
}
}
return true
}
func (d *AbstractResource[T]) Trim() {
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok {
// TODO clean up the peer groups that are not in the allowed peers group
for _, instance := range d.Instances {
instance.ClearPeerGroups()
}
}
}
func (abs *AbstractResource[T]) VerifyAuth(request *tools.APIRequest) bool {
return len(verifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(request)
}
type AbstractCustomizedResource[T InstanceITF] struct {
abstractResource
ExplicitBookingDurationS float64 `json:"explicit_location_duration_s,omitempty" bson:"explicit_location_duration_s,omitempty"`
@@ -179,35 +203,6 @@ func verifyAuthAction[T InstanceITF](baseInstance []T, request *tools.APIRequest
return instances
}
/*
* VerifyPartnerships is a function that verifies the partnerships of the resource
* an instance can only have one partnership available for a peer
* it returns a boolean
*/
func (abs *AbstractResource[T]) VerifyPartnerships() bool {
// a peer can be part of only one partnership by instance
// may we need to define partnership in a different DB
for _, instance := range abs.Instances {
if !instance.VerifyPartnerships() {
return false
}
}
return true
}
func (d *AbstractResource[T]) Trim() {
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok {
// TODO clean up the peer groups that are not in the allowed peers group
for _, instance := range d.Instances {
instance.ClearPeerGroups()
}
}
}
func (abs *AbstractResource[T]) VerifyAuth(request *tools.APIRequest) bool {
return len(verifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(request)
}
type ResourceInstance[T ResourcePartnerITF] struct {
UUID string `json:"id,omitempty" bson:"id,omitempty"`
Location geopoint.GeoPoint `json:"location,omitempty" bson:"location,omitempty"`

View File

@@ -96,8 +96,7 @@ func (t StorageResourcePricingStrategy) GetQuantity(amountOfDataGB float64) (flo
}
type StorageResourcePricingProfile struct {
Pricing *pricing.PricingStrategy[StorageResourcePricingStrategy] `json:"cpus_prices,omitempty" bson:"cpus_prices,omitempty"` // CPUsPrices is the prices of the CPUs
pricing.ExploitPricingProfile // ExploitPricingProfile is the pricing profile of a storage it means that we exploit the resource for an amount of continuous time
pricing.ExploitPricingProfile[StorageResourcePricingStrategy] // ExploitPricingProfile is the pricing profile of a storage it means that we exploit the resource for an amount of continuous time
}
func (p *StorageResourcePricingProfile) IsBuying() bool {

View File

@@ -3,7 +3,6 @@ package resources
import (
"time"
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
)
@@ -36,8 +35,16 @@ func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor
}
type WorkflowResourcePricingProfile struct {
ID string `json:"id,omitempty" bson:"id,omitempty"`
ExploitedResourceSet
pricing.ExploitPricingProfile // ExploitPricingProfile is the pricing profile of a workflow it means that we exploit the resource for an amount of continuous time
}
func (p *WorkflowResourcePricingProfile) GetOverrideStrategyValue() int {
return -1
}
func (p *WorkflowResourcePricingProfile) GetID() string {
return p.ID
}
func (p *WorkflowResourcePricingProfile) IsBuying() bool {