added api definitions in the apis package

This commit is contained in:
gezimbll
2025-06-17 09:12:02 +02:00
committed by Dan Christian Bogos
parent 4edf0e7f83
commit 3c11cddb0d
13 changed files with 440 additions and 460 deletions

View File

@@ -23,7 +23,6 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/apis"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -99,71 +98,6 @@ func TestAccountsActionRemoveBalance(t *testing.T) {
}
}
func TestAccountsGetAccount(t *testing.T) {
cfg := config.NewDefaultCGRConfig()
cfg.GeneralCfg().DefaultCaching = utils.MetaNone
connMgr := engine.NewConnManager(cfg)
dataDB, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(dataDB, cfg, connMgr)
acc := NewAccountS(cfg, &engine.FilterS{}, connMgr, dm)
fltrs := engine.NewFilterS(cfg, connMgr, dm)
cfg.GeneralCfg().DefaultCaching = utils.MetaNone
admS := apis.NewAdminSv1(cfg, dm, nil, fltrs, nil)
acc_args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
Balances: map[string]*utils.Balance{
"VoiceBalance": {
ID: "VoiceBalance",
Weights: utils.DynamicWeights{
{
Weight: 12,
},
},
Type: "*abstract",
Opts: map[string]any{
"Destination": 10,
},
CostIncrements: []*utils.CostIncrement{
{
RecurrentFee: utils.NewDecimal(1, 0),
Increment: utils.NewDecimal(1, 1),
},
},
Units: utils.NewDecimal(0, 0),
},
},
Weights: utils.DynamicWeights{
{
Weight: 10,
},
},
},
APIOpts: nil,
}
var setRply string
err := admS.SetAccount(context.Background(), acc_args, &setRply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
var reply utils.Account
args := &utils.TenantIDWithAPIOpts{
TenantID: utils.NewTenantID("cgrates.org:test_ID1"),
}
if err := acc.V1GetAccount(context.Background(), args, &reply); err != nil {
t.Error(err)
}
if !reflect.DeepEqual(&reply, acc_args.Account) {
t.Errorf("Expected %v\n but received %v", reply, acc_args.Account)
}
}
func TestAccountsDebitConcretes(t *testing.T) {
engine.Cache.Clear(nil)
cfg := config.NewDefaultCGRConfig()
@@ -172,9 +106,8 @@ func TestAccountsDebitConcretes(t *testing.T) {
dm := engine.NewDataManager(data, cfg, nil)
fltr := engine.NewFilterS(cfg, nil, dm)
accnts := NewAccountS(cfg, fltr, nil, dm)
admS := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
if err := dm.SetAccount(context.Background(),
&utils.Account{
Tenant: "cgrates.org",
ID: "TestV1DebitAbstracts",
@@ -232,11 +165,7 @@ func TestAccountsDebitConcretes(t *testing.T) {
},
},
},
},
APIOpts: nil,
}
var setRpl string
if err := admS.SetAccount(context.Background(), args, &setRpl); err != nil {
}, true); err != nil {
t.Error(err)
}
@@ -263,9 +192,8 @@ func TestAccountsMaxConcretes(t *testing.T) {
dm := engine.NewDataManager(data, cfg, nil)
fltr := engine.NewFilterS(cfg, nil, dm)
accnts := NewAccountS(cfg, fltr, nil, dm)
admS := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
if err := dm.SetAccount(context.Background(),
&utils.Account{
Tenant: "cgrates.org",
ID: "TestV1DebitAbstracts",
FilterIDs: []string{"*string:~*req.Account:1004"},
@@ -322,11 +250,7 @@ func TestAccountsMaxConcretes(t *testing.T) {
},
},
},
},
APIOpts: nil,
}
var setRpl string
if err := admS.SetAccount(context.Background(), args, &setRpl); err != nil {
}, true); err != nil {
t.Error(err)
}
@@ -514,11 +438,10 @@ func TestAccountsActionSetBalance(t *testing.T) {
connMgr := engine.NewConnManager(cfg)
dataDB, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(dataDB, cfg, connMgr)
admS := apis.NewAdminSv1(cfg, dm, connMgr, nil, nil)
newCache := engine.NewCacheS(cfg, dm, connMgr, nil)
engine.Cache = newCache
args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
if err := dm.SetAccount(context.Background(),
&utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
@@ -548,67 +471,9 @@ func TestAccountsActionSetBalance(t *testing.T) {
Weight: 10,
},
},
},
APIOpts: nil,
}, true); err != nil {
t.Errorf("expected <%+v>,\nreceived <%+v>", nil, err)
}
var setRply string
err := admS.SetAccount(context.Background(), args, &setRply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
if !reflect.DeepEqual(setRply, `OK`) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", `OK`, utils.ToJSON(setRply))
}
var getRply utils.Account
err = admS.GetAccount(context.Background(),
&utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "",
ID: "test_ID1",
},
APIOpts: nil,
}, &getRply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
expectedGet := utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
Balances: map[string]*utils.Balance{
"VoiceBalance": {
ID: "VoiceBalance",
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 12,
},
},
Type: "*abstract",
Opts: map[string]any{
"Destination": 10,
},
CostIncrements: []*utils.CostIncrement{
{
RecurrentFee: utils.NewDecimal(1, 1),
Increment: utils.NewDecimal(1, 1),
},
},
Units: utils.NewDecimal(0, 0),
},
},
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 10,
},
},
}
if !reflect.DeepEqual(getRply, expectedGet) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expectedGet), utils.ToJSON(getRply))
}
accS := NewAccountS(cfg, &engine.FilterS{}, connMgr, dm)
var rpEv utils.EventCharges
@@ -620,8 +485,7 @@ func TestAccountsActionSetBalance(t *testing.T) {
},
APIOpts: map[string]any{},
}
err = accS.V1DebitAbstracts(context.Background(), ev, &rpEv)
if err != nil {
if err := accS.V1DebitAbstracts(context.Background(), ev, &rpEv); err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
@@ -700,11 +564,11 @@ func TestAccountsDebitAbstracts(t *testing.T) {
connMgr := engine.NewConnManager(cfg)
dataDB, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(dataDB, cfg, connMgr)
admS := apis.NewAdminSv1(cfg, dm, connMgr, nil, nil)
newCache := engine.NewCacheS(cfg, dm, connMgr, nil)
accS := NewAccountS(cfg, &engine.FilterS{}, connMgr, dm)
engine.Cache = newCache
args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
err := dm.SetAccount(context.Background(),
&utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
@@ -734,68 +598,10 @@ func TestAccountsDebitAbstracts(t *testing.T) {
Weight: 10,
},
},
},
APIOpts: nil,
}
var setRply string
err := admS.SetAccount(context.Background(), args, &setRply)
}, true)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
t.Fatal(err)
}
if !reflect.DeepEqual(setRply, `OK`) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", `OK`, utils.ToJSON(setRply))
}
var getRply utils.Account
err = admS.GetAccount(context.Background(),
&utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "",
ID: "test_ID1",
},
APIOpts: nil,
}, &getRply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
expectedGet := utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
Balances: map[string]*utils.Balance{
"VoiceBalance": {
ID: "VoiceBalance",
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 12,
},
},
Type: "*abstract",
Opts: map[string]any{
"Destination": 10,
},
Units: utils.NewDecimal(0, 0),
CostIncrements: []*utils.CostIncrement{
{
RecurrentFee: utils.NewDecimal(1, 0),
Increment: utils.NewDecimal(1, 1),
},
},
},
},
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 10,
},
},
}
if !reflect.DeepEqual(getRply, expectedGet) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expectedGet), utils.ToJSON(getRply))
}
accS := NewAccountS(cfg, &engine.FilterS{}, connMgr, dm)
var rpEv utils.EventCharges
ev := &utils.CGREvent{
@@ -886,11 +692,10 @@ func TestAccountsMaxAbstracts(t *testing.T) {
connMgr := engine.NewConnManager(cfg)
dataDB, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(dataDB, cfg, connMgr)
admS := apis.NewAdminSv1(cfg, dm, connMgr, nil, nil)
newCache := engine.NewCacheS(cfg, dm, connMgr, nil)
engine.Cache = newCache
args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
err := dm.SetAccount(context.Background(),
&utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
@@ -920,65 +725,10 @@ func TestAccountsMaxAbstracts(t *testing.T) {
Weight: 10,
},
},
},
APIOpts: nil,
}
var setRply string
err := admS.SetAccount(context.Background(), args, &setRply)
}, true)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
} else if setRply != utils.OK {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", `OK`, utils.ToJSON(setRply))
t.Fatal(err)
}
var getRply utils.Account
err = admS.GetAccount(context.Background(),
&utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
ID: "test_ID1",
},
APIOpts: map[string]any{},
}, &getRply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
expectedGet := utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
Balances: map[string]*utils.Balance{
"VoiceBalance": {
ID: "VoiceBalance",
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 12,
},
},
Type: "*abstract",
Opts: map[string]any{
"Destination": 10,
},
Units: utils.NewDecimal(0, 0),
CostIncrements: []*utils.CostIncrement{
{
RecurrentFee: utils.NewDecimal(1, 1),
Increment: utils.NewDecimal(1, 1),
},
},
},
},
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 10,
},
},
}
if !reflect.DeepEqual(getRply, expectedGet) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expectedGet), utils.ToJSON(getRply))
}
cfg.AccountSCfg().RateSConns = []string{"*internal"}
accS := NewAccountS(cfg, &engine.FilterS{}, connMgr, dm)
@@ -1072,11 +822,10 @@ func TestAccountsAccountsForEvent(t *testing.T) {
connMgr := engine.NewConnManager(cfg)
dataDB, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(dataDB, cfg, connMgr)
admS := apis.NewAdminSv1(cfg, dm, connMgr, nil, nil)
newCache := engine.NewCacheS(cfg, dm, connMgr, nil)
engine.Cache = newCache
args := &utils.AccountWithAPIOpts{
Account: &utils.Account{
err := dm.SetAccount(context.Background(),
&utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
@@ -1100,61 +849,10 @@ func TestAccountsAccountsForEvent(t *testing.T) {
Weight: 10,
},
},
},
APIOpts: nil,
}
var setRply string
err := admS.SetAccount(context.Background(), args, &setRply)
}, true)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
t.Fatal(err)
}
if !reflect.DeepEqual(setRply, `OK`) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", `OK`, utils.ToJSON(setRply))
}
var getRply utils.Account
err = admS.GetAccount(context.Background(),
&utils.TenantIDWithAPIOpts{
TenantID: &utils.TenantID{
Tenant: "",
ID: "test_ID1",
},
APIOpts: nil,
}, &getRply)
if err != nil {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", nil, err)
}
expectedGet := utils.Account{
Tenant: "cgrates.org",
ID: "test_ID1",
Opts: map[string]any{},
Balances: map[string]*utils.Balance{
"VoiceBalance": {
ID: "VoiceBalance",
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 12,
},
},
Type: "*abstract",
Opts: map[string]any{
"Destination": 10,
},
Units: utils.NewDecimal(0, 0),
},
},
Weights: utils.DynamicWeights{
{
FilterIDs: nil,
Weight: 10,
},
},
}
if !reflect.DeepEqual(getRply, expectedGet) {
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", utils.ToJSON(expectedGet), utils.ToJSON(getRply))
}
accS := NewAccountS(cfg, &engine.FilterS{}, connMgr, dm)
rpEv := make([]*utils.Account, 0)

View File

@@ -27,7 +27,6 @@ import (
"github.com/cgrates/birpc"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/apis"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
@@ -49,10 +48,9 @@ func TestActionsAPIs(t *testing.T) {
data, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(data, cfg, nil)
fltrs := engine.NewFilterS(cfg, nil, dm)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, nil)
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
if err := dm.SetActionProfile(context.Background(),
&utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
FilterIDs: []string{"*string:~*req.Account:1001"},
@@ -61,11 +59,7 @@ func TestActionsAPIs(t *testing.T) {
ID: "actID",
},
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf, &reply); err != nil {
}, true); err != nil {
t.Error(err)
}
@@ -80,6 +74,7 @@ func TestActionsAPIs(t *testing.T) {
},
}
var reply string
if err := aS.V1ScheduleActions(context.Background(), ev, &reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
@@ -129,35 +124,27 @@ func TestActionsExecuteActionsResetTH(t *testing.T) {
rpcInternal <- cc
cM := engine.NewConnManager(cfg)
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaThresholds), utils.ThresholdSv1, rpcInternal)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, cM)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaResetThreshold,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaResetThreshold,
},
Targets: map[string]utils.StringSet{
utils.MetaThresholds: {
"THD_ID": struct{}{},
},
},
Targets: map[string]utils.StringSet{
utils.MetaThresholds: {
"THD_ID": struct{}{},
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf, true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with ResetThreshold
@@ -172,6 +159,7 @@ func TestActionsExecuteActionsResetTH(t *testing.T) {
},
}
var reply string
if err := aS.V1ExecuteActions(context.Background(), ev,
&reply); err != nil {
t.Error(err)
@@ -221,35 +209,27 @@ func TestActionsExecuteActionsResetSQ(t *testing.T) {
rpcInternal <- cc
cM := engine.NewConnManager(cfg)
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaStats), utils.StatSv1, rpcInternal)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, cM)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaResetStatQueue,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaResetStatQueue,
},
Targets: map[string]utils.StringSet{
utils.MetaStats: {
"SQ_ID": struct{}{},
},
},
Targets: map[string]utils.StringSet{
utils.MetaStats: {
"SQ_ID": struct{}{},
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf, true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with ResetStatQueue
@@ -264,6 +244,7 @@ func TestActionsExecuteActionsResetSQ(t *testing.T) {
},
}
var reply string
if err := aS.V1ExecuteActions(context.Background(), ev,
&reply); err != nil {
t.Error(err)
@@ -311,35 +292,29 @@ func TestActionsExecuteActionsSetBalance(t *testing.T) {
rpcInternal <- cc
cM := engine.NewConnManager(cfg)
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAccounts), utils.AccountSv1, rpcInternal)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, cM)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaSetBalance,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaSetBalance,
},
Targets: map[string]utils.StringSet{
utils.MetaAccounts: {
"ACC_ID": struct{}{},
},
},
Targets: map[string]utils.StringSet{
utils.MetaAccounts: {
"ACC_ID": struct{}{},
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf, true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with SetBalance
@@ -400,35 +375,29 @@ func TestActionsExecuteActionsAddBalance(t *testing.T) {
rpcInternal <- cc
cM := engine.NewConnManager(cfg)
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAccounts), utils.AccountSv1, rpcInternal)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, cM)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaAddBalance,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaAddBalance,
},
Targets: map[string]utils.StringSet{
utils.MetaAccounts: {
"ACC_ID": struct{}{},
},
},
Targets: map[string]utils.StringSet{
utils.MetaAccounts: {
"ACC_ID": struct{}{},
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf,
true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with AddBalance
@@ -442,7 +411,7 @@ func TestActionsExecuteActionsAddBalance(t *testing.T) {
utils.OptsActionsProfileIDs: []string{"actPrfID"},
},
}
var reply string
if err := aS.V1ExecuteActions(context.Background(), ev,
&reply); err != nil {
t.Error(err)
@@ -472,32 +441,26 @@ func TestActionsExecuteActionsLog(t *testing.T) {
dataDB, _ := engine.NewInternalDB(nil, nil, nil, cfg.DataDbCfg().Items)
dm := engine.NewDataManager(dataDB, cfg, nil)
fltrs := engine.NewFilterS(cfg, nil, dm)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, nil)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaLog,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaLog,
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf,
true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with Log
ev := &utils.CGREvent{
Tenant: "cgrates.org",
@@ -557,30 +520,25 @@ func TestActionsExecuteActionsLogCDRs(t *testing.T) {
rpcInternal <- cc
cM := engine.NewConnManager(cfg)
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.CDRs), utils.CDRsV1, rpcInternal)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, cM)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.CDRLog,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.CDRLog,
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf,
true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with CDRLog
@@ -645,35 +603,30 @@ func TestActionsExecuteActionsRemBalance(t *testing.T) {
rpcInternal <- cc
cM := engine.NewConnManager(cfg)
cM.AddInternalConn(utils.ConcatenatedKey(utils.MetaInternal, utils.MetaAccounts), utils.AccountSv1, rpcInternal)
adms := apis.NewAdminSv1(cfg, dm, nil, nil, nil)
aS := NewActionS(cfg, fltrs, dm, cM)
// Set ActionProfile
actPrf := &utils.ActionProfileWithAPIOpts{
ActionProfile: &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaRemBalance,
},
actPrf := &utils.ActionProfile{
Tenant: "cgrates.org",
ID: "actPrfID",
Actions: []*utils.APAction{
{
ID: "actID",
Type: utils.MetaRemBalance,
},
Targets: map[string]utils.StringSet{
utils.MetaAccounts: {
"ACC_ID": struct{}{},
},
},
Targets: map[string]utils.StringSet{
utils.MetaAccounts: {
"ACC_ID": struct{}{},
},
},
}
var reply string
if err := adms.SetActionProfile(context.Background(), actPrf,
&reply); err != nil {
if err := dm.SetActionProfile(context.Background(), actPrf,
true); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Error("Unexpected reply returned:", reply)
}
// ExecuteActions with RemBalance

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/accounts"
"github.com/cgrates/cgrates/utils"
)
@@ -172,3 +173,53 @@ func (admS *AdminSv1) RemoveAccount(ctx *context.Context, arg *utils.TenantIDWit
*reply = utils.OK
return nil
}
// NewAccountSv1 initializes the AccountSv1 object.
func NewAccountSv1(accs *accounts.AccountS) *AccountSv1 {
return &AccountSv1{accs: accs}
}
// AccountSv1 represents the RPC object to register for accounts v1 APIs.
type AccountSv1 struct {
accs *accounts.AccountS
}
// AccountsForEvent returns the matching Accounts for Event
func (aS *AccountSv1) AccountsForEvent(ctx *context.Context, args *utils.CGREvent, aps *[]*utils.Account) error {
return aS.accs.V1AccountsForEvent(ctx, args, aps)
}
// MaxAbstracts returns the maximum abstract units for the event, based on matching Accounts
func (aS *AccountSv1) MaxAbstracts(ctx *context.Context, args *utils.CGREvent, eEc *utils.EventCharges) error {
return aS.accs.V1MaxAbstracts(ctx, args, eEc)
}
// DebitAbstracts performs debit for the provided event
func (aS *AccountSv1) DebitAbstracts(ctx *context.Context, args *utils.CGREvent, eEc *utils.EventCharges) (err error) {
return aS.accs.V1DebitAbstracts(ctx, args, eEc)
}
// MaxConcretes returns the maximum concrete units for the event, based on matching Accounts
func (aS *AccountSv1) MaxConcretes(ctx *context.Context, args *utils.CGREvent, eEc *utils.EventCharges) (err error) {
return aS.accs.V1MaxConcretes(ctx, args, eEc)
}
// DebitConcretes performs debit of concrete units for the provided event
func (aS *AccountSv1) DebitConcretes(ctx *context.Context, args *utils.CGREvent, eEc *utils.EventCharges) (err error) {
return aS.accs.V1DebitConcretes(ctx, args, eEc)
}
// RefundCharges will refund charges recorded inside EventCharges
func (aS *AccountSv1) RefundCharges(ctx *context.Context, args *utils.APIEventCharges, rply *string) (err error) {
return aS.accs.V1RefundCharges(ctx, args, rply)
}
// ActionSetBalance performs an update for a specific balance in account
func (aS *AccountSv1) ActionSetBalance(ctx *context.Context, args *utils.ArgsActSetBalance, rply *string) (err error) {
return aS.accs.V1ActionSetBalance(ctx, args, rply)
}
// RemoveBalance removes a balance for a specific account
func (aS *AccountSv1) ActionRemoveBalance(ctx *context.Context, args *utils.ArgsActRemoveBalances, rply *string) (err error) {
return aS.accs.V1ActionRemoveBalance(ctx, args, rply)
}

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/actions"
"github.com/cgrates/cgrates/utils"
)
@@ -173,3 +174,23 @@ func (admS *AdminSv1) RemoveActionProfile(ctx *context.Context, arg *utils.Tenan
*reply = utils.OK
return nil
}
// NewActionSv1 initializes the ActionSv1 object.
func NewActionSv1(acts *actions.ActionS) *ActionSv1 {
return &ActionSv1{acts: acts}
}
// ActionSv1 represents the RPC object to register for actions v1 APIs.
type ActionSv1 struct {
acts *actions.ActionS
}
// ScheduleActions will be called to schedule actions matching the arguments
func (aS *ActionSv1) ScheduleActions(ctx *context.Context, args *utils.CGREvent, rpl *string) (err error) {
return aS.acts.V1ScheduleActions(ctx, args, rpl)
}
// ExecuteActions will be called to execute ASAP action profiles, ignoring their Schedule field
func (aS *ActionSv1) ExecuteActions(ctx *context.Context, args *utils.CGREvent, rpl *string) (err error) {
return aS.acts.V1ExecuteActions(ctx, args, rpl)
}

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/attributes"
"github.com/cgrates/cgrates/utils"
)
@@ -176,3 +177,23 @@ func (admS *AdminSv1) RemoveAttributeProfile(ctx *context.Context, arg *utils.Te
*reply = utils.OK
return nil
}
// NewAttributeSv1 initializes the AttributeSv1 object.
func NewAttributeSv1(atrs *attributes.AttributeS) *AttributeSv1 {
return &AttributeSv1{atrs: atrs}
}
// AttributeSv1 represents the RPC object to register for attributes v1 APIs.
type AttributeSv1 struct {
atrs *attributes.AttributeS
}
// V1GetAttributeForEvent returns the AttributeProfile that matches the event
func (atrS *AttributeSv1) V1GetAttributeForEvent(ctx *context.Context, args *utils.CGREvent, attrPrf *utils.APIAttributeProfile) (err error) {
return atrS.V1GetAttributeForEvent(ctx, args, attrPrf)
}
// V1ProcessEvent proccess the event and returns the result
func (atrS *AttributeSv1) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, attrEvntRpl *attributes.AttrSProcessEventReply) (err error) {
return atrS.V1ProcessEvent(ctx, args, attrEvntRpl)
}

View File

@@ -23,6 +23,7 @@ import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/cdrs"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/utils"
)
@@ -59,3 +60,28 @@ func (admS AdminSv1) RemoveCDRs(ctx *context.Context, args *utils.CDRFilters, re
*reply = utils.OK
return
}
// NewCdrSv1 initializes the CdrSv1 object.
func NewCdrSv1(cdrs *cdrs.CDRServer) *CdrSv1 {
return &CdrSv1{cdrs: cdrs}
}
// CdrSv1 represents the RPC object to register for cdrs v1 APIs.
type CdrSv1 struct {
cdrs *cdrs.CDRServer
}
// V1ProcessEvent will process the CGREvent
func (cdrS *CdrSv1) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return cdrS.cdrs.V1ProcessEvent(ctx, args, reply)
}
// V1ProcessEventWithGet has the same logic with V1ProcessEvent except it adds the proccessed events to the reply
func (cdrS *CdrSv1) V1ProcessEventWithGet(ctx *context.Context, args *utils.CGREvent, evs *[]*utils.EventsWithOpts) (err error) {
return cdrS.cdrs.V1ProcessEventWithGet(ctx, args, evs)
}
// V1ProcessStoredEvents processes stored events based on provided filters.
func (cdrS *CdrSv1) V1ProcessStoredEvents(ctx *context.Context, args *utils.CDRFilters, reply *string) (err error) {
return cdrS.cdrs.V1ProcessStoredEvents(ctx, args, reply)
}

View File

@@ -24,6 +24,7 @@ import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/chargers"
"github.com/cgrates/cgrates/utils"
)
@@ -172,3 +173,23 @@ func (adms *AdminSv1) RemoveChargerProfile(ctx *context.Context, arg *utils.Tena
*reply = utils.OK
return nil
}
// NewChargerSv1 initializes the ChargerSv1 object.
func NewChargerSv1(chgs *chargers.ChargerS) *ChargerSv1 {
return &ChargerSv1{chgs: chgs}
}
// ChargerSv1 represents the RPC object to register for chargers v1 APIs.
type ChargerSv1 struct {
chgs *chargers.ChargerS
}
// V1ProcessEvent will process the event received via API and return list of events forked
func (chgS *ChargerSv1) V1ProcessEvent(ctx *context.Context, args *utils.CGREvent, reply *[]*chargers.ChrgSProcessEventReply) (err error) {
return chgS.chgs.V1ProcessEvent(ctx, args, reply)
}
// V1GetChargersForEvent exposes the list of ordered matching ChargingProfiles for an event
func (chgS *ChargerSv1) V1GetChargersForEvent(ctx *context.Context, args *utils.CGREvent, rply *[]*utils.ChargerProfile) (err error) {
return chgS.chgs.V1GetChargersForEvent(ctx, args, rply)
}

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/ips"
"github.com/cgrates/cgrates/utils"
)
@@ -175,3 +176,38 @@ func (s *AdminSv1) RemoveIPProfile(ctx *context.Context, arg *utils.TenantIDWith
*reply = utils.OK
return nil
}
// NewIPSv1 initializes the IPSv1 object.
func NewIPSv1(ipS *ips.IPService) *IPSv1 {
return &IPSv1{ips: ipS}
}
// IPSv1 represents the RPC object to register for ips v1 APIs.
type IPSv1 struct {
ips *ips.IPService
}
// V1GetIPAllocationsForEvent returns active IPs matching the event.
func (ipS *IPSv1) V1GetIPAllocationsForEvent(ctx *context.Context, args *utils.CGREvent, reply *ips.IPAllocationsList) (err error) {
return ipS.V1GetIPAllocationsForEvent(ctx, args, reply)
}
// V1AuthorizeIP queries service to find if an Usage is allowed
func (ipS *IPSv1) V1AuthorizeIP(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return ipS.ips.V1AuthorizeIP(ctx, args, reply)
}
// V1AllocateIP is called when an IP requires allocation.
func (ipS *IPSv1) V1AllocateIP(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return ipS.ips.V1AllocateIP(ctx, args, reply)
}
// V1ReleaseIP is called when we need to clear an allocation
func (ipS *IPSv1) V1ReleaseIP(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return ipS.ips.V1ReleaseIP(ctx, args, reply)
}
// V1GetIPAllocations returns all IP allocations for a tenant.
func (ipS *IPSv1) V1GetIPAllocations(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *utils.IPAllocations) (err error) {
return ipS.ips.V1GetIPAllocations(ctx, arg, reply)
}

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/rankings"
"github.com/cgrates/cgrates/utils"
)
@@ -173,3 +174,33 @@ func (adms *AdminSv1) RemoveRankingProfile(ctx *context.Context, args *utils.Ten
*reply = utils.OK
return nil
}
// NewRankingSv1 initializes the RankingSv1 object.
func NewRankingSv1(rnkS *rankings.RankingS) *RankingSv1 {
return &RankingSv1{rnkS: rnkS}
}
// RankingSv1 represents the RPC object to register for rankings v1 APIs.
type RankingSv1 struct {
rnkS *rankings.RankingS
}
// V1ScheduleQueries manually schedules or reschedules ranking queries.
func (rnkS *RankingSv1) V1ScheduleQueries(ctx *context.Context, args *utils.ArgScheduleRankingQueries, scheduled *int) (err error) {
return rnkS.rnkS.V1ScheduleQueries(ctx, args, scheduled)
}
// V1GetRanking retrieves ranking metrics with optional filtering.
func (rnkS *RankingSv1) V1GetRanking(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, retRanking *utils.Ranking) (err error) {
return rnkS.rnkS.V1GetRanking(ctx, arg, retRanking)
}
// V1GetSchedule retrieves information about currently scheduled rankings.
func (rnkS *RankingSv1) V1GetSchedule(ctx *context.Context, args *utils.ArgScheduledRankings, schedRankings *[]utils.ScheduledRanking) (err error) {
return rnkS.rnkS.V1GetSchedule(ctx, args, schedRankings)
}
// V1GetRankingSummary retrieves the most recent ranking summary.
func (rnkS *RankingSv1) V1GetRankingSummary(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *utils.RankingSummary) (err error) {
return rnkS.rnkS.V1GetRankingSummary(ctx, arg, reply)
}

View File

@@ -26,6 +26,7 @@ import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/rates"
"github.com/cgrates/cgrates/utils"
)
@@ -306,3 +307,31 @@ func (admS *AdminSv1) RemoveRateProfile(ctx *context.Context, arg *utils.TenantI
*reply = utils.OK
return nil
}
// NewRateSv1 initializes the RateSv1 object.
func NewRateSv1(rtS *rates.RateS) *RateSv1 {
return &RateSv1{rtS: rtS}
}
// RateSv1 represents the RPC object to register for rates v1 APIs.
type RateSv1 struct {
rtS *rates.RateS
}
// V1RateProfilesForEvent will be called to list the RateProfilesIDs that are matching the event
func (rtS *RateSv1) V1RateProfilesForEvent(ctx *context.Context, args *utils.CGREvent, rpIDs *[]string) (err error) {
return rtS.rtS.V1RateProfilesForEvent(ctx, args, rpIDs)
}
// RateProfilesForEvent returns the list of rates that are matching the event from a specific profile
func (rS *RateSv1) V1RateProfileRatesForEvent(ctx *context.Context, args *utils.CGREventWithRateProfile, rtIDs *[]string) (err error) {
return rS.rtS.V1RateProfileRatesForEvent(ctx, args, rtIDs)
}
// V1CostForEvent calculates the cost for an event using matching rate
// profiles. If a higher priority profile fails, it tries the next matching
// profile. This continues until a valid cost is found or all profiles are
// exhausted.
func (rS *RateSv1) V1CostForEvent(ctx *context.Context, args *utils.CGREvent, rpCost *utils.RateProfileCost) (err error) {
return rS.rtS.V1CostForEvent(ctx, args, rpCost)
}

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/resources"
"github.com/cgrates/cgrates/utils"
)
@@ -176,3 +177,43 @@ func (adms *AdminSv1) RemoveResourceProfile(ctx *context.Context, arg *utils.Ten
*reply = utils.OK
return nil
}
// NewResourceSv1 initializes the ResourceSv1 object.
func NewResourceSv1(rsS *resources.ResourceS) *ResourceSv1 {
return &ResourceSv1{rsS: rsS}
}
// ResourceSv1 represents the RPC object to register for resources v1 APIs.
type ResourceSv1 struct {
rsS *resources.ResourceS
}
// V1GetResourcesForEvent returns active resource configs matching the event
func (rS *ResourceSv1) V1GetResourcesForEvent(ctx *context.Context, args *utils.CGREvent, reply *resources.Resources) (err error) {
return rS.rsS.V1GetResourcesForEvent(ctx, args, reply)
}
// V1AuthorizeResources queries service to find if an Usage is allowed
func (rS *ResourceSv1) V1AuthorizeResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return rS.rsS.V1AuthorizeResources(ctx, args, reply)
}
// V1AllocateResources is called when a resource requires allocation
func (rS *ResourceSv1) V1AllocateResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return rS.rsS.V1AllocateResources(ctx, args, reply)
}
// V1ReleaseResources is called when we need to clear an allocation
func (rS *ResourceSv1) V1ReleaseResources(ctx *context.Context, args *utils.CGREvent, reply *string) (err error) {
return rS.rsS.V1ReleaseResources(ctx, args, reply)
}
// V1GetResource returns a resource
func (rS *ResourceSv1) V1GetResource(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *utils.Resource) error {
return rS.rsS.V1GetResource(ctx, arg, reply)
}
// V1GetResource returns a resource configuration
func (rS *ResourceSv1) V1GetResourceWithConfig(ctx *context.Context, arg *utils.TenantIDWithAPIOpts, reply *utils.ResourceWithConfig) (err error) {
return rS.rsS.V1GetResourceWithConfig(ctx, arg, reply)
}

View File

@@ -23,6 +23,7 @@ import (
"time"
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/routes"
"github.com/cgrates/cgrates/utils"
)
@@ -173,3 +174,23 @@ func (adms *AdminSv1) RemoveRouteProfile(ctx *context.Context, args *utils.Tenan
*reply = utils.OK
return nil
}
// NewRouteSv1 initializes the RouteSv1 object.
func NewRouteSv1(rpS *routes.RouteS) *RouteSv1 {
return &RouteSv1{rpS: rpS}
}
// RouteSv1 represents the RPC object to register for routes v1 APIs.
type RouteSv1 struct {
rpS *routes.RouteS
}
// V1GetRoutes returns the list of valid routes.
func (rpS *RouteSv1) V1GetRoutes(ctx *context.Context, args *utils.CGREvent, reply *routes.SortedRoutesList) (err error) {
return rpS.rpS.V1GetRoutes(ctx, args, reply)
}
// V1GetRoutesList returns the list of valid routes.
func (rpS *RouteSv1) V1GetRoutesList(ctx *context.Context, args *utils.CGREvent, reply *[]string) (err error) {
return rpS.rpS.V1GetRoutesList(ctx, args, reply)
}

View File

@@ -20,6 +20,7 @@ package apis
import (
"github.com/cgrates/birpc/context"
"github.com/cgrates/cgrates/trends"
"github.com/cgrates/cgrates/utils"
)
@@ -139,3 +140,33 @@ func (adms *AdminSv1) RemoveTrendProfile(ctx *context.Context, args *utils.Tenan
*reply = utils.OK
return nil
}
// NewTrendSv1 initializes the TrendSv1 object.
func NewTrendSv1(trndS *trends.TrendS) *TrendSv1 {
return &TrendSv1{trndS: trndS}
}
// TrendSv1 represents the RPC object to register for trends v1 APIs.
type TrendSv1 struct {
trndS *trends.TrendS
}
// V1ScheduleQueries manually schedules or reschedules trend queries.
func (tS *TrendSv1) V1ScheduleQueries(ctx *context.Context, args *utils.ArgScheduleTrendQueries, scheduled *int) (err error) {
return tS.trndS.V1ScheduleQueries(ctx, args, scheduled)
}
// V1GetTrend retrieves trend metrics with optional time and index filtering.
func (tS *TrendSv1) V1GetTrend(ctx *context.Context, arg *utils.ArgGetTrend, retTrend *utils.Trend) (err error) {
return tS.trndS.V1GetTrend(ctx, arg, retTrend)
}
// V1GetScheduledTrends retrieves information about currently scheduled trends.
func (tS *TrendSv1) V1GetScheduledTrends(ctx *context.Context, args *utils.ArgScheduledTrends, schedTrends *[]utils.ScheduledTrend) (err error) {
return tS.trndS.V1GetScheduledTrends(ctx, args, schedTrends)
}
// V1GetTrendSummary retrieves the most recent trend summary.
func (tS *TrendSv1) V1GetTrendSummary(ctx *context.Context, arg utils.TenantIDWithAPIOpts, reply *utils.TrendSummary) (err error) {
return tS.trndS.V1GetTrendSummary(ctx, arg, reply)
}