add exec
This commit is contained in:
parent
6e5c873796
commit
a0f436b3e1
@ -22,7 +22,8 @@ import (
|
||||
* AbstractResource is a struct that represents a resource
|
||||
* it defines the resource data
|
||||
*/
|
||||
type AbsResource struct {
|
||||
|
||||
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
|
||||
@ -30,36 +31,32 @@ type AbsResource 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
|
||||
}
|
||||
|
||||
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{}
|
||||
@ -123,7 +120,7 @@ type ResourceInstance[T ResourcePartnerITF] struct {
|
||||
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
|
||||
// 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"`
|
||||
}
|
||||
@ -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'
|
||||
*/
|
||||
|
@ -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*/
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user