light modification
This commit is contained in:
parent
918006302b
commit
ae9a80c8f3
@ -2,8 +2,8 @@ package common
|
|||||||
|
|
||||||
// CPU is a struct that represents a CPU
|
// CPU is a struct that represents a CPU
|
||||||
type CPU struct {
|
type CPU struct {
|
||||||
Model string `bson:"platform,omitempty" json:"platform,omitempty"`
|
Model string `bson:"model,omitempty" json:"model,omitempty"`
|
||||||
FrequencyGhz float64 `bson:"frenquency,omitempty" json:"frenquency,omitempty"`
|
FrequencyGhz float64 `bson:"frequency,omitempty" json:"frequency,omitempty"`
|
||||||
Cores int `bson:"cores,omitempty" json:"cores,omitempty"`
|
Cores int `bson:"cores,omitempty" json:"cores,omitempty"`
|
||||||
Architecture string `bson:"architecture,omitempty" json:"architecture,omitempty"`
|
Architecture string `bson:"architecture,omitempty" json:"architecture,omitempty"`
|
||||||
}
|
}
|
||||||
@ -14,8 +14,9 @@ type RAM struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type GPU struct {
|
type GPU struct {
|
||||||
Model string `bson:"platform,omitempty" json:"platform,omitempty"`
|
Model string `bson:"model,omitempty" json:"model,omitempty"`
|
||||||
MemoryGb float64 `bson:"memory,omitempty" json:"memory,omitempty" description:"Units in MB"`
|
MemoryGb float64 `bson:"memory,omitempty" json:"memory,omitempty" description:"Units in MB"`
|
||||||
|
Cores map[string]int `bson:"cores,omitempty" json:"cores,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfrastructureType int
|
type InfrastructureType int
|
||||||
|
@ -5,7 +5,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PricingProfileITF interface {
|
type PricingProfileITF interface {
|
||||||
GetID() string
|
|
||||||
GetPrice(quantity float64, val float64, start time.Time, end time.Time, params ...string) (float64, error)
|
GetPrice(quantity float64, val float64, start time.Time, end time.Time, params ...string) (float64, error)
|
||||||
IsPurchased() bool
|
IsPurchased() bool
|
||||||
GetOverrideStrategyValue() int
|
GetOverrideStrategyValue() int
|
||||||
@ -20,16 +19,11 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AccessPricingProfile[T Strategy] struct { // only use for acces such as : DATA && PROCESSING
|
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:"pricing,omitempty" bson:"pricing,omitempty"` // Price is the price of the resource
|
||||||
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
|
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
|
RefundRatio int32 `json:"refund_ratio" bson:"refund_ratio" default:"0"` // RefundRatio is the refund ratio if missing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *AccessPricingProfile[T]) GetID() string {
|
|
||||||
return b.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
func (b *AccessPricingProfile[T]) GetOverrideStrategyValue() int {
|
func (b *AccessPricingProfile[T]) GetOverrideStrategyValue() int {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
@ -50,9 +44,9 @@ type ExploitPricingProfile[T Strategy] struct { // only use for exploit such as
|
|||||||
AccessPricingProfile[T]
|
AccessPricingProfile[T]
|
||||||
AdditionnalRefundTypes []RefundType `json:"refund_types" bson:"refund_types"` // RefundTypes is the refund types of the pricing
|
AdditionnalRefundTypes []RefundType `json:"refund_types" bson:"refund_types"` // RefundTypes is the refund types of the pricing
|
||||||
|
|
||||||
PrivilegeStrategy ExploitPrivilegeStrategy `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
|
GarantedDelaySecond uint `json:"garanted_delay_second,omitempty" bson:"garanted_delay_second,omitempty"` // GarantedDelaySecond is the garanted delay of the pricing
|
||||||
|
|
||||||
Exceeding bool
|
Exceeding bool `json:"exceeding" bson:"exceeding"` // Exceeding is the exceeding of the bill
|
||||||
ExceedingRatio int32 `json:"exceeding_ratio" bson:"exceeding_ratio" default:"0"` // ExceedingRatio is the exceeding ratio of the bill
|
ExceedingRatio int32 `json:"exceeding_ratio" bson:"exceeding_ratio" default:"0"` // ExceedingRatio is the exceeding ratio of the bill
|
||||||
}
|
}
|
||||||
|
@ -85,35 +85,14 @@ func BookingEstimation(t TimePricingStrategy, price float64, locationDurationInS
|
|||||||
return 0, errors.New("Pricing strategy not found")
|
return 0, errors.New("Pricing strategy not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// hmmmm
|
|
||||||
type PricingStrategy[T Strategy] struct {
|
type PricingStrategy[T Strategy] struct {
|
||||||
Price float64 `json:"Price" bson:"Price" default:"0"` // Price is the Price of the pricing
|
Price float64 `json:"price" bson:"price" default:"0"` // Price is the Price of the pricing
|
||||||
|
Currency string `json:"currency" bson:"currency" default:"USD"` // Currency is the currency of the pricing
|
||||||
BuyingStrategy BuyingStrategy `json:"buying_strategy" bson:"buying_strategy" default:"0"` // BuyingStrategy is the buying strategy of the pricing
|
BuyingStrategy BuyingStrategy `json:"buying_strategy" bson:"buying_strategy" default:"0"` // BuyingStrategy is the buying strategy of the pricing
|
||||||
TimePricingStrategy TimePricingStrategy `json:"time_pricing_strategy" bson:"time_pricing_strategy" default:"0"` // TimePricingStrategy is the time pricing strategy of the pricing
|
TimePricingStrategy TimePricingStrategy `json:"time_pricing_strategy" bson:"time_pricing_strategy" default:"0"` // TimePricingStrategy is the time pricing strategy of the pricing
|
||||||
OverrideStrategy T `json:"override_strategy" bson:"override_strategy" default:"-1"` // Modulation is the modulation of the pricing
|
OverrideStrategy T `json:"override_strategy" bson:"override_strategy" default:"-1"` // Modulation is the modulation of the pricing
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PricingStrategy[T]) SetStrategy(Price float64, BuyingStrategy BuyingStrategy, TimePricingStrategy TimePricingStrategy) error {
|
|
||||||
if TimePricingStrategy == ONCE && (BuyingStrategy != UNLIMITED || BuyingStrategy != PAY_PER_USE) {
|
|
||||||
return errors.New("time pricing strategy can only be set to ONCE if buying strategy is UNLIMITED or PAY_PER_USE")
|
|
||||||
} else if BuyingStrategy == SUBSCRIPTION && (TimePricingStrategy == ONCE) {
|
|
||||||
return errors.New("subscription duration in second must be set if buying strategy is SUBSCRIPTION")
|
|
||||||
}
|
|
||||||
p.Price = Price
|
|
||||||
p.BuyingStrategy = BuyingStrategy
|
|
||||||
p.TimePricingStrategy = TimePricingStrategy
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p PricingStrategy[T]) SetSpecificPerUseStrategy(strategy T) error {
|
|
||||||
if p.BuyingStrategy == UNLIMITED {
|
|
||||||
return errors.New("UNLIMITED buying strategy can't have a specific strategy, Price is set on buying")
|
|
||||||
}
|
|
||||||
p.OverrideStrategy = strategy
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// QUANTITY can be how many of gb core per example
|
|
||||||
func (p PricingStrategy[T]) GetPrice(amountOfData float64, bookingTimeDuration float64, start time.Time, end *time.Time) (float64, error) {
|
func (p PricingStrategy[T]) GetPrice(amountOfData float64, bookingTimeDuration float64, start time.Time, end *time.Time) (float64, error) {
|
||||||
if p.BuyingStrategy == SUBSCRIPTION {
|
if p.BuyingStrategy == SUBSCRIPTION {
|
||||||
return BookingEstimation(p.GetTimePricingStrategy(), p.Price*float64(amountOfData), bookingTimeDuration, start, end)
|
return BookingEstimation(p.GetTimePricingStrategy(), p.Price*float64(amountOfData), bookingTimeDuration, start, end)
|
||||||
|
@ -7,12 +7,14 @@ const (
|
|||||||
GB StorageSize = iota
|
GB StorageSize = iota
|
||||||
MB
|
MB
|
||||||
KB
|
KB
|
||||||
|
TB
|
||||||
)
|
)
|
||||||
|
|
||||||
var argoType = [...]string{
|
var argoType = [...]string{
|
||||||
"Gi",
|
"Gi",
|
||||||
"Mi",
|
"Mi",
|
||||||
"Ki",
|
"Ki",
|
||||||
|
"Ti",
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new instance of the StorageResource struct
|
// New creates a new instance of the StorageResource struct
|
||||||
|
@ -25,13 +25,22 @@ func (d *ComputeResource) GetAccessor(request *tools.APIRequest) utils.Accessor
|
|||||||
return NewAccessor[*ComputeResource](tools.COMPUTE_RESOURCE, request, func() utils.DBObject { return &ComputeResource{} })
|
return NewAccessor[*ComputeResource](tools.COMPUTE_RESOURCE, request, func() utils.DBObject { return &ComputeResource{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ComputeNode struct {
|
||||||
|
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||||
|
Quantity int64 `json:"quantity" bson:"quantity" default:"1"`
|
||||||
|
RAM *common.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
||||||
|
CPUs map[string]int64 `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs key is model
|
||||||
|
GPUs map[string]int64 `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs key is model
|
||||||
|
}
|
||||||
|
|
||||||
type ComputeResourceInstance struct {
|
type ComputeResourceInstance struct {
|
||||||
ResourceInstance[*ComputeResourcePartnership]
|
ResourceInstance[*ComputeResourcePartnership]
|
||||||
SecurityLevel string `json:"security_level,omitempty" bson:"security_level,omitempty"`
|
SecurityLevel string `json:"security_level,omitempty" bson:"security_level,omitempty"`
|
||||||
PowerSource string `json:"power_source,omitempty" bson:"power_source,omitempty"`
|
PowerSources []string `json:"power_sources,omitempty" bson:"power_sources,omitempty"`
|
||||||
CPUs map[string]*common.CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs key is model
|
AnnualCO2Emissions float64 `json:"annual_co2_emissions,omitempty" bson:"co2_emissions,omitempty"`
|
||||||
GPUs map[string]*common.GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs key is model
|
CPUs map[string]*common.CPU `bson:"cpus,omitempty" json:"cpus,omitempty"` // CPUs is the list of CPUs key is model
|
||||||
RAM *common.RAM `bson:"ram,omitempty" json:"ram,omitempty"` // RAM is the RAM
|
GPUs map[string]*common.GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs key is model
|
||||||
|
Nodes []*ComputeNode `json:"nodes,omitempty" bson:"nodes,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ComputeResourcePartnership struct {
|
type ComputeResourcePartnership struct {
|
||||||
|
@ -25,13 +25,14 @@ const (
|
|||||||
type DataResource struct {
|
type DataResource struct {
|
||||||
AbstractIntanciatedResource[*ResourceInstance[*DataResourcePartnership]]
|
AbstractIntanciatedResource[*ResourceInstance[*DataResourcePartnership]]
|
||||||
Type string `bson:"type,omitempty" json:"type,omitempty"`
|
Type string `bson:"type,omitempty" json:"type,omitempty"`
|
||||||
|
Source string `json:"source,omitempty" bson:"source,omitempty"` // Source is the source of the resource
|
||||||
Quality string `bson:"quality,omitempty" json:"quality,omitempty"`
|
Quality string `bson:"quality,omitempty" json:"quality,omitempty"`
|
||||||
OpenData bool `bson:"open_data" json:"open_data" default:"false"` // Type is the type of the storage
|
OpenData bool `bson:"open_data" json:"open_data" default:"false"` // Type is the type of the storage
|
||||||
Static bool `bson:"static" json:"static" default:"false"`
|
Static bool `bson:"static" json:"static" default:"false"`
|
||||||
UpdatePeriod time.Time `bson:"update_period,omitempty" json:"update_period,omitempty"`
|
UpdatePeriod time.Time `bson:"update_period,omitempty" json:"update_period,omitempty"`
|
||||||
PersonalData bool `bson:"personal_data,omitempty" json:"personal_data,omitempty"`
|
PersonalData bool `bson:"personal_data,omitempty" json:"personal_data,omitempty"`
|
||||||
AnonymizedPersonalData bool `bson:"anonymized_personal_data,omitempty" json:"anonymized_personal_data,omitempty"`
|
AnonymizedPersonalData bool `bson:"anonymized_personal_data,omitempty" json:"anonymized_personal_data,omitempty"`
|
||||||
SizeGB float64 `json:"size_gb,omitempty" bson:"size_gb,omitempty"` // SizeGB is the size of the data License DataLicense `json:"license" bson:"license" description:"license of the data" default:"0"` // License is the license of the data
|
SizeGB float64 `json:"size,omitempty" bson:"size,omitempty"` // SizeGB is the size of the data License DataLicense `json:"license" bson:"license" description:"license of the data" default:"0"` // License is the license of the data
|
||||||
// ? Interest DataLicense `json:"interest" bson:"interest" description:"interest of the data" default:"0"` // Interest is the interest of the data
|
// ? Interest DataLicense `json:"interest" bson:"interest" description:"interest of the data" default:"0"` // Interest is the interest of the data
|
||||||
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
||||||
}
|
}
|
||||||
|
@ -9,17 +9,17 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type PricedResource struct {
|
type PricedResource struct {
|
||||||
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||||
Logo string `json:"logo,omitempty" bson:"logo,omitempty"`
|
Logo string `json:"logo,omitempty" bson:"logo,omitempty"`
|
||||||
InstancesRefs map[string]string `json:"instances_refs,omitempty" bson:"instances_refs,omitempty"`
|
InstancesRefs map[string]string `json:"instances_refs,omitempty" bson:"instances_refs,omitempty"`
|
||||||
PricingProfiles map[string][]pricing.PricingProfileITF `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
PricingProfiles []pricing.PricingProfileITF `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
||||||
SelectedPricing *pricing.PricingProfileITF `json:"selected_pricing,omitempty" bson:"selected_pricing,omitempty"`
|
SelectedPricing *pricing.PricingProfileITF `json:"selected_pricing,omitempty" bson:"selected_pricing,omitempty"`
|
||||||
ExplicitBookingDurationS float64 `json:"explicit_location_duration_s,omitempty" bson:"explicit_location_duration_s,omitempty"`
|
ExplicitBookingDurationS float64 `json:"explicit_location_duration_s,omitempty" bson:"explicit_location_duration_s,omitempty"`
|
||||||
UsageStart *time.Time `json:"start,omitempty" bson:"start,omitempty"`
|
UsageStart *time.Time `json:"start,omitempty" bson:"start,omitempty"`
|
||||||
UsageEnd *time.Time `json:"end,omitempty" bson:"end,omitempty"`
|
UsageEnd *time.Time `json:"end,omitempty" bson:"end,omitempty"`
|
||||||
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty"`
|
CreatorID string `json:"peer_id,omitempty" bson:"peer_id,omitempty"`
|
||||||
ResourceID string `json:"resource_id,omitempty" bson:"resource_id,omitempty"`
|
ResourceID string `json:"resource_id,omitempty" bson:"resource_id,omitempty"`
|
||||||
ResourceType tools.DataType `json:"resource_type,omitempty" bson:"resource_type,omitempty"`
|
ResourceType tools.DataType `json:"resource_type,omitempty" bson:"resource_type,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abs *PricedResource) GetID() string {
|
func (abs *PricedResource) GetID() string {
|
||||||
|
@ -71,10 +71,10 @@ type AbstractIntanciatedResource[T ResourceInstanceITF] struct {
|
|||||||
func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource(
|
func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource(
|
||||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||||
instances := map[string]string{}
|
instances := map[string]string{}
|
||||||
profiles := map[string][]pricing.PricingProfileITF{}
|
profiles := []pricing.PricingProfileITF{}
|
||||||
for _, instance := range abs.Instances {
|
for _, instance := range abs.Instances {
|
||||||
instances[instance.GetID()] = instance.GetName()
|
instances[instance.GetID()] = instance.GetName()
|
||||||
profiles[instance.GetID()] = instance.GetPricingsProfiles(request.PeerID, request.Groups)
|
profiles = instance.GetPricingsProfiles(request.PeerID, request.Groups)
|
||||||
}
|
}
|
||||||
return &PricedResource{
|
return &PricedResource{
|
||||||
Name: abs.Name,
|
Name: abs.Name,
|
||||||
@ -175,7 +175,7 @@ func (ri *ResourceInstance[T]) ClearPeerGroups() {
|
|||||||
type ResourcePartnerShip[T pricing.PricingProfileITF] struct {
|
type ResourcePartnerShip[T pricing.PricingProfileITF] struct {
|
||||||
Namespace string `json:"namespace" bson:"namespace" default:"default-namespace"`
|
Namespace string `json:"namespace" bson:"namespace" default:"default-namespace"`
|
||||||
PeerGroups map[string][]string `json:"peer_groups,omitempty" bson:"peer_groups,omitempty"`
|
PeerGroups map[string][]string `json:"peer_groups,omitempty" bson:"peer_groups,omitempty"`
|
||||||
PricingProfiles map[string]T `json:"pricing,omitempty" bson:"pricing,omitempty"`
|
PricingProfiles []T `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF {
|
func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF {
|
||||||
|
@ -31,15 +31,11 @@ func (w *WorkflowResource) SetAllowedInstances(request *tools.APIRequest) {
|
|||||||
|
|
||||||
func (w *WorkflowResource) ConvertToPricedResource(
|
func (w *WorkflowResource) ConvertToPricedResource(
|
||||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||||
instances := map[string]string{}
|
|
||||||
profiles := map[string][]pricing.PricingProfileITF{}
|
|
||||||
return &PricedResource{
|
return &PricedResource{
|
||||||
Name: w.Name,
|
Name: w.Name,
|
||||||
Logo: w.Logo,
|
Logo: w.Logo,
|
||||||
ResourceID: w.UUID,
|
ResourceID: w.UUID,
|
||||||
ResourceType: t,
|
ResourceType: t,
|
||||||
InstancesRefs: instances,
|
CreatorID: w.CreatorID,
|
||||||
PricingProfiles: profiles,
|
|
||||||
CreatorID: w.CreatorID,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user