light modification
This commit is contained in:
parent
abd6c1d712
commit
ad69c04951
@ -25,6 +25,15 @@ 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{} })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *ComputeResource) ConvertToPricedResource(
|
||||||
|
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||||
|
p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request)
|
||||||
|
priced := p.(*PricedResource)
|
||||||
|
return &PricedComputeResource{
|
||||||
|
PricedResource: *priced,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type ComputeNode struct {
|
type ComputeNode struct {
|
||||||
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
Name string `json:"name,omitempty" bson:"name,omitempty"`
|
||||||
Quantity int64 `json:"quantity" bson:"quantity" default:"1"`
|
Quantity int64 `json:"quantity" bson:"quantity" default:"1"`
|
||||||
|
@ -41,6 +41,15 @@ func (d *DataResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
|||||||
return NewAccessor[*DataResource](tools.DATA_RESOURCE, request, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor
|
return NewAccessor[*DataResource](tools.DATA_RESOURCE, request, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (abs *DataResource) ConvertToPricedResource(
|
||||||
|
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||||
|
p := abs.AbstractIntanciatedResource.ConvertToPricedResource(t, request)
|
||||||
|
priced := p.(*PricedResource)
|
||||||
|
return &PricedDataResource{
|
||||||
|
PricedResource: *priced,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type DataResourcePartnership struct {
|
type DataResourcePartnership struct {
|
||||||
ResourcePartnerShip[*DataResourcePricingProfile]
|
ResourcePartnerShip[*DataResourcePricingProfile]
|
||||||
MaxDownloadableGbAllowed float64 `json:"allowed_gb,omitempty" bson:"allowed_gb,omitempty"`
|
MaxDownloadableGbAllowed float64 `json:"allowed_gb,omitempty" bson:"allowed_gb,omitempty"`
|
||||||
|
@ -1,36 +1,18 @@
|
|||||||
package resources
|
package resources
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
"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/resources/resource_model"
|
"cloud.o-forge.io/core/oc-lib/models/resources/resource_model"
|
||||||
"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"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShallowResourceInterface interface {
|
|
||||||
utils.DBObject
|
|
||||||
GetType() tools.DataType
|
|
||||||
GetCreatorID() string
|
|
||||||
GetPricingID() string
|
|
||||||
GetLocationStart() *time.Time
|
|
||||||
GetLocationEnd() *time.Time
|
|
||||||
GetExplicitDurationInS() float64
|
|
||||||
SetStartUsage(start time.Time)
|
|
||||||
SetEndUsage(end time.Time)
|
|
||||||
GetPartnership(request *tools.APIRequest) ResourcePartnerITF
|
|
||||||
SetResourceModel(model *resource_model.ResourceModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResourceInterface interface {
|
type ResourceInterface interface {
|
||||||
utils.DBObject
|
utils.DBObject
|
||||||
Trim()
|
Trim()
|
||||||
Transform() utils.DBObject
|
|
||||||
ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF
|
ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF
|
||||||
SetAllowedInstances(request *tools.APIRequest)
|
SetAllowedInstances(request *tools.APIRequest)
|
||||||
SetResourceModel(model *resource_model.ResourceModel)
|
SetResourceModel(model *resource_model.ResourceModel)
|
||||||
SetSelection(selection *int)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResourceInstanceITF interface {
|
type ResourceInstanceITF interface {
|
||||||
|
@ -33,17 +33,14 @@ type AbstractResource struct {
|
|||||||
SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance
|
SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AbstractResource) SetSelection(selection *int) {
|
func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||||
r.SelectedInstanceIndex = selection
|
return nil
|
||||||
}
|
|
||||||
|
|
||||||
func (r *AbstractResource) Transform() utils.DBObject {
|
|
||||||
return r
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AbstractResource) StoreDraftDefault() {
|
func (r *AbstractResource) StoreDraftDefault() {
|
||||||
r.IsDraft = true
|
r.IsDraft = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *AbstractResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
func (r *AbstractResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
|
||||||
if r.IsDraft != set.IsDrafted() && set.IsDrafted() {
|
if r.IsDraft != set.IsDrafted() && set.IsDrafted() {
|
||||||
return true, set // only state can be updated
|
return true, set // only state can be updated
|
||||||
@ -55,10 +52,6 @@ func (r *AbstractResource) CanDelete() bool {
|
|||||||
return r.IsDraft // only draft bookings can be deleted
|
return r.IsDraft // only draft bookings can be deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) {
|
func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) {
|
||||||
abs.ResourceModel = model
|
abs.ResourceModel = model
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,6 @@ func (dca *resourceMongoAccessor[T]) LoadOne(id string) (utils.DBObject, int, er
|
|||||||
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
|
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
|
||||||
}
|
}
|
||||||
d.(T).SetAllowedInstances(dca.Request)
|
d.(T).SetAllowedInstances(dca.Request)
|
||||||
d = d.(T).Transform()
|
|
||||||
return d, 200, nil
|
return d, 200, nil
|
||||||
}, dca)
|
}, dca)
|
||||||
}
|
}
|
||||||
@ -74,7 +73,6 @@ func (wfa *resourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObj
|
|||||||
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
|
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
|
||||||
}
|
}
|
||||||
d.(T).SetAllowedInstances(wfa.Request)
|
d.(T).SetAllowedInstances(wfa.Request)
|
||||||
d = d.(T).Transform()
|
|
||||||
return d
|
return d
|
||||||
}, isDraft, wfa)
|
}, isDraft, wfa)
|
||||||
}
|
}
|
||||||
@ -87,7 +85,6 @@ func (wfa *resourceMongoAccessor[T]) Search(filters *dbs.Filters, search string,
|
|||||||
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
|
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
|
||||||
}
|
}
|
||||||
d.(T).SetAllowedInstances(wfa.Request)
|
d.(T).SetAllowedInstances(wfa.Request)
|
||||||
d = d.(T).Transform()
|
|
||||||
return d
|
return d
|
||||||
}, isDraft, wfa)
|
}, isDraft, wfa)
|
||||||
}
|
}
|
||||||
|
@ -25,10 +25,6 @@ func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor
|
|||||||
return NewAccessor[*StorageResource](tools.STORAGE_RESOURCE, request, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor
|
return NewAccessor[*StorageResource](tools.STORAGE_RESOURCE, request, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *StorageResource) Transform() utils.DBObject {
|
|
||||||
return r
|
|
||||||
}
|
|
||||||
|
|
||||||
type StorageResourceInstance struct {
|
type StorageResourceInstance struct {
|
||||||
ResourceInstance[*StorageResourcePartnership]
|
ResourceInstance[*StorageResourcePartnership]
|
||||||
Local bool `bson:"local" json:"local"`
|
Local bool `bson:"local" json:"local"`
|
||||||
|
@ -2,6 +2,7 @@ package resources
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"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/utils"
|
||||||
"cloud.o-forge.io/core/oc-lib/tools"
|
"cloud.o-forge.io/core/oc-lib/tools"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,6 +20,10 @@ type WorkflowResource struct {
|
|||||||
abstractWorkflowResource
|
abstractWorkflowResource
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
|
||||||
|
return NewAccessor[*ComputeResource](tools.WORKFLOW_RESOURCE, request, func() utils.DBObject { return &WorkflowResource{} })
|
||||||
|
}
|
||||||
|
|
||||||
func (d *WorkflowResource) Trim() {
|
func (d *WorkflowResource) Trim() {
|
||||||
/* EMPTY */
|
/* EMPTY */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user