mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added method for ReplicatorSv1 for AccountProfile in dispatchesr
This commit is contained in:
committed by
Dan Christian Bogos
parent
d52f5636ad
commit
5e8c34d118
@@ -269,4 +269,12 @@ type ReplicatorSv1Interface interface {
|
||||
GetIndexes(args *utils.GetIndexesArg, reply *map[string]utils.StringSet) error
|
||||
SetIndexes(args *utils.SetIndexesArg, reply *string) error
|
||||
RemoveIndexes(args *utils.GetIndexesArg, reply *string) error
|
||||
|
||||
GetAccountProfile(tntID *utils.TenantIDWithOpts, reply *utils.AccountProfile) error
|
||||
SetAccountProfile(args *utils.AccountProfileWithOpts, reply *string) error
|
||||
RemoveAccountProfile(args *utils.TenantIDWithOpts, reply *string) error
|
||||
|
||||
GetActionProfile(tntID *utils.TenantIDWithOpts, reply *engine.ActionProfile) error
|
||||
SetActionProfile(args *engine.ActionProfileWithOpts, reply *string) error
|
||||
RemoveActionProfile(args *utils.TenantIDWithOpts, reply *string) error
|
||||
}
|
||||
|
||||
@@ -1286,6 +1286,36 @@ func (dS *DispatcherReplicatorSv1) RemoveIndexes(args *utils.GetIndexesArg, repl
|
||||
return dS.dS.ReplicatorSv1RemoveIndexes(args, reply)
|
||||
}
|
||||
|
||||
// GetAccountProfile .
|
||||
func (dS *DispatcherReplicatorSv1) GetAccountProfile(tntID *utils.TenantIDWithOpts, reply *utils.AccountProfile) error {
|
||||
return dS.dS.ReplicatorSv1GetAccountProfile(tntID, reply)
|
||||
}
|
||||
|
||||
// SetAccountProfile .
|
||||
func (dS *DispatcherReplicatorSv1) SetAccountProfile(args *utils.AccountProfileWithOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1SetAccountProfile(args, reply)
|
||||
}
|
||||
|
||||
// RemoveAccountProfile .
|
||||
func (dS *DispatcherReplicatorSv1) RemoveAccountProfile(args *utils.TenantIDWithOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1RemoveAccountProfile(args, reply)
|
||||
}
|
||||
|
||||
// GetActionProfile .
|
||||
func (dS *DispatcherReplicatorSv1) GetActionProfile(tntID *utils.TenantIDWithOpts, reply *engine.ActionProfile) error {
|
||||
return dS.dS.ReplicatorSv1GetActionProfile(tntID, reply)
|
||||
}
|
||||
|
||||
// SetActionProfile .
|
||||
func (dS *DispatcherReplicatorSv1) SetActionProfile(args *engine.ActionProfileWithOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1SetActionProfile(args, reply)
|
||||
}
|
||||
|
||||
// RemoveActionProfile .
|
||||
func (dS *DispatcherReplicatorSv1) RemoveActionProfile(args *utils.TenantIDWithOpts, reply *string) error {
|
||||
return dS.dS.ReplicatorSv1RemoveActionProfile(args, reply)
|
||||
}
|
||||
|
||||
func NewDispatcherRateSv1(dps *dispatchers.DispatcherService) *DispatcherRateSv1 {
|
||||
return &DispatcherRateSv1{dR: dps}
|
||||
}
|
||||
|
||||
@@ -1099,8 +1099,8 @@ const CGRATES_CFG_JSON = `
|
||||
"accounts": { // AccountS config
|
||||
"enabled": false, // starts service: <true|false>
|
||||
"indexed_selects": true, // enable profile matching exclusively on indexes
|
||||
"attributes_conns": [],
|
||||
"rates_conns": [],
|
||||
"attributes_conns": [], // connections to AttributeS for account/balance updates, empty to disable attributes functionality: <""|*internal|$rpc_conns_id>
|
||||
"rates_conns": [], // connections to RatesS for account/balance updates, empty to disable rates functionality: <""|*internal|$rpc_conns_id>
|
||||
"thresholds_conns": [], // connections to ThresholdS for account/balance updates, empty to disable thresholds functionality: <""|*internal|$rpc_conns_id>
|
||||
//"string_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
"prefix_indexed_fields": [], // query indexes based on these fields for faster processing
|
||||
|
||||
@@ -20,7 +20,7 @@ cgrates.org,ATTR_API_PSE_AUTH,*auth,*string:~*req.ApiKey:pse12345,,,*req.APIMeth
|
||||
cgrates.org,ATTR_API_CFG_AUTH,*auth,*string:~*req.ApiKey:cfg12345,,,*req.APIMethods,*constant,ConfigSv1.GetConfig&ConfigSv1.ReloadConfig,false,20
|
||||
cgrates.org,ATTR_API_APIER_AUTH,*auth,*string:~*req.ApiKey:apier12345,,,*req.APIMethods,*constant,APIerSv1.GetAttributeProfile&APIerSv1.SetAttributeProfile,false,20
|
||||
cgrates.org,ATTR_API_RALS_AUTH,*auth,*string:~*req.ApiKey:rals12345,,,*req.APIMethods,*constant,RALsV1.Ping&RALsV1.GetRatingPlansCost,false,20
|
||||
cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.ApiKey:repl12345,,,*req.APIMethods,*constant,ReplicatorSv1.Ping&ReplicatorSv1.GetAccount&ReplicatorSv1.SetAccount&ReplicatorSv1.RemoveAccount&ReplicatorSv1.GetRouteProfile&ReplicatorSv1.SetRouteProfile&ReplicatorSv1.RemoveRouteProfile&ReplicatorSv1.GetAttributeProfile&ReplicatorSv1.SetAttributeProfile&ReplicatorSv1.RemoveAttributeProfile&ReplicatorSv1.SetChargerProfile&ReplicatorSv1.GetChargerProfile&ReplicatorSv1.RemoveChargerProfile&ReplicatorSv1.GetDispatcherProfile&ReplicatorSv1.SetDispatcherProfile&ReplicatorSv1.RemoveDispatcherProfile&ReplicatorSv1.GetDispatcherHost&ReplicatorSv1.SetDispatcherHost&ReplicatorSv1.RemoveDispatcherHost&ReplicatorSv1.GetFilter&ReplicatorSv1.SetFilter&ReplicatorSv1.RemoveFilter&ReplicatorSv1.GetThreshold&ReplicatorSv1.SetThreshold&ReplicatorSv1.RemoveThreshold&ReplicatorSv1.GetStatQueue&ReplicatorSv1.SetStatQueue&ReplicatorSv1.RemoveStatQueue&ReplicatorSv1.GetResource&ReplicatorSv1.SetResource&ReplicatorSv1.RemoveResource&ReplicatorSv1.GetResourceProfile&ReplicatorSv1.SetResourceProfile&ReplicatorSv1.RemoveResourceProfile&ReplicatorSv1.GetStatQueueProfile&ReplicatorSv1.SetStatQueueProfile&ReplicatorSv1.RemoveStatQueueProfile&ReplicatorSv1.GetThresholdProfile&ReplicatorSv1.SetThresholdProfile&ReplicatorSv1.RemoveThresholdProfile&ReplicatorSv1.GetTiming&ReplicatorSv1.SetTiming&ReplicatorSv1.RemoveTiming&ReplicatorSv1.GetActionTriggers&ReplicatorSv1.SetActionTriggers&ReplicatorSv1.RemoveActionTriggers&ReplicatorSv1.SetSharedGroup&ReplicatorSv1.GetSharedGroup&ReplicatorSv1.RemoveSharedGroup&ReplicatorSv1.SetActions&ReplicatorSv1.GetActions&ReplicatorSv1.RemoveActions&ReplicatorSv1.SetActionPlan&ReplicatorSv1.GetActionPlan&ReplicatorSv1.RemoveActionPlan&ReplicatorSv1.SetAccountActionPlans&ReplicatorSv1.GetAccountActionPlans&ReplicatorSv1.RemAccountActionPlans&ReplicatorSv1.SetRatingPlan&ReplicatorSv1.GetRatingPlan&ReplicatorSv1.RemoveRatingPlan&ReplicatorSv1.SetRatingProfile&ReplicatorSv1.GetRatingProfile&ReplicatorSv1.RemoveRatingProfile&ReplicatorSv1.SetDestination&ReplicatorSv1.GetDestination&ReplicatorSv1.RemoveDestination&ReplicatorSv1.SetLoadIDs&ReplicatorSv1.GetItemLoadIDs&ReplicatorSv1.SetRateProfile&ReplicatorSv1.GetRateProfile&ReplicatorSv1.RemoveRateProfile,false,20
|
||||
cgrates.org,ATTR_API_REPLICATOR_AUTH,*auth,*string:~*req.ApiKey:repl12345,,,*req.APIMethods,*constant,ReplicatorSv1.Ping&ReplicatorSv1.GetAccount&ReplicatorSv1.SetAccount&ReplicatorSv1.RemoveAccount&ReplicatorSv1.GetRouteProfile&ReplicatorSv1.SetRouteProfile&ReplicatorSv1.RemoveRouteProfile&ReplicatorSv1.GetAttributeProfile&ReplicatorSv1.SetAttributeProfile&ReplicatorSv1.RemoveAttributeProfile&ReplicatorSv1.SetChargerProfile&ReplicatorSv1.GetChargerProfile&ReplicatorSv1.RemoveChargerProfile&ReplicatorSv1.GetDispatcherProfile&ReplicatorSv1.SetDispatcherProfile&ReplicatorSv1.RemoveDispatcherProfile&ReplicatorSv1.GetDispatcherHost&ReplicatorSv1.SetDispatcherHost&ReplicatorSv1.RemoveDispatcherHost&ReplicatorSv1.GetFilter&ReplicatorSv1.SetFilter&ReplicatorSv1.RemoveFilter&ReplicatorSv1.GetThreshold&ReplicatorSv1.SetThreshold&ReplicatorSv1.RemoveThreshold&ReplicatorSv1.GetStatQueue&ReplicatorSv1.SetStatQueue&ReplicatorSv1.RemoveStatQueue&ReplicatorSv1.GetResource&ReplicatorSv1.SetResource&ReplicatorSv1.RemoveResource&ReplicatorSv1.GetResourceProfile&ReplicatorSv1.SetResourceProfile&ReplicatorSv1.RemoveResourceProfile&ReplicatorSv1.GetStatQueueProfile&ReplicatorSv1.SetStatQueueProfile&ReplicatorSv1.RemoveStatQueueProfile&ReplicatorSv1.GetThresholdProfile&ReplicatorSv1.SetThresholdProfile&ReplicatorSv1.RemoveThresholdProfile&ReplicatorSv1.GetTiming&ReplicatorSv1.SetTiming&ReplicatorSv1.RemoveTiming&ReplicatorSv1.GetActionTriggers&ReplicatorSv1.SetActionTriggers&ReplicatorSv1.RemoveActionTriggers&ReplicatorSv1.SetSharedGroup&ReplicatorSv1.GetSharedGroup&ReplicatorSv1.RemoveSharedGroup&ReplicatorSv1.SetActions&ReplicatorSv1.GetActions&ReplicatorSv1.RemoveActions&ReplicatorSv1.SetActionPlan&ReplicatorSv1.GetActionPlan&ReplicatorSv1.RemoveActionPlan&ReplicatorSv1.SetAccountActionPlans&ReplicatorSv1.GetAccountActionPlans&ReplicatorSv1.RemAccountActionPlans&ReplicatorSv1.SetRatingPlan&ReplicatorSv1.GetRatingPlan&ReplicatorSv1.RemoveRatingPlan&ReplicatorSv1.SetRatingProfile&ReplicatorSv1.GetRatingProfile&ReplicatorSv1.RemoveRatingProfile&ReplicatorSv1.SetDestination&ReplicatorSv1.GetDestination&ReplicatorSv1.RemoveDestination&ReplicatorSv1.SetLoadIDs&ReplicatorSv1.GetItemLoadIDs&ReplicatorSv1.SetRateProfile&ReplicatorSv1.GetRateProfile&ReplicatorSv1.RemoveRateProfile&ReplicatorSv1.SetAccountProfile&ReplicatorSv1.GetAccountProfile&ReplicatorSv1.RemoveAccountProfile&ReplicatorSv1.SetActionProfile&ReplicatorSv1.GetActionProfile&ReplicatorSv1.RemoveActionProfile,false,20
|
||||
cgrates.org,ATTR_API_CDRSV2,*auth,*string:~*req.ApiKey:cdrsv212345,,,*req.APIMethods,*constant,CDRsV2.ProcessEvent&CDRsV2.StoreSessionCost,false,20
|
||||
cgrates.org,ATTR_API_RATES_AUTH,*auth,*string:~*req.ApiKey:rPrf12345,,,*req.APIMethods,*constant,RateSv1.Ping&RateSv1.CostForEvent,false,20
|
||||
cgrates.org,ATTR_API_CORE_AUTH,*auth,*string:~*req.ApiKey:core12345,,,*req.APIMethods,*constant,CoreSv1.Status&CoreSv1.Ping&CoreSv1.Sleep,false,20
|
||||
|
||||
|
@@ -1575,3 +1575,61 @@ func (dS *DispatcherService) ReplicatorSv1RemoveIndexes(args *utils.GetIndexesAr
|
||||
Opts: args.Opts,
|
||||
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveIndexes, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ReplicatorSv1GetAccountProfile(args *utils.TenantIDWithOpts, reply *utils.AccountProfile) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args.TenantID != nil && args.TenantID.Tenant != utils.EmptyString {
|
||||
tnt = args.TenantID.Tenant
|
||||
}
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if err = dS.authorize(utils.ReplicatorSv1GetAccountProfile, tnt,
|
||||
utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: tnt,
|
||||
ID: args.ID,
|
||||
},
|
||||
Opts: args.Opts,
|
||||
}, utils.MetaReplicator, utils.ReplicatorSv1GetAccountProfile, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ReplicatorSv1SetAccountProfile(args *utils.AccountProfileWithOpts, rpl *string) (err error) {
|
||||
if args == nil {
|
||||
args = &utils.AccountProfileWithOpts{}
|
||||
}
|
||||
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if err = dS.authorize(utils.ReplicatorSv1SetAccountProfile, args.Tenant,
|
||||
utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: args.Tenant,
|
||||
},
|
||||
Opts: args.Opts,
|
||||
}, utils.MetaReplicator, utils.ReplicatorSv1SetAccountProfile, args, rpl)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) ReplicatorSv1RemoveAccountProfile(args *utils.TenantIDWithOpts, rpl *string) (err error) {
|
||||
if args == nil {
|
||||
args = &utils.TenantIDWithOpts{}
|
||||
}
|
||||
args.Tenant = utils.FirstNonEmpty(args.Tenant, dS.cfg.GeneralCfg().DefaultTenant)
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if err = dS.authorize(utils.ReplicatorSv1RemoveAccountProfile, args.Tenant,
|
||||
utils.IfaceAsString(args.Opts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREventWithOpts{
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: args.Tenant,
|
||||
},
|
||||
Opts: args.Opts,
|
||||
}, utils.MetaReplicator, utils.ReplicatorSv1RemoveAccountProfile, args, rpl)
|
||||
}
|
||||
|
||||
@@ -53,6 +53,8 @@ var sTestsDspRpl = []func(t *testing.T){
|
||||
testDspRplRatingProfile,
|
||||
testDspRplDestination,
|
||||
testDspRplRateProfile,
|
||||
testDspRplAccountProfile,
|
||||
testDspRplActionProfile,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
@@ -1545,3 +1547,122 @@ func testDspRplRateProfile(t *testing.T) {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
|
||||
}
|
||||
}
|
||||
func testDspRplAccountProfile(t *testing.T) {
|
||||
// Set RateProfile
|
||||
var replyStr string
|
||||
rPrf := &utils.AccountProfileWithOpts{
|
||||
AccountProfile: &utils.AccountProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP1",
|
||||
},
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetAccountProfile, rPrf, &replyStr); err != nil {
|
||||
t.Error("Unexpected error when calling ReplicatorSv1.SetAccountProfile: ", err)
|
||||
} else if replyStr != utils.OK {
|
||||
t.Error("Unexpected reply returned", replyStr)
|
||||
}
|
||||
// Get RateProfile
|
||||
var reply *utils.AccountProfile
|
||||
args := &utils.TenantIDWithOpts{
|
||||
TenantID: &utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP1",
|
||||
},
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountProfile, args, &reply); err != nil {
|
||||
t.Error("Unexpected error when calling ReplicatorSv1.GetAccountProfile: ", err)
|
||||
} else if !reflect.DeepEqual(rPrf.AccountProfile, reply) {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", rPrf.AccountProfile, reply)
|
||||
}
|
||||
// Stop engine 1
|
||||
allEngine.stopEngine(t)
|
||||
|
||||
// Get RateProfile
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountProfile, args, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
|
||||
}
|
||||
|
||||
// Start engine 1
|
||||
allEngine.startEngine(t)
|
||||
|
||||
// Remove RateProfile
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveAccountProfile, args, &replyStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if replyStr != utils.OK {
|
||||
t.Error("Unexpected reply returned", replyStr)
|
||||
}
|
||||
|
||||
// Get RateProfile
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetAccountProfile, args, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testDspRplActionProfile(t *testing.T) {
|
||||
// Set RateProfile
|
||||
var replyStr string
|
||||
rPrf := &engine.ActionProfileWithOpts{
|
||||
ActionProfile: &engine.ActionProfile{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP1",
|
||||
},
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1SetActionProfile, rPrf, &replyStr); err != nil {
|
||||
t.Error("Unexpected error when calling ReplicatorSv1.SetActionProfile: ", err)
|
||||
} else if replyStr != utils.OK {
|
||||
t.Error("Unexpected reply returned", replyStr)
|
||||
}
|
||||
// Get RateProfile
|
||||
var reply *engine.ActionProfile
|
||||
args := &utils.TenantIDWithOpts{
|
||||
TenantID: &utils.TenantID{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "RP1",
|
||||
},
|
||||
Opts: map[string]interface{}{
|
||||
utils.OptsAPIKey: "repl12345",
|
||||
},
|
||||
}
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionProfile, args, &reply); err != nil {
|
||||
t.Error("Unexpected error when calling ReplicatorSv1.GetActionProfile: ", err)
|
||||
} else if !reflect.DeepEqual(rPrf.ActionProfile, reply) {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", rPrf.ActionProfile, reply)
|
||||
}
|
||||
// Stop engine 1
|
||||
allEngine.stopEngine(t)
|
||||
|
||||
// Get RateProfile
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionProfile, args, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
|
||||
}
|
||||
|
||||
// Start engine 1
|
||||
allEngine.startEngine(t)
|
||||
|
||||
// Remove RateProfile
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1RemoveActionProfile, args, &replyStr); err != nil {
|
||||
t.Error(err)
|
||||
} else if replyStr != utils.OK {
|
||||
t.Error("Unexpected reply returned", replyStr)
|
||||
}
|
||||
|
||||
// Get RateProfile
|
||||
if err := dispEngine.RPC.Call(utils.ReplicatorSv1GetActionProfile, args, &reply); err == nil ||
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
t.Errorf("Expecting: %+v, received: %+v, ", utils.ErrNotFound, err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user