Compare commits

..

No commits in common. "918006302bb44ea07c55a7fc47d1f6725c556f89" and "78157b80d26743596534f03e271cd47c10426b81" have entirely different histories.

9 changed files with 62 additions and 38 deletions

1
go.mod
View File

@ -38,6 +38,7 @@ require (
github.com/klauspost/compress v1.17.9 // indirect
github.com/kr/text v0.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/marcinwyszynski/geopoint v0.0.0-20140302213024-cf2a6f750c5b
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect

2
go.sum
View File

@ -55,6 +55,8 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/marcinwyszynski/geopoint v0.0.0-20140302213024-cf2a6f750c5b h1:XBF8THPBy28s2ryI7+/Jf/847unLWxYMpJveX5Kox+0=
github.com/marcinwyszynski/geopoint v0.0.0-20140302213024-cf2a6f750c5b/go.mod h1:z1oqhOuuYpPHmUmAK2aNygKFlPdb4o3PppQnVTRFdrI=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=

View File

@ -16,7 +16,7 @@ import (
* it defines the resource compute
*/
type ComputeResource struct {
AbstractIntanciatedResource[*ComputeResourceInstance]
AbstractResource[*ComputeResourceInstance]
Architecture string `json:"architecture,omitempty" bson:"architecture,omitempty"` // Architecture is the architecture
Infrastructure common.InfrastructureType `json:"infrastructure,omitempty" bson:"infrastructure,omitempty"`
}

View File

@ -23,7 +23,7 @@ const (
* it defines the resource data
*/
type DataResource struct {
AbstractIntanciatedResource[*ResourceInstance[*DataResourcePartnership]]
AbstractResource[*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

View File

@ -30,7 +30,6 @@ 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 {

View File

@ -24,7 +24,7 @@ type ProcessingUsage struct {
* it defines the resource processing
*/
type ProcessingResource struct {
AbstractIntanciatedResource[*ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]]
AbstractResource[*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

View File

@ -22,7 +22,7 @@ import (
* it defines the resource data
*/
type AbstractResource 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,45 +30,37 @@ type AbstractResource 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
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 *AbstractResource) SetSelection(selection *int) {
r.SelectedInstanceIndex = selection
}
func (r *AbstractResource) Transform() utils.DBObject {
func (r *AbstractResource[T]) Transform() utils.DBObject {
return r
}
func (r *AbstractResource) StoreDraftDefault() {
func (r *AbstractResource[T]) StoreDraftDefault() {
r.IsDraft = true
}
func (r *AbstractResource) 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 *AbstractResource) CanDelete() bool {
func (r *AbstractResource[T]) CanDelete() bool {
return r.IsDraft // only draft bookings can be deleted
}
func (ao *AbstractResource) GetAccessor(request *tools.APIRequest) utils.Accessor {
func (ao *AbstractResource[T]) GetAccessor(request *tools.APIRequest) utils.Accessor {
return nil
}
func (abs *AbstractResource) SetResourceModel(model *resource_model.ResourceModel) {
func (abs *AbstractResource[T]) SetResourceModel(model *resource_model.ResourceModel) {
abs.ResourceModel = model
}
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(
func (abs *AbstractResource[T]) ConvertToPricedResource(
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
instances := map[string]string{}
profiles := map[string][]pricing.PricingProfileITF{}
@ -87,11 +79,11 @@ func (abs *AbstractIntanciatedResource[T]) ConvertToPricedResource(
}
}
func (abs *AbstractIntanciatedResource[T]) SetAllowedInstances(request *tools.APIRequest) {
func (abs *AbstractResource[T]) SetAllowedInstances(request *tools.APIRequest) {
abs.Instances = verifyAuthAction[T](abs.Instances, request)
}
func (d *AbstractIntanciatedResource[T]) Trim() {
func (d *AbstractResource[T]) Trim() {
if ok, _ := (&peer.Peer{AbstractObject: utils.AbstractObject{UUID: d.CreatorID}}).IsMySelf(); !ok {
for _, instance := range d.Instances {
instance.ClearPeerGroups()
@ -99,7 +91,7 @@ func (d *AbstractIntanciatedResource[T]) Trim() {
}
}
func (abs *AbstractIntanciatedResource[T]) VerifyAuth(request *tools.APIRequest) bool {
func (abs *AbstractResource[T]) VerifyAuth(request *tools.APIRequest) bool {
return len(verifyAuthAction[T](abs.Instances, request)) > 0 || abs.AbstractObject.VerifyAuth(request)
}
@ -137,7 +129,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:"partnerships,omitempty" bson:"partnerships,omitempty"`
Partnerships []T `json:"partner_resource,omitempty" bson:"partner_resource,omitempty"`
}
func (ri *ResourceInstance[T]) GetID() string {

View File

@ -15,10 +15,10 @@ import (
* it defines the resource storage
*/
type StorageResource struct {
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
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
}
func (d *StorageResource) GetAccessor(request *tools.APIRequest) utils.Accessor {

View File

@ -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"
)
@ -10,23 +12,51 @@ 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 {
AbstractResource
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 (d *WorkflowResource) Trim() {
/* EMPTY */
func (r *WorkflowResource) Transform() utils.DBObject {
return r
}
func (abs *WorkflowResource) VerifyAuth(request *tools.APIRequest) bool {
return true
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*/
}
func (w *WorkflowResource) SetAllowedInstances(request *tools.APIRequest) {
/* EMPTY */
/*EMPTY AND PROUD TO BE*/
}
func (w *WorkflowResource) ConvertToPricedResource(