massive draft for payment process (UNCOMPLETE)
This commit is contained in:
@@ -1,18 +1,96 @@
|
||||
package resources
|
||||
|
||||
import (
|
||||
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||
"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"
|
||||
)
|
||||
|
||||
// WorkflowResource is a struct that represents a workflow resource
|
||||
// it defines the resource workflow
|
||||
type WorkflowResource struct {
|
||||
resource_model.AbstractResource
|
||||
// COMPLEX SHOULD BE REFACTORED
|
||||
// we don't have any information about the accessor
|
||||
type abstractWorkflowResource struct {
|
||||
ExploitedResourceSet
|
||||
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"` // WorkflowID is the ID of the native workflow
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*WorkflowResource](tools.WORKFLOW_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &WorkflowResource{} }) // Create a new instance of the accessor
|
||||
// WorkflowResource is a struct that represents a workflow resource
|
||||
// it defines the resource workflow
|
||||
type WorkflowResource struct {
|
||||
AbstractResource[*ResourceInstance[*ResourcePartnerShip[*WorkflowResourcePricingProfile]]]
|
||||
abstractWorkflowResource
|
||||
}
|
||||
|
||||
type CustomizedWorkflowResource struct {
|
||||
AbstractCustomizedResource[*ResourceInstance[*ResourcePartnerShip[*WorkflowResourcePricingProfile]]]
|
||||
abstractWorkflowResource
|
||||
}
|
||||
|
||||
func (r *CustomizedWorkflowResource) GetType() tools.DataType {
|
||||
return tools.WORKFLOW_RESOURCE
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||
return NewAccessor[*WorkflowResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} }) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
type WorkflowResourcePricingProfile struct {
|
||||
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) IsBuying() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
/*
|
||||
* Missing wich Instance is selected
|
||||
*
|
||||
*/
|
||||
|
||||
func (p *WorkflowResourcePricingProfile) GetPrice(amountOfData float64, val float64, start time.Time, end time.Time, request *tools.APIRequest, params ...string) (float64, error) {
|
||||
// load workflow
|
||||
price := float64(0)
|
||||
pp, err := getPrice[*CustomizedDataResource](p.DataResources, amountOfData, val, start, end, request, params...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
price += pp
|
||||
pp, err = getPrice[*CustomizedStorageResource](p.StorageResources, amountOfData, val, start, end, request, params...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
price += pp
|
||||
pp, err = getPrice[*CustomizedProcessingResource](p.ProcessingResources, amountOfData, val, start, end, request, params...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
price += pp
|
||||
pp, err = getPrice[*CustomizedComputeResource](p.ComputeResources, amountOfData, val, start, end, request, params...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
price += pp
|
||||
pp, err = getPrice[*CustomizedWorkflowResource](p.WorkflowResources, amountOfData, val, start, end, request, params...)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
price += pp
|
||||
return price, nil
|
||||
}
|
||||
|
||||
func getPrice[T ShallowResourceInterface](arr []T, amountOfData float64, val float64, start time.Time, end time.Time, request *tools.APIRequest, params ...string) (float64, error) {
|
||||
// load workflow
|
||||
price := float64(0)
|
||||
for _, data := range arr {
|
||||
partner := data.GetPartnership(request)
|
||||
pricing := partner.GetPricing(data.GetPricingID())
|
||||
pp, err := pricing.GetPrice(amountOfData, val, start, end, request)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
price += pp
|
||||
}
|
||||
return price, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user