diff --git a/models/resources/compute.go b/models/resources/compute.go index e96bc98..74dedd6 100644 --- a/models/resources/compute.go +++ b/models/resources/compute.go @@ -16,7 +16,7 @@ import ( * it defines the resource compute */ type ComputeResource struct { - AbstractResource[*ComputeResourceInstance] + AbstractIntanciatedResource[*ComputeResourceInstance] Architecture string `json:"architecture,omitempty" bson:"architecture,omitempty"` // Architecture is the architecture Infrastructure common.InfrastructureType `json:"infrastructure,omitempty" bson:"infrastructure,omitempty"` } diff --git a/models/resources/data.go b/models/resources/data.go index 88bdb90..52f5387 100644 --- a/models/resources/data.go +++ b/models/resources/data.go @@ -23,7 +23,7 @@ const ( * it defines the resource data */ type DataResource struct { - AbstractResource[*ResourceInstance[*DataResourcePartnership]] + AbstractIntanciatedResource[*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 diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index 1c45020..286518a 100644 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -30,6 +30,7 @@ type ResourceInterface interface { ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF SetAllowedInstances(request *tools.APIRequest) SetResourceModel(model *resource_model.ResourceModel) + SetSelection(selection *int) } type ResourceInstanceITF interface { diff --git a/models/resources/processing.go b/models/resources/processing.go index 8369e13..a0509e6 100644 --- a/models/resources/processing.go +++ b/models/resources/processing.go @@ -24,7 +24,7 @@ type ProcessingUsage struct { * it defines the resource processing */ type ProcessingResource struct { - AbstractResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]] + AbstractIntanciatedResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]] 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 diff --git a/models/resources/resource.go b/models/resources/resource.go index 1ccda72..39299c5 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -22,7 +22,7 @@ import ( * it defines the resource data */ -type AbstractResource[T ResourceInstanceITF] struct { +type AbstractResource struct { utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) Logo string `json:"logo,omitempty" bson:"logo,omitempty" validate:"required"` // Logo is the logo of the resource Description string `json:"description,omitempty" bson:"description,omitempty"` // Description is the description of the resource @@ -30,37 +30,45 @@ type AbstractResource[T ResourceInstanceITF] struct { Owners []utils.Owner `json:"owners,omitempty" bson:"owners,omitempty"` // Owners is the list of owners of the resource ResourceModel *resource_model.ResourceModel `json:"resource_model,omitempty" bson:"resource_model,omitempty"` // ResourceModel is the model of the resource UsageRestrictions string `bson:"usage_restrictions,omitempty" json:"usage_restrictions,omitempty"` - SelectedInstanceIndex int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance - Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource + SelectedInstanceIndex *int `json:"selected_instance_index,omitempty" bson:"selected_instance_index,omitempty"` // SelectedInstance is the selected instance } -func (r *AbstractResource[T]) Transform() utils.DBObject { +func (r *AbstractResource) SetSelection(selection *int) { + r.SelectedInstanceIndex = selection +} + +func (r *AbstractResource) Transform() utils.DBObject { return r } -func (r *AbstractResource[T]) StoreDraftDefault() { +func (r *AbstractResource) StoreDraftDefault() { r.IsDraft = true } -func (r *AbstractResource[T]) CanUpdate(set utils.DBObject) (bool, utils.DBObject) { +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 } return r.IsDraft != set.IsDrafted() && set.IsDrafted(), set } -func (r *AbstractResource[T]) CanDelete() bool { +func (r *AbstractResource) CanDelete() bool { return r.IsDraft // only draft bookings can be deleted } -func (ao *AbstractResource[T]) GetAccessor(request *tools.APIRequest) utils.Accessor { +func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor { return nil } -func (abs *AbstractResource[T]) SetResourceModel(model *resource_model.ResourceModel) { +func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) { abs.ResourceModel = model } -func (abs *AbstractResource[T]) ConvertToPricedResource( +type AbstractIntanciatedResource[T ResourceInstanceITF] struct { + AbstractResource // AbstractResource contains the basic fields of an object (id, name) + Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource +} + +func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource( t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { instances := map[string]string{} profiles := map[string][]pricing.PricingProfileITF{} @@ -79,11 +87,11 @@ func (abs *AbstractResource[T]) ConvertToPricedResource( } } -func (abs *AbstractResource[T]) SetAllowedInstances(request *tools.APIRequest) { +func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) { abs.Instances = verifyAuthAction[T](abs.Instances, request) } -func (d *AbstractResource[T]) Trim() { +func (d *AbstractIntanciatedResource[T]) Trim() { if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok { for _, instance := range d.Instances { instance.ClearPeerGroups() @@ -91,7 +99,7 @@ func (d *AbstractResource[T]) Trim() { } } -func (abs *AbstractResource[T]) VerifyAuth(request *tools.APIRequest) bool { +func (abs *AbstractIntanciatedResource[T]) VerifyAuth(request *tools.APIRequest) bool { return len(verifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(request) } @@ -129,7 +137,7 @@ type ResourceInstance[T ResourcePartnerITF] struct { Location GeoPoint `json:"location,omitempty" bson:"location,omitempty"` Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"` AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"` - Partnerships []T `json:"partner_resource,omitempty" bson:"partner_resource,omitempty"` + Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"` } func (ri *ResourceInstance[T]) GetID() string { diff --git a/models/resources/storage.go b/models/resources/storage.go index 87b5da4..aa98ff9 100644 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -15,10 +15,10 @@ import ( * it defines the resource storage */ type StorageResource struct { - AbstractResource[*StorageResourceInstance] // AbstractResource contains the basic fields of an object (id, name) - Type common.StorageType `bson:"type,omitempty"` // Type is the type of the storage - TypeJSON string `json:"type,omitempty"` - Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage + AbstractIntanciatedResource[*StorageResourceInstance] // AbstractResource contains the basic fields of an object (id, name) + Type common.StorageType `bson:"type,omitempty"` // Type is the type of the storage + TypeJSON string `json:"type,omitempty"` + Acronym string `bson:"acronym,omitempty" json:"acronym,omitempty"` // Acronym is the acronym of the storage } func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor { diff --git a/models/resources/workflow.go b/models/resources/workflow.go index 1f1c026..ed36a7e 100644 --- a/models/resources/workflow.go +++ b/models/resources/workflow.go @@ -2,8 +2,6 @@ package resources import ( "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" ) @@ -12,51 +10,23 @@ type abstractWorkflowResource struct { WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"` // WorkflowID is the ID of the native workflow } +type WorkflowResourcePricingProfile struct{} + // WorkflowResource is a struct that represents a workflow resource // it defines the resource workflow type WorkflowResource struct { - utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) - Logo string `json:"logo,omitempty" bson:"logo,omitempty" validate:"required"` // Logo is the logo of the resource - Description string `json:"description,omitempty" bson:"description,omitempty"` // Description is the description of the resource - ShortDescription string `json:"short_description,omitempty" bson:"short_description,omitempty" validate:"required"` // ShortDescription is the short description of the resource - Owners []utils.Owner `json:"owners,omitempty" bson:"owners,omitempty"` // Owners is the list of owners of the resource - ResourceModel *resource_model.ResourceModel `json:"resource_model,omitempty" bson:"resource_model,omitempty"` // ResourceModel is the model of the resource - UsageRestrictions string `bson:"usage_restrictions,omitempty" json:"usage_restrictions,omitempty"` + AbstractResource abstractWorkflowResource } -func (r *WorkflowResource) Transform() utils.DBObject { - return r +func (d *WorkflowResource) Trim() { + /* EMPTY */ } - -func (r *WorkflowResource) StoreDraftDefault() { - r.IsDraft = true +func (abs *WorkflowResource) VerifyAuth(request *tools.APIRequest) bool { + return true } -func (r *WorkflowResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) { - if r.IsDraft != set.IsDrafted() && set.IsDrafted() { - return true, set // only state can be updated - } - return r.IsDraft != set.IsDrafted() && set.IsDrafted(), set -} - -func (r *WorkflowResource) CanDelete() bool { - return r.IsDraft // only draft bookings can be deleted -} - -func (ao *WorkflowResource) GetAccessor(request *tools.APIRequest) utils.Accessor { - return nil -} - -func (abs *WorkflowResource) SetResourceModel(model *resource_model.ResourceModel) { - abs.ResourceModel = model -} - -func (w *WorkflowResource) Trim() { - /*EMPTY AND PROUD TO BE*/ -} - func (w *WorkflowResource) SetAllowedInstances(request *tools.APIRequest) { - /*EMPTY AND PROUD TO BE*/ + /* EMPTY */ } func (w *WorkflowResource) ConvertToPricedResource(