From 2fb2e0d506d268606c504f1c1c5d7d3e18007baf Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 16 Jul 2015 15:13:46 +0300 Subject: [PATCH] fixed local tests and added two new console cmds --- apier/v1/apier.go | 9 +--- apier/v1/apier_local_test.go | 2 +- apier/v1/cdrsv1.go | 4 +- console/import_tp_from_folder.go | 63 ++++++++++++++++++++++++++++ console/maxusage.go | 67 ++++++++++++++++++++++++++++++ data/conf/samples/apier/apier.json | 8 +++- engine/storage_csv.go | 4 +- engine/users.go | 4 +- utils/apitpdata.go | 7 ++++ 9 files changed, 155 insertions(+), 13 deletions(-) create mode 100644 console/import_tp_from_folder.go create mode 100644 console/maxusage.go diff --git a/apier/v1/apier.go b/apier/v1/apier.go index d7cc578ef..0c4c3eddd 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -447,14 +447,7 @@ func (self *ApierV1) LoadTariffPlanFromStorDb(attrs AttrLoadTpFromStorDb, reply return nil } -type AttrImportTPFromFolder struct { - TPid string - FolderPath string - RunId string - CsvSeparator string -} - -func (self *ApierV1) ImportTariffPlanFromFolder(attrs AttrImportTPFromFolder, reply *string) error { +func (self *ApierV1) ImportTariffPlanFromFolder(attrs utils.AttrImportTPFromFolder, reply *string) error { if missing := utils.MissingStructFields(&attrs, []string{"TPid", "FolderPath"}); len(missing) != 0 { return utils.NewErrMandatoryIeMissing(missing...) } diff --git a/apier/v1/apier_local_test.go b/apier/v1/apier_local_test.go index a75a9fee5..e025888a5 100644 --- a/apier/v1/apier_local_test.go +++ b/apier/v1/apier_local_test.go @@ -1725,7 +1725,7 @@ func TestApierImportTPFromFolderPath(t *testing.T) { return } var reply string - if err := rater.Call("ApierV1.ImportTariffPlanFromFolder", AttrImportTPFromFolder{TPid: "TEST_TPID2", FolderPath: "/usr/share/cgrates/tariffplans/tutorial"}, &reply); err != nil { + if err := rater.Call("ApierV1.ImportTariffPlanFromFolder", utils.AttrImportTPFromFolder{TPid: "TEST_TPID2", FolderPath: "/usr/share/cgrates/tariffplans/tutorial"}, &reply); err != nil { t.Error("Got error on ApierV1.ImportTarrifPlanFromFolder: ", err.Error()) } else if reply != utils.OK { t.Error("Calling ApierV1.ImportTarrifPlanFromFolder got reply: ", reply) diff --git a/apier/v1/cdrsv1.go b/apier/v1/cdrsv1.go index 6cadcb9e2..a0b82923e 100644 --- a/apier/v1/cdrsv1.go +++ b/apier/v1/cdrsv1.go @@ -46,7 +46,9 @@ func (self *CdrsV1) ProcessExternalCdr(cdr *engine.ExternalCdr, reply *string) e *reply = err.Error() return err } - *cdr = out.(engine.ExternalCdr) + if upcdr, ok := out.(engine.ExternalCdr); ok { + *cdr = upcdr + } if err := self.CdrSrv.ProcessExternalCdr(cdr); err != nil { return utils.NewErrServerError(err) } diff --git a/console/import_tp_from_folder.go b/console/import_tp_from_folder.go new file mode 100644 index 000000000..7453563e9 --- /dev/null +++ b/console/import_tp_from_folder.go @@ -0,0 +1,63 @@ +/* +Rating system designed to be used in VoIP Carriers World +Copyright (C) 2012-2015 ITsysCOM + +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 := &ImportTpFromFolder{ + name: "import_tp_from_folder", + rpcMethod: "ApierV1.ImportTariffPlanFromFolder", + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type ImportTpFromFolder struct { + name string + rpcMethod string + rpcParams *utils.AttrImportTPFromFolder + rpcResult string + *CommandExecuter +} + +func (self *ImportTpFromFolder) Name() string { + return self.name +} + +func (self *ImportTpFromFolder) RpcMethod() string { + return self.rpcMethod +} + +func (self *ImportTpFromFolder) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &utils.AttrImportTPFromFolder{} + } + return self.rpcParams +} + +func (self *ImportTpFromFolder) PostprocessRpcParams() error { + return nil +} + +func (self *ImportTpFromFolder) RpcResult() interface{} { + var s string + return &s +} diff --git a/console/maxusage.go b/console/maxusage.go new file mode 100644 index 000000000..96afd8ba9 --- /dev/null +++ b/console/maxusage.go @@ -0,0 +1,67 @@ +/* +Rating system designed to be used in VoIP Carriers World +Copyright (C) 2012-2015 ITsysCOM + +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" + +func init() { + c := &CmdGetMaxUsage{ + name: "maxusage", + rpcMethod: "ApierV1.GetMaxUsage", + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdGetMaxUsage struct { + name string + rpcMethod string + rpcParams *engine.UsageRecord + clientArgs []string + *CommandExecuter +} + +func (self *CmdGetMaxUsage) Name() string { + return self.name +} + +func (self *CmdGetMaxUsage) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdGetMaxUsage) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &engine.UsageRecord{Direction: "*out"} + } + return self.rpcParams +} + +func (self *CmdGetMaxUsage) PostprocessRpcParams() error { + return nil +} + +func (self *CmdGetMaxUsage) RpcResult() interface{} { + var f float64 + return &f +} + +func (self *CmdGetMaxUsage) ClientArgs() []string { + return self.clientArgs +} diff --git a/data/conf/samples/apier/apier.json b/data/conf/samples/apier/apier.json index 22fd7733b..262abf177 100644 --- a/data/conf/samples/apier/apier.json +++ b/data/conf/samples/apier/apier.json @@ -4,6 +4,12 @@ // Used in apier_local_tests // Starts rater, cdrs and mediator connecting over internal channel +"listen": { + "rpc_json": ":2012", // RPC JSON listening address + "rpc_gob": ":2013", // RPC GOB listening address + "http": ":2080", // HTTP listening address +}, + "rater": { "enabled": true, // enable Rater service: }, @@ -23,4 +29,4 @@ } }, -} \ No newline at end of file +} diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 661110bf9..55b8fc421 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -479,7 +479,9 @@ func (csvs *CSVStorage) GetTpUsers(filter *TpUser) ([]TpUser, error) { return nil, err } else { u := tpUser.(TpUser) - u.Tpid = filter.Tpid + if filter != nil { + u.Tpid = filter.Tpid + } tpUsers = append(tpUsers, u) } } diff --git a/engine/users.go b/engine/users.go index ce1cfc8a2..8e937fc83 100644 --- a/engine/users.go +++ b/engine/users.go @@ -356,6 +356,9 @@ func (ps *ProxyUserService) GetIndexes(in string, reply *map[string][]string) er } func LoadUserProfile(in interface{}, extraFields string) (interface{}, error) { + if userService == nil { // no user service => no fun + return in, nil + } m, err := utils.ToMapStringString(in) if err != nil { return nil, err @@ -376,7 +379,6 @@ func LoadUserProfile(in interface{}, extraFields string) (interface{}, error) { up.Profile[key] = val } } - // add extra fields if extraFields != "" { extra, err := utils.GetMapExtraFields(in, extraFields) diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 9c5dda207..9495ddb8e 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -758,6 +758,13 @@ type AttrLoadTpFromFolder struct { Validate bool // Run structural checks on data } +type AttrImportTPFromFolder struct { + TPid string + FolderPath string + RunId string + CsvSeparator string +} + type AttrGetDestination struct { Id string }