light modification

This commit is contained in:
mr 2025-01-15 09:20:26 +01:00
parent abd6c1d712
commit ad69c04951
7 changed files with 26 additions and 35 deletions

View File

@ -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{} })
}
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 {
Name string `json:"name,omitempty" bson:"name,omitempty"`
Quantity int64 `json:"quantity" bson:"quantity" default:"1"`

View File

@ -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
}
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 {
ResourcePartnerShip[*DataResourcePricingProfile]
MaxDownloadableGbAllowed float64 `json:"allowed_gb,omitempty" bson:"allowed_gb,omitempty"`

View File

@ -1,36 +1,18 @@
package resources
import (
"time"
"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/utils"
"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 {
utils.DBObject
Trim()
Transform() utils.DBObject
ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF
SetAllowedInstances(request *tools.APIRequest)
SetResourceModel(model *resource_model.ResourceModel)
SetSelection(selection *int)
}
type ResourceInstanceITF interface {

View File

@ -33,17 +33,14 @@ type AbstractResource struct {
SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance
}
func (r *AbstractResource) SetSelection(selection *int) {
r.SelectedInstanceIndex = selection
}
func (r *AbstractResource) Transform() utils.DBObject {
return r
func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return nil
}
func (r *AbstractResource) StoreDraftDefault() {
r.IsDraft = true
}
func (r *AbstractResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) {
if r.IsDraft != set.IsDrafted() && set.IsDrafted() {
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
}
func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
return nil
}
func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) {
abs.ResourceModel = model
}

View File

@ -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).SetAllowedInstances(dca.Request)
d = d.(T).Transform()
return d, 200, nil
}, dca)
}
@ -74,7 +73,6 @@ func (wfa *resourceMongoAccessor[T]) LoadAll(isDraft bool) ([]utils.ShallowDBObj
d.(T).SetResourceModel(resources[0].(*resource_model.ResourceModel))
}
d.(T).SetAllowedInstances(wfa.Request)
d = d.(T).Transform()
return d
}, 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).SetAllowedInstances(wfa.Request)
d = d.(T).Transform()
return d
}, isDraft, wfa)
}

View File

@ -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
}
func (r *StorageResource) Transform() utils.DBObject {
return r
}
type StorageResourceInstance struct {
ResourceInstance[*StorageResourcePartnership]
Local bool `bson:"local" json:"local"`

View File

@ -2,6 +2,7 @@ package resources
import (
"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"
)
@ -19,6 +20,10 @@ type WorkflowResource struct {
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() {
/* EMPTY */
}