diff --git a/agents/diam_it_test.go b/agents/diam_it_test.go
index a3fe07e72..f108ad660 100644
--- a/agents/diam_it_test.go
+++ b/agents/diam_it_test.go
@@ -28,7 +28,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -1454,15 +1453,15 @@ func testDiamItEmulateTerminate(t *testing.T) {
}
var result string
//add the second charger
- chargerProfile := &v1.ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.com",
- ID: "CustomCharger",
- RunID: "CustomCharger",
- AttributeIDs: []string{"*constant:*req.Category:custom_charger"},
- Weight: 20,
- },
- }
+ // chargerProfile := &v1.ChargerWithAPIOpts{
+ // ChargerProfile: &engine.ChargerProfile{
+ // Tenant: "cgrates.com",
+ // ID: "CustomCharger",
+ // RunID: "CustomCharger",
+ // AttributeIDs: []string{"*constant:*req.Category:custom_charger"},
+ // Weight: 20,
+ // },
+ // }
if err := apierRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
t.Error(err)
diff --git a/analyzers/analyzers.go b/analyzers/analyzers.go
old mode 100755
new mode 100644
diff --git a/apier/v1/accountprofiles.go b/apier/v1/accountprofiles.go
deleted file mode 100644
index 087fc7e81..000000000
--- a/apier/v1/accountprofiles.go
+++ /dev/null
@@ -1,197 +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/birpc/context"
- "github.com/cgrates/cgrates/accounts"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetAccount returns an Account
-func (apierSv1 *APIerSv1) GetAccount(arg *utils.TenantIDWithAPIOpts, reply *utils.Account) 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
- }
- ap, err := apierSv1.DataManager.GetAccount(tnt, arg.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *ap
- return nil
-}
-
-// GetAccountIDs returns list of action profile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetAccountIDs(args *utils.PaginatorWithTenant, actPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.AccountPrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *actPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-// GetAccountIDsCount sets in reply var the total number of AccountIDs registered for a tenant
-// returns ErrNotFound in case of 0 AccountIDs
-func (apierSv1 *APIerSv1) GetAccountIDsCount(args *utils.TenantWithAPIOpts, reply *int) (err error) {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- var keys []string
- prfx := utils.AccountPrefix + tnt + utils.ConcatenatedKeySep
- if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), prfx); err != nil {
- return err
- }
- if len(keys) == 0 {
- return utils.ErrNotFound
- }
- *reply = len(keys)
- return
-}
-
-//SetAccount add/update a new Account
-func (apierSv1 *APIerSv1) SetAccount(extAp *utils.APIAccountWithOpts, reply *string) error {
- if missing := utils.MissingStructFields(extAp.APIAccount, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if extAp.Tenant == utils.EmptyString {
- extAp.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- ap, err := extAp.AsAccount()
- if err != nil {
- return err
- }
- if err := apierSv1.DataManager.SetAccount(ap, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheAccounts and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheAccounts: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// RemoveAccount remove a specific Account
-func (apierSv1 *APIerSv1) RemoveAccount(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.RemoveAccount(tnt, arg.ID,
- utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheAccounts and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheAccounts: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// NewAccountSv1 initializes AccountSv1
-func NewAccountSv1(aS *accounts.AccountS) *AccountSv1 {
- return &AccountSv1{aS: aS}
-}
-
-// AccountSv1 exports RPC from RLs
-type AccountSv1 struct {
- aS *accounts.AccountS
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (aSv1 *AccountSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(aSv1, serviceMethod, args, reply)
-}
-
-// Ping return pong if the service is active
-func (aSv1 *AccountSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// AccountsForEvent returns the matching Account for Event
-func (aSv1 *AccountSv1) AccountsForEvent(args *utils.ArgsAccountsForEvent,
- aps *[]*utils.Account) (err error) {
- return aSv1.aS.V1AccountsForEvent(args, aps)
-}
-
-// MaxAbstracts returns the maximum abstracts for the event, based on matching Account
-func (aSv1 *AccountSv1) MaxAbstracts(args *utils.ArgsAccountsForEvent,
- eEc *utils.ExtEventCharges) (err error) {
- return aSv1.aS.V1MaxAbstracts(args, eEc)
-}
-
-// DebitAbstracts performs debit for the provided event
-func (aSv1 *AccountSv1) DebitAbstracts(args *utils.ArgsAccountsForEvent,
- eEc *utils.ExtEventCharges) (err error) {
- return aSv1.aS.V1DebitAbstracts(args, eEc)
-}
-
-// MaxConcretes returns the maximum concretes for the event, based on the matching Account
-func (aSv1 *AccountSv1) MaxConcretes(args *utils.ArgsAccountsForEvent,
- eEc *utils.ExtEventCharges) (err error) {
- return aSv1.aS.V1MaxConcretes(args, eEc)
-}
-
-// DebitConcretes performs debit of concrete units for the provided event
-func (aSv1 *AccountSv1) DebitConcretes(args *utils.ArgsAccountsForEvent,
- eEc *utils.ExtEventCharges) (err error) {
- return aSv1.aS.V1DebitConcretes(args, eEc)
-}
-
-// ActionSetBalance performs a set balance action
-func (aSv1 *AccountSv1) ActionSetBalance(args *utils.ArgsActSetBalance,
- eEc *string) (err error) {
- return aSv1.aS.V1ActionSetBalance(args, eEc)
-}
-
-// ActionRemoveBalance removes a balance from an account
-func (aSv1 *AccountSv1) ActionRemoveBalance(args *utils.ArgsActRemoveBalances,
- eEc *string) (err error) {
- return aSv1.aS.V1ActionRemoveBalance(args, eEc)
-}
diff --git a/apier/v1/accountprofiles_it_test.go b/apier/v1/accountprofiles_it_test.go
deleted file mode 100644
index 9a3bf9e4b..000000000
--- a/apier/v1/accountprofiles_it_test.go
+++ /dev/null
@@ -1,374 +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"
- "github.com/ericlagergren/decimal"
-)
-
-var (
- accPrfCfgPath string
- accPrfCfg *config.CGRConfig
- accSRPC *rpc.Client
- apiAccPrf *utils.APIAccountWithOpts
- accPrf *utils.Account
- accPrfConfigDIR string //run tests for specific configuration
-
- sTestsAccPrf = []func(t *testing.T){
- testAccountSInitCfg,
- testAccountSInitDataDb,
- testAccountSResetStorDb,
- testAccountSStartEngine,
- testAccountSRPCConn,
- testAccountSLoadFromFolder,
- testAccountSGetAccount,
- testAccountSPing,
- testAccountSSettAccount,
- testAccountSGetAccountIDs,
- testAccountSGetAccountIDsCount,
- testAccountSUpdateAccount,
- testAccountSRemoveAccount,
- testAccountSKillEngine,
- }
-)
-
-//Test start here
-func TestAccountSIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- accPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- accPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- accPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsAccPrf {
- t.Run(accPrfConfigDIR, stest)
- }
-}
-
-func testAccountSInitCfg(t *testing.T) {
- var err error
- accPrfCfgPath = path.Join(*dataDir, "conf", "samples", accPrfConfigDIR)
- accPrfCfg, err = config.NewCGRConfigFromPath(accPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testAccountSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(accPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testAccountSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(accPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testAccountSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(accPrfCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testAccountSRPCConn(t *testing.T) {
- var err error
- accSRPC, err = newRPCClient(accPrfCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testAccountSLoadFromFolder(t *testing.T) {
- var reply string
- acts := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutaccounts")}
- if err := accSRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, acts, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testAccountSGetAccount(t *testing.T) {
- eAcnt := &utils.Account{
- Tenant: "cgrates.org",
- ID: "1001",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Balances: map[string]*utils.Balance{
- "GenericBalance1": &utils.Balance{
- ID: "GenericBalance1",
- Weights: []*utils.DynamicWeight{
- {
- Weight: 20,
- },
- },
- Type: utils.MetaAbstract,
- Units: &utils.Decimal{decimal.New(int64(time.Hour), 0)},
- UnitFactors: []*utils.UnitFactor{
- &utils.UnitFactor{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Factor: &utils.Decimal{decimal.New(1024, 3)},
- },
- },
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance1": &utils.Balance{
- ID: "MonetaryBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(5, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance2": &utils.Balance{
- ID: "MonetaryBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(3, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- }
- var reply *utils.Account
- if err := accSRPC.Call(utils.APIerSv1GetAccount,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1001"}}, &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(eAcnt, reply) {
- t.Errorf("Expecting : %+v \n received: %+v", utils.ToJSON(eAcnt), utils.ToJSON(reply))
- }
-}
-
-func testAccountSPing(t *testing.T) {
- var resp string
- if err := accSRPC.Call(utils.AccountSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testAccountSSettAccount(t *testing.T) {
- apiAccPrf = &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "id_test",
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "MonetaryBalance": &utils.APIBalance{
- ID: "MonetaryBalance",
- Weights: ";10",
- Type: utils.MetaMonetary,
- CostIncrements: []*utils.APICostIncrement{
- {
- FilterIDs: []string{"fltr1", "fltr2"},
- Increment: utils.Float64Pointer(1.3),
- FixedFee: utils.Float64Pointer(2.3),
- RecurrentFee: utils.Float64Pointer(3.3),
- },
- },
- AttributeIDs: []string{"attr1", "attr2"},
- UnitFactors: []*utils.APIUnitFactor{
- {
- FilterIDs: []string{"fltr1", "fltr2"},
- Factor: 100,
- },
- {
- FilterIDs: []string{"fltr3"},
- Factor: 200,
- },
- },
- Units: 14,
- },
- "VoiceBalance": &utils.APIBalance{
- ID: "VoiceBalance",
- Weights: ";10",
- Type: utils.MetaVoice,
- Units: 3600000000000,
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var result string
- expErr := utils.ErrNotFound.Error()
- if err := accSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "id_test"}}, &result); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
- var reply string
- if err := accSRPC.Call(utils.APIerSv1SetAccount, apiAccPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- if accPrf, err = apiAccPrf.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := accSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "id_test"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(accPrf, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", accPrf, reply2)
- }
-
-}
-
-func testAccountSGetAccountIDs(t *testing.T) {
- expected := []string{"id_test", "1001", "1002"}
- var result []string
- if err := accSRPC.Call(utils.APIerSv1GetAccountIDs, utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := accSRPC.Call(utils.APIerSv1GetAccountIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := accSRPC.Call(utils.APIerSv1GetAccountIDs, utils.PaginatorWithTenant{
- Tenant: "cgrates.org",
- Paginator: utils.Paginator{Limit: utils.IntPointer(1)},
- }, &result); err != nil {
- t.Error(err)
- } else if 1 != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", 1, result)
- }
-
-}
-
-func testAccountSGetAccountIDsCount(t *testing.T) {
- var reply int
- if err := accSRPC.Call(utils.APIerSv1GetAccountIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 3 {
- t.Errorf("Expecting: 3, received: %+v", reply)
- }
-
-}
-
-func testAccountSUpdateAccount(t *testing.T) {
- var reply string
- apiAccPrf.Weights = ";2"
- apiAccPrf.Balances["MonetaryBalance"].CostIncrements[0].FixedFee = utils.Float64Pointer(123.5)
- if err := accSRPC.Call(utils.APIerSv1SetAccount, apiAccPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- if accPrf, err = apiAccPrf.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := accSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "id_test"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(accPrf, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", accPrf, reply2)
- }
-}
-
-func testAccountSRemoveAccount(t *testing.T) {
- var reply string
- if err := accSRPC.Call(utils.APIerSv1RemoveAccount, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "id_test"}}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var reply2 *utils.Account
- expErr := utils.ErrNotFound.Error()
- if err := accSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "id_test"}}, &reply2); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
- if err := accSRPC.Call(utils.APIerSv1RemoveAccount, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "id_test"}}, &reply2); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
-}
-
-func testAccountSKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/accountsv1_it_test.go b/apier/v1/accountsv1_it_test.go
deleted file mode 100644
index 05a554110..000000000
--- a/apier/v1/accountsv1_it_test.go
+++ /dev/null
@@ -1,1422 +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"
- "github.com/ericlagergren/decimal"
-)
-
-var (
- acntSConfigDIR string //run tests for specific configuration
- acntSCfgPath string
- acntSCfg *config.CGRConfig
- acntSRPC *rpc.Client
-)
-
-//Test start here
-func TestAccountSv1IT(t *testing.T) {
- sTestsAccountS := []func(t *testing.T){
- testAccountSv1InitCfg,
- testAccountSv1InitDataDb,
- testAccountSv1ResetStorDb,
- testAccountSv1StartEngine,
- testAccountSv1RPCConn,
- testAccountSv1LoadFromFolder,
- //testAccountSv1AccountsForEvent,
- //testAccountSv1MaxAbstracts,
- //testAccountSv1DebitAbstracts,
- //testAccountSv1SimpleDebit,
- //testAccountSv1DebitMultipleAcc,
- //testAccountSv1DebitMultipleAccLimited,
- testAccountSv1DebitWithAttributeSandRateS,
- //testAccountSv1DebitWithRateS,
- //testAccountSv1DebitWithRateS2,
- //testAccountSv1MaxConcretes,
- //testAccountSv1DebitConcretes,
- //testAccountSv1ActionSetBalance,
- //testAccountSv1ActionRemoveBalance,
- testAccountSv1KillEngine,
- }
- switch *dbType {
- case utils.MetaInternal:
- acntSConfigDIR = "accounts_internal"
- case utils.MetaMySQL:
- t.SkipNow()
- case utils.MetaMongo:
- t.SkipNow()
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatalf("unknown Database type <%s>", *dbType)
- }
- for _, stest := range sTestsAccountS {
- t.Run(acntSConfigDIR, stest)
- }
-}
-
-func testAccountSv1InitCfg(t *testing.T) {
- var err error
- acntSCfgPath = path.Join(*dataDir, "conf", "samples", acntSConfigDIR)
- acntSCfg, err = config.NewCGRConfigFromPath(acntSCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testAccountSv1InitDataDb(t *testing.T) {
- if err := engine.InitDataDB(acntSCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testAccountSv1ResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(acntSCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testAccountSv1StartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(acntSCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testAccountSv1RPCConn(t *testing.T) {
- var err error
- acntSRPC, err = newRPCClient(acntSCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testAccountSv1LoadFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutaccounts")}
- if err := acntSRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testAccountSv1AccountsForEvent(t *testing.T) {
- eAcnts := []*utils.Account{
- {
- Tenant: "cgrates.org",
- ID: "1001",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Balances: map[string]*utils.Balance{
- "GenericBalance1": &utils.Balance{
- ID: "GenericBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 20,
- },
- },
- Type: utils.MetaAbstract,
- Units: &utils.Decimal{decimal.New(int64(time.Hour), 0)},
- UnitFactors: []*utils.UnitFactor{
- &utils.UnitFactor{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Factor: &utils.Decimal{decimal.New(1024, 3)},
- },
- },
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance1": &utils.Balance{
- ID: "MonetaryBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(5, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance2": &utils.Balance{
- ID: "MonetaryBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(3, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var acnts []*utils.Account
- if err := acntSRPC.Call(utils.AccountSv1AccountsForEvent,
- &utils.ArgsAccountsForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1AccountForEvent",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- }}}, &acnts); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eAcnts, acnts) {
- t.Errorf("Expecting : %s \n received: %s", utils.ToJSON(eAcnts), utils.ToJSON(acnts))
- }
-}
-
-func testAccountSv1MaxAbstracts(t *testing.T) {
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1MaxAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1MaxUsage",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.ToR: utils.MetaVoice,
- utils.Usage: "15m",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 800000000000.0 { // 500s from first monetary + 300s from last monetary
- t.Errorf("received usage: %v", *eEc.Abstracts)
- }
-
- // Make sure we did not Debit anything from Account
- eAcnt := &utils.Account{
- Tenant: "cgrates.org",
- ID: "1001",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Balances: map[string]*utils.Balance{
- "GenericBalance1": &utils.Balance{
- ID: "GenericBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 20,
- },
- },
- Type: utils.MetaAbstract,
- Units: &utils.Decimal{decimal.New(int64(time.Hour), 0)},
- UnitFactors: []*utils.UnitFactor{
- &utils.UnitFactor{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Factor: &utils.Decimal{decimal.New(1024, 3)},
- },
- },
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance1": &utils.Balance{
- ID: "MonetaryBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(5, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance2": &utils.Balance{
- ID: "MonetaryBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(3, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- }
-
- var reply *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1001"}}, &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(eAcnt, reply) {
- t.Errorf("Expecting : %+v \n received: %+v", utils.ToJSON(eAcnt), utils.ToJSON(reply))
- }
-}
-
-func testAccountSv1DebitAbstracts(t *testing.T) {
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1MaxUsage",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.ToR: utils.MetaVoice,
- utils.Usage: "15m",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 800000000000.0 { // 500s from first monetary + 300s from last monetary
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- // Make sure we debit the right units from Account
- eAcnt := &utils.Account{
- Tenant: "cgrates.org",
- ID: "1001",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Balances: map[string]*utils.Balance{
- "GenericBalance1": &utils.Balance{
- ID: "GenericBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 20,
- },
- },
- Type: utils.MetaAbstract,
- Units: &utils.Decimal{decimal.New(int64(3300*time.Second), 0)},
- UnitFactors: []*utils.UnitFactor{
- &utils.UnitFactor{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Factor: &utils.Decimal{decimal.New(1024, 3)},
- },
- },
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance1": &utils.Balance{
- ID: "MonetaryBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 30,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1024, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 2)},
- },
- },
- },
- "MonetaryBalance2": &utils.Balance{
- ID: "MonetaryBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*voice"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- }
-
- var reply *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1001"}}, &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(eAcnt, reply) {
- t.Errorf("Expecting : %+v \n received: %+v", utils.ToJSON(eAcnt), utils.ToJSON(reply))
- }
-}
-
-func testAccountSv1SimpleDebit(t *testing.T) {
- accPrfAPI := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "CustomAccount",
- FilterIDs: []string{"*string:~*req.Account:CustomAccount"},
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 100,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(0.1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var result string
- expErr := utils.ErrNotFound.Error()
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &result); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- var convAcc *utils.Account
- if convAcc, err = accPrfAPI.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1SimpleDebit",
- Event: map[string]interface{}{
- utils.AccountField: "CustomAccount",
- utils.Usage: "10",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 10.0 {
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(99, 0)) != 0 {
- t.Errorf("Expecting : %+v, received: %s", decimal.New(99, 0), reply2.Balances["Balance1"].Units)
- }
-}
-
-func testAccountSv1DebitMultipleAcc(t *testing.T) {
- accPrfAPI := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "CustomAccount",
- FilterIDs: []string{"*string:~*req.Account:CustomAccount"},
- Weights: ";20",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 100,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(0.1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- var convAcc *utils.Account
- if convAcc, err = accPrfAPI.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
- }
-
- accPrfAPI2 := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "CustomAccount2",
- FilterIDs: []string{"*string:~*req.Account:CustomAccount"},
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 50,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(0.1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI2, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var convAcc2 *utils.Account
- if convAcc2, err = accPrfAPI2.AsAccount(); err != nil {
- t.Fatal(err)
- }
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount2"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc2, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc2, reply2)
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1SimpleDebit",
- Event: map[string]interface{}{
- utils.AccountField: "CustomAccount",
- utils.Usage: "1400",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 1400.0 {
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(0, 0)) != 0 {
- t.Errorf("Expecting : %s, received: %s", decimal.New(0, 0), reply2.Balances["Balance1"].Units)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount2"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(10, 0)) != 0 {
- t.Errorf("Expecting : %s, received: %s", decimal.New(10, 0), reply2.Balances["Balance1"].Units)
- }
-}
-
-func testAccountSv1DebitMultipleAccLimited(t *testing.T) {
- accPrfAPI := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "CustomAccount",
- FilterIDs: []string{"*string:~*req.Account:CustomAccount"},
- Weights: ";20",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 100,
- Opts: map[string]interface{}{
- utils.MetaBalanceLimit: 50.0,
- },
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(0.1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- var convAcc *utils.Account
- if convAcc, err = accPrfAPI.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
- }
-
- accPrfAPI2 := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "CustomAccount2",
- FilterIDs: []string{"*string:~*req.Account:CustomAccount"},
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 50,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(0.1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI2, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var convAcc2 *utils.Account
- if convAcc2, err = accPrfAPI2.AsAccount(); err != nil {
- t.Fatal(err)
- }
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount2"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc2, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc2, reply2)
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1SimpleDebit",
- Event: map[string]interface{}{
- utils.AccountField: "CustomAccount",
- utils.Usage: "900",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 900.0 {
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(50, 0)) != 0 {
- t.Errorf("Expecting : %s, received: %s", decimal.New(50, 0), reply2.Balances["Balance1"].Units)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomAccount2"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(10, 0)) != 0 {
- t.Errorf("Expecting : %s, received: %s", decimal.New(10, 0), reply2.Balances["Balance1"].Units)
- }
-}
-
-func testAccountSv1DebitWithAttributeSandRateS(t *testing.T) {
- accPrfAPI := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "ACC_WITH_ATTRIBUTES",
- FilterIDs: []string{"*string:~*req.Account:ACC_WITH_ATTRIBUTES"},
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 100,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(-1),
- },
- },
- AttributeIDs: []string{"*constant:*req.CustomField:CustomValue"},
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- var convAcc *utils.Account
- if convAcc, err = accPrfAPI.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_ATTRIBUTES"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
- }
-
- //set a rate profile to be used in case of debit
- apiRPrf := &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP_Test",
- Weights: ";10",
- Rates: map[string]*utils.APIRate{
- "RT_ALWAYS": {
- ID: "RT_ALWAYS",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.1),
- Increment: utils.Float64Pointer(1),
- Unit: utils.Float64Pointer(1),
- },
- },
- },
- },
- }
-
- if err := acntSRPC.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)
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1DebitWithAttributeS",
- Event: map[string]interface{}{
- utils.AccountField: "ACC_WITH_ATTRIBUTES",
- utils.Usage: "10",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 10.0 {
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_ATTRIBUTES"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(99, 0)) != 0 {
- t.Errorf("Expecting : %+v, received: %s", decimal.New(99, 0), reply2.Balances["Balance1"].Units)
- }
-}
-
-func testAccountSv1DebitWithRateS(t *testing.T) {
- accPrfAPI := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "ACC_WITH_RATES",
- FilterIDs: []string{"*string:~*req.Account:ACC_WITH_RATES"},
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 100,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(-1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- var convAcc *utils.Account
- if convAcc, err = accPrfAPI.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_RATES"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
- }
-
- //set a rate profile to be used in case of debit
- apiRPrf := &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP_Test2",
- FilterIDs: []string{"*string:~*req.Account:ACC_WITH_RATES"},
- Weights: ";20",
- Rates: map[string]*utils.APIRate{
- "RT_ALWAYS": {
- ID: "RT_ALWAYS",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.5),
- Increment: utils.Float64Pointer(2),
- Unit: utils.Float64Pointer(2),
- },
- },
- },
- },
- }
-
- if err := acntSRPC.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)
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1DebitWithAttributeS",
- Event: map[string]interface{}{
- utils.AccountField: "ACC_WITH_RATES",
- utils.Usage: "20",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 20.0 {
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_RATES"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(95, 0)) != 0 {
- t.Errorf("Expecting : %+v, received: %s", decimal.New(95, 0), reply2.Balances["Balance1"].Units)
- }
-}
-
-func testAccountSv1DebitWithRateS2(t *testing.T) {
- accPrfAPI := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "ACC_WITH_RATES2",
- FilterIDs: []string{"*string:~*req.Account:ACC_WITH_RATES2"},
- Weights: ";10",
- Balances: map[string]*utils.APIBalance{
- "Balance1": &utils.APIBalance{
- ID: "Balance1",
- Weights: ";10",
- Type: utils.MetaAbstract,
- Units: 100,
- CostIncrements: []*utils.APICostIncrement{
- {
- Increment: utils.Float64Pointer(1),
- RecurrentFee: utils.Float64Pointer(-1),
- },
- },
- RateProfileIDs: []string{"RP_Test22"},
- },
- "Balance2": &utils.APIBalance{
- ID: "Balance2",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 100,
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, accPrfAPI, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var err error
- var convAcc *utils.Account
- if convAcc, err = accPrfAPI.AsAccount(); err != nil {
- t.Error(err)
- }
- var reply2 *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_RATES2"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(convAcc, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", convAcc, reply2)
- }
-
- //set a rate profile to be used in case of debit
- apiRPrf := &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP_Test22",
- FilterIDs: []string{"*string:~*req.Account:ACC_WITH_RATES2"},
- Weights: ";20",
- Rates: map[string]*utils.APIRate{
- "RT_ALWAYS": {
- ID: "RT_ALWAYS",
- Weights: ";0",
- ActivationTimes: "* * * * *",
- IntervalRates: []*utils.APIIntervalRate{
- {
- IntervalStart: "0",
- RecurrentFee: utils.Float64Pointer(0.5),
- Increment: utils.Float64Pointer(2),
- Unit: utils.Float64Pointer(2),
- },
- },
- },
- },
- }
-
- if err := acntSRPC.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)
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1DebitAbstracts,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1DebitWithAttributeS",
- Event: map[string]interface{}{
- utils.AccountField: "ACC_WITH_RATES2",
- utils.Usage: "20",
- }}}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Abstracts == nil || *eEc.Abstracts != 20.0 {
- t.Fatalf("received usage: %v", *eEc.Abstracts)
- }
-
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACC_WITH_RATES2"}}, &reply2); err != nil {
- t.Error(err)
- } else if reply2.Balances["Balance1"].Units.Cmp(decimal.New(80, 0)) != 0 {
- t.Errorf("Expecting : %+v, received: %s", decimal.New(80, 0), reply2.Balances["Balance1"].Units)
- }
-}
-
-func testAccountSv1MaxConcretes(t *testing.T) {
- apiAccPrf = &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "1004",
- FilterIDs: []string{"*string:~*req.Account:1004"},
- Balances: map[string]*utils.APIBalance{
- "ConcreteBalance1": &utils.APIBalance{
- ID: "ConcreteBalance1",
- Weights: ";20",
- Type: utils.MetaConcrete,
- Units: 21,
- CostIncrements: []*utils.APICostIncrement{
- &utils.APICostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: utils.Float64Pointer(1),
- FixedFee: utils.Float64Pointer(0),
- RecurrentFee: utils.Float64Pointer(1),
- },
- },
- },
- "ConcreteBalance2": &utils.APIBalance{
- ID: "ConcreteBalance2",
- Weights: ";10",
- Type: utils.MetaConcrete,
- Units: 20,
- CostIncrements: []*utils.APICostIncrement{
- &utils.APICostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: utils.Float64Pointer(1),
- FixedFee: utils.Float64Pointer(0),
- RecurrentFee: utils.Float64Pointer(1),
- },
- },
- },
- "AbstractBalance1": &utils.APIBalance{
- ID: "AbstractBalance1",
- Weights: ";5",
- Type: utils.MetaAbstract,
- Units: 20,
- CostIncrements: []*utils.APICostIncrement{
- &utils.APICostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: utils.Float64Pointer(float64(time.Second)),
- FixedFee: utils.Float64Pointer(0),
- RecurrentFee: utils.Float64Pointer(1),
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
-
- var reply string
- if err := acntSRPC.Call(utils.APIerSv1SetAccount, apiAccPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- exp, err := apiAccPrf.AsAccount()
- if err != nil {
- t.Error(err)
- }
- var result *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1004"}}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, result) {
- t.Errorf("Expected %+v\n, received %+v", utils.ToJSON(exp), utils.ToJSON(result))
- }
-
- var eEc *utils.ExtEventCharges
- if err := acntSRPC.Call(utils.AccountSv1MaxConcretes,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1MaxConcretes",
- Event: map[string]interface{}{
- utils.AccountField: "1004",
- utils.ToR: utils.MetaData,
- utils.Usage: "50ns",
- },
- }}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Concretes == nil || *eEc.Concretes != 41 {
- t.Errorf("received usage: %v", *eEc.Concretes)
- }
-
- //make sure we did not Debit from our Account
- exp, err = apiAccPrf.AsAccount()
- if err != nil {
- t.Error(err)
- }
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1004"}}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, result) {
- t.Errorf("Expected %+v\n, received %+v", utils.ToJSON(exp), utils.ToJSON(result))
- }
-}
-func testAccountSv1DebitConcretes(t *testing.T) {
- var eEc *utils.ExtEventCharges
- //Now we know the usage, we will debit it from account
- if err := acntSRPC.Call(utils.AccountSv1DebitConcretes,
- &utils.ArgsAccountsForEvent{CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAccountSv1MaxConcretes",
- Event: map[string]interface{}{
- utils.AccountField: "1004",
- utils.ToR: utils.MetaData,
- utils.Usage: "50ns",
- },
- }}, &eEc); err != nil {
- t.Error(err)
- } else if eEc.Concretes == nil || *eEc.Concretes != 41 {
- t.Errorf("received usage: %v", *eEc.Concretes)
- }
-
- exp := &utils.Account{
- Tenant: "cgrates.org",
- ID: "1004",
- FilterIDs: []string{"*string:~*req.Account:1004"},
- Balances: map[string]*utils.Balance{
- "ConcreteBalance1": &utils.Balance{
- ID: "ConcreteBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 20,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- "ConcreteBalance2": &utils.Balance{
- ID: "ConcreteBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- "AbstractBalance1": &utils.Balance{
- ID: "AbstractBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 5,
- },
- },
- Type: utils.MetaAbstract,
- Units: &utils.Decimal{decimal.New(20, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- }
-
- var result *utils.Account
- //As we debit, our Account balances are changed now
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1004"}}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, result) {
- t.Errorf("Expected %+v\n, received %+v", utils.ToJSON(exp), utils.ToJSON(result))
- }
-}
-
-func testAccountSv1ActionSetBalance(t *testing.T) {
- expectedSetBalance := &utils.Account{
- Tenant: "cgrates.org",
- ID: "1004",
- FilterIDs: []string{"*string:~*req.Account:1004"},
- Balances: map[string]*utils.Balance{
- "ConcreteBalance1": &utils.Balance{
- ID: "ConcreteBalance1",
- Weights: utils.DynamicWeights{
- {
- FilterIDs: []string{"fltr1", "fltr2"},
- Weight: 20,
- },
- {
- FilterIDs: []string{"fltr1"},
- Weight: 30,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- "ConcreteBalance2": &utils.Balance{
- ID: "ConcreteBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- "AbstractBalance1": &utils.Balance{
- ID: "AbstractBalance1",
- Weights: utils.DynamicWeights{
- {
- Weight: 5,
- },
- },
- Type: utils.MetaAbstract,
- Units: &utils.Decimal{decimal.New(120, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(int64(time.Second), 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{"TH_ID1"},
- }
- var reply string
- if err := acntSRPC.Call(utils.AccountSv1ActionSetBalance, &utils.ArgsActSetBalance{
- Tenant: "cgrates.org", AccountID: "1004",
- Diktats: []*utils.BalDiktat{
- {
- Path: "*account.ThresholdIDs",
- Value: "TH_ID1",
- },
- },
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Unexpected reply returned")
- }
- if err := acntSRPC.Call(utils.AccountSv1ActionSetBalance, &utils.ArgsActSetBalance{
- Tenant: "cgrates.org", AccountID: "1004",
- Diktats: []*utils.BalDiktat{
- {
- Path: "*balance.AbstractBalance1.Units",
- Value: "120",
- },
- },
- Reset: true,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Unexpected reply returned")
- }
- if err := acntSRPC.Call(utils.AccountSv1ActionSetBalance, &utils.ArgsActSetBalance{
- Tenant: "cgrates.org", AccountID: "1004",
- Diktats: []*utils.BalDiktat{
- {
- Path: "*balance.ConcreteBalance1.Weights",
- Value: "fltr1&fltr2;20;fltr1;30",
- },
- },
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Unexpected reply returned")
- }
-
- var result *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1004"}}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedSetBalance, result) {
- t.Errorf("Expected %+v\n, received %+v", utils.ToJSON(expectedSetBalance), utils.ToJSON(result))
- }
-}
-
-func testAccountSv1ActionRemoveBalance(t *testing.T) {
- var reply string
- if err := acntSRPC.Call(utils.AccountSv1ActionRemoveBalance, &utils.ArgsActRemoveBalances{
- Tenant: "cgrates.org", AccountID: "1004",
- BalanceIDs: []string{"AbstractBalance1"},
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Unexpected reply returned")
- }
-
- expectedSetBalance := &utils.Account{
- Tenant: "cgrates.org",
- ID: "1004",
- FilterIDs: []string{"*string:~*req.Account:1004"},
- Balances: map[string]*utils.Balance{
- "ConcreteBalance1": &utils.Balance{
- ID: "ConcreteBalance1",
- Weights: utils.DynamicWeights{
- {
- FilterIDs: []string{"fltr1", "fltr2"},
- Weight: 20,
- },
- {
- FilterIDs: []string{"fltr1"},
- Weight: 30,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- "ConcreteBalance2": &utils.Balance{
- ID: "ConcreteBalance2",
- Weights: utils.DynamicWeights{
- {
- Weight: 10,
- },
- },
- Type: utils.MetaConcrete,
- Units: &utils.Decimal{decimal.New(0, 0)},
- CostIncrements: []*utils.CostIncrement{
- &utils.CostIncrement{
- FilterIDs: []string{"*string:~*req.ToR:*data"},
- Increment: &utils.Decimal{decimal.New(1, 0)},
- FixedFee: &utils.Decimal{decimal.New(0, 0)},
- RecurrentFee: &utils.Decimal{decimal.New(1, 0)},
- },
- },
- },
- },
- ThresholdIDs: []string{"TH_ID1"},
- }
-
- var result *utils.Account
- if err := acntSRPC.Call(utils.APIerSv1GetAccount, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1004"}}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedSetBalance, result) {
- t.Errorf("Expected %+v\n, received %+v", utils.ToJSON(expectedSetBalance), utils.ToJSON(result))
- }
-}
-
-func testAccountSv1KillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/actions.go b/apier/v1/actions.go
deleted file mode 100644
index 0e407d01b..000000000
--- a/apier/v1/actions.go
+++ /dev/null
@@ -1,171 +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/birpc/context"
- "github.com/cgrates/cgrates/actions"
-
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetActionProfile returns an Action Profile
-func (apierSv1 *APIerSv1) GetActionProfile(arg *utils.TenantIDWithAPIOpts, reply *engine.ActionProfile) 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
- }
- ap, err := apierSv1.DataManager.GetActionProfile(tnt, arg.ID, true, true, utils.NonTransactional)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *ap
- return nil
-}
-
-// GetActionProfileIDs returns list of action profile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetActionProfileIDs(args *utils.PaginatorWithTenant, actPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.ActionProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *actPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-// GetActionProfileIDsCount sets in reply var the total number of ActionProfileIDs registered for a tenant
-// returns ErrNotFound in case of 0 ActionProfileIDs
-func (apierSv1 *APIerSv1) GetActionProfileIDsCount(args *utils.TenantWithAPIOpts, reply *int) (err error) {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- var keys []string
- prfx := utils.ActionProfilePrefix + tnt + utils.ConcatenatedKeySep
- if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), prfx); err != nil {
- return err
- }
- if len(keys) == 0 {
- return utils.ErrNotFound
- }
- *reply = len(keys)
- return
-}
-
-//SetActionProfile add/update a new Action Profile
-func (apierSv1 *APIerSv1) SetActionProfile(ap *engine.ActionProfileWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(ap.ActionProfile, []string{utils.ID, utils.Actions}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if ap.Tenant == utils.EmptyString {
- ap.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
-
- if err := apierSv1.DataManager.SetActionProfile(ap.ActionProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheActionProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheActionProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.CallCache(utils.IfaceAsString(ap.APIOpts[utils.CacheOpt]), ap.Tenant, utils.CacheActionProfiles,
- ap.TenantID(), &ap.FilterIDs, nil, ap.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// RemoveActionProfile remove a specific Action Profile
-func (apierSv1 *APIerSv1) RemoveActionProfile(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.RemoveActionProfile(tnt, arg.ID,
- utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheActionProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheActionProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheActionProfiles,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// NewActionSv1 initializes ActionSv1
-func NewActionSv1(aS *actions.ActionS) *ActionSv1 {
- return &ActionSv1{aS: aS}
-}
-
-// ActionSv1 exports RPC from RLs
-type ActionSv1 struct {
- aS *actions.ActionS
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (aSv1 *ActionSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(aSv1, serviceMethod, args, reply)
-}
-
-// Ping return pong if the service is active
-func (aSv1 *ActionSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// ScheduleActions will be called to schedule actions matching the arguments
-func (aSv1 *ActionSv1) ScheduleActions(args *utils.ArgActionSv1ScheduleActions, rpl *string) error {
- return aSv1.aS.V1ScheduleActions(args, rpl)
-}
-
-// ExecuteActions will be called to execute ASAP action profiles, ignoring their Schedule field
-func (aSv1 *ActionSv1) ExecuteActions(args *utils.ArgActionSv1ScheduleActions, rpl *string) error {
- return aSv1.aS.V1ExecuteActions(args, rpl)
-}
diff --git a/apier/v1/actions_it_test.go b/apier/v1/actions_it_test.go
deleted file mode 100644
index fd46dcc55..000000000
--- a/apier/v1/actions_it_test.go
+++ /dev/null
@@ -1,398 +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 (
- actPrfCfgPath string
- actPrfCfg *config.CGRConfig
- actSRPC *rpc.Client
- actPrf *engine.ActionProfileWithAPIOpts
- actPrfConfigDIR string //run tests for specific configuration
-
- sTestsActPrf = []func(t *testing.T){
- testActionSInitCfg,
- testActionSInitDataDb,
- testActionSResetStorDb,
- testActionSStartEngine,
- testActionSRPCConn,
- testActionSLoadFromFolder,
- testActionSGetActionProfile,
- testActionSPing,
- testActionSSettActionProfile,
- testActionSGetActionProfileIDs,
- testActionSGetActionProfileIDsCount,
- testActionSUpdateActionProfile,
- testActionSRemoveActionProfile,
- testActionSKillEngine,
- //cache test
- testActionSInitCfg,
- testActionSInitDataDb,
- testActionSResetStorDb,
- testActionSStartEngine,
- testActionSRPCConn,
- testActionSCacheTestGetNotFound,
- testActionSCacheTestSet,
- testActionSCacheTestGetNotFound,
- testActionSCacheReload,
- testActionSCacheTestGetFound,
- testActionSKillEngine,
- }
-)
-
-//Test start here
-func TestActionSIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- actPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- actPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- actPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsActPrf {
- t.Run(actPrfConfigDIR, stest)
- }
-}
-
-func testActionSInitCfg(t *testing.T) {
- var err error
- actPrfCfgPath = path.Join(*dataDir, "conf", "samples", actPrfConfigDIR)
- actPrfCfg, err = config.NewCGRConfigFromPath(actPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testActionSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(actPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testActionSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(actPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testActionSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(actPrfCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testActionSRPCConn(t *testing.T) {
- var err error
- actSRPC, err = newRPCClient(actPrfCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testActionSLoadFromFolder(t *testing.T) {
- var reply string
- acts := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutactions")}
- if err := actSRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, acts, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testActionSGetActionProfile(t *testing.T) {
- expected := &engine.ActionProfile{
- Tenant: "cgrates.org",
- ID: "ONE_TIME_ACT",
- FilterIDs: []string{},
- Weight: 10,
- Schedule: utils.MetaASAP,
- Targets: map[string]utils.StringSet{
- utils.MetaAccounts: {"1001": {}, "1002": {}},
- },
- Actions: []*engine.APAction{
- {
- ID: "TOPUP",
- Type: "*add_balance",
- Diktats: []*engine.APDiktat{{
- Path: "*balance.TestBalance.Units",
- Value: "10",
- }},
- },
- {
- ID: "SET_BALANCE_TEST_DATA",
- Type: "*set_balance",
- Diktats: []*engine.APDiktat{{
- Path: "*balance.TestDataBalance.Type",
- Value: "*data",
- }},
- },
- {
- ID: "TOPUP_TEST_DATA",
- Type: "*add_balance",
- Diktats: []*engine.APDiktat{{
- Path: "*balance.TestDataBalance.Units",
- Value: "1024",
- }},
- },
- {
- ID: "SET_BALANCE_TEST_VOICE",
- Type: "*set_balance",
- Diktats: []*engine.APDiktat{{
- Path: "*balance.TestVoiceBalance.Type",
- Value: "*voice",
- }},
- },
- {
- ID: "TOPUP_TEST_VOICE",
- Type: "*add_balance",
- Diktats: []*engine.APDiktat{{
- Path: "*balance.TestVoiceBalance.Units",
- Value: "15m15s",
- }},
- },
- {
- ID: "SET_BALANCE_TEST_FILTERS",
- Type: "*set_balance",
- Diktats: []*engine.APDiktat{{
- Path: "*balance.TestVoiceBalance.Filters",
- Value: "*string:~*req.CustomField:500",
- }},
- },
- {
- ID: "TOPUP_REM_VOICE",
- Type: "*rem_balance",
- Diktats: []*engine.APDiktat{{
- Path: "TestVoiceBalance2",
- }},
- },
- },
- }
- if *encoding == utils.MetaGOB {
- expected.FilterIDs = nil
- for i := range expected.Actions {
- expected.Actions[i].FilterIDs = nil
- }
- }
- var reply *engine.ActionProfile
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ONE_TIME_ACT"}}, &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(expected, reply) {
- t.Errorf("Expecting : %+v \n received: %+v", utils.ToJSON(expected), utils.ToJSON(reply))
- }
-}
-
-func testActionSPing(t *testing.T) {
- var resp string
- if err := actSRPC.Call(utils.ActionSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testActionSSettActionProfile(t *testing.T) {
- actPrf = &engine.ActionProfileWithAPIOpts{
- ActionProfile: &engine.ActionProfile{
- Tenant: "tenant_test",
- ID: "id_test",
- Actions: []*engine.APAction{
- {
- ID: "test_action_id",
- Diktats: []*engine.APDiktat{{}},
- },
- {
- ID: "test_action_id2",
- Diktats: []*engine.APDiktat{{}},
- },
- },
- },
- APIOpts: map[string]interface{}{},
- }
- var result string
- expErr := utils.ErrNotFound.Error()
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}}, &result); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
- var reply string
- if err := actSRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var reply2 *engine.ActionProfile
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(actPrf.ActionProfile, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", actPrf.ActionProfile, reply2)
- }
-}
-
-func testActionSGetActionProfileIDs(t *testing.T) {
-
- expected := []string{"id_test"}
- var result []string
- if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDs, utils.PaginatorWithTenant{Tenant: "tenant_test"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDs, utils.PaginatorWithTenant{
- Tenant: "tenant_test",
- Paginator: utils.Paginator{Limit: utils.IntPointer(1)},
- }, &result); err != nil {
- t.Error(err)
- } else if 1 != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-
-}
-
-func testActionSGetActionProfileIDsCount(t *testing.T) {
- var reply int
- if err := actSRPC.Call(utils.APIerSv1GetActionProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "tenant_test"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 1 {
- t.Errorf("Expecting: 1, received: %+v", reply)
- }
-}
-
-func testActionSUpdateActionProfile(t *testing.T) {
- var reply string
- actPrf.Weight = 2
- if err := actSRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var reply2 *engine.ActionProfile
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(actPrf.ActionProfile, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", actPrf.ActionProfile, reply2)
- }
-}
-
-func testActionSRemoveActionProfile(t *testing.T) {
- var reply string
- if err := actSRPC.Call(utils.APIerSv1RemoveActionProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var reply2 *engine.ActionProfile
- expErr := utils.ErrNotFound.Error()
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}}, &reply2); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
- if err := actSRPC.Call(utils.APIerSv1RemoveActionProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "tenant_test", ID: "id_test"}}, &reply2); err == nil || err.Error() != expErr {
- t.Errorf("Expected error: %v received: %v", expErr, err)
- }
-}
-
-func testActionSKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testActionSCacheTestGetNotFound(t *testing.T) {
- var reply *utils.TenantIDWithAPIOpts
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ACTION_CACHE"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-}
-
-func testActionSCacheTestGetFound(t *testing.T) {
- var reply *utils.TenantIDWithAPIOpts
- if err := actSRPC.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ACTION_CACHE"}, &reply); err != nil {
- t.Fatal(err)
- }
-}
-
-func testActionSCacheTestSet(t *testing.T) {
- actPrf = &engine.ActionProfileWithAPIOpts{
- ActionProfile: &engine.ActionProfile{
- Tenant: "cgrates.org",
- ID: "ACTION_CACHE",
- Actions: []*engine.APAction{
- {
- ID: "ACTION_CACHE",
- Diktats: []*engine.APDiktat{{}},
- },
- },
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- var reply string
- if err := actSRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-}
-
-func testActionSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.ActionProfileIDs: {"cgrates.org:ACTION_CACHE"},
- },
- }
- var reply string
- if err := actSRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/analyzer.go b/apier/v1/analyzer.go
deleted file mode 100755
index 5fdf807ec..000000000
--- a/apier/v1/analyzer.go
+++ /dev/null
@@ -1,52 +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 FITNEtS 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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/analyzers"
- "github.com/cgrates/cgrates/utils"
-)
-
-// NewAnalyzerSv1 initializes AnalyzerSv1
-func NewAnalyzerSv1(aS *analyzers.AnalyzerService) *AnalyzerSv1 {
- return &AnalyzerSv1{aS: aS}
-}
-
-// AnalyzerSv1 exports RPC from RLs
-type AnalyzerSv1 struct {
- aS *analyzers.AnalyzerService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (aSv1 *AnalyzerSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(aSv1, serviceMethod, args, reply)
-}
-
-// Ping return pong if the service is active
-func (aSv1 *AnalyzerSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// StringQuery returns a list of API that match the query
-func (aSv1 *AnalyzerSv1) StringQuery(search *analyzers.QueryArgs, reply *[]map[string]interface{}) error {
- return aSv1.aS.V1StringQuery(search, reply)
-}
diff --git a/apier/v1/api_interfaces.go b/apier/v1/api_interfaces.go
deleted file mode 100644
index 648e458a6..000000000
--- a/apier/v1/api_interfaces.go
+++ /dev/null
@@ -1,246 +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/config"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
- "github.com/cgrates/ltcache"
-)
-
-type ThresholdSv1Interface interface {
- GetThresholdIDs(tenant *utils.TenantWithAPIOpts, tIDs *[]string) error
- GetThresholdsForEvent(args *engine.ThresholdsArgsProcessEvent, reply *engine.Thresholds) error
- GetThreshold(tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error
- ProcessEvent(args *engine.ThresholdsArgsProcessEvent, tIDs *[]string) error
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type StatSv1Interface interface {
- GetQueueIDs(tenant *utils.TenantWithAPIOpts, qIDs *[]string) error
- ProcessEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error
- GetStatQueuesForEvent(args *engine.StatsArgsProcessEvent, reply *[]string) (err error)
- GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error)
- GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error)
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type ResourceSv1Interface interface {
- GetResourcesForEvent(args *utils.ArgRSv1ResourceUsage, reply *engine.Resources) error
- AuthorizeResources(args *utils.ArgRSv1ResourceUsage, reply *string) error
- AllocateResources(args *utils.ArgRSv1ResourceUsage, reply *string) error
- ReleaseResources(args *utils.ArgRSv1ResourceUsage, reply *string) error
- GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error
- GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type RouteSv1Interface interface {
- GetRoutes(args *engine.ArgsGetRoutes, reply *engine.SortedRoutesList) error
- GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) error
- GetRoutesList(args *engine.ArgsGetRoutes, reply *[]string) error
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type AttributeSv1Interface interface {
- GetAttributeForEvent(args *engine.AttrArgsProcessEvent, reply *engine.AttributeProfile) (err error)
- ProcessEvent(args *engine.AttrArgsProcessEvent, reply *engine.AttrSProcessEventReply) error
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type ChargerSv1Interface interface {
- Ping(ign *utils.CGREvent, reply *string) error
- GetChargersForEvent(cgrEv *utils.CGREvent, reply *engine.ChargerProfiles) error
- ProcessEvent(args *utils.CGREvent, reply *[]*engine.ChrgSProcessEventReply) error
-}
-
-type SessionSv1Interface interface {
- AuthorizeEvent(args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReply) error
- AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs, rply *sessions.V1AuthorizeReplyWithDigest) error
- InitiateSession(args *sessions.V1InitSessionArgs, rply *sessions.V1InitSessionReply) error
- InitiateSessionWithDigest(args *sessions.V1InitSessionArgs, rply *sessions.V1InitReplyWithDigest) error
- UpdateSession(args *sessions.V1UpdateSessionArgs, rply *sessions.V1UpdateSessionReply) error
- SyncSessions(args *utils.TenantWithAPIOpts, rply *string) error
- TerminateSession(args *sessions.V1TerminateSessionArgs, rply *string) error
- ProcessCDR(cgrEv *utils.CGREvent, rply *string) error
- ProcessMessage(args *sessions.V1ProcessMessageArgs, rply *sessions.V1ProcessMessageReply) error
- ProcessEvent(args *sessions.V1ProcessEventArgs, rply *sessions.V1ProcessEventReply) error
- GetActiveSessions(args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error
- GetActiveSessionsCount(args *utils.SessionFilter, rply *int) error
- ForceDisconnect(args *utils.SessionFilter, rply *string) error
- GetPassiveSessions(args *utils.SessionFilter, rply *[]*sessions.ExternalSession) error
- GetPassiveSessionsCount(args *utils.SessionFilter, rply *int) error
- Ping(ign *utils.CGREvent, reply *string) error
- ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithAPIOpts, rply *string) error
- SetPassiveSession(args *sessions.Session, reply *string) error
- ActivateSessions(args *utils.SessionIDsWithAPIOpts, reply *string) error
- DeactivateSessions(args *utils.SessionIDsWithAPIOpts, reply *string) error
-
- STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error
- STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error
-}
-
-type CacheSv1Interface interface {
- GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts, reply *[]string) error
- HasItem(args *utils.ArgsGetCacheItemWithAPIOpts, reply *bool) error
- GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts, reply *time.Time) error
- RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts, reply *string) error
- RemoveItems(args utils.AttrReloadCacheWithAPIOpts, reply *string) error
- Clear(cacheIDs *utils.AttrCacheIDsWithAPIOpts, reply *string) error
- GetCacheStats(cacheIDs *utils.AttrCacheIDsWithAPIOpts, rply *map[string]*ltcache.CacheStats) error
- PrecacheStatus(cacheIDs *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) error
- HasGroup(args *utils.ArgsGetGroupWithAPIOpts, rply *bool) error
- GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts, rply *[]string) error
- RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts, rply *string) error
- ReloadCache(attrs *utils.AttrReloadCacheWithAPIOpts, reply *string) error
- LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) error
- ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error)
- ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error)
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type GuardianSv1Interface interface {
- RemoteLock(attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error)
- RemoteUnlock(refID *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error)
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type CDRsV1Interface interface {
- ProcessCDR(cdr *engine.CDRWithAPIOpts, reply *string) error
- ProcessEvent(arg *engine.ArgV1ProcessEvent, reply *string) error
- ProcessExternalCDR(cdr *engine.ExternalCDRWithAPIOpts, reply *string) error
- RateCDRs(arg *engine.ArgRateCDRs, reply *string) error
- GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error
- GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type ServiceManagerV1Interface interface {
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type ConfigSv1Interface interface {
- GetConfig(section *config.SectionWithAPIOpts, reply *map[string]interface{}) (err error)
- ReloadConfig(section *config.ReloadArgs, reply *string) (err error)
- SetConfig(args *config.SetConfigArgs, reply *string) (err error)
- SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error)
- GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error)
-}
-
-type CoreSv1Interface interface {
- Status(arg *utils.TenantWithAPIOpts, reply *map[string]interface{}) error
- Ping(ign *utils.CGREvent, reply *string) error
- 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
- GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error
- GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error
- GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error
- GetFilter(tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error
- GetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error
- GetThresholdProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error
- GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error
- GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error
- GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error
- GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error
- GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error
- 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
- SetThreshold(th *engine.ThresholdWithAPIOpts, reply *string) error
- SetDestination(dst *engine.DestinationWithAPIOpts, reply *string) error
- SetReverseDestination(dst *engine.DestinationWithAPIOpts, reply *string) error
- SetStatQueue(ssq *engine.StatQueueWithAPIOpts, reply *string) error
- SetFilter(fltr *engine.FilterWithAPIOpts, reply *string) error
- SetStatQueueProfile(sq *engine.StatQueueProfileWithAPIOpts, reply *string) error
- SetTiming(tm *utils.TPTimingWithAPIOpts, reply *string) error
- SetResource(rs *engine.ResourceWithAPIOpts, reply *string) error
- SetResourceProfile(rs *engine.ResourceProfileWithAPIOpts, reply *string) error
- SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, reply *string) error
- 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
- SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) error
- RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) error
- SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) error
- RemoveDestination(id *utils.StringWithAPIOpts, reply *string) error
- RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveTiming(id *utils.StringWithAPIOpts, reply *string) error
- RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
- RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
- 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
- RemoveIndexes(args *utils.GetIndexesArg, reply *string) error
-
- GetAccount(tntID *utils.TenantIDWithAPIOpts, reply *utils.Account) error
- SetAccount(args *utils.AccountWithAPIOpts, reply *string) error
- RemoveAccount(args *utils.TenantIDWithAPIOpts, reply *string) error
-
- GetActionProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ActionProfile) error
- SetActionProfile(args *engine.ActionProfileWithAPIOpts, reply *string) error
- RemoveActionProfile(args *utils.TenantIDWithAPIOpts, reply *string) error
-}
-
-type ActionSv1Interface interface {
- ScheduleActions(args *utils.ArgActionSv1ScheduleActions, rpl *string) error
- ExecuteActions(args *utils.ArgActionSv1ScheduleActions, rpl *string) error
- Ping(ign *utils.CGREvent, reply *string) error
-}
-
-type AccountSv1Interface interface {
- Ping(ign *utils.CGREvent, reply *string) error
- AccountsForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.Account) error
- MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error
- DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error
- ActionSetBalance(args *utils.ArgsActSetBalance, eEc *string) (err error)
- MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error)
- DebitConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) (err error)
- ActionRemoveBalance(args *utils.ArgsActRemoveBalances, eEc *string) (err error)
-}
diff --git a/apier/v1/api_interfaces_test.go b/apier/v1/api_interfaces_test.go
deleted file mode 100644
index 3e1cbadab..000000000
--- a/apier/v1/api_interfaces_test.go
+++ /dev/null
@@ -1,113 +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 (
- "testing"
-)
-
-func TestThresholdSv1Interface(t *testing.T) {
- _ = ThresholdSv1Interface(NewDispatcherThresholdSv1(nil))
- _ = ThresholdSv1Interface(NewThresholdSv1(nil))
-}
-
-func TestStatSv1Interface(t *testing.T) {
- _ = StatSv1Interface(NewDispatcherStatSv1(nil))
- _ = StatSv1Interface(NewStatSv1(nil))
-}
-
-func TestResourceSv1Interface(t *testing.T) {
- _ = ResourceSv1Interface(NewDispatcherResourceSv1(nil))
- _ = ResourceSv1Interface(NewResourceSv1(nil))
-}
-
-func TestRouteSv1Interface(t *testing.T) {
- _ = RouteSv1Interface(NewDispatcherRouteSv1(nil))
- _ = RouteSv1Interface(NewRouteSv1(nil))
-}
-
-func TestAttributeSv1Interface(t *testing.T) {
- _ = AttributeSv1Interface(NewDispatcherAttributeSv1(nil))
- _ = AttributeSv1Interface(NewAttributeSv1(nil))
-}
-
-func TestChargerSv1Interface(t *testing.T) {
- _ = ChargerSv1Interface(NewDispatcherChargerSv1(nil))
- _ = ChargerSv1Interface(NewChargerSv1(nil))
-}
-
-func TestSessionSv1Interface(t *testing.T) {
- _ = SessionSv1Interface(NewDispatcherSessionSv1(nil))
- _ = SessionSv1Interface(NewSessionSv1(nil, nil))
-}
-
-func TestRateProfileInterface(t *testing.T) {
- _ = RateProfileSv1Interface(NewDispatcherRateSv1(nil))
- _ = RateProfileSv1Interface(NewRateSv1(nil))
-}
-
-func TestCacheSv1Interface(t *testing.T) {
- _ = CacheSv1Interface(NewDispatcherCacheSv1(nil))
- _ = CacheSv1Interface(NewCacheSv1(nil))
-}
-
-func TestGuardianSv1Interface(t *testing.T) {
- _ = GuardianSv1Interface(NewDispatcherGuardianSv1(nil))
- _ = GuardianSv1Interface(NewGuardianSv1())
-}
-
-func TestCDRsV1Interface(t *testing.T) {
- _ = CDRsV1Interface(NewDispatcherSCDRsV1(nil))
- _ = CDRsV1Interface(NewCDRsV1(nil))
-}
-
-func TestServiceManagerV1Interface(t *testing.T) {
- _ = ServiceManagerV1Interface(NewDispatcherSServiceManagerV1(nil))
- _ = ServiceManagerV1Interface(NewServiceManagerV1(nil))
-}
-
-func TestConfigSv1Interface(t *testing.T) {
- _ = ConfigSv1Interface(NewDispatcherConfigSv1(nil))
- _ = ConfigSv1Interface(NewConfigSv1(nil))
-}
-
-func TestCoreSv1Interface(t *testing.T) {
- _ = CoreSv1Interface(NewDispatcherCoreSv1(nil))
- _ = CoreSv1Interface(NewCoreSv1(nil))
-}
-
-func TestReplicatorSv1Interface(t *testing.T) {
- _ = ReplicatorSv1Interface(NewDispatcherReplicatorSv1(nil))
- _ = ReplicatorSv1Interface(NewReplicatorSv1(nil, nil))
-}
-
-func TestRateSv1Interface(t *testing.T) {
- _ = RateSv1Interface(NewDispatcherRateSv1(nil))
- _ = RateSv1Interface(NewRateSv1(nil))
-}
-
-func TestAccountSv1Interface(t *testing.T) {
- _ = AccountSv1Interface(NewDispatcherAccountSv1(nil))
- _ = AccountSv1Interface(NewAccountSv1(nil))
-}
-
-func TestActionSv1Interface(t *testing.T) {
- _ = ActionSv1Interface(NewDispatcherActionSv1(nil))
- _ = ActionSv1Interface(NewActionSv1(nil))
-}
diff --git a/apier/v1/apier.go b/apier/v1/apier.go
deleted file mode 100644
index ee78c904f..000000000
--- a/apier/v1/apier.go
+++ /dev/null
@@ -1,1173 +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 (
- "encoding/csv"
- "fmt"
- "os"
- "path"
- "strconv"
- "strings"
-
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-type APIerSv1 struct {
- StorDb engine.LoadStorage // we should consider keeping only one of StorDB type
- CdrDb engine.CdrStorage
- DataManager *engine.DataManager
- Config *config.CGRConfig
- FilterS *engine.FilterS //Used for CDR Exporter
- ConnMgr *engine.ConnManager
-
- StorDBChan chan engine.StorDB
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (apierSv1 *APIerSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(apierSv1, serviceMethod, args, reply)
-}
-
-func (apierSv1 *APIerSv1) GetDestination(dstId *string, reply *engine.Destination) error {
- if dst, err := apierSv1.DataManager.GetDestination(*dstId, true, true, utils.NonTransactional); err != nil {
- return utils.ErrNotFound
- } else {
- *reply = *dst
- }
- return nil
-}
-
-type AttrRemoveDestination struct {
- DestinationIDs []string
- Prefixes []string
-}
-
-func (apierSv1 *APIerSv1) RemoveDestination(attr *AttrRemoveDestination, reply *string) (err error) {
- for _, dstID := range attr.DestinationIDs {
- var oldDst *engine.Destination
- if oldDst, err = apierSv1.DataManager.GetDestination(dstID, true, true,
- utils.NonTransactional); err != nil && err != utils.ErrNotFound {
- return
- }
- if len(attr.Prefixes) != 0 {
- newDst := &engine.Destination{
- ID: dstID,
- Prefixes: make([]string, 0, len(oldDst.Prefixes)),
- }
- toRemove := utils.NewStringSet(attr.Prefixes)
- for _, prfx := range oldDst.Prefixes {
- if !toRemove.Has(prfx) {
- newDst.Prefixes = append(newDst.Prefixes, prfx)
- }
- }
- if len(newDst.Prefixes) != 0 { // only update the current destination
- if err = apierSv1.DataManager.SetDestination(newDst, utils.NonTransactional); err != nil {
- return
- }
- if err = apierSv1.DataManager.UpdateReverseDestination(oldDst, newDst, utils.NonTransactional); err != nil {
- return
- }
- if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns,
- utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{utils.ReverseDestinationIDs: oldDst.Prefixes,
- utils.DestinationIDs: {dstID}},
- }, reply); err != nil {
- return
- }
- continue
- }
- }
- if err = apierSv1.DataManager.RemoveDestination(dstID, utils.NonTransactional); err != nil {
- return
- }
- if err = apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns,
- utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{utils.ReverseDestinationIDs: oldDst.Prefixes,
- utils.DestinationIDs: {dstID}},
- }, reply); err != nil {
- return
- }
- }
- *reply = utils.OK
- return
-}
-
-// GetReverseDestination retrieves revese destination list for a prefix
-func (apierSv1 *APIerSv1) GetReverseDestination(prefix *string, reply *[]string) (err error) {
- if *prefix == utils.EmptyString {
- return utils.NewErrMandatoryIeMissing("prefix")
- }
- var revLst []string
- if revLst, err = apierSv1.DataManager.GetReverseDestination(*prefix, true, true, utils.NonTransactional); err != nil {
- return
- }
- *reply = revLst
- return
-}
-
-// ComputeReverseDestinations will rebuild complete reverse destinations data
-func (apierSv1 *APIerSv1) ComputeReverseDestinations(ignr *string, reply *string) (err error) {
- if err = apierSv1.DataManager.RebuildReverseForPrefix(utils.ReverseDestinationPrefix); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-func (apierSv1 *APIerSv1) SetDestination(attrs *utils.AttrSetDestination, reply *string) (err error) {
- if missing := utils.MissingStructFields(attrs, []string{"Id", "Prefixes"}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- dest := &engine.Destination{ID: attrs.Id, Prefixes: attrs.Prefixes}
- var oldDest *engine.Destination
- if oldDest, err = apierSv1.DataManager.GetDestination(attrs.Id, true, true, utils.NonTransactional); err != nil {
- if err != utils.ErrNotFound {
- return utils.NewErrServerError(err)
- }
- } else if !attrs.Overwrite {
- return utils.ErrExists
- }
- if err := apierSv1.DataManager.SetDestination(dest, utils.NonTransactional); err != nil {
- return utils.NewErrServerError(err)
- }
- if err = apierSv1.DataManager.UpdateReverseDestination(oldDest, dest, utils.NonTransactional); err != nil {
- return
- }
- if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns,
- utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{utils.ReverseDestinationIDs: dest.Prefixes,
- utils.DestinationIDs: {attrs.Id}},
- }, reply); err != nil {
- return err
- }
- *reply = utils.OK
- return nil
-}
-
-type AttrLoadDestination struct {
- TPid string
- ID string
-}
-
-// Load destinations from storDb into dataDb.
-func (apierSv1 *APIerSv1) LoadDestination(attrs *AttrLoadDestination, reply *string) error {
- if len(attrs.TPid) == 0 {
- return utils.NewErrMandatoryIeMissing("TPid")
- }
- dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
- attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone, apierSv1.Config.ApierCfg().CachesConns,
- apierSv1.Config.ApierCfg().ActionSConns,
- apierSv1.Config.DataDbCfg().Type == utils.Internal)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if loaded, err := dbReader.LoadDestinationsFiltered(attrs.ID); err != nil {
- return utils.NewErrServerError(err)
- } else if !loaded {
- return utils.ErrNotFound
- }
- if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns,
- utils.CacheSv1ReloadCache, utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{utils.DestinationIDs: {attrs.ID}},
- }, reply); err != nil {
- return err
- }
- *reply = utils.OK
- return nil
-}
-
-type AttrLoadTpFromStorDb struct {
- TPid string
- DryRun bool // Only simulate, no write
- APIOpts map[string]interface{}
- Caching *string // Caching strategy
-}
-
-// Loads complete data in a TP from storDb
-func (apierSv1 *APIerSv1) LoadTariffPlanFromStorDb(attrs *AttrLoadTpFromStorDb, reply *string) error {
- if len(attrs.TPid) == 0 {
- return utils.NewErrMandatoryIeMissing("TPid")
- }
- dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
- attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
- apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionSConns,
- apierSv1.Config.DataDbCfg().Type == utils.Internal)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if err := dbReader.LoadAll(); err != nil {
- return utils.NewErrServerError(err)
- }
- if attrs.DryRun {
- *reply = utils.OK
- return nil // Mission complete, no errors
- }
- if err := dbReader.WriteToDatabase(false, false); err != nil {
- return utils.NewErrServerError(err)
- }
- //verify If Caching is present in arguments
- caching := config.CgrConfig().GeneralCfg().DefaultCaching
- if attrs.Caching != nil {
- caching = *attrs.Caching
- }
- // reload cache
- utils.Logger.Info("APIerSv1.LoadTariffPlanFromStorDb, reloading cache.")
- if err := dbReader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
- return utils.NewErrServerError(err)
- }
- if len(apierSv1.Config.ApierCfg().ActionSConns) != 0 {
- utils.Logger.Info("APIerSv1.LoadTariffPlanFromStorDb, reloading scheduler.")
- if err := dbReader.ReloadScheduler(true); err != nil {
- return utils.NewErrServerError(err)
- }
- }
- // release the reader with it's structures
- dbReader.Init()
- *reply = utils.OK
- return nil
-}
-
-func (apierSv1 *APIerSv1) ImportTariffPlanFromFolder(attrs *utils.AttrImportTPFromFolder, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{"TPid", "FolderPath"}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if len(attrs.CsvSeparator) == 0 {
- attrs.CsvSeparator = ","
- }
- if fi, err := os.Stat(attrs.FolderPath); err != nil {
- if strings.HasSuffix(err.Error(), "no such file or directory") {
- return utils.ErrInvalidPath
- }
- return utils.NewErrServerError(err)
- } else if !fi.IsDir() {
- return utils.ErrInvalidPath
- }
- csvImporter := engine.TPCSVImporter{
- TPid: attrs.TPid,
- StorDB: apierSv1.StorDb,
- DirPath: attrs.FolderPath,
- Sep: rune(attrs.CsvSeparator[0]),
- Verbose: false,
- ImportID: attrs.RunId,
- }
- if err := csvImporter.Run(); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// Deprecated attrs
-type V1AttrSetActions struct {
- ActionsId string // Actions id
- Overwrite bool // If previously defined, will be overwritten
- Actions []*V1TPAction // Set of actions this Actions profile will perform
-}
-type V1TPActions struct {
- TPid string // Tariff plan id
- ActionsId string // Actions id
- Actions []*V1TPAction // Set of actions this Actions profile will perform
-}
-
-type V1TPAction struct {
- Identifier string // Identifier mapped in the code
- BalanceId string // Balance identification string (account scope)
- BalanceUuid string // Balance identification string (global scope)
- BalanceType string // Type of balance the action will operate on
- Units float64 // Number of units to add/deduct
- ExpiryTime string // Time when the units will expire
- Filter string // The condition on balances that is checked before the action
- TimingTags string // Timing when balance is active
- DestinationIds string // Destination profile id
- RatingSubject string // Reference a rate subject defined in RatingProfiles
- Categories string // category filter for balances
- SharedGroups string // Reference to a shared group
- BalanceWeight *float64 // Balance weight
- ExtraParameters string
- BalanceBlocker string
- BalanceDisabled string
- Weight float64 // Action's weight
-}
-
-func verifyFormat(tStr string) bool {
- if tStr == utils.EmptyString ||
- tStr == utils.MetaASAP {
- return true
- }
-
- if len(tStr) > 8 { // hh:mm:ss
- return false
- }
- if a := strings.Split(tStr, utils.InInFieldSep); len(a) != 3 {
- return false
- } else {
- if _, err := strconv.Atoi(a[0]); err != nil {
- return false
- } else if _, err := strconv.Atoi(a[1]); err != nil {
- return false
- } else if _, err := strconv.Atoi(a[2]); err != nil {
- return false
- }
- }
- return true
-}
-
-func (apierSv1 *APIerSv1) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *string) error {
- // verify if FolderPath is present
- if len(attrs.FolderPath) == 0 {
- return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath")
- }
- // check if exists or is valid
- if fi, err := os.Stat(attrs.FolderPath); err != nil {
- if strings.HasSuffix(err.Error(), "no such file or directory") {
- return utils.ErrInvalidPath
- }
- return utils.NewErrServerError(err)
- } else if !fi.IsDir() {
- return utils.ErrInvalidPath
- }
-
- // create the TpReader
- loader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(),
- engine.NewFileCSVStorage(utils.CSVSep, attrs.FolderPath),
- "", apierSv1.Config.GeneralCfg().DefaultTimezone,
- apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionSConns,
- apierSv1.Config.DataDbCfg().Type == utils.Internal)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- //Load the data
- if err := loader.LoadAll(); err != nil {
- return utils.NewErrServerError(err)
- }
- if attrs.DryRun {
- *reply = utils.OK
- return nil // Mission complete, no errors
- }
-
- // write data intro Database
- if err := loader.WriteToDatabase(false, false); err != nil {
- return utils.NewErrServerError(err)
- }
- //verify If Caching is present in arguments
- caching := config.CgrConfig().GeneralCfg().DefaultCaching
- if attrs.Caching != nil {
- caching = *attrs.Caching
- }
- // reload cache
- utils.Logger.Info("APIerSv1.LoadTariffPlanFromFolder, reloading cache.")
- if err := loader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
- return utils.NewErrServerError(err)
- }
- if len(apierSv1.Config.ApierCfg().ActionSConns) != 0 {
- utils.Logger.Info("APIerSv1.LoadTariffPlanFromFolder, reloading scheduler.")
- if err := loader.ReloadScheduler(true); err != nil {
- return utils.NewErrServerError(err)
- }
- }
- // release the reader with it's structures
- loader.Init()
- *reply = utils.OK
- return nil
-}
-
-// RemoveTPFromFolder will load the tarrifplan from folder into TpReader object
-// and will delete if from database
-func (apierSv1 *APIerSv1) RemoveTPFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *string) error {
- // verify if FolderPath is present
- if len(attrs.FolderPath) == 0 {
- return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath")
- }
- // check if exists or is valid
- if fi, err := os.Stat(attrs.FolderPath); err != nil {
- if strings.HasSuffix(err.Error(), "no such file or directory") {
- return utils.ErrInvalidPath
- }
- return utils.NewErrServerError(err)
- } else if !fi.IsDir() {
- return utils.ErrInvalidPath
- }
-
- // create the TpReader
- loader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(),
- engine.NewFileCSVStorage(utils.CSVSep, attrs.FolderPath), "", apierSv1.Config.GeneralCfg().DefaultTimezone,
- apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionSConns,
- apierSv1.Config.DataDbCfg().Type == utils.Internal)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- //Load the data
- if err := loader.LoadAll(); err != nil {
- return utils.NewErrServerError(err)
- }
- if attrs.DryRun {
- *reply = utils.OK
- return nil // Mission complete, no errors
- }
-
- // remove data from Database
- if err := loader.RemoveFromDatabase(false, false); err != nil {
- return utils.NewErrServerError(err)
- }
- //verify If Caching is present in arguments
- caching := config.CgrConfig().GeneralCfg().DefaultCaching
- if attrs.Caching != nil {
- caching = *attrs.Caching
- }
- // reload cache
- utils.Logger.Info("APIerSv1.RemoveTPFromFolder, reloading cache.")
- if err := loader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
- return utils.NewErrServerError(err)
- }
- if len(apierSv1.Config.ApierCfg().ActionSConns) != 0 {
- utils.Logger.Info("APIerSv1.RemoveTPFromFolder, reloading scheduler.")
- if err := loader.ReloadScheduler(true); err != nil {
- return utils.NewErrServerError(err)
- }
- }
- // release the reader with it's structures
- loader.Init()
- *reply = utils.OK
- return nil
-}
-
-// RemoveTPFromStorDB will load the tarrifplan from StorDB into TpReader object
-// and will delete if from database
-func (apierSv1 *APIerSv1) RemoveTPFromStorDB(attrs *AttrLoadTpFromStorDb, reply *string) error {
- if len(attrs.TPid) == 0 {
- return utils.NewErrMandatoryIeMissing("TPid")
- }
- dbReader, err := engine.NewTpReader(apierSv1.DataManager.DataDB(), apierSv1.StorDb,
- attrs.TPid, apierSv1.Config.GeneralCfg().DefaultTimezone,
- apierSv1.Config.ApierCfg().CachesConns, apierSv1.Config.ApierCfg().ActionSConns,
- apierSv1.Config.DataDbCfg().Type == utils.Internal)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if err := dbReader.LoadAll(); err != nil {
- return utils.NewErrServerError(err)
- }
- if attrs.DryRun {
- *reply = utils.OK
- return nil // Mission complete, no errors
- }
- // remove data from Database
- if err := dbReader.RemoveFromDatabase(false, false); err != nil {
- return utils.NewErrServerError(err)
- }
- //verify If Caching is present in arguments
- caching := config.CgrConfig().GeneralCfg().DefaultCaching
- if attrs.Caching != nil {
- caching = *attrs.Caching
- }
- // reload cache
- utils.Logger.Info("APIerSv1.RemoveTPFromStorDB, reloading cache.")
- if err := dbReader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
- return utils.NewErrServerError(err)
- }
- if len(apierSv1.Config.ApierCfg().ActionSConns) != 0 {
- utils.Logger.Info("APIerSv1.RemoveTPFromStorDB, reloading scheduler.")
- if err := dbReader.ReloadScheduler(true); err != nil {
- return utils.NewErrServerError(err)
- }
- }
- // release the reader with it's structures
- dbReader.Init()
- *reply = utils.OK
- return nil
-}
-
-type AttrRemoveRatingProfile struct {
- Tenant string
- Category string
- Subject string
-}
-
-func (arrp *AttrRemoveRatingProfile) GetId() (result string) {
- result = utils.MetaOut + utils.ConcatenatedKeySep
- if arrp.Tenant != "" && arrp.Tenant != utils.MetaAny {
- result += arrp.Tenant + utils.ConcatenatedKeySep
- } else {
- return
- }
-
- if arrp.Category != "" && arrp.Category != utils.MetaAny {
- result += arrp.Category + utils.ConcatenatedKeySep
- } else {
- return
- }
- if arrp.Subject != "" && arrp.Subject != utils.MetaAny {
- result += arrp.Subject
- }
- return
-}
-
-func (apierSv1 *APIerSv1) GetLoadHistory(attrs *utils.Paginator, reply *[]*utils.LoadInstance) error {
- nrItems := -1
- offset := 0
- if attrs.Offset != nil { // For offset we need full data
- offset = *attrs.Offset
- } else if attrs.Limit != nil {
- nrItems = *attrs.Limit
- }
- loadHist, err := apierSv1.DataManager.DataDB().GetLoadHistory(nrItems, true, utils.NonTransactional)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if attrs.Offset != nil && attrs.Limit != nil { // Limit back to original
- nrItems = *attrs.Limit
- }
- if len(loadHist) == 0 || len(loadHist) <= offset || nrItems == 0 {
- return utils.ErrNotFound
- }
- if offset != 0 {
- nrItems = offset + nrItems
- }
- if nrItems == -1 || nrItems > len(loadHist) { // So we can use it in indexing bellow
- nrItems = len(loadHist)
- }
- *reply = loadHist[offset:nrItems]
- return nil
-}
-
-type ArgsReplyFailedPosts struct {
- FailedRequestsInDir *string // if defined it will be our source of requests to be replayed
- FailedRequestsOutDir *string // if defined it will become our destination for files failing to be replayed, *none to be discarded
- Modules []string // list of modules for which replay the requests, nil for all
-}
-
-// ReplayFailedPosts will repost failed requests found in the FailedRequestsInDir
-func (apierSv1 *APIerSv1) ReplayFailedPosts(args *ArgsReplyFailedPosts, reply *string) (err error) {
- failedReqsInDir := apierSv1.Config.GeneralCfg().FailedPostsDir
- if args.FailedRequestsInDir != nil && *args.FailedRequestsInDir != "" {
- failedReqsInDir = *args.FailedRequestsInDir
- }
- failedReqsOutDir := failedReqsInDir
- if args.FailedRequestsOutDir != nil && *args.FailedRequestsOutDir != "" {
- failedReqsOutDir = *args.FailedRequestsOutDir
- }
- filesInDir, _ := os.ReadDir(failedReqsInDir)
- if len(filesInDir) == 0 {
- return utils.ErrNotFound
- }
- for _, file := range filesInDir { // First file in directory is the one we need, harder to find it's name out of config
- if len(args.Modules) != 0 {
- var allowedModule bool
- for _, mod := range args.Modules {
- if strings.HasPrefix(file.Name(), mod) {
- allowedModule = true
- break
- }
- }
- if !allowedModule {
- continue // this file is not to be processed due to Modules ACL
- }
- }
- filePath := path.Join(failedReqsInDir, file.Name())
- expEv, err := engine.NewExportEventsFromFile(filePath)
- if err != nil {
- return utils.NewErrServerError(err)
- }
-
- failoverPath := utils.MetaNone
- if failedReqsOutDir != utils.MetaNone {
- failoverPath = path.Join(failedReqsOutDir, file.Name())
- }
-
- failedPosts, err := expEv.ReplayFailedPosts(apierSv1.Config.GeneralCfg().PosterAttempts)
- if err != nil && failedReqsOutDir != utils.MetaNone { // Got error from HTTPPoster could be that content was not written, we need to write it ourselves
- if err = failedPosts.WriteToFile(failoverPath); err != nil {
- return utils.NewErrServerError(err)
- }
- }
-
- }
- *reply = utils.OK
- return nil
-}
-
-func (apierSv1 *APIerSv1) GetLoadIDs(args *string, reply *map[string]int64) (err error) {
- var loadIDs map[string]int64
- if loadIDs, err = apierSv1.DataManager.GetItemLoadIDs(*args, false); err != nil {
- return
- }
- *reply = loadIDs
- return
-}
-
-type LoadTimeArgs struct {
- Timezone string
- Item string
-}
-
-func (apierSv1 *APIerSv1) GetLoadTimes(args *LoadTimeArgs, reply *map[string]string) (err error) {
- if loadIDs, err := apierSv1.DataManager.GetItemLoadIDs(args.Item, false); err != nil {
- return err
- } else {
- provMp := make(map[string]string)
- for key, val := range loadIDs {
- timeVal, err := utils.ParseTimeDetectLayout(strconv.FormatInt(val, 10), args.Timezone)
- if err != nil {
- return err
- }
- provMp[key] = timeVal.String()
- }
- *reply = provMp
- }
- return
-}
-
-// ListenAndServe listen for storbd reload
-func (apierSv1 *APIerSv1) ListenAndServe(stopChan chan struct{}) {
- utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ApierS))
- for {
- select {
- case <-stopChan:
- return
- case stordb, ok := <-apierSv1.StorDBChan:
- if !ok { // the chanel was closed by the shutdown of stordbService
- return
- }
- apierSv1.CdrDb = stordb
- apierSv1.StorDb = stordb
- }
- }
-}
-
-// Ping return pong if the service is active
-func (apierSv1 *APIerSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-//ExportToFolder export specific items (or all items if items is empty) from DataDB back to CSV
-func (apierSv1 *APIerSv1) ExportToFolder(arg *utils.ArgExportToFolder, reply *string) error {
- // if items is empty we need to export all items
- 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.MetaAccounts}
- }
- if _, err := os.Stat(arg.Path); os.IsNotExist(err) {
- os.Mkdir(arg.Path, os.ModeDir)
- }
- for _, item := range arg.Items {
- switch item {
- case utils.MetaAttributes:
- prfx := utils.AttributeProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.AttributesCsv))
- 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.AttributeMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- attPrf, err := apierSv1.DataManager.GetAttributeProfile(context.TODO(), tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPAttribute(
- engine.AttributeProfileToAPI(attPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaChargers:
- prfx := utils.ChargerProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.ChargersCsv))
- 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.ChargerMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- chrPrf, err := apierSv1.DataManager.GetChargerProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPCharger(
- engine.ChargerProfileToAPI(chrPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaDispatchers:
- prfx := utils.DispatcherProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.DispatcherProfilesCsv))
- 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.DispatcherProfileMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- dpsPrf, err := apierSv1.DataManager.GetDispatcherProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPDispatcherProfile(
- engine.DispatcherProfileToAPI(dpsPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaDispatcherHosts:
- prfx := utils.DispatcherHostPrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.DispatcherHostsCsv))
- 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.DispatcherHostMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- dpsPrf, err := apierSv1.DataManager.GetDispatcherHost(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- if record, err := engine.CsvDump(engine.APItoModelTPDispatcherHost(
- engine.DispatcherHostToAPI(dpsPrf))); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- csvWriter.Flush()
- case utils.MetaFilters:
- prfx := utils.FilterPrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.FiltersCsv))
- 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.FilterMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- fltr, err := apierSv1.DataManager.GetFilter(context.TODO(), tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPFilter(
- engine.FilterToTPFilter(fltr)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaResources:
- prfx := utils.ResourceProfilesPrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.ResourcesCsv))
- 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.ResourceMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- resPrf, err := apierSv1.DataManager.GetResourceProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelResource(
- engine.ResourceProfileToAPI(resPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaStats:
- prfx := utils.StatQueueProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.StatsCsv))
- 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.StatMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- stsPrf, err := apierSv1.DataManager.GetStatQueueProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelStats(
- engine.StatQueueProfileToAPI(stsPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaRoutes:
- prfx := utils.RouteProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.RoutesCsv))
- 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.RouteMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- spp, err := apierSv1.DataManager.GetRouteProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPRoutes(
- engine.RouteProfileToAPI(spp)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaThresholds:
- prfx := utils.ThresholdProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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.ThresholdsCsv))
- 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.ThresholdMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- thPrf, err := apierSv1.DataManager.GetThresholdProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPThreshold(
- engine.ThresholdProfileToAPI(thPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- case utils.MetaRateProfiles:
- prfx := utils.RateProfilePrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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(context.TODO(), 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.ActionProfilesCsv))
- 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.ActionProfileMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- rPrf, err := apierSv1.DataManager.GetActionProfile(tntID[0], tntID[1],
- true, false, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPActionProfile(engine.ActionProfileToAPI(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.MetaAccounts:
- prfx := utils.AccountPrefix
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), prfx)
- if err != nil {
- return err
- }
- if len(keys) == 0 {
- continue
- }
- f, err := os.Create(path.Join(arg.Path, utils.AccountsCsv))
- 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.AccountMdls{}.CSVHeader()); err != nil {
- return err
- }
- for _, key := range keys {
- tntID := strings.SplitN(key[len(prfx):], utils.InInFieldSep, 2)
- accPrf, err := apierSv1.DataManager.GetAccount(tntID[0], tntID[1])
- if err != nil {
- return err
- }
- for _, model := range engine.APItoModelTPAccount(engine.AccountToAPI(accPrf)) {
- if record, err := engine.CsvDump(model); err != nil {
- return err
- } else if err := csvWriter.Write(record); err != nil {
- return err
- }
- }
- }
- csvWriter.Flush()
- }
- }
- *reply = utils.OK
- return nil
-}
-
-func (apierSv1 *APIerSv1) ExportCDRs(args *utils.ArgExportCDRs, reply *map[string]interface{}) (err error) {
- if len(apierSv1.Config.ApierCfg().EEsConns) == 0 {
- return utils.NewErrNotConnected(utils.EEs)
- }
- cdrsFltr, err := args.RPCCDRsFilter.AsCDRsFilter(apierSv1.Config.GeneralCfg().DefaultTimezone)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- cdrs, _, err := apierSv1.CdrDb.GetCDRs(cdrsFltr, false)
- if err != nil {
- return err
- } else if len(cdrs) == 0 {
- return utils.ErrNotFound
- }
- withErros := false
- var rplyCdr map[string]map[string]interface{}
- for _, cdr := range cdrs {
- argCdr := &utils.CGREventWithEeIDs{
- EeIDs: args.ExporterIDs,
- CGREvent: cdr.AsCGREvent(),
- }
- if args.Verbose {
- argCdr.CGREvent.APIOpts[utils.OptsEEsVerbose] = struct{}{}
- }
- if err := apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().EEsConns, utils.EeSv1ProcessEvent,
- argCdr, &rplyCdr); err != nil {
- utils.Logger.Warning(fmt.Sprintf("<%s> error: <%s> processing event: <%s> with <%s>",
- utils.ApierS, err.Error(), utils.ToJSON(cdr.AsCGREvent()), utils.EventExporterS))
- withErros = true
- }
- }
- if withErros {
- return utils.ErrPartiallyExecuted
- }
- // we consider only the last reply because it should have the metrics updated
- for exporterID, metrics := range rplyCdr {
- (*reply)[exporterID] = metrics
- }
- return
-}
diff --git a/apier/v1/apier2_it_test.go b/apier/v1/apier2_it_test.go
deleted file mode 100644
index bd8cca451..000000000
--- a/apier/v1/apier2_it_test.go
+++ /dev/null
@@ -1,622 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- apierCfgPath string
- apierCfg *config.CGRConfig
- apierRPC *rpc.Client
- APIerSv2ConfigDIR string //run tests for specific configuration
-
- sTestsAPIer = []func(t *testing.T){
- testAPIerInitCfg,
- testAPIerInitDataDb,
- testAPIerResetStorDb,
- testAPIerStartEngine,
- testAPIerRPCConn,
- testAPIerLoadFromFolder,
- testAPIerVerifyAttributesAfterLoad,
- testAPIerRemoveTPFromFolder,
- testAPIerAfterDelete,
- testAPIerVerifyAttributesAfterDelete,
- testAPIerLoadFromFolder,
- testAPIerGetRatingPlanCost,
- testAPIerGetRatingPlanCost2,
- testAPIerGetRatingPlanCost3,
- testAPIerGetActionPlanIDs,
- testAPIerGetRatingPlanIDs,
- testAPIerSetActionPlanDfltTime,
- testAPIerLoadRatingPlan,
- testAPIerLoadRatingPlan2,
- testAPIerLoadRatingProfile,
- testAPIerLoadFromFolderAccountAction,
- testAPIerKillEngine,
- }
-)
-
-//Test start here
-func TestApierIT2(t *testing.T) {
- // no need for a new config with *gob transport in this case
- switch *dbType {
- case utils.MetaInternal:
- APIerSv2ConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- APIerSv2ConfigDIR = "tutmysql"
- case utils.MetaMongo:
- APIerSv2ConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsAPIer {
- t.Run(APIerSv2ConfigDIR, stest)
- }
-}
-
-func testAPIerInitCfg(t *testing.T) {
- var err error
- apierCfgPath = path.Join(*dataDir, "conf", "samples", APIerSv2ConfigDIR)
- apierCfg, err = config.NewCGRConfigFromPath(apierCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testAPIerInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(apierCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testAPIerResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(apierCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testAPIerStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(apierCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testAPIerRPCConn(t *testing.T) {
- var err error
- apierRPC, err = newRPCClient(apierCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testAPIerLoadFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
- if err := apierRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testAPIerVerifyAttributesAfterLoad(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer("simpleauth"),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAPIerAfterDelete",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- },
- },
- }
-
- eAttrPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: ev.Tenant,
- ID: "ATTR_1001_SIMPLEAUTH",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Contexts: []string{"simpleauth"},
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{},
- Path: utils.MetaReq + utils.NestingSep + "Password",
- Type: utils.MetaConstant,
- Value: config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep),
- },
- },
- Weight: 20.0,
- },
- }
- if *encoding == utils.MetaGOB {
- eAttrPrf.Attributes[0].FilterIDs = nil // in gob emtpty slice is encoded as nil
- }
- eAttrPrf.Compile()
- var attrReply *engine.AttributeProfile
- if err := apierRPC.Call(utils.AttributeSv1GetAttributeForEvent,
- ev, &attrReply); err != nil {
- t.Error(err)
- }
- if attrReply == nil {
- t.Errorf("Expecting attrReply to not be nil")
- // attrReply shoud not be nil so exit function
- // to avoid nil segmentation fault;
- // if this happens try to run this test manualy
- return
- }
- attrReply.Compile() // Populate private variables in RSRParsers
- if !reflect.DeepEqual(eAttrPrf.AttributeProfile, attrReply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eAttrPrf.AttributeProfile), utils.ToJSON(attrReply))
- }
-}
-
-func testAPIerRemoveTPFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
- if err := apierRPC.Call(utils.APIerSv1RemoveTPFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testAPIerAfterDelete(t *testing.T) {
- var reply *engine.AttributeProfile
- if err := apierRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
- var replyTh *engine.ThresholdProfile
- if err := apierRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &replyTh); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
-}
-
-func testAPIerVerifyAttributesAfterDelete(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer("simpleauth"),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAPIerAfterDelete",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- },
- },
- }
- var attrReply *engine.AttributeProfile
- if err := apierRPC.Call(utils.AttributeSv1GetAttributeForEvent,
- ev, &attrReply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAPIerGetRatingPlanCost(t *testing.T) {
- arg := &utils.RatingPlanCostArg{
- Destination: "1002",
- RatingPlanIDs: []string{"RP_1001", "RP_1002"},
- SetupTime: utils.MetaNow,
- Usage: "1h",
- }
- var reply dispatchers.RatingPlanCost
- if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
- t.Error(err)
- } else if reply.RatingPlanID != "RP_1001" {
- t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
- } else if *reply.EventCost.Cost != 6.5118 {
- t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
- } else if *reply.EventCost.Usage != time.Hour {
- t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
- }
-}
-
-// we need to discuss about this case
-// because 1003 have the following DestinationRate
-// DR_1003_MAXCOST_DISC,DST_1003,RT_1CNT_PER_SEC,*up,4,0.12,*disconnect
-func testAPIerGetRatingPlanCost2(t *testing.T) {
- arg := &utils.RatingPlanCostArg{
- Destination: "1003",
- RatingPlanIDs: []string{"RP_1001", "RP_1002"},
- SetupTime: utils.MetaNow,
- Usage: "1h",
- }
- var reply dispatchers.RatingPlanCost
- if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
- t.Error(err)
- } else if reply.RatingPlanID != "RP_1001" {
- t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
- } else if *reply.EventCost.Cost != 36 {
- t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
- } else if *reply.EventCost.Usage != time.Hour {
- t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
- }
-}
-
-func testAPIerGetRatingPlanCost3(t *testing.T) {
- arg := &utils.RatingPlanCostArg{
- Destination: "1001",
- RatingPlanIDs: []string{"RP_1001", "RP_1002"},
- SetupTime: utils.MetaNow,
- Usage: "1h",
- }
- var reply dispatchers.RatingPlanCost
- if err := apierRPC.Call(utils.RALsV1GetRatingPlansCost, arg, &reply); err != nil {
- t.Error(err)
- } else if reply.RatingPlanID != "RP_1002" {
- t.Error("Unexpected RatingPlanID: ", reply.RatingPlanID)
- } else if *reply.EventCost.Cost != 6.5118 {
- t.Error("Unexpected Cost: ", *reply.EventCost.Cost)
- } else if *reply.EventCost.Usage != time.Hour {
- t.Error("Unexpected Usage: ", *reply.EventCost.Usage)
- }
-}
-
-func testAPIerGetActionPlanIDs(t *testing.T) {
- var reply []string
- if err := apierRPC.Call(utils.APIerSv1GetActionPlanIDs,
- &utils.PaginatorWithTenant{Tenant: "cgrates.org"},
- &reply); err != nil {
- t.Error(err)
- } else if len(reply) != 1 {
- t.Errorf("Expected: 1 , received: <%+v>", len(reply))
- } else if reply[0] != "AP_PACKAGE_10" {
- t.Errorf("Expected: AP_PACKAGE_10 , received: <%+v>", reply[0])
- }
-}
-
-func testAPIerGetRatingPlanIDs(t *testing.T) {
- var reply []string
- expected := []string{"RP_1002_LOW", "RP_1003", "RP_1001", "RP_MMS", "RP_SMS", "RP_1002"}
- if err := apierRPC.Call(utils.APIerSv1GetRatingPlanIDs,
- &utils.PaginatorWithTenant{Tenant: "cgrates.org"},
- &reply); err != nil {
- t.Error(err)
- }
- sort.Strings(reply)
- sort.Strings(expected)
- if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expected: <%+v> , received: <%+v>", utils.ToJSON(expected), utils.ToJSON(reply))
-
- }
-}
-
-func testAPIerSetActionPlanDfltTime(t *testing.T) {
- var reply1 string
- hourlyAP := &AttrSetActionPlan{
- Id: "AP_HOURLY",
- ActionPlan: []*AttrActionPlan{
- {
- ActionsId: "ACT_TOPUP_RST_10",
- Time: utils.MetaHourly,
- Weight: 20.0,
- },
- },
- }
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &hourlyAP, &reply1); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply1 != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1)
- }
- dailyAP := &AttrSetActionPlan{
- Id: "AP_DAILY",
- ActionPlan: []*AttrActionPlan{
- {
- ActionsId: "ACT_TOPUP_RST_10",
- Time: utils.MetaDaily,
- Weight: 20.0,
- },
- },
- }
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &dailyAP, &reply1); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply1 != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1)
- }
- weeklyAP := &AttrSetActionPlan{
- Id: "AP_WEEKLY",
- ActionPlan: []*AttrActionPlan{
- {
- ActionsId: "ACT_TOPUP_RST_10",
- Time: utils.MetaWeekly,
- Weight: 20.0,
- },
- },
- }
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &weeklyAP, &reply1); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply1 != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1)
- }
- monthlyAP := &AttrSetActionPlan{
- Id: "AP_MONTHLY",
- ActionPlan: []*AttrActionPlan{
- {
- ActionsId: "ACT_TOPUP_RST_10",
- Time: utils.MetaMonthly,
- Weight: 20.0,
- },
- },
- }
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &monthlyAP, &reply1); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply1 != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1)
- }
-}
-
-func testAPIerLoadRatingPlan(t *testing.T) {
- attrs := utils.AttrSetDestination{Id: "DEST_CUSTOM", Prefixes: []string{"+4986517174963", "+4986517174960"}}
- var reply string
- if err := apierRPC.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- rt := &utils.TPRateRALs{TPid: "TP_SAMPLE", ID: "SAMPLE_RATE_ID", RateSlots: []*utils.RateSlot{
- {ConnectFee: 0, Rate: 0, RateUnit: "1s", RateIncrement: "1s", GroupIntervalStart: "0s"},
- }}
- if err := apierRPC.Call(utils.APIerSv1SetTPRate, rt, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPRate: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPRate: ", reply)
- }
-
- dr := &utils.TPDestinationRate{TPid: "TP_SAMPLE", ID: "DR_SAMPLE_DESTINATION_RATE", DestinationRates: []*utils.DestinationRate{
- {DestinationId: "DEST_CUSTOM", RateId: "SAMPLE_RATE_ID",
- RoundingMethod: "*up", RoundingDecimals: 4},
- }}
- if err := apierRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply)
- }
-
- rp := &utils.TPRatingPlan{TPid: "TP_SAMPLE", ID: "RPl_SAMPLE_RATING_PLAN",
- RatingPlanBindings: []*utils.TPRatingPlanBinding{
- {DestinationRatesId: "DR_SAMPLE_DESTINATION_RATE", TimingId: utils.MetaAny,
- Weight: 10},
- }}
-
- if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply)
- }
-
- if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN"}, &reply); err != nil {
- t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply)
- }
-
- rpRply := new(engine.RatingPlan)
- rplnId := "RPl_SAMPLE_RATING_PLAN"
- if err := apierRPC.Call(utils.APIerSv1GetRatingPlan, &rplnId, rpRply); err != nil {
- t.Error("Got error on APIerSv1.GetRatingPlan: ", err.Error())
- }
-
-}
-
-func testAPIerLoadRatingPlan2(t *testing.T) {
- var reply string
-
- dr := &utils.TPDestinationRate{TPid: "TP_SAMPLE", ID: "DR_WITH_ERROR", DestinationRates: []*utils.DestinationRate{
- {DestinationId: "DST_NOT_FOUND", RateId: "SAMPLE_RATE_ID",
- RoundingMethod: "*up", RoundingDecimals: 4},
- }}
- if err := apierRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply)
- }
-
- rp := &utils.TPRatingPlan{TPid: "TP_SAMPLE", ID: "RPL_WITH_ERROR",
- RatingPlanBindings: []*utils.TPRatingPlanBinding{
- {DestinationRatesId: "DR_WITH_ERROR", TimingId: utils.MetaAny,
- Weight: 10},
- }}
-
- if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply)
- }
-
- if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan,
- &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPL_WITH_ERROR"}, &reply); err == nil {
- t.Error("Expected to get error: ", err)
- }
-
-}
-
-func testAPIerLoadRatingProfile(t *testing.T) {
- var reply string
- rpf := &utils.TPRatingProfile{
- TPid: "TP_SAMPLE",
- LoadId: "TP_SAMPLE",
- Tenant: "cgrates.org",
- Category: "call",
- Subject: utils.MetaAny,
- RatingPlanActivations: []*utils.TPRatingActivation{{
- ActivationTime: "2012-01-01T00:00:00Z",
- RatingPlanId: "RPl_SAMPLE_RATING_PLAN",
- FallbackSubjects: utils.EmptyString,
- }},
- }
- // add a TPRatingProfile
- if err := apierRPC.Call(utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil {
- t.Error(err)
- }
- // load the TPRatingProfile into dataDB
- argsRPrf := &utils.TPRatingProfile{
- TPid: "TP_SAMPLE", LoadId: "TP_SAMPLE",
- Tenant: "cgrates.org", Category: "call", Subject: "*any"}
- if err := apierRPC.Call(utils.APIerSv1LoadRatingProfile, argsRPrf, &reply); err != nil {
- t.Error(err)
- }
-
- // verify if was added correctly
- var rpl engine.RatingProfile
- attrGetRatingPlan := &utils.AttrGetRatingProfile{
- Tenant: "cgrates.org", Category: "call", Subject: utils.MetaAny}
- actTime, err := utils.ParseTimeDetectLayout("2012-01-01T00:00:00Z", utils.EmptyString)
- if err != nil {
- t.Error(err)
- }
- expected := engine.RatingProfile{
- Id: "*out:cgrates.org:call:*any",
- RatingPlanActivations: engine.RatingPlanActivations{
- {
- ActivationTime: actTime,
- RatingPlanId: "RPl_SAMPLE_RATING_PLAN",
- },
- },
- }
- if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil {
- t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err)
- } else if !reflect.DeepEqual(expected, rpl) {
- t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))
- }
-
- // add new RatingPlan
- rp := &utils.TPRatingPlan{TPid: "TP_SAMPLE", ID: "RPl_SAMPLE_RATING_PLAN2",
- RatingPlanBindings: []*utils.TPRatingPlanBinding{
- {DestinationRatesId: "DR_SAMPLE_DESTINATION_RATE", TimingId: utils.MetaAny,
- Weight: 10},
- }}
-
- if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply)
- }
-
- if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN2"}, &reply); err != nil {
- t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply)
- }
-
- // overwrite the existing TPRatingProfile with a new RatingPlanActivations
- rpf = &utils.TPRatingProfile{
- TPid: "TP_SAMPLE",
- LoadId: "TP_SAMPLE",
- Tenant: "cgrates.org",
- Category: "call",
- Subject: utils.MetaAny,
- RatingPlanActivations: []*utils.TPRatingActivation{
- {
- ActivationTime: "2012-01-01T00:00:00Z",
- RatingPlanId: "RPl_SAMPLE_RATING_PLAN",
- FallbackSubjects: utils.EmptyString,
- },
- {
- ActivationTime: "2012-02-02T00:00:00Z",
- RatingPlanId: "RPl_SAMPLE_RATING_PLAN2",
- FallbackSubjects: utils.EmptyString,
- },
- },
- }
-
- if err := apierRPC.Call(utils.APIerSv1SetTPRatingProfile, rpf, &reply); err != nil {
- t.Error(err)
- }
-
- // load the TPRatingProfile into dataDB
- // because the RatingProfile exists the RatingPlanActivations will be merged
- if err := apierRPC.Call(utils.APIerSv1LoadRatingProfile, argsRPrf, &reply); err != nil {
- t.Error(err)
- }
- actTime2, err := utils.ParseTimeDetectLayout("2012-02-02T00:00:00Z", utils.EmptyString)
- if err != nil {
- t.Error(err)
- }
- expected = engine.RatingProfile{
- Id: "*out:cgrates.org:call:*any",
- RatingPlanActivations: engine.RatingPlanActivations{
- {
- ActivationTime: actTime,
- RatingPlanId: "RPl_SAMPLE_RATING_PLAN",
- },
- {
- ActivationTime: actTime2,
- RatingPlanId: "RPl_SAMPLE_RATING_PLAN2",
- },
- },
- }
- if err := apierRPC.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil {
- t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err)
- } else if !reflect.DeepEqual(expected, rpl) {
- t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))
- }
-
-}
-
-func testAPIerLoadFromFolderAccountAction(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
- if err := apierRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
- attrs2 := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "account_action_from_tutorial")}
- if err := apierRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs2, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
- var acnt *engine.Account
- attrAcnt := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "AccountWithAPFromTutorial",
- }
- if err := apierRPC.Call(utils.APIerSv2GetAccount, attrAcnt, &acnt); err != nil {
- t.Error(err)
- } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != 10.0 {
- t.Errorf("Expecting: %v, received: %v",
- 10.0, rply)
- }
-}
-
-func testAPIerKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/apier_it_test.go b/apier/v1/apier_it_test.go
deleted file mode 100644
index 3e8e34f77..000000000
--- a/apier/v1/apier_it_test.go
+++ /dev/null
@@ -1,1160 +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 (
- "encoding/json"
- "fmt"
- "net/http"
- "net/rpc"
- "net/url"
- "os"
- "path"
- "reflect"
- "sort"
- "strings"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/servmanager"
- "github.com/cgrates/cgrates/utils"
- "github.com/cgrates/ltcache"
- "github.com/streadway/amqp"
-)
-
-// ToDo: Replace rpc.Client with internal rpc server and Apier using internal map as both data and stor so we can run the tests non-local
-
-/*
-README:
-
- Enable local tests by passing '-local' to the go test command
- It is expected that the data folder of CGRateS exists at path /usr/share/cgrates/data or passed via command arguments.
- Prior running the tests, create database and users by running:
- mysql -pyourrootpwd < /usr/share/cgrates/data/storage/mysql/create_db_with_users.sql
- What these tests do:
- * Flush tables in storDb to start clean.
- * Start engine with default configuration and give it some time to listen (here caching can slow down, hence the command argument parameter).
- * Connect rpc client depending on encoding defined in configuration.
- * Execute remote Apis and test their replies(follow testtp scenario so we can test load in dataDb also).
-*/
-var (
- cfgPath string
- cfg *config.CGRConfig
- rater *rpc.Client
- APIerSv1ConfigDIR string
-
- apierTests = []func(t *testing.T){
- testApierLoadConfig,
- testApierCreateDirs,
- testApierInitDataDb,
- testApierInitStorDb,
- testApierStartEngine,
- testApierRpcConn,
- testApierTPTiming,
- testApierTPDestination,
- testApierTPActions,
-
- testApierSetRatingProfileWithoutTenant,
- testApierRemoveRatingProfilesWithoutTenant,
- testApierReloadCache,
- testApierGetDestination,
- testApierExecuteAction,
- testApierExecuteActionWithoutTenant,
- testApierSetActions,
- testApierGetActions,
- testApierSetActionPlan,
- testApierResetDataBeforeLoadFromFolder,
- testApierLoadTariffPlanFromFolder,
- testApierComputeReverse,
- testApierResetDataAfterLoadFromFolder,
- testApierSetChargerS,
- testApierGetAccountAfterLoad,
- testApierResponderGetCost,
- testApierMaxDebitInexistentAcnt,
- testApierCdrServer,
- testApierITGetCdrs,
- testApierITProcessCdr,
- testApierGetCallCostLog,
- testApierITSetDestination,
- testApierITGetScheduledActions,
- testApierITGetDataCost,
- testApierITGetCost,
- testApierInitDataDb2,
- testApierInitStorDb2,
- testApierReloadCache2,
- testApierReloadScheduler2,
- testApierImportTPFromFolderPath,
- testApierLoadTariffPlanFromStorDbDryRun,
- testApierGetCacheStats2,
- testApierLoadTariffPlanFromStorDb,
- testApierStartStopServiceStatus,
- testApierReplayFldPosts,
- testApierGetDataDBVesions,
- testApierGetStorDBVesions,
- testApierBackwardsCompatible,
- testApierStopEngine,
- }
-)
-
-func TestApierIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow() // need tests redesign
- case utils.MetaMySQL:
- APIerSv1ConfigDIR = "apier_mysql"
- case utils.MetaMongo:
- APIerSv1ConfigDIR = "apier_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range apierTests {
- t.Run(APIerSv1ConfigDIR, stest)
- }
-}
-
-func testApierLoadConfig(t *testing.T) {
- var err error
- cfgPath = path.Join(*dataDir, "conf", "samples", APIerSv1ConfigDIR) // no need for a new config with *gob transport in this case
- if cfg, err = config.NewCGRConfigFromPath(cfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testApierCreateDirs(t *testing.T) {
- for _, pathDir := range []string{"/var/log/cgrates/ers/in", "/var/log/cgrates/ers/out"} {
- if err := os.RemoveAll(pathDir); err != nil {
- t.Fatal("Error removing folder: ", pathDir, err)
- }
- if err := os.MkdirAll(pathDir, 0755); err != nil {
- t.Fatal("Error creating folder: ", pathDir, err)
- }
- }
-}
-
-func testApierInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Empty tables before using them
-func testApierInitStorDb(t *testing.T) {
- if err := engine.InitStorDB(cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start engine
-func testApierStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(cfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testApierRpcConn(t *testing.T) {
- var err error
- rater, err = newRPCClient(cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
-}
-
-// Test here TPTiming APIs
-func testApierTPTiming(t *testing.T) {
- // ALWAYS,*any,*any,*any,*any,00:00:00
- tmAlways := &utils.ApierTPTiming{TPid: utils.TestSQL,
- ID: "ALWAYS",
- Years: utils.MetaAny,
- Months: utils.MetaAny,
- MonthDays: utils.MetaAny,
- WeekDays: utils.MetaAny,
- Time: "00:00:00",
- }
- tmAlways2 := new(utils.ApierTPTiming)
- *tmAlways2 = *tmAlways
- tmAlways2.ID = "ALWAYS2"
- tmAsap := &utils.ApierTPTiming{
- TPid: utils.TestSQL,
- ID: "ASAP",
- Years: utils.MetaAny,
- Months: utils.MetaAny,
- MonthDays: utils.MetaAny,
- WeekDays: utils.MetaAny,
- Time: "*asap",
- }
- var reply string
- for _, tm := range []*utils.ApierTPTiming{tmAlways, tmAsap, tmAlways2} {
- if err := rater.Call(utils.APIerSv1SetTPTiming, &tm, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPTiming: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPTiming: ", reply)
- }
- }
- // Check second set
- if err := rater.Call(utils.APIerSv1SetTPTiming, &tmAlways, &reply); err != nil {
- t.Error("Got error on second APIerSv1.SetTPTiming: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetTPTiming got reply: ", reply)
- }
- // Check missing params
- if err := rater.Call(utils.APIerSv1SetTPTiming, new(utils.ApierTPTiming), &reply); err == nil {
- t.Error("Calling APIerSv1.SetTPTiming, expected error, received: ", reply)
- } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID Years Months MonthDays WeekDays Time]" {
- t.Error("Calling APIerSv1.SetTPTiming got unexpected error: ", err.Error())
- }
- // Test get
- var rplyTmAlways2 *utils.ApierTPTiming
- if err := rater.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{tmAlways2.TPid, tmAlways2.ID}, &rplyTmAlways2); err != nil {
- t.Error("Calling APIerSv1.GetTPTiming, got error: ", err.Error())
- } else if !reflect.DeepEqual(tmAlways2, rplyTmAlways2) {
- t.Errorf("Calling APIerSv1.GetTPTiming expected: %v, received: %v", tmAlways, rplyTmAlways2)
- }
- // Test remove
- if err := rater.Call(utils.APIerSv1RemoveTPTiming, AttrGetTPTiming{tmAlways2.TPid, tmAlways2.ID}, &reply); err != nil {
- t.Error("Calling APIerSv1.RemoveTPTiming, got error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.RemoveTPTiming received: ", reply)
- }
- // Test getIds
- var rplyTmIds []string
- expectedTmIds := []string{"ALWAYS", "ASAP"}
- if err := rater.Call(utils.APIerSv1GetTPTimingIds, &AttrGetTPTimingIds{tmAlways.TPid, utils.PaginatorWithSearch{}}, &rplyTmIds); err != nil {
- t.Error("Calling APIerSv1.GetTPTimingIds, got error: ", err.Error())
- }
- sort.Strings(expectedTmIds)
- sort.Strings(rplyTmIds)
- if !reflect.DeepEqual(expectedTmIds, rplyTmIds) {
- t.Errorf("Calling APIerSv1.GetTPTimingIds expected: %v, received: %v", expectedTmIds, rplyTmIds)
- }
-}
-
-// Test here TPTiming APIs
-func testApierTPDestination(t *testing.T) {
- var reply string
- dstDe := &utils.TPDestination{TPid: utils.TestSQL, ID: "GERMANY", Prefixes: []string{"+49"}}
- dstDeMobile := &utils.TPDestination{TPid: utils.TestSQL, ID: "GERMANY_MOBILE", Prefixes: []string{"+4915", "+4916", "+4917"}}
- dstFs := &utils.TPDestination{TPid: utils.TestSQL, ID: "FS_USERS", Prefixes: []string{"10"}}
- dstDe2 := new(utils.TPDestination)
- *dstDe2 = *dstDe // Data which we use for remove, still keeping the sample data to check proper loading
- dstDe2.ID = "GERMANY2"
- for _, dst := range []*utils.TPDestination{dstDe, dstDeMobile, dstFs, dstDe2} {
- if err := rater.Call(utils.APIerSv1SetTPDestination, dst, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPDestination: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPDestination: ", reply)
- }
- }
- // Check second set
- if err := rater.Call(utils.APIerSv1SetTPDestination, dstDe2, &reply); err != nil {
- t.Error("Got error on second APIerSv1.SetTPDestination: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetTPDestination got reply: ", reply)
- }
- // Check missing params
- if err := rater.Call(utils.APIerSv1SetTPDestination, new(utils.TPDestination), &reply); err == nil {
- t.Error("Calling APIerSv1.SetTPDestination, expected error, received: ", reply)
- } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID Prefixes]" {
- t.Error("Calling APIerSv1.SetTPDestination got unexpected error: ", err.Error())
- }
- // Test get
- var rplyDstDe2 *utils.TPDestination
- if err := rater.Call(utils.APIerSv1GetTPDestination, &AttrGetTPDestination{dstDe2.TPid, dstDe2.ID}, &rplyDstDe2); err != nil {
- t.Error("Calling APIerSv1.GetTPDestination, got error: ", err.Error())
- } else if !reflect.DeepEqual(dstDe2, rplyDstDe2) {
- t.Errorf("Calling APIerSv1.GetTPDestination expected: %v, received: %v", dstDe2, rplyDstDe2)
- }
- // Test remove
- if err := rater.Call(utils.APIerSv1RemoveTPDestination, &AttrGetTPDestination{dstDe2.TPid, dstDe2.ID}, &reply); err != nil {
- t.Error("Calling APIerSv1.RemoveTPTiming, got error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.RemoveTPTiming received: ", reply)
- }
- // Test getIds
- var rplyDstIds []string
- expectedDstIds := []string{"FS_USERS", "GERMANY", "GERMANY_MOBILE"}
- if err := rater.Call(utils.APIerSv1GetTPDestinationIDs, &AttrGetTPDestinationIds{TPid: dstDe.TPid}, &rplyDstIds); err != nil {
- t.Error("Calling APIerSv1.GetTPDestinationIDs, got error: ", err.Error())
- }
- sort.Strings(expectedDstIds)
- sort.Strings(rplyDstIds)
- if !reflect.DeepEqual(expectedDstIds, rplyDstIds) {
- t.Errorf("Calling APIerSv1.GetTPDestinationIDs expected: %v, received: %v", expectedDstIds, rplyDstIds)
- }
-}
-
-func testApierTPActions(t *testing.T) {
- var reply string
- act := &utils.TPActions{TPid: utils.TestSQL,
- ID: "PREPAID_10", Actions: []*utils.TPAction{
- {Identifier: "*topup_reset", BalanceType: utils.MetaMonetary,
- Units: "10", ExpiryTime: "*unlimited",
- DestinationIds: utils.MetaAny, BalanceWeight: "10", Weight: 10},
- }}
- actWarn := &utils.TPActions{TPid: utils.TestSQL, ID: "WARN_VIA_HTTP", Actions: []*utils.TPAction{
- {Identifier: "*http_post", ExtraParameters: "http://localhost:8000", Weight: 10},
- }}
- actLog := &utils.TPActions{TPid: utils.TestSQL, ID: "LOG_BALANCE", Actions: []*utils.TPAction{
- {Identifier: "*log", Weight: 10},
- }}
- actTst := new(utils.TPActions)
- *actTst = *act
- actTst.ID = utils.TestSQL
- for _, ac := range []*utils.TPActions{act, actWarn, actTst, actLog} {
- if err := rater.Call(utils.APIerSv1SetTPActions, ac, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetTPActions: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv1.SetTPActions: ", reply)
- }
- }
- // Check second set
- if err := rater.Call(utils.APIerSv1SetTPActions, actTst, &reply); err != nil {
- t.Error("Got error on second APIerSv1.SetTPActions: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetTPActions got reply: ", reply)
- }
- // Check missing params
- if err := rater.Call(utils.APIerSv1SetTPActions, new(utils.TPActions), &reply); err == nil {
- t.Error("Calling APIerSv1.SetTPActions, expected error, received: ", reply)
- } else if err.Error() != "MANDATORY_IE_MISSING: [TPid ID Actions]" {
- t.Error("Calling APIerSv1.SetTPActions got unexpected error: ", err.Error())
- }
- // Test get
- var rplyActs *utils.TPActions
- if err := rater.Call(utils.APIerSv1GetTPActions, &AttrGetTPActions{TPid: actTst.TPid, ID: actTst.ID}, &rplyActs); err != nil {
- t.Error("Calling APIerSv1.GetTPActions, got error: ", err.Error())
- } else if !reflect.DeepEqual(actTst, rplyActs) {
- t.Errorf("Calling APIerSv1.GetTPActions expected: %v, received: %v", actTst, rplyActs)
- }
- // Test remove
- if err := rater.Call(utils.APIerSv1RemoveTPActions, &AttrGetTPActions{TPid: actTst.TPid, ID: actTst.ID}, &reply); err != nil {
- t.Error("Calling APIerSv1.RemoveTPActions, got error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.RemoveTPActions received: ", reply)
- }
- // Test getIds
- var rplyIds []string
- expectedIds := []string{"LOG_BALANCE", "PREPAID_10", "WARN_VIA_HTTP"}
- if err := rater.Call(utils.APIerSv1GetTPActionIds, &AttrGetTPActionIds{TPid: actTst.TPid}, &rplyIds); err != nil {
- t.Error("Calling APIerSv1.GetTPActionIds, got error: ", err.Error())
- }
- sort.Strings(expectedIds)
- sort.Strings(rplyIds)
- if !reflect.DeepEqual(expectedIds, rplyIds) {
- t.Errorf("Calling APIerSv1.GetTPActionIds expected: %v, received: %v", expectedIds, rplyIds)
- }
-}
-
-// Test here ReloadCache
-func testApierReloadCache(t *testing.T) {
- var reply string
- arc := new(utils.AttrReloadCacheWithAPIOpts)
- // Simple test that command is executed without errors
- if err := rater.Call(utils.CacheSv1ReloadCache, arc, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
- var rcvStats map[string]*ltcache.CacheStats
- expectedStats := engine.GetDefaultEmptyCacheStats()
- expectedStats[utils.CacheActions].Items = 1
- expectedStats[utils.CacheReverseDestinations].Items = 10
- expectedStats[utils.CacheLoadIDs].Items = 8
- expectedStats[utils.CacheRPCConnections].Items = 1
- if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(expectedStats, rcvStats) {
- t.Errorf("Calling CacheSv1.GetCacheStats expected: %+v,\n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats))
- }
-}
-
-// Test here GetDestination
-func testApierGetDestination(t *testing.T) {
- reply := new(engine.Destination)
- dstId := "GERMANY_MOBILE"
- expectedReply := &engine.Destination{ID: dstId, Prefixes: []string{"+4915", "+4916", "+4917"}}
- if err := rater.Call(utils.APIerSv1GetDestination, &dstId, reply); err != nil {
- t.Error("Got error on APIerSv1.GetDestination: ", err.Error())
- } else if !reflect.DeepEqual(expectedReply, reply) {
- t.Errorf("Calling APIerSv1.GetDestination expected: %v, received: %v", expectedReply, reply)
- }
-}
-
-// Test here ExecuteAction
-func testApierExecuteAction(t *testing.T) {
- var reply string
- // Add balance to a previously known account
- attrs := utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "dan2", ActionsId: "PREPAID_10"}
- if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil {
- t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply)
- }
- reply2 := utils.EmptyString
- // Add balance to an account which does n exist
- attrs = utils.AttrExecuteAction{Tenant: "cgrates.org", Account: "dan2", ActionsId: "DUMMY_ACTION"}
- if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply2); err == nil || reply2 == utils.OK {
- t.Error("Expecting error on APIerSv1.ExecuteAction.", err, reply2)
- }
-}
-
-func testApierExecuteActionWithoutTenant(t *testing.T) {
- var reply string
- // Add balance to a previously known account
- attrs := utils.AttrExecuteAction{Account: "dan2", ActionsId: "PREPAID_10"}
- if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil {
- t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply)
- }
- reply2 := utils.EmptyString
- // Add balance to an account which does n exist
- attrs = utils.AttrExecuteAction{Account: "dan2", ActionsId: "DUMMY_ACTION"}
- if err := rater.Call(utils.APIerSv1ExecuteAction, attrs, &reply2); err == nil || reply2 == utils.OK {
- t.Error("Expecting error on APIerSv1.ExecuteAction.", err, reply2)
- }
-}
-
-func testApierSetActions(t *testing.T) {
- act1 := &V1TPAction{Identifier: utils.MetaTopUpReset, BalanceType: utils.MetaMonetary, Units: 75.0, ExpiryTime: utils.MetaUnlimited, Weight: 20.0}
- attrs1 := &V1AttrSetActions{ActionsId: "ACTS_1", Actions: []*V1TPAction{act1}}
- reply1 := utils.EmptyString
- if err := rater.Call(utils.APIerSv1SetActions, &attrs1, &reply1); err != nil {
- t.Error("Got error on APIerSv1.SetActions: ", err.Error())
- } else if reply1 != utils.OK {
- t.Errorf("Calling APIerSv1.SetActions received: %s", reply1)
- }
- // Calling the second time should raise EXISTS
- if err := rater.Call(utils.APIerSv1SetActions, &attrs1, &reply1); err == nil || err.Error() != "EXISTS" {
- t.Error("Unexpected result on duplication: ", err.Error())
- }
-}
-
-func testApierGetActions(t *testing.T) {
- expectActs := []*utils.TPAction{
- {Identifier: utils.MetaTopUpReset, BalanceType: utils.MetaMonetary,
- Units: "75", BalanceWeight: "0", BalanceBlocker: "false",
- BalanceDisabled: "false", ExpiryTime: utils.MetaUnlimited, Weight: 20.0}}
-
- var reply []*utils.TPAction
- if err := rater.Call(utils.APIerSv1GetActions, utils.StringPointer("ACTS_1"), &reply); err != nil {
- t.Error("Got error on APIerSv1.GetActions: ", err.Error())
- } else if !reflect.DeepEqual(expectActs, reply) {
- t.Errorf("Expected: %v, received: %v", utils.ToJSON(expectActs), utils.ToJSON(reply))
- }
-}
-
-func testApierSetActionPlan(t *testing.T) {
- atm1 := &AttrActionPlan{ActionsId: "ACTS_1", MonthDays: "1", Time: "00:00:00", Weight: 20.0}
- atms1 := &AttrSetActionPlan{Id: "ATMS_1", ActionPlan: []*AttrActionPlan{atm1}}
- reply1 := utils.EmptyString
- if err := rater.Call(utils.APIerSv1SetActionPlan, &atms1, &reply1); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply1 != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply1)
- }
- // Calling the second time should raise EXISTS
- if err := rater.Call(utils.APIerSv1SetActionPlan, &atms1, &reply1); err == nil || err.Error() != "EXISTS" {
- t.Error("Unexpected result on duplication: ", err.Error())
- }
-}
-
-// Start fresh before loading from folder
-func testApierResetDataBeforeLoadFromFolder(t *testing.T) {
- testApierInitDataDb(t)
- var reply string
- // Simple test that command is executed without errors
- if err := rater.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: nil,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Reply: ", reply)
- }
- var rcvStats map[string]*ltcache.CacheStats
- expectedStats := engine.GetDefaultEmptyCacheStats()
- err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats)
- if err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(rcvStats, expectedStats) {
- t.Errorf("Calling CacheSv1.GetCacheStats expected: %v, received: %v", utils.ToJSON(expectedStats), utils.ToJSON(rcvStats))
- }
-}
-
-// Test here LoadTariffPlanFromFolder
-func testApierLoadTariffPlanFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: utils.EmptyString}
- if err := rater.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err == nil || !strings.HasPrefix(err.Error(), utils.ErrMandatoryIeMissing.Error()) {
- t.Error(err)
- }
- attrs = &utils.AttrLoadTpFromFolder{FolderPath: "/INVALID/"}
- if err := rater.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err == nil || err.Error() != utils.ErrInvalidPath.Error() {
- t.Error(err)
- }
- // Simple test that command is executed without errors
- attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")}
- if err := rater.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error("Got error on APIerSv1.LoadTariffPlanFromFolder: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.LoadTariffPlanFromFolder got reply: ", reply)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-// For now just test that they execute without errors
-func testApierComputeReverse(t *testing.T) {
- var reply string
- if err := rater.Call(utils.APIerSv1ComputeReverseDestinations, utils.EmptyString, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Received: ", reply)
- }
- if err := rater.Call(utils.APIerSv1ComputeAccountActionPlans, utils.EmptyString, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Received: ", reply)
- }
-}
-
-func testApierResetDataAfterLoadFromFolder(t *testing.T) {
- time.Sleep(10 * time.Millisecond)
- var rcvStats map[string]*ltcache.CacheStats
- expStats := engine.GetDefaultEmptyCacheStats()
- expStats[utils.CacheAccountActionPlans].Items = 3
- expStats[utils.CacheActionPlans].Items = 7
- expStats[utils.CacheActions].Items = 5
- expStats[utils.CacheDestinations].Items = 3
- expStats[utils.CacheLoadIDs].Items = 17
- expStats[utils.CacheRPCConnections].Items = 2
- if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v,\n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
- var reply string
- // Simple test that command is executed without errors
- if err := rater.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error(reply)
- }
- expStats[utils.CacheActionTriggers].Items = 1
- expStats[utils.CacheActions].Items = 13
- expStats[utils.CacheAttributeProfiles].Items = 1
- expStats[utils.CacheFilters].Items = 15
- expStats[utils.CacheRatingPlans].Items = 5
- expStats[utils.CacheRatingProfiles].Items = 5
- expStats[utils.CacheResourceProfiles].Items = 3
- expStats[utils.CacheResources].Items = 3
- expStats[utils.CacheReverseDestinations].Items = 5
- expStats[utils.CacheStatQueueProfiles].Items = 1
- expStats[utils.CacheStatQueues].Items = 1
- expStats[utils.CacheRouteProfiles].Items = 2
- expStats[utils.CacheThresholdProfiles].Items = 1
- expStats[utils.CacheThresholds].Items = 1
- expStats[utils.CacheLoadIDs].Items = 33
- expStats[utils.CacheTimings].Items = 12
- expStats[utils.CacheThresholdFilterIndexes].Items = 5
- expStats[utils.CacheThresholdFilterIndexes].Groups = 1
- expStats[utils.CacheStatFilterIndexes].Items = 2
- expStats[utils.CacheStatFilterIndexes].Groups = 1
- expStats[utils.CacheRouteFilterIndexes].Items = 2
- expStats[utils.CacheRouteFilterIndexes].Groups = 1
- expStats[utils.CacheResourceFilterIndexes].Items = 5
- expStats[utils.CacheResourceFilterIndexes].Groups = 1
- expStats[utils.CacheAttributeFilterIndexes].Items = 4
- expStats[utils.CacheAttributeFilterIndexes].Groups = 1
- expStats[utils.CacheReverseFilterIndexes].Items = 10
- expStats[utils.CacheReverseFilterIndexes].Groups = 7
-
- if err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
-}
-
-func testApierSetChargerS(t *testing.T) {
- //add a default charger
- chargerProfile := &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Default",
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"*none"},
- Weight: 20,
- },
- }
- var result string
- if err := rater.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-// Make sure balance was topped-up
-// Bug reported by DigiDaz over IRC
-func testApierGetAccountAfterLoad(t *testing.T) {
- var reply *engine.Account
- attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}
- if err := rater.Call(utils.APIerSv2GetAccount, attrs, &reply); err != nil {
- t.Error("Got error on APIerSv1.GetAccount: ", err.Error())
- } else if reply.BalanceMap[utils.MetaMonetary].GetTotalValue() != 13 {
- t.Errorf("Calling APIerSv1.GetBalance expected: 13, received: %v \n\n for:%s", reply.BalanceMap[utils.MetaMonetary].GetTotalValue(), utils.ToJSON(reply))
- }
-}
-
-// Test here ResponderGetCost
-func testApierResponderGetCost(t *testing.T) {
- tStart, _ := utils.ParseTimeDetectLayout("2013-08-07T17:30:00Z", utils.EmptyString)
- tEnd, _ := utils.ParseTimeDetectLayout("2013-08-07T17:31:30Z", utils.EmptyString)
- cd := &engine.CallDescriptorWithAPIOpts{
- CallDescriptor: &engine.CallDescriptor{
- Category: "call",
- Tenant: "cgrates.org",
- Subject: "1001",
- Account: "1001",
- Destination: "+4917621621391",
- DurationIndex: 90,
- TimeStart: tStart,
- TimeEnd: tEnd,
- },
- }
- var cc engine.CallCost
- // Simple test that command is executed without errors
- if err := rater.Call(utils.ResponderGetCost, cd, &cc); err != nil {
- t.Error("Got error on Responder.GetCost: ", err.Error())
- } else if cc.Cost != 90.0 {
- t.Errorf("Calling Responder.GetCost got callcost: %v", cc)
- }
-}
-
-func testApierMaxDebitInexistentAcnt(t *testing.T) {
- cc := &engine.CallCost{}
- cd := &engine.CallDescriptorWithAPIOpts{
- CallDescriptor: &engine.CallDescriptor{
- Tenant: "cgrates.org",
- Category: "call",
- Subject: "INVALID",
- Account: "INVALID",
- Destination: "1002",
- TimeStart: time.Date(2014, 3, 27, 10, 42, 26, 0, time.UTC),
- TimeEnd: time.Date(2014, 3, 27, 10, 42, 26, 0, time.UTC).Add(10 * time.Second),
- },
- }
- if err := rater.Call(utils.ResponderMaxDebit, cd, cc); err == nil {
- t.Error(err.Error())
- }
- if err := rater.Call(utils.ResponderDebit, cd, cc); err == nil {
- t.Error(err.Error())
- }
-}
-
-func testApierCdrServer(t *testing.T) {
- httpClient := new(http.Client)
- cdrForm1 := url.Values{utils.OriginID: []string{"dsafdsaf"}, utils.OriginHost: []string{"192.168.1.1"}, utils.RequestType: []string{utils.MetaRated},
- utils.Tenant: []string{"cgrates.org"}, utils.Category: []string{"call"}, utils.AccountField: []string{"1001"}, utils.Subject: []string{"1001"}, utils.Destination: []string{"1002"},
- utils.SetupTime: []string{"2013-11-07T08:42:22Z"},
- utils.AnswerTime: []string{"2013-11-07T08:42:26Z"}, utils.Usage: []string{"10"}, "field_extr1": []string{"val_extr1"}, "fieldextr2": []string{"valextr2"}}
- cdrForm2 := url.Values{utils.OriginID: []string{"adsafdsaf"}, utils.OriginHost: []string{"192.168.1.1"}, utils.RequestType: []string{utils.MetaRated},
- utils.Tenant: []string{"cgrates.org"}, utils.Category: []string{"call"}, utils.AccountField: []string{"1001"}, utils.Subject: []string{"1001"}, utils.Destination: []string{"1002"},
- utils.SetupTime: []string{"2013-11-07T08:42:23Z"},
- utils.AnswerTime: []string{"2013-11-07T08:42:26Z"}, utils.Usage: []string{"10"}, "field_extr1": []string{"val_extr1"}, "fieldextr2": []string{"valextr2"}}
- for _, cdrForm := range []url.Values{cdrForm1, cdrForm2} {
- cdrForm.Set(utils.Source, utils.TestSQL)
- if _, err := httpClient.PostForm(fmt.Sprintf("http://%s/cdr_http", "127.0.0.1:2080"), cdrForm); err != nil {
- t.Error(err.Error())
- }
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond)
-}
-
-func testApierITGetCdrs(t *testing.T) {
- var reply []*engine.ExternalCDR
- req := utils.AttrGetCdrs{MediationRunIds: []string{utils.MetaDefault}}
- if err := rater.Call(utils.APIerSv1GetCDRs, &req, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(reply) != 2 {
- t.Error("Unexpected number of CDRs returned: ", len(reply))
- }
-}
-
-func testApierITProcessCdr(t *testing.T) {
- var reply string
- cdr := &engine.CDRWithAPIOpts{
- CDR: &engine.CDR{CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), OrderID: 123, ToR: utils.MetaVoice, OriginID: "dsafdsaf",
- OriginHost: "192.168.1.1", Source: "test", RequestType: utils.MetaRated, Tenant: "cgrates.org", Category: "call", Account: "1001", Subject: "1001",
- Destination: "1002",
- SetupTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), RunID: utils.MetaDefault,
- Usage: 10 * time.Second, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01,
- },
- }
- if err := rater.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
- var cdrs []*engine.ExternalCDR
- req := utils.AttrGetCdrs{MediationRunIds: []string{utils.MetaDefault}}
- if err := rater.Call(utils.APIerSv1GetCDRs, &req, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 3 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- }
-}
-
-// Test here ResponderGetCost
-func testApierGetCallCostLog(t *testing.T) {
- var cc engine.EventCost
- var attrs utils.AttrGetCallCost
- // Simple test that command is executed without errors
- if err := rater.Call(utils.APIerSv1GetEventCost, &attrs, &cc); err == nil {
- t.Error("Failed to detect missing fields in APIerSv1.GetCallCostLog")
- }
- attrs.CgrId = "dummyid"
- attrs.RunId = "default"
- if err := rater.Call(utils.APIerSv1GetEventCost, &attrs, &cc); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error("APIerSv1.GetCallCostLog: should return NOT_FOUND, got:", err)
- }
- tm := time.Now().Truncate(time.Millisecond).UTC()
- cdr := &engine.CDRWithAPIOpts{
- CDR: &engine.CDR{
- CGRID: "Cdr1",
- OrderID: 123,
- ToR: utils.MetaVoice,
- OriginID: "OriginCDR1",
- OriginHost: "192.168.1.1",
- Source: "test",
- RequestType: utils.MetaRated,
- Tenant: "cgrates.org",
- Category: "call",
- Account: "1001",
- Subject: "1001",
- Destination: "+4986517174963",
- SetupTime: tm,
- AnswerTime: tm,
- RunID: utils.MetaDefault,
- Usage: 0,
- ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
- Cost: 1.01,
- },
- }
- var reply string
- if err := rater.Call(utils.CDRsV1ProcessCDR, cdr, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
- time.Sleep(100 * time.Millisecond)
- expected := engine.EventCost{
- CGRID: "Cdr1",
- RunID: utils.MetaDefault,
- StartTime: tm,
- Usage: utils.DurationPointer(0),
- Cost: utils.Float64Pointer(0),
- Charges: []*engine.ChargingInterval{{
- RatingID: utils.EmptyString,
- Increments: nil,
- CompressFactor: 0,
- }},
- AccountSummary: nil,
- Rating: engine.Rating{},
- Accounting: engine.Accounting{},
- RatingFilters: engine.RatingFilters{},
- Rates: engine.ChargedRates{},
- Timings: engine.ChargedTimings{},
- }
- if *encoding == utils.MetaGOB {
- expected.Usage = nil // 0 value are encoded as nil in gob
- expected.Cost = nil
- }
- attrs.CgrId = "Cdr1"
- attrs.RunId = utils.EmptyString
- if err := rater.Call(utils.APIerSv1GetEventCost, &attrs, &cc); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, cc) {
- t.Errorf("Expecting %s ,received %s", utils.ToJSON(expected), utils.ToJSON(cc))
- }
-}
-
-func testApierITSetDestination(t *testing.T) {
- attrs := utils.AttrSetDestination{Id: "TEST_SET_DESTINATION", Prefixes: []string{"+4986517174963", "+4986517174960"}}
- var reply string
- if err := rater.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- if err := rater.Call(utils.APIerSv1SetDestination, &attrs, &reply); err == nil || err.Error() != "EXISTS" { // Second time without overwrite should generate error
- t.Error("Unexpected error", err.Error())
- }
- attrs = utils.AttrSetDestination{Id: "TEST_SET_DESTINATION", Prefixes: []string{"+4986517174963", "+4986517174964"}, Overwrite: true}
- if err := rater.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- eDestination := engine.Destination{ID: attrs.Id, Prefixes: attrs.Prefixes}
- var rcvDestination engine.Destination
- if err := rater.Call(utils.APIerSv1GetDestination, &attrs.Id, &rcvDestination); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if !reflect.DeepEqual(eDestination, rcvDestination) {
- t.Errorf("Expecting: %+v, received: %+v", eDestination, rcvDestination)
- }
- eRcvIDs := []string{attrs.Id}
- var rcvIDs []string
- if err := rater.Call(utils.APIerSv1GetReverseDestination, &attrs.Prefixes[0], &rcvIDs); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if !reflect.DeepEqual(eRcvIDs, rcvIDs) {
- t.Errorf("Expecting: %+v, received: %+v", eRcvIDs, rcvIDs)
- }
-}
-
-// func testApierITGetScheduledActions(t *testing.T) {
-// var rply []*scheduler.ScheduledAction
-// if err := rater.Call(utils.APIerSv1GetScheduledActions, scheduler.ArgsGetScheduledActions{}, &rply); err != nil {
-// t.Error("Unexpected error: ", err)
-// }
-// }
-
-func testApierITGetDataCost(t *testing.T) {
- attrs := AttrGetDataCost{Category: "data", Tenant: "cgrates.org",
- Subject: "1001", AnswerTime: utils.MetaNow, Usage: 640113}
- var rply *engine.DataCost
- if err := rater.Call(utils.APIerSv1GetDataCost, &attrs, &rply); err != nil {
- t.Error("Unexpected nil error received: ", err.Error())
- } else if rply.Cost != 128.0240 {
- t.Errorf("Unexpected cost received: %f", rply.Cost)
- }
-}
-
-func testApierITGetCost(t *testing.T) {
- attrs := AttrGetCost{Category: "data", Tenant: "cgrates.org",
- Subject: "1001", AnswerTime: utils.MetaNow, Usage: "640113"}
- var rply *engine.EventCost
- if err := rater.Call(utils.APIerSv1GetCost, &attrs, &rply); err != nil {
- t.Error("Unexpected nil error received: ", err.Error())
- } else if *rply.Cost != 128.0240 {
- t.Errorf("Unexpected cost received: %f", *rply.Cost)
- }
-}
-
-// Test LoadTPFromStorDb
-func testApierInitDataDb2(t *testing.T) {
- if err := engine.InitDataDB(cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testApierInitStorDb2(t *testing.T) {
- if err := engine.InitStorDB(cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testApierReloadCache2(t *testing.T) {
- var reply string
- // Simple test that command is executed without errors
- if err := rater.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: nil,
- }, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
-
-func testApierReloadScheduler2(t *testing.T) {
- var reply string
- // Simple test that command is executed without errors
- if err := rater.Call(utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil {
- t.Error("Got error on SchedulerSv1.Reload: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling SchedulerSv1.Reload got reply: ", reply)
- }
-}
-
-func testApierImportTPFromFolderPath(t *testing.T) {
- var reply string
- if err := rater.Call(utils.APIerSv1ImportTariffPlanFromFolder,
- utils.AttrImportTPFromFolder{TPid: "TEST_TPID2",
- FolderPath: "/usr/share/cgrates/tariffplans/oldtutorial"}, &reply); err != nil {
- t.Error("Got error on APIerSv1.ImportTarrifPlanFromFolder: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.ImportTarrifPlanFromFolder got reply: ", reply)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testApierLoadTariffPlanFromStorDbDryRun(t *testing.T) {
- var reply string
- if err := rater.Call(utils.APIerSv1LoadTariffPlanFromStorDb,
- &AttrLoadTpFromStorDb{TPid: "TEST_TPID2", DryRun: true}, &reply); err != nil {
- t.Error("Got error on APIerSv1.LoadTariffPlanFromStorDb: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.LoadTariffPlanFromStorDb got reply: ", reply)
- }
-}
-
-func testApierGetCacheStats2(t *testing.T) {
- var rcvStats map[string]*ltcache.CacheStats
- expectedStats := engine.GetDefaultEmptyCacheStats()
- err := rater.Call(utils.CacheSv1GetCacheStats, new(utils.AttrCacheIDsWithAPIOpts), &rcvStats)
- if err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(expectedStats, rcvStats) {
- t.Errorf("Calling CacheSv1.GetCacheStats expected: %v, received: %v", expectedStats, rcvStats)
- }
-}
-
-func testApierLoadTariffPlanFromStorDb(t *testing.T) {
- var reply string
- if err := rater.Call(utils.APIerSv1LoadTariffPlanFromStorDb,
- &AttrLoadTpFromStorDb{TPid: "TEST_TPID2"}, &reply); err != nil {
- t.Error("Got error on APIerSv1.LoadTariffPlanFromStorDb: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.LoadTariffPlanFromStorDb got reply: ", reply)
- }
-}
-
-func testApierStartStopServiceStatus(t *testing.T) {
- var reply string
- if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.RunningCaps {
- t.Errorf("Received: <%s>", reply)
- }
- if err := rater.Call(utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: "INVALID"}},
- &reply); err == nil || err.Error() != utils.UnsupportedServiceIDCaps {
- t.Error(err)
- }
- if err := rater.Call(utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Received: <%s>", reply)
- }
- if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.StoppedCaps {
- t.Errorf("Received: <%s>", reply)
- }
- if err := rater.Call(utils.ServiceManagerV1StartService, &dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Received: <%s>", reply)
- }
- if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithAPIOpts{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.RunningCaps {
- t.Errorf("Received: <%s>", reply)
- }
- if err := rater.Call(utils.SchedulerSv1Reload, utils.StringWithAPIOpts{}, &reply); err != nil {
- t.Error("Got error on SchedulerSv1.Reload: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling SchedulerSv1.Reload got reply: ", reply)
- }
-}
-
-func testApierSetRatingProfileWithoutTenant(t *testing.T) {
- var reply string
- rpa := &utils.TPRatingActivation{ActivationTime: "2012-01-01T00:00:00Z", RatingPlanId: "RETAIL1", FallbackSubjects: "dan4"}
- rpf := &utils.AttrSetRatingProfile{Category: utils.Call, Subject: "dan3", RatingPlanActivations: []*utils.TPRatingActivation{rpa}}
- if err := rater.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply)
- }
- expectedID := utils.ConcatenatedKey(utils.MetaOut, "cgrates.org", utils.Call, "dan3")
- var result *engine.RatingProfile
- if err := rater.Call(utils.APIerSv1GetRatingProfile,
- &utils.AttrGetRatingProfile{Category: utils.Call, Subject: "dan3"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedID, result.Id) {
- t.Errorf("Expected %+v, received %+v", expectedID, result.Id)
- }
-}
-
-func testApierRemoveRatingProfilesWithoutTenant(t *testing.T) {
- var reply string
- if err := rater.Call(utils.APIerSv1RemoveRatingProfile, &AttrRemoveRatingProfile{
- Category: utils.Call,
- Subject: "dan3",
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected: %s, received: %s ", utils.OK, reply)
- }
- var result *engine.RatingProfile
- if err := rater.Call(utils.APIerSv1GetRatingProfile,
- &utils.AttrGetRatingProfile{Category: utils.Call, Subject: "dan3"},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testApierReplayFldPosts(t *testing.T) {
- bev := []byte(`{"ID":"cgrates.org:1007","BalanceMap":{"*monetary":[{"Uuid":"367be35a-96ee-40a5-b609-9130661f5f12","ID":"","Value":0,"ExpirationDate":"0001-01-01T00:00:00Z","Weight":10,"DestinationIDs":{},"RatingSubject":"","Categories":{},"SharedGroups":{"SHARED_A":true},"Timings":null,"TimingIDs":{},"Disabled":false,"Factor":null,"Blocker":false}]},"UnitCounters":{"*monetary":[{"CounterType":"*event","Counters":[{"Value":0,"Filter":{"Uuid":null,"ID":"b8531413-10d5-47ad-81ad-2bc272e8f0ca","Type":"*monetary","Value":null,"ExpirationDate":null,"Weight":null,"DestinationIDs":{"FS_USERS":true},"RatingSubject":null,"Categories":null,"SharedGroups":null,"TimingIDs":null,"Timings":null,"Disabled":null,"Factor":null,"Blocker":null}}]}]},"ActionTriggers":[{"ID":"STANDARD_TRIGGERS","UniqueID":"46ac7b8c-685d-4555-bf73-fa6cfbc2fa21","ThresholdType":"*min_balance","ThresholdValue":2,"Recurrent":false,"MinSleep":0,"ExpirationDate":"0001-01-01T00:00:00Z","ActivationDate":"0001-01-01T00:00:00Z","Balance":{"Uuid":null,"ID":null,"Type":"*monetary","Value":null,"ExpirationDate":null,"Weight":null,"DestinationIDs":null,"RatingSubject":null,"Categories":null,"SharedGroups":null,"TimingIDs":null,"Timings":null,"Disabled":null,"Factor":null,"Blocker":null},"Weight":10,"ActionsID":"LOG_WARNING","MinQueuedItems":0,"Executed":true,"LastExecutionTime":"2017-01-31T14:03:57.961651647+01:00"},{"ID":"STANDARD_TRIGGERS","UniqueID":"b8531413-10d5-47ad-81ad-2bc272e8f0ca","ThresholdType":"*max_event_counter","ThresholdValue":5,"Recurrent":false,"MinSleep":0,"ExpirationDate":"0001-01-01T00:00:00Z","ActivationDate":"0001-01-01T00:00:00Z","Balance":{"Uuid":null,"ID":null,"Type":"*monetary","Value":null,"ExpirationDate":null,"Weight":null,"DestinationIDs":{"FS_USERS":true},"RatingSubject":null,"Categories":null,"SharedGroups":null,"TimingIDs":null,"Timings":null,"Disabled":null,"Factor":null,"Blocker":null},"Weight":10,"ActionsID":"LOG_WARNING","MinQueuedItems":0,"Executed":false,"LastExecutionTime":"0001-01-01T00:00:00Z"},{"ID":"STANDARD_TRIGGERS","UniqueID":"8b424186-7a31-4aef-99c5-35e12e6fed41","ThresholdType":"*max_balance","ThresholdValue":20,"Recurrent":false,"MinSleep":0,"ExpirationDate":"0001-01-01T00:00:00Z","ActivationDate":"0001-01-01T00:00:00Z","Balance":{"Uuid":null,"ID":null,"Type":"*monetary","Value":null,"ExpirationDate":null,"Weight":null,"DestinationIDs":null,"RatingSubject":null,"Categories":null,"SharedGroups":null,"TimingIDs":null,"Timings":null,"Disabled":null,"Factor":null,"Blocker":null},"Weight":10,"ActionsID":"LOG_WARNING","MinQueuedItems":0,"Executed":false,"LastExecutionTime":"0001-01-01T00:00:00Z"},{"ID":"STANDARD_TRIGGERS","UniqueID":"28557f3b-139c-4a27-9d17-bda1f54b7c19","ThresholdType":"*max_balance","ThresholdValue":100,"Recurrent":false,"MinSleep":0,"ExpirationDate":"0001-01-01T00:00:00Z","ActivationDate":"0001-01-01T00:00:00Z","Balance":{"Uuid":null,"ID":null,"Type":"*monetary","Value":null,"ExpirationDate":null,"Weight":null,"DestinationIDs":null,"RatingSubject":null,"Categories":null,"SharedGroups":null,"TimingIDs":null,"Timings":null,"Disabled":null,"Factor":null,"Blocker":null},"Weight":10,"ActionsID":"DISABLE_AND_LOG","MinQueuedItems":0,"Executed":false,"LastExecutionTime":"0001-01-01T00:00:00Z"}],"AllowNegative":false,"Disabled":false}"`)
- ev := &engine.ExportEvents{
- Path: "http://localhost:2081",
- Format: utils.MetaHTTPjson,
- Events: []interface{}{&engine.HTTPPosterRequest{Body: bev, Header: http.Header{"Content-Type": []string{"application/json"}}}},
- }
- fileName := "act>*http_post|63bed4ea-615e-4096-b1f4-499f64f29b28.json"
-
- args := ArgsReplyFailedPosts{
- FailedRequestsInDir: utils.StringPointer("/tmp/TestsAPIerSv1/in"),
- FailedRequestsOutDir: utils.StringPointer("/tmp/TestsAPIerSv1/out"),
- }
- for _, dir := range []string{*args.FailedRequestsInDir, *args.FailedRequestsOutDir} {
- if err := os.RemoveAll(dir); err != nil {
- t.Errorf("Error %s removing folder: %s", err, dir)
- }
- if err := os.MkdirAll(dir, 0755); err != nil {
- t.Errorf("Error %s creating folder: %s", err, dir)
- }
- }
- err := ev.WriteToFile(path.Join(*args.FailedRequestsInDir, fileName))
- if err != nil {
- t.Error(err)
- }
- var reply string
- if err := rater.Call(utils.APIerSv1ReplayFailedPosts, &args, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply: ", reply)
- }
- outPath := path.Join(*args.FailedRequestsOutDir, fileName)
- outEv, err := engine.NewExportEventsFromFile(outPath)
- if err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ev, outEv) {
- t.Errorf("Expecting: %q, received: %q", utils.ToJSON(ev), utils.ToJSON(outEv))
- }
- fileName = "cdr|ae8cc4b3-5e60-4396-b82a-64b96a72a03c.json"
- bev = []byte(`{"CGRID":"88ed9c38005f07576a1e1af293063833b60edcc6"}`)
- fileInPath := path.Join(*args.FailedRequestsInDir, fileName)
- ev = &engine.ExportEvents{
- Path: "amqp://guest:guest@localhost:5672/",
- Opts: map[string]interface{}{
- "queueID": "cgrates_cdrs",
- },
- Format: utils.MetaAMQPjsonMap,
- Events: []interface{}{bev},
- }
- err = ev.WriteToFile(path.Join(*args.FailedRequestsInDir, fileName))
- if err != nil {
- t.Error(err)
- }
- if err := rater.Call(utils.APIerSv1ReplayFailedPosts, &args, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply: ", reply)
- }
- if _, err := os.Stat(fileInPath); !os.IsNotExist(err) {
- t.Error("InFile still exists")
- }
- if _, err := os.Stat(path.Join(*args.FailedRequestsOutDir, fileName)); !os.IsNotExist(err) {
- t.Error("OutFile created")
- }
- // connect to RabbitMQ server and check if the content was posted there
- conn, err := amqp.Dial("amqp://guest:guest@localhost:5672/")
- if err != nil {
- t.Fatal(err)
- }
- defer conn.Close()
- ch, err := conn.Channel()
- if err != nil {
- t.Fatal(err)
- }
- defer ch.Close()
- q, err := ch.QueueDeclare("cgrates_cdrs", true, false, false, false, nil)
- if err != nil {
- t.Fatal(err)
- }
- msgs, err := ch.Consume(q.Name, utils.EmptyString, true, false, false, false, nil)
- if err != nil {
- t.Fatal(err)
- }
- select {
- case d := <-msgs:
- var rcvCDR map[string]string
- if err := json.Unmarshal(d.Body, &rcvCDR); err != nil {
- t.Error(err)
- }
- if rcvCDR[utils.CGRID] != "88ed9c38005f07576a1e1af293063833b60edcc6" {
- t.Errorf("Unexpected CDR received: %+v", rcvCDR)
- }
- case <-time.After(100 * time.Millisecond):
- t.Error("No message received from RabbitMQ")
- }
- for _, dir := range []string{*args.FailedRequestsInDir, *args.FailedRequestsOutDir} {
- if err := os.RemoveAll(dir); err != nil {
- t.Errorf("Error %s removing folder: %s", err, dir)
- }
- }
-}
-
-func testApierGetDataDBVesions(t *testing.T) {
- var reply *engine.Versions
- if err := rater.Call(utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(engine.CurrentDataDBVersions(), *reply) {
- t.Errorf("Expecting : %+v, received: %+v", engine.CurrentDataDBVersions(), *reply)
- }
-}
-
-func testApierGetStorDBVesions(t *testing.T) {
- var reply *engine.Versions
- if err := rater.Call(utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(engine.CurrentStorDBVersions(), *reply) {
- t.Errorf("Expecting : %+v, received: %+v", engine.CurrentStorDBVersions(), *reply)
- }
-}
-
-func testApierBackwardsCompatible(t *testing.T) {
- var reply string
- if err := rater.Call("ApierV1.Ping", new(utils.CGREvent), &reply); err != nil {
- t.Error(err)
- } else if reply != utils.Pong {
- t.Errorf("Expecting : %+v, received: %+v", utils.Pong, reply)
- }
-}
-
-// Simply kill the engine after we are done with tests within this file
-func testApierStopEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/attributes.go b/apier/v1/attributes.go
deleted file mode 100644
index 68ee2bf02..000000000
--- a/apier/v1/attributes.go
+++ /dev/null
@@ -1,184 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetAttributeProfile returns an Attribute Profile
-func (apierSv1 *APIerSv1) GetAttributeProfile(arg *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) (err 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
- }
- var alsPrf *engine.AttributeProfile
- if alsPrf, err = apierSv1.DataManager.GetAttributeProfile(context.TODO(), tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return
- }
- *reply = *alsPrf
- return nil
-}
-
-// GetAttributeProfileIDs returns list of attributeProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetAttributeProfileIDs(args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.AttributeProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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
-}
-
-// GetAttributeProfileIDsCount sets in reply var the total number of AttributeProfileIDs registered for a tenant
-// returns ErrNotFound in case of 0 AttributeProfileIDs
-func (apierSv1 *APIerSv1) GetAttributeProfileIDsCount(args *utils.TenantWithAPIOpts, reply *int) (err error) {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- var keys []string
- prfx := utils.AttributeProfilePrefix + tnt + utils.ConcatenatedKeySep
- if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), prfx); err != nil {
- return err
- }
- if len(keys) == 0 {
- return utils.ErrNotFound
- }
- *reply = len(keys)
- return
-}
-
-//SetAttributeProfile add/update a new Attribute Profile
-func (apierSv1 *APIerSv1) SetAttributeProfile(alsWrp *engine.AttributeProfileWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(alsWrp.AttributeProfile, []string{utils.ID, utils.Attributes}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if alsWrp.Tenant == utils.EmptyString {
- alsWrp.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- for _, attr := range alsWrp.Attributes {
- if attr.Path == utils.EmptyString {
- return utils.NewErrMandatoryIeMissing("Path")
- }
- for _, sub := range attr.Value {
- if sub.Rules == utils.EmptyString {
- return utils.NewErrMandatoryIeMissing("Rules")
- }
- if err := sub.Compile(); err != nil {
- return utils.NewErrServerError(err)
- }
- }
- }
- if err := apierSv1.DataManager.SetAttributeProfile(context.TODO(), alsWrp.AttributeProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheAttributeProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
-
- if err := apierSv1.CallCache(utils.IfaceAsString(alsWrp.APIOpts[utils.CacheOpt]), alsWrp.Tenant, utils.CacheAttributeProfiles,
- alsWrp.TenantID(), &alsWrp.FilterIDs, alsWrp.Contexts, alsWrp.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//RemoveAttributeProfile remove a specific Attribute Profile
-func (apierSv1 *APIerSv1) RemoveAttributeProfile(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.RemoveAttributeProfile(context.TODO(), 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(context.TODO(), map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheAttributeProfiles,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// NewAttributeSv1 returns the RPC Object for AttributeS
-func NewAttributeSv1(attrS *engine.AttributeService) *AttributeSv1 {
- return &AttributeSv1{attrS: attrS}
-}
-
-// AttributeSv1 exports RPC from RLs
-type AttributeSv1 struct {
- attrS *engine.AttributeService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (alSv1 *AttributeSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(alSv1, serviceMethod, args, reply)
-}
-
-// GetAttributeForEvent returns matching AttributeProfile for Event
-func (alSv1 *AttributeSv1) GetAttributeForEvent(args *engine.AttrArgsProcessEvent,
- reply *engine.AttributeProfile) (err error) {
- return alSv1.attrS.V1GetAttributeForEvent(context.TODO(), args, reply)
-}
-
-// ProcessEvent will replace event fields with the ones in matching AttributeProfile
-func (alSv1 *AttributeSv1) ProcessEvent(args *engine.AttrArgsProcessEvent,
- reply *engine.AttrSProcessEventReply) error {
- return alSv1.attrS.V1ProcessEvent(context.TODO(), args, reply)
-}
-
-// Ping return pong if the service is active
-func (alSv1 *AttributeSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/attributes_it_test.go b/apier/v1/attributes_it_test.go
deleted file mode 100644
index 03b01b9ca..000000000
--- a/apier/v1/attributes_it_test.go
+++ /dev/null
@@ -1,2039 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- alsPrfCfgPath string
- alsPrfCfg *config.CGRConfig
- attrSRPC *rpc.Client
- alsPrf *engine.AttributeProfileWithAPIOpts
- alsPrfConfigDIR string //run tests for specific configuration
-
- sTestsAlsPrf = []func(t *testing.T){
- testAttributeSInitCfg,
- testAttributeSInitDataDb,
- testAttributeSResetStorDb,
- testAttributeSStartEngine,
- testAttributeSRPCConn,
- testAttributeSLoadFromFolder,
- testAttributeSGetAttributeForEvent,
- testAttributeSGetAttributeForEventNotFound,
- testAttributeSGetAttributeForEventWithMetaAnyContext,
- testAttributeSProcessEvent,
- testAttributeSProcessEventNotFound,
- testAttributeSProcessEventMissing,
- testAttributeSProcessEventWithNoneSubstitute,
- testAttributeSProcessEventWithNoneSubstitute2,
- testAttributeSProcessEventWithNoneSubstitute3,
- testAttributeSProcessEventWithHeader,
- testAttributeSGetAttPrfIDs,
- testAttributeSSetAlsPrfBrokenReference,
- testAttributeSGetAlsPrfBeforeSet,
- testAttributeSSetAlsPrf,
- testAttributeSUpdateAlsPrf,
- testAttributeSRemAlsPrf,
- testAttributeSSetAlsPrf2,
- testAttributeSSetAlsPrf3,
- testAttributeSSetAlsPrf4,
- testAttributeSPing,
- testAttributeSProcessEventWithSearchAndReplace,
- testAttributeSProcessWithMultipleRuns,
- testAttributeSProcessWithMultipleRuns2,
- testAttributeSGetAttributeProfileIDsCount,
- testAttributeSSetAttributeWithEmptyPath,
- testAttributeSSetAlsPrfWithoutTenant,
- testAttributeSRmvAlsPrfWithoutTenant,
- testAttributeSKillEngine,
- //start test for cache options
- testAttributeSInitCfg,
- testAttributeSInitDataDb,
- testAttributeSResetStorDb,
- testAttributeSStartEngine,
- testAttributeSRPCConn,
- testAttributeSCachingMetaNone,
- testAttributeSCachingMetaLoad,
- testAttributeSCachingMetaReload1,
- testAttributeSCachingMetaReload2,
- testAttributeSCachingMetaRemove,
- testAttributeSCacheOpts,
- testAttributeSKillEngine,
- //cache test
- testAttributeSInitCfg,
- testAttributeSInitDataDb,
- testAttributeSResetStorDb,
- testAttributeSStartEngine,
- testAttributeSRPCConn,
- testAttributeSCacheTestProcessEventNotFound,
- testAttributeSCacheTestSetProfile,
- testAttributeSCacheTestProcessEventNotFound,
- testAttributeSCacheTestReload,
- testAttributeSCacheTestProcessEventFound,
- testAttributeSKillEngine,
- }
-)
-
-//Test start here
-func TestAttributeSIT(t *testing.T) {
- attrsTests := sTestsAlsPrf
- switch *dbType {
- case utils.MetaInternal:
- attrsTests = sTestsAlsPrf[:29]
- alsPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- alsPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- alsPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range attrsTests {
- t.Run(alsPrfConfigDIR, stest)
- }
-}
-
-func testAttributeSInitCfg(t *testing.T) {
- var err error
- alsPrfCfgPath = path.Join(*dataDir, "conf", "samples", alsPrfConfigDIR)
- alsPrfCfg, err = config.NewCGRConfigFromPath(alsPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testAttributeSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(alsPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testAttributeSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(alsPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testAttributeSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(alsPrfCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testAttributeSRPCConn(t *testing.T) {
- var err error
- attrSRPC, err = newRPCClient(alsPrfCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testAttributeSGetAlsPrfBeforeSet(t *testing.T) {
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAttributeSLoadFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
- if err := attrSRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testAttributeSGetAttributeForEvent(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSGetAttributeForEvent",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.Destination: "+491511231234",
- },
- },
- }
-
- eAttrPrf := &engine.AttributeProfile{
- Tenant: ev.Tenant,
- ID: "ATTR_1",
- FilterIDs: []string{"*string:~*req.Account:1007"},
- Contexts: []string{utils.MetaCDRs, utils.MetaSessionS},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- Type: utils.MetaConstant,
- FilterIDs: []string{},
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- Type: utils.MetaConstant,
- FilterIDs: []string{},
- },
- },
- Weight: 10.0,
- }
- if *encoding == utils.MetaGOB {
- eAttrPrf.Attributes[0].FilterIDs = nil
- eAttrPrf.Attributes[1].FilterIDs = nil
- }
- eAttrPrf.Compile()
- var attrReply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent,
- ev, &attrReply); err != nil {
- t.Fatal(err)
- }
- attrReply.Compile() // Populate private variables in RSRParsers
- sort.Strings(attrReply.Contexts)
- if !reflect.DeepEqual(eAttrPrf, attrReply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eAttrPrf), utils.ToJSON(attrReply))
- }
-
- ev.Tenant = utils.EmptyString
- ev.ID = "randomID"
- if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent,
- ev, &attrReply); err != nil {
- t.Fatal(err)
- }
- attrReply.Compile() // Populate private variables in RSRParsers
- sort.Strings(attrReply.Contexts)
- if !reflect.DeepEqual(eAttrPrf, attrReply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eAttrPrf), utils.ToJSON(attrReply))
- }
-}
-
-func testAttributeSGetAttributeForEventNotFound(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaCDRs),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSGetAttributeForEventWihMetaAnyContext",
- Event: map[string]interface{}{
- utils.AccountField: "dan",
- utils.Destination: "+491511231234",
- },
- },
- }
- eAttrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: ev.Tenant,
- ID: "ATTR_3",
- FilterIDs: []string{"*string:~*req.Account:dan"},
- Contexts: []string{utils.MetaSessionS},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 10.0,
- },
- }
- eAttrPrf2.Compile()
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_3"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(eAttrPrf2.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", eAttrPrf2, reply)
- }
- var attrReply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent,
- ev, &attrReply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAttributeSGetAttributeForEventWithMetaAnyContext(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaCDRs),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSGetAttributeForEventWihMetaAnyContext",
- Event: map[string]interface{}{
- utils.AccountField: "dan",
- utils.Destination: "+491511231234",
- },
- },
- }
- eAttrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: ev.Tenant,
- ID: "ATTR_2",
- FilterIDs: []string{"*string:~*req.Account:dan"},
- Contexts: []string{utils.MetaAny},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 10.0,
- },
- }
- eAttrPrf2.Compile()
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_2"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(eAttrPrf2.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", eAttrPrf2.AttributeProfile, reply)
- }
- var attrReply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.AttributeSv1GetAttributeForEvent,
- ev, &attrReply); err != nil {
- t.Fatal(err)
- }
- attrReply.Compile()
- if !reflect.DeepEqual(eAttrPrf2.AttributeProfile, attrReply) {
- t.Errorf("Expecting: %s, received: %s", utils.ToJSON(eAttrPrf2.AttributeProfile), utils.ToJSON(attrReply))
- }
-}
-
-func testAttributeSProcessEvent(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.Destination: "+491511231234",
- },
- },
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_1"},
- AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.AccountField,
- utils.MetaReq + utils.NestingSep + utils.Subject},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Subject: "1001",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- } else {
- sort.Strings(eRply.AlteredFields)
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply, &rplyEv) { // second for reversed order of attributes
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
- }
-
- ev.Tenant = ""
- ev.ID = "randomID"
- eRply.ID = "randomID"
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- } else {
- sort.Strings(eRply.AlteredFields)
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply, &rplyEv) { // second for reversed order of attributes
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
- }
-}
-
-func testAttributeSProcessEventNotFound(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEventNotFound",
- Event: map[string]interface{}{
- utils.AccountField: "Inexistent",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAttributeSProcessEventMissing(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "NonExist",
- utils.Category: "*attributes",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err == nil ||
- err.Error() != "MANDATORY_IE_MISSING: [Category]" {
- t.Error(err)
- }
-}
-
-func testAttributeSProcessEventWithNoneSubstitute(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1008",
- utils.Destination: "+491511231234",
- },
- },
- }
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "AttributeWithNonSubstitute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1008"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{"*string:~*req.Account:1008"},
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile(utils.MetaRemove, utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"AttributeWithNonSubstitute"},
- AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.AccountField,
- utils.MetaReq + utils.NestingSep + utils.Subject},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
-
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- }
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply, &rplyEv) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
-}
-
-func testAttributeSProcessEventWithNoneSubstitute2(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1008",
- utils.Subject: "1008",
- utils.Destination: "+491511231234",
- },
- },
- }
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "AttributeWithNonSubstitute",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Account:1008"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{"*string:~*req.Account:1008"},
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile(utils.MetaRemove, utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"AttributeWithNonSubstitute"},
- AlteredFields: []string{"*req.Account", "*req.Subject"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- eRply2 := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"AttributeWithNonSubstitute"},
- AlteredFields: []string{utils.MetaReq + utils.NestingSep + utils.Subject,
- utils.MetaReq + utils.NestingSep + utils.AccountField},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eRply, &rplyEv) &&
- !reflect.DeepEqual(eRply2, &rplyEv) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
-}
-
-func testAttributeSProcessEventWithNoneSubstitute3(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1008",
- utils.Subject: "1001",
- utils.Destination: "+491511231234",
- },
- },
- }
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "AttributeWithNonSubstitute",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Account:1008"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{"*string:~*req.Account:1008"},
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- FilterIDs: []string{"*string:~*req.Subject:1008"},
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile(utils.MetaRemove, utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"AttributeWithNonSubstitute"},
- AlteredFields: []string{"*req.Account"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSWithNoneSubstitute",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Subject: "1001",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eRply, &rplyEv) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
-}
-
-func testAttributeSProcessEventWithHeader(t *testing.T) {
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_Header",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Field1:Value1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field2",
- Value: config.NewRSRParsersMustCompile("~*req.Field1", utils.InfieldSep),
- },
- },
- Blocker: true,
- Weight: 5,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- attrArgs := &engine.AttrArgsProcessEvent{
- ProcessRuns: utils.IntPointer(1),
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "HeaderEventForAttribute",
- Event: map[string]interface{}{
- "Field1": "Value1",
- },
- },
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_Header"},
- AlteredFields: []string{"*req.Field2"},
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "HeaderEventForAttribute",
- Event: map[string]interface{}{
- "Field1": "Value1",
- "Field2": "Value1",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- attrArgs, &rplyEv); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eRply, &rplyEv) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
-}
-
-func testAttributeSGetAttPrfIDs(t *testing.T) {
- expected := []string{"ATTR_2", "ATTR_PASS", "ATTR_1", "ATTR_3", "ATTR_Header", "AttributeWithNonSubstitute"}
- var result []string
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{
- Tenant: "cgrates.org",
- Paginator: utils.Paginator{Limit: utils.IntPointer(10)},
- }, &result); err != nil {
- t.Error(err)
- } else if 10 < len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testAttributeSSetAlsPrfBrokenReference(t *testing.T) {
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ApierTest",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"FLTR_ACNT_danBroken", "FLTR_DST_DEBroken"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: config.NewRSRParsersMustCompile("Al1", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- var result string
- expErr := "SERVER_ERROR: broken reference to filter: FLTR_ACNT_danBroken for item with ID: cgrates.org:ApierTest"
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-}
-
-func testAttributeSSetAlsPrf(t *testing.T) {
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ApierTest",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: config.NewRSRParsersMustCompile("Al1", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
-}
-
-func testAttributeSUpdateAlsPrf(t *testing.T) {
- alsPrf.Attributes = []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: config.NewRSRParsersMustCompile("Al1", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + "FL2",
- Value: config.NewRSRParsersMustCompile("Al2", utils.InfieldSep),
- },
- }
- alsPrf.Compile()
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- sort.Strings(reply.FilterIDs)
- sort.Strings(alsPrf.AttributeProfile.FilterIDs)
- sort.Strings(reply.Contexts)
- sort.Strings(alsPrf.AttributeProfile.Contexts)
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
-}
-
-func testAttributeSRemAlsPrf(t *testing.T) {
- var resp string
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if alsPrfConfigDIR == "tutinternal" { // do not double remove the profile
- return
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // remove twice shoud return not found
- resp = ""
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &resp); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testAttributeSSetAlsPrf2(t *testing.T) {
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "golant",
- ID: "ATTR_972587832508_SESSIONAUTH",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Account:972587832508"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.RSRParsers{
- &config.RSRParser{
- Rules: "roam",
- },
- },
- },
- },
- Blocker: false,
- Weight: 10,
- },
- }
- alsPrf.Compile()
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "golant", ID: "ATTR_972587832508_SESSIONAUTH"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
-}
-
-func testAttributeSSetAlsPrf3(t *testing.T) {
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "golant",
- ID: "ATTR_972587832508_SESSIONAUTH",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:Account:972587832508"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.RSRParsers{
- &config.RSRParser{
- Rules: "",
- },
- },
- },
- },
- Blocker: false,
- Weight: 10,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil {
- t.Error(err)
- }
-}
-
-func testAttributeSSetAlsPrf4(t *testing.T) {
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "golant",
- ID: "ATTR_972587832508_SESSIONAUTH",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Account:972587832508"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.RSRParsers{
- &config.RSRParser{},
- },
- },
- },
- Blocker: false,
- Weight: 10,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err == nil {
- t.Error(err)
- }
-}
-
-func testAttributeSPing(t *testing.T) {
- var resp string
- if err := attrSRPC.Call(utils.AttributeSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testAttributeSProcessEventWithSearchAndReplace(t *testing.T) {
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_Search_and_replace",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Category:call"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Category",
- Value: config.NewRSRParsersMustCompile("~*req.Category:s/(.*)/${1}_suffix/", utils.InfieldSep),
- },
- },
- Blocker: true,
- Weight: 10,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- attrArgs := &engine.AttrArgsProcessEvent{
- ProcessRuns: utils.IntPointer(1),
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "HeaderEventForAttribute",
- Event: map[string]interface{}{
- "Category": "call",
- },
- },
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_Search_and_replace"},
- AlteredFields: []string{"*req.Category"},
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "HeaderEventForAttribute",
- Event: map[string]interface{}{
- "Category": "call_suffix",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- attrArgs, &rplyEv); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eRply, &rplyEv) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
-}
-
-func testAttributeSProcessWithMultipleRuns(t *testing.T) {
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- }
- attrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_2",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Field1:Value1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field2",
- Value: config.NewRSRParsersMustCompile("Value2", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- attrPrf3 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_3",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.NotFound:NotFound"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field3",
- Value: config.NewRSRParsersMustCompile("Value3", utils.InfieldSep),
- },
- },
- Weight: 30,
- },
- }
- // Add attribute in DM
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf3, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- attrArgs := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- ProcessRuns: utils.IntPointer(4),
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: utils.GenUUID(),
- Event: map[string]interface{}{
- "InitialField": "InitialValue",
- },
- },
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_1", "ATTR_2"},
- AlteredFields: []string{"*req.Field1", "*req.Field2"},
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: utils.GenUUID(),
- Event: map[string]interface{}{
- "InitialField": "InitialValue",
- "Field1": "Value1",
- "Field2": "Value2",
- },
- },
- }
-
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- attrArgs, &rplyEv); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(eRply.MatchedProfiles, rplyEv.MatchedProfiles) {
- t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, rplyEv.MatchedProfiles)
- }
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply.AlteredFields, rplyEv.AlteredFields) {
- t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, rplyEv.AlteredFields)
- } else if !reflect.DeepEqual(eRply.CGREvent.Event, rplyEv.CGREvent.Event) {
- t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, rplyEv.CGREvent.Event)
- }
-}
-
-func testAttributeSProcessWithMultipleRuns2(t *testing.T) {
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- }
- attrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_2",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Field1:Value1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field2",
- Value: config.NewRSRParsersMustCompile("Value2", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- attrPrf3 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_3",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Field2:Value2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field3",
- Value: config.NewRSRParsersMustCompile("Value3", utils.InfieldSep),
- },
- },
- Weight: 30,
- },
- }
- // Add attributeProfiles
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf3, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- attrArgs := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- ProcessRuns: utils.IntPointer(4),
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: utils.GenUUID(),
- Event: map[string]interface{}{
- "InitialField": "InitialValue",
- },
- },
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_1", "ATTR_2", "ATTR_3", "ATTR_2"},
- AlteredFields: []string{"*req.Field1", "*req.Field2", "*req.Field3"},
- CGREvent: &utils.CGREvent{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: utils.GenUUID(),
- Event: map[string]interface{}{
- "InitialField": "InitialValue",
- "Field1": "Value1",
- "Field2": "Value2",
- "Field3": "Value3",
- },
- },
- }
-
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- attrArgs, &rplyEv); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(eRply.MatchedProfiles, rplyEv.MatchedProfiles) {
- t.Errorf("Expecting %+v, received: %+v", eRply.MatchedProfiles, rplyEv.MatchedProfiles)
- }
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply.AlteredFields, rplyEv.AlteredFields) {
- t.Errorf("Expecting %+v, received: %+v", eRply.AlteredFields, rplyEv.AlteredFields)
- } else if !reflect.DeepEqual(eRply.CGREvent.Event, rplyEv.CGREvent.Event) {
- t.Errorf("Expecting %+v, received: %+v", eRply.CGREvent.Event, rplyEv.CGREvent.Event)
- }
-}
-
-func testAttributeSGetAttributeProfileIDsCount(t *testing.T) {
- var reply int
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{}, &reply); err != nil {
- t.Error(err)
- } else if reply != 7 {
- t.Errorf("Expecting: 7, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 7 {
- t.Errorf("Expecting: 7, received: %+v", reply)
- }
- var resp string
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ATTR_1",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 6 {
- t.Errorf("Expecting: 6, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ATTR_2",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 5 {
- t.Errorf("Expecting: 5, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ATTR_3",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 4 {
- t.Errorf("Expecting: 4, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ATTR_Header",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 3 {
- t.Errorf("Expecting: 3, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ATTR_PASS",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 2 {
- t.Errorf("Expecting: 2, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ATTR_Search_and_replace",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if reply != 1 {
- t.Errorf("Expecting: 1, received: %+v", reply)
- }
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "AttributeWithNonSubstitute",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAttributeSKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-//Start tests for caching
-func testAttributeSCachingMetaNone(t *testing.T) {
- //*none option should not add attribute in cache only in Datamanager
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply bool
- argsCache := utils.ArgsGetCacheItem{
- CacheID: utils.CacheAttributeProfiles,
- ItemID: "cgrates.org:ATTR_1",
- }
- if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: false, received:%v", reply)
- }
-
- var rcvKeys []string
- argsCache2 := utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheAttributeProfiles,
- }
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ",
- utils.ErrNotFound, err.Error(), rcvKeys)
- }
-
- //check in dataManager
- expected := []string{"ATTR_1"}
- var rcvIDs []string
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, rcvIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
- }
-}
-
-func testAttributeSCachingMetaLoad(t *testing.T) {
- //*load option should add attribute in cache and in Datamanager
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaLoad,
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply bool
- argsCache := utils.ArgsGetCacheItem{
- CacheID: utils.CacheAttributeProfiles,
- ItemID: "cgrates.org:ATTR_1",
- }
- if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil {
- t.Error(err)
- } else if !reply {
- t.Errorf("Expected: true, received:%v", reply)
- }
-
- var rcvKeys []string
- expectedIDs := []string{"cgrates.org:ATTR_1"}
- argsCache2 := utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheAttributeProfiles,
- }
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rcvKeys, expectedIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys)
- }
-
- rcvKeys = nil
- argsCache2 = utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheAttributeFilterIndexes,
- }
- expectedIDs = []string{"cgrates.org:*sessions:*string:*req.InitialField:InitialValue"}
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rcvKeys, expectedIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys)
- }
-
- //check in dataManager
- expected := []string{"ATTR_1"}
- var rcvIDs []string
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, rcvIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
- }
- //remove from cache and DataManager the profile
- var resp string
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: attrPrf1.Tenant, ID: attrPrf1.ID},
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- }}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-
- argsCache = utils.ArgsGetCacheItem{
- CacheID: utils.CacheAttributeProfiles,
- ItemID: "cgrates.org:ATTR_1",
- }
- if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: false, received:%v", reply)
- }
-
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ",
- utils.ErrNotFound, err, rcvKeys)
- }
-
- //check in dataManager
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ",
- utils.ErrNotFound, err, rcvIDs)
- }
-}
-
-func testAttributeSCachingMetaReload1(t *testing.T) {
- //*reload add the attributes in cache if was there before
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaReload,
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply bool
- argsCache := utils.ArgsGetCacheItem{
- CacheID: utils.CacheAttributeProfiles,
- ItemID: "cgrates.org:ATTR_1",
- }
- if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: false, received:%v", reply)
- }
-
- var rcvKeys []string
- argsCache2 := utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheAttributeProfiles,
- }
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ",
- utils.ErrNotFound, err, rcvKeys)
- }
-
- //check in dataManager
- expected := []string{"ATTR_1"}
- var rcvIDs []string
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, rcvIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
- }
-}
-
-func testAttributeSCachingMetaReload2(t *testing.T) {
- //add cache with *load option
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaLoad,
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &reply); err != nil {
- t.Fatal(err)
- }
- attrPrf1.Compile()
- reply.Compile()
- if !reflect.DeepEqual(attrPrf1.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", attrPrf1.AttributeProfile, reply)
- }
-
- //add cache with *reload option
- // should overwrite the first
- attrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Test:Test"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaReload,
- },
- }
- // set the profile
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}}, &reply); err != nil {
- t.Fatal(err)
- }
- attrPrf2.Compile()
- reply.Compile()
- if !reflect.DeepEqual(attrPrf2.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", attrPrf2.AttributeProfile, reply)
- }
-}
-
-func testAttributeSCachingMetaRemove(t *testing.T) {
- //add cache with *load option
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaLoad,
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply bool
- argsCache := utils.ArgsGetCacheItem{
- CacheID: utils.CacheAttributeProfiles,
- ItemID: "cgrates.org:ATTR_1",
- }
- if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil {
- t.Error(err)
- } else if !reply {
- t.Errorf("Expected: true, received:%v", reply)
- }
-
- var rcvKeys []string
- expectedIDs := []string{"cgrates.org:ATTR_1"}
- argsCache2 := utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheAttributeProfiles,
- }
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rcvKeys, expectedIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expectedIDs, rcvKeys)
- }
-
- // add with *remove cache option
- // should delete it from cache
- attrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Test:Test"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaRemove,
- },
- }
- // set the profile
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- if err := attrSRPC.Call(utils.CacheSv1HasItem, argsCache, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: false, received:%v", reply)
- }
-
- if err := attrSRPC.Call(utils.CacheSv1GetItemIDs, argsCache2, &rcvKeys); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ",
- utils.ErrNotFound, err.Error(), rcvKeys)
- }
-
- //check in dataManager
- expected := []string{"ATTR_1"}
- var rcvIDs []string
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &rcvIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, rcvIDs) {
- t.Errorf("Expecting : %+v, received: %+v", expected, rcvIDs)
- }
-
-}
-
-func testAttributeSSetAttributeWithEmptyPath(t *testing.T) {
- eAttrPrf2 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ATTR_3",
- FilterIDs: []string{"*string:~*req.Account:dan"},
- Contexts: []string{utils.MetaSessionS},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 1, 14, 0, 0, 0, 0, time.UTC)},
- Attributes: []*engine.Attribute{
- {
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 10.0,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, eAttrPrf2, &result); err == nil {
- t.Errorf("Expected error received nil")
- }
-}
-
-func testAttributeSCacheOpts(t *testing.T) {
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_WITH_OPTS",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.InitialField:InitialValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- "Method": "SetAttributeProfile",
- "CustomField": "somethingCustom",
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) {
- var reply string
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- ID: "ApierTest1",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: config.NewRSRParsersMustCompile("Al1", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- alsPrf.AttributeProfile.Tenant = "cgrates.org"
- var result *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ApierTest1"}},
- &result); err != nil {
- t.Error(err)
- } else if result.Compile(); !reflect.DeepEqual(alsPrf.AttributeProfile, result) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(alsPrf.AttributeProfile), utils.ToJSON(result))
- }
-}
-
-func testAttributeSRmvAlsPrfWithoutTenant(t *testing.T) {
- var reply string
- if err := attrSRPC.Call(utils.APIerSv1RemoveAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ApierTest1"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ApierTest1"}},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAttributeSCacheTestProcessEventNotFound(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- AttributeIDs: []string{"ATTR_CACHE"},
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testAttributeSCacheTestProcessEventFound(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{},
- },
- AttributeIDs: []string{"ATTR_CACHE"},
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := attrSRPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- }
-}
-
-func testAttributeSCacheTestSetProfile(t *testing.T) {
- //*none option should not add attribute in cache only in Datamanager
- attrPrf1 := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: config.CgrConfig().GeneralCfg().DefaultTenant,
- ID: "ATTR_CACHE",
- Contexts: []string{utils.MetaSessionS},
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Field1",
- Value: config.NewRSRParsersMustCompile("Value1", utils.InfieldSep),
- },
- },
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- // set the profile
- var result string
- if err := attrSRPC.Call(utils.APIerSv1SetAttributeProfile, attrPrf1, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
-}
-
-func testAttributeSCacheTestReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.AttributeProfileIDs: {"cgrates.org:ATTR_CACHE"},
- },
- }
- var reply string
- if err := attrSRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/cache_replication_it_test.go b/apier/v1/cache_replication_it_test.go
deleted file mode 100644
index 74d113561..000000000
--- a/apier/v1/cache_replication_it_test.go
+++ /dev/null
@@ -1,244 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-
- "github.com/cgrates/cgrates/config"
-)
-
-var (
- engine1Cfg *config.CGRConfig
- engine1RPC *rpc.Client
- engine1CfgPath string
- engine2Cfg *config.CGRConfig
- engine2RPC *rpc.Client
- engine2CfgPath string
-
- sTestsCacheSReplicate = []func(t *testing.T){
- testCacheSReplicateLoadConfig,
- testCacheSReplicateInitDataDb,
- testCacheSReplicateInitStorDb,
- testCacheSReplicateStartEngine,
- testCacheSReplicateRpcConn,
- testCacheSReplicateLoadTariffPlanFromFolder,
- testCacheSReplicateProcessAttributes,
- testCacheSReplicateProcessRateProfile,
- testCacheSReplicateStopEngine,
- }
-)
-
-func TestCacheSv1ReplicateIT(t *testing.T) {
- for _, stest := range sTestsCacheSReplicate {
- t.Run("TestCacheSv1ReplicateIT", stest)
- }
-}
-
-func testCacheSReplicateLoadConfig(t *testing.T) {
- var err error
- engine1CfgPath = path.Join(*dataDir, "conf", "samples", "replication_cache", "engine1")
- if engine1Cfg, err = config.NewCGRConfigFromPath(engine1CfgPath); err != nil {
- t.Error(err)
- }
- engine2CfgPath = path.Join(*dataDir, "conf", "samples", "replication_cache", "engine2")
- if engine2Cfg, err = config.NewCGRConfigFromPath(engine2CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testCacheSReplicateInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(engine1Cfg); err != nil {
- t.Fatal(err)
- }
- if err := engine.InitDataDB(engine2Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Empty tables before using them
-func testCacheSReplicateInitStorDb(t *testing.T) {
- if err := engine.InitStorDB(engine1Cfg); err != nil {
- t.Fatal(err)
- }
- if err := engine.InitStorDB(engine2Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start engine
-func testCacheSReplicateStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(engine1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(engine2CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testCacheSReplicateRpcConn(t *testing.T) {
- var err error
- engine1RPC, err = newRPCClient(engine1Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to RPC: ", err.Error())
- }
- engine2RPC, err = newRPCClient(engine2Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to RPC: ", err.Error())
- }
-}
-
-func testCacheSReplicateLoadTariffPlanFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")}
- if err := engine2RPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond)
-}
-
-func testCacheSReplicateProcessAttributes(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testCacheSReplicateProcessAttributes",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- },
- },
- }
- eRply := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{utils.MetaReq + utils.NestingSep + "OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testCacheSReplicateProcessAttributes",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- "OfficeGroup": "Marketing",
- },
- APIOpts: map[string]interface{}{},
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := engine1RPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- } else {
- sort.Strings(eRply.AlteredFields)
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply, &rplyEv) { // second for reversed order of attributes
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
- }
- if err := engine2RPC.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- } else {
- sort.Strings(eRply.AlteredFields)
- sort.Strings(rplyEv.AlteredFields)
- if !reflect.DeepEqual(eRply, &rplyEv) { // second for reversed order of attributes
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eRply), utils.ToJSON(rplyEv))
- }
- }
-}
-
-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/caches.go b/apier/v1/caches.go
deleted file mode 100644
index 64ea926a1..000000000
--- a/apier/v1/caches.go
+++ /dev/null
@@ -1,134 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
- "github.com/cgrates/ltcache"
-)
-
-func NewCacheSv1(cacheS *engine.CacheS) *CacheSv1 {
- return &CacheSv1{cacheS: cacheS}
-}
-
-// CacheSv1 exports RPC from CacheS
-type CacheSv1 struct {
- cacheS *engine.CacheS
-}
-
-// GetItemIDs returns the IDs for cacheID with given prefix
-func (chSv1 *CacheSv1) GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts,
- reply *[]string) error {
- return chSv1.cacheS.V1GetItemIDs(args, reply)
-}
-
-// HasItem verifies the existence of an Item in cache
-func (chSv1 *CacheSv1) HasItem(args *utils.ArgsGetCacheItemWithAPIOpts,
- reply *bool) error {
- return chSv1.cacheS.V1HasItem(args, reply)
-}
-
-// GetItemExpiryTime returns the expiryTime for an item
-func (chSv1 *CacheSv1) GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts,
- reply *time.Time) error {
- return chSv1.cacheS.V1GetItemExpiryTime(args, reply)
-}
-
-// RemoveItem removes the Item with ID from cache
-func (chSv1 *CacheSv1) RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts,
- reply *string) error {
- return chSv1.cacheS.V1RemoveItem(args, reply)
-}
-
-// RemoveItems removes the Items with ID from cache
-func (chSv1 *CacheSv1) RemoveItems(args utils.AttrReloadCacheWithAPIOpts,
- reply *string) error {
- return chSv1.cacheS.V1RemoveItems(args, reply)
-}
-
-// Clear will clear partitions in the cache (nil fol all, empty slice for none)
-func (chSv1 *CacheSv1) Clear(args *utils.AttrCacheIDsWithAPIOpts,
- reply *string) error {
- return chSv1.cacheS.V1Clear(args, reply)
-}
-
-// GetCacheStats returns CacheStats filtered by cacheIDs
-func (chSv1 *CacheSv1) GetCacheStats(args *utils.AttrCacheIDsWithAPIOpts,
- rply *map[string]*ltcache.CacheStats) error {
- return chSv1.cacheS.V1GetCacheStats(args, rply)
-}
-
-// PrecacheStatus checks status of active precache processes
-func (chSv1 *CacheSv1) PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, rply *map[string]string) error {
- return chSv1.cacheS.V1PrecacheStatus(args, rply)
-}
-
-// HasGroup checks existence of a group in cache
-func (chSv1 *CacheSv1) HasGroup(args *utils.ArgsGetGroupWithAPIOpts,
- rply *bool) (err error) {
- return chSv1.cacheS.V1HasGroup(args, rply)
-}
-
-// GetGroupItemIDs returns a list of itemIDs in a cache group
-func (chSv1 *CacheSv1) GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts,
- rply *[]string) (err error) {
- return chSv1.cacheS.V1GetGroupItemIDs(args, rply)
-}
-
-// RemoveGroup will remove a group and all items belonging to it from cache
-func (chSv1 *CacheSv1) RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts,
- rply *string) (err error) {
- return chSv1.cacheS.V1RemoveGroup(args, rply)
-}
-
-// ReloadCache reloads cache from DB for a prefix or completely
-func (chSv1 *CacheSv1) ReloadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) {
- return chSv1.cacheS.V1ReloadCache(*args, reply)
-}
-
-// LoadCache loads cache from DB for a prefix or completely
-func (chSv1 *CacheSv1) LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) {
- return chSv1.cacheS.V1LoadCache(*args, reply)
-}
-
-// Ping used to determinate if component is active
-func (chSv1 *CacheSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// ReplicateSet replicate an item
-func (chSv1 *CacheSv1) ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) {
- return chSv1.cacheS.V1ReplicateSet(args, reply)
-}
-
-// ReplicateRemove remove an item
-func (chSv1 *CacheSv1) ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) {
- return chSv1.cacheS.V1ReplicateRemove(args, reply)
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (chSv1 *CacheSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(chSv1, serviceMethod, args, reply)
-}
diff --git a/apier/v1/caches_it_test.go b/apier/v1/caches_it_test.go
deleted file mode 100644
index bcad35602..000000000
--- a/apier/v1/caches_it_test.go
+++ /dev/null
@@ -1,470 +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"
- "github.com/cgrates/ltcache"
-)
-
-var (
- chcCfg *config.CGRConfig
- chcRPC *rpc.Client
- chcCfgPath string
- cacheConfigDIR string
-
- sTestsCacheSV1 = []func(t *testing.T){
- testCacheSLoadConfig,
- testCacheSInitDataDb,
- testCacheSInitStorDb,
- testCacheSStartEngine,
- testCacheSRpcConn,
- testCacheSLoadTariffPlanFromFolder,
- testCacheSAfterLoadFromFolder,
- testCacheSFlush,
- testCacheSReload,
- testCacheSGetItemIDs,
- testCacheSHasItem,
- testCacheSGetItemExpiryTime,
- testCacheSReloadCache,
- testCacheSRemoveItem,
- testCacheSRemoveItems,
- testCacheSClear,
- testCacheSReload,
- testCacheSPrecacheStatus,
- testCacheSPing,
- testCacheSStopEngine,
- }
-)
-
-// Test start here
-func TestCacheSv1IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- cacheConfigDIR = "tutmysql"
- case utils.MetaMongo:
- cacheConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsCacheSV1 {
- t.Run(cacheConfigDIR, stest)
- }
-}
-
-func testCacheSLoadConfig(t *testing.T) {
- var err error
- chcCfgPath = path.Join(*dataDir, "conf", "samples", "precache", cacheConfigDIR)
- if chcCfg, err = config.NewCGRConfigFromPath(chcCfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testCacheSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(chcCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Empty tables before using them
-func testCacheSInitStorDb(t *testing.T) {
- if err := engine.InitStorDB(chcCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start engine
-func testCacheSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(chcCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testCacheSRpcConn(t *testing.T) {
- var err error
- chcRPC, err = newRPCClient(chcCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to RPC: ", err.Error())
- }
-}
-
-func testCacheSLoadTariffPlanFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")}
- if err := chcRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond)
-}
-
-func testCacheSAfterLoadFromFolder(t *testing.T) {
- var rcvStats map[string]*ltcache.CacheStats
- expStats := engine.GetDefaultEmptyCacheStats()
- expStats[utils.CacheAccountActionPlans].Items = 3
- expStats[utils.CacheActionPlans].Items = 7
- expStats[utils.CacheActions].Items = 5
- expStats[utils.CacheDestinations].Items = 3
- expStats[utils.CacheLoadIDs].Items = 17
- expStats[utils.CacheRPCConnections].Items = 2
- if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
- reply := ""
- // Simple test that command is executed without errors
- if err := chcRPC.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error(reply)
- }
- expStats[utils.CacheActionTriggers].Items = 1
- expStats[utils.CacheActions].Items = 13
- expStats[utils.CacheAttributeProfiles].Items = 1
- expStats[utils.CacheFilters].Items = 15
- expStats[utils.CacheRatingPlans].Items = 5
- expStats[utils.CacheRatingProfiles].Items = 5
- expStats[utils.CacheResourceProfiles].Items = 3
- expStats[utils.CacheResources].Items = 3
- expStats[utils.CacheReverseDestinations].Items = 5
- expStats[utils.CacheStatQueueProfiles].Items = 1
- expStats[utils.CacheStatQueues].Items = 1
- expStats[utils.CacheRouteProfiles].Items = 2
- expStats[utils.CacheThresholdProfiles].Items = 1
- expStats[utils.CacheThresholds].Items = 1
- expStats[utils.CacheLoadIDs].Items = 33
- expStats[utils.CacheTimings].Items = 12
- expStats[utils.CacheThresholdFilterIndexes].Items = 5
- expStats[utils.CacheThresholdFilterIndexes].Groups = 1
- expStats[utils.CacheStatFilterIndexes].Items = 2
- expStats[utils.CacheStatFilterIndexes].Groups = 1
- expStats[utils.CacheRouteFilterIndexes].Items = 2
- expStats[utils.CacheRouteFilterIndexes].Groups = 1
- expStats[utils.CacheResourceFilterIndexes].Items = 5
- expStats[utils.CacheResourceFilterIndexes].Groups = 1
- expStats[utils.CacheAttributeFilterIndexes].Items = 4
- expStats[utils.CacheAttributeFilterIndexes].Groups = 1
- expStats[utils.CacheReverseFilterIndexes].Items = 10
- expStats[utils.CacheReverseFilterIndexes].Groups = 7
-
- if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v,\n received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
-}
-
-func testCacheSFlush(t *testing.T) {
- reply := ""
- if err := chcRPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: nil,
- }, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
- var rcvStats map[string]*ltcache.CacheStats
- expStats := engine.GetDefaultEmptyCacheStats()
- if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
-}
-
-func testCacheSReload(t *testing.T) {
- var rcvStats map[string]*ltcache.CacheStats
- expStats := engine.GetDefaultEmptyCacheStats()
- reply := ""
- // Simple test that command is executed without errors
- if err := chcRPC.Call(utils.CacheSv1LoadCache, utils.NewAttrReloadCacheWithOpts(), &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error(reply)
- }
- expStats[utils.CacheAccountActionPlans].Items = 3
- expStats[utils.CacheActionPlans].Items = 7
- expStats[utils.CacheActions].Items = 6
- expStats[utils.CacheDestinations].Items = 3
- expStats[utils.CacheActionTriggers].Items = 1
- expStats[utils.CacheActions].Items = 13
- expStats[utils.CacheAttributeProfiles].Items = 1
- expStats[utils.CacheFilters].Items = 15
- expStats[utils.CacheRatingPlans].Items = 5
- expStats[utils.CacheRatingProfiles].Items = 5
- expStats[utils.CacheResourceProfiles].Items = 3
- expStats[utils.CacheResources].Items = 3
- expStats[utils.CacheReverseDestinations].Items = 5
- expStats[utils.CacheStatQueueProfiles].Items = 1
- expStats[utils.CacheStatQueues].Items = 1
- expStats[utils.CacheRouteProfiles].Items = 2
- expStats[utils.CacheThresholdProfiles].Items = 1
- expStats[utils.CacheThresholds].Items = 1
- expStats[utils.CacheLoadIDs].Items = 33
- expStats[utils.CacheTimings].Items = 12
- expStats[utils.CacheThresholdFilterIndexes].Items = 5
- expStats[utils.CacheThresholdFilterIndexes].Groups = 1
- expStats[utils.CacheStatFilterIndexes].Items = 2
- expStats[utils.CacheStatFilterIndexes].Groups = 1
- expStats[utils.CacheRouteFilterIndexes].Items = 2
- expStats[utils.CacheRouteFilterIndexes].Groups = 1
- expStats[utils.CacheResourceFilterIndexes].Items = 5
- expStats[utils.CacheResourceFilterIndexes].Groups = 1
- expStats[utils.CacheAttributeFilterIndexes].Items = 4
- expStats[utils.CacheAttributeFilterIndexes].Groups = 1
- expStats[utils.CacheReverseFilterIndexes].Items = 10
- expStats[utils.CacheReverseFilterIndexes].Groups = 7
-
- if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error(err)
- }
- rcvStats[utils.MetaAPIBan].Items = 0
- if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
-}
-
-func testCacheSGetItemIDs(t *testing.T) {
- var rcvKeys []string
- var expKeys []string
- argsAPI := utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheThresholdProfiles,
- ItemIDPrefix: "NotExistent",
- }
- if err := chcRPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), rcvKeys)
- }
-
- expKeys = []string{"cgrates.org:Threshold1"}
- argsAPI = utils.ArgsGetCacheItemIDs{
- CacheID: utils.CacheThresholdProfiles,
- }
- if err := chcRPC.Call(utils.CacheSv1GetItemIDs, argsAPI, &rcvKeys); err != nil {
- t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error())
- }
- if !reflect.DeepEqual(expKeys, rcvKeys) {
- t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys)
- }
-}
-
-func testCacheSHasItem(t *testing.T) {
- var reply bool
- var expected bool
- argsAPI := utils.ArgsGetCacheItem{
- CacheID: utils.CacheThresholdProfiles,
- ItemID: "NotExistent",
- }
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: %v , received:%v", expected, reply)
- }
-
- expected = true
- argsAPI = utils.ArgsGetCacheItem{
- CacheID: utils.CacheThresholdProfiles,
- ItemID: "cgrates.org:Threshold1",
- }
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if !reply {
- t.Errorf("Expected: %v , received:%v", expected, reply)
- }
-}
-
-func testCacheSGetItemExpiryTime(t *testing.T) {
- var reply time.Time
- var expected time.Time
- argsAPI := utils.ArgsGetCacheItem{
- CacheID: utils.CacheThresholdProfiles,
- ItemID: "NotExistent",
- }
- if err := chcRPC.Call(utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatalf("Expected error: %s received error: %s and reply: %v ", utils.ErrNotFound, err.Error(), reply)
- }
-
- // expected = true
- argsAPI = utils.ArgsGetCacheItem{
- CacheID: utils.CacheThresholdProfiles,
- ItemID: "cgrates.org:Threshold1",
- }
- if err := chcRPC.Call(utils.CacheSv1GetItemExpiryTime, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, reply) {
- t.Errorf("Expected: %v , received:%v", expected, reply)
- }
-}
-
-func testCacheSReloadCache(t *testing.T) {
- var reply string
- if err := chcRPC.Call(utils.CacheSv1ReloadCache, new(utils.AttrReloadCacheWithAPIOpts), &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
-
-func testCacheSRemoveItem(t *testing.T) {
- var reply bool
- argsAPI := utils.ArgsGetCacheItem{
- CacheID: utils.CacheThresholdProfiles,
- ItemID: "cgrates.org:Threshold1",
- }
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if !reply {
- t.Errorf("Expected: %v , received:%v", true, reply)
- }
- var remReply string
- if err := chcRPC.Call(utils.CacheSv1RemoveItem, argsAPI, &remReply); err != nil {
- t.Error(err)
- } else if remReply != utils.OK {
- t.Errorf("Expected: %v , received:%v", utils.OK, remReply)
- }
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: %v , received:%v", false, reply)
- }
-}
-
-func testCacheSRemoveItems(t *testing.T) {
- // var rcvKeys []string
- // expKeys := []string{"cgrates.org:Stats1"}
- // argsAPI2 := utils.ArgsGetCacheItemIDs{
- // CacheID: utils.CacheStatQueueProfiles,
- // }
- // if err := chcRPC.Call(utils.CacheSv1GetItemIDs, argsAPI2, &rcvKeys); err != nil {
- // t.Fatalf("Got error on APIerSv1.GetCacheStats: %s ", err.Error())
- // }
- // if !reflect.DeepEqual(expKeys, rcvKeys) {
- // t.Errorf("Expected: %+v, received: %+v", expKeys, rcvKeys)
- // }
- var reply bool
- argsAPI := utils.ArgsGetCacheItem{
- CacheID: utils.CacheStatQueueProfiles,
- ItemID: "cgrates.org:Stats1",
- }
-
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if !reply {
- t.Errorf("Expected: %v , received:%v", true, reply)
- }
- argsAPI = utils.ArgsGetCacheItem{
- CacheID: utils.CacheRouteProfiles,
- ItemID: "cgrates.org:ROUTE_1",
- }
-
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if !reply {
- t.Errorf("Expected: %v , received:%v", true, reply)
- }
- var remReply string
- if err := chcRPC.Call(utils.CacheSv1RemoveItems, utils.AttrReloadCacheWithAPIOpts{
- APIOpts: make(map[string]interface{}),
- Tenant: "cgrates.org",
- ArgsCache: map[string][]string{
- utils.StatsQueueProfileIDs: {"cgrates.org:Stats1"},
- utils.RouteProfileIDs: {"cgrates.org:ROUTE_1"},
- },
- }, &remReply); err != nil {
- t.Error(err)
- } else if remReply != utils.OK {
- t.Errorf("Expected: %v , received:%v", utils.OK, remReply)
- }
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: %v , received:%v", false, reply)
- }
-
- argsAPI = utils.ArgsGetCacheItem{
- CacheID: utils.CacheStatQueueProfiles,
- ItemID: "cgrates.org:Stats1",
- }
-
- if err := chcRPC.Call(utils.CacheSv1HasItem, argsAPI, &reply); err != nil {
- t.Error(err)
- } else if reply {
- t.Errorf("Expected: %v , received:%v", false, reply)
- }
-}
-
-func testCacheSClear(t *testing.T) {
- reply := ""
- if err := chcRPC.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
- var rcvStats map[string]*ltcache.CacheStats
- expStats := engine.GetDefaultEmptyCacheStats()
- if err := chcRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error("Got error on CacheSv1.GetCacheStats: ", err.Error())
- } else if !reflect.DeepEqual(expStats, rcvStats) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expStats), utils.ToJSON(rcvStats))
- }
-}
-
-func testCacheSPrecacheStatus(t *testing.T) {
- var reply map[string]string
- expected := make(map[string]string)
- for k := range utils.CachePartitions {
- expected[k] = utils.MetaReady
- }
- if err := chcRPC.Call(utils.CacheSv1PrecacheStatus, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil {
- t.Fatal(err)
- }
- reply[utils.MetaAPIBan] = utils.MetaReady // do not check the status for this partition
- if !reflect.DeepEqual(expected, reply) {
- t.Errorf("Expected: %v , received:%v", utils.ToJSON(expected), utils.ToJSON(reply))
- }
-}
-
-func testCacheSPing(t *testing.T) {
- var reply string
- expected := utils.Pong
- if err := chcRPC.Call(utils.CacheSv1Ping, &utils.CGREvent{}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expected, reply) {
- t.Errorf("Expected: %v , received:%v", utils.ToJSON(expected), utils.ToJSON(reply))
- }
-
-}
-
-func testCacheSStopEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/caps_it_test.go b/apier/v1/caps_it_test.go
deleted file mode 100644
index 38cdaa162..000000000
--- a/apier/v1/caps_it_test.go
+++ /dev/null
@@ -1,319 +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 (
- "bytes"
- "fmt"
- "io"
- "net/http"
- "net/rpc"
- "path"
- "strings"
- "sync"
- "testing"
- "time"
-
- "github.com/cenkalti/rpc2"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- capsCfgPath string
- capsCfg *config.CGRConfig
- capsRPC *rpc.Client
- capsBiRPC *rpc2.Client
- capsConfigDIR string //run tests for specific configuration
-
- sTestsCaps = []func(t *testing.T){
- testCapsInitCfg,
- testCapsStartEngine,
- testCapsRPCConn,
- testCapsBusyAPIs,
- testCapsQueueAPIs,
- testCapsOnHTTPBusy,
- testCapsOnHTTPQueue,
- testCapsOnBiJSONBusy,
- testCapsOnBiJSONQueue,
- testCapsKillEngine,
- }
-
- // used by benchmarks
- capsOnce sync.Once
- capsLastCfgDir string
-)
-
-//Test start here
-func TestCapsBusyJSON(t *testing.T) {
- capsConfigDIR = "caps_busy"
- for _, stest := range sTestsCaps {
- t.Run(capsConfigDIR, stest)
- }
-}
-
-func TestCapsQueueJSON(t *testing.T) {
- capsConfigDIR = "caps_queue"
- for _, stest := range sTestsCaps {
- t.Run(capsConfigDIR, stest)
- }
-}
-
-func testCapsInitCfg(t *testing.T) {
- var err error
- capsCfgPath = path.Join(*dataDir, "conf", "samples", capsConfigDIR)
- capsCfg, err = config.NewCGRConfigFromPath(capsCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-// Start CGR Engine
-func testCapsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(capsCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testCapsRPCConn(t *testing.T) {
- var err error
- capsRPC, err = newRPCClient(capsCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
- if capsBiRPC, err = utils.NewBiJSONrpcClient(capsCfg.SessionSCfg().ListenBijson,
- nil); err != nil {
- t.Fatal(err)
- }
-}
-
-func testCapsBusyAPIs(t *testing.T) {
- if capsConfigDIR != "caps_busy" {
- t.SkipNow()
- }
- var failedAPIs int
- wg := new(sync.WaitGroup)
- lock := new(sync.Mutex)
- for i := 0; i < 5; i++ {
- wg.Add(1)
- go func() {
- var resp string
- if err := capsRPC.Call(utils.CoreSv1Sleep,
- &utils.DurationArgs{Duration: 10 * time.Millisecond},
- &resp); err != nil {
- lock.Lock()
- failedAPIs++
- lock.Unlock()
- wg.Done()
- return
- }
- wg.Done()
- }()
- }
- wg.Wait()
- if failedAPIs < 2 {
- t.Errorf("Expected at leat 2 APIs to wait")
- }
-}
-
-func testCapsQueueAPIs(t *testing.T) {
- if capsConfigDIR != "caps_queue" {
- t.SkipNow()
- }
- wg := new(sync.WaitGroup)
- for i := 0; i < 5; i++ {
- wg.Add(1)
- go func() {
- var resp string
- if err := capsRPC.Call(utils.CoreSv1Sleep,
- &utils.DurationArgs{Duration: 10 * time.Millisecond},
- &resp); err != nil {
- wg.Done()
- t.Error(err)
- return
- }
- wg.Done()
- }()
- }
- wg.Wait()
-}
-
-func testCapsOnHTTPBusy(t *testing.T) {
- if capsConfigDIR != "caps_busy" {
- t.SkipNow()
- }
- var fldAPIs int64
- wg := new(sync.WaitGroup)
- lock := new(sync.Mutex)
- for i := 0; i < 5; i++ {
- wg.Add(1)
- go func(index int) {
- resp, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "CoreSv1.Sleep", "params": [{"Duration":10000000}], "id":%d}`, index))))
- if err != nil {
- wg.Done()
- t.Error(err)
- return
- }
- contents, err := io.ReadAll(resp.Body)
- if err != nil {
- wg.Done()
- t.Error(err)
- return
- }
- resp.Body.Close()
- if strings.Contains(string(contents), utils.ErrMaxConcurentRPCExceeded.Error()) {
- lock.Lock()
- fldAPIs++
- lock.Unlock()
- }
- wg.Done()
- return
- }(i)
- }
- wg.Wait()
- if fldAPIs < 2 {
- t.Errorf("Expected at leat 2 APIs to wait")
- }
-}
-
-func testCapsOnHTTPQueue(t *testing.T) {
- if capsConfigDIR != "caps_queue" {
- t.SkipNow()
- }
- wg := new(sync.WaitGroup)
- for i := 0; i < 5; i++ {
- wg.Add(1)
- go func(index int) {
- _, err := http.Post("http://localhost:2080/jsonrpc", "application/json", bytes.NewBuffer([]byte(fmt.Sprintf(`{"method": "CoreSv1.Sleep", "params": [{"Duration":10000000}], "id":%d}`, index))))
- if err != nil {
- wg.Done()
- t.Error(err)
- return
- }
- wg.Done()
- return
- }(i)
- }
- wg.Wait()
-}
-
-func testCapsOnBiJSONBusy(t *testing.T) {
- if capsConfigDIR != "caps_busy" {
- t.SkipNow()
- }
- var failedAPIs int
- wg := new(sync.WaitGroup)
- lock := new(sync.Mutex)
- for i := 0; i < 5; i++ {
- wg.Add(1)
- go func() {
- var resp string
- if err := capsBiRPC.Call(utils.SessionSv1Sleep,
- &utils.DurationArgs{Duration: 10 * time.Millisecond},
- &resp); err != nil {
- lock.Lock()
- failedAPIs++
- lock.Unlock()
- wg.Done()
- return
- }
- wg.Done()
- }()
- }
- wg.Wait()
- if failedAPIs < 2 {
- t.Errorf("Expected at leat 2 APIs to wait")
- }
-}
-
-func testCapsOnBiJSONQueue(t *testing.T) {
- if capsConfigDIR != "caps_queue" {
- t.SkipNow()
- }
- wg := new(sync.WaitGroup)
- for i := 0; i < 5; i++ {
- wg.Add(1)
- go func() {
- var resp string
- if err := capsBiRPC.Call(utils.SessionSv1Sleep,
- &utils.DurationArgs{Duration: 10 * time.Millisecond},
- &resp); err != nil {
- wg.Done()
- t.Error(err)
- return
- }
- wg.Done()
- }()
- }
- wg.Wait()
-}
-
-func testCapsKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func benchmarkInit(b *testing.B, cfgDir string) {
- b.StopTimer()
- // restart cgrates only if needed
- if cfgDir != capsLastCfgDir {
- capsOnce = sync.Once{}
- }
- capsOnce.Do(func() {
- capsLastCfgDir = cfgDir
- var err error
- capsCfgPath = path.Join(*dataDir, "conf", "samples", cfgDir)
- if capsCfg, err = config.NewCGRConfigFromPath(capsCfgPath); err != nil {
- b.Fatal(err)
- }
- if _, err := engine.StopStartEngine(capsCfgPath, *waitRater); err != nil {
- b.Fatal(err)
- }
- if capsRPC, err = newRPCClient(capsCfg.ListenCfg()); err != nil {
- b.Fatal(err)
- }
- // b.Logf("Preparation done for %s", cfgDir)
- })
- b.StartTimer()
-}
-
-func benchmarkCall(b *testing.B) {
- var rply map[string]interface{}
- for i := 0; i < b.N; i++ {
- if err := capsRPC.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil {
- b.Error(err)
- }
- }
-}
-
-func BenchmarkcapsWithLimit(b *testing.B) {
- benchmarkInit(b, "caps_queue_bench")
- benchmarkCall(b)
-}
-
-func BenchmarkcapsWithoutLimit(b *testing.B) {
- benchmarkInit(b, "tutmysql")
- benchmarkCall(b)
-}
diff --git a/apier/v1/cdrs.go b/apier/v1/cdrs.go
deleted file mode 100644
index b2075cf45..000000000
--- a/apier/v1/cdrs.go
+++ /dev/null
@@ -1,97 +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 (
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// Retrieves CDRs based on the filters
-func (apierSv1 *APIerSv1) GetCDRs(attrs *utils.AttrGetCdrs, reply *[]*engine.ExternalCDR) error {
- cdrsFltr, err := attrs.AsCDRsFilter(apierSv1.Config.GeneralCfg().DefaultTimezone)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if cdrs, _, err := apierSv1.CdrDb.GetCDRs(cdrsFltr, false); err != nil {
- return err
- } else if len(cdrs) == 0 {
- *reply = make([]*engine.ExternalCDR, 0)
- } else {
- for _, cdr := range cdrs {
- *reply = append(*reply, cdr.AsExternalCDR())
- }
- }
- return nil
-}
-
-// New way of removing CDRs
-func (apierSv1 *APIerSv1) RemoveCDRs(attrs *utils.RPCCDRsFilter, reply *string) error {
- cdrsFilter, err := attrs.AsCDRsFilter(apierSv1.Config.GeneralCfg().DefaultTimezone)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if _, _, err := apierSv1.CdrDb.GetCDRs(cdrsFilter, true); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-func NewCDRsV1(CDRs *engine.CDRServer) *CDRsV1 {
- return &CDRsV1{CDRs: CDRs}
-}
-
-// Receive CDRs via RPC methods
-type CDRsV1 struct {
- CDRs *engine.CDRServer
-}
-
-// ProcessCDR will process a CDR in CGRateS internal format
-func (cdrSv1 *CDRsV1) ProcessCDR(cdr *engine.CDRWithAPIOpts, reply *string) error {
- return cdrSv1.CDRs.V1ProcessCDR(cdr, reply)
-}
-
-// ProcessEvent will process an Event based on the flags attached
-func (cdrSv1 *CDRsV1) ProcessEvent(arg *engine.ArgV1ProcessEvent, reply *string) error {
- return cdrSv1.CDRs.V1ProcessEvent(arg, reply)
-}
-
-// ProcessExternalCDR will process a CDR in external format
-func (cdrSv1 *CDRsV1) ProcessExternalCDR(cdr *engine.ExternalCDRWithAPIOpts, reply *string) error {
- return cdrSv1.CDRs.V1ProcessExternalCDR(cdr, reply)
-}
-
-// RateCDRs can re-/rate remotely CDRs
-func (cdrSv1 *CDRsV1) RateCDRs(arg *engine.ArgRateCDRs, reply *string) error {
- return cdrSv1.CDRs.V1RateCDRs(arg, reply)
-}
-
-func (cdrSv1 *CDRsV1) GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error {
- return cdrSv1.CDRs.V1CountCDRs(args, reply)
-}
-
-func (cdrSv1 *CDRsV1) GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error {
- return cdrSv1.CDRs.V1GetCDRs(*args, reply)
-}
-
-func (cdrSv1 *CDRsV1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/cdrs_it_test.go b/apier/v1/cdrs_it_test.go
deleted file mode 100644
index 90676ab30..000000000
--- a/apier/v1/cdrs_it_test.go
+++ /dev/null
@@ -1,625 +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"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- cdrsCfgPath string
- cdrsCfg *config.CGRConfig
- cdrsRpc *rpc.Client
- cdrsConfDIR string // run the tests for specific configuration
-
- sTestsCDRsIT = []func(t *testing.T){
- testV1CDRsInitConfig,
- testV1CDRsInitDataDb,
- testV1CDRsInitCdrDb,
- testV1CDRsStartEngine,
- testV1CDRsRpcConn,
- testV1CDRsLoadTariffPlanFromFolder,
- testV1CDRsProcessEventWithRefund,
- testV1CDRsRefundOutOfSessionCost,
- testV1CDRsRefundCDR,
- testV1CDRsKillEngine,
-
- testV1CDRsInitConfig,
- testV1CDRsInitDataDb,
- testV1CDRsInitCdrDb,
- testV1CDRsStartEngine,
- testV1CDRsRpcConn,
- testV1CDRsLoadTariffPlanFromFolderSMS,
- testV1CDRsAddBalanceForSMS,
- testV1CDRsKillEngine,
- }
-)
-
-func TestCDRsIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- cdrsConfDIR = "cdrsv1internal"
- case utils.MetaMySQL:
- cdrsConfDIR = "cdrsv1mysql"
- case utils.MetaMongo:
- cdrsConfDIR = "cdrsv1mongo"
- case utils.MetaPostgres:
- cdrsConfDIR = "cdrsv1postgres"
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsCDRsIT {
- t.Run(cdrsConfDIR, stest)
- }
-}
-
-func testV1CDRsInitConfig(t *testing.T) {
- var err error
- cdrsCfgPath = path.Join(*dataDir, "conf", "samples", cdrsConfDIR)
- if cdrsCfg, err = config.NewCGRConfigFromPath(cdrsCfgPath); err != nil {
- t.Fatal("Got config error: ", err.Error())
- }
-}
-
-func testV1CDRsInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(cdrsCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// InitDb so we can rely on count
-func testV1CDRsInitCdrDb(t *testing.T) {
- if err := engine.InitStorDB(cdrsCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1CDRsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(cdrsCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testV1CDRsRpcConn(t *testing.T) {
- var err error
- cdrsRpc, err = newRPCClient(cdrsCfg.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 testV1CDRsLoadTariffPlanFromFolder(t *testing.T) {
- var loadInst string
- if err := cdrsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder,
- &utils.AttrLoadTpFromFolder{FolderPath: path.Join(
- *dataDir, "tariffplans", "testit")}, &loadInst); err != nil {
- t.Error(err)
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
-}
-
-func testV1CDRsProcessEventWithRefund(t *testing.T) {
- var acnt *engine.Account
- acntAttrs := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "testV1CDRsProcessEventWithRefund"}
- attrSetBalance := utils.AttrSetBalance{
- Tenant: acntAttrs.Tenant,
- Account: acntAttrs.Account,
- BalanceType: utils.MetaVoice,
- Value: 120000000000,
- Balance: map[string]interface{}{
- utils.ID: "BALANCE1",
- utils.Weight: 20,
- },
- }
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("received: %s", reply)
- }
- attrSetBalance = utils.AttrSetBalance{
- Tenant: acntAttrs.Tenant,
- Account: acntAttrs.Account,
- BalanceType: utils.MetaVoice,
- Value: 180000000000,
- Balance: map[string]interface{}{
- utils.ID: "BALANCE2",
- utils.Weight: 10,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("received: <%s>", reply)
- }
- expectedVoice := 300000000000.0
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if rply := acnt.BalanceMap[utils.MetaVoice].GetTotalValue(); rply != expectedVoice {
- t.Errorf("Expecting: %v, received: %v", expectedVoice, rply)
- }
- argsEv := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.RunID: "testv1",
- utils.OriginID: "testV1CDRsProcessEventWithRefund",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "testV1CDRsProcessEventWithRefund",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
- utils.Usage: 3 * time.Minute,
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
- var cdrs []*engine.ExternalCDR
- if err := cdrsRpc.Call(utils.APIerSv1GetCDRs, &utils.AttrGetCdrs{}, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 0 {
- t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1))
- } else if blc2 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE2"); blc2.Value != 120000000000 {
- t.Errorf("Balance2 is: %s", utils.ToIJSON(blc2))
- }
- // without re-rate we should be denied
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err == nil {
- t.Error("should receive error here")
- }
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 0 {
- t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1))
- } else if blc2 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE2"); blc2.Value != 120000000000 {
- t.Errorf("Balance2 is: %s", utils.ToIJSON(blc2))
- }
- argsEv = &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs, utils.MetaRerate},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.RunID: "testv1",
- utils.OriginID: "testV1CDRsProcessEventWithRefund",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "testV1CDRsProcessEventWithRefund",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if blc1 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE1"); blc1.Value != 120000000000 { // refund is done after debit
- t.Errorf("Balance1 is: %s", utils.ToIJSON(blc1))
- } else if blc2 := acnt.GetBalanceWithID(utils.MetaVoice, "BALANCE2"); blc2.Value != 120000000000 {
- t.Errorf("Balance2 is: %s", utils.ToIJSON(blc2))
- }
- return
-}
-
-func testV1CDRsRefundOutOfSessionCost(t *testing.T) {
- //create a sessionCost and store it into storDB
- var acnt *engine.Account
- acntAttrs := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "testV1CDRsRefundOutOfSessionCost"}
- attrSetBalance := utils.AttrSetBalance{
- Tenant: acntAttrs.Tenant,
- Account: acntAttrs.Account,
- BalanceType: utils.MetaMonetary,
- Value: 123,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- utils.Weight: 20,
- },
- }
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("received: %s", reply)
- }
-
- exp := 123.0
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp {
- t.Errorf("Expecting: %v, received: %v", exp, rply)
- }
- balanceUuid := acnt.BalanceMap[utils.MetaMonetary][0].Uuid
-
- attr := &engine.AttrCDRSStoreSMCost{
- Cost: &engine.SMCost{
- CGRID: "test1",
- RunID: utils.MetaDefault,
- OriginID: "testV1CDRsRefundOutOfSessionCost",
- CostSource: utils.MetaSessionS,
- Usage: 3 * time.Minute,
- CostDetails: &engine.EventCost{
- CGRID: "test1",
- RunID: utils.MetaDefault,
- StartTime: time.Date(2017, 1, 9, 16, 18, 21, 0, time.UTC),
- Usage: utils.DurationPointer(3 * time.Minute),
- Cost: utils.Float64Pointer(2.3),
- Charges: []*engine.ChargingInterval{
- {
- RatingID: "c1a5ab9",
- Increments: []*engine.ChargingIncrement{
- {
- Usage: 2 * time.Minute,
- Cost: 2.0,
- AccountingID: "a012888",
- CompressFactor: 1,
- },
- {
- Usage: time.Second,
- Cost: 0.005,
- AccountingID: "44d6c02",
- CompressFactor: 60,
- },
- },
- CompressFactor: 1,
- },
- },
- AccountSummary: &engine.AccountSummary{
- Tenant: "cgrates.org",
- ID: "testV1CDRsRefundOutOfSessionCost",
- BalanceSummaries: []*engine.BalanceSummary{
- {
- UUID: balanceUuid,
- Type: utils.MetaMonetary,
- Value: 50,
- },
- },
- AllowNegative: false,
- Disabled: false,
- },
- Rating: engine.Rating{
- "c1a5ab9": &engine.RatingUnit{
- ConnectFee: 0.1,
- RoundingMethod: "*up",
- RoundingDecimals: 5,
- RatesID: "ec1a177",
- RatingFiltersID: "43e77dc",
- },
- },
- Accounting: engine.Accounting{
- "a012888": &engine.BalanceCharge{
- AccountID: "cgrates.org:testV1CDRsRefundOutOfSessionCost",
- BalanceUUID: balanceUuid,
- Units: 120.7,
- },
- "44d6c02": &engine.BalanceCharge{
- AccountID: "cgrates.org:testV1CDRsRefundOutOfSessionCost",
- BalanceUUID: balanceUuid,
- Units: 120.7,
- },
- },
- Rates: engine.ChargedRates{
- "ec1a177": engine.RateGroups{
- &engine.RGRate{
- GroupIntervalStart: 0,
- Value: 0.01,
- RateIncrement: time.Minute,
- RateUnit: time.Second},
- },
- },
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV1StoreSessionCost,
- attr, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("received: %s", reply)
- }
-
- argsEv := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.CGRID: "test1",
- utils.RunID: utils.MetaDefault,
- utils.OriginID: "testV1CDRsRefundOutOfSessionCost",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "testV1CDRsRefundOutOfSessionCost",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
- utils.Usage: 123 * time.Minute,
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-
- // Initial the balance was 123.0
- // after refunc the balance become 123.0+2.3=125.3
- exp = 124.0454
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp {
- t.Errorf("Expecting: %v, received: %v", exp, rply)
- }
-}
-
-func testV1CDRsRefundCDR(t *testing.T) {
- //create a sessionCost and store it into storDB
- var acnt *engine.Account
- acntAttrs := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "testV1CDRsRefundCDR"}
- attrSetBalance := utils.AttrSetBalance{
- Tenant: acntAttrs.Tenant,
- Account: acntAttrs.Account,
- BalanceType: utils.MetaMonetary,
- Value: 123,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- utils.Weight: 20,
- },
- }
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("received: %s", reply)
- }
-
- exp := 123.0
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp {
- t.Errorf("Expecting: %v, received: %v", exp, rply)
- }
-
- balanceUuid := acnt.BalanceMap[utils.MetaMonetary][0].Uuid
-
- argsEv := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRefund},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.RunID: utils.MetaDefault,
- utils.OriginID: "testV1CDRsRefundCDR",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "testV1CDRsRefundCDR",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- utils.CostDetails: &engine.EventCost{
- CGRID: "test1",
- RunID: utils.MetaDefault,
- StartTime: time.Date(2017, 1, 9, 16, 18, 21, 0, time.UTC),
- Usage: utils.DurationPointer(3 * time.Minute),
- Cost: utils.Float64Pointer(2.3),
- Charges: []*engine.ChargingInterval{
- {
- RatingID: "c1a5ab9",
- Increments: []*engine.ChargingIncrement{
- {
- Usage: 2 * time.Minute,
- Cost: 2.0,
- AccountingID: "a012888",
- CompressFactor: 1,
- },
- {
- Usage: time.Second,
- Cost: 0.005,
- AccountingID: "44d6c02",
- CompressFactor: 60,
- },
- },
- CompressFactor: 1,
- },
- },
- AccountSummary: &engine.AccountSummary{
- Tenant: "cgrates.org",
- ID: "testV1CDRsRefundCDR",
- BalanceSummaries: []*engine.BalanceSummary{
- {
- UUID: balanceUuid,
- Type: utils.MetaMonetary,
- Value: 50,
- },
- },
- AllowNegative: false,
- Disabled: false,
- },
- Rating: engine.Rating{
- "c1a5ab9": &engine.RatingUnit{
- ConnectFee: 0.1,
- RoundingMethod: "*up",
- RoundingDecimals: 5,
- RatesID: "ec1a177",
- RatingFiltersID: "43e77dc",
- },
- },
- Accounting: engine.Accounting{
- "a012888": &engine.BalanceCharge{
- AccountID: "cgrates.org:testV1CDRsRefundCDR",
- BalanceUUID: balanceUuid,
- Units: 120.7,
- },
- "44d6c02": &engine.BalanceCharge{
- AccountID: "cgrates.org:testV1CDRsRefundCDR",
- BalanceUUID: balanceUuid,
- Units: 120.7,
- },
- },
- Rates: engine.ChargedRates{
- "ec1a177": engine.RateGroups{
- &engine.RGRate{
- GroupIntervalStart: 0,
- Value: 0.01,
- RateIncrement: time.Minute,
- RateUnit: time.Second},
- },
- },
- },
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-
- // Initial the balance was 123.0
- // after refund the balance become 123.0 + 2.3 = 125.3
- exp = 125.3
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, acntAttrs, &acnt); err != nil {
- t.Error(err)
- } else if rply := acnt.BalanceMap[utils.MetaMonetary].GetTotalValue(); rply != exp {
- t.Errorf("Expecting: %v, received: %v", exp, rply)
- }
-}
-
-func testV1CDRsLoadTariffPlanFromFolderSMS(t *testing.T) {
- var loadInst string
- if err := cdrsRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder,
- &utils.AttrLoadTpFromFolder{FolderPath: path.Join(
- *dataDir, "tariffplans", "tutorial")}, &loadInst); err != nil {
- t.Error(err)
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
-}
-
-func testV1CDRsAddBalanceForSMS(t *testing.T) {
- var reply string
- attrs := &AttrAddBalance{
- Tenant: "cgrates.org",
- Account: "testV1CDRsAddBalanceForSMS",
- BalanceType: utils.MetaSMS,
- Value: 1000,
- }
- if err := cdrsRpc.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil {
- t.Error("Got error on APIerSv1.AddBalance: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.AddBalance received: %s", reply)
- }
-
- attrs = &AttrAddBalance{
- Tenant: "cgrates.org",
- Account: "testV1CDRsAddBalanceForSMS",
- BalanceType: utils.MetaMonetary,
- Value: 10,
- }
- if err := cdrsRpc.Call(utils.APIerSv1AddBalance, attrs, &reply); err != nil {
- t.Error("Got error on APIerSv1.AddBalance: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.AddBalance received: %s", reply)
- }
-
- var acnt *engine.Account
- attrAcc := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "testV1CDRsAddBalanceForSMS",
- }
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap[utils.MetaSMS]) != 1 {
- t.Errorf("Expecting: %v, received: %v", 1, len(acnt.BalanceMap[utils.MetaSMS]))
- } else if acnt.BalanceMap[utils.MetaSMS].GetTotalValue() != 1000 {
- t.Errorf("Expecting: %v, received: %v", 1000, acnt.BalanceMap[utils.MetaSMS].GetTotalValue())
- } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 {
- t.Errorf("Expecting: %v, received: %v", 1, len(acnt.BalanceMap[utils.MetaMonetary]))
- } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10 {
- t.Errorf("Expecting: %v, received: %v", 10, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue())
- }
-
- argsEv := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.CGRID: "asdfas",
- utils.ToR: utils.MetaSMS,
- utils.Category: "sms",
- utils.RunID: utils.MetaDefault,
- utils.OriginID: "testV1CDRsAddBalanceForSMS",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "testV1CDRsAddBalanceForSMS",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2019, 11, 27, 12, 21, 26, 0, time.UTC),
- utils.Usage: 1,
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsEv, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap[utils.MetaSMS]) != 1 {
- t.Errorf("Expecting: %v, received: %v", 1, len(acnt.BalanceMap[utils.MetaSMS]))
- } else if acnt.BalanceMap[utils.MetaSMS].GetTotalValue() != 999 {
- t.Errorf("Expecting: %v, received: %v", 999, acnt.BalanceMap[utils.MetaSMS].GetTotalValue())
- } else if len(acnt.BalanceMap[utils.MetaMonetary]) != 1 {
- t.Errorf("Expecting: %v, received: %v", 1, len(acnt.BalanceMap[utils.MetaMonetary]))
- } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != 10 {
- t.Errorf("Expecting: %v, received: %v", 10, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue())
- }
-
-}
-
-func testV1CDRsKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/chargers.go b/apier/v1/chargers.go
deleted file mode 100644
index 375ca6623..000000000
--- a/apier/v1/chargers.go
+++ /dev/null
@@ -1,153 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetChargerProfile returns a Charger Profile
-func (apierSv1 *APIerSv1) GetChargerProfile(arg *utils.TenantID, reply *engine.ChargerProfile) 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 cpp, err := apierSv1.DataManager.GetChargerProfile(tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- } else {
- *reply = *cpp
- }
- return nil
-}
-
-// GetChargerProfileIDs returns list of chargerProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetChargerProfileIDs(args *utils.PaginatorWithTenant, chPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.ChargerProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *chPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-type ChargerWithAPIOpts struct {
- *engine.ChargerProfile
- APIOpts map[string]interface{}
-}
-
-//SetChargerProfile add/update a new Charger Profile
-func (apierSv1 *APIerSv1) SetChargerProfile(arg *ChargerWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(arg.ChargerProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if arg.Tenant == utils.EmptyString {
- arg.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.SetChargerProfile(arg.ChargerProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheChargerProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheChargerProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for ChargerProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheChargerProfiles,
- arg.TenantID(), &arg.FilterIDs, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//RemoveChargerProfile remove a specific Charger Profile
-func (apierSv1 *APIerSv1) RemoveChargerProfile(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.RemoveChargerProfile(tnt,
- arg.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheChargerProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheChargerProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for ChargerProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheChargerProfiles,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-func NewChargerSv1(cS *engine.ChargerService) *ChargerSv1 {
- return &ChargerSv1{cS: cS}
-}
-
-// Exports RPC from ChargerS
-type ChargerSv1 struct {
- cS *engine.ChargerService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (cSv1 *ChargerSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(cSv1, serviceMethod, args, reply)
-}
-
-func (cSv1 *ChargerSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// GetChargerForEvent returns matching ChargerProfile for Event
-func (cSv1 *ChargerSv1) GetChargersForEvent(cgrEv *utils.CGREvent,
- reply *engine.ChargerProfiles) error {
- return cSv1.cS.V1GetChargersForEvent(cgrEv, reply)
-}
-
-// ProcessEvent
-func (cSv1 *ChargerSv1) ProcessEvent(args *utils.CGREvent,
- reply *[]*engine.ChrgSProcessEventReply) error {
- return cSv1.cS.V1ProcessEvent(args, reply)
-}
diff --git a/apier/v1/chargers_it_test.go b/apier/v1/chargers_it_test.go
deleted file mode 100755
index fabf2192a..000000000
--- a/apier/v1/chargers_it_test.go
+++ /dev/null
@@ -1,713 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- chargerCfgPath string
- chargerCfg *config.CGRConfig
- chargerRPC *rpc.Client
- chargerProfile *ChargerWithAPIOpts
- chargerConfigDIR string //run tests for specific configuration
-
- chargerEvent = []*utils.CGREvent{
- {
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- },
- APIOpts: map[string]interface{}{utils.OptsContext: "simpleauth"},
- },
-
- {
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1010",
- "DistinctMatch": "cgrates",
- },
- },
- {
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- },
- APIOpts: map[string]interface{}{utils.OptsContext: "simpleauth"},
- },
- }
-
- sTestsCharger = []func(t *testing.T){
- testChargerSInitCfg,
- testChargerSInitDataDb,
- testChargerSResetStorDb,
- testChargerSStartEngine,
- testChargerSRPCConn,
- testChargerSLoadAddCharger,
- testChargerSGetChargersForEvent,
- testChargerSGetChargersForEvent2,
- testChargerSProcessEvent,
- testChargerSSetChargerProfile,
- testChargerSGetChargerProfileIDs,
- testChargerSUpdateChargerProfile,
- testChargerSRemChargerProfile,
- testChargerSPing,
- testChargerSProcessWithNotFoundAttribute,
- testChargerSProccessEventWithProcceSRunS,
- testChargerSSetChargerProfileWithoutTenant,
- testChargerSRemChargerProfileWithoutTenant,
- testChargerSKillEngine,
- //cache test
- testChargerSInitCfg,
- testChargerSInitDataDb,
- testChargerSResetStorDb,
- testChargerSStartEngine,
- testChargerSRPCConn,
- testChargerSCacheTestGetNotFound,
- testChargerSCacheTestSet,
- testChargerSCacheTestGetNotFound,
- testChargerSCacheReload,
- testChargerSCacheTestGetFound,
- testChargerSKillEngine,
- }
-)
-
-//Test start here
-func TestChargerSIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- chargerConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- chargerConfigDIR = "tutmysql"
- case utils.MetaMongo:
- chargerConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsCharger {
- t.Run(chargerConfigDIR, stest)
- }
-}
-
-func testChargerSInitCfg(t *testing.T) {
- var err error
- chargerCfgPath = path.Join(*dataDir, "conf", "samples", chargerConfigDIR)
- chargerCfg, err = config.NewCGRConfigFromPath(chargerCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testChargerSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(chargerCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testChargerSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(chargerCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testChargerSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(chargerCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testChargerSRPCConn(t *testing.T) {
- var err error
- chargerRPC, err = newRPCClient(chargerCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testChargerSLoadAddCharger(t *testing.T) {
- chargerProfile := &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Charger1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"ATTR_1001_SIMPLEAUTH"},
- Weight: 20,
- },
- }
-
- var result string
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Charger2",
- FilterIDs: []string{"*string:~*req.Account:1007"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"*constant:*req.RequestType:*rated;*constant:*req.Category:call"},
- Weight: 20,
- },
- }
-
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "ChargerNotMatching",
- FilterIDs: []string{"*string:~*req.Account:1015", "*gt:~*req.Usage:10"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"*none"},
- Weight: 20,
- },
- }
-
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ATTR_1001_SIMPLEAUTH",
- Contexts: []string{"simpleauth"},
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Password",
- Value: config.RSRParsers{
- &config.RSRParser{
- Rules: "CGRateS.org",
- },
- },
- },
- },
- Blocker: false,
- Weight: 10,
- },
- }
- if err := chargerRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testChargerSGetChargersForEvent(t *testing.T) {
- chargerProfiles := &engine.ChargerProfiles{
- &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Charger1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"ATTR_1001_SIMPLEAUTH"},
- Weight: 20,
- },
- }
- var result *engine.ChargerProfiles
- if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent,
- chargerEvent[1], &result); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent,
- chargerEvent[0], &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, chargerProfiles) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(chargerProfiles), utils.ToJSON(result))
- }
-
- chargerProfiles = &engine.ChargerProfiles{
- &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Charger1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"ATTR_1001_SIMPLEAUTH"},
- Weight: 20,
- },
- }
- chargerEvent[0].Tenant = utils.EmptyString
- if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent,
- chargerEvent[0], &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, chargerProfiles) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(chargerProfiles), utils.ToJSON(result))
- }
-}
-
-func testChargerSGetChargersForEvent2(t *testing.T) {
- var result *engine.ChargerProfiles
- if err := chargerRPC.Call(utils.ChargerSv1GetChargersForEvent,
- &utils.CGREvent{ // matching Charger1
- Tenant: utils.EmptyString,
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1015",
- utils.Usage: 1,
- },
- }, &result); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- t.Error(utils.ToJSON(result))
- }
-}
-
-func testChargerSProcessEvent(t *testing.T) {
- processedEv := []*engine.ChrgSProcessEventReply{
- {
- ChargerSProfile: "Charger1",
- AttributeSProfiles: []string{"ATTR_1001_SIMPLEAUTH"},
- AlteredFields: []string{utils.MetaReqRunID, "*req.Password"},
- CGREvent: &utils.CGREvent{ // matching Charger1
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- "Password": "CGRateS.org",
- "RunID": utils.MetaDefault,
- },
- APIOpts: map[string]interface{}{utils.OptsContext: "simpleauth", utils.Subsys: utils.MetaChargers},
- },
- },
- }
- var result []*engine.ChrgSProcessEventReply
- if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[1], &result); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[0], &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, processedEv) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(processedEv), utils.ToJSON(result))
- }
- result = []*engine.ChrgSProcessEventReply{}
- processedEv = []*engine.ChrgSProcessEventReply{
- {
- ChargerSProfile: "Charger2",
- AttributeSProfiles: []string{"*constant:*req.RequestType:*rated;*constant:*req.Category:call"},
- AlteredFields: []string{"*req.Category", "*req.RequestType", utils.MetaReqRunID},
- CGREvent: &utils.CGREvent{ // matching Charger1
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.RequestType: "*rated",
- utils.Category: "call",
- utils.RunID: utils.MetaDefault,
- },
- APIOpts: map[string]interface{}{utils.OptsContext: "simpleauth", utils.Subsys: utils.MetaChargers},
- },
- },
- }
- if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[2], &result); err != nil {
- t.Fatal(err)
- }
- sort.Strings(result[0].AlteredFields)
- if !reflect.DeepEqual(result, processedEv) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(processedEv), utils.ToJSON(result))
- }
-
- chargerEvent[2].Tenant = utils.EmptyString
- if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, chargerEvent[2], &result); err != nil {
- t.Fatal(err)
- }
- sort.Strings(result[0].AlteredFields)
- if !reflect.DeepEqual(result, processedEv) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(processedEv), utils.ToJSON(result))
- }
-}
-
-func testChargerSSetChargerProfile(t *testing.T) {
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "ApierTest",
- FilterIDs: []string{"*wrong:inline"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"Attr1", "Attr2"},
- Weight: 20,
- },
- }
- var result string
- expErr := "SERVER_ERROR: broken reference to filter: *wrong:inline for item with ID: cgrates.org:ApierTest"
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
- var reply *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- chargerProfile.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~Account:1002"}
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)
- }
-}
-
-func testChargerSGetChargerProfileIDs(t *testing.T) {
- expected := []string{"Charger1", "Charger2", "ApierTest", "ChargerNotMatching"}
- var result []string
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfileIDs, utils.PaginatorWithTenant{
- Tenant: "cgrates.org",
- Paginator: utils.Paginator{Limit: utils.IntPointer(1)},
- }, &result); err != nil {
- t.Error(err)
- } else if 1 != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testChargerSUpdateChargerProfile(t *testing.T) {
- chargerProfile.RunID = "*rated"
- var result string
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)
- }
-}
-
-func testChargerSRemChargerProfile(t *testing.T) {
- var resp string
- if err := chargerRPC.Call(utils.APIerSv1RemoveChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var reply *engine.AttributeProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := chargerRPC.Call(utils.APIerSv1RemoveChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &resp); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testChargerSPing(t *testing.T) {
- var resp string
- if err := chargerRPC.Call(utils.ChargerSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testChargerSProcessWithNotFoundAttribute(t *testing.T) {
- var result string
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "ChargerWithoutAttribute",
- FilterIDs: []string{"*string:~*req.CustomField:WithoutAttributes"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- RunID: "CustomRun",
- Weight: 20,
- },
- }
-
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- ev := &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "CustomEvent",
- Event: map[string]interface{}{
- utils.AccountField: "Random",
- "CustomField": "WithoutAttributes",
- },
- }
- processedEv := []*engine.ChrgSProcessEventReply{
- {
- ChargerSProfile: "ChargerWithoutAttribute",
- AttributeSProfiles: []string{},
- AlteredFields: []string{utils.MetaReqRunID},
- CGREvent: &utils.CGREvent{ // matching ChargerWithoutAttribute
- Tenant: "cgrates.org",
- ID: "CustomEvent",
- Event: map[string]interface{}{
- utils.AccountField: "Random",
- "CustomField": "WithoutAttributes",
- "RunID": "CustomRun",
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaChargers},
- },
- },
- }
- if *encoding == utils.MetaGOB {
- processedEv[0].AttributeSProfiles = nil
- }
- var rply []*engine.ChrgSProcessEventReply
- if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, ev, &rply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rply, processedEv) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(processedEv), utils.ToJSON(rply))
- }
-
-}
-func testChargerSKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testChargerSProccessEventWithProcceSRunS(t *testing.T) {
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "ApierTest",
- FilterIDs: []string{"*string:~*req.Account:1010"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"*constant:*req.Account:1002", "*constant:*req.Account:1003"},
- Weight: 20,
- },
- }
- var result string
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)
- }
-
- processedEv := []*engine.ChrgSProcessEventReply{
- {
- ChargerSProfile: "ApierTest",
- AttributeSProfiles: []string{"*constant:*req.Account:1002"},
- AlteredFields: []string{utils.MetaReqRunID, "*req.Account"},
- CGREvent: &utils.CGREvent{ // matching Charger1
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.RunID: "*default",
- },
- APIOpts: map[string]interface{}{
- utils.Subsys: utils.MetaChargers,
- utils.OptsAttributesProcessRuns: 1.,
- },
- },
- },
- }
- cgrEv := &utils.CGREvent{ // matching Charger1
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1010",
- },
- APIOpts: map[string]interface{}{utils.OptsAttributesProcessRuns: 1.},
- }
- var result2 []*engine.ChrgSProcessEventReply
- if err := chargerRPC.Call(utils.ChargerSv1ProcessEvent, cgrEv, &result2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result2, processedEv) {
- t.Errorf("Expecting : %s, received: %s", utils.ToJSON(processedEv), utils.ToJSON(result2))
- }
-}
-
-func testChargerSSetChargerProfileWithoutTenant(t *testing.T) {
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- ID: "randomID",
- FilterIDs: []string{"*string:~*req.Account:1010"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"Attr1", "Attr2"},
- Weight: 20,
- },
- }
- var reply string
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- chargerProfile.ChargerProfile.Tenant = "cgrates.org"
- var result *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{ID: "randomID"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, result) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(chargerProfile.ChargerProfile), utils.ToJSON(result))
- }
-}
-
-func testChargerSRemChargerProfileWithoutTenant(t *testing.T) {
- var reply string
- if err := chargerRPC.Call(utils.APIerSv1RemoveChargerProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "randomID"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{ID: "randomID"},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testChargerSCacheTestGetNotFound(t *testing.T) {
- var reply *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "CHARGERS_CACHE"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-}
-
-func testChargerSCacheTestGetFound(t *testing.T) {
- var reply *engine.ChargerProfile
- if err := chargerRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "CHARGERS_CACHE"}, &reply); err != nil {
- t.Fatal(err)
- }
-}
-
-func testChargerSCacheTestSet(t *testing.T) {
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "CHARGERS_CACHE",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- var reply string
- if err := chargerRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-}
-
-func testChargerSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.ChargerProfileIDs: {"cgrates.org:CHARGERS_CACHE"},
- },
- }
- var reply string
- if err := chargerRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/config.go b/apier/v1/config.go
deleted file mode 100644
index 1c7c30eb9..000000000
--- a/apier/v1/config.go
+++ /dev/null
@@ -1,66 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/utils"
-)
-
-// NewConfigSv1 returns a new ConfigSv1
-func NewConfigSv1(cfg *config.CGRConfig) *ConfigSv1 {
- return &ConfigSv1{cfg: cfg}
-}
-
-// ConfigSv1 exports RPC for config
-type ConfigSv1 struct {
- cfg *config.CGRConfig
-}
-
-// GetConfig will retrieve from CGRConfig a section
-func (cSv1 *ConfigSv1) GetConfig(section *config.SectionWithAPIOpts, reply *map[string]interface{}) (err error) {
- return cSv1.cfg.V1GetConfig(section, reply)
-}
-
-// ReloadConfig reloads the configuration
-func (cSv1 *ConfigSv1) ReloadConfig(args *config.ReloadArgs, reply *string) (err error) {
- return cSv1.cfg.V1ReloadConfig(args, reply)
-}
-
-// SetConfig reloads the sections of config
-func (cSv1 *ConfigSv1) SetConfig(args *config.SetConfigArgs, reply *string) (err error) {
- return cSv1.cfg.V1SetConfig(args, reply)
-}
-
-// SetConfigFromJSON reloads the sections of config
-func (cSv1 *ConfigSv1) SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error) {
- return cSv1.cfg.V1SetConfigFromJSON(args, reply)
-}
-
-// GetConfigAsJSON will retrieve from CGRConfig a section
-func (cSv1 *ConfigSv1) GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error) {
- return cSv1.cfg.V1GetConfigAsJSON(args, reply)
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (cSv1 *ConfigSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(cSv1, serviceMethod, args, reply)
-}
diff --git a/apier/v1/config_it_test.go b/apier/v1/config_it_test.go
deleted file mode 100644
index 75d113222..000000000
--- a/apier/v1/config_it_test.go
+++ /dev/null
@@ -1,563 +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 (
- "fmt"
- "net/rpc"
- "net/rpc/jsonrpc"
- "os/exec"
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- configCfgPath string
- configCfg *config.CGRConfig
- configRPC *rpc.Client
- configConfigDIR string //run tests for specific configuration
-
- sTestsConfig = []func(t *testing.T){
- testConfigSInitCfg,
- testConfigSInitDataDb,
- testConfigSResetStorDb,
- testConfigSStartEngine,
- testConfigSRPCConn,
- testConfigSSetConfigSessionS,
- testConfigSSetConfigEEsDryRun,
- testConfigSSetConfigEEs,
- testConfigSv1GetJSONSectionWithoutTenant,
- testConfigSSetConfigFromJSONCoreSDryRun,
- testConfigSSetConfigFromJSONCoreS,
- testConfigSReloadConfigCoreSDryRun,
- testConfigSReloadConfigCoreS,
- testConfigSKillEngine,
- testConfigStartEngineWithConfigs,
- testConfigStartEngineFromHTTP,
- testConfigSKillEngine,
- }
-)
-
-//Test start here
-func TestConfigSIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- configConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- configConfigDIR = "tutmysql"
- case utils.MetaMongo:
- configConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsConfig {
- t.Run(configConfigDIR, stest)
- }
-}
-
-func testConfigSInitCfg(t *testing.T) {
- var err error
- configCfgPath = path.Join(*dataDir, "conf", "samples", configConfigDIR)
- configCfg, err = config.NewCGRConfigFromPath(configCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testConfigSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(configCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testConfigSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(configCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testConfigSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(configCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testConfigSRPCConn(t *testing.T) {
- var err error
- configRPC, err = newRPCClient(configCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testConfigSSetConfigSessionS(t *testing.T) {
- var reply string
- if err := configRPC.Call(utils.ConfigSv1SetConfig, &config.SetConfigArgs{
- Tenant: "cgrates.org",
- Config: map[string]interface{}{
- "sessions": map[string]interface{}{
- "enabled": true,
- "resources_conns": []string{"*localhost"},
- "routes_conns": []string{"*localhost"},
- "attributes_conns": []string{"*localhost"},
- "rals_conns": []string{"*internal"},
- "cdrs_conns": []string{"*internal"},
- "configs_conns": []string{"*internal"},
- },
- },
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
- exp := map[string]interface{}{
- "enabled": true,
- "channel_sync_interval": "0",
- "alterable_fields": []interface{}{},
- "client_protocol": 1.,
- "debit_interval": "0",
- "listen_bijson": "127.0.0.1:2014",
- "listen_bigob": "",
- "session_ttl": "0",
- "session_indexes": []interface{}{utils.OriginID},
- "attributes_conns": []interface{}{utils.MetaLocalHost},
- "cdrs_conns": []interface{}{utils.MetaInternal},
- "chargers_conns": []interface{}{utils.MetaInternal},
- "rals_conns": []interface{}{utils.MetaInternal},
- "replication_conns": []interface{}{},
- "resources_conns": []interface{}{utils.MetaLocalHost},
- "routes_conns": []interface{}{utils.MetaLocalHost},
- "scheduler_conns": []interface{}{},
- "thresholds_conns": []interface{}{},
- "stats_conns": []interface{}{},
- "min_dur_low_balance": "0",
- "stir": map[string]interface{}{
- "allowed_attest": []interface{}{utils.MetaAny},
- "default_attest": "A",
- "payload_maxduration": "-1",
- "privatekey_path": "",
- "publickey_path": "",
- },
- "store_session_costs": false,
- "terminate_attempts": 5.,
- utils.DefaultUsageCfg: map[string]interface{}{
- utils.MetaAny: "3h0m0s",
- utils.MetaVoice: "3h0m0s",
- utils.MetaData: "1048576",
- utils.MetaSMS: "1",
- },
- }
- if *encoding == utils.MetaGOB {
- var empty []string
- exp = map[string]interface{}{
- "enabled": true,
- "listen_bijson": "127.0.0.1:2014",
- "listen_bigob": "",
- "chargers_conns": []string{utils.MetaInternal},
- "rals_conns": []string{utils.MetaInternal},
- "resources_conns": []string{utils.MetaLocalHost},
- "thresholds_conns": empty,
- "stats_conns": empty,
- "routes_conns": []string{utils.MetaLocalHost},
- "attributes_conns": []string{utils.MetaLocalHost},
- "cdrs_conns": []string{utils.MetaInternal},
- "replication_conns": empty,
- "scheduler_conns": empty,
- "session_indexes": []string{"OriginID"},
- "client_protocol": 1.,
- "terminate_attempts": 5,
- "channel_sync_interval": "0",
- "debit_interval": "0",
- "session_ttl": "0",
- "store_session_costs": false,
- "min_dur_low_balance": "0",
- "alterable_fields": empty,
- "stir": map[string]interface{}{
- "allowed_attest": []string{utils.MetaAny},
- "default_attest": "A",
- "payload_maxduration": "-1",
- "privatekey_path": "",
- "publickey_path": "",
- },
- utils.DefaultUsageCfg: map[string]string{
- utils.MetaAny: "3h0m0s",
- utils.MetaVoice: "3h0m0s",
- utils.MetaData: "1048576",
- utils.MetaSMS: "1",
- },
- }
- }
- exp = map[string]interface{}{
- config.SessionSJson: exp,
- }
- var rpl map[string]interface{}
- if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{
- Tenant: "cgrates.org",
- Section: config.SessionSJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rpl) {
- t.Errorf("Expected %+v , received: %+v ", utils.ToJSON(exp), utils.ToJSON(rpl))
- }
-}
-
-func testConfigSv1GetJSONSectionWithoutTenant(t *testing.T) {
- exp := map[string]interface{}{
- "enabled": true,
- "listen_bijson": "127.0.0.1:2014",
- "listen_bigob": "",
- "chargers_conns": []interface{}{utils.MetaInternal},
- "rals_conns": []interface{}{utils.MetaInternal},
- "resources_conns": []interface{}{utils.MetaLocalHost},
- "thresholds_conns": []interface{}{},
- "stats_conns": []interface{}{},
- "routes_conns": []interface{}{utils.MetaLocalHost},
- "attributes_conns": []interface{}{utils.MetaLocalHost},
- "cdrs_conns": []interface{}{utils.MetaInternal},
- "replication_conns": []interface{}{},
- "scheduler_conns": []interface{}{},
- "session_indexes": []interface{}{"OriginID"},
- "client_protocol": 1.,
- "terminate_attempts": 5.,
- "channel_sync_interval": "0",
- "debit_interval": "0",
- "session_ttl": "0",
- "store_session_costs": false,
- "min_dur_low_balance": "0",
- "alterable_fields": []interface{}{},
- "stir": map[string]interface{}{
- "allowed_attest": []interface{}{utils.MetaAny},
- "default_attest": "A",
- "payload_maxduration": "-1",
- "privatekey_path": "",
- "publickey_path": "",
- },
- utils.DefaultUsageCfg: map[string]interface{}{
- utils.MetaAny: "3h0m0s",
- utils.MetaVoice: "3h0m0s",
- utils.MetaData: "1048576",
- utils.MetaSMS: "1",
- },
- }
- if *encoding == utils.MetaGOB {
- var empty []string
- exp = map[string]interface{}{
- "enabled": true,
- "listen_bijson": "127.0.0.1:2014",
- "chargers_conns": []string{utils.MetaInternal},
- "rals_conns": []string{utils.MetaInternal},
- "resources_conns": []string{utils.MetaLocalHost},
- "thresholds_conns": empty,
- "stats_conns": empty,
- "routes_conns": []string{utils.MetaLocalHost},
- "attributes_conns": []string{utils.MetaLocalHost},
- "cdrs_conns": []string{utils.MetaInternal},
- "replication_conns": empty,
- "scheduler_conns": empty,
- "session_indexes": []string{"OriginID"},
- "client_protocol": 1.,
- "terminate_attempts": 5,
- "channel_sync_interval": "0",
- "debit_interval": "0",
- "session_ttl": "0",
- "store_session_costs": false,
- "min_dur_low_balance": "0",
- "alterable_fields": empty,
- "stir": map[string]interface{}{
- "allowed_attest": []string{utils.MetaAny},
- "default_attest": "A",
- "payload_maxduration": "-1",
- "privatekey_path": "",
- "publickey_path": "",
- },
- utils.DefaultUsageCfg: map[string]string{
- utils.MetaAny: "3h0m0s",
- utils.MetaVoice: "3h0m0s",
- utils.MetaData: "1048576",
- utils.MetaSMS: "1",
- },
- }
- }
- exp = map[string]interface{}{
- config.SessionSJson: exp,
- }
- var rpl map[string]interface{}
- if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{
- Section: config.SessionSJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rpl) {
- t.Errorf("Expected %+v , received: %+v ", utils.ToJSON(exp), utils.ToJSON(rpl))
- }
-}
-
-func testConfigSSetConfigEEsDryRun(t *testing.T) {
- if *encoding == utils.MetaGOB {
- t.SkipNow()
- }
- var reply string
- if err := configRPC.Call(utils.ConfigSv1SetConfig, &config.SetConfigArgs{
- Config: map[string]interface{}{
- "ees": map[string]interface{}{
- "enabled": true,
- },
- },
- DryRun: true,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
-
- var rpl map[string]interface{}
- if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{
- Section: config.EEsJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if rpl[config.EEsJson].(map[string]interface{})["enabled"] != false {
- t.Errorf("Expected EEs to not change , received: %+v ", utils.ToJSON(rpl))
- }
-}
-
-func testConfigSSetConfigEEs(t *testing.T) {
- if *encoding == utils.MetaGOB {
- t.SkipNow()
- }
- var reply string
- if err := configRPC.Call(utils.ConfigSv1SetConfig, &config.SetConfigArgs{
- Config: map[string]interface{}{
- "ees": map[string]interface{}{
- "enabled": true,
- "attributes_conns": []string{},
- "cache": map[string]interface{}{},
- "exporters": []interface{}{map[string]interface{}{
- "id": utils.MetaDefault,
- "fields": []interface{}{},
- }},
- },
- },
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
- eporter := map[string]interface{}{
- "attempts": 1.,
- "attribute_context": "",
- "attribute_ids": []interface{}{},
- "export_path": "/var/spool/cgrates/ees",
- "field_separator": ",",
- "fields": []interface{}{},
- "filters": []interface{}{},
- "flags": []interface{}{},
- "id": "*default",
- "synchronous": false,
- "tenant": "",
- "timezone": "",
- "type": "*none",
- "opts": map[string]interface{}{},
- }
- exp := map[string]interface{}{
- "enabled": true,
- "attributes_conns": []interface{}{},
- "cache": map[string]interface{}{"*file_csv": map[string]interface{}{"limit": -1., "precache": false, "replicate": false, "static_ttl": false, "ttl": "5s"}},
- "exporters": []interface{}{eporter},
- }
- exp = map[string]interface{}{
- config.EEsJson: exp,
- }
- var rpl map[string]interface{}
- if err := configRPC.Call(utils.ConfigSv1GetConfig, &config.SectionWithAPIOpts{
- Section: config.EEsJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(exp, rpl) {
- t.Errorf("Expected %+v , received: %+v ", utils.ToJSON(exp), utils.ToJSON(rpl))
- }
-}
-
-func testConfigSKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testConfigStartEngineWithConfigs(t *testing.T) {
- var err error
- configCfgPath = path.Join(*dataDir, "conf", "samples", "configs_active")
- configCfg, err = config.NewCGRConfigFromPath(configCfgPath)
- if err != nil {
- t.Error(err)
- }
- if _, err := engine.StopStartEngine(configCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
- configRPC, err = newRPCClient(configCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
- var rply map[string]interface{}
- if err := configRPC.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil {
- t.Error(err)
- } else if rply[utils.NodeID] != "EngineWithConfigSActive" {
- t.Errorf("Expected %+v , received: %+v ", "EngineWithConfigSActive", rply)
- }
-}
-
-func testConfigStartEngineFromHTTP(t *testing.T) {
- enginePath, err := exec.LookPath("cgr-engine")
- if err != nil {
- t.Error(err)
- }
- eng := exec.Command(enginePath, "-config_path", "http://127.0.0.1:3080/configs/tutmysql/cgrates.json")
- if err := eng.Start(); err != nil {
- t.Error(err)
- }
- fib := utils.Fib()
- var jsonClnt *rpc.Client
- var connected bool
- for i := 0; i < 200; i++ {
- time.Sleep(time.Duration(fib()) * time.Millisecond)
- if jsonClnt, err = jsonrpc.Dial(utils.TCP, "localhost:2012"); err != nil {
- utils.Logger.Warning(fmt.Sprintf("Error <%s> when opening test connection to: <%s>",
- err.Error(), "localhost:2012"))
- } else {
- connected = true
- break
- }
- }
- if !connected {
- t.Errorf("engine did not open port <%s>", "localhost:2012")
- }
- time.Sleep(100 * time.Millisecond)
- var rply map[string]interface{}
- if err := jsonClnt.Call(utils.CoreSv1Status, &utils.TenantWithAPIOpts{}, &rply); err != nil {
- t.Error(err)
- }
-}
-
-func testConfigSSetConfigFromJSONCoreSDryRun(t *testing.T) {
- cfgStr := `{"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*queue","shutdown_timeout":"1s"}}`
- var reply string
- if err := configRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{
- Tenant: "cgrates.org",
- Config: cfgStr,
- DryRun: true,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
-
- expCfg := "{\"cores\":{\"caps\":0,\"caps_stats_interval\":\"0\",\"caps_strategy\":\"*busy\",\"shutdown_timeout\":\"1s\"}}"
- var rpl string
- if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
- Tenant: "cgrates.org",
- Section: config.CoreSCfgJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if expCfg != rpl {
- t.Errorf("Expected %q , received: %q", expCfg, rpl)
- }
-}
-
-func testConfigSSetConfigFromJSONCoreS(t *testing.T) {
- cfgStr := `{"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*queue","shutdown_timeout":"1s"}}`
- var reply string
- if err := configRPC.Call(utils.ConfigSv1SetConfigFromJSON, &config.SetConfigFromJSONArgs{
- Tenant: "cgrates.org",
- Config: cfgStr,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
-
- var rpl string
- if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
- Tenant: "cgrates.org",
- Section: config.CoreSCfgJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if cfgStr != rpl {
- t.Errorf("Expected %q , received: %q", cfgStr, rpl)
- }
-}
-
-func testConfigSReloadConfigCoreSDryRun(t *testing.T) {
- cfgStr := `{"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*queue","shutdown_timeout":"1s"}}`
- var reply string
- if err := configRPC.Call(utils.ConfigSv1ReloadConfig, &config.ReloadArgs{
- Tenant: "cgrates.org",
- Path: path.Join(*dataDir, "conf", "samples", "caps_busy"),
- Section: config.CoreSCfgJson,
- DryRun: true,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
-
- var rpl string
- if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
- Tenant: "cgrates.org",
- Section: config.CoreSCfgJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if cfgStr != rpl {
- t.Errorf("Expected %q , received: %q", cfgStr, rpl)
- }
-}
-
-func testConfigSReloadConfigCoreS(t *testing.T) {
- cfgStr := `{"cores":{"caps":2,"caps_stats_interval":"0","caps_strategy":"*busy","shutdown_timeout":"1s"}}`
- var reply string
- if err := configRPC.Call(utils.ConfigSv1ReloadConfig, &config.ReloadArgs{
- Tenant: "cgrates.org",
- Path: path.Join(*dataDir, "conf", "samples", "caps_busy"),
- Section: config.CoreSCfgJson,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected OK received: %s", reply)
- }
-
- var rpl string
- if err := configRPC.Call(utils.ConfigSv1GetConfigAsJSON, &config.SectionWithAPIOpts{
- Tenant: "cgrates.org",
- Section: config.CoreSCfgJson,
- }, &rpl); err != nil {
- t.Error(err)
- } else if cfgStr != rpl {
- t.Errorf("Expected %q , received: %q", cfgStr, rpl)
- }
-}
diff --git a/apier/v1/core.go b/apier/v1/core.go
deleted file mode 100644
index 96d0835dd..000000000
--- a/apier/v1/core.go
+++ /dev/null
@@ -1,59 +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/birpc/context"
- "github.com/cgrates/cgrates/cores"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewCoreSv1(cS *cores.CoreService) *CoreSv1 {
- return &CoreSv1{cS: cS}
-}
-
-// CoreSv1 exports RPC from RLs
-type CoreSv1 struct {
- cS *cores.CoreService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (cS *CoreSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(cS, serviceMethod, args, reply)
-}
-
-func (cS *CoreSv1) Status(arg *utils.TenantWithAPIOpts, reply *map[string]interface{}) error {
- return cS.cS.Status(arg, reply)
-}
-
-// Ping used to determinate if component is active
-func (cS *CoreSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// Sleep is used to test the concurrent requests mechanism
-func (cS *CoreSv1) Sleep(arg *utils.DurationArgs, reply *string) error {
- time.Sleep(arg.Duration)
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/cost_bench_it_test.go b/apier/v1/cost_bench_it_test.go
deleted file mode 100644
index ebd655f16..000000000
--- a/apier/v1/cost_bench_it_test.go
+++ /dev/null
@@ -1,322 +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"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- costBenchCfgPath string
- costBenchCfg *config.CGRConfig
- costBenchRPC *rpc.Client
- costBenchConfigDIR string //run tests for specific configuration
-)
-
-func testCostBenchInitCfg(b *testing.B) {
- var err error
- costBenchCfgPath = path.Join(*dataDir, "conf", "samples", costBenchConfigDIR)
- costBenchCfg, err = config.NewCGRConfigFromPath(costBenchCfgPath)
- if err != nil {
- b.Error(err)
- }
-}
-
-func testCostBenchInitDataDb(b *testing.B) {
- if err := engine.InitDataDB(costBenchCfg); err != nil {
- b.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testCostBenchResetStorDb(b *testing.B) {
- if err := engine.InitStorDB(costBenchCfg); err != nil {
- b.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testCostBenchStartEngine(b *testing.B) {
- if _, err := engine.StopStartEngine(costBenchCfgPath, 500); err != nil {
- b.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testCostBenchRPCConn(b *testing.B) {
- var err error
- costBenchRPC, err = newRPCClient(costBenchCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- b.Fatal(err)
- }
-}
-
-func testCostBenchLoadFromFolder(b *testing.B) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
- if err := costBenchRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- b.Error(err)
- }
- time.Sleep(500 * time.Millisecond)
-}
-
-func testCostBenchLoadFromFolder2(b *testing.B) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial2")}
- if err := costBenchRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- b.Error(err)
- }
- 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"
- testCostBenchInitCfg(b)
- testCostBenchInitDataDb(b)
- testCostBenchResetStorDb(b)
- testCostBenchStartEngine(b)
- testCostBenchRPCConn(b)
- testCostBenchLoadFromFolder(b)
-
- tNow := time.Now()
- cd := &engine.CallDescriptorWithAPIOpts{
- CallDescriptor: &engine.CallDescriptor{
- Category: "call",
- Tenant: "cgrates.org",
- Subject: "1001",
- Account: "1001",
- Destination: "1002",
- DurationIndex: 120000000000,
- TimeStart: tNow,
- TimeEnd: tNow.Add(120000000000),
- },
- }
- var cc engine.CallCost
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- if err := costBenchRPC.Call(utils.ResponderGetCost, cd, &cc); err != nil {
- b.Error("Got error on Responder.GetCost: ", err.Error())
- }
- }
- b.StopTimer()
- testCostBenchKillEngine(b)
-}
-
-// go test -run=^$ -tags=integration -v -bench=BenchmarkCostDiffPeriodWithRALs -benchtime=5s
-func BenchmarkCostDiffPeriodWithRALs(b *testing.B) {
- costBenchConfigDIR = "tutinternal"
- testCostBenchInitCfg(b)
- testCostBenchInitDataDb(b)
- testCostBenchResetStorDb(b)
- testCostBenchStartEngine(b)
- testCostBenchRPCConn(b)
- testCostBenchLoadFromFolder2(b)
-
- tStart, _ := utils.ParseTimeDetectLayout("2020-12-09T07:00:00Z", utils.EmptyString)
- tEnd, _ := utils.ParseTimeDetectLayout("2020-12-09T09:00:00Z", utils.EmptyString)
- cd := &engine.CallDescriptorWithAPIOpts{
- CallDescriptor: &engine.CallDescriptor{
- Category: "call",
- Tenant: "cgrates.org",
- Subject: "1010",
- Destination: "1012",
- DurationIndex: tEnd.Sub(tStart),
- TimeStart: tStart,
- TimeEnd: tEnd,
- },
- }
- var cc engine.CallCost
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- if err := costBenchRPC.Call(utils.ResponderGetCost, cd, &cc); err != nil {
- b.Error("Got error on Responder.GetCost: ", err.Error())
- }
- }
- b.StopTimer()
- testCostBenchKillEngine(b)
-}
-
-// go test -run=^$ -tags=integration -v -bench=BenchmarkCostWithRateS -benchtime=5s
-func BenchmarkCostWithRateS(b *testing.B) {
- costBenchConfigDIR = "tutinternal"
- testCostBenchInitCfg(b)
- testCostBenchInitDataDb(b)
- testCostBenchResetStorDb(b)
- testCostBenchStartEngine(b)
- testCostBenchRPCConn(b)
- testCostBenchSetRateProfile(b)
- 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: "2m",
- },
- },
- }
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- if err := costBenchRPC.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- b.Error(err)
- }
- }
- b.StopTimer()
- testCostBenchKillEngine(b)
-}
-
-// go test -run=^$ -tags=integration -v -bench=BenchmarkCostDiffPeriodWithRateS -benchtime=5s
-func BenchmarkCostDiffPeriodWithRateS(b *testing.B) {
- costBenchConfigDIR = "tutinternal"
- testCostBenchInitCfg(b)
- testCostBenchInitDataDb(b)
- testCostBenchResetStorDb(b)
- testCostBenchStartEngine(b)
- testCostBenchRPCConn(b)
- testCostBenchSetRateProfile2(b)
- var rply *utils.RateProfileCost
- argsRt := &utils.ArgsCostForEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.Subject: "1010",
- },
- APIOpts: map[string]interface{}{
- utils.OptsRatesStartTime: time.Date(2020, 12, 23, 59, 0, 0, 0, time.UTC),
- utils.OptsRatesUsage: "2h",
- },
- },
- }
- b.ResetTimer()
- for i := 0; i < b.N; i++ {
- if err := costBenchRPC.Call(utils.RateSv1CostForEvent, &argsRt, &rply); err != nil {
- b.Error(err)
- }
- }
- b.StopTimer()
- testCostBenchKillEngine(b)
-}
-
-func testCostBenchKillEngine(b *testing.B) {
- if err := engine.KillEngine(500); err != nil {
- b.Error(err)
- }
-}
diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go
deleted file mode 100755
index cbe6a18ea..000000000
--- a/apier/v1/dispatcher.go
+++ /dev/null
@@ -1,1171 +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/birpc/context"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
- "github.com/cgrates/ltcache"
-)
-
-// GetDispatcherProfile returns a Dispatcher Profile
-func (apierSv1 *APIerSv1) GetDispatcherProfile(arg *utils.TenantID, reply *engine.DispatcherProfile) 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
- }
- dpp, err := apierSv1.DataManager.GetDispatcherProfile(tnt, arg.ID, true, true, utils.NonTransactional)
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = *dpp
- return nil
-}
-
-// GetDispatcherProfileIDs returns list of dispatcherProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetDispatcherProfileIDs(tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error {
- tenant := tenantArg.Tenant
- if tenant == utils.EmptyString {
- tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.DispatcherProfilePrefix + tenant + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *dPrfIDs = tenantArg.PaginateStringSlice(retIDs)
- return nil
-}
-
-type DispatcherWithAPIOpts struct {
- *engine.DispatcherProfile
- APIOpts map[string]interface{}
-}
-
-//SetDispatcherProfile add/update a new Dispatcher Profile
-func (apierSv1 *APIerSv1) SetDispatcherProfile(args *DispatcherWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args.DispatcherProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if args.Tenant == utils.EmptyString {
- args.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.SetDispatcherProfile(args.DispatcherProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheDispatcherProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheDispatcherProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for DispatcherProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), args.Tenant, utils.CacheDispatcherProfiles,
- args.TenantID(), &args.FilterIDs, args.Subsystems, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//RemoveDispatcherProfile remove a specific Dispatcher Profile
-func (apierSv1 *APIerSv1) RemoveDispatcherProfile(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.RemoveDispatcherProfile(tnt,
- arg.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheDispatcherProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheDispatcherProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for DispatcherProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheDispatcherProfiles,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetDispatcherHost returns a Dispatcher Host
-func (apierSv1 *APIerSv1) GetDispatcherHost(arg *utils.TenantID, reply *engine.DispatcherHost) 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
- }
- dpp, err := apierSv1.DataManager.GetDispatcherHost(tnt, arg.ID, true, false, utils.NonTransactional)
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = *dpp
- return nil
-}
-
-// GetDispatcherHostIDs returns list of dispatcherHost IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetDispatcherHostIDs(tenantArg *utils.PaginatorWithTenant, dPrfIDs *[]string) error {
- tenant := tenantArg.Tenant
- if tenant == utils.EmptyString {
- tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.DispatcherHostPrefix + tenant + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *dPrfIDs = tenantArg.PaginateStringSlice(retIDs)
- return nil
-}
-
-//SetDispatcherHost add/update a new Dispatcher Host
-func (apierSv1 *APIerSv1) SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args.DispatcherHost, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if args.Tenant == utils.EmptyString {
- args.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.SetDispatcherHost(args.DispatcherHost); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheDispatcherHosts and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheDispatcherHosts: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for DispatcherProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), args.Tenant, utils.CacheDispatcherHosts,
- args.TenantID(), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//RemoveDispatcherHost remove a specific Dispatcher Host
-func (apierSv1 *APIerSv1) RemoveDispatcherHost(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.RemoveDispatcherHost(tnt,
- arg.ID, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheDispatcherHosts and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheDispatcherHosts: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for DispatcherProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheDispatcherHosts,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-func NewDispatcherThresholdSv1(dps *dispatchers.DispatcherService) *DispatcherThresholdSv1 {
- return &DispatcherThresholdSv1{dS: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherThresholdSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// Ping implements ThresholdSv1Ping
-func (dT *DispatcherThresholdSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dT.dS.ThresholdSv1Ping(args, reply)
-}
-
-// GetThresholdsForEvent implements ThresholdSv1GetThresholdsForEvent
-func (dT *DispatcherThresholdSv1) GetThresholdsForEvent(tntID *engine.ThresholdsArgsProcessEvent,
- t *engine.Thresholds) error {
- return dT.dS.ThresholdSv1GetThresholdsForEvent(tntID, t)
-}
-
-// ProcessEvent implements ThresholdSv1ProcessEvent
-func (dT *DispatcherThresholdSv1) ProcessEvent(args *engine.ThresholdsArgsProcessEvent,
- tIDs *[]string) error {
- return dT.dS.ThresholdSv1ProcessEvent(args, tIDs)
-}
-
-func (dT *DispatcherThresholdSv1) GetThresholdIDs(args *utils.TenantWithAPIOpts,
- tIDs *[]string) error {
- return dT.dS.ThresholdSv1GetThresholdIDs(args, tIDs)
-}
-
-func (dT *DispatcherThresholdSv1) GetThreshold(args *utils.TenantIDWithAPIOpts,
- th *engine.Threshold) error {
- return dT.dS.ThresholdSv1GetThreshold(args, th)
-}
-
-func NewDispatcherStatSv1(dps *dispatchers.DispatcherService) *DispatcherStatSv1 {
- return &DispatcherStatSv1{dS: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherStatSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// Ping implements StatSv1Ping
-func (dSts *DispatcherStatSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dSts.dS.StatSv1Ping(args, reply)
-}
-
-// GetStatQueuesForEvent implements StatSv1GetStatQueuesForEvent
-func (dSts *DispatcherStatSv1) GetStatQueuesForEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error {
- return dSts.dS.StatSv1GetStatQueuesForEvent(args, reply)
-}
-
-// GetQueueStringMetrics implements StatSv1GetQueueStringMetrics
-func (dSts *DispatcherStatSv1) GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts,
- reply *map[string]string) error {
- return dSts.dS.StatSv1GetQueueStringMetrics(args, reply)
-}
-
-func (dSts *DispatcherStatSv1) GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts,
- reply *map[string]float64) error {
- return dSts.dS.StatSv1GetQueueFloatMetrics(args, reply)
-}
-
-func (dSts *DispatcherStatSv1) GetQueueIDs(args *utils.TenantWithAPIOpts,
- reply *[]string) error {
- return dSts.dS.StatSv1GetQueueIDs(args, reply)
-}
-
-// GetQueueStringMetrics implements StatSv1ProcessEvent
-func (dSts *DispatcherStatSv1) ProcessEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error {
- return dSts.dS.StatSv1ProcessEvent(args, reply)
-}
-
-func NewDispatcherResourceSv1(dps *dispatchers.DispatcherService) *DispatcherResourceSv1 {
- return &DispatcherResourceSv1{dRs: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherResourceSv1 struct {
- dRs *dispatchers.DispatcherService
-}
-
-// Ping implements ResourceSv1Ping
-func (dRs *DispatcherResourceSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dRs.dRs.ResourceSv1Ping(args, reply)
-}
-
-// GetResourcesForEvent implements ResourceSv1GetResourcesForEvent
-func (dRs *DispatcherResourceSv1) GetResourcesForEvent(args *utils.ArgRSv1ResourceUsage,
- reply *engine.Resources) error {
- return dRs.dRs.ResourceSv1GetResourcesForEvent(*args, reply)
-}
-
-func (dRs *DispatcherResourceSv1) GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error {
- return dRs.dRs.ResourceSv1GetResource(args, reply)
-}
-
-func (dRs *DispatcherResourceSv1) GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error {
- return dRs.dRs.ResourceSv1GetResourceWithConfig(args, reply)
-}
-
-func (dRs *DispatcherResourceSv1) AuthorizeResources(args *utils.ArgRSv1ResourceUsage,
- reply *string) error {
- return dRs.dRs.ResourceSv1AuthorizeResources(*args, reply)
-}
-
-func (dRs *DispatcherResourceSv1) AllocateResources(args *utils.ArgRSv1ResourceUsage,
- reply *string) error {
- return dRs.dRs.ResourceSv1AllocateResources(*args, reply)
-}
-
-func (dRs *DispatcherResourceSv1) ReleaseResources(args *utils.ArgRSv1ResourceUsage,
- reply *string) error {
- return dRs.dRs.ResourceSv1ReleaseResources(*args, reply)
-}
-
-func NewDispatcherRouteSv1(dps *dispatchers.DispatcherService) *DispatcherRouteSv1 {
- return &DispatcherRouteSv1{dRoute: dps}
-}
-
-// Exports RPC from RouteS
-type DispatcherRouteSv1 struct {
- dRoute *dispatchers.DispatcherService
-}
-
-// Ping implements RouteSv1Ping
-func (dRoute *DispatcherRouteSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dRoute.dRoute.RouteSv1Ping(args, reply)
-}
-
-// GetRoutes implements RouteSv1GetRoutes
-func (dRoute *DispatcherRouteSv1) GetRoutes(args *engine.ArgsGetRoutes, reply *engine.SortedRoutesList) error {
- return dRoute.dRoute.RouteSv1GetRoutes(args, reply)
-}
-
-// GetRouteProfilesForEvent returns a list of route profiles that match for Event
-func (dRoute *DispatcherRouteSv1) GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) error {
- return dRoute.dRoute.RouteSv1GetRouteProfilesForEvent(args, reply)
-}
-
-// GetRoutesList returns sorted list of routes for Event as a string slice
-func (dRoute *DispatcherRouteSv1) GetRoutesList(args *engine.ArgsGetRoutes, reply *[]string) error {
- return dRoute.dRoute.RouteSv1GetRoutesList(args, reply)
-}
-
-func NewDispatcherAttributeSv1(dps *dispatchers.DispatcherService) *DispatcherAttributeSv1 {
- return &DispatcherAttributeSv1{dA: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherAttributeSv1 struct {
- dA *dispatchers.DispatcherService
-}
-
-// Ping implements AttributeSv1Ping
-func (dA *DispatcherAttributeSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dA.dA.AttributeSv1Ping(args, reply)
-}
-
-// GetAttributeForEvent implements AttributeSv1GetAttributeForEvent
-func (dA *DispatcherAttributeSv1) GetAttributeForEvent(args *engine.AttrArgsProcessEvent,
- reply *engine.AttributeProfile) error {
- return dA.dA.AttributeSv1GetAttributeForEvent(args, reply)
-}
-
-// ProcessEvent implements AttributeSv1ProcessEvent
-func (dA *DispatcherAttributeSv1) ProcessEvent(args *engine.AttrArgsProcessEvent,
- reply *engine.AttrSProcessEventReply) error {
- return dA.dA.AttributeSv1ProcessEvent(args, reply)
-}
-
-func NewDispatcherChargerSv1(dps *dispatchers.DispatcherService) *DispatcherChargerSv1 {
- return &DispatcherChargerSv1{dC: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherChargerSv1 struct {
- dC *dispatchers.DispatcherService
-}
-
-// Ping implements ChargerSv1Ping
-func (dC *DispatcherChargerSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dC.dC.ChargerSv1Ping(args, reply)
-}
-
-// GetChargersForEvent implements ChargerSv1GetChargersForEvent
-func (dC *DispatcherChargerSv1) GetChargersForEvent(args *utils.CGREvent,
- reply *engine.ChargerProfiles) (err error) {
- return dC.dC.ChargerSv1GetChargersForEvent(args, reply)
-}
-
-// ProcessEvent implements ChargerSv1ProcessEvent
-func (dC *DispatcherChargerSv1) ProcessEvent(args *utils.CGREvent,
- reply *[]*engine.ChrgSProcessEventReply) (err error) {
- return dC.dC.ChargerSv1ProcessEvent(args, reply)
-}
-
-func NewDispatcherSessionSv1(dps *dispatchers.DispatcherService) *DispatcherSessionSv1 {
- return &DispatcherSessionSv1{dS: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherSessionSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// Ping implements SessionSv1Ping
-func (dS *DispatcherSessionSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.SessionSv1Ping(args, reply)
-}
-
-// AuthorizeEventWithDigest implements SessionSv1AuthorizeEventWithDigest
-func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs,
- reply *sessions.V1AuthorizeReplyWithDigest) error {
- return dS.dS.SessionSv1AuthorizeEventWithDigest(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) AuthorizeEvent(args *sessions.V1AuthorizeArgs,
- reply *sessions.V1AuthorizeReply) error {
- return dS.dS.SessionSv1AuthorizeEvent(args, reply)
-}
-
-// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
-func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(args *sessions.V1InitSessionArgs,
- reply *sessions.V1InitReplyWithDigest) (err error) {
- return dS.dS.SessionSv1InitiateSessionWithDigest(args, reply)
-}
-
-// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
-func (dS *DispatcherSessionSv1) InitiateSession(args *sessions.V1InitSessionArgs,
- reply *sessions.V1InitSessionReply) (err error) {
- return dS.dS.SessionSv1InitiateSession(args, reply)
-}
-
-// ProcessCDR implements SessionSv1ProcessCDR
-func (dS *DispatcherSessionSv1) ProcessCDR(args *utils.CGREvent,
- reply *string) (err error) {
- return dS.dS.SessionSv1ProcessCDR(args, reply)
-}
-
-// ProcessMessage implements SessionSv1ProcessMessage
-func (dS *DispatcherSessionSv1) ProcessMessage(args *sessions.V1ProcessMessageArgs,
- reply *sessions.V1ProcessMessageReply) (err error) {
- return dS.dS.SessionSv1ProcessMessage(args, reply)
-}
-
-// ProcessMessage implements SessionSv1ProcessMessage
-func (dS *DispatcherSessionSv1) ProcessEvent(args *sessions.V1ProcessEventArgs,
- reply *sessions.V1ProcessEventReply) (err error) {
- return dS.dS.SessionSv1ProcessEvent(args, reply)
-}
-
-// TerminateSession implements SessionSv1TerminateSession
-func (dS *DispatcherSessionSv1) TerminateSession(args *sessions.V1TerminateSessionArgs,
- reply *string) (err error) {
- return dS.dS.SessionSv1TerminateSession(args, reply)
-}
-
-// UpdateSession implements SessionSv1UpdateSession
-func (dS *DispatcherSessionSv1) UpdateSession(args *sessions.V1UpdateSessionArgs,
- reply *sessions.V1UpdateSessionReply) (err error) {
- return dS.dS.SessionSv1UpdateSession(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) GetActiveSessions(args *utils.SessionFilter,
- reply *[]*sessions.ExternalSession) (err error) {
- return dS.dS.SessionSv1GetActiveSessions(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) GetActiveSessionsCount(args *utils.SessionFilter,
- reply *int) (err error) {
- return dS.dS.SessionSv1GetActiveSessionsCount(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) ForceDisconnect(args *utils.SessionFilter,
- reply *string) (err error) {
- return dS.dS.SessionSv1ForceDisconnect(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) GetPassiveSessions(args *utils.SessionFilter,
- reply *[]*sessions.ExternalSession) (err error) {
- return dS.dS.SessionSv1GetPassiveSessions(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) GetPassiveSessionsCount(args *utils.SessionFilter,
- reply *int) (err error) {
- return dS.dS.SessionSv1GetPassiveSessionsCount(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithAPIOpts,
- reply *string) (err error) {
- return dS.dS.SessionSv1ReplicateSessions(*args, reply)
-}
-
-func (dS *DispatcherSessionSv1) SetPassiveSession(args *sessions.Session,
- reply *string) (err error) {
- return dS.dS.SessionSv1SetPassiveSession(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) ActivateSessions(args *utils.SessionIDsWithAPIOpts, reply *string) error {
- return dS.dS.SessionSv1ActivateSessions(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) DeactivateSessions(args *utils.SessionIDsWithAPIOpts, reply *string) error {
- return dS.dS.SessionSv1DeactivateSessions(args, reply)
-}
-
-func (dS *DispatcherSessionSv1) SyncSessions(args *utils.TenantWithAPIOpts, rply *string) error {
- return dS.dS.SessionSv1SyncSessions(args, rply)
-}
-
-func (dS *DispatcherSessionSv1) STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error {
- return dS.dS.SessionSv1STIRAuthenticate(args, reply)
-}
-func (dS *DispatcherSessionSv1) STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error {
- return dS.dS.SessionSv1STIRIdentity(args, reply)
-}
-
-func NewDispatcherCacheSv1(dps *dispatchers.DispatcherService) *DispatcherCacheSv1 {
- return &DispatcherCacheSv1{dS: dps}
-}
-
-// Exports RPC from CacheSv1
-type DispatcherCacheSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// GetItemIDs returns the IDs for cacheID with given prefix
-func (dS *DispatcherCacheSv1) GetItemIDs(args *utils.ArgsGetCacheItemIDsWithAPIOpts,
- reply *[]string) error {
- return dS.dS.CacheSv1GetItemIDs(args, reply)
-}
-
-// HasItem verifies the existence of an Item in cache
-func (dS *DispatcherCacheSv1) HasItem(args *utils.ArgsGetCacheItemWithAPIOpts,
- reply *bool) error {
- return dS.dS.CacheSv1HasItem(args, reply)
-}
-
-// GetItemExpiryTime returns the expiryTime for an item
-func (dS *DispatcherCacheSv1) GetItemExpiryTime(args *utils.ArgsGetCacheItemWithAPIOpts,
- reply *time.Time) error {
- return dS.dS.CacheSv1GetItemExpiryTime(args, reply)
-}
-
-// RemoveItem removes the Item with ID from cache
-func (dS *DispatcherCacheSv1) RemoveItem(args *utils.ArgsGetCacheItemWithAPIOpts,
- reply *string) error {
- return dS.dS.CacheSv1RemoveItem(args, reply)
-}
-
-// RemoveItems removes the Item with ID from cache
-func (dS *DispatcherCacheSv1) RemoveItems(args utils.AttrReloadCacheWithAPIOpts,
- reply *string) error {
- return dS.dS.CacheSv1RemoveItems(args, reply)
-}
-
-// Clear will clear partitions in the cache (nil fol all, empty slice for none)
-func (dS *DispatcherCacheSv1) Clear(args *utils.AttrCacheIDsWithAPIOpts,
- reply *string) error {
- return dS.dS.CacheSv1Clear(args, reply)
-}
-
-// GetCacheStats returns CacheStats filtered by cacheIDs
-func (dS *DispatcherCacheSv1) GetCacheStats(args *utils.AttrCacheIDsWithAPIOpts,
- reply *map[string]*ltcache.CacheStats) error {
- return dS.dS.CacheSv1GetCacheStats(args, reply)
-}
-
-// PrecacheStatus checks status of active precache processes
-func (dS *DispatcherCacheSv1) PrecacheStatus(args *utils.AttrCacheIDsWithAPIOpts, reply *map[string]string) error {
- return dS.dS.CacheSv1PrecacheStatus(args, reply)
-}
-
-// HasGroup checks existence of a group in cache
-func (dS *DispatcherCacheSv1) HasGroup(args *utils.ArgsGetGroupWithAPIOpts,
- reply *bool) (err error) {
- return dS.dS.CacheSv1HasGroup(args, reply)
-}
-
-// GetGroupItemIDs returns a list of itemIDs in a cache group
-func (dS *DispatcherCacheSv1) GetGroupItemIDs(args *utils.ArgsGetGroupWithAPIOpts,
- reply *[]string) (err error) {
- return dS.dS.CacheSv1GetGroupItemIDs(args, reply)
-}
-
-// RemoveGroup will remove a group and all items belonging to it from cache
-func (dS *DispatcherCacheSv1) RemoveGroup(args *utils.ArgsGetGroupWithAPIOpts,
- reply *string) (err error) {
- return dS.dS.CacheSv1RemoveGroup(args, reply)
-}
-
-// ReloadCache reloads cache from DB for a prefix or completely
-func (dS *DispatcherCacheSv1) ReloadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) {
- return dS.dS.CacheSv1ReloadCache(*args, reply)
-}
-
-// LoadCache loads cache from DB for a prefix or completely
-func (dS *DispatcherCacheSv1) LoadCache(args *utils.AttrReloadCacheWithAPIOpts, reply *string) (err error) {
- return dS.dS.CacheSv1LoadCache(*args, reply)
-}
-
-// ReplicateSet replicate an item
-func (dS *DispatcherCacheSv1) ReplicateSet(args *utils.ArgCacheReplicateSet, reply *string) (err error) {
- return dS.dS.CacheSv1ReplicateSet(args, reply)
-}
-
-// ReplicateRemove remove an item
-func (dS *DispatcherCacheSv1) ReplicateRemove(args *utils.ArgCacheReplicateRemove, reply *string) (err error) {
- return dS.dS.CacheSv1ReplicateRemove(args, reply)
-}
-
-// Ping used to determinate if component is active
-func (dS *DispatcherCacheSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.CacheSv1Ping(args, reply)
-}
-
-func NewDispatcherGuardianSv1(dps *dispatchers.DispatcherService) *DispatcherGuardianSv1 {
- return &DispatcherGuardianSv1{dS: dps}
-}
-
-// Exports RPC from CacheSv1
-type DispatcherGuardianSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// RemoteLock will lock a key from remote
-func (dS *DispatcherGuardianSv1) RemoteLock(attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) {
- return dS.dS.GuardianSv1RemoteLock(*attr, reply)
-}
-
-// RemoteUnlock will unlock a key from remote based on reference ID
-func (dS *DispatcherGuardianSv1) RemoteUnlock(attr *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) {
- return dS.dS.GuardianSv1RemoteUnlock(*attr, reply)
-}
-
-// Ping used to detreminate if component is active
-func (dS *DispatcherGuardianSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.GuardianSv1Ping(args, reply)
-}
-
-func NewDispatcherSv1(dS *dispatchers.DispatcherService) *DispatcherSv1 {
- return &DispatcherSv1{dS: dS}
-}
-
-type DispatcherSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// GetProfileForEvent returns the matching dispatcher profile for the provided event
-func (dSv1 DispatcherSv1) GetProfileForEvent(ev *utils.CGREvent,
- dPrfl *engine.DispatcherProfile) error {
- return dSv1.dS.V1GetProfileForEvent(ev, dPrfl)
-}
-
-/*
-func (dSv1 DispatcherSv1) Apier(args *utils.MethodParameters, reply *interface{}) (err error) {
- return dSv1.dS.V1Apier(new(APIerSv1), args, reply)
-}
-*/
-
-func (rS *DispatcherSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-func NewDispatcherSCDRsV1(dps *dispatchers.DispatcherService) *DispatcherSCDRsV1 {
- return &DispatcherSCDRsV1{dS: dps}
-}
-
-// Exports RPC from CDRsV1
-type DispatcherSCDRsV1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// Ping used to detreminate if component is active
-func (dS *DispatcherSCDRsV1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.CDRsV1Ping(args, reply)
-}
-
-func (dS *DispatcherSCDRsV1) GetCDRs(args *utils.RPCCDRsFilterWithAPIOpts, reply *[]*engine.CDR) error {
- return dS.dS.CDRsV1GetCDRs(args, reply)
-}
-
-func (dS *DispatcherSCDRsV1) GetCDRsCount(args *utils.RPCCDRsFilterWithAPIOpts, reply *int64) error {
- return dS.dS.CDRsV1GetCDRsCount(args, reply)
-}
-
-func (dS *DispatcherSCDRsV1) RateCDRs(args *engine.ArgRateCDRs, reply *string) error {
- return dS.dS.CDRsV1RateCDRs(args, reply)
-}
-
-func (dS *DispatcherSCDRsV1) ProcessExternalCDR(args *engine.ExternalCDRWithAPIOpts, reply *string) error {
- return dS.dS.CDRsV1ProcessExternalCDR(args, reply)
-}
-
-func (dS *DispatcherSCDRsV1) ProcessEvent(args *engine.ArgV1ProcessEvent, reply *string) error {
- return dS.dS.CDRsV1ProcessEvent(args, reply)
-}
-
-func (dS *DispatcherSCDRsV1) ProcessCDR(args *engine.CDRWithAPIOpts, reply *string) error {
- return dS.dS.CDRsV1ProcessCDR(args, reply)
-}
-
-func NewDispatcherSServiceManagerV1(dps *dispatchers.DispatcherService) *DispatcherSServiceManagerV1 {
- return &DispatcherSServiceManagerV1{dS: dps}
-}
-
-// Exports RPC from ServiceManagerV1
-type DispatcherSServiceManagerV1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// Ping used to detreminate if component is active
-func (dS *DispatcherSServiceManagerV1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.ServiceManagerV1Ping(args, reply)
-}
-
-func NewDispatcherConfigSv1(dps *dispatchers.DispatcherService) *DispatcherConfigSv1 {
- return &DispatcherConfigSv1{dS: dps}
-}
-
-// Exports RPC from CDRsV1
-type DispatcherConfigSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-func (dS *DispatcherConfigSv1) GetConfig(args *config.SectionWithAPIOpts, reply *map[string]interface{}) (err error) {
- return dS.dS.ConfigSv1GetConfig(args, reply)
-}
-
-func (dS *DispatcherConfigSv1) ReloadConfig(args *config.ReloadArgs, reply *string) (err error) {
- return dS.dS.ConfigSv1ReloadConfig(args, reply)
-}
-
-func (dS *DispatcherConfigSv1) SetConfig(args *config.SetConfigArgs, reply *string) (err error) {
- return dS.dS.ConfigSv1SetConfig(args, reply)
-}
-
-func (dS *DispatcherConfigSv1) SetConfigFromJSON(args *config.SetConfigFromJSONArgs, reply *string) (err error) {
- return dS.dS.ConfigSv1SetConfigFromJSON(args, reply)
-}
-func (dS *DispatcherConfigSv1) GetConfigAsJSON(args *config.SectionWithAPIOpts, reply *string) (err error) {
- return dS.dS.ConfigSv1GetConfigAsJSON(args, reply)
-}
-
-func NewDispatcherCoreSv1(dps *dispatchers.DispatcherService) *DispatcherCoreSv1 {
- return &DispatcherCoreSv1{dS: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherCoreSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-func (dS *DispatcherCoreSv1) Status(args *utils.TenantWithAPIOpts, reply *map[string]interface{}) error {
- return dS.dS.CoreSv1Status(args, reply)
-}
-
-// Ping used to detreminate if component is active
-func (dS *DispatcherCoreSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.CoreSv1Ping(args, reply)
-}
-
-func (dS *DispatcherCoreSv1) Sleep(arg *utils.DurationArgs, reply *string) error {
- return dS.dS.CoreSv1Sleep(arg, reply)
-}
-
-type DispatcherReplicatorSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-func NewDispatcherReplicatorSv1(dps *dispatchers.DispatcherService) *DispatcherReplicatorSv1 {
- return &DispatcherReplicatorSv1{dS: dps}
-}
-
-// Ping used to detreminate if component is active
-func (dS *DispatcherReplicatorSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dS.dS.ReplicatorSv1Ping(args, reply)
-}
-
-// GetDestination
-func (dS *DispatcherReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error {
- return dS.dS.ReplicatorSv1GetDestination(key, reply)
-}
-
-// GetReverseDestination
-func (dS *DispatcherReplicatorSv1) GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error {
- return dS.dS.ReplicatorSv1GetReverseDestination(key, reply)
-}
-
-// GetStatQueue
-func (dS *DispatcherReplicatorSv1) GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error {
- return dS.dS.ReplicatorSv1GetStatQueue(tntID, reply)
-}
-
-// GetFilter
-func (dS *DispatcherReplicatorSv1) GetFilter(tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error {
- return dS.dS.ReplicatorSv1GetFilter(tntID, reply)
-}
-
-// GetThreshold
-func (dS *DispatcherReplicatorSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error {
- return dS.dS.ReplicatorSv1GetThreshold(tntID, reply)
-}
-
-// GetThresholdProfile
-func (dS *DispatcherReplicatorSv1) GetThresholdProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error {
- return dS.dS.ReplicatorSv1GetThresholdProfile(tntID, reply)
-}
-
-// GetStatQueueProfile
-func (dS *DispatcherReplicatorSv1) GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error {
- return dS.dS.ReplicatorSv1GetStatQueueProfile(tntID, reply)
-}
-
-// GetTiming
-func (dS *DispatcherReplicatorSv1) GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error {
- return dS.dS.ReplicatorSv1GetTiming(id, reply)
-}
-
-// GetResource
-func (dS *DispatcherReplicatorSv1) GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error {
- return dS.dS.ReplicatorSv1GetResource(tntID, reply)
-}
-
-// GetResourceProfile
-func (dS *DispatcherReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error {
- return dS.dS.ReplicatorSv1GetResourceProfile(tntID, reply)
-}
-
-// GetRouteProfile
-func (dS *DispatcherReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error {
- return dS.dS.ReplicatorSv1GetRouteProfile(tntID, reply)
-}
-
-// GetAttributeProfile
-func (dS *DispatcherReplicatorSv1) GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error {
- return dS.dS.ReplicatorSv1GetAttributeProfile(tntID, reply)
-}
-
-// GetChargerProfile
-func (dS *DispatcherReplicatorSv1) GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error {
- return dS.dS.ReplicatorSv1GetChargerProfile(tntID, reply)
-}
-
-// GetDispatcherProfile
-func (dS *DispatcherReplicatorSv1) GetDispatcherProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error {
- 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)
-}
-
-// GetItemLoadIDs
-func (dS *DispatcherReplicatorSv1) GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error {
- return dS.dS.ReplicatorSv1GetItemLoadIDs(itemID, reply)
-}
-
-//finished all the above
-
-// SetThresholdProfile
-func (dS *DispatcherReplicatorSv1) SetThresholdProfile(args *engine.ThresholdProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetThresholdProfile(args, reply)
-}
-
-// SetThreshold
-func (dS *DispatcherReplicatorSv1) SetThreshold(args *engine.ThresholdWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetThreshold(args, reply)
-}
-
-// SetDestination
-func (dS *DispatcherReplicatorSv1) SetDestination(args *engine.DestinationWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetDestination(args, reply)
-}
-
-// SetReverseDestination
-func (dS *DispatcherReplicatorSv1) SetReverseDestination(args *engine.DestinationWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetReverseDestination(args, reply)
-}
-
-// SetStatQueue
-func (dS *DispatcherReplicatorSv1) SetStatQueue(args *engine.StatQueueWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetStatQueue(args, reply)
-}
-
-// SetFilter
-func (dS *DispatcherReplicatorSv1) SetFilter(args *engine.FilterWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetFilter(args, reply)
-}
-
-// SetStatQueueProfile
-func (dS *DispatcherReplicatorSv1) SetStatQueueProfile(args *engine.StatQueueProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetStatQueueProfile(args, reply)
-}
-
-// SetTiming
-func (dS *DispatcherReplicatorSv1) SetTiming(args *utils.TPTimingWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetTiming(args, reply)
-}
-
-// SetResource
-func (dS *DispatcherReplicatorSv1) SetResource(args *engine.ResourceWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetResource(args, reply)
-}
-
-// SetResourceProfile
-func (dS *DispatcherReplicatorSv1) SetResourceProfile(args *engine.ResourceProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetResourceProfile(args, reply)
-}
-
-// SetRouteProfile
-func (dS *DispatcherReplicatorSv1) SetRouteProfile(args *engine.RouteProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetRouteProfile(args, reply)
-}
-
-// SetAttributeProfile
-func (dS *DispatcherReplicatorSv1) SetAttributeProfile(args *engine.AttributeProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetAttributeProfile(args, reply)
-}
-
-// SetChargerProfile
-func (dS *DispatcherReplicatorSv1) SetChargerProfile(args *engine.ChargerProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetChargerProfile(args, reply)
-}
-
-// SetDispatcherProfile
-func (dS *DispatcherReplicatorSv1) SetDispatcherProfile(args *engine.DispatcherProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetDispatcherProfile(args, reply)
-}
-
-// SetRateProfile
-func (dS *DispatcherReplicatorSv1) SetRateProfile(args *utils.RateProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetRateProfile(args, reply)
-}
-
-// SetDispatcherHost
-func (dS *DispatcherReplicatorSv1) SetDispatcherHost(args *engine.DispatcherHostWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetDispatcherHost(args, reply)
-}
-
-// RemoveThreshold
-func (dS *DispatcherReplicatorSv1) RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveThreshold(args, reply)
-}
-
-// SetLoadIDs
-func (dS *DispatcherReplicatorSv1) SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetLoadIDs(args, reply)
-}
-
-// RemoveDestination
-func (dS *DispatcherReplicatorSv1) RemoveDestination(args *utils.StringWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveDestination(args, reply)
-}
-
-// RemoveStatQueue
-func (dS *DispatcherReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveStatQueue(args, reply)
-}
-
-// RemoveFilter
-func (dS *DispatcherReplicatorSv1) RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveFilter(args, reply)
-}
-
-// RemoveThresholdProfile
-func (dS *DispatcherReplicatorSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveThresholdProfile(args, reply)
-}
-
-// RemoveStatQueueProfile
-func (dS *DispatcherReplicatorSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveStatQueueProfile(args, reply)
-}
-
-// RemoveTiming
-func (dS *DispatcherReplicatorSv1) RemoveTiming(args *utils.StringWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveTiming(args, reply)
-}
-
-// RemoveResource
-func (dS *DispatcherReplicatorSv1) RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveResource(args, reply)
-}
-
-// RemoveResourceProfile
-func (dS *DispatcherReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveResourceProfile(args, reply)
-}
-
-// RemoveRouteProfile
-func (dS *DispatcherReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveRouteProfile(args, reply)
-}
-
-// RemoveAttributeProfile
-func (dS *DispatcherReplicatorSv1) RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveAttributeProfile(args, reply)
-}
-
-// RemoveChargerProfile
-func (dS *DispatcherReplicatorSv1) RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveChargerProfile(args, reply)
-}
-
-// RemoveDispatcherProfile
-func (dS *DispatcherReplicatorSv1) RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveDispatcherProfile(args, reply)
-}
-
-// RemoveDispatcherHost
-func (dS *DispatcherReplicatorSv1) RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *string) error {
- 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)
-}
-
-// SetIndexes .
-func (dS *DispatcherReplicatorSv1) SetIndexes(args *utils.SetIndexesArg, reply *string) error {
- return dS.dS.ReplicatorSv1SetIndexes(args, reply)
-}
-
-// RemoveIndexes .
-func (dS *DispatcherReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveIndexes(args, reply)
-}
-
-// GetAccount .
-func (dS *DispatcherReplicatorSv1) GetAccount(tntID *utils.TenantIDWithAPIOpts, reply *utils.Account) error {
- return dS.dS.ReplicatorSv1GetAccount(tntID, reply)
-}
-
-// SetAccount .
-func (dS *DispatcherReplicatorSv1) SetAccount(args *utils.AccountWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetAccount(args, reply)
-}
-
-// RemoveAccount .
-func (dS *DispatcherReplicatorSv1) RemoveAccount(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveAccount(args, reply)
-}
-
-// GetActionProfile .
-func (dS *DispatcherReplicatorSv1) GetActionProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ActionProfile) error {
- return dS.dS.ReplicatorSv1GetActionProfile(tntID, reply)
-}
-
-// SetActionProfile .
-func (dS *DispatcherReplicatorSv1) SetActionProfile(args *engine.ActionProfileWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1SetActionProfile(args, reply)
-}
-
-// RemoveActionProfile .
-func (dS *DispatcherReplicatorSv1) RemoveActionProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- return dS.dS.ReplicatorSv1RemoveActionProfile(args, reply)
-}
-
-func NewDispatcherRateSv1(dps *dispatchers.DispatcherService) *DispatcherRateSv1 {
- return &DispatcherRateSv1{dR: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherRateSv1 struct {
- dR *dispatchers.DispatcherService
-}
-
-// Ping implements RateSv1Ping
-func (dR *DispatcherRateSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dR.dR.RateSv1Ping(args, reply)
-}
-
-func (dR *DispatcherRateSv1) CostForEvent(args *utils.ArgsCostForEvent, rpCost *utils.RateProfileCost) error {
- return dR.dR.RateSv1CostForEvent(args, rpCost)
-}
-
-func NewDispatcherActionSv1(dps *dispatchers.DispatcherService) *DispatcherActionSv1 {
- return &DispatcherActionSv1{dR: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherActionSv1 struct {
- dR *dispatchers.DispatcherService
-}
-
-// Ping implements ActionSv1Ping
-func (dR *DispatcherActionSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dR.dR.ActionSv1Ping(args, reply)
-}
-
-func (dR *DispatcherActionSv1) ScheduleActions(args *utils.ArgActionSv1ScheduleActions, rpl *string) error {
- return dR.dR.ActionSv1ScheduleActions(args, rpl)
-}
-func (dR *DispatcherActionSv1) ExecuteActions(args *utils.ArgActionSv1ScheduleActions, rpl *string) error {
- return dR.dR.ActionSv1ExecuteActions(args, rpl)
-}
-
-func NewDispatcherAccountSv1(dps *dispatchers.DispatcherService) *DispatcherAccountSv1 {
- return &DispatcherAccountSv1{dR: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherAccountSv1 struct {
- dR *dispatchers.DispatcherService
-}
-
-// Ping implements AccountSv1Ping
-func (dR *DispatcherAccountSv1) Ping(args *utils.CGREvent, reply *string) error {
- return dR.dR.AccountSv1Ping(args, reply)
-}
-
-func (dR *DispatcherAccountSv1) AccountsForEvent(args *utils.ArgsAccountsForEvent, aps *[]*utils.Account) error {
- return dR.dR.AccountsForEvent(args, aps)
-}
-
-func (dR *DispatcherAccountSv1) MaxAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error {
- return dR.dR.MaxAbstracts(args, eEc)
-}
-
-func (dR *DispatcherAccountSv1) DebitAbstracts(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error {
- return dR.dR.DebitAbstracts(args, eEc)
-}
-
-func (dR *DispatcherAccountSv1) MaxConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error {
- return dR.dR.MaxConcretes(args, eEc)
-}
-
-func (dR *DispatcherAccountSv1) DebitConcretes(args *utils.ArgsAccountsForEvent, eEc *utils.ExtEventCharges) error {
- return dR.dR.DebitConcretes(args, eEc)
-}
-
-func (dR *DispatcherAccountSv1) ActionSetBalance(args *utils.ArgsActSetBalance, eEc *string) (err error) {
- return dR.dR.AccountSv1ActionSetBalance(args, eEc)
-}
-
-func (dR *DispatcherAccountSv1) ActionRemoveBalance(args *utils.ArgsActRemoveBalances, eEc *string) (err error) {
- return dR.dR.AccountSv1ActionRemoveBalance(args, eEc)
-}
diff --git a/apier/v1/dispatcher_it_test.go b/apier/v1/dispatcher_it_test.go
deleted file mode 100644
index 89b30a1b7..000000000
--- a/apier/v1/dispatcher_it_test.go
+++ /dev/null
@@ -1,534 +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"
- "github.com/cgrates/ltcache"
-)
-
-var (
- dispatcherCfgPath string
- dispatcherCfg *config.CGRConfig
- dispatcherRPC *rpc.Client
- dispatcherProfile *DispatcherWithAPIOpts
- dispatcherHost *engine.DispatcherHostWithAPIOpts
- dispatcherConfigDIR string //run tests for specific configuration
-
- sTestsDispatcher = []func(t *testing.T){
-
- testDispatcherSInitCfg,
- testDispatcherSInitDataDb,
- testDispatcherSResetStorDb,
- testDispatcherSStartEngine,
- testDispatcherSRPCConn,
-
- testDispatcherSSetDispatcherProfile,
- testDispatcherSGetDispatcherProfileIDs,
- testDispatcherSUpdateDispatcherProfile,
- testDispatcherSGetDispatcherProfileCache,
- testDispatcherSRemDispatcherProfile,
- testDispatcherSSetDispatcherProfileWithoutTenant,
- testDispatcherSRemDispatcherProfileWithoutTenant,
-
- testDispatcherSSetDispatcherHost,
- testDispatcherSGetDispatcherHostIDs,
- testDispatcherSUpdateDispatcherHost,
- testDispatcherSGetDispatcherHostCache,
- testDispatcherSRemDispatcherHost,
- testDispatcherSSetDispatcherHostWithoutTenant,
- testDispatcherSRemDispatcherHostWithoutTenant,
-
- testDispatcherSKillEngine,
-
- //cache test
- testDispatcherSInitCfg,
- testDispatcherSInitDataDb,
- testDispatcherSResetStorDb,
- testDispatcherSStartEngine,
- testDispatcherSRPCConn,
- testDispatcherSCacheTestGetNotFound,
- testDispatcherSCacheTestSet,
- testDispatcherSCacheTestGetNotFound,
- testDispatcherSCacheReload,
- testDispatcherSCacheTestGetFound,
- testDispatcherSKillEngine,
- }
-)
-
-//Test start here
-func TestDispatcherSIT(t *testing.T) {
- sTestsDispatcherCacheSV1 := sTestsDispatcher
- switch *dbType {
- case utils.MetaInternal:
- dispatcherConfigDIR = "tutinternal"
- sTestsDispatcherCacheSV1 = sTestsDispatcherCacheSV1[:len(sTestsDispatcherCacheSV1)-10]
- case utils.MetaMySQL:
- dispatcherConfigDIR = "tutmysql"
- case utils.MetaMongo:
- dispatcherConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsDispatcherCacheSV1 {
- t.Run(dispatcherConfigDIR, stest)
- }
-}
-
-func testDispatcherSInitCfg(t *testing.T) {
- var err error
- dispatcherCfgPath = path.Join(*dataDir, "conf", "samples", dispatcherConfigDIR)
- dispatcherCfg, err = config.NewCGRConfigFromPath(dispatcherCfgPath)
- if err != nil {
- t.Error(err)
- }
- dispatcherCfg.DataFolderPath = *dataDir
-}
-
-func testDispatcherSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(dispatcherCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testDispatcherSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(dispatcherCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testDispatcherSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(dispatcherCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testDispatcherSRPCConn(t *testing.T) {
- var err error
- dispatcherRPC, err = newRPCClient(dispatcherCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testDispatcherSSetDispatcherProfile(t *testing.T) {
- var reply string
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "Dsp1",
- FilterIDs: []string{"*wrong:inline"},
- Strategy: utils.MetaFirst,
- Weight: 20,
- },
- }
-
- expErr := "SERVER_ERROR: broken reference to filter: *wrong:inline for item with ID: cgrates.org:Dsp1"
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile,
- &reply); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
-
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- dispatcherProfile.FilterIDs = []string{"*string:~*req.Account:1001"}
-
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- var dsp *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)
- }
-}
-
-func testDispatcherSGetDispatcherProfileIDs(t *testing.T) {
- var result []string
- expected := []string{"Dsp1"}
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs,
- &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(result) != len(expected) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfileIDs,
- &utils.PaginatorWithTenant{Tenant: dispatcherProfile.Tenant}, &result); err != nil {
- t.Error(err)
- } else if len(result) != len(expected) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testDispatcherSUpdateDispatcherProfile(t *testing.T) {
- var result string
- dispatcherProfile.Strategy = utils.MetaWeight
- dispatcherProfile.Subsystems = []string{utils.MetaAttributes, utils.MetaSessionS, utils.MetaCDRs}
- dispatcherProfile.ActivationInterval = &utils.ActivationInterval{
- ActivationTime: time.Date(2019, 3, 1, 0, 0, 0, 0, time.UTC),
- ExpiryTime: time.Date(2019, 4, 1, 0, 0, 0, 0, time.UTC),
- }
- dispatcherProfile.Hosts = engine.DispatcherHostProfiles{
- &engine.DispatcherHostProfile{ID: "HOST1", Weight: 20.0},
- &engine.DispatcherHostProfile{ID: "HOST2", Weight: 10.0},
- }
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, result)
- }
-
- var dsp *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)
- }
-}
-
-func testDispatcherSGetDispatcherProfileCache(t *testing.T) {
- if dispatcherConfigDIR == "tutinternal" {
- t.SkipNow()
- }
- var rcvStats map[string]*ltcache.CacheStats
- if err := dispatcherRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error(err)
- } else if rcvStats[utils.CacheDispatcherProfiles].Items != 1 {
- t.Errorf("Expecting: 1 DispatcherProfiles, received: %+v", rcvStats[utils.CacheDispatcherProfiles])
- }
-}
-
-func testDispatcherSRemDispatcherProfile(t *testing.T) {
- var result string
- if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, result)
- }
-
- var dsp *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &dsp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}},
- &result); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testDispatcherSSetDispatcherHost(t *testing.T) {
- var reply string
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- dispatcherHost = &engine.DispatcherHostWithAPIOpts{
- DispatcherHost: &engine.DispatcherHost{
- Tenant: "cgrates.org",
- RemoteHost: &config.RemoteHost{
- ID: "DspHst1",
- Address: "*internal",
- },
- },
- }
-
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost,
- dispatcherHost,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- var dsp *engine.DispatcherHost
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)
- }
-}
-
-func testDispatcherSGetDispatcherHostIDs(t *testing.T) {
- var result []string
- expected := []string{"DspHst1"}
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs,
- &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(result) != len(expected) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHostIDs,
- &utils.PaginatorWithTenant{Tenant: dispatcherHost.Tenant}, &result); err != nil {
- t.Error(err)
- } else if len(result) != len(expected) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testDispatcherSUpdateDispatcherHost(t *testing.T) {
- var result string
- dispatcherHost.RemoteHost = &config.RemoteHost{
- ID: "DspHst1",
- Address: ":4012",
- Transport: utils.MetaGOB,
- TLS: false,
- }
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost,
- dispatcherHost, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, result)
- }
-
- var dsp *engine.DispatcherHost
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)
- }
-}
-
-func testDispatcherSGetDispatcherHostCache(t *testing.T) {
- if dispatcherConfigDIR == "tutinternal" {
- t.SkipNow()
- }
- var rcvStats map[string]*ltcache.CacheStats
- if err := dispatcherRPC.Call(utils.CacheSv1GetCacheStats, &utils.AttrCacheIDsWithAPIOpts{}, &rcvStats); err != nil {
- t.Error(err)
- } else if rcvStats[utils.CacheDispatcherHosts].Items != 0 {
- t.Errorf("Expecting: 0 DispatcherProfiles, received: %+v", rcvStats[utils.CacheDispatcherHosts])
- }
-}
-
-func testDispatcherSRemDispatcherHost(t *testing.T) {
- var result string
- if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, result)
- }
-
- var dsp *engine.DispatcherHost
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}},
- &result); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testDispatcherSKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
-
-func testDispatcherSSetDispatcherProfileWithoutTenant(t *testing.T) {
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- ID: "Dsp1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Strategy: utils.MetaFirst,
- Weight: 20,
- },
- }
- var reply string
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- dispatcherProfile.DispatcherProfile.Tenant = "cgrates.org"
- var result *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{ID: "Dsp1"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, result) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(dispatcherProfile.DispatcherProfile), utils.ToJSON(result))
- }
-}
-
-func testDispatcherSRemDispatcherProfileWithoutTenant(t *testing.T) {
- var reply string
- if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "Dsp1"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{ID: "Dsp1"},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testDispatcherSSetDispatcherHostWithoutTenant(t *testing.T) {
- dispatcherHost = &engine.DispatcherHostWithAPIOpts{
- DispatcherHost: &engine.DispatcherHost{
- RemoteHost: &config.RemoteHost{
- ID: "DspHst7",
- Address: "*internal",
- },
- },
- }
- var reply string
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherHost, dispatcherHost, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- dispatcherHost.DispatcherHost.Tenant = "cgrates.org"
- var result *engine.DispatcherHost
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{ID: "DspHst7"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, dispatcherHost.DispatcherHost) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(dispatcherHost.DispatcherHost), utils.ToJSON(result))
- }
-}
-
-func testDispatcherSRemDispatcherHostWithoutTenant(t *testing.T) {
- var reply string
- if err := dispatcherRPC.Call(utils.APIerSv1RemoveDispatcherHost,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "DspHst7"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.DispatcherHost
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{ID: "DspHst7"},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testDispatcherSCacheTestGetNotFound(t *testing.T) {
- var suplsReply *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "DISPATCHER_CACHE",
- }, &suplsReply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testDispatcherSCacheTestGetFound(t *testing.T) {
- var suplsReply *engine.DispatcherProfile
- if err := dispatcherRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "DISPATCHER_CACHE",
- }, &suplsReply); err != nil {
- t.Error(err)
- }
-}
-
-func testDispatcherSCacheTestSet(t *testing.T) {
- var reply string
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "DISPATCHER_CACHE",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- if err := dispatcherRPC.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
-}
-
-func testDispatcherSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.DispatcherProfileIDs: {"cgrates.org:DISPATCHER_CACHE"},
- },
- }
- var reply string
- if err := dispatcherRPC.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/dispatchersv1_it_test.go b/apier/v1/dispatchersv1_it_test.go
deleted file mode 100644
index dd1e216ff..000000000
--- a/apier/v1/dispatchersv1_it_test.go
+++ /dev/null
@@ -1,246 +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"
- "os/exec"
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- dspCfgPath string
- dspCfg *config.CGRConfig
- dspRPC *rpc.Client
-
- sTestsDspDspv1 = []func(t *testing.T){
- testDspITLoadConfig,
- testDspITResetDataDB,
- testDspITResetStorDb,
- testDspITStartEngine,
- testDspITRPCConn,
- testDspITLoadData,
- testDspDspv1GetProfileForEvent,
- testDspDspv1GetProfileForEventWithMethod,
- testDspITStopCgrEngine,
- }
-)
-
-//Test start here
-
-func TestDspDspv1(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- dispatcherConfigDIR = "dispatchers_mysql"
- case utils.MetaMongo:
- dispatcherConfigDIR = "dispatchers_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- if *encoding == utils.MetaGOB {
- dispatcherConfigDIR += "_gob"
- }
- for _, stest := range sTestsDspDspv1 {
- t.Run(dispatcherConfigDIR, stest)
- }
-}
-
-func testDspITLoadConfig(t *testing.T) {
- var err error
- dspCfgPath = path.Join(*dataDir, "conf", "samples", "dispatchers", dispatcherConfigDIR)
- if dspCfg, err = config.NewCGRConfigFromPath(dspCfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testDspITResetDataDB(t *testing.T) {
- if err := engine.InitDataDB(dspCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testDspITResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(dspCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testDspITStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(dspCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testDspITRPCConn(t *testing.T) {
- var err error
- dspRPC, err = newRPCClient(dspCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testDspITLoadData(t *testing.T) {
- wchan := make(chan struct{}, 1)
- go func() {
- loaderPath, err := exec.LookPath("cgr-loader")
- if err != nil {
- t.Error(err)
- }
- loader := exec.Command(loaderPath, "-config_path", dspCfgPath, "-path", path.Join(*dataDir, "tariffplans", "dispatchers"))
-
- if err := loader.Start(); err != nil {
- t.Error(err)
- }
- loader.Wait()
- wchan <- struct{}{}
- }()
- select {
- case <-wchan:
- case <-time.After(time.Second):
- t.Errorf("cgr-loader failed: ")
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testDspDspv1GetProfileForEvent(t *testing.T) {
- arg := &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testDspv1",
- Event: map[string]interface{}{
- utils.EventName: "Event1",
- },
- APIOpts: map[string]interface{}{
- utils.Subsys: utils.MetaAny,
- },
- }
- var reply engine.DispatcherProfile
- expected := engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "EVENT1",
- Subsystems: []string{utils.MetaAny},
- FilterIDs: []string{"*string:~*req.EventName:Event1"},
- StrategyParams: make(map[string]interface{}),
- Strategy: utils.MetaWeight,
- Weight: 30,
- Hosts: engine.DispatcherHostProfiles{
- &engine.DispatcherHostProfile{
- ID: "ALL2",
- FilterIDs: []string{},
- Weight: 20,
- Params: make(map[string]interface{}),
- },
- &engine.DispatcherHostProfile{
- ID: "ALL",
- FilterIDs: []string{},
- Weight: 10,
- Params: make(map[string]interface{}),
- },
- },
- }
- if *encoding == utils.MetaGOB { // in gob emtpty slice is encoded as nil
- expected.Hosts[0].FilterIDs = nil
- expected.Hosts[1].FilterIDs = nil
- }
- expected.Hosts.Sort()
- if err := dspRPC.Call(utils.DispatcherSv1GetProfileForEvent, &arg, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Hosts.Sort()
- if !reflect.DeepEqual(expected, reply) {
- t.Errorf("expected: %s ,\n received: %s", utils.ToJSON(expected), utils.ToJSON(reply))
- }
-
- arg2 := &utils.CGREvent{
- ID: "testDspvWithoutTenant",
- Event: map[string]interface{}{
- utils.EventName: "Event1",
- },
- APIOpts: map[string]interface{}{
- utils.Subsys: utils.MetaAny,
- },
- }
- expected.Hosts.Sort()
- if err := dspRPC.Call(utils.DispatcherSv1GetProfileForEvent, &arg2, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Hosts.Sort()
- if !reflect.DeepEqual(expected, reply) {
- t.Errorf("expected: %s ,\n received: %s", utils.ToJSON(expected), utils.ToJSON(reply))
- }
-}
-
-func testDspDspv1GetProfileForEventWithMethod(t *testing.T) {
- arg := &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testDspv2",
- Event: map[string]interface{}{},
- APIOpts: map[string]interface{}{
- utils.Subsys: utils.MetaAny,
- utils.OptsDispatcherMethod: utils.DispatcherSv1GetProfileForEvent,
- },
- }
- var reply engine.DispatcherProfile
- expected := engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "EVENT6",
- Subsystems: []string{utils.MetaAny},
- FilterIDs: []string{"*string:~*opts.*method:DispatcherSv1.GetProfileForEvent"},
- StrategyParams: make(map[string]interface{}),
- Strategy: utils.MetaWeight,
- Weight: 20,
- Hosts: engine.DispatcherHostProfiles{
- &engine.DispatcherHostProfile{
- ID: "SELF",
- FilterIDs: []string{},
- Weight: 20,
- Params: make(map[string]interface{}),
- },
- },
- }
- if *encoding == utils.MetaGOB { // in gob emtpty slice is encoded as nil
- expected.Hosts[0].FilterIDs = nil
- }
- expected.Hosts.Sort()
- if err := dspRPC.Call(utils.DispatcherSv1GetProfileForEvent, &arg, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Hosts.Sort()
- if !reflect.DeepEqual(expected, reply) {
- t.Errorf("expected: %s ,\n received: %s", utils.ToJSON(expected), utils.ToJSON(reply))
- }
-}
-
-func testDspITStopCgrEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/ees.go b/apier/v1/ees.go
deleted file mode 100644
index 3073eeb71..000000000
--- a/apier/v1/ees.go
+++ /dev/null
@@ -1,44 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/ees"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewEeSv1(eeS *ees.EventExporterS) *EeSv1 {
- return &EeSv1{eeS: eeS}
-}
-
-type EeSv1 struct {
- eeS *ees.EventExporterS
-}
-
-func (eeSv1 *EeSv1) Ping(_ context.Context, _ *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// ProcessEvent triggers exports on EEs side
-func (eeSv1 *EeSv1) ProcessEvent(args *utils.CGREventWithEeIDs,
- reply *map[string]map[string]interface{}) error {
- return eeSv1.eeS.V1ProcessEvent(args, reply)
-}
diff --git a/apier/v1/ees_it_test.go b/apier/v1/ees_it_test.go
deleted file mode 100644
index d0f52b1c9..000000000
--- a/apier/v1/ees_it_test.go
+++ /dev/null
@@ -1,323 +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"
- "os"
- "path"
- "path/filepath"
- "strings"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- eeSCfgPath string
- eeSCfg *config.CGRConfig
- eeSRPC *rpc.Client
- eeSConfigDIR string //run tests for specific configuration
-
- sTestsEEs = []func(t *testing.T){
- testEEsPrepareFolder,
- testEEsInitCfg,
- testEEsInitDataDb,
- testEEsResetStorDb,
- testEEsStartEngine,
- testEEsRPCConn,
- testEEsAddCDRs,
- testEEsExportCDRs,
- testEEsVerifyExports,
- testEEsExportCDRsMultipleExporters,
- testEEsVerifyExportsMultipleExporters,
- testEEsKillEngine,
- testEEsCleanFolder,
- }
-)
-
-//Test start here
-func TestExportCDRs(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- eeSConfigDIR = "ees_internal"
- case utils.MetaMySQL:
- eeSConfigDIR = "ees_mysql"
- case utils.MetaMongo:
- eeSConfigDIR = "ees_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsEEs {
- t.Run(eeSConfigDIR, stest)
- }
-}
-
-func testEEsPrepareFolder(t *testing.T) {
- for _, dir := range []string{"/tmp/testCSV", "/tmp/testCSV2", "/tmp/testCSV3"} {
- if err := os.RemoveAll(dir); err != nil {
- t.Fatal("Error removing folder: ", dir, err)
- }
- if err := os.MkdirAll(dir, os.ModePerm); err != nil {
- t.Fatal("Error creating folder: ", dir, err)
- }
- }
-}
-
-func testEEsInitCfg(t *testing.T) {
- var err error
- eeSCfgPath = path.Join(*dataDir, "conf", "samples", eeSConfigDIR)
- eeSCfg, err = config.NewCGRConfigFromPath(eeSCfgPath)
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testEEsInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(eeSCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testEEsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(eeSCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testEEsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(eeSCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testEEsRPCConn(t *testing.T) {
- var err error
- eeSRPC, err = newRPCClient(eeSCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testEEsAddCDRs(t *testing.T) {
- //add a default charger
- chargerProfile := &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Default",
- RunID: utils.MetaRaw,
- AttributeIDs: []string{"*none"},
- Weight: 20,
- },
- }
- var result string
- if err := eeSRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- storedCdrs := []*engine.CDR{
- {CGRID: "Cdr1",
- OrderID: 1, ToR: utils.MetaVoice, OriginID: "OriginCDR1", OriginHost: "192.168.1.1", Source: "test",
- RequestType: utils.MetaNone, Tenant: "cgrates.org",
- Category: "call", Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC),
- AnswerTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC), RunID: utils.MetaDefault, Usage: 10 * time.Second,
- ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01,
- },
- {CGRID: "Cdr2",
- OrderID: 2, ToR: utils.MetaVoice, OriginID: "OriginCDR2", OriginHost: "192.168.1.1", Source: "test2",
- RequestType: utils.MetaNone, Tenant: "cgrates.org", Category: "call",
- Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC),
- AnswerTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC), RunID: utils.MetaDefault, Usage: 5 * time.Second,
- ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01,
- },
- {CGRID: "Cdr3",
- OrderID: 3, ToR: utils.MetaVoice, OriginID: "OriginCDR3", OriginHost: "192.168.1.1", Source: "test2",
- RequestType: utils.MetaNone, Tenant: "cgrates.org", Category: "call",
- Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC),
- AnswerTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC), RunID: utils.MetaDefault, Usage: 30 * time.Second,
- ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01,
- },
- {CGRID: "Cdr4",
- OrderID: 4, ToR: utils.MetaVoice, OriginID: "OriginCDR4", OriginHost: "192.168.1.1", Source: "test3",
- RequestType: utils.MetaNone, Tenant: "cgrates.org", Category: "call",
- Account: "1001", Subject: "1001", Destination: "+4986517174963", SetupTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC),
- AnswerTime: time.Date(2018, 10, 4, 15, 3, 10, 0, time.UTC), RunID: utils.MetaDefault, Usage: 0,
- ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}, Cost: 1.01,
- },
- }
- for _, cdr := range storedCdrs {
- var reply string
- if err := eeSRPC.Call(utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
- }
-}
-
-func testEEsExportCDRs(t *testing.T) {
- attr := &utils.ArgExportCDRs{
- ExporterIDs: []string{"CSVExporter"},
- Verbose: true,
- }
- var rply map[string]interface{}
- if err := eeSRPC.Call(utils.APIerSv1ExportCDRs, &attr, &rply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- }
- if len(rply) != 1 {
- t.Errorf("Expected %+v, received: %+v", 1, len(rply))
- } else {
- val, _ := rply["CSVExporter"]
- for k, v := range val.(map[string]interface{}) {
- switch k {
- case utils.FirstExpOrderID:
- if v != 1.0 {
- t.Errorf("Expected %+v, received: %+v", 1.0, v)
- }
- case utils.LastExpOrderID:
- if v != 4.0 {
- t.Errorf("Expected %+v, received: %+v", 4.0, v)
- }
- case utils.NumberOfEvents:
- if v != 4.0 {
- t.Errorf("Expected %+v, received: %+v", 4.0, v)
- }
- case utils.TotalCost:
- if v != 4.04 {
- t.Errorf("Expected %+v, received: %+v", 4.04, v)
- }
-
- }
- }
- }
-}
-
-func testEEsVerifyExports(t *testing.T) {
- time.Sleep(time.Second + 600*time.Millisecond)
- var files []string
- err := filepath.Walk("/tmp/testCSV/", func(path string, info os.FileInfo, err error) error {
- if strings.HasSuffix(path, utils.CSVSuffix) {
- files = append(files, path)
- }
- return nil
- })
- if err != nil {
- t.Error(err)
- }
- if len(files) != 1 {
- t.Errorf("Expected %+v, received: %+v", 1, len(files))
- }
- eCnt := "Cdr1,*raw,*voice,OriginCDR1,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,10,1.01\n" +
- "Cdr2,*raw,*voice,OriginCDR2,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,5,1.01\n" +
- "Cdr3,*raw,*voice,OriginCDR3,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,30,1.01\n" +
- "Cdr4,*raw,*voice,OriginCDR4,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,0,1.01\n"
- if outContent1, err := os.ReadFile(files[0]); err != nil {
- t.Error(err)
- } else if len(eCnt) != len(string(outContent1)) {
- t.Errorf("Expecting: \n<%+v>, \nreceived: \n<%+v>", len(eCnt), len(string(outContent1)))
- t.Errorf("Expecting: \n<%q>, \nreceived: \n<%q>", eCnt, string(outContent1))
- }
-}
-
-func testEEsExportCDRsMultipleExporters(t *testing.T) {
- attr := &utils.ArgExportCDRs{
- ExporterIDs: []string{"CSVExporter", "CSVExporter2"},
- Verbose: true,
- }
- var rply map[string]interface{}
- if err := eeSRPC.Call(utils.APIerSv1ExportCDRs, &attr, &rply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- }
- if len(rply) != 2 {
- t.Errorf("Expected %+v, received: %+v", 1, len(rply))
- } else {
- for _, expID := range []string{"CSVExporter", "CSVExporter2"} {
- val, _ := rply[expID]
- for k, v := range val.(map[string]interface{}) {
- switch k {
- case utils.FirstExpOrderID:
- if v != 1.0 {
- t.Errorf("Expected %+v, received: %+v", 1.0, v)
- }
- case utils.LastExpOrderID:
- if v != 4.0 {
- t.Errorf("Expected %+v, received: %+v", 4.0, v)
- }
- case utils.NumberOfEvents:
- if v != 4.0 {
- t.Errorf("Expected %+v, received: %+v", 4.0, v)
- }
- case utils.TotalCost:
- if v != 4.04 {
- t.Errorf("Expected %+v, received: %+v", 4.04, v)
- }
-
- }
- }
- }
- }
-}
-
-func testEEsVerifyExportsMultipleExporters(t *testing.T) {
- time.Sleep(time.Second)
- var files []string
- err := filepath.Walk("/tmp/testCSV2/", func(path string, info os.FileInfo, err error) error {
- if strings.HasSuffix(path, utils.CSVSuffix) {
- files = append(files, path)
- }
- return nil
- })
- if err != nil {
- t.Error(err)
- }
- if len(files) != 1 {
- t.Errorf("Expected %+v, received: %+v", 1, len(files))
- }
- eCnt := "Cdr1,*raw,*voice,OriginCDR1,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,10,1.01\n" +
- "Cdr2,*raw,*voice,OriginCDR2,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,5,1.01\n" +
- "Cdr3,*raw,*voice,OriginCDR3,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,30,1.01\n" +
- "Cdr4,*raw,*voice,OriginCDR4,*none,cgrates.org,call,1001,1001,+4986517174963,2018-10-04T15:03:10Z,2018-10-04T15:03:10Z,0,1.01\n"
- if outContent1, err := os.ReadFile(files[0]); err != nil {
- t.Error(err)
- } else if len(eCnt) != len(string(outContent1)) {
- t.Errorf("Expecting: \n<%q>, \nreceived: \n<%q>", eCnt, string(outContent1))
- }
-}
-
-func testEEsKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testEEsCleanFolder(t *testing.T) {
- for _, dir := range []string{"/tmp/testCSV", "/tmp/testCSV2", "/tmp/testCSV3"} {
- if err := os.RemoveAll(dir); err != nil {
- t.Fatal("Error removing folder: ", dir, err)
- }
- }
-}
diff --git a/apier/v1/filter_indexes.go b/apier/v1/filter_indexes.go
deleted file mode 100644
index cf2b541d0..000000000
--- a/apier/v1/filter_indexes.go
+++ /dev/null
@@ -1,696 +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 (
- "strings"
-
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-type AttrGetFilterIndexes struct {
- Tenant string
- Context string
- ItemType string
- FilterType string
- FilterField string
- FilterValue string
- utils.Paginator
-}
-
-type AttrRemFilterIndexes struct {
- Tenant string
- Context string
- ItemType string
-}
-
-func (apierSv1 *APIerSv1) RemoveFilterIndexes(arg *AttrRemFilterIndexes, reply *string) (err error) {
- if missing := utils.MissingStructFields(arg, []string{"ItemType"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := arg.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- tntCtx := arg.Tenant
- switch arg.ItemType {
- case utils.MetaThresholds:
- arg.ItemType = utils.CacheThresholdFilterIndexes
- case utils.MetaRoutes:
- arg.ItemType = utils.CacheRouteFilterIndexes
- case utils.MetaStats:
- arg.ItemType = utils.CacheStatFilterIndexes
- case utils.MetaResources:
- arg.ItemType = utils.CacheResourceFilterIndexes
- case utils.MetaChargers:
- arg.ItemType = utils.CacheChargerFilterIndexes
- case utils.MetaAccounts:
- arg.ItemType = utils.CacheAccountsFilterIndexes
- 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...)
- }
- arg.ItemType = utils.CacheDispatcherFilterIndexes
- tntCtx = utils.ConcatenatedKey(tnt, arg.Context)
- case utils.MetaAttributes:
- if missing := utils.MissingStructFields(arg, []string{"Context"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- arg.ItemType = utils.CacheAttributeFilterIndexes
- tntCtx = utils.ConcatenatedKey(tnt, arg.Context)
- }
- if err = apierSv1.DataManager.RemoveIndexes(arg.ItemType, tntCtx, utils.EmptyString); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-func (apierSv1 *APIerSv1) GetFilterIndexes(arg *AttrGetFilterIndexes, reply *[]string) (err error) {
- var indexes map[string]utils.StringSet
- var indexedSlice []string
- indexesFilter := make(map[string]utils.StringSet)
- if missing := utils.MissingStructFields(arg, []string{"ItemType"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := arg.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- tntCtx := arg.Tenant
- switch arg.ItemType {
- case utils.MetaThresholds:
- arg.ItemType = utils.CacheThresholdFilterIndexes
- case utils.MetaRoutes:
- arg.ItemType = utils.CacheRouteFilterIndexes
- case utils.MetaStats:
- arg.ItemType = utils.CacheStatFilterIndexes
- case utils.MetaResources:
- arg.ItemType = utils.CacheResourceFilterIndexes
- case utils.MetaChargers:
- arg.ItemType = utils.CacheChargerFilterIndexes
- case utils.MetaAccounts:
- arg.ItemType = utils.CacheAccountsFilterIndexes
- 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...)
- }
- arg.ItemType = utils.CacheDispatcherFilterIndexes
- tntCtx = utils.ConcatenatedKey(tnt, arg.Context)
- case utils.MetaAttributes:
- if missing := utils.MissingStructFields(arg, []string{"Context"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- arg.ItemType = utils.CacheAttributeFilterIndexes
- tntCtx = utils.ConcatenatedKey(tnt, arg.Context)
- }
- if indexes, err = apierSv1.DataManager.GetIndexes(context.TODO(),
- arg.ItemType, tntCtx, utils.EmptyString, true, true); err != nil {
- return
- }
- if arg.FilterType != utils.EmptyString {
- for val, strmap := range indexes {
- if strings.HasPrefix(val, arg.FilterType) {
- indexesFilter[val] = strmap
- for _, value := range strmap.AsSlice() {
- indexedSlice = append(indexedSlice, utils.ConcatenatedKey(val, value))
- }
- }
- }
- if len(indexedSlice) == 0 {
- return utils.ErrNotFound
- }
- }
- if arg.FilterField != utils.EmptyString {
- if len(indexedSlice) == 0 {
- indexesFilter = make(map[string]utils.StringSet)
- for val, strmap := range indexes {
- if strings.Index(val, arg.FilterField) != -1 {
- indexesFilter[val] = strmap
- for _, value := range strmap.AsSlice() {
- indexedSlice = append(indexedSlice, utils.ConcatenatedKey(val, value))
- }
- }
- }
- if len(indexedSlice) == 0 {
- return utils.ErrNotFound
- }
- } else {
- var cloneIndexSlice []string
- for val, strmap := range indexesFilter {
- if strings.Index(val, arg.FilterField) != -1 {
- for _, value := range strmap.AsSlice() {
- cloneIndexSlice = append(cloneIndexSlice, utils.ConcatenatedKey(val, value))
- }
- }
- }
- if len(cloneIndexSlice) == 0 {
- return utils.ErrNotFound
- }
- indexedSlice = cloneIndexSlice
- }
- }
- if arg.FilterValue != utils.EmptyString {
- if len(indexedSlice) == 0 {
- for val, strmap := range indexes {
- if strings.Index(val, arg.FilterValue) != -1 {
- for _, value := range strmap.AsSlice() {
- indexedSlice = append(indexedSlice, utils.ConcatenatedKey(val, value))
- }
- }
- }
- if len(indexedSlice) == 0 {
- return utils.ErrNotFound
- }
- } else {
- var cloneIndexSlice []string
- for val, strmap := range indexesFilter {
- if strings.Index(val, arg.FilterValue) != -1 {
- for _, value := range strmap.AsSlice() {
- cloneIndexSlice = append(cloneIndexSlice, utils.ConcatenatedKey(val, value))
- }
- }
- }
- if len(cloneIndexSlice) == 0 {
- return utils.ErrNotFound
- }
- indexedSlice = cloneIndexSlice
- }
- }
- if len(indexedSlice) == 0 {
- for val, strmap := range indexes {
- for _, value := range strmap.AsSlice() {
- indexedSlice = append(indexedSlice, utils.ConcatenatedKey(val, value))
- }
- }
- }
- if arg.Paginator.Limit != nil || arg.Paginator.Offset != nil {
- *reply = arg.Paginator.PaginateStringSlice(indexedSlice)
- } else {
- *reply = indexedSlice
- }
- return nil
-}
-
-// ComputeFilterIndexes selects which index filters to recompute
-func (apierSv1 *APIerSv1) ComputeFilterIndexes(args *utils.ArgsComputeFilterIndexes, reply *string) (err error) {
- transactionID := utils.GenUUID()
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
-
- //ThresholdProfile Indexes
- if args.ThresholdS {
- if args.ThresholdS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheThresholdFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- th, e := apierSv1.DataManager.GetThresholdProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(th.FilterIDs))
- for i, fltrID := range th.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
- //StatQueueProfile Indexes
- if args.StatS {
- if args.StatS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheStatFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- sq, e := apierSv1.DataManager.GetStatQueueProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(sq.FilterIDs))
- for i, fltrID := range sq.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
- //ResourceProfile Indexes
- if args.ResourceS {
- if args.ResourceS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheResourceFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- rp, e := apierSv1.DataManager.GetResourceProfile(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)
- }
- }
- //SupplierProfile Indexes
- if args.RouteS {
- if args.RouteS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheRouteFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- rp, e := apierSv1.DataManager.GetRouteProfile(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)
- }
- }
- //AttributeProfile Indexes
- if args.AttributeS {
- if args.AttributeS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheAttributeFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- ap, e := apierSv1.DataManager.GetAttributeProfile(context.TODO(), tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- if !utils.IsSliceMember(ap.Contexts, ctx) {
- return nil, nil
- }
- fltrIDs := make([]string, len(ap.FilterIDs))
- for i, fltrID := range ap.FilterIDs {
- fltrIDs[i] = fltrID
- }
-
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
- //Account Indexes
- if args.AccountS {
- if args.AccountS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheAccountsFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- acp, e := apierSv1.DataManager.GetAccount(tnt, id)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(acp.FilterIDs))
- for i, fltrID := range acp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
- //ActionProfile Indexes
- if args.ActionS {
- if args.ActionS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheActionProfilesFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- atp, e := apierSv1.DataManager.GetActionProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(atp.FilterIDs))
- for i, fltrID := range atp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
-
- }); err != nil && err != utils.ErrNotFound {
- 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,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- ap, e := apierSv1.DataManager.GetChargerProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(ap.FilterIDs))
- for i, fltrID := range ap.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
- //DispatcherProfile Indexes
- if args.DispatcherS {
- if args.DispatcherS, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheDispatcherFilterIndexes,
- nil, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- dsp, e := apierSv1.DataManager.GetDispatcherProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- if !utils.IsSliceMember(dsp.Subsystems, ctx) {
- return nil, nil
- }
- fltrIDs := make([]string, len(dsp.FilterIDs))
- for i, fltrID := range dsp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- }
-
- tntCtx := args.Tenant
- if args.Context != utils.EmptyString {
- tntCtx = utils.ConcatenatedKey(tnt, args.Context)
- }
- //Now we move from tmpKey to the right key for each type
- //ThresholdProfile Indexes
- if args.ThresholdS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheThresholdFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //StatQueueProfile Indexes
- if args.StatS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheStatFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //ResourceProfile Indexes
- if args.ResourceS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheResourceFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //RouteProfile Indexes
- if args.RouteS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheRouteFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //Account Indexes
- if args.AccountS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheAccountsFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //ActionProfile Indexes
- if args.ActionS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheActionProfilesFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //RateProfile Indexes
- if args.RateS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheRateProfilesFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- for _, val := range ratePrf {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheRateFilterIndexes, val, nil, true, transactionID); err != nil {
- return
- }
- }
- }
- //AttributeProfile Indexes
- if args.AttributeS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheAttributeFilterIndexes, tntCtx, nil, true, transactionID); err != nil {
- return
- }
- }
- //ChargerProfile Indexes
- if args.ChargerS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheChargerFilterIndexes, tnt, nil, true, transactionID); err != nil {
- return
- }
- }
- //DispatcherProfile Indexes
- if args.DispatcherS {
- if err = apierSv1.DataManager.SetIndexes(context.TODO(), utils.CacheDispatcherFilterIndexes, tntCtx, nil, true, transactionID); err != nil {
- return
- }
- }
- *reply = utils.OK
- return nil
-}
-
-// ComputeFilterIndexIDs computes specific filter indexes
-func (apierSv1 *APIerSv1) ComputeFilterIndexIDs(args *utils.ArgsComputeFilterIndexIDs, reply *string) (err error) {
- transactionID := utils.NonTransactional
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- //ThresholdProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheThresholdFilterIndexes,
- &args.ThresholdIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- th, e := apierSv1.DataManager.GetThresholdProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(th.FilterIDs))
- for i, fltrID := range th.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- //StatQueueProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheStatFilterIndexes,
- &args.StatIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- sq, e := apierSv1.DataManager.GetStatQueueProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(sq.FilterIDs))
- for i, fltrID := range sq.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- //ResourceProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheResourceFilterIndexes,
- &args.ResourceIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- rp, e := apierSv1.DataManager.GetResourceProfile(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)
- }
- //RouteProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheRouteFilterIndexes,
- &args.RouteIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- rp, e := apierSv1.DataManager.GetRouteProfile(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)
- }
- //Account Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheAccountsFilterIndexes,
- &args.AccountIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- acp, e := apierSv1.DataManager.GetAccount(tnt, id)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(acp.FilterIDs))
- for i, fltrID := range acp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- //ActionProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheActionProfilesFilterIndexes,
- &args.ActionProfileIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- atp, e := apierSv1.DataManager.GetActionProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(atp.FilterIDs))
- for i, fltrID := range atp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); 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) {
- ap, e := apierSv1.DataManager.GetAttributeProfile(context.TODO(), tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- if !utils.IsSliceMember(ap.Contexts, ctx) {
- return nil, nil
- }
- fltrIDs := make([]string, len(ap.FilterIDs))
- for i, fltrID := range ap.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- //ChargerProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheChargerFilterIndexes,
- &args.ChargerIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- ap, e := apierSv1.DataManager.GetChargerProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- fltrIDs := make([]string, len(ap.FilterIDs))
- for i, fltrID := range ap.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- //DispatcherProfile Indexes
- if _, err = engine.ComputeIndexes(apierSv1.DataManager, tnt, args.Context, utils.CacheDispatcherFilterIndexes,
- &args.DispatcherIDs, transactionID, func(tnt, id, ctx string) (*[]string, error) {
- dsp, e := apierSv1.DataManager.GetDispatcherProfile(tnt, id, true, false, utils.NonTransactional)
- if e != nil {
- return nil, e
- }
- if !utils.IsSliceMember(dsp.Subsystems, ctx) {
- return nil, nil
- }
- fltrIDs := make([]string, len(dsp.FilterIDs))
- for i, fltrID := range dsp.FilterIDs {
- fltrIDs[i] = fltrID
- }
- return &fltrIDs, nil
- }); err != nil && err != utils.ErrNotFound {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/filter_indexes_it_test.go b/apier/v1/filter_indexes_it_test.go
deleted file mode 100644
index dcfe0f2a1..000000000
--- a/apier/v1/filter_indexes_it_test.go
+++ /dev/null
@@ -1,3374 +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 FIdxTNESS 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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-const (
- tenant = "cgrates.org"
-)
-
-var (
- tFIdxRpc *rpc.Client
- emptySlice = []string{}
-
- sTestsFilterIndexesSV1 = []func(t *testing.T){
- testV1FIdxLoadConfig,
- testV1FIdxdxInitDataDb,
- testV1FIdxResetStorDb,
- testV1FIdxStartEngine,
- testV1FIdxRpcConn,
-
- testV1FIdxSetThresholdProfile,
- testV1FIdxComputeThresholdsIndexes,
- testV1FIdxSetSecondThresholdProfile,
- testV1FIdxSecondComputeThresholdsIndexes,
- testV1FIdxThirdComputeThresholdsIndexes,
- testV1FIdxRemoveThresholdProfile,
-
- testV1FIdxSetStatQueueProfileIndexes,
- testV1FIdxComputeStatQueueProfileIndexes,
- testV1FIdxSetSecondStatQueueProfileIndexes,
- testV1FIdxSecondComputeStatQueueProfileIndexes,
- testV1FIdxRemoveStatQueueProfile,
-
- testV1FIdxSetResourceProfileIndexes,
- testV1FIdxComputeResourceProfileIndexes,
- testV1FIdxSetSecondResourceProfileIndexes,
- testV1FIdxSecondComputeResourceProfileIndexes,
- testV1FIdxRemoveResourceProfile,
-
- testV1FIdxSetRouteProfileIndexes,
- testV1FIdxComputeRouteProfileIndexes,
- testV1FIdxSetSecondRouteProfileIndexes,
- testV1FIdxSecondComputeRouteProfileIndexes,
- testV1FIdxRemoveRouteProfile,
-
- testV1FIdxdxInitDataDb,
- testV1FISetAccountIndexes,
- testV1FIComputeAccountIndexes,
- testV1FISetSecondFilterForAccount,
- testV1FIComputeIDsAccountIndexes,
- testV1FIRemoveAccount,
-
- testV1FIdxdxInitDataDb,
- testV1FISetActionProfileIndexes,
- testV1FIComputeActionProfileIndexes,
- testVF1SetSecondActionProfile,
- testVF1ComputeIDsActionProfileIndexes,
- testV1FIRemoveActionProfile,
- testV1FIdxdxInitDataDb,
-
- testV1FISetRateProfileRatesIndexes,
- testV1FIComputeRateProfileRatesIndexes,
- testV1FISetSecondRateProfileRate,
- testVF1ComputeIDsRateProfileRateIndexes,
- testVF1RemoveRateProfileRates,
- testV1FIdxdxInitDataDb,
- testV1IndexClearCache,
-
- testV1FISetRateProfileIndexes,
- testV1FIComputeRateProfileIndexes,
- testV1FISetSecondRateProfile,
- testV1FIComputeIDsRateProfileIndexes,
- testVF1RemoveRateProfile,
- testV1FIdxdxInitDataDb,
-
- testV1FIdxSetAttributeProfileIndexes,
- testV1FIdxComputeAttributeProfileIndexes,
- testV1FIdxSetSecondAttributeProfileIndexes,
- testV1FIdxSecondComputeAttributeProfileIndexes,
- testV1FIdxComputeWithAnotherContext,
- testV1FIdxRemoveAttributeProfile,
-
- testV1FIdxdxInitDataDb,
- testV1FIdxPopulateDatabase,
- testV1FIdxGetFilterIndexes1,
- testV1FIdxGetFilterIndexes2,
- testV1FIdxGetFilterIndexes3,
- testV1FIdxGetFilterIndexes4,
-
- testV1FIdxdxInitDataDb,
- testV1FIdxSetDispatcherProfile,
- testV1FIdxComputeDispatcherProfileIndexes,
- testV1FIdxSetDispatcherProfile2,
- testV1FIdxComputeDispatcherProfileIndexes2,
-
- testV1FIdxStopEngine,
- }
-)
-
-// Test start here
-func TestFIdxV1IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tSv1ConfDIR = "tutinternal"
- case utils.MetaMySQL:
- tSv1ConfDIR = "tutmysql"
- case utils.MetaMongo:
- tSv1ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsFilterIndexesSV1 {
- t.Run(tSv1ConfDIR, stest)
- }
-}
-
-func testV1FIdxLoadConfig(t *testing.T) {
- tSv1CfgPath = path.Join(*dataDir, "conf", "samples", tSv1ConfDIR)
- var err error
- if tSv1Cfg, err = config.NewCGRConfigFromPath(tSv1CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1FIdxdxInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(tSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1IndexClearCache(t *testing.T) {
- var reply string
- if err := tFIdxRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testV1FIdxResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1FIdxStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tSv1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1FIdxRpcConn(t *testing.T) {
- var err error
- tFIdxRpc, err = newRPCClient(tSv1Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
-}
-
-//ThresholdProfile
-func testV1FIdxSetThresholdProfile(t *testing.T) {
- var reply *engine.ThresholdProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "TestFilter",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"TestFilter"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: 1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1", "ACT_2"},
- Async: true,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- t.Error(indexes)
- }
-}
-
-func testV1FIdxComputeThresholdsIndexes(t *testing.T) {
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- ThresholdS: true,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxSetSecondThresholdProfile(t *testing.T) {
- var reply *engine.ThresholdProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "TestFilter2",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1002"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
-
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE2",
- FilterIDs: []string{"TestFilter2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: 1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1", "ACT_2"},
- Async: true,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxSecondComputeThresholdsIndexes(t *testing.T) {
- thid := []string{"TEST_PROFILE2"}
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- ThresholdIDs: thid,
- }, &result); err != nil {
- t.Error(err)
- }
- if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIDX := []string{"*string:*req.Account:1002:TEST_PROFILE2"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxThirdComputeThresholdsIndexes(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- ThresholdS: true,
- }, &result); err != nil {
- t.Error(err)
- }
- if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1", "*string:*req.Account:1002:TEST_PROFILE2"}
- sort.Strings(expectedIDX)
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- sort.Strings(indexes)
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxRemoveThresholdProfile(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- ThresholdS: true,
- }, &result); err != nil {
- t.Error(err)
- }
- if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var sqp *engine.ThresholdProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//StatQueueProfile
-func testV1FIdxSetStatQueueProfileIndexes(t *testing.T) {
- var reply *engine.StatQueueProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_1",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"FLTR_1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaSum,
- },
- {
- MetricID: utils.MetaACD,
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxComputeStatQueueProfileIndexes(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- StatS: true,
- }, &result); err != nil {
- t.Error(err)
- }
- if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxSetSecondStatQueueProfileIndexes(t *testing.T) {
- var reply *engine.StatQueueProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_2",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE2",
- FilterIDs: []string{"FLTR_2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: "*sum",
- },
- {
- MetricID: utils.MetaACD,
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxSecondComputeStatQueueProfileIndexes(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(
- utils.APIerSv1ComputeFilterIndexIDs, &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- StatIDs: []string{"TEST_PROFILE2"},
- }, &result); err != nil {
- t.Error(err)
- }
- if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE2"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxRemoveStatQueueProfile(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- StatS: true,
- }, &result); err != nil {
- t.Error(err)
- }
- if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &result); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaStats, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//ResourceProfile
-func testV1FIdxSetResourceProfileIndexes(t *testing.T) {
- var reply *engine.ResourceProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_RES_RCFG1",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: tenant,
- ID: "RCFG1",
- FilterIDs: []string{"FLTR_RES_RCFG1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: 10 * time.Microsecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{"Val1", "Val2"},
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxComputeResourceProfileIndexes(t *testing.T) {
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- ResourceS: true,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- expectedIDX := []string{"*string:*req.Account:1001:RCFG1"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxSetSecondResourceProfileIndexes(t *testing.T) {
- var reply *engine.StatQueueProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_2",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: tenant,
- ID: "RCFG2",
- FilterIDs: []string{"FLTR_2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: 10 * time.Microsecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{"Val1", "Val2"},
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxSecondComputeResourceProfileIndexes(t *testing.T) {
- rsid := []string{"RCFG2"}
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- ResourceIDs: rsid,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- expectedIDX := []string{"*string:*req.Account:1001:RCFG2"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxRemoveResourceProfile(t *testing.T) {
- var resp string
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- ResourceS: true,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: tenant, ID: "RCFG1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: tenant, ID: "RCFG2"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG1"},
- &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetResourceProfile, &utils.TenantID{Tenant: tenant, ID: "RCFG2"},
- &reply2); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaResources, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//RouteProfile
-func testV1FIdxSetRouteProfileIndexes(t *testing.T) {
- var reply *engine.RouteProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_1",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- rPrf := &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"FLTR_1"},
- Sorting: "Sort1",
- SortingParameters: []string{"Param1", "Param2"},
- Routes: []*engine.Route{{
- ID: "SPL1",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- }},
- Weight: 10,
- },
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxComputeRouteProfileIndexes(t *testing.T) {
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- RouteS: true,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE1"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxSetSecondRouteProfileIndexes(t *testing.T) {
- var reply *engine.RouteProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_2",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- rPrf := &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE2",
- FilterIDs: []string{"FLTR_2"},
- Sorting: "Sort1",
- SortingParameters: []string{"Param1", "Param2"},
- Routes: []*engine.Route{{
- ID: "SPL1",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_2"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- }},
- Weight: 10,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxSecondComputeRouteProfileIndexes(t *testing.T) {
- spid := []string{"TEST_PROFILE2"}
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- RouteIDs: spid,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- expectedIDX := []string{"*string:*req.Account:1001:TEST_PROFILE2"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxRemoveRouteProfile(t *testing.T) {
- var resp string
- var reply2 string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes, &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- RouteS: true,
- }, &reply2); err != nil {
- t.Error(err)
- }
- if reply2 != utils.OK {
- t.Errorf("Error: %+v", reply2)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply2); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE2"}, &reply2); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaRoutes, Tenant: tenant, FilterType: utils.MetaString},
- &indexes); err != nil &&
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//Account
-func testV1FISetAccountIndexes(t *testing.T) {
- var reply *utils.Account
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "ACCPRF_FLTR",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.Account",
- Values: []string{"1001", "1002"},
- },
- },
- },
- }
- 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 is not an accPrf in database, so we will get NOT_FOUND
- if err := tFIdxRpc.Call(utils.APIerSv1GetAccount,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACC_PRF"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //set in db an accPrf then we will get it without errors
- accPrf := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: tenant,
- ID: "ACC_PRF",
- FilterIDs: []string{"*prefix:~*req.Destination:123", "ACCPRF_FLTR"},
- Balances: map[string]*utils.APIBalance{
- "ConcreteBalance": {
- ID: "ConcreteBalance",
- Type: utils.MetaConcrete,
- Units: 200,
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetAccount, accPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Unexpected reply returned")
- }
- newAccPrf, err := accPrf.AsAccount()
- if err != nil {
- t.Error(err)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetAccount,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACC_PRF"}},
- &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, newAccPrf) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(newAccPrf), utils.ToJSON(reply))
- }
-
- var indexes []string
- expectedIDx := []string{"*string:*req.Account:1001:ACC_PRF", "*string:*req.Account:1002:ACC_PRF", "*prefix:*req.Destination:123:ACC_PRF"}
- //trying to get indexes,
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaAccounts, 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 testV1FIComputeAccountIndexes(t *testing.T) {
- //remove indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaAccounts, Tenant: tenant},
- &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.MetaAccounts, Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //compute them, to put indexes again in db for the right subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- AccountS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.Account:1001:ACC_PRF", "*string:*req.Account:1002:ACC_PRF", "*prefix:*req.Destination:123:ACC_PRF"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaAccounts, 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 testV1FISetSecondFilterForAccount(t *testing.T) {
- //new filter
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "ACCPRF_FLTR2",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.CGRID",
- Values: []string{"Dan1"},
- },
- },
- },
- }
- 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)
- }
-
- //we will overwrite this AccPrf with our new filter
- accPrf := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: tenant,
- ID: "ACC_PRF",
- FilterIDs: []string{"*prefix:~*req.Destination:123", "ACCPRF_FLTR", "ACCPRF_FLTR2"},
- Balances: map[string]*utils.APIBalance{
- "ConcreteBalance": {
- ID: "ConcreteBalance",
- Type: utils.MetaConcrete,
- Units: 200,
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetAccount, accPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Unexpected reply returned")
- }
- newAccPrf, err := accPrf.AsAccount()
- if err != nil {
- t.Error(err)
- }
- var reply *utils.Account
- if err := tFIdxRpc.Call(utils.APIerSv1GetAccount,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACC_PRF"}},
- &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, newAccPrf) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(newAccPrf), utils.ToJSON(reply))
- }
-
- var indexes []string
- expectedIDx := []string{"*string:*req.Account:1001:ACC_PRF", "*string:*req.Account:1002:ACC_PRF",
- "*prefix:*req.Destination:123:ACC_PRF", "*string:*req.CGRID:Dan1:ACC_PRF"}
- //trying to get indexes, should be indexes for both filters:"ACCPRF_FLTR" and "ACCPRF_FLTR2"
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaAccounts, 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 testV1FIComputeIDsAccountIndexes(t *testing.T) {
- //remove indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaAccounts, Tenant: tenant},
- &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.MetaAccounts, Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //compute them, to put indexes again in db for the right subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- AccountIDs: []string{"ACC_PRF"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.Account:1001:ACC_PRF", "*string:*req.Account:1002:ACC_PRF",
- "*prefix:*req.Destination:123:ACC_PRF", "*string:*req.CGRID:Dan1:ACC_PRF"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaAccounts, 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 testV1FIRemoveAccount(t *testing.T) {
- //removing accPrf from db will delete the indexes from dB
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveAccount,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACC_PRF"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- var reply *utils.Account
- //there is not an accPrf in database, so we will get NOT_FOUND
- if err := tFIdxRpc.Call(utils.APIerSv1GetAccount,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACC_PRF"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- var indexes []string
- //there are no indexes in db, as we removed actprf from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaAccounts, Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//ActionProfile
-func testV1FISetActionProfileIndexes(t *testing.T) {
- //set a new filter in db
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "ACTION_FLTR",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.ToR",
- Values: []string{"*sms", "*data", "~*req.Voice"},
- },
- },
- },
- }
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //there is not an actPrf in db, so we will get NOT_FOUND
- var reply *engine.ActionProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected %+v, received %+v", utils.ErrNotFound, err)
- }
-
- //set an actPrf in db, so we will get it without any problems
- actPrf := &engine.ActionProfileWithAPIOpts{
- ActionProfile: &engine.ActionProfile{
- Tenant: tenant,
- ID: "ACT_PRF",
- FilterIDs: []string{"*prefix:~*req.Account:1001|1002", "ACTION_FLTR"},
- Schedule: "* * * * *",
- Actions: []*engine.APAction{
- {
- ID: "TOPUP",
- FilterIDs: []string{},
- Type: utils.MetaLog,
- Diktats: []*engine.APDiktat{{
- Path: "~*balance.TestBalance.Value",
- Value: "10",
- }},
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetActionProfile, actPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- //get it from db and compare
- if err := tFIdxRpc.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF"}},
- &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, actPrf.ActionProfile) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(actPrf.ActionProfile), utils.ToJSON(reply))
- }
-
- //get indexes to verify if these are indexed well
- var indexes []string
- expectedIDx := []string{"*string:*req.ToR:*sms:ACT_PRF", "*string:*req.ToR:*data:ACT_PRF",
- "*prefix:*req.Account:1001:ACT_PRF", "*prefix:*req.Account:1002:ACT_PRF"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, 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 for that inline actPRf filter (with Type *prefix)
- expectedIDx = []string{"*prefix:*req.Account:1001:ACT_PRF", "*prefix:*req.Account:1002:ACT_PRF"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, Tenant: tenant, FilterType: utils.MetaPrefix},
- &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 ToR
- expectedIDx = []string{"*string:*req.ToR:*sms:ACT_PRF", "*string:*req.ToR:*data:ACT_PRF"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, Tenant: tenant, FilterField: "*req.ToR"},
- &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 the indexes only with Value 1001
- expectedIDx = []string{"*prefix:*req.Account:1001:ACT_PRF"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, Tenant: tenant, FilterValue: "1001"},
- &indexes); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(indexes, expectedIDx) {
- t.Errorf("Expected %+v, received %+v", expectedIDx, indexes)
- }
-}
-
-func testV1FIComputeActionProfileIndexes(t *testing.T) {
- //remove indexes from db
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaActionProfiles, 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.MetaActionProfiles, 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,
- ActionS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.ToR:*sms:ACT_PRF", "*string:*req.ToR:*data:ACT_PRF",
- "*prefix:*req.Account:1001:ACT_PRF", "*prefix:*req.Account:1002:ACT_PRF"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, 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 testVF1SetSecondActionProfile(t *testing.T) {
- //second filter in db
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "ACTION_FLTR2",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: "~*req.OriginID",
- Values: []string{"Dan1"},
- },
- },
- },
- }
- 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)
- }
-
- //set the second actPrf in db with our filter
- actPrf := &engine.ActionProfileWithAPIOpts{
- ActionProfile: &engine.ActionProfile{
- Tenant: tenant,
- ID: "ACT_PRF2",
- FilterIDs: []string{"ACTION_FLTR2"},
- Actions: []*engine.APAction{
- {
- ID: "TORESET",
- FilterIDs: []string{},
- Type: utils.MetaLog,
- },
- },
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetActionProfile, actPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- //get it from db and compare
- var reply *engine.ActionProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF2"}},
- &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, actPrf.ActionProfile) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(actPrf.ActionProfile), utils.ToJSON(reply))
- }
-
- //get indexes to verify if these are indexed well
- var indexes []string
- expectedIDx := []string{"*string:*req.ToR:*sms:ACT_PRF", "*string:*req.ToR:*data:ACT_PRF",
- "*prefix:*req.Account:1001:ACT_PRF", "*prefix:*req.Account:1002:ACT_PRF", "*string:*req.OriginID:Dan1:ACT_PRF2"}
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, 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 testVF1ComputeIDsActionProfileIndexes(t *testing.T) {
- //remove indexes from db for both actPrf
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{ItemType: utils.MetaActionProfiles, Tenant: tenant},
- &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.MetaActionProfiles, Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //firstly, compute indexes for "ACT_PRF"
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- ActionProfileIDs: []string{"ACT_PRF"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx := []string{"*string:*req.ToR:*sms:ACT_PRF", "*string:*req.ToR:*data:ACT_PRF",
- "*prefix:*req.Account:1001:ACT_PRF", "*prefix:*req.Account:1002:ACT_PRF"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, 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)
- }
- }
-
- //secondly, compute indexes for "ACT_PRF2"
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- ActionProfileIDs: []string{"ACT_PRF2"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- expectedIDx = []string{"*string:*req.ToR:*sms:ACT_PRF", "*string:*req.ToR:*data:ACT_PRF",
- "*prefix:*req.Account:1001:ACT_PRF", "*prefix:*req.Account:1002:ACT_PRF", "*string:*req.OriginID:Dan1:ACT_PRF2"}
- //as we compute them, next we will try to get them again from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, 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 testV1FIRemoveActionProfile(t *testing.T) {
- //we will remove actionProfiles 1 by one(ACT_PRF) first
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- var reply *engine.ActionProfile
- //there is not an actPrf in database, so we will get NOT_FOUND
- if err := tFIdxRpc.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //we will remove actionProfiles 1 by one(ACT_PRF2) second
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF2"}},
- &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected result returned", result)
- }
-
- //there is not an actPrf in database, so we will get NOT_FOUND
- if err := tFIdxRpc.Call(utils.APIerSv1GetActionProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ACT_PRF2"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //bcs both profiles are removed, there are not any indexes in db
- var indexes []string
- //there are no indexes in db, as we removed actprf from db
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{ItemType: utils.MetaActionProfiles, Tenant: tenant},
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//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
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_1",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ApierTest"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: tenant,
- ID: "ApierTest",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"FLTR_1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{"*string:~*req.FL1:In1"},
- Path: "FL1",
- Value: config.NewRSRParsersMustCompile("Al1", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: tenant, ID: "ApierTest"}}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(alsPrf.FilterIDs, reply.FilterIDs) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.FilterIDs, reply.FilterIDs)
- } else if !reflect.DeepEqual(alsPrf.ActivationInterval, reply.ActivationInterval) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.ActivationInterval, reply.ActivationInterval)
- } else if !reflect.DeepEqual(len(alsPrf.Attributes), len(reply.Attributes)) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Attributes), utils.ToJSON(reply.Attributes))
- } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID)
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- Context: utils.MetaSessionS}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaAttributes, Tenant: tenant, FilterType: utils.MetaString,
- Context: utils.MetaSessionS}, &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxComputeAttributeProfileIndexes(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- AttributeS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIDX := []string{"*string:*req.Account:1001:ApierTest"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- FilterType: utils.MetaString,
- Context: utils.MetaSessionS}, &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxSetSecondAttributeProfileIndexes(t *testing.T) {
- var reply *engine.AttributeProfile
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_2",
- Rules: []*engine.FilterRule{{
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- 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)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: tenant, ID: "ApierTest2"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: tenant,
- ID: "ApierTest2",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"FLTR_2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{{
- FilterIDs: []string{"*string:~*req.FL1:In1"},
- Path: "FL1",
- Value: config.NewRSRParsersMustCompile("Al1", utils.InfieldSep),
- }},
- Weight: 20,
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: tenant, ID: "ApierTest2"}}, &reply); err != nil {
- t.Error(err)
- t.Error(err)
- } else if !reflect.DeepEqual(alsPrf.FilterIDs, reply.FilterIDs) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.FilterIDs, reply.FilterIDs)
- } else if !reflect.DeepEqual(alsPrf.ActivationInterval, reply.ActivationInterval) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.ActivationInterval, reply.ActivationInterval)
- } else if !reflect.DeepEqual(len(alsPrf.Attributes), len(reply.Attributes)) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.Attributes), utils.ToJSON(reply.Attributes))
- } else if !reflect.DeepEqual(alsPrf.ID, reply.ID) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.ID, reply.ID)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes,
- &AttrRemFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- Context: utils.MetaSessionS}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes,
- &AttrGetFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- FilterType: utils.MetaString,
- Context: utils.MetaSessionS}, &indexes); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxSecondComputeAttributeProfileIndexes(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexIDs,
- &utils.ArgsComputeFilterIndexIDs{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- AttributeIDs: []string{"ApierTest2"},
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIDX := []string{"*string:*req.Account:1001:ApierTest2"}
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- FilterType: utils.MetaString,
- Context: utils.MetaSessionS}, &indexes); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxComputeWithAnotherContext(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaAny,
- AttributeS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- FilterType: utils.MetaString,
- Context: utils.MetaAny}, &indexes); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- t.Error(indexes)
- }
-}
-
-func testV1FIdxRemoveAttributeProfile(t *testing.T) {
- var result string
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- AttributeS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "ApierTest"}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "ApierTest2"}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: tenant, ID: "ApierTest2"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: tenant, ID: "ApierTest"}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaAttributes,
- Tenant: tenant,
- FilterType: utils.MetaString,
- Context: utils.MetaSessionS}, &indexes); err != nil &&
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxPopulateDatabase(t *testing.T) {
- var result string
- resPrf := engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: tenant,
- ID: "ResProfile1",
- FilterIDs: []string{"*string:~*req.Account:1001",
- "*string:~*req.Destination:1001",
- "*string:~*req.Destination:2001",
- "*string:~*req.Account:1002",
- "*prefix:~*req.Account:10",
- "*string:~*req.Destination:1001",
- "*prefix:~*req.Destination:20",
- "*string:~*req.Account:1002"},
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- resPrf = engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: tenant,
- ID: "ResProfile2",
- FilterIDs: []string{"*string:~*req.Account:1001",
- "*string:~*req.Destination:1001",
- "*string:~*req.Destination:2001",
- "*string:~*req.Account:2002",
- "*prefix:~*req.Account:10",
- "*string:~*req.Destination:2001",
- "*prefix:~*req.Destination:20",
- "*string:~*req.Account:1002"},
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- resPrf = engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: tenant,
- ID: "ResProfile3",
- FilterIDs: []string{"*string:~*req.Account:3001",
- "*string:~*req.Destination:1001",
- "*string:~*req.Destination:2001",
- "*string:~*req.Account:1002",
- "*prefix:~*req.Account:10",
- "*prefix:~*req.Destination:1001",
- "*prefix:~*req.Destination:200",
- "*string:~*req.Account:1003"},
- },
- }
- if err := tFIdxRpc.Call(utils.APIerSv1SetResourceProfile, resPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testV1FIdxGetFilterIndexes1(t *testing.T) {
- arg := &AttrGetFilterIndexes{
- Tenant: tenant,
- ItemType: utils.MetaResources,
- }
- expectedIndexes := []string{
- "*string:*req.Account:3001:ResProfile3",
- "*string:*req.Destination:1001:ResProfile1",
- "*string:*req.Destination:1001:ResProfile2",
- "*string:*req.Destination:1001:ResProfile3",
- "*string:*req.Account:1002:ResProfile1",
- "*string:*req.Account:1002:ResProfile2",
- "*string:*req.Account:1002:ResProfile3",
- "*string:*req.Account:1003:ResProfile3",
- "*prefix:*req.Destination:20:ResProfile1",
- "*prefix:*req.Destination:20:ResProfile2",
- "*string:*req.Account:1001:ResProfile1",
- "*string:*req.Account:1001:ResProfile2",
- "*string:*req.Account:2002:ResProfile2",
- "*prefix:*req.Destination:1001:ResProfile3",
- "*prefix:*req.Destination:200:ResProfile3",
- "*string:*req.Destination:2001:ResProfile1",
- "*string:*req.Destination:2001:ResProfile2",
- "*string:*req.Destination:2001:ResProfile3",
- "*prefix:*req.Account:10:ResProfile1",
- "*prefix:*req.Account:10:ResProfile2",
- "*prefix:*req.Account:10:ResProfile3"}
- sort.Strings(expectedIndexes)
- var reply []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil {
- t.Error(err)
- } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedIndexes), utils.ToJSON(reply))
- }
-}
-
-func testV1FIdxGetFilterIndexes2(t *testing.T) {
- arg := &AttrGetFilterIndexes{
- Tenant: tenant,
- ItemType: utils.MetaResources,
- FilterType: utils.MetaString,
- }
- expectedIndexes := []string{
- "*string:*req.Account:1003:ResProfile3",
- "*string:*req.Account:3001:ResProfile3",
- "*string:*req.Destination:1001:ResProfile1",
- "*string:*req.Destination:1001:ResProfile2",
- "*string:*req.Destination:1001:ResProfile3",
- "*string:*req.Account:1002:ResProfile1",
- "*string:*req.Account:1002:ResProfile2",
- "*string:*req.Account:1002:ResProfile3",
- "*string:*req.Account:1001:ResProfile1",
- "*string:*req.Account:1001:ResProfile2",
- "*string:*req.Destination:2001:ResProfile3",
- "*string:*req.Destination:2001:ResProfile1",
- "*string:*req.Destination:2001:ResProfile2",
- "*string:*req.Account:2002:ResProfile2"}
- sort.Strings(expectedIndexes)
- var reply []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil {
- t.Error(err)
- } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, reply)
- }
-}
-
-func testV1FIdxGetFilterIndexes3(t *testing.T) {
- arg := &AttrGetFilterIndexes{
- Tenant: tenant,
- ItemType: utils.MetaResources,
- FilterType: utils.MetaPrefix,
- }
- expectedIndexes := []string{
- "*prefix:*req.Destination:20:ResProfile1",
- "*prefix:*req.Destination:20:ResProfile2",
- "*prefix:*req.Account:10:ResProfile1",
- "*prefix:*req.Account:10:ResProfile2",
- "*prefix:*req.Account:10:ResProfile3",
- "*prefix:*req.Destination:200:ResProfile3",
- "*prefix:*req.Destination:1001:ResProfile3"}
- sort.Strings(expectedIndexes)
- var reply []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil {
- t.Error(err)
- } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, reply)
- }
-}
-
-func testV1FIdxGetFilterIndexes4(t *testing.T) {
- arg := &AttrGetFilterIndexes{
- Tenant: tenant,
- ItemType: utils.MetaResources,
- FilterType: utils.MetaString,
- FilterField: "Account",
- }
- expectedIndexes := []string{
- "*string:*req.Account:1003:ResProfile3",
- "*string:*req.Account:3001:ResProfile3",
- "*string:*req.Account:1002:ResProfile1",
- "*string:*req.Account:1002:ResProfile2",
- "*string:*req.Account:1002:ResProfile3",
- "*string:*req.Account:1001:ResProfile1",
- "*string:*req.Account:1001:ResProfile2",
- "*string:*req.Account:2002:ResProfile2"}
- sort.Strings(expectedIndexes)
- var reply []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &reply); err != nil {
- t.Error(err)
- } else if sort.Strings(reply); !reflect.DeepEqual(expectedIndexes, reply) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, reply)
- }
-}
-
-func testV1FIdxSetDispatcherProfile(t *testing.T) {
- var reply string
- //add a dispatcherProfile for 2 subsystems and verify if the index was created for both
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "DSP_Test1",
- FilterIDs: []string{"*string:~*req.Account:1001", "*string:~*req.Subject:2012", "*prefix:~*req.RandomField:RandomValue"},
- Strategy: utils.MetaFirst,
- Subsystems: []string{utils.MetaAttributes, utils.MetaSessionS},
- Weight: 20,
- },
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- //verify *string index for *attributes subsystem
- arg := &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaAttributes,
- ItemType: utils.MetaDispatchers,
- FilterType: utils.MetaString,
- }
- expectedIndexes := []string{
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- var idx []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil {
- t.Error(err)
- } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) {
- t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(idx))
- }
-
- //verify *string index for *sessions subsystem
- arg = &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- ItemType: utils.MetaDispatchers,
- FilterType: utils.MetaString,
- }
- expectedIndexes = []string{
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil {
- t.Error(err)
- } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) {
- t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(idx))
- }
-
- //verify indexes for *sessions subsystem
- arg = &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- ItemType: utils.MetaDispatchers,
- }
- expectedIndexes = []string{
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil {
- t.Error(err)
- } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx)
- }
- //remove the indexes for *sessions subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaDispatchers,
- Tenant: tenant,
- Context: utils.MetaSessionS}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- //verify if was removed
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg,
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //verify *string index for *attributes subsystem
- arg = &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaAttributes,
- ItemType: utils.MetaDispatchers,
- }
- expectedIndexes = []string{
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil {
- t.Error(err)
- } else if sort.Strings(idx); !reflect.DeepEqual(len(expectedIndexes), len(idx)) {
- t.Errorf("Expecting: %+v, received: %+v", len(expectedIndexes), len(idx))
- }
-}
-
-func testV1FIdxComputeDispatcherProfileIndexes(t *testing.T) {
- var result string
- //recompute indexes for dispatcherProfile for *sessions subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- DispatcherS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIndexes := []string{
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaDispatchers,
- Tenant: tenant,
- Context: utils.MetaSessionS}, &indexes); err != nil {
- t.Error(err)
- } else if sort.Strings(indexes); !reflect.DeepEqual(expectedIndexes, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxSetDispatcherProfile2(t *testing.T) {
- var reply string
- //add a new dispatcherProfile with empty filterIDs
- //should create an index of type *none:*any:*any for *attributes subsystem
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "DSP_Test2",
- Subsystems: []string{utils.MetaAttributes},
- Weight: 20,
- },
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- //add a new dispatcherProfile with empty filterIDs
- //should create an index of type *none:*any:*any for *sessions subsystem
- dispatcherProfile2 := DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "DSP_Test3",
- Subsystems: []string{utils.MetaSessionS},
- Weight: 20,
- },
- }
-
- if err := tFIdxRpc.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile2,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- //verify indexes for *attributes subsystem
- arg := &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaAttributes,
- ItemType: utils.MetaDispatchers,
- }
- expectedIndexes := []string{
- "*none:*any:*any:DSP_Test2",
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- var idx []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil {
- t.Error(err)
- } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx)
- }
-
- //verify indexes for *sessions subsystem
- arg = &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- ItemType: utils.MetaDispatchers,
- }
- expectedIndexes = []string{
- "*none:*any:*any:DSP_Test3",
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg, &idx); err != nil {
- t.Error(err)
- } else if sort.Strings(idx); !reflect.DeepEqual(expectedIndexes, idx) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, idx)
- }
- //remove the indexes for *sessions subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaDispatchers,
- Tenant: tenant,
- Context: utils.MetaSessionS}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- //verify if indexes was removed for *sessions
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg,
- &indexes); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- //remove the indexes for *attribute subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1RemoveFilterIndexes, &AttrRemFilterIndexes{
- ItemType: utils.MetaDispatchers,
- Tenant: tenant,
- Context: utils.MetaAttributes}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- //verify indexes for *attributes subsystem
- arg = &AttrGetFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaAttributes,
- ItemType: utils.MetaDispatchers,
- }
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, arg,
- &idx); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxComputeDispatcherProfileIndexes2(t *testing.T) {
- var result string
- //recompute indexes for dispatcherProfile for *sessions subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaSessionS,
- DispatcherS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIndexes := []string{
- "*none:*any:*any:DSP_Test3",
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- var indexes []string
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaDispatchers,
- Tenant: tenant,
- Context: utils.MetaSessionS}, &indexes); err != nil {
- t.Error(err)
- } else if sort.Strings(indexes); !reflect.DeepEqual(expectedIndexes, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, utils.ToJSON(indexes))
- }
-
- //recompute indexes for dispatcherProfile for *attributes subsystem
- if err := tFIdxRpc.Call(utils.APIerSv1ComputeFilterIndexes,
- &utils.ArgsComputeFilterIndexes{
- Tenant: tenant,
- Context: utils.MetaAttributes,
- DispatcherS: true,
- }, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Error: %+v", result)
- }
- expectedIndexes = []string{
- "*none:*any:*any:DSP_Test2",
- "*prefix:*req.RandomField:RandomValue:DSP_Test1",
- "*string:*req.Account:1001:DSP_Test1",
- "*string:*req.Subject:2012:DSP_Test1",
- }
- sort.Strings(expectedIndexes)
- if err := tFIdxRpc.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaDispatchers,
- Tenant: tenant,
- Context: utils.MetaAttributes}, &indexes); err != nil {
- t.Error(err)
- } else if sort.Strings(indexes); !reflect.DeepEqual(expectedIndexes, indexes) {
- t.Errorf("Expecting: %+v, received: %+v", expectedIndexes, utils.ToJSON(indexes))
- }
-}
-
-func testV1FIdxStopEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/filterindexecache_it_test.go b/apier/v1/filterindexecache_it_test.go
deleted file mode 100644
index bf32ed92d..000000000
--- a/apier/v1/filterindexecache_it_test.go
+++ /dev/null
@@ -1,1641 +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 FIdxCaTNESS 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 (
- tFIdxCaRpc *rpc.Client
- sTestsFilterIndexesSV1Ca = []func(t *testing.T){
- testV1FIdxCaLoadConfig,
- testV1FIdxCaInitDataDb,
- testV1FIdxCaResetStorDb,
- testV1FIdxCaStartEngine,
- testV1FIdxCaRpcConn,
-
- testV1FIdxCaProcessEventWithNotFound,
- testV1FIdxCaSetThresholdProfile,
- testV1FIdxCaFromFolder,
- testV1FIdxCaGetThresholdFromTP,
- testV1FIdxCaUpdateThresholdProfile,
- testV1FIdxCaUpdateThresholdProfileFromTP,
- testV1FIdxCaRemoveThresholdProfile,
-
- testV1FIdxCaInitDataDb,
- testV1FIdxCaGetStatQueuesWithNotFound,
- testV1FIdxCaSetStatQueueProfile,
- testV1FIdxCaFromFolder,
- testV1FIdxCaGetStatQueuesFromTP,
- testV1FIdxCaUpdateStatQueueProfile,
- testV1FIdxCaUpdateStatQueueProfileFromTP,
- testV1FIdxCaRemoveStatQueueProfile,
-
- testV1FIdxCaInitDataDb,
- testV1FIdxCaProcessAttributeProfileEventWithNotFound,
- testV1FIdxCaSetAttributeProfile,
- testV1FIdxCaFromFolder,
- testV1FIdxCaGetAttributeProfileFromTP,
- testV1FIdxCaUpdateAttributeProfile,
- testV1FIdxCaUpdateAttributeProfileFromTP,
- testV1FIdxCaRemoveAttributeProfile,
-
- testV1FIdxCaInitDataDb,
- testV1FIdxCaGetResourceProfileWithNotFound,
- testV1FIdxCaSetResourceProfile,
- testV1FIdxCaFromFolder,
- testV1FIdxCaGetResourceProfileFromTP,
- testV1FIdxCaUpdateResourceProfile,
- testV1FIdxCaUpdateResourceProfileFromTP,
- testV1FIdxCaRemoveResourceProfile,
- testV1FIdxCaStopEngine,
- }
-)
-
-// Test start here
-func TestFIdxCaV1IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- tSv1ConfDIR = "tutmysql"
- case utils.MetaMongo:
- tSv1ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsFilterIndexesSV1Ca {
- t.Run(tSv1ConfDIR, stest)
- }
-}
-
-func testV1FIdxCaLoadConfig(t *testing.T) {
- var err error
- tSv1CfgPath = path.Join(*dataDir, "conf", "samples", tSv1ConfDIR)
- if tSv1Cfg, err = config.NewCGRConfigFromPath(tSv1CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(tSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testV1FIdxCaResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1FIdxCaStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tSv1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1FIdxCaRpcConn(t *testing.T) {
- var err error
- tFIdxCaRpc, err = newRPCClient(tSv1Cfg.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 testV1FIdxCaFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
- if err := tFIdxCaRpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-//ThresholdProfile
-func testV1FIdxCaProcessEventWithNotFound(t *testing.T) {
- tEv := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.BalanceUpdate,
- utils.AccountField: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- var thIDs []string
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaSetThresholdProfile(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "TestFilter",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType,
- Type: utils.MetaString,
- Values: []string{utils.BalanceUpdate},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"TestFilter"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MinHits: 1,
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- Async: true,
- },
- }
-
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //matches TEST_PROFILE1
- tEv := &engine.ThresholdsArgsProcessEvent{
- ThresholdIDs: []string{"TEST_PROFILE1"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.BalanceUpdate,
- utils.AccountField: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- var thIDs []string
- eIDs := []string{"TEST_PROFILE1"}
- //Testing ProcessEvent on set thresholdprofile using apier
-
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thIDs, eIDs) {
- t.Errorf("Expecting hits: %s, received: %s", eIDs, thIDs)
- }
-}
-
-func testV1FIdxCaGetThresholdFromTP(t *testing.T) {
- //matches THD_ACNT_BALANCE_1
- tEv := &engine.ThresholdsArgsProcessEvent{
- ThresholdIDs: []string{"THD_ACNT_BALANCE_1"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.BalanceUpdate,
- utils.AccountField: "1001",
- utils.BalanceID: utils.MetaDefault,
- utils.Units: 12.3,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- var thIDs []string
- eIDs := []string{"THD_ACNT_BALANCE_1"}
- //Testing ProcessEvent on set thresholdprofile using apier
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent,
- tEv, &thIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thIDs, eIDs) {
- t.Errorf("Expecting hits: %s, received: %s", eIDs, thIDs)
- }
-}
-
-func testV1FIdxCaUpdateThresholdProfile(t *testing.T) {
- var result string
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "TestFilter2",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1002"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType,
- Type: utils.MetaString,
- Values: []string{utils.AccountUpdate},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"TestFilter2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- Async: true,
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //make sure doesn't match the thresholdprofile after update
- tEv := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- var thIDs []string
- eIDs := []string{}
- //Testing ProcessEvent on set thresholdprofile after update making sure there are no hits
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //matches thresholdprofile after update
- tEv2 := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1002",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- eIDs = []string{"TEST_PROFILE1"}
- //Testing ProcessEvent on set thresholdprofile after update
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thIDs, eIDs) {
- t.Errorf("Expecting : %s, received: %s", eIDs, thIDs)
- }
-}
-
-func testV1FIdxCaUpdateThresholdProfileFromTP(t *testing.T) {
- var result string
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "TestFilter3",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1003"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType,
- Type: utils.MetaString,
- Values: []string{utils.BalanceUpdate},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- var reply *engine.ThresholdProfile
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}, &reply); err != nil {
- t.Error(err)
- }
- if reply == nil {
- t.Errorf("Expecting reply to not be nil")
- // reply shoud not be nil so exit function
- // to avoid nil segmentation fault;
- // if this happens try to run this test manualy
- return
- }
- reply.FilterIDs = []string{"TestFilter3"}
-
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetThresholdProfile, &engine.ThresholdProfileWithAPIOpts{ThresholdProfile: reply}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- tEv := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.EventType: utils.BalanceUpdate,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- var thIDs []string
- //Testing ProcessEvent on set thresholdprofile using apier
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- tEv2 := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.EventType: utils.BalanceUpdate,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- eIDs := []string{"THD_ACNT_BALANCE_1"}
- //Testing ProcessEvent on set thresholdprofile using apier
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thIDs, eIDs) {
- t.Errorf("Expecting : %s, received: %s", eIDs, thIDs)
- }
-}
-
-func testV1FIdxCaRemoveThresholdProfile(t *testing.T) {
- var resp string
- tEv := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event8",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.EventType: utils.AccountUpdate,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- var thIDs []string
- eIDs := []string{"TEST_PROFILE1"}
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thIDs, eIDs) {
- t.Errorf("Expecting : %s, received: %s", eIDs, thIDs)
- }
-
- tEv2 := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event9",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.EventType: utils.BalanceUpdate,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- eIDs = []string{"THD_ACNT_BALANCE_1"}
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thIDs, eIDs) {
- t.Errorf("Expecting : %s, received: %s", eIDs, thIDs)
- }
- //Remove threshold profile that was set form api
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var sqp *engine.ThresholdProfile
- //Test the remove
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //Remove threshold profile that was set form tariffplan
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- //Test the remove
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv, &thIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.ThresholdSv1ProcessEvent, tEv2, &thIDs); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//StatQueue
-func testV1FIdxCaGetStatQueuesWithNotFound(t *testing.T) {
- var reply *[]string
- tEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- tEv.CGREvent.Tenant = utils.EmptyString
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaSetStatQueueProfile(t *testing.T) {
- tenant := "cgrates.org"
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "FLTR_1",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType,
- Type: utils.MetaString,
- Values: []string{utils.AccountUpdate},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
-
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"FLTR_1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: "*sum#~*req.Val",
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- tEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1001",
- "Val": 10,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- var reply []string
- expected := []string{"TEST_PROFILE1"}
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent,
- tEv, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-}
-
-func testV1FIdxCaGetStatQueuesFromTP(t *testing.T) {
- var reply []string
- expected := []string{"Stats1"}
- ev2 := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, ev2, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- ev3 := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, &ev3, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- tEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, &tEv, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- tEv2 := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, &tEv2, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-}
-
-func testV1FIdxCaUpdateStatQueueProfile(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_2",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1003"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType,
- Type: utils.MetaString,
- Values: []string{utils.BalanceUpdate},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"FLTR_2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: "*sum#~*req.Val",
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply []string
- expected := []string{"TEST_PROFILE1"}
- tEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.BalanceUpdate,
- utils.AccountField: "1003",
- "Val": 10,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-}
-
-func testV1FIdxCaUpdateStatQueueProfileFromTP(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_3",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1003"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.EventType,
- Type: utils.MetaString,
- Values: []string{utils.AccountUpdate},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply engine.StatQueueProfile
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &reply); err != nil {
- t.Error(err)
- }
- reply.FilterIDs = []string{"FLTR_3"}
- reply.ActivationInterval = &utils.ActivationInterval{ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetStatQueueProfile,
- &engine.StatQueueProfileWithAPIOpts{StatQueueProfile: &reply}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- tEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1003",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- var ids []string
- expected := []string{"Stats1"}
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent,
- tEv, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, ids)
- }
-}
-
-func testV1FIdxCaRemoveStatQueueProfile(t *testing.T) {
- var reply []string
- expected := []string{"TEST_PROFILE1"}
- tEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.BalanceUpdate,
- utils.AccountField: "1003",
- "Val": 10,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- expected = []string{"Stats1"}
- tEv2 := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1003",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv2, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- var result string
- //Remove threshold profile that was set form api
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var sqp *engine.StatQueueProfile
- //Test the remove
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //Remove threshold profile that was set form tariffplan
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //Test the remove
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.StatSv1ProcessEvent, tEv2, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-//AttributeProfile
-func testV1FIdxCaProcessAttributeProfileEventWithNotFound(t *testing.T) {
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "3009",
- utils.Destination: "+492511231234",
- },
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaSetAttributeProfile(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "TestFilter",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1009"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
- Type: utils.MetaString,
- Values: []string{"+491511231234"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"TestFilter"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //matches TEST_PROFILE1
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "1009",
- utils.Destination: "+491511231234",
- },
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent,
- ev, &rplyEv); err != nil {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaGetAttributeProfileFromTP(t *testing.T) {
- //matches ATTR_1
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.Destination: "+491511231234",
- },
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaUpdateAttributeProfile(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "TestFilter2",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"2009"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
- Type: utils.MetaString,
- Values: []string{"+492511231234"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"TestFilter2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //matches TEST_PROFILE1
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "2009",
- utils.Destination: "+492511231234",
- },
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaUpdateAttributeProfileFromTP(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "TestFilter3",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"3009"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
- Type: utils.MetaString,
- Values: []string{"+492511231234"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply engine.AttributeProfile
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}},
- &reply); err != nil {
- t.Error(err)
- }
- reply.FilterIDs = []string{"TestFilter3"}
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetAttributeProfile, &engine.AttributeProfileWithAPIOpts{AttributeProfile: &reply}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //matches TEST_PROFILE1
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "3009",
- utils.Destination: "+492511231234",
- },
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaRemoveAttributeProfile(t *testing.T) {
- var resp string
- ev := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "3009",
- utils.Destination: "+492511231234",
- },
- },
- }
- var rplyEv engine.AttrSProcessEventReply
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err != nil {
- t.Error(err)
- }
-
- ev2 := &engine.AttrArgsProcessEvent{
- Context: utils.StringPointer(utils.MetaSessionS),
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testAttributeSProcessEvent",
- Event: map[string]interface{}{
- utils.AccountField: "2009",
- utils.Destination: "+492511231234",
- },
- },
- }
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err != nil {
- t.Error(err)
- }
- //Remove threshold profile that was set form api
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org",
- ID: "TEST_PROFILE1"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var sqp *engine.AttributeProfile
- //Test the remove
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}},
- &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //Remove threshold profile that was set form tariffplan
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org",
- ID: "ATTR_1"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- //Test the remove
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1"}},
- &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev, &rplyEv); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.AttributeSv1ProcessEvent, ev2, &rplyEv); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-// ResourceProfile
-func testV1FIdxCaGetResourceProfileWithNotFound(t *testing.T) {
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.Subject: "1001",
- utils.Destination: "1002"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsRU, &reply); err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- argsRU.Tenant = utils.EmptyString
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsRU, &reply); err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
-}
-func testV1FIdxCaSetResourceProfile(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_RES_RCFG1",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject,
- Type: utils.MetaString,
- Values: []string{"1002"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "RCFG1",
- FilterIDs: []string{"FLTR_RES_RCFG1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: 0,
- AllocationMessage: "Approved",
- Limit: 10,
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Subject: "1002",
- utils.Destination: "1001"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &result); err != nil {
- t.Error(err)
- } else if result != "Approved" {
- t.Error("Unexpected reply returned", result)
- }
-
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsRU, &result); err != nil {
- t.Error(err)
- } else if result != "Approved" {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testV1FIdxCaGetResourceProfileFromTP(t *testing.T) {
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e63",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.Subject: "1002",
- utils.Destination: "1001"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- } else if reply != "Approved" {
- t.Error("Unexpected reply returned", reply)
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsRU, &reply); err != nil {
- t.Error(err)
- } else if reply != "Approved" {
- t.Error("Unexpected reply returned", reply)
- }
-
- argsReU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.Subject: "1001",
- utils.Destination: "1002"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsReU, &reply); err != nil {
- t.Error(err)
- } else if reply != "ResGroup1" {
- t.Error("Unexpected reply returned", reply)
- }
-}
-
-func testV1FIdxCaUpdateResourceProfile(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_RES_RCFG2",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"2002"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject,
- Type: utils.MetaString,
- Values: []string{"2001"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
- Type: utils.MetaString,
- Values: []string{"2002"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "RCFG1",
- FilterIDs: []string{"FLTR_RES_RCFG2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: 10 * time.Microsecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetResourceProfile,
- rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- argsReU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "2002",
- utils.Subject: "2001",
- utils.Destination: "2002"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsReU, &result); err != nil {
- t.Error(err)
- } else if result != "MessageAllocation" {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testV1FIdxCaUpdateResourceProfileFromTP(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_RES_RCFG3",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1002"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Subject,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Destination,
- Type: utils.MetaString,
- Values: []string{"1002"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply engine.ResourceProfile
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, &reply); err != nil {
- t.Error(err)
- }
- reply.FilterIDs = []string{"FLTR_RES_RCFG3"}
- reply.ActivationInterval = &utils.ActivationInterval{ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC)}
-
- if err := tFIdxCaRpc.Call(utils.APIerSv1SetResourceProfile, &engine.ResourceProfileWithAPIOpts{ResourceProfile: &reply}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- argsReU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e65",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.Subject: "1001",
- utils.Destination: "1002"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, &argsReU, &result); err != nil {
- t.Error(err)
- } else if result != "ResGroup1" {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testV1FIdxCaRemoveResourceProfile(t *testing.T) {
- var resp string
- argsReU := utils.ArgRSv1ResourceUsage{
- UsageID: "653a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "2002",
- utils.Subject: "2001",
- utils.Destination: "2002"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AllocateResources, argsReU, &resp); err != nil {
- t.Error(err)
- } else if resp != "MessageAllocation" {
- t.Error("Unexpected reply returned", resp)
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, &argsReU, &resp); err != nil {
- t.Error(err)
- } else if resp != "MessageAllocation" {
- t.Error("Unexpected reply returned", resp)
- }
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "654a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.Subject: "1001",
- utils.Destination: "1002"},
- },
- Units: 6,
- }
- if err := tFIdxCaRpc.Call(utils.ResourceSv1AuthorizeResources, &argsRU, &resp); err != nil {
- t.Error(err)
- } else if resp != "ResGroup1" {
- t.Error("Unexpected reply returned", resp)
- }
-
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var sqp *engine.ThresholdProfile
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RCFG1"}, &sqp); err == nil &&
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := tFIdxCaRpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}, &sqp); err == nil &&
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1FIdxCaStopEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/filters.go b/apier/v1/filters.go
deleted file mode 100644
index ced761067..000000000
--- a/apier/v1/filters.go
+++ /dev/null
@@ -1,115 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-//SetFilter add a new Filter
-func (apierSv1 *APIerSv1) SetFilter(arg *engine.FilterWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(arg.Filter, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if arg.Tenant == utils.EmptyString {
- arg.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.SetFilter(arg.Filter, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheFilters and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheFilters: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for Filter
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheFilters,
- arg.TenantID(), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//GetFilter returns a Filter
-func (apierSv1 *APIerSv1) GetFilter(arg *utils.TenantID, reply *engine.Filter) 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 fltr, err := apierSv1.DataManager.GetFilter(context.TODO(), tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- } else {
- *reply = *fltr
- }
- return nil
-}
-
-// GetFilterIDs returns list of Filter IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetFilterIDs(args *utils.PaginatorWithTenant, fltrIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.FilterPrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *fltrIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-//RemoveFilter remove a specific filter
-func (apierSv1 *APIerSv1) RemoveFilter(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.RemoveFilter(tnt, arg.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheFilters and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheFilters: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for Filter
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheFilters,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/filters_it_test.go b/apier/v1/filters_it_test.go
deleted file mode 100644
index 47f2c25a9..000000000
--- a/apier/v1/filters_it_test.go
+++ /dev/null
@@ -1,276 +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 (
- filterCfgPath string
- filterCfg *config.CGRConfig
- filterRPC *rpc.Client
- filter *engine.FilterWithAPIOpts
- filterConfigDIR string //run tests for specific configuration
-
- sTestsFilter = []func(t *testing.T){
- testFilterInitCfg,
- testFilterResetDataDB,
- testFilterStartEngine,
- testFilterRpcConn,
- testFilterGetFilterBeforeSet,
- testFilterSetFilter,
- testFilterGetFilterAfterSet,
- testFilterGetFilterIDs,
- testFilterUpdateFilter,
- testFilterGetFilterAfterUpdate,
- testFilterRemoveFilter,
- testFilterGetFilterAfterRemove,
- testFilterSetFilterWithoutTenant,
- testFilterRemoveFilterWithoutTenant,
- testFilterKillEngine,
- }
-)
-
-//Test start here
-func TestFilterIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- filterConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- filterConfigDIR = "tutmysql"
- case utils.MetaMongo:
- filterConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsFilter {
- t.Run(filterConfigDIR, stest)
- }
-}
-
-func testFilterInitCfg(t *testing.T) {
- var err error
- filterCfgPath = path.Join(*dataDir, "conf", "samples", filterConfigDIR)
- filterCfg, err = config.NewCGRConfigFromPath(filterCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-// Wipe out the cdr database
-func testFilterResetDataDB(t *testing.T) {
- if err := engine.InitDataDB(filterCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testFilterStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(filterCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testFilterRpcConn(t *testing.T) {
- var err error
- filterRPC, err = newRPCClient(filterCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testFilterGetFilterBeforeSet(t *testing.T) {
- var reply *engine.Filter
- if err := filterRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testFilterSetFilter(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "Filter1",
- Rules: []*engine.FilterRule{
- {
- Element: "~*req.Account",
- Type: utils.MetaString,
- Values: []string{"1001", "1002"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
-
- var result string
- if err := filterRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testFilterGetFilterIDs(t *testing.T) {
- expected := []string{"Filter1"}
- var result []string
- if err := filterRPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := filterRPC.Call(utils.APIerSv1GetFilterIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testFilterGetFilterAfterSet(t *testing.T) {
- var reply *engine.Filter
- if err := filterRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(filter.Filter, reply) {
- t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply)
- }
-}
-
-func testFilterUpdateFilter(t *testing.T) {
- filter.Rules = []*engine.FilterRule{
- {
- Element: "~*req.Account",
- Type: utils.MetaString,
- Values: []string{"1001", "1002"},
- },
- {
- Element: "~*req.Destination",
- Type: utils.MetaPrefix,
- Values: []string{"10", "20"},
- },
- }
- var result string
- if err := filterRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testFilterGetFilterAfterUpdate(t *testing.T) {
- var reply *engine.Filter
- if err := filterRPC.Call(utils.APIerSv1GetFilter,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(filter.Filter, reply) {
- t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply)
- }
-}
-
-func testFilterRemoveFilter(t *testing.T) {
- var resp string
- if err := filterRPC.Call(utils.APIerSv1RemoveFilter,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testFilterGetFilterAfterRemove(t *testing.T) {
- var reply *engine.Filter
- if err := filterRPC.Call(utils.APIerSv1GetFilter,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testFilterKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testFilterSetFilterWithoutTenant(t *testing.T) {
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- ID: "FilterWithoutTenant",
- Rules: []*engine.FilterRule{
- {
- Element: "~*req.Account",
- Type: utils.MetaString,
- Values: []string{"1001", "1002"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var reply string
- if err := filterRPC.Call(utils.APIerSv1SetFilter, filter, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.Filter
- filter.Filter.Tenant = "cgrates.org"
- if err := filterRPC.Call(utils.APIerSv1GetFilter,
- &utils.TenantID{ID: "FilterWithoutTenant"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, filter.Filter) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(filter.Filter), utils.ToJSON(result))
- }
-}
-
-func testFilterRemoveFilterWithoutTenant(t *testing.T) {
- var reply string
- if err := filterRPC.Call(utils.APIerSv1RemoveFilter,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "FilterWithoutTenant"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.Filter
- if err := filterRPC.Call(utils.APIerSv1GetFilter,
- &utils.TenantID{ID: "FilterWithoutTenant"},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
diff --git a/apier/v1/full_remote_it_test.go b/apier/v1/full_remote_it_test.go
deleted file mode 100644
index 8bf0cff6b..000000000
--- a/apier/v1/full_remote_it_test.go
+++ /dev/null
@@ -1,829 +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 (
- fullRemInternalCfgPath string
- fullRemInternalCfgDirPath string
- fullRemInternalCfg *config.CGRConfig
- fullRemInternalRPC *rpc.Client
-
- fullRemEngineOneCfgPath string
- fullRemEngineOneCfgDirPath string
- fullRemEngineOneCfg *config.CGRConfig
- fullRemEngineOneRPC *rpc.Client
-
- sTestsFullRemoteIT = []func(t *testing.T){
- testFullRemoteITInitCfg,
- testFullRemoteITDataFlush,
- testFullRemoteITStartEngine,
- testFullRemoteITRPCConn,
- testFullRemoteITAttribute,
- testFullRemoteITStatQueue,
- testFullRemoteITThreshold,
- testFullRemoteITResource,
- testFullRemoteITRoute,
- testFullRemoteITFilter,
- testFullRemoteITCharger,
- testFullRemoteITDispatcher,
- testFullRemoteITRate,
- testFullRemoteITAction,
- testFullRemoteITAccount,
- testFullRemoteITKillEngine,
- }
-)
-
-func TestFullRemoteIT(t *testing.T) {
- fullRemInternalCfgDirPath = "internal"
- fullRemEngineOneCfgDirPath = "remote"
-
- for _, stest := range sTestsFullRemoteIT {
- t.Run(*dbType, stest)
- }
-}
-
-func testFullRemoteITInitCfg(t *testing.T) {
- var err error
- fullRemInternalCfgPath = path.Join(*dataDir, "conf", "samples", "full_remote", fullRemInternalCfgDirPath)
- fullRemInternalCfg, err = config.NewCGRConfigFromPath(fullRemInternalCfgPath)
- if err != nil {
- t.Error(err)
- }
-
- // prepare config for engine1
- fullRemEngineOneCfgPath = path.Join(*dataDir, "conf", "samples",
- "full_remote", fullRemEngineOneCfgDirPath)
- fullRemEngineOneCfg, err = config.NewCGRConfigFromPath(fullRemEngineOneCfgPath)
- if err != nil {
- t.Error(err)
- }
- fullRemEngineOneCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
-
-}
-
-func testFullRemoteITDataFlush(t *testing.T) {
- if err := engine.InitDataDB(fullRemEngineOneCfg); err != nil {
- t.Fatal(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testFullRemoteITStartEngine(t *testing.T) {
- engine.KillEngine(100)
- if _, err := engine.StartEngine(fullRemInternalCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(fullRemEngineOneCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- time.Sleep(200 * time.Millisecond)
-}
-
-func testFullRemoteITRPCConn(t *testing.T) {
- var err error
- fullRemInternalRPC, err = newRPCClient(fullRemInternalCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
- fullRemEngineOneRPC, err = newRPCClient(fullRemEngineOneCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testFullRemoteITAttribute(t *testing.T) {
- // verify for not found in internal
- var reply *engine.AttributeProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ATTR_1001_SIMPLEAUTH",
- Contexts: []string{"simpleauth"},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Attributes: []*engine.Attribute{{
- Path: utils.MetaReq + utils.NestingSep + "Password",
- Type: utils.MetaConstant,
- Value: config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep),
- }},
- Weight: 20,
- },
- }
- alsPrf.Compile()
- // add an attribute profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}},
- &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.AttributeProfile), utils.ToJSON(reply))
- }
- // update the attribute profile and verify it to be updated
- alsPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- alsPrf.Compile()
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}},
- &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.AttributeProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITStatQueue(t *testing.T) {
- // verify for not found in internal
- var reply *engine.StatQueueProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- stat := &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaACD,
- },
- {
- MetricID: utils.MetaTCD,
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- // add a statQueue profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetStatQueueProfile, stat, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(stat.StatQueueProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(stat.StatQueueProfile), utils.ToJSON(reply))
- }
- // update the statQueue profile and verify it to be updated
- stat.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetStatQueueProfile, stat, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetStatQueueProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(stat.StatQueueProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(stat.StatQueueProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITThreshold(t *testing.T) {
- // verify for not found in internal
- var reply *engine.ThresholdProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetThresholdProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- tPrfl := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Test",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1"},
- Async: true,
- },
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetThresholdProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tPrfl.ThresholdProfile), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- tPrfl.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetThresholdProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tPrfl.ThresholdProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITResource(t *testing.T) {
- // verify for not found in internal
- var reply *engine.ResourceProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- rlsPrf := &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "ResGroup1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- UsageTTL: -1,
- Limit: 7,
- AllocationMessage: "",
- Stored: true,
- Weight: 10,
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rlsPrf.ResourceProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(rlsPrf.ResourceProfile), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- rlsPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetResourceProfile, rlsPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetResourceProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rlsPrf.ResourceProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(rlsPrf.ResourceProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITRoute(t *testing.T) {
- // verify for not found in internal
- var reply *engine.RouteProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetRouteProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- routePrf := &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "ROUTE_ACNT_1001",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2017, 11, 27, 0, 0, 0, 0, time.UTC),
- },
- Sorting: utils.MetaWeight,
- Routes: []*engine.Route{{
- ID: "route1",
- Weight: 10,
- }, {
- ID: "route2",
- Weight: 20,
- }},
- Weight: 20,
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetRouteProfile, routePrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetRouteProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(routePrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(routePrf), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- routePrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetRouteProfile, routePrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetRouteProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(routePrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(routePrf), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITFilter(t *testing.T) {
- // verify for not found in internal
- var reply *engine.Filter
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetFilter,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- fltr := &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_ACNT_1001",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Values: []string{"1001"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetFilter, fltr, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetFilter,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(fltr, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(fltr), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- fltr.Rules = []*engine.FilterRule{
- {
- Element: "~*req.Account",
- Type: utils.MetaString,
- Values: []string{"1001", "1002"},
- },
- {
- Element: "~*req.Destination",
- Type: utils.MetaPrefix,
- Values: []string{"10", "20"},
- },
- }
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetFilter, fltr, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetFilter,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(fltr, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(fltr), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITCharger(t *testing.T) {
- // verify for not found in internal
- var reply *engine.ChargerProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetChargerProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- chargerProfile := &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "DEFAULT",
- RunID: utils.MetaDefault,
- AttributeIDs: []string{utils.MetaNone},
- Weight: 0,
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetChargerProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(chargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(chargerProfile), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- chargerProfile.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetChargerProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(chargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(chargerProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITDispatcher(t *testing.T) {
- // verify for not found in internal
- var reply *engine.DispatcherProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetDispatcherProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "Dsp1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Strategy: utils.MetaFirst,
- Weight: 20,
- },
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetDispatcherProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(dispatcherProfile.DispatcherProfile), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- dispatcherProfile.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetDispatcherProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(dispatcherProfile.DispatcherProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITRate(t *testing.T) {
- // verify for not found in internal
- var reply *utils.RateProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- apiRPrf := &utils.APIRateProfileWithAPIOpts{
- APIRateProfile: &utils.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- 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 *",
- },
- },
- },
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetRateProfile, apiRPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- rPrf, err := apiRPrf.AsRateProfile()
- if err != nil {
- t.Error(err)
- }
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}},
- &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(rPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(rPrf), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- apiRPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetRateProfile, apiRPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
- rPrf, err = apiRPrf.AsRateProfile()
- if err != nil {
- t.Error(err)
- }
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}},
- &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(rPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(rPrf), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITAction(t *testing.T) {
- // verify for not found in internal
- var reply *engine.ActionProfile
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetActionProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACT_1"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- var replySet string
- actPrf = &engine.ActionProfileWithAPIOpts{
- ActionProfile: &engine.ActionProfile{
- Tenant: "cgrates.org",
- ID: "ACT_1",
- Actions: []*engine.APAction{
- {
- ID: "test_action_id",
- Diktats: []*engine.APDiktat{{}},
- },
- {
- ID: "test_action_id2",
- Diktats: []*engine.APDiktat{{}},
- },
- },
- },
- APIOpts: map[string]interface{}{},
- }
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetActionProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACT_1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(actPrf.ActionProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(actPrf.ActionProfile), utils.ToJSON(reply))
- }
- // update the threshold profile and verify it to be updated
- actPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetActionProfile, actPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetActionProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ACT_1"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(actPrf.ActionProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(actPrf.ActionProfile), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITAccount(t *testing.T) {
- // verify for not found in internal
- var reply *utils.Account
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetAccount,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1001"}},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-
- apiAccPrf := &utils.APIAccountWithOpts{
- APIAccount: &utils.APIAccount{
- Tenant: "cgrates.org",
- ID: "1001",
- Weights: ";20",
- Opts: map[string]interface{}{
- "TEST0": 2.,
- },
- Balances: map[string]*utils.APIBalance{
- "MonetaryBalance": {
- ID: "MonetaryBalance",
- Weights: ";10",
- Type: utils.MetaMonetary,
- Opts: map[string]interface{}{
- "TEST1": 5.,
- },
- CostIncrements: []*utils.APICostIncrement{
- {
- FilterIDs: []string{"fltr1", "fltr2"},
- Increment: utils.Float64Pointer(1.3),
- FixedFee: utils.Float64Pointer(2.3),
- RecurrentFee: utils.Float64Pointer(3.3),
- },
- },
- AttributeIDs: []string{"attr1", "attr2"},
- UnitFactors: []*utils.APIUnitFactor{
- {
- FilterIDs: []string{"fltr1", "fltr2"},
- Factor: 100,
- },
- {
- FilterIDs: []string{"fltr3"},
- Factor: 200,
- },
- },
- Units: 14,
- },
- "VoiceBalance": {
- ID: "VoiceBalance",
- Weights: ";10",
- Type: utils.MetaVoice,
- Opts: map[string]interface{}{},
- Units: 3600000000000,
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var replySet string
-
- // add a threshold profile in engine1 and verify it internal
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetAccount, apiAccPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- accPrf, err := apiAccPrf.AsAccount()
- if err != nil {
- t.Error(err)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetAccount,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1001"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(accPrf, reply) {
- t.Errorf("Expecting : %+v \n, received: %+v", utils.ToJSON(accPrf), utils.ToJSON(reply))
- }
-
- // update the threshold profile and verify it to be updated
- apiAccPrf.FilterIDs = []string{"*string:~*req.Account:1001", "*string:~*req.Destination:1002"}
- if err := fullRemEngineOneRPC.Call(utils.APIerSv1SetAccount, apiAccPrf, &replySet); err != nil {
- t.Error(err)
- } else if replySet != utils.OK {
- t.Error("Unexpected reply returned", replySet)
- }
-
- accPrf, err = apiAccPrf.AsAccount()
- if err != nil {
- t.Error(err)
- }
-
- if err := fullRemInternalRPC.Call(utils.APIerSv1GetAccount,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "1001"}},
- &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(accPrf, reply) {
- t.Errorf("Expecting : %+v \n, received: %+v", utils.ToJSON(accPrf), utils.ToJSON(reply))
- }
-}
-
-func testFullRemoteITKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/guardian.go b/apier/v1/guardian.go
deleted file mode 100644
index 787e522d7..000000000
--- a/apier/v1/guardian.go
+++ /dev/null
@@ -1,56 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/guardian"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewGuardianSv1() *GuardianSv1 {
- return &GuardianSv1{}
-}
-
-type GuardianSv1 struct{}
-
-// RemoteLock will lock a key from remote
-func (self *GuardianSv1) RemoteLock(attr *dispatchers.AttrRemoteLockWithAPIOpts, reply *string) (err error) {
- *reply = guardian.Guardian.GuardIDs(attr.ReferenceID, attr.Timeout, attr.LockIDs...)
- return
-}
-
-// RemoteUnlock will unlock a key from remote based on reference ID
-func (self *GuardianSv1) RemoteUnlock(refID *dispatchers.AttrRemoteUnlockWithAPIOpts, reply *[]string) (err error) {
- *reply = guardian.Guardian.UnguardIDs(refID.RefID)
- return
-}
-
-// Ping return pong if the service is active
-func (self *GuardianSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (self *GuardianSv1) Call(_ *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(self, serviceMethod, args, reply)
-}
diff --git a/apier/v1/guardian_it_test.go b/apier/v1/guardian_it_test.go
deleted file mode 100644
index f43d30f17..000000000
--- a/apier/v1/guardian_it_test.go
+++ /dev/null
@@ -1,105 +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 (
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-//Test start here
-func TestGuardianSIT(t *testing.T) {
- var err error
- var guardianConfigDIR string
- switch *dbType {
- case utils.MetaInternal:
- guardianConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- guardianConfigDIR = "tutmysql"
- case utils.MetaMongo:
- guardianConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- guardianCfgPath := path.Join(*dataDir, "conf", "samples", guardianConfigDIR)
- guardianCfg, err := config.NewCGRConfigFromPath(guardianCfgPath)
- if err != nil {
- t.Error(err)
- }
-
- if err = engine.InitDataDB(guardianCfg); err != nil {
- t.Fatal(err)
- }
-
- if err = engine.InitStorDB(guardianCfg); err != nil {
- t.Fatal(err)
- }
-
- // start engine
- if _, err = engine.StopStartEngine(guardianCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-
- // start RPC
- guardianRPC, err := newRPCClient(guardianCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-
- // lock
- args := utils.AttrRemoteLock{
- ReferenceID: "",
- LockIDs: []string{"lock1"},
- Timeout: 500 * time.Millisecond,
- }
- var reply string
- if err = guardianRPC.Call(utils.GuardianSv1RemoteLock, &args, &reply); err != nil {
- t.Error(err)
- }
- var unlockReply []string
- if err = guardianRPC.Call(utils.GuardianSv1RemoteUnlock, &dispatchers.AttrRemoteUnlockWithAPIOpts{RefID: reply}, &unlockReply); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(args.LockIDs, unlockReply) {
- t.Errorf("Expected: %s , received: %s", utils.ToJSON(args.LockIDs), utils.ToJSON(unlockReply))
- }
-
- // ping
- var resp string
- if err = guardianRPC.Call(utils.GuardianSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-
- // stop engine
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/lib_test.go b/apier/v1/lib_test.go
deleted file mode 100644
index e7d7c2efc..000000000
--- a/apier/v1/lib_test.go
+++ /dev/null
@@ -1,47 +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 (
- "errors"
- "flag"
- "net/rpc"
- "net/rpc/jsonrpc"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
- waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for rater to start and cache")
- encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication")
- dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)")
-)
-
-func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) {
- switch *encoding {
- case utils.MetaJSON:
- return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen)
- case utils.MetaGOB:
- return rpc.Dial(utils.TCP, cfg.RPCGOBListen)
- default:
- return nil, errors.New("UNSUPPORTED_RPC")
- }
-}
diff --git a/apier/v1/libapier.go b/apier/v1/libapier.go
deleted file mode 100644
index 1509a1ec8..000000000
--- a/apier/v1/libapier.go
+++ /dev/null
@@ -1,187 +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 (
- "strings"
-
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// CallCache caching the item based on cacheopt
-// visible in APIerSv2
-func (apierSv1 *APIerSv1) CallCache(cacheopt string, tnt, cacheID, itemID string,
- filters *[]string, contexts []string, opts map[string]interface{}) (err error) {
- var reply, method string
- var args interface{}
- switch utils.FirstNonEmpty(cacheopt, apierSv1.Config.GeneralCfg().DefaultCaching) {
- case utils.MetaNone:
- return
- case utils.MetaReload:
- method = utils.CacheSv1ReloadCache
- if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
- return
- }
- case utils.MetaLoad:
- method = utils.CacheSv1LoadCache
- if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
- return
- }
- case utils.MetaRemove:
- method = utils.CacheSv1RemoveItems
- if args, err = apierSv1.composeArgsReload(tnt, cacheID, itemID, filters, contexts, opts); err != nil {
- return
- }
- case utils.MetaClear:
- cacheIDs := make([]string, 1, 2)
- cacheIDs[0] = cacheID
- // do not send a EmptyString if the item doesn't have indexes
- if cIdx, has := utils.CacheInstanceToCacheIndex[cacheID]; has {
- cacheIDs = append(cacheIDs, cIdx)
- }
- method = utils.CacheSv1Clear
- args = &utils.AttrCacheIDsWithAPIOpts{
- Tenant: tnt,
- CacheIDs: cacheIDs,
- APIOpts: opts,
- }
-
- }
- return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns,
- method, args, &reply)
-}
-
-// composeArgsReload add the ItemID to AttrReloadCache
-// for a specific CacheID
-func (apierSv1 *APIerSv1) composeArgsReload(tnt, cacheID, itemID string, filterIDs *[]string, contexts []string, opts map[string]interface{}) (rpl utils.AttrReloadCacheWithAPIOpts, err error) {
- rpl = utils.AttrReloadCacheWithAPIOpts{
- Tenant: tnt,
- ArgsCache: map[string][]string{
- utils.CacheInstanceToArg[cacheID]: {itemID},
- },
- APIOpts: opts,
- }
- if filterIDs == nil { // in case we remove a profile we do not need to reload the indexes
- return
- }
- // populate the indexes
- idxCacheID := utils.CacheInstanceToArg[utils.CacheInstanceToCacheIndex[cacheID]]
- if len(*filterIDs) == 0 { // in case we do not have any filters reload the *none filter indexes
- indxID := utils.ConcatenatedKey(utils.MetaNone, utils.MetaAny, utils.MetaAny)
- if cacheID != utils.CacheAttributeProfiles &&
- cacheID != utils.CacheDispatcherProfiles {
- rpl.ArgsCache[idxCacheID] = []string{utils.ConcatenatedKey(tnt, indxID)}
- return
- }
- rpl.ArgsCache[idxCacheID] = make([]string, len(contexts))
- for i, ctx := range contexts {
- rpl.ArgsCache[idxCacheID][i] = utils.ConcatenatedKey(tnt, ctx, indxID)
- }
- return
- }
- indxIDs := make([]string, 0, len(*filterIDs))
- for _, id := range *filterIDs {
- var fltr *engine.Filter
- if fltr, err = apierSv1.DataManager.GetFilter(context.TODO(), tnt, id, true, true, utils.NonTransactional); err != nil {
- return
- }
- for _, flt := range fltr.Rules {
- if !engine.FilterIndexTypes.Has(flt.Type) {
- continue
- }
- isDyn := strings.HasPrefix(flt.Element, utils.DynamicDataPrefix)
- for _, fldVal := range flt.Values {
- if isDyn {
- if !strings.HasPrefix(fldVal, utils.DynamicDataPrefix) {
- indxIDs = append(indxIDs, utils.ConcatenatedKey(flt.Type, flt.Element[1:], fldVal))
- }
- } else if strings.HasPrefix(fldVal, utils.DynamicDataPrefix) {
- indxIDs = append(indxIDs, utils.ConcatenatedKey(flt.Type, fldVal[1:], flt.Element))
- }
- }
- }
- }
- if cacheID != utils.CacheAttributeProfiles &&
- cacheID != utils.CacheDispatcherProfiles {
- rpl.ArgsCache[idxCacheID] = make([]string, len(indxIDs))
- for i, indxID := range indxIDs {
- rpl.ArgsCache[idxCacheID][i] = utils.ConcatenatedKey(tnt, indxID)
- }
- return
- }
-
- rpl.ArgsCache[idxCacheID] = make([]string, 0, len(indxIDs)*len(indxIDs))
- for _, ctx := range contexts {
- for _, indxID := range indxIDs {
- rpl.ArgsCache[idxCacheID] = append(rpl.ArgsCache[idxCacheID], utils.ConcatenatedKey(tnt, ctx, indxID))
- }
- }
- return
-}
-
-// callCacheRevDestinations used for reverse destination, loadIDs and indexes replication
-func (apierSv1 *APIerSv1) callCacheMultiple(cacheopt, tnt, cacheID string, itemIDs []string, opts map[string]interface{}) (err error) {
- if len(itemIDs) == 0 {
- return
- }
- var reply, method string
- var args interface{}
- switch utils.FirstNonEmpty(cacheopt, apierSv1.Config.GeneralCfg().DefaultCaching) {
- case utils.MetaNone:
- return
- case utils.MetaReload:
- method = utils.CacheSv1ReloadCache
- args = utils.AttrReloadCacheWithAPIOpts{
- Tenant: tnt,
- ArgsCache: map[string][]string{
- utils.CacheInstanceToArg[cacheID]: itemIDs,
- },
- APIOpts: opts,
- }
- case utils.MetaLoad:
- method = utils.CacheSv1LoadCache
- args = utils.AttrReloadCacheWithAPIOpts{
- Tenant: tnt,
- ArgsCache: map[string][]string{
- utils.CacheInstanceToArg[cacheID]: itemIDs,
- },
- APIOpts: opts,
- }
- case utils.MetaRemove:
- method = utils.CacheSv1RemoveItems
- args = utils.AttrReloadCacheWithAPIOpts{
- Tenant: tnt,
- ArgsCache: map[string][]string{
- utils.CacheInstanceToArg[cacheID]: itemIDs,
- },
- APIOpts: opts,
- }
- case utils.MetaClear:
- method = utils.CacheSv1Clear
- args = &utils.AttrCacheIDsWithAPIOpts{
- Tenant: tnt,
- CacheIDs: []string{cacheID},
- APIOpts: opts,
- }
- }
- return apierSv1.ConnMgr.Call(context.TODO(), apierSv1.Config.ApierCfg().CachesConns,
- method, args, &reply)
-}
diff --git a/apier/v1/libapier_test.go b/apier/v1/libapier_test.go
deleted file mode 100644
index 173e25666..000000000
--- a/apier/v1/libapier_test.go
+++ /dev/null
@@ -1,216 +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 (
- "reflect"
- "testing"
-
- "github.com/cgrates/birpc"
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestComposeArgsReload(t *testing.T) {
- apv1 := &APIerSv1{}
- expArgs := utils.AttrReloadCacheWithAPIOpts{
- APIOpts: make(map[string]interface{}),
- Tenant: "cgrates.org",
- ArgsCache: map[string][]string{
- utils.AttributeProfileIDs: {"cgrates.org:ATTR1"},
- },
- }
-
- if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles,
- "cgrates.org:ATTR1", nil, nil, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(expArgs, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
- }
-
- expArgs.ArgsCache[utils.AttributeFilterIndexIDs] = []string{"cgrates.org:*cdrs:*none:*any:*any"}
-
- if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles,
- "cgrates.org:ATTR1", &[]string{}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(expArgs, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
- }
-
- expArgs.ArgsCache[utils.AttributeFilterIndexIDs] = []string{
- "cgrates.org:*cdrs:*string:*req.Account:1001",
- "cgrates.org:*cdrs:*prefix:*req.Destination:1001",
- }
-
- if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheAttributeProfiles,
- "cgrates.org:ATTR1", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination", "*gt:~req.Usage:0"}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(expArgs, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
- }
-
- expArgs = utils.AttrReloadCacheWithAPIOpts{
- APIOpts: make(map[string]interface{}),
- Tenant: "cgrates.org",
- ArgsCache: map[string][]string{
- utils.StatsQueueProfileIDs: {"cgrates.org:Stat2"},
- utils.StatFilterIndexIDs: {
- "cgrates.org:*string:*req.Account:1001",
- "cgrates.org:*prefix:*req.Destination:1001",
- },
- },
- }
-
- if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"}, nil, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(expArgs, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
- }
-
- expArgs.ArgsCache[utils.StatFilterIndexIDs] = []string{"cgrates.org:*none:*any:*any"}
-
- if rply, err := apv1.composeArgsReload("cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(expArgs, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(expArgs), utils.ToJSON(rply))
- }
-
- if _, err := apv1.composeArgsReload("cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"FLTR1"}, []string{utils.MetaCDRs}, make(map[string]interface{})); err != utils.ErrNoDatabaseConn {
- t.Fatal(err)
- }
-}
-
-type rpcRequest struct {
- Method string
- Params interface{}
-}
-type rpcMock chan *rpcRequest
-
-func (r rpcMock) Call(_ *context.Context, method string, args, _ interface{}) error {
- r <- &rpcRequest{
- Method: method,
- Params: args,
- }
- return nil
-}
-
-func TestCallCache(t *testing.T) {
- cache := make(rpcMock, 1)
- ch := make(chan birpc.ClientConnector, 1)
- ch <- cache
- cn := engine.NewConnManager(config.CgrConfig(), map[string]chan birpc.ClientConnector{
- utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches): ch,
- })
- apv1 := &APIerSv1{
- ConnMgr: cn,
- Config: config.CgrConfig(),
- }
- if err := apv1.CallCache(utils.MetaNone, "", "", "", nil, nil, nil); err != nil {
- t.Fatal(err)
- } else if len(cache) != 0 {
- t.Fatal("Expected call cache to not be called")
- }
- exp := &rpcRequest{
- Method: utils.CacheSv1Clear,
- Params: &utils.AttrCacheIDsWithAPIOpts{
- Tenant: "cgrates.org",
- CacheIDs: []string{utils.CacheStatQueueProfiles, utils.CacheStatFilterIndexes},
- APIOpts: make(map[string]interface{}),
- },
- }
- if err := apv1.CallCache(utils.MetaClear, "cgrates.org", utils.CacheStatQueueProfiles, "", nil, nil, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if len(cache) != 1 {
- t.Fatal("Expected call cache to be called")
- } else if rply := <-cache; !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-
- exp = &rpcRequest{
- Method: utils.CacheSv1ReloadCache,
- Params: utils.AttrReloadCacheWithAPIOpts{
- APIOpts: make(map[string]interface{}),
- Tenant: "cgrates.org",
- ArgsCache: map[string][]string{
- utils.StatsQueueProfileIDs: {"cgrates.org:Stat2"},
- utils.StatFilterIndexIDs: {
- "cgrates.org:*string:*req.Account:1001",
- "cgrates.org:*prefix:*req.Destination:1001",
- },
- },
- },
- }
-
- if err := apv1.CallCache(utils.MetaReload, "cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"},
- nil, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if len(cache) != 1 {
- t.Fatal("Expected call cache to be called")
- } else if rply := <-cache; !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rply))
- }
- exp.Method = utils.CacheSv1LoadCache
- if err := apv1.CallCache(utils.MetaLoad, "cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"},
- nil, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if len(cache) != 1 {
- t.Fatal("Expected call cache to be called")
- } else if rply := <-cache; !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rply))
- }
- exp.Method = utils.CacheSv1RemoveItems
- if err := apv1.CallCache(utils.MetaRemove, "cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"*string:~*req.Account:1001|~req.Subject", "*prefix:1001:~*req.Destination"},
- nil, make(map[string]interface{})); err != nil {
- t.Fatal(err)
- } else if len(cache) != 1 {
- t.Fatal("Expected call cache to be called")
- } else if rply := <-cache; !reflect.DeepEqual(exp, rply) {
- t.Errorf("Expected %s ,received: %s", utils.ToJSON(exp), utils.ToJSON(rply))
- }
-
- if err := apv1.CallCache(utils.MetaLoad, "cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"FLTR1", "*prefix:1001:~*req.Destination"},
- nil, make(map[string]interface{})); err != utils.ErrNoDatabaseConn {
- t.Fatal(err)
- } else if len(cache) != 0 {
- t.Fatal("Expected call cache to not be called")
- }
- if err := apv1.CallCache(utils.MetaRemove, "cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"FLTR1", "*prefix:1001:~*req.Destination"},
- nil, make(map[string]interface{})); err != utils.ErrNoDatabaseConn {
- t.Fatal(err)
- } else if len(cache) != 0 {
- t.Fatal("Expected call cache to not be called")
- }
- if err := apv1.CallCache(utils.MetaReload, "cgrates.org", utils.CacheStatQueueProfiles,
- "cgrates.org:Stat2", &[]string{"FLTR1", "*prefix:1001:~*req.Destination"},
- nil, make(map[string]interface{})); err != utils.ErrNoDatabaseConn {
- t.Fatal(err)
- } else if len(cache) != 0 {
- t.Fatal("Expected call cache to not be called")
- }
-}
diff --git a/apier/v1/loaders.go b/apier/v1/loaders.go
deleted file mode 100644
index b9b5402c9..000000000
--- a/apier/v1/loaders.go
+++ /dev/null
@@ -1,55 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/loaders"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewLoaderSv1(ldrS *loaders.LoaderService) *LoaderSv1 {
- return &LoaderSv1{ldrS: ldrS}
-}
-
-// Exports RPC from LoaderService
-type LoaderSv1 struct {
- ldrS *loaders.LoaderService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (ldrSv1 *LoaderSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(ldrSv1, serviceMethod, args, reply)
-}
-
-func (ldrSv1 *LoaderSv1) Load(args *loaders.ArgsProcessFolder,
- rply *string) error {
- return ldrSv1.ldrS.V1Load(args, rply)
-}
-
-func (ldrSv1 *LoaderSv1) Remove(args *loaders.ArgsProcessFolder,
- rply *string) error {
- return ldrSv1.ldrS.V1Remove(args, rply)
-}
-
-func (rsv1 *LoaderSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/precache_it_test.go b/apier/v1/precache_it_test.go
deleted file mode 100644
index d0750f7e8..000000000
--- a/apier/v1/precache_it_test.go
+++ /dev/null
@@ -1,257 +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 (
- "flag"
- "net/rpc"
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
- "github.com/cgrates/ltcache"
-)
-
-var (
- precacheCfgPath string
- precacheCfg *config.CGRConfig
- precacheRPC *rpc.Client
- precacheConfigDIR string //run tests for specific configuration
-
- // use this flag to test the APIBan implemnentation for precache
- apiBan = flag.Bool("apiban", true, "used to control if we run the apiban tests")
-
- sTestsPrecache = []func(t *testing.T){
- testPrecacheInitCfg,
- testPrecacheResetDataDB,
- testPrecacheStartEngine,
- testPrecacheRpcConn,
- testPrecacheGetCacheStatsBeforeLoad,
- testPrecacheFromFolder,
- testPrecacheRestartEngine,
- testPrecacheGetItemIDs,
- testPrecacheGetCacheStatsAfterRestart,
- testPrecacheKillEngine,
- }
-)
-
-// this tests may fail because of apiban limit( 5 requests per 2 minutes for an APIKey)
-// if needed add more APIKeys
-func TestPrecacheIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- precacheConfigDIR = "tutmysql"
- case utils.MetaMongo:
- precacheConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- if *apiBan {
- precacheConfigDIR += "_apiban"
- }
- for _, stest := range sTestsPrecache {
- t.Run(precacheConfigDIR, stest)
- }
-}
-
-func testPrecacheInitCfg(t *testing.T) {
- var err error
- precacheCfgPath = path.Join(*dataDir, "conf", "samples", "precache", precacheConfigDIR)
- precacheCfg, err = config.NewCGRConfigFromPath(precacheCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testPrecacheResetDataDB(t *testing.T) {
- if err := engine.InitDataDB(precacheCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testPrecacheStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(precacheCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testPrecacheRpcConn(t *testing.T) {
- var err error
- precacheRPC, err = newRPCClient(precacheCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testPrecacheGetItemIDs(t *testing.T) {
- args := &utils.ArgsGetCacheItemIDs{
- CacheID: utils.MetaDefault,
- }
- var reply *[]string
- if err := precacheRPC.Call(utils.CacheSv1GetItemIDs, args, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testPrecacheGetCacheStatsBeforeLoad(t *testing.T) {
- var reply *map[string]*ltcache.CacheStats
- args := &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: []string{},
- }
- dfltStats := engine.GetDefaultEmptyCacheStats()
- expectedStats := &dfltStats
- if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil {
- t.Error(err.Error())
- } else if !reflect.DeepEqual(reply, expectedStats) {
- t.Errorf("Expecting : %+v,\n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(reply))
- }
-}
-
-func testPrecacheFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "precache")}
- if err := precacheRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testPrecacheRestartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(precacheCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
- var err error
- precacheRPC, err = newRPCClient(precacheCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
- time.Sleep(2 * time.Second) // let the *apiban cache to be populated
-}
-
-func testPrecacheGetCacheStatsAfterRestart(t *testing.T) {
- var reply *map[string]*ltcache.CacheStats
- args := &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: []string{},
- }
- expectedStats := &map[string]*ltcache.CacheStats{
- utils.MetaDefault: {},
- utils.CacheAttributeFilterIndexes: {
- Items: 2,
- Groups: 2,
- },
- utils.CacheAttributeProfiles: {Items: 1},
- utils.CacheChargerFilterIndexes: {},
- utils.CacheChargerProfiles: {},
- utils.CacheDispatcherFilterIndexes: {},
- utils.CacheDispatcherProfiles: {Items: 6},
- utils.CacheDispatcherHosts: {Items: 1},
- utils.CacheDispatcherRoutes: {},
- utils.CacheDispatcherLoads: {},
- utils.CacheDestinations: {Items: 5},
- utils.CacheDispatchers: {},
- utils.CacheEventResources: {},
- utils.CacheFilters: {Items: 15},
- utils.CacheRateProfilesFilterIndexes: {},
- utils.CacheRateFilterIndexes: {},
- utils.CacheRateProfiles: {},
- utils.CacheResourceFilterIndexes: {
- Items: 6,
- Groups: 1,
- },
- utils.CacheResourceProfiles: {Items: 3},
- utils.CacheResources: {Items: 3},
- utils.CacheReverseDestinations: {Items: 7},
- utils.CacheRPCResponses: {},
- utils.CacheStatFilterIndexes: {
- Items: 2,
- Groups: 1,
- },
- utils.CacheStatQueueProfiles: {Items: 1},
- utils.CacheStatQueues: {Items: 1},
- utils.CacheSTIR: {},
- utils.CacheCapsEvents: {},
- utils.CacheEventCharges: {},
- utils.CacheRouteFilterIndexes: {
- Items: 6,
- Groups: 1,
- },
- utils.CacheRouteProfiles: {Items: 3},
- utils.CacheThresholdFilterIndexes: {
- Items: 10,
- Groups: 1,
- },
- utils.CacheThresholdProfiles: {Items: 7},
- utils.CacheThresholds: {Items: 7},
- utils.CacheTimings: {},
- utils.CacheDiameterMessages: {},
- utils.CacheClosedSessions: {},
- utils.CacheLoadIDs: {},
- utils.CacheRPCConnections: {},
- utils.CacheCDRIDs: {},
- utils.CacheUCH: {},
- utils.CacheReverseFilterIndexes: {},
- utils.CacheAccounts: {},
- utils.CacheVersions: {},
- utils.CacheTBLTPTimings: {},
- utils.CacheTBLTPDestinations: {},
- utils.CacheTBLTPResources: {},
- utils.CacheTBLTPStats: {},
- utils.CacheTBLTPThresholds: {},
- utils.CacheTBLTPFilters: {},
- utils.CacheSessionCostsTBL: {},
- utils.CacheCDRsTBL: {},
- utils.CacheTBLTPRoutes: {},
- utils.CacheTBLTPAttributes: {},
- utils.CacheTBLTPChargers: {},
- utils.CacheTBLTPDispatchers: {},
- utils.CacheTBLTPDispatcherHosts: {},
- utils.CacheTBLTPRateProfiles: {},
- utils.MetaAPIBan: {},
- utils.CacheActionProfiles: {},
- utils.CacheActionProfilesFilterIndexes: {},
- utils.CacheTBLTPActionProfiles: {},
- utils.CacheTBLTPAccounts: {},
- utils.CacheReplicationHosts: {},
- }
- if *apiBan {
- (*expectedStats)[utils.MetaAPIBan] = <cache.CacheStats{Items: 254}
- }
- if err := precacheRPC.Call(utils.CacheSv1GetCacheStats, args, &reply); err != nil {
- t.Error(err.Error())
- } else if !reflect.DeepEqual(reply, expectedStats) {
- t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(expectedStats), utils.ToJSON(reply))
- }
-}
-
-func testPrecacheKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/preload_it_test.go b/apier/v1/preload_it_test.go
deleted file mode 100644
index 0c1576821..000000000
--- a/apier/v1/preload_it_test.go
+++ /dev/null
@@ -1,177 +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"
- "net/rpc/jsonrpc"
- "os"
- "os/exec"
- "path"
- "reflect"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/utils"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
-)
-
-var (
- preloadCfgPath string
- preloadCfgDIR string
- preloadCfg *config.CGRConfig
- preloadRPC *rpc.Client
-
- preloadTests = []func(t *testing.T){
- testCreateDirs,
- testPreloadITInitConfig,
- testPreloadITStartEngine,
- testPreloadITRpcConn,
- testPreloadITVerifyAttributes,
- testCleanupFiles,
- testPreloadITKillEngine,
- }
-)
-
-func TestPreload(t *testing.T) {
- preloadCfgDIR = "tutinternal"
- for _, test := range preloadTests {
- t.Run(preloadCfgDIR, test)
- }
-}
-
-func testCreateDirs(t *testing.T) {
- for _, dir := range []string{"/tmp/In", "/tmp/Out", "/tmp/LoaderIn", "/tmp/SubpathWithoutMove",
- "/tmp/SubpathLoaderWithMove", "/tmp/SubpathOut", "/tmp/templateLoaderIn", "/tmp/templateLoaderOut",
- "/tmp/customSepLoaderIn", "/tmp/customSepLoaderOut"} {
- if err := os.RemoveAll(dir); err != nil {
- t.Fatal("Error removing folder: ", dir, err)
- }
- if err := os.MkdirAll(dir, 0755); err != nil {
- t.Fatal("Error creating folder: ", dir, err)
- }
- }
- if err := os.WriteFile(path.Join("/tmp/In", utils.AttributesCsv), []byte(engine.AttributesCSVContent), 0644); err != nil {
- t.Fatal(err.Error())
- }
-}
-
-func testPreloadITInitConfig(t *testing.T) {
- var err error
- preloadCfgPath = path.Join(*dataDir, "conf", "samples", "loaders", preloadCfgDIR)
- if preloadCfg, err = config.NewCGRConfigFromPath(preloadCfgPath); err != nil {
- t.Fatal("Got config error: ", err.Error())
- }
-}
-
-func testPreloadITStartEngine(t *testing.T) {
- enginePath, err := exec.LookPath("cgr-engine")
- if err != nil {
- t.Error(err)
- }
- eng := exec.Command(enginePath, "-config_path", preloadCfgPath, "-preload", "CustomLoader")
- if err := eng.Start(); err != nil {
- t.Error(err)
- }
- fib := utils.Fib()
- var connected bool
- for i := 0; i < 25; i++ {
- time.Sleep(time.Duration(fib()) * time.Millisecond)
- if _, err := jsonrpc.Dial(utils.TCP, preloadCfg.ListenCfg().RPCJSONListen); err != nil {
- t.Logf("Error <%s> when opening test connection to: <%s>",
- err.Error(), preloadCfg.ListenCfg().RPCJSONListen)
- } else {
- connected = true
- break
- }
- }
- if !connected {
- t.Errorf("engine did not open port <%s>", preloadCfg.ListenCfg().RPCJSONListen)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testPreloadITRpcConn(t *testing.T) {
- var err error
- preloadRPC, err = newRPCClient(preloadCfg.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 testPreloadITVerifyAttributes(t *testing.T) {
- eAttrPrf := &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ALS1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Contexts: []string{"con1", "con2", "con3"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC)},
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{"*string:~*req.Field1:Initial"},
- Path: "*req.Field1",
- Type: utils.MetaVariable,
- Value: config.NewRSRParsersMustCompile("Sub1", utils.InfieldSep),
- },
- {
- FilterIDs: []string{},
- Path: "*req.Field2",
- Type: utils.MetaVariable,
- Value: config.NewRSRParsersMustCompile("Sub2", utils.InfieldSep),
- },
- },
- Blocker: true,
- Weight: 20.0,
- }
-
- var reply *engine.AttributeProfile
- if err := preloadRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ALS1"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- sort.Strings(reply.Contexts)
- if !reflect.DeepEqual(eAttrPrf, reply) {
- eAttrPrf.Attributes[1].FilterIDs = nil
- if !reflect.DeepEqual(eAttrPrf, reply) {
- t.Errorf("Expecting : %+v,\n received: %+v", utils.ToJSON(eAttrPrf), utils.ToJSON(reply))
- }
- }
-}
-
-func testCleanupFiles(t *testing.T) {
- for _, dir := range []string{"/tmp/In", "/tmp/Out", "/tmp/LoaderIn", "/tmp/SubpathWithoutMove",
- "/tmp/SubpathLoaderWithMove", "/tmp/SubpathOut"} {
- if err := os.RemoveAll(dir); err != nil {
- t.Fatal("Error removing folder: ", dir, err)
- }
- }
-}
-
-func testPreloadITKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/rateprofiles.go b/apier/v1/rateprofiles.go
deleted file mode 100644
index 98170a513..000000000
--- a/apier/v1/rateprofiles.go
+++ /dev/null
@@ -1,222 +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/birpc/context"
- "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(context.TODO(), 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(context.TODO(), 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(context.TODO(), 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(context.TODO(), 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(context.TODO(), 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(context.TODO(), 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 birpc.ClientConnector interface for internal RPC
-func (rSv1 *RateSv1) Call(ctx *context.Context, serviceMethod string,
- args, 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 6008e7a12..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/apier/v1/remote_it_test.go b/apier/v1/remote_it_test.go
deleted file mode 100644
index eeff1c1cc..000000000
--- a/apier/v1/remote_it_test.go
+++ /dev/null
@@ -1,868 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- internalCfgPath string
- internalCfgDirPath string
- internalCfg *config.CGRConfig
- internalRPC *rpc.Client
-
- engineOneCfgPath string
- engineOneCfgDirPath string
- engineOneCfg *config.CGRConfig
- engineOneRPC *rpc.Client
-
- engineTwoCfgPath string
- engineTwoCfgDirPath string
- engineTwoCfg *config.CGRConfig
- engineTwoRPC *rpc.Client
-
- sTestsInternalRemoteIT = []func(t *testing.T){
- testInternalRemoteITInitCfg,
- testInternalRemoteITDataFlush,
- testInternalRemoteITStartEngine,
- testInternalRemoteITRPCConn,
- testInternalRemoteLoadDataInEngineTwo,
-
- testInternalRemoteITGetAttribute,
- testInternalRemoteITGetThreshold,
- testInternalRemoteITGetThresholdProfile,
- testInternalRemoteITGetResource,
- testInternalRemoteITGetResourceProfile,
- testInternalRemoteITGetStatQueueProfile,
- testInternalRemoteITGetRoute,
- testInternalRemoteITGetFilter,
- testInternalRemoteITGetDestination,
- testInternalRemoteITGetReverseDestination,
- testInternalRemoteITGetChargerProfile,
- testInternalRemoteITGetDispatcherProfile,
- testInternalRemoteITGetDispatcherHost,
- testInternalRemoteITGetRateProfile,
-
- testInternalReplicationSetThreshold,
- testInternalMatchThreshold,
- testInternalReplicateStats,
-
- testInternalRemoteITKillEngine,
- }
-)
-
-func TestInternalRemoteIT(t *testing.T) {
- internalCfgDirPath = "internal"
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- engineOneCfgDirPath = "engine1_redis"
- engineTwoCfgDirPath = "engine2_redis"
- case utils.MetaMongo:
- engineOneCfgDirPath = "engine1_mongo"
- engineTwoCfgDirPath = "engine2_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- if *encoding == utils.MetaGOB {
- internalCfgDirPath += "_gob"
- }
- for _, stest := range sTestsInternalRemoteIT {
- t.Run(*dbType, stest)
- }
-}
-
-func testInternalRemoteITInitCfg(t *testing.T) {
- var err error
- internalCfgPath = path.Join(*dataDir, "conf", "samples", "remote_replication", internalCfgDirPath)
- internalCfg, err = config.NewCGRConfigFromPath(internalCfgPath)
- if err != nil {
- t.Error(err)
- }
-
- // prepare config for engine1
- engineOneCfgPath = path.Join(*dataDir, "conf", "samples",
- "remote_replication", engineOneCfgDirPath)
- engineOneCfg, err = config.NewCGRConfigFromPath(engineOneCfgPath)
- if err != nil {
- t.Error(err)
- }
- engineOneCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
-
- // prepare config for engine2
- engineTwoCfgPath = path.Join(*dataDir, "conf", "samples",
- "remote_replication", engineTwoCfgDirPath)
- engineTwoCfg, err = config.NewCGRConfigFromPath(engineTwoCfgPath)
- if err != nil {
- t.Error(err)
- }
- engineTwoCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
-
-}
-
-func testInternalRemoteITDataFlush(t *testing.T) {
- if err := engine.InitDataDB(engineOneCfg); err != nil {
- t.Fatal(err)
- }
- if err := engine.InitDataDB(engineTwoCfg); err != nil {
- t.Fatal(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testInternalRemoteITStartEngine(t *testing.T) {
- engine.KillEngine(100)
- if _, err := engine.StartEngine(engineOneCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(engineTwoCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(internalCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- time.Sleep(200 * time.Millisecond)
-}
-
-func testInternalRemoteITRPCConn(t *testing.T) {
- var err error
- engineOneRPC, err = newRPCClient(engineOneCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
- engineTwoRPC, err = newRPCClient(engineTwoCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
- internalRPC, err = newRPCClient(internalCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testInternalRemoteLoadDataInEngineTwo(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
- if err := engineTwoRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testInternalRemoteITGetAttribute(t *testing.T) {
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ATTR_1001_SIMPLEAUTH",
- Contexts: []string{"simpleauth"},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Attributes: []*engine.Attribute{{
- Path: utils.MetaReq + utils.NestingSep + "Password",
- Type: utils.MetaConstant,
- Value: config.NewRSRParsersMustCompile("CGRateS.org", utils.InfieldSep),
- }},
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var reply *engine.AttributeProfile
- if err := internalRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ATTR_1001_SIMPLEAUTH"}}, &reply); err != nil {
- t.Fatal(err)
- }
- if *encoding == utils.MetaGOB { // in gob emtpty slice is encoded as nil
- alsPrf.AttributeProfile.Attributes[0].FilterIDs = nil
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.AttributeProfile), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetThreshold(t *testing.T) {
- var td engine.Threshold
- eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}
- if err := internalRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd, td) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- }
-}
-
-func testInternalRemoteITGetThresholdProfile(t *testing.T) {
- var reply *engine.ThresholdProfile
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_ACNT_1001",
- FilterIDs: []string{"FLTR_ACNT_1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- MaxHits: 1,
- MinHits: 1,
- MinSleep: time.Second,
- Weight: 10.0,
- ActionIDs: []string{"ACT_LOG_WARNING"},
- Async: true,
- },
- }
- if err := internalRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_1001"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(tPrfl.ThresholdProfile), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetResource(t *testing.T) {
- var reply *engine.Resource
- expectedResources := &engine.Resource{
- Tenant: "cgrates.org",
- ID: "ResGroup1",
- Usages: map[string]*engine.ResourceUsage{},
- }
- if err := internalRPC.Call(utils.ResourceSv1GetResource,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup1"}}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expectedResources) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedResources), utils.ToJSON(reply))
- }
-
- if err := internalRPC.Call(utils.ResourceSv1GetResource,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ResGroup1"}}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expectedResources) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedResources), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetResourceProfile(t *testing.T) {
- rlsPrf := &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "ResGroup1",
- FilterIDs: []string{"FLTR_RES"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- UsageTTL: -1,
- Limit: 7,
- AllocationMessage: "",
- Stored: true,
- Weight: 10,
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
- var reply *engine.ResourceProfile
- if err := internalRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: rlsPrf.ID}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, rlsPrf.ResourceProfile) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsPrf.ResourceProfile), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetStatQueueProfile(t *testing.T) {
- expStq := &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "Stats2",
- FilterIDs: []string{"FLTR_ACNT_1001_1002"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: -1,
- MinItems: 0,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaTCC,
- },
- {
- MetricID: utils.MetaTCD,
- },
- },
- Stored: false,
- Blocker: true,
- Weight: 30,
- ThresholdIDs: []string{utils.MetaNone},
- }
- //reverse metric order
- expStq2 := &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "Stats2",
- FilterIDs: []string{"FLTR_ACNT_1001_1002"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: -1,
- MinItems: 0,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaTCD,
- },
- {
- MetricID: utils.MetaTCC,
- },
- },
- Stored: false,
- Blocker: true,
- Weight: 30,
- ThresholdIDs: []string{utils.MetaNone},
- }
- var reply *engine.StatQueueProfile
- if err := internalRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Stats2"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expStq, reply) && !reflect.DeepEqual(reply, expStq2) {
- t.Errorf("Expecting: %+v or %+v, received: %+v", utils.ToJSON(expStq),
- utils.ToJSON(expStq2), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetRoute(t *testing.T) {
- var reply *engine.RouteProfile
- routePrf := &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "ROUTE_ACNT_1001",
- FilterIDs: []string{"FLTR_ACNT_1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2017, 11, 27, 0, 0, 0, 0, time.UTC),
- },
- Sorting: utils.MetaWeight,
- Routes: []*engine.Route{
- {
- ID: "route1",
- Weight: 10,
- },
- {
- ID: "route2",
- Weight: 20,
- },
- },
- Weight: 20,
- }
- // routeProfile in reverse order
- routePrf2 := &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "ROUTE_ACNT_1001",
- FilterIDs: []string{"FLTR_ACNT_1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2017, 11, 27, 0, 0, 0, 0, time.UTC),
- },
- Sorting: utils.MetaWeight,
- Routes: []*engine.Route{{
- ID: "route2",
- Weight: 20,
- }, {
- ID: "route1",
- Weight: 10,
- }},
- Weight: 20,
- }
- if *encoding == utils.MetaGOB { // in gob emtpty slice is encoded as nil
- routePrf.SortingParameters = nil
- routePrf2.SortingParameters = nil
- }
-
- if err := internalRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_ACNT_1001"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(routePrf, reply) && !reflect.DeepEqual(routePrf2, reply) {
- t.Errorf("Expecting: %+v, \n received: %+v", utils.ToJSON(routePrf), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetFilter(t *testing.T) {
- expFltr := &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_ACNT_1001",
- Rules: []*engine.FilterRule{
- {
- Type: utils.MetaString,
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Values: []string{"1001"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- }
- var reply *engine.Filter
- if err := internalRPC.Call(utils.APIerSv1GetFilter,
- &utils.TenantID{Tenant: "cgrates.org", ID: "FLTR_ACNT_1001"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expFltr, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(expFltr), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetDestination(t *testing.T) {
- var dst *engine.Destination
- eDst := &engine.Destination{
- ID: "DST_1002",
- Prefixes: []string{"1002"},
- }
- if err := internalRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("DST_1002"), &dst); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eDst, dst) {
- t.Errorf("Expected: %v,\n received: %v", eDst, dst)
- }
-}
-
-func testInternalRemoteITGetReverseDestination(t *testing.T) {
- var ids []string
- eIDs := []string{"DST_1002"}
- if err := internalRPC.Call(utils.APIerSv1GetReverseDestination, utils.StringPointer("1002"), &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eIDs, ids) {
- t.Errorf("Expected: %v,\n received: %v", eIDs, ids)
- }
-}
-
-func testInternalRemoteITGetChargerProfile(t *testing.T) {
- chargerProfile := &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "DEFAULT",
- RunID: utils.MetaDefault,
- AttributeIDs: []string{utils.MetaNone},
- Weight: 0,
- }
- if *encoding == utils.MetaGOB {
- chargerProfile.FilterIDs = nil
- }
- var reply *engine.ChargerProfile
- if err := internalRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DEFAULT"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(chargerProfile), utils.ToJSON(reply))
- }
-}
-
-func testInternalRemoteITGetDispatcherProfile(t *testing.T) {
- var reply string
- if err := internalRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "Dsp1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Strategy: utils.MetaFirst,
- Weight: 20,
- },
- }
-
- if err := engineTwoRPC.Call(utils.APIerSv1SetDispatcherProfile,
- dispatcherProfile,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- var dsp *engine.DispatcherProfile
- if err := internalRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)
- }
-}
-
-func testInternalRemoteITGetDispatcherHost(t *testing.T) {
- var reply string
- if err := internalRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- dispatcherHost = &engine.DispatcherHostWithAPIOpts{
- DispatcherHost: &engine.DispatcherHost{
- Tenant: "cgrates.org",
- RemoteHost: &config.RemoteHost{
- ID: "DspHst1",
- Address: "*internal",
- },
- },
- }
-
- if err := engineTwoRPC.Call(utils.APIerSv1SetDispatcherHost,
- dispatcherHost,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- var dsp *engine.DispatcherHost
- if err := internalRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)
- }
-}
-
-func testInternalRemoteITGetRateProfile(t *testing.T) {
- var rcv *utils.RateProfile
- if err := internalRPC.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}},
- &rcv); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- rPrf := &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",
- },
- "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{
- Tenant: "cgrates.org",
- ID: "RP1",
- 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 *",
- },
- },
- },
- }
- var reply string
- if err := engineTwoRPC.Call(utils.APIerSv1SetRateProfile,
- apiRPrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
-
- var rPfrg *utils.RateProfile
- if err := internalRPC.Call(utils.APIerSv1GetRateProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RP1"}},
- &rPfrg); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rPrf, rPfrg) {
- t.Errorf("Expecting : %+v, received: %+v", rPrf, rPfrg)
- }
-}
-
-func testInternalReplicationSetThreshold(t *testing.T) {
- var reply *engine.ThresholdProfile
- var result string
- if err := internalRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //verify indexes on engine2 before adding new threshold profile
- var indexes []string
- expectedIDX := []string{"*string:*req.Account:1001:THD_ACNT_1001",
- "*string:*req.Account:1002:THD_ACNT_1002"}
- if err := engineTwoRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- sort.Strings(indexes)
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
- //verify indexes on internal before adding new threshold profile
- if err := internalRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- sort.Strings(indexes)
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-
- tPrfl := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Replication",
- FilterIDs: []string{"*string:~*req.Account:1001", "*string:~*req.CustomField:CustomValue"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_LOG_WARNING"},
- Async: true,
- },
- }
- if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- time.Sleep(50 * time.Millisecond)
- if err := internalRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- expectedIDX = []string{
- "*string:*req.Account:1001:THD_ACNT_1001",
- "*string:*req.Account:1001:THD_Replication",
- "*string:*req.Account:1002:THD_ACNT_1002",
- "*string:*req.CustomField:CustomValue:THD_Replication",
- }
- // verify index on internal
- sort.Strings(expectedIDX)
- if err := internalRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- sort.Strings(indexes)
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
- // verify data on engine1
- if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- expectedIDX2 := []string{
- "*string:*req.Account:1001:THD_ACNT_1001",
- "*string:*req.Account:1001:THD_Replication",
- "*string:*req.CustomField:CustomValue:THD_Replication",
- }
- // verify indexes on engine1 (should be the same as internal)
- if err := engineOneRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- sort.Strings(indexes)
- if !reflect.DeepEqual(expectedIDX2, indexes) {
- t.Errorf("Expecting: %+v, received: %+v",
- expectedIDX2, utils.ToJSON(indexes))
- }
- // verify data on engine2
- if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- expectedIDX = []string{"*string:*req.Account:1001:THD_ACNT_1001",
- "*string:*req.Account:1001:THD_Replication",
- "*string:*req.Account:1002:THD_ACNT_1002",
- "*string:*req.CustomField:CustomValue:THD_Replication",
- }
- // check if indexes was created correctly on engine2
- if err := engineTwoRPC.Call(utils.APIerSv1GetFilterIndexes, &AttrGetFilterIndexes{
- ItemType: utils.MetaThresholds, Tenant: "cgrates.org", FilterType: utils.MetaString},
- &indexes); err != nil {
- t.Error(err)
- }
- sort.Strings(indexes)
- if !reflect.DeepEqual(expectedIDX, indexes) {
- t.Errorf("Expecting: %+v,\n received: %+v",
- expectedIDX, utils.ToJSON(indexes))
- }
-
-}
-
-func testInternalMatchThreshold(t *testing.T) {
- ev := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- },
- },
- }
- var ids []string
- eIDs := []string{"THD_ACNT_1002"}
- if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- ev = &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- },
- },
- }
- eIDs = []string{"THD_ACNT_1001"}
- if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- ev2 := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- },
- },
- }
- if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev2, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
-}
-
-func testInternalReplicateStats(t *testing.T) {
- var reply string
-
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "StatsToReplicate",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaACD,
- },
- {
- MetricID: utils.MetaTCD,
- },
- },
- ThresholdIDs: []string{"*none"},
- Weight: 20,
- MinItems: 1,
- },
- }
-
- if err := internalRPC.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var rcv *engine.StatQueueProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "StatsToReplicate"}, &rcv); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, rcv) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(rcv))
- }
-
- if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "StatsToReplicate"}, &rcv); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, rcv) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(rcv))
- }
-
-}
-
-func testInternalRemoteITKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/replicate_it_test.go b/apier/v1/replicate_it_test.go
deleted file mode 100644
index ee17c0ff5..000000000
--- a/apier/v1/replicate_it_test.go
+++ /dev/null
@@ -1,1174 +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 (
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- sTestsInternalReplicateIT = []func(t *testing.T){
- testInternalReplicateITInitCfg,
- testInternalReplicateITDataFlush,
- testInternalReplicateITStartEngine,
- testInternalReplicateITRPCConn,
- testInternalReplicateLoadDataInInternalEngine,
-
- testInternalReplicateITDestination,
- testInternalReplicateITAttributeProfile,
- testInternalReplicateITRouteProfile,
- testInternalReplicateITStatQueueProfile,
- testInternalReplicateITDispatcherProfile,
- testInternalReplicateITChargerProfile,
- testInternalReplicateITDispatcherHost,
- testInternalReplicateITFilter,
- testInternalReplicateITResourceProfile,
- testInternalReplicateITThresholdProfile,
- testInternalReplicateITThreshold,
- testInternalReplicateITRateProfile,
- testInternalReplicateITLoadIds,
-
- testInternalReplicateITKillEngine,
- }
-)
-
-func TestInternalReplicateIT(t *testing.T) {
- internalCfgDirPath = "internal"
- switch *dbType {
- case utils.MetaInternal:
- t.SkipNow()
- case utils.MetaMySQL:
- engineOneCfgDirPath = "engine1_redis"
- engineTwoCfgDirPath = "engine2_redis"
- case utils.MetaMongo:
- engineOneCfgDirPath = "engine1_mongo"
- engineTwoCfgDirPath = "engine2_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- if *encoding == utils.MetaGOB {
- internalCfgDirPath += "_gob"
- }
- for _, stest := range sTestsInternalReplicateIT {
- t.Run(*dbType, stest)
- }
-}
-
-func testInternalReplicateITInitCfg(t *testing.T) {
- var err error
- internalCfgPath = path.Join(*dataDir, "conf", "samples", "replication", internalCfgDirPath)
- internalCfg, err = config.NewCGRConfigFromPath(internalCfgPath)
- if err != nil {
- t.Error(err)
- }
-
- // prepare config for engine1
- engineOneCfgPath = path.Join(*dataDir, "conf", "samples", "replication", engineOneCfgDirPath)
- engineOneCfg, err = config.NewCGRConfigFromPath(engineOneCfgPath)
- if err != nil {
- t.Error(err)
- }
-
- // prepare config for engine2
- engineTwoCfgPath = path.Join(*dataDir, "conf", "samples", "replication", engineTwoCfgDirPath)
- engineTwoCfg, err = config.NewCGRConfigFromPath(engineTwoCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITDataFlush(t *testing.T) {
- if err := engine.InitDataDB(engineOneCfg); err != nil {
- t.Fatal(err)
- }
- if err := engine.InitDataDB(engineTwoCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testInternalReplicateITStartEngine(t *testing.T) {
- if _, err := engine.StartEngine(engineOneCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(engineTwoCfgPath, 500); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(internalCfgPath, 500); err != nil {
- t.Fatal(err)
- }
-}
-
-func testInternalReplicateITRPCConn(t *testing.T) {
- var err error
- engineOneRPC, err = newRPCClient(engineOneCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
- engineTwoRPC, err = newRPCClient(engineTwoCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
- internalRPC, err = newRPCClient(internalCfg.ListenCfg())
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testInternalReplicateLoadDataInInternalEngine(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}
- if err := internalRPC.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testInternalReplicateITDestination(t *testing.T) {
- //check
- rpl := &engine.Destination{}
- if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //set
- attrs := utils.AttrSetDestination{Id: "testDestination", Prefixes: []string{"004", "005"}}
- var reply string
- if err := internalRPC.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- eDst := &engine.Destination{
- ID: "testDestination",
- Prefixes: []string{"004", "005"},
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eDst, rpl) {
- t.Errorf("Expected: %v,\n received: %v", eDst, rpl)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eDst, rpl) {
- t.Errorf("Expected: %v,\n received: %v", eDst, rpl)
- }
-
- // remove
- attr := &AttrRemoveDestination{DestinationIDs: []string{"testDestination"}, Prefixes: []string{"004", "005"}}
- if err := internalRPC.Call(utils.APIerSv1RemoveDestination, &attr, &reply); err != nil {
- t.Error("Unexpected error", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Unexpected reply returned: %+v", reply)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDestination, utils.StringPointer("testDestination"), &rpl); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITAttributeProfile(t *testing.T) {
- //set
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ATTR_CDRE",
- Contexts: []string{"*cdre"},
- FilterIDs: []string{"*string:~*req.Subject:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile("ATTR_SUBJECT", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Category,
- Value: config.NewRSRParsersMustCompile("ATTR_CATEGORY", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- var reply *engine.AttributeProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
- reply = &engine.AttributeProfile{}
- //remove
- if err := internalRPC.Call(utils.APIerSv1RemoveAttributeProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //check again
- if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)
- }
-}
-
-func testInternalReplicateITRouteProfile(t *testing.T) {
- // check
- var reply *engine.RouteProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- rPrf := &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- Sorting: "Sort1",
- SortingParameters: []string{"Param1", "Param2"},
- Routes: []*engine.Route{
- {
- ID: "SPL1",
- RatingPlanIDs: []string{"RP1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParameter1",
- },
- },
- Weight: 10,
- },
- }
- // set
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetRouteProfile, rPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rPrf.RouteProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", rPrf.RouteProfile, reply)
- }
- // remove
- var resp string
- if err := internalRPC.Call(utils.APIerSv1RemoveRouteProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITStatQueueProfile(t *testing.T) {
- // check
- var reply *engine.StatQueueProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // set
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE1",
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2020, 4, 18, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2020, 4, 18, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: "*sum",
- },
- {
- MetricID: "*acd",
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //check
- if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", statConfig.StatQueueProfile, reply)
- }
- //remove
- if err := internalRPC.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITDispatcherProfile(t *testing.T) {
- // check
- var reply string
- if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // set
- dispatcherProfile = &DispatcherWithAPIOpts{
- DispatcherProfile: &engine.DispatcherProfile{
- Tenant: "cgrates.org",
- ID: "Dsp1",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- Strategy: utils.MetaFirst,
- Weight: 20,
- },
- }
- if err := internalRPC.Call(utils.APIerSv1SetDispatcherProfile, dispatcherProfile,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
- // check
- var dsp *engine.DispatcherProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherProfile.DispatcherProfile, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherProfile.DispatcherProfile, dsp)
- }
- // remove
- var result string
- if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, result)
- }
- // remove again
- if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}}, &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // check again
- if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"}, &dsp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITChargerProfile(t *testing.T) {
- // check
- var reply *engine.ChargerProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // set
- chargerProfile = &ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "ApierTest",
- FilterIDs: []string{"*string:~*req.Account:1001", "*string:~Account:1002"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"Attr1", "Attr2"},
- Weight: 20,
- },
- }
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply)
- }
- // remove
- if err := internalRPC.Call(utils.APIerSv1RemoveChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //check
- if err := engineOneRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ApierTest"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITDispatcherHost(t *testing.T) {
- // check
- var reply string
- if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- dispatcherHost = &engine.DispatcherHostWithAPIOpts{
- DispatcherHost: &engine.DispatcherHost{
- Tenant: "cgrates.org",
- RemoteHost: &config.RemoteHost{
- ID: "DspHst1",
- Address: "*internal",
- },
- },
- }
- //set
- if err := internalRPC.Call(utils.APIerSv1SetDispatcherHost,
- dispatcherHost,
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
- // check
- var dsp *engine.DispatcherHost
- if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(dispatcherHost.DispatcherHost, dsp) {
- t.Errorf("Expecting : %+v, received: %+v", dispatcherHost.DispatcherHost, dsp)
- }
- // remove
- if err := internalRPC.Call(utils.APIerSv1RemoveDispatcherHost,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting : %+v, received: %+v", utils.OK, reply)
- }
- //check
- if err := engineOneRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetDispatcherHost,
- &utils.TenantID{Tenant: "cgrates.org", ID: "DspHst1"},
- &dsp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITFilter(t *testing.T) {
- // check
- var reply *engine.Filter
- if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //set
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "Filter1",
- Rules: []*engine.FilterRule{
- {
- Element: "~*req.Account",
- Type: utils.MetaString,
- Values: []string{"1001", "1002"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var rcv string
- if err := internalRPC.Call(utils.APIerSv1SetFilter, filter, &rcv); err != nil {
- t.Error(err)
- } else if rcv != utils.OK {
- t.Error("Unexpected reply returned", rcv)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(filter.Filter, reply) {
- t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(filter.Filter, reply) {
- t.Errorf("Expecting : %+v, received: %+v", filter.Filter, reply)
- }
- // remove
- var resp string
- if err := internalRPC.Call(utils.APIerSv1RemoveFilter,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- // check again
- if err := engineOneRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetFilter, &utils.TenantID{Tenant: "cgrates.org", ID: "Filter1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITResourceProfile(t *testing.T) {
- // check
- var reply *engine.ResourceProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // set
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "RES_GR_TEST",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: time.Nanosecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{"Val1"},
- },
- }
-
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply))
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply))
- }
- // remove
- if err := internalRPC.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check again
- if err := engineOneRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITThresholdProfile(t *testing.T) {
- // check
- var reply *engine.ThresholdProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- // set
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: tenant,
- ID: "TestFilter",
- Rules: []*engine.FilterRule{{
- Element: "~*req.Account",
- Type: utils.MetaString,
- Values: []string{"1001"},
- }},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: tenant,
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"TestFilter"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: 1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1", "ACT_2"},
- Async: true,
- },
- }
- if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- // remove
- if err := internalRPC.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check again
- if err := engineOneRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testInternalReplicateITThreshold(t *testing.T) {
- // get threshold
- var td engine.Threshold
- if err := engineOneRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "THD_Test"},
- }, &td); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "THD_Test"},
- }, &td); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- tEvs := engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1005",
- utils.AllowNegative: true,
- utils.Disabled: false,
- utils.Units: 12.3},
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
-
- tPrfl := engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: tenant,
- ID: "THD_Test",
- FilterIDs: []string{},
- MaxHits: -1,
- Weight: 30,
- // ActionIDs: []string{"ACT_LOG"},
- },
- }
- // set Threshold
- var reply string
- if err := internalRPC.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- //get
- if err := internalRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "THD_Test"},
- }, &td); err != nil {
- t.Error(err)
- } else if td.Hits != 0 { //still not processed
- t.Errorf("Expecting threshold to be hit once received: %v", td.Hits)
- }
-
- // processEvent
- var ids []string
- //eIDs := []string{}
- if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, &tEvs, &ids); err != nil {
- t.Error(err)
- } else if len(ids) != 1 {
- t.Errorf("Expecting 1: ,received %+v", len(ids))
- } else if ids[0] != "THD_Test" {
- t.Errorf("Expecting: THD_Test, received %q", ids[0])
- }
- //get
- if err := internalRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "THD_Test"},
- }, &td); err != nil {
- t.Error(err)
- } else if td.Hits != 1 { //processed
- t.Errorf("Expecting threshold to be hit once received: %v", td.Hits)
- }
-
- // remove
- var result string
- if err := internalRPC.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantID{Tenant: tenant, ID: "THD_Test"}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- if err := engineOneRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "THD_Test"},
- }, &td); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := engineTwoRPC.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{
- Tenant: tenant,
- ID: "THD_Test"},
- }, &td); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
-}
-
-func testInternalReplicateITRateProfile(t *testing.T) {
- //set
- rPrf := &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",
- },
- "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.APIRateProfile{
- Tenant: "cgrates.org",
- ID: "RP1",
- 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 *",
- },
- },
- }
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetRateProfile, apiRPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check
- var reply *utils.RateProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", rPrf, reply)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(rPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", rPrf, reply)
- }
- //remove
- if err := internalRPC.Call(utils.APIerSv1RemoveRateProfile, &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{
- Tenant: rPrf.Tenant, ID: rPrf.ID}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //check again
- if err := engineOneRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)
- }
- if err := engineTwoRPC.Call(utils.APIerSv1GetRateProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: rPrf.Tenant, ID: rPrf.ID}}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting: %+v received: %+v", utils.ErrNotFound, err)
- }
-}
-
-func testInternalReplicateITLoadIds(t *testing.T) {
- // get LoadIDs
- var rcv1e1 map[string]int64
- if err := engineOneRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e1); err != nil {
- t.Error(err)
- }
- var rcv1e2 map[string]int64
- if err := engineTwoRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv1e2); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(rcv1e1, rcv1e2) {
- t.Errorf("Expecting same LoadIDs for both engines")
- }
- // set AttributeProfile
- alsPrf = &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "AttributeWithNonSubstitute",
- Contexts: []string{utils.MetaSessionS},
- FilterIDs: []string{"*string:~*req.Account:1008"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2020, 4, 18, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2020, 4, 18, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- FilterIDs: []string{"*string:~*req.Account:1008"},
- Path: utils.MetaReq + utils.NestingSep + utils.AccountField,
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Subject,
- Value: config.NewRSRParsersMustCompile(utils.MetaRemove, utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var result string
- if err := internalRPC.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- // check AttributeProfile
- var reply *engine.AttributeProfile
- if err := engineOneRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: alsPrf.Tenant, ID: alsPrf.ID}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
- // check again the LoadIDs
- var rcv2e1 map[string]int64
- if err := engineOneRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e1); err != nil {
- t.Error(err)
- }
- var rcv2e2 map[string]int64
- if err := engineTwoRPC.Call(utils.APIerSv1GetLoadIDs, utils.StringPointer(utils.EmptyString), &rcv2e2); err != nil {
- t.Error(err)
- }
-
- // needs to be different LoadIds after the APIerSv1SetAttributeProfile call
- if reflect.DeepEqual(rcv1e1, rcv2e1) {
- t.Errorf("Expecting same LoadIDs for both engines")
- }
- // needs to be same LoadIds in both engines
- if !reflect.DeepEqual(rcv2e1, rcv2e2) {
- t.Errorf("Expecting same LoadIDs for both engines")
- }
- // check if the data was corectly modified after the APIerSv1SetAttributeProfile call
- // only CacheAttributeProfiles should differ
- if rcv1e1[utils.CacheAttributeProfiles] == rcv2e1[utils.CacheAttributeProfiles] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheAttributeProfiles], rcv2e1[utils.CacheAttributeProfiles])
- } else if rcv1e1[utils.CacheChargerProfiles] != rcv2e1[utils.CacheChargerProfiles] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheChargerProfiles], rcv2e1[utils.CacheChargerProfiles])
- } else if rcv1e1[utils.CacheDestinations] != rcv2e1[utils.CacheDestinations] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheDestinations], rcv2e1[utils.CacheDestinations])
- } else if rcv1e1[utils.CacheFilters] != rcv2e1[utils.CacheFilters] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheFilters], rcv2e1[utils.CacheFilters])
- } else if rcv1e1[utils.CacheResourceProfiles] != rcv2e1[utils.CacheResourceProfiles] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheResourceProfiles], rcv2e1[utils.CacheResourceProfiles])
- } else if rcv1e1[utils.CacheResources] != rcv2e1[utils.CacheResources] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheResources], rcv2e1[utils.CacheResources])
- } else if rcv1e1[utils.CacheReverseDestinations] != rcv2e1[utils.CacheReverseDestinations] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheReverseDestinations], rcv2e1[utils.CacheReverseDestinations])
- } else if rcv1e1[utils.CacheStatQueueProfiles] != rcv2e1[utils.CacheStatQueueProfiles] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheStatQueueProfiles], rcv2e1[utils.CacheStatQueueProfiles])
- } else if rcv1e1[utils.CacheRouteProfiles] != rcv2e1[utils.CacheRouteProfiles] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheRouteProfiles], rcv2e1[utils.CacheRouteProfiles])
- } else if rcv1e1[utils.CacheThresholdProfiles] != rcv2e1[utils.CacheThresholdProfiles] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheThresholdProfiles], rcv2e1[utils.CacheThresholdProfiles])
- } else if rcv1e1[utils.CacheThresholds] != rcv2e1[utils.CacheThresholds] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheThresholds], rcv2e1[utils.CacheThresholds])
- } else if rcv1e1[utils.CacheTimings] != rcv2e1[utils.CacheTimings] {
- t.Errorf("Expecting: %+v, received: %+v", rcv1e1[utils.CacheTimings], rcv2e1[utils.CacheTimings])
- }
-}
-
-func testInternalReplicateITKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/replicator.go b/apier/v1/replicator.go
deleted file mode 100644
index 0dfa91883..000000000
--- a/apier/v1/replicator.go
+++ /dev/null
@@ -1,774 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// NewReplicatorSv1 constructs the ReplicatorSv1 object
-func NewReplicatorSv1(dm *engine.DataManager, v1 *APIerSv1) *ReplicatorSv1 {
- return &ReplicatorSv1{
- dm: dm,
- v1: v1,
- }
-}
-
-// ReplicatorSv1 exports the DataDB methods to RPC
-type ReplicatorSv1 struct {
- dm *engine.DataManager
- v1 *APIerSv1 // needed for CallCache only
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (rplSv1 *ReplicatorSv1) Call(ctx *context.Context, serviceMethod string, args, reply interface{}) error {
- return utils.APIerRPCCall(rplSv1, serviceMethod, args, reply)
-}
-
-// GetDestination is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetDestination(key *utils.StringWithAPIOpts, reply *engine.Destination) error {
- engine.UpdateReplicationFilters(utils.DestinationPrefix, key.Arg, utils.IfaceAsString(key.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetDestinationDrv(key.Arg, utils.NonTransactional)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetReverseDestination is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetReverseDestination(key *utils.StringWithAPIOpts, reply *[]string) error {
- rcv, err := rplSv1.dm.DataDB().GetReverseDestinationDrv(key.Arg, utils.NonTransactional)
- if err != nil {
- return err
- }
- for _, dstID := range rcv {
- engine.UpdateReplicationFilters(utils.DestinationPrefix, dstID, utils.IfaceAsString(key.APIOpts[utils.RemoteHostOpt]))
- }
- *reply = rcv
- return nil
-}
-
-// GetStatQueue is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) error {
- engine.UpdateReplicationFilters(utils.StatQueuePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetStatQueueDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetFilter is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetFilter(tntID *utils.TenantIDWithAPIOpts, reply *engine.Filter) error {
- engine.UpdateReplicationFilters(utils.FilterPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetFilterDrv(context.TODO(), tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetThreshold is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *engine.Threshold) error {
- engine.UpdateReplicationFilters(utils.ThresholdPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetThresholdDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetThresholdProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetThresholdProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ThresholdProfile) error {
- engine.UpdateReplicationFilters(utils.ThresholdProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetThresholdProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetStatQueueProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetStatQueueProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.StatQueueProfile) error {
- engine.UpdateReplicationFilters(utils.StatQueueProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetStatQueueProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetTiming is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetTiming(id *utils.StringWithAPIOpts, reply *utils.TPTiming) error {
- engine.UpdateReplicationFilters(utils.TimingsPrefix, id.Arg, utils.IfaceAsString(id.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetTimingDrv(id.Arg)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetResource is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetResource(tntID *utils.TenantIDWithAPIOpts, reply *engine.Resource) error {
- engine.UpdateReplicationFilters(utils.ResourcesPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetResourceDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetResourceProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetResourceProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ResourceProfile) error {
- engine.UpdateReplicationFilters(utils.ResourceProfilesPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetResourceProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetRouteProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetRouteProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.RouteProfile) error {
- engine.UpdateReplicationFilters(utils.RouteProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetRouteProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetAttributeProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetAttributeProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.AttributeProfile) error {
- engine.UpdateReplicationFilters(utils.AttributeProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetAttributeProfileDrv(context.TODO(), tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetChargerProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetChargerProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ChargerProfile) error {
- engine.UpdateReplicationFilters(utils.ChargerProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetChargerProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetDispatcherProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetDispatcherProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherProfile) error {
- engine.UpdateReplicationFilters(utils.DispatcherProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetDispatcherProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetDispatcherHost is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetDispatcherHost(tntID *utils.TenantIDWithAPIOpts, reply *engine.DispatcherHost) error {
- engine.UpdateReplicationFilters(utils.DispatcherHostPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetDispatcherHostDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetRateProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetRateProfile(tntID *utils.TenantIDWithAPIOpts, reply *utils.RateProfile) error {
- engine.UpdateReplicationFilters(utils.RateProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetRateProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetActionProfile is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetActionProfile(tntID *utils.TenantIDWithAPIOpts, reply *engine.ActionProfile) error {
- engine.UpdateReplicationFilters(utils.ActionProfilePrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetActionProfileDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetAccount is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetAccount(tntID *utils.TenantIDWithAPIOpts, reply *utils.Account) error {
- engine.UpdateReplicationFilters(utils.AccountPrefix, tntID.TenantID.TenantID(), utils.IfaceAsString(tntID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetAccountDrv(tntID.Tenant, tntID.ID)
- if err != nil {
- return err
- }
- *reply = *rcv
- return nil
-}
-
-// GetItemLoadIDs is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetItemLoadIDs(itemID *utils.StringWithAPIOpts, reply *map[string]int64) error {
- engine.UpdateReplicationFilters(utils.LoadIDPrefix, itemID.Arg, utils.IfaceAsString(itemID.APIOpts[utils.RemoteHostOpt]))
- rcv, err := rplSv1.dm.DataDB().GetItemLoadIDsDrv(itemID.Arg)
- if err != nil {
- return err
- }
- *reply = rcv
- return nil
-}
-
-// GetIndexes is the remote method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error {
- engine.UpdateReplicationFilters(utils.CacheInstanceToPrefix[args.IdxItmType], args.TntCtx, utils.IfaceAsString(args.APIOpts[utils.RemoteHostOpt]))
- indx, err := rplSv1.dm.DataDB().GetIndexesDrv(context.TODO(), args.IdxItmType, args.TntCtx, args.IdxKey)
- if err != nil {
- return err
- }
- *reply = indx
- return nil
-}
-
-// SetDestination is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetDestination(dst *engine.DestinationWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetDestinationDrv(dst.Destination, utils.NonTransactional); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(dst.APIOpts[utils.CacheOpt]),
- dst.Tenant, utils.CacheDestinations, dst.ID, nil, nil, dst.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetReverseDestination is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetReverseDestination(dst *engine.DestinationWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetReverseDestinationDrv(dst.Destination.ID, dst.Destination.Prefixes, utils.NonTransactional); err != nil {
- return
- }
- if err = rplSv1.v1.callCacheMultiple(utils.IfaceAsString(dst.APIOpts[utils.CacheOpt]),
- dst.Tenant, utils.CacheReverseDestinations, dst.Prefixes, dst.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetThresholdProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetThresholdProfile(th *engine.ThresholdProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetThresholdProfileDrv(th.ThresholdProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(th.APIOpts[utils.CacheOpt]),
- th.Tenant, utils.CacheThresholdProfiles, th.TenantID(), &th.FilterIDs, nil, th.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetThreshold is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetThreshold(th *engine.ThresholdWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetThresholdDrv(th.Threshold); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(th.APIOpts[utils.CacheOpt]),
- th.Tenant, utils.CacheThresholds, th.TenantID(), nil, nil, th.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetStatQueueProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetStatQueueProfile(sq *engine.StatQueueProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetStatQueueProfileDrv(sq.StatQueueProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(sq.APIOpts[utils.CacheOpt]),
- sq.Tenant, utils.CacheStatQueueProfiles, sq.TenantID(), &sq.FilterIDs, nil, sq.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetStatQueue is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetStatQueue(sq *engine.StatQueueWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetStatQueueDrv(nil, sq.StatQueue); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(sq.APIOpts[utils.CacheOpt]),
- sq.Tenant, utils.CacheStatQueues, sq.TenantID(), nil, nil, sq.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetFilter is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetFilter(fltr *engine.FilterWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetFilterDrv(context.TODO(), fltr.Filter); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(fltr.APIOpts[utils.CacheOpt]),
- fltr.Tenant, utils.CacheFilters, fltr.TenantID(), nil, nil, fltr.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetTiming is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetTiming(tm *utils.TPTimingWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetTimingDrv(tm.TPTiming); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(tm.APIOpts[utils.CacheOpt]),
- tm.Tenant, utils.CacheTimings, tm.ID, nil, nil, tm.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetResourceProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetResourceProfile(rs *engine.ResourceProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetResourceProfileDrv(rs.ResourceProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(rs.APIOpts[utils.CacheOpt]),
- rs.Tenant, utils.CacheResourceProfiles, rs.TenantID(), &rs.FilterIDs, nil, rs.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetResource is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetResource(rs *engine.ResourceWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetResourceDrv(rs.Resource); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(rs.APIOpts[utils.CacheOpt]),
- rs.Tenant, utils.CacheResources, rs.TenantID(), nil, nil, rs.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetRouteProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetRouteProfile(sp *engine.RouteProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetRouteProfileDrv(sp.RouteProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(sp.APIOpts[utils.CacheOpt]),
- sp.Tenant, utils.CacheRouteProfiles, sp.TenantID(), &sp.FilterIDs, nil, sp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetAttributeProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetAttributeProfile(ap *engine.AttributeProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetAttributeProfileDrv(context.TODO(), ap.AttributeProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(ap.APIOpts[utils.CacheOpt]),
- ap.Tenant, utils.CacheAttributeProfiles, ap.TenantID(), &ap.FilterIDs, ap.Contexts, ap.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetChargerProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetChargerProfile(cp *engine.ChargerProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetChargerProfileDrv(cp.ChargerProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(cp.APIOpts[utils.CacheOpt]),
- cp.Tenant, utils.CacheChargerProfiles, cp.TenantID(), &cp.FilterIDs, nil, cp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetDispatcherProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetDispatcherProfile(dpp *engine.DispatcherProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetDispatcherProfileDrv(dpp.DispatcherProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(dpp.APIOpts[utils.CacheOpt]),
- dpp.Tenant, utils.CacheDispatcherProfiles, dpp.TenantID(), &dpp.FilterIDs, dpp.Subsystems, dpp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetDispatcherHost is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetDispatcherHost(dpp *engine.DispatcherHostWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetDispatcherHostDrv(dpp.DispatcherHost); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(dpp.APIOpts[utils.CacheOpt]),
- dpp.Tenant, utils.CacheDispatcherHosts, dpp.TenantID(), nil, nil, dpp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetRateProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetRateProfile(dpp *utils.RateProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetRateProfileDrv(dpp.RateProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(dpp.APIOpts[utils.CacheOpt]),
- dpp.Tenant, utils.CacheRateProfiles, dpp.TenantID(), &dpp.FilterIDs, nil, dpp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetActionProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetActionProfile(acp *engine.ActionProfileWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetActionProfileDrv(acp.ActionProfile); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(acp.APIOpts[utils.CacheOpt]),
- acp.Tenant, utils.CacheActionProfiles, acp.TenantID(), &acp.FilterIDs, nil, acp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetAccount is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetAccount(acp *utils.AccountWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetAccountDrv(acp.Account); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(acp.APIOpts[utils.CacheOpt]),
- acp.Tenant, utils.CacheAccounts, acp.TenantID(), &acp.FilterIDs, nil, acp.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetLoadIDs is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetLoadIDs(args *utils.LoadIDsWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetLoadIDsDrv(context.TODO(), args.LoadIDs); err != nil {
- return
- }
- lIDs := make([]string, 0, len(args.LoadIDs))
- for lID := range args.LoadIDs {
- lIDs = append(lIDs, lID)
- }
- if err = rplSv1.v1.callCacheMultiple(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheLoadIDs, lIDs, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// SetIndexes is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) SetIndexes(args *utils.SetIndexesArg, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().SetIndexesDrv(context.TODO(), args.IdxItmType, args.TntCtx, args.Indexes, true, utils.NonTransactional); err != nil {
- return
- }
- cIDs := make([]string, 0, len(args.Indexes))
- for idxKey := range args.Indexes {
- cIDs = append(cIDs, utils.ConcatenatedKey(args.TntCtx, idxKey))
- }
- if err = rplSv1.v1.callCacheMultiple(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, args.IdxItmType, cIDs, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveThreshold is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveThreshold(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveThresholdDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheThresholds, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveDestination is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveDestination(id *utils.StringWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveDestinationDrv(id.Arg, utils.NonTransactional); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
- id.Tenant, utils.CacheDestinations, id.Arg, nil, nil, id.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveStatQueue is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveStatQueue(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemStatQueueDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheStatQueues, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveFilter is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveFilter(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveFilterDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheFilters, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveThresholdProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemThresholdProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheThresholdProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveStatQueueProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemStatQueueProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheStatQueueProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveTiming is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveTiming(id *utils.StringWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveTimingDrv(id.Arg); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(id.APIOpts[utils.CacheOpt]),
- id.Tenant, utils.CacheTimings, id.Arg, nil, nil, id.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveResource is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveResource(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveResourceDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheResources, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveResourceProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveResourceProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveResourceProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheResourceProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveRouteProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveRouteProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheRouteProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveAttributeProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveAttributeProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveAttributeProfileDrv(context.TODO(), args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheAttributeProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveChargerProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveChargerProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveChargerProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheChargerProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveDispatcherProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveDispatcherProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveDispatcherProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheDispatcherProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveRateProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveRateProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveRateProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheRateProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveActionProfile is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveActionProfile(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveActionProfileDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheActionProfiles, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveAccount is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveAccount(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveAccountDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheAccounts, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveDispatcherHost is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveDispatcherHost(args *utils.TenantIDWithAPIOpts, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveDispatcherHostDrv(args.Tenant, args.ID); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, utils.CacheDispatcherHosts, args.TenantID.TenantID(), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// RemoveIndexes is the replication method coresponding to the dataDb driver method
-func (rplSv1 *ReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, reply *string) (err error) {
- if err = rplSv1.dm.DataDB().RemoveIndexesDrv(args.IdxItmType, args.TntCtx, args.IdxKey); err != nil {
- return
- }
- if err = rplSv1.v1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]),
- args.Tenant, args.IdxItmType, utils.ConcatenatedKey(args.TntCtx, args.IdxKey), nil, nil, args.APIOpts); err != nil {
- return
- }
- *reply = utils.OK
- return
-}
-
-// Ping used to determine if the RPC is active
-func (rplSv1 *ReplicatorSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go
deleted file mode 100644
index 93e6ae63e..000000000
--- a/apier/v1/resourcesv1.go
+++ /dev/null
@@ -1,195 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewResourceSv1(rls *engine.ResourceService) *ResourceSv1 {
- return &ResourceSv1{rls: rls}
-}
-
-// Exports RPC from RLs
-type ResourceSv1 struct {
- rls *engine.ResourceService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (rsv1 *ResourceSv1) Call(ctx *context.Context, serviceMethod string, args, reply interface{}) error {
- return utils.APIerRPCCall(rsv1, serviceMethod, args, reply)
-}
-
-// GetResourcesForEvent returns Resources matching a specific event
-func (rsv1 *ResourceSv1) GetResourcesForEvent(args *utils.ArgRSv1ResourceUsage, reply *engine.Resources) error {
- return rsv1.rls.V1ResourcesForEvent(*args, reply)
-}
-
-// AuthorizeResources checks if there are limits imposed for event
-func (rsv1 *ResourceSv1) AuthorizeResources(args *utils.ArgRSv1ResourceUsage, reply *string) error {
- return rsv1.rls.V1AuthorizeResources(*args, reply)
-}
-
-// V1InitiateResourceUsage records usage for an event
-func (rsv1 *ResourceSv1) AllocateResources(args *utils.ArgRSv1ResourceUsage, reply *string) error {
- return rsv1.rls.V1AllocateResource(*args, reply)
-}
-
-// V1TerminateResourceUsage releases usage for an event
-func (rsv1 *ResourceSv1) ReleaseResources(args *utils.ArgRSv1ResourceUsage, reply *string) error {
- return rsv1.rls.V1ReleaseResource(*args, reply)
-}
-
-// GetResource returns a resource configuration
-func (rsv1 *ResourceSv1) GetResource(args *utils.TenantIDWithAPIOpts, reply *engine.Resource) error {
- return rsv1.rls.V1GetResource(args, reply)
-}
-
-func (rsv1 *ResourceSv1) GetResourceWithConfig(args *utils.TenantIDWithAPIOpts, reply *engine.ResourceWithConfig) error {
- return rsv1.rls.V1GetResourceWithConfig(args, reply)
-}
-
-// GetResourceProfile returns a resource configuration
-func (apierSv1 *APIerSv1) GetResourceProfile(arg *utils.TenantID, reply *engine.ResourceProfile) error {
- if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := utils.EmptyString
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if rcfg, err := apierSv1.DataManager.GetResourceProfile(tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- } else {
- *reply = *rcfg
- }
- return nil
-}
-
-// GetResourceProfileIDs returns list of resourceProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetResourceProfileIDs(args *utils.PaginatorWithTenant, rsPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.ResourceProfilesPrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *rsPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-//SetResourceProfile adds a new resource configuration
-func (apierSv1 *APIerSv1) SetResourceProfile(arg *engine.ResourceProfileWithAPIOpts, reply *string) (err error) {
- if missing := utils.MissingStructFields(arg.ResourceProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if arg.Tenant == utils.EmptyString {
- arg.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err = apierSv1.DataManager.SetResourceProfile(arg.ResourceProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheResourceProfiles and CacheResources and store it in database
- //make 1 insert for both ResourceProfile and Resources instead of 2
- loadID := time.Now().UnixNano()
- if err = apierSv1.DataManager.SetLoadIDs(context.TODO(),
- map[string]int64{utils.CacheResourceProfiles: loadID,
- utils.CacheResources: loadID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for ResourceProfile
- if err = apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheResourceProfiles,
- arg.TenantID(), &arg.FilterIDs, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- var ttl *time.Duration
- if arg.UsageTTL > 0 {
- ttl = &arg.UsageTTL
- }
- // for non stored we do not save the metrics
- if err = apierSv1.DataManager.SetResource(&engine.Resource{
- Tenant: arg.Tenant,
- ID: arg.ID,
- Usages: make(map[string]*engine.ResourceUsage),
- }, ttl, arg.Limit, !arg.Stored); err != nil {
- return
- }
- //handle caching for Resource
- if err = apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheResources,
- arg.TenantID(), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
-
- *reply = utils.OK
- return nil
-}
-
-//RemoveResourceProfile remove a specific resource configuration
-func (apierSv1 *APIerSv1) RemoveResourceProfile(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.RemoveResourceProfile(tnt, arg.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for ResourceProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheResourceProfiles,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.DataManager.RemoveResource(tnt, arg.ID, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheResourceProfiles and CacheResources and store it in database
- //make 1 insert for both ResourceProfile and Resources instead of 2
- loadID := time.Now().UnixNano()
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheResourceProfiles: loadID, utils.CacheResources: loadID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for Resource
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), tnt, utils.CacheResources,
- utils.ConcatenatedKey(tnt, arg.ID), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-func (rsv1 *ResourceSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go
deleted file mode 100644
index 56a65531f..000000000
--- a/apier/v1/resourcesv1_it_test.go
+++ /dev/null
@@ -1,1103 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- rlsV1CfgPath string
- rlsV1Cfg *config.CGRConfig
- rlsV1Rpc *rpc.Client
- rlsV1ConfDIR string //run tests for specific configuration
- rlsConfig *engine.ResourceProfileWithAPIOpts
-
- sTestsRLSV1 = []func(t *testing.T){
- testV1RsLoadConfig,
- testV1RsInitDataDb,
- testV1RsResetStorDb,
- testV1RsStartEngine,
- testV1RsRpcConn,
- testV1RsFromFolder,
- testV1RsGetResourcesForEvent,
- testV1RsTTL0,
- testV1RsAllocateResource,
- testV1RsAuthorizeResources,
- testV1RsReleaseResource,
- testV1RsDBStore,
- testV1RsGetResourceProfileBeforeSet,
- testV1RsSetResourceProfile,
- testV1RsGetResourceProfileIDs,
- testV1RsGetResourceProfileAfterSet,
- testV1RsUpdateResourceProfile,
- testV1RsGetResourceProfileAfterUpdate,
- testV1RsRemResourceProfile,
- testV1RsGetResourceProfileAfterDelete,
- testV1RsResourcePing,
- testV1RsMatchNotFound,
- testV1RsAllocateUnlimited,
- testV1RsGetResourceProfileWithoutTenant,
- testV1RsRemResourceProfileWithoutTenant,
- testV1RsSetResourceProfileWithOpts,
- testV1RsAuthorizeResourcesWithOpts,
- testV1RsStopEngine,
- testV1RsStartEngine,
- testV1RsRpcConn,
- testV1RsCheckAuthorizeResourcesAfterRestart,
- testV1RsStopEngine,
- //cache test
- testV1RsLoadConfig,
- testV1RsInitDataDb,
- testV1RsResetStorDb,
- testV1RsStartEngine,
- testV1RsRpcConn,
- testResourceSCacheTestGetNotFound,
- testResourceSCacheTestSet,
- testResourceSCacheTestGetNotFound,
- testResourceSCacheReload,
- testResourceSCacheTestGetFound,
- testV1RsStopEngine,
- }
-)
-
-//Test start here
-func TestRsV1IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- rlsV1ConfDIR = "tutinternal"
- sTestsRLSV1 = sTestsRLSV1[:len(sTestsRLSV1)-4]
- case utils.MetaMySQL:
- rlsV1ConfDIR = "tutmysql"
- case utils.MetaMongo:
- rlsV1ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsRLSV1 {
- t.Run(rlsV1ConfDIR, stest)
- }
-}
-
-func testV1RsLoadConfig(t *testing.T) {
- var err error
- rlsV1CfgPath = path.Join(*dataDir, "conf", "samples", rlsV1ConfDIR)
- if rlsV1Cfg, err = config.NewCGRConfigFromPath(rlsV1CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RsInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(rlsV1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testV1RsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(rlsV1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(rlsV1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RsRpcConn(t *testing.T) {
- var err error
- rlsV1Rpc, err = newRPCClient(rlsV1Cfg.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 testV1RsFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
- if err := rlsV1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-
-}
-
-func testV1RsGetResourcesForEvent(t *testing.T) {
- var reply *engine.Resources
- args := &utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "Event1",
- Event: map[string]interface{}{"Unknown": "unknown"},
- },
- UsageID: "RandomUsageID",
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- args.CGREvent.Event = map[string]interface{}{"Destination": "10", "Account": "1001"}
- args.CGREvent.ID = utils.UUIDSha1Prefix()
- args.UsageID = "RandomUsageID2"
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil {
- t.Error(err)
- }
- if reply == nil {
- t.Errorf("Expecting reply to not be nil")
- // reply shoud not be nil so exit function
- // to avoid nil segmentation fault;
- // if this happens try to run this test manualy
- return
- }
- if len(*reply) != 1 {
- t.Fatalf("Expecting: %+v, received: %+v", 1, len(*reply))
- }
- if (*reply)[0].ID != "ResGroup2" {
- t.Errorf("Expecting: %+v, received: %+v", "ResGroup2", (*reply)[0].ID)
- }
-
- args.CGREvent.Event = map[string]interface{}{"Destination": "20"}
- args.CGREvent.ID = utils.UUIDSha1Prefix()
- args.UsageID = "RandomUsageID3"
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- args.CGREvent.Event = map[string]interface{}{"Account": "1002", "Subject": "test", "Destination": "1002"}
- args.CGREvent.ID = utils.UUIDSha1Prefix()
- args.UsageID = "RandomUsageID5"
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil {
- t.Error(err)
- }
- if len(*reply) != 1 {
- t.Errorf("Expecting: %+v, received: %+v", 2, len(*reply))
- }
-
- args.CGREvent.Event = map[string]interface{}{"Account": "1002", "Subject": "test", "Destination": "1001"}
- args.CGREvent.ID = utils.UUIDSha1Prefix()
- args.UsageID = "RandomUsageID5"
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil {
- t.Error(err)
- }
- if len(*reply) != 1 {
- t.Errorf("Expecting: %+v, received: %+v", 1, len(*reply))
- }
- if (*reply)[0].ID != "ResGroup2" {
- t.Errorf("Expecting: %+v, received: %+v", "ResGroup2", (*reply)[0].ID)
- }
-
- args.CGREvent.Tenant = utils.EmptyString
- args.CGREvent.ID = utils.UUIDSha1Prefix()
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &reply); err != nil {
- t.Error(err)
- }
- if len(*reply) != 1 {
- t.Errorf("Expecting: %+v, received: %+v", 1, len(*reply))
- }
- if (*reply)[0].ID != "ResGroup2" {
- t.Errorf("Expecting: %+v, received: %+v", "ResGroup2", (*reply)[0].ID)
- }
-}
-
-func testV1RsTTL0(t *testing.T) {
- // only matching Resource3
- argsRU := utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "3001",
- "Destination": "3002"},
- },
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e21",
- Units: 1,
- }
- var reply string
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- }
- // overwrite the first allocation
- argsRU = utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "3001",
- "Destination": "3002"},
- },
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e21",
- Units: 2,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, argsRU, &reply); err != nil {
- t.Error(err)
- }
- // too many units should be rejected
- argsRU = utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "3001",
- "Destination": "3002"},
- },
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e22",
- Units: 4,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, argsRU, &reply); err == nil ||
- err.Error() != utils.ErrResourceUnavailable.Error() {
- t.Error(err)
- }
- // check the record
- var rs *engine.Resources
- args := &utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "3001",
- "Destination": "3002"},
- },
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e21",
- }
- expiryTime, err := utils.ParseTimeDetectLayout("0001-01-01T00:00:00Z", "")
- if err != nil {
- t.Error(err)
- }
- expectedResources := &engine.Resource{
- Tenant: "cgrates.org",
- ID: "ResGroup3",
- Usages: map[string]*engine.ResourceUsage{
- "651a8db2-4f67-4cf8-b622-169e8a482e21": {
- Tenant: "cgrates.org",
- ID: "651a8db2-4f67-4cf8-b622-169e8a482e21",
- ExpiryTime: expiryTime,
- Units: 2,
- },
- },
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent,
- args, &rs); err != nil {
- t.Error(err)
- } else if len(*rs) != 1 {
- t.Errorf("Resources: %+v", rs)
- } else {
- res := *rs
- if !reflect.DeepEqual(expectedResources.Tenant, res[0].Tenant) {
- t.Errorf("Expecting: %+v, received: %+v", expectedResources.Tenant, res[0].Tenant)
- } else if !reflect.DeepEqual(expectedResources.ID, res[0].ID) {
- t.Errorf("Expecting: %+v, received: %+v", expectedResources.ID, res[0].ID)
- } else if !reflect.DeepEqual(expectedResources.Usages, res[0].Usages) {
- t.Errorf("Expecting: %+v, received: %+v", expectedResources.Usages, res[0].Usages)
- }
- }
- // release should not give out errors
- var releaseReply string
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e25", // same ID should be accepted by first group since the previous resource should be expired
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "3001",
- "Destination": "3002"},
- },
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources,
- argsRU, &releaseReply); err != nil {
- t.Error(err)
- }
-
- argsRU.Tenant = utils.EmptyString
- if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources,
- argsRU, &releaseReply); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RsAllocateResource(t *testing.T) {
- // first event matching Resource1
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e51",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 3,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- }
- eAllocationMsg := "ResGroup1"
- if reply != eAllocationMsg {
- t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply)
- }
- // Second event to test matching of exact limit of first resource
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e52",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 4,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- }
- eAllocationMsg = "ResGroup1"
- if reply != eAllocationMsg {
- t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply)
- }
- // Third event testing overflow to second resource which still has one resource available
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e53",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "dan",
- "Subject": "dan",
- "Destination": "1002"},
- },
- Units: 1,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- }
- eAllocationMsg = "SPECIAL_1002"
- if reply != eAllocationMsg {
- t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply)
- }
- // Test resource unavailable
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e54", // same ID should be accepted by first group since the previous resource should be expired
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 1,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err == nil || err.Error() != utils.ErrResourceUnavailable.Error() {
- t.Error(err)
- }
- eAllocationMsg = "ResGroup1"
- time.Sleep(time.Second) // Give time for allocations on first resource to expire
-
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 1,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- }
- eAllocationMsg = "ResGroup1"
- if reply != eAllocationMsg {
- t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply)
- }
-}
-
-func testV1RsAuthorizeResources(t *testing.T) {
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 6,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err != nil {
- t.Error(err)
- } else if reply != "ResGroup1" { // already 3 usages active before allow call, we should have now more than allowed
- t.Error("Unexpected reply returned", reply)
- }
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 7,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsRU, &reply); err.Error() != utils.ErrResourceUnauthorized.Error() {
- t.Error(err)
- }
-}
-
-func testV1RsReleaseResource(t *testing.T) {
- // release the only resource active for Resource1
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- }
- // try reserving with full units for Resource1, case which did not work in previous test
- // only match Resource1 since we don't want for storing of the resource2 bellow
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e61",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 7,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources, &argsRU, &reply); err != nil {
- t.Error(err)
- } else if reply != "ResGroup1" {
- t.Error("Unexpected reply returned", reply)
- }
- var rs *engine.Resources
- args := &utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "Event5",
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- UsageID: utils.UUIDSha1Prefix(),
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil {
- t.Error(err)
- } else if len(*rs) != 2 {
- t.Errorf("Resources: %+v", rs)
- }
- if rs == nil {
- t.Fatal("Expecting rs to not be nil")
- }
- // make sure Resource1 have no more active resources
- for _, r := range *rs {
- if r.ID == "ResGroup1" &&
- (len(r.Usages) != 0 || len(r.TTLIdx) != 0) {
- t.Errorf("Unexpected resource: %+v", r)
- }
- }
- // release an empty resource should return error
- argsRU = utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e55", // same ID should be accepted by first group since the previous resource should be expired
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources,
- argsRU, &reply); err == nil || err.Error() != "cannot find usage record with id: 651a8db2-4f67-4cf8-b622-169e8a482e55" {
- t.Error(err)
- }
-}
-
-func testV1RsDBStore(t *testing.T) {
- if rlsV1ConfDIR == "tutinternal" {
- t.SkipNow()
- }
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e71",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- Units: 1,
- }
- var reply string
- eAllocationMsg := "ResGroup1"
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources, argsRU, &reply); err != nil {
- t.Error(err)
- } else if reply != eAllocationMsg {
- t.Errorf("Expecting: %+v, received: %+v", eAllocationMsg, reply)
- }
- var rs *engine.Resources
- args := &utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "Event3",
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e71",
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil {
- t.Error(err)
- } else if len(*rs) != 2 {
- t.Errorf("Resources: %+v", rs)
- }
- if rs == nil {
- t.Fatal("Expecting rs to not be nil")
- }
- // count resources before restart
- for _, r := range *rs {
- switch r.ID {
- case "ResGroup1":
- if len(r.Usages) != 1 || len(r.TTLIdx) != 1 {
- t.Errorf("Unexpected resource: %+v", r)
- }
- case "ResGroup2":
- if len(r.Usages) != 4 || len(r.TTLIdx) != 4 {
- t.Errorf("Unexpected resource: %+v", r)
- }
- }
- }
- if _, err := engine.StopStartEngine(rlsV1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
- var err error
- rlsV1Rpc, err = newRPCClient(rlsV1Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
- rs = new(engine.Resources)
- args = &utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "Event4",
- Event: map[string]interface{}{
- "Account": "1002",
- "Subject": "1001",
- "Destination": "1002"},
- },
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e71",
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResourcesForEvent, args, &rs); err != nil {
- t.Error(err)
- } else if len(*rs) != 2 {
- t.Errorf("Resources: %+v", rs)
- }
- // count resources after restart
- for _, r := range *rs {
- switch r.ID {
- case "ResGroup1":
- if len(r.Usages) != 0 || len(r.TTLIdx) != 0 {
- t.Errorf("Unexpected resource: %+v", r)
- }
- case "ResGroup2":
- if len(r.Usages) != 4 || len(r.TTLIdx) != 4 {
- t.Errorf("Unexpected resource: %s", utils.ToJSON(r))
- }
- }
- }
-}
-
-func testV1RsGetResourceProfileBeforeSet(t *testing.T) {
- var reply *string
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RsSetResourceProfile(t *testing.T) {
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "RES_GR_TEST",
- FilterIDs: []string{"*wrong:inline"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: time.Nanosecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{"Val1"},
- },
- }
-
- var result string
- expErr := "SERVER_ERROR: broken reference to filter: *wrong:inline for item with ID: cgrates.org:RES_GR_TEST"
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
-
- rlsConfig.FilterIDs = []string{"*string:~*req.Account:1001"}
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testV1RsGetResourceProfileIDs(t *testing.T) {
- expected := []string{"ResGroup2", "ResGroup1", "ResGroup3", "RES_GR_TEST"}
- sort.Strings(expected)
- var result []string
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfileIDs, utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- }
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfileIDs, utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- }
- sort.Strings(result)
- if !reflect.DeepEqual(expected, result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testV1RsGetResourceProfileAfterSet(t *testing.T) {
- var reply *engine.ResourceProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply))
- }
-}
-
-func testV1RsUpdateResourceProfile(t *testing.T) {
- var result string
- rlsConfig.FilterIDs = []string{"*string:~*req.Account:1001", "*prefix:~*req.DST:10"}
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testV1RsGetResourceProfileAfterUpdate(t *testing.T) {
- var reply *engine.ResourceProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &reply); err != nil {
- t.Error(err)
- } else {
- sort.Strings(reply.FilterIDs)
- sort.Strings(rlsConfig.ResourceProfile.FilterIDs)
- if !reflect.DeepEqual(reply, rlsConfig.ResourceProfile) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(reply))
- }
- }
-}
-
-func testV1RsRemResourceProfile(t *testing.T) {
- var resp string
- if err := rlsV1Rpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- if err := rlsV1Rpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: rlsConfig.ID}, &resp); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testV1RsGetResourceProfileAfterDelete(t *testing.T) {
- var reply *string
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RES_GR_TEST"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RsResourcePing(t *testing.T) {
- var resp string
- if err := rlsV1Rpc.Call(utils.ResourceSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testV1RsMatchNotFound(t *testing.T) {
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "Res_NotFound",
- FilterIDs: []string{"*string:~*req.Account:CustomTest", "*notempty:~*req.Custom:"},
- UsageTTL: time.Nanosecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
-
- var result string
-
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- argsRU := utils.ArgRSv1ResourceUsage{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "Account": "CustomTest",
- "Custom": ""},
- },
- UsageID: "test",
- Units: 1,
- }
- var reply string
- if err := rlsV1Rpc.Call(utils.ResourceSv1ReleaseResources,
- argsRU, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RsAllocateUnlimited(t *testing.T) {
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "RES_ULTIMITED",
- FilterIDs: []string{"*string:~*req.CustomField:UnlimitedEvent"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: -1,
- Limit: -1,
- AllocationMessage: "CustomUnlimitedMessage",
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{utils.MetaNone},
- },
- }
-
- var result string
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e51",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: utils.UUIDSha1Prefix(),
- Event: map[string]interface{}{
- "CustomField": "UnlimitedEvent"},
- },
- Units: 1,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- argsRU, &reply); err != nil {
- t.Error(err)
- } else if reply != "CustomUnlimitedMessage" {
- t.Errorf("Expecting: %+v, received: %+v", "CustomUnlimitedMessage", reply)
- }
-
- var rplyRes *engine.Resource
- expRes := &engine.Resource{
- Tenant: "cgrates.org",
- ID: "RES_ULTIMITED",
- Usages: map[string]*engine.ResourceUsage{
- "651a8db2-4f67-4cf8-b622-169e8a482e51": {
- Tenant: "cgrates.org",
- ID: "651a8db2-4f67-4cf8-b622-169e8a482e51",
- Units: 1,
- },
- },
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ULTIMITED"},
- }, &rplyRes); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expRes, rplyRes) {
- t.Errorf("Expecting: %+v, received: %+v", expRes, rplyRes)
- }
-
-}
-
-func testV1RsStopEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RsGetResourceProfileWithoutTenant(t *testing.T) {
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- ID: "RES_ULTIMITED2",
- FilterIDs: []string{"*string:~*req.CustomField:UnlimitedEvent"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- UsageTTL: time.Nanosecond,
- Limit: 10,
- AllocationMessage: "MessageAllocation",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{"Val1"},
- },
- }
- var reply string
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- rlsConfig.Tenant = "cgrates.org"
- var result *engine.ResourceProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{ID: rlsConfig.ID},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rlsConfig.ResourceProfile, result) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rlsConfig.ResourceProfile), utils.ToJSON(result))
- }
-}
-
-func testV1RsRemResourceProfileWithoutTenant(t *testing.T) {
- var reply string
- if err := rlsV1Rpc.Call(utils.APIerSv1RemoveResourceProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: rlsConfig.ID}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.ResourceProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{ID: rlsConfig.ID},
- &result); err == nil || utils.ErrNotFound.Error() != err.Error() {
- t.Error(err)
- }
-}
-
-func testV1RsSetResourceProfileWithOpts(t *testing.T) {
- rlsCfg := &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "TEST_WITH_OPTS",
- FilterIDs: []string{"*string:~*opts.CustomField:1007"},
- UsageTTL: time.Duration(1) * time.Nanosecond,
- Limit: 10,
- Blocker: true,
- Weight: 20,
- },
- }
- var reply string
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsCfg, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- var result *engine.ResourceProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_WITH_OPTS"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(rlsCfg.ResourceProfile, result) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(rlsCfg.ResourceProfile), utils.ToJSON(result))
- }
-}
-
-func testV1RsAuthorizeResourcesWithOpts(t *testing.T) {
- var reply string
- argsRU := utils.ArgRSv1ResourceUsage{
- UsageID: "651a8db2-4f67-4cf8-b622-169e8a482e45",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TEST_WITH_OPTS",
- Event: map[string]interface{}{
- "Subject": "1001",
- "Destination": "1002",
- },
- APIOpts: map[string]interface{}{
- "CustomField": "1007",
- },
- },
- Units: 6,
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AuthorizeResources,
- &argsRU,
- &reply); err != nil {
- t.Error(err)
- } else if reply != "TEST_WITH_OPTS" {
- t.Error("Unexpected reply returned", reply)
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1AllocateResources,
- &argsRU,
- &reply); err != nil {
- t.Error(err)
- } else if reply != "TEST_WITH_OPTS" {
- t.Error("Unexpected reply returned", reply)
- }
-}
-
-func testV1RsCheckAuthorizeResourcesAfterRestart(t *testing.T) {
- var rplyRes *engine.Resource
- expRes := &engine.Resource{
- Tenant: "cgrates.org",
- ID: "RES_ULTIMITED",
- Usages: map[string]*engine.ResourceUsage{
- "651a8db2-4f67-4cf8-b622-169e8a482e51": {
- Tenant: "cgrates.org",
- ID: "651a8db2-4f67-4cf8-b622-169e8a482e51",
- Units: 1,
- },
- },
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "RES_ULTIMITED"},
- }, &rplyRes); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expRes, rplyRes) {
- t.Errorf("Expecting: %+v, received: %+v", expRes, rplyRes)
- }
-
- rplyRes = new(engine.Resource)
- expRes = &engine.Resource{
- Tenant: "cgrates.org",
- ID: "TEST_WITH_OPTS",
- Usages: map[string]*engine.ResourceUsage{},
- }
- if err := rlsV1Rpc.Call(utils.ResourceSv1GetResource, &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_WITH_OPTS"},
- }, &rplyRes); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expRes, rplyRes) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expRes), utils.ToJSON(rplyRes))
- }
-
-}
-
-func testResourceSCacheTestGetNotFound(t *testing.T) {
- var reply *engine.ChargerProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RESOURCE_CACHE"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-}
-
-func testResourceSCacheTestGetFound(t *testing.T) {
- var reply *engine.ChargerProfile
- if err := rlsV1Rpc.Call(utils.APIerSv1GetResourceProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "RESOURCE_CACHE"}, &reply); err != nil {
- t.Fatal(err)
- }
-}
-
-func testResourceSCacheTestSet(t *testing.T) {
- rlsConfig = &engine.ResourceProfileWithAPIOpts{
- ResourceProfile: &engine.ResourceProfile{
- Tenant: "cgrates.org",
- ID: "RESOURCE_CACHE",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- var result string
- if err := rlsV1Rpc.Call(utils.APIerSv1SetResourceProfile, rlsConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testResourceSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.ResourceProfileIDs: {"cgrates.org:RESOURCE_CACHE"},
- },
- }
- var reply string
- if err := rlsV1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/routes.go b/apier/v1/routes.go
deleted file mode 100644
index b929818b4..000000000
--- a/apier/v1/routes.go
+++ /dev/null
@@ -1,154 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetRouteProfile returns a Route configuration
-func (apierSv1 *APIerSv1) GetRouteProfile(arg *utils.TenantID, reply *engine.RouteProfile) 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 rp, err := apierSv1.DataManager.GetRouteProfile(tnt, arg.ID, true, true, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- } else {
- *reply = *rp
- }
- return nil
-}
-
-// GetRouteProfileIDs returns list of routeProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetRouteProfileIDs(args *utils.PaginatorWithTenant, sppPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.RouteProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *sppPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-type RouteWithAPIOpts struct {
- *engine.RouteProfile
- APIOpts map[string]interface{}
-}
-
-//SetRouteProfile add a new Route configuration
-func (apierSv1 *APIerSv1) SetRouteProfile(args *RouteWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args.RouteProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if args.Tenant == utils.EmptyString {
- args.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.SetRouteProfile(args.RouteProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheRouteProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheRouteProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for SupplierProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), args.Tenant, utils.CacheRouteProfiles,
- args.TenantID(), &args.FilterIDs, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-//RemoveRouteProfile remove a specific Route configuration
-func (apierSv1 *APIerSv1) RemoveRouteProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.RemoveRouteProfile(tnt, args.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheRouteProfiles and store it in database
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheRouteProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for SupplierProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), tnt, utils.CacheRouteProfiles,
- utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-func NewRouteSv1(rS *engine.RouteService) *RouteSv1 {
- return &RouteSv1{rS: rS}
-}
-
-// RouteSv1 exports RPC from RouteS
-type RouteSv1 struct {
- rS *engine.RouteService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (rS *RouteSv1) Call(ctx *context.Context, serviceMethod string, args, reply interface{}) error {
- return utils.APIerRPCCall(rS, serviceMethod, args, reply)
-}
-
-// GetRoutes returns sorted list of routes for Event
-func (rS *RouteSv1) GetRoutes(args *engine.ArgsGetRoutes, reply *engine.SortedRoutesList) error {
- return rS.rS.V1GetRoutes(args, reply)
-}
-
-// GetRouteProfilesForEvent returns a list of route profiles that match for Event
-func (rS *RouteSv1) GetRouteProfilesForEvent(args *utils.CGREvent, reply *[]*engine.RouteProfile) error {
- return rS.rS.V1GetRouteProfilesForEvent(args, reply)
-}
-
-func (rS *RouteSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// GetRoutesList returns sorted list of routes for Event as a string slice
-func (rS *RouteSv1) GetRoutesList(args *engine.ArgsGetRoutes, reply *[]string) error {
- return rS.rS.V1GetRoutesList(args, reply)
-}
diff --git a/apier/v1/routes_it_test.go b/apier/v1/routes_it_test.go
deleted file mode 100644
index 8115c410c..000000000
--- a/apier/v1/routes_it_test.go
+++ /dev/null
@@ -1,1708 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- routeSv1CfgPath string
- routeSv1Cfg *config.CGRConfig
- routeSv1Rpc *rpc.Client
- routePrf *RouteWithAPIOpts
- routeSv1ConfDIR string //run tests for specific configuration
-
- sTestsRouteSV1 = []func(t *testing.T){
- testV1RouteLoadConfig,
- testV1RouteInitDataDb,
- testV1RouteResetStorDb,
- testV1RouteStartEngine,
- testV1RouteRpcConn,
- testV1RouteGetBeforeDataLoad,
- testV1RouteFromFolder,
- testV1RouteGetWeightRoutes,
- testV1RouteGetLeastCostRoutes,
- testV1RouteGetLeastCostRoutesWithoutUsage,
- testV1RouteGetLeastCostRoutesWithMaxCost,
- testV1RouteGetLeastCostRoutesWithMaxCost2,
- testV1RouteGetLeastCostRoutesWithMaxCostNotFound,
- testV1RouteGetHighestCostRoutes,
- testV1RouteGetLeastCostRoutesErr,
- testV1RoutePolulateStatsForQOS,
- testV1RouteGetQOSRoutes,
- testV1RouteGetQOSRoutes2,
- testV1RouteGetQOSRoutes3,
- testV1RouteGetQOSRoutesFiltred,
- testV1RouteGetQOSRoutesFiltred2,
- testV1RouteGetRouteWithoutFilter,
- testV1RouteSetRouteProfiles,
- testV1RouteGetRouteProfileIDs,
- testV1RouteUpdateRouteProfiles,
- testV1RouteRemRouteProfiles,
- testV1RouteGetRouteForEvent,
- testV1RouteSetRouteProfilesWithoutTenant,
- testV1RouteRemRouteProfilesWithoutTenant,
- // reset the database and load the TP again
- testV1RouteInitDataDb,
- testV1RouteClearCache, // reset the cache so the indexes are created corectly
- testV1RouteFromFolder,
- testV1RoutesOneRouteWithoutDestination,
- testV1RouteRoutePing,
- testV1RouteMultipleRouteSameID,
- testV1RouteAccountWithRatingPlan,
- testV1RouteStopEngine,
- //cache test
- testV1RouteLoadConfig,
- testV1RouteInitDataDb,
- testV1RouteResetStorDb,
- testV1RouteStartEngine,
- testV1RouteRpcConn,
- testRouteSCacheTestGetNotFound,
- testRouteSCacheTestSet,
- testRouteSCacheTestGetNotFound,
- testRouteSCacheReload,
- testRouteSCacheTestGetFound,
- testV1RouteStopEngine,
- }
-)
-
-// Test start here
-func TestRouteSV1IT(t *testing.T) {
- sTestsRouteCacheSV1 := sTestsRouteSV1
- switch *dbType {
- case utils.MetaInternal:
- routeSv1ConfDIR = "tutinternal"
- sTestsRouteCacheSV1 = sTestsRouteCacheSV1[:len(sTestsRouteCacheSV1)-10]
- case utils.MetaMySQL:
- routeSv1ConfDIR = "tutmysql"
- case utils.MetaMongo:
- routeSv1ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsRouteCacheSV1 {
- t.Run(routeSv1ConfDIR, stest)
- }
-}
-
-func testV1RouteLoadConfig(t *testing.T) {
- var err error
- routeSv1CfgPath = path.Join(*dataDir, "conf", "samples", routeSv1ConfDIR)
- if routeSv1Cfg, err = config.NewCGRConfigFromPath(routeSv1CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RouteInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(routeSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RouteClearCache(t *testing.T) {
- var reply string
- if err := routeSv1Rpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{}, &reply); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testV1RouteResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(routeSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RouteStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(routeSv1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1RouteRpcConn(t *testing.T) {
- var err error
- routeSv1Rpc, err = newRPCClient(routeSv1Cfg.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 testV1RouteGetBeforeDataLoad(t *testing.T) {
- var suplsReply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ROUTE_WEIGHT_1",
- }, &suplsReply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RouteFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testit")}
- if err := routeSv1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testV1RouteGetWeightRoutes(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetWeightRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1007",
- utils.Destination: "+491511231234",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_WEIGHT_1",
- Sorting: utils.MetaWeight,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route2",
- SortingData: map[string]interface{}{
- utils.Weight: 20.0,
- },
- },
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-
- ev.CGREvent.Tenant = utils.EmptyString
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteGetLeastCostRoutes(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetLeastCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.Subject: "1003",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
- utils.Usage: "1m20s",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_LEASTCOST_1",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route3",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0136,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 15.0,
- },
- },
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0136,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 10.0,
- },
- },
- {
- RouteID: "route2",
- SortingData: map[string]interface{}{
- utils.Cost: 1.2667,
- utils.RatingPlanID: "RP_RETAIL1",
- utils.Weight: 20.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteGetLeastCostRoutesWithoutUsage(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetLeastCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.Subject: "1003",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_LEASTCOST_1",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route3",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0102,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 15.0,
- },
- },
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0102,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 10.0,
- },
- },
- {
- RouteID: "route2",
- SortingData: map[string]interface{}{
- utils.Cost: 1.2,
- utils.RatingPlanID: "RP_RETAIL1",
- utils.Weight: 20.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteGetLeastCostRoutesWithMaxCost(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- MaxCost: "0.30",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetLeastCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.Subject: "1001",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
- utils.Usage: "1m20s",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_LEASTCOST_1",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route3",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0136,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 15.0,
- },
- },
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0136,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteGetLeastCostRoutesWithMaxCostNotFound(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- MaxCost: "0.001",
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetLeastCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.Subject: "1001",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
- utils.Usage: "1m20s",
- },
- },
- }
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil && err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RouteGetLeastCostRoutesWithMaxCost2(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- MaxCost: utils.MetaEventCost,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetLeastCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.Subject: "SPECIAL_1002",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2014, 01, 14, 0, 0, 0, 0, time.UTC),
- utils.Usage: "10m20s",
- utils.Category: "call",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_LEASTCOST_1",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route3",
- SortingData: map[string]interface{}{
- utils.Cost: 0.1054,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 15.0,
- },
- },
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.1054,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteGetHighestCostRoutes(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetHighestCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
- utils.Usage: "1m20s",
- "DistinctMatch": "*highest_cost",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_HIGHESTCOST_1",
- Sorting: utils.MetaHC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route2",
- SortingData: map[string]interface{}{
- utils.Cost: 1.2667,
- utils.RatingPlanID: "RP_RETAIL1",
- utils.Weight: 20.0,
- },
- },
- {
- RouteID: "route3",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0136,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 15.0,
- },
- },
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0136,
- utils.RatingPlanID: "RP_SPECIAL_1002",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteGetLeastCostRoutesErr(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- IgnoreErrors: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetHighestCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1000",
- utils.Destination: "1001",
- utils.SetupTime: "*now",
- "Subject": "TEST",
- },
- },
- }
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testV1RoutePolulateStatsForQOS(t *testing.T) {
- var reply []string
- expected := []string{"Stat_1"}
- ev1 := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 11 * time.Second,
- utils.Cost: 10.0,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- expected = []string{"Stat_1"}
- ev1 = &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 11 * time.Second,
- utils.Cost: 10.5,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- expected = []string{"Stat_2"}
- ev1 = &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 5 * time.Second,
- utils.Cost: 12.5,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- expected = []string{"Stat_2"}
- ev1 = &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 6 * time.Second,
- utils.Cost: 17.5,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- expected = []string{"Stat_3"}
- ev1 = &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.AccountField: "1003",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 11 * time.Second,
- utils.Cost: 12.5,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- expected = []string{"Stat_1_1"}
- ev1 = &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- "Stat": "Stat1_1",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 11 * time.Second,
- utils.Cost: 12.5,
- utils.PDD: 12 * time.Second,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-
- expected = []string{"Stat_1_1"}
- ev1 = &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- "Stat": "Stat1_1",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 15 * time.Second,
- utils.Cost: 15.5,
- utils.PDD: 15 * time.Second,
- },
- },
- }
- if err := routeSv1Rpc.Call(utils.StatSv1ProcessEvent, ev1, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
-}
-
-func testV1RouteGetQOSRoutes(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetQOSRoutes",
- Event: map[string]interface{}{
- "DistinctMatch": "*qos",
- },
- },
- }
- expRouteIDs := []string{"route1", "route3", "route2"}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else {
- rcvSupl := make([]string, len(suplsReply[0].Routes))
- for i, supl := range suplsReply[0].Routes {
- rcvSupl[i] = supl.RouteID
- }
- if suplsReply[0].ProfileID != "ROUTE_QOS_1" {
- t.Errorf("Expecting: ROUTE_QOS_1, received: %s",
- suplsReply[0].ProfileID)
- }
- if !reflect.DeepEqual(rcvSupl, expRouteIDs) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- expRouteIDs, utils.ToJSON(rcvSupl))
- }
- }
-}
-
-func testV1RouteGetQOSRoutes2(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetQOSRoutes",
- Event: map[string]interface{}{
- "DistinctMatch": "*qos2",
- },
- },
- }
- expRouteIDs := []string{"route3", "route2", "route1"}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else {
- rcvSupl := make([]string, len(suplsReply[0].Routes))
- for i, supl := range suplsReply[0].Routes {
- rcvSupl[i] = supl.RouteID
- }
- if suplsReply[0].ProfileID != "ROUTE_QOS_2" {
- t.Errorf("Expecting: ROUTE_QOS_2, received: %s",
- suplsReply[0].ProfileID)
- }
- if !reflect.DeepEqual(rcvSupl, expRouteIDs) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- expRouteIDs, utils.ToJSON(rcvSupl))
- }
- }
-}
-
-func testV1RouteGetQOSRoutes3(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetQOSRoutes",
- Event: map[string]interface{}{
- "DistinctMatch": "*qos3",
- },
- },
- }
- expRouteIDs := []string{"route1", "route3", "route2"}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else {
- rcvSupl := make([]string, len(suplsReply[0].Routes))
- for i, supl := range suplsReply[0].Routes {
- rcvSupl[i] = supl.RouteID
- }
- if suplsReply[0].ProfileID != "ROUTE_QOS_3" {
- t.Errorf("Expecting: ROUTE_QOS_3, received: %s",
- suplsReply[0].ProfileID)
- }
- if !reflect.DeepEqual(rcvSupl, expRouteIDs) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- expRouteIDs, utils.ToJSON(rcvSupl))
- }
- }
-}
-
-func testV1RouteGetQOSRoutesFiltred(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetQOSRoutes",
- Event: map[string]interface{}{
- "DistinctMatch": "*qos_filtred",
- },
- },
- }
- expRouteIDs := []string{"route1", "route3"}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else {
- rcvSupl := make([]string, len(suplsReply[0].Routes))
- for i, supl := range suplsReply[0].Routes {
- rcvSupl[i] = supl.RouteID
- }
- if suplsReply[0].ProfileID != "ROUTE_QOS_FILTRED" {
- t.Errorf("Expecting: ROUTE_QOS_FILTRED, received: %s",
- suplsReply[0].ProfileID)
- }
- if !reflect.DeepEqual(rcvSupl, expRouteIDs) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- expRouteIDs, utils.ToJSON(suplsReply))
- }
- }
-}
-
-func testV1RouteGetQOSRoutesFiltred2(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetQOSRoutes",
- Event: map[string]interface{}{
- "DistinctMatch": "*qos_filtred2",
- utils.AccountField: "1003",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2017, 12, 1, 14, 25, 0, 0, time.UTC),
- utils.Usage: "1m20s",
- },
- },
- }
- expRouteIDs := []string{"route3", "route2"}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else {
- rcvSupl := make([]string, len(suplsReply[0].Routes))
- for i, supl := range suplsReply[0].Routes {
- rcvSupl[i] = supl.RouteID
- }
- if suplsReply[0].ProfileID != "ROUTE_QOS_FILTRED2" {
- t.Errorf("Expecting: ROUTE_QOS_FILTRED2, received: %s",
- suplsReply[0].ProfileID)
- }
- if !reflect.DeepEqual(rcvSupl, expRouteIDs) {
- t.Errorf("Expecting: %+v, \n received: %+v",
- expRouteIDs, utils.ToJSON(rcvSupl))
- }
- }
-}
-
-func testV1RouteGetRouteWithoutFilter(t *testing.T) {
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetRouteWithoutFilter",
- Event: map[string]interface{}{
- utils.AccountField: "1008",
- utils.Destination: "+49",
- },
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_WEIGHT_2",
- Sorting: utils.MetaWeight,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteSetRouteProfiles(t *testing.T) {
- routePrf = &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"FLTR_NotFound"},
- Sorting: "Sort1",
- SortingParameters: []string{"Param1", "Param2"},
- Routes: []*engine.Route{
- {
- ID: "ROUTE1",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParameter1",
- },
- },
- Weight: 10,
- },
- }
-
- var result string
- expErr := "SERVER_ERROR: broken reference to filter: FLTR_NotFound for item with ID: cgrates.org:TEST_PROFILE1"
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
-
- var reply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- routePrf.FilterIDs = []string{"FLTR_1"}
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(routePrf.RouteProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", routePrf.RouteProfile, reply)
- }
-}
-
-func testV1RouteGetRouteProfileIDs(t *testing.T) {
- expected := []string{"ROUTE_HIGHESTCOST_1", "ROUTE_QOS_1", "ROUTE_QOS_2", "ROUTE_QOS_FILTRED", "ROUTE_QOS_FILTRED2",
- "ROUTE_ACNT_1001", "ROUTE_LEASTCOST_1", "ROUTE_WEIGHT_2", "ROUTE_WEIGHT_1", "ROUTE_QOS_3",
- "TEST_PROFILE1", "ROUTE_LOAD_DIST", "ROUTE_LCR"}
- var result []string
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfileIDs,
- &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfileIDs,
- &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testV1RouteUpdateRouteProfiles(t *testing.T) {
- routePrf.Routes = []*engine.Route{
- {
- ID: "ROUTE1",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParameter1",
- },
- {
- ID: "ROUTE2",
- RatingPlanIDs: []string{"RP2"},
- FilterIDs: []string{"FLTR_2"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res2", "ResGroup2"},
- StatIDs: []string{"Stat2"},
- Weight: 20,
- Blocker: true,
- RouteParameters: "SortingParameter2",
- },
- }
- reverseRoutes := []*engine.Route{
- {
- ID: "ROUTE2",
- RatingPlanIDs: []string{"RP2"},
- FilterIDs: []string{"FLTR_2"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res2", "ResGroup2"},
- StatIDs: []string{"Stat2"},
- Weight: 20,
- Blocker: true,
- RouteParameters: "SortingParameter2",
- },
- {
- ID: "ROUTE1",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParameter1",
- },
- }
- var result string
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(routePrf.Routes, reply.Routes) && !reflect.DeepEqual(reverseRoutes, reply.Routes) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(routePrf), utils.ToJSON(reply))
- }
-}
-
-func testV1RouteRemRouteProfiles(t *testing.T) {
- var resp string
- if err := routeSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var reply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := routeSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}}, &resp); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testV1RouteRoutePing(t *testing.T) {
- var resp string
- if err := routeSv1Rpc.Call(utils.RouteSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testV1RouteGetRouteForEvent(t *testing.T) {
- ev := &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RouteGetHighestCostRoutes",
- Event: map[string]interface{}{
- utils.AccountField: "1000",
- utils.Destination: "1001",
- utils.SetupTime: "*now",
- utils.Subject: "TEST",
- },
- }
- expected := engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "ROUTE_LCR",
- FilterIDs: []string{"FLTR_TEST"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2017, 11, 27, 00, 00, 00, 00, time.UTC),
- },
- Sorting: utils.MetaLC,
- SortingParameters: []string{},
- Routes: []*engine.Route{
- {
- ID: "route_1",
- FilterIDs: nil,
- AccountIDs: nil,
- RatingPlanIDs: []string{"RP_TEST_1"},
- ResourceIDs: nil,
- StatIDs: nil,
- Weight: 10,
- Blocker: false,
- RouteParameters: "",
- },
- {
- ID: "route_2",
- FilterIDs: nil,
- AccountIDs: nil,
- RatingPlanIDs: []string{"RP_TEST_2"},
- ResourceIDs: nil,
- StatIDs: nil,
- Weight: 0,
- Blocker: false,
- RouteParameters: "",
- },
- },
- Weight: 50,
- }
- if *encoding == utils.MetaGOB { // in gob emtpty slice is encoded as nil
- expected.SortingParameters = nil
- }
- var supProf []*engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRouteProfilesForEvent,
- ev, &supProf); err != nil {
- t.Fatal(err)
- }
- sort.Slice(expected.Routes, func(i, j int) bool {
- return expected.Routes[i].Weight < expected.Routes[j].Weight
- })
- sort.Slice(supProf[0].Routes, func(i, j int) bool {
- return supProf[0].Routes[i].Weight < supProf[0].Routes[j].Weight
- })
- if !reflect.DeepEqual(expected, *supProf[0]) {
- t.Errorf("Expected: %s ,received: %s", utils.ToJSON(expected), utils.ToJSON(supProf))
- }
-
- supProf = nil
- ev.Tenant = utils.EmptyString
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRouteProfilesForEvent,
- ev, &supProf); err != nil {
- t.Fatal(err)
- }
- sort.Slice(expected.Routes, func(i, j int) bool {
- if expected.Routes[i].ID != expected.Routes[j].ID {
- return expected.Routes[i].ID < expected.Routes[j].ID
- }
- return expected.Routes[i].Weight < expected.Routes[j].Weight
- })
- sort.Slice(supProf[0].Routes, func(i, j int) bool {
- if supProf[0].Routes[i].ID != supProf[0].Routes[j].ID {
- return supProf[0].Routes[i].ID < supProf[0].Routes[j].ID
- }
- return supProf[0].Routes[i].Weight < supProf[0].Routes[j].Weight
- })
- if !reflect.DeepEqual(&expected, supProf[0]) {
- t.Errorf("Expected: %s \n,received: %s", utils.ToJSON(expected), utils.ToJSON(supProf[0]))
- }
-}
-
-// Scenario: We create two rating plans RP_MOBILE and RP_LOCAL
-// RP_LOCAL contains destination for both mobile and local
-// and RP_MOBILE contains destinations only for mobile
-// Create a RouteProfile with *least_cost strategy with 2 routes
-// route1 have attached RP_LOCAL and route2 have attach RP_MOBILE
-func testV1RoutesOneRouteWithoutDestination(t *testing.T) {
- var reply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "ROUTE_DESTINATION"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- routePrf = &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "ROUTE_DESTINATION",
- FilterIDs: []string{"*string:~*req.Account:SpecialCase"},
- Sorting: utils.MetaLC,
- Routes: []*engine.Route{
- {
- ID: "local",
- RatingPlanIDs: []string{"RP_LOCAL"},
- Weight: 10,
- },
- {
- ID: "mobile",
- RatingPlanIDs: []string{"RP_MOBILE"},
- FilterIDs: []string{"*destinations:~*req.Destination:DST_MOBILE"},
- Weight: 10,
- },
- },
- Weight: 100,
- },
- }
-
- var result string
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testV1RoutesOneRouteWithoutDestination",
- Event: map[string]interface{}{
- utils.AccountField: "SpecialCase",
- utils.Destination: "+24680",
- utils.SetupTime: utils.MetaNow,
- utils.Usage: "2m",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "ROUTE_DESTINATION",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "local",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0396,
- "RatingPlanID": "RP_LOCAL",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteMultipleRouteSameID(t *testing.T) {
- var reply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "MULTIPLE_ROUTES"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- routePrf = &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "MULTIPLE_ROUTES",
- FilterIDs: []string{"*string:~*req.Account:SpecialCase2"},
- Sorting: utils.MetaLC,
- Routes: []*engine.Route{
- {
- ID: "Route1",
- RatingPlanIDs: []string{"RP_LOCAL"},
- FilterIDs: []string{"*string:~*req.Month:April"},
- Weight: 10,
- },
- {
- ID: "Route1",
- RatingPlanIDs: []string{"RP_MOBILE"},
- FilterIDs: []string{"*string:~*req.Month:May"},
- Weight: 10,
- },
- },
- Weight: 100,
- },
- }
-
- var result string
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- tNow := time.Now()
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Time: &tNow,
- ID: "testV1RouteMultipleRouteSameID",
- Event: map[string]interface{}{
- utils.AccountField: "SpecialCase2",
- utils.Destination: "+135876",
- utils.SetupTime: utils.MetaNow,
- utils.Usage: "2m",
- "Month": "April",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := engine.SortedRoutesList{{
- ProfileID: "MULTIPLE_ROUTES",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "Route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0396,
- "RatingPlanID": "RP_LOCAL",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- var suplsReply engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-
- ev = &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Time: &tNow,
- ID: "testV1RouteMultipleRouteSameID",
- Event: map[string]interface{}{
- utils.AccountField: "SpecialCase2",
- utils.Destination: "+135876",
- utils.SetupTime: utils.MetaNow,
- utils.Usage: "2m",
- "Month": "May",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls = engine.SortedRoutesList{{
- ProfileID: "MULTIPLE_ROUTES",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "Route1",
- SortingData: map[string]interface{}{
- utils.Cost: 0.0204,
- "RatingPlanID": "RP_MOBILE",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s, received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-}
-
-func testV1RouteAccountWithRatingPlan(t *testing.T) {
- routePrf = &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "RouteWithAccAndRP",
- FilterIDs: []string{"*string:~*req.EventType:testV1RouteAccountWithRatingPlan"},
- Sorting: utils.MetaLC,
- Routes: []*engine.Route{
- {
- ID: "RouteWithAccAndRP",
- AccountIDs: []string{"AccWithVoice"},
- RatingPlanIDs: []string{"RP_ANY2CNT_SEC"},
- Weight: 20,
- },
- {
- ID: "RouteWithRP",
- RatingPlanIDs: []string{"RP_ANY1CNT_SEC"},
- Weight: 10,
- },
- },
- Weight: 100,
- },
- }
-
- var result string
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- // attrSetBalance := utils.AttrSetBalance{
- // Tenant: "cgrates.org",
- // Account: "AccWithVoice",
- // BalanceType: utils.MetaVoice,
- // Value: 30 * float64(time.Second),
- // Balance: map[string]interface{}{
- // utils.ID: "VoiceBalance",
- // },
- // }
- // var reply string
- // if err := routeSv1Rpc.Call(utils.APIerSv2SetBalance, &attrSetBalance, &reply); err != nil {
- // t.Error(err)
- // } else if reply != utils.OK {
- // t.Errorf("Received: %s", reply)
- // }
- // var acnt *engine.Account
- // attrAcc := &utils.AttrGetAccount{
- // Tenant: "cgrates.org",
- // Account: "AccWithVoice",
- // }
- // if err := routeSv1Rpc.Call(utils.APIerSv2GetAccount, attrAcc, &acnt); err != nil {
- // t.Error(err)
- // } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != 30*float64(time.Second) {
- // t.Errorf("Unexpected balance received : %+v", acnt.BalanceMap[utils.MetaVoice].GetTotalValue())
- // }
-
- // test for 30 seconds usage
- // we expect that the route with account to have cost 0
- tNow := time.Now()
- ev := &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Time: &tNow,
- ID: "testV1RouteAccountWithRatingPlan",
- Event: map[string]interface{}{
- utils.AccountField: "RandomAccount",
- utils.Destination: "+135876",
- utils.SetupTime: utils.MetaNow,
- utils.Usage: "30s",
- "EventType": "testV1RouteAccountWithRatingPlan",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls := &engine.SortedRoutesList{{
- ProfileID: "RouteWithAccAndRP",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "RouteWithAccAndRP",
- SortingData: map[string]interface{}{
- utils.AccountField: "AccWithVoice",
- utils.Cost: 0.0,
- "MaxUsage": 30000000000.0,
- utils.Weight: 20.0,
- },
- },
- {
- RouteID: "RouteWithRP",
- SortingData: map[string]interface{}{
- utils.Cost: 0.3,
- "RatingPlanID": "RP_ANY1CNT_SEC",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- if *encoding == utils.MetaGOB {
- (*eSpls)[0].Routes = []*engine.SortedRoute{
- {
- RouteID: "RouteWithAccAndRP",
- SortingData: map[string]interface{}{
- utils.AccountField: "AccWithVoice",
- utils.Cost: 0.,
- "MaxUsage": 30 * time.Second,
- utils.Weight: 20.,
- },
- },
- {
- RouteID: "RouteWithRP",
- SortingData: map[string]interface{}{
- utils.Cost: 0.3,
- "RatingPlanID": "RP_ANY1CNT_SEC",
- utils.Weight: 10.,
- },
- },
- }
- }
- var suplsReply *engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &suplsReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, suplsReply) {
- t.Errorf("Expecting: %s \n received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(suplsReply))
- }
-
- // test for 60 seconds usage
- // 30 seconds are covered by account and the remaining will be calculated
- ev = &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Time: &tNow,
- ID: "testV1RouteAccountWithRatingPlan",
- Event: map[string]interface{}{
- utils.AccountField: "RandomAccount",
- utils.Destination: "+135876",
- utils.SetupTime: utils.MetaNow,
- utils.Usage: "60s",
- "EventType": "testV1RouteAccountWithRatingPlan",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls = &engine.SortedRoutesList{{
- ProfileID: "RouteWithAccAndRP",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "RouteWithAccAndRP",
- SortingData: map[string]interface{}{
- utils.AccountField: "AccWithVoice",
- utils.Cost: 0.6,
- "MaxUsage": 30000000000.0,
- "RatingPlanID": "RP_ANY2CNT_SEC",
- utils.Weight: 20.0,
- },
- },
- {
- RouteID: "RouteWithRP",
- SortingData: map[string]interface{}{
- utils.Cost: 0.6,
- "RatingPlanID": "RP_ANY1CNT_SEC",
- utils.Weight: 10.0,
- },
- },
- },
- }}
- if *encoding == utils.MetaGOB {
- (*eSpls)[0].Routes = []*engine.SortedRoute{
- {
- RouteID: "RouteWithAccAndRP",
- SortingData: map[string]interface{}{
- utils.AccountField: "AccWithVoice",
- utils.Cost: 0.6,
- "MaxUsage": 30 * time.Second,
- "RatingPlanID": "RP_ANY2CNT_SEC",
- utils.Weight: 20.,
- },
- },
- {
- RouteID: "RouteWithRP",
- SortingData: map[string]interface{}{
- utils.Cost: 0.6,
- "RatingPlanID": "RP_ANY1CNT_SEC",
- utils.Weight: 10.,
- },
- },
- }
- }
- var routeRply *engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &routeRply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, routeRply) {
- t.Errorf("Expecting: %s \n received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(routeRply))
- }
-
- // test for 61 seconds usage
- // 30 seconds are covered by account and the remaining will be calculated
- ev = &engine.ArgsGetRoutes{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- Time: &tNow,
- ID: "testV1RouteAccountWithRatingPlan",
- Event: map[string]interface{}{
- utils.AccountField: "RandomAccount",
- utils.Destination: "+135876",
- utils.SetupTime: utils.MetaNow,
- utils.Usage: "1m1s",
- "EventType": "testV1RouteAccountWithRatingPlan",
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- eSpls = &engine.SortedRoutesList{{
- ProfileID: "RouteWithAccAndRP",
- Sorting: utils.MetaLC,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "RouteWithRP",
- SortingData: map[string]interface{}{
- utils.Cost: 0.61,
- "RatingPlanID": "RP_ANY1CNT_SEC",
- utils.Weight: 10.0,
- },
- },
- {
- RouteID: "RouteWithAccAndRP",
- SortingData: map[string]interface{}{
- utils.AccountField: "AccWithVoice",
- utils.Cost: 0.62,
- "MaxUsage": 30000000000.0,
- "RatingPlanID": "RP_ANY2CNT_SEC",
- utils.Weight: 20.0,
- },
- },
- },
- }}
- if *encoding == utils.MetaGOB {
- (*eSpls)[0].Routes = []*engine.SortedRoute{
- {
- RouteID: "RouteWithRP",
- SortingData: map[string]interface{}{
- utils.Cost: 0.61,
- "RatingPlanID": "RP_ANY1CNT_SEC",
- utils.Weight: 10.,
- },
- },
- {
- RouteID: "RouteWithAccAndRP",
- SortingData: map[string]interface{}{
- utils.AccountField: "AccWithVoice",
- utils.Cost: 0.62,
- "MaxUsage": 30 * time.Second,
- "RatingPlanID": "RP_ANY2CNT_SEC",
- utils.Weight: 20.,
- },
- },
- }
- }
- var routeRply2 *engine.SortedRoutesList
- if err := routeSv1Rpc.Call(utils.RouteSv1GetRoutes,
- ev, &routeRply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eSpls, routeRply2) {
- t.Errorf("Expecting: %s \n received: %s",
- utils.ToJSON(eSpls), utils.ToJSON(routeRply2))
- }
-
-}
-
-func testV1RouteStopEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testV1RouteSetRouteProfilesWithoutTenant(t *testing.T) {
- routePrf = &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE10",
- FilterIDs: []string{"FLTR_1"},
- Sorting: "Sort1",
- SortingParameters: []string{"Param1", "Param2"},
- Routes: []*engine.Route{
- {
- ID: "ROUTE1",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParameter1",
- },
- },
- Weight: 10,
- },
- }
- var reply string
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- routePrf.Tenant = "cgrates.org"
- var result *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{ID: "TEST_PROFILE10"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, routePrf.RouteProfile) {
- t.Errorf("Expected %+v, received %+v", utils.ToJSON(routePrf.RouteProfile), utils.ToJSON(result))
- }
-}
-
-func testV1RouteRemRouteProfilesWithoutTenant(t *testing.T) {
- var reply string
- if err := routeSv1Rpc.Call(utils.APIerSv1RemoveRouteProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "TEST_PROFILE10"}},
- &reply); err != nil {
- t.Error(err)
- }
- var result *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{ID: "TEST_PROFILE10"},
- &result); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testRouteSCacheTestGetNotFound(t *testing.T) {
- var suplsReply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ROUTE_CACHE",
- }, &suplsReply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testRouteSCacheTestGetFound(t *testing.T) {
- var suplsReply *engine.RouteProfile
- if err := routeSv1Rpc.Call(utils.APIerSv1GetRouteProfile,
- &utils.TenantID{
- Tenant: "cgrates.org",
- ID: "ROUTE_CACHE",
- }, &suplsReply); err != nil {
- t.Error(err)
- }
-}
-
-func testRouteSCacheTestSet(t *testing.T) {
- routePrf = &RouteWithAPIOpts{
- RouteProfile: &engine.RouteProfile{
- Tenant: "cgrates.org",
- ID: "ROUTE_CACHE",
- Routes: []*engine.Route{
- {
- ID: "ROUTE_CACHE",
- RatingPlanIDs: []string{"RP1"},
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc"},
- ResourceIDs: []string{"Res1", "ResGroup2"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParameter1",
- },
- },
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
-
- var result string
- if err := routeSv1Rpc.Call(utils.APIerSv1SetRouteProfile, routePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testRouteSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.RouteProfileIDs: {"cgrates.org:ROUTE_CACHE"},
- },
- }
- var reply string
- if err := routeSv1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/servicemanager.go b/apier/v1/servicemanager.go
deleted file mode 100644
index 2c37fc35c..000000000
--- a/apier/v1/servicemanager.go
+++ /dev/null
@@ -1,45 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/servmanager"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewServiceManagerV1(sm *servmanager.ServiceManager) *ServiceManagerV1 {
- return &ServiceManagerV1{sm: sm}
-}
-
-type ServiceManagerV1 struct {
- sm *servmanager.ServiceManager // Need to have them capitalize so we can export in V2
-}
-
-// Ping return pong if the service is active
-func (servManager *ServiceManagerV1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (servManager *ServiceManagerV1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(servManager, serviceMethod, args, reply)
-}
diff --git a/apier/v1/sessions.go b/apier/v1/sessions.go
deleted file mode 100644
index 153929266..000000000
--- a/apier/v1/sessions.go
+++ /dev/null
@@ -1,164 +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 (
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewSessionSv1(sS *sessions.SessionS, caps *engine.Caps) *SessionSv1 {
- return &SessionSv1{
- sS: sS,
- caps: caps,
- }
-}
-
-// SessionSv1 exports RPC from SessionSv1
-type SessionSv1 struct {
- sS *sessions.SessionS
- caps *engine.Caps
-}
-
-func (ssv1 *SessionSv1) AuthorizeEvent(args *sessions.V1AuthorizeArgs,
- rply *sessions.V1AuthorizeReply) error {
- return ssv1.sS.BiRPCv1AuthorizeEvent(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) AuthorizeEventWithDigest(args *sessions.V1AuthorizeArgs,
- rply *sessions.V1AuthorizeReplyWithDigest) error {
- return ssv1.sS.BiRPCv1AuthorizeEventWithDigest(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) InitiateSession(args *sessions.V1InitSessionArgs,
- rply *sessions.V1InitSessionReply) error {
- return ssv1.sS.BiRPCv1InitiateSession(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) InitiateSessionWithDigest(args *sessions.V1InitSessionArgs,
- rply *sessions.V1InitReplyWithDigest) error {
- return ssv1.sS.BiRPCv1InitiateSessionWithDigest(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) UpdateSession(args *sessions.V1UpdateSessionArgs,
- rply *sessions.V1UpdateSessionReply) error {
- return ssv1.sS.BiRPCv1UpdateSession(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) SyncSessions(args *utils.TenantWithAPIOpts,
- rply *string) error {
- return ssv1.sS.BiRPCv1SyncSessions(nil, &utils.TenantWithAPIOpts{}, rply)
-}
-
-func (ssv1 *SessionSv1) TerminateSession(args *sessions.V1TerminateSessionArgs,
- rply *string) error {
- return ssv1.sS.BiRPCv1TerminateSession(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) ProcessCDR(cgrEv *utils.CGREvent, rply *string) error {
- return ssv1.sS.BiRPCv1ProcessCDR(nil, cgrEv, rply)
-}
-
-func (ssv1 *SessionSv1) ProcessMessage(args *sessions.V1ProcessMessageArgs,
- rply *sessions.V1ProcessMessageReply) error {
- return ssv1.sS.BiRPCv1ProcessMessage(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) ProcessEvent(args *sessions.V1ProcessEventArgs,
- rply *sessions.V1ProcessEventReply) error {
- return ssv1.sS.BiRPCv1ProcessEvent(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) GetActiveSessions(args *utils.SessionFilter,
- rply *[]*sessions.ExternalSession) error {
- return ssv1.sS.BiRPCv1GetActiveSessions(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) GetActiveSessionsCount(args *utils.SessionFilter,
- rply *int) error {
- return ssv1.sS.BiRPCv1GetActiveSessionsCount(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) ForceDisconnect(args *utils.SessionFilter,
- rply *string) error {
- return ssv1.sS.BiRPCv1ForceDisconnect(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) GetPassiveSessions(args *utils.SessionFilter,
- rply *[]*sessions.ExternalSession) error {
- return ssv1.sS.BiRPCv1GetPassiveSessions(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) GetPassiveSessionsCount(args *utils.SessionFilter,
- rply *int) error {
- return ssv1.sS.BiRPCv1GetPassiveSessionsCount(nil, args, rply)
-}
-
-func (ssv1 *SessionSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
-
-func (ssv1 *SessionSv1) ReplicateSessions(args *dispatchers.ArgsReplicateSessionsWithAPIOpts, rply *string) error {
- return ssv1.sS.BiRPCv1ReplicateSessions(nil, args.ArgsReplicateSessions, rply)
-}
-
-func (ssv1 *SessionSv1) SetPassiveSession(args *sessions.Session,
- reply *string) error {
- return ssv1.sS.BiRPCv1SetPassiveSession(nil, args, reply)
-}
-
-// ActivateSessions is called to activate a list/all sessions
-func (ssv1 *SessionSv1) ActivateSessions(args *utils.SessionIDsWithAPIOpts, reply *string) error {
- return ssv1.sS.BiRPCv1ActivateSessions(nil, args, reply)
-}
-
-// DeactivateSessions is called to deactivate a list/all active sessios
-func (ssv1 *SessionSv1) DeactivateSessions(args *utils.SessionIDsWithAPIOpts, reply *string) error {
- return ssv1.sS.BiRPCv1DeactivateSessions(nil, args, reply)
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (ssv1 *SessionSv1) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(ssv1, serviceMethod, args, reply)
-}
-
-// ReAuthorize sends the RAR for filterd sessions
-func (ssv1 *SessionSv1) ReAuthorize(args *utils.SessionFilter, reply *string) error {
- return ssv1.sS.BiRPCv1ReAuthorize(nil, args, reply)
-}
-
-// DisconnectPeer sends the DPR for the OriginHost and OriginRealm
-func (ssv1 *SessionSv1) DisconnectPeer(args *utils.DPRArgs, reply *string) error {
- return ssv1.sS.BiRPCv1DisconnectPeer(nil, args, reply)
-}
-
-// STIRAuthenticate checks the identity using STIR/SHAKEN
-func (ssv1 *SessionSv1) STIRAuthenticate(args *sessions.V1STIRAuthenticateArgs, reply *string) error {
- return ssv1.sS.BiRPCv1STIRAuthenticate(nil, args, reply)
-}
-
-// STIRIdentity creates the identity for STIR/SHAKEN
-func (ssv1 *SessionSv1) STIRIdentity(args *sessions.V1STIRIdentityArgs, reply *string) error {
- return ssv1.sS.BiRPCv1STIRIdentity(nil, args, reply)
-}
diff --git a/apier/v1/sessions_process_event_it_test.go b/apier/v1/sessions_process_event_it_test.go
deleted file mode 100644
index 3dccc2df4..000000000
--- a/apier/v1/sessions_process_event_it_test.go
+++ /dev/null
@@ -1,895 +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 (
- "path"
- "reflect"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
-)
-
-//Use from sessionsv1_it_test.go
-//functions insted of duplicate them here
-// eg: initCfg,ResetDB,StopEngine,etc...
-var sTestSessionSv1ProcessEvent = []func(t *testing.T){
- testSSv1ItInitCfg,
- testSSv1ItResetDataDb,
- testSSv1ItResetStorDb,
- testSSv1ItStartEngine,
- testSSv1ItRpcConn,
- testSSv1ItPing,
- testSSv1ItTPFromFolder,
- testSSv1ItProcessEventAuth,
- testSSv1ItProcessEventInitiateSession,
- testSSv1ItProcessEventUpdateSession,
- testSSv1ItProcessEventTerminateSession,
- testSSv1ItProcessCDRForSessionFromProcessEvent,
- testSSv1ItGetCDRs,
- testSSv1ItProcessEventWithGetCost,
- testSSv1ItProcessEventWithGetCost2,
- testSSv1ItProcessEventWithGetCost3,
- testSSv1ItProcessEventWithGetCost4,
- testSSv1ItGetCost,
- testSSv1ItProcessEventWithCDR,
- testSSv1ItGetCDRsFromProcessEvent,
- testSSv1ItProcessEventWithCDRResourceError,
- testSSv1ItGetCDRsFromProcessEventResourceError,
- testSSv1ItProcessEventWithCDRResourceErrorBlockError,
- testSSv1ItGetCDRsFromProcessEventResourceErrorBlockError,
- testSSv1ItStopCgrEngine,
-}
-
-func TestSSv1ItProcessEventWithPrepaid(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- sessionsConfDIR = "sessions_internal"
- case utils.MetaMySQL:
- sessionsConfDIR = "sessions_mysql"
- case utils.MetaMongo:
- sessionsConfDIR = "sessions_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- sSV1RequestType = utils.MetaPrepaid
- for _, stest := range sTestSessionSv1ProcessEvent {
- t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
- }
-}
-
-func TestSSv1ItProcessEventWithPostPaid(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- sessionsConfDIR = "sessions_internal"
- case utils.MetaMySQL:
- sessionsConfDIR = "sessions_mysql"
- case utils.MetaMongo:
- sessionsConfDIR = "sessions_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- sSV1RequestType = utils.MetaPostpaid
- sTestSessionSv1ProcessEvent = append(sTestSessionSv1ProcessEvent[:len(sTestSessionSv1ProcessEvent)-7], testSSv1ItStopCgrEngine)
- for _, stest := range sTestSessionSv1ProcessEvent {
- t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
- }
-}
-
-func TestSSv1ItProcessEventWithRated(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- sessionsConfDIR = "sessions_internal"
- case utils.MetaMySQL:
- sessionsConfDIR = "sessions_mysql"
- case utils.MetaMongo:
- sessionsConfDIR = "sessions_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- sSV1RequestType = utils.MetaRated
- sTestSessionSv1ProcessEvent = append(sTestSessionSv1ProcessEvent[:len(sTestSessionSv1ProcessEvent)-7], testSSv1ItStopCgrEngine)
- for _, stest := range sTestSessionSv1ProcessEvent {
- t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
- }
-}
-
-func TestSSv1ItProcessEventWithPseudoPrepaid(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- sessionsConfDIR = "sessions_internal"
- case utils.MetaMySQL:
- sessionsConfDIR = "sessions_mysql"
- case utils.MetaMongo:
- sessionsConfDIR = "sessions_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- sSV1RequestType = utils.MetaPseudoPrepaid
- for _, stest := range sTestSessionSv1ProcessEvent {
- t.Run(sessionsConfDIR+utils.EmptyString+sSV1RequestType, stest)
- }
-}
-
-func testSSv1ItInitCfg(t *testing.T) {
- var err error
- sSv1CfgPath = path.Join(*dataDir, "conf", "samples", sessionsConfDIR)
- // Init config first
- sSv1Cfg, err = config.NewCGRConfigFromPath(sSv1CfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testSSv1ItProcessEventAuth(t *testing.T) {
- authUsage := 5 * time.Minute
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.ConcatenatedKey(utils.MetaResources, utils.MetaAuthorize),
- utils.ConcatenatedKey(utils.MetaResources, utils.MetaDerivedReply),
- utils.ConcatenatedKey(utils.MetaRALs, utils.MetaAuthorize),
- utils.ConcatenatedKey(utils.MetaRALs, utils.MetaDerivedReply),
- utils.MetaRoutes, utils.MetaAttributes, utils.MetaChargers},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventAuth",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.Usage: authUsage,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent, args, &rply); err != nil {
- t.Fatal(err)
- }
- expMaxUsage := map[string]time.Duration{
- "CustomerCharges": authUsage,
- "SupplierCharges": authUsage,
- "raw": authUsage,
- utils.MetaRaw: authUsage,
- }
- if !reflect.DeepEqual(expMaxUsage, rply.MaxUsage) {
- t.Errorf("Expected %s received %s", expMaxUsage, rply.MaxUsage)
- }
- if rply.ResourceAllocation == nil || rply.ResourceAllocation["CustomerCharges"] == utils.EmptyString {
- t.Errorf("Unexpected ResourceAllocation: %s", rply.ResourceAllocation)
- }
- eSplrs := engine.SortedRoutesList{{
- ProfileID: "ROUTE_ACNT_1001",
- Sorting: utils.MetaWeight,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- "Weight": 20.0,
- },
- },
- {
- RouteID: "route2",
- SortingData: map[string]interface{}{
- "Weight": 10.0,
- },
- },
- },
- }, {
- ProfileID: "ROUTE_WEIGHT_2",
- Sorting: utils.MetaWeight,
- Routes: []*engine.SortedRoute{{
- RouteID: "route1",
- SortingData: map[string]interface{}{
- "Weight": 10.0,
- },
- }},
- }}
- if !reflect.DeepEqual(eSplrs, rply.RouteProfiles[utils.MetaRaw]) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.RouteProfiles[utils.MetaRaw]))
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
-
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventAuth",
- Event: map[string]interface{}{
- utils.CGRID: "4be779c004d9f784e836db9ffd41b50319d71fe8",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes[utils.MetaRaw]) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes[utils.MetaRaw]))
- }
-}
-
-func testSSv1ItProcessEventInitiateSession(t *testing.T) {
- initUsage := 5 * time.Minute
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.ConcatenatedKey(utils.MetaRALs, utils.MetaInitiate),
- utils.ConcatenatedKey(utils.MetaRALs, utils.MetaDerivedReply),
- utils.ConcatenatedKey(utils.MetaResources, utils.MetaAllocate),
- utils.ConcatenatedKey(utils.MetaResources, utils.MetaDerivedReply),
- utils.MetaAttributes, utils.MetaChargers},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventInitiateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect the value of Usage field
- // if this was missing the MaxUsage should be equal to MaxCallDuration from config
- expMaxUsage := map[string]time.Duration{
- "CustomerCharges": initUsage,
- "SupplierCharges": initUsage,
- // "raw": initUsage,
- utils.MetaRaw: initUsage,
- }
- if !reflect.DeepEqual(expMaxUsage, rply.MaxUsage) {
- t.Errorf("Expected %s received %s", expMaxUsage, rply.MaxUsage)
- }
- if rply.ResourceAllocation == nil || rply.ResourceAllocation["CustomerCharges"] != "RES_ACNT_1001" {
- t.Errorf("Unexpected ResourceAllocation: %s", rply.ResourceAllocation)
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventInitiateSession",
- Event: map[string]interface{}{
- utils.CGRID: "4be779c004d9f784e836db9ffd41b50319d71fe8",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.AnswerTime: "2018-01-07T17:00:10Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes[utils.MetaRaw]) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes[utils.MetaRaw]))
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
- }
-}
-
-func testSSv1ItProcessEventUpdateSession(t *testing.T) {
- reqUsage := 5 * time.Minute
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.ConcatenatedKey(utils.MetaRALs, utils.MetaUpdate),
- utils.ConcatenatedKey(utils.MetaRALs, utils.MetaDerivedReply),
- utils.MetaAttributes},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventUpdateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: reqUsage,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventUpdateSession",
- Event: map[string]interface{}{
- utils.CGRID: "4be779c004d9f784e836db9ffd41b50319d71fe8",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.AnswerTime: "2018-01-07T17:00:10Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes[utils.MetaRaw]) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes[utils.MetaRaw]))
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect the value of Usage field
- // if this was missing the MaxUsage should be equal to MaxCallDuration from config
- expMaxUsage := map[string]time.Duration{
- "CustomerCharges": reqUsage,
- "SupplierCharges": reqUsage,
- // "raw": reqUsage,
- utils.MetaRaw: reqUsage,
- }
- if !reflect.DeepEqual(expMaxUsage, rply.MaxUsage) {
- t.Errorf("Expected %s received %s", expMaxUsage, rply.MaxUsage)
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions))
- }
-}
-
-func testSSv1ItProcessEventTerminateSession(t *testing.T) {
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.ConcatenatedKey(utils.MetaRALs, utils.MetaTerminate),
- utils.ConcatenatedKey(utils.MetaResources, utils.MetaRelease)},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventTerminateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testSSv1ItProcessCDRForSessionFromProcessEvent(t *testing.T) {
- args := utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessCDRForSessionFromProcessEvent",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEvent",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- }
- var rply string
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply != utils.OK {
- t.Errorf("Unexpected reply: %s", rply)
- }
-}
-
-func testSSv1ItGetCDRs(t *testing.T) {
- var cdrCnt int64
- req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 3 { // 3 for each CDR
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
-
- var cdrs []*engine.CDR
- args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"raw"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"},
- OriginIDs: []string{"testSSv1ItProcessEvent"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.198 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
- OriginIDs: []string{"testSSv1ItProcessEvent"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
-}
-
-func testSSv1ItProcessEventWithGetCost(t *testing.T) {
- // GetCost for ANY2CNT Subject
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithGetCost",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaMonetary,
- utils.OriginID: "testSSv1ItProcessEventWithGetCost",
- utils.RequestType: sSV1RequestType,
- utils.Subject: "*attributes",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.Attributes == nil {
- t.Error("Received nil Attributes")
- } else if !reflect.DeepEqual(rply.Attributes[utils.MetaRaw].MatchedProfiles, []string{"ATTR_SUBJECT_CASE1"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"ATTR_SUBJECT_CASE1"}, rply.Attributes[utils.MetaRaw].MatchedProfiles)
- } else if !reflect.DeepEqual(rply.Attributes[utils.MetaRaw].AlteredFields, []string{"*req.Subject"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"*req.Subject"}, rply.Attributes[utils.MetaRaw].AlteredFields)
- }
- if rply.Cost == nil {
- t.Errorf("Received nil Cost")
- } else if rply.Cost[utils.MetaRaw] != 0.198 { // same cost as in CDR
- t.Errorf("Expected: %+v,received: %+v", 0.198, rply.Cost[utils.MetaRaw])
- }
-}
-
-func testSSv1ItProcessEventWithGetCost2(t *testing.T) {
- // GetCost for SPECIAL_1002 Subject
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithGetCost2",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaMonetary,
- utils.OriginID: "testSSv1ItProcessEventWithGetCost2",
- utils.RequestType: sSV1RequestType,
- utils.Subject: "*attributes",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.Attributes == nil {
- t.Error("Received nil Attributes")
- } else if !reflect.DeepEqual(rply.Attributes[utils.MetaRaw].MatchedProfiles, []string{"ATTR_SUBJECT_CASE2"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"ATTR_SUBJECT_CASE2"}, rply.Attributes[utils.MetaRaw].MatchedProfiles)
- } else if !reflect.DeepEqual(rply.Attributes[utils.MetaRaw].AlteredFields, []string{"*req.Subject"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"*req.Subject"}, rply.Attributes[utils.MetaRaw].AlteredFields)
- }
- if rply.Cost == nil {
- t.Errorf("Received nil Cost")
- } else if rply.Cost[utils.MetaRaw] != 0.102 { // same cost as in CDR
- t.Errorf("Expected: %+v,received: %+v", 0.102, rply.Cost[utils.MetaRaw])
- }
-}
-
-func testSSv1ItProcessEventWithGetCost3(t *testing.T) {
- // GetCost for RP_RETAIL Subject
- // 0.8 connect fee + 0.4 for first minute
- // for the 9 minutes remaining apply
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithGetCost3",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaMonetary,
- utils.OriginID: "testSSv1ItProcessEventWithGetCost3",
- utils.RequestType: sSV1RequestType,
- utils.Subject: "*attributes",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.Attributes == nil {
- t.Error("Received nil Attributes")
- } else if !reflect.DeepEqual(rply.Attributes[utils.MetaRaw].MatchedProfiles, []string{"ATTR_SUBJECT_CASE3"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"ATTR_SUBJECT_CASE3"}, rply.Attributes[utils.MetaRaw].MatchedProfiles)
- } else if !reflect.DeepEqual(rply.Attributes[utils.MetaRaw].AlteredFields, []string{"*req.Subject"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"*req.Subject"}, rply.Attributes[utils.MetaRaw].AlteredFields)
- }
- if rply.Cost == nil {
- t.Errorf("Received nil Cost")
- } else if rply.Cost[utils.MetaRaw] != 2.9999 {
- t.Errorf("Expected: %+v,received: %+v", 2.9999, rply.Cost[utils.MetaRaw])
- }
-}
-
-func testSSv1ItProcessEventWithGetCost4(t *testing.T) {
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaAttributes, utils.ConcatenatedKey(utils.MetaRALs, utils.MetaCost)},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithGetCost4",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaMonetary,
- utils.OriginID: "testSSv1ItProcessEventWithGetCost4",
- utils.RequestType: sSV1RequestType,
- utils.Subject: "*attributes",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err == nil || err.Error() != utils.ErrRatingPlanNotFound.Error() {
- t.Error(err)
- }
-
-}
-
-func testSSv1ItGetCost(t *testing.T) {
- // GetCost for ANY2CNT Subject
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaAttributes},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItGetCost",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaMonetary,
- utils.OriginID: "testSSv1ItProcessEventWithGetCost",
- utils.RequestType: sSV1RequestType,
- utils.Subject: "*attributes",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1GetCostReply
- if err := sSv1BiRpc.Call(utils.SessionSv1GetCost,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.Attributes == nil {
- t.Error("Received nil Attributes")
- } else if !reflect.DeepEqual(rply.Attributes.MatchedProfiles, []string{"ATTR_SUBJECT_CASE1"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"ATTR_SUBJECT_CASE1"}, rply.Attributes.MatchedProfiles)
- } else if !reflect.DeepEqual(rply.Attributes.AlteredFields, []string{"*req.Subject"}) {
- t.Errorf("Expected: %+v,received: %+v", []string{"*req.Subject"}, rply.Attributes.AlteredFields)
- }
- if rply.EventCost == nil {
- t.Errorf("Received nil EventCost")
- } else if *rply.EventCost.Cost != 0.198 { // same cost as in CDR
- t.Errorf("Expected: %+v,received: %+v", 0.198, *rply.EventCost.Cost)
- } else if *rply.EventCost.Usage != 10*time.Minute {
- t.Errorf("Expected: %+v,received: %+v", 10*time.Minute, *rply.EventCost.Usage)
- }
-}
-
-func testSSv1ItProcessEventWithCDR(t *testing.T) {
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaCDRs + utils.InInFieldSep + utils.MetaRALs}, // *cdrs:*rals
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithCDR",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEventWithCDR",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
-}
-
-func testSSv1ItGetCDRsFromProcessEvent(t *testing.T) {
- var cdrCnt int64
- req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 3 { // 3 for each CDR
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
-
- var cdrs []*engine.CDR
- args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- OriginIDs: []string{"testSSv1ItProcessEventWithCDR"},
- RunIDs: []string{"raw"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- RunIDs: []string{"CustomerCharges"},
- OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.198 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- RunIDs: []string{"SupplierCharges"},
- OriginIDs: []string{"testSSv1ItProcessEventWithCDR"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
-}
-
-func testSSv1ItProcessEventWithCDRResourceError(t *testing.T) {
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaCDRs + utils.InInFieldSep + utils.MetaRALs,
- utils.ConcatenatedKey(utils.MetaResources, utils.MetaRelease)}, // force a resource error and expect that the cdr to be written
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithCDRResourceError",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEventWithCDRResourceError",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err == nil || err.Error() != utils.ErrPartiallyExecuted.Error() {
- t.Error(err)
- }
-}
-
-func testSSv1ItGetCDRsFromProcessEventResourceError(t *testing.T) {
- var cdrCnt int64
- req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 3 { // 3 for each CDR
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
-
- var cdrs []*engine.CDR
- args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"},
- RunIDs: []string{"raw"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- RunIDs: []string{"CustomerCharges"},
- OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.198 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- RunIDs: []string{"SupplierCharges"},
- OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceError"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
-}
-
-func testSSv1ItProcessEventWithCDRResourceErrorBlockError(t *testing.T) {
- args := &sessions.V1ProcessEventArgs{
- Flags: []string{utils.MetaCDRs + utils.InInFieldSep + utils.MetaRALs,
- utils.ConcatenatedKey(utils.MetaResources, utils.MetaRelease),
- utils.MetaBlockerError}, // expended to stop the processing because we have error at resource
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "testSSv1ItProcessEventWithCDRResourceErrorBlockError",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItProcessEventWithCDRResourceErrorBlockError",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply sessions.V1ProcessEventReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessEvent,
- args, &rply); err == nil || err.Error() != "RESOURCES_ERROR:cannot find usage record with id: testSSv1ItProcessEventWithCDRResourceErrorBlockError" {
- t.Error(err)
- }
-}
-
-func testSSv1ItGetCDRsFromProcessEventResourceErrorBlockError(t *testing.T) {
- var cdrCnt int64
- req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{
- OriginIDs: []string{"testSSv1ItProcessEventWithCDRResourceErrorBlockError"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 0 {
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
-
-}
diff --git a/apier/v1/sessions_thresholds_it_test.go b/apier/v1/sessions_thresholds_it_test.go
deleted file mode 100755
index 162c74309..000000000
--- a/apier/v1/sessions_thresholds_it_test.go
+++ /dev/null
@@ -1,649 +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/cenkalti/rpc2"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- sSv1CfgPath2 string
- sSv1Cfg2 *config.CGRConfig
- sSv1BiRpc2 *rpc2.Client
- sSApierRpc2 *rpc.Client
- disconnectEvChan2 = make(chan *utils.AttrDisconnectSession)
- sessionsConfDIR string
-
- sessionsThresholdTests = []func(t *testing.T){
- testSessionSv1ItInitCfg,
- testSessionSv1ItResetDataDb,
- testSessionSv1ItResetStorDb,
- testSessionSv1ItStartEngine,
- testSessionSv1ItRpcConn,
- testSessionSv1ItTPFromFolder,
- testSessionSv1ItGetThreshold,
- testSessionSv1ItAuth,
- testSessionSv1ItInitiateSession,
- testSessionSv1ItTerminateSession,
- testSessionSv1ItAuthNotFoundThreshold,
- testSessionSv1ItInitNotFoundThreshold,
- testSessionSv1ItTerminateNotFoundThreshold,
- testSessionSv1ItAuthNotFoundThresholdAndStats,
- testSessionSv1ItInitNotFoundThresholdAndStats,
- testSessionSv1ItTerminateNotFoundThresholdAndStats,
- testSessionSv1ItStopCgrEngine,
- }
-)
-
-func TestSessionSITtests(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- sessionsConfDIR = "sessions_internal"
- case utils.MetaMySQL:
- sessionsConfDIR = "sessions_mysql"
- case utils.MetaMongo:
- sessionsConfDIR = "sessions_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sessionsThresholdTests {
- t.Run(sessionsConfDIR, stest)
- }
-}
-
-func handleDisconnectSession2(clnt *rpc2.Client,
- args *utils.AttrDisconnectSession, reply *string) error {
- disconnectEvChan2 <- args
- *reply = utils.OK
- return nil
-}
-
-func testSessionSv1ItInitCfg(t *testing.T) {
- var err error
- sSv1CfgPath2 = path.Join(*dataDir, "conf", "samples", sessionsConfDIR)
- // Init config first
- sSv1Cfg2, err = config.NewCGRConfigFromPath(sSv1CfgPath2)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testSessionSv1ItResetDataDb(t *testing.T) {
- if err := engine.InitDataDB(sSv1Cfg2); err != nil {
- t.Fatal(err)
- }
-}
-
-func testSessionSv1ItResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(sSv1Cfg2); err != nil {
- t.Fatal(err)
- }
-}
-
-func testSessionSv1ItStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(sSv1CfgPath2, 100); err != nil {
- t.Fatal(err)
- }
-}
-
-func testSessionSv1ItRpcConn(t *testing.T) {
- dummyClnt, err := utils.NewBiJSONrpcClient(sSv1Cfg2.SessionSCfg().ListenBijson,
- nil)
- if err != nil {
- t.Fatal(err)
- }
- clntHandlers := map[string]interface{}{
- utils.SessionSv1DisconnectSession: handleDisconnectSession2,
- }
- if sSv1BiRpc2, err = utils.NewBiJSONrpcClient(sSv1Cfg2.SessionSCfg().ListenBijson,
- clntHandlers); err != nil {
- t.Fatal(err)
- }
- if sSApierRpc2, err = newRPCClient(sSv1Cfg2.ListenCfg()); err != nil {
- t.Fatal(err)
- }
- dummyClnt.Close() // close so we don't get EOF error when disconnecting server
-}
-
-// Load the tariff plan, creating accounts and their balances
-func testSessionSv1ItTPFromFolder(t *testing.T) {
- attrs := &utils.AttrLoadTpFromFolder{
- FolderPath: path.Join(*dataDir, "tariffplans", "testit")}
- var loadInst utils.LoadInstance
- if err := sSApierRpc2.Call(utils.APIerSv2LoadTariffPlanFromFolder, attrs, &loadInst); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testSessionSv1ItGetThreshold(t *testing.T) {
- tPrfl := &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_ACNT_1001",
- FilterIDs: []string{"FLTR_ACCOUNT_1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 29, 15, 0, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 0,
- Blocker: false,
- Weight: 10.0,
- ActionIDs: []string{"TOPUP_MONETARY_10"},
- Async: false,
- }
- var reply *engine.ThresholdProfile
- if err := sSApierRpc2.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org",
- ID: "THD_ACNT_1001"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl, reply) {
- t.Errorf("Expecting: %+v, received: %+v",
- utils.ToJSON(tPrfl), utils.ToJSON(reply))
- }
- // Verify account before authorization
- expectedAccount := &engine.Account{
- ID: "cgrates.org:1001",
- BalanceMap: map[string]engine.Balances{
- utils.MetaMonetary: []*engine.Balance{
- {
- Value: 10,
- Weight: 10,
- },
- },
- },
- }
- // Uuid will be generated
- // so we will compare ID from Account and Value from BalanceMap
- var reply2 *engine.Account
- if err := sSApierRpc2.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org",
- Account: "1001"}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedAccount.ID, reply2.ID) {
- t.Errorf("Expecting: %s, received: %s",
- expectedAccount.ID, reply2.ID)
- } else if !reflect.DeepEqual(
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply2.BalanceMap[utils.MetaMonetary][0].Value) {
- t.Errorf("Expecting: %f, received: %f",
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply2.BalanceMap[utils.MetaMonetary][0].Value)
- }
-}
-
-func testSessionSv1ItAuth(t *testing.T) {
- args := &sessions.V1AuthorizeArgs{
- AuthorizeResources: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItAuth",
- Event: map[string]interface{}{
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1001",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- },
- },
- }
- var rply sessions.V1AuthorizeReply
- if err := sSv1BiRpc2.Call(utils.SessionSv1AuthorizeEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- if *rply.ResourceAllocation == "" {
- t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
- }
- if !reflect.DeepEqual(*rply.ThresholdIDs, []string{"THD_ACNT_1001"}) {
- t.Errorf("Unexpected ThresholdIDs: %v", *rply.ThresholdIDs)
- }
- // Hit threshold and execute action (topup with 10 units)
- expectedAccount := &engine.Account{
- ID: "cgrates.org:1001",
- BalanceMap: map[string]engine.Balances{
- utils.MetaMonetary: []*engine.Balance{
- {
- Value: 20,
- Weight: 10,
- },
- },
- },
- }
- // Uuid will be generated
- // so we will compare ID from Account and Value from BalanceMap
- var reply *engine.Account
- if err := sSApierRpc2.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org",
- Account: "1001"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedAccount.ID, reply.ID) {
- t.Errorf("Expecting: %s, received: %s",
- expectedAccount.ID, reply.ID)
- } else if !reflect.DeepEqual(
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply.BalanceMap[utils.MetaMonetary][0].Value) {
- t.Errorf("Expecting: %f, received: %f",
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply.BalanceMap[utils.MetaMonetary][0].Value)
- }
-}
-
-func testSessionSv1ItInitiateSession(t *testing.T) {
- initUsage := 5 * time.Minute
- args := &sessions.V1InitSessionArgs{
- InitSession: true,
- AllocateResources: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItInitiateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1001",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018,
- time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitSessionReply
- if err := sSv1BiRpc2.Call(utils.SessionSv1InitiateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- if !reflect.DeepEqual(*rply.ThresholdIDs, []string{"THD_ACNT_1001"}) {
- t.Errorf("Unexpected ThresholdIDs: %v", *rply.ThresholdIDs)
- }
- expectedAccount := &engine.Account{
- ID: "cgrates.org:1001",
- BalanceMap: map[string]engine.Balances{
- utils.MetaMonetary: []*engine.Balance{
- {
- Value: 29.898000,
- Weight: 10,
- },
- },
- },
- }
- // Uuid will be generated
- // so we will compare ID from Account and Value from BalanceMap
- var reply *engine.Account
- if err := sSApierRpc2.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org",
- Account: "1001"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedAccount.ID, reply.ID) {
- t.Errorf("Expecting: %s, received: %s",
- expectedAccount.ID, reply.ID)
- } else if !reflect.DeepEqual(
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply.BalanceMap[utils.MetaMonetary][0].Value) {
- t.Errorf("Expecting: %f, received: %f",
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply.BalanceMap[utils.MetaMonetary][0].Value)
- }
-}
-
-func testSessionSv1ItTerminateSession(t *testing.T) {
- args := &sessions.V1TerminateSessionArgs{
- TerminateSession: true,
- ReleaseResources: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItTerminateSession",
- Event: map[string]interface{}{
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1001",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply string
- if err := sSv1BiRpc2.Call(utils.SessionSv1TerminateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply != utils.OK {
- t.Errorf("Unexpected reply: %s", rply)
- }
- expectedAccount := &engine.Account{
- ID: "cgrates.org:1001",
- BalanceMap: map[string]engine.Balances{
- utils.MetaMonetary: []*engine.Balance{
- {
- Value: 39.796000,
- Weight: 10,
- },
- },
- },
- }
- // Uuid will be generated
- // so we will compare ID from Account and Value from BalanceMap
- var reply2 *engine.Account
- if err := sSApierRpc2.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org",
- Account: "1001"}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedAccount.ID, reply2.ID) {
- t.Errorf("Expecting: %s, received: %s",
- expectedAccount.ID, reply2.ID)
- } else if !reflect.DeepEqual(
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply2.BalanceMap[utils.MetaMonetary][0].Value) {
- t.Errorf("Expecting: %f, received: %f",
- expectedAccount.BalanceMap[utils.MetaMonetary][0].Value,
- reply2.BalanceMap[utils.MetaMonetary][0].Value)
- }
-}
-
-func testSessionSv1ItAuthNotFoundThreshold(t *testing.T) {
- args := &sessions.V1AuthorizeArgs{
- ProcessStats: true,
- GetMaxUsage: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSesssonSv1ItNotFoundThreshold",
- Event: map[string]interface{}{
- utils.OriginID: "TestSesssonSv1ItNotFoundThreshold",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1002",
- utils.Destination: "1001",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- },
- },
- }
- var rply sessions.V1AuthorizeReply
- if err := sSv1BiRpc2.Call(utils.SessionSv1AuthorizeEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.ThresholdIDs != nil {
- t.Errorf("Expecting: nil, received: %+v",
- rply.ThresholdIDs)
- }
- if rply.StatQueueIDs != nil && len(*rply.StatQueueIDs) != 1 && (*rply.StatQueueIDs)[0] != "Stat_2" {
- t.Errorf("Unexpected StatQueueIDs: %+v", rply.StatQueueIDs)
- }
-}
-
-func testSessionSv1ItInitNotFoundThreshold(t *testing.T) {
- initUsage := 1024
- args := &sessions.V1InitSessionArgs{
- ProcessStats: true,
- InitSession: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSessionSv1ItInitNotFoundThreshold",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaData,
- utils.OriginID: "TestSessionSv1ItInitNotFoundThreshold",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1002",
- utils.Subject: "RP_ANY2CNT",
- utils.Destination: "1001",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018,
- time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitSessionReply
- if err := sSv1BiRpc2.Call(utils.SessionSv1InitiateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.MaxUsage == nil || *rply.MaxUsage != 1024 {
- t.Errorf("Expecting: %+v, received: %+v",
- 1024, rply.MaxUsage)
- }
- if rply.ThresholdIDs != nil {
- t.Errorf("Expecting: nil, received: %+v",
- rply.ThresholdIDs)
- }
- if rply.StatQueueIDs != nil && len(*rply.StatQueueIDs) != 1 && (*rply.StatQueueIDs)[0] != "Stat_2" {
- t.Errorf("Unexpected StatQueueIDs: %+v", rply.StatQueueIDs)
- }
-
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
- }
-}
-
-func testSessionSv1ItTerminateNotFoundThreshold(t *testing.T) {
- initUsage := 1024
- args := &sessions.V1TerminateSessionArgs{
- ProcessStats: true,
- TerminateSession: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSessionSv1ItTerminateNotFoundThreshold",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaData,
- utils.OriginID: "TestSessionSv1ItInitNotFoundThreshold",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1002",
- utils.Subject: "RP_ANY2CNT",
- utils.Destination: "1001",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018,
- time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply string
- if err := sSv1BiRpc2.Call(utils.SessionSv1TerminateSession,
- args, &rply); err != nil {
- t.Fatal(err)
- }
- if rply != utils.OK {
- t.Fatalf("Unexpected reply: %s", rply)
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testSessionSv1ItAuthNotFoundThresholdAndStats(t *testing.T) {
- var resp string
- if err := sSApierRpc2.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Stat_2"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-
- args := &sessions.V1AuthorizeArgs{
- ProcessStats: true,
- GetMaxUsage: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSesssonSv1ItNotFoundThreshold",
- Event: map[string]interface{}{
- utils.OriginID: "TestSesssonSv1ItNotFoundThreshold",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1002",
- utils.Destination: "1001",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- },
- },
- }
- var rply sessions.V1AuthorizeReply
- if err := sSv1BiRpc2.Call(utils.SessionSv1AuthorizeEvent,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.ThresholdIDs != nil {
- t.Errorf("Expecting: nil, received: %+v",
- rply.ThresholdIDs)
- }
- if rply.StatQueueIDs != nil {
- t.Errorf("Expecting: nil, received: %+v",
- rply.StatQueueIDs)
- }
-}
-
-func testSessionSv1ItInitNotFoundThresholdAndStats(t *testing.T) {
- initUsage := 1024
- args := &sessions.V1InitSessionArgs{
- ProcessStats: true,
- InitSession: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSessionSv1ItInitNotFoundThreshold",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaData,
- utils.OriginID: "TestSessionSv1ItInitNotFoundThreshold",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1002",
- utils.Subject: "RP_ANY2CNT",
- utils.Destination: "1001",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018,
- time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitSessionReply
- if err := sSv1BiRpc2.Call(utils.SessionSv1InitiateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply.MaxUsage == nil || *rply.MaxUsage != 1024 {
- t.Errorf("Expecting: %+v, received: %+v",
- 1024, rply.MaxUsage)
- }
- if rply.ThresholdIDs != nil {
- t.Errorf("Expecting: nil, received: %+v",
- rply.ThresholdIDs)
- }
- if rply.StatQueueIDs != nil {
- t.Errorf("Expecting: nil, received: %+v",
- rply.StatQueueIDs)
- }
-
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
- }
-}
-
-func testSessionSv1ItTerminateNotFoundThresholdAndStats(t *testing.T) {
- initUsage := 1024
- args := &sessions.V1TerminateSessionArgs{
- ProcessStats: true,
- TerminateSession: true,
- ProcessThresholds: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSessionSv1ItTerminateNotFoundThreshold",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaData,
- utils.OriginID: "TestSessionSv1ItInitNotFoundThreshold",
- utils.RequestType: utils.MetaPrepaid,
- utils.AccountField: "1002",
- utils.Subject: "RP_ANY2CNT",
- utils.Destination: "1001",
- utils.SetupTime: time.Date(2018,
- time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018,
- time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply string
- if err := sSv1BiRpc2.Call(utils.SessionSv1TerminateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply != utils.OK {
- t.Errorf("Unexpected reply: %s", rply)
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc2.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testSessionSv1ItStopCgrEngine(t *testing.T) {
- if err := sSv1BiRpc2.Close(); err != nil { // Close the connection so we don't get EOF warnings from client
- t.Error(err)
- }
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/sessionsbirpc.go b/apier/v1/sessionsbirpc.go
deleted file mode 100644
index 6e385a668..000000000
--- a/apier/v1/sessionsbirpc.go
+++ /dev/null
@@ -1,357 +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/birpc/context"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
-)
-
-// Bidirectional JSON methods following
-func (ssv1 *SessionSv1) Handlers() map[string]interface{} {
- return map[string]interface{}{
- utils.SessionSv1GetActiveSessions: ssv1.BiRPCv1GetActiveSessions,
- utils.SessionSv1GetActiveSessionsCount: ssv1.BiRPCv1GetActiveSessionsCount,
- utils.SessionSv1GetPassiveSessions: ssv1.BiRPCv1GetPassiveSessions,
- utils.SessionSv1GetPassiveSessionsCount: ssv1.BiRPCv1GetPassiveSessionsCount,
-
- utils.SessionSv1AuthorizeEvent: ssv1.BiRPCv1AuthorizeEvent,
- utils.SessionSv1AuthorizeEventWithDigest: ssv1.BiRPCv1AuthorizeEventWithDigest,
- utils.SessionSv1InitiateSession: ssv1.BiRPCv1InitiateSession,
- utils.SessionSv1InitiateSessionWithDigest: ssv1.BiRPCv1InitiateSessionWithDigest,
- utils.SessionSv1UpdateSession: ssv1.BiRPCv1UpdateSession,
- utils.SessionSv1SyncSessions: ssv1.BiRPCv1SyncSessions,
- utils.SessionSv1TerminateSession: ssv1.BiRPCv1TerminateSession,
- utils.SessionSv1ProcessCDR: ssv1.BiRPCv1ProcessCDR,
- utils.SessionSv1ProcessMessage: ssv1.BiRPCv1ProcessMessage,
- utils.SessionSv1ProcessEvent: ssv1.BiRPCv1ProcessEvent,
-
- utils.SessionSv1ForceDisconnect: ssv1.BiRPCv1ForceDisconnect,
- utils.SessionSv1RegisterInternalBiJSONConn: ssv1.BiRPCv1RegisterInternalBiJSONConn,
- utils.SessionSv1Ping: ssv1.BiRPCPing,
-
- utils.SessionSv1ReplicateSessions: ssv1.BiRPCv1ReplicateSessions,
- utils.SessionSv1SetPassiveSession: ssv1.BiRPCv1SetPassiveSession,
- utils.SessionSv1ActivateSessions: ssv1.BiRPCv1ActivateSessions,
- utils.SessionSv1DeactivateSessions: ssv1.BiRPCv1DeactivateSessions,
-
- utils.SessionSv1ReAuthorize: ssv1.BiRPCV1ReAuthorize,
- utils.SessionSv1DisconnectPeer: ssv1.BiRPCV1DisconnectPeer,
-
- utils.SessionSv1STIRAuthenticate: ssv1.BiRPCV1STIRAuthenticate,
- utils.SessionSv1STIRIdentity: ssv1.BiRPCV1STIRIdentity,
-
- utils.SessionSv1Sleep: ssv1.BiRPCV1Sleep, // Sleep method is used to test the concurrent requests mechanism
- }
-}
-
-func (ssv1 *SessionSv1) BiRPCv1AuthorizeEvent(ctx *context.Context, args *sessions.V1AuthorizeArgs,
- rply *sessions.V1AuthorizeReply) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1AuthorizeEvent(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1AuthorizeEventWithDigest(ctx *context.Context, args *sessions.V1AuthorizeArgs,
- rply *sessions.V1AuthorizeReplyWithDigest) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1AuthorizeEventWithDigest(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1InitiateSession(ctx *context.Context, args *sessions.V1InitSessionArgs,
- rply *sessions.V1InitSessionReply) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1InitiateSession(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1InitiateSessionWithDigest(ctx *context.Context, args *sessions.V1InitSessionArgs,
- rply *sessions.V1InitReplyWithDigest) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1InitiateSessionWithDigest(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1UpdateSession(ctx *context.Context, args *sessions.V1UpdateSessionArgs,
- rply *sessions.V1UpdateSessionReply) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1UpdateSession(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1SyncSessions(ctx *context.Context, args *utils.TenantWithAPIOpts,
- rply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1SyncSessions(ctx.Client, &utils.TenantWithAPIOpts{}, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1TerminateSession(ctx *context.Context, args *sessions.V1TerminateSessionArgs,
- rply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1TerminateSession(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1ProcessCDR(ctx *context.Context, cgrEv *utils.CGREvent,
- rply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ProcessCDR(ctx.Client, cgrEv, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1ProcessMessage(ctx *context.Context, args *sessions.V1ProcessMessageArgs,
- rply *sessions.V1ProcessMessageReply) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ProcessMessage(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1ProcessEvent(ctx *context.Context, args *sessions.V1ProcessEventArgs,
- rply *sessions.V1ProcessEventReply) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ProcessEvent(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1GetActiveSessions(ctx *context.Context, args *utils.SessionFilter,
- rply *[]*sessions.ExternalSession) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1GetActiveSessions(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1GetActiveSessionsCount(ctx *context.Context, args *utils.SessionFilter,
- rply *int) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1GetActiveSessionsCount(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter,
- rply *[]*sessions.ExternalSession) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1GetPassiveSessions(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1GetPassiveSessionsCount(ctx *context.Context, args *utils.SessionFilter,
- rply *int) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1GetPassiveSessionsCount(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1ForceDisconnect(ctx *context.Context, args *utils.SessionFilter,
- rply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ForceDisconnect(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1RegisterInternalBiJSONConn(ctx *context.Context, args string,
- rply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1RegisterInternalBiJSONConn(ctx.Client, args, rply)
-}
-
-func (ssv1 *SessionSv1) BiRPCPing(ctx *context.Context, ign *utils.CGREvent,
- reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.Ping(ign, reply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1ReplicateSessions(ctx *context.Context,
- args sessions.ArgsReplicateSessions, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ReplicateSessions(ctx.Client, args, reply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1SetPassiveSession(ctx *context.Context,
- args *sessions.Session, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1SetPassiveSession(ctx.Client, args, reply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1ActivateSessions(ctx *context.Context,
- args *utils.SessionIDsWithAPIOpts, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ActivateSessions(ctx.Client, args, reply)
-}
-
-func (ssv1 *SessionSv1) BiRPCv1DeactivateSessions(ctx *context.Context,
- args *utils.SessionIDsWithAPIOpts, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1DeactivateSessions(ctx.Client, args, reply)
-}
-
-// BiRPCV1ReAuthorize sends the RAR for filterd sessions
-func (ssv1 *SessionSv1) BiRPCV1ReAuthorize(ctx *context.Context,
- args *utils.SessionFilter, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1ReAuthorize(ctx.Client, args, reply)
-}
-
-// BiRPCV1DisconnectPeer sends the DPR for the OriginHost and OriginRealm
-func (ssv1 *SessionSv1) BiRPCV1DisconnectPeer(ctx *context.Context,
- args *utils.DPRArgs, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1DisconnectPeer(ctx.Client, args, reply)
-}
-
-// BiRPCV1STIRAuthenticate checks the identity using STIR/SHAKEN
-func (ssv1 *SessionSv1) BiRPCV1STIRAuthenticate(ctx *context.Context,
- args *sessions.V1STIRAuthenticateArgs, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1STIRAuthenticate(ctx.Client, args, reply)
-}
-
-// BiRPCV1STIRIdentity creates the identity for STIR/SHAKEN
-func (ssv1 *SessionSv1) BiRPCV1STIRIdentity(ctx *context.Context,
- args *sessions.V1STIRIdentityArgs, reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- return ssv1.sS.BiRPCv1STIRIdentity(nil, args, reply)
-}
-
-func (ssv1 *SessionSv1) BiRPCV1Sleep(ctx *context.Context, arg *utils.DurationArgs,
- reply *string) (err error) {
- if ssv1.caps.IsLimited() {
- if err = ssv1.caps.Allocate(); err != nil {
- return
- }
- defer ssv1.caps.Deallocate()
- }
- time.Sleep(arg.Duration)
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go
deleted file mode 100644
index 2a0b1794e..000000000
--- a/apier/v1/sessionsv1_it_test.go
+++ /dev/null
@@ -1,1146 +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/cenkalti/rpc2"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- sSv1CfgPath string
- sSv1Cfg *config.CGRConfig
- sSv1BiRpc *rpc2.Client
- sSApierRpc *rpc.Client
- discEvChan = make(chan *utils.AttrDisconnectSession, 1)
- sSV1RequestType string
-
- sTestSessionSv1 = []func(t *testing.T){
- testSSv1ItInitCfgDir,
- testSSv1ItInitCfg,
- testSSv1ItResetDataDb,
- testSSv1ItResetStorDb,
- testSSv1ItStartEngine,
- testSSv1ItRpcConn,
- testSSv1ItPing,
- testSSv1ItTPFromFolder,
- testSSv1ItAuth,
- testSSv1ItAuthWithDigest,
- testSSv1ItInitiateSession,
- testSSv1ItUpdateSession,
- testSSv1ItTerminateSession,
- testSSv1ItProcessCDR,
- testSSv1ItProcessEvent,
- testSSv1ItCDRsGetCdrs,
- testSSv1ItForceUpdateSession,
- testSSv1ItDynamicDebit,
- testSSv1ItDeactivateSessions,
- testSSv1ItAuthNotFoundCharger,
- testSSv1ItInitiateSessionNotFoundCharger,
-
- testSSv1ItInitiateSessionWithDigest, // no need for session terminate because is the last test
-
- testSSv1ItStopCgrEngine,
- }
-)
-
-func testSSv1ItInitCfgDir(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- sessionsConfDIR = "sessions_internal"
- case utils.MetaMySQL:
- sessionsConfDIR = "sessions_mysql"
- case utils.MetaMongo:
- sessionsConfDIR = "sessions_mongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-}
-
-func handleDisconnectSession(clnt *rpc2.Client,
- args *utils.AttrDisconnectSession, reply *string) error {
- discEvChan <- args
- // free the channel
- <-discEvChan
- *reply = utils.OK
- return nil
-}
-
-func handleGetSessionIDs(clnt *rpc2.Client,
- ignParam string, sessionIDs *[]*sessions.SessionID) error {
- return nil
-}
-
-func TestSSv1ItWithPrepaid(t *testing.T) {
- if *dbType == utils.MetaPostgres {
- t.SkipNow()
- }
- sSV1RequestType = utils.MetaPrepaid
- for _, stest := range sTestSessionSv1 {
- t.Run(sSV1RequestType, stest)
- }
-}
-
-func TestSSv1ItWithPostPaid(t *testing.T) {
- if *dbType == utils.MetaPostgres {
- t.SkipNow()
- }
- sSV1RequestType = utils.MetaPostpaid
- for _, stest := range sTestSessionSv1 {
- t.Run(sSV1RequestType, stest)
- }
-}
-
-func TestSSv1ItWithRated(t *testing.T) {
- if *dbType == utils.MetaPostgres {
- t.SkipNow()
- }
- sSV1RequestType = utils.MetaRated
- for _, stest := range sTestSessionSv1 {
- t.Run(sSV1RequestType, stest)
- }
-}
-
-func TestSSv1ItWithPseudoPrepaid(t *testing.T) {
- if *dbType == utils.MetaPostgres {
- t.SkipNow()
- }
- sSV1RequestType = utils.MetaPseudoPrepaid
- for _, stest := range sTestSessionSv1 {
- t.Run(sSV1RequestType, stest)
- }
-}
-
-func testSSv1ItResetDataDb(t *testing.T) {
- if err := engine.InitDataDB(sSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testSSv1ItResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(sSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testSSv1ItStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(sSv1CfgPath, 1000); err != nil {
- t.Fatal(err)
- }
-}
-
-func testSSv1ItRpcConn(t *testing.T) {
- dummyClnt, err := utils.NewBiJSONrpcClient(sSv1Cfg.SessionSCfg().ListenBijson,
- nil)
- if err != nil {
- t.Fatal(err)
- }
- clntHandlers := map[string]interface{}{
- utils.SessionSv1DisconnectSession: handleDisconnectSession,
- utils.SessionSv1GetActiveSessionIDs: handleGetSessionIDs,
- }
- if sSv1BiRpc, err = utils.NewBiJSONrpcClient(sSv1Cfg.SessionSCfg().ListenBijson,
- clntHandlers); err != nil {
- t.Fatal(err)
- }
- if sSApierRpc, err = newRPCClient(sSv1Cfg.ListenCfg()); err != nil {
- t.Fatal(err)
- }
- dummyClnt.Close() // close so we don't get EOF error when disconnecting server
-}
-
-func testSSv1ItPing(t *testing.T) {
- var resp string
- if err := sSv1BiRpc.Call(utils.SessionSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-// Load the tariff plan, creating accounts and their balances
-func testSSv1ItTPFromFolder(t *testing.T) {
- attrs := &utils.AttrLoadTpFromFolder{
- FolderPath: path.Join(*dataDir, "tariffplans", "testit")}
- var loadInst utils.LoadInstance
- if err := sSApierRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder,
- attrs, &loadInst); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testSSv1ItAuth(t *testing.T) {
- authUsage := 5 * time.Minute
- args := &sessions.V1AuthorizeArgs{
- GetMaxUsage: true,
- AuthorizeResources: true,
- GetRoutes: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItAuth",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.Usage: authUsage,
- },
- },
- }
- var rply sessions.V1AuthorizeReply
- if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEvent, args, &rply); err != nil {
- t.Fatal(err)
- }
- if rply.MaxUsage == nil || *rply.MaxUsage != authUsage {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- if *rply.ResourceAllocation == "" {
- t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
- }
- eSplrs := engine.SortedRoutesList{{
- ProfileID: "ROUTE_ACNT_1001",
- Sorting: utils.MetaWeight,
- Routes: []*engine.SortedRoute{
- {
- RouteID: "route1",
- SortingData: map[string]interface{}{
- "Weight": 20.0,
- },
- },
- {
- RouteID: "route2",
- SortingData: map[string]interface{}{
- "Weight": 10.0,
- },
- },
- },
- }, {
- ProfileID: "ROUTE_WEIGHT_2",
- Sorting: utils.MetaWeight,
- Routes: []*engine.SortedRoute{{
- RouteID: "route1",
- SortingData: map[string]interface{}{
- "Weight": 10.0,
- },
- }},
- }}
- if !reflect.DeepEqual(eSplrs, rply.RouteProfiles) {
- t.Errorf("expecting: %+v,\n received: %+v", utils.ToJSON(eSplrs), utils.ToJSON(rply.RouteProfiles))
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItAuth",
- Event: map[string]interface{}{
- utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
- }
-}
-
-func testSSv1ItAuthWithDigest(t *testing.T) {
- authUsage := 5 * time.Minute
- args := &sessions.V1AuthorizeArgs{
- GetMaxUsage: true,
- AuthorizeResources: true,
- GetRoutes: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItAuth",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.Usage: authUsage,
- },
- APIOpts: map[string]interface{}{utils.OptsRouteProfilesCount: 1},
- },
- }
- var rply sessions.V1AuthorizeReplyWithDigest
- if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEventWithDigest, args, &rply); err != nil {
- t.Fatal(err)
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect -1
- if rply.MaxUsage != authUsage.Seconds() {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- if *rply.ResourceAllocation == "" {
- t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
- }
- eSplrs := utils.StringPointer("route1,route2")
- if *eSplrs != *rply.RoutesDigest {
- t.Errorf("expecting: %v, received: %v", *eSplrs, *rply.RoutesDigest)
- }
- eAttrs := utils.StringPointer("OfficeGroup:Marketing")
- if *eAttrs != *rply.AttributesDigest {
- t.Errorf("expecting: %v, received: %v", *eAttrs, *rply.AttributesDigest)
- }
-}
-
-func testSSv1ItInitiateSession(t *testing.T) {
- initUsage := 5 * time.Minute
- args := &sessions.V1InitSessionArgs{
- InitSession: true,
- AllocateResources: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItInitiateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitSessionReply
- if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession,
- args, &rply); err != nil {
- t.Fatal(err)
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect the value of Usage field
- // if this was missing the MaxUsage should be equal to MaxCallDuration from config
- if rply.MaxUsage == nil || *rply.MaxUsage != initUsage {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- if *rply.ResourceAllocation != "RES_ACNT_1001" {
- t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItInitiateSession",
- Event: map[string]interface{}{
- utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.AnswerTime: "2018-01-07T17:00:10Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
- }
-}
-
-func testSSv1ItInitiateSessionWithDigest(t *testing.T) {
- initUsage := 5 * time.Minute
- args := &sessions.V1InitSessionArgs{
- InitSession: true,
- AllocateResources: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItInitiateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It2",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitReplyWithDigest
- if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSessionWithDigest,
- args, &rply); err != nil {
- t.Fatal(err)
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect the value of Usage field
- // if this was missing the MaxUsage should be equal to MaxCallDuration from config
- if rply.MaxUsage != initUsage.Seconds() {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- if *rply.ResourceAllocation != "RES_ACNT_1001" {
- t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
- }
- eAttrs := utils.StringPointer("OfficeGroup:Marketing")
- if !reflect.DeepEqual(eAttrs, rply.AttributesDigest) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.AttributesDigest))
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions))
- }
-}
-
-func testSSv1ItUpdateSession(t *testing.T) {
- reqUsage := 5 * time.Minute
- args := &sessions.V1UpdateSessionArgs{
- GetAttributes: true,
- UpdateSession: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItUpdateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: reqUsage,
- },
- },
- }
- var rply sessions.V1UpdateSessionReply
- if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItUpdateSession",
- Event: map[string]interface{}{
- utils.CGRID: "5668666d6b8e44eb949042f25ce0796ec3592ff9",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.AnswerTime: "2018-01-07T17:00:10Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes) {
- t.Fatalf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect the value of Usage field
- // if this was missing the MaxUsage should be equal to MaxCallDuration from config
- if rply.MaxUsage == nil || *rply.MaxUsage != reqUsage {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s", utils.ToJSON(aSessions))
- }
-}
-
-func testSSv1ItTerminateSession(t *testing.T) {
- args := &sessions.V1TerminateSessionArgs{
- TerminateSession: true,
- ReleaseResources: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItUpdateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- },
- }
- var rply string
- if err := sSv1BiRpc.Call(utils.SessionSv1TerminateSession,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply != utils.OK {
- t.Errorf("Unexpected reply: %s", rply)
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error %s received error %v and reply %s", utils.ErrNotFound, err, utils.ToJSON(aSessions))
- }
-}
-
-func testSSv1ItProcessCDR(t *testing.T) {
- args := &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItProcessCDR",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 10 * time.Minute,
- },
- }
- var rply string
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR,
- args, &rply); err != nil {
- t.Error(err)
- }
- if rply != utils.OK {
- t.Errorf("Unexpected reply: %s", rply)
- }
-}
-
-// TestSSv1ItProcessEvent processes individual event and also checks it's CDRs
-func testSSv1ItProcessEvent(t *testing.T) {
- initUsage := 5 * time.Minute
- args := &sessions.V1ProcessMessageArgs{
- AllocateResources: true,
- Debit: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItProcessEvent",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It2",
- utils.OriginHost: "TestSSv1It3",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1ProcessMessageReply
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessMessage,
- args, &rply); err != nil {
- t.Fatal(err)
- }
- // in case of prepaid and pseudoprepade we expect a MaxUsage of 5min
- // and in case of postpaid and rated we expect the value of Usage field
- // if this was missing the MaxUsage should be equal to MaxCallDuration from config
- if rply.MaxUsage == nil || *rply.MaxUsage != initUsage {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- if *rply.ResourceAllocation != "RES_ACNT_1001" {
- t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItProcessEvent",
- Event: map[string]interface{}{
- utils.CGRID: "f7f5cf1029905f9b98be1a608e4bd975b8e51413",
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "TestSSv1It2",
- utils.OriginHost: "TestSSv1It3",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.AnswerTime: "2018-01-07T17:00:10Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes) {
- t.Errorf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- var rplyCDR string
- if err := sSv1BiRpc.Call(utils.SessionSv1ProcessCDR,
- args.CGREvent, &rplyCDR); err != nil {
- t.Error(err)
- }
- if rplyCDR != utils.OK {
- t.Errorf("Unexpected reply: %s", rplyCDR)
- }
-}
-
-func testSSv1ItCDRsGetCdrs(t *testing.T) {
- var cdrCnt int64
- req := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRsCount, req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 6 { // 3 for each CDR
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
-
- var cdrs []*engine.CDR
- args := &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"raw"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 2 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"},
- OriginIDs: []string{"TestSSv1It1"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.198 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 10*time.Minute {
- t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
- }
- if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.198 {
- t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
- OriginIDs: []string{"TestSSv1It1"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 10*time.Minute {
- t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
- }
- if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.102 {
- t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
- }
- }
-
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"},
- OriginIDs: []string{"TestSSv1It2"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.099 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 5*time.Minute {
- t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
- }
- if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.099 {
- t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
- }
- }
- args = &utils.RPCCDRsFilterWithAPIOpts{RPCCDRsFilter: &utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"},
- OriginIDs: []string{"TestSSv1It2"}}}
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.051 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].CostDetails.Usage == nil || *cdrs[0].CostDetails.Usage != 5*time.Minute {
- t.Errorf("Unexpected usage from CostDetails for CDR: %+v", cdrs[0].CostDetails.Usage)
- }
- if cdrs[0].CostDetails.Cost == nil || *cdrs[0].CostDetails.Cost != 0.051 {
- t.Errorf("Unexpected cost from CostDetails for CDR: %+v", cdrs[0].CostDetails.Cost)
- }
- }
-}
-
-func testSSv1ItForceUpdateSession(t *testing.T) {
- if sSV1RequestType != utils.MetaPrepaid {
- t.SkipNow()
- return
- }
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Error: %v with len(asessions)=%v", err, len(aSessions))
- }
- var acnt *engine.Account
- attrs := &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "1001"}
- eAcntVal := 9.55
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal {
- t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue())
- }
-
- reqUsage := 5 * time.Minute
- args := &sessions.V1UpdateSessionArgs{
- GetAttributes: true,
- UpdateSession: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItUpdateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: reqUsage,
- },
- },
- }
- var rply sessions.V1UpdateSessionReply
- if err := sSv1BiRpc.Call(utils.SessionSv1UpdateSession,
- args, &rply); err != nil {
- t.Fatal(err)
- }
- eAttrs := &engine.AttrSProcessEventReply{
- MatchedProfiles: []string{"ATTR_ACNT_1001"},
- AlteredFields: []string{"*req.OfficeGroup"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItUpdateSession",
- Event: map[string]interface{}{
- utils.CGRID: "70876773b294f0e1476065f8d18bb9ec6bcb3d5f",
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaVoice,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- "OfficeGroup": "Marketing",
- utils.OriginID: "TestSSv1It",
- utils.RequestType: sSV1RequestType,
- utils.SetupTime: "2018-01-07T17:00:00Z",
- utils.AnswerTime: "2018-01-07T17:00:10Z",
- utils.Usage: 300000000000.0,
- },
- APIOpts: map[string]interface{}{utils.Subsys: utils.MetaSessionS},
- },
- }
- if !reflect.DeepEqual(eAttrs, rply.Attributes) {
- t.Fatalf("expecting: %+v, received: %+v",
- utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
- }
- if rply.MaxUsage == nil || *rply.MaxUsage != reqUsage {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
- }
- aSessions = make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active ssesions: %s", utils.ToJSON(aSessions))
- }
-
- eAcntVal = 9.4
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal {
- t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue())
- }
- rplyt := ""
- if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
- map[string]string{utils.OriginID: "TestSSv1It"}, &rplyt); err != nil {
- t.Error(err)
- } else if rplyt != utils.OK {
- t.Errorf("Unexpected reply: %s", rplyt)
- }
- aSessions = make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaMonetary].GetTotalValue() != eAcntVal { // no monetary change bacause the sessin was terminated
- t.Errorf("Expected: %f, received: %f", eAcntVal, acnt.BalanceMap[utils.MetaMonetary].GetTotalValue())
- }
- var cdrs []*engine.CDR
- argsCDR := &utils.RPCCDRsFilterWithAPIOpts{
- RPCCDRsFilter: &utils.RPCCDRsFilter{
- RunIDs: []string{"CustomerCharges"},
- OriginIDs: []string{"TestSSv1It"},
- },
- }
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs), "\n", utils.ToJSON(cdrs))
- } else {
- if cdrs[0].Cost != 0.099 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- argsCDR = &utils.RPCCDRsFilterWithAPIOpts{
- RPCCDRsFilter: &utils.RPCCDRsFilter{
- RunIDs: []string{"SupplierCharges"},
- OriginIDs: []string{"TestSSv1It"},
- },
- }
- if err := sSApierRpc.Call(utils.CDRsV1GetCDRs, argsCDR, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.051 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
-}
-
-func testSSv1ItDynamicDebit(t *testing.T) {
- if sSV1RequestType != utils.MetaPrepaid {
- t.SkipNow()
- return
- }
- attrSetBalance := utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "TestDynamicDebit",
- BalanceType: utils.MetaVoice,
- Value: 2 * float64(time.Second),
- Balance: map[string]interface{}{
- utils.ID: "TestDynamicDebitBalance",
- utils.RatingSubject: "*zero5ms",
- },
- }
- var reply string
- if err := sSApierRpc.Call(utils.APIerSv2SetBalance, attrSetBalance, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Received: %s", reply)
- }
- var acnt *engine.Account
- attrs := &utils.AttrGetAccount{
- Tenant: attrSetBalance.Tenant,
- Account: attrSetBalance.Account,
- }
- eAcntVal := 2 * float64(time.Second)
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal {
- t.Errorf("Expecting: %v, received: %v",
- time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.MetaVoice].GetTotalValue()))
- }
-
- args1 := &sessions.V1InitSessionArgs{
- InitSession: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItInitiateSession2",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestDynamicTDebit",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "TestDynamicDebit",
- utils.Subject: "TEST",
- utils.Destination: "TEST",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: 0,
- },
- APIOpts: map[string]interface{}{
- utils.OptsDebitInterval: 30 * time.Millisecond,
- },
- },
- }
- var rply1 sessions.V1InitSessionReply
- if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession,
- args1, &rply1); err != nil {
- t.Error(err)
- return
- } else if rply1.MaxUsage == nil || *rply1.MaxUsage != 3*time.Hour /* MaxCallDuration from config*/ {
- t.Errorf("Unexpected MaxUsage: %v", rply1.MaxUsage)
- }
-
- aSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %+v , %s ", len(aSessions), utils.ToJSON(aSessions))
- }
- time.Sleep(time.Millisecond)
- eAcntVal -= float64(time.Millisecond) * 30 * 2 // 2 session
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal {
- t.Errorf("Expecting: %v, received: %v",
- time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.MetaVoice].GetTotalValue()))
- }
-
- time.Sleep(10 * time.Millisecond)
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal {
- t.Errorf("Expecting: %v, received: %v",
- time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.MetaVoice].GetTotalValue()))
- }
- time.Sleep(20 * time.Millisecond)
- eAcntVal -= float64(time.Millisecond) * 30 * 2 // 2 session
- if err := sSApierRpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaVoice].GetTotalValue() != eAcntVal {
- t.Errorf("Expecting: %v, received: %v",
- time.Duration(eAcntVal), time.Duration(acnt.BalanceMap[utils.MetaVoice].GetTotalValue()))
- }
-
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %+v , %s ", len(aSessions), utils.ToJSON(aSessions))
- }
-
- var rplyt string
- if err := sSv1BiRpc.Call(utils.SessionSv1ForceDisconnect,
- nil, &rplyt); err != nil {
- t.Error(err)
- } else if rplyt != utils.OK {
- t.Errorf("Unexpected reply: %s", rplyt)
- }
-
- time.Sleep(50 * time.Millisecond)
-
- aSessions = make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, nil, &aSessions); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testSSv1ItDeactivateSessions(t *testing.T) {
- aSessions := make([]*sessions.ExternalSession, 0)
- pSessions := make([]*sessions.ExternalSession, 0)
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil && err.Error() != utils.NotFoundCaps {
- t.Error(err)
- }
- if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps {
- t.Error(err)
- }
- initUsage := 5 * time.Minute
- args := &sessions.V1InitSessionArgs{
- InitSession: true,
- GetAttributes: true,
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "TestSSv1ItInitiateSession",
- Event: map[string]interface{}{
- utils.Tenant: "cgrates.org",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "TestSSv1It1",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitSessionReply
- if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession, args, &rply); err != nil {
- t.Fatal(err)
- }
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil {
- t.Error(err)
- } else if len(aSessions) != 3 {
- t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
- }
- if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil && err.Error() != utils.NotFoundCaps {
- t.Error(err)
- }
- var reply string
- err := sSv1BiRpc.Call(utils.SessionSv1DeactivateSessions, &utils.SessionIDsWithAPIOpts{}, &reply)
- if err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: OK, received : %+v", reply)
- }
- if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, new(utils.SessionFilter), &aSessions); err != nil && err.Error() != utils.NotFoundCaps {
- t.Error(err)
- }
- if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, new(utils.SessionFilter), &pSessions); err != nil {
- t.Error(err)
- } else if len(pSessions) != 3 {
- t.Errorf("Expecting: 2, received: %+v", len(pSessions))
- }
-}
-
-func testSSv1ItAuthNotFoundCharger(t *testing.T) {
- authUsage := 5 * time.Minute
- args := &sessions.V1AuthorizeArgs{
- GetMaxUsage: true,
- CGREvent: &utils.CGREvent{
- Tenant: "Unexist",
- ID: "testSSv1ItAuthNotFoundCharger",
- Event: map[string]interface{}{
- utils.Tenant: "Unexist",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItAuthNotFoundCharger",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.Usage: authUsage,
- },
- },
- }
- var rply sessions.V1AuthorizeReply
- if err := sSv1BiRpc.Call(utils.SessionSv1AuthorizeEvent, args,
- &rply); err == nil || err.Error() != utils.NewErrChargerS(utils.ErrNotFound).Error() {
- t.Errorf("Expecting: %+v, received: %+v", utils.NewErrChargerS(utils.ErrNotFound), err)
- }
-}
-
-func testSSv1ItInitiateSessionNotFoundCharger(t *testing.T) {
- initUsage := 5 * time.Minute
- args := &sessions.V1InitSessionArgs{
- InitSession: true,
- CGREvent: &utils.CGREvent{
- Tenant: "Unexist",
- ID: "testSSv1ItInitiateSessionNotFoundCharger",
- Event: map[string]interface{}{
- utils.Tenant: "Unexist",
- utils.ToR: utils.MetaVoice,
- utils.OriginID: "testSSv1ItInitiateSessionNotFoundCharger",
- utils.RequestType: sSV1RequestType,
- utils.AccountField: "1001",
- utils.Subject: "ANY2CNT",
- utils.Destination: "1002",
- utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
- utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
- utils.Usage: initUsage,
- },
- },
- }
- var rply sessions.V1InitSessionReply
- if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession,
- args, &rply); err == nil || err.Error() != utils.NewErrChargerS(utils.ErrNotFound).Error() {
- t.Errorf("Expecting: %+v, received: %+v", utils.NewErrChargerS(utils.ErrNotFound), err)
- }
-}
-
-func testSSv1ItStopCgrEngine(t *testing.T) {
- if err := sSv1BiRpc.Close(); err != nil { // Close the connection so we don't get EOF warnings from client
- t.Error(err)
- }
- if err := engine.KillEngine(1000); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/smg.go b/apier/v1/smg.go
deleted file mode 100644
index ac8a46813..000000000
--- a/apier/v1/smg.go
+++ /dev/null
@@ -1,68 +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 (
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/sessions"
-)
-
-func NewSMGenericV1(sS *sessions.SessionS, caps *engine.Caps) *SMGenericV1 {
- return &SMGenericV1{
- Ss: sS,
- caps: caps,
- }
-}
-
-// Exports RPC from SMGeneric
-// DEPRECATED, use SessionSv1 instead
-type SMGenericV1 struct {
- Ss *sessions.SessionS
- caps *engine.Caps
-}
-
-// Returns MaxUsage (for calls in seconds), -1 for no limit
-func (smgv1 *SMGenericV1) GetMaxUsage(ev map[string]interface{},
- maxUsage *float64) error {
- return smgv1.Ss.BiRPCV1GetMaxUsage(nil, ev, maxUsage)
-}
-
-// Called on session start, returns the maximum number of seconds the session can last
-func (smgv1 *SMGenericV1) InitiateSession(ev map[string]interface{},
- maxUsage *float64) error {
- return smgv1.Ss.BiRPCV1InitiateSession(nil, ev, maxUsage)
-}
-
-// Interim updates, returns remaining duration from the rater
-func (smgv1 *SMGenericV1) UpdateSession(ev map[string]interface{},
- maxUsage *float64) error {
- return smgv1.Ss.BiRPCV1UpdateSession(nil, ev, maxUsage)
-}
-
-// Called on session end, should stop debit loop
-func (smgv1 *SMGenericV1) TerminateSession(ev map[string]interface{},
- reply *string) error {
- return smgv1.Ss.BiRPCV1TerminateSession(nil, ev, reply)
-}
-
-// Called on session end, should send the CDR to CDRS
-func (smgv1 *SMGenericV1) ProcessCDR(ev map[string]interface{},
- reply *string) error {
- return smgv1.Ss.BiRPCV1ProcessCDR(nil, ev, reply)
-}
diff --git a/apier/v1/smgbirpc.go b/apier/v1/smgbirpc.go
deleted file mode 100644
index 57585b877..000000000
--- a/apier/v1/smgbirpc.go
+++ /dev/null
@@ -1,94 +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 (
- "github.com/cgrates/birpc/context"
-)
-
-// Publishes methods exported by SMGenericV1 as SMGenericV1 (so we can handle standard RPC methods via birpc socket)
-func (smgv1 *SMGenericV1) Handlers() map[string]interface{} {
- return map[string]interface{}{
- "SMGenericV1.GetMaxUsage": smgv1.BiRPCV1GetMaxUsage,
- "SMGenericV1.InitiateSession": smgv1.BiRPCV1InitiateSession,
- "SMGenericV1.UpdateSession": smgv1.BiRPCV1UpdateSession,
- "SMGenericV1.TerminateSession": smgv1.BiRPCV1TerminateSession,
- "SMGenericV1.ProcessCDR": smgv1.BiRPCV1ProcessCDR,
- }
-}
-
-/// Returns MaxUsage (for calls in seconds), -1 for no limit
-func (smgv1 *SMGenericV1) BiRPCV1GetMaxUsage(ctx *context.Context,
- ev map[string]interface{}, maxUsage *float64) (err error) {
- if smgv1.caps.IsLimited() {
- if err = smgv1.caps.Allocate(); err != nil {
- return
- }
- defer smgv1.caps.Deallocate()
- }
- return smgv1.Ss.BiRPCV1GetMaxUsage(ctx.Client, ev, maxUsage)
-}
-
-// Called on session start, returns the maximum number of seconds the session can last
-func (smgv1 *SMGenericV1) BiRPCV1InitiateSession(ctx *context.Context,
- ev map[string]interface{}, maxUsage *float64) (err error) {
- if smgv1.caps.IsLimited() {
- if err = smgv1.caps.Allocate(); err != nil {
- return
- }
- defer smgv1.caps.Deallocate()
- }
- return smgv1.Ss.BiRPCV1InitiateSession(ctx.Client, ev, maxUsage)
-}
-
-// Interim updates, returns remaining duration from the rater
-func (smgv1 *SMGenericV1) BiRPCV1UpdateSession(ctx *context.Context,
- ev map[string]interface{}, maxUsage *float64) (err error) {
- if smgv1.caps.IsLimited() {
- if err = smgv1.caps.Allocate(); err != nil {
- return
- }
- defer smgv1.caps.Deallocate()
- }
- return smgv1.Ss.BiRPCV1UpdateSession(ctx.Client, ev, maxUsage)
-}
-
-// Called on session end, should stop debit loop
-func (smgv1 *SMGenericV1) BiRPCV1TerminateSession(ctx *context.Context,
- ev map[string]interface{}, reply *string) (err error) {
- if smgv1.caps.IsLimited() {
- if err = smgv1.caps.Allocate(); err != nil {
- return
- }
- defer smgv1.caps.Deallocate()
- }
- return smgv1.Ss.BiRPCV1TerminateSession(ctx.Client, ev, reply)
-}
-
-// Called on session end, should send the CDR to CDRS
-func (smgv1 *SMGenericV1) BiRPCV1ProcessCDR(ctx *context.Context,
- ev map[string]interface{}, reply *string) (err error) {
- if smgv1.caps.IsLimited() {
- if err = smgv1.caps.Allocate(); err != nil {
- return
- }
- defer smgv1.caps.Deallocate()
- }
- return smgv1.Ss.BiRPCV1ProcessCDR(ctx.Client, ev, reply)
-}
diff --git a/apier/v1/stats.go b/apier/v1/stats.go
deleted file mode 100644
index b692ac154..000000000
--- a/apier/v1/stats.go
+++ /dev/null
@@ -1,210 +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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// GetStatQueueProfile returns a StatQueue profile
-func (apierSv1 *APIerSv1) GetStatQueueProfile(arg *utils.TenantID, reply *engine.StatQueueProfile) (err 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
- }
- sCfg, err := apierSv1.DataManager.GetStatQueueProfile(tnt, arg.ID,
- true, true, utils.NonTransactional)
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = *sCfg
- return
-}
-
-// GetStatQueueProfileIDs returns list of statQueueProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetStatQueueProfileIDs(args *utils.PaginatorWithTenant, stsPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.StatQueueProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *stsPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-// SetStatQueueProfile alters/creates a StatQueueProfile
-func (apierSv1 *APIerSv1) SetStatQueueProfile(arg *engine.StatQueueProfileWithAPIOpts, reply *string) (err error) {
- if missing := utils.MissingStructFields(arg.StatQueueProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if arg.Tenant == utils.EmptyString {
- arg.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err = apierSv1.DataManager.SetStatQueueProfile(arg.StatQueueProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheStatQueueProfiles and CacheStatQueues and store it in database
- //make 1 insert for both StatQueueProfile and StatQueue instead of 2
- loadID := time.Now().UnixNano()
- if err = apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheStatQueueProfiles: loadID, utils.CacheStatQueues: loadID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for StatQueueProfile
- if err = apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheStatQueueProfiles,
- arg.TenantID(), &arg.FilterIDs, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- var ttl *time.Duration
- if arg.TTL > 0 {
- ttl = &arg.TTL
- }
- sq := &engine.StatQueue{
- Tenant: arg.Tenant,
- ID: arg.ID,
- }
- if !arg.Stored { // for not stored queues create the metrics
- if sq, err = engine.NewStatQueue(arg.Tenant, arg.ID, arg.Metrics,
- arg.MinItems); err != nil {
- return err
- }
- }
- // for non stored we do not save the metrics
- if err = apierSv1.DataManager.SetStatQueue(sq,
- arg.Metrics, arg.MinItems, ttl, arg.QueueLength,
- !arg.Stored); err != nil {
- return err
- }
- //handle caching for StatQueues
- if err := apierSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), arg.Tenant, utils.CacheStatQueues,
- arg.TenantID(), nil, nil, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
-
- *reply = utils.OK
- return nil
-}
-
-// RemoveStatQueueProfile remove a specific stat configuration
-func (apierSv1 *APIerSv1) RemoveStatQueueProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.RemoveStatQueueProfile(tnt, args.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for StatQueueProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), tnt, utils.CacheStatQueueProfiles,
- utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.DataManager.RemoveStatQueue(tnt, args.ID, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheStatQueueProfiles and CacheStatQueues and store it in database
- //make 1 insert for both StatQueueProfile and StatQueue instead of 2
- loadID := time.Now().UnixNano()
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheStatQueueProfiles: loadID, utils.CacheStatQueues: loadID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for StatQueues
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), tnt, utils.CacheStatQueues,
- utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// NewStatSv1 initializes StatSV1
-func NewStatSv1(sS *engine.StatService) *StatSv1 {
- return &StatSv1{sS: sS}
-}
-
-// StatSv1 exports RPC from RLs
-type StatSv1 struct {
- sS *engine.StatService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (stsv1 *StatSv1) Call(ctx *context.Context, serviceMethod string, args, reply interface{}) error {
- return utils.APIerRPCCall(stsv1, serviceMethod, args, reply)
-}
-
-// GetQueueIDs returns list of queueIDs registered for a tenant
-func (stsv1 *StatSv1) GetQueueIDs(tenant *utils.TenantWithAPIOpts, qIDs *[]string) error {
- return stsv1.sS.V1GetQueueIDs(tenant.Tenant, qIDs)
-}
-
-// ProcessEvent returns processes a new Event
-func (stsv1 *StatSv1) ProcessEvent(args *engine.StatsArgsProcessEvent, reply *[]string) error {
- return stsv1.sS.V1ProcessEvent(args, reply)
-}
-
-// GetStatQueuesForEvent returns the list of queues IDs in the system
-func (stsv1 *StatSv1) GetStatQueuesForEvent(args *engine.StatsArgsProcessEvent, reply *[]string) (err error) {
- return stsv1.sS.V1GetStatQueuesForEvent(args, reply)
-}
-
-// GetStatQueue returns a StatQueue object
-func (stsv1 *StatSv1) GetStatQueue(args *utils.TenantIDWithAPIOpts, reply *engine.StatQueue) (err error) {
- return stsv1.sS.V1GetStatQueue(args, reply)
-}
-
-// GetQueueStringMetrics returns the string metrics for a Queue
-func (stsv1 *StatSv1) GetQueueStringMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]string) (err error) {
- return stsv1.sS.V1GetQueueStringMetrics(args.TenantID, reply)
-}
-
-// GetQueueFloatMetrics returns the float metrics for a Queue
-func (stsv1 *StatSv1) GetQueueFloatMetrics(args *utils.TenantIDWithAPIOpts, reply *map[string]float64) (err error) {
- return stsv1.sS.V1GetQueueFloatMetrics(args.TenantID, reply)
-}
-
-// ResetStatQueue resets the stat queue
-func (stsv1 *StatSv1) ResetStatQueue(tntID *utils.TenantIDWithAPIOpts, reply *string) error {
- return stsv1.sS.V1ResetStatQueue(tntID.TenantID, reply)
-}
-
-// Ping .
-func (stsv1 *StatSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/stats_it_test.go b/apier/v1/stats_it_test.go
deleted file mode 100644
index c82df93b0..000000000
--- a/apier/v1/stats_it_test.go
+++ /dev/null
@@ -1,1735 +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 (
- "math/rand"
- "net/rpc"
- "path"
- "reflect"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- stsV1CfgPath string
- stsV1Cfg *config.CGRConfig
- stsV1Rpc *rpc.Client
- statConfig *engine.StatQueueProfileWithAPIOpts
- stsV1ConfDIR string //run tests for specific configuration
-
- evs = []*utils.CGREvent{
- {
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 135 * time.Second,
- utils.Cost: 123.0}},
- {
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second}},
- {
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.SetupTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 0}},
- }
-
- sTestsStatSV1 = []func(t *testing.T){
- testV1STSLoadConfig,
- testV1STSInitDataDb,
- testV1STSStartEngine,
- testV1STSRpcConn,
- testV1STSFromFolder,
- testV1STSGetStats,
- testV1STSProcessEvent,
- testV1STSGetStatsAfterRestart,
- testV1STSSetStatQueueProfile,
- testV1STSGetStatQueueProfileIDs,
- testV1STSUpdateStatQueueProfile,
- testV1STSRemoveStatQueueProfile,
- testV1STSStatsPing,
- testV1STSProcessMetricsWithFilter,
- testV1STSProcessStaticMetrics,
- testV1STSProcessStatWithThreshold,
- testV1STSV1GetQueueIDs,
- testV1STSV1GetStatQueuesForEventWithoutTenant,
- testV1STSV1StatSv1GetQueueStringMetricsWithoutTenant,
- testV1STSV1StatSv1ResetAction,
- testV1STSGetStatQueueProfileWithoutTenant,
- testV1STSRemStatQueueProfileWithoutTenant,
- testV1STSProcessCDRStat,
- testV1STSOverWriteStats,
- testV1STSProcessStatWithThreshold2,
- testV1STSSimulateAccountUpdate,
- testV1STSGetStatQueueWithoutExpired,
- testV1STSGetStatQueueWithoutStored,
- testV1STSStopEngine,
- testV1STSStartEngine,
- testV1STSRpcConn,
- testV1STSCheckMetricsAfterRestart,
- testV1STSStopEngine,
- //cache test
- testV1STSLoadConfig,
- testV1STSInitDataDb,
- testV1STSStartEngine,
- testV1STSRpcConn,
- testStatSCacheProcessEventNotFound,
- testStatSCacheSet,
- testStatSCacheProcessEventNotFound,
- testStatSCacheReload,
- testStatSCacheProcessEventFound,
- testV1STSStopEngine,
- }
-)
-
-func init() {
- rand.Seed(time.Now().UnixNano()) // used in benchmarks
-}
-
-//Test start here
-func TestSTSV1IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- stsV1ConfDIR = "tutinternal"
- sTestsStatSV1 = sTestsStatSV1[:len(sTestsStatSV1)-4]
- case utils.MetaMySQL:
- stsV1ConfDIR = "tutmysql"
- case utils.MetaMongo:
- stsV1ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsStatSV1 {
- t.Run(stsV1ConfDIR, stest)
- }
-}
-
-func testV1STSLoadConfig(t *testing.T) {
- var err error
- stsV1CfgPath = path.Join(*dataDir, "conf", "samples", stsV1ConfDIR)
- if stsV1Cfg, err = config.NewCGRConfigFromPath(stsV1CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1STSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(stsV1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1STSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(stsV1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1STSRpcConn(t *testing.T) {
- var err error
- stsV1Rpc, err = newRPCClient(stsV1Cfg.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 testV1STSFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
- if err := stsV1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testV1STSGetStats(t *testing.T) {
- var reply []string
- expectedIDs := []string{"Stats1"}
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedIDs, reply) {
- t.Errorf("expecting: %+v, received reply: %s", expectedIDs, reply)
- }
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaASR: utils.NotAvailable,
- utils.MetaACD: utils.NotAvailable,
- utils.MetaTCC: utils.NotAvailable,
- utils.MetaTCD: utils.NotAvailable,
- utils.MetaACC: utils.NotAvailable,
- utils.MetaPDD: utils.NotAvailable,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable,
- utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}},
- &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSV1StatSv1GetQueueStringMetricsWithoutTenant(t *testing.T) {
- var reply []string
- expectedIDs := []string{"CustomStatProfile", "Stats1", "StaticStatQueue", "StatWithThreshold"}
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs,
- &utils.TenantWithAPIOpts{}, &reply); err != nil {
- t.Error(err)
- } else {
- sort.Strings(reply)
- sort.Strings(expectedIDs)
- if !reflect.DeepEqual(expectedIDs, reply) {
- t.Errorf("expecting: %+v, received reply: %s", expectedIDs, reply)
- }
- }
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaACD: "12s",
- utils.MetaTCD: "18s",
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.CustomValue: "10",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: expectedIDs[0]}},
- &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", utils.ToJSON(expectedMetrics), utils.ToJSON(metrics))
- }
-}
-func testV1STSV1StatSv1ResetAction(t *testing.T) {
- var reply string
- if err := stsV1Rpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{
- ActionsId: "ACT_RESET_STS",
- Actions: []*utils.TPAction{{Identifier: utils.MetaResetStatQueue, ExtraParameters: "cgrates.org:CustomStatProfile"}},
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
- }
- attrs := utils.AttrExecuteAction{Tenant: "cgrates.org", ActionsId: "ACT_RESET_STS"}
- if err := stsV1Rpc.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil {
- t.Error(err)
- }
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaACD: utils.NotAvailable,
- utils.MetaTCD: utils.NotAvailable,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.CustomValue: utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "CustomStatProfile"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", utils.ToJSON(expectedMetrics), utils.ToJSON(metrics))
- }
-}
-
-func testV1STSProcessEvent(t *testing.T) {
- var reply []string
- expected := []string{"Stats1"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 135 * time.Second,
- utils.Cost: 123.0,
- utils.PDD: 12 * time.Second,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- //process with one event (should be N/A becaus MinItems is 2)
- expectedMetrics := map[string]string{
- utils.MetaASR: utils.NotAvailable,
- utils.MetaACD: utils.NotAvailable,
- utils.MetaTCC: utils.NotAvailable,
- utils.MetaTCD: utils.NotAvailable,
- utils.MetaACC: utils.NotAvailable,
- utils.MetaPDD: utils.NotAvailable,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable,
- utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: utils.NotAvailable,
- }
- var metrics map[string]string
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-
- //process with one event (should be N/A becaus MinItems is 2)
- expectedFloatMetrics := map[string]float64{
- utils.MetaASR: -1.0,
- utils.MetaACD: -1.0,
- utils.MetaTCC: -1.0,
- utils.MetaTCD: -1.0,
- utils.MetaACC: -1.0,
- utils.MetaPDD: -1.0,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: -1.0,
- utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: -1.0,
- }
- var floatMetrics map[string]float64
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &floatMetrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedFloatMetrics, floatMetrics) {
- t.Errorf("expecting: %+v, received reply: %+v", expectedFloatMetrics, floatMetrics)
- }
-
- args2 := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.Cost: 12.1,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args2, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- args3 := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.SetupTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 0,
- utils.Cost: 0,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args3, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply)
- }
- expectedMetrics2 := map[string]string{
- utils.MetaASR: "66.66667%",
- utils.MetaACD: "1m0s",
- utils.MetaACC: "45.03333",
- utils.MetaTCD: "3m0s",
- utils.MetaTCC: "135.1",
- utils.MetaPDD: utils.NotAvailable,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "180000000000",
- utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "60000000000",
- }
- var metrics2 map[string]string
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &metrics2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics2, metrics2) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics2, metrics2)
- }
-
- expectedFloatMetrics2 := map[string]float64{
- utils.MetaASR: 66.66667,
- utils.MetaACD: 60,
- utils.MetaTCC: 135.1,
- utils.MetaTCD: 180,
- utils.MetaACC: 45.03333,
- utils.MetaPDD: -1.0,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: 180000000000,
- utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: 60000000000,
- }
- var floatMetrics2 map[string]float64
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &floatMetrics2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedFloatMetrics2, floatMetrics2) {
- t.Errorf("expecting: %+v, received reply: %+v", expectedFloatMetrics2, floatMetrics2)
- }
-
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueFloatMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "Stats1"}}, &floatMetrics2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedFloatMetrics2, floatMetrics2) {
- t.Errorf("expecting: %+v, received reply: %+v", expectedFloatMetrics2, floatMetrics2)
- }
-
-}
-
-func testV1STSGetStatsAfterRestart(t *testing.T) {
- // in case of internal we skip this test
- if stsV1ConfDIR == "tutinternal" {
- t.SkipNow()
- }
- // time.Sleep(time.Second)
- if _, err := engine.StopStartEngine(stsV1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
- var err error
- stsV1Rpc, err = newRPCClient(stsV1Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
-
- //get stats metrics after restart
- expectedMetrics2 := map[string]string{
- utils.MetaASR: "66.66667%",
- utils.MetaACD: "1m0s",
- utils.MetaACC: "45.03333",
- utils.MetaTCD: "3m0s",
- utils.MetaTCC: "135.1",
- utils.MetaPDD: utils.NotAvailable,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "180000000000",
- utils.MetaAverage + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.Usage: "60000000000",
- }
- var metrics2 map[string]string
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Stats1"}}, &metrics2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics2, metrics2) {
- t.Errorf("After restat expecting: %+v, received reply: %s", expectedMetrics2, metrics2)
- }
-}
-
-func testV1STSSetStatQueueProfile(t *testing.T) {
- var result string
- var reply *engine.StatQueueProfile
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "TEST_PROFILE1",
- FilterIDs: []string{"*wrong:inline"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaACD,
- },
- {
- MetricID: utils.MetaTCD,
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
-
- expErr := "SERVER_ERROR: broken reference to filter: *wrong:inline for item with ID: cgrates.org:TEST_PROFILE1"
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
- statConfig.FilterIDs = []string{"FLTR_1"}
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_1",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
-}
-
-func testV1STSGetStatQueueProfileIDs(t *testing.T) {
- expected := []string{"Stats1", "TEST_PROFILE1"}
- var result []string
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testV1STSUpdateStatQueueProfile(t *testing.T) {
- var result string
- filter = &engine.FilterWithAPIOpts{
- Filter: &engine.Filter{
- Tenant: "cgrates.org",
- ID: "FLTR_2",
- Rules: []*engine.FilterRule{
- {
- Element: utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + utils.AccountField,
- Type: utils.MetaString,
- Values: []string{"1001"},
- },
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetFilter, filter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- statConfig.FilterIDs = []string{"FLTR_1", "FLTR_2"}
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
-}
-
-func testV1STSRemoveStatQueueProfile(t *testing.T) {
- var resp string
- if err := stsV1Rpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var sqp *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &sqp); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TEST_PROFILE1"}, &resp); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testV1STSProcessMetricsWithFilter(t *testing.T) {
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "CustomStatProfile",
- FilterIDs: []string{"*string:~*req.DistinctVal:RandomVal"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaACD,
- FilterIDs: []string{"*gt:~*req.Usage:10s"},
- },
- {
- MetricID: utils.MetaTCD,
- FilterIDs: []string{"*gt:~*req.Usage:5s"},
- },
- {
- MetricID: utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue",
- FilterIDs: []string{"*exists:~*req.CustomValue:", "*gte:~*req.CustomValue:10.0"},
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- //set the custom statProfile
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //verify it
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "CustomStatProfile"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
- //verify metrics
- expectedIDs := []string{"CustomStatProfile"}
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaACD: utils.NotAvailable,
- utils.MetaTCD: utils.NotAvailable,
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue": utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- //process event
- var reply2 []string
- expected := []string{"CustomStatProfile"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- "DistinctVal": "RandomVal",
- utils.Usage: 6 * time.Second,
- "CustomValue": 7.0,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- expectedMetrics = map[string]string{
- utils.MetaACD: utils.NotAvailable,
- utils.MetaTCD: "6s",
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue": utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- //second process
- args = engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- "DistinctVal": "RandomVal",
- utils.Usage: 12 * time.Second,
- "CustomValue": 10.0,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
-
- expectedMetrics = map[string]string{
- utils.MetaACD: "12s",
- utils.MetaTCD: "18s",
- utils.MetaSum + utils.HashtagSep + utils.DynamicDataPrefix + utils.MetaReq + utils.NestingSep + "CustomValue": "10",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSProcessStaticMetrics(t *testing.T) {
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "StaticStatQueue",
- FilterIDs: []string{"*string:~*req.StaticMetrics:StaticMetrics"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "1",
- },
- {
- MetricID: utils.MetaAverage + utils.HashtagSep + "2",
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- //set the custom statProfile
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //verify it
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "StaticStatQueue"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
- //verify metrics
- expectedIDs := []string{"StaticStatQueue"}
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaSum + utils.HashtagSep + "1": utils.NotAvailable,
- utils.MetaAverage + utils.HashtagSep + "2": utils.NotAvailable,
- }
- //process event
- var reply2 []string
- expected := []string{"StaticStatQueue"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- "StaticMetrics": "StaticMetrics",
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "1": "1",
- utils.MetaAverage + utils.HashtagSep + "2": "2",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- //second process
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "1": "2",
- utils.MetaAverage + utils.HashtagSep + "2": "2",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-
- if err := stsV1Rpc.Call(utils.StatSv1ResetStatQueue,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Errorf("expecting: %+v, received reply: %s", utils.OK, result)
- }
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "1": utils.NotAvailable,
- utils.MetaAverage + utils.HashtagSep + "2": utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSStatsPing(t *testing.T) {
- var resp string
- if err := stsV1Rpc.Call(utils.StatSv1Ping, new(utils.CGREvent), &resp); err != nil {
- t.Error(err)
- } else if resp != utils.Pong {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testV1STSProcessStatWithThreshold(t *testing.T) {
- stTh := &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "StatWithThreshold",
- FilterIDs: []string{"*string:~*req.CustomEvent:CustomEvent"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaTCD,
- },
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "2",
- },
- },
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, stTh, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- thSts := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Stat",
- FilterIDs: []string{"*string:~*req.EventType:StatUpdate",
- "*string:~*req.StatID:StatWithThreshold", "*exists:~*req.*tcd:", "*gte:~*req.*tcd:1s"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Weight: 20.0,
- ActionIDs: []string{"LOG_WARNING"},
- Async: true,
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetThresholdProfile, thSts, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //process event
- var reply2 []string
- expected := []string{"StatWithThreshold"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- "CustomEvent": "CustomEvent",
- utils.Usage: 45 * time.Second,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
-
- var td engine.Threshold
- eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_Stat", Hits: 1}
- if err := stsV1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Stat"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd.Hits, td.Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- }
-}
-
-func testV1STSProcessCDRStat(t *testing.T) {
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "StatForCDR",
- FilterIDs: []string{"*string:~*req.OriginID:dsafdsaf"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "~*req.CostDetails.Usage",
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 50,
- MinItems: 1,
- },
- }
- //set the custom statProfile
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //verify it
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "StatForCDR"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
- //verify metrics
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaSum + utils.HashtagSep + "1": utils.NotAvailable,
- }
- //process event
- cc := &engine.CallCost{
- Category: "generic",
- Tenant: "cgrates.org",
- Subject: "1001",
- Account: "1001",
- Destination: "data",
- ToR: "*data",
- Cost: 1.01,
- AccountSummary: &engine.AccountSummary{
- Tenant: "cgrates.org",
- ID: "AccountFromAccountSummary",
- BalanceSummaries: []*engine.BalanceSummary{
- {
- UUID: "f9be602747f4",
- ID: "monetary",
- Type: utils.MetaMonetary,
- Value: 0.5,
- },
- {
- UUID: "2e02510ab90a",
- ID: "voice",
- Type: utils.MetaVoice,
- Value: 10,
- },
- },
- },
- }
-
- cdr := &engine.CDR{
- CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()),
- OrderID: 123,
- ToR: utils.MetaVoice,
- OriginID: "dsafdsaf",
- OriginHost: "192.168.1.1",
- Source: utils.UnitTest,
- RequestType: utils.MetaRated,
- Tenant: "cgrates.org",
- Category: "call",
- Account: "1002",
- Subject: "1001",
- Destination: "+4986517174963",
- SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC),
- AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC),
- RunID: utils.MetaDefault,
- Usage: 10 * time.Second,
- ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"},
- Cost: 1.01,
- CostDetails: engine.NewEventCostFromCallCost(cc, "TestCDRTestCDRAsMapStringIface2", utils.MetaDefault),
- }
- cdr.CostDetails.Compute()
- cdr.CostDetails.Usage = utils.DurationPointer(10 * time.Second)
-
- var reply2 []string
- expected := []string{"StatForCDR"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: cdr.AsCGREvent(),
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*req.CostDetails.Usage": "10000000000",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForCDR"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- //second process
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*req.CostDetails.Usage": "20000000000",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForCDR"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSOverWriteStats(t *testing.T) {
- initStat := &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "InitStat",
- FilterIDs: []string{"*string:~*req.OriginID:dsafdsaf"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "1",
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- //set the custom statProfile
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, initStat, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //verify it
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "InitStat"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(initStat.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(initStat.StatQueueProfile), utils.ToJSON(reply))
- }
-
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaSum + utils.HashtagSep + "1": utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "InitStat"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- // set the new profile with other metric and make sure the statQueue is updated
- initStat2 := &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "InitStat",
- FilterIDs: []string{"*string:~*req.OriginID:dsafdsaf"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "~*req.Test",
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, initStat2, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- var metrics2 map[string]string
- expectedMetrics2 := map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*req.Test": utils.NotAvailable,
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "InitStat"}}, &metrics2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics2, metrics2) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics2, metrics2)
- }
-}
-
-func testV1STSProcessStatWithThreshold2(t *testing.T) {
- stTh := &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "StatWithThreshold2",
- FilterIDs: []string{"*string:~*req.CustomEvent2:CustomEvent2"}, //custom filter for event
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaTCD,
- },
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "2",
- },
- },
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, stTh, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- thSts := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Stat2",
- FilterIDs: []string{"*string:~*req.EventType:StatUpdate",
- "*string:~*req.StatID:StatWithThreshold2", "*exists:~*req.*sum#2:", "*gt:~*req.*sum#2:1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Weight: 20.0,
- ActionIDs: []string{"LOG_WARNING"},
- Async: true,
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetThresholdProfile, thSts, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //process event
- var reply2 []string
- expected := []string{"StatWithThreshold2"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- "CustomEvent2": "CustomEvent2",
- utils.Usage: 45 * time.Second,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
-
- var td engine.Threshold
- eTd := engine.Threshold{Tenant: "cgrates.org", ID: "THD_Stat2", Hits: 1}
- if err := stsV1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Stat"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd.Hits, td.Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- }
-}
-
-func testV1STSStopEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
-
-// Run benchmarks with:
-// BenchmarkStatSV1SetEvent 5000 263437 ns/op
-func BenchmarkSTSV1SetEvent(b *testing.B) {
- if _, err := engine.StopStartEngine(stsV1CfgPath, 1000); err != nil {
- b.Fatal(err)
- }
- b.StopTimer()
- var err error
- stsV1Rpc, err = newRPCClient(stsV1Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- b.Fatal("Could not connect to rater: ", err.Error())
- }
- var reply string
- b.StartTimer()
- for i := 0; i < b.N; i++ {
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &evs[rand.Intn(len(evs))],
- &reply); err != nil {
- b.Error(err)
- } else if reply != utils.OK {
- b.Errorf("received reply: %s", reply)
- }
- }
-}
-
-// BenchmarkStatSV1GetQueueStringMetrics 20000 94607 ns/op
-func BenchmarkSTSV1GetQueueStringMetrics(b *testing.B) {
- for i := 0; i < b.N; i++ {
- var metrics map[string]string
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "STATS_1"}},
- &metrics); err != nil {
- b.Error(err)
- }
- }
-}
-
-func testV1STSGetStatQueueProfileWithoutTenant(t *testing.T) {
- statConfig := &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- ID: "TEST_PROFILE10",
- FilterIDs: []string{"FLTR_1"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 10,
- TTL: 10 * time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaACD,
- },
- {
- MetricID: utils.MetaTCD,
- },
- },
- ThresholdIDs: []string{"Val1", "Val2"},
- Blocker: true,
- Stored: true,
- Weight: 20,
- MinItems: 1,
- },
- }
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- statConfig.Tenant = "cgrates.org"
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{ID: "TEST_PROFILE10"},
- &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply, statConfig.StatQueueProfile) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
-}
-
-func testV1STSRemStatQueueProfileWithoutTenant(t *testing.T) {
- var reply string
- if err := stsV1Rpc.Call(utils.APIerSv1RemoveStatQueueProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "TEST_PROFILE10"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{ID: "TEST_PROFILE10"},
- &result); err == nil || utils.ErrNotFound.Error() != err.Error() {
- t.Error(err)
- }
-}
-
-func testV1STSV1GetQueueIDs(t *testing.T) {
- expected := []string{"StatWithThreshold", "Stats1", "StaticStatQueue", "CustomStatProfile"}
- sort.Strings(expected)
- var qIDs []string
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs,
- &utils.TenantWithAPIOpts{},
- &qIDs); err != nil {
- t.Error(err)
- } else {
- sort.Strings(qIDs)
- if !reflect.DeepEqual(qIDs, expected) {
- t.Errorf("Expected %+v \n ,received %+v", expected, qIDs)
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueIDs,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"},
- &qIDs); err != nil {
- t.Error(err)
- } else {
- sort.Strings(qIDs)
- if !reflect.DeepEqual(qIDs, expected) {
- t.Errorf("Expected %+v \n ,received %+v", expected, qIDs)
- }
- }
- }
-}
-
-func testV1STSV1GetStatQueuesForEventWithoutTenant(t *testing.T) {
- var reply []string
- estats := []string{"Stats1"}
- if err := stsV1Rpc.Call(utils.StatSv1GetStatQueuesForEvent,
- &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- ID: "GetStats",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 45 * time.Second,
- utils.RunID: utils.MetaDefault,
- utils.Cost: 10.0,
- utils.Destination: "1001",
- },
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "stat12345",
- },
- },
- }, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(estats, reply) {
- t.Errorf("expecting: %+v, received reply: %v", estats, reply)
- }
-}
-
-func testV1STSSimulateAccountUpdate(t *testing.T) {
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "StatForAccountUpdate",
- FilterIDs: []string{
- "*string:~*opts.*eventType:AccountUpdate",
- "*string:~*asm.ID:testV1STSSimulateAccountUpdate",
- },
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- },
- QueueLength: 100,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{
- {
- MetricID: utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value",
- },
- },
- ThresholdIDs: []string{"*none"},
- Blocker: true,
- Stored: true,
- Weight: 50,
- MinItems: 1,
- },
- }
- //set the custom statProfile
- var result string
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- //verify it
- var reply *engine.StatQueueProfile
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
- //verify metrics
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": utils.NotAvailable,
- }
-
- var reply2 []string
- expected := []string{"StatForAccountUpdate"}
-
- attrSetBalance := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "testV1STSSimulateAccountUpdate",
- BalanceType: "*monetary",
- Value: 1.5,
- Balance: map[string]interface{}{
- utils.ID: "HolidayBalance",
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &result); err != nil {
- t.Error("Got error on APIerSv1.SetBalance: ", err.Error())
- } else if result != utils.OK {
- t.Errorf("Calling APIerSv1.SetBalance received: %s", result)
- }
-
- var acnt *engine.Account
- attrs := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "testV1STSSimulateAccountUpdate",
- }
- if err := stsV1Rpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- }
-
- acntUpdateEv := &engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{ // hitting TH_ACNT_UPDATE_EV
- Tenant: "cgrates.org",
- ID: "SIMULATE_ACNT_UPDATE_EV",
- Event: acnt.AsAccountSummary().AsMapInterface(),
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
-
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &acntUpdateEv, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": "1.5",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- //second process
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &acntUpdateEv, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- expectedMetrics = map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": "3",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSGetStatQueueWithoutExpired(t *testing.T) {
- var result string
- var reply *engine.StatQueueProfile
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "Sq1Nanao",
- FilterIDs: []string{"*string:~*req.StatQ:Sq1Nanao"},
- QueueLength: 10,
- TTL: 1,
- Metrics: []*engine.MetricWithFilters{{
- MetricID: utils.MetaTCD,
- }},
- Blocker: true,
- Stored: true,
- Weight: 200,
- MinItems: 1,
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1Nanao"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
-
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaTCD: utils.NotAvailable,
- }
- //process event
- var reply2 []string
- expected := []string{"Sq1Nanao"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "event1012",
- Event: map[string]interface{}{
- "StatQ": "Sq1Nanao",
- utils.Usage: 10,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1Nanao"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSGetStatQueueWithoutStored(t *testing.T) {
- var result string
- var reply *engine.StatQueueProfile
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "Sq1NotStored",
- FilterIDs: []string{"*string:~*req.StatQ:Sq1NotStored"},
- QueueLength: 10,
- TTL: time.Second,
- Metrics: []*engine.MetricWithFilters{{
- MetricID: utils.MetaTCD,
- }},
- Blocker: true,
- Weight: 200,
- MinItems: 1,
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1GetStatQueueProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(statConfig.StatQueueProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(statConfig.StatQueueProfile), utils.ToJSON(reply))
- }
-
- var metrics map[string]string
- expectedMetrics := map[string]string{
- utils.MetaTCD: "10s",
- }
- //process event
- var reply2 []string
- expected := []string{"Sq1NotStored"}
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "Sq1NotStored",
- Event: map[string]interface{}{
- "StatQ": "Sq1NotStored",
- utils.Usage: 10 * time.Second,
- },
- },
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(reply2, expected) {
- t.Errorf("Expecting: %+v, received: %+v", expected, reply2)
- }
- //verify metrics after first process
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testV1STSCheckMetricsAfterRestart(t *testing.T) {
- var metrics map[string]string
-
- expectedMetrics := map[string]string{
- utils.MetaSum + utils.HashtagSep + "~*asm.BalanceSummaries.HolidayBalance.Value": "3",
- }
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "StatForAccountUpdate"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
- expectedMetrics = map[string]string{
- utils.MetaTCD: utils.NotAvailable,
- }
- metrics = map[string]string{}
- if err := stsV1Rpc.Call(utils.StatSv1GetQueueStringMetrics,
- &utils.TenantIDWithAPIOpts{
- TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "Sq1NotStored"}}, &metrics); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedMetrics, metrics) {
- t.Errorf("expecting: %+v, received reply: %s", expectedMetrics, metrics)
- }
-}
-
-func testStatSCacheProcessEventNotFound(t *testing.T) {
- var reply []string
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "STAT_CACHE",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 135 * time.Second,
- utils.Cost: 123.0,
- utils.PDD: 12 * time.Second,
- },
- },
- StatIDs: []string{"STAT_CACHE"},
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-func testStatSCacheProcessEventFound(t *testing.T) {
- var reply []string
- args := engine.StatsArgsProcessEvent{
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "STAT_CACHE",
- Event: map[string]interface{}{
- utils.AccountField: "1001",
- utils.AnswerTime: time.Date(2014, 7, 14, 14, 25, 0, 0, time.UTC),
- utils.Usage: 135 * time.Second,
- utils.Cost: 123.0,
- utils.PDD: 12 * time.Second,
- },
- },
- StatIDs: []string{"STAT_CACHE"},
- }
- if err := stsV1Rpc.Call(utils.StatSv1ProcessEvent, &args, &reply); err != nil {
- t.Error(err)
- }
-}
-
-func testStatSCacheSet(t *testing.T) {
- var result string
- statConfig = &engine.StatQueueProfileWithAPIOpts{
- StatQueueProfile: &engine.StatQueueProfile{
- Tenant: "cgrates.org",
- ID: "STAT_CACHE",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- if err := stsV1Rpc.Call(utils.APIerSv1SetStatQueueProfile, statConfig, &result); err != nil {
- t.Fatalf("Expected error: %+v, received: %+v", nil, err)
- }
-}
-
-func testStatSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.StatsQueueProfileIDs: {"cgrates.org:STAT_CACHE"},
- },
- }
- var reply string
- if err := stsV1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/thresholds.go b/apier/v1/thresholds.go
deleted file mode 100644
index 22f0a4028..000000000
--- a/apier/v1/thresholds.go
+++ /dev/null
@@ -1,201 +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 FITNEtS 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/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// NewThresholdSv1 initializes ThresholdSV1
-func NewThresholdSv1(tS *engine.ThresholdService) *ThresholdSv1 {
- return &ThresholdSv1{tS: tS}
-}
-
-// ThresholdSv1 exports RPC from RLs
-type ThresholdSv1 struct {
- tS *engine.ThresholdService
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (tSv1 *ThresholdSv1) Call(ctx *context.Context, serviceMethod string, args, reply interface{}) error {
- return utils.APIerRPCCall(tSv1, serviceMethod, args, reply)
-}
-
-// GetThresholdIDs returns list of threshold IDs registered for a tenant
-func (tSv1 *ThresholdSv1) GetThresholdIDs(tenant *utils.TenantWithAPIOpts, tIDs *[]string) error {
- return tSv1.tS.V1GetThresholdIDs(tenant.Tenant, tIDs)
-}
-
-// GetThresholdsForEvent returns a list of thresholds matching an event
-func (tSv1 *ThresholdSv1) GetThresholdsForEvent(args *engine.ThresholdsArgsProcessEvent, reply *engine.Thresholds) error {
- return tSv1.tS.V1GetThresholdsForEvent(args, reply)
-}
-
-// GetThreshold queries a Threshold
-func (tSv1 *ThresholdSv1) GetThreshold(tntID *utils.TenantIDWithAPIOpts, t *engine.Threshold) error {
- return tSv1.tS.V1GetThreshold(tntID.TenantID, t)
-}
-
-// ProcessEvent will process an Event
-func (tSv1 *ThresholdSv1) ProcessEvent(args *engine.ThresholdsArgsProcessEvent, tIDs *[]string) error {
- return tSv1.tS.V1ProcessEvent(args, tIDs)
-}
-
-// ResetThreshold resets the threshold hits
-func (tSv1 *ThresholdSv1) ResetThreshold(tntID *utils.TenantIDWithAPIOpts, reply *string) error {
- return tSv1.tS.V1ResetThreshold(tntID.TenantID, reply)
-}
-
-// GetThresholdProfile returns a Threshold Profile
-func (apierSv1 *APIerSv1) GetThresholdProfile(arg *utils.TenantID, reply *engine.ThresholdProfile) (err 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
- }
- th, err := apierSv1.DataManager.GetThresholdProfile(tnt, arg.ID, true, true, utils.NonTransactional)
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = *th
- return
-}
-
-// GetThresholdProfileIDs returns list of thresholdProfile IDs registered for a tenant
-func (apierSv1 *APIerSv1) GetThresholdProfileIDs(args *utils.PaginatorWithTenant, thPrfIDs *[]string) error {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- prfx := utils.ThresholdProfilePrefix + tnt + utils.ConcatenatedKeySep
- keys, err := apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), 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):]
- }
- *thPrfIDs = args.PaginateStringSlice(retIDs)
- return nil
-}
-
-// GetThresholdProfileIDsCount sets in reply var the total number of ThresholdProfileIDs registered for the received tenant
-// returns ErrNotFound in case of 0 ThresholdProfileIDs
-func (apierSv1 *APIerSv1) GetThresholdProfileIDsCount(args *utils.TenantWithAPIOpts, reply *int) (err error) {
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- var keys []string
- prfx := utils.ThresholdProfilePrefix + tnt + utils.ConcatenatedKeySep
- if keys, err = apierSv1.DataManager.DataDB().GetKeysForPrefix(context.TODO(), prfx); err != nil {
- return err
- }
- if len(keys) == 0 {
- return utils.ErrNotFound
- }
- *reply = len(keys)
- return nil
-}
-
-// SetThresholdProfile alters/creates a ThresholdProfile
-func (apierSv1 *APIerSv1) SetThresholdProfile(args *engine.ThresholdProfileWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args.ThresholdProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if args.Tenant == utils.EmptyString {
- args.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.SetThresholdProfile(args.ThresholdProfile, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheThresholdProfiles and CacheThresholds and store it in database
- //make 1 insert for both ThresholdProfile and Threshold instead of 2
- loadID := time.Now().UnixNano()
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheThresholdProfiles: loadID, utils.CacheThresholds: loadID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for ThresholdProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), args.Tenant, utils.CacheThresholdProfiles,
- args.TenantID(), &args.FilterIDs, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.DataManager.SetThreshold(&engine.Threshold{Tenant: args.Tenant, ID: args.ID}, args.MinSleep, false); err != nil {
- return err
- }
- //handle caching for Threshold
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), args.Tenant, utils.CacheThresholds,
- args.TenantID(), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
-
- *reply = utils.OK
- return nil
-}
-
-// RemoveThresholdProfile removes a specific Threshold Profile
-func (apierSv1 *APIerSv1) RemoveThresholdProfile(args *utils.TenantIDWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(args, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tnt := args.Tenant
- if tnt == utils.EmptyString {
- tnt = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.DataManager.RemoveThresholdProfile(tnt, args.ID, utils.NonTransactional, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for ThresholdProfile
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), tnt, utils.CacheThresholdProfiles,
- utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := apierSv1.DataManager.RemoveThreshold(tnt, args.ID, utils.NonTransactional); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheThresholdProfiles and CacheThresholds and store it in database
- //make 1 insert for both ThresholdProfile and Threshold instead of 2
- loadID := time.Now().UnixNano()
- if err := apierSv1.DataManager.SetLoadIDs(context.TODO(), map[string]int64{utils.CacheThresholdProfiles: loadID, utils.CacheThresholds: loadID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- //handle caching for Threshold
- if err := apierSv1.CallCache(utils.IfaceAsString(args.APIOpts[utils.CacheOpt]), tnt, utils.CacheThresholds,
- utils.ConcatenatedKey(tnt, args.ID), nil, nil, args.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// Ping .
-func (tSv1 *ThresholdSv1) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v1/thresholds_it_test.go b/apier/v1/thresholds_it_test.go
deleted file mode 100644
index eea79864d..000000000
--- a/apier/v1/thresholds_it_test.go
+++ /dev/null
@@ -1,1036 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tSv1CfgPath string
- tSv1Cfg *config.CGRConfig
- tSv1Rpc *rpc.Client
- tPrfl *engine.ThresholdProfileWithAPIOpts
- tSv1ConfDIR string //run tests for specific configuration
-
- tEvs = []*engine.ThresholdsArgsProcessEvent{
- {
- CGREvent: &utils.CGREvent{ // hitting THD_ACNT_BALANCE_1
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.EventType: utils.AccountUpdate,
- utils.AccountField: "1002",
- utils.AllowNegative: true,
- utils.Disabled: false,
- utils.Units: 12.3},
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_ACNT_BALANCE_1
- Tenant: "cgrates.org",
- ID: "event2",
- Event: map[string]interface{}{
- utils.EventType: utils.BalanceUpdate,
- utils.AccountField: "1002",
- utils.BalanceID: utils.MetaDefault,
- utils.Units: 12.3,
- utils.ExpiryTime: time.Date(2009, 11, 10, 23, 00, 0, 0, time.UTC),
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.BalanceUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_STATS_1
- Tenant: "cgrates.org",
- ID: "event3",
- Event: map[string]interface{}{
- utils.EventType: utils.StatUpdate,
- utils.StatID: "Stats1",
- utils.AccountField: "1002",
- "ASR": 35.0,
- "ACD": "2m45s",
- "TCC": 12.7,
- "TCD": "12m15s",
- "ACC": 0.75,
- "PDD": "2s",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.StatUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_STATS_1 and THD_STATS_2
- Tenant: "cgrates.org",
- ID: "event4",
- Event: map[string]interface{}{
- utils.EventType: utils.StatUpdate,
- utils.StatID: "STATS_HOURLY_DE",
- utils.AccountField: "1002",
- "ASR": 35.0,
- "ACD": "2m45s",
- "TCD": "1h",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.StatUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_STATS_3
- Tenant: "cgrates.org",
- ID: "event5",
- Event: map[string]interface{}{
- utils.EventType: utils.StatUpdate,
- utils.StatID: "STATS_DAILY_DE",
- utils.AccountField: "1002",
- "ACD": "2m45s",
- "TCD": "3h1s",
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.StatUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_RES_1
- Tenant: "cgrates.org",
- ID: "event6",
- Event: map[string]interface{}{
- utils.EventType: utils.ResourceUpdate,
- utils.AccountField: "1002",
- utils.ResourceID: "RES_GRP_1",
- utils.Usage: 10.0,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.ResourceUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_RES_1
- Tenant: "cgrates.org",
- ID: "event6",
- Event: map[string]interface{}{
- utils.EventType: utils.ResourceUpdate,
- utils.AccountField: "1002",
- utils.ResourceID: "RES_GRP_1",
- utils.Usage: 10.0,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.ResourceUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_RES_1
- Tenant: "cgrates.org",
- ID: "event6",
- Event: map[string]interface{}{
- utils.EventType: utils.ResourceUpdate,
- utils.AccountField: "1002",
- utils.ResourceID: "RES_GRP_1",
- utils.Usage: 10.0,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.ResourceUpdate,
- },
- },
- },
- {
- CGREvent: &utils.CGREvent{ // hitting THD_CDRS_1
- Tenant: "cgrates.org",
- ID: "cdrev1",
- Event: map[string]interface{}{
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- utils.CGRID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()),
- utils.RunID: utils.MetaRaw,
- utils.OrderID: 123,
- utils.OriginHost: "192.168.1.1",
- utils.Source: utils.UnitTest,
- utils.OriginID: "dsafdsaf",
- utils.ToR: utils.MetaVoice,
- utils.RequestType: utils.MetaRated,
- utils.Tenant: "cgrates.org",
- utils.Category: "call",
- utils.AccountField: "1007",
- utils.Subject: "1007",
- utils.Destination: "+4986517174963",
- utils.SetupTime: time.Date(2013, 11, 7, 8, 42, 20, 0, time.UTC),
- utils.PDD: 0 * time.Second,
- utils.AnswerTime: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC),
- utils.Usage: 10 * time.Second,
- utils.Route: "SUPPL1",
- utils.Cost: -1.0,
- },
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.CDR,
- },
- },
- },
- }
-
- sTestsThresholdSV1 = []func(t *testing.T){
- testV1TSLoadConfig,
- testV1TSInitDataDb,
- testV1TSResetStorDb,
- testV1TSStartEngine,
- testV1TSRpcConn,
- testV1TSFromFolder,
- testV1TSGetThresholds,
- testV1TSProcessEvent,
- testV1TSGetThresholdsAfterProcess,
- testV1TSGetThresholdsAfterRestart,
- testv1TSGetThresholdProfileIDs,
- testv1TSGetThresholdProfileIDsCount,
- testV1TSSetThresholdProfileBrokenReference,
- testV1TSSetThresholdProfile,
- testV1TSUpdateThresholdProfile,
- testV1TSRemoveThresholdProfile,
- testV1TSMaxHits,
- testV1TSUpdateSnooze,
- testV1TSGetThresholdProfileWithoutTenant,
- testV1TSRemThresholdProfileWithoutTenant,
- testV1TSProcessEventWithoutTenant,
- testV1TSGetThresholdsWithoutTenant,
- testV1TSProcessAccountUpdateEvent,
- testV1TSResetThresholdsWithoutTenant,
- testV1TSStopEngine,
- //cache test
- testV1TSLoadConfig,
- testV1TSInitDataDb,
- testV1TSResetStorDb,
- testV1TSStartEngine,
- testV1TSRpcConn,
- testThresholdSCacheProcessEventNotFound,
- testThresholdSCacheSet,
- testThresholdSCacheProcessEventNotFound,
- testThresholdSCacheReload,
- testThresholdSCacheProcessEventFound,
- testV1TSStopEngine,
- }
-)
-
-// Test start here
-func TestTSV1IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tSv1ConfDIR = "tutinternal"
- case utils.MetaMySQL:
- tSv1ConfDIR = "tutmysql"
- case utils.MetaMongo:
- tSv1ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsThresholdSV1 {
- t.Run(tSv1ConfDIR, stest)
- }
-}
-
-func testV1TSLoadConfig(t *testing.T) {
- var err error
- tSv1CfgPath = path.Join(*dataDir, "conf", "samples", tSv1ConfDIR)
- if tSv1Cfg, err = config.NewCGRConfigFromPath(tSv1CfgPath); err != nil {
- t.Error(err)
- }
-}
-
-func testV1TSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(tSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testV1TSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tSv1Cfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1TSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tSv1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV1TSRpcConn(t *testing.T) {
- var err error
- tSv1Rpc, err = newRPCClient(tSv1Cfg.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 testV1TSFromFolder(t *testing.T) {
- var reply string
- attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "oldtutorial")}
- if err := tSv1Rpc.Call(utils.APIerSv1LoadTariffPlanFromFolder, attrs, &reply); err != nil {
- t.Error(err)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testV1TSGetThresholds(t *testing.T) {
- var tIDs []string
- expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED", "THD_STATS_3", "THD_CDRS_1"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs,
- &utils.TenantWithAPIOpts{}, &tIDs); err != nil {
- t.Error(err)
- } else if len(expectedIDs) != len(tIDs) {
- t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs)
- }
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &tIDs); err != nil {
- t.Error(err)
- } else if len(expectedIDs) != len(tIDs) {
- t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs)
- }
- var td engine.Threshold
- eTd := engine.Threshold{Tenant: "cgrates.org", ID: expectedIDs[0]}
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: expectedIDs[0]}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd, td) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- }
-}
-
-func testV1TSProcessEvent(t *testing.T) {
- var ids []string
- eIDs := []string{}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[0], &ids); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- eIDs = []string{"THD_ACNT_BALANCE_1"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[1], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- eIDs = []string{"THD_STATS_1"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[2], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- eIDs = []string{"THD_STATS_2", "THD_STATS_1"}
- eIDs2 := []string{"THD_STATS_1", "THD_STATS_2"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[3], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) && !reflect.DeepEqual(ids, eIDs2) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- eIDs = []string{"THD_STATS_3"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[4], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- eIDs = []string{"THD_RES_1"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[5], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[6], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[7], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- eIDs = []string{"THD_CDRS_1"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, &tEvs[8], &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
-}
-
-func testV1TSGetThresholdsAfterProcess(t *testing.T) {
- var tIDs []string
- expectedIDs := []string{"THD_RES_1", "THD_STATS_2", "THD_STATS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdIDs,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"}, &tIDs); err != nil {
- t.Error(err)
- } else if len(expectedIDs) != len(tIDs) { // THD_STATS_3 is not reccurent, so it was removed
- t.Errorf("expecting: %+v, received reply: %s", expectedIDs, tIDs)
- }
- var td engine.Threshold
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err != nil {
- t.Error(err)
- } else if td.Snooze.IsZero() { // make sure Snooze time was reset during execution
- t.Errorf("received: %+v", td)
- }
-}
-
-func testV1TSGetThresholdsAfterRestart(t *testing.T) {
- // in case of internal we skip this test
- if tSv1ConfDIR == "tutinternal" {
- t.SkipNow()
- }
- // time.Sleep(time.Second)
- if _, err := engine.StopStartEngine(tSv1CfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
- var err error
- tSv1Rpc, err = newRPCClient(tSv1Cfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal("Could not connect to rater: ", err.Error())
- }
- var td engine.Threshold
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_ACNT_BALANCE_1"}}, &td); err != nil {
- t.Error(err)
- } else if td.Snooze.IsZero() { // make sure Snooze time was reset during execution
- t.Errorf("received: %+v", td)
- }
-}
-
-func testV1TSSetThresholdProfileBrokenReference(t *testing.T) {
- var reply *engine.ThresholdProfile
- var result string
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Test",
- FilterIDs: []string{"NonExistingFilter"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1"},
- Async: true,
- },
- }
- expErr := "SERVER_ERROR: broken reference to filter: NonExistingFilter for item with ID: cgrates.org:THD_Test"
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err == nil || err.Error() != expErr {
- t.Fatalf("Expected error: %q, received: %v", expErr, err)
- }
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Fatal(err)
- }
-}
-
-func testv1TSGetThresholdProfileIDs(t *testing.T) {
- expected := []string{"THD_STATS_1", "THD_STATS_2", "THD_STATS_3", "THD_RES_1", "THD_CDRS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"}
- var result []string
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDs, &utils.PaginatorWithTenant{Tenant: "cgrates.org"}, &result); err != nil {
- t.Error(err)
- } else if len(expected) != len(result) {
- t.Errorf("Expecting : %+v, received: %+v", expected, result)
- }
-}
-
-func testV1TSSetThresholdProfile(t *testing.T) {
- var reply *engine.ThresholdProfile
- var result string
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Test",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1"},
- Async: true,
- },
- }
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
-}
-
-func testV1TSUpdateThresholdProfile(t *testing.T) {
- var result string
- tPrfl.FilterIDs = []string{"*string:~Account:1001", "*prefix:~DST:10"}
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.ThresholdProfile
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &reply); err != nil {
- t.Error(err)
- } else {
- sort.Strings(reply.FilterIDs)
- sort.Strings(tPrfl.ThresholdProfile.FilterIDs)
- if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
- }
- }
-}
-
-func testV1TSRemoveThresholdProfile(t *testing.T) {
- var resp string
- if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
- var sqp *engine.ThresholdProfile
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &sqp); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Received %s and the error:%+v", utils.ToJSON(sqp), err)
- }
- if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &resp); err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expected error: %v received: %v", utils.ErrNotFound, err)
- }
-}
-
-func testV1TSMaxHits(t *testing.T) {
- var reply string
- // check if exist
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "TH3",
- MaxHits: 3,
- },
- }
- //set
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- var ids []string
- eIDs := []string{"TH3"}
- thEvent := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{ // hitting TH3
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- utils.AccountField: "1002",
- },
- },
- }
- //process event
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- //check threshold after first process ( hits : 1)
- var td engine.Threshold
- eTd := engine.Threshold{Tenant: "cgrates.org", ID: "TH3", Hits: 1}
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd.Hits, td.Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- }
- //process event
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
-
- //check threshold for event
- var ths engine.Thresholds
- eTd.Hits = 2
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdsForEvent,
- thEvent, &ths); err != nil {
- t.Error(err)
- } else if len(ths) != 1 {
- t.Errorf("expecting: 1, received: %+v", utils.ToJSON(ths))
- } else if !reflect.DeepEqual(eTd.TenantID(), ths[0].TenantID()) {
- t.Errorf("expecting: %+v, received: %+v", eTd.TenantID(), ths[0].TenantID())
- } else if !reflect.DeepEqual(eTd.Hits, ths[0].Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd.Hits, ths[0].Hits)
- }
-
- //check threshold for event without tenant
- thEvent.Tenant = utils.EmptyString
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThresholdsForEvent,
- thEvent, &ths); err != nil {
- t.Error(err)
- } else if len(ths) != 1 {
- t.Errorf("expecting: 1, received: %+v", utils.ToJSON(ths))
- } else if !reflect.DeepEqual(eTd.TenantID(), ths[0].TenantID()) {
- t.Errorf("expecting: %+v, received: %+v", eTd.TenantID(), ths[0].TenantID())
- } else if !reflect.DeepEqual(eTd.Hits, ths[0].Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd.Hits, ths[0].Hits)
- }
-
- //check threshold after second process ( hits : 2)
- eTd.Hits = 2
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd.Hits, td.Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- }
-
- //process event
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- //check threshold after third process (reached the maximum hits and should be removed)
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH3"}}, &td); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Err : %+v \n, td : %+v", err, utils.ToJSON(td))
- }
-}
-
-func testV1TSUpdateSnooze(t *testing.T) {
- var reply string
- // check if exist
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TH4"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- customTh := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "TH4",
- FilterIDs: []string{"*string:~*req.CustomEv:SnoozeEv"},
- MinSleep: 10 * time.Minute,
- Weight: 100,
- },
- }
- //set
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, customTh, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- var ids []string
- eIDs := []string{"TH4"}
- thEvent := &engine.ThresholdsArgsProcessEvent{
- ThresholdIDs: []string{"TH4"},
- CGREvent: &utils.CGREvent{ // hitting TH4
- Tenant: "cgrates.org",
- ID: "event1",
- Event: map[string]interface{}{
- "CustomEv": "SnoozeEv",
- },
- },
- }
- tNow := time.Now()
- //process event
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
- //check threshold after first process ( hits : 1)
- var td engine.Threshold
- eTd := engine.Threshold{Tenant: "cgrates.org", ID: "TH4", Hits: 1}
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH4"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd.Hits, td.Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- } else if !(td.Snooze.After(tNow.Add(9*time.Minute)) && td.Snooze.Before(tNow.Add(11*time.Minute))) { // Snooze time should be between time.Now + 9 min and time.Now + 11 min
- t.Errorf("expecting: %+v, received: %+v", tNow.Add(10*time.Minute), td.Snooze)
- }
-
- customTh2 := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "TH4",
- FilterIDs: []string{"*string:~*req.CustomEv:SnoozeEv"},
- MinSleep: 5 * time.Minute,
- Weight: 100,
- },
- }
- //set
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, customTh2, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "TH4"}}, &td); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eTd.Hits, td.Hits) {
- t.Errorf("expecting: %+v, received: %+v", eTd, td)
- } else if !(td.Snooze.After(tNow.Add(4*time.Minute)) && td.Snooze.Before(tNow.Add(6*time.Minute))) { // Snooze time should be between time.Now + 9 min and time.Now + 11 min
- t.Errorf("expecting: %+v, received: %+v", tNow.Add(10*time.Minute), td.Snooze)
- }
-
-}
-
-func testV1TSStopEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
-
-func testV1TSGetThresholdProfileWithoutTenant(t *testing.T) {
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- ID: "randomID",
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 5 * time.Minute,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_1"},
- Async: true,
- },
- }
- var reply string
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- tPrfl.ThresholdProfile.Tenant = "cgrates.org"
- var result *engine.ThresholdProfile
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{ID: "randomID"},
- &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, result) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(tPrfl.ThresholdProfile), utils.ToJSON(result))
- }
-}
-
-func testV1TSRemThresholdProfileWithoutTenant(t *testing.T) {
- var reply string
- if err := tSv1Rpc.Call(utils.APIerSv1RemoveThresholdProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "randomID"}},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- var result *engine.ThresholdProfile
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{ID: "randomID"},
- &result); err == nil || utils.ErrNotFound.Error() != err.Error() {
- t.Error(err)
- }
-}
-
-func testv1TSGetThresholdProfileIDsCount(t *testing.T) {
- var reply int
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDsCount,
- &utils.TenantWithAPIOpts{},
- &reply); err != nil {
- t.Error(err)
- } else if reply != 7 {
- t.Errorf("Expected 7, received %+v", reply)
- }
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfileIDsCount,
- &utils.TenantWithAPIOpts{Tenant: "cgrates.org"},
- &reply); err != nil {
- t.Error(err)
- } else if reply != 7 {
- t.Errorf("Expected 7, received %+v", reply)
- }
-}
-
-func testV1TSProcessEventWithoutTenant(t *testing.T) {
- var ids []string
- eIDs := []string{"TH4"}
- thEvent := &engine.ThresholdsArgsProcessEvent{
- ThresholdIDs: []string{"TH4"},
- CGREvent: &utils.CGREvent{ // hitting TH4
- ID: "event1",
- Event: map[string]interface{}{
- "CustomEv": "SnoozeEv",
- },
- },
- }
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
-}
-
-func testV1TSGetThresholdsWithoutTenant(t *testing.T) {
- expectedThreshold := &engine.Threshold{
- Tenant: "cgrates.org",
- ID: "THD_ACNT_BALANCE_1",
- Hits: 1,
- }
- var reply *engine.Threshold
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}},
- &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedThreshold.ID, reply.ID) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold.ID), utils.ToJSON(reply.ID))
- } else if !reflect.DeepEqual(expectedThreshold.Tenant, reply.Tenant) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold.Tenant), utils.ToJSON(reply.Tenant))
- } else if !reflect.DeepEqual(expectedThreshold.ID, reply.ID) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold.Tenant), utils.ToJSON(reply.Tenant))
- }
-}
-
-func testV1TSProcessAccountUpdateEvent(t *testing.T) {
- var result string
- thAcntUpdate := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "TH_ACNT_UPDATE_EV",
- FilterIDs: []string{
- "*string:~*opts.*eventType:AccountUpdate",
- "*string:~*asm.ID:testV1TSProcessAccountUpdateEvent",
- "*gt:~*asm.BalanceSummaries.HolidayBalance.Value:1.0",
- },
- MaxHits: 10,
- MinSleep: 10 * time.Millisecond,
- Weight: 20.0,
- ActionIDs: []string{"LOG_WARNING"},
- Async: true,
- },
- }
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, thAcntUpdate, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.ThresholdProfile
- if err := tSv1Rpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "TH_ACNT_UPDATE_EV"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(thAcntUpdate.ThresholdProfile, reply) {
- t.Errorf("Expecting: %+v, received: %+v", thAcntUpdate.ThresholdProfile, reply)
- }
-
- attrSetBalance := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "testV1TSProcessAccountUpdateEvent",
- BalanceType: "*monetary",
- Value: 1.5,
- Balance: map[string]interface{}{
- utils.ID: "HolidayBalance",
- },
- }
- if err := tSv1Rpc.Call(utils.APIerSv1SetBalance, attrSetBalance, &result); err != nil {
- t.Error("Got error on APIerSv1.SetBalance: ", err.Error())
- } else if result != utils.OK {
- t.Errorf("Calling APIerSv1.SetBalance received: %s", result)
- }
-
- var acnt *engine.Account
- attrs := &utils.AttrGetAccount{
- Tenant: "cgrates.org",
- Account: "testV1TSProcessAccountUpdateEvent",
- }
- if err := tSv1Rpc.Call(utils.APIerSv2GetAccount, attrs, &acnt); err != nil {
- t.Error(err)
- }
-
- acntUpdateEv := &engine.ThresholdsArgsProcessEvent{
- CGREvent: &utils.CGREvent{ // hitting TH_ACNT_UPDATE_EV
- Tenant: "cgrates.org",
- ID: "SIMULATE_ACNT_UPDATE_EV",
- Event: acnt.AsAccountSummary().AsMapInterface(),
- APIOpts: map[string]interface{}{
- utils.MetaEventType: utils.AccountUpdate,
- },
- },
- }
-
- var ids []string
- eIDs := []string{"TH_ACNT_UPDATE_EV"}
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, acntUpdateEv, &ids); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(ids, eIDs) {
- t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
- }
-
-}
-
-func testV1TSResetThresholdsWithoutTenant(t *testing.T) {
- expectedThreshold := &engine.Threshold{
- Tenant: "cgrates.org",
- ID: "THD_ACNT_BALANCE_1",
- Hits: 1,
- }
- var reply *engine.Threshold
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}},
- &reply); err != nil {
- t.Fatal(err)
- }
- reply.Snooze = expectedThreshold.Snooze
- if !reflect.DeepEqual(expectedThreshold, reply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold), utils.ToJSON(reply))
- }
- var result string
- if err := tSv1Rpc.Call(utils.ThresholdSv1ResetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}},
- &result); err != nil {
- t.Fatal(err)
- } else if result != utils.OK {
- t.Errorf("Expected %+v \n, received %+v", utils.OK, result)
- }
- expectedThreshold.Hits = 0
- reply = nil
- if err := tSv1Rpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "THD_ACNT_BALANCE_1"}},
- &reply); err != nil {
- t.Fatal(err)
- }
- reply.Snooze = expectedThreshold.Snooze
- if !reflect.DeepEqual(expectedThreshold, reply) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedThreshold), utils.ToJSON(reply))
- }
-}
-
-func testThresholdSCacheProcessEventNotFound(t *testing.T) {
- var ids []string
- thEvent := &engine.ThresholdsArgsProcessEvent{
- ThresholdIDs: []string{"THRESHOLD_CACHE"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "THRESHOLD_CACHE",
- Event: map[string]interface{}{
- "CustomEv": "SnoozeEv",
- },
- },
- }
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testThresholdSCacheProcessEventFound(t *testing.T) {
- var ids []string
- thEvent := &engine.ThresholdsArgsProcessEvent{
- ThresholdIDs: []string{"THRESHOLD_CACHE"},
- CGREvent: &utils.CGREvent{
- Tenant: "cgrates.org",
- ID: "THRESHOLD_CACHE",
- Event: map[string]interface{}{
- "CustomEv": "SnoozeEv",
- },
- },
- }
- if err := tSv1Rpc.Call(utils.ThresholdSv1ProcessEvent, thEvent, &ids); err != nil {
- t.Error(err)
- }
-}
-
-func testThresholdSCacheSet(t *testing.T) {
- var result string
- tPrfl = &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THRESHOLD_CACHE",
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaNone,
- },
- }
- if err := tSv1Rpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testThresholdSCacheReload(t *testing.T) {
- cache := &utils.AttrReloadCacheWithAPIOpts{
- ArgsCache: map[string][]string{
- utils.ThresholdProfileIDs: {"cgrates.org:THRESHOLD_CACHE"},
- },
- }
- var reply string
- if err := tSv1Rpc.Call(utils.CacheSv1ReloadCache, cache, &reply); err != nil {
- t.Error("Got error on CacheSv1.ReloadCache: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling CacheSv1.ReloadCache got reply: ", reply)
- }
-}
diff --git a/apier/v1/tp.go b/apier/v1/tp.go
deleted file mode 100644
index 226587517..000000000
--- a/apier/v1/tp.go
+++ /dev/null
@@ -1,172 +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
-
-// Tariff plan related APIs
-
-import (
- "encoding/base64"
- "os"
- "path/filepath"
-
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-type AttrGetTPIds struct {
-}
-
-// Queries tarrif plan identities gathered from all tables.
-func (apierSv1 *APIerSv1) GetTPIds(attrs *AttrGetTPIds, reply *[]string) error {
- if ids, err := apierSv1.StorDb.GetTpIds(utils.EmptyString); err != nil {
- return utils.NewErrServerError(err)
- } else if ids == nil {
- return utils.ErrNotFound
- } else {
- *reply = ids
- }
- return nil
-}
-
-type AttrImportTPZipFile struct {
- TPid string
- File []byte
-}
-
-func (apierSv1 *APIerSv1) ImportTPZipFile(attrs *AttrImportTPZipFile, reply *string) error {
- tmpDir, err := os.MkdirTemp("/tmp", "cgr_")
- if err != nil {
- *reply = "ERROR: creating temp directory!"
- return err
- }
- zipFile := filepath.Join(tmpDir, "/file.zip")
- if err = os.WriteFile(zipFile, attrs.File, os.ModePerm); err != nil {
- *reply = "ERROR: writing zip file!"
- return err
- }
- if err = utils.Unzip(zipFile, tmpDir); err != nil {
- *reply = "ERROR: unziping file!"
- return err
- }
- csvfilesFound := false
- if err = filepath.Walk(tmpDir, func(path string, info os.FileInfo, err error) error {
- if !info.IsDir() {
- return nil
- }
- csvFiles, err := filepath.Glob(filepath.Join(path, "*csv"))
- if csvFiles != nil {
- if attrs.TPid == "" {
- *reply = "ERROR: missing TPid!"
- return err
- }
- csvImporter := engine.TPCSVImporter{
- TPid: attrs.TPid,
- StorDB: apierSv1.StorDb,
- DirPath: path,
- Sep: utils.CSVSep,
- Verbose: false,
- ImportID: "",
- }
- if errImport := csvImporter.Run(); errImport != nil {
- return errImport
- }
- csvfilesFound = true
- }
- return err
- }); err != nil || !csvfilesFound {
- *reply = "ERROR: finding csv files!"
- return err
- }
- os.RemoveAll(tmpDir)
- *reply = utils.OK
- return nil
-}
-
-type AttrRemTp struct {
- TPid string
-}
-
-func (apierSv1 *APIerSv1) RemTP(attrs *AttrRemTp, reply *string) error {
- if len(attrs.TPid) == 0 {
- return utils.NewErrMandatoryIeMissing(utils.TPid)
- }
- if err := apierSv1.StorDb.RemTpData("", attrs.TPid, nil); err != nil {
- return utils.NewErrServerError(err)
- } else {
- *reply = utils.OK
- }
- return nil
-}
-
-func (apierSv1 *APIerSv1) ExportTPToFolder(attrs *utils.AttrDirExportTP, exported *utils.ExportedTPStats) error {
- if attrs.TPid == nil || *attrs.TPid == "" {
- return utils.NewErrMandatoryIeMissing(utils.TPid)
- }
- dir := apierSv1.Config.GeneralCfg().TpExportPath
- if attrs.ExportPath != nil {
- dir = *attrs.ExportPath
- }
- fileFormat := utils.CSV
- if attrs.FileFormat != nil {
- fileFormat = *attrs.FileFormat
- }
- sep := ","
- if attrs.FieldSeparator != nil {
- sep = *attrs.FieldSeparator
- }
- compress := false
- if attrs.Compress != nil {
- compress = *attrs.Compress
- }
- tpExporter, err := engine.NewTPExporter(apierSv1.StorDb, *attrs.TPid, dir, fileFormat, sep, compress)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if err := tpExporter.Run(); err != nil {
- return utils.NewErrServerError(err)
- } else {
- *exported = *tpExporter.ExportStats()
- }
-
- return nil
-}
-
-func (apierSv1 *APIerSv1) ExportTPToZipString(attrs *utils.AttrDirExportTP, reply *string) error {
- if attrs.TPid == nil || *attrs.TPid == utils.EmptyString {
- return utils.NewErrMandatoryIeMissing(utils.TPid)
- }
- dir := utils.EmptyString
- fileFormat := utils.CSV
- if attrs.FileFormat != nil {
- fileFormat = *attrs.FileFormat
- }
- sep := ","
- if attrs.FieldSeparator != nil {
- sep = *attrs.FieldSeparator
- }
- tpExporter, err := engine.NewTPExporter(apierSv1.StorDb, *attrs.TPid, dir, fileFormat, sep, true)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if err := tpExporter.Run(); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = base64.StdEncoding.EncodeToString(tpExporter.GetCacheBuffer().Bytes())
- return nil
-}
diff --git a/apier/v1/tp_it_test.go b/apier/v1/tp_it_test.go
deleted file mode 100644
index 1bc0533b5..000000000
--- a/apier/v1/tp_it_test.go
+++ /dev/null
@@ -1,157 +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"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpCfgPath string
- tpCfg *config.CGRConfig
- tpRPC *rpc.Client
- tpConfigDIR string //run tests for specific configuration
-
- sTestsTP = []func(t *testing.T){
- testTPInitCfg,
- testTPResetStorDb,
- testTPStartEngine,
- testTPRpcConn,
- testTPImportTPFromFolderPath,
- testTPExportTPToFolder,
- testTPExportTPToFolderWithError,
- testTPKillEngine,
- }
-)
-
-//Test start here
-func TestTPIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- tpConfigDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
- tpConfigDIR = "tutmysql"
- for _, stest := range sTestsTP {
- t.Run(tpConfigDIR, stest)
- }
-}
-
-func testTPInitCfg(t *testing.T) {
- var err error
- tpCfgPath = path.Join(*dataDir, "conf", "samples", tpConfigDIR)
- tpCfg, err = config.NewCGRConfigFromPath(tpCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-// Wipe out the cdr database
-func testTPResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPRpcConn(t *testing.T) {
- var err error
- tpRPC, err = newRPCClient(tpCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPImportTPFromFolderPath(t *testing.T) {
- var reply string
- if err := tpRPC.Call(utils.APIerSv1ImportTariffPlanFromFolder,
- utils.AttrImportTPFromFolder{TPid: "TEST_TPID2",
- FolderPath: path.Join(*dataDir, "tariffplans", "tutorial")}, &reply); err != nil {
- t.Error("Got error on APIerSv1.ImportTarrifPlanFromFolder: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.ImportTarrifPlanFromFolder got reply: ", reply)
- }
- time.Sleep(100 * time.Millisecond)
-}
-
-func testTPExportTPToFolder(t *testing.T) {
- var reply *utils.ExportedTPStats
- expectedTPStas := &utils.ExportedTPStats{
- Compressed: true,
- ExportPath: "/tmp/",
- ExportedFiles: []string{utils.ChargersCsv, utils.ResourcesCsv, utils.StatsCsv, utils.ThresholdsCsv,
- utils.DestinationsCsv, utils.FiltersCsv, utils.RoutesCsv, utils.AttributesCsv},
- }
- sort.Strings(expectedTPStas.ExportedFiles)
- tpid := "TEST_TPID2"
- compress := true
- exportPath := "/tmp/"
- if err := tpRPC.Call(utils.APIerSv1ExportTPToFolder, &utils.AttrDirExportTP{TPid: &tpid, ExportPath: &exportPath, Compress: &compress}, &reply); err != nil {
- t.Error("Got error on APIerSv1.ExportTPToFolder: ", err.Error())
- } else if !reflect.DeepEqual(reply.ExportPath, expectedTPStas.ExportPath) {
- t.Errorf("Expecting : %+v, received: %+v", expectedTPStas.ExportPath, reply.ExportPath)
- } else if !reflect.DeepEqual(reply.Compressed, expectedTPStas.Compressed) {
- t.Errorf("Expecting : %+v, received: %+v", expectedTPStas.Compressed, reply.Compressed)
- } else if sort.Strings(reply.ExportedFiles); !reflect.DeepEqual(expectedTPStas.ExportedFiles, reply.ExportedFiles) {
- t.Errorf("Expecting : %+v, received: %+v", expectedTPStas.ExportedFiles, reply.ExportedFiles)
- }
-}
-
-func testTPExportTPToFolderWithError(t *testing.T) {
- var reply *utils.ExportedTPStats
- tpid := "UnexistedTP"
- compress := true
- exportPath := "/tmp/"
- if err := tpRPC.Call(utils.APIerSv1ExportTPToFolder,
- &utils.AttrDirExportTP{TPid: &tpid, ExportPath: &exportPath, Compress: &compress}, &reply); err == nil || err.Error() != utils.NewErrServerError(utils.ErrNotFound).Error() {
- t.Error("Expecting error, received: ", err)
- }
-
-}
-
-func testTPKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpaccountprofiles.go b/apier/v1/tpaccountprofiles.go
deleted file mode 100644
index 3edb861ac..000000000
--- a/apier/v1/tpaccountprofiles.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPAccount creates a new TPAccount within a tariff plan
-func (apierSv1 *APIerSv1) SetTPAccount(attrs *utils.TPAccount, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPAccounts([]*utils.TPAccount{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPAccount queries specific TPAccount on tariff plan
-func (apierSv1 *APIerSv1) GetTPAccount(attr *utils.TPTntID, reply *utils.TPAccount) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- spp, err := apierSv1.StorDb.GetTPAccounts(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *spp[0]
- return nil
-}
-
-type AttrGetTPAccountIDs struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPRouteIDs queries TPAccounts identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPAccountIDs(attrs *AttrGetTPAccountIDs, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAccounts,
- []string{"tenant", "id"}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPAccount removes specific TPAccount on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPAccount(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPAccounts, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpaccountprofiles_it_test.go b/apier/v1/tpaccountprofiles_it_test.go
deleted file mode 100644
index 330d294cb..000000000
--- a/apier/v1/tpaccountprofiles_it_test.go
+++ /dev/null
@@ -1,233 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpAcctPrfCfgPath string
- tpAcctPrfCfg *config.CGRConfig
- tpAcctPrfRPC *rpc.Client
- tpAcctPrf *utils.TPAccount
- tpAcctPrfDelay int
- tpAcctPrfConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPAcctPrf = []func(t *testing.T){
- testTPAcctPrfInitCfg,
- testTPAcctPrfResetStorDb,
- testTPAcctPrfStartEngine,
- testTPAcctPrfRPCConn,
- testTPAcctPrfGetTPAcctPrfBeforeSet,
- testTPAcctPrfSetTPAcctPrf,
- testTPAcctPrfGetTPAcctPrfAfterSet,
- testTPAcctPrfGetTPAcctPrfIDs,
- testTPAcctPrfUpdateTPAcctBal,
- testTPAcctPrfGetTPAcctBalAfterUpdate,
- testTPAcctPrfRemTPAcctPrf,
- testTPAcctPrfGetTPAcctPrfAfterRemove,
- testTPAcctPrfKillEngine,
-}
-
-//Test start here
-func TestTPAcctPrfIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpAcctPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpAcctPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpAcctPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPAcctPrf {
- t.Run(tpAcctPrfConfigDIR, stest)
- }
-}
-
-func testTPAcctPrfInitCfg(t *testing.T) {
- var err error
- tpAcctPrfCfgPath = path.Join(*dataDir, "conf", "samples", tpAcctPrfConfigDIR)
- tpAcctPrfCfg, err = config.NewCGRConfigFromPath(tpAcctPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpAcctPrfDelay = 1000
-}
-
-// Wipe out the cdr database
-func testTPAcctPrfResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpAcctPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPAcctPrfStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpAcctPrfCfgPath, tpAcctPrfDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPAcctPrfRPCConn(t *testing.T) {
- var err error
- tpAcctPrfRPC, err = jsonrpc.Dial(utils.TCP, tpAcctPrfCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPAcctPrfGetTPAcctPrfBeforeSet(t *testing.T) {
- var reply *utils.TPAccount
- if err := tpAcctPrfRPC.Call(utils.APIerSv1GetTPAccount,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "1001"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPAcctPrfSetTPAcctPrf(t *testing.T) {
- tpAcctPrf = &utils.TPAccount{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "1001",
- Weights: ";20",
- Balances: map[string]*utils.TPAccountBalance{
- "MonetaryBalance": {
- ID: "MonetaryBalance",
- Weights: ";10",
- Type: utils.MetaMonetary,
- Units: 14,
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- }
- var result string
- if err := tpAcctPrfRPC.Call(utils.APIerSv1SetTPAccount, tpAcctPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPAcctPrfGetTPAcctPrfAfterSet(t *testing.T) {
- var reply *utils.TPAccount
- if err := tpAcctPrfRPC.Call(utils.APIerSv1GetTPAccount,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "1001"}, &reply); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(tpAcctPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpAcctPrf), utils.ToJSON(reply))
- }
-}
-
-func testTPAcctPrfGetTPAcctPrfIDs(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:1001"}
- if err := tpAcctPrfRPC.Call(utils.APIerSv1GetTPAccountIDs,
- &AttrGetTPAccountIDs{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-}
-
-func testTPAcctPrfUpdateTPAcctBal(t *testing.T) {
- tpAcctPrf.Balances = map[string]*utils.TPAccountBalance{
- "MonetaryBalance2": {
- ID: "MonetaryBalance2",
- Weights: ";12",
- Type: utils.MetaMonetary,
- Units: 16,
- },
- }
- var result string
- if err := tpAcctPrfRPC.Call(utils.APIerSv1SetTPAccount, tpAcctPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPAcctPrfGetTPAcctBalAfterUpdate(t *testing.T) {
- var reply *utils.TPAccount
- revTPAcctPrf := &utils.TPAccount{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "1001",
- Weights: ";20",
- Balances: map[string]*utils.TPAccountBalance{
- "MonetaryBalance2": {
- ID: "MonetaryBalance2",
- Weights: ";12",
- Type: utils.MetaMonetary,
- Units: 16,
- },
- },
- ThresholdIDs: []string{utils.MetaNone},
- }
- if err := tpAcctPrfRPC.Call(utils.APIerSv1GetTPAccount,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "1001"}, &reply); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(tpAcctPrf, reply) && !reflect.DeepEqual(revTPAcctPrf, reply) {
- t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpAcctPrf), utils.ToJSON(reply))
- }
-}
-
-func testTPAcctPrfRemTPAcctPrf(t *testing.T) {
- var resp string
- if err := tpAcctPrfRPC.Call(utils.APIerSv1RemoveTPAccount,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "1001"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPAcctPrfGetTPAcctPrfAfterRemove(t *testing.T) {
- var reply *utils.TPAccount
- if err := tpAcctPrfRPC.Call(utils.APIerSv1GetTPAccount,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "1001"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPAcctPrfKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpAcctPrfDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpactionprofiles.go b/apier/v1/tpactionprofiles.go
deleted file mode 100644
index 23e0d489a..000000000
--- a/apier/v1/tpactionprofiles.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPActionProfile creates a new TPActionProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPActionProfile(attrs *utils.TPActionProfile, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPActionProfiles([]*utils.TPActionProfile{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPActionProfile queries specific TPActionProfile on tariff plan
-func (apierSv1 *APIerSv1) GetTPActionProfile(attr *utils.TPTntID, reply *utils.TPActionProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- spp, err := apierSv1.StorDb.GetTPActionProfiles(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *spp[0]
- return nil
-}
-
-type AttrGetTPActionProfileIDs struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPActionProfileIDs queries TPActionProfiles identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPActionProfileIDs(attrs *AttrGetTPActionProfileIDs, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPActionProfiles,
- []string{"tenant", "id"}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPActionProfile removes specific TPActionProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPActionProfile(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPActionProfiles, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpactionprofiles_it_test.go b/apier/v1/tpactionprofiles_it_test.go
deleted file mode 100644
index a342547cd..000000000
--- a/apier/v1/tpactionprofiles_it_test.go
+++ /dev/null
@@ -1,266 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "strings"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpActPrfCfgPath string
- tpActPrfCfg *config.CGRConfig
- tpActPrfRPC *rpc.Client
- tpActPrf *utils.TPActionProfile
- tpActPrfDelay int
- tpActPrfConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPActPrf = []func(t *testing.T){
- testTPActPrfInitCfg,
- testTPActPrfResetStorDb,
- testTPActPrfStartEngine,
- testTPActPrfRPCConn,
- testTPActPrfGetTPActPrfBeforeSet,
- testTPActPrfSetTPActPrf,
- testTPActPrfGetTPActPrfAfterSet,
- testTPActPrfGetTPActPrfIDs,
- testTPActPrfUpdateTPActPrf,
- testTPActPrfGetTPActPrfAfterUpdate,
- testTPActPrfRemTPActPrf,
- testTPActPrfGetTPActPrfAfterRemove,
- testTPActPrfKillEngine,
-}
-
-//Test start here
-func TestTPActPrfIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpActPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpActPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpActPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPActPrf {
- t.Run(tpActPrfConfigDIR, stest)
- }
-}
-
-func testTPActPrfInitCfg(t *testing.T) {
- var err error
- tpActPrfCfgPath = path.Join(*dataDir, "conf", "samples", tpActPrfConfigDIR)
- tpActPrfCfg, err = config.NewCGRConfigFromPath(tpActPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpActPrfDelay = 1000
-}
-
-// Wipe out the cdr database
-func testTPActPrfResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpActPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPActPrfStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpActPrfCfgPath, tpActPrfDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPActPrfRPCConn(t *testing.T) {
- var err error
- tpActPrfRPC, err = jsonrpc.Dial(utils.TCP, tpActPrfCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPActPrfGetTPActPrfBeforeSet(t *testing.T) {
- var reply *utils.TPActionProfile
- if err := tpActPrfRPC.Call(utils.APIerSv1GetTPActionProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPActPrfSetTPActPrf(t *testing.T) {
- tpActPrf = &utils.TPActionProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "ONE_TIME_ACT",
- Weight: 10,
- Schedule: utils.MetaASAP,
- Targets: []*utils.TPActionTarget{
- {
- TargetType: utils.MetaAccounts,
- TargetIDs: []string{"1001"},
- },
- },
- Actions: []*utils.TPAPAction{
- {
- ID: "TOPUP",
- FilterIDs: []string{},
- Type: "*topup",
- Diktats: []*utils.TPAPDiktat{{
- Path: "~*balance.TestBalance.Value",
- Value: "10",
- }},
- },
- },
- }
- sort.Strings(tpActPrf.FilterIDs)
- var result string
- if err := tpActPrfRPC.Call(utils.APIerSv1SetTPActionProfile, tpActPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPActPrfGetTPActPrfAfterSet(t *testing.T) {
- var reply *utils.TPActionProfile
- if err := tpActPrfRPC.Call(utils.APIerSv1GetTPActionProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "ONE_TIME_ACT"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- if !reflect.DeepEqual(tpActPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpActPrf), utils.ToJSON(reply))
- }
-}
-
-func testTPActPrfGetTPActPrfIDs(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:ONE_TIME_ACT"}
- if err := tpActPrfRPC.Call(utils.APIerSv1GetTPActionProfileIDs,
- &AttrGetTPActionProfileIDs{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-}
-
-func testTPActPrfUpdateTPActPrf(t *testing.T) {
- tpActPrf.Actions = []*utils.TPAPAction{
- {
- ID: "new_TOPUP",
- FilterIDs: []string{},
- Type: "*topup",
- Diktats: []*utils.TPAPDiktat{{
- Path: "~*balance.TestBalance.Value",
- Value: "10",
- }},
- },
- }
- var result string
- if err := tpActPrfRPC.Call(utils.APIerSv1SetTPActionProfile, tpActPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPActPrfGetTPActPrfAfterUpdate(t *testing.T) {
- var reply *utils.TPActionProfile
- revTPActPrf := &utils.TPActionProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "ONE_TIME_ACT",
- Weight: 10,
- Schedule: utils.MetaASAP,
- Targets: []*utils.TPActionTarget{
- {
- TargetType: utils.MetaAccounts,
- TargetIDs: []string{"1001"},
- },
- },
- Actions: []*utils.TPAPAction{
- {
- ID: "new_TOPUP",
- FilterIDs: []string{},
- Type: "*topup",
- Diktats: []*utils.TPAPDiktat{{
- Path: "~*balance.TestBalance.Value",
- Value: "10",
- }},
- },
- },
- }
- sort.Strings(revTPActPrf.FilterIDs)
- sort.Slice(revTPActPrf.Actions, func(i, j int) bool {
- return strings.Compare(revTPActPrf.Actions[i].ID, revTPActPrf.Actions[j].ID) == -1
- })
- if err := tpActPrfRPC.Call(utils.APIerSv1GetTPActionProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "ONE_TIME_ACT"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- sort.Slice(reply.Actions, func(i, j int) bool {
- return strings.Compare(reply.Actions[i].ID, reply.Actions[j].ID) == -1
- })
- if !reflect.DeepEqual(tpActPrf, reply) && !reflect.DeepEqual(revTPActPrf, reply) {
- t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpActPrf), utils.ToJSON(reply))
- }
-}
-
-func testTPActPrfRemTPActPrf(t *testing.T) {
- var resp string
- if err := tpActPrfRPC.Call(utils.APIerSv1RemoveTPActionProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "ONE_TIME_ACT"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPActPrfGetTPActPrfAfterRemove(t *testing.T) {
- var reply *utils.TPActionProfile
- if err := tpActPrfRPC.Call(utils.APIerSv1GetTPActionProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "ONE_TIME_ACT"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPActPrfKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpActPrfDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpattributes.go b/apier/v1/tpattributes.go
deleted file mode 100644
index 6657f5917..000000000
--- a/apier/v1/tpattributes.go
+++ /dev/null
@@ -1,96 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPAttributeProfile creates a new AttributeProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPAttributeProfile(attrs *utils.TPAttributeProfile, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
-
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPAttributes([]*utils.TPAttributeProfile{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPAttributeProfile queries specific AttributeProfile on Tariff plan
-func (apierSv1 *APIerSv1) GetTPAttributeProfile(attr *utils.TPTntID, reply *utils.TPAttributeProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- als, err := apierSv1.StorDb.GetTPAttributes(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *als[0]
- return nil
-}
-
-type AttrGetTPAttributeProfileIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPAttributeProfileIds queries attribute identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPAttributeProfileIds(attrs *AttrGetTPAttributeProfileIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPAttributes,
- []string{utils.TenantCfg, utils.IDCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if ids == nil {
- return utils.ErrNotFound
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPAttributeProfile removes specific AttributeProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPAttributeProfile(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPAttributes, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpattributes_it_test.go b/apier/v1/tpattributes_it_test.go
deleted file mode 100644
index a7357f106..000000000
--- a/apier/v1/tpattributes_it_test.go
+++ /dev/null
@@ -1,262 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "strings"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpAlsPrfCfgPath string
- tpAlsPrfCfg *config.CGRConfig
- tpAlsPrfRPC *rpc.Client
- tpAlsPrf *utils.TPAttributeProfile
- tpAlsPrfDelay int
- tpAlsPrfConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPAlsPrf = []func(t *testing.T){
- testTPAlsPrfInitCfg,
- testTPAlsPrfResetStorDb,
- testTPAlsPrfStartEngine,
- testTPAlsPrfRPCConn,
- testTPAlsPrfGetTPAlsPrfBeforeSet,
- testTPAlsPrfSetTPAlsPrf,
- testTPAlsPrfGetTPAlsPrfAfterSet,
- testTPAlsPrfGetTPAlsPrfIDs,
- testTPAlsPrfUpdateTPAlsPrf,
- testTPAlsPrfGetTPAlsPrfAfterUpdate,
- testTPAlsPrfRemTPAlsPrf,
- testTPAlsPrfGetTPAlsPrfAfterRemove,
- testTPAlsPrfKillEngine,
-}
-
-//Test start here
-func TestTPAlsPrfIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpAlsPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpAlsPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpAlsPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPAlsPrf {
- t.Run(tpAlsPrfConfigDIR, stest)
- }
-}
-
-func testTPAlsPrfInitCfg(t *testing.T) {
- var err error
- tpAlsPrfCfgPath = path.Join(*dataDir, "conf", "samples", tpAlsPrfConfigDIR)
- tpAlsPrfCfg, err = config.NewCGRConfigFromPath(tpAlsPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpAlsPrfDelay = 1000
-}
-
-// Wipe out the cdr database
-func testTPAlsPrfResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpAlsPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPAlsPrfStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpAlsPrfCfgPath, tpAlsPrfDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPAlsPrfRPCConn(t *testing.T) {
- var err error
- tpAlsPrfRPC, err = jsonrpc.Dial(utils.TCP, tpAlsPrfCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPAlsPrfGetTPAlsPrfBeforeSet(t *testing.T) {
- var reply *utils.TPAttributeProfile
- if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPAlsPrfSetTPAlsPrf(t *testing.T) {
- tpAlsPrf = &utils.TPAttributeProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "Attr1",
- FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- Contexts: []string{"con1"},
- Attributes: []*utils.TPAttribute{
- &utils.TPAttribute{
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: "Al1",
- FilterIDs: []string{},
- },
- },
- Weight: 20,
- }
- sort.Strings(tpAlsPrf.FilterIDs)
- var result string
- if err := tpAlsPrfRPC.Call(utils.APIerSv1SetTPAttributeProfile, tpAlsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPAlsPrfGetTPAlsPrfAfterSet(t *testing.T) {
- var reply *utils.TPAttributeProfile
- if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- if !reflect.DeepEqual(tpAlsPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpAlsPrf), utils.ToJSON(reply))
- }
-}
-
-func testTPAlsPrfGetTPAlsPrfIDs(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:Attr1"}
- if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfileIds,
- &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-}
-
-func testTPAlsPrfUpdateTPAlsPrf(t *testing.T) {
- tpAlsPrf.Attributes = []*utils.TPAttribute{
- &utils.TPAttribute{
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: "Al1",
- FilterIDs: []string{},
- },
- &utils.TPAttribute{
- Path: utils.MetaReq + utils.NestingSep + "FL2",
- Value: "Al2",
- FilterIDs: []string{},
- },
- }
- var result string
- if err := tpAlsPrfRPC.Call(utils.APIerSv1SetTPAttributeProfile, tpAlsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPAlsPrfGetTPAlsPrfAfterUpdate(t *testing.T) {
- var reply *utils.TPAttributeProfile
- revTPAlsPrf := &utils.TPAttributeProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "Attr1",
- FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- Contexts: []string{"con1"},
- Attributes: []*utils.TPAttribute{
- &utils.TPAttribute{
- Path: utils.MetaReq + utils.NestingSep + "FL2",
- Value: "Al2",
- FilterIDs: []string{},
- },
- &utils.TPAttribute{
- Path: utils.MetaReq + utils.NestingSep + "FL1",
- Value: "Al1",
- FilterIDs: []string{},
- },
- },
- Weight: 20,
- }
- sort.Strings(revTPAlsPrf.FilterIDs)
- sort.Slice(revTPAlsPrf.Attributes, func(i, j int) bool {
- return strings.Compare(revTPAlsPrf.Attributes[i].Path, revTPAlsPrf.Attributes[j].Path) == -1
- })
- if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- sort.Slice(reply.Attributes, func(i, j int) bool {
- return strings.Compare(reply.Attributes[i].Path, reply.Attributes[j].Path) == -1
- })
- if !reflect.DeepEqual(tpAlsPrf, reply) && !reflect.DeepEqual(revTPAlsPrf, reply) {
- t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpAlsPrf), utils.ToJSON(reply))
- }
-}
-
-func testTPAlsPrfRemTPAlsPrf(t *testing.T) {
- var resp string
- if err := tpAlsPrfRPC.Call(utils.APIerSv1RemoveTPAttributeProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPAlsPrfGetTPAlsPrfAfterRemove(t *testing.T) {
- var reply *utils.TPAttributeProfile
- if err := tpAlsPrfRPC.Call(utils.APIerSv1GetTPAttributeProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPAlsPrfKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpAlsPrfDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpchargers.go b/apier/v1/tpchargers.go
deleted file mode 100755
index 6cb4d26cc..000000000
--- a/apier/v1/tpchargers.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPCharger creates a new ChargerProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPCharger(attr *utils.TPChargerProfile, reply *string) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPChargers([]*utils.TPChargerProfile{attr}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPCharger queries specific ChargerProfile on Tariff plan
-func (apierSv1 *APIerSv1) GetTPCharger(attr *utils.TPTntID, reply *utils.TPChargerProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rls, err := apierSv1.StorDb.GetTPChargers(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rls[0]
- return nil
-}
-
-type AttrGetTPChargerIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPChargerIDs queries Charger identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPChargerIDs(attrs *AttrGetTPChargerIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPChargers, []string{utils.TenantCfg, utils.IDCfg},
- nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPCharger removes specific ChargerProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPCharger(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPChargers, attrs.TPid,
- map[string]string{"tenant": attrs.Tenant, "id": attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpchargers_it_test.go b/apier/v1/tpchargers_it_test.go
deleted file mode 100644
index 38c20da6c..000000000
--- a/apier/v1/tpchargers_it_test.go
+++ /dev/null
@@ -1,218 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpChrgsCfgPath string
- tpChrgsCfg *config.CGRConfig
- tpChrgsRPC *rpc.Client
- tpChrgs *utils.TPChargerProfile
- tpChrgsDelay int
- tpChrgsConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPChrgs = []func(t *testing.T){
- testTPChrgsInitCfg,
- testTPChrgsResetStorDb,
- testTPChrgsStartEngine,
- testTPChrgsRPCConn,
- testTPChrgsGetTPChrgsBeforeSet,
- testTPChrgsSetTPChrgs,
- testTPChrgsGetTPChrgsAfterSet,
- testTPChrgsGetTPChrgsIDs,
- testTPChrgsUpdateTPChrgs,
- testTPChrgsGetTPChrgsAfterUpdate,
- testTPChrgsRemTPChrgs,
- testTPChrgsGetTPChrgsAfterRemove,
- testTPChrgsKillEngine,
-}
-
-//Test start here
-func TestTPChrgsIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpChrgsConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpChrgsConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpChrgsConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPChrgs {
- t.Run(tpChrgsConfigDIR, stest)
- }
-}
-
-func testTPChrgsInitCfg(t *testing.T) {
- var err error
- tpChrgsCfgPath = path.Join(*dataDir, "conf", "samples", tpChrgsConfigDIR)
- tpChrgsCfg, err = config.NewCGRConfigFromPath(tpChrgsCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpChrgsDelay = 1000
-
-}
-
-// Wipe out the cdr database
-func testTPChrgsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpChrgsCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPChrgsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpChrgsCfgPath, tpChrgsDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPChrgsRPCConn(t *testing.T) {
- var err error
- tpChrgsRPC, err = jsonrpc.Dial(utils.TCP, tpChrgsCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPChrgsGetTPChrgsBeforeSet(t *testing.T) {
- var reply *utils.TPChargerProfile
- if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPChrgsSetTPChrgs(t *testing.T) {
- tpChrgs = &utils.TPChargerProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "Chrgs",
- FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"Attr1", "Attr2"},
- Weight: 20,
- }
- sort.Strings(tpChrgs.FilterIDs)
- sort.Strings(tpChrgs.AttributeIDs)
- var result string
- if err := tpChrgsRPC.Call(utils.APIerSv1SetTPCharger, tpChrgs, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPChrgsGetTPChrgsAfterSet(t *testing.T) {
- var reply *utils.TPChargerProfile
- if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- sort.Strings(reply.AttributeIDs)
- if !reflect.DeepEqual(tpChrgs, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpChrgs), utils.ToJSON(reply))
- }
-}
-
-func testTPChrgsGetTPChrgsIDs(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:Chrgs"}
- if err := tpChrgsRPC.Call(utils.APIerSv1GetTPChargerIDs,
- &AttrGetTPAttributeProfileIds{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedTPID), utils.ToJSON(result))
- }
-}
-
-func testTPChrgsUpdateTPChrgs(t *testing.T) {
- tpChrgs.AttributeIDs = []string{"Attr1", "Attr2", "Attr3"}
- var result string
- if err := tpChrgsRPC.Call(utils.APIerSv1SetTPCharger, tpChrgs, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPChrgsGetTPChrgsAfterUpdate(t *testing.T) {
- var reply *utils.TPChargerProfile
- if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- sort.Strings(reply.AttributeIDs)
- if !reflect.DeepEqual(tpChrgs, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpChrgs), utils.ToJSON(reply))
- }
-}
-
-func testTPChrgsRemTPChrgs(t *testing.T) {
- var resp string
- if err := tpChrgsRPC.Call(utils.APIerSv1RemoveTPCharger,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPChrgsGetTPChrgsAfterRemove(t *testing.T) {
- var reply *utils.TPChargerProfile
- if err := tpChrgsRPC.Call(utils.APIerSv1GetTPCharger,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Chrgs"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPChrgsKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpChrgsDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpdestinations.go b/apier/v1/tpdestinations.go
deleted file mode 100644
index 97c52e7cb..000000000
--- a/apier/v1/tpdestinations.go
+++ /dev/null
@@ -1,92 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPDestination creates a new destination within a tariff plan
-func (apierSv1 *APIerSv1) SetTPDestination(attrs *utils.TPDestination, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.Prefixes}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if err := apierSv1.StorDb.SetTPDestinations([]*utils.TPDestination{attrs}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-type AttrGetTPDestination struct {
- TPid string // Tariff plan id
- ID string // Destination id
-}
-
-// GetTPDestination queries a specific destination
-func (apierSv1 *APIerSv1) GetTPDestination(attrs *AttrGetTPDestination, reply *utils.TPDestination) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tpDsts, err := apierSv1.StorDb.GetTPDestinations(attrs.TPid, attrs.ID)
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- if len(tpDsts) == 0 {
- return utils.ErrNotFound
- }
- tpDst := tpDsts[0]
- *reply = utils.TPDestination{TPid: tpDst.TPid,
- ID: tpDst.ID, Prefixes: tpDst.Prefixes}
- return nil
-}
-
-type AttrGetTPDestinationIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPDestinationIDs queries destination identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPDestinationIDs(attrs *AttrGetTPDestinationIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDestinations,
- []string{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- if ids == nil {
- return utils.ErrNotFound
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPDestination removes specific Destination on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPDestination(attrs *AttrGetTPDestination, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPDestinations, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpdestinations_it_test.go b/apier/v1/tpdestinations_it_test.go
deleted file mode 100644
index 5c3bfc586..000000000
--- a/apier/v1/tpdestinations_it_test.go
+++ /dev/null
@@ -1,216 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpDestinationCfgPath string
- tpDestinationCfg *config.CGRConfig
- tpDestinationRPC *rpc.Client
- tpDestination *utils.TPDestination
- tpDestinationDelay int
- tpDestinationConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPDestinations = []func(t *testing.T){
- testTPDestinationsInitCfg,
- testTPDestinationsResetStorDb,
- testTPDestinationsStartEngine,
- testTPDestinationsRpcConn,
- testTPDestinationsGetTPDestinationBeforeSet,
- testTPDestinationsSetTPDestination,
- testTPDestinationsGetTPDestinationAfterSet,
- testTPDestinationsGetTPDestinationIds,
- testTPDestinationsUpdateTPDestination,
- testTPDestinationsGetTPDestinationAfterUpdate,
- testTPDestinationsRemoveTPDestination,
- testTPDestinationsGetTPDestinationAfterRemove,
- testTPDestinationsKillEngine,
-}
-
-//Test start here
-func TestTPDestinationsIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpDestinationConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpDestinationConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpDestinationConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- tpDestinationConfigDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPDestinations {
- t.Run(tpDestinationConfigDIR, stest)
- }
-}
-
-func testTPDestinationsInitCfg(t *testing.T) {
- var err error
- tpDestinationCfgPath = path.Join(*dataDir, "conf", "samples", tpDestinationConfigDIR)
- tpDestinationCfg, err = config.NewCGRConfigFromPath(tpDestinationCfgPath)
- if err != nil {
- t.Error(err)
- }
- switch tpDestinationConfigDIR {
- case "tutmongo": // Mongo needs more time to reset db, need to investigate
- tpDestinationDelay = 2000
- default:
- tpDestinationDelay = 1000
- }
-}
-
-// Wipe out the cdr database
-func testTPDestinationsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpDestinationCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPDestinationsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpDestinationCfgPath, tpDestinationDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPDestinationsRpcConn(t *testing.T) {
- var err error
- tpDestinationRPC, err = jsonrpc.Dial(utils.TCP, tpDestinationCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPDestinationsGetTPDestinationBeforeSet(t *testing.T) {
- var reply *utils.TPDestination
- if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination,
- &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
-}
-
-func testTPDestinationsSetTPDestination(t *testing.T) {
- tpDestination = &utils.TPDestination{
- TPid: "TPD",
- ID: "GERMANY",
- Prefixes: []string{"+49", "+4915"},
- }
- var result string
- if err := tpDestinationRPC.Call(utils.APIerSv1SetTPDestination, tpDestination, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPDestinationsGetTPDestinationAfterSet(t *testing.T) {
- var reply *utils.TPDestination
- if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination,
- &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tpDestination.TPid, reply.TPid) {
- t.Errorf("Expecting : %+v, received: %+v", tpDestination.TPid, reply.TPid)
- } else if !reflect.DeepEqual(tpDestination.ID, reply.ID) {
- t.Errorf("Expecting : %+v, received: %+v", tpDestination.ID, reply.ID)
- } else if !reflect.DeepEqual(len(tpDestination.Prefixes), len(reply.Prefixes)) {
- t.Errorf("Expecting : %+v, received: %+v", len(tpDestination.Prefixes), len(reply.Prefixes))
- }
-
-}
-
-func testTPDestinationsGetTPDestinationIds(t *testing.T) {
- var result []string
- expectedTPID := []string{"GERMANY"}
- if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestinationIDs,
- &AttrGetTPDestinationIds{TPid: "TPD"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-
-}
-
-func testTPDestinationsUpdateTPDestination(t *testing.T) {
- tpDestination.Prefixes = []string{"+49", "+4915", "+4916"}
- var result string
- if err := tpDestinationRPC.Call(utils.APIerSv1SetTPDestination, tpDestination, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
-}
-
-func testTPDestinationsGetTPDestinationAfterUpdate(t *testing.T) {
- var reply *utils.TPDestination
- if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination,
- &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tpDestination.TPid, reply.TPid) {
- t.Errorf("Expecting : %+v, received: %+v", tpDestination.TPid, reply.TPid)
- } else if !reflect.DeepEqual(tpDestination.ID, reply.ID) {
- t.Errorf("Expecting : %+v, received: %+v", tpDestination.ID, reply.ID)
- } else if !reflect.DeepEqual(len(tpDestination.Prefixes), len(reply.Prefixes)) {
- t.Errorf("Expecting : %+v, received: %+v", len(tpDestination.Prefixes), len(reply.Prefixes))
- }
-
-}
-
-func testTPDestinationsRemoveTPDestination(t *testing.T) {
- var resp string
- if err := tpDestinationRPC.Call(utils.APIerSv1RemoveTPDestination,
- &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-
-}
-
-func testTPDestinationsGetTPDestinationAfterRemove(t *testing.T) {
- var reply *utils.TPDestination
- if err := tpDestinationRPC.Call(utils.APIerSv1GetTPDestination,
- &AttrGetTPDestination{TPid: "TPD", ID: "GERMANY"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPDestinationsKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpDestinationDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpdispatchers.go b/apier/v1/tpdispatchers.go
deleted file mode 100644
index e5cafabe7..000000000
--- a/apier/v1/tpdispatchers.go
+++ /dev/null
@@ -1,164 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPDispatcherProfile creates a new DispatcherProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPDispatcherProfile(attr *utils.TPDispatcherProfile, reply *string) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPDispatcherProfiles([]*utils.TPDispatcherProfile{attr}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPDispatcherProfile queries specific DispatcherProfile on Tariff plan
-func (apierSv1 *APIerSv1) GetTPDispatcherProfile(attr *utils.TPTntID, reply *utils.TPDispatcherProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
-
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rls, err := apierSv1.StorDb.GetTPDispatcherProfiles(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rls[0]
- return nil
-}
-
-type AttrGetTPDispatcherIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPDispatcherProfileIDs queries dispatcher identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPDispatcherProfileIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatchers, []string{utils.TenantCfg, utils.IDCfg},
- nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPDispatcherProfile removes specific DispatcherProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPDispatcherProfile(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPDispatchers, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// SetTPDispatcherHost creates a new DispatcherHost within a tariff plan
-func (apierSv1 *APIerSv1) SetTPDispatcherHost(attr *utils.TPDispatcherHost, reply *string) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPDispatcherHosts([]*utils.TPDispatcherHost{attr}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPDispatcherHost queries specific DispatcherHosts on Tariff plan
-func (apierSv1 *APIerSv1) GetTPDispatcherHost(attr *utils.TPTntID, reply *utils.TPDispatcherHost) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
-
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rls, err := apierSv1.StorDb.GetTPDispatcherHosts(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rls[0]
- return nil
-}
-
-// GetTPDispatcherHostIDs queries dispatcher host identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPDispatcherHostIDs(attrs *AttrGetTPDispatcherIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPDispatcherHosts, []string{utils.TenantCfg, utils.IDCfg},
- nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPDispatcherHost removes specific DispatcherHost on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPDispatcherHost(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPDispatcherHosts, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpdispatchers_it_test.go b/apier/v1/tpdispatchers_it_test.go
deleted file mode 100644
index e4c7eebae..000000000
--- a/apier/v1/tpdispatchers_it_test.go
+++ /dev/null
@@ -1,220 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpDispatcherCfgPath string
- tpDispatcherCfg *config.CGRConfig
- tpDispatcherRPC *rpc.Client
- tpDispatcher *utils.TPDispatcherProfile
- tpDispatcherDelay int
- tpDispatcherConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPDispatchers = []func(t *testing.T){
- testTPDispatcherInitCfg,
- testTPDispatcherResetStorDb,
- testTPDispatcherStartEngine,
- testTPDispatcherRpcConn,
- testTPDispatcherGetTPDispatcherBeforeSet,
- testTPDispatcherSetTPDispatcher,
- testTPDispatcherGetTPDispatcherAfterSet,
- testTPDispatcherGetTPDispatcherIds,
- testTPDispatcherUpdateTPDispatcher,
- testTPDispatcherGetTPDispatcherAfterUpdate,
- testTPDispatcherRemTPDispatcher,
- testTPDispatcherGetTPDispatcherAfterRemove,
- testTPDispatcherKillEngine,
-}
-
-//Test start here
-func TestTPDispatcherIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpDispatcherConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpDispatcherConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpDispatcherConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPDispatchers {
- t.Run(tpDispatcherConfigDIR, stest)
- }
-}
-
-func testTPDispatcherInitCfg(t *testing.T) {
- var err error
- tpDispatcherCfgPath = path.Join(*dataDir, "conf", "samples", tpDispatcherConfigDIR)
- tpDispatcherCfg, err = config.NewCGRConfigFromPath(tpDispatcherCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpDispatcherDelay = 1000
-
-}
-
-// Wipe out the cdr database
-func testTPDispatcherResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpDispatcherCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPDispatcherStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpDispatcherCfgPath, tpDispatcherDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPDispatcherRpcConn(t *testing.T) {
- var err error
- tpDispatcherRPC, err = jsonrpc.Dial(utils.TCP, tpDispatcherCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPDispatcherGetTPDispatcherBeforeSet(t *testing.T) {
- var reply *utils.TPDispatcherProfile
- if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPDispatcherSetTPDispatcher(t *testing.T) {
- tpDispatcher = &utils.TPDispatcherProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "Dsp1",
- FilterIDs: []string{"*string:Account:1002"},
- Subsystems: make([]string, 0),
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- Strategy: utils.MetaFirst,
- Weight: 10,
- }
-
- var result string
- if err := tpDispatcherRPC.Call(utils.APIerSv1SetTPDispatcherProfile, tpDispatcher, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPDispatcherGetTPDispatcherAfterSet(t *testing.T) {
- var reply *utils.TPDispatcherProfile
- if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tpDispatcher, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpDispatcher), utils.ToJSON(reply))
- }
-}
-
-func testTPDispatcherGetTPDispatcherIds(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:Dsp1"}
- if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfileIDs,
- &AttrGetTPDispatcherIds{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-}
-
-func testTPDispatcherUpdateTPDispatcher(t *testing.T) {
- var result string
- if err := tpDispatcherRPC.Call(utils.APIerSv1SetTPDispatcherProfile, tpDispatcher, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPDispatcherGetTPDispatcherAfterUpdate(t *testing.T) {
- var reply *utils.TPDispatcherProfile
- revHosts := &utils.TPDispatcherProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "Dsp1",
- FilterIDs: []string{"*string:Account:1002"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- Strategy: utils.MetaFirst,
- Weight: 10,
- }
- if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &reply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tpDispatcher, reply) && !reflect.DeepEqual(revHosts, reply) {
- t.Errorf("Expecting : %+v \n and %+v\n, received: %+v", utils.ToJSON(tpDispatcher), utils.ToJSON(revHosts), utils.ToJSON(reply))
- }
-}
-
-func testTPDispatcherRemTPDispatcher(t *testing.T) {
- var resp string
- if err := tpDispatcherRPC.Call(utils.APIerSv1RemoveTPDispatcherProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPDispatcherGetTPDispatcherAfterRemove(t *testing.T) {
- var reply *utils.TPDispatcherProfile
- if err := tpDispatcherRPC.Call(utils.APIerSv1GetTPDispatcherProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Dsp1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPDispatcherKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpDispatcherDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpfilters.go b/apier/v1/tpfilters.go
deleted file mode 100644
index e10d0b4a7..000000000
--- a/apier/v1/tpfilters.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPFilterProfile creates a new FilterProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPFilterProfile(attrs *utils.TPFilterProfile, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPFilters([]*utils.TPFilterProfile{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPFilterProfile queries specific FilterProfile on tariff plan
-func (apierSv1 *APIerSv1) GetTPFilterProfile(attr *utils.TPTntID, reply *utils.TPFilterProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- filter, err := apierSv1.StorDb.GetTPFilters(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *filter[0]
- return nil
-}
-
-type AttrGetTPFilterProfileIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPFilterProfileIds queries FilterProfile identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPFilterProfileIds(attrs *AttrGetTPFilterProfileIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPFilters, []string{utils.TenantCfg, utils.IDCfg},
- nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPFilterProfile removes specific FilterProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPFilterProfile(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPFilters, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tpfilters_it_test.go b/apier/v1/tpfilters_it_test.go
deleted file mode 100644
index 8424e0b74..000000000
--- a/apier/v1/tpfilters_it_test.go
+++ /dev/null
@@ -1,239 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "strings"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpFilterCfgPath string
- tpFilterCfg *config.CGRConfig
- tpFilterRPC *rpc.Client
- tpFilter *utils.TPFilterProfile
- tpFilterDelay int
- tpFilterConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPFilters = []func(t *testing.T){
- testTPFilterInitCfg,
- testTPFilterResetStorDb,
- testTPFilterStartEngine,
- testTPFilterRpcConn,
- ttestTPFilterGetTPFilterBeforeSet,
- testTPFilterSetTPFilter,
- testTPFilterGetTPFilterAfterSet,
- testTPFilterGetFilterIds,
- testTPFilterUpdateTPFilter,
- testTPFilterGetTPFilterAfterUpdate,
- testTPFilterRemTPFilter,
- testTPFilterGetTPFilterAfterRemove,
- testTPFilterKillEngine,
-}
-
-//Test start here
-func TestTPFilterITMySql(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpFilterConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpFilterConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpFilterConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- tpFilterConfigDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPFilters {
- t.Run(tpFilterConfigDIR, stest)
- }
-}
-
-func testTPFilterInitCfg(t *testing.T) {
- var err error
- tpFilterCfgPath = path.Join(*dataDir, "conf", "samples", tpFilterConfigDIR)
- tpFilterCfg, err = config.NewCGRConfigFromPath(tpFilterCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpFilterDelay = 1000
-
-}
-
-// Wipe out the cdr database
-func testTPFilterResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpFilterCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPFilterStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpFilterCfgPath, tpFilterDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPFilterRpcConn(t *testing.T) {
- var err error
- tpFilterRPC, err = jsonrpc.Dial(utils.TCP, tpFilterCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func ttestTPFilterGetTPFilterBeforeSet(t *testing.T) {
- var reply *utils.TPFilterProfile
- if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPFilterSetTPFilter(t *testing.T) {
- tpFilter = &utils.TPFilterProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "Filter",
- Filters: []*utils.TPFilter{
- &utils.TPFilter{
- Type: utils.MetaString,
- Element: "~*req.Account",
- Values: []string{"1001", "1002"},
- },
- },
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- }
- sort.Strings(tpFilter.Filters[0].Values)
-
- var result string
- if err := tpFilterRPC.Call(utils.APIerSv1SetTPFilterProfile, tpFilter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPFilterGetTPFilterAfterSet(t *testing.T) {
- var reply *utils.TPFilterProfile
- if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.Filters[0].Values)
- if !reflect.DeepEqual(tpFilter, reply) {
- t.Errorf("Expecting : %+v, received: %+v", tpFilter, reply)
- }
-}
-
-func testTPFilterGetFilterIds(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:Filter"}
- if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfileIds,
- &AttrGetTPFilterProfileIds{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-}
-
-func testTPFilterUpdateTPFilter(t *testing.T) {
- tpFilter.Filters = []*utils.TPFilter{
- &utils.TPFilter{
- Type: utils.MetaString,
- Element: "~*req.Account",
- Values: []string{"1001", "1002"},
- },
- &utils.TPFilter{
- Type: utils.MetaPrefix,
- Element: "~*req.Destination",
- Values: []string{"10", "20"},
- },
- }
- sort.Slice(tpFilter.Filters, func(i, j int) bool {
- sort.Strings(tpFilter.Filters[i].Values)
- sort.Strings(tpFilter.Filters[j].Values)
- return strings.Compare(tpFilter.Filters[i].Element, tpFilter.Filters[j].Element) == -1
- })
- var result string
- if err := tpFilterRPC.Call(utils.APIerSv1SetTPFilterProfile, tpFilter, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPFilterGetTPFilterAfterUpdate(t *testing.T) {
- var reply *utils.TPFilterProfile
- if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Slice(reply.Filters, func(i, j int) bool {
- sort.Strings(reply.Filters[i].Values)
- sort.Strings(reply.Filters[j].Values)
- return strings.Compare(reply.Filters[i].Element, reply.Filters[j].Element) == -1
- })
- if !reflect.DeepEqual(tpFilter, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpFilter), utils.ToJSON(reply))
- }
-}
-
-func testTPFilterRemTPFilter(t *testing.T) {
- var resp string
- if err := tpFilterRPC.Call(utils.APIerSv1RemoveTPFilterProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPFilterGetTPFilterAfterRemove(t *testing.T) {
- var reply *utils.TPFilterProfile
- if err := tpFilterRPC.Call(utils.APIerSv1GetTPFilterProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Filter"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPFilterKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpFilterDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tprateprofiles.go b/apier/v1/tprateprofiles.go
deleted file mode 100644
index 9e7e6ac1b..000000000
--- a/apier/v1/tprateprofiles.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPRateProfile creates a new TPRateProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPRateProfile(attrs *utils.TPRateProfile, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPRateProfiles([]*utils.TPRateProfile{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPRateProfile queries specific TPRateProfile on tariff plan
-func (apierSv1 *APIerSv1) GetTPRateProfile(attr *utils.TPTntID, reply *utils.TPRateProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- filter, err := apierSv1.StorDb.GetTPRateProfiles(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *filter[0]
- return nil
-}
-
-type AttrGetTPRateProfileIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPRateProfileIds queries TPRateProfiles identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPRateProfileIds(attrs *AttrGetTPRateProfileIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRateProfiles, []string{utils.TenantCfg, utils.IDCfg},
- nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPRateProfile removes specific TPRateProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPRateProfile(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPRateProfiles, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tprateprofiles_it_test.go b/apier/v1/tprateprofiles_it_test.go
deleted file mode 100644
index e285ee7cb..000000000
--- a/apier/v1/tprateprofiles_it_test.go
+++ /dev/null
@@ -1,242 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpRatePrfCfgPath string
- tpRatePrfCfg *config.CGRConfig
- tpRatePrfRPC *rpc.Client
- tpRatePrf *utils.TPRateProfile
- tpRatePrfDelay int
- tpRatePrfConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPRatePrf = []func(t *testing.T){
- testTPRatePrfInitCfg,
- testTPRatePrfResetStorDb,
- testTPRatePrfStartEngine,
- testTPRatePrfRPCConn,
- testTPRatePrfGetTPRatePrfBeforeSet,
- testTPRatePrfSetTPRatePrf,
- testTPRatePrfGetTPRatePrfAfterSet,
- testTPRatePrfGetTPRatePrfIDs,
- testTPRatePrfUpdateTPRatePrf,
- testTPRatePrfGetTPRatePrfAfterUpdate,
- testTPRatePrfRemTPRatePrf,
- testTPRatePrfGetTPRatePrfAfterRemove,
- testTPRatePrfKillEngine,
-}
-
-//Test start here
-func TestTPRatePrfIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpRatePrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpRatePrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpRatePrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPRatePrf {
- t.Run(tpRatePrfConfigDIR, stest)
- }
-}
-
-func testTPRatePrfInitCfg(t *testing.T) {
- var err error
- tpRatePrfCfgPath = path.Join(*dataDir, "conf", "samples", tpRatePrfConfigDIR)
- tpRatePrfCfg, err = config.NewCGRConfigFromPath(tpRatePrfCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpRatePrfDelay = 1000
-}
-
-// Wipe out the cdr database
-func testTPRatePrfResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpRatePrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPRatePrfStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpRatePrfCfgPath, tpRatePrfDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPRatePrfRPCConn(t *testing.T) {
- var err error
- tpRatePrfRPC, err = jsonrpc.Dial(utils.TCP, tpRatePrfCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPRatePrfGetTPRatePrfBeforeSet(t *testing.T) {
- var reply *utils.TPRateProfile
- if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "Attr1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPRatePrfSetTPRatePrf(t *testing.T) {
- tpRatePrf = &utils.TPRateProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "RT_SPECIAL_1002",
- Weights: ";10",
- Rates: map[string]*utils.TPRate{
- "RT_ALWAYS": {
- ID: "RT_ALWAYS",
- FilterIDs: []string{"* * * * *"},
- Weights: ";0",
- Blocker: false,
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.01,
- Unit: "1m",
- Increment: "1s",
- },
- },
- },
- },
- }
- var result string
- if err := tpRatePrfRPC.Call(utils.APIerSv1SetTPRateProfile, tpRatePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPRatePrfGetTPRatePrfAfterSet(t *testing.T) {
- var reply *utils.TPRateProfile
- if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- if !reflect.DeepEqual(tpRatePrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpRatePrf), utils.ToJSON(reply))
- }
-}
-
-func testTPRatePrfGetTPRatePrfIDs(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:RT_SPECIAL_1002"}
- if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfileIds,
- &AttrGetTPRateProfileIds{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-}
-
-func testTPRatePrfUpdateTPRatePrf(t *testing.T) {
- tpRatePrf.Rates = map[string]*utils.TPRate{
- "RT_ALWAYS": {
- ID: "RT_ALWAYS",
- FilterIDs: []string{"* * * * *"},
- Weights: ";0",
- Blocker: false,
- IntervalRates: []*utils.TPIntervalRate{
- {
- IntervalStart: "0s",
- RecurrentFee: 0.01,
- Unit: "1m",
- Increment: "1s",
- },
- },
- },
- }
- var result string
- if err := tpRatePrfRPC.Call(utils.APIerSv1SetTPRateProfile, tpRatePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPRatePrfGetTPRatePrfAfterUpdate(t *testing.T) {
- var reply *utils.TPRateProfile
- revTPRatePrf := &utils.TPRateProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "RT_SPECIAL_1002",
- Weights: ";10",
- }
-
- if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"}, &reply); err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(tpRatePrf, reply) && !reflect.DeepEqual(revTPRatePrf, reply) {
- t.Errorf("Expecting : %+v, \n received: %+v", utils.ToJSON(tpRatePrf), utils.ToJSON(reply))
- }
-}
-
-func testTPRatePrfRemTPRatePrf(t *testing.T) {
- var resp string
- if err := tpRatePrfRPC.Call(utils.APIerSv1RemoveTPRateProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPRatePrfGetTPRatePrfAfterRemove(t *testing.T) {
- var reply *utils.TPActionProfile
- if err := tpRatePrfRPC.Call(utils.APIerSv1GetTPRateProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RT_SPECIAL_1002"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPRatePrfKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpRatePrfDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpresources.go b/apier/v1/tpresources.go
deleted file mode 100644
index 5093274fe..000000000
--- a/apier/v1/tpresources.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPResource creates a new resource within a tariff plan
-func (apierSv1 *APIerSv1) SetTPResource(attr *utils.TPResourceProfile, reply *string) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID, utils.Limit}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPResources([]*utils.TPResourceProfile{attr}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPResource queries specific Resource on Tariff plan
-func (apierSv1 *APIerSv1) GetTPResource(attr *utils.TPTntID, reply *utils.TPResourceProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rls, err := apierSv1.StorDb.GetTPResources(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rls[0]
- return nil
-}
-
-type AttrGetTPResourceIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPResourceIDs queries Resource identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPResourceIDs(attrs *AttrGetTPResourceIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPResources,
- []string{utils.TenantCfg, utils.IDCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPResource removes specific Resource on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPResource(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPResources, attrs.TPid, map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-
-}
diff --git a/apier/v1/tpresources_it_test.go b/apier/v1/tpresources_it_test.go
deleted file mode 100644
index c3fe2a45f..000000000
--- a/apier/v1/tpresources_it_test.go
+++ /dev/null
@@ -1,206 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpResCfgPath string
- tpResCfg *config.CGRConfig
- tpResRPC *rpc.Client
- tpRes *utils.TPResourceProfile
- tpResDelay int
- tpResConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPResources = []func(t *testing.T){
- testTPResInitCfg,
- testTPResResetStorDb,
- testTPResStartEngine,
- testTPResRpcConn,
- testTPResGetTPResourceBeforeSet,
- testTPResSetTPResource,
- testTPResGetTPResourceAfterSet,
- testTPResUpdateTPResource,
- testTPResGetTPResourceAfterUpdate,
- testTPResRemoveTPResource,
- testTPResGetTPResourceAfterRemove,
- testTPResKillEngine,
-}
-
-//Test start here
-func TestTPResIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpResConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpResConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpResConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- tpResConfigDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPResources {
- t.Run(tpResConfigDIR, stest)
- }
-}
-
-func testTPResInitCfg(t *testing.T) {
- var err error
- tpResCfgPath = path.Join(*dataDir, "conf", "samples", tpResConfigDIR)
- tpResCfg, err = config.NewCGRConfigFromPath(tpResCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpResDelay = 1000
-}
-
-// Wipe out the cdr database
-func testTPResResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpResCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPResStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpResCfgPath, tpResDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPResRpcConn(t *testing.T) {
- var err error
- tpResRPC, err = jsonrpc.Dial(utils.TCP, tpResCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPResGetTPResourceBeforeSet(t *testing.T) {
- var reply *utils.TPResourceProfile
- if err := tpResRPC.Call(utils.APIerSv1GetTPResource,
- &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPResSetTPResource(t *testing.T) {
- tpRes = &utils.TPResourceProfile{
- Tenant: "cgrates.org",
- TPid: "TPR1",
- ID: "ResGroup1",
- FilterIDs: []string{"FLTR_1"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- UsageTTL: "1s",
- Limit: "7",
- AllocationMessage: "",
- Blocker: true,
- Stored: true,
- Weight: 20,
- ThresholdIDs: []string{"ValOne", "ValTwo"},
- }
- sort.Strings(tpRes.ThresholdIDs)
- var result string
- if err := tpResRPC.Call(utils.APIerSv1SetTPResource, tpRes, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPResGetTPResourceAfterSet(t *testing.T) {
- var respond *utils.TPResourceProfile
- if err := tpResRPC.Call(utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"},
- &respond); err != nil {
- t.Fatal(err)
- }
- sort.Strings(respond.ThresholdIDs)
- if !reflect.DeepEqual(tpRes, respond) {
- t.Errorf("Expecting : %+v, received: %+v", tpRes, respond)
- }
-}
-
-func testTPResUpdateTPResource(t *testing.T) {
- var result string
- tpRes.FilterIDs = []string{"FLTR_1", "FLTR_STS1"}
- sort.Strings(tpRes.FilterIDs)
- if err := tpResRPC.Call(utils.APIerSv1SetTPResource, tpRes, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPResGetTPResourceAfterUpdate(t *testing.T) {
- var expectedTPR *utils.TPResourceProfile
- if err := tpResRPC.Call(utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"},
- &expectedTPR); err != nil {
- t.Fatal(err)
- }
- sort.Strings(expectedTPR.FilterIDs)
- sort.Strings(expectedTPR.ThresholdIDs)
- if !reflect.DeepEqual(tpRes, expectedTPR) {
- t.Errorf("Expecting: %+v, received: %+v", tpRes, expectedTPR)
- }
-}
-
-func testTPResRemoveTPResource(t *testing.T) {
- var resp string
- if err := tpResRPC.Call(utils.APIerSv1RemoveTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPResGetTPResourceAfterRemove(t *testing.T) {
- var respond *utils.TPResourceProfile
- if err := tpResRPC.Call(utils.APIerSv1GetTPResource, &utils.TPTntID{TPid: "TPR1", Tenant: "cgrates.org", ID: "ResGroup1"},
- &respond); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPResKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpResDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tproutes.go b/apier/v1/tproutes.go
deleted file mode 100644
index 5c1a6d637..000000000
--- a/apier/v1/tproutes.go
+++ /dev/null
@@ -1,95 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPRouteProfile creates a new RouteProfile within a tariff plan
-func (apierSv1 *APIerSv1) SetTPRouteProfile(attrs *utils.TPRouteProfile, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPRoutes([]*utils.TPRouteProfile{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPRouteProfile queries specific RouteProfile on tariff plan
-func (apierSv1 *APIerSv1) GetTPRouteProfile(attr *utils.TPTntID, reply *utils.TPRouteProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- spp, err := apierSv1.StorDb.GetTPRoutes(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *spp[0]
- return nil
-}
-
-type AttrGetTPRouteProfileIDs struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPRouteProfileIDs queries RouteProfile identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPRouteProfileIDs(attrs *AttrGetTPRouteProfileIDs, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPRoutes,
- []string{utils.TenantCfg, utils.IDCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPRouteProfile removes specific RouteProfile on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPRouteProfile(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPRoutes, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tproutes_it_test.go b/apier/v1/tproutes_it_test.go
deleted file mode 100644
index b14474b7b..000000000
--- a/apier/v1/tproutes_it_test.go
+++ /dev/null
@@ -1,260 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "strings"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpRouteCfgPath string
- tpRouteCfg *config.CGRConfig
- tpRouteRPC *rpc.Client
- tpRoutePrf *utils.TPRouteProfile
- tpRouteDelay int
- tpRouteConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPRoute = []func(t *testing.T){
- testTPRouteInitCfg,
- testTPRouteResetStorDb,
- testTPRouteStartEngine,
- testTPRouteRPCConn,
- testTPRouteGetTPRouteBeforeSet,
- testTPRouteSetTPRoute,
- testTPRouteGetTPRouteAfterSet,
- testTPRouteGetTPRouteIDs,
- testTPRouteUpdateTPRoute,
- testTPRouteGetTPRouteAfterUpdate,
- testTPRouteRemTPRoute,
- testTPRouteGetTPRouteAfterRemove,
- testTPRouteKillEngine,
-}
-
-//Test start here
-func TestTPRouteIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpRouteConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpRouteConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpRouteConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPRoute {
- t.Run(tpRouteConfigDIR, stest)
- }
-}
-
-func testTPRouteInitCfg(t *testing.T) {
- var err error
- tpRouteCfgPath = path.Join(*dataDir, "conf", "samples", tpRouteConfigDIR)
- tpRouteCfg, err = config.NewCGRConfigFromPath(tpRouteCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpRouteDelay = 1000
-
-}
-
-// Wipe out the cdr database
-func testTPRouteResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpRouteCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPRouteStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpRouteCfgPath, tpRouteDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPRouteRPCConn(t *testing.T) {
- var err error
- tpRouteRPC, err = jsonrpc.Dial(utils.TCP, tpRouteCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPRouteGetTPRouteBeforeSet(t *testing.T) {
- var reply *utils.TPRoute
- if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPRouteSetTPRoute(t *testing.T) {
- tpRoutePrf = &utils.TPRouteProfile{
- TPid: "TP1",
- Tenant: "cgrates.org",
- ID: "RoutePrf",
- FilterIDs: []string{"FLTR_ACNT_dan", "FLTR_DST_DE"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- Sorting: "*lc",
- Routes: []*utils.TPRoute{
- &utils.TPRoute{
- ID: "route1",
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc1", "Acc2"},
- RatingPlanIDs: []string{"RPL_1"},
- ResourceIDs: []string{"ResGroup1"},
- StatIDs: []string{"Stat1"},
- Weight: 10,
- Blocker: false,
- RouteParameters: "SortingParam1",
- },
- },
- Weight: 20,
- }
- sort.Strings(tpRoutePrf.FilterIDs)
- var result string
- if err := tpRouteRPC.Call(utils.APIerSv1SetTPRouteProfile,
- tpRoutePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPRouteGetTPRouteAfterSet(t *testing.T) {
- var reply *utils.TPRouteProfile
- if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- if !reflect.DeepEqual(tpRoutePrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(tpRoutePrf), utils.ToJSON(reply))
- }
-}
-
-func testTPRouteGetTPRouteIDs(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:RoutePrf"}
- if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfileIDs,
- &AttrGetTPRouteProfileIDs{TPid: "TP1"}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(expectedTPID, result) {
- t.Errorf("Expecting: %+v, received: %+v", expectedTPID, result)
- }
-
-}
-
-func testTPRouteUpdateTPRoute(t *testing.T) {
- tpRoutePrf.Routes = []*utils.TPRoute{
- &utils.TPRoute{
- ID: "route1",
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc1", "Acc2"},
- RatingPlanIDs: []string{"RPL_1"},
- ResourceIDs: []string{"ResGroup1"},
- StatIDs: []string{"Stat1"},
- Weight: 10,
- Blocker: true,
- RouteParameters: "SortingParam1",
- },
- &utils.TPRoute{
- ID: "route2",
- FilterIDs: []string{"FLTR_1"},
- AccountIDs: []string{"Acc3"},
- RatingPlanIDs: []string{"RPL_1"},
- ResourceIDs: []string{"ResGroup1"},
- StatIDs: []string{"Stat1"},
- Weight: 20,
- Blocker: false,
- RouteParameters: "SortingParam2",
- },
- }
- var result string
- if err := tpRouteRPC.Call(utils.APIerSv1SetTPRouteProfile,
- tpRoutePrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- sort.Slice(tpRoutePrf.Routes, func(i, j int) bool {
- return strings.Compare(tpRoutePrf.Routes[i].ID, tpRoutePrf.Routes[j].ID) == -1
- })
-}
-
-func testTPRouteGetTPRouteAfterUpdate(t *testing.T) {
- var reply *utils.TPRouteProfile
- if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.FilterIDs)
- sort.Slice(reply.Routes, func(i, j int) bool {
- return strings.Compare(reply.Routes[i].ID, reply.Routes[j].ID) == -1
- })
- if !reflect.DeepEqual(tpRoutePrf.Routes, reply.Routes) {
- t.Errorf("Expecting: %+v,\n received: %+v", utils.ToJSON(tpRoutePrf), utils.ToJSON(reply))
- }
-}
-
-func testTPRouteRemTPRoute(t *testing.T) {
- var resp string
- if err := tpRouteRPC.Call(utils.APIerSv1RemoveTPRouteProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"},
- &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPRouteGetTPRouteAfterRemove(t *testing.T) {
- var reply *utils.TPRouteProfile
- if err := tpRouteRPC.Call(utils.APIerSv1GetTPRouteProfile,
- &utils.TPTntID{TPid: "TP1", Tenant: "cgrates.org", ID: "RoutePrf"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPRouteKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpRouteDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpstats.go b/apier/v1/tpstats.go
deleted file mode 100644
index d2d332c05..000000000
--- a/apier/v1/tpstats.go
+++ /dev/null
@@ -1,100 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPStat creates a new stat within a tariff plan
-func (apierSv1 *APIerSv1) SetTPStat(attr *utils.TPStatProfile, reply *string) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPStats([]*utils.TPStatProfile{attr}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPStat queries specific Stat on Tariff plan
-func (apierSv1 *APIerSv1) GetTPStat(attr *utils.TPTntID, reply *utils.TPStatProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rls, err := apierSv1.StorDb.GetTPStats(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rls[0]
- return nil
-}
-
-type AttrGetTPStatIds struct {
- TPid string // Tariff plan id
- Tenant string
- utils.PaginatorWithSearch
-}
-
-// GetTPStatIDs queries Stat identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPStatIDs(attrs *AttrGetTPStatIds, reply *[]string) error {
- if missing := utils.MissingStructFields(&attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPStats,
- []string{utils.TenantCfg, utils.IDCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPStat removes specific Stat on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPStat(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPStats, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-
-}
diff --git a/apier/v1/tpstats_it_test.go b/apier/v1/tpstats_it_test.go
deleted file mode 100644
index ada0573f6..000000000
--- a/apier/v1/tpstats_it_test.go
+++ /dev/null
@@ -1,224 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "strings"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpStatCfgPath string
- tpStatCfg *config.CGRConfig
- tpStatRPC *rpc.Client
- tpStat *utils.TPStatProfile
- tpStatDelay int
- tpStatConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPStats = []func(t *testing.T){
- testTPStatsInitCfg,
- testTPStatsResetStorDb,
- testTPStatsStartEngine,
- testTPStatsRpcConn,
- testTPStatsGetTPStatBeforeSet,
- testTPStatsSetTPStat,
- testTPStatsGetTPStatAfterSet,
- testTPStatsUpdateTPStat,
- testTPStatsGetTPStatAfterUpdate,
- testTPStatsRemoveTPStat,
- testTPStatsGetTPStatAfterRemove,
- testTPStatsKillEngine,
-}
-
-//Test start here
-func TestTPStatIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpStatConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpStatConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpStatConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- tpStatConfigDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPStats {
- t.Run(tpStatConfigDIR, stest)
- }
-}
-
-func testTPStatsInitCfg(t *testing.T) {
- var err error
- tpStatCfgPath = path.Join(*dataDir, "conf", "samples", tpStatConfigDIR)
- tpStatCfg, err = config.NewCGRConfigFromPath(tpStatCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpStatDelay = 1000
-}
-
-// Wipe out the cdr database
-func testTPStatsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpStatCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPStatsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpStatCfgPath, tpStatDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPStatsRpcConn(t *testing.T) {
- var err error
- tpStatRPC, err = jsonrpc.Dial(utils.TCP, tpStatCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPStatsGetTPStatBeforeSet(t *testing.T) {
- var reply *utils.TPStatProfile
- if err := tpStatRPC.Call(utils.APIerSv1GetTPStat,
- &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"},
- &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPStatsSetTPStat(t *testing.T) {
- tpStat = &utils.TPStatProfile{
- Tenant: "cgrates.org",
- TPid: "TPS1",
- ID: "Stat1",
- FilterIDs: []string{"FLTR_1"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- TTL: "1",
- Metrics: []*utils.MetricWithFilters{
- &utils.MetricWithFilters{
- MetricID: "*sum",
- },
- },
- Blocker: false,
- Stored: false,
- Weight: 20,
- MinItems: 1,
- ThresholdIDs: []string{"ThreshValue", "ThreshValueTwo"},
- }
- sort.Strings(tpStat.ThresholdIDs)
- var result string
- if err := tpStatRPC.Call(utils.APIerSv1SetTPStat, tpStat, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPStatsGetTPStatAfterSet(t *testing.T) {
- var respond *utils.TPStatProfile
- if err := tpStatRPC.Call(utils.APIerSv1GetTPStat,
- &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &respond); err != nil {
- t.Fatal(err)
- }
- sort.Strings(respond.ThresholdIDs)
- if !reflect.DeepEqual(tpStat, respond) {
- t.Errorf("Expecting: %+v, received: %+v", tpStat, respond)
- }
-}
-
-func testTPStatsUpdateTPStat(t *testing.T) {
- var result string
- tpStat.Weight = 21
- tpStat.Metrics = []*utils.MetricWithFilters{
- &utils.MetricWithFilters{
- MetricID: "*sum",
- },
- &utils.MetricWithFilters{
- MetricID: "*averege",
- },
- }
- sort.Slice(tpStat.Metrics, func(i, j int) bool {
- return strings.Compare(tpStat.Metrics[i].MetricID, tpStat.Metrics[j].MetricID) == -1
- })
- if err := tpStatRPC.Call(utils.APIerSv1SetTPStat, tpStat, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPStatsGetTPStatAfterUpdate(t *testing.T) {
- var expectedTPS *utils.TPStatProfile
- if err := tpStatRPC.Call(utils.APIerSv1GetTPStat,
- &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &expectedTPS); err != nil {
- t.Fatal(err)
- }
- sort.Strings(expectedTPS.ThresholdIDs)
- sort.Slice(expectedTPS.Metrics, func(i, j int) bool {
- return strings.Compare(expectedTPS.Metrics[i].MetricID, expectedTPS.Metrics[j].MetricID) == -1
- })
- if !reflect.DeepEqual(tpStat, expectedTPS) {
- t.Errorf("Expecting: %+v, received: %+v", tpStat, expectedTPS)
- }
-}
-
-func testTPStatsRemoveTPStat(t *testing.T) {
- var resp string
- if err := tpStatRPC.Call(utils.APIerSv1RemoveTPStat,
- &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPStatsGetTPStatAfterRemove(t *testing.T) {
- var respond *utils.TPStatProfile
- if err := tpStatRPC.Call(utils.APIerSv1GetTPStat,
- &utils.TPTntID{TPid: "TPS1", Tenant: "cgrates.org", ID: "Stat1"},
- &respond); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPStatsKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpStatDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tpthresholds.go b/apier/v1/tpthresholds.go
deleted file mode 100644
index 934b56c34..000000000
--- a/apier/v1/tpthresholds.go
+++ /dev/null
@@ -1,100 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPThreshold creates a new threshold within a tariff plan
-func (apierSv1 *APIerSv1) SetTPThreshold(attr *utils.TPThresholdProfile, reply *string) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.SetTPThresholds([]*utils.TPThresholdProfile{attr}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// GetTPThreshold queries specific Threshold on Tariff plan
-func (apierSv1 *APIerSv1) GetTPThreshold(attr *utils.TPTntID, reply *utils.TPThresholdProfile) error {
- if missing := utils.MissingStructFields(attr, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attr.Tenant == utils.EmptyString {
- attr.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- rls, err := apierSv1.StorDb.GetTPThresholds(attr.TPid, attr.Tenant, attr.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *rls[0]
- return nil
-}
-
-type AttrGetTPThresholdIds struct {
- TPid string // Tariff plan id
- Tenant string
- utils.PaginatorWithSearch
-}
-
-// GetTPThresholdIDs queries Threshold identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPThresholdIDs(attrs *AttrGetTPThresholdIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPThresholds,
- []string{utils.TenantCfg, utils.IDCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPThreshold removes specific Threshold on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPThreshold(attrs *utils.TPTntID, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if attrs.Tenant == utils.EmptyString {
- attrs.Tenant = apierSv1.Config.GeneralCfg().DefaultTenant
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPThresholds, attrs.TPid,
- map[string]string{utils.TenantCfg: attrs.Tenant, utils.IDCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-
-}
diff --git a/apier/v1/tpthresholds_it_test.go b/apier/v1/tpthresholds_it_test.go
deleted file mode 100644
index ea0556dfc..000000000
--- a/apier/v1/tpthresholds_it_test.go
+++ /dev/null
@@ -1,219 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "sort"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpThresholdCfgPath string
- tpThresholdCfg *config.CGRConfig
- tpThresholdRPC *rpc.Client
- tpThreshold *utils.TPThresholdProfile
- tpThresholdDelay int
- tpThresholdConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPThreshold = []func(t *testing.T){
- testTPThreholdInitCfg,
- testTPThreholdResetStorDb,
- testTPThreholdStartEngine,
- testTPThreholdRpcConn,
- testTPThreholdGetTPThreholdBeforeSet,
- testTPThreholdSetTPThrehold,
- testTPThreholdGetTPThreholdAfterSet,
- testTPThreholdGetTPThreholdIds,
- testTPThreholdUpdateTPThrehold,
- testTPThreholdGetTPThreholdAfterUpdate,
- testTPThreholdRemTPThrehold,
- testTPThreholdGetTPThreholdAfterRemove,
- testTPThreholdKillEngine,
-}
-
-//Test start here
-func TestTPThresholdIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpThresholdConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpThresholdConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpThresholdConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- tpThresholdConfigDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPThreshold {
- t.Run(tpThresholdConfigDIR, stest)
- }
-}
-
-func testTPThreholdInitCfg(t *testing.T) {
- var err error
- tpThresholdCfgPath = path.Join(*dataDir, "conf", "samples", tpThresholdConfigDIR)
- tpThresholdCfg, err = config.NewCGRConfigFromPath(tpThresholdCfgPath)
- if err != nil {
- t.Error(err)
- }
- tpThresholdDelay = 1000
-
-}
-
-// Wipe out the cdr database
-func testTPThreholdResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpThresholdCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPThreholdStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpThresholdCfgPath, tpThresholdDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPThreholdRpcConn(t *testing.T) {
- var err error
- tpThresholdRPC, err = jsonrpc.Dial(utils.TCP, tpThresholdCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPThreholdGetTPThreholdBeforeSet(t *testing.T) {
- var reply *utils.TPThresholdProfile
- if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold,
- &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPThreholdSetTPThrehold(t *testing.T) {
- tpThreshold = &utils.TPThresholdProfile{
- TPid: "TH1",
- Tenant: "cgrates.org",
- ID: "Threshold",
- FilterIDs: []string{"FLTR_1", "FLTR_2"},
- ActivationInterval: &utils.TPActivationInterval{
- ActivationTime: "2014-07-29T15:00:00Z",
- ExpiryTime: "",
- },
- MinSleep: "1s",
- Blocker: true,
- Weight: 10,
- ActionIDs: []string{"Thresh1", "Thresh2"},
- Async: true,
- }
- sort.Strings(tpThreshold.FilterIDs)
- sort.Strings(tpThreshold.ActionIDs)
- var result string
- if err := tpThresholdRPC.Call(utils.APIerSv1SetTPThreshold, tpThreshold, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPThreholdGetTPThreholdAfterSet(t *testing.T) {
- var respond *utils.TPThresholdProfile
- if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold,
- &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &respond); err != nil {
- t.Fatal(err)
- }
- sort.Strings(respond.FilterIDs)
- sort.Strings(respond.ActionIDs)
- if !reflect.DeepEqual(tpThreshold, respond) {
- t.Errorf("Expecting: %+v, received: %+v", tpThreshold, respond)
- }
-}
-
-func testTPThreholdGetTPThreholdIds(t *testing.T) {
- var result []string
- expectedTPID := []string{"cgrates.org:Threshold"}
- if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThresholdIDs,
- &AttrGetTPThresholdIds{TPid: tpThreshold.TPid}, &result); err != nil {
- t.Fatal(err)
- } else if !reflect.DeepEqual(result, expectedTPID) {
- t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID)
- }
-}
-
-func testTPThreholdUpdateTPThrehold(t *testing.T) {
- var result string
- tpThreshold.FilterIDs = []string{"FLTR_1", "FLTR_2", "FLTR_3"}
- if err := tpThresholdRPC.Call(utils.APIerSv1SetTPThreshold, tpThreshold, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPThreholdGetTPThreholdAfterUpdate(t *testing.T) {
- var respond *utils.TPThresholdProfile
- if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold,
- &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &respond); err != nil {
- t.Fatal(err)
- }
- sort.Strings(respond.FilterIDs)
- sort.Strings(respond.ActionIDs)
- if !reflect.DeepEqual(tpThreshold, respond) {
- t.Errorf("Expecting: %+v, received: %+v", tpThreshold, respond)
- }
-}
-
-func testTPThreholdRemTPThrehold(t *testing.T) {
- var resp string
- if err := tpThresholdRPC.Call(utils.APIerSv1RemoveTPThreshold,
- &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPThreholdGetTPThreholdAfterRemove(t *testing.T) {
- var reply *utils.TPThresholdProfile
- if err := tpThresholdRPC.Call(utils.APIerSv1GetTPThreshold,
- &utils.TPTntID{TPid: "TH1", Tenant: "cgrates.org", ID: "Threshold"}, &reply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPThreholdKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpThresholdDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/tptimings.go b/apier/v1/tptimings.go
deleted file mode 100644
index 285c0b0ca..000000000
--- a/apier/v1/tptimings.go
+++ /dev/null
@@ -1,90 +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 (
- "github.com/cgrates/cgrates/utils"
-)
-
-// SetTPTiming creates a new timing within a tariff plan
-func (apierSv1 *APIerSv1) SetTPTiming(attrs *utils.ApierTPTiming, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID, utils.YearsFieldName, utils.MonthsFieldName, utils.MonthDaysFieldName, utils.WeekDaysFieldName, utils.Time}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if err := apierSv1.StorDb.SetTPTimings([]*utils.ApierTPTiming{attrs}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-type AttrGetTPTiming struct {
- TPid string // Tariff plan id
- ID string // Timing id
-}
-
-// GetTPTiming queries specific Timing on Tariff plan
-func (apierSv1 *APIerSv1) GetTPTiming(attrs *AttrGetTPTiming, reply *utils.ApierTPTiming) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- tms, err := apierSv1.StorDb.GetTPTimings(attrs.TPid, attrs.ID)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = *tms[0]
- return nil
-}
-
-type AttrGetTPTimingIds struct {
- TPid string // Tariff plan id
- utils.PaginatorWithSearch
-}
-
-// GetTPTimingIds queries timing identities on specific tariff plan.
-func (apierSv1 *APIerSv1) GetTPTimingIds(attrs *AttrGetTPTimingIds, reply *[]string) error {
- if missing := utils.MissingStructFields(attrs, []string{utils.TPid}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- ids, err := apierSv1.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPTimings,
- []string{utils.TagCfg}, nil, &attrs.PaginatorWithSearch)
- if err != nil {
- if err.Error() != utils.ErrNotFound.Error() {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- *reply = ids
- return nil
-}
-
-// RemoveTPTiming removes specific Timing on Tariff plan
-func (apierSv1 *APIerSv1) RemoveTPTiming(attrs AttrGetTPTiming, reply *string) error {
- if missing := utils.MissingStructFields(&attrs, []string{utils.TPid, utils.ID}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if err := apierSv1.StorDb.RemTpData(utils.TBLTPTimings, attrs.TPid, map[string]string{utils.TagCfg: attrs.ID}); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/tptimings_it_test.go b/apier/v1/tptimings_it_test.go
deleted file mode 100644
index 53599f3ae..000000000
--- a/apier/v1/tptimings_it_test.go
+++ /dev/null
@@ -1,200 +0,0 @@
-// +build offline
-
-/*
-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"
- "net/rpc/jsonrpc"
- "path"
- "reflect"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpTimingCfgPath string
- tpTimingCfg *config.CGRConfig
- tpTimingRPC *rpc.Client
- tpTiming *utils.ApierTPTiming
- tpTimingDelay int
- tpTimingConfigDIR string //run tests for specific configuration
-)
-
-var sTestsTPTiming = []func(t *testing.T){
- testTPTimingsInitCfg,
- testTPTimingsResetStorDb,
- testTPTimingsStartEngine,
- testTPTimingsRpcConn,
- testTPTimingsGetTPTimingBeforeSet,
- testTPTimingsSetTPTiming,
- testTPTimingsGetTPTimingAfterSet,
- testTPTimingsGetTPTimingIds,
- testTPTimingsUpdateTPTiming,
- testTPTimingsGetTPTimingAfterUpdate,
- testTPTimingsRemoveTPTiming,
- testTPTimingsGetTPTimingAfterRemove,
- testTPTimingsKillEngine,
-}
-
-//Test start here
-func TestTPTimingIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- tpTimingConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- tpTimingConfigDIR = "tutmysql"
- case utils.MetaMongo:
- tpTimingConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsTPTiming {
- t.Run(tpTimingConfigDIR, stest)
- }
-}
-
-func testTPTimingsInitCfg(t *testing.T) {
- var err error
- tpTimingCfgPath = path.Join(*dataDir, "conf", "samples", tpTimingConfigDIR)
- tpTimingCfg, err = config.NewCGRConfigFromPath(tpTimingCfgPath)
- if err != nil {
- t.Error(err)
- }
- switch tpTimingConfigDIR {
- case "tutmongo": // Mongo needs more time to reset db
- tpTimingDelay = 2000
- default:
- tpTimingDelay = 1000
- }
-}
-
-// Wipe out the cdr database
-func testTPTimingsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpTimingCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPTimingsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpTimingCfgPath, tpTimingDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPTimingsRpcConn(t *testing.T) {
- var err error
- tpTimingRPC, err = jsonrpc.Dial(utils.TCP, tpTimingCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPTimingsGetTPTimingBeforeSet(t *testing.T) {
- var reply *utils.ApierTPTiming
- if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPTimingsSetTPTiming(t *testing.T) {
- tpTiming = &utils.ApierTPTiming{
- TPid: "TPT1",
- ID: "Timing",
- Years: "2017",
- Months: "05",
- MonthDays: "01",
- WeekDays: "1",
- Time: "15:00:00Z",
- }
- var result string
- if err := tpTimingRPC.Call(utils.APIerSv1SetTPTiming, &tpTiming, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPTimingsGetTPTimingAfterSet(t *testing.T) {
- var respond *utils.ApierTPTiming
- if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &respond); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tpTiming, respond) {
- t.Errorf("Expecting: %+v, received: %+v", tpTiming, respond)
- }
-}
-
-func testTPTimingsGetTPTimingIds(t *testing.T) {
- var result []string
- expectedTPID := []string{"Timing"}
- if err := tpTimingRPC.Call(utils.APIerSv1GetTPTimingIds, &AttrGetTPTimingIds{TPid: tpTiming.TPid}, &result); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(result, expectedTPID) {
- t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID)
- }
-}
-
-func testTPTimingsUpdateTPTiming(t *testing.T) {
- var result string
- tpTiming.Years = "2015"
- if err := tpTimingRPC.Call(utils.APIerSv1SetTPTiming, &tpTiming, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-}
-
-func testTPTimingsGetTPTimingAfterUpdate(t *testing.T) {
- var expectedTPS *utils.ApierTPTiming
- if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &expectedTPS); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tpTiming, expectedTPS) {
- t.Errorf("Expecting: %+v, received: %+v", tpTiming, expectedTPS)
- }
-}
-
-func testTPTimingsRemoveTPTiming(t *testing.T) {
- var resp string
- if err := tpTimingRPC.Call(utils.APIerSv1RemoveTPTiming, &AttrGetTPTiming{TPid: tpTiming.TPid, ID: tpTiming.ID}, &resp); err != nil {
- t.Error(err)
- } else if resp != utils.OK {
- t.Error("Unexpected reply returned", resp)
- }
-}
-
-func testTPTimingsGetTPTimingAfterRemove(t *testing.T) {
- var reply *utils.ApierTPTiming
- if err := tpTimingRPC.Call(utils.APIerSv1GetTPTiming, &AttrGetTPTiming{TPid: "TPT1", ID: "Timining"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-}
-
-func testTPTimingsKillEngine(t *testing.T) {
- if err := engine.KillEngine(tpTimingDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v1/versions.go b/apier/v1/versions.go
deleted file mode 100644
index 7ec3cafe9..000000000
--- a/apier/v1/versions.go
+++ /dev/null
@@ -1,77 +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 (
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// Queries all versions from dataDB
-func (apierSv1 *APIerSv1) GetDataDBVersions(ign *string, reply *engine.Versions) error {
- if vrs, err := apierSv1.DataManager.DataDB().GetVersions(""); err != nil {
- return utils.NewErrServerError(err)
- } else if len(vrs) == 0 {
- return utils.ErrNotFound
- } else {
- *reply = vrs
- }
- return nil
-}
-
-// Queries all versions from stordb
-func (apierSv1 *APIerSv1) GetStorDBVersions(ign *string, reply *engine.Versions) error {
- if vrs, err := apierSv1.StorDb.GetVersions(""); err != nil {
- return utils.NewErrServerError(err)
- } else if len(vrs) == 0 {
- return utils.ErrNotFound
- } else {
- *reply = vrs
- }
- return nil
-}
-
-type SetVersionsArg struct {
- Versions engine.Versions
- Overwrite bool
-}
-
-// Queries all versions from dataDB
-func (apierSv1 *APIerSv1) SetDataDBVersions(arg *SetVersionsArg, reply *string) error {
- if arg.Versions == nil {
- arg.Versions = engine.CurrentDataDBVersions()
- }
- if err := apierSv1.DataManager.DataDB().SetVersions(arg.Versions, arg.Overwrite); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
-
-// Queries all versions from stordb
-func (apierSv1 *APIerSv1) SetStorDBVersions(arg *SetVersionsArg, reply *string) error {
- if arg.Versions == nil {
- arg.Versions = engine.CurrentDataDBVersions()
- }
- if err := apierSv1.StorDb.SetVersions(arg.Versions, arg.Overwrite); err != nil {
- return utils.NewErrServerError(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v1/versions_it_test.go b/apier/v1/versions_it_test.go
deleted file mode 100644
index 8977e59f4..000000000
--- a/apier/v1/versions_it_test.go
+++ /dev/null
@@ -1,224 +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"
- "testing"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- vrsCfgPath string
- vrsCfg *config.CGRConfig
- vrsRPC *rpc.Client
- vrsDelay int
- vrsConfigDIR string //run tests for specific configuration
- vrsStorageType string
-
- sTestsVrs = []func(t *testing.T){
- testVrsInitCfg,
- testVrsResetStorDb,
- testVrsStartEngine,
- testVrsRpcConn,
- testVrsDataDB,
- testVrsStorDB,
- testVrsSetDataDBVrs,
- testVrsSetStorDBVrs,
- testVrsKillEngine,
- }
-)
-
-//Test start here
-func TestVrsIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- // vrsConfigDIR = "tutinternal"
- // vrsStorageType = utils.INTERNAL
- t.SkipNow() // as is commented below
- case utils.MetaMySQL:
- vrsConfigDIR = "tutmysql"
- vrsStorageType = utils.Redis
- case utils.MetaMongo:
- vrsConfigDIR = "tutmongo"
- vrsStorageType = utils.Mongo
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsVrs {
- t.Run(vrsConfigDIR, stest)
- }
-}
-
-// func TestVrsITInternal(t *testing.T) {
-// vrsConfigDIR = "tutinternal"
-// vrsStorageType = utils.INTERNAL
-// for _, stest := range sTestsVrs {
-// t.Run(vrsConfigDIR, stest)
-// }
-// }
-
-func testVrsInitCfg(t *testing.T) {
- var err error
- vrsCfgPath = path.Join(*dataDir, "conf", "samples", vrsConfigDIR)
- vrsCfg, err = config.NewCGRConfigFromPath(vrsCfgPath)
- if err != nil {
- t.Error(err)
- }
- vrsCfg.DataFolderPath = *dataDir // Share DataFolderPath through config towards StoreDb for Flush()
- vrsDelay = 1000
-}
-
-// Wipe out the cdr database
-func testVrsResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(vrsCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testVrsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(vrsCfgPath, vrsDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testVrsRpcConn(t *testing.T) {
- var err error
- vrsRPC, err = newRPCClient(vrsCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testVrsDataDB(t *testing.T) {
- var result engine.Versions
- expectedVrs := engine.Versions{"ActionTriggers": 2,
- "Actions": 2, "RQF": 5, "ReverseDestinations": 1, "Attributes": 6, "RatingPlan": 1,
- "RatingProfile": 1, "Accounts": 3, "ActionPlans": 3, "Chargers": 2,
- "Destinations": 1, "LoadIDs": 1, "SharedGroups": 2, "Stats": 4, "Resource": 1,
- "Subscribers": 1, "Routes": 2, "Thresholds": 4, "Timing": 1, "Dispatchers": 2,
- "RateProfiles": 1}
- if err := vrsRPC.Call(utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil {
- t.Error(err)
- } else if expectedVrs.Compare(result, vrsStorageType, true) != "" {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedVrs), utils.ToJSON(result))
- }
-}
-
-func testVrsStorDB(t *testing.T) {
- var result engine.Versions
- expectedVrs := engine.Versions{"TpDestinations": 1, "TpResource": 1, "TpThresholds": 1,
- "TpActions": 1, "TpDestinationRates": 1, "TpFilters": 1, "TpRates": 1, "CDRs": 2, "TpActionTriggers": 1, "TpRatingPlans": 1,
- "TpSharedGroups": 1, "TpRoutes": 1, "SessionSCosts": 3, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1,
- "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1,
- "TpRatingPlan": 1, "TpResources": 1}
- if err := vrsRPC.Call(utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil {
- t.Error(err)
- } else if expectedVrs.Compare(result, vrsStorageType, true) != "" {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(result), utils.ToJSON(expectedVrs))
- }
-}
-
-func testVrsSetDataDBVrs(t *testing.T) {
- var reply string
- args := SetVersionsArg{
- Versions: engine.Versions{
- "Attributes": 3,
- },
- }
- if err := vrsRPC.Call(utils.APIerSv1SetDataDBVersions, &args, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- var result engine.Versions
- expectedVrs := engine.Versions{"ActionTriggers": 2,
- "Actions": 2, "RQF": 5, "ReverseDestinations": 1, "Attributes": 3, "RatingPlan": 1,
- "RatingProfile": 1, "Accounts": 3, "ActionPlans": 3, "Chargers": 2,
- "Destinations": 1, "LoadIDs": 1, "SharedGroups": 2, "Stats": 4, "Resource": 1,
- "Subscribers": 1, "Routes": 2, "Thresholds": 4, "Timing": 1,
- "RateProfiles": 1, "Dispatchers": 2}
- if err := vrsRPC.Call(utils.APIerSv1GetDataDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil {
- t.Error(err)
- } else if expectedVrs.Compare(result, vrsStorageType, true) != "" {
- t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(expectedVrs), utils.ToJSON(result))
- }
-
- args = SetVersionsArg{
- Versions: nil,
- }
- if err := vrsRPC.Call(utils.APIerSv1SetDataDBVersions, &args, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-}
-
-func testVrsSetStorDBVrs(t *testing.T) {
- var reply string
- args := SetVersionsArg{
- Versions: engine.Versions{
- "TpResources": 2,
- },
- }
- if err := vrsRPC.Call(utils.APIerSv1SetStorDBVersions, &args, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-
- var result engine.Versions
- expectedVrs := engine.Versions{"TpDestinations": 1, "TpResource": 1, "TpThresholds": 1,
- "TpActions": 1, "TpDestinationRates": 1, "TpFilters": 1, "TpRates": 1, "CDRs": 2, "TpActionTriggers": 1, "TpRatingPlans": 1,
- "TpSharedGroups": 1, "TpRoutes": 1, "SessionSCosts": 3, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1,
- "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1,
- "TpRatingPlan": 1, "TpResources": 2}
- if err := vrsRPC.Call(utils.APIerSv1GetStorDBVersions, utils.StringPointer(utils.EmptyString), &result); err != nil {
- t.Error(err)
- } else if expectedVrs.Compare(result, vrsStorageType, true) != "" {
- t.Errorf("Expecting: %+v, received: %+v", result, expectedVrs)
- }
-
- args = SetVersionsArg{
- Versions: nil,
- }
- if err := vrsRPC.Call(utils.APIerSv1SetStorDBVersions, &args, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting: %+v, received: %+v", utils.OK, reply)
- }
-}
-
-func testVrsKillEngine(t *testing.T) {
- if err := engine.KillEngine(vrsDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v2/apier.go b/apier/v2/apier.go
deleted file mode 100644
index 1b97b15b6..000000000
--- a/apier/v2/apier.go
+++ /dev/null
@@ -1,135 +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 v2
-
-import (
- "fmt"
- "os"
- "strings"
-
- "github.com/cgrates/birpc/context"
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-type APIerSv2 struct {
- v1.APIerSv1
-}
-
-// Call implements birpc.ClientConnector interface for internal RPC
-func (apiv2 *APIerSv2) Call(ctx *context.Context, serviceMethod string,
- args, reply interface{}) error {
- return utils.APIerRPCCall(apiv2, serviceMethod, args, reply)
-}
-
-type AttrLoadAccountActions struct {
- TPid string
- AccountActionsId string
-}
-
-func (apiv2 *APIerSv2) LoadTariffPlanFromFolder(attrs *utils.AttrLoadTpFromFolder, reply *utils.LoadInstance) error {
- if len(attrs.FolderPath) == 0 {
- return fmt.Errorf("%s:%s", utils.ErrMandatoryIeMissing.Error(), "FolderPath")
- }
- if fi, err := os.Stat(attrs.FolderPath); err != nil {
- if strings.HasSuffix(err.Error(), "no such file or directory") {
- return utils.ErrInvalidPath
- }
- return utils.NewErrServerError(err)
- } else if !fi.IsDir() {
- return utils.ErrInvalidPath
- }
- loader, err := engine.NewTpReader(apiv2.DataManager.DataDB(),
- engine.NewFileCSVStorage(utils.CSVSep, attrs.FolderPath), "", apiv2.Config.GeneralCfg().DefaultTimezone,
- apiv2.Config.ApierCfg().CachesConns, apiv2.Config.ApierCfg().ActionSConns,
- apiv2.Config.DataDbCfg().Type == utils.Internal)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if err := loader.LoadAll(); err != nil {
- return utils.NewErrServerError(err)
- }
- if attrs.DryRun {
- *reply = utils.LoadInstance{RatingLoadID: utils.DryRunCfg, AccountingLoadID: utils.DryRunCfg}
- return nil // Mission complete, no errors
- }
-
- if err := loader.WriteToDatabase(false, false); err != nil {
- return utils.NewErrServerError(err)
- }
-
- utils.Logger.Info("APIerSv2.LoadTariffPlanFromFolder, reloading cache.")
- //verify If Caching is present in arguments
- caching := config.CgrConfig().GeneralCfg().DefaultCaching
- if attrs.Caching != nil {
- caching = *attrs.Caching
- }
- if err := loader.ReloadCache(caching, true, attrs.APIOpts); err != nil {
- return utils.NewErrServerError(err)
- }
- if len(apiv2.Config.ApierCfg().ActionSConns) != 0 {
- utils.Logger.Info("APIerSv2.LoadTariffPlanFromFolder, reloading scheduler.")
- if err := loader.ReloadScheduler(true); err != nil {
- return utils.NewErrServerError(err)
- }
- }
- // release the reader with it's structures
- loader.Init()
- loadHistList, err := apiv2.DataManager.DataDB().GetLoadHistory(1, true, utils.NonTransactional)
- if err != nil {
- return err
- }
- if len(loadHistList) > 0 {
- *reply = *loadHistList[0]
- }
- return nil
-}
-
-type AttrGetDestinations struct {
- DestinationIDs []string
-}
-
-// GetDestinations returns a list of destination based on the destinationIDs given
-func (apiv2 *APIerSv2) GetDestinations(attr *AttrGetDestinations, reply *[]*engine.Destination) (err error) {
- if len(attr.DestinationIDs) == 0 {
- // get all destination ids
- if attr.DestinationIDs, err = apiv2.DataManager.DataDB().GetKeysForPrefix(context.TODO(), utils.DestinationPrefix); err != nil {
- return
- }
- for i, destID := range attr.DestinationIDs {
- attr.DestinationIDs[i] = destID[len(utils.DestinationPrefix):]
- }
- }
- dests := make([]*engine.Destination, len(attr.DestinationIDs))
- for i, destID := range attr.DestinationIDs {
- if dests[i], err = apiv2.DataManager.GetDestination(destID, true, true, utils.NonTransactional); err != nil {
- return
- }
- }
- *reply = dests
- return
-}
-
-// Ping return pong if the service is active
-func (apiv2 *APIerSv2) Ping(ign *utils.CGREvent, reply *string) error {
- *reply = utils.Pong
- return nil
-}
diff --git a/apier/v2/apierv2_it_test.go b/apier/v2/apierv2_it_test.go
deleted file mode 100644
index 3703131d3..000000000
--- a/apier/v2/apierv2_it_test.go
+++ /dev/null
@@ -1,501 +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 v2
-
-import (
- "fmt"
- "net/rpc"
- "path"
- "reflect"
- "testing"
- "time"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- apierCfgPath string
- apierCfg *config.CGRConfig
- apierRPC *rpc.Client
- dm *engine.DataManager // share db connection here so we can check data we set through APIs
- APIerSv2ConfDIR string
-
- sTestsv2it = []func(t *testing.T){
- testAPIerSv2itLoadConfig,
- testAPIerSv2itResetDataDb,
- testAPIerSv2itResetStorDb,
- testAPIerSv2itConnectDataDB,
- testAPIerSv2itStartEngine,
- testAPIerSv2itRpcConn,
- testAPIerSv2itAddBalance,
- testAPIerSv2itSetAction,
- testAPIerSv2itSetAccountActionTriggers,
- testAPIerSv2itFraudMitigation,
- testAPIerSv2itSetAccountWithAP,
- testAPIerSv2itSetActionWithCategory,
- testAPIerSv2itSetActionPlanWithWrongTiming,
- testAPIerSv2itSetActionPlanWithWrongTiming2,
- testAPIerSv2itBackwardsCompatible,
- testAPIerSv2itGetActionsCount,
- testAPIerSv2itKillEngine,
- }
-)
-
-func TestV2IT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- t.Skip()
- case utils.MetaMySQL:
- APIerSv2ConfDIR = "tutmysql"
- case utils.MetaMongo:
- APIerSv2ConfDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsv2it {
- t.Run(APIerSv2ConfDIR, stest)
- }
-}
-
-func testAPIerSv2itLoadConfig(t *testing.T) {
- apierCfgPath = path.Join(*dataDir, "conf", "samples", APIerSv2ConfDIR)
- if apierCfg, err = config.NewCGRConfigFromPath(apierCfgPath); err != nil {
- t.Error(err)
- }
-}
-
-// Remove data in both rating and accounting db
-func testAPIerSv2itResetDataDb(t *testing.T) {
- if err := engine.InitDataDB(apierCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testAPIerSv2itResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(apierCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testAPIerSv2itConnectDataDB(t *testing.T) {
- rdsITdb, err := engine.NewDataDBConn(apierCfg.DataDbCfg().Type,
- apierCfg.DataDbCfg().Host, apierCfg.DataDbCfg().Port,
- apierCfg.DataDbCfg().Name, apierCfg.DataDbCfg().User,
- apierCfg.DataDbCfg().Password, apierCfg.GeneralCfg().DBDataEncoding,
- apierCfg.DataDbCfg().Opts)
- if err != nil {
- t.Fatal("Could not connect to Redis", err.Error())
- }
- dm = engine.NewDataManager(rdsITdb, config.CgrConfig().CacheCfg(), nil)
-}
-
-// Start CGR Engine
-func testAPIerSv2itStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(apierCfgPath, 200); err != nil { // Mongo requires more time to start
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testAPIerSv2itRpcConn(t *testing.T) {
- apierRPC, err = newRPCClient(apierCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testAPIerSv2itAddBalance(t *testing.T) {
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "dan",
- BalanceType: utils.MetaMonetary,
- Value: 5.0,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- utils.Weight: 10.0,
- },
- }
- var reply string
- if err := apierRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
- var acnt engine.Account
- if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaMonetary][0].Value != 5.0 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0])
- }
-}
-
-func testAPIerSv2itSetAction(t *testing.T) {
- attrs := utils.AttrSetActions{ActionsId: "DISABLE_ACCOUNT", Actions: []*utils.TPAction{
- {Identifier: utils.MetaDisableAccount, Weight: 10.0},
- }}
- var reply string
- if err := apierRPC.Call(utils.APIerSv2SetActions, &attrs, &reply); err != nil {
- t.Error(err)
- }
- var acts map[string]engine.Actions
- if err := apierRPC.Call(utils.APIerSv2GetActions, &AttrGetActions{ActionIDs: []string{attrs.ActionsId}}, &acts); err != nil {
- t.Error(err)
- } else if len(acts) != 1 {
- t.Errorf("Received actions: %+v", acts)
- }
-}
-
-func testAPIerSv2itSetAccountActionTriggers(t *testing.T) {
- attrs := v1.AttrSetAccountActionTriggers{
- Tenant: "cgrates.org",
- Account: "dan",
- AttrSetActionTrigger: v1.AttrSetActionTrigger{
- GroupID: "MONITOR_MAX_BALANCE",
- ActionTrigger: map[string]interface{}{
- utils.ThresholdType: utils.TriggerMaxBalance,
- utils.ThresholdValue: 50,
- utils.BalanceType: utils.MetaMonetary,
- utils.ActionsID: "DISABLE_ACCOUNT",
- },
- },
- }
- var reply string
- if err := apierRPC.Call(utils.APIerSv2SetAccountActionTriggers, attrs, &reply); err != nil {
- t.Error(err)
- }
- var ats engine.ActionTriggers
- if err := apierRPC.Call(utils.APIerSv2GetAccountActionTriggers, utils.TenantAccount{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil {
- t.Error(err)
- } else if len(ats) != 1 || ats[0].ID != attrs.GroupID || ats[0].ThresholdValue != 50.0 {
- t.Errorf("Received: %+v", ats)
- }
- attrs.ActionTrigger[utils.ThresholdValue] = 55 // Change the threshold
- if err := apierRPC.Call(utils.APIerSv2SetAccountActionTriggers, attrs, &reply); err != nil {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2GetAccountActionTriggers, utils.TenantAccount{Tenant: "cgrates.org", Account: "dan"}, &ats); err != nil {
- t.Error(err)
- } else if len(ats) != 1 || ats[0].ID != attrs.GroupID || ats[0].ThresholdValue != 55.0 {
- t.Errorf("Received: %+v", ats)
- }
-}
-
-func testAPIerSv2itFraudMitigation(t *testing.T) {
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "dan",
- BalanceType: utils.MetaMonetary,
- Value: 60.0,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- utils.Weight: 10.0,
- },
- }
- var reply string
- if err := apierRPC.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
- var acnt engine.Account
- if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 60.0 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0])
- } else if !acnt.Disabled {
- t.Fatalf("Received account: %+v", acnt)
- }
- attrSetAcnt := &AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "dan",
- ExtraOptions: map[string]bool{
- utils.Disabled: false,
- },
- }
- if err := apierRPC.Call(utils.APIerSv2SetAccount, attrSetAcnt, &reply); err != nil {
- t.Fatal(err)
- }
- acnt = engine.Account{} // gob doesn't update the fields with default values
- if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "dan"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 60.0 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0])
- } else if acnt.Disabled {
- t.Fatalf("Received account: %+v", acnt)
- }
-}
-
-func testAPIerSv2itSetAccountWithAP(t *testing.T) {
- argActs1 := utils.AttrSetActions{ActionsId: "TestAPIerSv2itSetAccountWithAP_ACT_1",
- Actions: []*utils.TPAction{
- {Identifier: utils.MetaTopUpReset,
- BalanceType: utils.MetaMonetary, Units: "5.0", Weight: 20.0},
- }}
- var reply string
- if err := apierRPC.Call(utils.APIerSv2SetActions, &argActs1, &reply); err != nil {
- t.Error(err)
- }
- tNow := time.Now().Add(time.Minute)
- argAP1 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_1",
- ActionPlan: []*v1.AttrActionPlan{
- {ActionsId: argActs1.ActionsId,
- Time: fmt.Sprintf("%v:%v:%v", tNow.Hour(), tNow.Minute(), tNow.Second()), // 10:4:12
- Weight: 20.0}}}
- if _, err := dm.GetActionPlan(argAP1.Id, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &argAP1, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply)
- }
- argSetAcnt1 := AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "TestAPIerSv2itSetAccountWithAP1",
- ActionPlanIDs: []string{argAP1.Id},
- }
- acntID := utils.ConcatenatedKey(argSetAcnt1.Tenant, argSetAcnt1.Account)
- if _, err := dm.GetAccountActionPlans(acntID, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAcnt1, &reply); err != nil {
- t.Fatal(err)
- }
- if ap, err := dm.GetActionPlan(argAP1.Id, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
- t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
- }
- eAAPids := []string{argAP1.Id}
- if aapIDs, err := dm.GetAccountActionPlans(acntID, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eAAPids, aapIDs) {
- t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs)
- }
- // Set second AP so we can see the proper indexing done
- argAP2 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAP_AP_2",
- ActionPlan: []*v1.AttrActionPlan{
- {ActionsId: argActs1.ActionsId, MonthDays: "1", Time: "00:00:00", Weight: 20.0}}}
- if _, err := dm.GetActionPlan(argAP2.Id, true, utils.NonTransactional); err == nil || err != utils.ErrNotFound {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2SetActionPlan, argAP2, &reply); err != nil {
- t.Error("Got error on APIerSv2.SetActionPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActionPlan received: %s", reply)
- }
- // Test adding new AP
- argSetAcnt2 := AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "TestAPIerSv2itSetAccountWithAP1",
- ActionPlanIDs: []string{argAP2.Id},
- }
- if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAcnt2, &reply); err != nil {
- t.Fatal(err)
- }
- if ap, err := dm.GetActionPlan(argAP2.Id, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
- t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
- }
- if ap, err := dm.GetActionPlan(argAP1.Id, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
- t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
- }
- eAAPids = []string{argAP1.Id, argAP2.Id}
- if aapIDs, err := dm.GetAccountActionPlans(acntID, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eAAPids, aapIDs) {
- t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs)
- }
- // test remove and overwrite
- argSetAcnt2 = AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "TestAPIerSv2itSetAccountWithAP1",
- ActionPlanIDs: []string{argAP2.Id},
- ActionPlansOverwrite: true,
- }
- if err := apierRPC.Call(utils.APIerSv2SetAccount, &argSetAcnt2, &reply); err != nil {
- t.Fatal(err)
- }
- if ap, err := dm.GetActionPlan(argAP1.Id, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if _, hasIt := ap.AccountIDs[acntID]; hasIt {
- t.Errorf("ActionPlan does contain the accountID: %+v", ap)
- }
- if ap, err := dm.GetActionPlan(argAP2.Id, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if _, hasIt := ap.AccountIDs[acntID]; !hasIt {
- t.Errorf("ActionPlan does not contain the accountID: %+v", ap)
- }
- eAAPids = []string{argAP2.Id}
- if aapIDs, err := dm.GetAccountActionPlans(acntID, true, utils.NonTransactional); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(eAAPids, aapIDs) {
- t.Errorf("Expecting: %+v, received: %+v", eAAPids, aapIDs)
- }
-}
-
-func testAPIerSv2itSetActionWithCategory(t *testing.T) {
- var reply string
- attrsSetAccount := &utils.AttrSetAccount{Tenant: "cgrates.org", Account: "TestAPIerSv2itSetActionWithCategory"}
- if err := apierRPC.Call(utils.APIerSv1SetAccount, attrsSetAccount, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetAccount: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.SetAccount received: %s", reply)
- }
-
- argActs1 := utils.AttrSetActions{ActionsId: "TestAPIerSv2itSetActionWithCategory_ACT",
- Actions: []*utils.TPAction{
- {Identifier: utils.MetaTopUpReset,
- BalanceType: utils.MetaMonetary, Categories: "test", Units: "5.0", Weight: 20.0},
- }}
-
- if err := apierRPC.Call(utils.APIerSv2SetActions, &argActs1, &reply); err != nil {
- t.Error(err)
- }
-
- attrsEA := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: argActs1.ActionsId}
- if err := apierRPC.Call(utils.APIerSv1ExecuteAction, attrsEA, &reply); err != nil {
- t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply)
- }
-
- var acnt engine.Account
- if err := apierRPC.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org",
- Account: "TestAPIerSv2itSetActionWithCategory"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 5.0 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0])
- } else if len(acnt.BalanceMap[utils.MetaMonetary][0].Categories) != 1 &&
- acnt.BalanceMap[utils.MetaMonetary][0].Categories["test"] != true {
- t.Fatalf("Unexpected category received: %+v", utils.ToJSON(acnt))
- }
-}
-
-func testAPIerSv2itSetActionPlanWithWrongTiming(t *testing.T) {
- var reply string
- tNow := time.Now().Add(time.Minute).String()
- argAP1 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAPWithWrongTiming",
- ActionPlan: []*v1.AttrActionPlan{
- &v1.AttrActionPlan{
- ActionsId: "TestAPIerSv2itSetAccountWithAP_ACT_1",
- Time: tNow,
- Weight: 20.0,
- },
- },
- }
-
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &argAP1, &reply); err == nil ||
- err.Error() != fmt.Sprintf("UNSUPPORTED_FORMAT:%s", tNow) {
- t.Error("Expecting error ", err)
- }
-}
-
-func testAPIerSv2itSetActionPlanWithWrongTiming2(t *testing.T) {
- var reply string
- argAP1 := &v1.AttrSetActionPlan{Id: "TestAPIerSv2itSetAccountWithAPWithWrongTiming",
- ActionPlan: []*v1.AttrActionPlan{
- &v1.AttrActionPlan{
- ActionsId: "TestAPIerSv2itSetAccountWithAP_ACT_1",
- Time: "aa:bb:cc",
- Weight: 20.0,
- },
- },
- }
-
- if err := apierRPC.Call(utils.APIerSv1SetActionPlan, &argAP1, &reply); err == nil ||
- err.Error() != fmt.Sprintf("UNSUPPORTED_FORMAT:aa:bb:cc") {
- t.Error("Expecting error ", err)
- }
-}
-
-func testAPIerSv2itBackwardsCompatible(t *testing.T) {
- var reply string
- if err := apierRPC.Call("ApierV2.Ping", new(utils.CGREvent), &reply); err != nil {
- t.Error(err)
- } else if reply != utils.Pong {
- t.Errorf("Expecting : %+v, received: %+v", utils.Pong, reply)
- }
-}
-
-func testAPIerSv2itGetActionsCount(t *testing.T) {
- var reply1 int
- if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
- t.Error(err)
- } else if reply1 != 3 {
- t.Errorf("Expecting: 3, received : %+v", reply1)
- }
- attrs := utils.AttrSetActions{ActionsId: "DISABLE_ACCOUNT2", Actions: []*utils.TPAction{
- {Identifier: utils.MetaDisableAccount, Weight: 0.7},
- }}
- var reply string
- if err := apierRPC.Call(utils.APIerSv2SetActions, &attrs, &reply); err != nil {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
- t.Error(err)
- } else if reply1 != 4 {
- t.Errorf("Expecting: 4, received : %+v", reply1)
- }
-
- attrRemoveActions := &v1.AttrRemoveActions{
- ActionIDs: []string{"DISABLE_ACCOUNT", "DISABLE_ACCOUNT2", "TestAPIerSv2itSetAccountWithAP_ACT_1"},
- }
- if err := apierRPC.Call(utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
- t.Error(err)
- } else if reply1 != 1 {
- t.Errorf("Expecting: 1, received : %+v", reply1)
- }
- attrRemoveActions = &v1.AttrRemoveActions{
- ActionIDs: []string{"TestAPIerSv2itSetActionWithCategory_ACT"},
- }
- if err := apierRPC.Call(utils.APIerSv2RemoveActions, &attrRemoveActions, &reply); err != nil {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err == nil || err.Error() != utils.ErrNotFound.Error() {
- t.Errorf("Expecting %+v, received: %+v", utils.ErrNotFound, err)
- }
- attrs = utils.AttrSetActions{ActionsId: "Test", Actions: []*utils.TPAction{
- {Identifier: utils.MetaDisableAccount, Weight: 0.7},
- }}
- if err := apierRPC.Call(utils.APIerSv2SetActions, &attrs, &reply); err != nil {
- t.Error(err)
- }
- if err := apierRPC.Call(utils.APIerSv2GetActionsCount, &AttrGetActionsCount{}, &reply1); err != nil {
- t.Error(err)
- } else if reply1 != 1 {
- t.Errorf("Expecting: 1, received : %+v", reply1)
- }
-}
-
-func testAPIerSv2itKillEngine(t *testing.T) {
- if err := engine.KillEngine(delay); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v2/attributes.go b/apier/v2/attributes.go
deleted file mode 100644
index 74bf17b61..000000000
--- a/apier/v2/attributes.go
+++ /dev/null
@@ -1,60 +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 v2
-
-import (
- "time"
-
- "github.com/cgrates/birpc/context"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-type AttributeWithAPIOpts struct {
- *engine.APIAttributeProfile
- APIOpts map[string]interface{}
-}
-
-//SetAttributeProfile add/update a new Attribute Profile
-func (APIerSv2 *APIerSv2) SetAttributeProfile(arg *AttributeWithAPIOpts, reply *string) error {
- if missing := utils.MissingStructFields(arg.APIAttributeProfile, []string{utils.ID}); len(missing) != 0 {
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if arg.Tenant == utils.EmptyString {
- arg.Tenant = APIerSv2.Config.GeneralCfg().DefaultTenant
- }
- alsPrf, err := arg.APIAttributeProfile.AsAttributeProfile()
- if err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := APIerSv2.DataManager.SetAttributeProfile(context.TODO(), alsPrf, true); err != nil {
- return utils.APIErrorHandler(err)
- }
- //generate a loadID for CacheAttributeProfiles and store it in database
- if err := APIerSv2.DataManager.SetLoadIDs(context.TODO(),
- map[string]int64{utils.CacheAttributeProfiles: time.Now().UnixNano()}); err != nil {
- return utils.APIErrorHandler(err)
- }
- if err := APIerSv2.APIerSv1.CallCache(utils.IfaceAsString(arg.APIOpts[utils.CacheOpt]), alsPrf.Tenant, utils.CacheAttributeProfiles,
- alsPrf.TenantID(), &alsPrf.FilterIDs, alsPrf.Contexts, arg.APIOpts); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
diff --git a/apier/v2/attributes_it_test.go b/apier/v2/attributes_it_test.go
deleted file mode 100644
index ea82d309e..000000000
--- a/apier/v2/attributes_it_test.go
+++ /dev/null
@@ -1,301 +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 v2
-
-import (
- "net/rpc"
- "path"
- "reflect"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- alsPrfCfgPath string
- alsPrfCfg *config.CGRConfig
- attrSRPC *rpc.Client
- alsPrf *engine.AttributeProfile
- alsPrfConfigDIR string //run tests for specific configuration
-
- sTestsAlsPrf = []func(t *testing.T){
- testAttributeSInitCfg,
- testAttributeSInitDataDb,
- testAttributeSResetStorDb,
- testAttributeSStartEngine,
- testAttributeSRPCConn,
- testAttributeSSetAlsPrf,
- testAttributeSUpdateAlsPrf,
- testAttributeSSetAlsPrfWithoutTenant,
- testAttributeSKillEngine,
- }
-)
-
-//Test start here
-func TestAttributeSIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- alsPrfConfigDIR = "tutinternal"
- case utils.MetaMySQL:
- alsPrfConfigDIR = "tutmysql"
- case utils.MetaMongo:
- alsPrfConfigDIR = "tutmongo"
- case utils.MetaPostgres:
- t.SkipNow()
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsAlsPrf {
- t.Run(alsPrfConfigDIR, stest)
- }
-}
-
-func testAttributeSInitCfg(t *testing.T) {
- var err error
- alsPrfCfgPath = path.Join(*dataDir, "conf", "samples", alsPrfConfigDIR)
- alsPrfCfg, err = config.NewCGRConfigFromPath(alsPrfCfgPath)
- if err != nil {
- t.Error(err)
- }
-}
-
-func testAttributeSInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(alsPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testAttributeSResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(alsPrfCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testAttributeSStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(alsPrfCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testAttributeSRPCConn(t *testing.T) {
- var err error
- attrSRPC, err = newRPCClient(alsPrfCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testAttributeSSetAlsPrf(t *testing.T) {
- extAlsPrf := &AttributeWithAPIOpts{
- APIAttributeProfile: &engine.APIAttributeProfile{
- Tenant: "cgrates.org",
- ID: "ExternalAttribute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.ExternalAttribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Account",
- Value: "1001",
- },
- },
- Weight: 20,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ExternalAttribute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Account",
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ExternalAttribute"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
-}
-
-func testAttributeSUpdateAlsPrf(t *testing.T) {
- extAlsPrf := &AttributeWithAPIOpts{
- APIAttributeProfile: &engine.APIAttributeProfile{
- Tenant: "cgrates.org",
- ID: "ExternalAttribute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.ExternalAttribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Account",
- Value: "1001",
- },
- {
- Path: utils.MetaReq + utils.NestingSep + "Subject",
- Value: "~*req.Account",
- },
- },
- Weight: 20,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ExternalAttribute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Account",
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- {
- Path: utils.MetaReq + utils.NestingSep + "Subject",
- Value: config.NewRSRParsersMustCompile("~*req.Account", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- sort.Strings(alsPrf.AttributeProfile.Contexts)
- alsPrf.Compile()
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "ExternalAttribute"}}, &reply); err != nil {
- t.Fatal(err)
- }
- sort.Strings(reply.Contexts)
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", utils.ToJSON(alsPrf.AttributeProfile), utils.ToJSON(reply))
- }
-}
-
-func testAttributeSKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
-
-func testAttributeSSetAlsPrfWithoutTenant(t *testing.T) {
- extAlsPrf := &AttributeWithAPIOpts{
- APIAttributeProfile: &engine.APIAttributeProfile{
- ID: "ExternalAttribute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.ExternalAttribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Account",
- Value: "1001",
- },
- },
- Weight: 20,
- },
- }
- var result string
- if err := attrSRPC.Call(utils.APIerSv2SetAttributeProfile, extAlsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
-
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "ExternalAttribute",
- Contexts: []string{utils.MetaSessionS, utils.MetaCDRs},
- FilterIDs: []string{"*string:~*req.Account:1001"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaReq + utils.NestingSep + "Account",
- Value: config.NewRSRParsersMustCompile("1001", utils.InfieldSep),
- },
- },
- Weight: 20,
- },
- }
- alsPrf.Compile()
- var reply *engine.AttributeProfile
- if err := attrSRPC.Call(utils.APIerSv1GetAttributeProfile,
- utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{ID: "ExternalAttribute"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
-}
diff --git a/apier/v2/cdrs.go b/apier/v2/cdrs.go
deleted file mode 100644
index a5f53f25a..000000000
--- a/apier/v2/cdrs.go
+++ /dev/null
@@ -1,74 +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 v2
-
-import (
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// Retrieves CDRs based on the filters
-func (apier *APIerSv2) GetCDRs(attrs *utils.RPCCDRsFilter, reply *[]*engine.ExternalCDR) error {
- cdrsFltr, err := attrs.AsCDRsFilter(apier.Config.GeneralCfg().DefaultTimezone)
- if err != nil {
- return utils.NewErrServerError(err)
- }
- if cdrs, _, err := apier.CdrDb.GetCDRs(cdrsFltr, false); err != nil {
- if err.Error() != utils.NotFoundCaps {
- err = utils.NewErrServerError(err)
- }
- return err
- } else if len(cdrs) == 0 {
- *reply = make([]*engine.ExternalCDR, 0)
- } else {
- for _, cdr := range cdrs {
- *reply = append(*reply, cdr.AsExternalCDR())
- }
- }
- return nil
-}
-
-func (apier *APIerSv2) CountCDRs(attrs *utils.RPCCDRsFilter, reply *int64) error {
- cdrsFltr, err := attrs.AsCDRsFilter(apier.Config.GeneralCfg().DefaultTimezone)
- if err != nil {
- if err.Error() != utils.NotFoundCaps {
- err = utils.NewErrServerError(err)
- }
- return err
- }
- cdrsFltr.Count = true
- if _, count, err := apier.CdrDb.GetCDRs(cdrsFltr, false); err != nil {
- return utils.NewErrServerError(err)
- } else {
- *reply = count
- }
- return nil
-}
-
-// Receive CDRs via RPC methods, not included with APIer because it has way less dependencies and can be standalone
-type CDRsV2 struct {
- v1.CDRsV1
-}
-
-// ProcessEvent will process an Event based on the flags attached
-func (cdrSv2 *CDRsV2) ProcessEvent(arg *engine.ArgV1ProcessEvent, evs *[]*utils.EventWithFlags) error {
- return cdrSv2.CDRs.V2ProcessEvent(arg, evs)
-}
diff --git a/apier/v2/cdrs_it_test.go b/apier/v2/cdrs_it_test.go
deleted file mode 100644
index 3ac9dea2b..000000000
--- a/apier/v2/cdrs_it_test.go
+++ /dev/null
@@ -1,1179 +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 v2
-
-import (
- "net/rpc"
- "path"
- "reflect"
- "sync"
- "testing"
- "time"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- cdrsCfgPath string
- cdrsCfg *config.CGRConfig
- cdrsRpc *rpc.Client
- cdrsConfDIR string // run the tests for specific configuration
-
- // subtests to be executed for each confDIR
- sTestsCDRsIT = []func(t *testing.T){
- testV2CDRsInitConfig,
- testV2CDRsInitDataDb,
- testV2CDRsInitCdrDb,
- testV2CDRsStartEngine,
- testV2CDRsRpcConn,
- testV2CDRsLoadTariffPlanFromFolder,
- testV2CDRsProcessCDR,
- testV2CDRsGetCdrs,
- testV2CDRsRateCDRs,
- testV2CDRsGetCdrs2,
- testV2CDRsUsageNegative,
- testV2CDRsDifferentTenants,
-
- testV2CDRsRemoveRatingProfiles,
- testV2CDRsProcessCDRNoRattingPlan,
- testV2CDRsGetCdrsNoRattingPlan,
-
- testV2CDRsRateCDRsWithRatingPlan,
- testV2CDRsGetCdrsWithRatingPlan,
-
- testV2CDRsSetThreshold,
- testV2CDRsProcessCDRWithThreshold,
- testV2CDRsGetThreshold,
- testV2CDRsResetThresholdAction,
-
- testv2CDRsGetCDRsDest,
-
- testV2CDRsInitDataDb,
- testV2CDRsInitCdrDb,
- testV2CDRsRerate,
-
- testV2CDRsLoadTariffPlanFromFolder,
- testv2CDRsDynaPrepaid,
-
- //testV2CDRsDuplicateCDRs,
-
- testV2CDRsKillEngine,
- }
-)
-
-// Tests starting here
-func TestCDRsIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- cdrsConfDIR = "cdrsv2internal"
- case utils.MetaMySQL:
- cdrsConfDIR = "cdrsv2mysql"
- case utils.MetaMongo:
- cdrsConfDIR = "cdrsv2mongo"
- case utils.MetaPostgres:
- cdrsConfDIR = "cdrsv2psql"
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsCDRsIT {
- t.Run(cdrsConfDIR, stest)
- }
-}
-
-func testV2CDRsInitConfig(t *testing.T) {
- var err error
- cdrsCfgPath = path.Join(*dataDir, "conf", "samples", cdrsConfDIR)
- if cdrsCfg, err = config.NewCGRConfigFromPath(cdrsCfgPath); err != nil {
- t.Fatal("Got config error: ", err.Error())
- }
-}
-
-func testV2CDRsInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(cdrsCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// InitDb so we can rely on count
-func testV2CDRsInitCdrDb(t *testing.T) {
- if err := engine.InitStorDB(cdrsCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV2CDRsStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(cdrsCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testV2CDRsRpcConn(t *testing.T) {
- cdrsRpc, err = newRPCClient(cdrsCfg.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 testV2CDRsLoadTariffPlanFromFolder(t *testing.T) {
- var loadInst utils.LoadInstance
- if err := cdrsRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder,
- &utils.AttrLoadTpFromFolder{FolderPath: path.Join(
- *dataDir, "tariffplans", "testit")}, &loadInst); err != nil {
- t.Error(err)
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
-}
-
-func testV2CDRsProcessCDR(t *testing.T) {
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsProcessCDR1",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsProcessCDR",
- utils.RequestType: utils.MetaRated,
- // utils.Category: "call", //it will be populated as default in MapEvent.AsCDR
- utils.AccountField: "testV2CDRsProcessCDR",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
-
- var reply string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsGetCdrs(t *testing.T) {
- var cdrCnt int64
- req := utils.AttrGetCdrs{}
- if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 3 {
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
- var cdrs []*engine.ExternalCDR
- args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraFields["PayPalAccount"] != "paypal@cgrates.org" {
- t.Errorf("PayPalAccount should be added by AttributeS, have: %s",
- cdrs[0].ExtraFields["PayPalAccount"])
- }
- }
- args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.0198 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraFields["PayPalAccount"] != "paypal@cgrates.org" {
- t.Errorf("PayPalAccount should be added by AttributeS, have: %s",
- cdrs[0].ExtraFields["PayPalAccount"])
- }
- }
- args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.0102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraFields["PayPalAccount"] != "paypal@cgrates.org" {
- t.Errorf("PayPalAccount should be added by AttributeS, have: %s",
- cdrs[0].ExtraFields["PayPalAccount"])
- }
- }
-}
-
-// Should re-rate the supplier1 cost with RP_ANY2CNT
-func testV2CDRsRateCDRs(t *testing.T) {
- var rpl engine.RatingProfile
- attrGetRatingPlan := &utils.AttrGetRatingProfile{
- Tenant: "cgrates.org", Category: "call", Subject: "SUPPLIER1"}
- actTime, err := utils.ParseTimeDetectLayout("2018-01-01T00:00:00Z", "")
- if err != nil {
- t.Error(err)
- }
- expected := engine.RatingProfile{
- Id: "*out:cgrates.org:call:SUPPLIER1",
- RatingPlanActivations: engine.RatingPlanActivations{
- {
- ActivationTime: actTime,
- RatingPlanId: "RP_ANY1CNT",
- },
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil {
- t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err)
- } else if !reflect.DeepEqual(expected, rpl) {
- t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))
- }
-
- rpf := &utils.AttrSetRatingProfile{
- Tenant: "cgrates.org",
- Category: "call",
- Subject: "SUPPLIER1",
- RatingPlanActivations: []*utils.TPRatingActivation{
- {
- ActivationTime: "2018-01-01T00:00:00Z",
- RatingPlanId: "RP_ANY2CNT"}},
- Overwrite: true,
- }
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply)
- }
-
- expected = engine.RatingProfile{
- Id: "*out:cgrates.org:call:SUPPLIER1",
- RatingPlanActivations: engine.RatingPlanActivations{
- {
- ActivationTime: actTime,
- RatingPlanId: "RP_ANY2CNT",
- },
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1GetRatingProfile, attrGetRatingPlan, &rpl); err != nil {
- t.Errorf("Got error on APIerSv1.GetRatingProfile: %+v", err)
- } else if !reflect.DeepEqual(expected, rpl) {
- t.Errorf("Calling APIerSv1.GetRatingProfile expected: %+v, received: %+v", utils.ToJSON(expected), utils.ToJSON(rpl))
- }
-
- if err := cdrsRpc.Call(utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{
- RPCCDRsFilter: utils.RPCCDRsFilter{NotRunIDs: []string{"raw"}},
- Flags: []string{"*chargers:false"},
- }, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsGetCdrs2(t *testing.T) {
- var cdrCnt int64
- req := utils.AttrGetCdrs{}
- if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 3 {
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
- var cdrs []*engine.ExternalCDR
- args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.0198 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.0102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
-}
-
-func testV2CDRsUsageNegative(t *testing.T) {
- argsCdr := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsUsageNegative",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsUsageNegative",
- utils.RequestType: utils.MetaRated,
- utils.Category: "call",
- utils.AccountField: "testV2CDRsUsageNegative",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: -time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
- var reply string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsCdr, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-
- var cdrs []*engine.ExternalCDR
- args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, OriginIDs: []string{"testV2CDRsUsageNegative"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].Usage != "-1m0s" {
- t.Errorf("Unexpected usage for CDR: %s", cdrs[0].Usage)
- }
- }
- cdrs = nil // gob doesn't modify zero-value fields
- args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, OriginIDs: []string{"testV2CDRsUsageNegative"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].Usage != "0s" {
- t.Errorf("Unexpected usage for CDR: %s", cdrs[0].Usage)
- }
- }
- cdrs = nil // gob doesn't modify zero-value fields
- args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, OriginIDs: []string{"testV2CDRsUsageNegative"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].Usage != "0s" {
- t.Errorf("Unexpected usage for CDR: %s", cdrs[0].Usage)
- }
- }
-}
-
-func testV2CDRsDifferentTenants(t *testing.T) {
- //add an attribute
- alsPrf := &engine.AttributeProfileWithAPIOpts{
- AttributeProfile: &engine.AttributeProfile{
- Tenant: "cgrates.com",
- ID: "ATTR_Tenant",
- Contexts: []string{utils.MetaAny},
- FilterIDs: []string{"*string:~*req.Tenant:cgrates.com"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- Path: utils.MetaTenant,
- Type: utils.MetaConstant,
- Value: config.RSRParsers{
- &config.RSRParser{
- Rules: "CustomTenant",
- },
- },
- },
- {
- Path: utils.MetaReq + utils.NestingSep + utils.Tenant,
- Type: utils.MetaConstant,
- Value: config.RSRParsers{
- &config.RSRParser{
- Rules: "CustomTenant",
- },
- },
- },
- },
- Blocker: false,
- Weight: 10,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaReload,
- },
- }
- alsPrf.Compile()
- var result string
- if err := cdrsRpc.Call(utils.APIerSv1SetAttributeProfile, alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply *engine.AttributeProfile
- if err := cdrsRpc.Call(utils.APIerSv1GetAttributeProfile,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.com", ID: "ATTR_Tenant"}}, &reply); err != nil {
- t.Fatal(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf.AttributeProfile, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf.AttributeProfile, reply)
- }
- //add a charger
- chargerProfile := &v1.ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "CustomTenant",
- ID: "CustomCharger",
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: "CustomRunID",
- AttributeIDs: []string{"*none"},
- Weight: 20,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaReload,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- var reply2 *engine.ChargerProfile
- if err := cdrsRpc.Call(utils.APIerSv1GetChargerProfile,
- &utils.TenantID{Tenant: "CustomTenant", ID: "CustomCharger"}, &reply2); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(chargerProfile.ChargerProfile, reply2) {
- t.Errorf("Expecting : %+v, received: %+v", chargerProfile.ChargerProfile, reply2)
- }
-
- argsCdr := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaAttributes, utils.MetaChargers, "*stats:false", "*thresholds:false", utils.MetaStore},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.com",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsDifferentTenants",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsDifferentTenants",
- utils.RequestType: utils.MetaRated,
- utils.Category: "call",
- utils.AccountField: "testV2CDRsDifferentTenants",
- utils.Destination: "+4986517174963",
- utils.Tenant: "cgrates.com",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Second,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
- var reply3 string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, argsCdr, &reply3); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply3 != utils.OK {
- t.Error("Unexpected reply received: ", reply3)
- }
-
- var cdrs []*engine.ExternalCDR
- args := utils.RPCCDRsFilter{Tenants: []string{"CustomTenant"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 { // no raw Charger defined
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- }
-}
-
-func testV2CDRsRemoveRatingProfiles(t *testing.T) {
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv1RemoveRatingProfile, &v1.AttrRemoveRatingProfile{
- Tenant: "cgrates.org",
- Category: utils.Call,
- Subject: utils.MetaAny,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected: %s, received: %s ", utils.OK, reply)
- }
- if err := cdrsRpc.Call(utils.APIerSv1RemoveRatingProfile, &v1.AttrRemoveRatingProfile{
- Tenant: "cgrates.org",
- Category: utils.Call,
- Subject: "SUPPLIER1",
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expected: %s, received: %s ", utils.OK, reply)
- }
-}
-
-func testV2CDRsProcessCDRNoRattingPlan(t *testing.T) {
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsProcessCDR4",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsProcessCDR4",
- utils.RequestType: utils.MetaRated,
- utils.AccountField: "testV2CDRsProcessCDR4",
- utils.Subject: "NoSubject",
- utils.Destination: "+1234567",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
-
- var reply string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsGetCdrsNoRattingPlan(t *testing.T) {
- var cdrCnt int64
- req := utils.AttrGetCdrs{}
- if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 10 {
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
- var cdrs []*engine.ExternalCDR
- args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, Accounts: []string{"testV2CDRsProcessCDR4"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraInfo != utils.ErrRatingPlanNotFound.Error() {
- t.Errorf("Expected ExtraInfo : %s received :%s", utils.ErrRatingPlanNotFound.Error(), cdrs[0].ExtraInfo)
- }
- }
- args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraInfo != utils.ErrRatingPlanNotFound.Error() {
- t.Errorf("Expected ExtraInfo : %s received :%s", utils.ErrRatingPlanNotFound.Error(), cdrs[0].ExtraInfo)
- }
- }
-}
-
-// Should re-rate the supplier1 cost with RP_ANY2CNT
-func testV2CDRsRateCDRsWithRatingPlan(t *testing.T) {
- rpf := &utils.AttrSetRatingProfile{
- Tenant: "cgrates.org",
- Category: "call",
- Subject: "SUPPLIER1",
- RatingPlanActivations: []*utils.TPRatingActivation{
- {
- ActivationTime: "2018-01-01T00:00:00Z",
- RatingPlanId: "RP_ANY1CNT"}},
- Overwrite: true,
- }
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply)
- }
-
- rpf = &utils.AttrSetRatingProfile{
- Tenant: "cgrates.org",
- Category: "call",
- Subject: utils.MetaAny,
- RatingPlanActivations: []*utils.TPRatingActivation{
- {
- ActivationTime: "2018-01-01T00:00:00Z",
- RatingPlanId: "RP_TESTIT1"}},
- Overwrite: true,
- }
- if err := cdrsRpc.Call(utils.APIerSv1SetRatingProfile, &rpf, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetRatingProfile: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv1.SetRatingProfile got reply: ", reply)
- }
-
- if err := cdrsRpc.Call(utils.CDRsV1RateCDRs, &engine.ArgRateCDRs{
- RPCCDRsFilter: utils.RPCCDRsFilter{NotRunIDs: []string{"raw"}, Accounts: []string{"testV2CDRsProcessCDR4"}},
- Flags: []string{"*chargers:true"},
- }, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsGetCdrsWithRatingPlan(t *testing.T) {
- var cdrCnt int64
- req := utils.AttrGetCdrs{}
- if err := cdrsRpc.Call(utils.APIerSv2CountCDRs, &req, &cdrCnt); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if cdrCnt != 10 {
- t.Error("Unexpected number of CDRs returned: ", cdrCnt)
- }
- var cdrs []*engine.ExternalCDR
- args := utils.RPCCDRsFilter{RunIDs: []string{"raw"}, Accounts: []string{"testV2CDRsProcessCDR4"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != -1.0 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- }
- cdrs = []*engine.ExternalCDR{} // gob will not update zero value fields
- args = utils.RPCCDRsFilter{RunIDs: []string{"CustomerCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.0102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraInfo != "" {
- t.Errorf("Expected ExtraInfo : %s received :%s", "", cdrs[0].ExtraInfo)
- }
- }
- cdrs = []*engine.ExternalCDR{} // gob will not update zero value fields
- args = utils.RPCCDRsFilter{RunIDs: []string{"SupplierCharges"}, Accounts: []string{"testV2CDRsProcessCDR4"}}
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &args, &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 1 {
- t.Error("Unexpected number of CDRs returned: ", len(cdrs))
- } else {
- if cdrs[0].Cost != 0.0102 {
- t.Errorf("Unexpected cost for CDR: %f", cdrs[0].Cost)
- }
- if cdrs[0].ExtraInfo != "" {
- t.Errorf("Expected ExtraInfo : %s received :%s", "", cdrs[0].ExtraInfo)
- }
- }
-}
-
-func testV2CDRsSetThreshold(t *testing.T) {
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{
- ActionsId: "ACT_LOG",
- Actions: []*utils.TPAction{{Identifier: utils.MetaLog}},
- }, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
- }
- tPrfl := engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Test",
- FilterIDs: []string{
- "*lt:~*req.CostDetails.AccountSummary.BalanceSummaries[0].Value:10",
- "*string:~*req.Account:1005", // only for indexes
- },
- MaxHits: -1,
- Weight: 30,
- ActionIDs: []string{"ACT_LOG"},
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
- attrSetAcnt := AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "1005",
- ExtraOptions: map[string]bool{
- utils.AllowNegative: true,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil {
- t.Fatal(err)
- }
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "1005",
- BalanceType: utils.MetaMonetary,
- Value: 1,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- utils.Weight: 10.0,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV2CDRsProcessCDRWithThreshold(t *testing.T) {
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaThresholds, utils.MetaRALs, utils.ConcatenatedKey(utils.MetaChargers, "false")},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsProcessCDRWithThreshold",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsProcessCDRWithThreshold",
- utils.RequestType: utils.MetaPostpaid,
- utils.Category: "call",
- utils.AccountField: "1005",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: 100 * time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
- var reply string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsGetThreshold(t *testing.T) {
- var td engine.Threshold
- if err := cdrsRpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &td); err != nil {
- t.Error(err)
- } else if td.Hits != 1 {
- t.Errorf("Expecting threshold to be hit once received: %v", td.Hits)
- }
-}
-
-func testv2CDRsGetCDRsDest(t *testing.T) {
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaStore},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.CGRID: "9b3cd5e698af94f8916220866c831a982ed16318",
- utils.ToR: utils.MetaVoice,
- utils.RunID: "raw",
- utils.OriginID: "25160047719:0",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "*sessions",
- utils.RequestType: utils.MetaNone,
- utils.Category: "call",
- utils.AccountField: "1001",
- utils.Subject: "1001",
- utils.Destination: "+4915117174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: 100 * time.Minute,
- },
- },
- }
- var reply string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-
- var cdrs []*engine.ExternalCDR
- if err := cdrsRpc.Call(utils.APIerSv2GetCDRs, &utils.RPCCDRsFilter{DestinationPrefixes: []string{"+4915117174963"}},
- &cdrs); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if len(cdrs) != 3 {
- t.Error("Unexpected number of CDRs returned: ", len(reply))
- }
-}
-
-func testV2CDRsRerate(t *testing.T) {
- var reply string
- if err := cdrsRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: nil,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Reply: ", reply)
- }
- //add a charger
- chargerProfile := &v1.ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Default",
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"*none"},
- Weight: 20,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaReload,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- attrSetAcnt := AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "voiceAccount",
- }
- if err := cdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil {
- t.Fatal(err)
- }
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "voiceAccount",
- BalanceType: utils.MetaVoice,
- Value: 600000000000,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- "RatingSubject": "*zero1m",
- utils.Weight: 10.0,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
-
- var acnt *engine.Account
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 600000000000 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaVoice][0])
- }
-
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRerate},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsRerate",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsRerate",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "voiceAccount",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: 2 * time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
-
- var rplProcEv []*utils.EventWithFlags
- if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args, &rplProcEv); err != nil {
- t.Error("Unexpected error: ", err.Error())
- }
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 480000000000 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaVoice][0])
- }
-
- args2 := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRerate},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsRerate",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsRerate",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "voiceAccount",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
-
- if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args2, &rplProcEv); err != nil {
- t.Error("Unexpected error: ", err.Error())
- }
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "voiceAccount"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 540000000000 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaVoice][0])
- }
-}
-
-func testv2CDRsDynaPrepaid(t *testing.T) {
- var acnt engine.Account
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "CreatedAccount"}, &acnt); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
-
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRALs},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testv2CDRsDynaPrepaid",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testv2CDRsDynaPrepaid",
- utils.RequestType: utils.MetaDynaprepaid,
- utils.AccountField: "CreatedAccount",
- utils.Subject: "NoSubject",
- utils.Destination: "+1234567",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- },
- },
- }
-
- var reply string
- if err := cdrsRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "CreatedAccount"}, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaMonetary][0].Value != 9.9694 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0])
- }
-}
-
-func testV2CDRsDuplicateCDRs(t *testing.T) {
- var reply string
- if err := cdrsRpc.Call(utils.CacheSv1Clear, &utils.AttrCacheIDsWithAPIOpts{
- CacheIDs: nil,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Reply: ", reply)
- }
- //add a charger
- chargerProfile := &v1.ChargerWithAPIOpts{
- ChargerProfile: &engine.ChargerProfile{
- Tenant: "cgrates.org",
- ID: "Default",
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- RunID: utils.MetaDefault,
- AttributeIDs: []string{"*none"},
- Weight: 20,
- },
- APIOpts: map[string]interface{}{
- utils.CacheOpt: utils.MetaReload,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv1SetChargerProfile, chargerProfile, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Unexpected reply returned", reply)
- }
-
- attrSetAcnt := AttrSetAccount{
- Tenant: "cgrates.org",
- Account: "testV2CDRsDuplicateCDRs",
- }
- if err := cdrsRpc.Call(utils.APIerSv2SetAccount, &attrSetAcnt, &reply); err != nil {
- t.Fatal(err)
- }
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "testV2CDRsDuplicateCDRs",
- BalanceType: utils.MetaVoice,
- Value: 600000000000,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- "RatingSubject": "*zero1m",
- utils.Weight: 10.0,
- },
- }
- if err := cdrsRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
-
- var acnt *engine.Account
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 600000000000 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaVoice][0])
- }
-
- args := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRerate},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsDuplicateCDRs",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsDuplicateCDRs",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "testV2CDRsDuplicateCDRs",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: 2 * time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
-
- var rplProcEv []*utils.EventWithFlags
- if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args, &rplProcEv); err != nil {
- t.Error("Unexpected error: ", err.Error())
- }
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 480000000000 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaVoice][0])
- }
-
- var wg sync.WaitGroup
- for i := 0; i < 10; i++ {
- wg.Add(1)
- go func() {
- var rplProcEv []*utils.EventWithFlags
- args2 := &engine.ArgV1ProcessEvent{
- Flags: []string{utils.MetaRerate},
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsDuplicateCDRs",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsDuplicateCDRs",
- utils.RequestType: utils.MetaPseudoPrepaid,
- utils.AccountField: "testV2CDRsDuplicateCDRs",
- utils.Subject: "ANY2CNT",
- utils.Destination: "+4986517174963",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- "field_extr1": "val_extr1",
- "fieldextr2": "valextr2",
- },
- },
- }
- if err := cdrsRpc.Call(utils.CDRsV2ProcessEvent, args2, &rplProcEv); err != nil {
- t.Error("Unexpected error: ", err.Error())
- }
- wg.Done()
- }()
- }
- wg.Wait()
-
- if err := cdrsRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "testV2CDRsDuplicateCDRs"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaVoice][0].Value != 540000000000 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaVoice][0])
- }
-}
-
-func testV2CDRsKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
-
-func testV2CDRsResetThresholdAction(t *testing.T) {
- var reply string
- if err := cdrsRpc.Call(utils.APIerSv2SetActions, &utils.AttrSetActions{
- ActionsId: "ACT_RESET_THD",
- Actions: []*utils.TPAction{{Identifier: utils.MetaResetThreshold, ExtraParameters: "cgrates.org:THD_Test"}},
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
- }
- attrs := utils.AttrExecuteAction{Tenant: "cgrates.org", ActionsId: "ACT_RESET_THD"}
- if err := cdrsRpc.Call(utils.APIerSv1ExecuteAction, attrs, &reply); err != nil {
- t.Error(err)
- }
- var td engine.Threshold
- if err := cdrsRpc.Call(utils.ThresholdSv1GetThreshold,
- &utils.TenantIDWithAPIOpts{TenantID: &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}}, &td); err != nil {
- t.Error(err)
- } else if td.Hits != 0 {
- t.Errorf("Expecting threshold to be reset received: %v", td.Hits)
- }
-}
diff --git a/apier/v2/cdrs_offline_it_test.go b/apier/v2/cdrs_offline_it_test.go
deleted file mode 100644
index 97529eb33..000000000
--- a/apier/v2/cdrs_offline_it_test.go
+++ /dev/null
@@ -1,391 +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 v2
-
-import (
- "net/rpc"
- "path"
- "reflect"
- "testing"
- "time"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- cdrsOfflineCfgPath string
- cdrsOfflineCfg *config.CGRConfig
- cdrsOfflineRpc *rpc.Client
- cdrsOfflineConfDIR string // run the tests for specific configuration
-
- // subtests to be executed for each confDIR
- sTestsCDRsOfflineIT = []func(t *testing.T){
- testV2CDRsOfflineInitConfig,
- testV2CDRsOfflineInitDataDb,
- testV2CDRsOfflineInitCdrDb,
- testV2CDRsOfflineStartEngine,
- testV2cdrsOfflineRpcConn,
- testV2CDRsOfflineLoadData,
- testV2CDRsOfflineBalanceUpdate,
- testV2CDRsOfflineExpiryBalance,
- testV2CDRsBalancesWithSameWeight,
- testV2CDRsOfflineKillEngine,
- }
-)
-
-// Tests starting here
-func TestCDRsOfflineIT(t *testing.T) {
- switch *dbType {
- case utils.MetaInternal:
- cdrsOfflineConfDIR = "cdrsv2internal"
- case utils.MetaMySQL:
- cdrsOfflineConfDIR = "cdrsv2mysql"
- case utils.MetaMongo:
- cdrsOfflineConfDIR = "cdrsv2mongo"
- case utils.MetaPostgres:
- cdrsOfflineConfDIR = "cdrsv2psql"
- default:
- t.Fatal("Unknown Database type")
- }
- for _, stest := range sTestsCDRsOfflineIT {
- t.Run(cdrsOfflineConfDIR, stest)
- }
-}
-
-func testV2CDRsOfflineInitConfig(t *testing.T) {
- var err error
- cdrsOfflineCfgPath = path.Join(*dataDir, "conf", "samples", cdrsOfflineConfDIR)
- if cdrsOfflineCfg, err = config.NewCGRConfigFromPath(cdrsOfflineCfgPath); err != nil {
- t.Fatal("Got config error: ", err.Error())
- }
-}
-
-func testV2CDRsOfflineInitDataDb(t *testing.T) {
- if err := engine.InitDataDB(cdrsOfflineCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// InitDb so we can rely on count
-func testV2CDRsOfflineInitCdrDb(t *testing.T) {
- if err := engine.InitStorDB(cdrsOfflineCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-func testV2CDRsOfflineStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(cdrsOfflineCfgPath, *waitRater); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testV2cdrsOfflineRpcConn(t *testing.T) {
- cdrsOfflineRpc, err = newRPCClient(cdrsOfflineCfg.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 testV2CDRsOfflineLoadData(t *testing.T) {
- var loadInst utils.LoadInstance
- if err := cdrsOfflineRpc.Call(utils.APIerSv2LoadTariffPlanFromFolder,
- &utils.AttrLoadTpFromFolder{FolderPath: path.Join(
- *dataDir, "tariffplans", "testit")}, &loadInst); err != nil {
- t.Error(err)
- }
- time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups
-}
-
-func testV2CDRsOfflineBalanceUpdate(t *testing.T) {
- //add a test account with balance type monetary and value 10
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "test",
- BalanceType: utils.MetaMonetary,
- Value: 10.0,
- Balance: map[string]interface{}{
- utils.ID: utils.MetaDefault,
- utils.Weight: 10.0,
- },
- }
- var reply string
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
- var acnt *engine.Account
- if err := cdrsOfflineRpc.Call(utils.APIerSv2GetAccount, &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "test"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || acnt.BalanceMap[utils.MetaMonetary][0].Value != 10.0 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary][0])
- }
-
- var thReply *engine.ThresholdProfile
- var result string
-
- //create a log action
- attrsAA := &utils.AttrSetActions{ActionsId: "ACT_LOG", Actions: []*utils.TPAction{
- {Identifier: utils.MetaLog},
- }}
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetActions, attrsAA, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
- t.Error("Got error on APIerSv2.SetActions: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
- }
- //make sure that the threshold don't exit
- if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &thReply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //create a threshold that match out account
- tPrfl := engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Test",
- FilterIDs: []string{"*string:Account:test"},
- MaxHits: -1,
- MinSleep: time.Second,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_LOG"},
- Async: false,
- },
- }
- if err := cdrsOfflineRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test"}, &thReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl, thReply)
- }
-
- cgrEv := &utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsOfflineProcessCDR2",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsOfflineProcessCDR",
- utils.RequestType: utils.MetaPostpaid,
- utils.Category: "call",
- utils.AccountField: "test",
- utils.Subject: "test",
- utils.Destination: "1002",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- },
- }
- mapEv := engine.NewMapEvent(cgrEv.Event)
- cdr, err := mapEv.AsCDR(nil, "cgrates.org", "")
- if err != nil {
- t.Error("Unexpected error received: ", err)
- }
- //process cdr should trigger balance update event
- if err := cdrsOfflineRpc.Call(utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsOfflineExpiryBalance(t *testing.T) {
- var reply string
- acc := &utils.AttrSetActions{ActionsId: "ACT_TOPUP_TEST2", Actions: []*utils.TPAction{
- {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, BalanceId: "BalanceExpired1", Units: "5",
- ExpiryTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC).String(), BalanceWeight: "10", Weight: 20.0},
- {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, BalanceId: "BalanceExpired2", Units: "10",
- ExpiryTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC).String(), BalanceWeight: "10", Weight: 20.0},
- {Identifier: utils.MetaTopUp, BalanceType: utils.MetaMonetary, BalanceId: "NewBalance", Units: "10",
- ExpiryTime: utils.MetaUnlimited, BalanceWeight: "10", Weight: 20.0},
- }}
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetActions, acc, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
- t.Error("Got error on APIerSv2.SetActions: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
- }
-
- atm1 := &v1.AttrActionPlan{ActionsId: "ACT_TOPUP_TEST2", Time: "*asap", Weight: 20.0}
- atms1 := &v1.AttrSetActionPlan{Id: "AP_TEST2", ActionPlan: []*v1.AttrActionPlan{atm1}}
- if err := cdrsOfflineRpc.Call(utils.APIerSv1SetActionPlan, &atms1, &reply); err != nil {
- t.Error("Got error on APIerSv1.SetActionPlan: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv1.SetActionPlan received: %s", reply)
- }
-
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetAccount,
- &AttrSetAccount{Tenant: "cgrates.org", Account: "test2",
- ActionPlanIDs: []string{"AP_TEST2"}, ReloadScheduler: true},
- &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetAccount received: %s", reply)
- }
-
- var acnt *engine.Account
- //verify if the third balance was added
- if err := cdrsOfflineRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "test2"}, &acnt); err != nil {
- t.Error(err)
- } else if acnt.BalanceMap[utils.MetaMonetary].Len() != 1 {
- t.Errorf("Unexpected balance received: %+v", utils.ToIJSON(acnt))
- }
-
- var thReply *engine.ThresholdProfile
- var result string
-
- //create a log action
- attrsA := &utils.AttrSetActions{ActionsId: "ACT_LOG", Actions: []*utils.TPAction{
- {Identifier: utils.MetaLog},
- }}
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetActions, attrsA, &reply); err != nil && err.Error() != utils.ErrExists.Error() {
- t.Error("Got error on APIerSv2.SetActions: ", err.Error())
- } else if reply != utils.OK {
- t.Errorf("Calling APIerSv2.SetActions received: %s", reply)
- }
- //make sure that the threshold don't exit
- if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test2"}, &thReply); err == nil ||
- err.Error() != utils.ErrNotFound.Error() {
- t.Error(err)
- }
- //create a threshold that match out account
- tPrfl := &engine.ThresholdProfileWithAPIOpts{
- ThresholdProfile: &engine.ThresholdProfile{
- Tenant: "cgrates.org",
- ID: "THD_Test2",
- FilterIDs: []string{"*string:Account:test2"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- ExpiryTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- MaxHits: -1,
- MinSleep: 0,
- Blocker: false,
- Weight: 20.0,
- ActionIDs: []string{"ACT_LOG"},
- Async: false,
- },
- }
- if err := cdrsOfflineRpc.Call(utils.APIerSv1SetThresholdProfile, tPrfl, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- if err := cdrsOfflineRpc.Call(utils.APIerSv1GetThresholdProfile,
- &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Test2"}, &thReply); err != nil {
- t.Error(err)
- } else if !reflect.DeepEqual(tPrfl.ThresholdProfile, thReply) {
- t.Errorf("Expecting: %+v, received: %+v", tPrfl, thReply)
- }
-
- args := &engine.ArgV1ProcessEvent{
- CGREvent: utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsOfflineProcessCDR1",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsOfflineProcessCDR",
- utils.RequestType: utils.MetaPostpaid,
- utils.Category: "call",
- utils.AccountField: "test2",
- utils.Subject: "test2",
- utils.Destination: "1002",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- },
- },
- }
- //process cdr should trigger balance update event
- if err := cdrsOfflineRpc.Call(utils.CDRsV1ProcessEvent, args, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsBalancesWithSameWeight(t *testing.T) {
- //add a test account with balance type monetary and value 10
- attrs := &utils.AttrSetBalance{
- Tenant: "cgrates.org",
- Account: "specialTest",
- BalanceType: utils.MetaMonetary,
- Value: 10.0,
- Balance: map[string]interface{}{
- utils.ID: "SpecialBalance1",
- utils.Weight: 10.0,
- },
- }
- var reply string
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
- attrs.Balance[utils.ID] = "SpecialBalance2"
- if err := cdrsOfflineRpc.Call(utils.APIerSv2SetBalance, attrs, &reply); err != nil {
- t.Fatal(err)
- }
- var acnt *engine.Account
- if err := cdrsOfflineRpc.Call(utils.APIerSv2GetAccount,
- &utils.AttrGetAccount{Tenant: "cgrates.org", Account: "specialTest"}, &acnt); err != nil {
- t.Error(err)
- } else if len(acnt.BalanceMap) != 1 || len(acnt.BalanceMap[utils.MetaMonetary]) != 2 {
- t.Errorf("Unexpected balance received: %+v", acnt.BalanceMap[utils.MetaMonetary])
- }
-
- cgrEv := &utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.OriginID: "testV2CDRsBalancesWithSameWeight",
- utils.OriginHost: "192.168.1.1",
- utils.Source: "testV2CDRsBalancesWithSameWeight",
- utils.RequestType: utils.MetaPostpaid,
- utils.Category: "call",
- utils.AccountField: "specialTest",
- utils.Subject: "specialTest",
- utils.Destination: "1002",
- utils.AnswerTime: time.Date(2018, 8, 24, 16, 00, 26, 0, time.UTC),
- utils.Usage: time.Minute,
- },
- }
- mapEv := engine.NewMapEvent(cgrEv.Event)
- cdr, err := mapEv.AsCDR(nil, "cgrates.org", "")
- if err != nil {
- t.Error("Unexpected error received: ", err)
- }
- //process cdr should trigger balance update event
- if err := cdrsOfflineRpc.Call(utils.CDRsV1ProcessCDR, &engine.CDRWithAPIOpts{CDR: cdr}, &reply); err != nil {
- t.Error("Unexpected error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received: ", reply)
- }
-}
-
-func testV2CDRsOfflineKillEngine(t *testing.T) {
- if err := engine.KillEngine(*waitRater); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v2/dispatcher.go b/apier/v2/dispatcher.go
deleted file mode 100644
index 0b28cbaa7..000000000
--- a/apier/v2/dispatcher.go
+++ /dev/null
@@ -1,38 +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 v2
-
-import (
- "github.com/cgrates/cgrates/dispatchers"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-func NewDispatcherSCDRsV2(dps *dispatchers.DispatcherService) *DispatcherSCDRsV2 {
- return &DispatcherSCDRsV2{dS: dps}
-}
-
-// Exports RPC from CDRsV2
-type DispatcherSCDRsV2 struct {
- dS *dispatchers.DispatcherService
-}
-
-func (dS *DispatcherSCDRsV2) ProcessEvent(args *engine.ArgV1ProcessEvent, reply *[]*utils.EventWithFlags) error {
- return dS.dS.CDRsV2ProcessEvent(args, reply)
-}
diff --git a/apier/v2/lib_test.go b/apier/v2/lib_test.go
deleted file mode 100644
index 8bdd01564..000000000
--- a/apier/v2/lib_test.go
+++ /dev/null
@@ -1,47 +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 v2
-
-import (
- "errors"
- "flag"
- "net/rpc"
- "net/rpc/jsonrpc"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- dataDir = flag.String("data_dir", "/usr/share/cgrates", "CGR data dir path here")
- waitRater = flag.Int("wait_rater", 100, "Number of miliseconds to wait for rater to start and cache")
- encoding = flag.String("rpc", utils.MetaJSON, "what encoding whould be uused for rpc comunication")
- dbType = flag.String("dbtype", utils.MetaInternal, "The type of DataBase (Internal/Mongo/mySql)")
-)
-
-func newRPCClient(cfg *config.ListenCfg) (c *rpc.Client, err error) {
- switch *encoding {
- case utils.MetaJSON:
- return jsonrpc.Dial(utils.TCP, cfg.RPCJSONListen)
- case utils.MetaGOB:
- return rpc.Dial(utils.TCP, cfg.RPCGOBListen)
- default:
- return nil, errors.New("UNSUPPORTED_RPC")
- }
-}
diff --git a/apier/v2/tp_it_test.go b/apier/v2/tp_it_test.go
deleted file mode 100644
index c642a27d3..000000000
--- a/apier/v2/tp_it_test.go
+++ /dev/null
@@ -1,261 +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 v2
-
-import (
- "net/rpc"
- "path"
- "reflect"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-var (
- tpCfgPath string
- tpCfg *config.CGRConfig
- tpRPC *rpc.Client
- err error
- delay int
- configDIR string // relative path towards a config directory under samples prefix
- testTPid = "V2TestTPit"
-
- // subtests to be executed for each confDIR
- sTestsTutIT = []func(t *testing.T){
- testTPitLoadConfig,
- testTPitResetDataDb,
- testTPitResetStorDb,
- testTPitStartEngine,
- testTPitRpcConn,
- testTPitTimings,
- testTPitDestinations,
- testTPitKillEngine,
- }
-)
-
-// Tests starting here
-
-func TestTPit(t *testing.T) {
-
- switch *dbType {
- case utils.MetaInternal:
- configDIR = "tutinternal"
- case utils.MetaMySQL:
- configDIR = "tutmysql"
- case utils.MetaMongo:
- configDIR = "tutmongo"
- case utils.MetaPostgres:
- configDIR = "tutpostgres"
- default:
- t.Fatal("Unknown Database type")
- }
-
- for _, stest := range sTestsTutIT {
- t.Run(configDIR, stest)
- }
-}
-
-func testTPitLoadConfig(t *testing.T) {
- tpCfgPath = path.Join(*dataDir, "conf", "samples", configDIR)
- if tpCfg, err = config.NewCGRConfigFromPath(tpCfgPath); err != nil {
- t.Error(err)
- }
- switch configDIR {
- case "tutmongo": // Mongo needs more time to reset db, need to investigate
- delay = 4000
- default:
- delay = *waitRater
- }
-}
-
-// Remove data in both rating and accounting db
-func testTPitResetDataDb(t *testing.T) {
- if err := engine.InitDataDB(tpCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testTPitResetStorDb(t *testing.T) {
- if err := engine.InitStorDB(tpCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testTPitStartEngine(t *testing.T) {
- if _, err := engine.StopStartEngine(tpCfgPath, delay); err != nil { // Mongo requires more time to start
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testTPitRpcConn(t *testing.T) {
- var err error
- tpRPC, err = newRPCClient(tpCfg.ListenCfg()) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-}
-
-func testTPitTimings(t *testing.T) {
- // PEAK,*any,*any,*any,1;2;3;4;5,08:00:00
- tmPeak := &utils.ApierTPTiming{
- TPid: testTPid,
- ID: "PEAK",
- Years: "*any",
- Months: "*any",
- MonthDays: "*any",
- WeekDays: "1;2;3;4;5",
- Time: "08:00:00",
- }
- // OFFPEAK_MORNING,*any,*any,*any,1;2;3;4;5,00:00:00
- tmOffPeakMorning := &utils.ApierTPTiming{
- TPid: testTPid,
- ID: "OFFPEAK_MORNING",
- Years: "*any",
- Months: "*any",
- MonthDays: "*any",
- WeekDays: "1;2;3;4;5",
- Time: "00:00:00",
- }
- // OFFPEAK_EVENING,*any,*any,*any,1;2;3;4;5,19:00:00
- tmOffPeakEvening := &utils.ApierTPTiming{
- TPid: testTPid,
- ID: "OFFPEAK_EVENING",
- Years: "*any",
- Months: "*any",
- MonthDays: "*any",
- WeekDays: "1;2;3;4;5",
- Time: "19:00:00",
- }
- // OFFPEAK_WEEKEND,*any,*any,*any,6;7,00:00:00
- tmOffPeakWeekend := &utils.ApierTPTiming{
- TPid: testTPid,
- ID: "OFFPEAK_WEEKEND",
- Years: "*any",
- Months: "*any",
- MonthDays: "*any",
- WeekDays: "6;7",
- Time: "00:00:00",
- }
- // DUMMY, only used for the purpose of testing remove function
- tmDummyRemove := &utils.ApierTPTiming{
- TPid: testTPid,
- ID: "DUMMY_REMOVE",
- Years: "*any",
- Months: "*any",
- MonthDays: "*any",
- WeekDays: "*any",
- Time: "01:00:00",
- }
- // Test set
- var reply string
- for _, tm := range []*utils.ApierTPTiming{tmPeak, tmOffPeakMorning, tmOffPeakEvening, tmOffPeakWeekend, tmDummyRemove} {
- if err := tpRPC.Call(utils.APIerSv2SetTPTiming, tm, &reply); err != nil {
- t.Error("Got error on APIerSv2.SetTPTiming: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv2.SetTPTiming: ", reply)
- }
- }
- // Test get
- var rplyTmDummy *utils.ApierTPTiming
- if err := tpRPC.Call(utils.APIerSv2GetTPTiming, v1.AttrGetTPTiming{tmDummyRemove.TPid, tmDummyRemove.ID}, &rplyTmDummy); err != nil {
- t.Error("Calling APIerSv2.GetTPTiming, got error: ", err.Error())
- } else if !reflect.DeepEqual(tmDummyRemove, rplyTmDummy) {
- t.Errorf("Calling APIerSv2.GetTPTiming expected: %v, received: %v", tmDummyRemove, rplyTmDummy)
- }
- var rplyTmIDs []string
- expectedTmIDs := []string{"OFFPEAK_EVENING", "OFFPEAK_MORNING", "OFFPEAK_WEEKEND", "PEAK", tmDummyRemove.ID}
- if err := tpRPC.Call(utils.APIerSv1GetTPTimingIds, &v1.AttrGetTPTimingIds{testTPid, utils.PaginatorWithSearch{}}, &rplyTmIDs); err != nil {
- t.Error("Calling APIerSv1.GetTPTimingIds, got error: ", err.Error())
- } else if len(expectedTmIDs) != len(rplyTmIDs) {
- t.Errorf("Calling APIerSv1.GetTPTimingIds expected: %v, received: %v", expectedTmIDs, rplyTmIDs)
- }
- // Test remove
- if err := tpRPC.Call(utils.APIerSv2RemoveTPTiming, v1.AttrGetTPTiming{tmDummyRemove.TPid, tmDummyRemove.ID}, &reply); err != nil {
- t.Error("Calling APIerSv2.RemoveTPTiming, got error: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Calling APIerSv2.RemoveTPTiming received: ", reply)
- }
- // Test getIds
- rplyTmIDs = []string{}
- expectedTmIDs = []string{"OFFPEAK_EVENING", "OFFPEAK_MORNING", "OFFPEAK_WEEKEND", "PEAK"}
- if err := tpRPC.Call(utils.APIerSv1GetTPTimingIds, &v1.AttrGetTPTimingIds{testTPid, utils.PaginatorWithSearch{}}, &rplyTmIDs); err != nil {
- t.Error("Calling APIerSv1.GetTPTimingIds, got error: ", err.Error())
- } else if len(expectedTmIDs) != len(rplyTmIDs) {
- t.Errorf("Calling APIerSv1.GetTPTimingIds expected: %v, received: %v", expectedTmIDs, rplyTmIDs)
- }
-}
-
-func testTPitDestinations(t *testing.T) {
- var reply string
- // DST_1002,1002
- dst1002 := &utils.TPDestination{TPid: testTPid, ID: "DST_1002", Prefixes: []string{"1002"}}
- // DST_1003,1003
- dst1003 := &utils.TPDestination{TPid: testTPid, ID: "DST_1003", Prefixes: []string{"1003"}}
- // DST_1007,1007
- dst1007 := &utils.TPDestination{TPid: testTPid, ID: "DST_1007", Prefixes: []string{"1007"}}
- // DST_FS,10
- dstFS := &utils.TPDestination{TPid: testTPid, ID: "DST_FS", Prefixes: []string{"10"}}
- // DST_DE_MOBILE,+49151
- // DST_DE_MOBILE,+49161
- // DST_DE_MOBILE,+49171
- dstDEMobile := &utils.TPDestination{TPid: testTPid, ID: "DST_DE_MOBILE", Prefixes: []string{"+49151", "+49161", "+49171"}}
- dstDUMMY := &utils.TPDestination{TPid: testTPid, ID: "DUMMY_REMOVE", Prefixes: []string{"999"}}
- for _, dst := range []*utils.TPDestination{dst1002, dst1003, dst1007, dstFS, dstDEMobile, dstDUMMY} {
- if err := tpRPC.Call(utils.APIerSv2SetTPDestination, dst, &reply); err != nil {
- t.Error("Got error on APIerSv2.SetTPDestination: ", err.Error())
- } else if reply != utils.OK {
- t.Error("Unexpected reply received when calling APIerSv2.SetTPDestination: ", reply)
- }
- }
- // Test get
- var rplyDst *utils.TPDestination
- if err := tpRPC.Call(utils.APIerSv2GetTPDestination, &AttrGetTPDestination{testTPid, dstDEMobile.ID}, &rplyDst); err != nil {
- t.Error("Calling APIerSv2.GetTPDestination, got error: ", err.Error())
- } else if len(dstDEMobile.Prefixes) != len(rplyDst.Prefixes) {
- t.Errorf("Calling APIerSv2.GetTPDestination expected: %v, received: %v", dstDEMobile, rplyDst)
- }
- // Test remove
- if err := tpRPC.Call(utils.APIerSv2RemoveTPDestination, &AttrGetTPDestination{testTPid, dstDUMMY.ID}, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Error("Received: ", reply)
- }
- // Test getIds
- var rplyDstIds []string
- expectedDstIds := []string{"DST_1002", "DST_1003", "DST_1007", "DST_DE_MOBILE", "DST_FS"}
- if err := tpRPC.Call(utils.APIerSv2GetTPDestinationIDs, v1.AttrGetTPDestinationIds{TPid: testTPid}, &rplyDstIds); err != nil {
- t.Error("Calling APIerSv1.GetTPDestinationIDs, got error: ", err.Error())
- } else if len(expectedDstIds) != len(rplyDstIds) {
- t.Errorf("Calling APIerSv2.GetTPDestinationIDs expected: %v, received: %v", expectedDstIds, rplyDstIds)
- }
-}
-
-func testTPitKillEngine(t *testing.T) {
- if err := engine.KillEngine(100); err != nil {
- t.Error(err)
- }
-}
diff --git a/apier/v2/tpdestinations.go b/apier/v2/tpdestinations.go
deleted file mode 100644
index c5b627055..000000000
--- a/apier/v2/tpdestinations.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 v2
-
-import (
- "github.com/cgrates/cgrates/utils"
-)
-
-// Creates a new destination within a tariff plan
-func (self *APIerSv2) SetTPDestination(attrs *utils.TPDestination, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tag", "Prefixes"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if err := self.StorDb.SetTPDestinations([]*utils.TPDestination{attrs}); err != nil {
- return utils.APIErrorHandler(err)
- }
- *reply = utils.OK
- return nil
-}
-
-type AttrGetTPDestination struct {
- TPid string // Tariff plan id
- Tag string // Destination id
-}
-
-// Queries a specific destination
-func (self *APIerSv2) GetTPDestination(attrs *AttrGetTPDestination, reply *utils.TPDestination) error {
- if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tag"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if tpDsts, err := self.StorDb.GetTPDestinations(attrs.TPid, attrs.Tag); err != nil {
- return utils.APIErrorHandler(err)
- } else if len(tpDsts) == 0 {
- return utils.ErrNotFound
- } else {
- *reply = *tpDsts[0]
- }
- return nil
-}
-
-func (self *APIerSv2) RemoveTPDestination(attrs *AttrGetTPDestination, reply *string) error {
- if missing := utils.MissingStructFields(attrs, []string{"TPid", "Tag"}); len(missing) != 0 { //Params missing
- return utils.NewErrMandatoryIeMissing(missing...)
- }
- if err := self.StorDb.RemTpData(utils.TBLTPDestinations, attrs.TPid, map[string]string{"tag": attrs.Tag}); err != nil {
- return utils.APIErrorHandler(err)
- } else {
- *reply = utils.OK
- }
- return nil
-}
diff --git a/apis/admins.go b/apis/admins.go
index c650eacde..259bbeb43 100644
--- a/apis/admins.go
+++ b/apis/admins.go
@@ -23,7 +23,15 @@ import (
"github.com/cgrates/cgrates/engine"
)
-type AdminS struct {
+func NewAdminSv1(cfg *config.CGRConfig, dm *engine.DataManager, connMgr *engine.ConnManager) *AdminSv1 {
+ return &AdminSv1{
+ cfg: cfg,
+ dm: dm,
+ connMgr: connMgr,
+ }
+}
+
+type AdminSv1 struct {
cfg *config.CGRConfig
dm *engine.DataManager
connMgr *engine.ConnManager
diff --git a/apis/attributes.go b/apis/attributes.go
index dfaaa2126..622756314 100644
--- a/apis/attributes.go
+++ b/apis/attributes.go
@@ -27,7 +27,7 @@ import (
)
// GetAttributeProfile returns an Attribute Profile based on the tenant and ID received
-func (admS *AdminS) GetAttributeProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *engine.APIAttributeProfile) (err error) {
+func (admS *AdminSv1) GetAttributeProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *engine.APIAttributeProfile) (err error) {
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
@@ -48,7 +48,7 @@ func (admS *AdminS) GetAttributeProfile(ctx *context.Context, arg *utils.TenantI
}
// GetAttributeProfileIDs returns list of attributeProfile IDs registered for a tenant
-func (admS *AdminS) GetAttributeProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
+func (admS *AdminSv1) GetAttributeProfileIDs(ctx *context.Context, args *utils.PaginatorWithTenant, attrPrfIDs *[]string) error {
tnt := args.Tenant
if tnt == utils.EmptyString {
tnt = admS.cfg.GeneralCfg().DefaultTenant
@@ -71,7 +71,7 @@ func (admS *AdminS) GetAttributeProfileIDs(ctx *context.Context, args *utils.Pag
// GetAttributeProfileIDsCount returns the total number of AttributeProfileIDs registered for a tenant
// returns ErrNotFound in case of 0 AttributeProfileIDs
-func (admS *AdminS) GetAttributeProfileIDsCount(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *int) (err error) {
+func (admS *AdminSv1) GetAttributeProfileIDsCount(ctx *context.Context, args *utils.TenantWithAPIOpts, reply *int) (err error) {
tnt := args.Tenant
if tnt == utils.EmptyString {
tnt = admS.cfg.GeneralCfg().DefaultTenant
@@ -89,7 +89,7 @@ func (admS *AdminS) GetAttributeProfileIDsCount(ctx *context.Context, args *util
}
//SetAttributeProfile add/update a new Attribute Profile
-func (admS *AdminS) SetAttributeProfile(ctx *context.Context, arg *engine.AttributeWithAPIOpts, reply *string) error {
+func (admS *AdminSv1) SetAttributeProfile(ctx *context.Context, arg *engine.AttributeWithAPIOpts, reply *string) error {
if missing := utils.MissingStructFields(arg.APIAttributeProfile, []string{utils.ID}); len(missing) != 0 {
return utils.NewErrMandatoryIeMissing(missing...)
}
@@ -116,8 +116,8 @@ func (admS *AdminS) SetAttributeProfile(ctx *context.Context, arg *engine.Attrib
return nil
}
-//RemoveAttributeProfile remove a specific Attribute Profile based on tenant an ID
-func (apierSv1 *AdminS) RemoveAttributeProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error {
+// RemoveAttributeProfile remove a specific Attribute Profile based on tenant an ID
+func (apierSv1 *AdminSv1) RemoveAttributeProfile(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *string) error {
if missing := utils.MissingStructFields(arg, []string{utils.ID}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
diff --git a/apis/libadmin.go b/apis/libadmin.go
index 1d1eb783d..f59c23011 100644
--- a/apis/libadmin.go
+++ b/apis/libadmin.go
@@ -28,7 +28,7 @@ import (
// CallCache caching the item based on cacheopt
// visible in APIerSv2
-func (apierSv1 *AdminS) CallCache(ctx *context.Context, cacheopt string, tnt, cacheID, itemID string,
+func (apierSv1 *AdminSv1) CallCache(ctx *context.Context, cacheopt string, tnt, cacheID, itemID string,
filters *[]string, contexts []string, opts map[string]interface{}) (err error) {
var reply, method string
var args interface{}
@@ -65,13 +65,13 @@ func (apierSv1 *AdminS) CallCache(ctx *context.Context, cacheopt string, tnt, ca
}
}
- return apierSv1.connMgr.Call(ctx, apierSv1.cfg.ApierCfg().CachesConns,
+ return apierSv1.connMgr.Call(ctx, apierSv1.cfg.AdminSCfg().CachesConns,
method, args, &reply)
}
// composeArgsReload add the ItemID to AttrReloadCache
// for a specific CacheID
-func (apierSv1 *AdminS) composeArgsReload(ctx *context.Context, tnt, cacheID, itemID string, filterIDs *[]string, contexts []string, opts map[string]interface{}) (rpl utils.AttrReloadCacheWithAPIOpts, err error) {
+func (apierSv1 *AdminSv1) composeArgsReload(ctx *context.Context, tnt, cacheID, itemID string, filterIDs *[]string, contexts []string, opts map[string]interface{}) (rpl utils.AttrReloadCacheWithAPIOpts, err error) {
rpl = utils.AttrReloadCacheWithAPIOpts{
Tenant: tnt,
ArgsCache: map[string][]string{
diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go
index 1c95666fe..0ac526a38 100644
--- a/cmd/cgr-engine/cgr-engine.go
+++ b/cmd/cgr-engine/cgr-engine.go
@@ -39,7 +39,6 @@ import (
"github.com/cgrates/cgrates/loaders"
"github.com/cgrates/cgrates/registrarc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/services"
@@ -89,10 +88,10 @@ func initCacheS(internalCacheSChan chan birpc.ClientConnector,
}
}()
- chSv1 := v1.NewCacheSv1(chS)
- if !cfg.DispatcherSCfg().Enabled {
- server.RpcRegister(chSv1)
- }
+ // chSv1 := v1.NewCacheSv1(chS)
+ // if !cfg.DispatcherSCfg().Enabled {
+ // server.RpcRegister(chSv1)
+ // }
var rpc birpc.ClientConnector = chS
if anz.IsRunning() {
rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.CacheS)
@@ -103,23 +102,23 @@ func initCacheS(internalCacheSChan chan birpc.ClientConnector,
func initGuardianSv1(internalGuardianSChan chan birpc.ClientConnector, server *cores.Server,
anz *services.AnalyzerService) {
- grdSv1 := v1.NewGuardianSv1()
- if !cfg.DispatcherSCfg().Enabled {
- server.RpcRegister(grdSv1)
- }
- var rpc birpc.ClientConnector = grdSv1
- if anz.IsRunning() {
- rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.GuardianS)
- }
- internalGuardianSChan <- rpc
+ // grdSv1 := v1.NewGuardianSv1()
+ // if !cfg.DispatcherSCfg().Enabled {
+ // server.RpcRegister(grdSv1)
+ // }
+ // var rpc birpc.ClientConnector = grdSv1
+ // if anz.IsRunning() {
+ // rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.GuardianS)
+ // }
+ // internalGuardianSChan <- rpc
}
func initServiceManagerV1(internalServiceManagerChan chan birpc.ClientConnector,
srvMngr *servmanager.ServiceManager, server *cores.Server,
anz *services.AnalyzerService) {
- if !cfg.DispatcherSCfg().Enabled {
- server.RpcRegister(v1.NewServiceManagerV1(srvMngr))
- }
+ // if !cfg.DispatcherSCfg().Enabled {
+ // server.RpcRegister(v1.NewServiceManagerV1(srvMngr))
+ // }
var rpc birpc.ClientConnector = srvMngr
if anz.IsRunning() {
rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.ServiceManager)
@@ -129,15 +128,15 @@ func initServiceManagerV1(internalServiceManagerChan chan birpc.ClientConnector,
func initConfigSv1(internalConfigChan chan birpc.ClientConnector,
server *cores.Server, anz *services.AnalyzerService) {
- cfgSv1 := v1.NewConfigSv1(cfg)
- if !cfg.DispatcherSCfg().Enabled {
- server.RpcRegister(cfgSv1)
- }
- var rpc birpc.ClientConnector = cfgSv1
- if anz.IsRunning() {
- rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.ConfigSv1)
- }
- internalConfigChan <- rpc
+ // cfgSv1 := v1.NewConfigSv1(cfg)
+ // if !cfg.DispatcherSCfg().Enabled {
+ // server.RpcRegister(cfgSv1)
+ // }
+ // var rpc birpc.ClientConnector = cfgSv1
+ // if anz.IsRunning() {
+ // rpc = anz.GetAnalyzerS().NewAnalyzerConnector(rpc, utils.MetaInternal, utils.EmptyString, utils.ConfigSv1)
+ // }
+ // internalConfigChan <- rpc
}
func startRPC(server *cores.Server,
@@ -632,11 +631,9 @@ func main() {
routeS := services.NewRouteService(cfg, dmService, cacheS, filterSChan, server,
internalRouteSChan, connManager, anz, srvDep)
- apiSv1 := services.NewAPIerSv1Service(cfg, dmService, storDBService, filterSChan, server,
+ admS := services.NewAdminSv1Service(cfg, dmService, storDBService, filterSChan, server,
internalAPIerSv1Chan, connManager, anz, srvDep)
- apiSv2 := services.NewAPIerSv2Service(apiSv1, cfg, server, internalAPIerSv2Chan, anz, srvDep)
-
cdrS := services.NewCDRServer(cfg, dmService, storDBService, filterSChan, server, internalCDRServerChan,
connManager, anz, srvDep)
@@ -646,7 +643,7 @@ func main() {
internalLoaderSChan, connManager, anz, srvDep)
srvManager.AddServices(gvService, attrS, chrS, tS, stS, reS, routeS,
- apiSv1, apiSv2, cdrS, smg, coreS,
+ admS, cdrS, smg, coreS,
services.NewEventReaderService(cfg, filterSChan, shdChan, connManager, srvDep),
services.NewDNSAgent(cfg, filterSChan, shdChan, connManager, srvDep),
services.NewFreeswitchAgent(cfg, shdChan, connManager, srvDep),
diff --git a/cmd/cgr-loader/cgr-loader_it_test.go b/cmd/cgr-loader/cgr-loader_it_test.go
index 9e91b098b..946b83b13 100644
--- a/cmd/cgr-loader/cgr-loader_it_test.go
+++ b/cmd/cgr-loader/cgr-loader_it_test.go
@@ -28,6 +28,7 @@ import (
"reflect"
"testing"
+ "github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -306,7 +307,7 @@ func testLoadItCheckAttributes(t *testing.T) {
},
Weight: 20.0,
}
- if attr, err := db.GetAttributeProfileDrv("cgrates.org", "ATTR_1001_SIMPLEAUTH"); err != nil {
+ if attr, err := db.GetAttributeProfileDrv(context.Background(), "cgrates.org", "ATTR_1001_SIMPLEAUTH"); err != nil {
t.Fatal(err)
} else if attr.Compile(); !reflect.DeepEqual(eAttrPrf, attr) {
t.Errorf("Expecting: %+v, received: %+v", utils.ToJSON(eAttrPrf), utils.ToJSON(attr))
@@ -328,7 +329,7 @@ func testLoadItStartLoaderRemove(t *testing.T) {
}
func testLoadItCheckAttributes2(t *testing.T) {
- if _, err := db.GetAttributeProfileDrv("cgrates.org", "ATTR_1001_SESSIONAUTH"); err != utils.ErrNotFound {
+ if _, err := db.GetAttributeProfileDrv(context.Background(), "cgrates.org", "ATTR_1001_SESSIONAUTH"); err != utils.ErrNotFound {
t.Fatal(err)
}
}
diff --git a/config/apiercfg.go b/config/adminscfg.go
similarity index 94%
rename from config/apiercfg.go
rename to config/adminscfg.go
index 8ade7ee90..b66fe43af 100644
--- a/config/apiercfg.go
+++ b/config/adminscfg.go
@@ -22,8 +22,8 @@ import (
"github.com/cgrates/cgrates/utils"
)
-// ApierCfg is the configuration of Apier service
-type ApierCfg struct {
+// AdminSCfg is the configuration of Apier service
+type AdminSCfg struct {
Enabled bool
CachesConns []string // connections towards Cache
ActionSConns []string // connections towards Scheduler
@@ -31,7 +31,7 @@ type ApierCfg struct {
EEsConns []string // connections towards EEs
}
-func (aCfg *ApierCfg) loadFromJSONCfg(jsnCfg *ApierJsonCfg) (err error) {
+func (aCfg *AdminSCfg) loadFromJSONCfg(jsnCfg *AdminSJsonCfg) (err error) {
if jsnCfg == nil {
return
}
@@ -82,7 +82,7 @@ func (aCfg *ApierCfg) loadFromJSONCfg(jsnCfg *ApierJsonCfg) (err error) {
}
// AsMapInterface returns the config as a map[string]interface{}
-func (aCfg *ApierCfg) AsMapInterface() (initialMap map[string]interface{}) {
+func (aCfg *AdminSCfg) AsMapInterface() (initialMap map[string]interface{}) {
initialMap = map[string]interface{}{
utils.EnabledCfg: aCfg.Enabled,
}
@@ -130,8 +130,8 @@ func (aCfg *ApierCfg) AsMapInterface() (initialMap map[string]interface{}) {
}
// Clone returns a deep copy of ApierCfg
-func (aCfg ApierCfg) Clone() (cln *ApierCfg) {
- cln = &ApierCfg{
+func (aCfg AdminSCfg) Clone() (cln *AdminSCfg) {
+ cln = &AdminSCfg{
Enabled: aCfg.Enabled,
}
if aCfg.CachesConns != nil {
diff --git a/config/apiercfg_test.go b/config/apiercfg_test.go
index b452ac6b1..df6eae257 100644
--- a/config/apiercfg_test.go
+++ b/config/apiercfg_test.go
@@ -25,14 +25,14 @@ import (
)
func TestApierCfgloadFromJsonCfg(t *testing.T) {
- jsonCfg := &ApierJsonCfg{
+ jsonCfg := &AdminSJsonCfg{
Enabled: utils.BoolPointer(false),
Caches_conns: &[]string{utils.MetaInternal, "*conn1"},
Actions_conns: &[]string{utils.MetaInternal, "*conn1"},
Attributes_conns: &[]string{utils.MetaInternal, "*conn1"},
Ees_conns: &[]string{utils.MetaInternal, "*conn1"},
}
- expected := &ApierCfg{
+ expected := &AdminSCfg{
Enabled: false,
CachesConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches), "*conn1"},
ActionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
@@ -40,16 +40,16 @@ func TestApierCfgloadFromJsonCfg(t *testing.T) {
EEsConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaEEs), "*conn1"},
}
jsnCfg := NewDefaultCGRConfig()
- if err = jsnCfg.apier.loadFromJSONCfg(jsonCfg); err != nil {
+ if err = jsnCfg.admS.loadFromJSONCfg(jsonCfg); err != nil {
t.Error(err)
- } else if !reflect.DeepEqual(expected, jsnCfg.apier) {
- t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.apier))
+ } else if !reflect.DeepEqual(expected, jsnCfg.admS) {
+ t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(jsnCfg.admS))
}
}
func TestApierCfgAsMapInterface1(t *testing.T) {
cfgJSONStr := `{
- "apiers": {
+ "admins": {
"caches_conns":[],
},
}`
@@ -63,14 +63,14 @@ func TestApierCfgAsMapInterface1(t *testing.T) {
}
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSONStr); err != nil {
t.Error(err)
- } else if newMap := cgrCfg.apier.AsMapInterface(); !reflect.DeepEqual(newMap, eMap) {
+ } else if newMap := cgrCfg.admS.AsMapInterface(); !reflect.DeepEqual(newMap, eMap) {
t.Errorf("Expected %+v, received %+v", eMap, newMap)
}
}
func TestApierCfgAsMapInterface2(t *testing.T) {
myJSONStr := `{
- "apiers": {
+ "admins": {
"enabled": true,
"attributes_conns": ["*internal:*attributes", "*conn1"],
"ees_conns": ["*internal:*ees", "*conn1"],
@@ -87,13 +87,13 @@ func TestApierCfgAsMapInterface2(t *testing.T) {
}
if cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(myJSONStr); err != nil {
t.Error(err)
- } else if newMap := cgrCfg.apier.AsMapInterface(); !reflect.DeepEqual(expectedMap, newMap) {
+ } else if newMap := cgrCfg.admS.AsMapInterface(); !reflect.DeepEqual(expectedMap, newMap) {
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expectedMap), utils.ToJSON(newMap))
}
}
func TestApierCfgClone(t *testing.T) {
- sa := &ApierCfg{
+ sa := &AdminSCfg{
Enabled: false,
CachesConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches), "*conn1"},
ActionSConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaActions), "*conn1"},
diff --git a/config/config.go b/config/config.go
index 8477b699f..ee2aaa6f3 100644
--- a/config/config.go
+++ b/config/config.go
@@ -190,7 +190,7 @@ func newCGRConfig(config []byte) (cfg *CGRConfig, err error) {
cfg.migratorCgrCfg.OutStorDBOpts = make(map[string]interface{})
cfg.mailerCfg = new(MailerCfg)
cfg.loaderCfg = make(LoaderSCfgs, 0)
- cfg.apier = new(ApierCfg)
+ cfg.admS = new(AdminSCfg)
cfg.ersCfg = new(ERsCfg)
cfg.eesCfg = new(EEsCfg)
cfg.eesCfg.Cache = make(map[string]*CacheParamCfg)
@@ -325,7 +325,7 @@ type CGRConfig struct {
migratorCgrCfg *MigratorCgrCfg // MigratorCgr config
mailerCfg *MailerCfg // Mailer config
analyzerSCfg *AnalyzerSCfg // AnalyzerS config
- apier *ApierCfg // APIer config
+ admS *AdminSCfg // APIer config
ersCfg *ERsCfg // EventReader config
eesCfg *EEsCfg // EventExporter config
rateSCfg *RateSCfg // RateS config
@@ -760,11 +760,11 @@ func (cfg *CGRConfig) loadAPIBanCgrCfg(jsnCfg *CgrJsonCfg) (err error) {
// loadApierCfg loads the Apier section of the configuration
func (cfg *CGRConfig) loadApierCfg(jsnCfg *CgrJsonCfg) (err error) {
- var jsnApierCfg *ApierJsonCfg
+ var jsnApierCfg *AdminSJsonCfg
if jsnApierCfg, err = jsnCfg.ApierCfgJson(); err != nil {
return
}
- return cfg.apier.loadFromJSONCfg(jsnApierCfg)
+ return cfg.admS.loadFromJSONCfg(jsnApierCfg)
}
// loadCoreSCfg loads the CoreS section of the configuration
@@ -1069,11 +1069,11 @@ func (cfg *CGRConfig) AnalyzerSCfg() *AnalyzerSCfg {
return cfg.analyzerSCfg
}
-// ApierCfg reads the Apier configuration
-func (cfg *CGRConfig) ApierCfg() *ApierCfg {
- cfg.lks[ApierS].Lock()
- defer cfg.lks[ApierS].Unlock()
- return cfg.apier
+// AdminSCfg reads the Apier configuration
+func (cfg *CGRConfig) AdminSCfg() *AdminSCfg {
+ cfg.lks[AdminS].Lock()
+ defer cfg.lks[AdminS].Unlock()
+ return cfg.admS
}
// ERsCfg reads the EventReader configuration
@@ -1260,7 +1260,7 @@ func (cfg *CGRConfig) getLoadFunctions() map[string]func(*CgrJsonCfg) error {
DispatcherSJson: cfg.loadDispatcherSCfg,
RegistrarCJson: cfg.loadRegistrarCCfg,
AnalyzerCfgJson: cfg.loadAnalyzerCgrCfg,
- ApierS: cfg.loadApierCfg,
+ AdminS: cfg.loadApierCfg,
RPCConnsJsonName: cfg.loadRPCConns,
RateSJson: cfg.loadRateSCfg,
SIPAgentJson: cfg.loadSIPAgentCfg,
@@ -1427,9 +1427,9 @@ func (cfg *CGRConfig) reloadSections(sections ...string) {
subsystemsThatNeedDataDB := utils.NewStringSet([]string{DATADB_JSN,
CDRS_JSN, SessionSJson, ATTRIBUTE_JSN,
ChargerSCfgJson, RESOURCES_JSON, STATS_JSON, THRESHOLDS_JSON,
- RouteSJson, LoaderJson, DispatcherSJson, RateSJson, ApierS, AccountSCfgJson,
+ RouteSJson, LoaderJson, DispatcherSJson, RateSJson, AdminS, AccountSCfgJson,
ActionSJson})
- subsystemsThatNeedStorDB := utils.NewStringSet([]string{STORDB_JSN, CDRS_JSN, ApierS})
+ subsystemsThatNeedStorDB := utils.NewStringSet([]string{STORDB_JSN, CDRS_JSN, AdminS})
needsDataDB := false
needsStorDB := false
for _, section := range sections {
@@ -1505,8 +1505,8 @@ func (cfg *CGRConfig) reloadSections(sections ...string) {
cfg.rldChans[DispatcherSJson] <- struct{}{}
case AnalyzerCfgJson:
cfg.rldChans[AnalyzerCfgJson] <- struct{}{}
- case ApierS:
- cfg.rldChans[ApierS] <- struct{}{}
+ case AdminS:
+ cfg.rldChans[AdminS] <- struct{}{}
case EEsJson:
cfg.rldChans[EEsJson] <- struct{}{}
case SIPAgentJson:
@@ -1558,7 +1558,7 @@ func (cfg *CGRConfig) AsMapInterface(separator string) (mp map[string]interface{
CgrMigratorCfgJson: cfg.migratorCgrCfg.AsMapInterface(),
MAILER_JSN: cfg.mailerCfg.AsMapInterface(),
AnalyzerCfgJson: cfg.analyzerSCfg.AsMapInterface(),
- ApierS: cfg.apier.AsMapInterface(),
+ AdminS: cfg.admS.AsMapInterface(),
ERsJson: cfg.ersCfg.AsMapInterface(separator),
APIBanCfgJson: cfg.apiBanCfg.AsMapInterface(),
EEsJson: cfg.eesCfg.AsMapInterface(separator),
@@ -1701,8 +1701,8 @@ func (cfg *CGRConfig) V1GetConfig(args *SectionWithAPIOpts, reply *map[string]in
mp = cfg.LoaderCgrCfg().AsMapInterface()
case CgrMigratorCfgJson:
mp = cfg.MigratorCgrCfg().AsMapInterface()
- case ApierS:
- mp = cfg.ApierCfg().AsMapInterface()
+ case AdminS:
+ mp = cfg.AdminSCfg().AsMapInterface()
case EEsJson:
mp = cfg.EEsCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
case ERsJson:
@@ -1870,8 +1870,8 @@ func (cfg *CGRConfig) V1GetConfigAsJSON(args *SectionWithAPIOpts, reply *string)
mp = cfg.LoaderCgrCfg().AsMapInterface()
case CgrMigratorCfgJson:
mp = cfg.MigratorCgrCfg().AsMapInterface()
- case ApierS:
- mp = cfg.ApierCfg().AsMapInterface()
+ case AdminS:
+ mp = cfg.AdminSCfg().AsMapInterface()
case EEsJson:
mp = cfg.EEsCfg().AsMapInterface(cfg.GeneralCfg().RSRSep)
case ERsJson:
@@ -1985,7 +1985,7 @@ func (cfg *CGRConfig) Clone() (cln *CGRConfig) {
migratorCgrCfg: cfg.migratorCgrCfg.Clone(),
mailerCfg: cfg.mailerCfg.Clone(),
analyzerSCfg: cfg.analyzerSCfg.Clone(),
- apier: cfg.apier.Clone(),
+ admS: cfg.admS.Clone(),
ersCfg: cfg.ersCfg.Clone(),
eesCfg: cfg.eesCfg.Clone(),
rateSCfg: cfg.rateSCfg.Clone(),
diff --git a/config/config_defaults.go b/config/config_defaults.go
index 5460c7c46..1cdb7d2ad 100644
--- a/config/config_defaults.go
+++ b/config/config_defaults.go
@@ -926,7 +926,7 @@ const CGRATES_CFG_JSON = `
},
-"apiers": {
+"admins": {
"enabled": false,
"caches_conns":["*internal"],
"actions_conns": [], // connections to ActionS for reloads
diff --git a/config/config_json.go b/config/config_json.go
index 99ed4b117..c43d0c977 100644
--- a/config/config_json.go
+++ b/config/config_json.go
@@ -55,7 +55,7 @@ const (
ChargerSCfgJson = "chargers"
TlsCfgJson = "tls"
AnalyzerCfgJson = "analyzers"
- ApierS = "apiers"
+ AdminS = "admins"
DNSAgentJson = "dns_agent"
ERsJson = "ers"
EEsJson = "ees"
@@ -75,7 +75,7 @@ var (
CACHE_JSN, FilterSjsn, CDRS_JSN, ERsJson, SessionSJson, AsteriskAgentJSN, FreeSWITCHAgentJSN,
KamailioAgentJSN, DA_JSN, RA_JSN, HttpAgentJson, DNSAgentJson, ATTRIBUTE_JSN, ChargerSCfgJson, RESOURCES_JSON, STATS_JSON,
THRESHOLDS_JSON, RouteSJson, LoaderJson, MAILER_JSN, SURETAX_JSON, CgrLoaderCfgJson, CgrMigratorCfgJson, DispatcherSJson,
- AnalyzerCfgJson, ApierS, EEsJson, RateSJson, SIPAgentJson, RegistrarCJson, TemplatesJson, ConfigSJson, APIBanCfgJson, CoreSCfgJson,
+ AnalyzerCfgJson, AdminS, EEsJson, RateSJson, SIPAgentJson, RegistrarCJson, TemplatesJson, ConfigSJson, APIBanCfgJson, CoreSCfgJson,
ActionSJson, AccountSCfgJson}
sortedSectionsSet = utils.NewStringSet(sortedCfgSections)
)
@@ -480,12 +480,12 @@ func (jsnCfg CgrJsonCfg) AnalyzerCfgJson() (*AnalyzerSJsonCfg, error) {
return cfg, nil
}
-func (jsnCfg CgrJsonCfg) ApierCfgJson() (*ApierJsonCfg, error) {
- rawCfg, hasKey := jsnCfg[ApierS]
+func (jsnCfg CgrJsonCfg) ApierCfgJson() (*AdminSJsonCfg, error) {
+ rawCfg, hasKey := jsnCfg[AdminS]
if !hasKey {
return nil, nil
}
- cfg := new(ApierJsonCfg)
+ cfg := new(AdminSJsonCfg)
if err := json.Unmarshal(*rawCfg, cfg); err != nil {
return nil, err
}
diff --git a/config/config_json_test.go b/config/config_json_test.go
index 854d0c593..5cb0dd467 100644
--- a/config/config_json_test.go
+++ b/config/config_json_test.go
@@ -1851,7 +1851,7 @@ func TestDfAnalyzerCfg(t *testing.T) {
}
func TestDfApierCfg(t *testing.T) {
- eCfg := &ApierJsonCfg{
+ eCfg := &AdminSJsonCfg{
Enabled: utils.BoolPointer(false),
Caches_conns: &[]string{utils.MetaInternal},
Actions_conns: &[]string{},
diff --git a/config/config_test.go b/config/config_test.go
index 59c0aa94d..45a4d8c32 100644
--- a/config/config_test.go
+++ b/config/config_test.go
@@ -1637,11 +1637,11 @@ func TestLoadAPIBanCgrCfgError(t *testing.T) {
func TestLoadApierCfgError(t *testing.T) {
myJSONStr := `{
- "apiers": {
+ "admins": {
"actions_conns": "*internal",
},
}`
- expected := "json: cannot unmarshal string into Go struct field ApierJsonCfg.Actions_conns of type []string"
+ expected := "json: cannot unmarshal string into Go struct field AdminSJsonCfg.Actions_conns of type []string"
cgrConfig := NewDefaultCGRConfig()
if err != nil {
t.Error(err)
@@ -2237,7 +2237,7 @@ func TestAnalyzerConfig(t *testing.T) {
}
func TestApierConfig(t *testing.T) {
- expected := &ApierCfg{
+ expected := &AdminSCfg{
Enabled: false,
CachesConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)},
ActionSConns: []string{},
@@ -2248,7 +2248,7 @@ func TestApierConfig(t *testing.T) {
if err != nil {
t.Error(err)
}
- newConfig := cgrConfig.ApierCfg()
+ newConfig := cgrConfig.AdminSCfg()
if !reflect.DeepEqual(expected, newConfig) {
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(newConfig))
}
@@ -3601,15 +3601,15 @@ func TestNewCGRConfigFromPathNotFound(t *testing.T) {
}
func TestCgrCfgJSONDefaultApierCfg(t *testing.T) {
- aCfg := &ApierCfg{
+ aCfg := &AdminSCfg{
Enabled: false,
CachesConns: []string{utils.ConcatenatedKey(utils.MetaInternal, utils.MetaCaches)},
ActionSConns: []string{},
AttributeSConns: []string{},
EEsConns: []string{},
}
- if !reflect.DeepEqual(cgrCfg.apier, aCfg) {
- t.Errorf("received: %+v, expecting: %+v", cgrCfg.apier, aCfg)
+ if !reflect.DeepEqual(cgrCfg.admS, aCfg) {
+ t.Errorf("received: %+v, expecting: %+v", cgrCfg.admS, aCfg)
}
}
@@ -4504,7 +4504,7 @@ func TestV1GetConfigSectionMigrator(t *testing.T) {
func TestV1GetConfigSectionApierS(t *testing.T) {
var reply map[string]interface{}
expected := map[string]interface{}{
- ApierS: map[string]interface{}{
+ AdminS: map[string]interface{}{
utils.EnabledCfg: false,
utils.CachesConnsCfg: []string{utils.MetaInternal},
utils.ActionSConnsCfg: []string{},
@@ -4513,7 +4513,7 @@ func TestV1GetConfigSectionApierS(t *testing.T) {
},
}
cfgCgr := NewDefaultCGRConfig()
- if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: ApierS}, &reply); err != nil {
+ if err := cfgCgr.V1GetConfig(&SectionWithAPIOpts{Section: AdminS}, &reply); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(reply, expected) {
t.Errorf("Expected %+v \n, received %+v", utils.ToJSON(expected), utils.ToJSON(reply))
@@ -5219,9 +5219,9 @@ func TestV1GetConfigAsJSONCgrMigrator(t *testing.T) {
func TestV1GetConfigAsJSONApierS(t *testing.T) {
var reply string
- expected := `{"apiers":{"actions_conns":[],"attributes_conns":[],"caches_conns":["*internal"],"ees_conns":[],"enabled":false}}`
+ expected := `{"admins":{"actions_conns":[],"attributes_conns":[],"caches_conns":["*internal"],"ees_conns":[],"enabled":false}}`
cgrCfg := NewDefaultCGRConfig()
- if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: ApierS}, &reply); err != nil {
+ if err := cgrCfg.V1GetConfigAsJSON(&SectionWithAPIOpts{Section: AdminS}, &reply); err != nil {
t.Error(err)
} else if expected != reply {
t.Errorf("Expected %+v \n, received %+v", expected, reply)
@@ -5420,7 +5420,7 @@ func TestV1GetConfigAsJSONAllConfig(t *testing.T) {
}
}`
var reply string
- expected := `{"accounts":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"max_iterations":1000,"max_usage":259200000000000,"nested_fields":false,"prefix_indexed_fields":[],"rates_conns":[],"suffix_indexed_fields":[],"thresholds_conns":[]},"actions":{"accounts_conns":[],"cdrs_conns":[],"ees_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"stats_conns":[],"suffix_indexed_fields":[],"tenants":[],"thresholds_conns":[]},"analyzers":{"cleanup_interval":"1h0m0s","db_path":"/var/spool/cgrates/analyzers","enabled":false,"index_type":"*scorch","ttl":"24h0m0s"},"apiban":{"enabled":false,"keys":[]},"apiers":{"actions_conns":[],"attributes_conns":[],"caches_conns":["*internal"],"ees_conns":[],"enabled":false},"asterisk_agent":{"asterisk_conns":[{"address":"127.0.0.1:8088","alias":"","connect_attempts":3,"password":"CGRateS.org","reconnects":5,"user":"cgrates"}],"create_cdr":false,"enabled":false,"sessions_conns":["*birpc_internal"]},"attributes":{"apiers_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"process_runs":1,"resources_conns":[],"stats_conns":[],"suffix_indexed_fields":[]},"caches":{"partitions":{"*account_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*accounts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*action_profile_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*action_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*apiban":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"2m0s"},"*attribute_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*attribute_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*caps_events":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*cdr_ids":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"10m0s"},"*cdrs":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*charger_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*charger_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*closed_sessions":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"10s"},"*destinations":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*diameter_messages":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*dispatcher_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_hosts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_loads":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_routes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatchers":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*event_charges":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"10s"},"*event_resources":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*filters":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*load_ids":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rate_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rate_profile_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rate_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*replication_hosts":{"limit":0,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*resource_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*resource_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*resources":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*reverse_destinations":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*reverse_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*route_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*route_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rpc_connections":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rpc_responses":{"limit":0,"precache":false,"replicate":false,"static_ttl":false,"ttl":"2s"},"*session_costs":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*stat_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*statqueue_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*statqueues":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*stir":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*threshold_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*threshold_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*thresholds":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*timings":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_accounts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_action_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_attributes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_chargers":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_destinations":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_dispatcher_hosts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_dispatcher_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_filters":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_rate_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_resources":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_routes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_stats":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_thresholds":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_timings":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*uch":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*versions":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""}},"replication_conns":[]},"cdrs":{"actions_conns":[],"attributes_conns":[],"chargers_conns":[],"ees_conns":[],"enabled":false,"extra_fields":[],"online_cdr_exports":[],"session_cost_retries":5,"stats_conns":[],"store_cdrs":true,"thresholds_conns":[]},"chargers":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"suffix_indexed_fields":[]},"configs":{"enabled":false,"root_dir":"/var/spool/cgrates/configs","url":"/configs/"},"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*busy","shutdown_timeout":"1s"},"data_db":{"db_host":"127.0.0.1","db_name":"10","db_password":"","db_port":6379,"db_type":"*redis","db_user":"cgrates","items":{"*accounts":{"remote":false,"replicate":false},"*action_profiles":{"remote":false,"replicate":false},"*actions":{"remote":false,"replicate":false},"*attribute_profiles":{"remote":false,"replicate":false},"*charger_profiles":{"remote":false,"replicate":false},"*destinations":{"remote":false,"replicate":false},"*dispatcher_hosts":{"remote":false,"replicate":false},"*dispatcher_profiles":{"remote":false,"replicate":false},"*filters":{"remote":false,"replicate":false},"*indexes":{"remote":false,"replicate":false},"*load_ids":{"remote":false,"replicate":false},"*rate_profiles":{"remote":false,"replicate":false},"*resource_profiles":{"remote":false,"replicate":false},"*resources":{"remote":false,"replicate":false},"*reverse_destinations":{"remote":false,"replicate":false},"*route_profiles":{"remote":false,"replicate":false},"*statqueue_profiles":{"remote":false,"replicate":false},"*statqueues":{"remote":false,"replicate":false},"*threshold_profiles":{"remote":false,"replicate":false},"*thresholds":{"remote":false,"replicate":false},"*timings":{"remote":false,"replicate":false}},"opts":{"query_timeout":"10s","redis_ca_certificate":"","redis_client_certificate":"","redis_client_key":"","redis_cluster":false,"redis_cluster_ondown_delay":"0","redis_cluster_sync":"5s","redis_sentinel":"","redis_tls":false},"remote_conn_id":"","remote_conns":[],"replication_cache":"","replication_conns":[],"replication_filtered":false},"diameter_agent":{"asr_template":"","concurrent_requests":-1,"dictionaries_path":"/usr/share/cgrates/diameter/dict/","enabled":false,"forced_disconnect":"*none","listen":"127.0.0.1:3868","listen_net":"tcp","origin_host":"CGR-DA","origin_realm":"cgrates.org","product_name":"CGRateS","rar_template":"","request_processors":[],"sessions_conns":["*birpc_internal"],"synced_conn_requests":false,"vendor_id":0},"dispatchers":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"suffix_indexed_fields":[]},"dns_agent":{"enabled":false,"listen":"127.0.0.1:2053","listen_net":"udp","request_processors":[],"sessions_conns":["*internal"],"timezone":""},"ees":{"attributes_conns":[],"cache":{"*file_csv":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"5s"}},"enabled":false,"exporters":[{"attempts":1,"attribute_context":"","attribute_ids":[],"export_path":"/var/spool/cgrates/ees","field_separator":",","fields":[],"filters":[],"flags":[],"id":"*default","opts":{},"synchronous":false,"tenant":"","timezone":"","type":"*none"}]},"ers":{"enabled":false,"readers":[{"cache_dump_fields":[],"concurrent_requests":1024,"failed_calls_prefix":"","field_separator":",","fields":[{"mandatory":true,"path":"*cgreq.ToR","tag":"ToR","type":"*variable","value":"~*req.2"},{"mandatory":true,"path":"*cgreq.OriginID","tag":"OriginID","type":"*variable","value":"~*req.3"},{"mandatory":true,"path":"*cgreq.RequestType","tag":"RequestType","type":"*variable","value":"~*req.4"},{"mandatory":true,"path":"*cgreq.Tenant","tag":"Tenant","type":"*variable","value":"~*req.6"},{"mandatory":true,"path":"*cgreq.Category","tag":"Category","type":"*variable","value":"~*req.7"},{"mandatory":true,"path":"*cgreq.Account","tag":"Account","type":"*variable","value":"~*req.8"},{"mandatory":true,"path":"*cgreq.Subject","tag":"Subject","type":"*variable","value":"~*req.9"},{"mandatory":true,"path":"*cgreq.Destination","tag":"Destination","type":"*variable","value":"~*req.10"},{"mandatory":true,"path":"*cgreq.SetupTime","tag":"SetupTime","type":"*variable","value":"~*req.11"},{"mandatory":true,"path":"*cgreq.AnswerTime","tag":"AnswerTime","type":"*variable","value":"~*req.12"},{"mandatory":true,"path":"*cgreq.Usage","tag":"Usage","type":"*variable","value":"~*req.13"}],"filters":[],"flags":[],"header_define_character":":","id":"*default","opts":{},"partial_cache_expiry_action":"","partial_record_cache":"0","processed_path":"/var/spool/cgrates/ers/out","row_length":0,"run_delay":"0","source_path":"/var/spool/cgrates/ers/in","tenant":"","timezone":"","type":"*none","xml_root_path":[""]}],"sessions_conns":["*internal"]},"filters":{"apiers_conns":[],"resources_conns":[],"stats_conns":[]},"freeswitch_agent":{"create_cdr":false,"empty_balance_ann_file":"","empty_balance_context":"","enabled":false,"event_socket_conns":[{"address":"127.0.0.1:8021","alias":"127.0.0.1:8021","password":"ClueCon","reconnects":5}],"extra_fields":"","low_balance_ann_file":"","max_wait_connection":"2s","sessions_conns":["*birpc_internal"],"subscribe_park":true},"general":{"connect_attempts":5,"connect_timeout":"1s","dbdata_encoding":"*msgpack","default_caching":"*reload","default_category":"call","default_request_type":"*rated","default_tenant":"cgrates.org","default_timezone":"Local","digest_equal":":","digest_separator":",","failed_posts_dir":"/var/spool/cgrates/failed_posts","failed_posts_ttl":"5s","locking_timeout":"0","log_level":6,"logger":"*syslog","max_parallel_conns":100,"node_id":"ENGINE1","poster_attempts":3,"reconnects":-1,"reply_timeout":"2s","rounding_decimals":5,"rsr_separator":";","tpexport_dir":"/var/spool/cgrates/tpe"},"http":{"auth_users":{},"client_opts":{"dialFallbackDelay":"300ms","dialKeepAlive":"30s","dialTimeout":"30s","disableCompression":false,"disableKeepAlives":false,"expectContinueTimeout":"0","forceAttemptHttp2":true,"idleConnTimeout":"90s","maxConnsPerHost":0,"maxIdleConns":100,"maxIdleConnsPerHost":2,"responseHeaderTimeout":"0","skipTlsVerify":false,"tlsHandshakeTimeout":"10s"},"freeswitch_cdrs_url":"/freeswitch_json","http_cdrs":"/cdr_http","json_rpc_url":"/jsonrpc","registrars_url":"/registrar","use_basic_auth":false,"ws_url":"/ws"},"http_agent":[],"kamailio_agent":{"create_cdr":false,"enabled":false,"evapi_conns":[{"address":"127.0.0.1:8448","alias":"","reconnects":5}],"sessions_conns":["*birpc_internal"],"timezone":""},"listen":{"http":"127.0.0.1:2080","http_tls":"127.0.0.1:2280","rpc_gob":"127.0.0.1:2013","rpc_gob_tls":"127.0.0.1:2023","rpc_json":"127.0.0.1:2012","rpc_json_tls":"127.0.0.1:2022"},"loader":{"actions_conns":["*localhost"],"caches_conns":["*localhost"],"data_path":"./","disable_reverse":false,"field_separator":",","gapi_credentials":".gapi/credentials.json","gapi_token":".gapi/token.json","tpid":""},"loaders":[{"caches_conns":["*internal"],"data":[{"fields":[{"mandatory":true,"path":"Tenant","tag":"TenantID","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ProfileID","type":"*variable","value":"~*req.1"},{"path":"Contexts","tag":"Contexts","type":"*variable","value":"~*req.2"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.3"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.4"},{"path":"AttributeFilterIDs","tag":"AttributeFilterIDs","type":"*variable","value":"~*req.5"},{"path":"Path","tag":"Path","type":"*variable","value":"~*req.6"},{"path":"Type","tag":"Type","type":"*variable","value":"~*req.7"},{"path":"Value","tag":"Value","type":"*variable","value":"~*req.8"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.9"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.10"}],"file_name":"Attributes.csv","flags":null,"type":"*attributes"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Type","tag":"Type","type":"*variable","value":"~*req.2"},{"path":"Element","tag":"Element","type":"*variable","value":"~*req.3"},{"path":"Values","tag":"Values","type":"*variable","value":"~*req.4"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.5"}],"file_name":"Filters.csv","flags":null,"type":"*filters"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"UsageTTL","tag":"TTL","type":"*variable","value":"~*req.4"},{"path":"Limit","tag":"Limit","type":"*variable","value":"~*req.5"},{"path":"AllocationMessage","tag":"AllocationMessage","type":"*variable","value":"~*req.6"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.7"},{"path":"Stored","tag":"Stored","type":"*variable","value":"~*req.8"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.9"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.10"}],"file_name":"Resources.csv","flags":null,"type":"*resources"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"QueueLength","tag":"QueueLength","type":"*variable","value":"~*req.4"},{"path":"TTL","tag":"TTL","type":"*variable","value":"~*req.5"},{"path":"MinItems","tag":"MinItems","type":"*variable","value":"~*req.6"},{"path":"MetricIDs","tag":"MetricIDs","type":"*variable","value":"~*req.7"},{"path":"MetricFilterIDs","tag":"MetricFilterIDs","type":"*variable","value":"~*req.8"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.9"},{"path":"Stored","tag":"Stored","type":"*variable","value":"~*req.10"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.11"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.12"}],"file_name":"Stats.csv","flags":null,"type":"*stats"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"MaxHits","tag":"MaxHits","type":"*variable","value":"~*req.4"},{"path":"MinHits","tag":"MinHits","type":"*variable","value":"~*req.5"},{"path":"MinSleep","tag":"MinSleep","type":"*variable","value":"~*req.6"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.7"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.8"},{"path":"ActionIDs","tag":"ActionIDs","type":"*variable","value":"~*req.9"},{"path":"Async","tag":"Async","type":"*variable","value":"~*req.10"}],"file_name":"Thresholds.csv","flags":null,"type":"*thresholds"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Sorting","tag":"Sorting","type":"*variable","value":"~*req.4"},{"path":"SortingParameters","tag":"SortingParameters","type":"*variable","value":"~*req.5"},{"path":"RouteID","tag":"RouteID","type":"*variable","value":"~*req.6"},{"path":"RouteFilterIDs","tag":"RouteFilterIDs","type":"*variable","value":"~*req.7"},{"path":"RouteAccountIDs","tag":"RouteAccountIDs","type":"*variable","value":"~*req.8"},{"path":"RouteRatingPlanIDs","tag":"RouteRatingPlanIDs","type":"*variable","value":"~*req.9"},{"path":"RouteResourceIDs","tag":"RouteResourceIDs","type":"*variable","value":"~*req.10"},{"path":"RouteStatIDs","tag":"RouteStatIDs","type":"*variable","value":"~*req.11"},{"path":"RouteWeight","tag":"RouteWeight","type":"*variable","value":"~*req.12"},{"path":"RouteBlocker","tag":"RouteBlocker","type":"*variable","value":"~*req.13"},{"path":"RouteParameters","tag":"RouteParameters","type":"*variable","value":"~*req.14"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.15"}],"file_name":"Routes.csv","flags":null,"type":"*routes"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"RunID","tag":"RunID","type":"*variable","value":"~*req.4"},{"path":"AttributeIDs","tag":"AttributeIDs","type":"*variable","value":"~*req.5"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.6"}],"file_name":"Chargers.csv","flags":null,"type":"*chargers"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Contexts","tag":"Contexts","type":"*variable","value":"~*req.2"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.3"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.4"},{"path":"Strategy","tag":"Strategy","type":"*variable","value":"~*req.5"},{"path":"StrategyParameters","tag":"StrategyParameters","type":"*variable","value":"~*req.6"},{"path":"ConnID","tag":"ConnID","type":"*variable","value":"~*req.7"},{"path":"ConnFilterIDs","tag":"ConnFilterIDs","type":"*variable","value":"~*req.8"},{"path":"ConnWeight","tag":"ConnWeight","type":"*variable","value":"~*req.9"},{"path":"ConnBlocker","tag":"ConnBlocker","type":"*variable","value":"~*req.10"},{"path":"ConnParameters","tag":"ConnParameters","type":"*variable","value":"~*req.11"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.12"}],"file_name":"DispatcherProfiles.csv","flags":null,"type":"*dispatchers"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Address","tag":"Address","type":"*variable","value":"~*req.2"},{"path":"Transport","tag":"Transport","type":"*variable","value":"~*req.3"},{"path":"TLS","tag":"TLS","type":"*variable","value":"~*req.4"}],"file_name":"DispatcherHosts.csv","flags":null,"type":"*dispatcher_hosts"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.4"},{"path":"MinCost","tag":"MinCost","type":"*variable","value":"~*req.5"},{"path":"MaxCost","tag":"MaxCost","type":"*variable","value":"~*req.6"},{"path":"MaxCostStrategy","tag":"MaxCostStrategy","type":"*variable","value":"~*req.7"},{"path":"RateID","tag":"RateID","type":"*variable","value":"~*req.8"},{"path":"RateFilterIDs","tag":"RateFilterIDs","type":"*variable","value":"~*req.9"},{"path":"RateActivationTimes","tag":"RateActivationTimes","type":"*variable","value":"~*req.10"},{"path":"RateWeight","tag":"RateWeight","type":"*variable","value":"~*req.11"},{"path":"RateBlocker","tag":"RateBlocker","type":"*variable","value":"~*req.12"},{"path":"RateIntervalStart","tag":"RateIntervalStart","type":"*variable","value":"~*req.13"},{"path":"RateFixedFee","tag":"RateFixedFee","type":"*variable","value":"~*req.14"},{"path":"RateRecurrentFee","tag":"RateRecurrentFee","type":"*variable","value":"~*req.15"},{"path":"RateUnit","tag":"RateUnit","type":"*variable","value":"~*req.16"},{"path":"RateIncrement","tag":"RateIncrement","type":"*variable","value":"~*req.17"}],"file_name":"RateProfiles.csv","flags":null,"type":"*rate_profiles"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.4"},{"path":"Schedule","tag":"Schedule","type":"*variable","value":"~*req.5"},{"path":"TargetType","tag":"TargetType","type":"*variable","value":"~*req.6"},{"path":"TargetIDs","tag":"TargetIDs","type":"*variable","value":"~*req.7"},{"path":"ActionID","tag":"ActionID","type":"*variable","value":"~*req.8"},{"path":"ActionFilterIDs","tag":"ActionFilterIDs","type":"*variable","value":"~*req.9"},{"path":"ActionBlocker","tag":"ActionBlocker","type":"*variable","value":"~*req.10"},{"path":"ActionTTL","tag":"ActionTTL","type":"*variable","value":"~*req.11"},{"path":"ActionType","tag":"ActionType","type":"*variable","value":"~*req.12"},{"path":"ActionOpts","tag":"ActionOpts","type":"*variable","value":"~*req.13"},{"path":"ActionPath","tag":"ActionPath","type":"*variable","value":"~*req.14"},{"path":"ActionValue","tag":"ActionValue","type":"*variable","value":"~*req.15"}],"file_name":"ActionProfiles.csv","flags":null,"type":"*action_profiles"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.4"},{"path":"BalanceID","tag":"BalanceID","type":"*variable","value":"~*req.5"},{"path":"BalanceFilterIDs","tag":"BalanceFilterIDs","type":"*variable","value":"~*req.6"},{"path":"BalanceWeight","tag":"BalanceWeight","type":"*variable","value":"~*req.7"},{"path":"BalanceBlocker","tag":"BalanceBlocker","type":"*variable","value":"~*req.8"},{"path":"BalanceType","tag":"BalanceType","type":"*variable","value":"~*req.9"},{"path":"BalanceOpts","tag":"BalanceOpts","type":"*variable","value":"~*req.10"},{"path":"BalanceCostIncrements","tag":"BalanceCostIncrements","type":"*variable","value":"~*req.11"},{"path":"BalanceAttributeIDs","tag":"BalanceAttributeIDs","type":"*variable","value":"~*req.12"},{"path":"BalanceRateProfileIDs","tag":"BalanceRateProfileIDs","type":"*variable","value":"~*req.13"},{"path":"BalanceUnitFactors","tag":"BalanceUnitFactors","type":"*variable","value":"~*req.14"},{"path":"BalanceUnits","tag":"BalanceUnits","type":"*variable","value":"~*req.15"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.16"}],"file_name":"Accounts.csv","flags":null,"type":"*accounts"}],"dry_run":false,"enabled":false,"field_separator":",","id":"*default","lock_filename":".cgr.lck","run_delay":"0","tenant":"","tp_in_dir":"/var/spool/cgrates/loader/in","tp_out_dir":"/var/spool/cgrates/loader/out"}],"mailer":{"auth_password":"CGRateS.org","auth_user":"cgrates","from_address":"cgr-mailer@localhost.localdomain","server":"localhost"},"migrator":{"out_datadb_encoding":"msgpack","out_datadb_host":"127.0.0.1","out_datadb_name":"10","out_datadb_opts":{"redis_ca_certificate":"","redis_client_certificate":"","redis_client_key":"","redis_cluster":false,"redis_cluster_ondown_delay":"0","redis_cluster_sync":"5s","redis_sentinel":"","redis_tls":false},"out_datadb_password":"","out_datadb_port":"6379","out_datadb_type":"redis","out_datadb_user":"cgrates","out_stordb_host":"127.0.0.1","out_stordb_name":"cgrates","out_stordb_opts":{},"out_stordb_password":"","out_stordb_port":"3306","out_stordb_type":"mysql","out_stordb_user":"cgrates","users_filters":[]},"radius_agent":{"client_dictionaries":{"*default":"/usr/share/cgrates/radius/dict/"},"client_secrets":{"*default":"CGRateS.org"},"enabled":false,"listen_acct":"127.0.0.1:1813","listen_auth":"127.0.0.1:1812","listen_net":"udp","request_processors":[],"sessions_conns":["*internal"]},"rates":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"rate_indexed_selects":true,"rate_nested_fields":false,"rate_prefix_indexed_fields":[],"rate_suffix_indexed_fields":[],"suffix_indexed_fields":[],"verbosity":1000},"registrarc":{"dispatcher":{"enabled":false,"hosts":{},"refresh_interval":"5m0s","registrars_conns":[]},"rpc":{"enabled":false,"hosts":{},"refresh_interval":"5m0s","registrars_conns":[]}},"resources":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"store_interval":"","suffix_indexed_fields":[],"thresholds_conns":[]},"routes":{"attributes_conns":[],"default_ratio":1,"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"resources_conns":[],"stats_conns":[],"suffix_indexed_fields":[]},"rpc_conns":{"*bijson_localhost":{"conns":[{"address":"127.0.0.1:2014","transport":"*birpc_json"}],"poolSize":0,"strategy":"*first"},"*birpc_internal":{"conns":[{"address":"*birpc_internal","transport":""}],"poolSize":0,"strategy":"*first"},"*internal":{"conns":[{"address":"*internal","transport":""}],"poolSize":0,"strategy":"*first"},"*localhost":{"conns":[{"address":"127.0.0.1:2012","transport":"*json"}],"poolSize":0,"strategy":"*first"}},"sessions":{"actions_conns":[],"alterable_fields":[],"attributes_conns":[],"cdrs_conns":[],"channel_sync_interval":"0","chargers_conns":[],"client_protocol":1,"debit_interval":"0","default_usage":{"*any":"3h0m0s","*data":"1048576","*sms":"1","*voice":"3h0m0s"},"enabled":false,"listen_bigob":"","listen_bijson":"127.0.0.1:2014","min_dur_low_balance":"0","replication_conns":[],"resources_conns":[],"routes_conns":[],"session_indexes":[],"session_ttl":"0","stats_conns":[],"stir":{"allowed_attest":["*any"],"default_attest":"A","payload_maxduration":"-1","privatekey_path":"","publickey_path":""},"store_session_costs":false,"terminate_attempts":5,"thresholds_conns":[]},"sip_agent":{"enabled":false,"listen":"127.0.0.1:5060","listen_net":"udp","request_processors":[],"retransmission_timer":1000000000,"sessions_conns":["*internal"],"timezone":""},"stats":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"store_interval":"","store_uncompressed_limit":0,"suffix_indexed_fields":[],"thresholds_conns":[]},"stor_db":{"db_host":"127.0.0.1","db_name":"cgrates","db_password":"","db_port":3306,"db_type":"*mysql","db_user":"cgrates","items":{"*cdrs":{"remote":false,"replicate":false},"*session_costs":{"remote":false,"replicate":false},"*tp_accounts":{"remote":false,"replicate":false},"*tp_action_profiles":{"remote":false,"replicate":false},"*tp_attributes":{"remote":false,"replicate":false},"*tp_chargers":{"remote":false,"replicate":false},"*tp_destinations":{"remote":false,"replicate":false},"*tp_dispatcher_hosts":{"remote":false,"replicate":false},"*tp_dispatcher_profiles":{"remote":false,"replicate":false},"*tp_filters":{"remote":false,"replicate":false},"*tp_rate_profiles":{"remote":false,"replicate":false},"*tp_resources":{"remote":false,"replicate":false},"*tp_routes":{"remote":false,"replicate":false},"*tp_stats":{"remote":false,"replicate":false},"*tp_thresholds":{"remote":false,"replicate":false},"*tp_timings":{"remote":false,"replicate":false},"*versions":{"remote":false,"replicate":false}},"opts":{"conn_max_lifetime":0,"max_idle_conns":10,"max_open_conns":100,"mysql_location":"Local","query_timeout":"10s","sslmode":"disable"},"prefix_indexed_fields":[],"remote_conns":null,"replication_conns":null,"string_indexed_fields":[]},"suretax":{"bill_to_number":"","business_unit":"","client_number":"","client_tracking":"~*req.CGRID","customer_number":"~*req.Subject","include_local_cost":false,"orig_number":"~*req.Subject","p2pplus4":"","p2pzipcode":"","plus4":"","regulatory_code":"03","response_group":"03","response_type":"D4","return_file_code":"0","sales_type_code":"R","tax_exemption_code_list":"","tax_included":"0","tax_situs_rule":"04","term_number":"~*req.Destination","timezone":"UTC","trans_type_code":"010101","unit_type":"00","units":"1","url":"","validation_key":"","zipcode":""},"templates":{"*asr":[{"mandatory":true,"path":"*diamreq.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*diamreq.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*req.Destination-Host"},{"mandatory":true,"path":"*diamreq.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*req.Destination-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Realm","tag":"DestinationRealm","type":"*variable","value":"~*req.Origin-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Host","tag":"DestinationHost","type":"*variable","value":"~*req.Origin-Host"},{"mandatory":true,"path":"*diamreq.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"}],"*cca":[{"mandatory":true,"path":"*rep.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"path":"*rep.Result-Code","tag":"ResultCode","type":"*constant","value":"2001"},{"mandatory":true,"path":"*rep.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*vars.OriginHost"},{"mandatory":true,"path":"*rep.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*vars.OriginRealm"},{"mandatory":true,"path":"*rep.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"},{"mandatory":true,"path":"*rep.CC-Request-Type","tag":"CCRequestType","type":"*variable","value":"~*req.CC-Request-Type"},{"mandatory":true,"path":"*rep.CC-Request-Number","tag":"CCRequestNumber","type":"*variable","value":"~*req.CC-Request-Number"}],"*cdrLog":[{"mandatory":true,"path":"*cdr.ToR","tag":"ToR","type":"*variable","value":"~*req.BalanceType"},{"mandatory":true,"path":"*cdr.OriginHost","tag":"OriginHost","type":"*constant","value":"127.0.0.1"},{"mandatory":true,"path":"*cdr.RequestType","tag":"RequestType","type":"*constant","value":"*none"},{"mandatory":true,"path":"*cdr.Tenant","tag":"Tenant","type":"*variable","value":"~*req.Tenant"},{"mandatory":true,"path":"*cdr.Account","tag":"Account","type":"*variable","value":"~*req.Account"},{"mandatory":true,"path":"*cdr.Subject","tag":"Subject","type":"*variable","value":"~*req.Account"},{"mandatory":true,"path":"*cdr.Cost","tag":"Cost","type":"*variable","value":"~*req.Cost"},{"mandatory":true,"path":"*cdr.Source","tag":"Source","type":"*constant","value":"*cdrLog"},{"mandatory":true,"path":"*cdr.Usage","tag":"Usage","type":"*constant","value":"1"},{"mandatory":true,"path":"*cdr.RunID","tag":"RunID","type":"*variable","value":"~*req.ActionType"},{"mandatory":true,"path":"*cdr.SetupTime","tag":"SetupTime","type":"*constant","value":"*now"},{"mandatory":true,"path":"*cdr.AnswerTime","tag":"AnswerTime","type":"*constant","value":"*now"},{"mandatory":true,"path":"*cdr.PreRated","tag":"PreRated","type":"*constant","value":"true"}],"*err":[{"mandatory":true,"path":"*rep.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*rep.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*vars.OriginHost"},{"mandatory":true,"path":"*rep.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*vars.OriginRealm"}],"*errSip":[{"mandatory":true,"path":"*rep.Request","tag":"Request","type":"*constant","value":"SIP/2.0 500 Internal Server Error"}],"*rar":[{"mandatory":true,"path":"*diamreq.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*diamreq.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*req.Destination-Host"},{"mandatory":true,"path":"*diamreq.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*req.Destination-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Realm","tag":"DestinationRealm","type":"*variable","value":"~*req.Origin-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Host","tag":"DestinationHost","type":"*variable","value":"~*req.Origin-Host"},{"mandatory":true,"path":"*diamreq.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"},{"path":"*diamreq.Re-Auth-Request-Type","tag":"ReAuthRequestType","type":"*constant","value":"0"}]},"thresholds":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"store_interval":"","suffix_indexed_fields":[]},"tls":{"ca_certificate":"","client_certificate":"","client_key":"","server_certificate":"","server_key":"","server_name":"","server_policy":4}}`
+ expected := `{"accounts":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"max_iterations":1000,"max_usage":259200000000000,"nested_fields":false,"prefix_indexed_fields":[],"rates_conns":[],"suffix_indexed_fields":[],"thresholds_conns":[]},"actions":{"accounts_conns":[],"cdrs_conns":[],"ees_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"stats_conns":[],"suffix_indexed_fields":[],"tenants":[],"thresholds_conns":[]},"admins":{"actions_conns":[],"attributes_conns":[],"caches_conns":["*internal"],"ees_conns":[],"enabled":false},"analyzers":{"cleanup_interval":"1h0m0s","db_path":"/var/spool/cgrates/analyzers","enabled":false,"index_type":"*scorch","ttl":"24h0m0s"},"apiban":{"enabled":false,"keys":[]},"asterisk_agent":{"asterisk_conns":[{"address":"127.0.0.1:8088","alias":"","connect_attempts":3,"password":"CGRateS.org","reconnects":5,"user":"cgrates"}],"create_cdr":false,"enabled":false,"sessions_conns":["*birpc_internal"]},"attributes":{"apiers_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"process_runs":1,"resources_conns":[],"stats_conns":[],"suffix_indexed_fields":[]},"caches":{"partitions":{"*account_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*accounts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*action_profile_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*action_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*apiban":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"2m0s"},"*attribute_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*attribute_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*caps_events":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*cdr_ids":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"10m0s"},"*cdrs":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*charger_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*charger_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*closed_sessions":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"10s"},"*destinations":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*diameter_messages":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*dispatcher_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_hosts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_loads":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatcher_routes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*dispatchers":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*event_charges":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"10s"},"*event_resources":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*filters":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*load_ids":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rate_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rate_profile_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rate_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*replication_hosts":{"limit":0,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*resource_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*resource_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*resources":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*reverse_destinations":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*reverse_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*route_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*route_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rpc_connections":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*rpc_responses":{"limit":0,"precache":false,"replicate":false,"static_ttl":false,"ttl":"2s"},"*session_costs":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*stat_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*statqueue_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*statqueues":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*stir":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*threshold_filter_indexes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*threshold_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*thresholds":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*timings":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_accounts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_action_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_attributes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_chargers":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_destinations":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_dispatcher_hosts":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_dispatcher_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_filters":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_rate_profiles":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_resources":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_routes":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_stats":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_thresholds":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*tp_timings":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""},"*uch":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"3h0m0s"},"*versions":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":""}},"replication_conns":[]},"cdrs":{"actions_conns":[],"attributes_conns":[],"chargers_conns":[],"ees_conns":[],"enabled":false,"extra_fields":[],"online_cdr_exports":[],"session_cost_retries":5,"stats_conns":[],"store_cdrs":true,"thresholds_conns":[]},"chargers":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"suffix_indexed_fields":[]},"configs":{"enabled":false,"root_dir":"/var/spool/cgrates/configs","url":"/configs/"},"cores":{"caps":0,"caps_stats_interval":"0","caps_strategy":"*busy","shutdown_timeout":"1s"},"data_db":{"db_host":"127.0.0.1","db_name":"10","db_password":"","db_port":6379,"db_type":"*redis","db_user":"cgrates","items":{"*accounts":{"remote":false,"replicate":false},"*action_profiles":{"remote":false,"replicate":false},"*actions":{"remote":false,"replicate":false},"*attribute_profiles":{"remote":false,"replicate":false},"*charger_profiles":{"remote":false,"replicate":false},"*destinations":{"remote":false,"replicate":false},"*dispatcher_hosts":{"remote":false,"replicate":false},"*dispatcher_profiles":{"remote":false,"replicate":false},"*filters":{"remote":false,"replicate":false},"*indexes":{"remote":false,"replicate":false},"*load_ids":{"remote":false,"replicate":false},"*rate_profiles":{"remote":false,"replicate":false},"*resource_profiles":{"remote":false,"replicate":false},"*resources":{"remote":false,"replicate":false},"*reverse_destinations":{"remote":false,"replicate":false},"*route_profiles":{"remote":false,"replicate":false},"*statqueue_profiles":{"remote":false,"replicate":false},"*statqueues":{"remote":false,"replicate":false},"*threshold_profiles":{"remote":false,"replicate":false},"*thresholds":{"remote":false,"replicate":false},"*timings":{"remote":false,"replicate":false}},"opts":{"query_timeout":"10s","redis_ca_certificate":"","redis_client_certificate":"","redis_client_key":"","redis_cluster":false,"redis_cluster_ondown_delay":"0","redis_cluster_sync":"5s","redis_sentinel":"","redis_tls":false},"remote_conn_id":"","remote_conns":[],"replication_cache":"","replication_conns":[],"replication_filtered":false},"diameter_agent":{"asr_template":"","concurrent_requests":-1,"dictionaries_path":"/usr/share/cgrates/diameter/dict/","enabled":false,"forced_disconnect":"*none","listen":"127.0.0.1:3868","listen_net":"tcp","origin_host":"CGR-DA","origin_realm":"cgrates.org","product_name":"CGRateS","rar_template":"","request_processors":[],"sessions_conns":["*birpc_internal"],"synced_conn_requests":false,"vendor_id":0},"dispatchers":{"attributes_conns":[],"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"suffix_indexed_fields":[]},"dns_agent":{"enabled":false,"listen":"127.0.0.1:2053","listen_net":"udp","request_processors":[],"sessions_conns":["*internal"],"timezone":""},"ees":{"attributes_conns":[],"cache":{"*file_csv":{"limit":-1,"precache":false,"replicate":false,"static_ttl":false,"ttl":"5s"}},"enabled":false,"exporters":[{"attempts":1,"attribute_context":"","attribute_ids":[],"export_path":"/var/spool/cgrates/ees","field_separator":",","fields":[],"filters":[],"flags":[],"id":"*default","opts":{},"synchronous":false,"tenant":"","timezone":"","type":"*none"}]},"ers":{"enabled":false,"readers":[{"cache_dump_fields":[],"concurrent_requests":1024,"failed_calls_prefix":"","field_separator":",","fields":[{"mandatory":true,"path":"*cgreq.ToR","tag":"ToR","type":"*variable","value":"~*req.2"},{"mandatory":true,"path":"*cgreq.OriginID","tag":"OriginID","type":"*variable","value":"~*req.3"},{"mandatory":true,"path":"*cgreq.RequestType","tag":"RequestType","type":"*variable","value":"~*req.4"},{"mandatory":true,"path":"*cgreq.Tenant","tag":"Tenant","type":"*variable","value":"~*req.6"},{"mandatory":true,"path":"*cgreq.Category","tag":"Category","type":"*variable","value":"~*req.7"},{"mandatory":true,"path":"*cgreq.Account","tag":"Account","type":"*variable","value":"~*req.8"},{"mandatory":true,"path":"*cgreq.Subject","tag":"Subject","type":"*variable","value":"~*req.9"},{"mandatory":true,"path":"*cgreq.Destination","tag":"Destination","type":"*variable","value":"~*req.10"},{"mandatory":true,"path":"*cgreq.SetupTime","tag":"SetupTime","type":"*variable","value":"~*req.11"},{"mandatory":true,"path":"*cgreq.AnswerTime","tag":"AnswerTime","type":"*variable","value":"~*req.12"},{"mandatory":true,"path":"*cgreq.Usage","tag":"Usage","type":"*variable","value":"~*req.13"}],"filters":[],"flags":[],"header_define_character":":","id":"*default","opts":{},"partial_cache_expiry_action":"","partial_record_cache":"0","processed_path":"/var/spool/cgrates/ers/out","row_length":0,"run_delay":"0","source_path":"/var/spool/cgrates/ers/in","tenant":"","timezone":"","type":"*none","xml_root_path":[""]}],"sessions_conns":["*internal"]},"filters":{"apiers_conns":[],"resources_conns":[],"stats_conns":[]},"freeswitch_agent":{"create_cdr":false,"empty_balance_ann_file":"","empty_balance_context":"","enabled":false,"event_socket_conns":[{"address":"127.0.0.1:8021","alias":"127.0.0.1:8021","password":"ClueCon","reconnects":5}],"extra_fields":"","low_balance_ann_file":"","max_wait_connection":"2s","sessions_conns":["*birpc_internal"],"subscribe_park":true},"general":{"connect_attempts":5,"connect_timeout":"1s","dbdata_encoding":"*msgpack","default_caching":"*reload","default_category":"call","default_request_type":"*rated","default_tenant":"cgrates.org","default_timezone":"Local","digest_equal":":","digest_separator":",","failed_posts_dir":"/var/spool/cgrates/failed_posts","failed_posts_ttl":"5s","locking_timeout":"0","log_level":6,"logger":"*syslog","max_parallel_conns":100,"node_id":"ENGINE1","poster_attempts":3,"reconnects":-1,"reply_timeout":"2s","rounding_decimals":5,"rsr_separator":";","tpexport_dir":"/var/spool/cgrates/tpe"},"http":{"auth_users":{},"client_opts":{"dialFallbackDelay":"300ms","dialKeepAlive":"30s","dialTimeout":"30s","disableCompression":false,"disableKeepAlives":false,"expectContinueTimeout":"0","forceAttemptHttp2":true,"idleConnTimeout":"90s","maxConnsPerHost":0,"maxIdleConns":100,"maxIdleConnsPerHost":2,"responseHeaderTimeout":"0","skipTlsVerify":false,"tlsHandshakeTimeout":"10s"},"freeswitch_cdrs_url":"/freeswitch_json","http_cdrs":"/cdr_http","json_rpc_url":"/jsonrpc","registrars_url":"/registrar","use_basic_auth":false,"ws_url":"/ws"},"http_agent":[],"kamailio_agent":{"create_cdr":false,"enabled":false,"evapi_conns":[{"address":"127.0.0.1:8448","alias":"","reconnects":5}],"sessions_conns":["*birpc_internal"],"timezone":""},"listen":{"http":"127.0.0.1:2080","http_tls":"127.0.0.1:2280","rpc_gob":"127.0.0.1:2013","rpc_gob_tls":"127.0.0.1:2023","rpc_json":"127.0.0.1:2012","rpc_json_tls":"127.0.0.1:2022"},"loader":{"actions_conns":["*localhost"],"caches_conns":["*localhost"],"data_path":"./","disable_reverse":false,"field_separator":",","gapi_credentials":".gapi/credentials.json","gapi_token":".gapi/token.json","tpid":""},"loaders":[{"caches_conns":["*internal"],"data":[{"fields":[{"mandatory":true,"path":"Tenant","tag":"TenantID","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ProfileID","type":"*variable","value":"~*req.1"},{"path":"Contexts","tag":"Contexts","type":"*variable","value":"~*req.2"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.3"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.4"},{"path":"AttributeFilterIDs","tag":"AttributeFilterIDs","type":"*variable","value":"~*req.5"},{"path":"Path","tag":"Path","type":"*variable","value":"~*req.6"},{"path":"Type","tag":"Type","type":"*variable","value":"~*req.7"},{"path":"Value","tag":"Value","type":"*variable","value":"~*req.8"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.9"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.10"}],"file_name":"Attributes.csv","flags":null,"type":"*attributes"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Type","tag":"Type","type":"*variable","value":"~*req.2"},{"path":"Element","tag":"Element","type":"*variable","value":"~*req.3"},{"path":"Values","tag":"Values","type":"*variable","value":"~*req.4"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.5"}],"file_name":"Filters.csv","flags":null,"type":"*filters"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"UsageTTL","tag":"TTL","type":"*variable","value":"~*req.4"},{"path":"Limit","tag":"Limit","type":"*variable","value":"~*req.5"},{"path":"AllocationMessage","tag":"AllocationMessage","type":"*variable","value":"~*req.6"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.7"},{"path":"Stored","tag":"Stored","type":"*variable","value":"~*req.8"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.9"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.10"}],"file_name":"Resources.csv","flags":null,"type":"*resources"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"QueueLength","tag":"QueueLength","type":"*variable","value":"~*req.4"},{"path":"TTL","tag":"TTL","type":"*variable","value":"~*req.5"},{"path":"MinItems","tag":"MinItems","type":"*variable","value":"~*req.6"},{"path":"MetricIDs","tag":"MetricIDs","type":"*variable","value":"~*req.7"},{"path":"MetricFilterIDs","tag":"MetricFilterIDs","type":"*variable","value":"~*req.8"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.9"},{"path":"Stored","tag":"Stored","type":"*variable","value":"~*req.10"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.11"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.12"}],"file_name":"Stats.csv","flags":null,"type":"*stats"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"MaxHits","tag":"MaxHits","type":"*variable","value":"~*req.4"},{"path":"MinHits","tag":"MinHits","type":"*variable","value":"~*req.5"},{"path":"MinSleep","tag":"MinSleep","type":"*variable","value":"~*req.6"},{"path":"Blocker","tag":"Blocker","type":"*variable","value":"~*req.7"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.8"},{"path":"ActionIDs","tag":"ActionIDs","type":"*variable","value":"~*req.9"},{"path":"Async","tag":"Async","type":"*variable","value":"~*req.10"}],"file_name":"Thresholds.csv","flags":null,"type":"*thresholds"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Sorting","tag":"Sorting","type":"*variable","value":"~*req.4"},{"path":"SortingParameters","tag":"SortingParameters","type":"*variable","value":"~*req.5"},{"path":"RouteID","tag":"RouteID","type":"*variable","value":"~*req.6"},{"path":"RouteFilterIDs","tag":"RouteFilterIDs","type":"*variable","value":"~*req.7"},{"path":"RouteAccountIDs","tag":"RouteAccountIDs","type":"*variable","value":"~*req.8"},{"path":"RouteRatingPlanIDs","tag":"RouteRatingPlanIDs","type":"*variable","value":"~*req.9"},{"path":"RouteResourceIDs","tag":"RouteResourceIDs","type":"*variable","value":"~*req.10"},{"path":"RouteStatIDs","tag":"RouteStatIDs","type":"*variable","value":"~*req.11"},{"path":"RouteWeight","tag":"RouteWeight","type":"*variable","value":"~*req.12"},{"path":"RouteBlocker","tag":"RouteBlocker","type":"*variable","value":"~*req.13"},{"path":"RouteParameters","tag":"RouteParameters","type":"*variable","value":"~*req.14"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.15"}],"file_name":"Routes.csv","flags":null,"type":"*routes"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"RunID","tag":"RunID","type":"*variable","value":"~*req.4"},{"path":"AttributeIDs","tag":"AttributeIDs","type":"*variable","value":"~*req.5"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.6"}],"file_name":"Chargers.csv","flags":null,"type":"*chargers"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Contexts","tag":"Contexts","type":"*variable","value":"~*req.2"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.3"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.4"},{"path":"Strategy","tag":"Strategy","type":"*variable","value":"~*req.5"},{"path":"StrategyParameters","tag":"StrategyParameters","type":"*variable","value":"~*req.6"},{"path":"ConnID","tag":"ConnID","type":"*variable","value":"~*req.7"},{"path":"ConnFilterIDs","tag":"ConnFilterIDs","type":"*variable","value":"~*req.8"},{"path":"ConnWeight","tag":"ConnWeight","type":"*variable","value":"~*req.9"},{"path":"ConnBlocker","tag":"ConnBlocker","type":"*variable","value":"~*req.10"},{"path":"ConnParameters","tag":"ConnParameters","type":"*variable","value":"~*req.11"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.12"}],"file_name":"DispatcherProfiles.csv","flags":null,"type":"*dispatchers"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"Address","tag":"Address","type":"*variable","value":"~*req.2"},{"path":"Transport","tag":"Transport","type":"*variable","value":"~*req.3"},{"path":"TLS","tag":"TLS","type":"*variable","value":"~*req.4"}],"file_name":"DispatcherHosts.csv","flags":null,"type":"*dispatcher_hosts"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.4"},{"path":"MinCost","tag":"MinCost","type":"*variable","value":"~*req.5"},{"path":"MaxCost","tag":"MaxCost","type":"*variable","value":"~*req.6"},{"path":"MaxCostStrategy","tag":"MaxCostStrategy","type":"*variable","value":"~*req.7"},{"path":"RateID","tag":"RateID","type":"*variable","value":"~*req.8"},{"path":"RateFilterIDs","tag":"RateFilterIDs","type":"*variable","value":"~*req.9"},{"path":"RateActivationTimes","tag":"RateActivationTimes","type":"*variable","value":"~*req.10"},{"path":"RateWeight","tag":"RateWeight","type":"*variable","value":"~*req.11"},{"path":"RateBlocker","tag":"RateBlocker","type":"*variable","value":"~*req.12"},{"path":"RateIntervalStart","tag":"RateIntervalStart","type":"*variable","value":"~*req.13"},{"path":"RateFixedFee","tag":"RateFixedFee","type":"*variable","value":"~*req.14"},{"path":"RateRecurrentFee","tag":"RateRecurrentFee","type":"*variable","value":"~*req.15"},{"path":"RateUnit","tag":"RateUnit","type":"*variable","value":"~*req.16"},{"path":"RateIncrement","tag":"RateIncrement","type":"*variable","value":"~*req.17"}],"file_name":"RateProfiles.csv","flags":null,"type":"*rate_profiles"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.4"},{"path":"Schedule","tag":"Schedule","type":"*variable","value":"~*req.5"},{"path":"TargetType","tag":"TargetType","type":"*variable","value":"~*req.6"},{"path":"TargetIDs","tag":"TargetIDs","type":"*variable","value":"~*req.7"},{"path":"ActionID","tag":"ActionID","type":"*variable","value":"~*req.8"},{"path":"ActionFilterIDs","tag":"ActionFilterIDs","type":"*variable","value":"~*req.9"},{"path":"ActionBlocker","tag":"ActionBlocker","type":"*variable","value":"~*req.10"},{"path":"ActionTTL","tag":"ActionTTL","type":"*variable","value":"~*req.11"},{"path":"ActionType","tag":"ActionType","type":"*variable","value":"~*req.12"},{"path":"ActionOpts","tag":"ActionOpts","type":"*variable","value":"~*req.13"},{"path":"ActionPath","tag":"ActionPath","type":"*variable","value":"~*req.14"},{"path":"ActionValue","tag":"ActionValue","type":"*variable","value":"~*req.15"}],"file_name":"ActionProfiles.csv","flags":null,"type":"*action_profiles"},{"fields":[{"mandatory":true,"path":"Tenant","tag":"Tenant","type":"*variable","value":"~*req.0"},{"mandatory":true,"path":"ID","tag":"ID","type":"*variable","value":"~*req.1"},{"path":"FilterIDs","tag":"FilterIDs","type":"*variable","value":"~*req.2"},{"path":"ActivationInterval","tag":"ActivationInterval","type":"*variable","value":"~*req.3"},{"path":"Weight","tag":"Weight","type":"*variable","value":"~*req.4"},{"path":"BalanceID","tag":"BalanceID","type":"*variable","value":"~*req.5"},{"path":"BalanceFilterIDs","tag":"BalanceFilterIDs","type":"*variable","value":"~*req.6"},{"path":"BalanceWeight","tag":"BalanceWeight","type":"*variable","value":"~*req.7"},{"path":"BalanceBlocker","tag":"BalanceBlocker","type":"*variable","value":"~*req.8"},{"path":"BalanceType","tag":"BalanceType","type":"*variable","value":"~*req.9"},{"path":"BalanceOpts","tag":"BalanceOpts","type":"*variable","value":"~*req.10"},{"path":"BalanceCostIncrements","tag":"BalanceCostIncrements","type":"*variable","value":"~*req.11"},{"path":"BalanceAttributeIDs","tag":"BalanceAttributeIDs","type":"*variable","value":"~*req.12"},{"path":"BalanceRateProfileIDs","tag":"BalanceRateProfileIDs","type":"*variable","value":"~*req.13"},{"path":"BalanceUnitFactors","tag":"BalanceUnitFactors","type":"*variable","value":"~*req.14"},{"path":"BalanceUnits","tag":"BalanceUnits","type":"*variable","value":"~*req.15"},{"path":"ThresholdIDs","tag":"ThresholdIDs","type":"*variable","value":"~*req.16"}],"file_name":"Accounts.csv","flags":null,"type":"*accounts"}],"dry_run":false,"enabled":false,"field_separator":",","id":"*default","lock_filename":".cgr.lck","run_delay":"0","tenant":"","tp_in_dir":"/var/spool/cgrates/loader/in","tp_out_dir":"/var/spool/cgrates/loader/out"}],"mailer":{"auth_password":"CGRateS.org","auth_user":"cgrates","from_address":"cgr-mailer@localhost.localdomain","server":"localhost"},"migrator":{"out_datadb_encoding":"msgpack","out_datadb_host":"127.0.0.1","out_datadb_name":"10","out_datadb_opts":{"redis_ca_certificate":"","redis_client_certificate":"","redis_client_key":"","redis_cluster":false,"redis_cluster_ondown_delay":"0","redis_cluster_sync":"5s","redis_sentinel":"","redis_tls":false},"out_datadb_password":"","out_datadb_port":"6379","out_datadb_type":"redis","out_datadb_user":"cgrates","out_stordb_host":"127.0.0.1","out_stordb_name":"cgrates","out_stordb_opts":{},"out_stordb_password":"","out_stordb_port":"3306","out_stordb_type":"mysql","out_stordb_user":"cgrates","users_filters":[]},"radius_agent":{"client_dictionaries":{"*default":"/usr/share/cgrates/radius/dict/"},"client_secrets":{"*default":"CGRateS.org"},"enabled":false,"listen_acct":"127.0.0.1:1813","listen_auth":"127.0.0.1:1812","listen_net":"udp","request_processors":[],"sessions_conns":["*internal"]},"rates":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"rate_indexed_selects":true,"rate_nested_fields":false,"rate_prefix_indexed_fields":[],"rate_suffix_indexed_fields":[],"suffix_indexed_fields":[],"verbosity":1000},"registrarc":{"dispatcher":{"enabled":false,"hosts":{},"refresh_interval":"5m0s","registrars_conns":[]},"rpc":{"enabled":false,"hosts":{},"refresh_interval":"5m0s","registrars_conns":[]}},"resources":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"store_interval":"","suffix_indexed_fields":[],"thresholds_conns":[]},"routes":{"attributes_conns":[],"default_ratio":1,"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"resources_conns":[],"stats_conns":[],"suffix_indexed_fields":[]},"rpc_conns":{"*bijson_localhost":{"conns":[{"address":"127.0.0.1:2014","transport":"*birpc_json"}],"poolSize":0,"strategy":"*first"},"*birpc_internal":{"conns":[{"address":"*birpc_internal","transport":""}],"poolSize":0,"strategy":"*first"},"*internal":{"conns":[{"address":"*internal","transport":""}],"poolSize":0,"strategy":"*first"},"*localhost":{"conns":[{"address":"127.0.0.1:2012","transport":"*json"}],"poolSize":0,"strategy":"*first"}},"sessions":{"actions_conns":[],"alterable_fields":[],"attributes_conns":[],"cdrs_conns":[],"channel_sync_interval":"0","chargers_conns":[],"client_protocol":1,"debit_interval":"0","default_usage":{"*any":"3h0m0s","*data":"1048576","*sms":"1","*voice":"3h0m0s"},"enabled":false,"listen_bigob":"","listen_bijson":"127.0.0.1:2014","min_dur_low_balance":"0","replication_conns":[],"resources_conns":[],"routes_conns":[],"session_indexes":[],"session_ttl":"0","stats_conns":[],"stir":{"allowed_attest":["*any"],"default_attest":"A","payload_maxduration":"-1","privatekey_path":"","publickey_path":""},"store_session_costs":false,"terminate_attempts":5,"thresholds_conns":[]},"sip_agent":{"enabled":false,"listen":"127.0.0.1:5060","listen_net":"udp","request_processors":[],"retransmission_timer":1000000000,"sessions_conns":["*internal"],"timezone":""},"stats":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"store_interval":"","store_uncompressed_limit":0,"suffix_indexed_fields":[],"thresholds_conns":[]},"stor_db":{"db_host":"127.0.0.1","db_name":"cgrates","db_password":"","db_port":3306,"db_type":"*mysql","db_user":"cgrates","items":{"*cdrs":{"remote":false,"replicate":false},"*session_costs":{"remote":false,"replicate":false},"*tp_accounts":{"remote":false,"replicate":false},"*tp_action_profiles":{"remote":false,"replicate":false},"*tp_attributes":{"remote":false,"replicate":false},"*tp_chargers":{"remote":false,"replicate":false},"*tp_destinations":{"remote":false,"replicate":false},"*tp_dispatcher_hosts":{"remote":false,"replicate":false},"*tp_dispatcher_profiles":{"remote":false,"replicate":false},"*tp_filters":{"remote":false,"replicate":false},"*tp_rate_profiles":{"remote":false,"replicate":false},"*tp_resources":{"remote":false,"replicate":false},"*tp_routes":{"remote":false,"replicate":false},"*tp_stats":{"remote":false,"replicate":false},"*tp_thresholds":{"remote":false,"replicate":false},"*tp_timings":{"remote":false,"replicate":false},"*versions":{"remote":false,"replicate":false}},"opts":{"conn_max_lifetime":0,"max_idle_conns":10,"max_open_conns":100,"mysql_location":"Local","query_timeout":"10s","sslmode":"disable"},"prefix_indexed_fields":[],"remote_conns":null,"replication_conns":null,"string_indexed_fields":[]},"suretax":{"bill_to_number":"","business_unit":"","client_number":"","client_tracking":"~*req.CGRID","customer_number":"~*req.Subject","include_local_cost":false,"orig_number":"~*req.Subject","p2pplus4":"","p2pzipcode":"","plus4":"","regulatory_code":"03","response_group":"03","response_type":"D4","return_file_code":"0","sales_type_code":"R","tax_exemption_code_list":"","tax_included":"0","tax_situs_rule":"04","term_number":"~*req.Destination","timezone":"UTC","trans_type_code":"010101","unit_type":"00","units":"1","url":"","validation_key":"","zipcode":""},"templates":{"*asr":[{"mandatory":true,"path":"*diamreq.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*diamreq.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*req.Destination-Host"},{"mandatory":true,"path":"*diamreq.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*req.Destination-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Realm","tag":"DestinationRealm","type":"*variable","value":"~*req.Origin-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Host","tag":"DestinationHost","type":"*variable","value":"~*req.Origin-Host"},{"mandatory":true,"path":"*diamreq.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"}],"*cca":[{"mandatory":true,"path":"*rep.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"path":"*rep.Result-Code","tag":"ResultCode","type":"*constant","value":"2001"},{"mandatory":true,"path":"*rep.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*vars.OriginHost"},{"mandatory":true,"path":"*rep.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*vars.OriginRealm"},{"mandatory":true,"path":"*rep.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"},{"mandatory":true,"path":"*rep.CC-Request-Type","tag":"CCRequestType","type":"*variable","value":"~*req.CC-Request-Type"},{"mandatory":true,"path":"*rep.CC-Request-Number","tag":"CCRequestNumber","type":"*variable","value":"~*req.CC-Request-Number"}],"*cdrLog":[{"mandatory":true,"path":"*cdr.ToR","tag":"ToR","type":"*variable","value":"~*req.BalanceType"},{"mandatory":true,"path":"*cdr.OriginHost","tag":"OriginHost","type":"*constant","value":"127.0.0.1"},{"mandatory":true,"path":"*cdr.RequestType","tag":"RequestType","type":"*constant","value":"*none"},{"mandatory":true,"path":"*cdr.Tenant","tag":"Tenant","type":"*variable","value":"~*req.Tenant"},{"mandatory":true,"path":"*cdr.Account","tag":"Account","type":"*variable","value":"~*req.Account"},{"mandatory":true,"path":"*cdr.Subject","tag":"Subject","type":"*variable","value":"~*req.Account"},{"mandatory":true,"path":"*cdr.Cost","tag":"Cost","type":"*variable","value":"~*req.Cost"},{"mandatory":true,"path":"*cdr.Source","tag":"Source","type":"*constant","value":"*cdrLog"},{"mandatory":true,"path":"*cdr.Usage","tag":"Usage","type":"*constant","value":"1"},{"mandatory":true,"path":"*cdr.RunID","tag":"RunID","type":"*variable","value":"~*req.ActionType"},{"mandatory":true,"path":"*cdr.SetupTime","tag":"SetupTime","type":"*constant","value":"*now"},{"mandatory":true,"path":"*cdr.AnswerTime","tag":"AnswerTime","type":"*constant","value":"*now"},{"mandatory":true,"path":"*cdr.PreRated","tag":"PreRated","type":"*constant","value":"true"}],"*err":[{"mandatory":true,"path":"*rep.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*rep.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*vars.OriginHost"},{"mandatory":true,"path":"*rep.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*vars.OriginRealm"}],"*errSip":[{"mandatory":true,"path":"*rep.Request","tag":"Request","type":"*constant","value":"SIP/2.0 500 Internal Server Error"}],"*rar":[{"mandatory":true,"path":"*diamreq.Session-Id","tag":"SessionId","type":"*variable","value":"~*req.Session-Id"},{"mandatory":true,"path":"*diamreq.Origin-Host","tag":"OriginHost","type":"*variable","value":"~*req.Destination-Host"},{"mandatory":true,"path":"*diamreq.Origin-Realm","tag":"OriginRealm","type":"*variable","value":"~*req.Destination-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Realm","tag":"DestinationRealm","type":"*variable","value":"~*req.Origin-Realm"},{"mandatory":true,"path":"*diamreq.Destination-Host","tag":"DestinationHost","type":"*variable","value":"~*req.Origin-Host"},{"mandatory":true,"path":"*diamreq.Auth-Application-Id","tag":"AuthApplicationId","type":"*variable","value":"~*vars.*appid"},{"path":"*diamreq.Re-Auth-Request-Type","tag":"ReAuthRequestType","type":"*constant","value":"0"}]},"thresholds":{"enabled":false,"indexed_selects":true,"nested_fields":false,"prefix_indexed_fields":[],"store_interval":"","suffix_indexed_fields":[]},"tls":{"ca_certificate":"","client_certificate":"","client_key":"","server_certificate":"","server_key":"","server_name":"","server_policy":4}}`
cgrCfg, err := NewCGRConfigFromJSONStringWithDefaults(cfgJSON)
if err != nil {
t.Fatal(err)
@@ -5856,8 +5856,8 @@ func TestCGRConfigClone(t *testing.T) {
if !reflect.DeepEqual(cfg.analyzerSCfg, rcv.analyzerSCfg) {
t.Errorf("Expected: %+v\nReceived: %+v", utils.ToJSON(cfg.analyzerSCfg), utils.ToJSON(rcv.analyzerSCfg))
}
- if !reflect.DeepEqual(cfg.apier, rcv.apier) {
- t.Errorf("Expected: %+v\nReceived: %+v", utils.ToJSON(cfg.apier), utils.ToJSON(rcv.apier))
+ if !reflect.DeepEqual(cfg.admS, rcv.admS) {
+ t.Errorf("Expected: %+v\nReceived: %+v", utils.ToJSON(cfg.admS), utils.ToJSON(rcv.admS))
}
if !reflect.DeepEqual(cfg.ersCfg, rcv.ersCfg) {
t.Errorf("Expected: %+v\nReceived: %+v", utils.ToJSON(cfg.ersCfg), utils.ToJSON(rcv.ersCfg))
diff --git a/config/configsanity.go b/config/configsanity.go
index d9238c5dd..9a551f227 100644
--- a/config/configsanity.go
+++ b/config/configsanity.go
@@ -601,7 +601,7 @@ func (cfg *CGRConfig) checkConfigSanity() error {
}
}
// APIer sanity checks
- for _, connID := range cfg.apier.AttributeSConns {
+ for _, connID := range cfg.admS.AttributeSConns {
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.attributeSCfg.Enabled {
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.AttributeS, utils.APIerSv1)
}
@@ -609,7 +609,7 @@ func (cfg *CGRConfig) checkConfigSanity() error {
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.APIerSv1, connID)
}
}
- for _, connID := range cfg.apier.ActionSConns {
+ for _, connID := range cfg.admS.ActionSConns {
if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.actionSCfg.Enabled {
return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.SchedulerS, utils.APIerSv1)
}
@@ -663,8 +663,8 @@ func (cfg *CGRConfig) checkConfigSanity() error {
}
}
for _, connID := range cfg.filterSCfg.ApierSConns {
- if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.apier.Enabled {
- return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.ApierS, utils.FilterS)
+ if strings.HasPrefix(connID, utils.MetaInternal) && !cfg.admS.Enabled {
+ return fmt.Errorf("<%s> not enabled but requested by <%s> component", utils.AdminS, utils.FilterS)
}
if _, has := cfg.rpcConns[connID]; !has && !strings.HasPrefix(connID, utils.MetaInternal) {
return fmt.Errorf("<%s> connection with id: <%s> not defined", utils.FilterS, connID)
diff --git a/config/configsanity_test.go b/config/configsanity_test.go
index 56a68cafb..8c48b0958 100644
--- a/config/configsanity_test.go
+++ b/config/configsanity_test.go
@@ -1105,24 +1105,24 @@ func TestConfigSanityDataDB(t *testing.T) {
func TestConfigSanityAPIer(t *testing.T) {
cfg = NewDefaultCGRConfig()
- cfg.apier.AttributeSConns = []string{utils.MetaInternal}
+ cfg.admS.AttributeSConns = []string{utils.MetaInternal}
if err := cfg.checkConfigSanity(); err == nil || err.Error() != " not enabled but requested by component" {
t.Error(err)
}
- cfg.apier.AttributeSConns = []string{"test"}
+ cfg.admS.AttributeSConns = []string{"test"}
expected := " connection with id: not defined"
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
t.Errorf("Expecting: %+q received: %+q", expected, err)
}
- cfg.apier.AttributeSConns = []string{utils.MetaInternal}
+ cfg.admS.AttributeSConns = []string{utils.MetaInternal}
cfg.attributeSCfg.Enabled = true
- cfg.apier.ActionSConns = []string{utils.MetaInternal}
+ cfg.admS.ActionSConns = []string{utils.MetaInternal}
if err := cfg.checkConfigSanity(); err == nil || err.Error() != " not enabled but requested by component" {
t.Error(err)
}
- cfg.apier.ActionSConns = []string{"test"}
+ cfg.admS.ActionSConns = []string{"test"}
expected = " connection with id: not defined"
if err := cfg.checkConfigSanity(); err == nil || err.Error() != expected {
t.Errorf("Expecting: %+q received: %+q", expected, err)
@@ -1187,7 +1187,7 @@ func TestConfigSanityFilterS(t *testing.T) {
cfg.filterSCfg.ApierSConns = []string{utils.MetaInternal}
- if err := cfg.checkConfigSanity(); err == nil || err.Error() != " not enabled but requested by component" {
+ if err := cfg.checkConfigSanity(); err == nil || err.Error() != " not enabled but requested by component" {
t.Error(err)
}
cfg.filterSCfg.ApierSConns = []string{"test"}
diff --git a/config/libconfig_json.go b/config/libconfig_json.go
index 5caec2dce..4ba7b96e5 100644
--- a/config/libconfig_json.go
+++ b/config/libconfig_json.go
@@ -584,7 +584,7 @@ type AnalyzerSJsonCfg struct {
Cleanup_interval *string
}
-type ApierJsonCfg struct {
+type AdminSJsonCfg struct {
Enabled *bool
Caches_conns *[]string
Actions_conns *[]string
diff --git a/console/accounts_profile_ids_test.go b/console/accounts_profile_ids_test.go
deleted file mode 100644
index dff0f2cdd..000000000
--- a/console/accounts_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 TestCmdAccountsIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["accounts_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/accounts_profile_rem_test.go b/console/accounts_profile_rem_test.go
deleted file mode 100644
index 6eed48648..000000000
--- a/console/accounts_profile_rem_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 TestCmdAccountsRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["accounts_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/accounts_profile_set_test.go b/console/accounts_profile_set_test.go
deleted file mode 100644
index bc0818394..000000000
--- a/console/accounts_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 TestCmdAccountsSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["accounts_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/accounts_profile_test.go b/console/accounts_profile_test.go
deleted file mode 100644
index 77ec465c0..000000000
--- a/console/accounts_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 TestCmdAccounts(t *testing.T) {
- // commands map is initiated in init function
- command := commands["accounts"]
- // 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/active_sessions_test.go b/console/active_sessions_test.go
deleted file mode 100644
index cd3880748..000000000
--- a/console/active_sessions_test.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 (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdActiveSessions(t *testing.T) {
- // commands map is initiated in init function
- command := commands["active_sessions"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedSliceResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- utils.DurationIndex: {},
- utils.MaxRateUnit: {},
- utils.DebitInterval: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/attributes_for_event_test.go b/console/attributes_for_event_test.go
deleted file mode 100644
index 78a6b16a0..000000000
--- a/console/attributes_for_event_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 TestCmdAttributesForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["attributes_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.AttributeSv1)).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/attributes_process_event_test.go b/console/attributes_process_event_test.go
deleted file mode 100644
index 90b5d1c1f..000000000
--- a/console/attributes_process_event_test.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 (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdAttributesProcessEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["attributes_process_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.AttributeSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/attributes_profile_ids_test.go b/console/attributes_profile_ids_test.go
deleted file mode 100644
index fcc4a2beb..000000000
--- a/console/attributes_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 TestCmdAttributesProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["attributes_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/attributes_profile_rem_test.go b/console/attributes_profile_rem_test.go
deleted file mode 100644
index e41d1ae83..000000000
--- a/console/attributes_profile_rem_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 TestCmdAttributesProfileRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["attributes_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/attributes_profile_set.go b/console/attributes_profile_set.go
index 33759b7e9..e0d5aa739 100644
--- a/console/attributes_profile_set.go
+++ b/console/attributes_profile_set.go
@@ -19,7 +19,6 @@ along with this program. If not, see
package console
import (
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -28,7 +27,7 @@ func init() {
c := &CmdSetAttributes{
name: "attributes_profile_set",
rpcMethod: utils.APIerSv2SetAttributeProfile,
- rpcParams: &v2.AttributeWithAPIOpts{},
+ rpcParams: &engine.AttributeWithAPIOpts{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
@@ -37,7 +36,7 @@ func init() {
type CmdSetAttributes struct {
name string
rpcMethod string
- rpcParams *v2.AttributeWithAPIOpts
+ rpcParams *engine.AttributeWithAPIOpts
*CommandExecuter
}
@@ -51,7 +50,7 @@ func (self *CmdSetAttributes) RpcMethod() string {
func (self *CmdSetAttributes) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
- self.rpcParams = &v2.AttributeWithAPIOpts{APIAttributeProfile: new(engine.APIAttributeProfile)}
+ self.rpcParams = &engine.AttributeWithAPIOpts{APIAttributeProfile: new(engine.APIAttributeProfile)}
}
return self.rpcParams
}
diff --git a/console/attributes_profile_set_test.go b/console/attributes_profile_set_test.go
deleted file mode 100644
index e77ccc3e4..000000000
--- a/console/attributes_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"
-
- v2 "github.com/cgrates/cgrates/apier/v2"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdAttributesProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["attributes_profile_set"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v2.APIerSv2)).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/attributes_profile_test.go b/console/attributes_profile_test.go
deleted file mode 100644
index d406c9696..000000000
--- a/console/attributes_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 TestCmdAttributesProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["attributes_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/console/cache_clear_test.go b/console/cache_clear_test.go
deleted file mode 100644
index efedccc4d..000000000
--- a/console/cache_clear_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 TestCmdCacheClear(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_clear"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_group_item_id_test.go b/console/cache_group_item_id_test.go
deleted file mode 100644
index 8564fd2f3..000000000
--- a/console/cache_group_item_id_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 TestCmdCacheGroupItemId(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_group_item_ids"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_has_group_test.go b/console/cache_has_group_test.go
deleted file mode 100644
index 7da590c51..000000000
--- a/console/cache_has_group_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 TestCmdCacheHasGroup(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_has_group"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_has_item_test.go b/console/cache_has_item_test.go
deleted file mode 100644
index 79ec6dd94..000000000
--- a/console/cache_has_item_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 TestCmdCacheHasItem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_has_item"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_item_expiry_time_test.go b/console/cache_item_expiry_time_test.go
deleted file mode 100644
index 1838bc4d0..000000000
--- a/console/cache_item_expiry_time_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 TestCmdCacheExpiryTime(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_item_expiry_time"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_item_ids_test.go b/console/cache_item_ids_test.go
deleted file mode 100644
index 54fd6e715..000000000
--- a/console/cache_item_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 TestCmdCacheItermIds(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_item_ids"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_precache_status_test.go b/console/cache_precache_status_test.go
deleted file mode 100644
index 9af81dc57..000000000
--- a/console/cache_precache_status_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 TestCmdCachePrecacheStatus(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_precache_status"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_reload_test.go b/console/cache_reload_test.go
deleted file mode 100644
index c0b0199e0..000000000
--- a/console/cache_reload_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 TestCmdCacheReload(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_reload"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_remove_group_test.go b/console/cache_remove_group_test.go
deleted file mode 100644
index 4020dff74..000000000
--- a/console/cache_remove_group_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 TestCmdCacheRemoveGroup(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_remove_group"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_remove_item_test.go b/console/cache_remove_item_test.go
deleted file mode 100644
index 57d43e5ec..000000000
--- a/console/cache_remove_item_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 TestCmdCacheRemoveItem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_remove_item"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cache_stats_test.go b/console/cache_stats_test.go
deleted file mode 100644
index 92aa609c0..000000000
--- a/console/cache_stats_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 TestCmdCacheStats(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cache_stats"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CacheSv1)).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/cdrs_test.go b/console/cdrs_test.go
deleted file mode 100644
index e918a5f89..000000000
--- a/console/cdrs_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 TestCmdCdrs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["cdrs"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CDRsV1)).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/chargers_for_event_test.go b/console/chargers_for_event_test.go
deleted file mode 100644
index 5be956e68..000000000
--- a/console/chargers_for_event_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 TestCmdChargersForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["chargers_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ChargerSv1)).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/chargers_process_event_test.go b/console/chargers_process_event_test.go
deleted file mode 100644
index a9246c1f3..000000000
--- a/console/chargers_process_event_test.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 (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdChargersProcessEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["chargers_process_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ChargerSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-
-}
diff --git a/console/chargers_profile_ids_test.go b/console/chargers_profile_ids_test.go
deleted file mode 100644
index 25332d8a5..000000000
--- a/console/chargers_profile_ids_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdChargersProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["chargers_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/chargers_profile_rem_test.go b/console/chargers_profile_rem_test.go
deleted file mode 100644
index 033e845f2..000000000
--- a/console/chargers_profile_rem_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdChargersProfileRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["chargers_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/chargers_profile_set.go b/console/chargers_profile_set.go
index c43950dee..e5f8bfe57 100644
--- a/console/chargers_profile_set.go
+++ b/console/chargers_profile_set.go
@@ -18,12 +18,7 @@ along with this program. If not, see
package console
-import (
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
+/*
func init() {
c := &CmdSetChargers{
name: "chargers_profile_set",
@@ -64,3 +59,4 @@ func (self *CmdSetChargers) RpcResult() interface{} {
var s string
return &s
}
+*/
diff --git a/console/chargers_profile_set_test.go b/console/chargers_profile_set_test.go
deleted file mode 100644
index b68286943..000000000
--- a/console/chargers_profile_set_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdChargersProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["chargers_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/chargers_profile_test.go b/console/chargers_profile_test.go
deleted file mode 100644
index 2770bda29..000000000
--- a/console/chargers_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 TestCmdChargersProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["chargers_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 parameterme
- 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/command_executer_test.go b/console/command_executer_test.go
deleted file mode 100644
index f97d0323d..000000000
--- a/console/command_executer_test.go
+++ /dev/null
@@ -1,379 +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 (
- "encoding/json"
- "os"
- "reflect"
- "sort"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestToJSON(t *testing.T) {
- jsn := ToJSON(`TimeStart="Test" Crazy = 1 Mama=true coco Test=1`)
- expected := `{"TimeStart":"Test","Crazy":1,"Mama":true,"Test":1}`
- if string(jsn) != expected {
- t.Errorf("Expected: %s got: %s", expected, jsn)
- }
-}
-
-func TestToJSONValid(t *testing.T) {
- jsn := ToJSON(`TimeStart="Test" Crazy = 1 Mama=true coco Test=1`)
- a := make(map[string]interface{})
- if err := json.Unmarshal(jsn, &a); err != nil {
- t.Error("Error unmarshaling generated json: ", err)
- }
-}
-
-func TestToJSONEmpty(t *testing.T) {
- jsn := ToJSON("")
- if string(jsn) != `{}` {
- t.Error("Error empty: ", string(jsn))
- }
-}
-
-func TestToJSONString(t *testing.T) {
- jsn := ToJSON("1002")
- if string(jsn) != `{"Item":"1002"}` {
- t.Error("Error string: ", string(jsn))
- }
-}
-
-func TestToJSONArrayNoSpace(t *testing.T) {
- jsn := ToJSON(`Param=["id1","id2","id3"] Another="Patram"`)
- if string(jsn) != `{"Param":["id1","id2","id3"],"Another":"Patram"}` {
- t.Error("Error string: ", string(jsn))
- }
-}
-
-func TestToJSONArraySpace(t *testing.T) {
- jsn := ToJSON(`Param=["id1", "id2", "id3"] Another="Patram"`)
- if string(jsn) != `{"Param":["id1", "id2", "id3"],"Another":"Patram"}` {
- t.Error("Error string: ", string(jsn))
- }
-}
-
-func TestFromJSON(t *testing.T) {
- line := FromJSON([]byte(`{"TimeStart":"Test","Crazy":1,"Mama":true,"Test":1}`), []string{"TimeStart", "Crazy", "Mama", "Test"})
- expected := `TimeStart="Test" Crazy=1 Mama=true Test=1`
- if line != expected {
- t.Errorf("Expected: %s got: '%s'", expected, line)
- }
-}
-
-func TestFromJSONInterestingFields(t *testing.T) {
- line := FromJSON([]byte(`{"TimeStart":"Test","Crazy":1,"Mama":true,"Test":1}`), []string{"TimeStart", "Test"})
- expected := `TimeStart="Test" Test=1`
- if line != expected {
- t.Errorf("Expected: %s got: '%s'", expected, line)
- }
-}
-
-func TestFromJSONString(t *testing.T) {
- line := FromJSON([]byte(`1002`), []string{"string"})
- expected := `"1002"`
- if line != expected {
- t.Errorf("Expected: %s got: '%s'", expected, line)
- }
-}
-
-func TestFromJSONArrayNoSpace(t *testing.T) {
- line := FromJSON([]byte(`{"Param":["id1","id2","id3"], "TimeStart":"Test", "Test":1}`), []string{"Param", "TimeStart", "Test"})
- expected := `Param=["id1","id2","id3"] TimeStart="Test" Test=1`
- if line != expected {
- t.Errorf("Expected: %s got: '%s'", expected, line)
- }
-}
-
-func TestFromJSONArraySpace(t *testing.T) {
- line := FromJSON([]byte(`{"Param":["id1", "id2", "id3"], "TimeStart":"Test", "Test":1}`), []string{"Param", "TimeStart", "Test"})
- expected := `Param=["id1", "id2", "id3"] TimeStart="Test" Test=1`
- if line != expected {
- t.Errorf("Expected: %s got: '%s'", expected, line)
- }
-}
-
-func TestGetStringValue(t *testing.T) {
- dflt := utils.StringSet{}
- expected := "10"
- if rply := getStringValue(int64(10), dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = "true"
- if rply := getStringValue(true, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = "null"
- if rply := getStringValue(nil, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = "10.5"
- if rply := getStringValue(10.5, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = "[10,5]"
- if rply := getStringValue([]float32{10, 5}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = `{"ID":"id1","TimeValue":10000}`
- if rply := getStringValue(struct {
- ID string
- TimeValue int64
- }{ID: "id1", TimeValue: 10000}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- if rply := getStringValue(map[string]interface{}{
- "ID": "id1",
- "TimeValue": 10000}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = `{"ID":"id1","TimeValue":"1s"}`
- if rply := getStringValue(map[string]interface{}{
- "ID": "id1",
- "TimeValue": int64(time.Second)}, utils.StringSet{"TimeValue": {}}); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = "[10,20,30]"
- if rply := getSliceAsString([]interface{}{10, 20, 30}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-}
-
-func TestGetSliceAsString(t *testing.T) {
- dflt := utils.StringSet{}
- expected := "[10,20,30]"
- if rply := getSliceAsString([]interface{}{10, 20, 30}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = `["test1","test2","test3"]`
- if rply := getSliceAsString([]interface{}{"test1", "test2", "test3"}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-}
-
-func TestGetMapAsString(t *testing.T) {
- dflt := utils.StringSet{}
- expected := `{"ID":"id1","TimeValue":10000}`
- if rply := getStringValue(map[string]interface{}{
- "ID": "id1",
- "TimeValue": 10000}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = `{"ID":"id1","TimeValue":"1s"}`
- if rply := getStringValue(map[string]interface{}{
- "ID": "id1",
- "TimeValue": int64(time.Second)}, utils.StringSet{"TimeValue": {}}); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-}
-
-func TestGetFormatedResult(t *testing.T) {
- dflt := utils.StringSet{}
- expected := `{
- "ID": "id1",
- "TimeValue": 10000
-}`
- if rply := GetFormatedResult(map[string]interface{}{
- "ID": "id1",
- "TimeValue": 10000}, dflt); rply != expected {
- t.Errorf("Expecting: %q , received: %q", expected, rply)
- }
-
- expected = `{
- "ID": "id1",
- "TimeValue": "1s"
-}`
- if rply := GetFormatedResult(map[string]interface{}{
- "ID": "id1",
- "TimeValue": int64(time.Second)}, utils.StringSet{"TimeValue": {}}); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = `{
- "ID": "id1",
- "TimeValue": 10000
-}`
- if rply := GetFormatedResult(struct {
- ID string
- TimeValue int64
- }{ID: "id1", TimeValue: 10000}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-}
-
-func TestGetFormatedSliceResult(t *testing.T) {
- dflt := utils.StringSet{}
- expected := "[10,20,30]"
- if rply := getSliceAsString([]interface{}{10, 20, 30}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-
- expected = `["test1","test2","test3"]`
- if rply := getSliceAsString([]interface{}{"test1", "test2", "test3"}, dflt); rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-}
-
-func TestFromJSONInterestingFields2(t *testing.T) {
- jsn := utils.ToJSON(&utils.TenantIDWithAPIOpts{
- TenantID: new(utils.TenantID),
- APIOpts: make(map[string]interface{}),
- })
-
- line := FromJSON([]byte(jsn), []string{"Tenant", "ID", "APIOpts"})
- expected := `Tenant="" ID="" APIOpts={}`
- if line != expected {
- t.Log(jsn)
- t.Errorf("Expected: %s got: '%s'", expected, line)
- }
-}
-
-func TestGetStringValueInterface(t *testing.T) {
- dflt := utils.StringSet{}
- expected := getSliceAsString([]interface{}{}, dflt)
- rply := getStringValue([]interface{}{}, dflt)
- if rply != expected {
- t.Errorf("Expecting: %s , received: %s", expected, rply)
- }
-}
-
-func TestGetFormatedSliceResultCase2(t *testing.T) {
- dflt := utils.StringSet{}
- rply := GetFormatedSliceResult(true, dflt)
- expected := true
- if reflect.DeepEqual(expected, rply) {
- t.Errorf("Expecting: %+v , received: %+v", expected, rply)
- }
-}
-
-func TestCommandExecuterUsage(t *testing.T) {
- testStruct := &CommandExecuter{}
- testStruct.command = commands["accounts"]
- result := testStruct.Usage()
- expected := "\n\tUsage: accounts APIOpts=null \n"
- if !reflect.DeepEqual(expected, result) {
- t.Errorf("Expected <%+q>, Received <%+q>", expected, result)
- }
-
-}
-
-func TestCommandExecuterLocalExecute(t *testing.T) {
- testStruct := &CommandExecuter{}
- testStruct.command = commands["accounts"]
- result := testStruct.LocalExecute()
- expected := utils.EmptyString
- if !reflect.DeepEqual(expected, result) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
- }
-}
-
-func TestCommandExecuterLocalFromArgs(t *testing.T) {
- null, _ := os.Open(os.DevNull)
- stdout := os.Stdout
- os.Stdout = null
- testStruct := &CommandExecuter{}
- testStruct.command = commands["status"]
- cmdArgs := "argument_test"
- result := testStruct.FromArgs(cmdArgs, true)
- if !reflect.DeepEqual(nil, result) {
- t.Errorf("Expected <%+v>, Received <%+v>", nil, result)
- }
- os.Stdout = stdout
-}
-
-type mockCommandExecuter struct {
- Commander
-}
-
-func (*mockCommandExecuter) Name() string {
- return utils.EmptyString
-}
-
-func (*mockCommandExecuter) RpcMethod() string {
- return utils.EmptyString
-}
-
-func (*mockCommandExecuter) RpcParams(reset bool) interface{} {
- return struct{}{}
-}
-
-func (*mockCommandExecuter) PostprocessRpcParams() error {
- return nil
-}
-
-func (*mockCommandExecuter) RpcResult() interface{} {
- return nil
-}
-
-func (*mockCommandExecuter) ClientArgs() (args []string) {
- return
-}
-
-func TestCommandExecuterLocalFromArgsCase2(t *testing.T) {
- testStruct := &CommandExecuter{new(mockCommandExecuter)}
- cmdArgs := "argument_test"
- err := testStruct.FromArgs(cmdArgs, true)
- expected := "json: Unmarshal(non-pointer struct {})"
- if err == nil || err.Error() != expected {
- t.Errorf("\nExpected <%+v>, \nRecevied <%+v>", expected, err)
- }
-}
-
-func TestCommandExecuterClientArgs(t *testing.T) {
- testStruct := &CommandExecuter{}
- testStruct.command = commands["accounts"]
- result := testStruct.clientArgs(testStruct.command.RpcParams(true))
- expected := []string{"APIOpts", "ID", "Tenant"}
- sort.Strings(result)
- if !reflect.DeepEqual(expected, result) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
- }
-}
-
-type mockTest struct {
- a int
- B *bool
- C struct {
- }
- D time.Time
-}
-
-func TestCommandExecuterClientArgsCase(t *testing.T) {
- testStruct := &CommandExecuter{}
- testStruct.command = commands["accounts"]
- result := testStruct.clientArgs(new(mockTest))
- expected := []string{"B", "D"}
- sort.Strings(result)
- if !reflect.DeepEqual(expected, result) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
- }
-}
diff --git a/console/command_test.go b/console/command_test.go
deleted file mode 100644
index 8baf22189..000000000
--- a/console/command_test.go
+++ /dev/null
@@ -1,175 +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"
- "testing"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdGetCommands(t *testing.T) {
- expected := commands
- result := GetCommands()
- if !reflect.DeepEqual(result, expected) {
- t.Errorf("\nExpected <%+v>,\nReceived <%+v>", expected, result)
- }
-}
-
-func TestGetAvailableCommandsErr(t *testing.T) {
- err := getAvailabelCommandsErr()
- if err == nil {
- t.Errorf("\nExpected not nil,\nReceived <%+v>", err)
- }
-}
-
-func TestGetCommandValueCase1(t *testing.T) {
- expected := &CmdGetChargersForEvent{
- name: "chargers_for_event",
- rpcMethod: utils.ChargerSv1GetChargersForEvent,
- rpcParams: &utils.CGREvent{},
- }
- result, err := GetCommandValue("chargers_for_event", false)
- if err != nil {
- t.Fatal(err)
- }
- if !reflect.DeepEqual(utils.ToJSON(result), utils.ToJSON(expected)) {
- t.Errorf("\nExpected <%+v>,\nReceived <%+v>", utils.ToJSON(result), utils.ToJSON(expected))
- }
-}
-
-func TestGetCommandValueCase2(t *testing.T) {
- _, err := GetCommandValue("", false)
- if err == nil {
- t.Fatal(err)
- }
-}
-
-func TestGetCommandValueCase3(t *testing.T) {
- _, err := GetCommandValue("false_command", false)
- if err == nil {
- t.Fatal(err)
- }
-}
-
-func TestGetCommandValueCase4(t *testing.T) {
- _, err := GetCommandValue("chargers _for_event", false)
- if err == nil {
- t.Fatal(err)
- }
-}
-
-type mockCommander struct {
- Commander
-}
-
-func (*mockCommander) FromArgs(args string, verbose bool) error {
- return nil
-}
-
-func (*mockCommander) Usage() string {
- return utils.EmptyString
-}
-
-func (*mockCommander) RpcMethod() string {
- return utils.EmptyString
-}
-func (*mockCommander) RpcParams(bool) interface{} {
- return nil
-}
-
-func (*mockCommander) PostprocessRpcParams() error {
- return utils.ErrNotImplemented
-}
-
-func (*mockCommander) RpcResult() interface{} {
- return nil
-}
-func (*mockCommander) ClientArgs() []string {
- return []string{}
-}
-func (*mockCommander) Name() string {
- return utils.EmptyString
-}
-func (*mockCommander) LocalExecute() string {
- return utils.EmptyString
-}
-func (*mockCommander) GetFormatedResult(result interface{}) string {
- return utils.EmptyString
-}
-
-func TestGetCommandValueCase5(t *testing.T) {
- commands["chargers_for_event"] = new(mockCommander)
- _, err := GetCommandValue("chargers_for_event", true)
- if !reflect.DeepEqual(utils.ErrNotImplemented, err) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.ErrNotImplemented, err)
- }
-}
-
-type mockCommander2 struct {
- Commander
-}
-
-func (*mockCommander2) FromArgs(args string, verbose bool) error {
- return utils.ErrNotImplemented
-}
-
-func (*mockCommander2) Usage() string {
- return utils.EmptyString
-}
-
-func (*mockCommander2) RpcMethod() string {
- return utils.EmptyString
-}
-func (*mockCommander2) RpcParams(bool) interface{} {
- return nil
-}
-
-func (*mockCommander2) PostprocessRpcParams() error {
- return nil
-}
-
-func (*mockCommander2) RpcResult() interface{} {
- return nil
-}
-
-func (*mockCommander2) ClientArgs() []string {
- return []string{}
-}
-
-func (*mockCommander2) Name() string {
- return utils.EmptyString
-}
-
-func (*mockCommander2) LocalExecute() string {
- return utils.EmptyString
-}
-
-func (*mockCommander2) GetFormatedResult(result interface{}) string {
- return utils.EmptyString
-}
-
-func TestGetCommandValueCase6(t *testing.T) {
- commands["test"] = new(mockCommander2)
- _, err := GetCommandValue("test", true)
- if !reflect.DeepEqual(utils.ErrNotImplemented, err) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.ErrNotImplemented, err)
- }
-}
diff --git a/console/compute_filter_indexes_test.go b/console/compute_filter_indexes_test.go
deleted file mode 100644
index 17947664b..000000000
--- a/console/compute_filter_indexes_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdComputeFilterIndexes(t *testing.T) {
- // commands map is initiated in init function
- command := commands["compute_filter_indexes"]
- // 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/datadb_versions_test.go b/console/datadb_versions_test.go
deleted file mode 100644
index 8dbb84836..000000000
--- a/console/datadb_versions_test.go
+++ /dev/null
@@ -1,59 +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 TestCmdDataDBVersions(t *testing.T) {
- // commands map is initiated in init function
- command := commands["datadb_versions"]
- // 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 ")
- }
-
- // for coverage purpose
- result := command.RpcParams(false)
- if !reflect.DeepEqual(result, new(EmptyWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result)
- }
- // 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)
- }
- // for coverage purpose
- if err := command.ClientArgs(); err != nil {
- t.Fatal(err)
- }
-}
diff --git a/console/destination_set_test.go b/console/destination_set_test.go
deleted file mode 100644
index 134bc8c0f..000000000
--- a/console/destination_set_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdDestinationSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["destination_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/destinations.go b/console/destinations.go
index 7fab9e81c..d33fbcb61 100644
--- a/console/destinations.go
+++ b/console/destinations.go
@@ -18,8 +18,8 @@ along with this program. If not, see
package console
+/*
import (
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -64,3 +64,4 @@ func (self *CmdGetDestination) RpcResult() interface{} {
a := make([]*engine.Destination, 0)
return &a
}
+*/
diff --git a/console/destinations_test.go b/console/destinations_test.go
deleted file mode 100644
index 00fe47104..000000000
--- a/console/destinations_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"
-
- v2 "github.com/cgrates/cgrates/apier/v2"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdDestinations(t *testing.T) {
- // commands map is initiated in init function
- command := commands["destinations"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v2.APIerSv2)).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/dispatchers_for_event_test.go b/console/dispatchers_for_event_test.go
deleted file mode 100644
index b4e7309df..000000000
--- a/console/dispatchers_for_event_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 TestCmdDispatchersForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatches_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.DispatcherSv1)).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/dispatchers_host_ids_test.go b/console/dispatchers_host_ids_test.go
deleted file mode 100644
index 23664569c..000000000
--- a/console/dispatchers_host_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 TestCmdDispatchersHostIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_host_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/dispatchers_host_rem_test.go b/console/dispatchers_host_rem_test.go
deleted file mode 100644
index 0b91a8ce5..000000000
--- a/console/dispatchers_host_rem_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 TestCmdDispatchersHostRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_host_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/dispatchers_host_set_test.go b/console/dispatchers_host_set_test.go
deleted file mode 100644
index 907ac00c9..000000000
--- a/console/dispatchers_host_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 TestCmdDispatchersHostSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_host_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/dispatchers_host_test.go b/console/dispatchers_host_test.go
deleted file mode 100644
index 039764729..000000000
--- a/console/dispatchers_host_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 TestCmdDispatchersHost(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_host"]
- // 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/dispatchers_profile_ids_test.go b/console/dispatchers_profile_ids_test.go
deleted file mode 100644
index 942d8a8bc..000000000
--- a/console/dispatchers_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 TestCmdDispatchersProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_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/dispatchers_profile_rem_test.go b/console/dispatchers_profile_rem_test.go
deleted file mode 100644
index f798d7859..000000000
--- a/console/dispatchers_profile_rem_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 TestCmdDispatchersProfileRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_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/dispatchers_profile_set.go b/console/dispatchers_profile_set.go
index 003afa072..2dcd5a7cc 100644
--- a/console/dispatchers_profile_set.go
+++ b/console/dispatchers_profile_set.go
@@ -18,8 +18,8 @@ along with this program. If not, see
package console
+/*
import (
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -67,3 +67,4 @@ func (self *CmdSetDispatcherProfile) RpcResult() interface{} {
var s string
return &s
}
+*/
diff --git a/console/dispatchers_profile_set_test.go b/console/dispatchers_profile_set_test.go
deleted file mode 100644
index 4a1596735..000000000
--- a/console/dispatchers_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 TestCmdDispatchersProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_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/dispatchers_profile_test.go b/console/dispatchers_profile_test.go
deleted file mode 100644
index e4a3339a2..000000000
--- a/console/dispatchers_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 TestCmdDispatchersProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["dispatchers_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/console/filter_ids_test.go b/console/filter_ids_test.go
deleted file mode 100644
index c57c6180a..000000000
--- a/console/filter_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 TestCmdFilterIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["filter_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/filter_indexes.go b/console/filter_indexes.go
old mode 100755
new mode 100644
index 14e45e090..da50bf8bd
--- a/console/filter_indexes.go
+++ b/console/filter_indexes.go
@@ -18,8 +18,8 @@ along with this program. If not, see
package console
+/*
import (
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
@@ -64,3 +64,4 @@ func (self *CmdGetFilterIndexes) RpcResult() interface{} {
var atr []string
return &atr
}
+*/
diff --git a/console/filter_indexes_remove.go b/console/filter_indexes_remove.go
index 694ea2c02..d43c3a029 100644
--- a/console/filter_indexes_remove.go
+++ b/console/filter_indexes_remove.go
@@ -18,11 +18,7 @@ along with this program. If not, see
package console
-import (
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/utils"
-)
-
+/*
func init() {
c := &CmdRemoveFilterIndexes{
name: "filter_indexes_remove",
@@ -64,3 +60,4 @@ func (self *CmdRemoveFilterIndexes) RpcResult() interface{} {
var atr string
return &atr
}
+*/
diff --git a/console/filter_indexes_remove_test.go b/console/filter_indexes_remove_test.go
deleted file mode 100644
index 75e5aa9ae..000000000
--- a/console/filter_indexes_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 TestCmdFilterIndexesRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["filter_indexes_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/filter_indexes_test.go b/console/filter_indexes_test.go
deleted file mode 100644
index 124f0272f..000000000
--- a/console/filter_indexes_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 TestCmdFilterIndexes(t *testing.T) {
- // commands map is initiated in init function
- command := commands["filter_indexes"]
- // 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/filter_remove_test.go b/console/filter_remove_test.go
deleted file mode 100644
index bc35e3746..000000000
--- a/console/filter_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 TestCmdFilterRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["filter_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/filter_set_test.go b/console/filter_set_test.go
deleted file mode 100644
index 318e7244a..000000000
--- a/console/filter_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 TestCmdFilterSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["filter_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/filter_test.go b/console/filter_test.go
deleted file mode 100644
index 76162514f..000000000
--- a/console/filter_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 TestCmdFilter(t *testing.T) {
- // commands map is initiated in init function
- command := commands["filter"]
- // 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/get_json_section_test.go b/console/get_json_section_test.go
deleted file mode 100644
index 28a53f9d8..000000000
--- a/console/get_json_section_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 TestCmdGetJSONSection(t *testing.T) {
- // commands map is initiated in init function
- command := commands["get_json_section"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ConfigSv1)).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/import_tp_from_folder_test.go b/console/import_tp_from_folder_test.go
deleted file mode 100644
index c8ca0f4af..000000000
--- a/console/import_tp_from_folder_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 TestCmdTPFromFolder(t *testing.T) {
- // commands map is initiated in init function
- command := commands["import_tp_from_folder"]
- // 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/load_history_test.go b/console/load_history_test.go
deleted file mode 100644
index 6a0d7445a..000000000
--- a/console/load_history_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 TestCmdLoadHistory(t *testing.T) {
- // commands map is initiated in init function
- command := commands["load_history"]
- // 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/load_ids_test.go b/console/load_ids_test.go
deleted file mode 100644
index a58775588..000000000
--- a/console/load_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 TestCmdLoadIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["get_load_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 ")
- }
- // for coverage purpose
- result := command.RpcParams(false)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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/load_times.go b/console/load_times.go
index 9f3dfc4e8..2e8a94bc7 100644
--- a/console/load_times.go
+++ b/console/load_times.go
@@ -18,8 +18,8 @@ along with this program. If not, see
package console
+/*
import (
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
@@ -64,3 +64,4 @@ func (self *CmdLoadTimes) RpcResult() interface{} {
a := make(map[string]string, 0)
return &a
}
+*/
diff --git a/console/load_times_test.go b/console/load_times_test.go
deleted file mode 100644
index 8126e398b..000000000
--- a/console/load_times_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 TestCmdLoadTimes(t *testing.T) {
- // commands map is initiated in init function
- command := commands["get_load_times"]
- // 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/load_tp_from_folder_test.go b/console/load_tp_from_folder_test.go
deleted file mode 100644
index 9936202b7..000000000
--- a/console/load_tp_from_folder_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 TestCmdLoadTPFromFolder(t *testing.T) {
- // commands map is initiated in init function
- command := commands["load_tp_from_folder"]
- // 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/load_tp_from_stordb.go b/console/load_tp_from_stordb.go
index 55de48873..dec32b8f7 100644
--- a/console/load_tp_from_stordb.go
+++ b/console/load_tp_from_stordb.go
@@ -18,8 +18,8 @@ along with this program. If not, see
package console
+/*
import (
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
@@ -64,3 +64,4 @@ func (self *LoadTpFromStorDb) RpcResult() interface{} {
var s string
return &s
}
+*/
diff --git a/console/load_tp_from_stordb_test.go b/console/load_tp_from_stordb_test.go
deleted file mode 100644
index 0319f831a..000000000
--- a/console/load_tp_from_stordb_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 TestCmdLoadTPFromStorDB(t *testing.T) {
- // commands map is initiated in init function
- command := commands["load_tp_from_stordb"]
- // 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/loader_load.go b/console/loader_load.go
old mode 100755
new mode 100644
diff --git a/console/loader_load_test.go b/console/loader_load_test.go
deleted file mode 100644
index c8911a6f7..000000000
--- a/console/loader_load_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 TestCmdLoaderLoad(t *testing.T) {
- // commands map is initiated in init function
- command := commands["loader_load"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.LoaderSv1)).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/loader_remove.go b/console/loader_remove.go
old mode 100755
new mode 100644
diff --git a/console/loader_remove_test.go b/console/loader_remove_test.go
deleted file mode 100644
index c069417eb..000000000
--- a/console/loader_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 TestCmdLoaderRemove(t *testing.T) {
- // commands map is initiated in init function
- command := commands["loader_remove"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.LoaderSv1)).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/parse_test.go b/console/parse_test.go
deleted file mode 100644
index 3a7ae18a7..000000000
--- a/console/parse_test.go
+++ /dev/null
@@ -1,137 +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"
- "testing"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdParse(t *testing.T) {
- // commands map is initiated in init function
- command := commands["parse"]
-
- // for coverage purpose
- expected := command.Name()
- if !reflect.DeepEqual(expected, "parse") {
- t.Errorf("Expected <%+v>, Received <%+v>", "parse", expected)
- }
-
- // for coverage purpose
- expected = command.RpcMethod()
- if !reflect.DeepEqual(expected, utils.EmptyString) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.EmptyString, expected)
- }
-
- // for coverage purpose
- expected2 := command.RpcParams(true)
- if !reflect.DeepEqual(expected2, &AttrParse{}) {
- t.Errorf("Expected <%+v>, Received <%+v>", &AttrParse{}, expected2)
- }
-
- // for coverage purpose
- if err := command.RpcResult(); err != nil {
- t.Fatal(err)
- }
-
- // for coverage purpose
- if err := command.PostprocessRpcParams(); err != nil {
- t.Fatal(err)
- }
-
-}
-func TestCmdParseLocalExecuteCase1(t *testing.T) {
- // for coverage purpose
- testStruct := &CmdParse{
- rpcParams: &AttrParse{
- Expression: "",
- Value: "",
- },
- }
-
- result := testStruct.LocalExecute()
- expected := "Empty expression error"
- if !reflect.DeepEqual(result, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
- }
-
-}
-func TestCmdParseLocalExecuteCase2(t *testing.T) {
- // for coverage purpose
- testStruct := &CmdParse{
- rpcParams: &AttrParse{
- Expression: "test_exp",
- Value: "",
- },
- }
-
- result := testStruct.LocalExecute()
- expected := "Empty value error"
- if !reflect.DeepEqual(result, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
- }
-}
-
-func TestCmdParseLocalExecuteCase3(t *testing.T) {
- // for coverage purpose
- testStruct := &CmdParse{
- rpcParams: &AttrParse{
- Expression: "test_exp",
- Value: "test_val",
- },
- }
-
- result := testStruct.LocalExecute()
- expected := "test_exp"
- if !reflect.DeepEqual(result, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, result)
- }
-}
-
-func TestCmdParseLocalExecuteCase4(t *testing.T) {
- // for coverage purpose
- testStruct := &CmdParse{
- rpcParams: &AttrParse{
- Expression: "~*req.Field{*}",
- Value: "~*req.Field{*}",
- },
- }
- err := testStruct.LocalExecute()
- expected := "invalid converter value in string: <*>, err: unsupported converter definition: <*>"
- if !reflect.DeepEqual(err, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, err)
- }
-}
-
-func TestCmdParseLocalExecuteCase5(t *testing.T) {
- // for coverage purpose
- testStruct := &CmdParse{
- rpcParams: &AttrParse{
- Expression: "~*req.Field{*duration}",
- Value: "a",
- },
- }
- expected := "time: invalid duration \"a\""
- received := testStruct.LocalExecute()
- if !reflect.DeepEqual(received, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, received)
- }
-}
diff --git a/console/passive_sessions_test.go b/console/passive_sessions_test.go
deleted file mode 100644
index 6de89eb22..000000000
--- a/console/passive_sessions_test.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 (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdPassiveSessions(t *testing.T) {
- // commands map is initiated in init function
- command := commands["passive_sessions"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedSliceResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- utils.DurationIndex: {},
- utils.MaxRateUnit: {},
- utils.DebitInterval: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/ping.go b/console/ping.go
index efa63b979..5f2fb1255 100644
--- a/console/ping.go
+++ b/console/ping.go
@@ -73,8 +73,8 @@ func (self *CmdApierPing) RpcMethod() string {
return utils.AnalyzerSv1Ping
case utils.ReplicatorLow:
return utils.ReplicatorSv1Ping
- case utils.ApierSLow:
- return utils.APIerSv1Ping
+ // case utils.ApierSLow:
+ // return utils.APIerSv1Ping
case utils.EEsLow:
return utils.EeSv1Ping
case utils.RateSLow:
diff --git a/console/ping_test.go b/console/ping_test.go
deleted file mode 100644
index 26239ac4a..000000000
--- a/console/ping_test.go
+++ /dev/null
@@ -1,555 +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 TestCmdPingRoutesLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.RoutesLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.RouteSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.RouteSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.RouteSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingAttributesLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.AttributesLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.AttributeSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.AttributeSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.AttributeSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-
-}
-
-func TestCmdPingChargerSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.ChargerSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.ChargerSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.ChargerSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.ChargerSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-
-}
-
-func TestCmdPingResourcesLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.ResourcesLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.ResourceSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.ResourceSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.ResourceSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-
-}
-
-func TestCmdPingStatServiceLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.StatServiceLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.StatSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.StatSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.StatSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingThresholdsLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.ThresholdsLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.ThresholdSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.ThresholdSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.ThresholdSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingSessionsLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.SessionsLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.SessionSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.SessionSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingLoaderSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.LoaderSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.LoaderSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.LoaderSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.LoaderSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingDispatcherSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.DispatcherSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.DispatcherSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.DispatcherSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.DispatcherSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingAnalyzerSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.AnalyzerSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.AnalyzerSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.AnalyzerSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.AnalyzerSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingApierSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.ApierSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.APIerSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.APIerSv1Ping, result2)
- }
- 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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingEEsLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.EEsLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.EeSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.EeSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.EeSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1])
- if !ok {
- t.Fatal("method not found")
- }
- if m.Type.NumIn() != 4 { // ApierSv1 is consider and we expect 3 inputs
- t.Fatalf("invalid number of input parameters ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // verify the type of output parameter
- if ok := m.Type.In(3).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok {
- t.Fatalf("cannot assign output parameter")
- }
- // for coverage purpose
- if err := command.PostprocessRpcParams(); err != nil {
- t.Fatal(err)
- }
-}
-
-func TestCmdPingRateSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.RateSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.RateSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.RateSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.RateSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingAccountSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.AccountSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.AccountSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.AccountSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.AccountSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingActionSLow(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = utils.ActionSLow
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, utils.ActionSv1Ping) {
- t.Errorf("Expected <%+v>, Received <%+v>", utils.ActionSv1Ping, result2)
- }
- m, ok := reflect.TypeOf(new(v1.ActionSv1)).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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(StringWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result)
- }
- // 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)
- }
-}
-
-func TestCmdPingTestDefault(t *testing.T) {
- // commands map is initiated in init function
- command := commands["ping"]
- castCommand, canCast := command.(*CmdApierPing)
- if !canCast {
- t.Fatalf("cannot cast")
- }
- castCommand.item = "test_item"
- result2 := command.RpcMethod()
- if !reflect.DeepEqual(result2, "") {
- t.Errorf("Expected <%+v>, Received <%+v>", "", result2)
- }
-}
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_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_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/console/reload_config_test.go b/console/reload_config_test.go
deleted file mode 100644
index d4433789c..000000000
--- a/console/reload_config_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 TestCmdReloadConfig(t *testing.T) {
- // commands map is initiated in init function
- command := commands["reload_config"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ConfigSv1)).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/resources_allocate_test.go b/console/resources_allocate_test.go
deleted file mode 100644
index f084567f6..000000000
--- a/console/resources_allocate_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 TestCmdResourcesAllocate(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_allocate"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ResourceSv1)).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/resources_authorize_test.go b/console/resources_authorize_test.go
deleted file mode 100644
index 1a46281a6..000000000
--- a/console/resources_authorize_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 TestCmdResourcesAuthorize(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_authorize"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ResourceSv1)).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/resources_for_event_test.go b/console/resources_for_event_test.go
deleted file mode 100644
index 4600fb46a..000000000
--- a/console/resources_for_event_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 TestCmdResourcesForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ResourceSv1)).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/resources_profile_ids_test.go b/console/resources_profile_ids_test.go
deleted file mode 100644
index a8a6492ba..000000000
--- a/console/resources_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 TestCmdResourcesProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_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/resources_profile_rem_test.go b/console/resources_profile_rem_test.go
deleted file mode 100644
index 1aec01b00..000000000
--- a/console/resources_profile_rem_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 TestCmdResourcesProfileRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_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/resources_profile_set_test.go b/console/resources_profile_set_test.go
deleted file mode 100644
index 08d8366ac..000000000
--- a/console/resources_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 TestCmdResourcesProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_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/resources_profiles_test.go b/console/resources_profiles_test.go
deleted file mode 100644
index 02132753b..000000000
--- a/console/resources_profiles_test.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 (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdResourcesProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.UsageTTL: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/resources_release_test.go b/console/resources_release_test.go
deleted file mode 100644
index 9a2e638b3..000000000
--- a/console/resources_release_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 TestCmdResourcesRelease(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources_release"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ResourceSv1)).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/resources_test.go b/console/resources_test.go
deleted file mode 100644
index 9bd743964..000000000
--- a/console/resources_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 TestCmdResources(t *testing.T) {
- // commands map is initiated in init function
- command := commands["resources"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ResourceSv1)).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/routes_profile_ids_test.go b/console/routes_profile_ids_test.go
deleted file mode 100644
index 6607b81a9..000000000
--- a/console/routes_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 TestCmdRoutesProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["route_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/routes_profile_remove_test.go b/console/routes_profile_remove_test.go
deleted file mode 100644
index a40c444ed..000000000
--- a/console/routes_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 TestCmdRoutesProfileRemove(t *testing.T) {
- // commands map is initiated in init function
- command := commands["routes_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/routes_profile_set.go b/console/routes_profile_set.go
index b400f4d97..48bd29f90 100644
--- a/console/routes_profile_set.go
+++ b/console/routes_profile_set.go
@@ -18,12 +18,7 @@ along with this program. If not, see
package console
-import (
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
+/*
func init() {
c := &CmdSetRoute{
name: "routes_profile_set",
@@ -67,3 +62,4 @@ func (self *CmdSetRoute) RpcResult() interface{} {
var s string
return &s
}
+*/
diff --git a/console/routes_profile_set_test.go b/console/routes_profile_set_test.go
deleted file mode 100644
index 5355da554..000000000
--- a/console/routes_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 TestCmdRoutesProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["routes_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/routes_profile_test.go b/console/routes_profile_test.go
deleted file mode 100644
index 037d01354..000000000
--- a/console/routes_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 TestCmdRoutesProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["routes_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/console/routes_profiles_for_event_test.go b/console/routes_profiles_for_event_test.go
deleted file mode 100644
index 3d6a45834..000000000
--- a/console/routes_profiles_for_event_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 TestCmdRoutesProfilesForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["routes_profiles_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.RouteSv1)).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/routes_test.go b/console/routes_test.go
deleted file mode 100644
index 6e61cdfee..000000000
--- a/console/routes_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 TestCmdRoutes(t *testing.T) {
- // commands map is initiated in init function
- command := commands["routes"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.RouteSv1)).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/session_authorize_event_test.go b/console/session_authorize_event_test.go
deleted file mode 100644
index 6333d51e9..000000000
--- a/console/session_authorize_event_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 TestCmdSessionAuthorizeEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["session_authorize_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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/session_initiate_test.go b/console/session_initiate_test.go
deleted file mode 100644
index 263526a39..000000000
--- a/console/session_initiate_test.go
+++ /dev/null
@@ -1,63 +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 TestCmdSessionInitiate(t *testing.T) {
- // commands map is initiated in init function
- command := commands["session_initiate"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- utils.CapMaxUsage: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/session_process_cdr_test.go b/console/session_process_cdr_test.go
deleted file mode 100644
index 6fbb544d8..000000000
--- a/console/session_process_cdr_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 TestCmdSessionProcessCDR(t *testing.T) {
- // commands map is initiated in init function
- command := commands["session_process_cdr"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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/session_process_message_test.go b/console/session_process_message_test.go
deleted file mode 100644
index a6b2ad150..000000000
--- a/console/session_process_message_test.go
+++ /dev/null
@@ -1,63 +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 TestCmdSessionProcessMessage(t *testing.T) {
- // commands map is initiated in init function
- command := commands["session_process_message"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- utils.CapMaxUsage: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/session_terminate_test.go b/console/session_terminate_test.go
deleted file mode 100644
index 2014da8be..000000000
--- a/console/session_terminate_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 TestCmdSessionTerminate(t *testing.T) {
- // commands map is initiated in init function
- command := commands["session_terminate"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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/session_update_test.go b/console/session_update_test.go
deleted file mode 100644
index 080b2840a..000000000
--- a/console/session_update_test.go
+++ /dev/null
@@ -1,63 +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 TestCmdSessionUpdate(t *testing.T) {
- // commands map is initiated in init function
- command := commands["session_update"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.SessionSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.Usage: {},
- utils.CapMaxUsage: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/set_datadb_versions.go b/console/set_datadb_versions.go
index b2a769fd1..014adb78f 100644
--- a/console/set_datadb_versions.go
+++ b/console/set_datadb_versions.go
@@ -18,8 +18,8 @@ along with this program. If not, see
package console
+/*
import (
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
@@ -63,3 +63,4 @@ func (self *CmdSetDataDBVersions) RpcResult() interface{} {
var atr string
return &atr
}
+*/
diff --git a/console/set_datadb_versions_test.go b/console/set_datadb_versions_test.go
deleted file mode 100644
index fd047f755..000000000
--- a/console/set_datadb_versions_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdSetDataDBVersions(t *testing.T) {
- // commands map is initiated in init function
- command := commands["set_datadb_versions"]
- // 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/set_stordb_versions.go b/console/set_stordb_versions.go
index 8a4658b7b..7b81a3a56 100644
--- a/console/set_stordb_versions.go
+++ b/console/set_stordb_versions.go
@@ -18,11 +18,7 @@ along with this program. If not, see
package console
-import (
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/utils"
-)
-
+/*
func init() {
c := &CmdSetStorDBVersions{
name: "set_stordb_versions",
@@ -63,3 +59,4 @@ func (self *CmdSetStorDBVersions) RpcResult() interface{} {
var atr string
return &atr
}
+*/
diff --git a/console/set_stordb_versions_test.go b/console/set_stordb_versions_test.go
deleted file mode 100644
index 0b71c22df..000000000
--- a/console/set_stordb_versions_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdSetStorDBVersions(t *testing.T) {
- // commands map is initiated in init function
- command := commands["set_stordb_versions"]
- // 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/sleep_test.go b/console/sleep_test.go
deleted file mode 100644
index 561b2b196..000000000
--- a/console/sleep_test.go
+++ /dev/null
@@ -1,70 +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 TestCmdSleep(t *testing.T) {
- // commands map is initiated in init function
- command := commands["sleep"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CoreSv1)).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)
- }
-
-}
-func TestCmdSleepPostprocessRpcParamsCase2(t *testing.T) {
- testStruct := &CmdSleep{
- name: "",
- rpcMethod: "",
- rpcParams: &StringWrapper{
- Item: "test_item",
- },
- CommandExecuter: nil,
- }
-
- err := testStruct.PostprocessRpcParams()
- if err == nil || err.Error() != "time: invalid duration \"test_item\"" {
- t.Errorf("Expected , Received <%+v>", err)
- }
-
-}
diff --git a/console/stats_for_event_test.go b/console/stats_for_event_test.go
deleted file mode 100644
index c1f7ed09f..000000000
--- a/console/stats_for_event_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdStatsForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.StatSv1)).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/stats_metrics_test.go b/console/stats_metrics_test.go
deleted file mode 100644
index cdfab6305..000000000
--- a/console/stats_metrics_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdStatsMetrics(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_metrics"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.StatSv1)).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/stats_process_event_test.go b/console/stats_process_event_test.go
deleted file mode 100644
index bcc7f7059..000000000
--- a/console/stats_process_event_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdStatsProcessEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_process_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.StatSv1)).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/stats_profile_ids_test.go b/console/stats_profile_ids_test.go
deleted file mode 100644
index a961b58b9..000000000
--- a/console/stats_profile_ids_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdStatsProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_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/stats_profile_rem_test.go b/console/stats_profile_rem_test.go
deleted file mode 100644
index 4f5423375..000000000
--- a/console/stats_profile_rem_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdStatsProfileRem(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_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/stats_profile_set_test.go b/console/stats_profile_set_test.go
deleted file mode 100644
index e63867f4b..000000000
--- a/console/stats_profile_set_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdStatsProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_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/stats_profile_test.go b/console/stats_profile_test.go
deleted file mode 100644
index d5c0d38f4..000000000
--- a/console/stats_profile_test.go
+++ /dev/null
@@ -1,61 +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 TestCmdStatsProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stats_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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.TTL: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/console/status_test.go b/console/status_test.go
deleted file mode 100644
index d9fa36b15..000000000
--- a/console/status_test.go
+++ /dev/null
@@ -1,57 +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 TestCmdStatus(t *testing.T) {
- // commands map is initiated in init function
- command := commands["status"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.CoreSv1)).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)
- }
- // for coverage purpose
- if reflect.DeepEqual(command.ClientArgs(), []string{}) {
- t.Errorf("Expected <%+v>, Received <%+v>", []string{}, command.ClientArgs())
- }
-}
diff --git a/console/stordb_versions_test.go b/console/stordb_versions_test.go
deleted file mode 100644
index f92fa6b82..000000000
--- a/console/stordb_versions_test.go
+++ /dev/null
@@ -1,59 +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 TestCmdStorDBVersions(t *testing.T) {
- // commands map is initiated in init function
- command := commands["stordb_versions"]
- // 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 ")
- }
- // for coverage purpose
- result := command.RpcParams(true)
- if !reflect.DeepEqual(result, new(EmptyWrapper)) {
- t.Errorf("Expected <%T>, Received <%T>", new(EmptyWrapper), result)
- }
-
- // 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)
- }
- // for coverage purpose
- if err := command.ClientArgs(); err != nil {
- t.Fatal(err)
- }
-}
diff --git a/console/threshold_test.go b/console/threshold_test.go
deleted file mode 100644
index e3ab8cdb8..000000000
--- a/console/threshold_test.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 (
- "reflect"
- "strings"
- "testing"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestCmdThreshold(t *testing.T) {
- // commands map is initiated in init function
- command := commands["threshold"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ThresholdSv1)).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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.MinSleep: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-
-}
diff --git a/console/thresholds_for_event.go b/console/thresholds_for_event.go
old mode 100755
new mode 100644
diff --git a/console/thresholds_for_event_test.go b/console/thresholds_for_event_test.go
deleted file mode 100644
index 561b262f0..000000000
--- a/console/thresholds_for_event_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdThresholdsForEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["thresholds_for_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ThresholdSv1)).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/thresholds_process_event_test.go b/console/thresholds_process_event_test.go
deleted file mode 100644
index 11d3568a7..000000000
--- a/console/thresholds_process_event_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdThresholdsProcessEvent(t *testing.T) {
- // commands map is initiated in init function
- command := commands["thresholds_process_event"]
- // verify if ApierSv1 object has method on it
- m, ok := reflect.TypeOf(new(v1.ThresholdSv1)).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/thresholds_profile_ids_test.go b/console/thresholds_profile_ids_test.go
deleted file mode 100644
index 54f3bbba6..000000000
--- a/console/thresholds_profile_ids_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdThresholdsProfileIDs(t *testing.T) {
- // commands map is initiated in init function
- command := commands["thresholds_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/thresholds_profile_remove_test.go b/console/thresholds_profile_remove_test.go
deleted file mode 100644
index 03d6e0ceb..000000000
--- a/console/thresholds_profile_remove_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdThresholdsProfileRemove(t *testing.T) {
- // commands map is initiated in init function
- command := commands["thresholds_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/thresholds_profile_set_test.go b/console/thresholds_profile_set_test.go
deleted file mode 100644
index b8bd9d6ff..000000000
--- a/console/thresholds_profile_set_test.go
+++ /dev/null
@@ -1,53 +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 TestCmdThresholdsProfileSet(t *testing.T) {
- // commands map is initiated in init function
- command := commands["thresholds_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/thresholds_profile_test.go b/console/thresholds_profile_test.go
deleted file mode 100644
index f01b3b941..000000000
--- a/console/thresholds_profile_test.go
+++ /dev/null
@@ -1,61 +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 TestCmdThresholdsProfile(t *testing.T) {
- // commands map is initiated in init function
- command := commands["thresholds_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)
- }
- // for coverage purpose
- formatedResult := command.GetFormatedResult(command.RpcResult())
- expected := GetFormatedResult(command.RpcResult(), utils.StringSet{
- utils.MinSleep: {},
- })
- if !reflect.DeepEqual(formatedResult, expected) {
- t.Errorf("Expected <%+v>, Received <%+v>", expected, formatedResult)
- }
-}
diff --git a/cores/server.go b/cores/server.go
index 63c1fcef6..29277c554 100644
--- a/cores/server.go
+++ b/cores/server.go
@@ -82,6 +82,10 @@ func (s *Server) RpcRegisterName(name string, rcvr interface{}) {
s.Unlock()
}
+func (s *Server) RpcUnregisterName(name string) {
+ birpc.DefaultServer.UnregisterName(name)
+}
+
func (s *Server) RegisterHTTPFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) {
if s.httpMux != nil {
s.httpMux.HandleFunc(pattern, handler)
diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json
index 66bb2448e..f024180da 100755
--- a/data/conf/cgrates/cgrates.json
+++ b/data/conf/cgrates/cgrates.json
@@ -941,7 +941,7 @@
// },
-// "apiers": {
+// "admins": {
// "enabled": false,
// "caches_conns":["*internal"],
// "scheduler_conns": [], // connections to SchedulerS for reloads
diff --git a/data/conf/samples/acc_balance_keep_internal/cgrates.json b/data/conf/samples/acc_balance_keep_internal/cgrates.json
index 2db92048c..3e9430e02 100644
--- a/data/conf/samples/acc_balance_keep_internal/cgrates.json
+++ b/data/conf/samples/acc_balance_keep_internal/cgrates.json
@@ -97,7 +97,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/acc_balance_keep_internal_gob/cgrates.json b/data/conf/samples/acc_balance_keep_internal_gob/cgrates.json
index fa36884aa..db9a2faf3 100644
--- a/data/conf/samples/acc_balance_keep_internal_gob/cgrates.json
+++ b/data/conf/samples/acc_balance_keep_internal_gob/cgrates.json
@@ -103,7 +103,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/acc_balance_keep_mongo/cgrates.json b/data/conf/samples/acc_balance_keep_mongo/cgrates.json
index 92765c08d..f16d62122 100644
--- a/data/conf/samples/acc_balance_keep_mongo/cgrates.json
+++ b/data/conf/samples/acc_balance_keep_mongo/cgrates.json
@@ -98,7 +98,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/acc_balance_keep_mongo_gob/cgrates.json b/data/conf/samples/acc_balance_keep_mongo_gob/cgrates.json
index 45355c687..3120b7275 100644
--- a/data/conf/samples/acc_balance_keep_mongo_gob/cgrates.json
+++ b/data/conf/samples/acc_balance_keep_mongo_gob/cgrates.json
@@ -107,7 +107,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/acc_balance_keep_mysql/cgrates.json b/data/conf/samples/acc_balance_keep_mysql/cgrates.json
index 85ddaaa72..95b674cdd 100644
--- a/data/conf/samples/acc_balance_keep_mysql/cgrates.json
+++ b/data/conf/samples/acc_balance_keep_mysql/cgrates.json
@@ -97,7 +97,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/acc_balance_keep_mysql_gob/cgrates.json b/data/conf/samples/acc_balance_keep_mysql_gob/cgrates.json
index f3c243dd3..b6d120c8c 100644
--- a/data/conf/samples/acc_balance_keep_mysql_gob/cgrates.json
+++ b/data/conf/samples/acc_balance_keep_mysql_gob/cgrates.json
@@ -104,7 +104,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/accounts_internal/cgrates.json b/data/conf/samples/accounts_internal/cgrates.json
index 3afb376a7..a294590fc 100644
--- a/data/conf/samples/accounts_internal/cgrates.json
+++ b/data/conf/samples/accounts_internal/cgrates.json
@@ -39,7 +39,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/accounts_mysql/cgrates.json b/data/conf/samples/accounts_mysql/cgrates.json
index 61ead87fb..8684302d7 100644
--- a/data/conf/samples/accounts_mysql/cgrates.json
+++ b/data/conf/samples/accounts_mysql/cgrates.json
@@ -46,7 +46,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/actions_internal/cgradmin.json b/data/conf/samples/actions_internal/cgradmin.json
index f2023176c..d835e0a82 100644
--- a/data/conf/samples/actions_internal/cgradmin.json
+++ b/data/conf/samples/actions_internal/cgradmin.json
@@ -115,7 +115,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"]
diff --git a/data/conf/samples/actions_internal_gob/cgradmin.json b/data/conf/samples/actions_internal_gob/cgradmin.json
index fa1d8f5c7..c3dc52cc6 100644
--- a/data/conf/samples/actions_internal_gob/cgradmin.json
+++ b/data/conf/samples/actions_internal_gob/cgradmin.json
@@ -124,7 +124,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"]
diff --git a/data/conf/samples/actions_mongo/cgradmin.json b/data/conf/samples/actions_mongo/cgradmin.json
index ac0067c10..c5e47facf 100644
--- a/data/conf/samples/actions_mongo/cgradmin.json
+++ b/data/conf/samples/actions_mongo/cgradmin.json
@@ -120,7 +120,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"]
diff --git a/data/conf/samples/actions_mongo_gob/cgradmin.json b/data/conf/samples/actions_mongo_gob/cgradmin.json
index 7e3bbe9e5..be77cb614 100644
--- a/data/conf/samples/actions_mongo_gob/cgradmin.json
+++ b/data/conf/samples/actions_mongo_gob/cgradmin.json
@@ -121,7 +121,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"]
diff --git a/data/conf/samples/actions_mysql/cgradmin.json b/data/conf/samples/actions_mysql/cgradmin.json
index c2d86acf9..9731e9624 100644
--- a/data/conf/samples/actions_mysql/cgradmin.json
+++ b/data/conf/samples/actions_mysql/cgradmin.json
@@ -117,7 +117,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"]
diff --git a/data/conf/samples/actions_mysql_gob/cgradmin.json b/data/conf/samples/actions_mysql_gob/cgradmin.json
index 525dcbaa3..ab3225fc7 100644
--- a/data/conf/samples/actions_mysql_gob/cgradmin.json
+++ b/data/conf/samples/actions_mysql_gob/cgradmin.json
@@ -123,7 +123,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"]
diff --git a/data/conf/samples/analyzers/cgrates.json b/data/conf/samples/analyzers/cgrates.json
index ec84db230..392ae4efc 100644
--- a/data/conf/samples/analyzers/cgrates.json
+++ b/data/conf/samples/analyzers/cgrates.json
@@ -108,7 +108,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/apier_mongo/apier.json b/data/conf/samples/apier_mongo/apier.json
index bf0d3326d..ab1b28eb9 100644
--- a/data/conf/samples/apier_mongo/apier.json
+++ b/data/conf/samples/apier_mongo/apier.json
@@ -79,7 +79,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/apier_mysql/apier.json b/data/conf/samples/apier_mysql/apier.json
index abd7d9c0b..3671b1ffa 100644
--- a/data/conf/samples/apier_mysql/apier.json
+++ b/data/conf/samples/apier_mysql/apier.json
@@ -76,7 +76,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cache_replicate/dispatcher_engine/cgrates.json b/data/conf/samples/cache_replicate/dispatcher_engine/cgrates.json
index 7a4c38a6d..91ed864ad 100644
--- a/data/conf/samples/cache_replicate/dispatcher_engine/cgrates.json
+++ b/data/conf/samples/cache_replicate/dispatcher_engine/cgrates.json
@@ -44,7 +44,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cache_replicate/dispatcher_engine2/cgrates.json b/data/conf/samples/cache_replicate/dispatcher_engine2/cgrates.json
index 53564b5be..2e6a38ce5 100644
--- a/data/conf/samples/cache_replicate/dispatcher_engine2/cgrates.json
+++ b/data/conf/samples/cache_replicate/dispatcher_engine2/cgrates.json
@@ -42,7 +42,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cache_replicate/engine1/cgrates.json b/data/conf/samples/cache_replicate/engine1/cgrates.json
index f7ba37b85..bd2c7a4d7 100644
--- a/data/conf/samples/cache_replicate/engine1/cgrates.json
+++ b/data/conf/samples/cache_replicate/engine1/cgrates.json
@@ -50,7 +50,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/cache_rpl_active_active/dispatcher_engine/cgrates.json b/data/conf/samples/cache_rpl_active_active/dispatcher_engine/cgrates.json
index 7a4c38a6d..91ed864ad 100644
--- a/data/conf/samples/cache_rpl_active_active/dispatcher_engine/cgrates.json
+++ b/data/conf/samples/cache_rpl_active_active/dispatcher_engine/cgrates.json
@@ -44,7 +44,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cache_rpl_active_active/dispatcher_engine2/cgrates.json b/data/conf/samples/cache_rpl_active_active/dispatcher_engine2/cgrates.json
index d7b0a917f..1f3285300 100644
--- a/data/conf/samples/cache_rpl_active_active/dispatcher_engine2/cgrates.json
+++ b/data/conf/samples/cache_rpl_active_active/dispatcher_engine2/cgrates.json
@@ -51,7 +51,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cache_rpl_active_active/engine1/cgrates.json b/data/conf/samples/cache_rpl_active_active/engine1/cgrates.json
index f7ba37b85..bd2c7a4d7 100644
--- a/data/conf/samples/cache_rpl_active_active/engine1/cgrates.json
+++ b/data/conf/samples/cache_rpl_active_active/engine1/cgrates.json
@@ -50,7 +50,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/caps_busy/cgrates.json b/data/conf/samples/caps_busy/cgrates.json
index 5e5b890a6..fd244c8d1 100644
--- a/data/conf/samples/caps_busy/cgrates.json
+++ b/data/conf/samples/caps_busy/cgrates.json
@@ -32,7 +32,7 @@
},
-"apiers": {
+"admins": {
"enabled": true
},
diff --git a/data/conf/samples/caps_queue/cgrates.json b/data/conf/samples/caps_queue/cgrates.json
index 3b3886f5b..23239e789 100644
--- a/data/conf/samples/caps_queue/cgrates.json
+++ b/data/conf/samples/caps_queue/cgrates.json
@@ -31,7 +31,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/caps_queue_bench/cgrates.json b/data/conf/samples/caps_queue_bench/cgrates.json
index a30533b6d..81ae7fe25 100644
--- a/data/conf/samples/caps_queue_bench/cgrates.json
+++ b/data/conf/samples/caps_queue_bench/cgrates.json
@@ -111,7 +111,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsexport_internal/cgrates.json b/data/conf/samples/cdrsexport_internal/cgrates.json
index 1c33a1c3d..3c531ef54 100644
--- a/data/conf/samples/cdrsexport_internal/cgrates.json
+++ b/data/conf/samples/cdrsexport_internal/cgrates.json
@@ -158,7 +158,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsexport_mongo/cgrates.json b/data/conf/samples/cdrsexport_mongo/cgrates.json
index 14a65aec4..da8eaedb6 100644
--- a/data/conf/samples/cdrsexport_mongo/cgrates.json
+++ b/data/conf/samples/cdrsexport_mongo/cgrates.json
@@ -163,7 +163,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsexport_mysql/cgrates.json b/data/conf/samples/cdrsexport_mysql/cgrates.json
index d1c881792..f63ffe051 100644
--- a/data/conf/samples/cdrsexport_mysql/cgrates.json
+++ b/data/conf/samples/cdrsexport_mysql/cgrates.json
@@ -158,7 +158,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsonexpmaster_mongo/cdrsreplicationmaster.json b/data/conf/samples/cdrsonexpmaster_mongo/cdrsreplicationmaster.json
index 969238a1f..63cc90229 100644
--- a/data/conf/samples/cdrsonexpmaster_mongo/cdrsreplicationmaster.json
+++ b/data/conf/samples/cdrsonexpmaster_mongo/cdrsreplicationmaster.json
@@ -146,7 +146,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsonexpmaster_mysql/cdrsreplicationmaster.json b/data/conf/samples/cdrsonexpmaster_mysql/cdrsreplicationmaster.json
index 2ded3f3ba..bc50994a4 100644
--- a/data/conf/samples/cdrsonexpmaster_mysql/cdrsreplicationmaster.json
+++ b/data/conf/samples/cdrsonexpmaster_mysql/cdrsreplicationmaster.json
@@ -144,7 +144,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsonexpslave_mongo/cdrsreplicationslave.json b/data/conf/samples/cdrsonexpslave_mongo/cdrsreplicationslave.json
index 65165bd29..d13cb58d5 100644
--- a/data/conf/samples/cdrsonexpslave_mongo/cdrsreplicationslave.json
+++ b/data/conf/samples/cdrsonexpslave_mongo/cdrsreplicationslave.json
@@ -37,7 +37,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsonexpslave_mysql/cdrsreplicationslave.json b/data/conf/samples/cdrsonexpslave_mysql/cdrsreplicationslave.json
index 1b1c1e9c9..7e4c9fd02 100644
--- a/data/conf/samples/cdrsonexpslave_mysql/cdrsreplicationslave.json
+++ b/data/conf/samples/cdrsonexpslave_mysql/cdrsreplicationslave.json
@@ -35,7 +35,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/cdrsv1internal/cgrates.json b/data/conf/samples/cdrsv1internal/cgrates.json
index 6072ef4f1..c53491465 100644
--- a/data/conf/samples/cdrsv1internal/cgrates.json
+++ b/data/conf/samples/cdrsv1internal/cgrates.json
@@ -34,7 +34,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv1mongo/cgrates.json b/data/conf/samples/cdrsv1mongo/cgrates.json
index 9b7a4981d..f68193b19 100644
--- a/data/conf/samples/cdrsv1mongo/cgrates.json
+++ b/data/conf/samples/cdrsv1mongo/cgrates.json
@@ -37,7 +37,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv1mysql/cgrates.json b/data/conf/samples/cdrsv1mysql/cgrates.json
index 5ee985234..309895acf 100644
--- a/data/conf/samples/cdrsv1mysql/cgrates.json
+++ b/data/conf/samples/cdrsv1mysql/cgrates.json
@@ -34,7 +34,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv1postgres/cgrates.json b/data/conf/samples/cdrsv1postgres/cgrates.json
index c105245c0..a6929e510 100644
--- a/data/conf/samples/cdrsv1postgres/cgrates.json
+++ b/data/conf/samples/cdrsv1postgres/cgrates.json
@@ -32,7 +32,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv1processevent/cgrates.json b/data/conf/samples/cdrsv1processevent/cgrates.json
index 9145991b3..7035a835e 100644
--- a/data/conf/samples/cdrsv1processevent/cgrates.json
+++ b/data/conf/samples/cdrsv1processevent/cgrates.json
@@ -80,7 +80,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv1processeventmongo/cgrates.json b/data/conf/samples/cdrsv1processeventmongo/cgrates.json
index b4a30fb86..f5e42bcff 100644
--- a/data/conf/samples/cdrsv1processeventmongo/cgrates.json
+++ b/data/conf/samples/cdrsv1processeventmongo/cgrates.json
@@ -81,7 +81,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv1processeventmysql/cgrates.json b/data/conf/samples/cdrsv1processeventmysql/cgrates.json
index 9d1370568..d4302d235 100644
--- a/data/conf/samples/cdrsv1processeventmysql/cgrates.json
+++ b/data/conf/samples/cdrsv1processeventmysql/cgrates.json
@@ -79,7 +79,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2internal/cgrates.json b/data/conf/samples/cdrsv2internal/cgrates.json
index d690c0bc9..c710436e3 100644
--- a/data/conf/samples/cdrsv2internal/cgrates.json
+++ b/data/conf/samples/cdrsv2internal/cgrates.json
@@ -55,7 +55,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2internal_gob/cgrates.json b/data/conf/samples/cdrsv2internal_gob/cgrates.json
index e95d792a0..eaca03588 100644
--- a/data/conf/samples/cdrsv2internal_gob/cgrates.json
+++ b/data/conf/samples/cdrsv2internal_gob/cgrates.json
@@ -61,7 +61,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2mongo/cgrates.json b/data/conf/samples/cdrsv2mongo/cgrates.json
index 46df8b898..f2a6db6e4 100644
--- a/data/conf/samples/cdrsv2mongo/cgrates.json
+++ b/data/conf/samples/cdrsv2mongo/cgrates.json
@@ -55,7 +55,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2mongo_gob/cgrates.json b/data/conf/samples/cdrsv2mongo_gob/cgrates.json
index d166efeb8..f1226504e 100644
--- a/data/conf/samples/cdrsv2mongo_gob/cgrates.json
+++ b/data/conf/samples/cdrsv2mongo_gob/cgrates.json
@@ -64,7 +64,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2mysql/cdrsv2mysql.json b/data/conf/samples/cdrsv2mysql/cdrsv2mysql.json
index 0439c2117..696b92170 100644
--- a/data/conf/samples/cdrsv2mysql/cdrsv2mysql.json
+++ b/data/conf/samples/cdrsv2mysql/cdrsv2mysql.json
@@ -55,7 +55,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2mysql_gob/cdrsv2mysql.json b/data/conf/samples/cdrsv2mysql_gob/cdrsv2mysql.json
index 0a41f2b64..e32afbc12 100644
--- a/data/conf/samples/cdrsv2mysql_gob/cdrsv2mysql.json
+++ b/data/conf/samples/cdrsv2mysql_gob/cdrsv2mysql.json
@@ -63,7 +63,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv2psql/cdrsv2psql.json b/data/conf/samples/cdrsv2psql/cdrsv2psql.json
index e96025942..f951a17da 100644
--- a/data/conf/samples/cdrsv2psql/cdrsv2psql.json
+++ b/data/conf/samples/cdrsv2psql/cdrsv2psql.json
@@ -55,7 +55,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv_failover_internal/cgrates.json b/data/conf/samples/cdrsv_failover_internal/cgrates.json
index 1c7ef10d0..07721c9a3 100644
--- a/data/conf/samples/cdrsv_failover_internal/cgrates.json
+++ b/data/conf/samples/cdrsv_failover_internal/cgrates.json
@@ -57,7 +57,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv_failover_mongo/cgrates.json b/data/conf/samples/cdrsv_failover_mongo/cgrates.json
index 78b24b130..513812916 100644
--- a/data/conf/samples/cdrsv_failover_mongo/cgrates.json
+++ b/data/conf/samples/cdrsv_failover_mongo/cgrates.json
@@ -65,7 +65,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/cdrsv_failover_mysql/cgrates.json b/data/conf/samples/cdrsv_failover_mysql/cgrates.json
index 176360583..d62e32826 100644
--- a/data/conf/samples/cdrsv_failover_mysql/cgrates.json
+++ b/data/conf/samples/cdrsv_failover_mysql/cgrates.json
@@ -63,7 +63,7 @@
"attributes_conns": ["*internal"]
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"]
},
diff --git a/data/conf/samples/cluelrn/cgrates.json b/data/conf/samples/cluelrn/cgrates.json
index 88d55b5a9..6d44b4b55 100644
--- a/data/conf/samples/cluelrn/cgrates.json
+++ b/data/conf/samples/cluelrn/cgrates.json
@@ -55,7 +55,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diam_tutmysql/cgrates.json b/data/conf/samples/diam_tutmysql/cgrates.json
index 4d752ff12..62157b62f 100644
--- a/data/conf/samples/diam_tutmysql/cgrates.json
+++ b/data/conf/samples/diam_tutmysql/cgrates.json
@@ -70,7 +70,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_internal/cgrates.json b/data/conf/samples/diamagent_internal/cgrates.json
index de15120bf..3c33436cb 100644
--- a/data/conf/samples/diamagent_internal/cgrates.json
+++ b/data/conf/samples/diamagent_internal/cgrates.json
@@ -61,7 +61,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_internal_gobbirpc/cgrates.json b/data/conf/samples/diamagent_internal_gobbirpc/cgrates.json
index 3cd89a507..f5746ad2f 100644
--- a/data/conf/samples/diamagent_internal_gobbirpc/cgrates.json
+++ b/data/conf/samples/diamagent_internal_gobbirpc/cgrates.json
@@ -69,7 +69,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_internal_jsonbirpc/cgrates.json b/data/conf/samples/diamagent_internal_jsonbirpc/cgrates.json
index 272752d22..4cf4a17ba 100644
--- a/data/conf/samples/diamagent_internal_jsonbirpc/cgrates.json
+++ b/data/conf/samples/diamagent_internal_jsonbirpc/cgrates.json
@@ -68,7 +68,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_mongo/cgrates.json b/data/conf/samples/diamagent_mongo/cgrates.json
index c55c32459..6b5e888ca 100644
--- a/data/conf/samples/diamagent_mongo/cgrates.json
+++ b/data/conf/samples/diamagent_mongo/cgrates.json
@@ -66,7 +66,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_mongo_gobbirpc/cgrates.json b/data/conf/samples/diamagent_mongo_gobbirpc/cgrates.json
index b7d639b7e..0a9aeb057 100644
--- a/data/conf/samples/diamagent_mongo_gobbirpc/cgrates.json
+++ b/data/conf/samples/diamagent_mongo_gobbirpc/cgrates.json
@@ -74,7 +74,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_mongo_jsonbirpc/cgrates.json b/data/conf/samples/diamagent_mongo_jsonbirpc/cgrates.json
index ed770a342..e5af4597c 100644
--- a/data/conf/samples/diamagent_mongo_jsonbirpc/cgrates.json
+++ b/data/conf/samples/diamagent_mongo_jsonbirpc/cgrates.json
@@ -73,7 +73,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_mysql/cgrates.json b/data/conf/samples/diamagent_mysql/cgrates.json
index 4fdb9466d..4289891c4 100644
--- a/data/conf/samples/diamagent_mysql/cgrates.json
+++ b/data/conf/samples/diamagent_mysql/cgrates.json
@@ -62,7 +62,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_mysql_gobbirpc/cgrates.json b/data/conf/samples/diamagent_mysql_gobbirpc/cgrates.json
index e38008e3a..fc175bd6f 100644
--- a/data/conf/samples/diamagent_mysql_gobbirpc/cgrates.json
+++ b/data/conf/samples/diamagent_mysql_gobbirpc/cgrates.json
@@ -70,7 +70,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagent_mysql_jsonbirpc/cgrates.json b/data/conf/samples/diamagent_mysql_jsonbirpc/cgrates.json
index acf9ef17f..ef2f0efe2 100644
--- a/data/conf/samples/diamagent_mysql_jsonbirpc/cgrates.json
+++ b/data/conf/samples/diamagent_mysql_jsonbirpc/cgrates.json
@@ -69,7 +69,7 @@
"forced_disconnect": "*asr", // the request to send to diameter on DisconnectSession <*none|*asr|*rar>
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagentmaxconn_internal/cgrates.json b/data/conf/samples/diamagentmaxconn_internal/cgrates.json
index bf8f16e1b..0bcd35293 100755
--- a/data/conf/samples/diamagentmaxconn_internal/cgrates.json
+++ b/data/conf/samples/diamagentmaxconn_internal/cgrates.json
@@ -69,7 +69,7 @@
],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagentmaxconn_mongo/cgrates.json b/data/conf/samples/diamagentmaxconn_mongo/cgrates.json
index a2aa3b2b7..fb3d2d91d 100755
--- a/data/conf/samples/diamagentmaxconn_mongo/cgrates.json
+++ b/data/conf/samples/diamagentmaxconn_mongo/cgrates.json
@@ -73,7 +73,7 @@
],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamagentmaxconn_mysql/cgrates.json b/data/conf/samples/diamagentmaxconn_mysql/cgrates.json
index 34870143f..c1e2e2b9d 100755
--- a/data/conf/samples/diamagentmaxconn_mysql/cgrates.json
+++ b/data/conf/samples/diamagentmaxconn_mysql/cgrates.json
@@ -69,7 +69,7 @@
],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamsctpagent_internal/cgrates.json b/data/conf/samples/diamsctpagent_internal/cgrates.json
index fe70facb5..9966df01f 100755
--- a/data/conf/samples/diamsctpagent_internal/cgrates.json
+++ b/data/conf/samples/diamsctpagent_internal/cgrates.json
@@ -63,7 +63,7 @@
"rar_template": "*rar",
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamsctpagent_mongo/cgrates.json b/data/conf/samples/diamsctpagent_mongo/cgrates.json
index f1bdbe0b2..9f4f1ace4 100755
--- a/data/conf/samples/diamsctpagent_mongo/cgrates.json
+++ b/data/conf/samples/diamsctpagent_mongo/cgrates.json
@@ -67,7 +67,7 @@
"rar_template": "*rar",
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/diamsctpagent_mysql/cgrates.json b/data/conf/samples/diamsctpagent_mysql/cgrates.json
index 80ad6529c..9fea7ce14 100755
--- a/data/conf/samples/diamsctpagent_mysql/cgrates.json
+++ b/data/conf/samples/diamsctpagent_mysql/cgrates.json
@@ -63,7 +63,7 @@
"rar_template": "*rar",
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/all/cgrates.json b/data/conf/samples/dispatchers/all/cgrates.json
index 5deaeda75..e0247f971 100644
--- a/data/conf/samples/dispatchers/all/cgrates.json
+++ b/data/conf/samples/dispatchers/all/cgrates.json
@@ -104,7 +104,7 @@
"cdrs_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/dispatchers/all2/cgrates.json b/data/conf/samples/dispatchers/all2/cgrates.json
index 4af540d6d..54f0987b5 100644
--- a/data/conf/samples/dispatchers/all2/cgrates.json
+++ b/data/conf/samples/dispatchers/all2/cgrates.json
@@ -99,7 +99,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/dispatchers/all2_mongo/cgrates.json b/data/conf/samples/dispatchers/all2_mongo/cgrates.json
index 32adb4199..bda8f282c 100644
--- a/data/conf/samples/dispatchers/all2_mongo/cgrates.json
+++ b/data/conf/samples/dispatchers/all2_mongo/cgrates.json
@@ -103,7 +103,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/dispatchers/all2_mysql/cgrates.json b/data/conf/samples/dispatchers/all2_mysql/cgrates.json
index e98944993..49d47b26f 100644
--- a/data/conf/samples/dispatchers/all2_mysql/cgrates.json
+++ b/data/conf/samples/dispatchers/all2_mysql/cgrates.json
@@ -100,7 +100,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/dispatchers/all_mongo/cgrates.json b/data/conf/samples/dispatchers/all_mongo/cgrates.json
index 1cd4bce13..aaa47d8d5 100644
--- a/data/conf/samples/dispatchers/all_mongo/cgrates.json
+++ b/data/conf/samples/dispatchers/all_mongo/cgrates.json
@@ -107,7 +107,7 @@
"cdrs_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/dispatchers/all_mysql/cgrates.json b/data/conf/samples/dispatchers/all_mysql/cgrates.json
index dff4f6f38..c9fbcc18c 100644
--- a/data/conf/samples/dispatchers/all_mysql/cgrates.json
+++ b/data/conf/samples/dispatchers/all_mysql/cgrates.json
@@ -105,7 +105,7 @@
"cdrs_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/dispatchers/diamagent/cgrates.json b/data/conf/samples/dispatchers/diamagent/cgrates.json
index da920333f..178350681 100644
--- a/data/conf/samples/dispatchers/diamagent/cgrates.json
+++ b/data/conf/samples/dispatchers/diamagent/cgrates.json
@@ -55,7 +55,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"]
}
diff --git a/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json b/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json
index 7baa8bb2e..29cadabb6 100644
--- a/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_internal/cgrates.json
@@ -65,7 +65,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/dispatchers_internal_gob/cgrates.json b/data/conf/samples/dispatchers/dispatchers_internal_gob/cgrates.json
index ee4f7d1bf..f39985a90 100644
--- a/data/conf/samples/dispatchers/dispatchers_internal_gob/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_internal_gob/cgrates.json
@@ -75,7 +75,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json
index ef0f1dbc8..ea124fc95 100644
--- a/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_mongo/cgrates.json
@@ -71,7 +71,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/dispatchers_mongo_gob/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mongo_gob/cgrates.json
index 3f3af9c76..4a5abc8f4 100644
--- a/data/conf/samples/dispatchers/dispatchers_mongo_gob/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_mongo_gob/cgrates.json
@@ -78,7 +78,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json
index b012d723c..fadf9d4fe 100755
--- a/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_mysql/cgrates.json
@@ -60,7 +60,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/dispatchers_mysql_gob/cgrates.json b/data/conf/samples/dispatchers/dispatchers_mysql_gob/cgrates.json
index 39d750bc0..9b7bee183 100755
--- a/data/conf/samples/dispatchers/dispatchers_mysql_gob/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_mysql_gob/cgrates.json
@@ -77,7 +77,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/dispatchers_no_attributes/cgrates.json b/data/conf/samples/dispatchers/dispatchers_no_attributes/cgrates.json
index 77b625873..13850b0ab 100755
--- a/data/conf/samples/dispatchers/dispatchers_no_attributes/cgrates.json
+++ b/data/conf/samples/dispatchers/dispatchers_no_attributes/cgrates.json
@@ -46,7 +46,7 @@
"enabled": true,
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dispatchers/radagent/cgrates.json b/data/conf/samples/dispatchers/radagent/cgrates.json
index 138ce03c1..7da85da42 100644
--- a/data/conf/samples/dispatchers/radagent/cgrates.json
+++ b/data/conf/samples/dispatchers/radagent/cgrates.json
@@ -56,7 +56,7 @@
"sessions_conns": ["*localhost"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dnsagent_internal/cgrates.json b/data/conf/samples/dnsagent_internal/cgrates.json
index 51be029bd..48c1aaead 100644
--- a/data/conf/samples/dnsagent_internal/cgrates.json
+++ b/data/conf/samples/dnsagent_internal/cgrates.json
@@ -70,7 +70,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dnsagent_mongo/cgrates.json b/data/conf/samples/dnsagent_mongo/cgrates.json
index 61d923e0c..d0a673cb2 100644
--- a/data/conf/samples/dnsagent_mongo/cgrates.json
+++ b/data/conf/samples/dnsagent_mongo/cgrates.json
@@ -75,7 +75,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dnsagent_mysql/cgrates.json b/data/conf/samples/dnsagent_mysql/cgrates.json
index a2f7a705c..c3c73fef7 100644
--- a/data/conf/samples/dnsagent_mysql/cgrates.json
+++ b/data/conf/samples/dnsagent_mysql/cgrates.json
@@ -66,7 +66,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/dnsagent_reload/cgrates.json b/data/conf/samples/dnsagent_reload/cgrates.json
index f8c510495..043ffaca2 100644
--- a/data/conf/samples/dnsagent_reload/cgrates.json
+++ b/data/conf/samples/dnsagent_reload/cgrates.json
@@ -66,7 +66,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/docker/cgrates.json b/data/conf/samples/docker/cgrates.json
index 3faebe5ce..d389ecef6 100644
--- a/data/conf/samples/docker/cgrates.json
+++ b/data/conf/samples/docker/cgrates.json
@@ -110,7 +110,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json
index c07a7a9e0..e9171a125 100644
--- a/data/conf/samples/ees/cgrates.json
+++ b/data/conf/samples/ees/cgrates.json
@@ -432,7 +432,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ees_internal/cgrates.json b/data/conf/samples/ees_internal/cgrates.json
index aece68ee5..79a569476 100644
--- a/data/conf/samples/ees_internal/cgrates.json
+++ b/data/conf/samples/ees_internal/cgrates.json
@@ -144,7 +144,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"],
diff --git a/data/conf/samples/ees_mongo/cgrates.json b/data/conf/samples/ees_mongo/cgrates.json
index 1f9461669..5453739ff 100644
--- a/data/conf/samples/ees_mongo/cgrates.json
+++ b/data/conf/samples/ees_mongo/cgrates.json
@@ -148,7 +148,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"],
diff --git a/data/conf/samples/ees_mysql/cgrates.json b/data/conf/samples/ees_mysql/cgrates.json
index 4dd815444..dd35b7d27 100644
--- a/data/conf/samples/ees_mysql/cgrates.json
+++ b/data/conf/samples/ees_mysql/cgrates.json
@@ -146,7 +146,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"ees_conns": ["*localhost"],
diff --git a/data/conf/samples/ers_example/cgrates.json b/data/conf/samples/ers_example/cgrates.json
index 51a504886..cc3de3ec3 100644
--- a/data/conf/samples/ers_example/cgrates.json
+++ b/data/conf/samples/ers_example/cgrates.json
@@ -93,7 +93,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_internal/cgrates.json b/data/conf/samples/ers_internal/cgrates.json
index b3b6c5ee9..24f80338d 100644
--- a/data/conf/samples/ers_internal/cgrates.json
+++ b/data/conf/samples/ers_internal/cgrates.json
@@ -408,7 +408,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_mongo/cgrates.json b/data/conf/samples/ers_mongo/cgrates.json
index be17b9612..842473c24 100644
--- a/data/conf/samples/ers_mongo/cgrates.json
+++ b/data/conf/samples/ers_mongo/cgrates.json
@@ -409,7 +409,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_mysql/cgrates.json b/data/conf/samples/ers_mysql/cgrates.json
index 6436b14cf..ec187541b 100644
--- a/data/conf/samples/ers_mysql/cgrates.json
+++ b/data/conf/samples/ers_mysql/cgrates.json
@@ -406,7 +406,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_postgres/cgrates.json b/data/conf/samples/ers_postgres/cgrates.json
index a6cf46267..5440672fa 100644
--- a/data/conf/samples/ers_postgres/cgrates.json
+++ b/data/conf/samples/ers_postgres/cgrates.json
@@ -403,7 +403,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/disabled/cgrates.json b/data/conf/samples/ers_reload/disabled/cgrates.json
index 68b215b7f..fe2b9a766 100644
--- a/data/conf/samples/ers_reload/disabled/cgrates.json
+++ b/data/conf/samples/ers_reload/disabled/cgrates.json
@@ -64,7 +64,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/disabled_internal/cgrates.json b/data/conf/samples/ers_reload/disabled_internal/cgrates.json
index 1986655d9..c0af705e6 100644
--- a/data/conf/samples/ers_reload/disabled_internal/cgrates.json
+++ b/data/conf/samples/ers_reload/disabled_internal/cgrates.json
@@ -71,7 +71,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/disabled_mongo/cgrates.json b/data/conf/samples/ers_reload/disabled_mongo/cgrates.json
index 9b397f8a1..e3d5e9a48 100644
--- a/data/conf/samples/ers_reload/disabled_mongo/cgrates.json
+++ b/data/conf/samples/ers_reload/disabled_mongo/cgrates.json
@@ -72,7 +72,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/disabled_mysql/cgrates.json b/data/conf/samples/ers_reload/disabled_mysql/cgrates.json
index 8b2933d2d..1f3371505 100644
--- a/data/conf/samples/ers_reload/disabled_mysql/cgrates.json
+++ b/data/conf/samples/ers_reload/disabled_mysql/cgrates.json
@@ -71,7 +71,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/disabled_postgres/cgrates.json b/data/conf/samples/ers_reload/disabled_postgres/cgrates.json
index 5407e70fa..90ba39cde 100644
--- a/data/conf/samples/ers_reload/disabled_postgres/cgrates.json
+++ b/data/conf/samples/ers_reload/disabled_postgres/cgrates.json
@@ -72,7 +72,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/first_reload/cgrates.json b/data/conf/samples/ers_reload/first_reload/cgrates.json
index a18b62153..32b036672 100644
--- a/data/conf/samples/ers_reload/first_reload/cgrates.json
+++ b/data/conf/samples/ers_reload/first_reload/cgrates.json
@@ -105,7 +105,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/internal/cgrates.json b/data/conf/samples/ers_reload/internal/cgrates.json
index d769b65c6..0eb7d9d03 100644
--- a/data/conf/samples/ers_reload/internal/cgrates.json
+++ b/data/conf/samples/ers_reload/internal/cgrates.json
@@ -93,7 +93,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/ers_reload/second_reload/cgrates.json b/data/conf/samples/ers_reload/second_reload/cgrates.json
index aa2178b2d..9cac8b7d9 100644
--- a/data/conf/samples/ers_reload/second_reload/cgrates.json
+++ b/data/conf/samples/ers_reload/second_reload/cgrates.json
@@ -194,7 +194,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_replication/engine1_mongo/cgrates.json b/data/conf/samples/filtered_replication/engine1_mongo/cgrates.json
index 195abd385..42cee063a 100644
--- a/data/conf/samples/filtered_replication/engine1_mongo/cgrates.json
+++ b/data/conf/samples/filtered_replication/engine1_mongo/cgrates.json
@@ -69,7 +69,7 @@
"enabled": true,
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_replication/engine1_redis/cgrates.json b/data/conf/samples/filtered_replication/engine1_redis/cgrates.json
index 5cd46ca50..8f5ea6c24 100644
--- a/data/conf/samples/filtered_replication/engine1_redis/cgrates.json
+++ b/data/conf/samples/filtered_replication/engine1_redis/cgrates.json
@@ -65,7 +65,7 @@
"enabled": true,
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_replication/engine2_mongo/cgrates.json b/data/conf/samples/filtered_replication/engine2_mongo/cgrates.json
index f477ce252..643890f33 100644
--- a/data/conf/samples/filtered_replication/engine2_mongo/cgrates.json
+++ b/data/conf/samples/filtered_replication/engine2_mongo/cgrates.json
@@ -68,7 +68,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_replication/engine2_redis/cgrates.json b/data/conf/samples/filtered_replication/engine2_redis/cgrates.json
index 933702d1a..414cf42c3 100644
--- a/data/conf/samples/filtered_replication/engine2_redis/cgrates.json
+++ b/data/conf/samples/filtered_replication/engine2_redis/cgrates.json
@@ -66,7 +66,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_replication/internal/cgrates.json b/data/conf/samples/filtered_replication/internal/cgrates.json
index c701b9501..7e69e959a 100644
--- a/data/conf/samples/filtered_replication/internal/cgrates.json
+++ b/data/conf/samples/filtered_replication/internal/cgrates.json
@@ -88,7 +88,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_scheduler2_internal/cgrates.json b/data/conf/samples/filtered_scheduler2_internal/cgrates.json
index dbd2b3ac6..95e129095 100644
--- a/data/conf/samples/filtered_scheduler2_internal/cgrates.json
+++ b/data/conf/samples/filtered_scheduler2_internal/cgrates.json
@@ -37,7 +37,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_scheduler2_mongo/cgrates.json b/data/conf/samples/filtered_scheduler2_mongo/cgrates.json
index 5fc653cc7..12032c1ba 100644
--- a/data/conf/samples/filtered_scheduler2_mongo/cgrates.json
+++ b/data/conf/samples/filtered_scheduler2_mongo/cgrates.json
@@ -41,7 +41,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_scheduler2_mysql/cgrates.json b/data/conf/samples/filtered_scheduler2_mysql/cgrates.json
index 984fe3655..71b2a56db 100644
--- a/data/conf/samples/filtered_scheduler2_mysql/cgrates.json
+++ b/data/conf/samples/filtered_scheduler2_mysql/cgrates.json
@@ -39,7 +39,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_scheduler_internal/cgrates.json b/data/conf/samples/filtered_scheduler_internal/cgrates.json
index 629d91d10..53c3030cb 100644
--- a/data/conf/samples/filtered_scheduler_internal/cgrates.json
+++ b/data/conf/samples/filtered_scheduler_internal/cgrates.json
@@ -37,7 +37,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_scheduler_mongo/cgrates.json b/data/conf/samples/filtered_scheduler_mongo/cgrates.json
index c51b3791b..0a807f374 100644
--- a/data/conf/samples/filtered_scheduler_mongo/cgrates.json
+++ b/data/conf/samples/filtered_scheduler_mongo/cgrates.json
@@ -41,7 +41,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filtered_scheduler_mysql/cgrates.json b/data/conf/samples/filtered_scheduler_mysql/cgrates.json
index f342aef6c..90053baac 100644
--- a/data/conf/samples/filtered_scheduler_mysql/cgrates.json
+++ b/data/conf/samples/filtered_scheduler_mysql/cgrates.json
@@ -39,7 +39,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/filters/cgrates.json b/data/conf/samples/filters/cgrates.json
index e8b6965a3..5e94d1177 100644
--- a/data/conf/samples/filters/cgrates.json
+++ b/data/conf/samples/filters/cgrates.json
@@ -76,7 +76,7 @@
"attributes_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["*localhost"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/filters_gob/cgrates.json b/data/conf/samples/filters_gob/cgrates.json
index e0ea7b459..02f2a96f6 100644
--- a/data/conf/samples/filters_gob/cgrates.json
+++ b/data/conf/samples/filters_gob/cgrates.json
@@ -84,7 +84,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/filters_internal/cgrates.json b/data/conf/samples/filters_internal/cgrates.json
index 93bf4af2c..53f9132a0 100644
--- a/data/conf/samples/filters_internal/cgrates.json
+++ b/data/conf/samples/filters_internal/cgrates.json
@@ -76,7 +76,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["*localhost"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/filters_mongo/cgrates.json b/data/conf/samples/filters_mongo/cgrates.json
index 68abdc9d6..da8c70ba5 100644
--- a/data/conf/samples/filters_mongo/cgrates.json
+++ b/data/conf/samples/filters_mongo/cgrates.json
@@ -81,7 +81,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["*localhost"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/filters_mysql/cgrates.json b/data/conf/samples/filters_mysql/cgrates.json
index 99cd75e3f..7233d2b12 100644
--- a/data/conf/samples/filters_mysql/cgrates.json
+++ b/data/conf/samples/filters_mysql/cgrates.json
@@ -78,7 +78,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["*localhost"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/full_remote/internal/cgrates.json b/data/conf/samples/full_remote/internal/cgrates.json
index 0270a040b..dadda74b1 100644
--- a/data/conf/samples/full_remote/internal/cgrates.json
+++ b/data/conf/samples/full_remote/internal/cgrates.json
@@ -92,7 +92,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/full_remote/remote/cgrates.json b/data/conf/samples/full_remote/remote/cgrates.json
index ef0d618e1..c006a95e9 100644
--- a/data/conf/samples/full_remote/remote/cgrates.json
+++ b/data/conf/samples/full_remote/remote/cgrates.json
@@ -33,7 +33,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/gocs/au_site/cgrates.json b/data/conf/samples/gocs/au_site/cgrates.json
index 2a7bcdc11..924a299b1 100644
--- a/data/conf/samples/gocs/au_site/cgrates.json
+++ b/data/conf/samples/gocs/au_site/cgrates.json
@@ -73,7 +73,7 @@
"chargers_conns": ["*internal"],
},
- "apiers": {
+ "admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["conn1"],
diff --git a/data/conf/samples/gocs/dsp_site/cgrates.json b/data/conf/samples/gocs/dsp_site/cgrates.json
index b37b3a837..67c1e0412 100644
--- a/data/conf/samples/gocs/dsp_site/cgrates.json
+++ b/data/conf/samples/gocs/dsp_site/cgrates.json
@@ -44,7 +44,7 @@
"enabled": true
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"]
}
diff --git a/data/conf/samples/gocs/us_site/cgrates.json b/data/conf/samples/gocs/us_site/cgrates.json
index e507b69dd..6e2b38e54 100644
--- a/data/conf/samples/gocs/us_site/cgrates.json
+++ b/data/conf/samples/gocs/us_site/cgrates.json
@@ -91,7 +91,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["conn1"],
diff --git a/data/conf/samples/httpagent_internal/cgrates.json b/data/conf/samples/httpagent_internal/cgrates.json
index 67721e58e..f76e9e57c 100644
--- a/data/conf/samples/httpagent_internal/cgrates.json
+++ b/data/conf/samples/httpagent_internal/cgrates.json
@@ -56,7 +56,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagent_internal_gob/cgrates.json b/data/conf/samples/httpagent_internal_gob/cgrates.json
index 01a5e964c..d95b1bc14 100644
--- a/data/conf/samples/httpagent_internal_gob/cgrates.json
+++ b/data/conf/samples/httpagent_internal_gob/cgrates.json
@@ -63,7 +63,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagent_mongo/cgrates.json b/data/conf/samples/httpagent_mongo/cgrates.json
index 5ec49683e..1120c0d5b 100644
--- a/data/conf/samples/httpagent_mongo/cgrates.json
+++ b/data/conf/samples/httpagent_mongo/cgrates.json
@@ -59,7 +59,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagent_mongo_gob/cgrates.json b/data/conf/samples/httpagent_mongo_gob/cgrates.json
index 1a6d8febe..c53cbd589 100644
--- a/data/conf/samples/httpagent_mongo_gob/cgrates.json
+++ b/data/conf/samples/httpagent_mongo_gob/cgrates.json
@@ -65,7 +65,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagent_mysql/cgrates.json b/data/conf/samples/httpagent_mysql/cgrates.json
index c05ff7a24..6d1b35c10 100644
--- a/data/conf/samples/httpagent_mysql/cgrates.json
+++ b/data/conf/samples/httpagent_mysql/cgrates.json
@@ -57,7 +57,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagent_mysql_gob/cgrates.json b/data/conf/samples/httpagent_mysql_gob/cgrates.json
index 1e69fcbd5..f29f29412 100644
--- a/data/conf/samples/httpagent_mysql_gob/cgrates.json
+++ b/data/conf/samples/httpagent_mysql_gob/cgrates.json
@@ -64,7 +64,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagenttls_internal/cgrates.json b/data/conf/samples/httpagenttls_internal/cgrates.json
index 5bd04a495..3f367016f 100755
--- a/data/conf/samples/httpagenttls_internal/cgrates.json
+++ b/data/conf/samples/httpagenttls_internal/cgrates.json
@@ -67,7 +67,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagenttls_internal_gob/cgrates.json b/data/conf/samples/httpagenttls_internal_gob/cgrates.json
index 3a2ded0bb..5cad3ed4b 100755
--- a/data/conf/samples/httpagenttls_internal_gob/cgrates.json
+++ b/data/conf/samples/httpagenttls_internal_gob/cgrates.json
@@ -76,7 +76,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagenttls_mongo/cgrates.json b/data/conf/samples/httpagenttls_mongo/cgrates.json
index 0f834ea4b..15c3129e6 100755
--- a/data/conf/samples/httpagenttls_mongo/cgrates.json
+++ b/data/conf/samples/httpagenttls_mongo/cgrates.json
@@ -69,7 +69,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagenttls_mongo_gob/cgrates.json b/data/conf/samples/httpagenttls_mongo_gob/cgrates.json
index 4ad859603..be64ffa39 100755
--- a/data/conf/samples/httpagenttls_mongo_gob/cgrates.json
+++ b/data/conf/samples/httpagenttls_mongo_gob/cgrates.json
@@ -77,7 +77,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagenttls_mysql/cgrates.json b/data/conf/samples/httpagenttls_mysql/cgrates.json
index 25f7d966e..5cf2e4c02 100755
--- a/data/conf/samples/httpagenttls_mysql/cgrates.json
+++ b/data/conf/samples/httpagenttls_mysql/cgrates.json
@@ -67,7 +67,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/httpagenttls_mysql_gob/cgrates.json b/data/conf/samples/httpagenttls_mysql_gob/cgrates.json
index 24de9df89..7b5608f01 100755
--- a/data/conf/samples/httpagenttls_mysql_gob/cgrates.json
+++ b/data/conf/samples/httpagenttls_mysql_gob/cgrates.json
@@ -76,7 +76,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/hundred_rates/cgrates.json b/data/conf/samples/hundred_rates/cgrates.json
index 72a7e7b1a..cfaa9c75c 100644
--- a/data/conf/samples/hundred_rates/cgrates.json
+++ b/data/conf/samples/hundred_rates/cgrates.json
@@ -34,7 +34,7 @@
"enabled": true
},
- "apiers": {
+ "admins": {
"enabled": true,
},
diff --git a/data/conf/samples/internal_broadcast_replication/cgrates.json b/data/conf/samples/internal_broadcast_replication/cgrates.json
index 69ffcde84..1ac311dff 100644
--- a/data/conf/samples/internal_broadcast_replication/cgrates.json
+++ b/data/conf/samples/internal_broadcast_replication/cgrates.json
@@ -105,7 +105,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["broadcast_conn"],
},
diff --git a/data/conf/samples/internal_ttl_internal/cgrates.json b/data/conf/samples/internal_ttl_internal/cgrates.json
index d73792922..df4daac06 100644
--- a/data/conf/samples/internal_ttl_internal/cgrates.json
+++ b/data/conf/samples/internal_ttl_internal/cgrates.json
@@ -50,7 +50,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/loader_mongo/cgrates.json b/data/conf/samples/loader_mongo/cgrates.json
index ffcf3eec1..8009e319a 100644
--- a/data/conf/samples/loader_mongo/cgrates.json
+++ b/data/conf/samples/loader_mongo/cgrates.json
@@ -105,7 +105,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/loader_mysql/cgrates.json b/data/conf/samples/loader_mysql/cgrates.json
index 4bd77807b..7136e9da3 100644
--- a/data/conf/samples/loader_mysql/cgrates.json
+++ b/data/conf/samples/loader_mysql/cgrates.json
@@ -102,7 +102,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/loaders/tutinternal/cgrates.json b/data/conf/samples/loaders/tutinternal/cgrates.json
index c472c07b0..543ba5956 100644
--- a/data/conf/samples/loaders/tutinternal/cgrates.json
+++ b/data/conf/samples/loaders/tutinternal/cgrates.json
@@ -247,7 +247,7 @@
],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/loaders/tutmongo/cgrates.json b/data/conf/samples/loaders/tutmongo/cgrates.json
index 32eff1eb9..94c04f301 100644
--- a/data/conf/samples/loaders/tutmongo/cgrates.json
+++ b/data/conf/samples/loaders/tutmongo/cgrates.json
@@ -296,7 +296,7 @@
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/loaders/tutmysql/cgrates.json b/data/conf/samples/loaders/tutmysql/cgrates.json
index b14a9f38d..c17c653a8 100644
--- a/data/conf/samples/loaders/tutmysql/cgrates.json
+++ b/data/conf/samples/loaders/tutmysql/cgrates.json
@@ -295,7 +295,7 @@
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/mongoatlas/cgrates.json b/data/conf/samples/mongoatlas/cgrates.json
index 15ca36a5a..d7b1ddeea 100755
--- a/data/conf/samples/mongoatlas/cgrates.json
+++ b/data/conf/samples/mongoatlas/cgrates.json
@@ -128,7 +128,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/mongoreplica/cgrates.json b/data/conf/samples/mongoreplica/cgrates.json
index c8ec93954..8a8c9737b 100755
--- a/data/conf/samples/mongoreplica/cgrates.json
+++ b/data/conf/samples/mongoreplica/cgrates.json
@@ -88,7 +88,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/precache/tutmongo/cgrates.json b/data/conf/samples/precache/tutmongo/cgrates.json
index a0ffba293..bfdd18384 100644
--- a/data/conf/samples/precache/tutmongo/cgrates.json
+++ b/data/conf/samples/precache/tutmongo/cgrates.json
@@ -76,7 +76,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/precache/tutmongo_apiban/cgrates.json b/data/conf/samples/precache/tutmongo_apiban/cgrates.json
index a9354e20a..8fdefad76 100644
--- a/data/conf/samples/precache/tutmongo_apiban/cgrates.json
+++ b/data/conf/samples/precache/tutmongo_apiban/cgrates.json
@@ -77,7 +77,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/precache/tutmysql/cgrates.json b/data/conf/samples/precache/tutmysql/cgrates.json
index dad30eca1..7c4a55fee 100644
--- a/data/conf/samples/precache/tutmysql/cgrates.json
+++ b/data/conf/samples/precache/tutmysql/cgrates.json
@@ -67,7 +67,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/precache/tutmysql_apiban/cgrates.json b/data/conf/samples/precache/tutmysql_apiban/cgrates.json
index 6d19d74c9..933b7ddc3 100644
--- a/data/conf/samples/precache/tutmysql_apiban/cgrates.json
+++ b/data/conf/samples/precache/tutmysql_apiban/cgrates.json
@@ -68,7 +68,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/radagent_internal/cgrates.json b/data/conf/samples/radagent_internal/cgrates.json
index 583af9fd8..192574049 100644
--- a/data/conf/samples/radagent_internal/cgrates.json
+++ b/data/conf/samples/radagent_internal/cgrates.json
@@ -70,7 +70,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/radagent_internal_gob/cgrates.json b/data/conf/samples/radagent_internal_gob/cgrates.json
index 9c37f224c..1ee208c66 100644
--- a/data/conf/samples/radagent_internal_gob/cgrates.json
+++ b/data/conf/samples/radagent_internal_gob/cgrates.json
@@ -78,7 +78,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/radagent_mongo/cgrates.json b/data/conf/samples/radagent_mongo/cgrates.json
index c6b968ff5..cacfed812 100644
--- a/data/conf/samples/radagent_mongo/cgrates.json
+++ b/data/conf/samples/radagent_mongo/cgrates.json
@@ -73,7 +73,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/radagent_mongo_gob/cgrates.json b/data/conf/samples/radagent_mongo_gob/cgrates.json
index 87c878090..c17d50e05 100644
--- a/data/conf/samples/radagent_mongo_gob/cgrates.json
+++ b/data/conf/samples/radagent_mongo_gob/cgrates.json
@@ -81,7 +81,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/radagent_mysql/cgrates.json b/data/conf/samples/radagent_mysql/cgrates.json
index ebc611298..4f04821a5 100644
--- a/data/conf/samples/radagent_mysql/cgrates.json
+++ b/data/conf/samples/radagent_mysql/cgrates.json
@@ -69,7 +69,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/radagent_mysql_gob/cgrates.json b/data/conf/samples/radagent_mysql_gob/cgrates.json
index 2ad3043b5..22097a3f5 100644
--- a/data/conf/samples/radagent_mysql_gob/cgrates.json
+++ b/data/conf/samples/radagent_mysql_gob/cgrates.json
@@ -76,7 +76,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/redis_cluster/cgrates.json b/data/conf/samples/redis_cluster/cgrates.json
index 78096f378..83b80df3e 100755
--- a/data/conf/samples/redis_cluster/cgrates.json
+++ b/data/conf/samples/redis_cluster/cgrates.json
@@ -36,7 +36,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/redis_sentinel/cgrates.json b/data/conf/samples/redis_sentinel/cgrates.json
index 24833754b..2cd5377ef 100755
--- a/data/conf/samples/redis_sentinel/cgrates.json
+++ b/data/conf/samples/redis_sentinel/cgrates.json
@@ -35,7 +35,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/redis_tls/cgrates.json b/data/conf/samples/redis_tls/cgrates.json
index a9f4b3c87..9e31ca81a 100755
--- a/data/conf/samples/redis_tls/cgrates.json
+++ b/data/conf/samples/redis_tls/cgrates.json
@@ -39,7 +39,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/registrarc/all2_mongo/cgrates.json b/data/conf/samples/registrarc/all2_mongo/cgrates.json
index afda81f15..7669cb421 100644
--- a/data/conf/samples/registrarc/all2_mongo/cgrates.json
+++ b/data/conf/samples/registrarc/all2_mongo/cgrates.json
@@ -97,7 +97,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/registrarc/all2_mysql/cgrates.json b/data/conf/samples/registrarc/all2_mysql/cgrates.json
index 128c8b029..aea5b87d6 100644
--- a/data/conf/samples/registrarc/all2_mysql/cgrates.json
+++ b/data/conf/samples/registrarc/all2_mysql/cgrates.json
@@ -95,7 +95,7 @@
"chargers_conns": ["*internal"],
},
- "apiers": {
+ "admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/registrarc/all_mongo/cgrates.json b/data/conf/samples/registrarc/all_mongo/cgrates.json
index e0add73c0..c837bf36a 100644
--- a/data/conf/samples/registrarc/all_mongo/cgrates.json
+++ b/data/conf/samples/registrarc/all_mongo/cgrates.json
@@ -101,7 +101,7 @@
"cdrs_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/registrarc/all_mysql/cgrates.json b/data/conf/samples/registrarc/all_mysql/cgrates.json
index d2b5e0749..30474506b 100644
--- a/data/conf/samples/registrarc/all_mysql/cgrates.json
+++ b/data/conf/samples/registrarc/all_mysql/cgrates.json
@@ -99,7 +99,7 @@
"cdrs_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["conn1"],
"scheduler_conns": ["*internal"],
diff --git a/data/conf/samples/registrarc/dispatchers_mongo/cgrates.json b/data/conf/samples/registrarc/dispatchers_mongo/cgrates.json
index 3d763cbf2..a65806875 100644
--- a/data/conf/samples/registrarc/dispatchers_mongo/cgrates.json
+++ b/data/conf/samples/registrarc/dispatchers_mongo/cgrates.json
@@ -67,7 +67,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/registrarc/dispatchers_mysql/cgrates.json b/data/conf/samples/registrarc/dispatchers_mysql/cgrates.json
index bec156c79..3cacfbe75 100755
--- a/data/conf/samples/registrarc/dispatchers_mysql/cgrates.json
+++ b/data/conf/samples/registrarc/dispatchers_mysql/cgrates.json
@@ -56,7 +56,7 @@
"enabled": true,
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/registrarc/registrarc_rpc_mongo/cgrates.json b/data/conf/samples/registrarc/registrarc_rpc_mongo/cgrates.json
index 140cebb48..7563f2fb2 100644
--- a/data/conf/samples/registrarc/registrarc_rpc_mongo/cgrates.json
+++ b/data/conf/samples/registrarc/registrarc_rpc_mongo/cgrates.json
@@ -116,7 +116,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/registrarc/registrarc_rpc_mysql/cgrates.json b/data/conf/samples/registrarc/registrarc_rpc_mysql/cgrates.json
index 5e44367dd..317d69908 100644
--- a/data/conf/samples/registrarc/registrarc_rpc_mysql/cgrates.json
+++ b/data/conf/samples/registrarc/registrarc_rpc_mysql/cgrates.json
@@ -113,7 +113,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/registrarc/registrars_rpc_mongo/cgrates.json b/data/conf/samples/registrarc/registrars_rpc_mongo/cgrates.json
index 0fb4b0edc..91c4dbb48 100644
--- a/data/conf/samples/registrarc/registrars_rpc_mongo/cgrates.json
+++ b/data/conf/samples/registrarc/registrars_rpc_mongo/cgrates.json
@@ -42,7 +42,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/registrarc/registrars_rpc_mysql/cgrates.json b/data/conf/samples/registrarc/registrars_rpc_mysql/cgrates.json
index 109faa84f..cde76ee80 100644
--- a/data/conf/samples/registrarc/registrars_rpc_mysql/cgrates.json
+++ b/data/conf/samples/registrarc/registrars_rpc_mysql/cgrates.json
@@ -39,7 +39,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/conf/samples/remote_replication/engine1_mongo/cgrates.json b/data/conf/samples/remote_replication/engine1_mongo/cgrates.json
index 1ca49c2cc..82bf68368 100644
--- a/data/conf/samples/remote_replication/engine1_mongo/cgrates.json
+++ b/data/conf/samples/remote_replication/engine1_mongo/cgrates.json
@@ -35,7 +35,7 @@
"enabled": true,
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/remote_replication/engine1_redis/cgrates.json b/data/conf/samples/remote_replication/engine1_redis/cgrates.json
index e2d4c6bf5..8b54805d0 100644
--- a/data/conf/samples/remote_replication/engine1_redis/cgrates.json
+++ b/data/conf/samples/remote_replication/engine1_redis/cgrates.json
@@ -32,7 +32,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/remote_replication/engine2_mongo/cgrates.json b/data/conf/samples/remote_replication/engine2_mongo/cgrates.json
index 34264e1a3..da6efde5e 100644
--- a/data/conf/samples/remote_replication/engine2_mongo/cgrates.json
+++ b/data/conf/samples/remote_replication/engine2_mongo/cgrates.json
@@ -45,7 +45,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"caches_conns": ["replicateToCache"],
diff --git a/data/conf/samples/remote_replication/engine2_redis/cgrates.json b/data/conf/samples/remote_replication/engine2_redis/cgrates.json
index 1d54116fe..f60d9f986 100644
--- a/data/conf/samples/remote_replication/engine2_redis/cgrates.json
+++ b/data/conf/samples/remote_replication/engine2_redis/cgrates.json
@@ -43,7 +43,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"caches_conns": ["replicateToCache"],
diff --git a/data/conf/samples/remote_replication/internal/cgrates.json b/data/conf/samples/remote_replication/internal/cgrates.json
index 2bc39b4ae..12627fae8 100644
--- a/data/conf/samples/remote_replication/internal/cgrates.json
+++ b/data/conf/samples/remote_replication/internal/cgrates.json
@@ -91,7 +91,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"caches_conns":["connCache"],
diff --git a/data/conf/samples/remote_replication/internal_gob/cgrates.json b/data/conf/samples/remote_replication/internal_gob/cgrates.json
index 91a5c98e9..8aa9c3c34 100644
--- a/data/conf/samples/remote_replication/internal_gob/cgrates.json
+++ b/data/conf/samples/remote_replication/internal_gob/cgrates.json
@@ -89,7 +89,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/replication/engine1_mongo/cgrates.json b/data/conf/samples/replication/engine1_mongo/cgrates.json
index af6564a5a..3fb0c0765 100644
--- a/data/conf/samples/replication/engine1_mongo/cgrates.json
+++ b/data/conf/samples/replication/engine1_mongo/cgrates.json
@@ -35,7 +35,7 @@
"enabled": true,
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/replication/engine1_redis/cgrates.json b/data/conf/samples/replication/engine1_redis/cgrates.json
index 4a7b4cdfc..1a5b22f1a 100644
--- a/data/conf/samples/replication/engine1_redis/cgrates.json
+++ b/data/conf/samples/replication/engine1_redis/cgrates.json
@@ -32,7 +32,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/replication/engine2_mongo/cgrates.json b/data/conf/samples/replication/engine2_mongo/cgrates.json
index bf9c0fd6e..aac4f413a 100644
--- a/data/conf/samples/replication/engine2_mongo/cgrates.json
+++ b/data/conf/samples/replication/engine2_mongo/cgrates.json
@@ -36,7 +36,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/replication/engine2_redis/cgrates.json b/data/conf/samples/replication/engine2_redis/cgrates.json
index 1fa5548b7..47c6c27ed 100644
--- a/data/conf/samples/replication/engine2_redis/cgrates.json
+++ b/data/conf/samples/replication/engine2_redis/cgrates.json
@@ -32,7 +32,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/replication/internal/cgrates.json b/data/conf/samples/replication/internal/cgrates.json
index 3a36b6353..7e056d356 100644
--- a/data/conf/samples/replication/internal/cgrates.json
+++ b/data/conf/samples/replication/internal/cgrates.json
@@ -85,7 +85,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"caches_conns":["connCache"],
diff --git a/data/conf/samples/replication/internal_gob/cgrates.json b/data/conf/samples/replication/internal_gob/cgrates.json
index 17f2e9b45..2b4185a11 100644
--- a/data/conf/samples/replication/internal_gob/cgrates.json
+++ b/data/conf/samples/replication/internal_gob/cgrates.json
@@ -85,7 +85,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
"caches_conns":["connCache"],
diff --git a/data/conf/samples/replication_cache/engine1/cgrates.json b/data/conf/samples/replication_cache/engine1/cgrates.json
index b325260e3..4e6cd1f52 100644
--- a/data/conf/samples/replication_cache/engine1/cgrates.json
+++ b/data/conf/samples/replication_cache/engine1/cgrates.json
@@ -65,7 +65,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"]
},
diff --git a/data/conf/samples/replication_cache/engine2/cgrates.json b/data/conf/samples/replication_cache/engine2/cgrates.json
index ddb912305..dfc908730 100644
--- a/data/conf/samples/replication_cache/engine2/cgrates.json
+++ b/data/conf/samples/replication_cache/engine2/cgrates.json
@@ -43,7 +43,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/rpccaching_mongo/cgrates.json b/data/conf/samples/rpccaching_mongo/cgrates.json
index 0b4df8459..43236ec35 100644
--- a/data/conf/samples/rpccaching_mongo/cgrates.json
+++ b/data/conf/samples/rpccaching_mongo/cgrates.json
@@ -76,7 +76,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/rpccaching_mysql/cgrates.json b/data/conf/samples/rpccaching_mysql/cgrates.json
index 25521adee..57db5d043 100644
--- a/data/conf/samples/rpccaching_mysql/cgrates.json
+++ b/data/conf/samples/rpccaching_mysql/cgrates.json
@@ -66,7 +66,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessinternal/cgrates.json b/data/conf/samples/sessinternal/cgrates.json
index f9e66d0c5..e60933eff 100644
--- a/data/conf/samples/sessinternal/cgrates.json
+++ b/data/conf/samples/sessinternal/cgrates.json
@@ -86,7 +86,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessintjson/cgrates.json b/data/conf/samples/sessintjson/cgrates.json
index 86e8ef44c..2aa05f8a6 100644
--- a/data/conf/samples/sessintjson/cgrates.json
+++ b/data/conf/samples/sessintjson/cgrates.json
@@ -86,7 +86,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*localhost"],
},
diff --git a/data/conf/samples/sessions_internal/cgrates.json b/data/conf/samples/sessions_internal/cgrates.json
index 3aaa18af5..a8670e4a0 100644
--- a/data/conf/samples/sessions_internal/cgrates.json
+++ b/data/conf/samples/sessions_internal/cgrates.json
@@ -93,7 +93,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessions_mongo/cgrates.json b/data/conf/samples/sessions_mongo/cgrates.json
index 2b713070b..3ee9cc6c4 100644
--- a/data/conf/samples/sessions_mongo/cgrates.json
+++ b/data/conf/samples/sessions_mongo/cgrates.json
@@ -98,7 +98,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessions_mysql/cgrates.json b/data/conf/samples/sessions_mysql/cgrates.json
index e52ad4246..9670be17e 100644
--- a/data/conf/samples/sessions_mysql/cgrates.json
+++ b/data/conf/samples/sessions_mysql/cgrates.json
@@ -94,7 +94,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessions_replication/smgreplcmaster_mongo/cgrates.json b/data/conf/samples/sessions_replication/smgreplcmaster_mongo/cgrates.json
index b70e32726..b89c15fe8 100644
--- a/data/conf/samples/sessions_replication/smgreplcmaster_mongo/cgrates.json
+++ b/data/conf/samples/sessions_replication/smgreplcmaster_mongo/cgrates.json
@@ -65,7 +65,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessions_replication/smgreplcmaster_mysql/cgrates.json b/data/conf/samples/sessions_replication/smgreplcmaster_mysql/cgrates.json
index 9d9f3a2df..55688b772 100644
--- a/data/conf/samples/sessions_replication/smgreplcmaster_mysql/cgrates.json
+++ b/data/conf/samples/sessions_replication/smgreplcmaster_mysql/cgrates.json
@@ -56,7 +56,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessions_replication/smgreplcslave_mongo/cgrates.json b/data/conf/samples/sessions_replication/smgreplcslave_mongo/cgrates.json
index 127cb1cb0..f4236e0d0 100644
--- a/data/conf/samples/sessions_replication/smgreplcslave_mongo/cgrates.json
+++ b/data/conf/samples/sessions_replication/smgreplcslave_mongo/cgrates.json
@@ -70,7 +70,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sessions_replication/smgreplcslave_mysql/cgrates.json b/data/conf/samples/sessions_replication/smgreplcslave_mysql/cgrates.json
index 3bdabaa7b..f5590878c 100644
--- a/data/conf/samples/sessions_replication/smgreplcslave_mysql/cgrates.json
+++ b/data/conf/samples/sessions_replication/smgreplcslave_mysql/cgrates.json
@@ -61,7 +61,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sipagent_internal/cgrates.json b/data/conf/samples/sipagent_internal/cgrates.json
index 82aae0dc1..f12a0ae8f 100644
--- a/data/conf/samples/sipagent_internal/cgrates.json
+++ b/data/conf/samples/sipagent_internal/cgrates.json
@@ -77,7 +77,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sipagent_mongo/cgrates.json b/data/conf/samples/sipagent_mongo/cgrates.json
index e27163ba7..796288533 100644
--- a/data/conf/samples/sipagent_mongo/cgrates.json
+++ b/data/conf/samples/sipagent_mongo/cgrates.json
@@ -74,7 +74,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/sipagent_mysql/cgrates.json b/data/conf/samples/sipagent_mysql/cgrates.json
index 8a6d0533a..51e87ecab 100644
--- a/data/conf/samples/sipagent_mysql/cgrates.json
+++ b/data/conf/samples/sipagent_mysql/cgrates.json
@@ -67,7 +67,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smg_automatic_debits_internal/cgrates.json b/data/conf/samples/smg_automatic_debits_internal/cgrates.json
index 5e98c9964..d84eae912 100644
--- a/data/conf/samples/smg_automatic_debits_internal/cgrates.json
+++ b/data/conf/samples/smg_automatic_debits_internal/cgrates.json
@@ -46,7 +46,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smg_automatic_debits_mongo/cgrates.json b/data/conf/samples/smg_automatic_debits_mongo/cgrates.json
index 42532ab8e..85b207057 100644
--- a/data/conf/samples/smg_automatic_debits_mongo/cgrates.json
+++ b/data/conf/samples/smg_automatic_debits_mongo/cgrates.json
@@ -51,7 +51,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smg_automatic_debits_mysql/cgrates.json b/data/conf/samples/smg_automatic_debits_mysql/cgrates.json
index 7d1c99173..b012f931a 100644
--- a/data/conf/samples/smg_automatic_debits_mysql/cgrates.json
+++ b/data/conf/samples/smg_automatic_debits_mysql/cgrates.json
@@ -47,7 +47,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcmaster_mongo/cgrates.json b/data/conf/samples/smgreplcmaster_mongo/cgrates.json
index 22d9fe19c..8df31f57f 100644
--- a/data/conf/samples/smgreplcmaster_mongo/cgrates.json
+++ b/data/conf/samples/smgreplcmaster_mongo/cgrates.json
@@ -64,7 +64,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json b/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json
index a8354daf5..2215480c6 100644
--- a/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json
+++ b/data/conf/samples/smgreplcmaster_mongo_gob/cgrates.json
@@ -64,7 +64,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcmaster_mysql/cgrates.json b/data/conf/samples/smgreplcmaster_mysql/cgrates.json
index f979e4758..47fe40c6e 100644
--- a/data/conf/samples/smgreplcmaster_mysql/cgrates.json
+++ b/data/conf/samples/smgreplcmaster_mysql/cgrates.json
@@ -55,7 +55,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcmaster_mysql_gob/cgrates.json b/data/conf/samples/smgreplcmaster_mysql_gob/cgrates.json
index 63d67116b..3907dd644 100644
--- a/data/conf/samples/smgreplcmaster_mysql_gob/cgrates.json
+++ b/data/conf/samples/smgreplcmaster_mysql_gob/cgrates.json
@@ -55,7 +55,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcslave_mongo/cgrates.json b/data/conf/samples/smgreplcslave_mongo/cgrates.json
index fd313f34b..30b82e0fc 100644
--- a/data/conf/samples/smgreplcslave_mongo/cgrates.json
+++ b/data/conf/samples/smgreplcslave_mongo/cgrates.json
@@ -69,7 +69,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json b/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json
index 0bbc5aa51..24fd95d65 100644
--- a/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json
+++ b/data/conf/samples/smgreplcslave_mongo_gob/cgrates.json
@@ -68,7 +68,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcslave_mysql/cgrates.json b/data/conf/samples/smgreplcslave_mysql/cgrates.json
index b9113ca2d..dcd389b10 100644
--- a/data/conf/samples/smgreplcslave_mysql/cgrates.json
+++ b/data/conf/samples/smgreplcslave_mysql/cgrates.json
@@ -59,7 +59,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/smgreplcslave_mysql_gob/cgrates.json b/data/conf/samples/smgreplcslave_mysql_gob/cgrates.json
index 07baae109..ab813785e 100644
--- a/data/conf/samples/smgreplcslave_mysql_gob/cgrates.json
+++ b/data/conf/samples/smgreplcslave_mysql_gob/cgrates.json
@@ -58,7 +58,7 @@
"chargers_conns": ["*internal"],
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutinternal/cgrates.json b/data/conf/samples/tutinternal/cgrates.json
index fdbec58d4..5104bfa20 100644
--- a/data/conf/samples/tutinternal/cgrates.json
+++ b/data/conf/samples/tutinternal/cgrates.json
@@ -99,7 +99,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"]
},
diff --git a/data/conf/samples/tutinternal_gob/cgrates.json b/data/conf/samples/tutinternal_gob/cgrates.json
index 25015e6e3..ab7e8763c 100644
--- a/data/conf/samples/tutinternal_gob/cgrates.json
+++ b/data/conf/samples/tutinternal_gob/cgrates.json
@@ -100,7 +100,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["conn1"],
},
diff --git a/data/conf/samples/tutinternal_new/cgrates.json b/data/conf/samples/tutinternal_new/cgrates.json
index 70682c476..65abb3bfc 100644
--- a/data/conf/samples/tutinternal_new/cgrates.json
+++ b/data/conf/samples/tutinternal_new/cgrates.json
@@ -95,7 +95,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmongo/cgrates.json b/data/conf/samples/tutmongo/cgrates.json
index 914cc46ff..6db2a5546 100644
--- a/data/conf/samples/tutmongo/cgrates.json
+++ b/data/conf/samples/tutmongo/cgrates.json
@@ -114,7 +114,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmongo2/cgrates.json b/data/conf/samples/tutmongo2/cgrates.json
index de47c2d11..484440a7e 100644
--- a/data/conf/samples/tutmongo2/cgrates.json
+++ b/data/conf/samples/tutmongo2/cgrates.json
@@ -140,7 +140,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmongo2_gob/cgrates.json b/data/conf/samples/tutmongo2_gob/cgrates.json
index 93a6f2275..db0e07b0e 100644
--- a/data/conf/samples/tutmongo2_gob/cgrates.json
+++ b/data/conf/samples/tutmongo2_gob/cgrates.json
@@ -147,7 +147,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmongo_gob/cgrates.json b/data/conf/samples/tutmongo_gob/cgrates.json
index 80a547bce..d2d653377 100644
--- a/data/conf/samples/tutmongo_gob/cgrates.json
+++ b/data/conf/samples/tutmongo_gob/cgrates.json
@@ -111,7 +111,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmongojson/cgrates.json b/data/conf/samples/tutmongojson/cgrates.json
index 699bf98ef..5c1e3ceff 100644
--- a/data/conf/samples/tutmongojson/cgrates.json
+++ b/data/conf/samples/tutmongojson/cgrates.json
@@ -110,7 +110,7 @@
},
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmongonew/cgrates.json b/data/conf/samples/tutmongonew/cgrates.json
index 7873eac34..03dfce873 100644
--- a/data/conf/samples/tutmongonew/cgrates.json
+++ b/data/conf/samples/tutmongonew/cgrates.json
@@ -101,7 +101,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmysql/cgrates.json b/data/conf/samples/tutmysql/cgrates.json
index 422b140e1..fee8b3891 100644
--- a/data/conf/samples/tutmysql/cgrates.json
+++ b/data/conf/samples/tutmysql/cgrates.json
@@ -106,7 +106,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmysql2/cgrates.json b/data/conf/samples/tutmysql2/cgrates.json
index 54a49a221..08c0b4731 100644
--- a/data/conf/samples/tutmysql2/cgrates.json
+++ b/data/conf/samples/tutmysql2/cgrates.json
@@ -95,7 +95,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*localhost"],
},
diff --git a/data/conf/samples/tutmysql2_gob/cgrates.json b/data/conf/samples/tutmysql2_gob/cgrates.json
index 0e63c6f9a..29ff76c21 100644
--- a/data/conf/samples/tutmysql2_gob/cgrates.json
+++ b/data/conf/samples/tutmysql2_gob/cgrates.json
@@ -104,7 +104,7 @@
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmysql_internal/cgrates.json b/data/conf/samples/tutmysql_internal/cgrates.json
index 30ce55c64..884629450 100644
--- a/data/conf/samples/tutmysql_internal/cgrates.json
+++ b/data/conf/samples/tutmysql_internal/cgrates.json
@@ -215,7 +215,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutmysqljson/cgrates.json b/data/conf/samples/tutmysqljson/cgrates.json
index 6aa731592..087fa1167 100644
--- a/data/conf/samples/tutmysqljson/cgrates.json
+++ b/data/conf/samples/tutmysqljson/cgrates.json
@@ -106,7 +106,7 @@
- "apiers": {
+ "admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/tutpostgres/cgrates.json b/data/conf/samples/tutpostgres/cgrates.json
index eea667341..064bf48c6 100644
--- a/data/conf/samples/tutpostgres/cgrates.json
+++ b/data/conf/samples/tutpostgres/cgrates.json
@@ -93,7 +93,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/conf/samples/twoengines/engine1/cgrates.json b/data/conf/samples/twoengines/engine1/cgrates.json
index 68350b91a..faa02210d 100644
--- a/data/conf/samples/twoengines/engine1/cgrates.json
+++ b/data/conf/samples/twoengines/engine1/cgrates.json
@@ -40,7 +40,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"caches_conns":["cacheConn"]
},
diff --git a/data/conf/samples/twoengines/engine2/cgrates.json b/data/conf/samples/twoengines/engine2/cgrates.json
index 485db6c9c..ffa05fb3b 100644
--- a/data/conf/samples/twoengines/engine2/cgrates.json
+++ b/data/conf/samples/twoengines/engine2/cgrates.json
@@ -29,7 +29,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
},
diff --git a/data/tutorial_tests/asterisk_ari/cgrates/etc/cgrates/cgrates.json b/data/tutorial_tests/asterisk_ari/cgrates/etc/cgrates/cgrates.json
index 04384149c..46ebba6f4 100644
--- a/data/tutorial_tests/asterisk_ari/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorial_tests/asterisk_ari/cgrates/etc/cgrates/cgrates.json
@@ -108,7 +108,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorial_tests/fs_evsock/cgrates/etc/cgrates/cgrates.json b/data/tutorial_tests/fs_evsock/cgrates/etc/cgrates/cgrates.json
index 0a39d7331..1e978db08 100644
--- a/data/tutorial_tests/fs_evsock/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorial_tests/fs_evsock/cgrates/etc/cgrates/cgrates.json
@@ -106,7 +106,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorial_tests/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorial_tests/kamevapi/cgrates/etc/cgrates/cgrates.json
index ce4cc333e..9ec3bb984 100644
--- a/data/tutorial_tests/kamevapi/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorial_tests/kamevapi/cgrates/etc/cgrates/cgrates.json
@@ -107,7 +107,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorial_tests/osips/cgrates/etc/cgrates/cgrates.json b/data/tutorial_tests/osips/cgrates/etc/cgrates/cgrates.json
index ea2a0ddc5..b4d305b4f 100644
--- a/data/tutorial_tests/osips/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorial_tests/osips/cgrates/etc/cgrates/cgrates.json
@@ -98,7 +98,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json
index 5c0214ea4..c65880b0b 100644
--- a/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorials/asterisk_ari/cgrates/etc/cgrates/cgrates.json
@@ -107,7 +107,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json
index 0a39d7331..1e978db08 100644
--- a/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorials/fs_evsock/cgrates/etc/cgrates/cgrates.json
@@ -106,7 +106,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json
index 577bb8d1f..07731fa3c 100644
--- a/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorials/kamevapi/cgrates/etc/cgrates/cgrates.json
@@ -107,7 +107,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json b/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json
index 447e22911..c46e73743 100644
--- a/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorials/osips/cgrates/etc/cgrates/cgrates.json
@@ -97,7 +97,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/data/tutorials/sip_redirect/cgrates/etc/cgrates/cgrates.json b/data/tutorials/sip_redirect/cgrates/etc/cgrates/cgrates.json
index f37a400c5..8870bd3b9 100644
--- a/data/tutorials/sip_redirect/cgrates/etc/cgrates/cgrates.json
+++ b/data/tutorials/sip_redirect/cgrates/etc/cgrates/cgrates.json
@@ -96,7 +96,7 @@
},
-"apiers": {
+"admins": {
"enabled": true,
"scheduler_conns": ["*internal"],
},
diff --git a/dispatchers/attributes.go b/dispatchers/attributes.go
old mode 100755
new mode 100644
diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/chargers.go b/dispatchers/chargers.go
old mode 100755
new mode 100644
diff --git a/dispatchers/chargers_it_test.go b/dispatchers/chargers_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/dispatchers.go b/dispatchers/dispatchers.go
old mode 100755
new mode 100644
diff --git a/dispatchers/resources.go b/dispatchers/resources.go
old mode 100755
new mode 100644
diff --git a/dispatchers/resources_it_test.go b/dispatchers/resources_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/responder_it_test.go b/dispatchers/responder_it_test.go
deleted file mode 100644
index 7aa6d6948..000000000
--- a/dispatchers/responder_it_test.go
+++ /dev/null
@@ -1,240 +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 (
- "fmt"
- "testing"
- "time"
-
- "github.com/cgrates/cgrates/utils"
- "github.com/cgrates/rpcclient"
-)
-
-var sTestsDspRsp = []func(t *testing.T){
- testDspResponderStatus,
- testDspResponderShutdown,
-
- testDspResponderRandom,
- testDspResponderBroadcast,
- testDspResponderInternal,
-}
-
-//Test start here
-func TestDspResponder(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, sTestsDspRsp, "TestDspResponder", config1, config2, config3, "tutorial", "oldtutorial", dispDIR)
-}
-
-func testDspResponderStatus(t *testing.T) {
- var reply map[string]interface{}
- if err := allEngine.RPC.Call(utils.CoreSv1Status, utils.TenantWithAPIOpts{}, &reply); err != nil {
- t.Error(err)
- } else if reply[utils.NodeID] != "ALL" {
- t.Errorf("Received: %s", reply)
- }
- ev := utils.TenantWithAPIOpts{
- Tenant: "cgrates.org",
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- },
- }
- if err := dispEngine.RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil {
- t.Error(err)
- } else if reply[utils.NodeID] != "ALL" {
- t.Errorf("Received: %s", utils.ToJSON(reply))
- }
- allEngine.stopEngine(t)
- if err := dispEngine.RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil {
- t.Error(err)
- } else if reply[utils.NodeID] != "ALL2" {
- t.Errorf("Received: %s", utils.ToJSON(reply))
- }
- allEngine.startEngine(t)
-}
-
-func getNodeWithRoute(route string, t *testing.T) string {
- var reply map[string]interface{}
- var pingReply string
- pingEv := utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.EventName: "Random",
- },
-
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- utils.OptsRouteID: route,
- },
- }
- ev := utils.TenantWithAPIOpts{
- Tenant: "cgrates.org",
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- utils.OptsRouteID: route,
- },
- }
-
- if err := dispEngine.RPC.Call(utils.CoreSv1Ping, pingEv, &pingReply); err != nil {
- t.Error(err)
- } else if pingReply != utils.Pong {
- t.Errorf("Received: %s", pingReply)
- }
- if err := dispEngine.RPC.Call(utils.CoreSv1Status, ev, &reply); err != nil {
- t.Error(err)
- }
- if reply[utils.NodeID] == nil {
- return ""
- }
- return reply[utils.NodeID].(string)
-}
-
-func testDspResponderRandom(t *testing.T) {
- node := getNodeWithRoute("r_init", t)
- for i := 0; i < 10; i++ {
- if node != getNodeWithRoute(fmt.Sprintf("R_%v", i), t) {
- return
- }
- }
- t.Errorf("Random strategy fail with 0.0009765625%% probability")
-}
-
-func testDspResponderShutdown(t *testing.T) {
- var reply string
- var statusReply map[string]interface{}
- ev := utils.TenantWithAPIOpts{
- Tenant: "cgrates.org",
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- },
- }
- if err := dispEngine.RPC.Call(utils.ResponderShutdown, ev, &reply); err != nil {
- t.Error(err)
- } else if reply != "Done!" {
- t.Errorf("Received: %s", utils.ToJSON(reply))
- }
- if err := dispEngine.RPC.Call(utils.CoreSv1Status, &ev, &statusReply); err != nil {
- t.Error(err)
- } else if statusReply[utils.NodeID] != "ALL2" {
- t.Errorf("Received: %s", utils.ToJSON(statusReply))
- }
- if err := dispEngine.RPC.Call(utils.ResponderShutdown, &ev, &reply); err != nil {
- t.Error(err)
- } else if reply != "Done!" {
- t.Errorf("Received: %s", utils.ToJSON(reply))
- }
- allEngine.startEngine(t)
- allEngine2.startEngine(t)
-}
-
-func testDspResponderBroadcast(t *testing.T) {
- var pingReply string
- pingEv := utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.EventName: "Broadcast",
- },
-
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- },
- }
- if err := dispEngine.RPC.Call(utils.ResponderPing, pingEv, &pingReply); err != nil {
- t.Error(err)
- } else if pingReply != utils.Pong {
- t.Errorf("Received: %s", pingReply)
- }
-
- allEngine2.stopEngine(t)
- pingReply = ""
- if err := dispEngine.RPC.Call(utils.ResponderPing, pingEv, &pingReply); err == nil ||
- err.Error() != utils.ErrPartiallyExecuted.Error() {
- t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrPartiallyExecuted.Error(), err, pingReply)
- }
- allEngine.stopEngine(t)
- time.Sleep(10 * time.Millisecond)
- pingReply = ""
- if err := dispEngine.RPC.Call(utils.ResponderPing, pingEv, &pingReply); err == nil ||
- !rpcclient.IsNetworkError(err) {
- t.Errorf("Expected error: %s received error: %v and reply %q", utils.ErrPartiallyExecuted.Error(), err, pingReply)
- }
- allEngine.startEngine(t)
- allEngine2.startEngine(t)
-}
-
-func testDspResponderInternal(t *testing.T) {
- var reply map[string]interface{}
- var pingReply string
- route := "internal"
- pingEv := utils.CGREvent{
- Tenant: "cgrates.org",
- Event: map[string]interface{}{
- utils.EventName: "Internal",
- },
-
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- utils.OptsRouteID: route,
- },
- }
- ev := utils.TenantWithAPIOpts{
- Tenant: "cgrates.org",
- APIOpts: map[string]interface{}{
- utils.OptsAPIKey: "rsp12345",
- utils.OptsRouteID: route,
- },
- }
- if err := dispEngine.RPC.Call(utils.CoreSv1Ping, pingEv, &pingReply); err != nil {
- t.Error(err)
- } else if pingReply != utils.Pong {
- t.Errorf("Received: %s", pingReply)
- }
- if err := dispEngine.RPC.Call(utils.CoreSv1Status, &ev, &reply); err != nil {
- t.Error(err)
- }
- if reply[utils.NodeID] == nil {
- return
- }
- if strRply := reply[utils.NodeID].(string); strRply != "DispatcherS1" {
- t.Errorf("Expected: DispatcherS1 , received: %s", strRply)
- }
-}
diff --git a/dispatchers/routes.go b/dispatchers/routes.go
old mode 100755
new mode 100644
diff --git a/dispatchers/routes_it_test.go b/dispatchers/routes_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/sessions.go b/dispatchers/sessions.go
old mode 100755
new mode 100644
diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/stats.go b/dispatchers/stats.go
old mode 100755
new mode 100644
diff --git a/dispatchers/stats_it_test.go b/dispatchers/stats_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/thresholds.go b/dispatchers/thresholds.go
old mode 100755
new mode 100644
diff --git a/dispatchers/thresholds_it_test.go b/dispatchers/thresholds_it_test.go
old mode 100755
new mode 100644
diff --git a/dispatchers/utils.go b/dispatchers/utils.go
old mode 100755
new mode 100644
diff --git a/docs/conf.py b/docs/conf.py
index ce9c12fec..73e4b3237 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -217,4 +217,3 @@ man_pages = [
# extensions = ['autoapi.extension']
# autoapi_type = 'go'
-# autoapi_dirs = ['../apier/v1']
diff --git a/engine/chargers_test.go b/engine/chargers_test.go
old mode 100755
new mode 100644
diff --git a/engine/route_highestcost.go b/engine/route_highestcost.go
old mode 100755
new mode 100644
diff --git a/engine/route_qos.go b/engine/route_qos.go
old mode 100755
new mode 100644
diff --git a/engine/route_weight.go b/engine/route_weight.go
old mode 100755
new mode 100644
diff --git a/engine/tpexporter.go b/engine/tpexporter.go
index abfd07bee..cedb4a241 100644
--- a/engine/tpexporter.go
+++ b/engine/tpexporter.go
@@ -87,7 +87,7 @@ func (tpExp *TPExporter) Run() error {
storDataTimings, err := tpExp.storDB.GetTPTimings(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.TpTiming))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpTiming))
withError = true
}
@@ -98,7 +98,7 @@ func (tpExp *TPExporter) Run() error {
storDataDestinations, err := tpExp.storDB.GetTPDestinations(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.TpDestinations))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpDestinations))
withError = true
}
for _, sd := range storDataDestinations {
@@ -110,7 +110,7 @@ func (tpExp *TPExporter) Run() error {
storDataResources, err := tpExp.storDB.GetTPResources(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.TpResources))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpResources))
withError = true
}
for _, sd := range storDataResources {
@@ -122,7 +122,7 @@ func (tpExp *TPExporter) Run() error {
storDataStats, err := tpExp.storDB.GetTPStats(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.TpStats))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpStats))
withError = true
}
for _, sd := range storDataStats {
@@ -134,7 +134,7 @@ func (tpExp *TPExporter) Run() error {
storDataThresholds, err := tpExp.storDB.GetTPThresholds(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.TpThresholds))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpThresholds))
withError = true
}
for _, sd := range storDataThresholds {
@@ -146,7 +146,7 @@ func (tpExp *TPExporter) Run() error {
storDataFilters, err := tpExp.storDB.GetTPFilters(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.TpFilters))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpFilters))
withError = true
}
for _, sd := range storDataFilters {
@@ -158,7 +158,7 @@ func (tpExp *TPExporter) Run() error {
storDataRoutes, err := tpExp.storDB.GetTPRoutes(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.TpRoutes))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpRoutes))
withError = true
}
for _, sd := range storDataRoutes {
@@ -170,7 +170,7 @@ func (tpExp *TPExporter) Run() error {
storeDataAttributes, err := tpExp.storDB.GetTPAttributes(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.TpAttributes))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpAttributes))
withError = true
}
for _, sd := range storeDataAttributes {
@@ -182,7 +182,7 @@ func (tpExp *TPExporter) Run() error {
storDataChargers, err := tpExp.storDB.GetTPChargers(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.TpChargers))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpChargers))
withError = true
}
for _, sd := range storDataChargers {
@@ -194,7 +194,7 @@ func (tpExp *TPExporter) Run() error {
storDataDispatcherProfiles, err := tpExp.storDB.GetTPDispatcherProfiles(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.TpDispatcherProfiles))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpDispatcherProfiles))
withError = true
}
for _, sd := range storDataDispatcherProfiles {
@@ -206,7 +206,7 @@ func (tpExp *TPExporter) Run() error {
storDataDispatcherHosts, err := tpExp.storDB.GetTPDispatcherHosts(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.TpDispatcherHosts))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpDispatcherHosts))
withError = true
}
for _, sd := range storDataDispatcherHosts {
@@ -215,7 +215,7 @@ func (tpExp *TPExporter) Run() error {
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))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpRateProfiles))
withError = true
}
for _, sd := range storDataRateProfiles {
@@ -227,7 +227,7 @@ func (tpExp *TPExporter) Run() error {
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))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpActionProfiles))
withError = true
}
for _, sd := range storDataActionProfiles {
@@ -239,7 +239,7 @@ func (tpExp *TPExporter) Run() error {
storDataAccounts, err := tpExp.storDB.GetTPAccounts(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.TpAccounts))
+ utils.Logger.Warning(fmt.Sprintf("<%s> error: %s, when getting %s from stordb for export", utils.AdminS, err, utils.TpAccounts))
withError = true
}
for _, sd := range storDataAccounts {
diff --git a/ers/filefwv_it_test.go b/ers/filefwv_it_test.go
index a31948e88..96b6890a7 100644
--- a/ers/filefwv_it_test.go
+++ b/ers/filefwv_it_test.go
@@ -28,7 +28,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/ers/filejson_it_test.go b/ers/filejson_it_test.go
index 53963c047..a2089b590 100644
--- a/ers/filejson_it_test.go
+++ b/ers/filejson_it_test.go
@@ -27,9 +27,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
-
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/config"
diff --git a/ers/flatstore_it_test.go b/ers/flatstore_it_test.go
index f621e82f3..d67daa2dc 100644
--- a/ers/flatstore_it_test.go
+++ b/ers/flatstore_it_test.go
@@ -27,8 +27,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
-
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/ers/partial_csv_it_test.go b/ers/partial_csv_it_test.go
index f3b0db82e..109b6c1cf 100644
--- a/ers/partial_csv_it_test.go
+++ b/ers/partial_csv_it_test.go
@@ -29,8 +29,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
-
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/a1_it_test.go b/general_tests/a1_it_test.go
index dc392001a..355e47a8d 100644
--- a/general_tests/a1_it_test.go
+++ b/general_tests/a1_it_test.go
@@ -28,8 +28,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
diff --git a/general_tests/cacherpl_it_test.go b/general_tests/cacherpl_it_test.go
index d03d58a62..941c51490 100644
--- a/general_tests/cacherpl_it_test.go
+++ b/general_tests/cacherpl_it_test.go
@@ -29,8 +29,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
-
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/cdrs_exp_it_test.go b/general_tests/cdrs_exp_it_test.go
index 0cad2be3d..b435b274a 100644
--- a/general_tests/cdrs_exp_it_test.go
+++ b/general_tests/cdrs_exp_it_test.go
@@ -36,7 +36,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/cdrs_processevent_it_test.go b/general_tests/cdrs_processevent_it_test.go
index 382f8006a..9a28cfc38 100644
--- a/general_tests/cdrs_processevent_it_test.go
+++ b/general_tests/cdrs_processevent_it_test.go
@@ -30,7 +30,6 @@ import (
"testing"
"time"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/data_it_test.go b/general_tests/data_it_test.go
index 3d33a6548..99472b7be 100644
--- a/general_tests/data_it_test.go
+++ b/general_tests/data_it_test.go
@@ -25,7 +25,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
diff --git a/general_tests/dest_management_it_test.go b/general_tests/dest_management_it_test.go
index 674915d95..9ea27844d 100644
--- a/general_tests/dest_management_it_test.go
+++ b/general_tests/dest_management_it_test.go
@@ -28,7 +28,6 @@ import (
"testing"
"time"
- "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/destination_combined_it_test.go b/general_tests/destination_combined_it_test.go
index fd063b03a..e075092cf 100644
--- a/general_tests/destination_combined_it_test.go
+++ b/general_tests/destination_combined_it_test.go
@@ -25,7 +25,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/doubleremove_it_test.go b/general_tests/doubleremove_it_test.go
index 310c6e692..c083f8123 100644
--- a/general_tests/doubleremove_it_test.go
+++ b/general_tests/doubleremove_it_test.go
@@ -25,7 +25,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/filtered_replication_it_test.go b/general_tests/filtered_replication_it_test.go
index 78cb2a5ca..a08d0d7fc 100644
--- a/general_tests/filtered_replication_it_test.go
+++ b/general_tests/filtered_replication_it_test.go
@@ -27,8 +27,6 @@ import (
"time"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/filters_it_test.go b/general_tests/filters_it_test.go
index 45d0b8635..50ca0970e 100644
--- a/general_tests/filters_it_test.go
+++ b/general_tests/filters_it_test.go
@@ -27,7 +27,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/filters_test.go b/general_tests/filters_test.go
index abc1a45aa..f07fce40e 100644
--- a/general_tests/filters_test.go
+++ b/general_tests/filters_test.go
@@ -18,13 +18,13 @@ along with this program. If not, see
package general_tests
+/*
import (
"testing"
"time"
"github.com/cgrates/birpc"
"github.com/cgrates/birpc/context"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -121,3 +121,4 @@ func TestInlineFilterPassFiltersForEvent(t *testing.T) {
t.Errorf("Expecting: %+v, received: %+v", true, pass)
}
}
+*/
diff --git a/general_tests/gocs_it_test.go b/general_tests/gocs_it_test.go
index 7aa61f8f5..b70539544 100644
--- a/general_tests/gocs_it_test.go
+++ b/general_tests/gocs_it_test.go
@@ -28,8 +28,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
-
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/oldtutorial_it_test.go b/general_tests/oldtutorial_it_test.go
index 410f87ee4..197e8c9c8 100644
--- a/general_tests/oldtutorial_it_test.go
+++ b/general_tests/oldtutorial_it_test.go
@@ -29,8 +29,6 @@ package general_tests
// "testing"
// "time"
-// "github.com/cgrates/cgrates/apier/v1"
-// "github.com/cgrates/cgrates/apier/v2"
// "github.com/cgrates/cgrates/config"
// "github.com/cgrates/cgrates/engine"
// "github.com/cgrates/cgrates/utils"
diff --git a/general_tests/route_it_test.go b/general_tests/route_it_test.go
index c6b72ec17..6709e461a 100644
--- a/general_tests/route_it_test.go
+++ b/general_tests/route_it_test.go
@@ -27,7 +27,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/sentinel_it_test.go b/general_tests/sentinel_it_test.go
old mode 100755
new mode 100644
diff --git a/general_tests/sessions_concur_test.go b/general_tests/sessions_concur_test.go
index fa4a3ab08..8f05d8cac 100644
--- a/general_tests/sessions_concur_test.go
+++ b/general_tests/sessions_concur_test.go
@@ -28,8 +28,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
diff --git a/general_tests/tls_it_test.go b/general_tests/tls_it_test.go
old mode 100755
new mode 100644
diff --git a/general_tests/tp_it_test.go b/general_tests/tp_it_test.go
index 9f8d2a1b3..eb56c9765 100644
--- a/general_tests/tp_it_test.go
+++ b/general_tests/tp_it_test.go
@@ -26,8 +26,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/tutorial2_it_test.go b/general_tests/tutorial2_it_test.go
index c59006ce1..f0c4106a8 100644
--- a/general_tests/tutorial2_it_test.go
+++ b/general_tests/tutorial2_it_test.go
@@ -26,8 +26,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/general_tests/tutorial_calls_test.go b/general_tests/tutorial_calls_test.go
old mode 100755
new mode 100644
diff --git a/general_tests/tutorial_it_test.go b/general_tests/tutorial_it_test.go
index 622005e76..dd6e48ac1 100644
--- a/general_tests/tutorial_it_test.go
+++ b/general_tests/tutorial_it_test.go
@@ -27,7 +27,6 @@ import (
"testing"
"time"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
diff --git a/go.mod b/go.mod
index c650291b4..b36f26409 100644
--- a/go.mod
+++ b/go.mod
@@ -4,9 +4,7 @@ go 1.16
// replace github.com/cgrates/radigo => ../radigo
-replace github.com/cgrates/rpcclient => ../rpcclient
-replace github.com/cgrates/birpc => ../rpc
-replace github.com/cgrates/baningo => ../baningo
+// replace github.com/cgrates/rpcclient => ../rpcclient
require (
cloud.google.com/go v0.75.0 // indirect
@@ -18,14 +16,14 @@ require (
github.com/blevesearch/bleve v1.0.14
github.com/cenkalti/rpc2 v0.0.0-20210220005819-4a29bc83afe1
github.com/cgrates/aringo v0.0.0-20201113143849-3b299e4e636d
- github.com/cgrates/baningo v0.0.0-20201105145354-6e3173f6a91b
- github.com/cgrates/birpc v1.3.1-0.20210412111352-7281ab41f2fd
+ github.com/cgrates/baningo v0.0.0-20210413080722-004ffd5e429f
+ github.com/cgrates/birpc v1.3.1-0.20210413080448-f81834a37fd3
github.com/cgrates/cron v0.0.0-20201022095836-3522d5b72c70
github.com/cgrates/fsock v0.0.0-20191107070144-e7a331109df7
github.com/cgrates/kamevapi v0.0.0-20191001125829-7dbc3ad58817
github.com/cgrates/ltcache v0.0.0-20181016092649-92fb7fa77cca
github.com/cgrates/radigo v0.0.0-20201113143731-162035428d72
- github.com/cgrates/rpcclient v0.0.0-20210218104959-cc39fa26221e
+ github.com/cgrates/rpcclient v0.0.0-20210413084509-dc66fe9852ca
github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e
github.com/cgrates/ugocodec v0.0.0-20201023092048-df93d0123f60
github.com/creack/pty v1.1.11
diff --git a/go.sum b/go.sum
index 9d08043a1..2920cae23 100644
--- a/go.sum
+++ b/go.sum
@@ -83,10 +83,10 @@ github.com/cenkalti/rpc2 v0.0.0-20210220005819-4a29bc83afe1/go.mod h1:v2npkhrXyk
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cgrates/aringo v0.0.0-20201113143849-3b299e4e636d h1:1PLz/t3XZy5KF8EY/ShzBZoVLaY50+tnAbE1wu8rCfg=
github.com/cgrates/aringo v0.0.0-20201113143849-3b299e4e636d/go.mod h1:mMAzSIjK11XfRMrOIa7DXYl64REdPldRCbAgzKB47XQ=
-github.com/cgrates/baningo v0.0.0-20201105145354-6e3173f6a91b h1:9IX5Z3Tw7n2QrY7GLGGpqjjC/NVSJvQ7nxLkC2JP4vw=
-github.com/cgrates/baningo v0.0.0-20201105145354-6e3173f6a91b/go.mod h1:3SwVROaS1Iml5lqEhj0gRhDRtmbBgypZpKcEkVTSleU=
-github.com/cgrates/birpc v1.3.1-0.20210412111352-7281ab41f2fd h1:V8wb43eGTfj8GQ2CX89zwyIjloEE/aHFNC3t5IyJB4Y=
-github.com/cgrates/birpc v1.3.1-0.20210412111352-7281ab41f2fd/go.mod h1:z/PmNnDPqSQALedKJv5T8+eXIq6XHa9J0St1YsvAVns=
+github.com/cgrates/baningo v0.0.0-20210413080722-004ffd5e429f h1:dCp5BflGB8I8wlhWn4R5g0o4ok2pZRmcYHyzIks9Pbc=
+github.com/cgrates/baningo v0.0.0-20210413080722-004ffd5e429f/go.mod h1:3SwVROaS1Iml5lqEhj0gRhDRtmbBgypZpKcEkVTSleU=
+github.com/cgrates/birpc v1.3.1-0.20210413080448-f81834a37fd3 h1:AJrOcYMIQ/8X1i/kfqwOkQghxfJcPUloSRfK0n38JhI=
+github.com/cgrates/birpc v1.3.1-0.20210413080448-f81834a37fd3/go.mod h1:z/PmNnDPqSQALedKJv5T8+eXIq6XHa9J0St1YsvAVns=
github.com/cgrates/cron v0.0.0-20201022095836-3522d5b72c70 h1:/O+Dr12jcizDiCoIG2oK6wyE1pNRVQc62Wz+TfPWDhU=
github.com/cgrates/cron v0.0.0-20201022095836-3522d5b72c70/go.mod h1:I9cUDn/uzkakr0hmYTjXkQqf6wagg44L2p01gSYRRz0=
github.com/cgrates/fsock v0.0.0-20191107070144-e7a331109df7 h1:dxtBWRAr62vRRKkExmJZ0u1EbCw/y0vOkSfdFND5qXw=
@@ -97,6 +97,8 @@ github.com/cgrates/ltcache v0.0.0-20181016092649-92fb7fa77cca h1:Ejj4m0Ccl8dMMVn
github.com/cgrates/ltcache v0.0.0-20181016092649-92fb7fa77cca/go.mod h1:q7c996DUu8OrJRnewVSQzM+y/bRcxZAHoo+zCD8bFBo=
github.com/cgrates/radigo v0.0.0-20201113143731-162035428d72 h1:cTAWQEbab3gKkDSeaxkTaoiP/cNFx+7/kC96wYckk3g=
github.com/cgrates/radigo v0.0.0-20201113143731-162035428d72/go.mod h1:3IDSbfIqU5VsYKjrwa3HhuAK1jlI65wa1coHetoaN20=
+github.com/cgrates/rpcclient v0.0.0-20210413084509-dc66fe9852ca h1:ucFZvI96qqO9ukR2EF1lyNEl8t8I1GNaxs/zjIAAkZA=
+github.com/cgrates/rpcclient v0.0.0-20210413084509-dc66fe9852ca/go.mod h1:5LEYQt4uXkY4TeYsmAm/2gzAK08igOAblyUPTSh+k3Q=
github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e h1:izFjZB83/XRXInc+gMIssUxdbleGsGIuGCPj2u7RQo0=
github.com/cgrates/sipingo v1.0.1-0.20200514112313-699ebc1cdb8e/go.mod h1:0f2+3dq5Iiv3VlcuY83VPJ0QzqRlzDG1Cr8okogQE3g=
github.com/cgrates/ugocodec v0.0.0-20201023092048-df93d0123f60 h1:TQDg+HGB17LU8FitLiLvYazYSy62GQ1lO3lGKI3xUrU=
diff --git a/integration_test.sh b/integration_test.sh
index 260e7ef6b..0938ba3ed 100755
--- a/integration_test.sh
+++ b/integration_test.sh
@@ -8,12 +8,6 @@ if [ "$#" -ne 0 ]; then
# to run the integration tests for gob only add `-rpc=*gob` as argument to this script
# to run for a single dbtype add `-dbtype=*mysql` as argument
# ./integaration_tes.sh -dbtype=*mysql -rpc=*gob
-# echo "go test github.com/cgrates/cgrates/apier/v1 -tags=integration $@"
-# go test github.com/cgrates/cgrates/apier/v1 -tags=integration $@
-# results+=($?)
-# echo "go test github.com/cgrates/cgrates/apier/v2 -tags=integration $@"
-# go test github.com/cgrates/cgrates/apier/v2 -tags=integration $@
-# results+=($?)
echo "go test github.com/cgrates/cgrates/engine -tags=integration $@"
go test github.com/cgrates/cgrates/engine -tags=integration $@
results+=($?)
@@ -38,20 +32,11 @@ results+=($?)
echo "go test github.com/cgrates/cgrates/registrarc -tags=integration $@"
go test github.com/cgrates/cgrates/registrarc -tags=integration $@
results+=($?)
-echo "go test github.com/cgrates/cgrates/apier/v1 -tags=offline $@"
-go test github.com/cgrates/cgrates/apier/v1 -tags=offline $@
-results+=($?)
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration $@"
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration $@
results+=($?)
else
# Internal
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*internal'
-go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*internal
-results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*internal'
-go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*internal
-results+=($?)
echo 'go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*internal'
go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*internal
results+=($?)
@@ -76,19 +61,10 @@ results+=($?)
echo "go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*internal"
go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*internal
results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*internal'
-go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*internal
-results+=($?)
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*internal"
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*internal
results+=($?)
# SQL
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mysql'
-go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mysql
-results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*mysql'
-go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*mysql
-results+=($?)
echo 'go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*mysql'
go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*mysql
results+=($?)
@@ -113,19 +89,10 @@ results+=($?)
echo "go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*mysql"
go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*mysql
results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mysql'
-go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mysql
-results+=($?)
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*mysql"
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*mysql
results+=($?)
# Mongo
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo'
-go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*mongo
-results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*mongo'
-go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*mongo
-results+=($?)
echo 'go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*mongo'
go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*mongo
results+=($?)
@@ -150,19 +117,10 @@ results+=($?)
echo "go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*mongo"
go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*mongo
results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mongo'
-go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*mongo
-results+=($?)
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*mongo"
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*mongo
results+=($?)
# Postgres
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres'
-go test github.com/cgrates/cgrates/apier/v1 -tags=integration -dbtype=*postgres
-results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*postgres'
-go test github.com/cgrates/cgrates/apier/v2 -tags=integration -dbtype=*postgres
-results+=($?)
echo 'go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*postgres'
go test github.com/cgrates/cgrates/engine -tags=integration -dbtype=*postgres
results+=($?)
@@ -187,9 +145,6 @@ results+=($?)
echo "go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*postgres"
go test github.com/cgrates/cgrates/registrarc -tags=integration -dbtype=*postgres
results+=($?)
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*postgres'
-go test github.com/cgrates/cgrates/apier/v1 -tags=offline -dbtype=*postgres
-results+=($?)
echo "go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*postgres"
go test github.com/cgrates/cgrates/cmd/cgr-loader -tags=integration -dbtype=*postgres
results+=($?)
diff --git a/migrator/attributes_it_test.go b/migrator/attributes_it_test.go
old mode 100755
new mode 100644
diff --git a/migrator/cdrs.go b/migrator/cdrs.go
old mode 100755
new mode 100644
diff --git a/migrator/cdrs_it_test.go b/migrator/cdrs_it_test.go
old mode 100755
new mode 100644
diff --git a/migrator/chargers.go b/migrator/chargers.go
old mode 100755
new mode 100644
diff --git a/migrator/chargers_it_test.go b/migrator/chargers_it_test.go
old mode 100755
new mode 100644
diff --git a/migrator/migrator.go b/migrator/migrator.go
old mode 100755
new mode 100644
diff --git a/migrator/migrator_stordb.go b/migrator/migrator_stordb.go
old mode 100755
new mode 100644
diff --git a/migrator/stats_it_test.go b/migrator/stats_it_test.go
old mode 100755
new mode 100644
diff --git a/migrator/storage_map_datadb.go b/migrator/storage_map_datadb.go
old mode 100755
new mode 100644
diff --git a/migrator/storage_map_stordb.go b/migrator/storage_map_stordb.go
old mode 100755
new mode 100644
diff --git a/migrator/storage_sql.go b/migrator/storage_sql.go
old mode 100755
new mode 100644
diff --git a/migrator/tp_chargers.go b/migrator/tp_chargers.go
old mode 100755
new mode 100644
diff --git a/migrator/tp_filters_it_test.go b/migrator/tp_filters_it_test.go
old mode 100755
new mode 100644
diff --git a/offline_tp_test.sh b/offline_tp_test.sh
deleted file mode 100755
index 7b90c12bf..000000000
--- a/offline_tp_test.sh
+++ /dev/null
@@ -1,8 +0,0 @@
-./test.sh
-gen=$?
-echo 'go test github.com/cgrates/cgrates/apier/v1 -tags=offline_tp'
-go test github.com/cgrates/cgrates/apier/v1 -tags=offline_tp
-ap1=$?
-
-exit $gen && $ap1
-
diff --git a/services/accounts.go b/services/accounts.go
index c72b2db3a..c9c396b14 100644
--- a/services/accounts.go
+++ b/services/accounts.go
@@ -25,7 +25,6 @@ import (
"github.com/cgrates/birpc"
"github.com/cgrates/cgrates/accounts"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -66,8 +65,8 @@ type AccountService struct {
rldChan chan struct{}
stopChan chan struct{}
- acts *accounts.AccountS
- rpc *v1.AccountSv1 // useful on restart
+ acts *accounts.AccountS
+ // rpc *v1.AccountSv1 // useful on restart
connChan chan birpc.ClientConnector // publish the internal Subsystem when available
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -95,11 +94,11 @@ func (acts *AccountService) Start() (err error) {
go acts.acts.ListenAndServe(acts.stopChan, acts.rldChan)
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.AccountS))
- acts.rpc = v1.NewAccountSv1(acts.acts)
- if !acts.cfg.DispatcherSCfg().Enabled {
- acts.server.RpcRegister(acts.rpc)
- }
- acts.connChan <- acts.anz.GetInternalCodec(acts.rpc, utils.AccountS)
+ // acts.rpc = v1.NewAccountSv1(acts.acts)
+ // if !acts.cfg.DispatcherSCfg().Enabled {
+ // acts.server.RpcRegister(acts.rpc)
+ // }
+ // acts.connChan <- acts.anz.GetInternalCodec(acts.rpc, utils.AccountS)
return
}
@@ -115,7 +114,7 @@ func (acts *AccountService) Shutdown() (err error) {
close(acts.stopChan)
acts.acts.Shutdown()
acts.acts = nil
- acts.rpc = nil
+ // acts.rpc = nil
<-acts.connChan
acts.Unlock()
return
diff --git a/services/actions.go b/services/actions.go
index 4d19cc8f2..571762db2 100644
--- a/services/actions.go
+++ b/services/actions.go
@@ -25,7 +25,6 @@ import (
"github.com/cgrates/birpc"
"github.com/cgrates/cgrates/actions"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -66,8 +65,8 @@ type ActionService struct {
rldChan chan struct{}
stopChan chan struct{}
- acts *actions.ActionS
- rpc *v1.ActionSv1 // useful on restart
+ acts *actions.ActionS
+ // rpc *v1.ActionSv1 // useful on restart
connChan chan birpc.ClientConnector // publish the internal Subsystem when available
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -95,11 +94,11 @@ func (acts *ActionService) Start() (err error) {
go acts.acts.ListenAndServe(acts.stopChan, acts.rldChan)
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ActionS))
- acts.rpc = v1.NewActionSv1(acts.acts)
- if !acts.cfg.DispatcherSCfg().Enabled {
- acts.server.RpcRegister(acts.rpc)
- }
- acts.connChan <- acts.anz.GetInternalCodec(acts.rpc, utils.ActionS)
+ // acts.rpc = v1.NewActionSv1(acts.acts)
+ // if !acts.cfg.DispatcherSCfg().Enabled {
+ // acts.server.RpcRegister(acts.rpc)
+ // }
+ // acts.connChan <- acts.anz.GetInternalCodec(acts.rpc, utils.ActionS)
return
}
@@ -116,7 +115,7 @@ func (acts *ActionService) Shutdown() (err error) {
close(acts.stopChan)
acts.acts.Shutdown()
acts.acts = nil
- acts.rpc = nil
+ // acts.rpc = nil
<-acts.connChan
return
}
diff --git a/services/adminsv1.go b/services/adminsv1.go
new file mode 100644
index 000000000..85954fee5
--- /dev/null
+++ b/services/adminsv1.go
@@ -0,0 +1,140 @@
+/*
+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 services
+
+import (
+ "sync"
+
+ "github.com/cgrates/birpc"
+ "github.com/cgrates/cgrates/apis"
+ "github.com/cgrates/cgrates/config"
+ "github.com/cgrates/cgrates/cores"
+ "github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/servmanager"
+ "github.com/cgrates/cgrates/utils"
+)
+
+// NewAPIerSv1Service returns the APIerSv1 Service
+func NewAdminSv1Service(cfg *config.CGRConfig, dm *DataDBService,
+ storDB *StorDBService, filterSChan chan *engine.FilterS,
+ server *cores.Server,
+ internalAPIerSv1Chan chan birpc.ClientConnector,
+ connMgr *engine.ConnManager, anz *AnalyzerService,
+ srvDep map[string]*sync.WaitGroup) servmanager.Service {
+ return &AdminSv1Service{
+ connChan: internalAPIerSv1Chan,
+ cfg: cfg,
+ dm: dm,
+ storDB: storDB,
+ filterSChan: filterSChan,
+ server: server,
+ connMgr: connMgr,
+ anz: anz,
+ srvDep: srvDep,
+ }
+}
+
+// APIerSv1Service implements Service interface
+type AdminSv1Service struct {
+ sync.RWMutex
+ cfg *config.CGRConfig
+ dm *DataDBService
+ storDB *StorDBService
+ filterSChan chan *engine.FilterS
+ server *cores.Server
+ connMgr *engine.ConnManager
+
+ api *apis.AdminSv1
+ connChan chan birpc.ClientConnector
+
+ stopChan chan struct{}
+
+ anz *AnalyzerService
+ srvDep map[string]*sync.WaitGroup
+}
+
+// Start should handle the sercive start
+// For this service the start should be called from RAL Service
+func (apiService *AdminSv1Service) Start() (err error) {
+ if apiService.IsRunning() {
+ return utils.ErrServiceAlreadyRunning
+ }
+
+ // filterS := <-apiService.filterSChan
+ // apiService.filterSChan <- filterS
+ dbchan := apiService.dm.GetDMChan()
+ datadb := <-dbchan
+ dbchan <- datadb
+
+ // apiService.stopChan = make(chan struct{})
+ // storDBChan := make(chan engine.StorDB, 1)
+ // apiService.storDB.RegisterSyncChan(storDBChan)
+ // stordb := <-storDBChan
+
+ apiService.Lock()
+ defer apiService.Unlock()
+
+ apiService.api = apis.NewAdminSv1(apiService.cfg, datadb, apiService.connMgr)
+
+ // go apiService.api.ListenAndServe(apiService.stopChan)
+ // runtime.Gosched()
+ srv, _ := birpc.NewService(apiService.api, "", false)
+
+ if !apiService.cfg.DispatcherSCfg().Enabled {
+ apiService.server.RpcRegister(srv)
+ }
+
+ //backwards compatible
+ apiService.connChan <- apiService.anz.GetInternalCodec(srv, srv.Name)
+
+ return
+}
+
+// Reload handles the change of config
+func (apiService *AdminSv1Service) Reload() (err error) {
+ return
+}
+
+// Shutdown stops the service
+func (apiService *AdminSv1Service) Shutdown() (err error) {
+ apiService.Lock()
+ // close(apiService.stopChan)
+ apiService.api = nil
+ <-apiService.connChan
+ apiService.server.RpcUnregisterName(utils.AdminSv1)
+ apiService.Unlock()
+ return
+}
+
+// IsRunning returns if the service is running
+func (apiService *AdminSv1Service) IsRunning() bool {
+ apiService.RLock()
+ defer apiService.RUnlock()
+ return apiService.api != nil
+}
+
+// ServiceName returns the service name
+func (apiService *AdminSv1Service) ServiceName() string {
+ return utils.APIerSv1
+}
+
+// ShouldRun returns if the service should be running
+func (apiService *AdminSv1Service) ShouldRun() bool {
+ return apiService.cfg.AdminSCfg().Enabled
+}
diff --git a/services/analyzers.go b/services/analyzers.go
index c721df7fa..f6efa5da1 100644
--- a/services/analyzers.go
+++ b/services/analyzers.go
@@ -24,7 +24,6 @@ import (
"github.com/cgrates/birpc"
"github.com/cgrates/cgrates/analyzers"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -55,8 +54,8 @@ type AnalyzerService struct {
stopChan chan struct{}
shdChan *utils.SyncedChan
- anz *analyzers.AnalyzerService
- rpc *v1.AnalyzerSv1
+ anz *analyzers.AnalyzerService
+ // rpc *v1.AnalyzerSv1
connChan chan birpc.ClientConnector
srvDep map[string]*sync.WaitGroup
}
@@ -82,7 +81,7 @@ func (anz *AnalyzerService) Start() (err error) {
return
}(anz.anz)
anz.server.SetAnalyzer(anz.anz)
- anz.rpc = v1.NewAnalyzerSv1(anz.anz)
+ // anz.rpc = v1.NewAnalyzerSv1(anz.anz)
go anz.start()
return
}
@@ -101,10 +100,10 @@ func (anz *AnalyzerService) start() {
anz.filterSChan <- fS
anz.anz.SetFilterS(fS)
}
- if !anz.cfg.DispatcherSCfg().Enabled {
- anz.server.RpcRegister(anz.rpc)
- }
- anz.connChan <- anz.rpc
+ // if !anz.cfg.DispatcherSCfg().Enabled {
+ // anz.server.RpcRegister(anz.rpc)
+ // }
+ // anz.connChan <- anz.rpc
}
// Reload handles the change of config
@@ -119,7 +118,7 @@ func (anz *AnalyzerService) Shutdown() (err error) {
anz.server.SetAnalyzer(nil)
anz.anz.Shutdown()
anz.anz = nil
- anz.rpc = nil
+ // anz.rpc = nil
<-anz.connChan
anz.Unlock()
return
diff --git a/services/apiers_it_test.go b/services/apiers_it_test.go
deleted file mode 100644
index 603d5a036..000000000
--- a/services/apiers_it_test.go
+++ /dev/null
@@ -1,138 +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 services
-
-import (
- "path"
- "reflect"
- "sync"
- "testing"
- "time"
-
- "github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/cores"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/servmanager"
- "github.com/cgrates/cgrates/utils"
-)
-
-func TestApiersReload(t *testing.T) {
- cfg := config.NewDefaultCGRConfig()
-
- utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID)
- utils.Logger.SetLogLevel(7)
- filterSChan := make(chan *engine.FilterS, 1)
- filterSChan <- nil
- shdChan := utils.NewSyncedChan()
- shdWg := new(sync.WaitGroup)
- chS := engine.NewCacheS(cfg, nil, nil)
- close(chS.GetPrecacheChannel(utils.CacheThresholdProfiles))
- close(chS.GetPrecacheChannel(utils.CacheThresholds))
- close(chS.GetPrecacheChannel(utils.CacheThresholdFilterIndexes))
-
- cfg.ThresholdSCfg().Enabled = true
- server := cores.NewServer(nil)
- srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil)
- srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
- db := NewDataDBService(cfg, nil, srvDep)
- cfg.StorDbCfg().Type = utils.Internal
- stordb := NewStorDBService(cfg, srvDep)
- anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep)
- tS := NewThresholdService(cfg, db, chS, filterSChan, server, make(chan birpc.ClientConnector, 1), anz, srvDep)
- apiSv1 := NewAPIerSv1Service(cfg, db, stordb, filterSChan, server,
- make(chan birpc.ClientConnector, 1), nil, anz, srvDep)
-
- apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan birpc.ClientConnector, 1), anz, srvDep)
- srvMngr.AddServices(apiSv1, apiSv2, tS,
- NewLoaderService(cfg, db, filterSChan, server, make(chan birpc.ClientConnector, 1), nil, anz, srvDep), db, stordb)
- if err := srvMngr.StartServices(); err != nil {
- t.Error(err)
- }
- if apiSv1.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- if apiSv2.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- if db.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- if stordb.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- var reply string
- if err := cfg.V1ReloadConfig(&config.ReloadArgs{
- Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"),
- Section: config.ApierS,
- }, &reply); err != nil {
- t.Error(err)
- } else if reply != utils.OK {
- t.Errorf("Expecting OK ,received %s", reply)
- }
- time.Sleep(100 * time.Millisecond) //need to switch to gorutine
- if !apiSv1.IsRunning() {
- t.Errorf("Expected service to be running")
- }
- if !apiSv2.IsRunning() {
- t.Errorf("Expected service to be running")
- }
- if !db.IsRunning() {
- t.Errorf("Expected service to be running")
- }
- if !stordb.IsRunning() {
- t.Errorf("Expected service to be running")
- }
-
- err := apiSv1.Start()
- if err == nil || err != utils.ErrServiceAlreadyRunning {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err)
- }
- err2 := apiSv2.Start()
- if err2 == nil || err2 != utils.ErrServiceAlreadyRunning {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err2)
- }
- err = apiSv1.Reload()
- if err != nil {
- t.Errorf("\nExpecting ,\n Received <%+v>", err)
- }
- err2 = apiSv2.Reload()
- if err2 != nil {
- t.Errorf("\nExpecting ,\n Received <%+v>", err2)
- }
- expected := &v1.APIerSv1{}
- getAPIerSv1 := apiSv1.GetAPIerSv1()
- if reflect.DeepEqual(expected, getAPIerSv1) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", expected, utils.ToJSON(getAPIerSv1))
- }
- cfg.ApierCfg().Enabled = false
- cfg.GetReloadChan(config.ApierS) <- struct{}{}
- time.Sleep(100 * time.Millisecond)
- if apiSv1.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- if apiSv2.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- shdChan.CloseOnce()
- time.Sleep(10 * time.Millisecond)
-}
diff --git a/services/apiers_test.go b/services/apiers_test.go
deleted file mode 100644
index e92cffabb..000000000
--- a/services/apiers_test.go
+++ /dev/null
@@ -1,107 +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 services
-
-import (
- "reflect"
- "sync"
- "testing"
-
- "github.com/cgrates/birpc"
- v2 "github.com/cgrates/cgrates/apier/v2"
-
- v1 "github.com/cgrates/cgrates/apier/v1"
-
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/cores"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-//TestApiersCoverage for cover testing
-func TestApiersCoverage(t *testing.T) {
- cfg := config.NewDefaultCGRConfig()
- filterSChan := make(chan *engine.FilterS, 1)
- filterSChan <- nil
- shdChan := utils.NewSyncedChan()
- chS := engine.NewCacheS(cfg, nil, nil)
- cfg.ThresholdSCfg().Enabled = true
- server := cores.NewServer(nil)
- srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)}
- db := NewDataDBService(cfg, nil, srvDep)
- cfg.StorDbCfg().Type = utils.Internal
- stordb := NewStorDBService(cfg, srvDep)
- anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan birpc.ClientConnector, 1), srvDep)
- apiSv1 := NewAPIerSv1Service(cfg, db, stordb, filterSChan, server,
- make(chan birpc.ClientConnector, 1), nil, anz, srvDep)
- apiSv2 := NewAPIerSv2Service(apiSv1, cfg, server, make(chan birpc.ClientConnector, 1), anz, srvDep)
- if apiSv1.IsRunning() {
- t.Errorf("Expected service to be down")
- }
- if apiSv2.IsRunning() {
- t.Errorf("Expected service to be down")
- }
-
- apiSv1.api = &v1.APIerSv1{}
- apiSv2.api = &v2.APIerSv2{}
- if !apiSv1.IsRunning() {
- t.Errorf("Expected service to be running")
- }
- if !apiSv2.IsRunning() {
- t.Errorf("Expected service to be running")
- }
- serviceName := apiSv1.ServiceName()
- if serviceName != utils.APIerSv1 {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.APIerSv1, serviceName)
- }
- serviceName2 := apiSv2.ServiceName()
- if serviceName2 != utils.APIerSv2 {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.APIerSv2, serviceName2)
- }
- getApi1 := apiSv1.GetAPIerSv1()
- if !reflect.DeepEqual(getApi1, apiSv1.api) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", apiSv1.api, getApi1)
- }
- getApiChan1 := apiSv1.GetAPIerSv1Chan()
- if !reflect.DeepEqual(getApiChan1, apiSv1.APIerSv1Chan) {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", apiSv1.APIerSv1Chan, getApiChan1)
- }
- shouldRun := apiSv1.ShouldRun()
- if shouldRun != false {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun)
- }
- shouldRun2 := apiSv2.ShouldRun()
- if shouldRun2 != false {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", false, shouldRun2)
- }
- //populates apiSv1 and apiSv2 with something in order to call the close function
- apiSv1.stopChan = make(chan struct{}, 1)
- apiSv1.stopChan <- struct{}{}
- apiSv1.connChan = make(chan birpc.ClientConnector, 1)
- apiSv1.connChan <- chS
- shutdownApi1 := apiSv1.Shutdown()
- if shutdownApi1 != nil {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi1)
- }
- apiSv2.connChan = make(chan birpc.ClientConnector, 1)
- apiSv2.connChan <- chS
- shutdownApi2 := apiSv2.Shutdown()
- if shutdownApi2 != nil {
- t.Errorf("\nExpecting <%+v>,\n Received <%+v>", nil, shutdownApi2)
- }
-}
diff --git a/services/apierv1.go b/services/apierv1.go
deleted file mode 100644
index 9c162579a..000000000
--- a/services/apierv1.go
+++ /dev/null
@@ -1,165 +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 services
-
-import (
- "runtime"
- "sync"
-
- "github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/cores"
- "github.com/cgrates/cgrates/engine"
- "github.com/cgrates/cgrates/utils"
-)
-
-// NewAPIerSv1Service returns the APIerSv1 Service
-func NewAPIerSv1Service(cfg *config.CGRConfig, dm *DataDBService,
- storDB *StorDBService, filterSChan chan *engine.FilterS,
- server *cores.Server,
- internalAPIerSv1Chan chan birpc.ClientConnector,
- connMgr *engine.ConnManager, anz *AnalyzerService,
- srvDep map[string]*sync.WaitGroup) *APIerSv1Service {
- return &APIerSv1Service{
- connChan: internalAPIerSv1Chan,
- cfg: cfg,
- dm: dm,
- storDB: storDB,
- filterSChan: filterSChan,
- server: server,
- connMgr: connMgr,
- APIerSv1Chan: make(chan *v1.APIerSv1, 1),
- anz: anz,
- srvDep: srvDep,
- }
-}
-
-// APIerSv1Service implements Service interface
-type APIerSv1Service struct {
- sync.RWMutex
- cfg *config.CGRConfig
- dm *DataDBService
- storDB *StorDBService
- filterSChan chan *engine.FilterS
- server *cores.Server
- connMgr *engine.ConnManager
-
- api *v1.APIerSv1
- connChan chan birpc.ClientConnector
-
- stopChan chan struct{}
-
- APIerSv1Chan chan *v1.APIerSv1
- anz *AnalyzerService
- srvDep map[string]*sync.WaitGroup
-}
-
-// Start should handle the sercive start
-// For this service the start should be called from RAL Service
-func (apiService *APIerSv1Service) Start() (err error) {
- if apiService.IsRunning() {
- return utils.ErrServiceAlreadyRunning
- }
-
- filterS := <-apiService.filterSChan
- apiService.filterSChan <- filterS
- dbchan := apiService.dm.GetDMChan()
- datadb := <-dbchan
- dbchan <- datadb
-
- storDBChan := make(chan engine.StorDB, 1)
- apiService.stopChan = make(chan struct{})
- apiService.storDB.RegisterSyncChan(storDBChan)
- stordb := <-storDBChan
-
- apiService.Lock()
- defer apiService.Unlock()
-
- apiService.api = &v1.APIerSv1{
- DataManager: datadb,
- CdrDb: stordb,
- StorDb: stordb,
- Config: apiService.cfg,
- FilterS: filterS,
- ConnMgr: apiService.connMgr,
- StorDBChan: storDBChan,
- }
-
- go apiService.api.ListenAndServe(apiService.stopChan)
- runtime.Gosched()
-
- if !apiService.cfg.DispatcherSCfg().Enabled {
- apiService.server.RpcRegister(apiService.api)
- apiService.server.RpcRegisterName(utils.ApierV1, apiService.api)
- apiService.server.RpcRegister(v1.NewReplicatorSv1(datadb, apiService.api))
- }
-
- //backwards compatible
- apiService.connChan <- apiService.anz.GetInternalCodec(apiService.api, utils.APIerSv1)
-
- apiService.APIerSv1Chan <- apiService.api
- return
-}
-
-// Reload handles the change of config
-func (apiService *APIerSv1Service) Reload() (err error) {
- return
-}
-
-// Shutdown stops the service
-func (apiService *APIerSv1Service) Shutdown() (err error) {
- apiService.Lock()
- close(apiService.stopChan)
- apiService.api = nil
- <-apiService.connChan
- apiService.Unlock()
- return
-}
-
-// IsRunning returns if the service is running
-func (apiService *APIerSv1Service) IsRunning() bool {
- apiService.RLock()
- defer apiService.RUnlock()
- return apiService != nil && apiService.api != nil
-}
-
-// ServiceName returns the service name
-func (apiService *APIerSv1Service) ServiceName() string {
- return utils.APIerSv1
-}
-
-// GetAPIerSv1 returns the APIerSv1
-func (apiService *APIerSv1Service) GetAPIerSv1() *v1.APIerSv1 {
- apiService.RLock()
- defer apiService.RUnlock()
- return apiService.api
-}
-
-// ShouldRun returns if the service should be running
-func (apiService *APIerSv1Service) ShouldRun() bool {
- return apiService.cfg.ApierCfg().Enabled
-}
-
-// GetAPIerSv1Chan returns the DataManager chanel
-func (apiService *APIerSv1Service) GetAPIerSv1Chan() chan *v1.APIerSv1 {
- apiService.RLock()
- defer apiService.RUnlock()
- return apiService.APIerSv1Chan
-}
diff --git a/services/apierv2.go b/services/apierv2.go
deleted file mode 100644
index 559fdb0ae..000000000
--- a/services/apierv2.go
+++ /dev/null
@@ -1,114 +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 services
-
-import (
- "sync"
-
- "github.com/cgrates/birpc"
- v2 "github.com/cgrates/cgrates/apier/v2"
- "github.com/cgrates/cgrates/config"
- "github.com/cgrates/cgrates/cores"
- "github.com/cgrates/cgrates/utils"
-)
-
-// NewAPIerSv2Service returns the APIerSv2 Service
-func NewAPIerSv2Service(apiv1 *APIerSv1Service, cfg *config.CGRConfig,
- server *cores.Server, internalAPIerSv2Chan chan birpc.ClientConnector,
- anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) *APIerSv2Service {
- return &APIerSv2Service{
- apiv1: apiv1,
- connChan: internalAPIerSv2Chan,
- cfg: cfg,
- server: server,
- anz: anz,
- srvDep: srvDep,
- }
-}
-
-// APIerSv2Service implements Service interface
-type APIerSv2Service struct {
- sync.RWMutex
- cfg *config.CGRConfig
- server *cores.Server
-
- apiv1 *APIerSv1Service
- api *v2.APIerSv2
- connChan chan birpc.ClientConnector
- anz *AnalyzerService
- srvDep map[string]*sync.WaitGroup
-}
-
-// Start should handle the sercive start
-// For this service the start should be called from RAL Service
-func (api *APIerSv2Service) Start() (err error) {
- if api.IsRunning() {
- return utils.ErrServiceAlreadyRunning
- }
-
- apiV1Chan := api.apiv1.GetAPIerSv1Chan()
- apiV1 := <-apiV1Chan
- apiV1Chan <- apiV1
-
- api.Lock()
- defer api.Unlock()
-
- api.api = &v2.APIerSv2{
- APIerSv1: *apiV1,
- }
-
- if !api.cfg.DispatcherSCfg().Enabled {
- api.server.RpcRegister(api.api)
- api.server.RpcRegisterName(utils.ApierV2, api.api)
- }
-
- api.connChan <- api.anz.GetInternalCodec(api.api, utils.APIerSv2)
- return
-}
-
-// Reload handles the change of config
-func (api *APIerSv2Service) Reload() (err error) {
- return
-}
-
-// Shutdown stops the service
-func (api *APIerSv2Service) Shutdown() (err error) {
- api.Lock()
- api.api = nil
- <-api.connChan
- api.Unlock()
- return
-}
-
-// IsRunning returns if the service is running
-func (api *APIerSv2Service) IsRunning() bool {
- api.RLock()
- defer api.RUnlock()
- return api != nil && api.api != nil
-}
-
-// ServiceName returns the service name
-func (api *APIerSv2Service) ServiceName() string {
- return utils.APIerSv2
-}
-
-// ShouldRun returns if the service should be running
-func (api *APIerSv2Service) ShouldRun() bool {
- return api.cfg.ApierCfg().Enabled
-}
diff --git a/services/attributes.go b/services/attributes.go
index 2533665e1..efae1e962 100644
--- a/services/attributes.go
+++ b/services/attributes.go
@@ -23,7 +23,7 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
+ "github.com/cgrates/cgrates/apis"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -59,7 +59,7 @@ type AttributeService struct {
server *cores.Server
attrS *engine.AttributeService
- rpc *v1.AttributeSv1 // useful on restart
+ rpc *apis.AttributeSv1 // useful on restart
connChan chan birpc.ClientConnector // publish the internal Subsystem when available
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -84,11 +84,12 @@ func (attrS *AttributeService) Start() (err error) {
defer attrS.Unlock()
attrS.attrS = engine.NewAttributeService(datadb, filterS, attrS.cfg)
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.AttributeS))
- attrS.rpc = v1.NewAttributeSv1(attrS.attrS)
+ attrS.rpc = apis.NewAttributeSv1(attrS.attrS)
+ srv, _ := birpc.NewService(attrS.rpc, "", false)
if !attrS.cfg.DispatcherSCfg().Enabled {
- attrS.server.RpcRegister(attrS.rpc)
+ attrS.server.RpcRegister(srv)
}
- attrS.connChan <- attrS.anz.GetInternalCodec(attrS.rpc, utils.AttributeS)
+ attrS.connChan <- attrS.anz.GetInternalCodec(srv, utils.AttributeS)
return
}
@@ -100,11 +101,12 @@ func (attrS *AttributeService) Reload() (err error) {
// Shutdown stops the service
func (attrS *AttributeService) Shutdown() (err error) {
attrS.Lock()
- defer attrS.Unlock()
attrS.attrS.Shutdown()
attrS.attrS = nil
attrS.rpc = nil
<-attrS.connChan
+ attrS.server.RpcUnregisterName(utils.AttributeSv1)
+ attrS.Unlock()
return
}
@@ -112,7 +114,7 @@ func (attrS *AttributeService) Shutdown() (err error) {
func (attrS *AttributeService) IsRunning() bool {
attrS.RLock()
defer attrS.RUnlock()
- return attrS != nil && attrS.attrS != nil
+ return attrS.attrS != nil
}
// ServiceName returns the service name
diff --git a/services/cdrs.go b/services/cdrs.go
index 6049ea521..f74cfe42e 100644
--- a/services/cdrs.go
+++ b/services/cdrs.go
@@ -24,8 +24,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -61,9 +59,9 @@ type CDRServer struct {
filterSChan chan *engine.FilterS
server *cores.Server
- cdrS *engine.CDRServer
- rpcv1 *v1.CDRsV1
- rpcv2 *v2.CDRsV2
+ cdrS *engine.CDRServer
+ // rpcv1 *v1.CDRsV1
+ // rpcv2 *v2.CDRsV2
connChan chan birpc.ClientConnector
connMgr *engine.ConnManager
@@ -99,11 +97,11 @@ func (cdrService *CDRServer) Start() (err error) {
utils.Logger.Info("Registering CDRS HTTP Handlers.")
cdrService.cdrS.RegisterHandlersToServer(cdrService.server)
utils.Logger.Info("Registering CDRS RPC service.")
- cdrService.rpcv1 = v1.NewCDRsV1(cdrService.cdrS)
- cdrService.rpcv2 = &v2.CDRsV2{CDRsV1: *cdrService.rpcv1}
+ // cdrService.rpcv1 = v1.NewCDRsV1(cdrService.cdrS)
+ // cdrService.rpcv2 = &v2.CDRsV2{CDRsV1: *cdrService.rpcv1}
if !cdrService.cfg.DispatcherSCfg().Enabled {
- cdrService.server.RpcRegister(cdrService.rpcv1)
- cdrService.server.RpcRegister(cdrService.rpcv2)
+ // cdrService.server.RpcRegister(cdrService.rpcv1)
+ // cdrService.server.RpcRegister(cdrService.rpcv2)
// Make the cdr server available for internal communication
cdrService.server.RpcRegister(cdrService.cdrS) // register CdrServer for internal usage (TODO: refactor this)
}
@@ -121,8 +119,8 @@ func (cdrService *CDRServer) Shutdown() (err error) {
cdrService.Lock()
close(cdrService.stopChan)
cdrService.cdrS = nil
- cdrService.rpcv1 = nil
- cdrService.rpcv2 = nil
+ // cdrService.rpcv1 = nil
+ // cdrService.rpcv2 = nil
<-cdrService.connChan
cdrService.Unlock()
return
diff --git a/services/chargers.go b/services/chargers.go
index 89dab6847..c3a6980ae 100644
--- a/services/chargers.go
+++ b/services/chargers.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -59,8 +58,8 @@ type ChargerService struct {
server *cores.Server
connMgr *engine.ConnManager
- chrS *engine.ChargerService
- rpc *v1.ChargerSv1
+ chrS *engine.ChargerService
+ // rpc *v1.ChargerSv1
connChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -85,11 +84,11 @@ func (chrS *ChargerService) Start() (err error) {
defer chrS.Unlock()
chrS.chrS = engine.NewChargerService(datadb, filterS, chrS.cfg, chrS.connMgr)
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ChargerS))
- cSv1 := v1.NewChargerSv1(chrS.chrS)
- if !chrS.cfg.DispatcherSCfg().Enabled {
- chrS.server.RpcRegister(cSv1)
- }
- chrS.connChan <- chrS.anz.GetInternalCodec(cSv1, utils.ChargerS)
+ // cSv1 := v1.NewChargerSv1(chrS.chrS)
+ // if !chrS.cfg.DispatcherSCfg().Enabled {
+ // chrS.server.RpcRegister(cSv1)
+ // }
+ // chrS.connChan <- chrS.anz.GetInternalCodec(cSv1, utils.ChargerS)
return
}
@@ -104,7 +103,7 @@ func (chrS *ChargerService) Shutdown() (err error) {
defer chrS.Unlock()
chrS.chrS.Shutdown()
chrS.chrS = nil
- chrS.rpc = nil
+ // chrS.rpc = nil
<-chrS.connChan
return
}
diff --git a/services/cores.go b/services/cores.go
index 7a00f364a..848f6572a 100644
--- a/services/cores.go
+++ b/services/cores.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -52,8 +51,8 @@ type CoreService struct {
caps *engine.Caps
stopChan chan struct{}
- cS *cores.CoreService
- rpc *v1.CoreSv1
+ cS *cores.CoreService
+ // rpc *v1.CoreSv1
connChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -70,11 +69,11 @@ func (cS *CoreService) Start() (err error) {
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.CoreS))
cS.stopChan = make(chan struct{})
cS.cS = cores.NewCoreService(cS.cfg, cS.caps, cS.stopChan)
- cS.rpc = v1.NewCoreSv1(cS.cS)
- if !cS.cfg.DispatcherSCfg().Enabled {
- cS.server.RpcRegister(cS.rpc)
- }
- cS.connChan <- cS.anz.GetInternalCodec(cS.rpc, utils.CoreS)
+ // cS.rpc = v1.NewCoreSv1(cS.cS)
+ // if !cS.cfg.DispatcherSCfg().Enabled {
+ // cS.server.RpcRegister(cS.rpc)
+ // }
+ // cS.connChan <- cS.anz.GetInternalCodec(cS.rpc, utils.CoreS)
return
}
@@ -90,7 +89,7 @@ func (cS *CoreService) Shutdown() (err error) {
cS.cS.Shutdown()
close(cS.stopChan)
cS.cS = nil
- cS.rpc = nil
+ // cS.rpc = nil
<-cS.connChan
return
}
diff --git a/services/datadb.go b/services/datadb.go
index ca834ec55..0d24be05a 100644
--- a/services/datadb.go
+++ b/services/datadb.go
@@ -140,7 +140,7 @@ func (db *DataDBService) mandatoryDB() bool {
return db.cfg.ChargerSCfg().Enabled ||
db.cfg.AttributeSCfg().Enabled || db.cfg.ResourceSCfg().Enabled || db.cfg.StatSCfg().Enabled ||
db.cfg.ThresholdSCfg().Enabled || db.cfg.RouteSCfg().Enabled || db.cfg.DispatcherSCfg().Enabled ||
- db.cfg.LoaderCfg().Enabled() || db.cfg.ApierCfg().Enabled || db.cfg.RateSCfg().Enabled ||
+ db.cfg.LoaderCfg().Enabled() || db.cfg.AdminSCfg().Enabled || db.cfg.RateSCfg().Enabled ||
db.cfg.AccountSCfg().Enabled || db.cfg.ActionSCfg().Enabled || db.cfg.AnalyzerSCfg().Enabled
}
diff --git a/services/datadb_it_test.go b/services/datadb_it_test.go
index bb84735b4..6f3d35c60 100644
--- a/services/datadb_it_test.go
+++ b/services/datadb_it_test.go
@@ -163,9 +163,6 @@ func TestDataDBReload(t *testing.T) {
utils.MetaActionProfiles: {
Replicate: false,
Remote: false},
- utils.MetaAccounts: {
- Replicate: false,
- Remote: false},
},
}
if !reflect.DeepEqual(oldcfg, db.oldDBCfg) {
diff --git a/services/dispatchers.go b/services/dispatchers.go
index 3e217b4a3..b496eb435 100644
--- a/services/dispatchers.go
+++ b/services/dispatchers.go
@@ -22,8 +22,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
- v2 "github.com/cgrates/cgrates/apier/v2"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/dispatchers"
@@ -61,8 +59,8 @@ type DispatcherService struct {
server *cores.Server
connMgr *engine.ConnManager
- dspS *dispatchers.DispatcherService
- rpc *v1.DispatcherSv1
+ dspS *dispatchers.DispatcherService
+ // rpc *v1.DispatcherSv1
connChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -91,60 +89,60 @@ func (dspS *DispatcherService) Start() (err error) {
// for the moment we dispable Apier through dispatcher
// until we figured out a better sollution in case of gob server
// dspS.server.SetDispatched()
+ /*
+ dspS.server.RpcRegister(v1.NewDispatcherSv1(dspS.dspS))
- dspS.server.RpcRegister(v1.NewDispatcherSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.ThresholdSv1,
+ v1.NewDispatcherThresholdSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.ThresholdSv1,
- v1.NewDispatcherThresholdSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.StatSv1,
+ v1.NewDispatcherStatSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.StatSv1,
- v1.NewDispatcherStatSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.ResourceSv1,
+ v1.NewDispatcherResourceSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.ResourceSv1,
- v1.NewDispatcherResourceSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.RouteSv1,
+ v1.NewDispatcherRouteSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.RouteSv1,
- v1.NewDispatcherRouteSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.AttributeSv1,
+ v1.NewDispatcherAttributeSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.AttributeSv1,
- v1.NewDispatcherAttributeSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.SessionSv1,
+ v1.NewDispatcherSessionSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.SessionSv1,
- v1.NewDispatcherSessionSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.ChargerSv1,
+ v1.NewDispatcherChargerSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.ChargerSv1,
- v1.NewDispatcherChargerSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.CacheSv1,
+ v1.NewDispatcherCacheSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.CacheSv1,
- v1.NewDispatcherCacheSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.GuardianSv1,
+ v1.NewDispatcherGuardianSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.GuardianSv1,
- v1.NewDispatcherGuardianSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.CDRsV1,
+ v1.NewDispatcherSCDRsV1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.CDRsV1,
- v1.NewDispatcherSCDRsV1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.ConfigSv1,
+ v1.NewDispatcherConfigSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.ConfigSv1,
- v1.NewDispatcherConfigSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.CoreSv1,
+ v1.NewDispatcherCoreSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.CoreSv1,
- v1.NewDispatcherCoreSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.ReplicatorSv1,
+ v1.NewDispatcherReplicatorSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.ReplicatorSv1,
- v1.NewDispatcherReplicatorSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.CDRsV2,
+ v2.NewDispatcherSCDRsV2(dspS.dspS))
- dspS.server.RpcRegisterName(utils.CDRsV2,
- v2.NewDispatcherSCDRsV2(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.RateSv1,
+ v1.NewDispatcherRateSv1(dspS.dspS))
- dspS.server.RpcRegisterName(utils.RateSv1,
- v1.NewDispatcherRateSv1(dspS.dspS))
-
- dspS.server.RpcRegisterName(utils.ActionSv1,
- v1.NewDispatcherActionSv1(dspS.dspS))
-
- dspS.server.RpcRegisterName(utils.AccountSv1,
- v1.NewDispatcherAccountSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.ActionSv1,
+ v1.NewDispatcherActionSv1(dspS.dspS))
+ dspS.server.RpcRegisterName(utils.AccountSv1,
+ v1.NewDispatcherAccountSv1(dspS.dspS))
+ */
dspS.connChan <- dspS.anz.GetInternalCodec(dspS.dspS, utils.DispatcherS)
return
@@ -161,7 +159,7 @@ func (dspS *DispatcherService) Shutdown() (err error) {
defer dspS.Unlock()
dspS.dspS.Shutdown()
dspS.dspS = nil
- dspS.rpc = nil
+ // dspS.rpc = nil
<-dspS.connChan
return
}
diff --git a/services/ees.go b/services/ees.go
index deec74e30..2d73e4087 100644
--- a/services/ees.go
+++ b/services/ees.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/ees"
@@ -61,8 +60,8 @@ type EventExporterService struct {
rldChan chan struct{}
stopChan chan struct{}
- eeS *ees.EventExporterS
- rpc *v1.EeSv1
+ eeS *ees.EventExporterS
+ // rpc *v1.EeSv1
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
}
@@ -119,10 +118,10 @@ func (es *EventExporterService) Start() (err error) {
es.stopChan = make(chan struct{})
go es.eeS.ListenAndServe(es.stopChan, es.rldChan)
- es.rpc = v1.NewEeSv1(es.eeS)
- if !es.cfg.DispatcherSCfg().Enabled {
- es.server.RpcRegister(es.rpc)
- }
+ // es.rpc = v1.NewEeSv1(es.eeS)
+ // if !es.cfg.DispatcherSCfg().Enabled {
+ // es.server.RpcRegister(es.rpc)
+ // }
es.intConnChan <- es.anz.GetInternalCodec(es.eeS, utils.EventExporterS)
return
}
diff --git a/services/loaders.go b/services/loaders.go
index b9ef7788e..d5ad22a27 100644
--- a/services/loaders.go
+++ b/services/loaders.go
@@ -22,7 +22,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -58,8 +57,8 @@ type LoaderService struct {
server *cores.Server
stopChan chan struct{}
- ldrs *loaders.LoaderService
- rpc *v1.LoaderSv1
+ ldrs *loaders.LoaderService
+ // rpc *v1.LoaderSv1
connChan chan birpc.ClientConnector
connMgr *engine.ConnManager
anz *AnalyzerService
@@ -90,11 +89,11 @@ func (ldrs *LoaderService) Start() (err error) {
if err = ldrs.ldrs.ListenAndServe(ldrs.stopChan); err != nil {
return
}
- ldrs.rpc = v1.NewLoaderSv1(ldrs.ldrs)
- if !ldrs.cfg.DispatcherSCfg().Enabled {
- ldrs.server.RpcRegister(ldrs.rpc)
- }
- ldrs.connChan <- ldrs.anz.GetInternalCodec(ldrs.rpc, utils.LoaderS)
+ // ldrs.rpc = v1.NewLoaderSv1(ldrs.ldrs)
+ // if !ldrs.cfg.DispatcherSCfg().Enabled {
+ // ldrs.server.RpcRegister(ldrs.rpc)
+ // }
+ // ldrs.connChan <- ldrs.anz.GetInternalCodec(ldrs.rpc, utils.LoaderS)
return
}
@@ -123,7 +122,7 @@ func (ldrs *LoaderService) Reload() (err error) {
func (ldrs *LoaderService) Shutdown() (err error) {
ldrs.Lock()
ldrs.ldrs = nil
- ldrs.rpc = nil
+ // ldrs.rpc = nil
close(ldrs.stopChan)
<-ldrs.connChan
ldrs.Unlock()
diff --git a/services/rates.go b/services/rates.go
index 57f2894c4..0352d4fd6 100644
--- a/services/rates.go
+++ b/services/rates.go
@@ -22,7 +22,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/config"
@@ -30,7 +29,6 @@ import (
"github.com/cgrates/cgrates/rates"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
- //"github.com/cgrates/cgrates/apier/v1"
)
// NewRateService constructs RateService
@@ -65,8 +63,8 @@ type RateService struct {
rldChan chan struct{}
stopChan chan struct{}
- rateS *rates.RateS
- rpc *v1.RateSv1
+ rateS *rates.RateS
+ // rpc *v1.RateSv1
intConnChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -129,11 +127,11 @@ func (rs *RateService) Start() (err error) {
rs.stopChan = make(chan struct{})
go rs.rateS.ListenAndServe(rs.stopChan, rs.rldChan)
- rs.rpc = v1.NewRateSv1(rs.rateS)
- if !rs.cfg.DispatcherSCfg().Enabled {
- rs.server.RpcRegister(rs.rpc)
- }
+ // rs.rpc = v1.NewRateSv1(rs.rateS)
+ // if !rs.cfg.DispatcherSCfg().Enabled {
+ // rs.server.RpcRegister(rs.rpc)
+ // }
- rs.intConnChan <- rs.anz.GetInternalCodec(rs.rpc, utils.RateS)
+ // rs.intConnChan <- rs.anz.GetInternalCodec(rs.rpc, utils.RateS)
return
}
diff --git a/services/resources.go b/services/resources.go
index 1202046c7..918b01ecb 100644
--- a/services/resources.go
+++ b/services/resources.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -59,8 +58,8 @@ type ResourceService struct {
filterSChan chan *engine.FilterS
server *cores.Server
- reS *engine.ResourceService
- rpc *v1.ResourceSv1
+ reS *engine.ResourceService
+ // rpc *v1.ResourceSv1
connChan chan birpc.ClientConnector
connMgr *engine.ConnManager
anz *AnalyzerService
@@ -88,11 +87,11 @@ func (reS *ResourceService) Start() (err error) {
reS.reS = engine.NewResourceService(datadb, reS.cfg, filterS, reS.connMgr)
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ResourceS))
reS.reS.StartLoop()
- reS.rpc = v1.NewResourceSv1(reS.reS)
- if !reS.cfg.DispatcherSCfg().Enabled {
- reS.server.RpcRegister(reS.rpc)
- }
- reS.connChan <- reS.anz.GetInternalCodec(reS.rpc, utils.ResourceS)
+ // reS.rpc = v1.NewResourceSv1(reS.reS)
+ // if !reS.cfg.DispatcherSCfg().Enabled {
+ // reS.server.RpcRegister(reS.rpc)
+ // }
+ // reS.connChan <- reS.anz.GetInternalCodec(reS.rpc, utils.ResourceS)
return
}
@@ -111,7 +110,7 @@ func (reS *ResourceService) Shutdown() (err error) {
defer reS.Unlock()
reS.reS.Shutdown() //we don't verify the error because shutdown never returns an error
reS.reS = nil
- reS.rpc = nil
+ // reS.rpc = nil
<-reS.connChan
return
}
diff --git a/services/routes.go b/services/routes.go
index 939ade5bb..c11e2f677 100644
--- a/services/routes.go
+++ b/services/routes.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -60,8 +59,8 @@ type RouteService struct {
server *cores.Server
connMgr *engine.ConnManager
- routeS *engine.RouteService
- rpc *v1.RouteSv1
+ routeS *engine.RouteService
+ // rpc *v1.RouteSv1
connChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -87,11 +86,11 @@ func (routeS *RouteService) Start() (err error) {
routeS.routeS = engine.NewRouteService(datadb, filterS, routeS.cfg, routeS.connMgr)
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.RouteS))
- routeS.rpc = v1.NewRouteSv1(routeS.routeS)
- if !routeS.cfg.DispatcherSCfg().Enabled {
- routeS.server.RpcRegister(routeS.rpc)
- }
- routeS.connChan <- routeS.anz.GetInternalCodec(routeS.rpc, utils.RouteS)
+ // routeS.rpc = v1.NewRouteSv1(routeS.routeS)
+ // if !routeS.cfg.DispatcherSCfg().Enabled {
+ // routeS.server.RpcRegister(routeS.rpc)
+ // }
+ // routeS.connChan <- routeS.anz.GetInternalCodec(routeS.rpc, utils.RouteS)
return
}
@@ -106,7 +105,7 @@ func (routeS *RouteService) Shutdown() (err error) {
defer routeS.Unlock()
routeS.routeS.Shutdown() //we don't verify the error because shutdown never returns an error
routeS.routeS = nil
- routeS.rpc = nil
+ // routeS.rpc = nil
<-routeS.connChan
return
}
diff --git a/services/routes_test.go b/services/routes_test.go
index 881cde51a..9903ba54d 100644
--- a/services/routes_test.go
+++ b/services/routes_test.go
@@ -54,10 +54,10 @@ func TestSupplierSCoverage(t *testing.T) {
server: server,
connMgr: nil,
routeS: &engine.RouteService{},
- rpc: nil,
- connChan: make(chan birpc.ClientConnector, 1),
- anz: anz,
- srvDep: srvDep,
+ // rpc: nil,
+ connChan: make(chan birpc.ClientConnector, 1),
+ anz: anz,
+ srvDep: srvDep,
}
if !supS2.IsRunning() {
t.Errorf("Expected service to be running")
diff --git a/services/sessions.go b/services/sessions.go
index 3dc8d1e03..f29d648ee 100644
--- a/services/sessions.go
+++ b/services/sessions.go
@@ -26,7 +26,6 @@ import (
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/sessions"
@@ -61,9 +60,9 @@ type SessionService struct {
shdChan *utils.SyncedChan
stopChan chan struct{}
- sm *sessions.SessionS
- rpc *v1.SMGenericV1
- rpcv1 *v1.SessionSv1
+ sm *sessions.SessionS
+ // rpc *v1.SMGenericV1
+ // rpcv1 *v1.SessionSv1
connChan chan birpc.ClientConnector
// in order to stop the bircp server if necesary
@@ -96,20 +95,20 @@ func (smg *SessionService) Start() (err error) {
// Pass internal connection via BiRPCClient
smg.connChan <- smg.anz.GetInternalCodec(smg.sm, utils.SessionS)
// Register RPC handler
- smg.rpc = v1.NewSMGenericV1(smg.sm, smg.caps)
+ // smg.rpc = v1.NewSMGenericV1(smg.sm, smg.caps)
- smg.rpcv1 = v1.NewSessionSv1(smg.sm, smg.caps) // methods with multiple options
- if !smg.cfg.DispatcherSCfg().Enabled {
- smg.server.RpcRegister(smg.rpc)
- smg.server.RpcRegister(smg.rpcv1)
- }
+ // smg.rpcv1 = v1.NewSessionSv1(smg.sm, smg.caps) // methods with multiple options
+ // if !smg.cfg.DispatcherSCfg().Enabled {
+ // smg.server.RpcRegister(smg.rpc)
+ // smg.server.RpcRegister(smg.rpcv1)
+ // }
// Register BiRpc handlers
if smg.cfg.SessionSCfg().ListenBijson != "" {
smg.bircpEnabled = true
- smg.server.BiRPCRegisterName("SMGenericV1", smg.rpc)
- smg.server.BiRPCRegisterName(utils.SessionSv1, smg.rpcv1)
+ // smg.server.BiRPCRegisterName("SMGenericV1", smg.rpc)
+ // smg.server.BiRPCRegisterName(utils.SessionSv1, smg.rpcv1)
// run this in it's own goroutine
- go smg.start()
+ // go smg.start()
}
return
}
@@ -144,8 +143,8 @@ func (smg *SessionService) Shutdown() (err error) {
smg.bircpEnabled = false
}
smg.sm = nil
- smg.rpc = nil
- smg.rpcv1 = nil
+ // smg.rpc = nil
+ // smg.rpcv1 = nil
<-smg.connChan
return
}
diff --git a/services/sessions_it_test.go b/services/sessions_it_test.go
index 762b68411..d8dd60d66 100644
--- a/services/sessions_it_test.go
+++ b/services/sessions_it_test.go
@@ -28,6 +28,7 @@ import (
"time"
"github.com/cgrates/birpc"
+ "github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -41,11 +42,11 @@ func init() {
}
type testMockClients struct {
- calls func(args interface{}, reply interface{}) error
+ calls func(_ *context.Context, _, _ interface{}) error
}
-func (sT *testMockClients) Call(method string, arg interface{}, rply interface{}) error {
- return sT.calls(arg, rply)
+func (sT *testMockClients) Call(ctx *context.Context, method string, arg, rply interface{}) error {
+ return sT.calls(ctx, arg, rply)
}
func TestSessionSReload1(t *testing.T) {
@@ -81,7 +82,7 @@ func TestSessionSReload1(t *testing.T) {
clientConect := make(chan birpc.ClientConnector, 1)
clientConect <- &testMockClients{
- calls: func(args interface{}, reply interface{}) error {
+ calls: func(ctx *context.Context, args, reply interface{}) error {
rply, cancast := reply.(*[]*engine.ChrgSProcessEventReply)
if !cancast {
return fmt.Errorf("can't cast")
diff --git a/services/stats.go b/services/stats.go
index b181c2a90..b2ea696ff 100644
--- a/services/stats.go
+++ b/services/stats.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -60,8 +59,8 @@ type StatService struct {
server *cores.Server
connMgr *engine.ConnManager
- sts *engine.StatService
- rpc *v1.StatSv1
+ sts *engine.StatService
+ // rpc *v1.StatSv1
connChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -91,11 +90,11 @@ func (sts *StatService) Start() (err error) {
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem",
utils.CoreS, utils.StatS))
sts.sts.StartLoop()
- sts.rpc = v1.NewStatSv1(sts.sts)
- if !sts.cfg.DispatcherSCfg().Enabled {
- sts.server.RpcRegister(sts.rpc)
- }
- sts.connChan <- sts.anz.GetInternalCodec(sts.rpc, utils.StatS)
+ // sts.rpc = v1.NewStatSv1(sts.sts)
+ // if !sts.cfg.DispatcherSCfg().Enabled {
+ // sts.server.RpcRegister(sts.rpc)
+ // }
+ // sts.connChan <- sts.anz.GetInternalCodec(sts.rpc, utils.StatS)
return
}
@@ -114,7 +113,7 @@ func (sts *StatService) Shutdown() (err error) {
defer sts.Unlock()
sts.sts.Shutdown()
sts.sts = nil
- sts.rpc = nil
+ // sts.rpc = nil
<-sts.connChan
return
}
diff --git a/services/stordb.go b/services/stordb.go
index fc236bbf2..5f639227c 100644
--- a/services/stordb.go
+++ b/services/stordb.go
@@ -170,7 +170,7 @@ func (db *StorDBService) ServiceName() string {
// ShouldRun returns if the service should be running
func (db *StorDBService) ShouldRun() bool {
- return db.cfg.CdrsCfg().Enabled || db.cfg.ApierCfg().Enabled
+ return db.cfg.CdrsCfg().Enabled || db.cfg.AdminSCfg().Enabled
}
// RegisterSyncChan used by dependent subsystems to register a chanel to reload only the storDB(thread safe)
diff --git a/services/thresholds.go b/services/thresholds.go
index ff20cf2f7..1a6f7a889 100644
--- a/services/thresholds.go
+++ b/services/thresholds.go
@@ -23,7 +23,6 @@ import (
"sync"
"github.com/cgrates/birpc"
- v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/cores"
"github.com/cgrates/cgrates/engine"
@@ -57,8 +56,8 @@ type ThresholdService struct {
filterSChan chan *engine.FilterS
server *cores.Server
- thrs *engine.ThresholdService
- rpc *v1.ThresholdSv1
+ thrs *engine.ThresholdService
+ // rpc *v1.ThresholdSv1
connChan chan birpc.ClientConnector
anz *AnalyzerService
srvDep map[string]*sync.WaitGroup
@@ -87,11 +86,11 @@ func (thrs *ThresholdService) Start() (err error) {
utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.ThresholdS))
thrs.thrs.StartLoop()
- thrs.rpc = v1.NewThresholdSv1(thrs.thrs)
- if !thrs.cfg.DispatcherSCfg().Enabled {
- thrs.server.RpcRegister(thrs.rpc)
- }
- thrs.connChan <- thrs.anz.GetInternalCodec(thrs.rpc, utils.ThresholdS)
+ // thrs.rpc = v1.NewThresholdSv1(thrs.thrs)
+ // if !thrs.cfg.DispatcherSCfg().Enabled {
+ // thrs.server.RpcRegister(thrs.rpc)
+ // }
+ // thrs.connChan <- thrs.anz.GetInternalCodec(thrs.rpc, utils.ThresholdS)
return
}
@@ -110,7 +109,7 @@ func (thrs *ThresholdService) Shutdown() (err error) {
defer thrs.Unlock()
thrs.thrs.Shutdown()
thrs.thrs = nil
- thrs.rpc = nil
+ // thrs.rpc = nil
<-thrs.connChan
return
}
diff --git a/servmanager/servmanager.go b/servmanager/servmanager.go
index a438a56fc..bd53e72ef 100644
--- a/servmanager/servmanager.go
+++ b/servmanager/servmanager.go
@@ -136,7 +136,7 @@ func (srvMngr *ServiceManager) handleReload() {
go srvMngr.reloadService(utils.ResourceS)
case <-srvMngr.GetConfig().GetReloadChan(config.RouteSJson):
go srvMngr.reloadService(utils.RouteS)
- case <-srvMngr.GetConfig().GetReloadChan(config.ApierS):
+ case <-srvMngr.GetConfig().GetReloadChan(config.AdminS):
go func() {
srvMngr.reloadService(utils.APIerSv1)
srvMngr.reloadService(utils.APIerSv2)
diff --git a/utils/apitpdata.go b/utils/apitpdata.go
old mode 100755
new mode 100644
diff --git a/utils/consts.go b/utils/consts.go
old mode 100755
new mode 100644
index c3e9701da..4387c85b7
--- a/utils/consts.go
+++ b/utils/consts.go
@@ -940,7 +940,6 @@ const (
AnalyzerS = "AnalyzerS"
CDRServer = "CDRServer"
GuardianS = "GuardianS"
- ApierS = "ApierS"
)
// Lower service names
@@ -957,7 +956,6 @@ const (
SchedulerSLow = "schedulers"
LoaderSLow = "loaders"
ReplicatorLow = "replicator"
- ApierSLow = "apiers"
EEsLow = "ees"
RateSLow = "rates"
AccountSLow = "accounts"
@@ -1168,8 +1166,6 @@ const (
// APIerSv1 APIs
const (
- ApierV1 = "ApierV1"
- ApierV2 = "ApierV2"
APIerSv1 = "APIerSv1"
APIerSv1ComputeFilterIndexes = "APIerSv1.ComputeFilterIndexes"
APIerSv1ComputeFilterIndexIDs = "APIerSv1.ComputeFilterIndexIDs"
@@ -1579,6 +1575,12 @@ const (
APIerSv1RemoveActionProfile = "APIerSv1.RemoveActionProfile"
)
+// AdminSv1
+const (
+ AdminS = "AdminS"
+ AdminSv1 = "AdminSv1"
+)
+
//cgr_ variables
const (
CGRAccount = "cgr_account"
diff --git a/utils/syncedchan.go b/utils/syncedchan.go
index 1207eded3..a2dc03871 100644
--- a/utils/syncedchan.go
+++ b/utils/syncedchan.go
@@ -18,7 +18,9 @@ along with this program. If not, see
package utils
-import "sync"
+import (
+ "sync"
+)
func NewSyncedChan() *SyncedChan {
return &SyncedChan{