set up unfonctionnal rework, TODO -> pricing separation
This commit is contained in:
parent
7696f065f8
commit
be3b09b683
@ -195,7 +195,7 @@ ExploitPricingProfile ^-- ComputeResourcePricingProfile
|
|||||||
ExploitPricingProfile ^-- StorageResourcePricingProfile
|
ExploitPricingProfile ^-- StorageResourcePricingProfile
|
||||||
interface PricingProfileITF {
|
interface PricingProfileITF {
|
||||||
GetPrice(quantity float64, val float64, start date, end date, request) float64
|
GetPrice(quantity float64, val float64, start date, end date, request) float64
|
||||||
IsBuying() bool
|
IsPurchased() bool
|
||||||
}
|
}
|
||||||
class AccessPricingProfile {
|
class AccessPricingProfile {
|
||||||
ID string
|
ID string
|
||||||
|
29
doc/paymentflowV1.puml
Normal file
29
doc/paymentflowV1.puml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
@startuml
|
||||||
|
user -> client : schedule
|
||||||
|
client -> OrderAPIP1 : check book
|
||||||
|
OrderAPIP1 -> datacenterAPIP2 : check book
|
||||||
|
datacenterAPIP2 -> OrderAPIP1 : send ok
|
||||||
|
OrderAPIP1 -> datacenterAPIP2 : generate draft book
|
||||||
|
OrderAPIP1 -> client : send ok
|
||||||
|
client -> OrderAPIP1 : send scheduler
|
||||||
|
OrderAPIP1 -> OrderAPIP1 : draft executions
|
||||||
|
OrderAPIP1 -> OrderAPIP1 : draft order
|
||||||
|
OrderAPIP1 -> client : send drafted order
|
||||||
|
client -> user :
|
||||||
|
user -> client : select pricing profile
|
||||||
|
client -> OrderAPIP1 : update order
|
||||||
|
OrderAPIP1 -> datacenterAPIP2 : check book
|
||||||
|
datacenterAPIP2 -> OrderAPIP1 : send ok
|
||||||
|
OrderAPIP1 -> datacenterAPIP2 : generate draft book
|
||||||
|
OrderAPIP1 -> client : send order
|
||||||
|
user -> client : order
|
||||||
|
client -> OrderAPIP1 : order
|
||||||
|
OrderAPIP1 -> PaymentAPIBCP1 : send payment
|
||||||
|
PaymentAPIBCP1 -> OrderAPIP1 : send ok
|
||||||
|
OrderAPIP1 -> datacenterAPIP2 : undraft booking
|
||||||
|
OrderAPIP1 -> OrderAPIP1 : undraft execution
|
||||||
|
OrderAPIP1 -> OrderAPIP1 : undraft order
|
||||||
|
OrderAPIP1 -> client : send ok
|
||||||
|
client -> client : redirect
|
||||||
|
@enduml
|
||||||
|
|
@ -1,31 +0,0 @@
|
|||||||
package buying_status
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
|
||||||
)
|
|
||||||
|
|
||||||
type BuyingStatus struct {
|
|
||||||
utils.AbstractObject
|
|
||||||
BuyingDate time.Time `json:"buying_date" bson:"buying_date" validate:"required"`
|
|
||||||
EndBuyingDate *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 *BuyingStatus) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
|
||||||
return NewAccessor(request) // Create a new instance of the accessor
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *BuyingStatus) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
|
||||||
return r.IsDraft, set // only draft buying can be updated
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *BuyingStatus) CanDelete() bool { // ENDBuyingDate is passed
|
|
||||||
if r.EndBuyingDate != nil {
|
|
||||||
return time.Now().UTC().After(*r.EndBuyingDate)
|
|
||||||
}
|
|
||||||
return false // only draft bookings can be deleted
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
package buying_status
|
|
||||||
|
|
||||||
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 buyingStatusMongoAccessor 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) *buyingStatusMongoAccessor {
|
|
||||||
return &buyingStatusMongoAccessor{
|
|
||||||
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 *buyingStatusMongoAccessor) DeleteOne(id string) (utils.DBObject, int, error) {
|
|
||||||
return utils.GenericDeleteOne(id, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) UpdateOne(set utils.DBObject, id string) (utils.DBObject, int, error) {
|
|
||||||
return utils.GenericUpdateOne(set, id, a, &BuyingStatus{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) StoreOne(data utils.DBObject) (utils.DBObject, int, error) {
|
|
||||||
return utils.GenericStoreOne(data, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {
|
|
||||||
return utils.GenericStoreOne(data, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) LoadOne(id string) (utils.DBObject, int, error) {
|
|
||||||
return utils.GenericLoadOne[*BuyingStatus](id, func(d utils.DBObject) (utils.DBObject, int, error) {
|
|
||||||
if d.(*BuyingStatus).EndBuyingDate != nil && time.Now().UTC().After(*d.(*BuyingStatus).EndBuyingDate) {
|
|
||||||
utils.GenericDeleteOne(id, a)
|
|
||||||
return nil, 404, nil
|
|
||||||
}
|
|
||||||
return d, 200, nil
|
|
||||||
}, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) LoadAll(isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
|
||||||
return utils.GenericLoadAll[*BuyingStatus](a.getExec(), isDraft, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) Search(filters *dbs.Filters, search string, isDraft bool) ([]utils.ShallowDBObject, int, error) {
|
|
||||||
return utils.GenericSearch[*BuyingStatus](filters, search, (&BuyingStatus{}).GetObjectFilters(search), a.getExec(), isDraft, a)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a *buyingStatusMongoAccessor) getExec() func(utils.DBObject) utils.ShallowDBObject {
|
|
||||||
return func(d utils.DBObject) utils.ShallowDBObject {
|
|
||||||
if d.(*BuyingStatus).EndBuyingDate != nil && time.Now().UTC().After(*d.(*BuyingStatus).EndBuyingDate) {
|
|
||||||
utils.GenericDeleteOne(d.GetID(), a)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return d
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,7 +9,7 @@ import (
|
|||||||
type PricedItemITF interface {
|
type PricedItemITF interface {
|
||||||
GetID() string
|
GetID() string
|
||||||
GetType() tools.DataType
|
GetType() tools.DataType
|
||||||
IsBuying(request *tools.APIRequest) bool
|
IsPurchased(request *tools.APIRequest) bool
|
||||||
GetCreatorID() string
|
GetCreatorID() string
|
||||||
GetLocationStart() *time.Time
|
GetLocationStart() *time.Time
|
||||||
GetLocationEnd() *time.Time
|
GetLocationEnd() *time.Time
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
type PricingProfileITF interface {
|
type PricingProfileITF interface {
|
||||||
GetID() string
|
GetID() string
|
||||||
GetPrice(quantity float64, val float64, start time.Time, end time.Time, request *tools.APIRequest, params ...string) (float64, error)
|
GetPrice(quantity float64, val float64, start time.Time, end time.Time, request *tools.APIRequest, params ...string) (float64, error)
|
||||||
IsBuying() bool
|
IsPurchased() bool
|
||||||
GetOverrideStrategyValue() int
|
GetOverrideStrategyValue() int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@ import (
|
|||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/dbs"
|
"cloud.o-forge.io/core/oc-lib/dbs"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/booking"
|
"cloud.o-forge.io/core/oc-lib/models/booking"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/buying_status"
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
"cloud.o-forge.io/core/oc-lib/models/common/pricing"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/peer"
|
"cloud.o-forge.io/core/oc-lib/models/peer"
|
||||||
|
"cloud.o-forge.io/core/oc-lib/models/resources/purchase_resource"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
@ -172,7 +172,7 @@ func (o *Order) draftBookOrder(scheduler *workflow_execution.WorkflowSchedule, r
|
|||||||
return draftedBookings, errors.New("no request found")
|
return draftedBookings, errors.New("no request found")
|
||||||
}
|
}
|
||||||
for _, exec := range scheduler.WorkflowExecutions {
|
for _, exec := range scheduler.WorkflowExecutions {
|
||||||
bookings := exec.ToBookings(scheduler.Workflow)
|
bookings := exec.Book(scheduler.Workflow)
|
||||||
for _, booking := range bookings {
|
for _, booking := range bookings {
|
||||||
_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
||||||
tools.BOOKING, tools.POST, booking.Serialize(booking), request.Caller)
|
tools.BOOKING, tools.POST, booking.Serialize(booking), request.Caller)
|
||||||
@ -261,15 +261,14 @@ func (d *PeerOrder) Pay(request *tools.APIRequest, response chan *PeerOrder, wg
|
|||||||
d.Status = PAID // TO REMOVE LATER IT'S A MOCK
|
d.Status = PAID // TO REMOVE LATER IT'S A MOCK
|
||||||
if d.Status == PAID {
|
if d.Status == PAID {
|
||||||
for _, b := range d.Items {
|
for _, b := range d.Items {
|
||||||
if !b.Item.IsBuying(request) {
|
if !b.Item.IsPurchased(request) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
accessor := buying_status.NewAccessor(request)
|
accessor := purchase_resource.NewAccessor(request)
|
||||||
accessor.StoreOne(&buying_status.BuyingStatus{
|
accessor.StoreOne(&purchase_resource.PurchaseResource{
|
||||||
BuyingDate: time.Now(),
|
ResourceID: b.Item.GetID(),
|
||||||
ResourceID: b.Item.GetID(),
|
ResourceType: b.Item.GetType(),
|
||||||
ResourceType: b.Item.GetType(),
|
EndDate: b.Item.GetLocationEnd(),
|
||||||
EndBuyingDate: b.Item.GetLocationEnd(),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,21 +303,21 @@ func (d *PeerOrder) SetName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PeerItemOrder struct {
|
type PeerItemOrder struct {
|
||||||
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
Quantity int `json:"quantity,omitempty" bson:"quantity,omitempty"`
|
||||||
BuyingStatus buying_status.BuyingStatus `json:"buying_status,omitempty" bson:"buying_status,omitempty"`
|
Purchase purchase_resource.PurchaseResource `json:"purchase,omitempty" bson:"purchase,omitempty"`
|
||||||
Item pricing.PricedItemITF `json:"item,omitempty" bson:"item,omitempty"`
|
Item pricing.PricedItemITF `json:"item,omitempty" bson:"item,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *PeerItemOrder) GetPrice(request *tools.APIRequest) (float64, error) {
|
func (d *PeerItemOrder) GetPrice(request *tools.APIRequest) (float64, error) {
|
||||||
accessor := buying_status.NewAccessor(request)
|
accessor := purchase_resource.NewAccessor(request)
|
||||||
search, code, _ := accessor.Search(&dbs.Filters{
|
search, code, _ := accessor.Search(&dbs.Filters{
|
||||||
And: map[string][]dbs.Filter{
|
And: map[string][]dbs.Filter{
|
||||||
"resource_id": {{Operator: dbs.EQUAL.String(), Value: d.Item.GetID()}},
|
"resource_id": {{Operator: dbs.EQUAL.String(), Value: d.Item.GetID()}},
|
||||||
},
|
},
|
||||||
}, "", d.BuyingStatus.IsDraft)
|
}, "", d.Purchase.IsDraft)
|
||||||
if code == 200 && len(search) > 0 {
|
if code == 200 && len(search) > 0 {
|
||||||
for _, s := range search {
|
for _, s := range search {
|
||||||
if s.(*buying_status.BuyingStatus).EndBuyingDate == nil || time.Now().UTC().After(*s.(*buying_status.BuyingStatus).EndBuyingDate) {
|
if s.(*purchase_resource.PurchaseResource).EndDate == nil || time.Now().UTC().After(*s.(*purchase_resource.PurchaseResource).EndDate) {
|
||||||
return 0, nil
|
return 0, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ type ComputeResourcePricingProfile struct {
|
|||||||
|
|
||||||
// PROBLEM
|
// PROBLEM
|
||||||
|
|
||||||
func (p *ComputeResourcePricingProfile) IsBuying() bool {
|
func (p *ComputeResourcePricingProfile) IsPurchased() bool {
|
||||||
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,12 @@ const (
|
|||||||
LICENCED
|
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"`
|
Type string `bson:"type,omitempty" json:"type,omitempty"`
|
||||||
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
|
||||||
@ -26,17 +31,7 @@ type abstractDataResource struct {
|
|||||||
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
|
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
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* 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
|
|
||||||
// ? 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
|
||||||
}
|
}
|
||||||
@ -102,13 +97,12 @@ func (p *DataResourcePricingProfile) GetPrice(amountOfData float64, explicitDura
|
|||||||
return p.Pricing.GetPrice(amountOfData, explicitDuration, start, &end)
|
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
|
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomizedDataResource struct {
|
type CustomizedDataResource struct {
|
||||||
AbstractCustomizedResource[*ResourceInstance[*DataResourcePartnership]]
|
AbstractCustomizedResource[*ResourceInstance[*DataResourcePartnership]]
|
||||||
abstractDataResource
|
|
||||||
StorageGB float64 `json:"storage_gb,omitempty" bson:"storage_gb,omitempty"`
|
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
|
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
|
* ProcessingResource is a struct that represents a processing resource
|
||||||
* it defines the resource processing
|
* it defines the resource processing
|
||||||
*/
|
*/
|
||||||
type ProcessingResource struct {
|
type ProcessingResource struct {
|
||||||
AbstractResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]]
|
AbstractResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]]
|
||||||
abstractProcessingResource
|
Infrastructure common.InfrastructureType `json:"infrastructure,omitempty" bson:"infrastructure,omitempty"`
|
||||||
OpenSource bool `json:"open_source" bson:"open_source" default:"false"`
|
IsService bool `json:"is_service,omitempty" bson:"is_service,omitempty"` // IsService is a flag that indicates if the processing is a service
|
||||||
License string `json:"license,omitempty" bson:"license,omitempty"`
|
Usage *ProcessingUsage `bson:"usage,omitempty" json:"usage,omitempty"` // Usage is the usage of the processing
|
||||||
Maturity string `json:"maturity,omitempty" bson:"maturity,omitempty"`
|
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 {
|
type CustomizedProcessingResource struct {
|
||||||
AbstractCustomizedResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]]
|
AbstractCustomizedResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]]
|
||||||
abstractProcessingResource
|
IsService bool
|
||||||
Container common.Container `json:"container,omitempty" bson:"container,omitempty"` // Container is the container
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *CustomizedProcessingResource) GetType() tools.DataType {
|
func (r *CustomizedProcessingResource) GetType() tools.DataType {
|
||||||
@ -49,8 +45,8 @@ func (r *CustomizedProcessingResource) GetType() tools.DataType {
|
|||||||
|
|
||||||
func (a *CustomizedProcessingResource) GetExplicitDurationInS() float64 {
|
func (a *CustomizedProcessingResource) GetExplicitDurationInS() float64 {
|
||||||
if a.ExplicitBookingDurationS == 0 {
|
if a.ExplicitBookingDurationS == 0 {
|
||||||
if a.UsageEnd == nil || a.UsageStart == nil {
|
if a.IsService || a.UsageStart == nil {
|
||||||
if a.Service {
|
if a.IsService {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
return time.Duration(1 * time.Hour).Seconds()
|
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
|
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
|
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 {
|
func (abs *AbstractCustomizedResource[T]) IsPurchased(request *tools.APIRequest) bool {
|
||||||
return abs.GetPartnership(request).GetPricing(abs.SelectedPricing).IsBuying()
|
return abs.GetPartnership(request).GetPricing(abs.SelectedPricing).IsPurchased()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (abs *AbstractCustomizedResource[T]) GetLocationEnd() *time.Time {
|
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
|
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
|
return p.Pricing.BuyingStrategy != pricing.PAY_PER_USE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ func (p *WorkflowResourcePricingProfile) GetID() string {
|
|||||||
return p.ID
|
return p.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *WorkflowResourcePricingProfile) IsBuying() bool {
|
func (p *WorkflowResourcePricingProfile) IsPurchased() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,13 +27,15 @@ const (
|
|||||||
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
* every data in base root model should inherit from this struct (only exception is the ResourceModel)
|
||||||
*/
|
*/
|
||||||
type AbstractObject struct {
|
type AbstractObject struct {
|
||||||
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
UUID string `json:"id,omitempty" bson:"id,omitempty" validate:"required"`
|
||||||
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
Name string `json:"name,omitempty" bson:"name,omitempty" validate:"required"`
|
||||||
IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"`
|
IsDraft bool `json:"is_draft" bson:"is_draft" default:"false"`
|
||||||
UpdateDate time.Time `json:"update_date" bson:"update_date"`
|
CreatorID string `json:"creator_id" bson:"creator_id" default:"unknown"`
|
||||||
LastPeerWriter string `json:"last_peer_writer" bson:"last_peer_writer"`
|
|
||||||
CreatorID string `json:"creator_id" bson:"creator_id" default:"unknown"`
|
CreationDate time.Time `json:"creation_date" bson:"creation_date"`
|
||||||
AccessMode AccessMode `json:"access_mode" bson:"access_mode" default:"0"`
|
UpdateDate time.Time `json:"update_date" bson:"update_date"`
|
||||||
|
UpdaterID string `json:"updater_id" bson:"updater_id"`
|
||||||
|
AccessMode AccessMode `json:"access_mode" bson:"access_mode" default:"0"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AbstractObject) GenerateID() {
|
func (r *AbstractObject) GenerateID() {
|
||||||
@ -70,8 +72,9 @@ func (ao AbstractObject) GetName() string {
|
|||||||
|
|
||||||
func (ao *AbstractObject) UpToDate(user string, create bool) {
|
func (ao *AbstractObject) UpToDate(user string, create bool) {
|
||||||
ao.UpdateDate = time.Now()
|
ao.UpdateDate = time.Now()
|
||||||
ao.LastPeerWriter = user
|
ao.UpdaterID = user
|
||||||
if create {
|
if create {
|
||||||
|
ao.CreationDate = time.Now()
|
||||||
ao.CreatorID = user
|
ao.CreatorID = user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"cloud.o-forge.io/core/oc-lib/models/utils"
|
"cloud.o-forge.io/core/oc-lib/models/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -13,7 +12,7 @@ func TestStoreOneWorkflow(t *testing.T) {
|
|||||||
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
||||||
}
|
}
|
||||||
|
|
||||||
wma := NewAccessor(tools.APIRequest{})
|
wma := NewAccessor(nil)
|
||||||
id, _, _ := wma.StoreOne(&w)
|
id, _, _ := wma.StoreOne(&w)
|
||||||
|
|
||||||
assert.NotEmpty(t, id)
|
assert.NotEmpty(t, id)
|
||||||
@ -24,7 +23,7 @@ func TestLoadOneWorkflow(t *testing.T) {
|
|||||||
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
AbstractObject: utils.AbstractObject{Name: "testWorkflow"},
|
||||||
}
|
}
|
||||||
|
|
||||||
wma := NewAccessor(tools.APIRequest{})
|
wma := NewAccessor(nil)
|
||||||
new_w, _, _ := wma.StoreOne(&w)
|
new_w, _, _ := wma.StoreOne(&w)
|
||||||
assert.Equal(t, w, new_w)
|
assert.Equal(t, w, new_w)
|
||||||
}
|
}
|
||||||
|
@ -98,14 +98,14 @@ func (d *WorkflowExecutions) GetName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *WorkflowExecutions) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
func (d *WorkflowExecutions) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||||
return NewShallowAccessor(request) // Create a new instance of the accessor
|
return NewAccessor(request) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *WorkflowExecutions) VerifyAuth(request *tools.APIRequest) bool {
|
func (d *WorkflowExecutions) VerifyAuth(request *tools.APIRequest) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *WorkflowExecutions) ToBookings(wf *workflow.Workflow) []*booking.Booking {
|
func (d *WorkflowExecutions) Book(wf *workflow.Workflow) []*booking.Booking {
|
||||||
booking := []*booking.Booking{}
|
booking := []*booking.Booking{}
|
||||||
for _, p := range wf.ProcessingResources {
|
for _, p := range wf.ProcessingResources {
|
||||||
booking = append(booking, d.toItemBooking(wf.GetByRelatedProcessing(p.GetID(), wf.IsStorage))...)
|
booking = append(booking, d.toItemBooking(wf.GetByRelatedProcessing(p.GetID(), wf.IsStorage))...)
|
||||||
|
@ -16,11 +16,6 @@ import (
|
|||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Schedule struct {
|
|
||||||
Start time.Time
|
|
||||||
End *time.Time
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* WorkflowSchedule is a struct that contains the scheduling information of a workflow
|
* WorkflowSchedule is a struct that contains the scheduling information of a workflow
|
||||||
* It contains the mode of the schedule (Task or Service), the name of the schedule, the start and end time of the schedule and the cron expression
|
* It contains the mode of the schedule (Task or Service), the name of the schedule, the start and end time of the schedule and the cron expression
|
||||||
@ -78,7 +73,7 @@ func (ws *WorkflowSchedule) CheckBooking(wfID string, caller *tools.HTTPCaller)
|
|||||||
return false, wf, []*WorkflowExecutions{}, err
|
return false, wf, []*WorkflowExecutions{}, err
|
||||||
}
|
}
|
||||||
for _, exec := range execs {
|
for _, exec := range execs {
|
||||||
bookings := exec.ToBookings(wf)
|
bookings := exec.Book(wf)
|
||||||
for _, booking := range bookings {
|
for _, booking := range bookings {
|
||||||
_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
_, err := (&peer.Peer{}).LaunchPeerExecution(booking.DestPeerID, "",
|
||||||
tools.BOOKING, tools.POSTCHECK, booking.Serialize(booking), caller)
|
tools.BOOKING, tools.POSTCHECK, booking.Serialize(booking), caller)
|
||||||
@ -243,6 +238,11 @@ func (ws *WorkflowSchedule) getDates() ([]Schedule, error) {
|
|||||||
return schedule, nil
|
return schedule, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Schedule struct {
|
||||||
|
Start time.Time
|
||||||
|
End *time.Time
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO : LARGEST GRAIN PLANIFYING THE WORKFLOW WHEN OPTION IS SET
|
* TODO : LARGEST GRAIN PLANIFYING THE WORKFLOW WHEN OPTION IS SET
|
||||||
* SET PROTECTION BORDER TIME
|
* SET PROTECTION BORDER TIME
|
||||||
|
Loading…
Reference in New Issue
Block a user