Implement RemoveThreshold when replicate is true

This commit is contained in:
TeoV
2019-11-20 13:17:55 -05:00
committed by Dan Christian Bogos
parent af1cfc64c8
commit 5913709796
4 changed files with 39 additions and 23 deletions

View File

@@ -57,22 +57,22 @@ var sTestsInternalRemoteIT = []func(t *testing.T){
testInternalRemoteITStartEngine,
testInternalRemoteITRPCConn,
testInternalRemoteLoadDataInEngineTwo,
//testInternalRemoteITGetAccount,
//testInternalRemoteITGetAttribute,
//testInternalRemoteITGetThreshold,
//testInternalRemoteITGetThresholdProfile,
//testInternalRemoteITGetResource,
//testInternalRemoteITGetResourceProfile,
//testInternalRemoteITGetStatQueueProfile,
//testInternalRemoteITGetSupplier,
//testInternalRemoteITGetFilter,
//testInternalRemoteITGetRatingPlan,
//testInternalRemoteITGetRatingProfile,
//testInternalRemoteITGetAction,
//testInternalRemoteITGetActionPlan,
//testInternalRemoteITGetAccountActionPlan,
//testInternalRemoteITGetDestination,
//testInternalRemoteITGetReverseDestination,
testInternalRemoteITGetAccount,
testInternalRemoteITGetAttribute,
testInternalRemoteITGetThreshold,
testInternalRemoteITGetThresholdProfile,
testInternalRemoteITGetResource,
testInternalRemoteITGetResourceProfile,
testInternalRemoteITGetStatQueueProfile,
testInternalRemoteITGetSupplier,
testInternalRemoteITGetFilter,
testInternalRemoteITGetRatingPlan,
testInternalRemoteITGetRatingProfile,
testInternalRemoteITGetAction,
testInternalRemoteITGetActionPlan,
testInternalRemoteITGetAccountActionPlan,
testInternalRemoteITGetDestination,
testInternalRemoteITGetReverseDestination,
testInternalReplicationSetThreshold,
testInternalMatchThreshold,
testInternalRemoteITKillEngine,
@@ -640,6 +640,7 @@ func testInternalReplicationSetThreshold(t *testing.T) {
} else if result != utils.OK {
t.Error("Unexpected reply returned", result)
}
time.Sleep(50 * time.Millisecond)
if err := internalRPC.Call("ApierV1.GetThresholdProfile",
&utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil {
t.Error(err)
@@ -742,10 +743,8 @@ func testInternalMatchThreshold(t *testing.T) {
utils.Account: "1001",
},
}
if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev2, &ids); err != nil {
if err := internalRPC.Call(utils.ThresholdSv1ProcessEvent, ev2, &ids); err == nil || err.Error() != utils.ErrNotFound.Error() {
t.Error(err)
} else if !reflect.DeepEqual(ids, eIDs) {
t.Errorf("Expecting ids: %s, received: %s", eIDs, ids)
}
}

View File

@@ -494,6 +494,14 @@ func (rplSv1 *ReplicatorSv1) SetDispatcherHost(dpp *engine.DispatcherHost, reply
return nil
}
func (rplSv1 *ReplicatorSv1) RemoveThreshold(args *utils.TenantID, reply *string) error {
if err := rplSv1.dm.DataDB().RemoveThresholdDrv(args.Tenant, args.ID); err != nil {
return err
}
*reply = utils.OK
return nil
}
func (rplSv1 *ReplicatorSv1) SetLoadIDs(loadIDs map[string]int64, reply *string) error {
if err := rplSv1.dm.DataDB().SetLoadIDsDrv(loadIDs); err != nil {
return err

View File

@@ -321,7 +321,9 @@ func (dm *DataManager) GetDestination(key string, skipCache bool, transactionID
if err != nil {
if err == utils.ErrNotFound && dm.rmtConns != nil &&
config.CgrConfig().DataDbCfg().Items[utils.MetaDestinations].Remote {
err = dm.rmtConns.Call(utils.ReplicatorSv1GetDestination, key, &dest)
if err = dm.rmtConns.Call(utils.ReplicatorSv1GetDestination, key, &dest); err == nil {
err = dm.dataDB.SetDestinationDrv(dest, utils.NonTransactional)
}
}
if err != nil {
err = utils.CastRPCErr(err)
@@ -558,15 +560,16 @@ func (dm *DataManager) GetThreshold(tenant, id string,
if err != nil {
if err == utils.ErrNotFound &&
config.CgrConfig().DataDbCfg().Items[utils.MetaThresholds].Remote {
err = dm.rmtConns.Call(utils.ReplicatorSv1GetThreshold,
&utils.TenantID{Tenant: tenant, ID: id}, &th)
if err = dm.rmtConns.Call(utils.ReplicatorSv1GetThreshold,
&utils.TenantID{Tenant: tenant, ID: id}, &th); err == nil {
err = dm.dataDB.SetThresholdDrv(th)
}
}
if err != nil {
err = utils.CastRPCErr(err)
if err == utils.ErrNotFound && cacheWrite {
Cache.Set(utils.CacheThresholds, tntID, nil, nil,
cacheCommit(transactionID), transactionID)
}
return nil, err
}
@@ -596,6 +599,11 @@ func (dm *DataManager) RemoveThreshold(tenant, id, transactionID string) (err er
if err = dm.DataDB().RemoveThresholdDrv(tenant, id); err != nil {
return
}
if config.CgrConfig().DataDbCfg().Items[utils.MetaThresholds].Replicate {
var reply string
dm.rplConns.Call(utils.ReplicatorSv1RemoveThreshold,
&utils.TenantID{Tenant: tenant, ID: id}, &reply)
}
return
}

View File

@@ -842,6 +842,7 @@ const (
ReplicatorSv1SetDispatcherProfile = "ReplicatorSv1.SetDispatcherProfile"
ReplicatorSv1SetDispatcherHost = "ReplicatorSv1.SetDispatcherHost"
ReplicatorSv1SetLoadIDs = "ReplicatorSv1.SetLoadIDs"
ReplicatorSv1RemoveThreshold = "ReplicatorSv1.RemoveThreshold"
)
// ApierV1 APIs