set up unfonctionnal rework, TODO -> pricing separation
This commit is contained in:
@@ -58,7 +58,7 @@ type ComputeResourcePricingProfile struct {
|
||||
|
||||
// PROBLEM
|
||||
|
||||
func (p *ComputeResourcePricingProfile) IsBuying() bool {
|
||||
func (p *ComputeResourcePricingProfile) IsPurchased() bool {
|
||||
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,12 @@ const (
|
||||
LICENCED
|
||||
)
|
||||
|
||||
type abstractDataResource struct {
|
||||
/*
|
||||
* DataResource is a struct that represents a data resource
|
||||
* it defines the resource data
|
||||
*/
|
||||
type DataResource struct {
|
||||
AbstractResource[*ResourceInstance[*DataResourcePartnership]]
|
||||
Type string `bson:"type,omitempty" json:"type,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
|
||||
@@ -26,17 +31,7 @@ type abstractDataResource struct {
|
||||
UpdatePeriod time.Time `bson:"update_period,omitempty" json:"update_period,omitempty"`
|
||||
PersonalData bool `bson:"personal_data,omitempty" json:"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
|
||||
}
|
||||
|
||||
/*
|
||||
* DataResource is a struct that represents a data resource
|
||||
* it defines the resource data
|
||||
*/
|
||||
type DataResource struct {
|
||||
AbstractResource[*ResourceInstance[*DataResourcePartnership]]
|
||||
abstractDataResource // AbstractResource contains the basic fields of an object (id, name)
|
||||
License DataLicense `json:"license" bson:"license" description:"license of the data" default:"0"` // License is the license of the data
|
||||
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
|
||||
// ? 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
|
||||
}
|
||||
@@ -102,13 +97,12 @@ func (p *DataResourcePricingProfile) GetPrice(amountOfData float64, explicitDura
|
||||
return p.Pricing.GetPrice(amountOfData, explicitDuration, start, &end)
|
||||
}
|
||||
|
||||
func (p *DataResourcePricingProfile) IsBuying() bool {
|
||||
func (p *DataResourcePricingProfile) IsPurchased() bool {
|
||||
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||
}
|
||||
|
||||
type CustomizedDataResource struct {
|
||||
AbstractCustomizedResource[*ResourceInstance[*DataResourcePartnership]]
|
||||
abstractDataResource
|
||||
StorageGB float64 `json:"storage_gb,omitempty" bson:"storage_gb,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
6
models/resources/priced_resource/priced_resource.go
Normal file
6
models/resources/priced_resource/priced_resource.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package priced_resource
|
||||
|
||||
type PricedResource struct {
|
||||
}
|
||||
|
||||
/*TODO*/
|
||||
@@ -19,28 +19,24 @@ type ProcessingUsage struct {
|
||||
ScalingModel string `bson:"scaling_model,omitempty" json:"scaling_model,omitempty"` // ScalingModel is the scaling model
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
/*
|
||||
* ProcessingResource is a struct that represents a processing resource
|
||||
* it defines the resource processing
|
||||
*/
|
||||
type ProcessingResource struct {
|
||||
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"`
|
||||
Infrastructure common.InfrastructureType `json:"infrastructure,omitempty" bson:"infrastructure,omitempty"`
|
||||
IsService 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
|
||||
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"`
|
||||
Container common.Container `json:"container,omitempty" bson:"container,omitempty"` // Container is the container
|
||||
}
|
||||
|
||||
type CustomizedProcessingResource struct {
|
||||
AbstractCustomizedResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]]
|
||||
abstractProcessingResource
|
||||
Container common.Container `json:"container,omitempty" bson:"container,omitempty"` // Container is the container
|
||||
IsService bool
|
||||
}
|
||||
|
||||
func (r *CustomizedProcessingResource) GetType() tools.DataType {
|
||||
@@ -49,8 +45,8 @@ func (r *CustomizedProcessingResource) GetType() tools.DataType {
|
||||
|
||||
func (a *CustomizedProcessingResource) GetExplicitDurationInS() float64 {
|
||||
if a.ExplicitBookingDurationS == 0 {
|
||||
if a.UsageEnd == nil || a.UsageStart == nil {
|
||||
if a.Service {
|
||||
if a.IsService || a.UsageStart == nil {
|
||||
if a.IsService {
|
||||
return -1
|
||||
}
|
||||
return time.Duration(1 * time.Hour).Seconds()
|
||||
@@ -68,7 +64,7 @@ type ProcessingResourcePricingProfile struct {
|
||||
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 {
|
||||
func (p *ProcessingResourcePricingProfile) IsPurchased() bool {
|
||||
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||
}
|
||||
|
||||
|
||||
30
models/resources/purchase_resource/purchase_resource.go
Normal file
30
models/resources/purchase_resource/purchase_resource.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package purchase_resource
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type PurchaseResource struct {
|
||||
utils.AbstractObject
|
||||
EndDate *time.Time `json:"end_buying_date,omitempty" bson:"end_buying_date,omitempty"`
|
||||
ResourceID string `json:"resource_id" bson:"resource_id" validate:"required"`
|
||||
ResourceType tools.DataType `json:"resource_type" bson:"resource_type" validate:"required"`
|
||||
}
|
||||
|
||||
func (d *PurchaseResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
return NewAccessor(request) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
func (r *PurchaseResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
||||
return r.IsDraft, set // only draft buying can be updated
|
||||
}
|
||||
|
||||
func (r *PurchaseResource) CanDelete() bool { // ENDBuyingDate is passed
|
||||
if r.EndDate != nil {
|
||||
return time.Now().UTC().After(*r.EndDate)
|
||||
}
|
||||
return false // only draft bookings can be deleted
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package purchase_resource
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||
"cloud.o-forge.io/core/oc-lib/logs"
|
||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
type purchaseResourceMongoAccessor struct {
|
||||
utils.AbstractAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
|
||||
}
|
||||
|
||||
// New creates a new instance of the bookingMongoAccessor
|
||||
func NewAccessor(request *tools.APIRequest) *purchaseResourceMongoAccessor {
|
||||
return &purchaseResourceMongoAccessor{
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
Logger: logs.CreateLogger(tools.BUYING_STATUS.String()), // Create a logger with the data type
|
||||
Request: request,
|
||||
Type: tools.BUYING_STATUS,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Nothing special here, just the basic CRUD operations
|
||||
*/
|
||||
func (a *purchaseResourceMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericDeleteOne(id, a)
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericUpdateOne(set, id, a, &PurchaseResource{})
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return utils.GenericStoreOne(data, a)
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
||||
return utils.GenericStoreOne(data, a)
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
||||
return utils.GenericLoadOne[*PurchaseResource](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
||||
if d.(*PurchaseResource).EndDate != nil && time.Now().UTC().After(*d.(*PurchaseResource).EndDate) {
|
||||
utils.GenericDeleteOne(id, a)
|
||||
return nil, 404, nil
|
||||
}
|
||||
return d, 200, nil
|
||||
}, a)
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericLoadAll[*PurchaseResource](a.getExec(), isDraft, a)
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
||||
return utils.GenericSearch[*PurchaseResource](filters, search, (&PurchaseResource{}).GetObjectFilters(search), a.getExec(), isDraft, a)
|
||||
}
|
||||
|
||||
func (a *purchaseResourceMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
||||
if d.(*PurchaseResource).EndDate != nil && time.Now().UTC().After(*d.(*PurchaseResource).EndDate) {
|
||||
utils.GenericDeleteOne(d.GetID(), a)
|
||||
return nil
|
||||
}
|
||||
return d
|
||||
}
|
||||
}
|
||||
@@ -130,8 +130,8 @@ func (abs *AbstractCustomizedResource[T]) SetEndUsage(end time.Time) {
|
||||
}
|
||||
}
|
||||
|
||||
func (abs *AbstractCustomizedResource[T]) IsBuying(request *tools.APIRequest) bool {
|
||||
return abs.GetPartnership(request).GetPricing(abs.SelectedPricing).IsBuying()
|
||||
func (abs *AbstractCustomizedResource[T]) IsPurchased(request *tools.APIRequest) bool {
|
||||
return abs.GetPartnership(request).GetPricing(abs.SelectedPricing).IsPurchased()
|
||||
}
|
||||
|
||||
func (abs *AbstractCustomizedResource[T]) GetLocationEnd() *time.Time {
|
||||
|
||||
@@ -99,7 +99,7 @@ type StorageResourcePricingProfile struct {
|
||||
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 {
|
||||
func (p *StorageResourcePricingProfile) IsPurchased() bool {
|
||||
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ func (p *WorkflowResourcePricingProfile) GetID() string {
|
||||
return p.ID
|
||||
}
|
||||
|
||||
func (p *WorkflowResourcePricingProfile) IsBuying() bool {
|
||||
func (p *WorkflowResourcePricingProfile) IsPurchased() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user