set up
This commit is contained in:
@@ -31,11 +31,11 @@ func (r *ComputeResource) GetType() string {
|
||||
}
|
||||
|
||||
func (abs *ComputeResource) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF {
|
||||
if t != tools.COMPUTE_RESOURCE {
|
||||
return nil
|
||||
}
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request)
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request, buyingStrategy, pricingStrategy)
|
||||
priced := p.(*PricedResource)
|
||||
return &PricedComputeResource{
|
||||
PricedResource: *priced,
|
||||
|
||||
@@ -38,11 +38,11 @@ func (r *DataResource) GetType() string {
|
||||
}
|
||||
|
||||
func (abs *DataResource) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF {
|
||||
if t != tools.DATA_RESOURCE {
|
||||
return nil
|
||||
}
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request)
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request, buyingStrategy, pricingStrategy)
|
||||
priced := p.(*PricedResource)
|
||||
return &PricedDataResource{
|
||||
PricedResource: *priced,
|
||||
@@ -82,7 +82,7 @@ type DataResourcePartnership struct {
|
||||
type DataResourcePricingStrategy int
|
||||
|
||||
const (
|
||||
PER_DOWNLOAD DataResourcePricingStrategy = iota
|
||||
PER_DOWNLOAD DataResourcePricingStrategy = iota + 6
|
||||
PER_TB_DOWNLOADED
|
||||
PER_GB_DOWNLOADED
|
||||
PER_MB_DOWNLOADED
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
type ResourceInterface interface {
|
||||
utils.DBObject
|
||||
Trim()
|
||||
ConvertToPricedResource(t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF
|
||||
ConvertToPricedResource(t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF
|
||||
GetType() string
|
||||
GetSelectedInstance() utils.DBObject
|
||||
ClearEnv() utils.DBObject
|
||||
@@ -22,7 +22,7 @@ type ResourceInstanceITF interface {
|
||||
GetName() string
|
||||
StoreDraftDefault()
|
||||
ClearEnv()
|
||||
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
||||
GetPricingsProfiles(peerID string, groups []string, buyingStrategy int, pricingStrategy int) []pricing.PricingProfileITF
|
||||
GetPeerGroups() ([]ResourcePartnerITF, []map[string][]string)
|
||||
ClearPeerGroups()
|
||||
GetSelectedPartnership() ResourcePartnerITF
|
||||
@@ -30,7 +30,7 @@ type ResourceInstanceITF interface {
|
||||
}
|
||||
|
||||
type ResourcePartnerITF interface {
|
||||
GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF
|
||||
GetPricingsProfiles(peerID string, groups []string, buyingStrategy int, pricingStrategy int) []pricing.PricingProfileITF
|
||||
GetPeerGroups() map[string][]string
|
||||
ClearPeerGroups()
|
||||
}
|
||||
|
||||
@@ -52,13 +52,12 @@ type AbstractInstanciatedResource[T ResourceInstanceITF] struct {
|
||||
Instances []T `json:"instances,omitempty" bson:"instances,omitempty"` // Bill is the bill of the resource // Bill is the bill of the resource
|
||||
}
|
||||
|
||||
func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
func (abs *AbstractInstanciatedResource[T]) ConvertToPricedResource(t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF {
|
||||
instances := map[string]string{}
|
||||
profiles := []pricing.PricingProfileITF{}
|
||||
for _, instance := range abs.Instances {
|
||||
instances[instance.GetID()] = instance.GetName()
|
||||
profiles = instance.GetPricingsProfiles(request.PeerID, request.Groups)
|
||||
profiles = instance.GetPricingsProfiles(request.PeerID, request.Groups, buyingStrategy, pricingStrategy)
|
||||
}
|
||||
return &PricedResource{
|
||||
Name: abs.Name,
|
||||
@@ -184,10 +183,10 @@ func (ri *ResourceInstance[T]) GetPartnerships(peerID string, groups []string) [
|
||||
return partners
|
||||
}
|
||||
|
||||
func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF {
|
||||
func (ri *ResourceInstance[T]) GetPricingsProfiles(peerID string, groups []string, buyingStrategy int, pricingStrategy int) []pricing.PricingProfileITF {
|
||||
pricings := []pricing.PricingProfileITF{}
|
||||
for _, p := range ri.Partnerships {
|
||||
pricings = append(pricings, p.GetPricingsProfiles(peerID, groups)...)
|
||||
pricings = append(pricings, p.GetPricingsProfiles(peerID, groups, buyingStrategy, pricingStrategy)...)
|
||||
}
|
||||
return pricings
|
||||
}
|
||||
@@ -211,26 +210,31 @@ func (ri *ResourceInstance[T]) ClearPeerGroups() {
|
||||
type ResourcePartnerShip[T pricing.PricingProfileITF] struct {
|
||||
Namespace string `json:"namespace" bson:"namespace" default:"default-namespace"`
|
||||
PeerGroups map[string][]string `json:"peer_groups,omitempty" bson:"peer_groups,omitempty"`
|
||||
PricingProfiles []T `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
||||
PricingProfiles map[int]map[int]T `json:"pricing_profiles,omitempty" bson:"pricing_profiles,omitempty"`
|
||||
// to upgrade pricing profiles. to be a map BuyingStrategy, map of Strategy
|
||||
}
|
||||
|
||||
func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string) []pricing.PricingProfileITF {
|
||||
/*
|
||||
Le pricing doit être selectionné lors d'un scheduling...
|
||||
le type de paiement défini le type de stratégie de paiement
|
||||
note : il faut rajouté - une notion de facturation
|
||||
Une order est l'ensemble de la commande... un booking une réservation, une purchase un acte d'achat.
|
||||
Une bill (facture) représente alors... l'emission d'une facture à un instant T en but d'être honorée, envoyée ... etc.
|
||||
*/
|
||||
func (ri *ResourcePartnerShip[T]) GetPricingsProfiles(peerID string, groups []string, buyingStrategy int, pricingStrategy int) []pricing.PricingProfileITF {
|
||||
profiles := []pricing.PricingProfileITF{}
|
||||
if ri.PeerGroups[peerID] != nil {
|
||||
if slices.Contains(groups, "*") {
|
||||
for _, ri := range ri.PricingProfiles {
|
||||
profiles = append(profiles, ri)
|
||||
if ri.PeerGroups[peerID] == nil {
|
||||
return profiles
|
||||
}
|
||||
for _, p := range ri.PeerGroups[peerID] {
|
||||
if slices.Contains(groups, p) || slices.Contains(groups, "*") {
|
||||
for buyingS, ri := range ri.PricingProfiles {
|
||||
if _, ok := ri[pricingStrategy]; ok && buyingS == buyingStrategy {
|
||||
profiles = append(profiles, ri[pricingStrategy])
|
||||
}
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
for _, p := range ri.PeerGroups[peerID] {
|
||||
if slices.Contains(groups, p) {
|
||||
for _, ri := range ri.PricingProfiles {
|
||||
profiles = append(profiles, ri)
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
}
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
|
||||
@@ -31,11 +31,11 @@ func (r *StorageResource) GetType() string {
|
||||
}
|
||||
|
||||
func (abs *StorageResource) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF {
|
||||
if t != tools.STORAGE_RESOURCE {
|
||||
return nil
|
||||
}
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request)
|
||||
p := abs.AbstractInstanciatedResource.ConvertToPricedResource(t, request, buyingStrategy, pricingStrategy)
|
||||
priced := p.(*PricedResource)
|
||||
return &PricedStorageResource{
|
||||
PricedResource: *priced,
|
||||
@@ -105,7 +105,7 @@ func (t PrivilegeStoragePricingStrategy) String() string {
|
||||
type StorageResourcePricingStrategy int
|
||||
|
||||
const (
|
||||
PER_DATA_STORED StorageResourcePricingStrategy = iota
|
||||
PER_DATA_STORED StorageResourcePricingStrategy = iota + 6
|
||||
PER_TB_STORED
|
||||
PER_GB_STORED
|
||||
PER_MB_STORED
|
||||
|
||||
@@ -30,7 +30,7 @@ func TestComputeResource_ConvertToPricedResource(t *testing.T) {
|
||||
cr := &resources.ComputeResource{}
|
||||
cr.UUID = "comp123"
|
||||
cr.AbstractInstanciatedResource.UUID = cr.UUID
|
||||
result := cr.ConvertToPricedResource(tools.COMPUTE_RESOURCE, req)
|
||||
result := cr.ConvertToPricedResource(tools.COMPUTE_RESOURCE, req, 0, 0)
|
||||
assert.NotNil(t, result)
|
||||
assert.IsType(t, &resources.PricedComputeResource{}, result)
|
||||
}
|
||||
|
||||
@@ -27,10 +27,10 @@ func TestDataResource_GetAccessor(t *testing.T) {
|
||||
func TestDataResource_ConvertToPricedResource(t *testing.T) {
|
||||
d := &resources.DataResource{}
|
||||
d.UUID = "123"
|
||||
res := d.ConvertToPricedResource(tools.DATA_RESOURCE, &tools.APIRequest{})
|
||||
res := d.ConvertToPricedResource(tools.DATA_RESOURCE, &tools.APIRequest{}, 0, 0)
|
||||
assert.IsType(t, &resources.PricedDataResource{}, res)
|
||||
|
||||
nilRes := d.ConvertToPricedResource(tools.PROCESSING_RESOURCE, &tools.APIRequest{})
|
||||
nilRes := d.ConvertToPricedResource(tools.PROCESSING_RESOURCE, &tools.APIRequest{}, 0, 0)
|
||||
assert.Nil(t, nilRes)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,11 +16,13 @@ type MockInstance struct {
|
||||
resources.ResourceInstance[*MockPartner]
|
||||
}
|
||||
|
||||
func (m *MockInstance) GetID() string { return m.ID }
|
||||
func (m *MockInstance) GetName() string { return m.Name }
|
||||
func (m *MockInstance) ClearEnv() {}
|
||||
func (m *MockInstance) ClearPeerGroups() {}
|
||||
func (m *MockInstance) GetPricingsProfiles(string, []string) []pricing.PricingProfileITF { return nil }
|
||||
func (m *MockInstance) GetID() string { return m.ID }
|
||||
func (m *MockInstance) GetName() string { return m.Name }
|
||||
func (m *MockInstance) ClearEnv() {}
|
||||
func (m *MockInstance) ClearPeerGroups() {}
|
||||
func (m *MockInstance) GetPricingsProfiles(string, []string, int, int) []pricing.PricingProfileITF {
|
||||
return nil
|
||||
}
|
||||
func (m *MockInstance) GetPeerGroups() ([]resources.ResourcePartnerITF, []map[string][]string) {
|
||||
return nil, []map[string][]string{
|
||||
{"peer1": {"group1"}},
|
||||
@@ -35,7 +37,7 @@ func (m *MockPartner) GetPeerGroups() map[string][]string {
|
||||
return m.groups
|
||||
}
|
||||
func (m *MockPartner) ClearPeerGroups() {}
|
||||
func (m *MockPartner) GetPricingsProfiles(string, []string) []pricing.PricingProfileITF {
|
||||
func (m *MockPartner) GetPricingsProfiles(string, []string, int, int) []pricing.PricingProfileITF {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -28,14 +28,14 @@ func TestStorageResource_ConvertToPricedResource_ValidType(t *testing.T) {
|
||||
res := &resources.StorageResource{}
|
||||
res.AbstractInstanciatedResource.CreatorID = "creator"
|
||||
res.AbstractInstanciatedResource.UUID = "res-id"
|
||||
priced := res.ConvertToPricedResource(tools.STORAGE_RESOURCE, &tools.APIRequest{})
|
||||
priced := res.ConvertToPricedResource(tools.STORAGE_RESOURCE, &tools.APIRequest{}, 0, 0)
|
||||
assert.NotNil(t, priced)
|
||||
assert.IsType(t, &resources.PricedStorageResource{}, priced)
|
||||
}
|
||||
|
||||
func TestStorageResource_ConvertToPricedResource_InvalidType(t *testing.T) {
|
||||
res := &resources.StorageResource{}
|
||||
priced := res.ConvertToPricedResource(tools.COMPUTE_RESOURCE, &tools.APIRequest{})
|
||||
priced := res.ConvertToPricedResource(tools.COMPUTE_RESOURCE, &tools.APIRequest{}, 0, 0)
|
||||
assert.Nil(t, priced)
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ func TestWorkflowResource_ConvertToPricedResource(t *testing.T) {
|
||||
Groups: []string{"group1"},
|
||||
}
|
||||
|
||||
pr := w.ConvertToPricedResource(tools.WORKFLOW_RESOURCE, req)
|
||||
pr := w.ConvertToPricedResource(tools.WORKFLOW_RESOURCE, req, 0, 0)
|
||||
assert.Equal(t, "creator-id", pr.GetCreatorID())
|
||||
assert.Equal(t, tools.WORKFLOW_RESOURCE, pr.GetType())
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (w *WorkflowResource) SetAllowedInstances(request *tools.APIRequest) {
|
||||
}
|
||||
|
||||
func (w *WorkflowResource) ConvertToPricedResource(
|
||||
t tools.DataType, request *tools.APIRequest) pricing.PricedItemITF {
|
||||
t tools.DataType, request *tools.APIRequest, buyingStrategy int, pricingStrategy int) pricing.PricedItemITF {
|
||||
return &PricedResource{
|
||||
Name: w.Name,
|
||||
Logo: w.Logo,
|
||||
|
||||
Reference in New Issue
Block a user