Updated GetThresholdProfileIDs

This commit is contained in:
Tripon Alexandru-Ionut
2019-04-17 18:22:30 +03:00
committed by Dan Christian Bogos
parent 315b8048e8
commit 23ba89294a
7 changed files with 82 additions and 8 deletions

View File

@@ -74,8 +74,11 @@ func (apierV1 *ApierV1) GetThresholdProfile(arg *utils.TenantID, reply *engine.T
}
// GetThresholdProfileIDs returns list of thresholdProfile IDs registered for a tenant
func (apierV1 *ApierV1) GetThresholdProfileIDs(tenant string, thPrfIDs *[]string) error {
prfx := utils.ThresholdProfilePrefix + tenant + ":"
func (apierV1 *ApierV1) GetThresholdProfileIDs(args utils.TenantArgWithPaginator, thPrfIDs *[]string) error {
if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing
return utils.NewErrMandatoryIeMissing(missing...)
}
prfx := utils.ThresholdProfilePrefix + args.Tenant + ":"
keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx)
if err != nil {
return err
@@ -87,7 +90,7 @@ func (apierV1 *ApierV1) GetThresholdProfileIDs(tenant string, thPrfIDs *[]string
for i, key := range keys {
retIDs[i] = key[len(prfx):]
}
*thPrfIDs = retIDs
*thPrfIDs = args.PaginateStringSlice(retIDs)
return nil
}

View File

@@ -339,7 +339,7 @@ func testV1TSGetThresholdsAfterRestart(t *testing.T) {
func testv1TSGetThresholdProfileIDs(t *testing.T) {
expected := []string{"THD_STATS_1", "THD_STATS_2", "THD_STATS_3", "THD_RES_1", "THD_CDRS_1", "THD_ACNT_BALANCE_1", "THD_ACNT_EXPIRED"}
var result []string
if err := tSv1Rpc.Call("ApierV1.GetThresholdProfileIDs", "cgrates.org", &result); err != nil {
if err := tSv1Rpc.Call(utils.ApierV1GetThresholdProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{"cgrates.org"}}, &result); err != nil {
t.Error(err)
} else if len(expected) != len(result) {
t.Errorf("Expecting : %+v, received: %+v", expected, result)

View File

@@ -26,7 +26,7 @@ import (
func init() {
c := &CmdGetThreshold{
name: "threshold",
rpcMethod: "ApierV1.GetThresholdProfile",
rpcMethod: utils.ApierV1GetThresholdProfile,
rpcParams: &utils.TenantIDWithArgDispatcher{},
}
commands[c.Name()] = c

64
console/threshold_ids.go Normal file
View File

@@ -0,0 +1,64 @@
/*
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
Copyright (C) ITsysCOM GmbH
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package console
import (
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdGetThresholdIDs{
name: "threshold_ids",
rpcMethod: utils.ApierV1GetThresholdProfileIDs,
rpcParams: &utils.TenantArgWithPaginator{},
}
commands[c.Name()] = c
c.CommandExecuter = &CommandExecuter{c}
}
type CmdGetThresholdIDs struct {
name string
rpcMethod string
rpcParams *utils.TenantArgWithPaginator
*CommandExecuter
}
func (self *CmdGetThresholdIDs) Name() string {
return self.name
}
func (self *CmdGetThresholdIDs) RpcMethod() string {
return self.rpcMethod
}
func (self *CmdGetThresholdIDs) RpcParams(reset bool) interface{} {
if reset || self.rpcParams == nil {
self.rpcParams = &utils.TenantArgWithPaginator{}
}
return self.rpcParams
}
func (self *CmdGetThresholdIDs) PostprocessRpcParams() error {
return nil
}
func (self *CmdGetThresholdIDs) RpcResult() interface{} {
atr := []string{}
return &atr
}

View File

@@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils"
func init() {
c := &CmdRemoveThreshold{
name: "threshold_remove",
rpcMethod: "ApierV1.RemoveThresholdProfile",
rpcMethod: utils.ApierV1RemoveThresholdProfile,
rpcParams: &utils.TenantIDWithCache{},
}
commands[c.Name()] = c

View File

@@ -18,12 +18,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package console
import v1 "github.com/cgrates/cgrates/apier/v1"
import (
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/utils"
)
func init() {
c := &CmdSetThreshold{
name: "threshold_set",
rpcMethod: "ApierV1.SetThresholdProfile",
rpcMethod: utils.ApierV1SetThresholdProfile,
rpcParams: &v1.ThresholdWithCache{},
}
commands[c.Name()] = c

View File

@@ -790,6 +790,10 @@ const (
ThresholdSv1GetThresholdIDs = "ThresholdSv1.GetThresholdIDs"
ThresholdSv1Ping = "ThresholdSv1.Ping"
ThresholdSv1GetThresholdsForEvent = "ThresholdSv1.GetThresholdsForEvent"
ApierV1GetThresholdProfileIDs = "ApierV1.GetThresholdProfileIDs"
ApierV1GetThresholdProfile = "ApierV1.GetThresholdProfile"
ApierV1RemoveThresholdProfile = "ApierV1.RemoveThresholdProfile"
ApierV1SetThresholdProfile = "ApierV1.SetThresholdProfile"
)
// StatS APIs