From a0f436b3e162f2ce6719eece52d4d61b014f32ef Mon Sep 17 00:00:00 2001 From: mr Date: Mon, 13 Jan 2025 14:52:41 +0100 Subject: [PATCH] add exec --- models/resources/resource.go | 57 +++++++++++++++--------------------- models/resources/workflow.go | 32 +++++++++++++++++++- 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/models/resources/resource.go b/models/resources/resource.go index a56823a..4744da0 100644 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -22,44 +22,41 @@ import ( * AbstractResource is a struct that represents a resource * it defines the resource data */ -type AbsResource 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"` + +type AbstractResource[T ResourceInstanceITF] 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"` + 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 } -func (r *AbsResource) StoreDraftDefault() { +func (r *AbstractResource[T]) StoreDraftDefault() { r.IsDraft = true } -func (r *AbsResource) CanUpdate(set utils.DBObject) (bool, utils.DBObject) { +func (r *AbstractResource[T]) 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 *AbsResource) CanDelete() bool { +func (r *AbstractResource[T]) CanDelete() bool { return r.IsDraft // only draft bookings can be deleted } -func (ao *AbsResource) GetAccessor(request *tools.APIRequest) utils.Accessor { +func (ao *AbstractResource[T]) GetAccessor(request *tools.APIRequest) utils.Accessor { return nil } -func (abs *AbsResource) SetResourceModel(model *resource_model.ResourceModel) { +func (abs *AbstractResource[T]) SetResourceModel(model *resource_model.ResourceModel) { abs.ResourceModel = model } -type AbstractResource[T ResourceInstanceITF] struct { - AbsResource - 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 -} - func (abs *AbstractResource[T]) ConvertToPricedResource( t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF { instances := map[string]string{} @@ -119,13 +116,13 @@ func verifyAuthAction[T ResourceInstanceITF](baseInstance []T, request *tools.AP } type ResourceInstance[T ResourcePartnerITF] struct { - UUID string `json:"id,omitempty" bson:"id,omitempty"` - Name string `json:"name,omitempty" bson:"name,omitempty"` - Location geopoint.GeoPoint `json:"location,omitempty" bson:"location,omitempty"` - Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"` - Source string `bson:"source,omitempty" json:"source,omitempty"` // Source is the source of the storage - AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"` - Partnerships []T `json:"partner_resource,omitempty" bson:"partner_resource,omitempty"` + UUID string `json:"id,omitempty" bson:"id,omitempty"` + Name string `json:"name,omitempty" bson:"name,omitempty"` + Location geopoint.GeoPoint `json:"location,omitempty" bson:"location,omitempty"` + Country countries.CountryCode `json:"country,omitempty" bson:"country,omitempty"` + // Url string `json:"url,omitempty" bson:"url,omitempty"` + AccessProtocol string `json:"access_protocol,omitempty" bson:"access_protocol,omitempty"` + Partnerships []T `json:"partner_resource,omitempty" bson:"partner_resource,omitempty"` } func (ri *ResourceInstance[T]) GetID() string { @@ -188,11 +185,3 @@ func (rp *ResourcePartnerShip[T]) GetPeerGroups() map[string][]string { func (rp *ResourcePartnerShip[T]) ClearPeerGroups() { rp.PeerGroups = map[string][]string{} } - -/* --> when a workflow should book a resource --> it must be able to book a resource for a particular time --> the resource should be available for the time --> we must be able to parameter the resource for the time --> before bookin' -*/ diff --git a/models/resources/workflow.go b/models/resources/workflow.go index 894e5a3..f19345f 100644 --- a/models/resources/workflow.go +++ b/models/resources/workflow.go @@ -2,6 +2,8 @@ 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" ) @@ -13,10 +15,38 @@ type abstractWorkflowResource struct { // WorkflowResource is a struct that represents a workflow resource // it defines the resource workflow type WorkflowResource struct { - AbsResource + 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"` abstractWorkflowResource } +func (r *WorkflowResource) StoreDraftDefault() { + r.IsDraft = 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*/ }