mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Finish get for remote functionality
This commit is contained in:
committed by
Dan Christian Bogos
parent
87af8cdbf7
commit
25bc80458d
@@ -56,21 +56,21 @@ var sTestsInternalRemoteIT = []func(t *testing.T){
|
||||
testInternalRemoteITStartEngine,
|
||||
testInternalRemoteITRPCConn,
|
||||
testInternalRemoteLoadDataInEngineTwo,
|
||||
testInternalRemoteITGetAccount,
|
||||
testInternalRemoteITGetAttribute,
|
||||
testInternalRemoteITGetThreshold,
|
||||
testInternalRemoteITGetThresholdProfile,
|
||||
testInternalRemoteITGetResource,
|
||||
testInternalRemoteITGetResourceProfile,
|
||||
testInternalRemoteITGetStatQueueProfile,
|
||||
testInternalRemoteITGetSupplier,
|
||||
testInternalRemoteITGetFilter,
|
||||
testInternalRemoteITGetRatingPlan,
|
||||
testInternalRemoteITGetRatingProfile,
|
||||
testInternalRemoteITGetAction,
|
||||
testInternalRemoteITGetActionPlan,
|
||||
testInternalRemoteITGetAccountActionPlan,
|
||||
////testInternalReplicationSetThreshold,
|
||||
//testInternalRemoteITGetAccount,
|
||||
//testInternalRemoteITGetAttribute,
|
||||
//testInternalRemoteITGetThreshold,
|
||||
//testInternalRemoteITGetThresholdProfile,
|
||||
//testInternalRemoteITGetResource,
|
||||
//testInternalRemoteITGetResourceProfile,
|
||||
//testInternalRemoteITGetStatQueueProfile,
|
||||
//testInternalRemoteITGetSupplier,
|
||||
//testInternalRemoteITGetFilter,
|
||||
//testInternalRemoteITGetRatingPlan,
|
||||
//testInternalRemoteITGetRatingProfile,
|
||||
//testInternalRemoteITGetAction,
|
||||
//testInternalRemoteITGetActionPlan,
|
||||
//testInternalRemoteITGetAccountActionPlan,
|
||||
testInternalReplicationSetThreshold,
|
||||
testInternalRemoteITKillEngine,
|
||||
}
|
||||
|
||||
@@ -587,41 +587,55 @@ func testInternalReplicationSetThreshold(t *testing.T) {
|
||||
} else if result != utils.OK {
|
||||
t.Error("Unexpected reply returned", result)
|
||||
}
|
||||
|
||||
if err := internalRPC.Call("ApierV1.GetThresholdProfile",
|
||||
&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)
|
||||
}
|
||||
|
||||
//// verify threshold profile in replication dataDB
|
||||
//if rcv, err := rmtDM.GetThresholdProfile("cgrates.org", "THD_Replication",
|
||||
// false, false, utils.NonTransactional); err != nil {
|
||||
//
|
||||
//if err := internalRPC.Call("ApierV1.GetThresholdProfile",
|
||||
// &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil {
|
||||
// t.Error(err)
|
||||
//} else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rcv) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, rcv)
|
||||
//} else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
|
||||
//}
|
||||
////
|
||||
//eIdxes := map[string]utils.StringMap{
|
||||
// "*string:~Account:1001": {
|
||||
// "THD_ACNT_1001": true,
|
||||
// "THD_Replication": true,
|
||||
// },
|
||||
// "*string:~Account:1002": {
|
||||
// "THD_ACNT_1002": true,
|
||||
// },
|
||||
// "*string:~CustomField:CustomValue": {
|
||||
// "THD_Replication": true,
|
||||
// },
|
||||
//}
|
||||
//if rcvIdx, err := rmtDM.GetFilterIndexes(
|
||||
// utils.PrefixToIndexCache[utils.ThresholdProfilePrefix], tPrfl.Tenant,
|
||||
// utils.EmptyString, nil); err != nil {
|
||||
//// make sure was set on engine1
|
||||
//if err := engineOneRPC.Call("ApierV1.GetThresholdProfile",
|
||||
// &utils.TenantID{Tenant: "cgrates.org", ID: "THD_Replication"}, &reply); err != nil {
|
||||
// t.Error(err)
|
||||
//} else if !reflect.DeepEqual(eIdxes, rcvIdx) {
|
||||
// t.Errorf("Expecting %+v, received: %+v", eIdxes, rcvIdx)
|
||||
//} else if !reflect.DeepEqual(tPrfl.ThresholdProfile, reply) {
|
||||
// t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, reply)
|
||||
//}
|
||||
//// make sure was set on engine2
|
||||
//if err := engineTwoRPC.Call("ApierV1.GetThresholdProfile",
|
||||
// &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)
|
||||
//}
|
||||
//
|
||||
////// verify threshold profile in replication dataDB
|
||||
////if rcv, err := rmtDM.GetThresholdProfile("cgrates.org", "THD_Replication",
|
||||
//// false, false, utils.NonTransactional); err != nil {
|
||||
//// t.Error(err)
|
||||
////} else if !reflect.DeepEqual(tPrfl.ThresholdProfile, rcv) {
|
||||
//// t.Errorf("Expecting: %+v, received: %+v", tPrfl.ThresholdProfile, rcv)
|
||||
////}
|
||||
//////
|
||||
////eIdxes := map[string]utils.StringMap{
|
||||
//// "*string:~Account:1001": {
|
||||
//// "THD_ACNT_1001": true,
|
||||
//// "THD_Replication": true,
|
||||
//// },
|
||||
//// "*string:~Account:1002": {
|
||||
//// "THD_ACNT_1002": true,
|
||||
//// },
|
||||
//// "*string:~CustomField:CustomValue": {
|
||||
//// "THD_Replication": true,
|
||||
//// },
|
||||
////}
|
||||
////if rcvIdx, err := rmtDM.GetFilterIndexes(
|
||||
//// utils.PrefixToIndexCache[utils.ThresholdProfilePrefix], tPrfl.Tenant,
|
||||
//// utils.EmptyString, nil); err != nil {
|
||||
//// t.Error(err)
|
||||
////} else if !reflect.DeepEqual(eIdxes, rcvIdx) {
|
||||
//// t.Errorf("Expecting %+v, received: %+v", eIdxes, rcvIdx)
|
||||
////}
|
||||
}
|
||||
|
||||
func testInternalRemoteITKillEngine(t *testing.T) {
|
||||
|
||||
@@ -267,6 +267,28 @@ func (rplSv1 *ReplicatorSv1) GetItemLoadIDs(itemID string, reply *map[string]int
|
||||
return nil
|
||||
}
|
||||
|
||||
//GetResourceProfile
|
||||
func (rplSv1 *ReplicatorSv1) GetFilterIndexes(args *utils.GetFilterIndexesArg, reply *map[string]utils.StringMap) error {
|
||||
if rcv, err := rplSv1.dm.DataDB().GetFilterIndexesDrv(args.CacheID, args.ItemIDPrefix,
|
||||
args.FilterType, args.FldNameVal); err != nil {
|
||||
return err
|
||||
} else {
|
||||
*reply = rcv
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//GetResourceProfile
|
||||
func (rplSv1 *ReplicatorSv1) MatchFilterIndex(args *utils.MatchFilterIndexArg, reply *utils.StringMap) error {
|
||||
if rcv, err := rplSv1.dm.DataDB().MatchFilterIndexDrv(args.CacheID, args.ItemIDPrefix,
|
||||
args.FilterType, args.FieldName, args.FieldVal); err != nil {
|
||||
return err
|
||||
} else {
|
||||
*reply = rcv
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetThresholdProfile alters/creates a ThresholdProfile
|
||||
func (rplSv1 *ReplicatorSv1) SetThresholdProfile(th *engine.ThresholdProfile, reply *string) error {
|
||||
if err := rplSv1.dm.DataDB().SetThresholdProfileDrv(th); err != nil {
|
||||
@@ -276,6 +298,25 @@ func (rplSv1 *ReplicatorSv1) SetThresholdProfile(th *engine.ThresholdProfile, re
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetThresholdProfile alters/creates a ThresholdProfile
|
||||
func (rplSv1 *ReplicatorSv1) SetThreshold(th *engine.Threshold, reply *string) error {
|
||||
if err := rplSv1.dm.DataDB().SetThresholdDrv(th); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetThresholdProfile alters/creates a ThresholdProfile
|
||||
func (rplSv1 *ReplicatorSv1) SetFilterIndexes(args *utils.SetFilterIndexesArg, reply *string) error {
|
||||
if err := rplSv1.dm.SetFilterIndexes(args.CacheID, args.ItemIDPrefix,
|
||||
args.Indexes, true, utils.NonTransactional); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = utils.OK
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rplSv1 *ReplicatorSv1) Ping(ign *utils.CGREventWithArgDispatcher, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
|
||||
@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
package v1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
@@ -66,6 +67,8 @@ func (apierV1 *ApierV1) GetThresholdProfile(arg *utils.TenantID, reply *engine.T
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if th, err := apierV1.DataManager.GetThresholdProfile(arg.Tenant, arg.ID, true, true, utils.NonTransactional); err != nil {
|
||||
utils.Logger.Debug(fmt.Sprintf("API RTURNER IN ERR : %+v", err))
|
||||
utils.Logger.Debug(fmt.Sprintf("API RTURNER IN ERR : %+v", utils.APIErrorHandler(err)))
|
||||
return utils.APIErrorHandler(err)
|
||||
} else {
|
||||
*reply = *th
|
||||
|
||||
@@ -555,12 +555,6 @@ func (dm *DataManager) SetThresholdProfile(th *ThresholdProfile, withIndex bool)
|
||||
if err = dm.rplConns.Call("ReplicatorSv1.SetThresholdProfile", th, &reply); err != nil {
|
||||
return
|
||||
}
|
||||
if err = dm.rplConns.Call("ReplicatorSv1.SetIndexes", th, &reply); err != nil {
|
||||
return
|
||||
}
|
||||
if err = dm.rplConns.Call("ReplicatorSv1.SetThreshold", th, &reply); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -36,10 +36,13 @@ var csvr *TpReader
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
csvr, err = NewTpReader(dm.dataDB, NewStringCSVStorage(',', DestinationsCSVContent, TimingsCSVContent, RatesCSVContent, DestinationRatesCSVContent,
|
||||
RatingPlansCSVContent, RatingProfilesCSVContent, SharedGroupsCSVContent, ActionsCSVContent, ActionPlansCSVContent, ActionTriggersCSVContent,
|
||||
AccountActionsCSVContent, ResourcesCSVContent, StatsCSVContent, ThresholdsCSVContent, FiltersCSVContent, SuppliersCSVContent, AttributesCSVContent,
|
||||
ChargersCSVContent, DispatcherCSVContent, DispatcherHostCSVContent), testTPID, "", nil, nil)
|
||||
csvr, err = NewTpReader(dm.dataDB, NewStringCSVStorage(',',
|
||||
DestinationsCSVContent, TimingsCSVContent, RatesCSVContent, DestinationRatesCSVContent,
|
||||
RatingPlansCSVContent, RatingProfilesCSVContent, SharedGroupsCSVContent,
|
||||
ActionsCSVContent, ActionPlansCSVContent, ActionTriggersCSVContent, AccountActionsCSVContent,
|
||||
ResourcesCSVContent, StatsCSVContent, ThresholdsCSVContent, FiltersCSVContent,
|
||||
SuppliersCSVContent, AttributesCSVContent, ChargersCSVContent, DispatcherCSVContent,
|
||||
DispatcherHostCSVContent), testTPID, "", nil, nil)
|
||||
if err != nil {
|
||||
log.Print("error when creating TpReader:", err)
|
||||
}
|
||||
@@ -103,9 +106,10 @@ func init() {
|
||||
if err := csvr.LoadDispatcherHosts(); err != nil {
|
||||
log.Print("error in LoadDispatcherHosts:", err)
|
||||
}
|
||||
csvr.WriteToDatabase(false, false)
|
||||
if err := csvr.WriteToDatabase(false, false); err != nil {
|
||||
log.Print("error when writing into database", err)
|
||||
}
|
||||
Cache.Clear(nil)
|
||||
//dm.LoadDataDBCache(nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
}
|
||||
|
||||
func TestLoadDestinations(t *testing.T) {
|
||||
|
||||
@@ -817,7 +817,11 @@ const (
|
||||
ReplicatorSv1GetDispatcherProfile = "ReplicatorSv1.GetDispatcherProfile"
|
||||
ReplicatorSv1GetDispatcherHost = "ReplicatorSv1.GetDispatcheHost"
|
||||
ReplicatorSv1GetItemLoadIDs = "ReplicatorSv1.GetItemLoadIDs"
|
||||
ReplicatorSv1GetFilterIndexes = "ReplicatorSv1.GetFilterIndexes"
|
||||
ReplicatorSv1MatchFilterIndex = "ReplicatorSv1.MatchFilterIndex"
|
||||
ReplicatorSv1SetThresholdProfile = "ReplicatorSv1.SetThresholdProfile"
|
||||
ReplicatorSv1SetThreshold = "ReplicatorSv1.SetThreshold"
|
||||
ReplicatorSv1SetFilterIndexes = "ReplicatorSv1.SetFilterIndexes"
|
||||
)
|
||||
|
||||
// ApierV1 APIs
|
||||
|
||||
@@ -995,3 +995,24 @@ func LongExecTimeDetector(logID string, maxDur time.Duration) (endchan chan stru
|
||||
}()
|
||||
return
|
||||
}
|
||||
|
||||
type GetFilterIndexesArg struct {
|
||||
CacheID string
|
||||
ItemIDPrefix string
|
||||
FilterType string
|
||||
FldNameVal map[string]string
|
||||
}
|
||||
|
||||
type MatchFilterIndexArg struct {
|
||||
CacheID string
|
||||
ItemIDPrefix string
|
||||
FilterType string
|
||||
FieldName string
|
||||
FieldVal string
|
||||
}
|
||||
|
||||
type SetFilterIndexesArg struct {
|
||||
CacheID string
|
||||
ItemIDPrefix string
|
||||
Indexes map[string]StringMap
|
||||
}
|
||||
|
||||
@@ -224,4 +224,4 @@ func ErrPathNotReachable(path string) error {
|
||||
|
||||
func ErrNotConvertibleTF(from, to string) error {
|
||||
return fmt.Errorf("%s : from: %s to:%s", ErrNotConvertibleNoCaps.Error(), from, to)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user