diff --git a/apier/v1/apier.go b/apier/v1/apier.go index b72335757..464614381 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -722,7 +722,7 @@ func (self *ApierV1) ReloadScheduler(input string, reply *string) error { return nil } -func (self *ApierV1) ReloadCache(attrs utils.ApiReloadCache, reply *string) error { +func (self *ApierV1) ReloadCache(attrs utils.AttrReloadCache, reply *string) error { var dstKeys, rpKeys, rpfKeys, actKeys, aplKeys, shgKeys, lcrKeys, dcsKeys, alsKeys []string if len(attrs.DestinationIds) > 0 { dstKeys = make([]string, len(attrs.DestinationIds)) diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 3ac60d57c..409918918 100644 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -374,7 +374,7 @@ func main() { if *flush { dstIds, rplIds, rpfIds, lcrIds = nil, nil, nil, nil // Should reload all these on flush } - if err = rater.Call("ApierV1.ReloadCache", utils.ApiReloadCache{ + if err = rater.Call("ApierV1.ReloadCache", utils.AttrReloadCache{ DestinationIds: dstIds, RatingPlanIds: rplIds, RatingProfileIds: rpfIds, diff --git a/console/cache_reload.go b/console/cache_reload.go index 14547be0f..6cb8b838f 100644 --- a/console/cache_reload.go +++ b/console/cache_reload.go @@ -33,7 +33,7 @@ func init() { type CmdReloadCache struct { name string rpcMethod string - rpcParams *utils.ApiReloadCache + rpcParams *utils.AttrReloadCache rpcResult string *CommandExecuter } @@ -48,7 +48,7 @@ func (self *CmdReloadCache) RpcMethod() string { func (self *CmdReloadCache) RpcParams(reset bool) interface{} { if reset || self.rpcParams == nil { - self.rpcParams = &utils.ApiReloadCache{} + self.rpcParams = &utils.AttrReloadCache{} } return self.rpcParams } diff --git a/data/tariffplans/test/destinations/cacheall/DestinationRates.csv b/data/tariffplans/test/destinations/cacheall/DestinationRates.csv new file mode 100644 index 000000000..fd1eb6c7a --- /dev/null +++ b/data/tariffplans/test/destinations/cacheall/DestinationRates.csv @@ -0,0 +1 @@ +DR_100x,DST_100x,R_100x,*up,4,0, diff --git a/data/tariffplans/test/destinations/cacheall/Destinations.csv b/data/tariffplans/test/destinations/cacheall/Destinations.csv new file mode 100644 index 000000000..fb72bddbf --- /dev/null +++ b/data/tariffplans/test/destinations/cacheall/Destinations.csv @@ -0,0 +1,2 @@ +DST_100x,1001 +DST_100x,1002 \ No newline at end of file diff --git a/data/tariffplans/test/destinations/cacheall/Rates.csv b/data/tariffplans/test/destinations/cacheall/Rates.csv new file mode 100644 index 000000000..4dd524064 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheall/Rates.csv @@ -0,0 +1 @@ +R_100x,0,10,60s,1s,0s diff --git a/data/tariffplans/test/destinations/cacheall/RatingPlans.csv b/data/tariffplans/test/destinations/cacheall/RatingPlans.csv new file mode 100644 index 000000000..e0047fef0 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheall/RatingPlans.csv @@ -0,0 +1 @@ +RPL_100x,DR_100x,always,10 diff --git a/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv b/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv new file mode 100644 index 000000000..63587a0a8 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheall/RatingProfiles.csv @@ -0,0 +1 @@ +*out,cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x,, diff --git a/data/tariffplans/test/destinations/cacheall/Timings.csv b/data/tariffplans/test/destinations/cacheall/Timings.csv new file mode 100644 index 000000000..671732122 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheall/Timings.csv @@ -0,0 +1 @@ +always,*any,*any,*any,*any,00:00:00 diff --git a/data/tariffplans/test/destinations/cacheone/DestinationRates.csv b/data/tariffplans/test/destinations/cacheone/DestinationRates.csv new file mode 100644 index 000000000..fd1eb6c7a --- /dev/null +++ b/data/tariffplans/test/destinations/cacheone/DestinationRates.csv @@ -0,0 +1 @@ +DR_100x,DST_100x,R_100x,*up,4,0, diff --git a/data/tariffplans/test/destinations/cacheone/Destinations.csv b/data/tariffplans/test/destinations/cacheone/Destinations.csv new file mode 100644 index 000000000..5ac310bdc --- /dev/null +++ b/data/tariffplans/test/destinations/cacheone/Destinations.csv @@ -0,0 +1 @@ +DST_100x,1001 diff --git a/data/tariffplans/test/destinations/cacheone/Rates.csv b/data/tariffplans/test/destinations/cacheone/Rates.csv new file mode 100644 index 000000000..4dd524064 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheone/Rates.csv @@ -0,0 +1 @@ +R_100x,0,10,60s,1s,0s diff --git a/data/tariffplans/test/destinations/cacheone/RatingPlans.csv b/data/tariffplans/test/destinations/cacheone/RatingPlans.csv new file mode 100644 index 000000000..e0047fef0 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheone/RatingPlans.csv @@ -0,0 +1 @@ +RPL_100x,DR_100x,always,10 diff --git a/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv b/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv new file mode 100644 index 000000000..63587a0a8 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheone/RatingProfiles.csv @@ -0,0 +1 @@ +*out,cgrates.org,call,test,2014-01-14T00:00:00Z,RPL_100x,, diff --git a/data/tariffplans/test/destinations/cacheone/Timings.csv b/data/tariffplans/test/destinations/cacheone/Timings.csv new file mode 100644 index 000000000..671732122 --- /dev/null +++ b/data/tariffplans/test/destinations/cacheone/Timings.csv @@ -0,0 +1 @@ +always,*any,*any,*any,*any,00:00:00 diff --git a/data/tariffplans/test/destinations/removesome/Destinations.csv b/data/tariffplans/test/destinations/removesome/Destinations.csv index 15d102471..3d333a794 100644 --- a/data/tariffplans/test/destinations/removesome/Destinations.csv +++ b/data/tariffplans/test/destinations/removesome/Destinations.csv @@ -4,5 +4,4 @@ GERMANY_MOBILE,+4915 GERMANY_MOBILE,+4916 GERMANY_MOBILE,+4917 DATA_DEST,222 -EUROPE,+40 EUROPE,+49 diff --git a/general_tests/dest_management_it_test.go b/general_tests/dest_management_it_test.go index fe7ad30f4..c895241a7 100644 --- a/general_tests/dest_management_it_test.go +++ b/general_tests/dest_management_it_test.go @@ -140,6 +140,38 @@ func TestDestManagRemoveSomeDestinationLoaded(t *testing.T) { } } +func TestDestManagLoadTariffPlanFromFolderRemoveSomeFlush(t *testing.T) { + if !*testIntegration { + return + } + attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome"), FlushDb: true} + if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { + t.Error(err) + } else if destLoadInst.LoadId == "" { + t.Error("Empty loadId received, loadInstance: ", destLoadInst) + } + time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups +} + +func TestDestManagRemoveSomeFlushDestinationLoaded(t *testing.T) { + if !*testIntegration { + return + } + dests := make([]*engine.Destination, 0) + if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + t.Error("Got error on ApierV2.GetDestinations: ", err.Error()) + } else if len(dests) != 4 { + t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests)) + } + + var rcvStats utils.CacheStats + if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil { + t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) + } else if rcvStats.Destinations != 5 { + t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats) + } +} + func TestDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) { if !*testIntegration { return @@ -203,3 +235,124 @@ func TestDestManagAddOneDestinationLoaded(t *testing.T) { t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats) } } + +func TestDestManagCacheWithGetCache(t *testing.T) { + if !*testIntegration { + return + } + if err := engine.InitDataDb(destCfg); err != nil { + t.Fatal(err) + } + var reply string + if err := destRPC.Call("ApierV1.ReloadCache", utils.AttrReloadCache{}, &reply); err != nil { + t.Error("Got error on ApierV1.ReloadCache: ", err.Error()) + } else if reply != utils.OK { + t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply) + } + attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true} + if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { + t.Error(err) + } else if destLoadInst.LoadId == "" { + t.Error("Empty loadId received, loadInstance: ", destLoadInst) + } + time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups + + dests := make([]*engine.Destination, 0) + if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + t.Error("Got error on ApierV2.GetDestinations: ", err.Error()) + } else if len(dests) != 1 { + t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests)) + } + + var rcvStats utils.CacheStats + if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil { + t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) + } else if rcvStats.Destinations != 2 { + t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats) + } + + attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true} + if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { + t.Error(err) + } else if destLoadInst.LoadId == "" { + t.Error("Empty loadId received, loadInstance: ", destLoadInst) + } + time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups + + dests = make([]*engine.Destination, 0) + if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + t.Error("Got error on ApierV2.GetDestinations: ", err.Error()) + } else if len(dests) != 1 { + t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests)) + } + + if err := destRPC.Call("ApierV1.GetCacheStats", utils.AttrCacheStats{}, &rcvStats); err != nil { + t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) + } else if rcvStats.Destinations != 1 { + t.Errorf("Calling ApierV1.GetCacheStats received: %+v", rcvStats) + } +} + +func TestDestManagCacheWithGetCost(t *testing.T) { + if !*testIntegration { + return + } + if err := engine.InitDataDb(destCfg); err != nil { + t.Fatal(err) + } + var reply string + if err := destRPC.Call("ApierV1.ReloadCache", utils.AttrReloadCache{}, &reply); err != nil { + t.Error("Got error on ApierV1.ReloadCache: ", err.Error()) + } else if reply != utils.OK { + t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply) + } + attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true} + if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { + t.Error(err) + } else if destLoadInst.LoadId == "" { + t.Error("Empty loadId received, loadInstance: ", destLoadInst) + } + time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups + + dests := make([]*engine.Destination, 0) + if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + t.Error("Got error on ApierV2.GetDestinations: ", err.Error()) + } else if len(dests) != 1 { + t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests)) + } + + var cc engine.CallCost + cd := &engine.CallDescriptor{ + Direction: "*out", + Tenant: "cgrates.org", + Category: "call", + Account: "test", + Destination: "1002", + TimeStart: time.Date(2016, 2, 24, 0, 0, 0, 0, time.UTC), + TimeEnd: time.Date(2016, 2, 24, 0, 0, 10, 0, time.UTC), + } + if err := destRPC.Call("Responder.GetCost", cd, &cc); err != nil { + t.Error(err) + } else if cc.Cost != 1.6667 { + t.Error("Empty loadId received, loadInstance: ", utils.ToIJSON(cc)) + } + + attrs = &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheone"), FlushDb: true} + if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { + t.Error(err) + } else if destLoadInst.LoadId == "" { + t.Error("Empty loadId received, loadInstance: ", destLoadInst) + } + time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups + + dests = make([]*engine.Destination, 0) + if err := destRPC.Call("ApierV2.GetDestinations", v2.AttrGetDestinations{DestinationIDs: []string{}}, &dests); err != nil { + t.Error("Got error on ApierV2.GetDestinations: ", err.Error()) + } else if len(dests) != 1 { + t.Errorf("Calling ApierV2.GetDestinations got reply: %v", utils.ToIJSON(dests)) + } + + if err := destRPC.Call("Responder.GetCost", cd, &cc); err.Error() != utils.ErrUnauthorizedDestination.Error() { + t.Error(err) + } +} diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 80b428e9a..18bbf5c23 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -560,7 +560,7 @@ type AttrGetAccounts struct { } // Data used to do remote cache reloads via api -type ApiReloadCache struct { +type AttrReloadCache struct { DestinationIds []string RatingPlanIds []string RatingProfileIds []string