diff --git a/apier/v1/resourcesv1.go b/apier/v1/resourcesv1.go index 082bda9f8..8a3eb783b 100644 --- a/apier/v1/resourcesv1.go +++ b/apier/v1/resourcesv1.go @@ -86,8 +86,11 @@ func (apierV1 *ApierV1) GetResourceProfile(arg utils.TenantID, reply *engine.Res } // GetResourceProfileIDs returns list of resourceProfile IDs registered for a tenant -func (apierV1 *ApierV1) GetResourceProfileIDs(tenant string, rsPrfIDs *[]string) error { - prfx := utils.ResourceProfilesPrefix + tenant + ":" +func (apierV1 *ApierV1) GetResourceProfileIDs(args utils.TenantArgWithPaginator, rsPrfIDs *[]string) error { + if missing := utils.MissingStructFields(&args, []string{utils.Tenant}); len(missing) != 0 { //Params missing + return utils.NewErrMandatoryIeMissing(missing...) + } + prfx := utils.ResourceProfilesPrefix + args.Tenant + ":" keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx) if err != nil { return err @@ -99,7 +102,7 @@ func (apierV1 *ApierV1) GetResourceProfileIDs(tenant string, rsPrfIDs *[]string) for i, key := range keys { retIDs[i] = key[len(prfx):] } - *rsPrfIDs = retIDs + *rsPrfIDs = args.PaginateStringSlice(retIDs) return nil } diff --git a/apier/v1/resourcesv1_it_test.go b/apier/v1/resourcesv1_it_test.go index 2bac5045f..fbddbb3c5 100644 --- a/apier/v1/resourcesv1_it_test.go +++ b/apier/v1/resourcesv1_it_test.go @@ -650,7 +650,7 @@ func testV1RsSetResourceProfile(t *testing.T) { func testV1RsGetResourceProfileIDs(t *testing.T) { expected := []string{"ResGroup2", "ResGroup1", "ResGroup3", "RES_GR_TEST"} var result []string - if err := rlsV1Rpc.Call("ApierV1.GetResourceProfileIDs", "cgrates.org", &result); err != nil { + if err := rlsV1Rpc.Call(utils.ApierV1GetResourceProfileIDs, utils.TenantArgWithPaginator{TenantArg: utils.TenantArg{Tenant: "cgrates.org"}}, &result); err != nil { t.Error(err) } else if len(expected) != len(result) { t.Errorf("Expecting : %+v, received: %+v", expected, result) diff --git a/console/resource.go b/console/resource.go index 3fec3c6d2..1e82fdbad 100644 --- a/console/resource.go +++ b/console/resource.go @@ -26,7 +26,7 @@ import ( func init() { c := &CmdGetResource{ name: "resource", - rpcMethod: "ApierV1.GetResourceProfile", + rpcMethod: utils.ApierV1GetResourceProfile, rpcParams: &utils.TenantID{}, } commands[c.Name()] = c diff --git a/console/resource_ids.go b/console/resource_ids.go new file mode 100644 index 000000000..2cbd7763b --- /dev/null +++ b/console/resource_ids.go @@ -0,0 +1,65 @@ +/* +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 +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetResourceIDs{ + name: "resource_ids", + rpcMethod: utils.ApierV1GetResourceProfileIDs, + rpcParams: &utils.TenantArgWithPaginator{}, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetResourceIDs struct { + name string + rpcMethod string + rpcParams *utils.TenantArgWithPaginator + *CommandExecuter +} + +func (self *CmdGetResourceIDs) Name() string { + return self.name +} + +func (self *CmdGetResourceIDs) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetResourceIDs) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &utils.TenantArgWithPaginator{} + } + return self.rpcParams +} + +func (self *CmdGetResourceIDs) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetResourceIDs) RpcResult() interface{} { + atr := []string{} + return &atr +} diff --git a/console/resource_remove.go b/console/resource_remove.go index 056f56c24..f2067b5e2 100644 --- a/console/resource_remove.go +++ b/console/resource_remove.go @@ -23,7 +23,7 @@ import "github.com/cgrates/cgrates/utils" func init() { c := &CmdRemoveResource{ name: "resource_remove", - rpcMethod: "ApierV1.RemoveResourceProfile", + rpcMethod: utils.ApierV1RemoveResourceProfile, rpcParams: &utils.TenantIDWithCache{}, } commands[c.Name()] = c diff --git a/console/resource_set.go b/console/resource_set.go index d890ff0ec..94e730b76 100644 --- a/console/resource_set.go +++ b/console/resource_set.go @@ -18,12 +18,15 @@ along with this program. If not, see 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 := &CmdSetResource{ name: "resource_set", - rpcMethod: "ApierV1.SetResourceProfile", + rpcMethod: utils.ApierV1SetResourceProfile, rpcParams: &v1.ResourceWithCache{}, } commands[c.Name()] = c diff --git a/utils/consts.go b/utils/consts.go index 038e84d56..eef36ae09 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -805,6 +805,10 @@ const ( ResourceSv1AllocateResources = "ResourceSv1.AllocateResources" ResourceSv1ReleaseResources = "ResourceSv1.ReleaseResources" ResourceSv1Ping = "ResourceSv1.Ping" + ApierV1SetResourceProfile = "ApierV1.SetResourceProfile" + ApierV1RemoveResourceProfile = "ApierV1.RemoveResourceProfile" + ApierV1GetResourceProfile = "ApierV1.GetResourceProfile" + ApierV1GetResourceProfileIDs = "ApierV1.GetResourceProfileIDs" ) // SessionS APIs