diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 3e335ac6d..f5b5bfa4e 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -25,7 +25,6 @@ import ( "path" "strconv" "strings" - "time" "github.com/cgrates/cgrates/cache2go" "github.com/cgrates/cgrates/config" @@ -769,20 +768,6 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach } cs.Users = len(ups) } - if loadHistInsts, err := self.AccountDb.GetLoadHistory(1, false, utils.NonTransactional); err != nil || len(loadHistInsts) == 0 { - if err != nil { // Not really an error here since we only count in cache - utils.Logger.Warning(fmt.Sprintf("ApierV1.GetCacheStats, error on GetLoadHistory: %s", err.Error())) - } - cs.LastLoadID = utils.NOT_AVAILABLE - cs.LastRatingLoadID = utils.NOT_AVAILABLE - cs.LastAccountingLoadID = utils.NOT_AVAILABLE - cs.LastLoadTime = utils.NOT_AVAILABLE - } else { - cs.LastLoadID = loadHistInsts[0].LoadID - cs.LastRatingLoadID = loadHistInsts[0].RatingLoadID - cs.LastAccountingLoadID = loadHistInsts[0].AccountingLoadID - cs.LastLoadTime = loadHistInsts[0].LoadTime.Format(time.RFC3339) - } *reply = *cs return nil } diff --git a/apier/v1/apier_local_test.go b/apier/v1/apier_local_test.go index e44a0e8e9..dbec34152 100644 --- a/apier/v1/apier_local_test.go +++ b/apier/v1/apier_local_test.go @@ -828,7 +828,7 @@ func TestApierGetCacheStats(t *testing.T) { var rcvStats *utils.CacheStats var args utils.AttrCacheStats err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats) - expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 1, RatingProfiles: 0, Actions: 0, ActionPlans: 0, LastLoadID: utils.NOT_AVAILABLE, LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE} + expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 1, RatingProfiles: 0, Actions: 0, ActionPlans: 0} if err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { @@ -1247,7 +1247,7 @@ func TestApierResetDataBeforeLoadFromFolder(t *testing.T) { var rcvStats *utils.CacheStats var args utils.AttrCacheStats err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats) - expectedStats := &utils.CacheStats{LastLoadID: rcvStats.LastLoadID, LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime} + expectedStats := new(utils.CacheStats) if err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(rcvStats, expectedStats) { @@ -1763,7 +1763,7 @@ func TestApierGetCacheStats2(t *testing.T) { var rcvStats *utils.CacheStats var args utils.AttrCacheStats err := rater.Call("ApierV1.GetCacheStats", args, &rcvStats) - expectedStats := &utils.CacheStats{LastLoadID: rcvStats.LastLoadID, LastRatingLoadID: rcvStats.LastRatingLoadID, LastAccountingLoadID: rcvStats.LastAccountingLoadID, LastLoadTime: rcvStats.LastLoadTime} + expectedStats := new(utils.CacheStats) if err != nil { t.Error("Got error on ApierV1.GetCacheStats: ", err.Error()) } else if !reflect.DeepEqual(expectedStats, rcvStats) { diff --git a/apier/v1/smgenericv1_it_test.go b/apier/v1/smgenericv1_it_test.go index eebc2947d..5eed24046 100644 --- a/apier/v1/smgenericv1_it_test.go +++ b/apier/v1/smgenericv1_it_test.go @@ -117,8 +117,7 @@ func TestSMGV1CacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 0, RatingPlans: 4, RatingProfiles: 0, Actions: 7, ActionPlans: 4, SharedGroups: 0, Aliases: 0, ResourceLimits: 0, - DerivedChargers: 0, LcrProfiles: 0, CdrStats: 6, Users: 3, - LastLoadID: utils.NOT_AVAILABLE, LastRatingLoadID: utils.NOT_AVAILABLE, LastAccountingLoadID: utils.NOT_AVAILABLE, LastLoadTime: utils.NOT_AVAILABLE} + DerivedChargers: 0, LcrProfiles: 0, CdrStats: 6, Users: 3} var args utils.AttrCacheStats if err := smgV1Rpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/general_tests/dest_management_it_test.go b/general_tests/dest_management_it_test.go index 797dcdf99..05f31da80 100644 --- a/general_tests/dest_management_it_test.go +++ b/general_tests/dest_management_it_test.go @@ -16,7 +16,6 @@ import ( var destCfgPath string var destCfg *config.CGRConfig var destRPC *rpc.Client -var destLoadInst utils.LoadInstance // Share load information between tests func TestDestManagInitCfg(t *testing.T) { if !*testIntegration { @@ -81,10 +80,9 @@ func TestDestManagLoadTariffPlanFromFolderAll(t *testing.T) { return } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "alldests")} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -113,10 +111,9 @@ func TestDestManagLoadTariffPlanFromFolderRemoveSome(t *testing.T) { return } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome")} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -145,10 +142,9 @@ func TestDestManagLoadTariffPlanFromFolderRemoveSomeFlush(t *testing.T) { return } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "removesome"), FlushDb: true} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -177,10 +173,9 @@ func TestDestManagLoadTariffPlanFromFolderAddBack(t *testing.T) { return } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addback")} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -209,10 +204,9 @@ func TestDestManagLoadTariffPlanFromFolderAddOne(t *testing.T) { return } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "addone")} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } @@ -250,10 +244,9 @@ func TestDestManagCacheWithGetCache(t *testing.T) { t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply) } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -274,8 +267,6 @@ func TestDestManagCacheWithGetCache(t *testing.T) { 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.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -307,10 +298,9 @@ func TestDestManagCacheWithGetCost(t *testing.T) { t.Errorf("Calling ApierV1.ReloadCache received: %+v", reply) } attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "test", "destinations", "cacheall"), FlushDb: true} + var destLoadInst utils.LoadInstance if err := destRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &destLoadInst); err != nil { t.Error(err) - } else if destLoadInst.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups @@ -340,8 +330,6 @@ func TestDestManagCacheWithGetCost(t *testing.T) { 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.RatingLoadID == "" || destLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", destLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups diff --git a/general_tests/suretax_it_test.go b/general_tests/suretax_it_test.go index 391f3f69f..3fc8d5942 100644 --- a/general_tests/suretax_it_test.go +++ b/general_tests/suretax_it_test.go @@ -118,8 +118,7 @@ func TestSTICacheStats(t *testing.T) { return } var rcvStats *utils.CacheStats - expectedStats := &utils.CacheStats{Destinations: 1, RatingPlans: 1, RatingProfiles: 1, DerivedChargers: 1, - LastRatingLoadID: stiLoadInst.RatingLoadID, LastAccountingLoadID: stiLoadInst.AccountingLoadID, LastLoadTime: stiLoadInst.LoadTime.Format(time.RFC3339)} + expectedStats := &utils.CacheStats{Destinations: 1, RatingPlans: 1, RatingProfiles: 1, DerivedChargers: 1} var args utils.AttrCacheStats if err := stiRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/general_tests/tp_it_test.go b/general_tests/tp_it_test.go index dc5ab95e3..ab4eeb9be 100644 --- a/general_tests/tp_it_test.go +++ b/general_tests/tp_it_test.go @@ -84,8 +84,6 @@ func TestTpLoadTariffPlanFromFolder(t *testing.T) { attrs := &utils.AttrLoadTpFromFolder{FolderPath: path.Join(*dataDir, "tariffplans", "testtp")} if err := tpRPC.Call("ApierV2.LoadTariffPlanFromFolder", attrs, &tpLoadInst); err != nil { t.Error(err) - } else if tpLoadInst.RatingLoadID == "" || tpLoadInst.AccountingLoadID == "" { - t.Error("Empty loadId received, loadInstance: ", tpLoadInst) } time.Sleep(time.Duration(*waitRater) * time.Millisecond) // Give time for scheduler to execute topups } diff --git a/general_tests/tut_smgeneric_it_test.go b/general_tests/tut_smgeneric_it_test.go index 1fa300ffd..8ed99f2f9 100644 --- a/general_tests/tut_smgeneric_it_test.go +++ b/general_tests/tut_smgeneric_it_test.go @@ -115,7 +115,7 @@ func TestTutSMGCacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, ResourceLimits: 0, - DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastLoadID: "LoadTariffPlanFromFolderAPI", LastRatingLoadID: smgLoadInst.RatingLoadID, LastAccountingLoadID: smgLoadInst.AccountingLoadID, LastLoadTime: smgLoadInst.LoadTime.Format(time.RFC3339)} + DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3} var args utils.AttrCacheStats if err := tutSMGRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/general_tests/tutorial_local_test.go b/general_tests/tutorial_local_test.go index f10838c5d..4e5616f90 100644 --- a/general_tests/tutorial_local_test.go +++ b/general_tests/tutorial_local_test.go @@ -116,7 +116,7 @@ func TestTutLocalCacheStats(t *testing.T) { var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 7, RatingPlans: 4, RatingProfiles: 9, Actions: 8, ActionPlans: 4, SharedGroups: 1, Aliases: 1, ResourceLimits: 0, - DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3, LastLoadID: "LoadTariffPlanFromFolderAPI", LastRatingLoadID: loadInst.RatingLoadID, LastAccountingLoadID: loadInst.AccountingLoadID, LastLoadTime: loadInst.LoadTime.Format(time.RFC3339)} + DerivedChargers: 1, LcrProfiles: 5, CdrStats: 6, Users: 3} var args utils.AttrCacheStats if err := tutLocalRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) @@ -1102,7 +1102,7 @@ func TestTutLocalLeastCost(t *testing.T) { } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { t.Errorf("Expecting: %+v, received: %+v", eStLcr.Entry, lcr.Entry) } else if !reflect.DeepEqual(eStLcr.SupplierCosts, lcr.SupplierCosts) { - t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts[2], lcr.SupplierCosts[2]) + t.Errorf("Expecting: %+v, received: %+v", eStLcr.SupplierCosts, lcr.SupplierCosts) } cd = engine.CallDescriptor{ Direction: "*out", diff --git a/utils/apitpdata.go b/utils/apitpdata.go index bb46db6e8..0b039023c 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -578,24 +578,20 @@ type AttrCacheStats struct { // Add in the future filters here maybe so we avoid } type CacheStats struct { - Destinations int - ReverseDestinations int - RatingPlans int - RatingProfiles int - Actions int - ActionPlans int - SharedGroups int - DerivedChargers int - LcrProfiles int - CdrStats int - Users int - Aliases int - ReverseAliases int - ResourceLimits int - LastLoadID string - LastRatingLoadID string - LastAccountingLoadID string - LastLoadTime string + Destinations int + ReverseDestinations int + RatingPlans int + RatingProfiles int + Actions int + ActionPlans int + SharedGroups int + DerivedChargers int + LcrProfiles int + CdrStats int + Users int + Aliases int + ReverseAliases int + ResourceLimits int } type AttrExpFileCdrs struct {