diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go
index e296aed44..8a0d277f7 100644
--- a/apier/v1/api_interfaces.go
+++ b/apier/v1/api_interfaces.go
@@ -182,15 +182,6 @@ type CoreSv1Interface interface {
Sleep(arg *utils.DurationArgs, reply *string) error
}
-type RateSv1Interface interface {
- Ping(ign *utils.CGREvent, reply *string) error
- CostForEvent(args *utils.ArgsCostForEvent, rpCost *utils.RateProfileCost) error
-}
-
-type RateProfileSv1Interface interface {
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
type ReplicatorSv1Interface interface {
Ping(ign *utils.CGREvent, reply *string) error
GetAccount(args *utils.StringWithAPIOpts, reply *engine.Account) error
@@ -216,7 +207,6 @@ type ReplicatorSv1Interface interface {
GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error
GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error
GetDispatcherProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error
- GetRateProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.RateProfile) error
GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error
GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error
SetThresholdProfile(th *engine.ThresholdProfileWithAPIOpts, reply *string) error
@@ -239,7 +229,6 @@ type ReplicatorSv1Interface interface {
SetAttributeProfile(ap *engine.AttributeProfileWithAPIOpts, reply *string) error
SetChargerProfile(cp *engine.ChargerProfileWithAPIOpts, reply *string) error
SetDispatcherProfile(dpp *engine.DispatcherProfileWithAPIOpts, reply *string) error
- SetRateProfile(dpp *utils.RateProfileWithAPIOpts, reply *string) error
SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) error
SetAccountActionPlans(args *engine.SetAccountActionPlansArgWithAPIOpts, reply *string) error
SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) error
@@ -266,7 +255,6 @@ type ReplicatorSv1Interface interface {
RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveRateProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error
SetIndexes(args *utils.SetIndexesArg, reply *string) error
diff --git a/apier/v1/api_interfaces_test.go b/apier/v1/api_interfaces_test.go
index 2fac17dc0..1a0b6b740 100644
--- a/apier/v1/api_interfaces_test.go
+++ b/apier/v1/api_interfaces_test.go
@@ -64,11 +64,6 @@ func TestResponderInterface(t *testing.T) {
_ = ResponderInterface(&engine.Responder{})
}
-func TestRateProfileInterface(t *testing.T) {
- _ = RateProfileSv1Interface(NewDispatcherRateSv1(nil))
- _ = RateProfileSv1Interface(NewRateSv1(nil))
-}
-
func TestCacheSv1Interface(t *testing.T) {
_ = CacheSv1Interface(NewDispatcherCacheSv1(nil))
_ = CacheSv1Interface(NewCacheSv1(nil))
@@ -113,13 +108,3 @@ func TestReplicatorSv1Interface(t *testing.T) {
_ = ReplicatorSv1Interface(NewDispatcherReplicatorSv1(nil))
_ = ReplicatorSv1Interface(NewReplicatorSv1(nil, nil))
}
-
-func TestRateSv1Interface(t *testing.T) {
- _ = RateSv1Interface(NewDispatcherRateSv1(nil))
- _ = RateSv1Interface(NewRateSv1(nil))
-}
-
-func TestActionSv1Interface(t *testing.T) {
- _ = ActionSv1Interface(NewDispatcherActionSv1(nil))
- _ = ActionSv1Interface(NewActionSv1(nil))
-}
diff --git a/apier/v1/apier.go b/apier/v1/apier.go
index d3472224c..f28a77103 100644
--- a/apier/v1/apier.go
+++ b/apier/v1/apier.go
@@ -1537,7 +1537,7 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st
if len(arg.Items) == 0 {
arg.Items = []string{utils.MetaAttributes, utils.MetaChargers, utils.MetaDispatchers,
utils.MetaDispatcherHosts, utils.MetaFilters, utils.MetaResources, utils.MetaStats,
- utils.MetaRoutes, utils.MetaThresholds, utils.MetaRateProfiles, utils.MetaActionProfiles}
+ utils.MetaRoutes, utils.MetaThresholds}
}
if _, err := os.Stat(arg.Path); os.IsNotExist(err) {
os.Mkdir(arg.Path, os.ModeDir)
@@ -1884,44 +1884,6 @@ func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *st
}
}
csvWriter.Flush()
- case utils.MetaRateProfiles:
- prfx := utils.RateProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
- if err != nil {
- return err
- }
- if len(keys) == 0 { // if we don't find items we skip
- continue
- }
- f, err := os.Create(path.Join(arg.Path, utils.RateProfilesCsv))
- if err != nil {
- return err
- }
- defer f.Close()
-
- csvWriter := csv.NewWriter(f)
- csvWriter.Comma = utils.CSVSep
- //write the header of the file
- if err := csvWriter.Write(engine.RateProfileMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- rPrf, err := apierSv1.DataManager.GetRateProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPRateProfile(engine.RateProfileToAPI(rPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
-
case utils.MetaActionProfiles:
prfx := utils.ActionProfilePrefix
keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
diff --git a/apier/v1/cache_replication_it_test.go b/apier/v1/cache_replication_it_test.go
index 4ccd6d2e2..ac1e4f471 100644
--- a/apier/v1/cache_replication_it_test.go
+++ b/apier/v1/cache_replication_it_test.go
@@ -50,7 +50,6 @@ var (
testCacheSReplicateRpcConn,
testCacheSReplicateLoadTariffPlanFromFolder,
testCacheSReplicateProcessAttributes,
- testCacheSReplicateProcessRateProfile,
testCacheSReplicateStopEngine,
}
)
@@ -172,71 +171,6 @@ func testCacheSReplicateProcessAttributes(t *testing.T) {
}
}
-func testCacheSReplicateProcessRateProfile(t *testing.T) {
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- },
- },
- }
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rate1 := &utils.Rate{
- ID: "RT_ALWAYS",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(1, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- exp := &utils.RateProfileCost{
- ID: "RT_SPECIAL_1002",
- Cost: 0.01,
- RateSIntervals: []*utils.RateSInterval{{
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{{
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 60,
- }},
- CompressFactor: 1,
- }},
- }
- if err := engine1RPC.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
- }
- if err := engine2RPC.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
-
- }
-}
-
func testCacheSReplicateStopEngine(t *testing.T) {
if err := engine.KillEngine(300); err != nil {
t.Error(err)
diff --git a/apier/v1/cost_bench_it_test.go b/apier/v1/cost_bench_it_test.go
index 167aacbc3..52333ca91 100644
--- a/apier/v1/cost_bench_it_test.go
+++ b/apier/v1/cost_bench_it_test.go
@@ -94,94 +94,6 @@ func testCostBenchLoadFromFolder2(b *testing.B) {
time.Sleep(500 * time.Millisecond)
}
-func testCostBenchSetRateProfile(b *testing.B) {
- rPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- ID: "DefaultRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";10",
- Rates: map[string]*utils.APIRate{
- "RATE1": &utils.APIRate{
- ID: "RATE1",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- FixedFee: utils.Float64Pointer(0.4),
- RecurrentFee: utils.Float64Pointer(0.2),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(60000000000),
- },
- {
- IntervalStart: "1m",
- RecurrentFee: utils.Float64Pointer(0.1),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(1000000000),
- },
- },
- },
- },
- },
- }
- var reply string
- if err := costBenchRPC.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- b.Error(err)
- } else if reply != utils.OK {
- b.Error("Unexpected reply returned", reply)
- }
-}
-
-func testCostBenchSetRateProfile2(b *testing.B) {
- rate1 := &utils.APIRate{
- ID: "RATE1",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.2),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(60000000000),
- },
- {
- IntervalStart: "1m",
- RecurrentFee: utils.Float64Pointer(0.1),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(1000000000),
- },
- },
- }
- rtChristmas := &utils.APIRate{
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.APIIntervalRate{{
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.6),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(1000000000),
- }},
- }
- rPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- ID: "RateChristmas",
- FilterIDs: []string{"*string:~*req.Subject:1010"},
- Weights: ";50",
- Rates: map[string]*utils.APIRate{
- "RATE1": rate1,
- "RATE_CHRISTMAS": rtChristmas,
- },
- },
- }
- var reply string
- if err := costBenchRPC.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- b.Error(err)
- } else if reply != utils.OK {
- b.Error("Unexpected reply returned", reply)
- }
-}
-
// go test -run=^$ -tags=integration -v -bench=BenchmarkCostWithRALs -benchtime=5s
func BenchmarkCostWithRALs(b *testing.B) {
costBenchConfigDIR = "tutinternal"
diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go
index f0d8290c9..aaaf0a9c3 100755
--- a/apier/v1/dispatcher.go
+++ b/apier/v1/dispatcher.go
@@ -1019,11 +1019,6 @@ func (dS *DispatcherReplicatorSv1) GetDispatcherProfile(tntID *utils.TenantIDWit
return dS.dS.ReplicatorSv1GetDispatcherProfile(tntID, reply)
}
-// GetRateProfile
-func (dS *DispatcherReplicatorSv1) GetRateProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.RateProfile) error {
- return dS.dS.ReplicatorSv1GetRateProfile(tntID, reply)
-}
-
// GetDispatcherHost
func (dS *DispatcherReplicatorSv1) GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error {
return dS.dS.ReplicatorSv1GetDispatcherHost(tntID, reply)
@@ -1136,11 +1131,6 @@ func (dS *DispatcherReplicatorSv1) SetDispatcherProfile(args *engine.DispatcherP
return dS.dS.ReplicatorSv1SetDispatcherProfile(args, reply)
}
-// SetRateProfile
-func (dS *DispatcherReplicatorSv1) SetRateProfile(args *utils.RateProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetRateProfile(args, reply)
-}
-
// SetActionPlan
func (dS *DispatcherReplicatorSv1) SetActionPlan(args *engine.SetActionPlanArgWithAPIOpts, reply *string) error {
return dS.dS.ReplicatorSv1SetActionPlan(args, reply)
@@ -1271,11 +1261,6 @@ func (dS *DispatcherReplicatorSv1) RemoveDispatcherHost(args *utils.TenantIDWith
return dS.dS.ReplicatorSv1RemoveDispatcherHost(args, reply)
}
-// RemoveRateProfile
-func (dS *DispatcherReplicatorSv1) RemoveRateProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveRateProfile(args, reply)
-}
-
// GetIndexes .
func (dS *DispatcherReplicatorSv1) GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error {
return dS.dS.ReplicatorSv1GetIndexes(args, reply)
diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go
index 711da7443..e73db799a 100644
--- a/apier/v1/filter_indexes.go
+++ b/apier/v1/filter_indexes.go
@@ -63,14 +63,6 @@ func (apierSv1 *APIerSv1) RemoveFilterIndexes(arg *AttrRemFilterIndexes, reply *
arg.ItemType = utils.CacheChargerFilterIndexes
case utils.MetaActionProfiles:
arg.ItemType = utils.CacheActionProfilesFilterIndexes
- case utils.MetaRateProfiles:
- arg.ItemType = utils.CacheRateProfilesFilterIndexes
- case utils.MetaRateProfileRates:
- if missing := utils.MissingStructFields(arg, []string{"Context"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- arg.ItemType = utils.CacheRateFilterIndexes
- tntCtx = utils.ConcatenatedKey(tnt, arg.Context)
case utils.MetaDispatchers:
if missing := utils.MissingStructFields(arg, []string{"Context"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
@@ -116,14 +108,6 @@ func (apierSv1 *APIerSv1) GetFilterIndexes(arg *AttrGetFilterIndexes, reply *[]s
arg.ItemType = utils.CacheChargerFilterIndexes
case utils.MetaActionProfiles:
arg.ItemType = utils.CacheActionProfilesFilterIndexes
- case utils.MetaRateProfiles:
- arg.ItemType = utils.CacheRateProfilesFilterIndexes
- case utils.MetaRateProfileRates:
- if missing := utils.MissingStructFields(arg, []string{"Context"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- arg.ItemType = utils.CacheRateFilterIndexes
- tntCtx = utils.ConcatenatedKey(tnt, arg.Context)
case utils.MetaDispatchers:
if missing := utils.MissingStructFields(arg, []string{"Context"}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
@@ -340,43 +324,6 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterInde
return utils.APIErrorHandler(err)
}
}
- var ratePrf []string
- //RateProfile Indexes
- if args.RateS {
- if args.RateS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheRateProfilesFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- rpr, e := apierSv1.DataManager.GetRateProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- ratePrf = append(ratePrf, utils.ConcatenatedKey(tnt, id))
- fltrIDs := make([]string, len(rpr.FilterIDs))
- for i, fltrID := range rpr.FilterIDs {
- fltrIDs[i] = fltrID
- }
-
- rtIds := make([]string, 0, len(rpr.Rates))
-
- for key := range rpr.Rates {
- rtIds = append(rtIds, key)
- }
-
- _, e = engine.ComputeIndexes(apierSv1.DataManager, tnt, id, utils.CacheRateFilterIndexes,
- &rtIds, transactionID, func(_, id, _ string) (*[]string, error) {
- rateFilters := make([]string, len(rpr.Rates[id].FilterIDs))
- for i, fltrID := range rpr.Rates[id].FilterIDs {
- rateFilters[i] = fltrID
- }
- return &rateFilters, nil
- })
- if e != nil {
- return nil, e
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
//ChargerProfile Indexes
if args.ChargerS {
if args.ChargerS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheChargerFilterIndexes,
@@ -450,17 +397,7 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterInde
return
}
}
- //RateProfile Indexes
- if args.RateS {
- if err = apierSv1.DataManager.SetIndexes(utils.CacheRateProfilesFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- for _, val := range ratePrf {
- if err = apierSv1.DataManager.SetIndexes(utils.CacheRateFilterIndexes, val, nil, true, transactionID); err != nil {
- return
- }
- }
- }
+
//AttributeProfile Indexes
if args.AttributeS {
if err = apierSv1.DataManager.SetIndexes(utils.CacheAttributeFilterIndexes, tntCtx, nil, true, transactionID); err != nil {
@@ -565,38 +502,7 @@ func (apierSv1 *APIerSv1) ComputeFilterIndexIDs(args *utils.ArgsComputeFilterInd
}); err != nil && err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
- //RateProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheRateProfilesFilterIndexes,
- &args.RateProfileIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- rpr, e := apierSv1.DataManager.GetRateProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(rpr.FilterIDs))
- for i, fltrID := range rpr.FilterIDs {
- fltrIDs[i] = fltrID
- }
- rtIds := make([]string, 0, len(rpr.Rates))
-
- for key := range rpr.Rates {
- rtIds = append(rtIds, key)
- }
- _, e = engine.ComputeIndexes(apierSv1.DataManager, tnt, id, utils.CacheRateFilterIndexes,
- &rtIds, transactionID, func(_, id, _ string) (*[]string, error) {
- rateFilters := make([]string, len(rpr.Rates[id].FilterIDs))
- for i, fltrID := range rpr.Rates[id].FilterIDs {
- rateFilters[i] = fltrID
- }
- return &rateFilters, nil
- })
- if e != nil {
- return nil, e
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
//AttributeProfile Indexes
if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheAttributeFilterIndexes,
&args.AttributeIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go
index 864683832..153a22f21 100644
--- a/apier/v1/filter_indexes_it_test.go
+++ b/apier/v1/filter_indexes_it_test.go
@@ -80,21 +80,6 @@ var (
testV1FIRemoveActionProfile,
testV1FIdxdxInitDataDb,
- testV1FISetRateProfileRatesIndexes,
- testV1FIComputeRateProfileRatesIndexes,
- testV1FISetSecondRateProfileRate,
- testVF1ComputeIDsRateProfileRateIndexes,
- testVF1RemoveRateProfileRates,
- testV1FIdxdxInitDataDb,
- testV1IndexClearCache,
-
- testV1FISetRateProfileIndexes,
- testV1FIComputeRateProfileIndexes,
- testV1FISetSecondRateProfile,
- testV1FIComputeIDsRateProfileIndexes,
- testVF1RemoveRateProfile,
- testV1FIdxdxInitDataDb,
-
testV1FIdxSetAttributeProfileIndexes,
testV1FIdxComputeAttributeProfileIndexes,
testV1FIdxSetSecondAttributeProfileIndexes,
@@ -1513,795 +1498,6 @@ func testV1FIRemoveActionProfile(t *testing.T) {
}
}
-//RateProfileRate Indexes
-func testV1FISetRateProfileRatesIndexes(t *testing.T) {
- //set a filter for our rates
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "RATE_FLTR1",
- Rules: []*engine.FilterRule{{
- Type: utils.MetaString,
- Element: "~*req.Destination",
- Values: []string{"234"},
- }},
- },
- }
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //there are not any rates in db
- var reply *utils.RateProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP1"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //set in db a ratePrf with double populated rates with our filter
- ratePrfRates := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Usage:10m"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- FilterIDs: []string{"RATE_FLTR1", "*suffix:~*req.Account:1009"},
- ActivationTimes: "* * * * 1-5",
- },
- "RT_MONTH": {
- ID: "RT_MONTH",
- FilterIDs: []string{"RATE_FLTR1"},
- ActivationTimes: "* * * * *",
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetRateProfile, ratePrfRates, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- expRtPrf, err := ratePrfRates.AsRateProfile()
- if err != nil {
- t.Error(err)
- }
-
- //get it from db and compare
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP1"}},
- &reply); err != nil {
- t.Error(err)
- } else {
- expRtPrf.Compile()
- reply.Compile()
- if !reflect.DeepEqual(reply, expRtPrf) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expRtPrf), utils.ToJSON(reply))
- }
- }
-
- //get indexes to verify if these are indexed well
- var indexes []string
- expectedIDx := []string{"*suffix:*req.Account:1009:RT_WEEK", "*string:*req.Destination:234:RT_WEEK",
- "*string:*req.Destination:234:RT_MONTH"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //get indexes only with Type *string
- expectedIDx = []string{"*string:*req.Destination:234:RT_WEEK", "*string:*req.Destination:234:RT_MONTH"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates, Tenant: tenant,
- FilterType: utils.MetaString, Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //get indexes only with Field Destination
- expectedIDx = []string{"*string:*req.Destination:234:RT_WEEK", "*string:*req.Destination:234:RT_MONTH"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates, Tenant: tenant,
- FilterField: "*req.Destination", Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //get indexes only with 1009 Destination
- expectedIDx = []string{"*suffix:*req.Account:1009:RT_WEEK"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates, Tenant: tenant,
- FilterValue: "1009", Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testV1FIComputeRateProfileRatesIndexes(t *testing.T) {
- //remove indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //nothing to get from db
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err)
- }
-
- //compute them, to put indexes again in db for the right subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- RateS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.Destination:234:RT_WEEK",
- "*string:*req.Destination:234:RT_MONTH", "*suffix:*req.Account:1009:RT_WEEK"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testV1FISetSecondRateProfileRate(t *testing.T) {
- //second filter for a new rate in the same rate profile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "RTPRF_FLTR3",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.Usage",
- Values: []string{"10m", "40m", "~*opts.Usage"},
- },
- },
- },
- }
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- //append a new rate in the same rate profile
- ratePrfRates := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Usage:10m"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_YEAR": {
- ID: "RT_YEAR",
- FilterIDs: []string{"RTPRF_FLTR3"},
- ActivationTimes: "* * * * *",
- },
- },
- },
- }
- expRatePrf := utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Usage:10m"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- FilterIDs: []string{"RATE_FLTR1", "*suffix:~*req.Account:1009"},
- ActivationTimes: "* * * * 1-5",
- },
- "RT_MONTH": {
- ID: "RT_MONTH",
- FilterIDs: []string{"RATE_FLTR1"},
- ActivationTimes: "* * * * *",
- },
- "RT_YEAR": {
- ID: "RT_YEAR",
- FilterIDs: []string{"RTPRF_FLTR3"},
- ActivationTimes: "* * * * *",
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetRateProfileRates, ratePrfRates, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("unexpected reply returned")
- }
-
- //get it from db and compare
- var reply utils.RateProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP1"}},
- &reply); err != nil {
- t.Error(err)
- } else {
- expRatePrf.Compile()
- reply.Compile()
- if !reflect.DeepEqual(reply, expRatePrf) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expRatePrf), utils.ToJSON(reply))
- }
- }
-
- var indexes []string
- expectedIDx := []string{"*string:*req.Destination:234:RT_WEEK",
- "*string:*req.Destination:234:RT_MONTH", "*suffix:*req.Account:1009:RT_WEEK",
- "*string:*req.Usage:10m:RT_YEAR", "*string:*req.Usage:40m:RT_YEAR"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testVF1ComputeIDsRateProfileRateIndexes(t *testing.T) {
- //remove indexes
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- var indexes []string
- //nothing to get from db, as we removed them,
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //compute indexes for all three rates by ids
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- RateProfileIDs: []string{"RP1"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.Destination:234:RT_WEEK",
- "*string:*req.Destination:234:RT_MONTH", "*suffix:*req.Account:1009:RT_WEEK",
- "*string:*req.Usage:10m:RT_YEAR", "*string:*req.Usage:40m:RT_YEAR"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testVF1RemoveRateProfileRates(t *testing.T) {
- //removing rates from db will delete the indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveRateProfileRates,
- &RemoveRPrfRatesWithAPIOpts{ID: "RP1",
- Tenant: tenant, RateIDs: []string{"RT_WEEK", "RT_YEAR"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- expRatePrf := utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Usage:10m"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_MONTH": {
- ID: "RT_MONTH",
- FilterIDs: []string{"RATE_FLTR1"},
- ActivationTimes: "* * * * *",
- },
- },
- }
-
- var reply utils.RateProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP1"}},
- &reply); err != nil {
- t.Error(err)
- } else {
- expRatePrf.Compile()
- reply.Compile()
- if !reflect.DeepEqual(reply, expRatePrf) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expRatePrf), utils.ToJSON(reply))
- }
- }
-
- //compute the indexes only for the left rate
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- RateProfileIDs: []string{"RP1"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.Destination:234:RT_MONTH"}
- //as we compute them, next we will try to get them again from db
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //no we will remove the left rate and the profile
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveRateProfileRates,
- &RemoveRPrfRatesWithAPIOpts{ID: "RP1",
- Tenant: tenant, RateIDs: []string{"RT_MONTH"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //no indexes in db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfileRates,
- Tenant: tenant, Context: "RP1"},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
-}
-
-//RateProfile Indexes
-func testV1FISetRateProfileIndexes(t *testing.T) {
- //set a filter for our rates
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "RATEFLTR_FLTR1",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.OriginID",
- Values: []string{"~*opts.Account", "ID1"},
- },
- {
- Type: utils.MetaPrefix,
- Element: "~*req.Destination",
- Values: []string{"~*opts.Account", "123"},
- },
- },
- },
- }
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- //there are not any rates in db
- var reply *utils.RateProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP2"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //set in db a ratePrf with with our filterS
- ratePrfRates := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP2",
- FilterIDs: []string{"*string:~*req.Usage:10m", "RATEFLTR_FLTR1"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- FilterIDs: []string{"*suffix:~*req.Account:1009"},
- ActivationTimes: "* * * * 1-5",
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetRateProfile, ratePrfRates, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expRtPrf, err := ratePrfRates.AsRateProfile()
- if err != nil {
- t.Error(err)
- }
-
- //get it from db and compare
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP2"}},
- &reply); err != nil {
- t.Error(err)
- } else {
- expRtPrf.Compile()
- reply.Compile()
- if !reflect.DeepEqual(reply, expRtPrf) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expRtPrf), utils.ToJSON(reply))
- }
- }
-
- //get indexes to verify if these are indexed well
- var indexes []string
- expectedIDx := []string{"*string:*req.OriginID:ID1:RP2", "*prefix:*req.Destination:123:RP2",
- "*string:*req.Usage:10m:RP2"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //get indexes only with Type *string
- expectedIDx = []string{"*string:*req.OriginID:ID1:RP2",
- "*string:*req.Usage:10m:RP2"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles, Tenant: tenant,
- FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //get indexes only with Field OriginID
- expectedIDx = []string{"*string:*req.OriginID:ID1:RP2"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles, Tenant: tenant,
- FilterField: "*req.OriginID"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-
- //get indexes only with 10m
- expectedIDx = []string{"*string:*req.Usage:10m:RP2"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles, Tenant: tenant,
- FilterValue: "10m"},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testV1FIComputeRateProfileIndexes(t *testing.T) {
- //remove indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //nothing to get from db
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err)
- }
-
- //compute them, to put indexes again in db for the right subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- RateS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.OriginID:ID1:RP2", "*prefix:*req.Destination:123:RP2",
- "*string:*req.Usage:10m:RP2"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testV1FISetSecondRateProfile(t *testing.T) {
- //second filter for a new rate profile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "RTPRF_FLTR6",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.ToR",
- Values: []string{"*sms", "~*opts.Usage"},
- },
- },
- },
- }
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- //another rate profile
- ratePrfRates := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP3",
- FilterIDs: []string{"RTPRF_FLTR6"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- FilterIDs: []string{"*suffix:~*req.Account:1019"},
- ActivationTimes: "* * * * 1-5",
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetRateProfile, ratePrfRates, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("unexpected reply returned")
- }
- expRatePrf := utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP3",
- FilterIDs: []string{"RTPRF_FLTR6"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- FilterIDs: []string{"*suffix:~*req.Account:1019"},
- ActivationTimes: "* * * * 1-5",
- },
- },
- }
- //get it from db and compare
- var reply utils.RateProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP3"}},
- &reply); err != nil {
- t.Error(err)
- } else {
- expRatePrf.Compile()
- reply.Compile()
- if !reflect.DeepEqual(reply, expRatePrf) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expRatePrf), utils.ToJSON(reply))
- }
- }
-
- var indexes []string
- expectedIDx := []string{"*string:*req.OriginID:ID1:RP2", "*prefix:*req.Destination:123:RP2",
- "*string:*req.Usage:10m:RP2", "*string:*req.ToR:*sms:RP3"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testV1FIComputeIDsRateProfileIndexes(t *testing.T) {
- //remove indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //nothing to get from db
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err)
- }
-
- //compute them, to put indexes again in db for the right subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- RateProfileIDs: []string{"RP3", "RP2"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.OriginID:ID1:RP2", "*prefix:*req.Destination:123:RP2",
- "*string:*req.Usage:10m:RP2", "*string:*req.ToR:*sms:RP3"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaRateProfiles,
- Tenant: tenant},
- &indexes); err != nil {
- t.Error(err)
- } else {
- sort.Strings(expectedIDx)
- sort.Strings(indexes)
- if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
- }
-}
-
-func testVF1RemoveRateProfile(t *testing.T) {
- //removing rate profile from db will delete the indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- ID: "RP2",
- Tenant: tenant},
- },
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- ID: "RP3",
- Tenant: tenant}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //nothing to get from db
- var reply utils.RateProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP2"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "RP3"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //as we removed our profiles, the indexes are removed as well
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaRateProfiles, Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
//AttributeProfile Indexes
func testV1FIdxSetAttributeProfileIndexes(t *testing.T) {
var reply *engine.AttributeProfile
diff --git a/apier/v1/rateprofiles.go b/apier/v1/rateprofiles.go
deleted file mode 100644
index ed4dea0d2..000000000
--- a/apier/v1/rateprofiles.go
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package v1
-
-import (
- "time"
-
- "github.com/cgrates/cgrates/rates"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetRateProfile returns an Rate Profile
-func (apierSv1 *APIerSv1) GetRateProfile(arg *utils.TenantIDWithAPIOpts, reply *utils.RateProfile) error {
- if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := arg.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rPrf, err := apierSv1.DataManager.GetRateProfile(tnt, arg.ID, true, true, utils.NonTransactional)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rPrf
- return nil
-}
-
-// GetRateProfileIDs returns list of rate profile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetRateProfileIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.RateProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx)
- if err != nil {
- return err
- }
- if len(keys) == 0 {
- return utils.ErrNotFound
- }
- retIDs := make([]string, len(keys))
- for i, key := range keys {
- retIDs[i] = key[len(prfx):]
- }
- *attrPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-// GetRateProfileIDsCount sets in reply var the total number of RateProfileIDs registered for a tenant
-// returns ErrNotFound in case of 0 RateProfileIDs
-func (apierSv1 *APIerSv1) GetRateProfileIDsCount(args *utils.TenantWithAPIOpts, reply *int) (err error) {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- var keys []string
- prfx := utils.RateProfilePrefix + tnt + utils.ConcatenatedKeySep
- if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(prfx); err != nil {
- return err
- }
- if len(keys) == 0 {
- return utils.ErrNotFound
- }
- *reply = len(keys)
- return
-}
-
-//SetRateProfile add/update a new Rate Profile
-func (apierSv1 *APIerSv1) SetRateProfile(ext *utils.APIRateProfileWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(ext.APIRateProfile, []string{utils.ID, utils.Rates}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if ext.Tenant == utils.EmptyString {
- ext.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rPrf, err := ext.AsRateProfile()
- if err != nil {
- return err
- }
- if err := apierSv1.DataManager.SetRateProfile(rPrf, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheRateProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.CallCache(utils.IfaceAsString(ext.APIOpts[utils.CacheOpt]), rPrf.Tenant, utils.CacheRateProfiles,
- rPrf.TenantID(), &rPrf.FilterIDs, nil, ext.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//SetRateProfileRates add/update Rates from existing RateProfiles
-func (apierSv1 *APIerSv1) SetRateProfileRates(ext *utils.APIRateProfileWithAPIOpts, reply *string) (err error) {
- if missing := utils.MissingStructFields(ext.APIRateProfile, []string{utils.ID, utils.Rates}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if ext.Tenant == utils.EmptyString {
- ext.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rPrf, err := ext.AsRateProfile()
- if err != nil {
- return err
- }
- if err = apierSv1.DataManager.SetRateProfileRates(rPrf, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheRateProfiles and store it in database
- if err = apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err = apierSv1.CallCache(utils.IfaceAsString(ext.APIOpts[utils.CacheOpt]), rPrf.Tenant, utils.CacheRateProfiles,
- rPrf.TenantID(), &rPrf.FilterIDs, nil, ext.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-type RemoveRPrfRatesWithAPIOpts struct {
- Tenant string
- ID string
- RateIDs []string
- APIOpts map[string]interface{}
-}
-
-func (apierSv1 *APIerSv1) RemoveRateProfileRates(args *RemoveRPrfRatesWithAPIOpts, reply *string) (err error) {
- if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.RemoveRateProfileRates(tnt, args.ID, args.RateIDs, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheRateProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), tnt, utils.CacheRateProfiles,
- utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// RemoveRateProfile remove a specific Rate Profile
-func (apierSv1 *APIerSv1) RemoveRateProfile(arg *utils.TenantIDWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := arg.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.RemoveRateProfile(tnt, arg.ID,
- utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheAttributeProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(map[string]int64{utils.CacheRateProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheRateProfiles,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-func NewRateSv1(rateS *rates.RateS) *RateSv1 {
- return &RateSv1{rS: rateS}
-}
-
-// Exports RPC from RLs
-type RateSv1 struct {
- rS *rates.RateS
-}
-
-// Call implements rpcclient.ClientConnector interface for internal RPC
-func (rSv1 *RateSv1) Call(serviceMethod string,
- args interface{}, reply interface{}) error {
- return utils.APIerRPCCall(rSv1, serviceMethod, args, reply)
-}
-
-func (rSv1 *RateSv1) CostForEvent(args *utils.ArgsCostForEvent, rpCost *utils.RateProfileCost) (err error) {
- return rSv1.rS.V1CostForEvent(args, rpCost)
-}
-
-func (rSv1 *RateSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/rateprofiles_it_test.go b/apier/v1/rateprofiles_it_test.go
deleted file mode 100644
index 99f0cb2ed..000000000
--- a/apier/v1/rateprofiles_it_test.go
+++ /dev/null
@@ -1,1602 +0,0 @@
-// +build integration
-
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package v1
-
-import (
- "net/rpc"
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- ratePrfCfgPath string
- ratePrfCfg *config.CGRConfig
- ratePrfRpc *rpc.Client
- ratePrfConfDIR string //run tests for specific configuration
-
- sTestsRatePrf = []func(t *testing.T){
- testV1RatePrfLoadConfig,
- testV1RatePrfInitDataDb,
- testV1RatePrfResetStorDb,
- testV1RatePrfStartEngine,
- testV1RatePrfRpcConn,
- testV1RatePrfNotFound,
- testV1RatePrfFromFolder,
- testV1RatePrfGetRateProfileIDs,
- testV1RatePrfGetRateProfileIDsCount,
- testV1RatePrfVerifyRateProfile,
- testV1RatePrfRemoveRateProfile,
- testV1RatePrfNotFound,
- testV1RatePrfSetRateProfileRates,
- testV1RatePrfRemoveRateProfileRates,
- testV1RatePing,
- testV1RateGetRemoveRateProfileWithoutTenant,
- testV1RatePrfRemoveRateProfileWithoutTenant,
- testV1RatePrfGetRateProfileRatesWithoutTenant,
- testV1RatePrfRemoveRateProfileRatesWithoutTenant,
- testV1RateCostForEventWithDefault,
- testV1RateCostForEventWithUsage,
- testV1RateCostForEventWithWrongUsage,
- testV1RateCostForEventWithStartTime,
- testV1RateCostForEventWithWrongStartTime,
- testV1RateCostForEventWithOpts,
- //testV1RateCostForEventSpecial,
- //testV1RateCostForEventThreeRates,
- testV1RatePrfStopEngine,
- }
-)
-
-//Test start here
-func TestRatePrfIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- ratePrfConfDIR = "tutinternal"
- case utils.MetaMySQL:
- ratePrfConfDIR = "tutmysql"
- case utils.MetaMongo:
- ratePrfConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsRatePrf {
- t.Run(ratePrfConfDIR, stest)
- }
-}
-
-func testV1RatePrfLoadConfig(t *testing.T) {
- var err error
- ratePrfCfgPath = path.Join(*dataDir, "conf", "samples", ratePrfConfDIR)
- if ratePrfCfg, err = config.NewCGRConfigFromPath(ratePrfCfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RatePrfInitDataDb(t *testing.T) {
- if err := engine.InitDataDb(ratePrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testV1RatePrfResetStorDb(t *testing.T) {
- if err := engine.InitStorDb(ratePrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RatePrfStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(ratePrfCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RatePrfRpcConn(t *testing.T) {
- var err error
- ratePrfRpc, err = newRPCClient(ratePrfCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
-}
-
-func testV1RatePrfNotFound(t *testing.T) {
- var reply *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RatePrfFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutrates")}
- if err := ratePrfRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testV1RatePrfVerifyRateProfile(t *testing.T) {
- var reply *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}}, &reply); err != nil {
- t.Fatal(err)
- }
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rPrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- },
- }
- if !reflect.DeepEqual(rPrf, rPrf) {
- t.Errorf("Expecting: %+v, received: %+v",
- utils.ToJSON(rPrf), utils.ToJSON(rPrf))
- }
-}
-
-func testV1RatePrfRemoveRateProfile(t *testing.T) {
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}}, &reply); err != nil {
- t.Fatal(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-}
-
-func testV1RatePrfSetRateProfileRates(t *testing.T) {
- rPrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*wrong:inline"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- if err := rPrf.Compile(); err != nil {
- t.Fatal(err)
- }
- apiRPrf := &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*wrong:inline"},
- Weights: ";0",
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- },
- }
- var reply string
- expErr := "SERVER_ERROR: broken reference to filter: *wrong:inline for item with ID: cgrates.org:RP1"
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile,
- &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: apiRPrf,
- }, &reply); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
- apiRPrf.FilterIDs = []string{"*string:~*req.Subject:1001"}
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile,
- &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: apiRPrf,
- }, &reply); err != nil {
- t.Fatal(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- apiRPrfRates := &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- {
- IntervalStart: "1m",
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: ";10",
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- },
- }
-
- apiRPrfRates.Rates["RT_WEEK"].FilterIDs = []string{"*wrong:inline"}
- expErr = "SERVER_ERROR: broken reference to filter: *wrong:inline for rate with ID: RT_WEEK"
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfileRates,
- &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: apiRPrfRates,
- }, &reply); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
- apiRPrfRates.Rates["RT_WEEK"].FilterIDs = nil
-
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfileRates,
- &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: apiRPrfRates,
- }, &reply); err != nil {
- t.Fatal(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- rPrfUpdated := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- var rply *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}}, &rply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rPrfUpdated, rply) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- utils.ToJSON(rPrfUpdated), utils.ToJSON(rply))
- }
-}
-
-func testV1RatePrfRemoveRateProfileRates(t *testing.T) {
- apiRPrf := &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "SpecialRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- {
- IntervalStart: "1m",
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: ";10",
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- },
- }
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile,
- &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: apiRPrf,
- }, &reply); err != nil {
- t.Fatal(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfileRates,
- &RemoveRPrfRatesWithAPIOpts{
- Tenant: "cgrates.org",
- ID: "SpecialRate",
- RateIDs: []string{"RT_WEEKEND"},
- }, &reply); err != nil {
- t.Fatal(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- rPrfUpdated := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "SpecialRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- var rply *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "SpecialRate"}}, &rply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rPrfUpdated, rply) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- utils.ToJSON(rPrfUpdated), utils.ToJSON(rply))
- }
-
- if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfileRates,
- &RemoveRPrfRatesWithAPIOpts{
- Tenant: "cgrates.org",
- ID: "SpecialRate",
- }, &reply); err != nil {
- t.Fatal(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- rPrfUpdated2 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "SpecialRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{},
- }
- var rply2 *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "SpecialRate"}}, &rply2); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rPrfUpdated2, rply2) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- utils.ToJSON(rPrfUpdated2), utils.ToJSON(rply2))
- }
-}
-
-func testV1RatePing(t *testing.T) {
- var resp string
- if err := ratePrfRpc.Call(utils.RateSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testV1RatePrfStopEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RateGetRemoveRateProfileWithoutTenant(t *testing.T) {
- rateProfile := &utils.RateProfile{
- ID: "RPWithoutTenant",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- if *encoding == utils.MetaGOB {
- rateProfile.Rates["RT_WEEK"].FilterIDs = nil
- }
- apiRPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- ID: "RPWithoutTenant",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- },
- },
- }
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile, apiRPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *utils.RateProfile
- rateProfile.Tenant = "cgrates.org"
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "RPWithoutTenant"}},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, rateProfile) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rateProfile), utils.ToJSON(result))
- }
-}
-
-func testV1RatePrfRemoveRateProfileWithoutTenant(t *testing.T) {
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "RPWithoutTenant"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "RPWithoutTenant"}},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RatePrfGetRateProfileIDs(t *testing.T) {
- var result []string
- expected := []string{"RP1"}
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfileIDs,
- &utils.PaginatorWithTenant{},
- &result); err != nil {
- t.Error(err)
- } else if len(result) != len(expected) {
- t.Errorf("Expected %+v \n, received %+v", expected, result)
- }
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfileIDs,
- &utils.PaginatorWithTenant{Tenant: "cgrates.org"},
- &result); err != nil {
- t.Error(err)
- } else if len(result) != len(expected) {
- t.Errorf("Expected %+v \n, received %+v", expected, result)
- }
-}
-
-func testV1RatePrfGetRateProfileIDsCount(t *testing.T) {
- var reply int
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfileIDsCount,
- &utils.TenantWithAPIOpts{},
- &reply); err != nil {
- t.Error(err)
- } else if reply != 1 {
- t.Errorf("Expected 1, received %+v", reply)
- }
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"},
- &reply); err != nil {
- t.Error(err)
- } else if reply != 1 {
- t.Errorf("Expected 1, received %+v", reply)
- }
-}
-
-func testV1RatePrfGetRateProfileRatesWithoutTenant(t *testing.T) {
- rPrf := &utils.RateProfile{
- ID: "SpecialRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- },
- },
- }
- apiRPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- ID: "SpecialRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: ";10",
- ActivationTimes: "* * * * 0,6",
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- },
- },
- },
- }
- if *encoding == utils.MetaGOB {
- rPrf.Rates["RT_WEEK"].FilterIDs = nil
- rPrf.Rates["RT_WEEKEND"].FilterIDs = nil
- rPrf.Rates["RT_CHRISTMAS"].FilterIDs = nil
- }
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfileRates, apiRPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- rPrf.Tenant = "cgrates.org"
- var rply *utils.RateProfile
- if err := ratePrfRpc.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "SpecialRate"}},
- &rply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rPrf, rply) {
- t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(rPrf), utils.ToJSON(rply))
- }
-}
-
-func testV1RatePrfRemoveRateProfileRatesWithoutTenant(t *testing.T) {
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1RemoveRateProfileRates,
- &RemoveRPrfRatesWithAPIOpts{ID: "SpecialRate"},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-}
-
-func testV1RateCostForEventWithDefault(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rate1 := &utils.Rate{
- ID: "RATE1",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- rPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- ID: "DefaultRate",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";10",
- Rates: map[string]*utils.APIRate{
- "RATE1": &utils.APIRate{
- ID: "RATE1",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.12),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(60000000000),
- },
- {
- IntervalStart: "1m",
- RecurrentFee: utils.Float64Pointer(0.06),
- Unit: utils.Float64Pointer(60000000000),
- Increment: utils.Float64Pointer(1000000000),
- },
- },
- },
- },
- },
- }
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- },
- }
- exp := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 0.12,
- RateSIntervals: []*utils.RateSInterval{{
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{{
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- }},
- CompressFactor: 1,
- }},
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-}
-
-func testV1RateCostForEventWithUsage(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesUsage: "2m10s",
- },
- },
- }
- rate1 := &utils.Rate{
- ID: "RATE1",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- exp := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 0.19,
- RateSIntervals: []*utils.RateSInterval{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{
- {
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- {
- IncrementStart: utils.NewDecimal(int64(time.Minute), 0),
- Usage: utils.NewDecimal(int64(time.Minute+10*time.Second), 0),
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 70,
- },
- },
- CompressFactor: 1,
- },
- },
- }
-
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-
- argsRt2 := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesUsage: "4h10m15s",
- },
- },
- }
- exp2 := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 15.075,
- RateSIntervals: []*utils.RateSInterval{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{
- {
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- {
- IncrementStart: utils.NewDecimal(int64(time.Minute), 0),
- Usage: utils.NewDecimal(int64(4*time.Hour+9*time.Minute+15*time.Second), 0),
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 14955,
- },
- },
- CompressFactor: 1,
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt2, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp2, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp2), utils.ToJSON(rply))
- }
-}
-
-func testV1RateCostForEventWithWrongUsage(t *testing.T) {
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesUsage: "wrongUsage",
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err == nil ||
- err.Error() != "SERVER_ERROR: can't convert to decimal" {
- t.Errorf("Expected %+v \n, received %+v", "SERVER_ERROR: time: invalid duration \"wrongUsage\"", err)
- }
-}
-
-func testV1RateCostForEventWithStartTime(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rate1 := &utils.Rate{
- ID: "RATE1",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
-
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- },
- },
- }
- exp := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 0.12,
- RateSIntervals: []*utils.RateSInterval{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{
- {
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- },
- CompressFactor: 1,
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-
- argsRt2 := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC).String(),
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt2, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-}
-
-func testV1RateCostForEventWithWrongStartTime(t *testing.T) {
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesStartTime: "wrongTime",
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err == nil ||
- err.Error() != "SERVER_ERROR: Unsupported time format" {
- t.Errorf("Expected %+v \n, received %+v", "SERVER_ERROR: Unsupported time format", err)
- }
-}
-
-func testV1RateCostForEventWithOpts(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.OptsRatesUsage: "2m10s",
- },
- },
- }
- rate1 := &utils.Rate{
- ID: "RATE1",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- exp := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 0.19,
- RateSIntervals: []*utils.RateSInterval{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{
- {
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- {
- IncrementStart: utils.NewDecimal(int64(time.Minute), 0),
- Usage: utils.NewDecimal(int64(time.Minute+10*time.Second), 0),
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 70,
- },
- },
- CompressFactor: 1,
- },
- },
- }
-
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-
- argsRt2 := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.OptsRatesUsage: "4h10m15s",
- },
- },
- }
- exp2 := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 15.075,
- RateSIntervals: []*utils.RateSInterval{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{
- {
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- {
- IncrementStart: utils.NewDecimal(int64(time.Minute), 0),
- Usage: utils.NewDecimal(int64(4*time.Hour+9*time.Minute+15*time.Second), 0),
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 14955,
- },
- },
- CompressFactor: 1,
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt2, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp2, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp2), utils.ToJSON(rply))
- }
-}
-
-/*
-func testV1RateCostForEventSpecial(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rate1 := &engine.Rate{
- ID: "RATE1",
- Weight: 0,
- ActivationTimes: "* * * * *",
- IntervalRates: []*engine.IntervalRate{
- {
- IntervalStart: 0,
- RecurrentFee: utils.NewDecimal(2, 1),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: time.Minute,
- RecurrentFee: utils.NewDecimal(1, 1),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- rtChristmas := &engine.Rate{
- ID: "RT_CHRISTMAS",
- Weight: 30,
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*engine.IntervalRate{{
- IntervalStart: 0,
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- }},
- }
- rPrf := &engine.RateProfileWithOpts{
- RateProfileWithOpts: &engine.RateProfileWithOpts{
- RateProfile: &engine.RateProfile{
- ID: "RateChristmas",
- FilterIDs: []string{"*string:~*req.Subject:1002"},
- Weight: 50,
- Rates: map[string]*engine.Rate{
- "RATE1": rate1,
- "RATE_CHRISTMAS": rtChristmas,
- },
- },
- },
- }
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- var rply *engine.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREventWithOpts: &utils.CGREventWithOpts{
- Opts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2020, 12, 23, 23, 0, 0, 0, time.UTC),
- utils.OptsRatesUsage: "25h12m15s",
- },
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1002",
- },
- },
- },
- }
- exp := &engine.RateProfileCost{
- ID: "RateChristmas",
- Cost: 93.725,
- RateSIntervals: []*engine.RateSInterval{
- {
- UsageStart: 0,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: 0,
- Usage: time.Minute,
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- {
- UsageStart: 1 * time.Minute,
- Usage: 59 * time.Minute,
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 3540,
- },
- },
- CompressFactor: 1,
- },
- {
- UsageStart: time.Hour,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: time.Hour,
- Usage: 24 * time.Hour,
- Rate: rtChristmas,
- IntervalRateIndex: 0,
- CompressFactor: 86400,
- },
- },
- CompressFactor: 1,
- },
- {
- UsageStart: 25 * time.Hour,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: 25 * time.Hour,
- Usage: 735 * time.Second,
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 735,
- },
- },
- CompressFactor: 1,
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
-
- }
-}
-
-func testV1RateCostForEventThreeRates(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rate1 := &engine.Rate{
- ID: "RATE1",
- Weight: 0,
- ActivationTimes: "* * * * *",
- IntervalRates: []*engine.IntervalRate{
- {
- IntervalStart: 0,
- RecurrentFee: utils.NewDecimal(2, 1),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: time.Minute,
- RecurrentFee: utils.NewDecimal(1, 1),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
-
- rtNewYear1 := &engine.Rate{
- ID: "NEW_YEAR1",
- ActivationTimes: "* 12-23 31 12 *",
- Weight: 20,
- IntervalRates: []*engine.IntervalRate{
- {
- IntervalStart: 0,
- RecurrentFee: utils.NewDecimal(8, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- rtNewYear2 := &engine.Rate{
- ID: "NEW_YEAR2",
- ActivationTimes: "* 0-12 1 1 *",
- Weight: 30,
- IntervalRates: []*engine.IntervalRate{
- {
- IntervalStart: 0,
- RecurrentFee: utils.NewDecimal(5, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- }
- rPrf := &engine.RateProfileWithOpts{
- RateProfileWithOpts: &engine.RateProfileWithOpts{
- RateProfile: &engine.RateProfile{
- ID: "RateNewYear",
- FilterIDs: []string{"*string:~*req.Subject:1003"},
- Weight: 50,
- Rates: map[string]*engine.Rate{
- "RATE1": rate1,
- "NEW_YEAR1": rtNewYear1,
- "NEW_YEAR2": rtNewYear2,
- },
- },
- },
- }
- var reply string
- if err := ratePrfRpc.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- var rply *engine.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREventWithOpts: &utils.CGREventWithOpts{
- Opts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2020, 12, 31, 10, 0, 0, 0, time.UTC),
- utils.OptsRatesUsage: "35h12m15s",
- },
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1003",
- },
- },
- },
- }
- exp := &engine.RateProfileCost{
- ID: "RateNewYear",
- Cost: 157.925,
- RateSIntervals: []*engine.RateSInterval{
- {
- UsageStart: 0,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: 0,
- Usage: time.Minute,
- Rate: rate1,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- },
- {
- UsageStart: 1 * time.Minute,
- Usage: 119 * time.Minute,
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 7140,
- },
- },
- CompressFactor: 1,
- },
- {
- UsageStart: 2 * time.Hour,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: 2 * time.Hour,
- Usage: 12 * time.Hour,
- Rate: rtNewYear1,
- IntervalRateIndex: 0,
- CompressFactor: 43200,
- },
- },
- CompressFactor: 1,
- },
- {
- UsageStart: 14 * time.Hour,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: 14 * time.Hour,
- Usage: 46800 * time.Second,
- Rate: rtNewYear2,
- IntervalRateIndex: 0,
- CompressFactor: 46800,
- },
- },
- CompressFactor: 1,
- },
- {
- UsageStart: 27 * time.Hour,
- Increments: []*engine.RateSIncrement{
- {
- UsageStart: 27 * time.Hour,
- Usage: 29535 * time.Second,
- Rate: rate1,
- IntervalRateIndex: 1,
- CompressFactor: 29535,
- },
- },
- CompressFactor: 1,
- },
- },
- }
- if err := ratePrfRpc.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rply))
-
- }
-}
-*/
diff --git a/config/config.go b/config/config.go
index cfa99ac9d..1bc9d506b 100644
--- a/config/config.go
+++ b/config/config.go
@@ -348,7 +348,7 @@ type CGRConfig struct {
var posibleLoaderTypes = utils.NewStringSet([]string{utils.MetaAttributes,
utils.MetaResources, utils.MetaFilters, utils.MetaStats,
utils.MetaRoutes, utils.MetaThresholds, utils.MetaChargers,
- utils.MetaDispatchers, utils.MetaDispatcherHosts, utils.MetaRateProfiles})
+ utils.MetaDispatchers, utils.MetaDispatcherHosts})
var possibleReaderTypes = utils.NewStringSet([]string{utils.MetaFileCSV,
utils.MetaKafkajsonMap, utils.MetaFileXML, utils.MetaSQL, utils.MetaFileFWV,
diff --git a/console/rates_profile.go b/console/rates_profile.go
deleted file mode 100644
index 615eca642..000000000
--- a/console/rates_profile.go
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "github.com/cgrates/cgrates/utils"
-)
-
-func init() {
- c := &CmdGetRateProfile{
- name: "rates_profile",
- rpcMethod: utils.APIerSv1GetRateProfile,
- rpcParams: &utils.TenantIDWithAPIOpts{},
- }
- commands[c.Name()] = c
- c.CommandExecuter = &CommandExecuter{c}
-}
-
-// Commander implementation
-type CmdGetRateProfile struct {
- name string
- rpcMethod string
- rpcParams *utils.TenantIDWithAPIOpts
- *CommandExecuter
-}
-
-func (self *CmdGetRateProfile) Name() string {
- return self.name
-}
-
-func (self *CmdGetRateProfile) RpcMethod() string {
- return self.rpcMethod
-}
-
-func (self *CmdGetRateProfile) RpcParams(reset bool) interface{} {
- if reset || self.rpcParams == nil {
- self.rpcParams = &utils.TenantIDWithAPIOpts{}
- }
- return self.rpcParams
-}
-
-func (self *CmdGetRateProfile) PostprocessRpcParams() error {
- return nil
-}
-
-func (self *CmdGetRateProfile) RpcResult() interface{} {
- var atr utils.RateProfile
- return &atr
-}
diff --git a/console/rates_profile_ids.go b/console/rates_profile_ids.go
deleted file mode 100644
index d754c7d75..000000000
--- a/console/rates_profile_ids.go
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "github.com/cgrates/cgrates/utils"
-)
-
-func init() {
- c := &CmdRateProfileIDs{
- name: "rates_profile_ids",
- rpcMethod: utils.APIerSv1GetRateProfileIDs,
- rpcParams: &utils.PaginatorWithTenant{},
- }
- commands[c.Name()] = c
- c.CommandExecuter = &CommandExecuter{c}
-}
-
-// Commander implementation
-type CmdRateProfileIDs struct {
- name string
- rpcMethod string
- rpcParams *utils.PaginatorWithTenant
- *CommandExecuter
-}
-
-func (self *CmdRateProfileIDs) Name() string {
- return self.name
-}
-
-func (self *CmdRateProfileIDs) RpcMethod() string {
- return self.rpcMethod
-}
-
-func (self *CmdRateProfileIDs) RpcParams(reset bool) interface{} {
- if reset || self.rpcParams == nil {
- self.rpcParams = &utils.PaginatorWithTenant{}
- }
- return self.rpcParams
-}
-
-func (self *CmdRateProfileIDs) PostprocessRpcParams() error {
- return nil
-}
-
-func (self *CmdRateProfileIDs) RpcResult() interface{} {
- var atr []string
- return &atr
-}
diff --git a/console/rates_profile_ids_test.go b/console/rates_profile_ids_test.go
deleted file mode 100644
index c337c84c7..000000000
--- a/console/rates_profile_ids_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdRatesProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["rates_profile_ids"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
- if !ok {
- t.Fatal("method not found")
- }
- if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
- t.Fatalf("invalid number of input parameters ")
- }
- // verify the type of input parameter
- if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
- t.Fatalf("cannot assign input parameter")
- }
- // verify the type of output parameter
- if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
- t.Fatalf("cannot assign output parameter")
- }
- // for coverage purpose
- if err := command.PostprocessRpcParams(); err != nil {
- t.Fatal(err)
- }
-}
diff --git a/console/rates_profile_remove.go b/console/rates_profile_remove.go
deleted file mode 100644
index b56ae2e11..000000000
--- a/console/rates_profile_remove.go
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import "github.com/cgrates/cgrates/utils"
-
-func init() {
- c := &CmdRemoveRateProfile{
- name: "rates_profile_remove",
- rpcMethod: utils.APIerSv1RemoveRateProfile,
- rpcParams: &utils.TenantIDWithAPIOpts{},
- }
- commands[c.Name()] = c
- c.CommandExecuter = &CommandExecuter{c}
-}
-
-type CmdRemoveRateProfile struct {
- name string
- rpcMethod string
- rpcParams *utils.TenantIDWithAPIOpts
- *CommandExecuter
-}
-
-func (self *CmdRemoveRateProfile) Name() string {
- return self.name
-}
-
-func (self *CmdRemoveRateProfile) RpcMethod() string {
- return self.rpcMethod
-}
-
-func (self *CmdRemoveRateProfile) RpcParams(reset bool) interface{} {
- if reset || self.rpcParams == nil {
- self.rpcParams = &utils.TenantIDWithAPIOpts{APIOpts: make(map[string]interface{})}
- }
- return self.rpcParams
-}
-
-func (self *CmdRemoveRateProfile) PostprocessRpcParams() error {
- return nil
-}
-
-func (self *CmdRemoveRateProfile) RpcResult() interface{} {
- var s string
- return &s
-}
diff --git a/console/rates_profile_remove_test.go b/console/rates_profile_remove_test.go
deleted file mode 100644
index 271660bc2..000000000
--- a/console/rates_profile_remove_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdRatesProfileRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["rates_profile_remove"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
- if !ok {
- t.Fatal("method not found")
- }
- if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
- t.Fatalf("invalid number of input parameters ")
- }
- // verify the type of input parameter
- if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
- t.Fatalf("cannot assign input parameter")
- }
- // verify the type of output parameter
- if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
- t.Fatalf("cannot assign output parameter")
- }
- // for coverage purpose
- if err := command.PostprocessRpcParams(); err != nil {
- t.Fatal(err)
- }
-}
diff --git a/console/rates_profile_set.go b/console/rates_profile_set.go
deleted file mode 100644
index de43c1cd4..000000000
--- a/console/rates_profile_set.go
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "github.com/cgrates/cgrates/utils"
-)
-
-func init() {
- c := &CmdSetRateProfile{
- name: "rates_profile_set",
- rpcMethod: utils.APIerSv1SetRateProfile,
- rpcParams: &utils.APIRateProfileWithAPIOpts{},
- }
- commands[c.Name()] = c
- c.CommandExecuter = &CommandExecuter{c}
-}
-
-type CmdSetRateProfile struct {
- name string
- rpcMethod string
- rpcParams *utils.APIRateProfileWithAPIOpts
- *CommandExecuter
-}
-
-func (self *CmdSetRateProfile) Name() string {
- return self.name
-}
-
-func (self *CmdSetRateProfile) RpcMethod() string {
- return self.rpcMethod
-}
-
-func (self *CmdSetRateProfile) RpcParams(reset bool) interface{} {
- if reset || self.rpcParams == nil {
- self.rpcParams = &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: new(utils.APIRateProfile),
- APIOpts: make(map[string]interface{}),
- }
- }
- return self.rpcParams
-}
-
-func (self *CmdSetRateProfile) PostprocessRpcParams() error {
- return nil
-}
-
-func (self *CmdSetRateProfile) RpcResult() interface{} {
- var s string
- return &s
-}
diff --git a/console/rates_profile_set_test.go b/console/rates_profile_set_test.go
deleted file mode 100644
index c833aa725..000000000
--- a/console/rates_profile_set_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdRatesProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["rates_profile_set"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
- if !ok {
- t.Fatal("method not found")
- }
- if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
- t.Fatalf("invalid number of input parameters ")
- }
- // verify the type of input parameter
- if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
- t.Fatalf("cannot assign input parameter")
- }
- // verify the type of output parameter
- if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
- t.Fatalf("cannot assign output parameter")
- }
- // for coverage purpose
- if err := command.PostprocessRpcParams(); err != nil {
- t.Fatal(err)
- }
-}
diff --git a/console/rates_profile_test.go b/console/rates_profile_test.go
deleted file mode 100644
index 97827011b..000000000
--- a/console/rates_profile_test.go
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package console
-
-import (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdRatesProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["rates_profile"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.APIerSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
- if !ok {
- t.Fatal("method not found")
- }
- if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs
- t.Fatalf("invalid number of input parameters ")
- }
- // verify the type of input parameter
- if ok := m.Type.In(1).AssignableTo(reflect.TypeOf(command.RpcParams(true))); !ok {
- t.Fatalf("cannot assign input parameter")
- }
- // verify the type of output parameter
- if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
- t.Fatalf("cannot assign output parameter")
- }
- // for coverage purpose
- if err := command.PostprocessRpcParams(); err != nil {
- t.Fatal(err)
- }
-}
diff --git a/dispatchers/caches_it_test.go b/dispatchers/caches_it_test.go
index e3d395696..c62f2cbd7 100644
--- a/dispatchers/caches_it_test.go
+++ b/dispatchers/caches_it_test.go
@@ -166,56 +166,51 @@ func testDspChcLoadAfterFolder(t *testing.T) {
func testDspChcPrecacheStatus(t *testing.T) {
var reply map[string]string
expected := map[string]string{
- utils.CacheDestinations: utils.MetaReady,
- utils.CacheReverseDestinations: utils.MetaReady,
- utils.CacheRatingPlans: utils.MetaReady,
- utils.CacheRatingProfiles: utils.MetaReady,
- utils.CacheActions: utils.MetaReady,
- utils.CacheActionPlans: utils.MetaReady,
- utils.CacheAccountActionPlans: utils.MetaReady,
- utils.CacheActionTriggers: utils.MetaReady,
- utils.CacheSharedGroups: utils.MetaReady,
- utils.CacheResourceProfiles: utils.MetaReady,
- utils.CacheResources: utils.MetaReady,
- utils.CacheTimings: utils.MetaReady,
- utils.CacheStatQueueProfiles: utils.MetaReady,
- utils.CacheStatQueues: utils.MetaReady,
- utils.CacheThresholdProfiles: utils.MetaReady,
- utils.CacheThresholds: utils.MetaReady,
- utils.CacheFilters: utils.MetaReady,
- utils.CacheRouteProfiles: utils.MetaReady,
- utils.CacheAttributeProfiles: utils.MetaReady,
- utils.CacheChargerProfiles: utils.MetaReady,
- utils.CacheDispatcherProfiles: utils.MetaReady,
- utils.CacheDispatcherHosts: utils.MetaReady,
- utils.CacheDiameterMessages: utils.MetaReady,
- utils.CacheAttributeFilterIndexes: utils.MetaReady,
- utils.CacheResourceFilterIndexes: utils.MetaReady,
- utils.CacheStatFilterIndexes: utils.MetaReady,
- utils.CacheThresholdFilterIndexes: utils.MetaReady,
- utils.CacheRouteFilterIndexes: utils.MetaReady,
- utils.CacheChargerFilterIndexes: utils.MetaReady,
- utils.CacheDispatcherFilterIndexes: utils.MetaReady,
- utils.CacheRateProfilesFilterIndexes: utils.MetaReady,
- utils.CacheRateFilterIndexes: utils.MetaReady,
- utils.CacheRateProfiles: utils.MetaReady,
- utils.CacheLoadIDs: utils.MetaReady,
- utils.CacheCDRIDs: utils.MetaReady,
- utils.CacheClosedSessions: utils.MetaReady,
- utils.CacheDispatcherRoutes: utils.MetaReady,
- utils.CacheEventResources: utils.MetaReady,
- utils.CacheRPCConnections: utils.MetaReady,
- utils.CacheRPCResponses: utils.MetaReady,
- utils.CacheRatingProfilesTmp: utils.MetaReady,
- utils.CacheUCH: utils.MetaReady,
- utils.CacheSTIR: utils.MetaReady,
- utils.CacheDispatcherLoads: utils.MetaReady,
- utils.CacheDispatchers: utils.MetaReady,
- utils.CacheEventCharges: utils.MetaReady,
- utils.CacheReverseFilterIndexes: utils.MetaReady,
- utils.CacheCapsEvents: utils.MetaReady,
- utils.CacheActionProfiles: utils.MetaReady,
- utils.CacheActionProfilesFilterIndexes: utils.MetaReady,
+ utils.CacheDestinations: utils.MetaReady,
+ utils.CacheReverseDestinations: utils.MetaReady,
+ utils.CacheRatingPlans: utils.MetaReady,
+ utils.CacheRatingProfiles: utils.MetaReady,
+ utils.CacheActions: utils.MetaReady,
+ utils.CacheActionPlans: utils.MetaReady,
+ utils.CacheAccountActionPlans: utils.MetaReady,
+ utils.CacheActionTriggers: utils.MetaReady,
+ utils.CacheSharedGroups: utils.MetaReady,
+ utils.CacheResourceProfiles: utils.MetaReady,
+ utils.CacheResources: utils.MetaReady,
+ utils.CacheTimings: utils.MetaReady,
+ utils.CacheStatQueueProfiles: utils.MetaReady,
+ utils.CacheStatQueues: utils.MetaReady,
+ utils.CacheThresholdProfiles: utils.MetaReady,
+ utils.CacheThresholds: utils.MetaReady,
+ utils.CacheFilters: utils.MetaReady,
+ utils.CacheRouteProfiles: utils.MetaReady,
+ utils.CacheAttributeProfiles: utils.MetaReady,
+ utils.CacheChargerProfiles: utils.MetaReady,
+ utils.CacheDispatcherProfiles: utils.MetaReady,
+ utils.CacheDispatcherHosts: utils.MetaReady,
+ utils.CacheDiameterMessages: utils.MetaReady,
+ utils.CacheAttributeFilterIndexes: utils.MetaReady,
+ utils.CacheResourceFilterIndexes: utils.MetaReady,
+ utils.CacheStatFilterIndexes: utils.MetaReady,
+ utils.CacheThresholdFilterIndexes: utils.MetaReady,
+ utils.CacheRouteFilterIndexes: utils.MetaReady,
+ utils.CacheChargerFilterIndexes: utils.MetaReady,
+ utils.CacheDispatcherFilterIndexes: utils.MetaReady,
+ utils.CacheLoadIDs: utils.MetaReady,
+ utils.CacheCDRIDs: utils.MetaReady,
+ utils.CacheClosedSessions: utils.MetaReady,
+ utils.CacheDispatcherRoutes: utils.MetaReady,
+ utils.CacheEventResources: utils.MetaReady,
+ utils.CacheRPCConnections: utils.MetaReady,
+ utils.CacheRPCResponses: utils.MetaReady,
+ utils.CacheRatingProfilesTmp: utils.MetaReady,
+ utils.CacheUCH: utils.MetaReady,
+ utils.CacheSTIR: utils.MetaReady,
+ utils.CacheDispatcherLoads: utils.MetaReady,
+ utils.CacheDispatchers: utils.MetaReady,
+ utils.CacheEventCharges: utils.MetaReady,
+ utils.CacheReverseFilterIndexes: utils.MetaReady,
+ utils.CacheCapsEvents: utils.MetaReady,
utils.CacheAccounts: utils.MetaReady,
utils.CacheVersions: utils.MetaReady,
@@ -241,7 +236,6 @@ func testDspChcPrecacheStatus(t *testing.T) {
utils.CacheTBLTPChargers: utils.MetaReady,
utils.CacheTBLTPDispatchers: utils.MetaReady,
utils.CacheTBLTPDispatcherHosts: utils.MetaReady,
- utils.CacheTBLTPRateProfiles: utils.MetaReady,
utils.MetaAPIBan: utils.MetaReady,
utils.CacheTBLTPActionProfiles: utils.MetaReady,
utils.CacheReplicationHosts: utils.MetaReady,
diff --git a/dispatchers/rates.go b/dispatchers/rates.go
deleted file mode 100644
index fedb79834..000000000
--- a/dispatchers/rates.go
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package dispatchers
-
-import (
- "github.com/cgrates/cgrates/utils"
-)
-
-func (dS *DispatcherService) RateSv1Ping(args *utils.CGREvent, rpl *string) (err error) {
- if args == nil {
- args = new(utils.CGREvent)
- }
- args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
- if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
- if err = dS.authorize(utils.RateSv1Ping, args.Tenant,
- utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.Time); err != nil {
- return
- }
- }
- return dS.Dispatch(args, utils.RateS, utils.RateSv1Ping, args, rpl)
-}
-
-func (dS *DispatcherService) RateSv1CostForEvent(args *utils.ArgsCostForEvent, rpCost *utils.RateProfileCost) (err error) {
- if args == nil {
- args = new(utils.ArgsCostForEvent)
- }
- args.CGREvent.Tenant = utils.FirstNonEmpty(args.CGREvent.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
- if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
- if err = dS.authorize(utils.RateSv1CostForEvent, args.CGREvent.Tenant,
- utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), args.CGREvent.Time); err != nil {
- return
- }
- }
- return dS.Dispatch(args.CGREvent, utils.RateS, utils.RateSv1CostForEvent, args, rpCost)
-}
diff --git a/dispatchers/rates_it_test.go b/dispatchers/rates_it_test.go
deleted file mode 100644
index 3493975fb..000000000
--- a/dispatchers/rates_it_test.go
+++ /dev/null
@@ -1,227 +0,0 @@
-// +build integration
-
-/*
-Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
-Copyright (C) ITsysCOM GmbH
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see
-*/
-
-package dispatchers
-
-import (
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-var sTestsDspRPrf = []func(t *testing.T){
- testDspRPrfPing,
- testDspRPrfCostForEvent,
- testDspRPrfCostForEventWithoutFilters,
-}
-
-//Test start here
-func TestDspRateSIT(t *testing.T) {
- var config1, config2, config3 string
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- config1 = "all_mysql"
- config2 = "all2_mysql"
- config3 = "dispatchers_mysql"
- case utils.MetaMongo:
- config1 = "all_mongo"
- config2 = "all2_mongo"
- config3 = "dispatchers_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- dispDIR := "dispatchers"
- if *encoding == utils.MetaGOB {
- dispDIR += "_gob"
- }
- testDsp(t, sTestsDspRPrf, "TestDspRateSIT", config1, config2, config3, "tutorial", "oldtutorial", dispDIR)
-}
-
-func testDspRPrfPing(t *testing.T) {
- var reply string
- if err := allEngine.RPC.Call(utils.RateSv1Ping, new(utils.CGREvent), &reply); err != nil {
- t.Error(err)
- } else if reply != utils.Pong {
- t.Errorf("Received: %s", reply)
- }
- if err := dispEngine.RPC.Call(utils.RateSv1Ping, utils.CGREvent{
- Tenant: "cgrates.org",
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rPrf12345",
- },
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.Pong {
- t.Errorf("Received: %s", reply)
- }
-}
-
-func testDspRPrfCostForEvent(t *testing.T) {
- rPrf := &utils.APIRateProfile{
- ID: "DefaultRate",
- Tenant: "cgrates.org",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";10",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.12),
- Unit: utils.Float64Pointer(float64(time.Minute)),
- Increment: utils.Float64Pointer(float64(time.Minute)),
- },
- },
- },
- },
- }
- var reply string
- if err := allEngine.RPC.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK, received %+v", reply)
- }
- var rply *utils.RateProfile
- if err := allEngine.RPC.Call(utils.APIerSv1GetRateProfile, &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "DefaultRate",
- }, &rply); err != nil {
- t.Error(err)
- }
- rtWeek, err := rPrf.Rates["RT_WEEK"].AsRate()
- if err != nil {
- t.Fatal(err)
- }
- exp := &utils.RateProfileCost{
- ID: "DefaultRate",
- Cost: 0.12,
- RateSIntervals: []*utils.RateSInterval{{
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{{
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rtWeek,
- IntervalRateIndex: 0,
- CompressFactor: 1,
- }},
- CompressFactor: 1,
- }},
- }
-
- var rpCost *utils.RateProfileCost
- if err := dispEngine.RPC.Call(utils.RateSv1CostForEvent, &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "DefaultRate",
- Event: map[string]interface{}{
- utils.Subject: "1001",
- },
-
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rPrf12345",
- }}}, &rpCost); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rpCost, exp) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(exp), utils.ToJSON(rpCost))
- }
-}
-
-func testDspRPrfCostForEventWithoutFilters(t *testing.T) {
- rPrf := &utils.APIRateProfile{
- ID: "ID_RP",
- Tenant: "cgrates.org",
- Weights: ";10",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.25),
- Unit: utils.Float64Pointer(float64(time.Minute)),
- Increment: utils.Float64Pointer(float64(time.Second)),
- },
- },
- },
- },
- }
- var reply string
- if err := allEngine.RPC.Call(utils.APIerSv1SetRateProfile, rPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK, received %+v", reply)
- }
- var rply *utils.RateProfile
- if err := allEngine.RPC.Call(utils.APIerSv1GetRateProfile, &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ID_RP",
- }, &rply); err != nil {
- t.Error(err)
- }
- rtWeek, err := rPrf.Rates["RT_WEEK"].AsRate()
- if err != nil {
- t.Fatal(err)
- }
- exp := &utils.RateProfileCost{
- ID: "ID_RP",
- Cost: 0.25,
- RateSIntervals: []*utils.RateSInterval{{
- IntervalStart: utils.NewDecimal(0, 0),
- Increments: []*utils.RateSIncrement{{
- IncrementStart: utils.NewDecimal(0, 0),
- Usage: utils.NewDecimal(int64(time.Minute), 0),
- Rate: rtWeek,
- IntervalRateIndex: 0,
- CompressFactor: 60,
- }},
- CompressFactor: 1,
- }},
- }
-
- var rpCost *utils.RateProfileCost
- if err := dispEngine.RPC.Call(utils.RateSv1CostForEvent, &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
-
- Tenant: "cgrates.org",
- ID: "EVENT_RATE",
- Event: map[string]interface{}{
- utils.Subject: "1002",
- },
-
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rPrf12345",
- }}}, &rpCost); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rpCost, exp) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(exp), utils.ToJSON(rpCost))
- }
-}
diff --git a/dispatchers/replicator.go b/dispatchers/replicator.go
index d67f0002e..44a9aadc2 100644
--- a/dispatchers/replicator.go
+++ b/dispatchers/replicator.go
@@ -459,24 +459,6 @@ func (dS *DispatcherService) ReplicatorSv1GetDispatcherHost(args *utils.TenantID
}, utils.MetaReplicator, utils.ReplicatorSv1GetDispatcherHost, args, reply)
}
-func (dS *DispatcherService) ReplicatorSv1GetRateProfile(args *utils.TenantIDWithAPIOpts, reply *utils.RateProfile) (err error) {
- tnt := dS.cfg.GeneralCfg().DefaultTenant
- if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
- tnt = args.TenantID.Tenant
- }
- if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
- if err = dS.authorize(utils.ReplicatorSv1GetRateProfile, tnt,
- utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
- return
- }
- }
- return dS.Dispatch(&utils.CGREvent{
- Tenant: tnt,
- ID: args.ID,
- APIOpts: args.APIOpts,
- }, utils.MetaReplicator, utils.ReplicatorSv1GetRateProfile, args, reply)
-}
-
func (dS *DispatcherService) ReplicatorSv1GetActionProfile(args *utils.TenantIDWithAPIOpts, reply *engine.ActionProfile) (err error) {
tnt := dS.cfg.GeneralCfg().DefaultTenant
if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
@@ -852,23 +834,6 @@ func (dS *DispatcherService) ReplicatorSv1SetDispatcherProfile(args *engine.Disp
}, utils.MetaReplicator, utils.ReplicatorSv1SetDispatcherProfile, args, rpl)
}
-func (dS *DispatcherService) ReplicatorSv1SetRateProfile(args *utils.RateProfileWithAPIOpts, rpl *string) (err error) {
- if args == nil {
- args = &utils.RateProfileWithAPIOpts{}
- }
- args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
- if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
- if err = dS.authorize(utils.ReplicatorSv1SetRateProfile, args.Tenant,
- utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
- return
- }
- }
- return dS.Dispatch(&utils.CGREvent{
- Tenant: args.Tenant,
- APIOpts: args.APIOpts,
- }, utils.MetaReplicator, utils.ReplicatorSv1SetRateProfile, args, rpl)
-}
-
func (dS *DispatcherService) ReplicatorSv1SetActionProfile(args *engine.ActionProfileWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &engine.ActionProfileWithAPIOpts{}
@@ -1328,23 +1293,6 @@ func (dS *DispatcherService) ReplicatorSv1RemoveDispatcherHost(args *utils.Tenan
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveDispatcherHost, args, rpl)
}
-func (dS *DispatcherService) ReplicatorSv1RemoveRateProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {
- if args == nil {
- args = &utils.TenantIDWithAPIOpts{}
- }
- args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
- if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
- if err = dS.authorize(utils.ReplicatorSv1RemoveRateProfile, args.Tenant,
- utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
- return
- }
- }
- return dS.Dispatch(&utils.CGREvent{
- Tenant: args.Tenant,
- APIOpts: args.APIOpts,
- }, utils.MetaReplicator, utils.ReplicatorSv1RemoveRateProfile, args, rpl)
-}
-
func (dS *DispatcherService) ReplicatorSv1RemoveActionProfile(args *utils.TenantIDWithAPIOpts, rpl *string) (err error) {
if args == nil {
args = &utils.TenantIDWithAPIOpts{}
diff --git a/dispatchers/replicator_it_test.go b/dispatchers/replicator_it_test.go
index 6a05ec5f4..fadd6cd36 100644
--- a/dispatchers/replicator_it_test.go
+++ b/dispatchers/replicator_it_test.go
@@ -53,7 +53,6 @@ var sTestsDspRpl = []func(t *testing.T){
testDspRplRatingPlan,
testDspRplRatingProfile,
testDspRplDestination,
- testDspRplRateProfile,
testDspRplActionProfile,
}
@@ -1469,94 +1468,6 @@ func testDspRplLoadIDs(t *testing.T) {
allEngine.startEngine(t)
}
-func testDspRplRateProfile(t *testing.T) {
- // Set RateProfile
- var replyStr string
- rPrf := &utils.RateProfileWithAPIOpts{
- RateProfile: &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "FIRST_GI": {
- ID: "FIRST_GI",
- FilterIDs: []string{"*gi:~*req.Usage:0"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- Blocker: false,
- },
- "SECOND_GI": {
- ID: "SECOND_GI",
- FilterIDs: []string{"*gi:~*req.Usage:1m"},
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Blocker: false,
- },
- },
- },
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "repl12345",
- },
- }
- if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetRateProfile, rPrf, &replyStr); err != nil {
- t.Error("Unexpected error when calling ReplicatorSv1.SetRateProfile: ", err)
- } else if replyStr != utils.OK {
- t.Error("Unexpected reply returned", replyStr)
- }
- // Get RateProfile
- var reply *utils.RateProfile
- args := &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "RP1",
- },
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "repl12345",
- },
- }
- if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRateProfile, args, &reply); err != nil {
- t.Error("Unexpected error when calling ReplicatorSv1.GetRateProfile: ", err)
- } else if !reflect.DeepEqual(rPrf.RateProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v, ", rPrf.RateProfile, reply)
- }
- // Stop engine 1
- allEngine.stopEngine(t)
-
- // Get RateProfile
- if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRateProfile, args, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
- }
-
- // Start engine 1
- allEngine.startEngine(t)
-
- // Remove RateProfile
- if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveRateProfile, args, &replyStr); err != nil {
- t.Error(err)
- } else if replyStr != utils.OK {
- t.Error("Unexpected reply returned", replyStr)
- }
-
- // Get RateProfile
- if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetRateProfile, args, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
- }
-}
-
func testDspRplActionProfile(t *testing.T) {
// Set RateProfile
var replyStr string
diff --git a/engine/caches.go b/engine/caches.go
index a7e6a7b35..be591ef54 100644
--- a/engine/caches.go
+++ b/engine/caches.go
@@ -64,9 +64,6 @@ func init() {
gob.Register(new(DispatcherHost))
gob.Register(new(DispatcherHostProfile))
gob.Register(new(DispatcherHostWithAPIOpts))
- // RateProfiles
- gob.Register(new(utils.RateProfile))
- gob.Register(new(utils.RateProfileWithAPIOpts))
// ActionProfiles
gob.Register(new(ActionProfile))
gob.Register(new(ActionProfileWithAPIOpts))
diff --git a/engine/datadbmock.go b/engine/datadbmock.go
index b31565a90..9ab998c38 100644
--- a/engine/datadbmock.go
+++ b/engine/datadbmock.go
@@ -382,18 +382,6 @@ func (dbM *DataDBMock) RemoveDispatcherHostDrv(string, string) error {
return utils.ErrNotImplemented
}
-func (dbM *DataDBMock) GetRateProfileDrv(string, string) (*utils.RateProfile, error) {
- return nil, utils.ErrNotImplemented
-}
-
-func (dbM *DataDBMock) SetRateProfileDrv(*utils.RateProfile) error {
- return utils.ErrNotImplemented
-}
-
-func (dbM *DataDBMock) RemoveRateProfileDrv(string, string) error {
- return utils.ErrNotImplemented
-}
-
func (dbM *DataDBMock) GetActionProfileDrv(string, string) (*ActionProfile, error) {
return nil, utils.ErrNotImplemented
}
diff --git a/engine/datamanager.go b/engine/datamanager.go
index 3a7b5fd12..687f3b06b 100644
--- a/engine/datamanager.go
+++ b/engine/datamanager.go
@@ -35,9 +35,7 @@ var (
utils.RouteFilterIndexes: {},
utils.ChargerFilterIndexes: {},
utils.DispatcherFilterIndexes: {},
- utils.RateProfilesFilterIndexPrfx: {},
utils.ActionProfilesFilterIndexPrfx: {},
- utils.RateFilterIndexPrfx: {},
utils.ActionPlanIndexes: {},
utils.FilterIndexPrfx: {},
}
@@ -64,7 +62,6 @@ var (
utils.ChargerProfilePrefix: {},
utils.DispatcherProfilePrefix: {},
utils.DispatcherHostPrefix: {},
- utils.RateProfilePrefix: {},
utils.ActionProfilePrefix: {},
utils.AttributeFilterIndexes: {},
utils.ResourceFilterIndexes: {},
@@ -73,9 +70,7 @@ var (
utils.RouteFilterIndexes: {},
utils.ChargerFilterIndexes: {},
utils.DispatcherFilterIndexes: {},
- utils.RateProfilesFilterIndexPrfx: {},
utils.ActionProfilesFilterIndexPrfx: {},
- utils.RateFilterIndexPrfx: {},
utils.FilterIndexPrfx: {},
utils.MetaAPIBan: {}, // not realy a prefix as this is not stored in DB
}
@@ -222,9 +217,6 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
case utils.DispatcherHostPrefix:
tntID := utils.NewTenantID(dataID)
_, err = dm.GetDispatcherHost(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
- case utils.RateProfilePrefix:
- tntID := utils.NewTenantID(dataID)
- _, err = dm.GetRateProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
case utils.ActionProfilePrefix:
tntID := utils.NewTenantID(dataID)
_, err = dm.GetActionProfile(tntID.Tenant, tntID.ID, false, true, utils.NonTransactional)
@@ -270,18 +262,6 @@ func (dm *DataManager) CacheDataFromDB(prfx string, ids []string, mustBeCached b
return
}
_, err = dm.GetIndexes(utils.CacheDispatcherFilterIndexes, tntCtx, idxKey, false, true)
- case utils.RateProfilesFilterIndexPrfx:
- var tntCtx, idxKey string
- if tntCtx, idxKey, err = splitFilterIndex(dataID); err != nil {
- return
- }
- _, err = dm.GetIndexes(utils.CacheRateProfilesFilterIndexes, tntCtx, idxKey, false, true)
- case utils.RateFilterIndexPrfx:
- var tntCtx, idxKey string
- if tntCtx, idxKey, err = splitFilterIndex(dataID); err != nil {
- return
- }
- _, err = dm.GetIndexes(utils.CacheRateFilterIndexes, tntCtx, idxKey, false, true)
case utils.ActionProfilesFilterIndexPrfx:
var tntCtx, idxKey string
if tntCtx, idxKey, err = splitFilterIndex(dataID); err != nil {
@@ -3029,276 +3009,6 @@ func (dm *DataManager) SetLoadIDs(loadIDs map[string]int64) (err error) {
return
}
-func (dm *DataManager) GetRateProfile(tenant, id string, cacheRead, cacheWrite bool,
- transactionID string) (rpp *utils.RateProfile, err error) {
- tntID := utils.ConcatenatedKey(tenant, id)
- if cacheRead {
- if x, ok := Cache.Get(utils.CacheRateProfiles, tntID); ok {
- if x == nil {
- return nil, utils.ErrNotFound
- }
- return x.(*utils.RateProfile), nil
- }
- }
- if dm == nil {
- err = utils.ErrNoDatabaseConn
- return
- }
- rpp, err = dm.dataDB.GetRateProfileDrv(tenant, id)
- if err != nil {
- if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRateProfiles]; err == utils.ErrNotFound && itm.Remote {
- if err = dm.connMgr.Call(config.CgrConfig().DataDbCfg().RmtConns, nil,
- utils.ReplicatorSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: tenant, ID: id},
- APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID, utils.EmptyString,
- utils.FirstNonEmpty(config.CgrConfig().DataDbCfg().RmtConnID,
- config.CgrConfig().GeneralCfg().NodeID)),
- }, &rpp); err == nil {
- rpp.Sort()
- err = dm.dataDB.SetRateProfileDrv(rpp)
- }
- }
- if err != nil {
- err = utils.CastRPCErr(err)
- if err == utils.ErrNotFound && cacheWrite {
- if errCh := Cache.Set(utils.CacheRateProfiles, tntID, nil, nil,
- cacheCommit(transactionID), transactionID); errCh != nil {
- return nil, errCh
- }
-
- }
- return nil, err
- }
- }
- if err = rpp.Compile(); err != nil {
- return nil, err
- }
- if cacheWrite {
- if errCh := Cache.Set(utils.CacheRateProfiles, tntID, rpp, nil,
- cacheCommit(transactionID), transactionID); errCh != nil {
- return nil, errCh
- }
- }
- return
-}
-
-func (dm *DataManager) SetRateProfile(rpp *utils.RateProfile, withIndex bool) (err error) {
- if dm == nil {
- return utils.ErrNoDatabaseConn
- }
- if withIndex {
- if brokenReference := dm.checkFilters(rpp.Tenant, rpp.FilterIDs); len(brokenReference) != 0 {
- // if we get a broken filter do not set the profile
- return fmt.Errorf("broken reference to filter: %+v for item with ID: %+v",
- brokenReference, rpp.TenantID())
- }
- for _, rate := range rpp.Rates {
- if brokenReference := dm.checkFilters(rpp.Tenant, rate.FilterIDs); len(brokenReference) != 0 {
- // if we get a broken filter do not update the rates
- return fmt.Errorf("broken reference to filter: %+v for rate with ID: %+v",
- brokenReference, rate.ID)
- }
- }
- }
- oldRpp, err := dm.GetRateProfile(rpp.Tenant, rpp.ID, true, false, utils.NonTransactional)
- if err != nil && err != utils.ErrNotFound {
- return err
- }
- rpp.Sort()
- if err = dm.DataDB().SetRateProfileDrv(rpp); err != nil {
- return err
- }
- if withIndex {
- var oldFiltersIDs *[]string
- if oldRpp != nil {
- oldFiltersIDs = &oldRpp.FilterIDs
- }
- if err := updatedIndexes(dm, utils.CacheRateProfilesFilterIndexes, rpp.Tenant,
- utils.EmptyString, rpp.ID, oldFiltersIDs, rpp.FilterIDs, false); err != nil {
- return err
- }
- // remove indexes for old rates
- if oldRpp != nil {
- for key, rate := range oldRpp.Rates {
- if _, has := rpp.Rates[key]; has {
- continue
- }
- if err = removeItemFromFilterIndex(dm, utils.CacheRateFilterIndexes,
- rpp.Tenant, rpp.ID, key, rate.FilterIDs); err != nil {
- return
- }
- }
- }
- // create index for each rate
- for key, rate := range rpp.Rates {
- var oldRateFiltersIDs *[]string
- if oldRpp != nil {
- if oldRate, has := oldRpp.Rates[key]; has {
- oldRateFiltersIDs = &oldRate.FilterIDs
- }
- }
- // when we create the indexes for rates we use RateProfile ID as context
- if err := updatedIndexes(dm, utils.CacheRateFilterIndexes, rpp.Tenant,
- rpp.ID, key, oldRateFiltersIDs, rate.FilterIDs, true); err != nil {
- return err
- }
- }
-
- }
- if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRateProfiles]; itm.Replicate {
- err = replicate(dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
- config.CgrConfig().DataDbCfg().RplFiltered,
- utils.RateProfilePrefix, rpp.TenantID(), // this are used to get the host IDs from cache
- utils.ReplicatorSv1SetRateProfile,
- &utils.RateProfileWithAPIOpts{
- RateProfile: rpp,
- APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
- config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString)})
- }
- return
-}
-
-func (dm *DataManager) RemoveRateProfile(tenant, id string,
- transactionID string, withIndex bool) (err error) {
- if dm == nil {
- return utils.ErrNoDatabaseConn
- }
- oldRpp, err := dm.GetRateProfile(tenant, id, true, false, utils.NonTransactional)
- if err != nil && err != utils.ErrNotFound {
- return err
- }
- if err = dm.DataDB().RemoveRateProfileDrv(tenant, id); err != nil {
- return
- }
- if oldRpp == nil {
- return utils.ErrNotFound
- }
- if withIndex {
- for key, rate := range oldRpp.Rates {
- if err = removeItemFromFilterIndex(dm, utils.CacheRateFilterIndexes,
- oldRpp.Tenant, oldRpp.ID, key, rate.FilterIDs); err != nil {
- return
- }
- }
- if err = removeItemFromFilterIndex(dm, utils.CacheRateProfilesFilterIndexes,
- tenant, utils.EmptyString, id, oldRpp.FilterIDs); err != nil {
- return
- }
- }
- if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRateProfiles]; itm.Replicate {
- replicate(dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
- config.CgrConfig().DataDbCfg().RplFiltered,
- utils.RateProfilePrefix, utils.ConcatenatedKey(tenant, id), // this are used to get the host IDs from cache
- utils.ReplicatorSv1RemoveRateProfile,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: tenant, ID: id},
- APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
- config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString)})
- }
- return
-}
-
-func (dm *DataManager) RemoveRateProfileRates(tenant, id string, rateIDs []string, withIndex bool) (err error) {
- if dm == nil {
- return utils.ErrNoDatabaseConn
- }
- oldRpp, err := dm.GetRateProfile(tenant, id, true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- if len(rateIDs) == 0 {
- if withIndex {
- for key, rate := range oldRpp.Rates {
- if err = removeItemFromFilterIndex(dm, utils.CacheRateFilterIndexes,
- tenant, id, key, rate.FilterIDs); err != nil {
- return
- }
- }
- }
- oldRpp.Rates = map[string]*utils.Rate{}
- } else {
- for _, rateID := range rateIDs {
- if _, has := oldRpp.Rates[rateID]; !has {
- continue
- }
- if withIndex {
-
- if err = removeItemFromFilterIndex(dm, utils.CacheRateFilterIndexes,
- tenant, id, rateID, oldRpp.Rates[rateID].FilterIDs); err != nil {
- return
- }
- }
- delete(oldRpp.Rates, rateID)
- }
- }
- if err = dm.DataDB().SetRateProfileDrv(oldRpp); err != nil {
- return err
- }
-
- if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRateProfiles]; itm.Replicate {
- err = replicate(dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
- config.CgrConfig().DataDbCfg().RplFiltered,
- utils.RateProfilePrefix, oldRpp.TenantID(), // this are used to get the host IDs from cache
- utils.ReplicatorSv1SetRateProfile,
- &utils.RateProfileWithAPIOpts{
- RateProfile: oldRpp,
- APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
- config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString)})
- }
- return
-}
-
-func (dm *DataManager) SetRateProfileRates(rpp *utils.RateProfile, withIndex bool) (err error) {
- if dm == nil {
- return utils.ErrNoDatabaseConn
- }
- if withIndex {
- for _, rate := range rpp.Rates {
- if brokenReference := dm.checkFilters(rpp.Tenant, rate.FilterIDs); len(brokenReference) != 0 {
- // if we get a broken filter do not update the rates
- return fmt.Errorf("broken reference to filter: %+v for rate with ID: %+v",
- brokenReference, rate.ID)
- }
- }
- }
- oldRpp, err := dm.GetRateProfile(rpp.Tenant, rpp.ID, true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- // create index for each rate
- for key, rate := range rpp.Rates {
- if withIndex {
- var oldRateFiltersIDs *[]string
- if oldRate, has := oldRpp.Rates[key]; has {
- oldRateFiltersIDs = &oldRate.FilterIDs
- }
- // when we create the indexes for rates we use RateProfile ID as context
- if err := updatedIndexes(dm, utils.CacheRateFilterIndexes, rpp.Tenant,
- rpp.ID, key, oldRateFiltersIDs, rate.FilterIDs, true); err != nil {
- return err
- }
- }
- oldRpp.Rates[key] = rate
- }
-
- if err = dm.DataDB().SetRateProfileDrv(oldRpp); err != nil {
- return err
- }
-
- if itm := config.CgrConfig().DataDbCfg().Items[utils.MetaRateProfiles]; itm.Replicate {
- err = replicate(dm.connMgr, config.CgrConfig().DataDbCfg().RplConns,
- config.CgrConfig().DataDbCfg().RplFiltered,
- utils.RateProfilePrefix, oldRpp.TenantID(), // this are used to get the host IDs from cache
- utils.ReplicatorSv1SetRateProfile,
- &utils.RateProfileWithAPIOpts{
- RateProfile: oldRpp,
- APIOpts: utils.GenerateDBItemOpts(itm.APIKey, itm.RouteID,
- config.CgrConfig().DataDbCfg().RplCache, utils.EmptyString)})
- }
- return
-}
-
func (dm *DataManager) GetActionProfile(tenant, id string, cacheRead, cacheWrite bool,
transactionID string) (ap *ActionProfile, err error) {
tntID := utils.ConcatenatedKey(tenant, id)
diff --git a/engine/libindex.go b/engine/libindex.go
index f90ffec5a..ca6e3baf8 100644
--- a/engine/libindex.go
+++ b/engine/libindex.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package engine
import (
- "errors"
"fmt"
"strings"
@@ -179,8 +178,6 @@ func removeItemFromFilterIndex(dm *DataManager, idxItmType, tnt, ctx, itemID str
// itemID - the object id
// oldFilterIds - the filtersIDs that the old object had; this is optional if the object did not exist
// newFilterIDs - the filtersIDs for the object that will be set
-// useCtx - in case of subindexes(e.g. Rate from RateProfiles) need to add the ctx to the itemID when reverse filter indexes are set
-// used when updating the filters
func updatedIndexes(dm *DataManager, idxItmType, tnt, ctx, itemID string, oldFilterIds *[]string, newFilterIDs []string, useCtx bool) (err error) {
itmCtx := itemID
if useCtx {
@@ -713,73 +710,6 @@ func UpdateFilterIndex(dm *DataManager, oldFlt, newFlt *Filter) (err error) {
}); err != nil && err != utils.ErrNotFound {
return utils.APIErrorHandler(err)
}
- case utils.CacheRateProfilesFilterIndexes:
- if err = removeFilterIndexesForFilter(dm, idxItmType, newFlt.Tenant, //remove the indexes for the filter
- removeIndexKeys, indx); err != nil {
- return
- }
- idxSlice := indx.AsSlice()
- if _, err = ComputeIndexes(dm, newFlt.Tenant, utils.EmptyString, idxItmType, // compute all the indexes for afected items
- &idxSlice, utils.NonTransactional, func(tnt, id, ctx string) (*[]string, error) {
- rp, e := dm.GetRateProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(rp.FilterIDs))
- for i, fltrID := range rp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
-
- case utils.CacheRateFilterIndexes:
- itemIDs := make(map[string]utils.StringSet)
- for itemID := range indx {
- idSplit := strings.SplitN(itemID, utils.ConcatenatedKeySep, 2)
- if len(idSplit) < 2 {
- return errors.New("Expected to be 2 values")
- }
- if itemIDs[idSplit[1]] == nil {
- itemIDs[idSplit[1]] = make(utils.StringSet)
- }
- itemIDs[idSplit[1]].Add(idSplit[0])
- }
- for rpID, ids := range itemIDs {
- tntCtx := utils.ConcatenatedKey(newFlt.Tenant, rpID)
- if err = removeFilterIndexesForFilter(dm, idxItmType, tntCtx,
- removeIndexKeys, ids); err != nil {
- return
- }
- var rp *utils.RateProfile
- if rp, err = dm.GetRateProfile(newFlt.Tenant, rpID, true, false, utils.NonTransactional); err != nil {
- return
- }
- for itemID := range ids {
- rate, has := rp.Rates[itemID]
- if !has {
- return utils.ErrNotFound
- }
- refID := guardian.Guardian.GuardIDs(utils.EmptyString,
- config.CgrConfig().GeneralCfg().LockingTimeout, idxItmType+tntCtx)
- var updIdx map[string]utils.StringSet
- if updIdx, err = newFilterIndex(dm, idxItmType,
- newFlt.Tenant, rpID, itemID, rate.FilterIDs); err != nil {
- guardian.Guardian.UnguardIDs(refID)
- return
- }
- for _, idx := range updIdx {
- idx.Add(itemID)
- }
- if err = dm.SetIndexes(idxItmType, tntCtx,
- updIdx, false, utils.NonTransactional); err != nil {
- guardian.Guardian.UnguardIDs(refID)
- return
- }
- guardian.Guardian.UnguardIDs(refID)
- }
- }
case utils.CacheAttributeFilterIndexes:
for itemID := range indx {
var ap *AttributeProfile
diff --git a/engine/libtest.go b/engine/libtest.go
index d6e19adc7..a6c6c2fe4 100644
--- a/engine/libtest.go
+++ b/engine/libtest.go
@@ -280,22 +280,6 @@ cgrates.org,D1,,,,*first,,C2,*lt:~*req.Usage:10,10,false,192.168.56.204,
DispatcherHostCSVContent = `
#Tenant[0],ID[1],Address[2],Transport[3],TLS[4]
cgrates.org,ALL1,127.0.0.1:2012,*json,true
-`
- RateProfileCSVContent = `
-#Tenant,ID,FilterIDs,ActivationInterval,Weights,MinCost,MaxCost,MaxCostStrategy,RateID,RateFilterIDs,RateActivationStart,RateWeights,RateBlocker,RateIntervalStart,RateFixedFee,RateRecurrentFee,RateUnit,RateIncrement
-cgrates.org,RP1,*string:~*req.Subject:1001,,;0,0.1,0.6,*free,RT_WEEK,,"* * * * 1-5",;0,false,0s,0,0.12,1m,1m
-cgrates.org,RP1,,,,,,,RT_WEEK,,,,,1m,1.234,0.06,1m,1s
-cgrates.org,RP1,,,,,,,RT_WEEKEND,,"* * * * 0,6",;10,false,0s,0.089,0.06,1m,1s
-cgrates.org,RP1,,,,,,,RT_CHRISTMAS,,* * 24 12 *,;30,false,0s,0.0564,0.06,1m,1s
-`
- ActionProfileCSVContent = `
-#Tenant,ID,FilterIDs,ActivationInterval,Weight,Schedule,TargetType,TargetIDs,ActionID,ActionFilterIDs,ActionBlocker,ActionTTL,ActionType,ActionOpts,ActionPath,ActionValue
-cgrates.org,ONE_TIME_ACT,,,10,*asap,*accounts,1001;1002,TOPUP,,false,0s,*add_balance,,*balance.TestBalance.Value,10
-cgrates.org,ONE_TIME_ACT,,,,,,,SET_BALANCE_TEST_DATA,,false,0s,*set_balance,,*balance.TestDataBalance.Type,*data
-cgrates.org,ONE_TIME_ACT,,,,,,,TOPUP_TEST_DATA,,false,0s,*add_balance,,*balance.TestDataBalance.Value,1024
-cgrates.org,ONE_TIME_ACT,,,,,,,SET_BALANCE_TEST_VOICE,,false,0s,*set_balance,,*balance.TestVoiceBalance.Type,*voice
-cgrates.org,ONE_TIME_ACT,,,,,,,TOPUP_TEST_VOICE,,false,0s,*add_balance,,*balance.TestVoiceBalance.Value,15m15s
-cgrates.org,ONE_TIME_ACT,,,,,,,TOPUP_TEST_VOICE,,false,0s,*add_balance,,*balance.TestVoiceBalance2.Value,15m15s
`
)
@@ -502,59 +486,54 @@ func CallScript(scriptPath string, subcommand string, waitMs int) error {
func GetDefaultEmptyCacheStats() map[string]*ltcache.CacheStats {
return map[string]*ltcache.CacheStats{
- utils.MetaDefault: {},
- utils.CacheAccountActionPlans: {},
- utils.CacheActionPlans: {},
- utils.CacheActionTriggers: {},
- utils.CacheActions: {},
- utils.CacheAttributeFilterIndexes: {},
- utils.CacheAttributeProfiles: {},
- utils.CacheChargerFilterIndexes: {},
- utils.CacheChargerProfiles: {},
- utils.CacheDispatcherFilterIndexes: {},
- utils.CacheDispatcherProfiles: {},
- utils.CacheDispatcherHosts: {},
- utils.CacheDispatcherRoutes: {},
- utils.CacheDispatcherLoads: {},
- utils.CacheDispatchers: {},
- utils.CacheDestinations: {},
- utils.CacheEventResources: {},
- utils.CacheFilters: {},
- utils.CacheRatingPlans: {},
- utils.CacheRatingProfiles: {},
- utils.CacheResourceFilterIndexes: {},
- utils.CacheResourceProfiles: {},
- utils.CacheResources: {},
- utils.CacheReverseDestinations: {},
- utils.CacheRPCResponses: {},
- utils.CacheSharedGroups: {},
- utils.CacheStatFilterIndexes: {},
- utils.CacheStatQueueProfiles: {},
- utils.CacheStatQueues: {},
- utils.CacheSTIR: {},
- utils.CacheRouteFilterIndexes: {},
- utils.CacheRouteProfiles: {},
- utils.CacheThresholdFilterIndexes: {},
- utils.CacheThresholdProfiles: {},
- utils.CacheThresholds: {},
- utils.CacheRateProfiles: {},
- utils.CacheRateProfilesFilterIndexes: {},
- utils.CacheRateFilterIndexes: {},
- utils.CacheTimings: {},
- utils.CacheDiameterMessages: {},
- utils.CacheClosedSessions: {},
- utils.CacheLoadIDs: {},
- utils.CacheRPCConnections: {},
- utils.CacheCDRIDs: {},
- utils.CacheRatingProfilesTmp: {},
- utils.CacheUCH: {},
- utils.CacheEventCharges: {},
- utils.CacheReverseFilterIndexes: {},
- utils.MetaAPIBan: {},
- utils.CacheCapsEvents: {},
- utils.CacheActionProfiles: {},
- utils.CacheActionProfilesFilterIndexes: {},
- utils.CacheReplicationHosts: {},
+ utils.MetaDefault: {},
+ utils.CacheAccountActionPlans: {},
+ utils.CacheActionPlans: {},
+ utils.CacheActionTriggers: {},
+ utils.CacheActions: {},
+ utils.CacheAttributeFilterIndexes: {},
+ utils.CacheAttributeProfiles: {},
+ utils.CacheChargerFilterIndexes: {},
+ utils.CacheChargerProfiles: {},
+ utils.CacheDispatcherFilterIndexes: {},
+ utils.CacheDispatcherProfiles: {},
+ utils.CacheDispatcherHosts: {},
+ utils.CacheDispatcherRoutes: {},
+ utils.CacheDispatcherLoads: {},
+ utils.CacheDispatchers: {},
+ utils.CacheDestinations: {},
+ utils.CacheEventResources: {},
+ utils.CacheFilters: {},
+ utils.CacheRatingPlans: {},
+ utils.CacheRatingProfiles: {},
+ utils.CacheResourceFilterIndexes: {},
+ utils.CacheResourceProfiles: {},
+ utils.CacheResources: {},
+ utils.CacheReverseDestinations: {},
+ utils.CacheRPCResponses: {},
+ utils.CacheSharedGroups: {},
+ utils.CacheStatFilterIndexes: {},
+ utils.CacheStatQueueProfiles: {},
+ utils.CacheStatQueues: {},
+ utils.CacheSTIR: {},
+ utils.CacheRouteFilterIndexes: {},
+ utils.CacheRouteProfiles: {},
+ utils.CacheThresholdFilterIndexes: {},
+ utils.CacheThresholdProfiles: {},
+ utils.CacheThresholds: {},
+ utils.CacheTimings: {},
+ utils.CacheDiameterMessages: {},
+ utils.CacheClosedSessions: {},
+ utils.CacheLoadIDs: {},
+ utils.CacheRPCConnections: {},
+ utils.CacheCDRIDs: {},
+ utils.CacheRatingProfilesTmp: {},
+ utils.CacheUCH: {},
+ utils.CacheEventCharges: {},
+ utils.CacheReverseFilterIndexes: {},
+ utils.MetaAPIBan: {},
+ utils.CacheCapsEvents: {},
+ utils.CacheReplicationHosts: {},
utils.CacheAccounts: {},
utils.CacheVersions: {},
@@ -580,7 +559,6 @@ func GetDefaultEmptyCacheStats() map[string]*ltcache.CacheStats {
utils.CacheTBLTPChargers: {},
utils.CacheTBLTPDispatchers: {},
utils.CacheTBLTPDispatcherHosts: {},
- utils.CacheTBLTPRateProfiles: {},
utils.CacheTBLTPActionProfiles: {},
}
}
@@ -608,7 +586,6 @@ func GetDefaultEmptyArgCachePrefix() map[string][]string {
utils.ChargerProfilePrefix: nil,
utils.DispatcherProfilePrefix: nil,
utils.DispatcherHostPrefix: nil,
- utils.RateProfilePrefix: nil,
utils.ActionProfilePrefix: nil,
utils.TimingsPrefix: nil,
utils.AttributeFilterIndexes: nil,
@@ -618,8 +595,6 @@ func GetDefaultEmptyArgCachePrefix() map[string][]string {
utils.RouteFilterIndexes: nil,
utils.ChargerFilterIndexes: nil,
utils.DispatcherFilterIndexes: nil,
- utils.RateProfilesFilterIndexPrfx: nil,
- utils.RateFilterIndexPrfx: nil,
utils.ActionProfilesFilterIndexPrfx: nil,
utils.FilterIndexPrfx: nil,
}
diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go
index cfaddb447..146dee532 100644
--- a/engine/loader_csv_test.go
+++ b/engine/loader_csv_test.go
@@ -42,7 +42,7 @@ func init() {
ActionsCSVContent, ActionPlansCSVContent, ActionTriggersCSVContent, AccountActionsCSVContent,
ResourcesCSVContent, StatsCSVContent, ThresholdsCSVContent, FiltersCSVContent,
RoutesCSVContent, AttributesCSVContent, ChargersCSVContent, DispatcherCSVContent,
- DispatcherHostCSVContent, RateProfileCSVContent, ActionProfileCSVContent), testTPID, "", nil, nil, false)
+ DispatcherHostCSVContent), testTPID, "", nil, nil, false)
if err != nil {
log.Print("error when creating TpReader:", err)
}
@@ -106,9 +106,6 @@ func init() {
if err := csvr.LoadDispatcherHosts(); err != nil {
log.Print("error in LoadDispatcherHosts:", err)
}
- if err := csvr.LoadRateProfiles(); err != nil {
- log.Print("error in LoadRateProfiles:", err)
- }
if err := csvr.LoadActionProfiles(); err != nil {
log.Print("error in LoadActionProfiles: ", err)
}
@@ -1398,81 +1395,6 @@ func TestLoadDispatcherProfiles(t *testing.T) {
}
}
-func TestLoadRateProfiles(t *testing.T) {
- eRatePrf := &utils.TPRateProfile{
- TPid: testTPID,
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.12,
- Unit: "1m",
- Increment: "1m",
- },
- {
- IntervalStart: "1m",
- FixedFee: 1.234,
- RecurrentFee: 0.06,
- Unit: "1m",
- Increment: "1s",
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: ";10",
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- FixedFee: 0.089,
- RecurrentFee: 0.06,
- Unit: "1m",
- Increment: "1s",
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- FixedFee: 0.0564,
- RecurrentFee: 0.06,
- Unit: "1m",
- Increment: "1s",
- },
- },
- },
- },
- }
- if len(csvr.rateProfiles) != 1 {
- t.Errorf("Failed to load rateProfiles: %s", utils.ToIJSON(csvr.rateProfiles))
- }
- dppKey := utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}
- sort.Slice(csvr.rateProfiles[dppKey].Rates["RT_WEEK"].IntervalRates, func(i, j int) bool {
- return csvr.rateProfiles[dppKey].Rates["RT_WEEK"].IntervalRates[i].IntervalStart < csvr.rateProfiles[dppKey].Rates["RT_WEEK"].IntervalRates[j].IntervalStart
- })
-
- if !reflect.DeepEqual(eRatePrf, csvr.rateProfiles[dppKey]) {
- t.Errorf("Expecting: %+v,\n received: %+v",
- utils.ToJSON(eRatePrf), utils.ToJSON(csvr.rateProfiles[dppKey]))
- }
-}
-
func TestLoadActionProfiles(t *testing.T) {
expected := &utils.TPActionProfile{
TPid: testTPID,
diff --git a/engine/model_helpers.go b/engine/model_helpers.go
index 95332534a..6899d19d9 100644
--- a/engine/model_helpers.go
+++ b/engine/model_helpers.go
@@ -1819,7 +1819,7 @@ type RouteMdls []*RouteMdl
func (tps RouteMdls) CSVHeader() (result []string) {
return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString,
utils.Sorting, utils.SortingParameters, utils.RouteID, utils.RouteFilterIDs,
- utils.RouteAccountIDs, utils.RouteRatingplanIDs, utils.RouteRateProfileIDs, utils.RouteResourceIDs,
+ utils.RouteAccountIDs, utils.RouteRatingplanIDs, utils.RouteResourceIDs,
utils.RouteStatIDs, utils.RouteWeight, utils.RouteBlocker,
utils.RouteParameters, utils.Weight,
}
@@ -2867,300 +2867,6 @@ func DispatcherHostToAPI(dph *DispatcherHost) (tpDPH *utils.TPDispatcherHost) {
}
}
-// RateProfileMdls is used
-type RateProfileMdls []*RateProfileMdl
-
-// CSVHeader return the header for csv fields as a slice of string
-func (tps RateProfileMdls) CSVHeader() (result []string) {
- return []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs,
- utils.ActivationIntervalString, utils.Weight, utils.ConnectFee, utils.MinCost,
- utils.MaxCost, utils.MaxCostStrategy, utils.RateID,
- utils.RateFilterIDs, utils.RateActivationStart, utils.RateWeight, utils.RateBlocker,
- utils.RateIntervalStart, utils.RateFixedFee, utils.RateRecurrentFee, utils.RateUnit, utils.RateIncrement,
- }
-}
-
-func (tps RateProfileMdls) AsTPRateProfile() (result []*utils.TPRateProfile) {
- filterMap := make(map[string]utils.StringSet)
- mst := make(map[string]*utils.TPRateProfile)
- rateMap := make(map[string]map[string]*utils.TPRate)
- for _, tp := range tps {
- tenID := (&utils.TenantID{Tenant: tp.Tenant, ID: tp.ID}).TenantID()
- rPrf, found := mst[tenID]
- if !found {
- rPrf = &utils.TPRateProfile{
- TPid: tp.Tpid,
- Tenant: tp.Tenant,
- ID: tp.ID,
- }
- }
- if tp.RateID != utils.EmptyString {
- if _, has := rateMap[tenID]; !has {
- rateMap[tenID] = make(map[string]*utils.TPRate)
- }
- rate, found := rateMap[tenID][tp.RateID]
- if !found {
- rate = &utils.TPRate{
- ID: tp.RateID,
- IntervalRates: make([]*utils.TPIntervalRate, 0),
- Blocker: tp.RateBlocker,
- }
- }
- if tp.RateFilterIDs != utils.EmptyString {
- rateFilterSplit := strings.Split(tp.RateFilterIDs, utils.InfieldSep)
- rate.FilterIDs = append(rate.FilterIDs, rateFilterSplit...)
- }
- if tp.RateActivationTimes != utils.EmptyString {
- rate.ActivationTimes = tp.RateActivationTimes
- }
- if tp.RateWeights != utils.EmptyString {
- rate.Weights = tp.RateWeights
- }
- // create new interval rate and append to the slice
- intervalRate := new(utils.TPIntervalRate)
- if tp.RateIntervalStart != utils.EmptyString {
- intervalRate.IntervalStart = tp.RateIntervalStart
- }
- if tp.RateFixedFee != 0 {
- intervalRate.FixedFee = tp.RateFixedFee
- }
- if tp.RateRecurrentFee != 0 {
- intervalRate.RecurrentFee = tp.RateRecurrentFee
- }
- if tp.RateIncrement != utils.EmptyString {
- intervalRate.Increment = tp.RateIncrement
- }
- if tp.RateUnit != utils.EmptyString {
- intervalRate.Unit = tp.RateUnit
- }
- rate.IntervalRates = append(rate.IntervalRates, intervalRate)
- rateMap[tenID][tp.RateID] = rate
- }
-
- if tp.Weights != utils.EmptyString {
- rPrf.Weights = tp.Weights
- }
- if tp.MinCost != 0 {
- rPrf.MinCost = tp.MinCost
- }
- if tp.MaxCost != 0 {
- rPrf.MaxCost = tp.MaxCost
- }
- if tp.MaxCostStrategy != utils.EmptyString {
- rPrf.MaxCostStrategy = tp.MaxCostStrategy
- }
- if tp.ActivationInterval != utils.EmptyString {
- rPrf.ActivationInterval = new(utils.TPActivationInterval)
- aiSplt := strings.Split(tp.ActivationInterval, utils.InfieldSep)
- if len(aiSplt) == 2 {
- rPrf.ActivationInterval.ActivationTime = aiSplt[0]
- rPrf.ActivationInterval.ExpiryTime = aiSplt[1]
- } else if len(aiSplt) == 1 {
- rPrf.ActivationInterval.ActivationTime = aiSplt[0]
- }
- }
- if tp.FilterIDs != utils.EmptyString {
- if _, has := filterMap[tenID]; !has {
- filterMap[tenID] = make(utils.StringSet)
- }
- filterMap[tenID].AddSlice(strings.Split(tp.FilterIDs, utils.InfieldSep))
- }
- mst[tenID] = rPrf
- }
- result = make([]*utils.TPRateProfile, len(mst))
- i := 0
- for tntID, th := range mst {
- result[i] = th
- result[i].Rates = rateMap[tntID]
- result[i].FilterIDs = filterMap[tntID].AsSlice()
- i++
- }
- return
-}
-
-func APItoModelTPRateProfile(tPrf *utils.TPRateProfile) (mdls RateProfileMdls) {
- if len(tPrf.Rates) == 0 {
- return
- }
- i := 0
- for _, rate := range tPrf.Rates {
- for j, intervalRate := range rate.IntervalRates {
- mdl := &RateProfileMdl{
- Tenant: tPrf.Tenant,
- Tpid: tPrf.TPid,
- ID: tPrf.ID,
- }
- if i == 0 {
- for i, val := range tPrf.FilterIDs {
- if i != 0 {
- mdl.FilterIDs += utils.InfieldSep
- }
- mdl.FilterIDs += val
- }
-
- if tPrf.ActivationInterval != nil {
- if tPrf.ActivationInterval.ActivationTime != utils.EmptyString {
- mdl.ActivationInterval = tPrf.ActivationInterval.ActivationTime
- }
- if tPrf.ActivationInterval.ExpiryTime != utils.EmptyString {
- mdl.ActivationInterval += utils.InfieldSep + tPrf.ActivationInterval.ExpiryTime
- }
- }
- mdl.Weights = tPrf.Weights
- mdl.MinCost = tPrf.MinCost
- mdl.MaxCost = tPrf.MaxCost
- mdl.MaxCostStrategy = tPrf.MaxCostStrategy
- }
- mdl.RateID = rate.ID
- if j == 0 {
- for i, val := range rate.FilterIDs {
- if i != 0 {
- mdl.RateFilterIDs += utils.InfieldSep
- }
- mdl.RateFilterIDs += val
- }
- mdl.RateWeights = rate.Weights
- mdl.RateActivationTimes = rate.ActivationTimes
- mdl.RateBlocker = rate.Blocker
-
- }
- mdl.RateRecurrentFee = intervalRate.RecurrentFee
- mdl.RateFixedFee = intervalRate.FixedFee
- mdl.RateUnit = intervalRate.Unit
- mdl.RateIncrement = intervalRate.Increment
- mdl.RateIntervalStart = intervalRate.IntervalStart
- mdls = append(mdls, mdl)
- i++
- }
-
- }
- return
-}
-
-func APItoRateProfile(tpRp *utils.TPRateProfile, timezone string) (rp *utils.RateProfile, err error) {
- rp = &utils.RateProfile{
- Tenant: tpRp.Tenant,
- ID: tpRp.ID,
- FilterIDs: make([]string, len(tpRp.FilterIDs)),
- MaxCostStrategy: tpRp.MaxCostStrategy,
- Rates: make(map[string]*utils.Rate),
- MinCost: utils.NewDecimalFromFloat64(tpRp.MinCost),
- MaxCost: utils.NewDecimalFromFloat64(tpRp.MaxCost),
- }
- if tpRp.Weights != utils.EmptyString {
- weight, err := utils.NewDynamicWeightsFromString(tpRp.Weights, ";", "&")
- if err != nil {
- return nil, err
- }
- rp.Weights = weight
- }
- for i, stp := range tpRp.FilterIDs {
- rp.FilterIDs[i] = stp
- }
- if tpRp.ActivationInterval != nil {
- if rp.ActivationInterval, err = tpRp.ActivationInterval.AsActivationInterval(timezone); err != nil {
- return nil, err
- }
- }
- for key, rate := range tpRp.Rates {
- rp.Rates[key] = &utils.Rate{
- ID: rate.ID,
- Blocker: rate.Blocker,
- FilterIDs: rate.FilterIDs,
- ActivationTimes: rate.ActivationTimes,
- IntervalRates: make([]*utils.IntervalRate, len(rate.IntervalRates)),
- }
- if rate.Weights != utils.EmptyString {
- weight, err := utils.NewDynamicWeightsFromString(rate.Weights, ";", "&")
- if err != nil {
- return nil, err
- }
- rp.Rates[key].Weights = weight
- }
- for i, iRate := range rate.IntervalRates {
- rp.Rates[key].IntervalRates[i] = new(utils.IntervalRate)
- if rp.Rates[key].IntervalRates[i].IntervalStart, err = utils.NewDecimalFromUsage(iRate.IntervalStart); err != nil {
- return nil, err
- }
- rp.Rates[key].IntervalRates[i].FixedFee = utils.NewDecimalFromFloat64(iRate.FixedFee)
- rp.Rates[key].IntervalRates[i].RecurrentFee = utils.NewDecimalFromFloat64(iRate.RecurrentFee)
- if rp.Rates[key].IntervalRates[i].Unit, err = utils.NewDecimalFromUsage(iRate.Unit); err != nil {
- return nil, err
- }
- if rp.Rates[key].IntervalRates[i].Increment, err = utils.NewDecimalFromUsage(iRate.Increment); err != nil {
- return nil, err
- }
- }
- }
- return rp, nil
-}
-
-func RateProfileToAPI(rp *utils.RateProfile) (tpRp *utils.TPRateProfile) {
- tpRp = &utils.TPRateProfile{
- Tenant: rp.Tenant,
- ID: rp.ID,
- FilterIDs: make([]string, len(rp.FilterIDs)),
- ActivationInterval: new(utils.TPActivationInterval),
- Weights: rp.Weights.String(";", "&"),
- MaxCostStrategy: rp.MaxCostStrategy,
- Rates: make(map[string]*utils.TPRate),
- }
- if rp.MinCost != nil {
- //there should not be an invalid value of converting from Decimal into float64
- minCostF, _ := rp.MinCost.Float64()
- tpRp.MinCost = minCostF
- }
- if rp.MaxCost != nil {
- //there should not be an invalid value of converting from Decimal into float64
- maxCostF, _ := rp.MaxCost.Float64()
- tpRp.MaxCost = maxCostF
- }
-
- for key, rate := range rp.Rates {
- tpRp.Rates[key] = &utils.TPRate{
- ID: rate.ID,
- Weights: rate.Weights.String(";", "&"),
- Blocker: rate.Blocker,
- FilterIDs: rate.FilterIDs,
- ActivationTimes: rate.ActivationTimes,
- IntervalRates: make([]*utils.TPIntervalRate, len(rate.IntervalRates)),
- }
- for i, iRate := range rate.IntervalRates {
- tpRp.Rates[key].IntervalRates[i] = &utils.TPIntervalRate{
- IntervalStart: iRate.IntervalStart.String(),
- }
- if iRate.FixedFee != nil {
- //there should not be an invalid value of converting from Decimal into float64
- fixedFeeF, _ := iRate.FixedFee.Float64()
- tpRp.Rates[key].IntervalRates[i].FixedFee = fixedFeeF
- }
- if iRate.Unit != nil {
- tpRp.Rates[key].IntervalRates[i].Unit = iRate.Unit.String()
- }
- if iRate.Increment != nil {
- tpRp.Rates[key].IntervalRates[i].Increment = iRate.Increment.String()
- }
- if iRate.RecurrentFee != nil {
- //there should not be an invalid value of converting from Decimal into float64
- recFeeF, _ := iRate.RecurrentFee.Float64()
- tpRp.Rates[key].IntervalRates[i].RecurrentFee = recFeeF
- }
- }
- }
- for i, fli := range rp.FilterIDs {
- tpRp.FilterIDs[i] = fli
- }
- if rp.ActivationInterval != nil {
- if !rp.ActivationInterval.ActivationTime.IsZero() {
- tpRp.ActivationInterval.ActivationTime = rp.ActivationInterval.ActivationTime.Format(time.RFC3339)
- }
- if !rp.ActivationInterval.ExpiryTime.IsZero() {
- tpRp.ActivationInterval.ExpiryTime = rp.ActivationInterval.ExpiryTime.Format(time.RFC3339)
- }
- }
- return
-}
-
type ActionProfileMdls []*ActionProfileMdl
// CSVHeader return the header for csv fields as a slice of string
diff --git a/engine/model_helpers_test.go b/engine/model_helpers_test.go
index 335de7efe..99d81c2df 100644
--- a/engine/model_helpers_test.go
+++ b/engine/model_helpers_test.go
@@ -2829,7 +2829,7 @@ func TestCsvHeader(t *testing.T) {
eOut := []string{
"#" + utils.Tenant, utils.ID, utils.FilterIDs, utils.ActivationIntervalString,
utils.Sorting, utils.SortingParameters, utils.RouteID, utils.RouteFilterIDs,
- utils.RouteAccountIDs, utils.RouteRatingplanIDs, utils.RouteRateProfileIDs, utils.RouteResourceIDs,
+ utils.RouteAccountIDs, utils.RouteRatingplanIDs, utils.RouteResourceIDs,
utils.RouteStatIDs, utils.RouteWeight, utils.RouteBlocker,
utils.RouteParameters, utils.Weight,
}
@@ -4289,597 +4289,6 @@ func TestTPRoutesAsTPRouteProfile2(t *testing.T) {
}
}
-func TestRateProfileToAPI(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- rPrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- FixedFee: utils.NewDecimal(234, 5),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- },
- }
- eTPRatePrf := &utils.TPRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "",
- ExpiryTime: "",
- },
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: 0.12,
- Unit: "60000000000",
- Increment: "1000000000",
- },
- {
- IntervalStart: "60000000000",
- FixedFee: 0.00234,
- RecurrentFee: 0.06,
- Unit: "60000000000",
- Increment: "1000000000",
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: ";10",
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: 0.06,
- Unit: "60000000000",
- Increment: "1000000000",
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: 0.06,
- Unit: "60000000000",
- Increment: "1000000000",
- },
- },
- },
- },
- }
- if rcv := RateProfileToAPI(rPrf); !reflect.DeepEqual(rcv, eTPRatePrf) {
- t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eTPRatePrf), utils.ToJSON(rcv))
- }
-}
-
-func TestAPIToRateProfile(t *testing.T) {
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- eRprf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(23451, 4),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- },
- }
- tpRprf := &utils.TPRateProfile{
- TPid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- FixedFee: 2.3451,
- RecurrentFee: 0.12,
- Unit: "1m0s",
- Increment: "1m0s",
- },
- {
- IntervalStart: "1m0s",
- RecurrentFee: 0.06,
- Unit: "1m0s",
- Increment: "1s",
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: ";10",
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.06,
- Unit: "1m0s",
- Increment: "1s",
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.06,
- Unit: "1m0s",
- Increment: "1s",
- },
- },
- },
- },
- }
- if rcv, err := APItoRateProfile(tpRprf, utils.EmptyString); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rcv, eRprf) {
- t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eRprf), utils.ToJSON(rcv))
- }
-}
-
-func TestAPItoRateProfileError(t *testing.T) {
- tpRprf := &utils.TPRateProfile{
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: "0",
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: "0",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.06,
- Unit: "1ss",
- Increment: "1ss",
- },
- },
- },
- },
- }
- expectedErr := "invalid DynamicWeight format for string <0>"
- if _, err := APItoRateProfile(tpRprf, utils.EmptyString); err == nil || err.Error() != expectedErr {
- t.Error(err)
- }
-
- tpRprf.Weights = ";0"
- if _, err := APItoRateProfile(tpRprf, utils.EmptyString); err == nil || err.Error() != expectedErr {
- t.Error(err)
- }
-
- tpRprf.Rates["RT_WEEK"].Weights = ";0"
- expectedErr = "time: unknown unit \"ss\" in duration \"1ss\""
- if _, err := APItoRateProfile(tpRprf, utils.EmptyString); err == nil || err.Error() != expectedErr {
- t.Error(err)
- }
-
- tpRprf.Rates["RT_WEEK"].IntervalRates[0].Unit = "1s"
- if _, err := APItoRateProfile(tpRprf, utils.EmptyString); err == nil || err.Error() != expectedErr {
- t.Error(err)
- }
-}
-
-func TestAPIToRateProfileError(t *testing.T) {
- tpRprf := &utils.TPRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- ActivationInterval: &utils.TPActivationInterval{
- ExpiryTime: "NOT_A_TIME",
- },
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "NOT_A_TIME",
- FixedFee: 2.3451,
- RecurrentFee: 0.12,
- },
- },
- },
- },
- }
- expectedErr := "Unsupported time format"
- if _, err := APItoRateProfile(tpRprf, "UTC"); err == nil || err.Error() != expectedErr {
- t.Errorf("Expected %+v, received %+v", expectedErr, err)
- }
-
- expectedErr = "strconv.ParseInt: parsing \"NOT_A_TIME\": invalid syntax"
- tpRprf.ActivationInterval = nil
- if _, err := APItoRateProfile(tpRprf, "UTC"); err == nil || err.Error() != expectedErr {
- t.Errorf("Expected %+v, received %+q", expectedErr, err)
- }
-}
-
-func TestAPItoModelTPRateProfile(t *testing.T) {
- tpRprf := &utils.TPRateProfile{
- TPid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.12,
- Unit: "1m0s",
- Increment: "1m0s",
- },
- {
- IntervalStart: "1m",
- RecurrentFee: 0.06,
- Unit: "1m0s",
- Increment: "1s",
- },
- },
- },
- },
- }
-
- expModels := RateProfileMdls{
- &RateProfileMdl{
- PK: 0,
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "*string:~*req.Subject:1001",
- ActivationInterval: "",
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- RateID: "RT_WEEK",
- RateFilterIDs: "",
- RateActivationTimes: "* * * * 1-5",
- RateWeights: ";0",
- RateBlocker: false,
- RateIntervalStart: "1m",
- RateRecurrentFee: 0.06,
- RateUnit: "1m0s",
- RateIncrement: "1s",
- CreatedAt: time.Time{},
- },
- &RateProfileMdl{
- PK: 0,
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "",
- ActivationInterval: "",
- Weights: ";0",
- MinCost: 0,
- MaxCost: 0,
- MaxCostStrategy: "",
- RateID: "RT_WEEK",
- RateFilterIDs: "",
- RateActivationTimes: "",
- RateWeights: ";0",
- RateBlocker: false,
- RateIntervalStart: "0s",
- RateRecurrentFee: 0.12,
- RateUnit: "1m0s",
- RateIncrement: "1m0s",
- CreatedAt: time.Time{},
- },
- }
- expModelsRev := RateProfileMdls{
- &RateProfileMdl{
- PK: 0,
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "*string:~*req.Subject:1001",
- ActivationInterval: "",
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- RateID: "RT_WEEK",
- RateFilterIDs: "",
- RateActivationTimes: "* * * * 1-5",
- RateWeights: ";0",
- RateBlocker: false,
- RateIntervalStart: "0s",
- RateRecurrentFee: 0.12,
- RateUnit: "1m0s",
- RateIncrement: "1m0s",
- CreatedAt: time.Time{},
- },
- &RateProfileMdl{
- PK: 0,
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "",
- ActivationInterval: "",
- Weights: "",
- MinCost: 0,
- MaxCost: 0,
- MaxCostStrategy: "",
- RateID: "RT_WEEK",
- RateFilterIDs: "",
- RateActivationTimes: "",
- RateWeights: "",
- RateBlocker: false,
- RateIntervalStart: "1m",
- RateRecurrentFee: 0.06,
- RateUnit: "1m0s",
- RateIncrement: "1s",
- CreatedAt: time.Time{},
- },
- }
- rcv := APItoModelTPRateProfile(tpRprf)
- if !reflect.DeepEqual(rcv, expModels) && !reflect.DeepEqual(rcv, expModelsRev) {
- t.Errorf("Expecting: %+v or \n%+v,\nReceived: %+v", utils.ToJSON(expModels), utils.ToJSON(expModelsRev), utils.ToJSON(rcv))
- }
-}
-
-func TestAsTPRateProfile(t *testing.T) {
- rtMdl := RateProfileMdls{
- &RateProfileMdl{
- PK: 0,
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "*string:~*req.Subject:1001",
- ActivationInterval: "",
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- RateID: "RT_WEEK",
- RateFilterIDs: "",
- RateActivationTimes: "* * * * 1-5",
- RateWeights: ";0",
- RateBlocker: false,
- RateIntervalStart: "1m",
- RateRecurrentFee: 0.06,
- RateUnit: "1m",
- RateIncrement: "1s",
- CreatedAt: time.Time{},
- },
- &RateProfileMdl{
- PK: 0,
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "",
- ActivationInterval: "",
- Weights: ";0",
- MinCost: 0,
- MaxCost: 0,
- MaxCostStrategy: "",
- RateID: "RT_WEEK",
- RateFilterIDs: "",
- RateActivationTimes: "",
- RateWeights: ";0",
- RateBlocker: false,
- RateIntervalStart: "0s",
- RateRecurrentFee: 0.12,
- RateUnit: "1m",
- RateIncrement: "1m",
- CreatedAt: time.Time{},
- },
- }
-
- eRprf := &utils.TPRateProfile{
- TPid: utils.EmptyString,
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "1m",
- RecurrentFee: 0.06,
- Unit: "1m",
- Increment: "1s",
- },
- {
- IntervalStart: "0s",
- RecurrentFee: 0.12,
- Unit: "1m",
- Increment: "1m",
- },
- },
- },
- },
- }
- rcv := rtMdl.AsTPRateProfile()
- if len(rcv) != 1 {
- t.Errorf("Expecting: %+v,\nReceived: %+v", 1, len(rcv))
- } else if !reflect.DeepEqual(rcv[0], eRprf) {
- t.Errorf("Expecting: %+v,\nReceived: %+v", utils.ToJSON(eRprf), utils.ToJSON(rcv[0]))
- }
-}
-
func TestModelHelperCsvLoadError(t *testing.T) {
type testStruct struct {
Id int64
@@ -5193,111 +4602,6 @@ func TestRouteProfileToAPICase1(t *testing.T) {
}
-func TestRateProfileToAPIWithActInterval(t *testing.T) {
- testProfile := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2020, time.April,
- 11, 21, 34, 01, 0, time.UTC),
- ExpiryTime: time.Date(2020, time.April,
- 12, 21, 34, 01, 0, time.UTC),
- },
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{},
- }
-
- expStruct := &utils.TPRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2020-04-11T21:34:01Z",
- ExpiryTime: "2020-04-12T21:34:01Z",
- },
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{},
- }
- if result := RateProfileToAPI(testProfile); !reflect.DeepEqual(expStruct, result) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
- }
-}
-
-func TestAPItoModelTPRateProfileNil(t *testing.T) {
- testStruct := &utils.TPRateProfile{
- Rates: map[string]*utils.TPRate{},
- }
- result := APItoModelTPRateProfile(testStruct)
- if !reflect.DeepEqual(utils.ToJSON(result), "null") {
- t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(result))
- }
-}
-
-func TestAPItoModelTPRateProfileCase2(t *testing.T) {
- testStruct := &utils.TPRateProfile{
- FilterIDs: []string{"test_string1", "test_string2"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "2014-08-29T15:00:00Z",
- },
- Rates: map[string]*utils.TPRate{"RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- FilterIDs: []string{"test_string1", "test_string2"},
- Weights: ";30",
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.06,
- Unit: "1m0s",
- Increment: "1s",
- },
- },
- },
- },
- }
- expStruct := RateProfileMdls{{
- FilterIDs: "test_string1;test_string2",
- ActivationInterval: "2014-07-29T15:00:00Z;2014-08-29T15:00:00Z",
- RateID: "RT_CHRISTMAS",
- RateFilterIDs: "test_string1;test_string2",
- RateWeights: ";30",
- RateActivationTimes: "* * 24 12 *",
- RateIntervalStart: "0s",
- RateRecurrentFee: 0.06,
- RateUnit: "1m0s",
- RateIncrement: "1s",
- }}
- result := APItoModelTPRateProfile(testStruct)
- if !reflect.DeepEqual(result, expStruct) {
- t.Errorf("\nExpecting <%+v>>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
- }
-}
-
-func TestRateProfileMdlsCSVHeader(t *testing.T) {
- testRPMdls := RateProfileMdls{}
- result := testRPMdls.CSVHeader()
- expected := []string{"#" + utils.Tenant, utils.ID, utils.FilterIDs,
- utils.ActivationIntervalString, utils.Weight, utils.ConnectFee, utils.MinCost,
- utils.MaxCost, utils.MaxCostStrategy, utils.RateID,
- utils.RateFilterIDs, utils.RateActivationStart, utils.RateWeight, utils.RateBlocker,
- utils.RateIntervalStart, utils.RateFixedFee, utils.RateRecurrentFee, utils.RateUnit, utils.RateIncrement}
- if !reflect.DeepEqual(result, expected) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, result)
- }
-}
-
func TestDispatcherProfileToAPICase2(t *testing.T) {
structTest := &DispatcherProfile{
Subsystems: []string{},
@@ -5507,113 +4811,6 @@ func TestChargerProfileToAPILastCase(t *testing.T) {
}
}
-func TestRateProfileMdlsAsTPRateProfileCase2(t *testing.T) {
- testRPMdls := RateProfileMdls{&RateProfileMdl{
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "*string:~*req.Subject:1001",
- ActivationInterval: "2014-07-29T15:00:00Z;2014-08-29T15:00:00Z",
- Weights: ";1.2",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- RateID: "0",
- RateFilterIDs: "test_filter_id",
- RateWeights: ";2",
- },
- }
- expStruct := []*utils.TPRateProfile{
- {TPid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "2014-08-29T15:00:00Z",
- },
- Weights: ";1.2",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "0": {
- ID: "0",
- FilterIDs: []string{"test_filter_id"},
- Weights: ";2",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "",
- FixedFee: 0,
- RecurrentFee: 0,
- Unit: "",
- Increment: "",
- },
- },
- },
- },
- },
- }
- result := testRPMdls.AsTPRateProfile()
- if !reflect.DeepEqual(result, expStruct) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
- }
-
-}
-
-func TestRateProfileMdlsAsTPRateProfileCase3(t *testing.T) {
- testRPMdls := RateProfileMdls{&RateProfileMdl{
- Tpid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: "*string:~*req.Subject:1001",
- ActivationInterval: "2014-07-29T15:00:00Z",
- Weights: ";1.2",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- RateID: "0",
- RateFilterIDs: "test_filter_id",
- RateWeights: ";2",
- },
- }
- expStruct := []*utils.TPRateProfile{
- {TPid: "",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- },
- Weights: ";1.2",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "0": {
- ID: "0",
- FilterIDs: []string{"test_filter_id"},
- Weights: ";2",
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "",
- FixedFee: 0,
- RecurrentFee: 0,
- Unit: "",
- Increment: "",
- },
- },
- },
- },
- },
- }
- result := testRPMdls.AsTPRateProfile()
- if !reflect.DeepEqual(result, expStruct) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ToJSON(expStruct), utils.ToJSON(result))
- }
-
-}
-
func TestAPItoModelTPDispatcherProfileCase2(t *testing.T) {
structTest := &utils.TPDispatcherProfile{
ActivationInterval: &utils.TPActivationInterval{
diff --git a/engine/models.go b/engine/models.go
index 6bf406dcf..508fc3e6e 100644
--- a/engine/models.go
+++ b/engine/models.go
@@ -510,35 +510,6 @@ func (DispatcherHostMdl) TableName() string {
return utils.TBLTPDispatcherHosts
}
-type RateProfileMdl struct {
- PK uint `gorm:"primary_key"`
- Tpid string
- Tenant string `index:"0" re:""`
- ID string `index:"1" re:""`
- FilterIDs string `index:"2" re:""`
- ActivationInterval string `index:"3" re:""`
- Weights string `index:"4" re:""`
- MinCost float64 `index:"5" re:"\d+\.?\d*""`
- MaxCost float64 `index:"6" re:"\d+\.?\d*"`
- MaxCostStrategy string `index:"7" re:""`
- RateID string `index:"8" re:""`
- RateFilterIDs string `index:"9" re:""`
- RateActivationTimes string `index:"10" re:""`
- RateWeights string `index:"11" re:""`
- RateBlocker bool `index:"12" re:""`
- RateIntervalStart string `index:"13" re:""`
- RateFixedFee float64 `index:"14" re:"\d+\.?\d*"`
- RateRecurrentFee float64 `index:"15" re:"\d+\.?\d*"`
- RateUnit string `index:"16" re:""`
- RateIncrement string `index:"17" re:""`
-
- CreatedAt time.Time
-}
-
-func (RateProfileMdl) TableName() string {
- return utils.TBLTPRateProfiles
-}
-
type ActionProfileMdl struct {
PK uint `gorm:"primary_key"`
Tpid string
diff --git a/engine/storage_csv.go b/engine/storage_csv.go
index b4ab4d3c7..bcd5bafbf 100644
--- a/engine/storage_csv.go
+++ b/engine/storage_csv.go
@@ -64,7 +64,6 @@ type CSVStorage struct {
chargerProfilesFn []string
dispatcherProfilesFn []string
dispatcherHostsFn []string
- rateProfilesFn []string
actionProfilesFn []string
}
@@ -74,8 +73,7 @@ func NewCSVStorage(sep rune,
destinationratetimingsFn, ratingprofilesFn, sharedgroupsFn,
actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn,
resProfilesFn, statsFn, thresholdsFn, filterFn, routeProfilesFn,
- attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn,
- rateProfilesFn, actionProfilesFn []string) *CSVStorage {
+ attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn []string) *CSVStorage {
return &CSVStorage{
sep: sep,
generator: NewCsvFile,
@@ -99,7 +97,6 @@ func NewCSVStorage(sep rune,
chargerProfilesFn: chargerProfilesFn,
dispatcherProfilesFn: dispatcherProfilesFn,
dispatcherHostsFn: dispatcherHostsFn,
- rateProfilesFn: rateProfilesFn,
actionProfilesFn: actionProfilesFn,
}
}
@@ -130,7 +127,6 @@ func NewFileCSVStorage(sep rune, dataPath string) *CSVStorage {
chargersPaths := appendName(allFoldersPath, utils.ChargersCsv)
dispatcherprofilesPaths := appendName(allFoldersPath, utils.DispatcherProfilesCsv)
dispatcherhostsPaths := appendName(allFoldersPath, utils.DispatcherHostsCsv)
- rateProfilesFn := appendName(allFoldersPath, utils.RateProfilesCsv)
actionProfilesFn := appendName(allFoldersPath, utils.ActionProfilesCsv)
return NewCSVStorage(sep,
destinationsPaths,
@@ -153,7 +149,6 @@ func NewFileCSVStorage(sep rune, dataPath string) *CSVStorage {
chargersPaths,
dispatcherprofilesPaths,
dispatcherhostsPaths,
- rateProfilesFn,
actionProfilesFn,
)
}
@@ -164,16 +159,14 @@ func NewStringCSVStorage(sep rune,
destinationratetimingsFn, ratingprofilesFn, sharedgroupsFn,
actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn,
resProfilesFn, statsFn, thresholdsFn, filterFn, routeProfilesFn,
- attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn,
- rateProfilesFn, actionProfilesFn string) *CSVStorage {
+ attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn string) *CSVStorage {
c := NewCSVStorage(sep, []string{destinationsFn}, []string{timingsFn},
[]string{ratesFn}, []string{destinationratesFn}, []string{destinationratetimingsFn},
[]string{ratingprofilesFn}, []string{sharedgroupsFn}, []string{actionsFn},
[]string{actiontimingsFn}, []string{actiontriggersFn}, []string{accountactionsFn},
[]string{resProfilesFn}, []string{statsFn}, []string{thresholdsFn}, []string{filterFn},
[]string{routeProfilesFn}, []string{attributeProfilesFn}, []string{chargerProfilesFn},
- []string{dispatcherProfilesFn}, []string{dispatcherHostsFn}, []string{rateProfilesFn},
- []string{actionProfilesFn})
+ []string{dispatcherProfilesFn}, []string{dispatcherHostsFn})
c.generator = NewCsvString
return c
}
@@ -215,8 +208,6 @@ func NewGoogleCSVStorage(sep rune, spreadsheetID string) (*CSVStorage, error) {
getIfExist(utils.Chargers),
getIfExist(utils.DispatcherProfiles),
getIfExist(utils.DispatcherHosts),
- getIfExist(utils.RateProfiles),
- getIfExist(utils.ActionProfiles))
c.generator = func() csvReaderCloser {
return &csvGoogle{
spreadsheetID: spreadsheetID,
@@ -248,7 +239,6 @@ func NewURLCSVStorage(sep rune, dataPath string) *CSVStorage {
var chargersPaths []string
var dispatcherprofilesPaths []string
var dispatcherhostsPaths []string
- var rateProfilesPaths []string
var actionProfilesPaths []string
for _, baseURL := range strings.Split(dataPath, utils.InfieldSep) {
@@ -273,7 +263,6 @@ func NewURLCSVStorage(sep rune, dataPath string) *CSVStorage {
chargersPaths = append(chargersPaths, joinURL(baseURL, utils.ChargersCsv))
dispatcherprofilesPaths = append(dispatcherprofilesPaths, joinURL(baseURL, utils.DispatcherProfilesCsv))
dispatcherhostsPaths = append(dispatcherhostsPaths, joinURL(baseURL, utils.DispatcherHostsCsv))
- rateProfilesPaths = append(rateProfilesPaths, joinURL(baseURL, utils.RateProfilesCsv))
actionProfilesPaths = append(actionProfilesPaths, joinURL(baseURL, utils.ActionProfilesCsv))
continue
}
@@ -318,8 +307,6 @@ func NewURLCSVStorage(sep rune, dataPath string) *CSVStorage {
dispatcherprofilesPaths = append(dispatcherprofilesPaths, baseURL)
case strings.HasSuffix(baseURL, utils.DispatcherHostsCsv):
dispatcherhostsPaths = append(dispatcherhostsPaths, baseURL)
- case strings.HasSuffix(baseURL, utils.RateProfilesCsv):
- rateProfilesPaths = append(rateProfilesPaths, baseURL)
case strings.HasSuffix(baseURL, utils.ActionProfilesCsv):
actionProfilesPaths = append(actionProfilesPaths, baseURL)
@@ -347,7 +334,6 @@ func NewURLCSVStorage(sep rune, dataPath string) *CSVStorage {
chargersPaths,
dispatcherprofilesPaths,
dispatcherhostsPaths,
- rateProfilesPaths,
actionProfilesPaths,
)
c.generator = func() csvReaderCloser {
@@ -663,18 +649,6 @@ func (csvs *CSVStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.
return tpDDHs.AsTPDispatcherHosts(), nil
}
-func (csvs *CSVStorage) GetTPRateProfiles(tpid, tenant, id string) ([]*utils.TPRateProfile, error) {
- var tpDPPs RateProfileMdls
- if err := csvs.proccesData(RateProfileMdl{}, csvs.rateProfilesFn, func(tp interface{}) {
- dpp := tp.(RateProfileMdl)
- dpp.Tpid = tpid
- tpDPPs = append(tpDPPs, &dpp)
- }); err != nil {
- return nil, err
- }
- return tpDPPs.AsTPRateProfile(), nil
-}
-
func (csvs *CSVStorage) GetTPActionProfiles(tpid, tenant, id string) ([]*utils.TPActionProfile, error) {
var tpDPPs ActionProfileMdls
if err := csvs.proccesData(ActionProfileMdl{}, csvs.actionProfilesFn, func(tp interface{}) {
diff --git a/engine/storage_interface.go b/engine/storage_interface.go
index cfcc17942..d98349b92 100644
--- a/engine/storage_interface.go
+++ b/engine/storage_interface.go
@@ -129,9 +129,6 @@ type DataDB interface {
GetDispatcherHostDrv(string, string) (*DispatcherHost, error)
SetDispatcherHostDrv(*DispatcherHost) error
RemoveDispatcherHostDrv(string, string) error
- GetRateProfileDrv(string, string) (*utils.RateProfile, error)
- SetRateProfileDrv(*utils.RateProfile) error
- RemoveRateProfileDrv(string, string) error
GetActionProfileDrv(string, string) (*ActionProfile, error)
SetActionProfileDrv(*ActionProfile) error
RemoveActionProfileDrv(string, string) error
@@ -184,7 +181,6 @@ type LoadReader interface {
GetTPChargers(string, string, string) ([]*utils.TPChargerProfile, error)
GetTPDispatcherProfiles(string, string, string) ([]*utils.TPDispatcherProfile, error)
GetTPDispatcherHosts(string, string, string) ([]*utils.TPDispatcherHost, error)
- GetTPRateProfiles(string, string, string) ([]*utils.TPRateProfile, error)
GetTPActionProfiles(string, string, string) ([]*utils.TPActionProfile, error)
}
@@ -210,7 +206,6 @@ type LoadWriter interface {
SetTPChargers([]*utils.TPChargerProfile) error
SetTPDispatcherProfiles([]*utils.TPDispatcherProfile) error
SetTPDispatcherHosts([]*utils.TPDispatcherHost) error
- SetTPRateProfiles([]*utils.TPRateProfile) error
SetTPActionProfiles([]*utils.TPActionProfile) error
}
diff --git a/engine/storage_internal_datadb.go b/engine/storage_internal_datadb.go
index 1348b7634..6e82d9fdd 100644
--- a/engine/storage_internal_datadb.go
+++ b/engine/storage_internal_datadb.go
@@ -819,29 +819,6 @@ func (iDB *InternalDB) RemoveDispatcherHostDrv(tenant, id string) (err error) {
return
}
-func (iDB *InternalDB) GetRateProfileDrv(tenant, id string) (rpp *utils.RateProfile, err error) {
- x, ok := Cache.Get(utils.CacheRateProfiles, utils.ConcatenatedKey(tenant, id))
- if !ok || x == nil {
- return nil, utils.ErrNotFound
- }
- return x.(*utils.RateProfile), nil
-}
-
-func (iDB *InternalDB) SetRateProfileDrv(rpp *utils.RateProfile) (err error) {
- if err = rpp.Compile(); err != nil {
- return
- }
- Cache.SetWithoutReplicate(utils.CacheRateProfiles, rpp.TenantID(), rpp, nil,
- cacheCommit(utils.NonTransactional), utils.NonTransactional)
- return
-}
-
-func (iDB *InternalDB) RemoveRateProfileDrv(tenant, id string) (err error) {
- Cache.RemoveWithoutReplicate(utils.CacheRateProfiles, utils.ConcatenatedKey(tenant, id),
- cacheCommit(utils.NonTransactional), utils.NonTransactional)
- return
-}
-
func (iDB *InternalDB) GetActionProfileDrv(tenant, id string) (ap *ActionProfile, err error) {
x, ok := Cache.Get(utils.CacheActionProfiles, utils.ConcatenatedKey(tenant, id))
if !ok || x == nil {
diff --git a/engine/storage_internal_stordb.go b/engine/storage_internal_stordb.go
index 8fe5a5de8..1597f25be 100644
--- a/engine/storage_internal_stordb.go
+++ b/engine/storage_internal_stordb.go
@@ -563,28 +563,6 @@ func (iDB *InternalDB) GetTPDispatcherHosts(tpid, tenant, id string) (dpps []*ut
return
}
-func (iDB *InternalDB) GetTPRateProfiles(tpid, tenant, id string) (tpPrfs []*utils.TPRateProfile, err error) {
- key := tpid
- if tenant != utils.EmptyString {
- key += utils.ConcatenatedKeySep + tenant
- }
- if id != utils.EmptyString {
- key += utils.ConcatenatedKeySep + id
- }
- ids := Cache.GetItemIDs(utils.CacheTBLTPRateProfiles, key)
- for _, id := range ids {
- x, ok := Cache.Get(utils.CacheTBLTPRateProfiles, id)
- if !ok || x == nil {
- return nil, utils.ErrNotFound
- }
- tpPrfs = append(tpPrfs, x.(*utils.TPRateProfile))
- }
- if len(tpPrfs) == 0 {
- return nil, utils.ErrNotFound
- }
- return
-}
-
func (iDB *InternalDB) GetTPActionProfiles(tpid, tenant, id string) (tpPrfs []*utils.TPActionProfile, err error) {
key := tpid
if tenant != utils.EmptyString {
@@ -858,17 +836,6 @@ func (iDB *InternalDB) SetTPDispatcherHosts(dpps []*utils.TPDispatcherHost) (err
return
}
-func (iDB *InternalDB) SetTPRateProfiles(tpPrfs []*utils.TPRateProfile) (err error) {
- if len(tpPrfs) == 0 {
- return nil
- }
- for _, tpPrf := range tpPrfs {
- Cache.SetWithoutReplicate(utils.CacheTBLTPRateProfiles, utils.ConcatenatedKey(tpPrf.TPid, tpPrf.Tenant, tpPrf.ID), tpPrf, nil,
- cacheCommit(utils.NonTransactional), utils.NonTransactional)
- }
- return
-}
-
func (iDB *InternalDB) SetTPActionProfiles(tpPrfs []*utils.TPActionProfile) (err error) {
if len(tpPrfs) == 0 {
return nil
diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go
index 09b0a007a..68b6aa28c 100644
--- a/engine/storage_mongo_datadb.go
+++ b/engine/storage_mongo_datadb.go
@@ -637,8 +637,6 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err er
result, err = ms.getField2(sctx, ColCpp, utils.ChargerProfilePrefix, subject, tntID)
case utils.DispatcherProfilePrefix:
result, err = ms.getField2(sctx, ColDpp, utils.DispatcherProfilePrefix, subject, tntID)
- case utils.RateProfilePrefix:
- result, err = ms.getField2(sctx, ColRpp, utils.RateProfilePrefix, subject, tntID)
case utils.ActionProfilePrefix:
result, err = ms.getField2(sctx, ColApp, utils.ActionProfilePrefix, subject, tntID)
case utils.DispatcherHostPrefix:
@@ -659,12 +657,6 @@ func (ms *MongoStorage) GetKeysForPrefix(prefix string) (result []string, err er
result, err = ms.getField3(sctx, ColIndx, utils.DispatcherFilterIndexes, "key")
case utils.ActionPlanIndexes:
result, err = ms.getField3(sctx, ColIndx, utils.ActionPlanIndexes, "key")
- case utils.ActionProfilesFilterIndexPrfx:
- result, err = ms.getField3(sctx, ColIndx, utils.ActionProfilesFilterIndexPrfx, "key")
- case utils.RateProfilesFilterIndexPrfx:
- result, err = ms.getField3(sctx, ColIndx, utils.RateProfilesFilterIndexPrfx, "key")
- case utils.RateFilterIndexPrfx:
- result, err = ms.getField3(sctx, ColIndx, utils.RateFilterIndexPrfx, "key")
case utils.FilterIndexPrfx:
result, err = ms.getField3(sctx, ColIndx, utils.FilterIndexPrfx, "key")
default:
@@ -715,8 +707,6 @@ func (ms *MongoStorage) HasDataDrv(category, subject, tenant string) (has bool,
count, err = ms.getCol(ColDpp).CountDocuments(sctx, bson.M{"tenant": tenant, "id": subject})
case utils.DispatcherHostPrefix:
count, err = ms.getCol(ColDph).CountDocuments(sctx, bson.M{"tenant": tenant, "id": subject})
- case utils.RateProfilePrefix:
- count, err = ms.getCol(ColRpp).CountDocuments(sctx, bson.M{"tenant": tenant, "id": subject})
case utils.ActionProfilePrefix:
count, err = ms.getCol(ColApp).CountDocuments(sctx, bson.M{"tenant": tenant, "id": subject})
default:
@@ -2008,42 +1998,6 @@ func (ms *MongoStorage) RemoveLoadIDsDrv() (err error) {
})
}
-func (ms *MongoStorage) GetRateProfileDrv(tenant, id string) (rpp *utils.RateProfile, err error) {
- rpp = new(utils.RateProfile)
- err = ms.query(func(sctx mongo.SessionContext) (err error) {
- cur := ms.getCol(ColRpp).FindOne(sctx, bson.M{"tenant": tenant, "id": id})
- if err := cur.Decode(rpp); err != nil {
- rpp = nil
- if err == mongo.ErrNoDocuments {
- return utils.ErrNotFound
- }
- return err
- }
- return nil
- })
- return
-}
-
-func (ms *MongoStorage) SetRateProfileDrv(rpp *utils.RateProfile) (err error) {
- return ms.query(func(sctx mongo.SessionContext) (err error) {
- _, err = ms.getCol(ColRpp).UpdateOne(sctx, bson.M{"tenant": rpp.Tenant, "id": rpp.ID},
- bson.M{"$set": rpp},
- options.Update().SetUpsert(true),
- )
- return err
- })
-}
-
-func (ms *MongoStorage) RemoveRateProfileDrv(tenant, id string) (err error) {
- return ms.query(func(sctx mongo.SessionContext) (err error) {
- dr, err := ms.getCol(ColRpp).DeleteOne(sctx, bson.M{"tenant": tenant, "id": id})
- if dr.DeletedCount == 0 {
- return utils.ErrNotFound
- }
- return err
- })
-}
-
func (ms *MongoStorage) GetActionProfileDrv(tenant, id string) (ap *ActionProfile, err error) {
ap = new(ActionProfile)
err = ms.query(func(sctx mongo.SessionContext) (err error) {
diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go
index 384a34048..aab8e70aa 100644
--- a/engine/storage_mongo_stordb.go
+++ b/engine/storage_mongo_stordb.go
@@ -1529,55 +1529,6 @@ func (ms *MongoStorage) SetTPDispatcherHosts(tpDPPs []*utils.TPDispatcherHost) (
})
}
-func (ms *MongoStorage) GetTPRateProfiles(tpid, tenant, id string) ([]*utils.TPRateProfile, error) {
- filter := bson.M{"tpid": tpid}
- if id != "" {
- filter["id"] = id
- }
- if tenant != "" {
- filter["tenant"] = tenant
- }
- var results []*utils.TPRateProfile
- err := ms.query(func(sctx mongo.SessionContext) (err error) {
- cur, err := ms.getCol(utils.TBLTPRateProfiles).Find(sctx, filter)
- if err != nil {
- return err
- }
- for cur.Next(sctx) {
- var tp utils.TPRateProfile
- err := cur.Decode(&tp)
- if err != nil {
- return err
- }
- results = append(results, &tp)
- }
- if len(results) == 0 {
- return utils.ErrNotFound
- }
- return cur.Close(sctx)
- })
- return results, err
-}
-
-func (ms *MongoStorage) SetTPRateProfiles(tpDPPs []*utils.TPRateProfile) (err error) {
- if len(tpDPPs) == 0 {
- return
- }
-
- return ms.query(func(sctx mongo.SessionContext) (err error) {
- for _, tp := range tpDPPs {
- _, err = ms.getCol(utils.TBLTPRateProfiles).UpdateOne(sctx, bson.M{"tpid": tp.TPid, "id": tp.ID},
- bson.M{"$set": tp},
- options.Update().SetUpsert(true),
- )
- if err != nil {
- return err
- }
- }
- return nil
- })
-}
-
func (ms *MongoStorage) GetTPActionProfiles(tpid, tenant, id string) ([]*utils.TPActionProfile, error) {
filter := bson.M{"tpid": tpid}
if id != "" {
diff --git a/engine/storage_redis.go b/engine/storage_redis.go
index 61feb0bcc..7b2214085 100644
--- a/engine/storage_redis.go
+++ b/engine/storage_redis.go
@@ -269,8 +269,7 @@ func (rs *RedisStorage) HasDataDrv(category, subject, tenant string) (exists boo
case utils.ResourcesPrefix, utils.ResourceProfilesPrefix, utils.StatQueuePrefix,
utils.StatQueueProfilePrefix, utils.ThresholdPrefix, utils.ThresholdProfilePrefix,
utils.FilterPrefix, utils.RouteProfilePrefix, utils.AttributeProfilePrefix,
- utils.ChargerProfilePrefix, utils.DispatcherProfilePrefix, utils.DispatcherHostPrefix,
- utils.RateProfilePrefix:
+ utils.ChargerProfilePrefix, utils.DispatcherProfilePrefix, utils.DispatcherHostPrefix:
err := rs.Cmd(&i, redis_EXISTS, category+utils.ConcatenatedKey(tenant, subject))
return i == 1, err
}
@@ -1248,30 +1247,6 @@ func (rs *RedisStorage) RemoveLoadIDsDrv() (err error) {
return rs.Cmd(nil, redis_DEL, utils.LoadIDs)
}
-func (rs *RedisStorage) GetRateProfileDrv(tenant, id string) (rpp *utils.RateProfile, err error) {
- var values []byte
- if err = rs.Cmd(&values, redis_GET, utils.RateProfilePrefix+utils.ConcatenatedKey(tenant, id)); err != nil {
- return
- } else if len(values) == 0 {
- err = utils.ErrNotFound
- return
- }
- err = rs.ms.Unmarshal(values, &rpp)
- return
-}
-
-func (rs *RedisStorage) SetRateProfileDrv(rpp *utils.RateProfile) (err error) {
- var result []byte
- if result, err = rs.ms.Marshal(rpp); err != nil {
- return
- }
- return rs.Cmd(nil, redis_SET, utils.RateProfilePrefix+utils.ConcatenatedKey(rpp.Tenant, rpp.ID), string(result))
-}
-
-func (rs *RedisStorage) RemoveRateProfileDrv(tenant, id string) (err error) {
- return rs.Cmd(nil, redis_DEL, utils.RateProfilePrefix+utils.ConcatenatedKey(tenant, id))
-}
-
func (rs *RedisStorage) GetActionProfileDrv(tenant, id string) (ap *ActionProfile, err error) {
var values []byte
if err = rs.Cmd(&values, redis_GET, utils.ActionProfilePrefix+utils.ConcatenatedKey(tenant, id)); err != nil {
diff --git a/engine/storage_sql.go b/engine/storage_sql.go
index cc8e6729d..f116f1915 100644
--- a/engine/storage_sql.go
+++ b/engine/storage_sql.go
@@ -241,8 +241,7 @@ func (sqls *SQLStorage) RemTpData(table, tpid string, args map[string]string) er
utils.TBLTPSharedGroups, utils.TBLTPActions, utils.TBLTPActionTriggers,
utils.TBLTPAccountActions, utils.TBLTPResources, utils.TBLTPStats, utils.TBLTPThresholds,
utils.TBLTPFilters, utils.TBLTPActionPlans, utils.TBLTPRoutes, utils.TBLTPAttributes,
- utils.TBLTPChargers, utils.TBLTPDispatchers, utils.TBLTPDispatcherHosts,
- utils.TBLTPActionProfiles, utils.TBLTPRateProfiles} {
+ utils.TBLTPChargers, utils.TBLTPDispatchers, utils.TBLTPDispatcherHosts} {
if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil {
tx.Rollback()
return err
@@ -729,28 +728,6 @@ func (sqls *SQLStorage) SetTPDispatcherHosts(tpDPPs []*utils.TPDispatcherHost) e
return nil
}
-func (sqls *SQLStorage) SetTPRateProfiles(tpDPPs []*utils.TPRateProfile) error {
- if len(tpDPPs) == 0 {
- return nil
- }
- tx := sqls.db.Begin()
- for _, dpp := range tpDPPs {
- // Remove previous
- if err := tx.Where(&RateProfileMdl{Tpid: dpp.TPid, ID: dpp.ID}).Delete(RateProfileMdl{}).Error; err != nil {
- tx.Rollback()
- return err
- }
- for _, mst := range APItoModelTPRateProfile(dpp) {
- if err := tx.Create(&mst).Error; err != nil {
- tx.Rollback()
- return err
- }
- }
- }
- tx.Commit()
- return nil
-}
-
func (sqls *SQLStorage) SetTPActionProfiles(tpAps []*utils.TPActionProfile) error {
if len(tpAps) == 0 {
return nil
@@ -1595,25 +1572,6 @@ func (sqls *SQLStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.
return arls, nil
}
-func (sqls *SQLStorage) GetTPRateProfiles(tpid, tenant, id string) ([]*utils.TPRateProfile, error) {
- var dpps RateProfileMdls
- q := sqls.db.Where("tpid = ?", tpid)
- if len(id) != 0 {
- q = q.Where("id = ?", id)
- }
- if len(tenant) != 0 {
- q = q.Where("tenant = ?", tenant)
- }
- if err := q.Find(&dpps).Error; err != nil {
- return nil, err
- }
- arls := dpps.AsTPRateProfile()
- if len(arls) == 0 {
- return arls, utils.ErrNotFound
- }
- return arls, nil
-}
-
func (sqls *SQLStorage) GetTPActionProfiles(tpid, tenant, id string) ([]*utils.TPActionProfile, error) {
var dpps ActionProfileMdls
q := sqls.db.Where("tpid = ?", tpid)
diff --git a/engine/tpexporter.go b/engine/tpexporter.go
index 61804c0b9..bd266bec1 100644
--- a/engine/tpexporter.go
+++ b/engine/tpexporter.go
@@ -320,18 +320,6 @@ func (tpExp *TPExporter) Run() error {
toExportMap[utils.DispatcherHostsCsv] = append(toExportMap[utils.DispatcherHostsCsv], APItoModelTPDispatcherHost(sd))
}
- storDataRateProfiles, err := tpExp.storDb.GetTPRateProfiles(tpExp.tpID, "", "")
- if err != nil && err.Error() != utils.ErrNotFound.Error() {
- utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.ApierS, err, utils.TpRateProfiles))
- withError = true
- }
- for _, sd := range storDataRateProfiles {
- sdModels := APItoModelTPRateProfile(sd)
- for _, sdModel := range sdModels {
- toExportMap[utils.RateProfilesCsv] = append(toExportMap[utils.RateProfilesCsv], sdModel)
- }
- }
-
storDataActionProfiles, err := tpExp.storDb.GetTPActionProfiles(tpExp.tpID, "", "")
if err != nil && err.Error() != utils.ErrNotFound.Error() {
utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.ApierS, err, utils.TpActionProfiles))
diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go
index f146b83c6..13c8e15ac 100644
--- a/engine/tpimporter_csv.go
+++ b/engine/tpimporter_csv.go
@@ -60,7 +60,6 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{
utils.ChargersCsv: (*TPCSVImporter).importChargerProfiles,
utils.DispatcherProfilesCsv: (*TPCSVImporter).importDispatcherProfiles,
utils.DispatcherHostsCsv: (*TPCSVImporter).importDispatcherHosts,
- utils.RateProfilesCsv: (*TPCSVImporter).importRateProfiles,
utils.ActionProfilesCsv: (*TPCSVImporter).importActionProfiles,
}
@@ -360,17 +359,6 @@ func (tpImp *TPCSVImporter) importDispatcherHosts(fn string) error {
return tpImp.StorDb.SetTPDispatcherHosts(dpps)
}
-func (tpImp *TPCSVImporter) importRateProfiles(fn string) error {
- if tpImp.Verbose {
- log.Printf("Processing file: <%s> ", fn)
- }
- rpps, err := tpImp.csvr.GetTPRateProfiles(tpImp.TPid, "", "")
- if err != nil {
- return err
- }
- return tpImp.StorDb.SetTPRateProfiles(rpps)
-}
-
func (tpImp *TPCSVImporter) importActionProfiles(fn string) error {
if tpImp.Verbose {
log.Printf("Processing file: <%s> ", fn)
diff --git a/engine/tpreader.go b/engine/tpreader.go
index 6bd27db28..9f4fc60a3 100644
--- a/engine/tpreader.go
+++ b/engine/tpreader.go
@@ -56,7 +56,6 @@ type TpReader struct {
chargerProfiles map[utils.TenantID]*utils.TPChargerProfile
dispatcherProfiles map[utils.TenantID]*utils.TPDispatcherProfile
dispatcherHosts map[utils.TenantID]*utils.TPDispatcherHost
- rateProfiles map[utils.TenantID]*utils.TPRateProfile
actionProfiles map[utils.TenantID]*utils.TPActionProfile
resources []*utils.TenantID // IDs of resources which need creation based on resourceProfiles
statQueues []*utils.TenantID // IDs of statQueues which need creation based on statQueueProfiles
@@ -106,7 +105,6 @@ func (tpr *TpReader) Init() {
tpr.chargerProfiles = make(map[utils.TenantID]*utils.TPChargerProfile)
tpr.dispatcherProfiles = make(map[utils.TenantID]*utils.TPDispatcherProfile)
tpr.dispatcherHosts = make(map[utils.TenantID]*utils.TPDispatcherHost)
- tpr.rateProfiles = make(map[utils.TenantID]*utils.TPRateProfile)
tpr.actionProfiles = make(map[utils.TenantID]*utils.TPActionProfile)
tpr.filters = make(map[utils.TenantID]*utils.TPFilterProfile)
tpr.acntActionPlans = make(map[string][]string)
@@ -322,7 +320,7 @@ func (tpr *TpReader) LoadRatingProfilesFiltered(qriedRpf *utils.TPRatingProfile)
var resultRatingProfile *RatingProfile
mpTpRpfs, err := tpr.lr.GetTPRatingProfiles(qriedRpf)
if err != nil {
- return fmt.Errorf("no RateProfile for filter %v, error: %v", qriedRpf, err)
+ return fmt.Errorf("no RatingProfile for filter %v, error: %v", qriedRpf, err)
}
rpfs, err := MapTPRatingProfiles(mpTpRpfs)
@@ -1285,26 +1283,6 @@ func (tpr *TpReader) LoadDispatcherHostsFiltered(tag string) (err error) {
return nil
}
-func (tpr *TpReader) LoadRateProfiles() error {
- return tpr.LoadRateProfilesFiltered("")
-}
-
-func (tpr *TpReader) LoadRateProfilesFiltered(tag string) (err error) {
- rls, err := tpr.lr.GetTPRateProfiles(tpr.tpid, "", tag)
- if err != nil {
- return err
- }
- mapRateProfiles := make(map[utils.TenantID]*utils.TPRateProfile)
- for _, rl := range rls {
- if err = verifyInlineFilterS(rl.FilterIDs); err != nil {
- return
- }
- mapRateProfiles[utils.TenantID{Tenant: rl.Tenant, ID: rl.ID}] = rl
- }
- tpr.rateProfiles = mapRateProfiles
- return nil
-}
-
func (tpr *TpReader) LoadActionProfiles() error {
return tpr.LoadActionProfilesFiltered("")
}
@@ -1390,9 +1368,6 @@ func (tpr *TpReader) LoadAll() (err error) {
if err = tpr.LoadDispatcherHosts(); err != nil && err.Error() != utils.NotFoundCaps {
return
}
- if err = tpr.LoadRateProfiles(); err != nil && err.Error() != utils.NotFoundCaps {
- return
- }
if err = tpr.LoadActionProfiles(); err != nil && err.Error() != utils.NotFoundCaps {
return
}
@@ -1838,25 +1813,6 @@ func (tpr *TpReader) WriteToDatabase(verbose, disableReverse bool) (err error) {
loadIDs[utils.CacheDispatcherHosts] = loadID
}
- if verbose {
- log.Print("RateProfiles:")
- }
- for _, tpTH := range tpr.rateProfiles {
- var th *utils.RateProfile
- if th, err = APItoRateProfile(tpTH, tpr.timezone); err != nil {
- return
- }
- if err = tpr.dm.SetRateProfile(th, true); err != nil {
- return
- }
- if verbose {
- log.Print("\t", th.TenantID())
- }
- }
- if len(tpr.rateProfiles) != 0 {
- loadIDs[utils.CacheRateProfiles] = loadID
- }
-
if verbose {
log.Print("ActionProfiles:")
}
@@ -1972,8 +1928,6 @@ func (tpr *TpReader) ShowStatistics() {
log.Print("DispatcherProfiles: ", len(tpr.dispatcherProfiles))
// Dispatcher Hosts
log.Print("DispatcherHosts: ", len(tpr.dispatcherHosts))
- // Rate profiles
- log.Print("RateProfiles: ", len(tpr.rateProfiles))
// Action profiles
log.Print("ActionProfiles: ", len(tpr.actionProfiles))
}
@@ -2126,15 +2080,6 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) {
i++
}
return keys, nil
-
- case utils.RateProfilePrefix:
- keys := make([]string, len(tpr.rateProfiles))
- i := 0
- for k := range tpr.rateProfiles {
- keys[i] = k.TenantID()
- i++
- }
- return keys, nil
case utils.ActionProfilePrefix:
keys := make([]string, len(tpr.actionProfiles))
i := 0
@@ -2366,19 +2311,6 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error
}
}
- if verbose {
- log.Print("RateProfiles:")
- }
- for _, tpRp := range tpr.rateProfiles {
- if err = tpr.dm.RemoveRateProfile(tpRp.Tenant, tpRp.ID,
- utils.NonTransactional, true); err != nil {
- return
- }
- if verbose {
- log.Print("\t", utils.ConcatenatedKey(tpRp.Tenant, tpRp.ID))
- }
- }
-
if verbose {
log.Print("ActionProfiles:")
}
@@ -2495,9 +2427,6 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disableReverse bool) (err error
if len(tpr.dispatcherHosts) != 0 {
loadIDs[utils.CacheDispatcherHosts] = loadID
}
- if len(tpr.rateProfiles) != 0 {
- loadIDs[utils.CacheRateProfiles] = loadID
- }
if len(tpr.actionProfiles) != 0 {
loadIDs[utils.CacheActionProfiles] = loadID
}
@@ -2536,7 +2465,6 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i
chargerIDs, _ := tpr.GetLoadedIds(utils.ChargerProfilePrefix)
dppIDs, _ := tpr.GetLoadedIds(utils.DispatcherProfilePrefix)
dphIDs, _ := tpr.GetLoadedIds(utils.DispatcherHostPrefix)
- ratePrfIDs, _ := tpr.GetLoadedIds(utils.RateProfilePrefix)
actionPrfIDs, _ := tpr.GetLoadedIds(utils.ActionProfilePrefix)
aps, _ := tpr.GetLoadedIds(utils.ActionPlanPrefix)
@@ -2565,7 +2493,6 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i
utils.ChargerProfileIDs: chargerIDs,
utils.DispatcherProfileIDs: dppIDs,
utils.DispatcherHostIDs: dphIDs,
- utils.RateProfileIDs: ratePrfIDs,
utils.ActionProfileIDs: actionPrfIDs,
},
}
@@ -2618,10 +2545,6 @@ func (tpr *TpReader) ReloadCache(caching string, verbose bool, opts map[string]i
if len(dppIDs) != 0 {
cacheIDs = append(cacheIDs, utils.CacheDispatcherFilterIndexes)
}
- if len(ratePrfIDs) != 0 {
- cacheIDs = append(cacheIDs, utils.CacheRateProfilesFilterIndexes)
- cacheIDs = append(cacheIDs, utils.CacheRateFilterIndexes)
- }
if len(actionPrfIDs) != 0 {
cacheIDs = append(cacheIDs, utils.CacheActionProfilesFilterIndexes)
}
diff --git a/engine/version.go b/engine/version.go
index c5c99374c..6264c8a33 100644
--- a/engine/version.go
+++ b/engine/version.go
@@ -163,7 +163,6 @@ func CurrentDataDBVersions() Versions {
utils.Chargers: 2,
utils.Dispatchers: 2,
utils.LoadIDsVrs: 1,
- utils.RateProfiles: 1,
utils.ActionProfiles: 1,
}
}
@@ -195,7 +194,6 @@ func CurrentStorDBVersions() Versions {
utils.TpRatingProfile: 1,
utils.TpChargers: 1,
utils.TpDispatchers: 1,
- utils.TpRateProfiles: 1,
utils.TpActionProfiles: 1,
}
}
diff --git a/engine/version_test.go b/engine/version_test.go
index 9d4ab7954..ff81dec90 100644
--- a/engine/version_test.go
+++ b/engine/version_test.go
@@ -92,8 +92,7 @@ func TestCurrentDBVersions(t *testing.T) {
utils.Timing: 1, utils.RQF: 5, utils.Resource: 1,
utils.Subscribers: 1, utils.Destinations: 1, utils.ReverseDestinations: 1,
utils.RatingPlan: 1, utils.RatingProfile: 1, utils.Chargers: 2,
- utils.Dispatchers: 2, utils.LoadIDsVrs: 1, utils.RateProfiles: 1,
- utils.ActionProfiles: 1,
+ utils.Dispatchers: 2, utils.LoadIDsVrs: 1, utils.ActionProfiles: 1,
}
expVersStorDB := Versions{
utils.CostDetails: 2, utils.SessionSCosts: 3, utils.CDRs: 2,
@@ -104,7 +103,7 @@ func TestCurrentDBVersions(t *testing.T) {
utils.TpResources: 1, utils.TpRates: 1, utils.TpTiming: 1,
utils.TpResource: 1, utils.TpDestinations: 1, utils.TpRatingPlan: 1,
utils.TpRatingProfile: 1, utils.TpChargers: 1, utils.TpDispatchers: 1,
- utils.TpRateProfiles: 1, utils.TpActionProfiles: 1,
+ utils.TpActionProfiles: 1,
}
if vrs := CurrentDBVersions(utils.Mongo, true); !reflect.DeepEqual(expVersDataDB, vrs) {
t.Errorf("Expectred %+v, received %+v", expVersDataDB, vrs)
diff --git a/engine/z_filterindexer_it_test.go b/engine/z_filterindexer_it_test.go
index 94c83ff63..f7325b31d 100644
--- a/engine/z_filterindexer_it_test.go
+++ b/engine/z_filterindexer_it_test.go
@@ -82,10 +82,8 @@ var sTests = []func(t *testing.T){
testITFlush,
testITIsDBEmpty,
testITTestIndexingMetaNot,
- testITIndexRateProfileRateIndexes,
testITFlush,
testITIsDBEmpty,
- testITIndexRateProfileIndexes,
testITFlush,
testITIsDBEmpty,
testITTestIndexingMetaSuffix,
@@ -1971,386 +1969,6 @@ func testITTestIndexingMetaNot(t *testing.T) {
}
}
-func testITIndexRateProfileRateIndexes(t *testing.T) {
- rPrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "FIRST_GI": {
- ID: "FIRST_GI",
- FilterIDs: []string{"*string:~*req.Category:call"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- Blocker: false,
- },
- "SECOND_GI": {
- ID: "SECOND_GI",
- FilterIDs: []string{"*string:~*req.Category:voice"},
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Blocker: false,
- },
- },
- }
- if err := dataManager.SetRateProfile(rPrf, true); err != nil {
- t.Error(err)
- }
- eIdxes := map[string]utils.StringSet{
- "*string:*req.Category:call": {
- "FIRST_GI": struct{}{},
- },
- "*string:*req.Category:voice": {
- "SECOND_GI": struct{}{},
- },
- }
- if rcvIdx, err := dataManager.GetIndexes(
- utils.CacheRateFilterIndexes, "cgrates.org:RP1",
- utils.EmptyString, true, true); err != nil {
- t.Error(err)
- } else {
- if !reflect.DeepEqual(eIdxes, rcvIdx) {
- t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(eIdxes), utils.ToJSON(rcvIdx))
- }
- }
-
- // update the RateProfile by adding a new Rate
- rPrf = &utils.RateProfile{ // recreate the profile because if we test on internal
- Tenant: "cgrates.org", // each update on the original item will update the item from DB
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "FIRST_GI": {
- ID: "FIRST_GI",
- FilterIDs: []string{"*string:~*req.Category:call"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- Blocker: false,
- },
- "SECOND_GI": {
- ID: "SECOND_GI",
- FilterIDs: []string{"*string:~*req.Category:voice"},
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Blocker: false,
- },
- "THIRD_GI": {
- ID: "THIRD_GI",
- FilterIDs: []string{"*string:~*req.Category:custom"},
- Weights: utils.DynamicWeights{
- {
- Weight: 20,
- },
- },
- Blocker: false,
- },
- },
- }
- if err := dataManager.SetRateProfile(rPrf, true); err != nil {
- t.Error(err)
- }
- eIdxes = map[string]utils.StringSet{
- "*string:*req.Category:call": {
- "FIRST_GI": struct{}{},
- },
- "*string:*req.Category:voice": {
- "SECOND_GI": struct{}{},
- },
- "*string:*req.Category:custom": {
- "THIRD_GI": struct{}{},
- },
- }
- if rcvIdx, err := dataManager.GetIndexes(
- utils.CacheRateFilterIndexes, "cgrates.org:RP1",
- utils.EmptyString, true, true); err != nil {
- t.Error(err)
- } else {
- if !reflect.DeepEqual(eIdxes, rcvIdx) {
- t.Errorf("Expecting %+v, received: %+v", eIdxes, rcvIdx)
- }
- }
-
- //here we will set a filter
- fltr := &Filter{
- Tenant: "cgrates.org",
- ID: "FLTR",
- Rules: []*FilterRule{{Type: utils.MetaString, Element: "Dan", Values: []string{"~*req.Account", "~*req.Destination", "DAN2"}}},
- }
- if err := dataManager.SetFilter(fltr, true); err != nil {
- t.Error(err)
- }
- rPrf2 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP2",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "CUSTOM_RATE1": {
- ID: "CUSTOM_RATE1",
- FilterIDs: []string{"*string:~*req.Subject:1001", "FLTR"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- Blocker: false,
- },
- "CUSTOM_RATE2": {
- ID: "CUSTOM_RATE2",
- FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Category:call"},
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Blocker: false,
- },
- },
- }
- if err := dataManager.SetRateProfile(rPrf2, true); err != nil {
- t.Error(err)
- }
- eIdxes = map[string]utils.StringSet{
- "*string:*req.Subject:1001": {
- "CUSTOM_RATE1": struct{}{},
- "CUSTOM_RATE2": struct{}{},
- },
- "*string:*req.Category:call": {
- "CUSTOM_RATE2": struct{}{},
- },
- "*string:*req.Account:Dan": {
- "CUSTOM_RATE1": struct{}{},
- },
- "*string:*req.Destination:Dan": {
- "CUSTOM_RATE1": struct{}{},
- },
- }
- if rcvIdx, err := dataManager.GetIndexes(
- utils.CacheRateFilterIndexes, "cgrates.org:RP2",
- utils.EmptyString, true, true); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eIdxes, rcvIdx) {
- t.Errorf("Expecting %+v, received: %+v", eIdxes, rcvIdx)
- }
-
- //here we will check the reverse indexes
- eIdxes = map[string]utils.StringSet{
- utils.CacheRateFilterIndexes: {
- "CUSTOM_RATE1:RP2": struct{}{},
- },
- }
- if rcvIdx, err := dataManager.GetIndexes(
- utils.CacheReverseFilterIndexes, "cgrates.org:FLTR",
- utils.EmptyString, true, true); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eIdxes, rcvIdx) {
- t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(eIdxes), utils.ToJSON(rcvIdx))
- }
-
- //now we will update the filter
- fltr = &Filter{
- Tenant: "cgrates.org",
- ID: "FLTR",
- Rules: []*FilterRule{{Type: utils.MetaString, Element: "10m", Values: []string{"~*req.Usage", "~*req.Debited", "DAN2"}}},
- }
- if err := dataManager.SetFilter(fltr, true); err != nil {
- t.Error(err)
- }
-
- eIdxes = map[string]utils.StringSet{
- "*string:*req.Subject:1001": {
- "CUSTOM_RATE1": struct{}{},
- "CUSTOM_RATE2": struct{}{},
- },
- "*string:*req.Category:call": {
- "CUSTOM_RATE2": struct{}{},
- },
- "*string:*req.Usage:10m": {
- "CUSTOM_RATE1": struct{}{},
- },
- "*string:*req.Debited:10m": {
- "CUSTOM_RATE1": struct{}{},
- },
- }
- if rcvIdx, err := dataManager.GetIndexes(
- utils.CacheRateFilterIndexes, "cgrates.org:RP2",
- utils.EmptyString, true, true); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eIdxes, rcvIdx) {
- t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(eIdxes), utils.ToJSON(rcvIdx))
- }
-
- //invalid or inexisting tenant:context or index key
- eIdxes = nil
- if rcvIdx, err := dataManager.GetIndexes(
- utils.CacheRateFilterIndexes, "cgrates.org:RP4",
- utils.EmptyString, true, true); err == nil || err != utils.ErrNotFound {
- t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err)
- } else if !reflect.DeepEqual(eIdxes, rcvIdx) {
- t.Errorf("Expecting %+v, received: %+v", utils.ToJSON(eIdxes), utils.ToJSON(rcvIdx))
- }
-
-}
-
-func testITIndexRateProfileIndexes(t *testing.T) {
- fltr1 := &Filter{
- Tenant: "cgrates.org",
- ID: "FLTR",
- Rules: []*FilterRule{{Type: utils.MetaString, Element: "~*req.Usage", Values: []string{"10m"}}},
- }
- if err := dataManager.SetFilter(fltr1, true); err != nil {
- t.Error(err)
- }
- rPrf1 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1004|1005", "FLTR"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "CUSTOM1_RATE1": {
- ID: "CUSTOM1_RATE1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Blocker: false,
- },
- "CUSTOM1_RATE2": {
- ID: "CUSTOM1_RATE2",
- FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Category:call"},
- Blocker: false,
- },
- },
- }
- rPrf2 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP2",
- FilterIDs: []string{"*string:~*req.ToR:*sms|*voice", "*string:~*req.Subject:1004"},
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "CUSTOM2_RATE1": {
- ID: "CUSTOM2_RATE1",
- FilterIDs: []string{"*string:~*req.Subject:1009"},
- Blocker: false,
- },
- },
- }
- if err := dataManager.SetRateProfile(rPrf1, true); err != nil {
- t.Error(err)
- } else if err := dataManager.SetRateProfile(rPrf2, true); err != nil {
- t.Error(err)
- }
-
- expIdx := map[string]utils.StringSet{
- "*string:*req.Subject:1004": {
- "RP1": struct{}{},
- "RP2": struct{}{},
- },
- "*string:*req.Subject:1005": {
- "RP1": struct{}{},
- },
- "*string:*req.ToR:*sms": {
- "RP2": struct{}{},
- },
- "*string:*req.ToR:*voice": {
- "RP2": struct{}{},
- },
- "*string:*req.Usage:10m": {
- "RP1": struct{}{},
- },
- }
- if rcv, err := dataManager.GetIndexes(utils.CacheRateProfilesFilterIndexes,
- "cgrates.org", utils.EmptyString, false, false); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rcv, expIdx) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIdx), utils.ToJSON(rcv))
- }
-
- //we will update the filter
- fltr1 = &Filter{
- Tenant: "cgrates.org",
- ID: "FLTR",
- Rules: []*FilterRule{{Type: utils.MetaString, Element: "~*req.CustomField", Values: []string{"234", "567"}}},
- }
- if err := dataManager.SetFilter(fltr1, true); err != nil {
- t.Error(err)
- }
- expIdx = map[string]utils.StringSet{
- "*string:*req.Subject:1004": {
- "RP1": struct{}{},
- "RP2": struct{}{},
- },
- "*string:*req.Subject:1005": {
- "RP1": struct{}{},
- },
- "*string:*req.ToR:*sms": {
- "RP2": struct{}{},
- },
- "*string:*req.ToR:*voice": {
- "RP2": struct{}{},
- },
- "*string:*req.CustomField:234": {
- "RP1": struct{}{},
- },
- "*string:*req.CustomField:567": {
- "RP1": struct{}{},
- },
- }
- if rcv, err := dataManager.GetIndexes(utils.CacheRateProfilesFilterIndexes,
- "cgrates.org", utils.EmptyString, false, false); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rcv, expIdx) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIdx), utils.ToJSON(rcv))
- }
-
- //here we will get the reverse indexes
- expIdx = map[string]utils.StringSet{
- utils.CacheRateProfilesFilterIndexes: {
- "RP1": struct{}{},
- },
- }
- if rcv, err := dataManager.GetIndexes(utils.CacheReverseFilterIndexes,
- "cgrates.org:FLTR", utils.EmptyString, false, false); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rcv, expIdx) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIdx), utils.ToJSON(rcv))
- }
-
- //nothing to get with with an invalid indexKey
- expIdx = nil
- if rcv, err := dataManager.GetIndexes(utils.CacheRateProfilesFilterIndexes,
- "cgrates.org", "*string:*req.CustomField:2346", false, false); err == nil || err != utils.ErrNotFound {
- t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err)
- } else if !reflect.DeepEqual(rcv, expIdx) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(expIdx), utils.ToJSON(rcv))
- }
-}
-
func testITTestIndexingMetaSuffix(t *testing.T) {
th := &ThresholdProfile{
Tenant: "cgrates.org",
diff --git a/engine/z_onstor_it_test.go b/engine/z_onstor_it_test.go
index 102b3d8e4..e82a24074 100644
--- a/engine/z_onstor_it_test.go
+++ b/engine/z_onstor_it_test.go
@@ -75,7 +75,6 @@ var (
testOnStorITTestAttributeSubstituteIface,
testOnStorITChargerProfile,
testOnStorITDispatcherProfile,
- testOnStorITRateProfile,
testOnStorITActionProfile,
//testOnStorITCacheActionTriggers,
//testOnStorITCRUDActionTriggers,
@@ -2154,87 +2153,6 @@ func testOnStorITDispatcherProfile(t *testing.T) {
}
}
-func testOnStorITRateProfile(t *testing.T) {
- rPrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001", "*string:~*req.Subject:1002"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "FIRST_GI": {
- ID: "FIRST_GI",
- FilterIDs: []string{"*gi:~*req.Usage:0"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- Blocker: false,
- },
- "SECOND_GI": {
- ID: "SECOND_GI",
- FilterIDs: []string{"*gi:~*req.Usage:1m"},
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Blocker: false,
- },
- },
- }
- if _, rcvErr := onStor.GetRateProfile("cgrates.org", "RP1",
- true, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
- t.Error(rcvErr)
- }
- if err := onStor.SetRateProfile(rPrf, false); err != nil {
- t.Error(err)
- }
- if err = rPrf.Compile(); err != nil {
- t.Fatal(err)
- }
- //get from database
- if rcv, err := onStor.GetRateProfile("cgrates.org", "RP1",
- false, false, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rPrf, rcv) {
- t.Errorf("Expecting: %v, received: %v", rPrf, rcv)
- }
- expectedT := []string{"rtp_cgrates.org:RP1"}
- if itm, err := onStor.DataDB().GetKeysForPrefix(utils.RateProfilePrefix); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedT, itm) {
- t.Errorf("Expected : %+v, but received %+v", expectedT, itm)
- }
- //update
- rPrf.FilterIDs = []string{"*string:~*req.Accout:1001", "*prefix:~*req.Destination:10"}
- if err := onStor.SetRateProfile(rPrf, false); err != nil {
- t.Error(err)
- }
-
- //get from database
- if rcv, err := onStor.GetRateProfile("cgrates.org", "RP1",
- false, false, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if !(reflect.DeepEqual(rPrf, rcv)) {
- t.Errorf("Expecting: %v, received: %v", rPrf, rcv)
- }
- if err := onStor.RemoveRateProfile(rPrf.Tenant, rPrf.ID,
- utils.NonTransactional, false); err != nil {
- t.Error(err)
- }
- //check database if removed
- if _, rcvErr := onStor.GetRateProfile("cgrates.org", "RP1",
- false, false, utils.NonTransactional); rcvErr != nil && rcvErr != utils.ErrNotFound {
- t.Error(rcvErr)
- }
-}
-
func testOnStorITActionProfile(t *testing.T) {
actPrf := &ActionProfile{
Tenant: "cgrates.org",
diff --git a/engine/z_stordb_it_test.go b/engine/z_stordb_it_test.go
index 5bee9037d..8145fc555 100644
--- a/engine/z_stordb_it_test.go
+++ b/engine/z_stordb_it_test.go
@@ -48,7 +48,6 @@ var sTestsStorDBit = []func(t *testing.T){
testStorDBitCRUDTPDispatcherProfiles,
testStorDBitCRUDTPDispatcherHosts,
testStorDBitCRUDTPFilters,
- testStorDBitCRUDTPRateProfiles,
testStorDBitCRUDTPRoutes,
testStorDBitCRUDTPThresholds,
testStorDBitCRUDTPAttributes,
@@ -436,73 +435,6 @@ func testStorDBitCRUDTPFilters(t *testing.T) {
}
}
-func testStorDBitCRUDTPRateProfiles(t *testing.T) {
- //READ
- if _, err := storDB.GetTPRateProfiles("ID_RP1", utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
- t.Error(err)
- }
-
- //WRITE
- tpr := []*utils.TPRateProfile{
- {
- TPid: "id_RP1",
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: ";0",
- MinCost: 0.1,
- MaxCost: 0.6,
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.TPRate{
- "FIRST_GI": {
- ID: "FIRST_GI",
- FilterIDs: []string{"*gi:~*req.Usage:0"},
- Weights: ";0",
- IntervalRates: []*utils.TPIntervalRate{
- {
- RecurrentFee: 0.12,
- Unit: "1m",
- Increment: "1m",
- },
- },
- Blocker: false,
- },
- },
- },
- }
- if err := storDB.SetTPRateProfiles(tpr); err != nil {
- t.Error(err)
- }
-
- //READ
- if rcv, err := storDB.GetTPRateProfiles(tpr[0].TPid, utils.EmptyString, utils.EmptyString); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rcv[0], tpr[0]) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(tpr[0]), utils.ToJSON(rcv[0]))
- }
-
- //UPDATE and WRITE
- tpr[0].MaxCost = 2.0
- tpr[0].MinCost = 0.2
- if err := storDB.SetTPRateProfiles(tpr); err != nil {
- t.Error(err)
- }
-
- //READ
- if rcv, err := storDB.GetTPRateProfiles(tpr[0].TPid, utils.EmptyString, utils.EmptyString); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rcv[0], tpr[0]) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(tpr[0]), utils.ToJSON(rcv[0]))
- }
-
- //REMOVE AND READ
- if err := storDB.RemTpData(utils.EmptyString, tpr[0].TPid, nil); err != nil {
- t.Error(err)
- } else if _, err := storDB.GetTPRateProfiles(tpr[0].TPid, utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
- t.Error(err)
- }
-}
-
func testStorDBitCRUDTPRoutes(t *testing.T) {
//READ
if _, err := storDB.GetTPRoutes("TP1", utils.EmptyString, utils.EmptyString); err != utils.ErrNotFound {
diff --git a/general_tests/filtered_replication_it_test.go b/general_tests/filtered_replication_it_test.go
index 5dea677b9..2d82dbbdd 100644
--- a/general_tests/filtered_replication_it_test.go
+++ b/general_tests/filtered_replication_it_test.go
@@ -64,7 +64,6 @@ var (
testFltrRplChargerProfile,
testFltrRplDispatcherProfile,
testFltrRplDispatcherHost,
- testFltrRplRateProfile,
testFltrRplActionProfile,
testFltrRplAccount,
testFltrRplDestination,
@@ -1339,146 +1338,6 @@ func testFltrRplDispatcherHost(t *testing.T) {
}
}
-func testFltrRplRateProfile(t *testing.T) {
- rpID := "RP1"
- rpPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: rpID,
- FilterIDs: []string{"*string:~*req.Account:dan"},
- Weights: ";0",
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.APIRate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: ";0",
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- },
- },
- },
- },
- },
- }
- expPrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: rpID,
- FilterIDs: []string{"*string:~*req.Account:dan"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- var result string
- var replyPrfl *utils.RateProfile
- var rplyIDs []string
- // empty
- if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
- if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
-
- if err := fltrRplInternalRPC.Call(utils.APIerSv1SetRateProfile, rpPrf, &result); err != nil {
- t.Fatal(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := fltrRplInternalRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &replyPrfl); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(expPrf, replyPrfl) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl))
- }
- replyPrfl = nil
-
- if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
- if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
-
- if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &replyPrfl); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(expPrf, replyPrfl) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl))
- }
- replyPrfl = nil
- rpPrf.Weights = ";15"
- expPrf.Weights[0].Weight = 15
- if err := fltrRplInternalRPC.Call(utils.APIerSv1SetRateProfile, rpPrf, &result); err != nil {
- t.Fatal(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := fltrRplInternalRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &replyPrfl); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(expPrf, replyPrfl) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl))
- }
- replyPrfl = nil
-
- // use replicator to see if the attribute was changed in the DB
- if err := fltrRplEngine1RPC.Call(utils.ReplicatorSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &replyPrfl); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(expPrf, replyPrfl) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(expPrf), utils.ToJSON(replyPrfl))
- }
-
- if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
-
- if err := fltrRplInternalRPC.Call(utils.APIerSv1RemoveRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: rpID}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := fltrRplEngine1RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
- if err := fltrRplEngine2RPC.Call(utils.APIerSv1GetRateProfileIDs, &utils.PaginatorWithTenant{}, &rplyIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Unexpected error: %v", err)
- }
-}
-
func testFltrRplActionProfile(t *testing.T) {
acID := "ATTR1"
acPrf := &engine.ActionProfileWithAPIOpts{
diff --git a/loaders/lib_test.go b/loaders/lib_test.go
index fb6bf2bf7..c131ade74 100644
--- a/loaders/lib_test.go
+++ b/loaders/lib_test.go
@@ -69,197 +69,6 @@ func (s *testMockCacheConn) Call(method string, arg interface{}, rply interface{
}
}
-func TestProcessContentCallsLoadCache(t *testing.T) {
- sMock := &testMockCacheConn{
- calls: map[string]func(arg interface{}, rply interface{}) error{
- utils.CacheSv1LoadCache: func(arg interface{}, rply interface{}) error {
- prply, can := rply.(*string)
- if !can {
- t.Errorf("Wrong argument type: %T", rply)
- }
- *prply = utils.OK
- return nil
- },
- utils.CacheSv1Clear: func(arg interface{}, rply interface{}) error {
- prply, can := rply.(*string)
- if !can {
- t.Errorf("Wrong argument type : %T", rply)
- return nil
- }
- *prply = utils.OK
- return nil
- },
- },
- }
- internalCacheSChann := make(chan rpcclient.ClientConnector, 1)
- internalCacheSChann <- sMock
- data := engine.NewInternalDB(nil, nil, true)
- ldr := &Loader{
- ldrID: "TestProcessContentCallsLoadCache",
- bufLoaderData: make(map[string][]LoaderData),
- dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
- connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{
- utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChann,
- }),
- cacheConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)},
- timezone: "UTC",
- }
- ldr.dataTpls = map[string][]*config.FCTemplate{
- utils.MetaRateProfiles: {
- {Tag: "TenantID",
- Path: "Tenant",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
- Mandatory: true},
- {Tag: "ProfileID",
- Path: "ID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
- Mandatory: true},
- {Tag: "Weight",
- Path: "Weight",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.2", utils.InfieldSep)},
- },
- }
- ratePrfCsv := `
-#Tenant[0],ID[1],Weight[2]
-cgrates.org,MOCK_RELOAD_ID,20
-`
- rdr := io.NopCloser(strings.NewReader(ratePrfCsv))
- rdrCsv := csv.NewReader(rdr)
- rdrCsv.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{
- fileName: utils.RateProfilesCsv,
- rdr: rdr,
- csvRdr: rdrCsv,
- },
- },
- }
- if err := ldr.processContent(utils.MetaRateProfiles, utils.MetaLoad); err != nil {
- t.Error(err)
- }
-
- // Calling the method again while cacheConnsID is not valid
- ldr.cacheConns = []string{utils.MetaInternal}
- rdr = io.NopCloser(strings.NewReader(ratePrfCsv))
- rdrCsv = csv.NewReader(rdr)
- rdrCsv.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{
- fileName: utils.RateProfilesCsv,
- rdr: rdr,
- csvRdr: rdrCsv,
- },
- },
- }
- expected := "UNSUPPORTED_SERVICE_METHOD"
- if err := ldr.processContent(utils.MetaRateProfiles, utils.MetaLoad); err == nil || err.Error() != expected {
- t.Errorf("Expected %+v, received %+v", expected, err)
- }
-}
-
-func TestProcessContentCallsReloadCache(t *testing.T) {
- // Clear cache because connManager sets the internal connection in cache
- engine.Cache.Clear([]string{utils.CacheRPCConnections})
-
- sMock2 := &testMockCacheConn{
- calls: map[string]func(arg interface{}, rply interface{}) error{
- utils.CacheSv1ReloadCache: func(arg interface{}, rply interface{}) error {
- prply, can := rply.(*string)
- if !can {
- t.Errorf("Wrong argument type : %T", rply)
- return nil
- }
- *prply = utils.OK
- return nil
- },
- utils.CacheSv1Clear: func(arg interface{}, rply interface{}) error {
- prply, can := rply.(*string)
- if !can {
- t.Errorf("Wrong argument type : %T", rply)
- return nil
- }
- *prply = utils.OK
- return nil
- },
- },
- }
- data := engine.NewInternalDB(nil, nil, true)
-
- internalCacheSChan := make(chan rpcclient.ClientConnector, 1)
- internalCacheSChan <- sMock2
- ldr := &Loader{
- ldrID: "TestProcessContentCalls",
- bufLoaderData: make(map[string][]LoaderData),
- connMgr: engine.NewConnManager(config.CgrConfig(), map[string]chan rpcclient.ClientConnector{
- utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): internalCacheSChan,
- }),
- dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
- cacheConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)},
- timezone: "UTC",
- }
- ldr.dataTpls = map[string][]*config.FCTemplate{
- utils.MetaRateProfiles: {
- {Tag: "TenantID",
- Path: "Tenant",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
- Mandatory: true},
- {Tag: "ProfileID",
- Path: "ID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
- Mandatory: true},
- {Tag: "Weight",
- Path: "Weight",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.2", utils.InfieldSep)},
- },
- }
- ratePrfCsv := `
-#Tenant[0],ID[1],Weight[2]
-cgrates.org,MOCK_RELOAD_ID,20
-`
- rdr := io.NopCloser(strings.NewReader(ratePrfCsv))
- rdrCsv := csv.NewReader(rdr)
- rdrCsv.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{
- fileName: utils.RateProfilesCsv,
- rdr: rdr,
- csvRdr: rdrCsv,
- },
- },
- }
- if err := ldr.processContent(utils.MetaRateProfiles, utils.MetaReload); err != nil {
- t.Error(err)
- }
-
- // Calling the method again while cacheConnsID is not valid
- ldr.cacheConns = []string{utils.MetaInternal}
- rdr = io.NopCloser(strings.NewReader(ratePrfCsv))
- rdrCsv = csv.NewReader(rdr)
- rdrCsv.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{
- fileName: utils.RateProfilesCsv,
- rdr: rdr,
- csvRdr: rdrCsv,
- },
- },
- }
- expected := "UNSUPPORTED_SERVICE_METHOD"
- if err := ldr.processContent(utils.MetaRateProfiles, utils.MetaReload); err == nil || err.Error() != expected {
- t.Errorf("Expected %+v, received %+v", expected, err)
- }
-}
-
func TestProcessContentCallsRemoveItems(t *testing.T) {
// Clear cache because connManager sets the internal connection in cache
engine.Cache.Clear([]string{utils.CacheRPCConnections})
diff --git a/loaders/loader.go b/loaders/loader.go
index fcf25f95f..39affbd02 100644
--- a/loaders/loader.go
+++ b/loaders/loader.go
@@ -574,41 +574,6 @@ func (ldr *Loader) storeLoadedData(loaderType string,
cacheArgs[utils.DispatcherHostIDs] = ids
}
}
- case utils.MetaRateProfiles:
- cacheIDs = []string{utils.CacheRateProfilesFilterIndexes, utils.CacheRateFilterIndexes}
- for _, lDataSet := range lds {
- rpMdls := make(engine.RateProfileMdls, len(lDataSet))
- for i, ld := range lDataSet {
- rpMdls[i] = new(engine.RateProfileMdl)
- if err = utils.UpdateStructWithIfaceMap(rpMdls[i], ld); err != nil {
- return
- }
- }
- for _, tpRpl := range rpMdls.AsTPRateProfile() {
- rpl, err := engine.APItoRateProfile(tpRpl, ldr.timezone)
- if err != nil {
- return err
- }
- if ldr.dryRun {
- utils.Logger.Info(
- fmt.Sprintf("<%s-%s> DRY_RUN: RateProfile: %s",
- utils.LoaderS, ldr.ldrID, utils.ToJSON(rpl)))
- continue
- }
- // get IDs so we can reload in cache
- ids = append(ids, rpl.TenantID())
- if ldr.flagsTpls[loaderType].GetBool(utils.MetaPartial) {
- if err := ldr.dm.SetRateProfileRates(rpl, true); err != nil {
- return err
- }
- } else {
- if err := ldr.dm.SetRateProfile(rpl, true); err != nil {
- return err
- }
- }
- cacheArgs[utils.RateProfileIDs] = ids
- }
- }
case utils.MetaActionProfiles:
cacheIDs = []string{utils.CacheActionProfilesFilterIndexes}
for _, lDataSet := range lds {
@@ -930,36 +895,6 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa
cacheArgs[utils.DispatcherHostIDs] = ids
}
}
- case utils.MetaRateProfiles:
- cacheIDs = []string{utils.CacheRateProfilesFilterIndexes, utils.CacheRateFilterIndexes}
- for tntID, ldData := range lds {
- if ldr.dryRun {
- utils.Logger.Info(
- fmt.Sprintf("<%s-%s> DRY_RUN: RateProfileIDs: %s",
- utils.LoaderS, ldr.ldrID, tntID))
- } else {
- tntIDStruct := utils.NewTenantID(tntID)
- // get IDs so we can reload in cache
- ids = append(ids, tntID)
- if ldr.flagsTpls[loaderType].GetBool(utils.MetaPartial) {
- rateIDs, err := ldData[0].GetRateIDs()
- if err != nil {
- return err
- }
- if err := ldr.dm.RemoveRateProfileRates(tntIDStruct.Tenant,
- tntIDStruct.ID, rateIDs, true); err != nil {
- return err
- }
- } else {
- if err := ldr.dm.RemoveRateProfile(tntIDStruct.Tenant,
- tntIDStruct.ID, utils.NonTransactional, true); err != nil {
- return err
- }
- }
-
- cacheArgs[utils.RateProfileIDs] = ids
- }
- }
case utils.MetaActionProfiles:
cacheIDs = []string{utils.CacheActionProfiles, utils.CacheActionProfilesFilterIndexes}
for tntID := range lds {
diff --git a/loaders/loader_test.go b/loaders/loader_test.go
index 0f7d20ec0..1f95aa392 100644
--- a/loaders/loader_test.go
+++ b/loaders/loader_test.go
@@ -1455,854 +1455,6 @@ func TestLoaderRemoveContentSingleFile(t *testing.T) {
t.Error(err)
}
}
-
-func TestLoaderProcessRateProfile(t *testing.T) {
- data := engine.NewInternalDB(nil, nil, true)
- ldr := &Loader{
- ldrID: "TestLoaderProcessRateProfile",
- bufLoaderData: make(map[string][]LoaderData),
- dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
- timezone: "UTC",
- }
- ldr.dataTpls = map[string][]*config.FCTemplate{
- utils.MetaRateProfiles: {
- {Tag: "TenantID",
- Path: "Tenant",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
- Mandatory: true},
- {Tag: "ProfileID",
- Path: "ID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
- Mandatory: true},
- {Tag: "FilterIDs",
- Path: "FilterIDs",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.2", utils.InfieldSep)},
- {Tag: "ActivationInterval",
- Path: "ActivationInterval",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.3", utils.InfieldSep)},
- {Tag: "Weights",
- Path: "Weights",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.4", utils.InfieldSep)},
- {Tag: "MinCost",
- Path: "MinCost",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.5", utils.InfieldSep)},
- {Tag: "MaxCost",
- Path: "MaxCost",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.6", utils.InfieldSep)},
- {Tag: "MaxCostStrategy",
- Path: "MaxCostStrategy",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.7", utils.InfieldSep)},
- {Tag: "RateID",
- Path: "RateID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.8", utils.InfieldSep)},
- {Tag: "RateFilterIDs",
- Path: "RateFilterIDs",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.9", utils.InfieldSep)},
- {Tag: "RateActivationTimes",
- Path: "RateActivationTimes",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.10", utils.InfieldSep)},
- {Tag: "RateWeights",
- Path: "RateWeights",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.11", utils.InfieldSep)},
- {Tag: "RateBlocker",
- Path: "RateBlocker",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.12", utils.InfieldSep)},
- {Tag: "RateIntervalStart",
- Path: "RateIntervalStart",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.13", utils.InfieldSep)},
- {Tag: "RateFixedFee",
- Path: "RateFixedFee",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.14", utils.InfieldSep)},
- {Tag: "RateRecurrentFee",
- Path: "RateRecurrentFee",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.15", utils.InfieldSep)},
- {Tag: "RateUnit",
- Path: "RateUnit",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.16", utils.InfieldSep)},
- {Tag: "RateIncrement",
- Path: "RateIncrement",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.17", utils.InfieldSep)},
- },
- }
- rdr := io.NopCloser(strings.NewReader(engine.RateProfileCSVContent))
- csvRdr := csv.NewReader(rdr)
- csvRdr.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr, csvRdr: csvRdr}},
- }
- if err := ldr.processContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
- t.Error(err)
- }
- if len(ldr.bufLoaderData) != 0 {
- t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
- }
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- eRatePrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- FixedFee: utils.NewDecimal(1234, 3),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(89, 3),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(564, 4),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- },
- }
- rcv, err := ldr.dm.GetRateProfile("cgrates.org", "RP1",
- true, false, utils.NonTransactional)
- if err != nil {
- t.Error(err)
- }
- rcv.Compile()
- eRatePrf.Compile()
- if !reflect.DeepEqual(rcv, eRatePrf) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf), utils.ToJSON(rcv))
- }
-
- //cannot set RateProfile when dryrun is true
- ldr.dryRun = true
- rdr = io.NopCloser(strings.NewReader(engine.RateProfileCSVContent))
- csvRdr = csv.NewReader(rdr)
- csvRdr.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr, csvRdr: csvRdr}},
- }
- if err := ldr.processContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
- t.Error(err)
- }
-
-}
-
-func TestLoaderProcessRateProfileRates(t *testing.T) {
- data := engine.NewInternalDB(nil, nil, true)
- ldr := &Loader{
- ldrID: "TestLoaderProcessRateProfile",
- bufLoaderData: make(map[string][]LoaderData),
- flagsTpls: make(map[string]utils.FlagsWithParams),
- dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
- timezone: "UTC",
- }
- ldr.dataTpls = map[string][]*config.FCTemplate{
- utils.MetaRateProfiles: {
- {Tag: "TenantID",
- Path: "Tenant",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
- Mandatory: true},
- {Tag: "ProfileID",
- Path: "ID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
- Mandatory: true},
- {Tag: "FilterIDs",
- Path: "FilterIDs",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.2", utils.InfieldSep)},
- {Tag: "ActivationInterval",
- Path: "ActivationInterval",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.3", utils.InfieldSep)},
- {Tag: "Weights",
- Path: "Weights",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.4", utils.InfieldSep)},
- {Tag: "MinCost",
- Path: "MinCost",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.5", utils.InfieldSep)},
- {Tag: "MaxCost",
- Path: "MaxCost",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.6", utils.InfieldSep)},
- {Tag: "MaxCostStrategy",
- Path: "MaxCostStrategy",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.7", utils.InfieldSep)},
- {Tag: "RateID",
- Path: "RateID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.8", utils.InfieldSep)},
- {Tag: "RateFilterIDs",
- Path: "RateFilterIDs",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.9", utils.InfieldSep)},
- {Tag: "RateActivationTimes",
- Path: "RateActivationTimes",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.10", utils.InfieldSep)},
- {Tag: "RateWeights",
- Path: "RateWeights",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.11", utils.InfieldSep)},
- {Tag: "RateBlocker",
- Path: "RateBlocker",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.12", utils.InfieldSep)},
- {Tag: "RateIntervalStart",
- Path: "RateIntervalStart",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.13", utils.InfieldSep)},
- {Tag: "RateFixedFee",
- Path: "RateFixedFee",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.14", utils.InfieldSep)},
- {Tag: "RateRecurrentFee",
- Path: "RateRecurrentFee",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.15", utils.InfieldSep)},
- {Tag: "RateUnit",
- Path: "RateUnit",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.16", utils.InfieldSep)},
- {Tag: "RateIncrement",
- Path: "RateIncrement",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.17", utils.InfieldSep)},
- },
- }
- ratePrfCnt1 := `
-#Tenant,ID,FilterIDs,ActivationInterval,Weights,MinCost,MaxCost,MaxCostStrategy,RateID,RateFilterIDs,RateActivationTimes,RateWeights,RateBlocker,RateIntervalStart,RateFixedFee,RateRecurrentFee,RateUnit,RateIncrement
-cgrates.org,RP1,*string:~*req.Subject:1001,,;0,0.1,0.6,*free,RT_WEEK,,"* * * * 1-5",;0,false,0s,0.4,0.12,1m,1m
-cgrates.org,RP1,,,,,,,RT_WEEK,,,,,1m,,0.06,1m,1s
-`
- ratePrfCnt2 := `
-#Tenant,ID,FilterIDs,ActivationInterval,Weights,RoundingMethod,RoundingDecimals,MinCost,MaxCost,MaxCostStrategy,RateID,RateFilterIDs,RateActivationTimes,RateWeights,RateBlocker,RateIntervalStart,RateValue,RateUnit,RateIncrement
-cgrates.org,RP1,,,,,,,RT_WEEKEND,,"* * * * 0,6",;10,false,0s,,0.06,1m,1s
-cgrates.org,RP1,,,,,,,RT_CHRISTMAS,,* * 24 12 *,;30,false,0s,,0.06,1m,1s
-`
- rdr1 := io.NopCloser(strings.NewReader(ratePrfCnt1))
- csvRdr1 := csv.NewReader(rdr1)
- csvRdr1.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr1, csvRdr: csvRdr1}},
- }
- if err := ldr.processContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
- t.Error(err)
- }
- if len(ldr.bufLoaderData) != 0 {
- t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
- }
- minDecimal, err := utils.NewDecimalFromUsage("1m")
- if err != nil {
- t.Error(err)
- }
- secDecimal, err := utils.NewDecimalFromUsage("1s")
- if err != nil {
- t.Error(err)
- }
- eRatePrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(4, 1),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- },
- }
- rcv, err := ldr.dm.GetRateProfile("cgrates.org", "RP1",
- true, false, utils.NonTransactional)
- if err != nil {
- t.Error(err)
- }
- rcv.Compile()
- eRatePrf.Compile()
- if !reflect.DeepEqual(rcv, eRatePrf) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf), utils.ToJSON(rcv))
- }
-
- rdr2 := io.NopCloser(strings.NewReader(ratePrfCnt2))
- csvRdr2 := csv.NewReader(rdr2)
- csvRdr2.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr2, csvRdr: csvRdr2}},
- }
- ldr.flagsTpls[utils.MetaRateProfiles] = utils.FlagsWithParamsFromSlice([]string{utils.MetaPartial})
- if err := ldr.processContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
- t.Error(err)
- }
- if len(ldr.bufLoaderData) != 0 {
- t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
- }
- eRatePrf = &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MinCost: utils.NewDecimal(1, 1),
- MaxCost: utils.NewDecimal(6, 1),
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(4, 1),
- RecurrentFee: utils.NewDecimal(12, 2),
- Unit: minDecimal,
- Increment: minDecimal,
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- FixedFee: utils.NewDecimal(0, 0),
- RecurrentFee: utils.NewDecimal(6, 2),
- Unit: minDecimal,
- Increment: secDecimal,
- },
- },
- },
- },
- }
- rcv, err = ldr.dm.GetRateProfile("cgrates.org", "RP1",
- true, false, utils.NonTransactional)
- if err != nil {
- t.Error(err)
- }
- rcv.Compile()
- eRatePrf.Compile()
- if !reflect.DeepEqual(rcv, eRatePrf) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf), utils.ToJSON(rcv))
- }
-
-}
-
-func TestLoaderRemoveRateProfileRates(t *testing.T) {
- data := engine.NewInternalDB(nil, nil, true)
- ldr := &Loader{
- ldrID: "TestLoaderRemoveRateProfileRates",
- bufLoaderData: make(map[string][]LoaderData),
- flagsTpls: make(map[string]utils.FlagsWithParams),
- dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
- timezone: "UTC",
- }
- ldr.dataTpls = map[string][]*config.FCTemplate{
- utils.MetaRateProfiles: {
- {Tag: "TenantID",
- Path: "Tenant",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
- Mandatory: true},
- {Tag: "ProfileID",
- Path: "ID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
- Mandatory: true},
- {Tag: "RateIDs",
- Path: "RateIDs",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.2", utils.InfieldSep)},
- },
- }
-
- rPfr := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- if err := ldr.dm.SetRateProfile(rPfr, true); err != nil {
- t.Error(err)
- }
- rPfr2 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP2",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- },
- },
- },
- "RT_WEEKEND": {
- ID: "RT_WEEKEND",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- ActivationTimes: "* * * * 0,6",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- if err := ldr.dm.SetRateProfile(rPfr2, true); err != nil {
- t.Error(err)
- }
-
- ratePrfCnt1 := `
-#Tenant,ID,RateIDs
-cgrates.org,RP1,RT_WEEKEND
-`
- ratePrfCnt2 := `
-#Tenant,ID,RateIDs
-cgrates.org,RP2,RT_WEEKEND;RT_CHRISTMAS
-cgrates.org,RP1,
-`
- rdr1 := io.NopCloser(strings.NewReader(ratePrfCnt1))
- csvRdr1 := csv.NewReader(rdr1)
- csvRdr1.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr1, csvRdr: csvRdr1}},
- }
- ldr.flagsTpls[utils.MetaRateProfiles] = utils.FlagsWithParamsFromSlice([]string{utils.MetaPartial})
- if err := ldr.removeContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
- t.Error(err)
- }
- if len(ldr.bufLoaderData) != 0 {
- t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
- }
-
- eRatePrf := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- },
- },
- },
- "RT_CHRISTMAS": {
- ID: "RT_CHRISTMAS",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- ActivationTimes: "* * 24 12 *",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- },
- },
- },
- }
- rcv, err := ldr.dm.GetRateProfile("cgrates.org", "RP1",
- true, false, utils.NonTransactional)
- if err != nil {
- t.Error(err)
- }
- rcv.Compile()
- eRatePrf.Compile()
- if !reflect.DeepEqual(rcv, eRatePrf) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf), utils.ToJSON(rcv))
- }
-
- rdr2 := io.NopCloser(strings.NewReader(ratePrfCnt2))
- csvRdr2 := csv.NewReader(rdr2)
- csvRdr2.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr2, csvRdr: csvRdr2}},
- }
- ldr.flagsTpls[utils.MetaRateProfiles] = utils.FlagsWithParamsFromSlice([]string{utils.MetaPartial})
- if err := ldr.removeContent(utils.MetaRateProfiles, utils.EmptyString); err != nil {
- t.Error(err)
- }
- if len(ldr.bufLoaderData) != 0 {
- t.Errorf("wrong buffer content: %+v", ldr.bufLoaderData)
- }
-
- eRatePrf2 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP2",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{
- "RT_WEEK": {
- ID: "RT_WEEK",
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- ActivationTimes: "* * * * 1-5",
- IntervalRates: []*utils.IntervalRate{
- {
- IntervalStart: utils.NewDecimal(0, 0),
- },
- {
- IntervalStart: utils.NewDecimal(int64(time.Minute), 0),
- },
- },
- },
- },
- }
- rcv, err = ldr.dm.GetRateProfile("cgrates.org", "RP2",
- true, false, utils.NonTransactional)
- if err != nil {
- t.Error(err)
- }
- rcv.Compile()
- eRatePrf2.Compile()
- if !reflect.DeepEqual(rcv, eRatePrf2) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf2), utils.ToJSON(rcv))
- }
-
- eRatePrf3 := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- Weights: utils.DynamicWeights{
- {
- Weight: 0,
- },
- },
- MaxCostStrategy: "*free",
- Rates: map[string]*utils.Rate{},
- }
- rcv, err = ldr.dm.GetRateProfile("cgrates.org", "RP1",
- true, false, utils.NonTransactional)
- if err != nil {
- t.Error(err)
- }
- rcv.Compile()
- eRatePrf3.Compile()
- if !reflect.DeepEqual(rcv, eRatePrf3) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eRatePrf3), utils.ToJSON(rcv))
- }
-}
-
-func TestRemoveRateProfileFlagsError(t *testing.T) {
- data := engine.NewInternalDB(nil, nil, true)
- ldr := &Loader{
- ldrID: "TestLoaderRemoveRateProfileRates",
- bufLoaderData: make(map[string][]LoaderData),
- flagsTpls: make(map[string]utils.FlagsWithParams),
- dm: engine.NewDataManager(data, config.CgrConfig().CacheCfg(), nil),
- timezone: "UTC",
- }
- ldr.dataTpls = map[string][]*config.FCTemplate{
- utils.MetaRateProfiles: {
- {Tag: "TenantID",
- Path: "Tenant",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.0", utils.InfieldSep),
- Mandatory: true},
- {Tag: "ProfileID",
- Path: "ID",
- Type: utils.MetaComposed,
- Value: config.NewRSRParsersMustCompile("~*req.1", utils.InfieldSep),
- Mandatory: true},
- },
- }
- ratePrfCnt1 := `
-#Tenant,ID
-cgrates.org,RP2
-`
- rPfr := &utils.RateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- }
- if err := ldr.dm.SetRateProfile(rPfr, true); err != nil {
- t.Error(err)
- }
-
- rdr1 := io.NopCloser(strings.NewReader(ratePrfCnt1))
- csvRdr1 := csv.NewReader(rdr1)
- csvRdr1.Comment = '#'
- ldr.rdrs = map[string]map[string]*openedCSVFile{
- utils.MetaRateProfiles: {
- utils.RateProfilesCsv: &openedCSVFile{fileName: utils.RateProfilesCsv,
- rdr: rdr1, csvRdr: csvRdr1}},
- }
- ldr.flagsTpls[utils.MetaRateProfiles] = utils.FlagsWithParamsFromSlice([]string{utils.MetaPartial})
- expectedErr := "cannot find RateIDs in