From 64b5c62c490f3289b31443369aedb85e5bb7972e Mon Sep 17 00:00:00 2001 From: Tripon Alexandru-Ionut Date: Tue, 9 Apr 2019 15:39:45 +0300 Subject: [PATCH] Added set/get/remove dispatcher hosts and profiles to console --- apier/v1/dispatcher.go | 12 +++++- apier/v1/dispatcher_it_test.go | 2 +- console/dispatcherhost.go | 65 +++++++++++++++++++++++++++++ console/dispatcherhost_ids.go | 64 ++++++++++++++++++++++++++++ console/dispatcherhost_remove.go | 64 ++++++++++++++++++++++++++++ console/dispatcherhost_set.go | 65 +++++++++++++++++++++++++++++ console/dispatcherprofile.go | 65 +++++++++++++++++++++++++++++ console/dispatcherprofile_ids.go | 64 ++++++++++++++++++++++++++++ console/dispatcherprofile_remove.go | 64 ++++++++++++++++++++++++++++ console/dispatcherprofile_set.go | 65 +++++++++++++++++++++++++++++ utils/consts.go | 5 +++ 11 files changed, 532 insertions(+), 3 deletions(-) create mode 100644 console/dispatcherhost.go create mode 100644 console/dispatcherhost_ids.go create mode 100644 console/dispatcherhost_remove.go create mode 100644 console/dispatcherhost_set.go create mode 100644 console/dispatcherprofile.go create mode 100644 console/dispatcherprofile_ids.go create mode 100644 console/dispatcherprofile_remove.go create mode 100644 console/dispatcherprofile_set.go diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go index bb2d9cdb7..556c62b6d 100755 --- a/apier/v1/dispatcher.go +++ b/apier/v1/dispatcher.go @@ -42,7 +42,11 @@ func (apierV1 *ApierV1) GetDispatcherProfile(arg *utils.TenantID, reply *engine. } // GetDispatcherProfileIDs returns list of dispatcherProfile IDs registered for a tenant -func (apierV1 *ApierV1) GetDispatcherProfileIDs(tenant string, dPrfIDs *[]string) error { +func (apierV1 *ApierV1) GetDispatcherProfileIDs(tenantArg *utils.TenantArg, dPrfIDs *[]string) error { + if tenantArg.Tenant == "" { + return utils.NewErrMandatoryIeMissing(utils.Tenant) + } + tenant := tenantArg.Tenant prfx := utils.DispatcherProfilePrefix + tenant + ":" keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx) if err != nil { @@ -127,7 +131,11 @@ func (apierV1 *ApierV1) GetDispatcherHost(arg *utils.TenantID, reply *engine.Dis } // GetDispatcherHostIDs returns list of dispatcherHost IDs registered for a tenant -func (apierV1 *ApierV1) GetDispatcherHostIDs(tenant string, dPrfIDs *[]string) error { +func (apierV1 *ApierV1) GetDispatcherHostIDs(tenantArg *utils.TenantArg, dPrfIDs *[]string) error { + if tenantArg.Tenant == "" { + return utils.NewErrMandatoryIeMissing(utils.Tenant) + } + tenant := tenantArg.Tenant prfx := utils.DispatcherHostPrefix + tenant + ":" keys, err := apierV1.DataManager.DataDB().GetKeysForPrefix(prfx) if err != nil { diff --git a/apier/v1/dispatcher_it_test.go b/apier/v1/dispatcher_it_test.go index ab26ebfea..abad7c287 100644 --- a/apier/v1/dispatcher_it_test.go +++ b/apier/v1/dispatcher_it_test.go @@ -150,7 +150,7 @@ func testDispatcherSGetDispatcherProfileIDs(t *testing.T) { var result []string expected := []string{"Dsp1"} if err := dispatcherRPC.Call("ApierV1.GetDispatcherProfileIDs", - dispatcherProfile.Tenant, &result); err != nil { + utils.TenantArg{Tenant: dispatcherProfile.Tenant}, &result); err != nil { t.Error(err) } else if len(result) != len(expected) { t.Errorf("Expecting : %+v, received: %+v", expected, result) diff --git a/console/dispatcherhost.go b/console/dispatcherhost.go new file mode 100644 index 000000000..e48153525 --- /dev/null +++ b/console/dispatcherhost.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/engine" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetDispatcherHost{ + name: "dispatcherhost", + rpcMethod: utils.ApierV1GetDispatcherHost, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetDispatcherHost struct { + name string + rpcMethod string + rpcParams *utils.TenantID + *CommandExecuter +} + +func (self *CmdGetDispatcherHost) Name() string { + return self.name +} + +func (self *CmdGetDispatcherHost) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetDispatcherHost) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantID) + } + return self.rpcParams +} + +func (self *CmdGetDispatcherHost) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetDispatcherHost) RpcResult() interface{} { + var s engine.DispatcherHost + return &s +} diff --git a/console/dispatcherhost_ids.go b/console/dispatcherhost_ids.go new file mode 100644 index 000000000..e8103c2b1 --- /dev/null +++ b/console/dispatcherhost_ids.go @@ -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 +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetDispatcherHostIDs{ + name: "dispatcherhost_ids", + rpcMethod: utils.ApierV1GetDispatcherHostIDs, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetDispatcherHostIDs struct { + name string + rpcMethod string + rpcParams *utils.TenantArg + *CommandExecuter +} + +func (self *CmdGetDispatcherHostIDs) Name() string { + return self.name +} + +func (self *CmdGetDispatcherHostIDs) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetDispatcherHostIDs) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantArg) + } + return self.rpcParams +} + +func (self *CmdGetDispatcherHostIDs) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetDispatcherHostIDs) RpcResult() interface{} { + var s []string + return &s +} diff --git a/console/dispatcherhost_remove.go b/console/dispatcherhost_remove.go new file mode 100644 index 000000000..c95975c95 --- /dev/null +++ b/console/dispatcherhost_remove.go @@ -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 +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdRemoveDispatcherHost{ + name: "dispatcherhost_remove", + rpcMethod: utils.ApierV1RemoveDispatcherHost, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdRemoveDispatcherHost struct { + name string + rpcMethod string + rpcParams *utils.TenantIDWrapper + *CommandExecuter +} + +func (self *CmdRemoveDispatcherHost) Name() string { + return self.name +} + +func (self *CmdRemoveDispatcherHost) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdRemoveDispatcherHost) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantIDWrapper) + } + return self.rpcParams +} + +func (self *CmdRemoveDispatcherHost) PostprocessRpcParams() error { + return nil +} + +func (self *CmdRemoveDispatcherHost) RpcResult() interface{} { + var s string + return &s +} diff --git a/console/dispatcherhost_set.go b/console/dispatcherhost_set.go new file mode 100644 index 000000000..739e5980c --- /dev/null +++ b/console/dispatcherhost_set.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 ( + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdSetDispatcherHost{ + name: "dispatcherhost_set", + rpcMethod: utils.ApierV1SetDispatcherHost, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdSetDispatcherHost struct { + name string + rpcMethod string + rpcParams *v1.DispatcherHostWrapper + *CommandExecuter +} + +func (self *CmdSetDispatcherHost) Name() string { + return self.name +} + +func (self *CmdSetDispatcherHost) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdSetDispatcherHost) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(v1.DispatcherHostWrapper) + } + return self.rpcParams +} + +func (self *CmdSetDispatcherHost) PostprocessRpcParams() error { + return nil +} + +func (self *CmdSetDispatcherHost) RpcResult() interface{} { + var s string + return &s +} diff --git a/console/dispatcherprofile.go b/console/dispatcherprofile.go new file mode 100644 index 000000000..9d7a82233 --- /dev/null +++ b/console/dispatcherprofile.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/engine" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetDispatcherProfile{ + name: "dispatcherprofile", + rpcMethod: utils.ApierV1GetDispatcherProfile, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetDispatcherProfile struct { + name string + rpcMethod string + rpcParams *utils.TenantID + *CommandExecuter +} + +func (self *CmdGetDispatcherProfile) Name() string { + return self.name +} + +func (self *CmdGetDispatcherProfile) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetDispatcherProfile) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantID) + } + return self.rpcParams +} + +func (self *CmdGetDispatcherProfile) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetDispatcherProfile) RpcResult() interface{} { + var s engine.DispatcherProfile + return &s +} diff --git a/console/dispatcherprofile_ids.go b/console/dispatcherprofile_ids.go new file mode 100644 index 000000000..da3153ec1 --- /dev/null +++ b/console/dispatcherprofile_ids.go @@ -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 +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdGetDispatcherProfileIDs{ + name: "dispatcherprofile_ids", + rpcMethod: utils.ApierV1GetDispatcherProfileIDs, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetDispatcherProfileIDs struct { + name string + rpcMethod string + rpcParams *utils.TenantArg + *CommandExecuter +} + +func (self *CmdGetDispatcherProfileIDs) Name() string { + return self.name +} + +func (self *CmdGetDispatcherProfileIDs) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetDispatcherProfileIDs) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantArg) + } + return self.rpcParams +} + +func (self *CmdGetDispatcherProfileIDs) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetDispatcherProfileIDs) RpcResult() interface{} { + var s []string + return &s +} diff --git a/console/dispatcherprofile_remove.go b/console/dispatcherprofile_remove.go new file mode 100644 index 000000000..7d7d8c569 --- /dev/null +++ b/console/dispatcherprofile_remove.go @@ -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 +*/ + +package console + +import ( + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdRemoveDispatcherProfile{ + name: "dispatcherprofile_remove", + rpcMethod: utils.ApierV1RemoveDispatcherProfile, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdRemoveDispatcherProfile struct { + name string + rpcMethod string + rpcParams *utils.TenantIDWrapper + *CommandExecuter +} + +func (self *CmdRemoveDispatcherProfile) Name() string { + return self.name +} + +func (self *CmdRemoveDispatcherProfile) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdRemoveDispatcherProfile) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(utils.TenantIDWrapper) + } + return self.rpcParams +} + +func (self *CmdRemoveDispatcherProfile) PostprocessRpcParams() error { + return nil +} + +func (self *CmdRemoveDispatcherProfile) RpcResult() interface{} { + var s string + return &s +} diff --git a/console/dispatcherprofile_set.go b/console/dispatcherprofile_set.go new file mode 100644 index 000000000..d2815594d --- /dev/null +++ b/console/dispatcherprofile_set.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 ( + v1 "github.com/cgrates/cgrates/apier/v1" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdSetDispatcherProfile{ + name: "dispatcherprofile_set", + rpcMethod: utils.ApierV1SetDispatcherProfile, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdSetDispatcherProfile struct { + name string + rpcMethod string + rpcParams *v1.DispatcherWithCache + *CommandExecuter +} + +func (self *CmdSetDispatcherProfile) Name() string { + return self.name +} + +func (self *CmdSetDispatcherProfile) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdSetDispatcherProfile) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = new(v1.DispatcherWithCache) + } + return self.rpcParams +} + +func (self *CmdSetDispatcherProfile) PostprocessRpcParams() error { + return nil +} + +func (self *CmdSetDispatcherProfile) RpcResult() interface{} { + var s string + return &s +} diff --git a/utils/consts.go b/utils/consts.go index 251114af3..bc8d4c5f1 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -708,7 +708,12 @@ const ( ApierV1Ping = "ApierV1.Ping" ApierV1SetDispatcherProfile = "ApierV1.SetDispatcherProfile" ApierV1GetDispatcherProfile = "ApierV1.GetDispatcherProfile" + ApierV1GetDispatcherProfileIDs = "ApierV1.GetDispatcherProfileIDs" ApierV1RemoveDispatcherProfile = "ApierV1.RemoveDispatcherProfile" + ApierV1SetDispatcherHost = "ApierV1.SetDispatcherHost" + ApierV1GetDispatcherHost = "ApierV1.GetDispatcherHost" + ApierV1GetDispatcherHostIDs = "ApierV1.GetDispatcherHostIDs" + ApierV1RemoveDispatcherHost = "ApierV1.RemoveDispatcherHost" ApierV1GetResource = "ApierV1.GetResource" ApierV1GetEventCost = "ApierV1.GetEventCost" ApierV1LoadTariffPlanFromFolder = "ApierV1.LoadTariffPlanFromFolder"