diff --git a/models/common/models/access_configuration.go b/models/common/models/access_configuration.go index a428854..821b3ef 100644 --- a/models/common/models/access_configuration.go +++ b/models/common/models/access_configuration.go @@ -6,8 +6,6 @@ type Container struct { Args string `json:"args,omitempty" bson:"args,omitempty"` // Args is the container arguments Env map[string]string `json:"env,omitempty" bson:"env,omitempty"` // Env is the container environment variables Volumes map[string]string `json:"volumes,omitempty" bson:"volumes,omitempty"` // Volumes is the container volumes - - Exposes []Expose `bson:"exposes,omitempty" json:"exposes,omitempty"` // Expose is the execution } type Expose struct { diff --git a/models/resources/data.go b/models/resources/data.go index eee55fc..68f9508 100755 --- a/models/resources/data.go +++ b/models/resources/data.go @@ -37,6 +37,15 @@ func (r *DataResource) GetType() string { return tools.DATA_RESOURCE.String() } +func (ri *DataResource) StoreDraftDefault() { + ri.AbstractObject.StoreDraftDefault() + ri.Env = append(ri.Env, models.Param{ + Attr: "source", + Value: "[resource]instance.source", + Readonly: true, + }) +} + func (abs *DataResource) ConvertToPricedResource(t tools.DataType, selectedInstance *int, selectedPartnership *int, selectedBuyingStrategy *int, selectedStrategy *int, selectedBookingModeIndex *int, request *tools.APIRequest) (pricing.PricedItemITF, error) { if t != tools.DATA_RESOURCE { return nil, errors.New("not the proper type expected : cannot convert to priced resource : have " + t.String() + " wait Data") @@ -67,31 +76,6 @@ func NewDataInstance(name string, peerID string) ResourceInstanceITF { } } -func (ri *DataInstance) StoreDraftDefault() { - // Enforce peerless invariant: a public-origin instance cannot have peer ownership. - if ri.Origin.Ref != "" && (ri.CreatorID != "" || len(ri.Partnerships) > 0) { - // Strip partnerships and creator: the structural invariant wins. - // Origin.Ref presence is the authoritative signal that this is peerless. - ri.CreatorID = "" - ri.Partnerships = nil - } - found := false - for _, p := range ri.ResourceInstance.Env { - if p.Attr == "source" { - found = true - break - } - } - if !found { - ri.ResourceInstance.Env = append(ri.ResourceInstance.Env, models.Param{ - Attr: "source", - Value: ri.Source, - Readonly: true, - }) - } - ri.ResourceInstance.StoreDraftDefault() -} - type DataResourcePartnership struct { ResourcePartnerShip[*DataResourcePricingProfile] MaxDownloadableGbAllowed float64 `json:"allowed_gb,omitempty" bson:"allowed_gb,omitempty"` @@ -102,7 +86,7 @@ type DataResourcePartnership struct { type DataResourcePricingStrategy int const ( - PER_DOWNLOAD DataResourcePricingStrategy = iota + 6 + PER_DOWNLOAD DataResourcePricingStrategy = iota + 7 PER_TB_DOWNLOADED PER_GB_DOWNLOADED PER_MB_DOWNLOADED diff --git a/models/resources/interfaces.go b/models/resources/interfaces.go index 9f34113..58c8bad 100755 --- a/models/resources/interfaces.go +++ b/models/resources/interfaces.go @@ -22,6 +22,7 @@ type ResourceInterface interface { SetAllowedInstances(request *tools.APIRequest, instance_id ...string) []ResourceInstanceITF AddInstances(instance ResourceInstanceITF) GetSelectedInstance(index *int) ResourceInstanceITF + StoreDraftDefault() } type ResourceInstanceITF interface { @@ -30,8 +31,6 @@ type ResourceInstanceITF interface { GetName() string GetOrigin() OriginMeta IsPeerless() bool - StoreDraftDefault() - ClearEnv() FilterInstance(peerID string) GetProfile(peerID string, partnershipIndex *int, buying *int, strategy *int) pricing.PricingProfileITF GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF diff --git a/models/resources/processing.go b/models/resources/processing.go index 5f227b6..5e28f9f 100755 --- a/models/resources/processing.go +++ b/models/resources/processing.go @@ -52,15 +52,6 @@ type ProcessingInstance struct { ContentType string `json:"content_type,omitempty" bson:"content_type,omitempty"` } -func (ri *ProcessingInstance) StoreDraftDefault() { - // Enforce peerless invariant: a public-origin instance cannot have peer ownership. - if ri.Origin.Ref != "" && (ri.CreatorID != "" || len(ri.Partnerships) > 0) { - ri.CreatorID = "" - ri.Partnerships = nil - } - ri.ResourceInstance.StoreDraftDefault() -} - func NewProcessingInstance(name string, peerID string) ResourceInstanceITF { return &ProcessingInstance{ ResourceInstance: ResourceInstance[*ResourcePartnerShip[*ProcessingResourcePricingProfile]]{ diff --git a/models/resources/resource.go b/models/resources/resource.go index a112e70..a93076d 100755 --- a/models/resources/resource.go +++ b/models/resources/resource.go @@ -29,12 +29,23 @@ type AbstractResource struct { Owners []utils.Owner `json:"owners,omitempty" bson:"owners,omitempty"` // Owners is the list of owners of the resource UsageRestrictions string `bson:"usage_restrictions,omitempty" json:"usage_restrictions,omitempty"` AllowedBookingModes map[booking.BookingMode]*pricing.PricingVariation `bson:"allowed_booking_modes" json:"allowed_booking_modes"` + + Env []models.Param `json:"env,omitempty" bson:"env,omitempty"` + Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` + Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"` } func (abs *AbstractResource) FilterPeer(peerID string) *dbs.Filters { return nil } +func (ri *AbstractResource) ClearEnv() utils.DBObject { + ri.Env = []models.Param{} + ri.Inputs = []models.Param{} + ri.Outputs = []models.Param{} + return ri +} + func (r *AbstractResource) GetBookingModes() map[booking.BookingMode]*pricing.PricingVariation { if len(r.AllowedBookingModes) == 0 { return map[booking.BookingMode]*pricing.PricingVariation{ @@ -137,13 +148,6 @@ func ConvertToPricedResource[T pricing.PricingProfileITF](t tools.DataType, }, nil } -func (abs *AbstractInstanciatedResource[T]) ClearEnv() utils.DBObject { - for _, instance := range abs.Instances { - instance.ClearEnv() - } - return abs -} - func (r *AbstractInstanciatedResource[T]) GetSelectedInstance(selected *int) ResourceInstanceITF { if selected != nil && len(r.Instances) > *selected { return r.Instances[*selected] @@ -220,9 +224,6 @@ 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"` - Env []models.Param `json:"env,omitempty" bson:"env,omitempty"` - Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` - Outputs []models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"` Partnerships []T `json:"partnerships,omitempty" bson:"partnerships,omitempty"` @@ -266,12 +267,6 @@ func (ri *ResourceInstance[T]) FilterInstance(peerID string) { ri.Partnerships = partnerships } -func (ri *ResourceInstance[T]) ClearEnv() { - ri.Env = []models.Param{} - ri.Inputs = []models.Param{} - ri.Outputs = []models.Param{} -} - func (ri *ResourceInstance[T]) GetProfile(peerID string, partnershipIndex *int, buyingIndex *int, strategyIndex *int) pricing.PricingProfileITF { if ri.IsPeerless() { return pricing.GetDefaultPricingProfile() diff --git a/models/resources/storage.go b/models/resources/storage.go index 7df2e5e..eaea40b 100755 --- a/models/resources/storage.go +++ b/models/resources/storage.go @@ -44,6 +44,15 @@ func (abs *StorageResource) ConvertToPricedResource(t tools.DataType, selectedIn }, nil } +func (ri *StorageResource) StoreDraftDefault() { + ri.AbstractObject.StoreDraftDefault() + ri.Env = append(ri.Env, models.Param{ + Attr: "source", + Value: "[resource]instance.source", + Readonly: true, + }) +} + type StorageResourceInstance struct { ResourceInstance[*StorageResourcePartnership] Source string `bson:"source,omitempty" json:"source,omitempty"` // Source is the source of the storage @@ -72,30 +81,6 @@ func NewStorageResourceInstance(name string, peerID string) ResourceInstanceITF } } -func (ri *StorageResourceInstance) ClearEnv() { - ri.Env = []models.Param{} - ri.Inputs = []models.Param{} - ri.Outputs = []models.Param{} -} - -func (ri *StorageResourceInstance) StoreDraftDefault() { - found := false - for _, p := range ri.ResourceInstance.Env { - if p.Attr == "source" { - found = true - break - } - } - if !found { - ri.ResourceInstance.Env = append(ri.ResourceInstance.Env, models.Param{ - Attr: "source", - Value: ri.Source, - Readonly: true, - }) - } - ri.ResourceInstance.StoreDraftDefault() -} - type StorageResourcePartnership struct { ResourcePartnerShip[*StorageResourcePricingProfile] MaxSizeGBAllowed float64 `json:"allowed_gb,omitempty" bson:"allowed_gb,omitempty"` @@ -121,7 +106,7 @@ func (t PrivilegeStoragePricingStrategy) String() string { type StorageResourcePricingStrategy int const ( - PER_DATA_STORED StorageResourcePricingStrategy = iota + 6 + PER_DATA_STORED StorageResourcePricingStrategy = iota + 7 PER_TB_STORED PER_GB_STORED PER_MB_STORED diff --git a/models/resources/tests/data_test.go b/models/resources/tests/data_test.go index 755dfd4..05b6aab 100644 --- a/models/resources/tests/data_test.go +++ b/models/resources/tests/data_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - "cloud.o-forge.io/core/oc-lib/models/common/models" "cloud.o-forge.io/core/oc-lib/models/common/pricing" "cloud.o-forge.io/core/oc-lib/models/resources" "cloud.o-forge.io/core/oc-lib/tools" @@ -34,23 +33,6 @@ func TestDataResource_ConvertToPricedResource(t *testing.T) { assert.Nil(t, nilRes) } -func TestDataInstance_StoreDraftDefault(t *testing.T) { - di := &resources.DataInstance{ - Source: "test-src", - ResourceInstance: resources.ResourceInstance[*resources.DataResourcePartnership]{ - Env: []models.Param{}, - }, - } - di.StoreDraftDefault() - assert.Len(t, di.ResourceInstance.Env, 1) - assert.Equal(t, "source", di.ResourceInstance.Env[0].Attr) - assert.Equal(t, "test-src", di.ResourceInstance.Env[0].Value) - - // Call again, should not duplicate - di.StoreDraftDefault() - assert.Len(t, di.ResourceInstance.Env, 1) -} - func TestDataResourcePricingStrategy_GetQuantity(t *testing.T) { tests := []struct { strategy resources.DataResourcePricingStrategy diff --git a/models/resources/tests/storage_test.go b/models/resources/tests/storage_test.go index 11a82d0..e1720d5 100644 --- a/models/resources/tests/storage_test.go +++ b/models/resources/tests/storage_test.go @@ -3,7 +3,6 @@ package resources_test import ( "testing" - "cloud.o-forge.io/core/oc-lib/models/common/models" "cloud.o-forge.io/core/oc-lib/tools" "github.com/stretchr/testify/assert" @@ -37,36 +36,6 @@ func TestStorageResource_ConvertToPricedResource_InvalidType(t *testing.T) { assert.Nil(t, priced) } -func TestStorageResourceInstance_ClearEnv(t *testing.T) { - inst := &resources.StorageResourceInstance{ - ResourceInstance: resources.ResourceInstance[*resources.StorageResourcePartnership]{ - Env: []models.Param{{Attr: "A"}}, - Inputs: []models.Param{{Attr: "B"}}, - Outputs: []models.Param{{Attr: "C"}}, - }, - } - - inst.ClearEnv() - assert.Empty(t, inst.Env) - assert.Empty(t, inst.Inputs) - assert.Empty(t, inst.Outputs) -} - -func TestStorageResourceInstance_StoreDraftDefault(t *testing.T) { - inst := &resources.StorageResourceInstance{ - Source: "my-source", - ResourceInstance: resources.ResourceInstance[*resources.StorageResourcePartnership]{ - Env: []models.Param{}, - }, - } - - inst.StoreDraftDefault() - assert.Len(t, inst.Env, 1) - assert.Equal(t, "source", inst.Env[0].Attr) - assert.Equal(t, "my-source", inst.Env[0].Value) - assert.True(t, inst.Env[0].Readonly) -} - func TestStorageResourcePricingStrategy_GetQuantity(t *testing.T) { tests := []struct { strategy resources.StorageResourcePricingStrategy diff --git a/models/workflow/workflow.go b/models/workflow/workflow.go index 5aff6a8..a6bbc10 100644 --- a/models/workflow/workflow.go +++ b/models/workflow/workflow.go @@ -43,12 +43,15 @@ func (c ConfigItem) Get(key string) *int { type Workflow struct { utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) resources.ResourceSet - Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"` // Graph UI & logic representation of the workflow - ScheduleActive bool `json:"schedule_active" bson:"schedule_active"` // ScheduleActive is a flag that indicates if the schedule is active, if not the workflow is not scheduled and no execution or booking will be set + Graph *graph.Graph `bson:"graph,omitempty" json:"graph,omitempty"` // Graph UI & logic representation of the workflow // Schedule *WorkflowSchedule `bson:"schedule,omitempty" json:"schedule,omitempty"` // Schedule is the schedule of the workflow - Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow // AbstractWorkflow contains the basic fields of a workflow - Env []models.Param `json:"env,omitempty" bson:"env,omitempty"` - Inputs []models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` + Shared []string `json:"shared,omitempty" bson:"shared,omitempty"` // Shared is the ID of the shared workflow // AbstractWorkflow contains the basic fields of a workflow + + Env map[string]models.Param `json:"env,omitempty" bson:"env,omitempty"` + Inputs map[string]models.Param `json:"inputs,omitempty" bson:"inputs,omitempty"` + Outputs map[string]models.Param `json:"outputs,omitempty" bson:"outputs,omitempty"` + Args map[string]string `json:"args,omitempty" bson:"args,omitempty"` + Exposes map[string]models.Expose `bson:"exposes,omitempty" json:"exposes,omitempty"` // Expose is the execution } func (d *Workflow) GetAccessor(request *tools.APIRequest) utils.Accessor { @@ -618,7 +621,7 @@ func (wf *Workflow) Planify(start time.Time, end *time.Time, instances ConfigIte if start.Before(now) { start = now } - // PLANNED: honour the caller's start date as-is. + // PLANNED: honour the caller's start date as-is. } priceds := map[tools.DataType]map[string]pricing.PricedItemITF{}