fixed local tests and added two new console cmds

This commit is contained in:
Radu Ioan Fericean
2015-07-16 15:13:46 +03:00
parent d5ca85573f
commit 2fb2e0d506
9 changed files with 155 additions and 13 deletions

View File

@@ -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...)
}

View File

@@ -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)

View File

@@ -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)
}

View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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
}

67
console/maxusage.go Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>
*/
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
}

View File

@@ -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: <true|false>
},
@@ -23,4 +29,4 @@
}
},
}
}

View File

@@ -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)
}
}

View File

@@ -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)

View File

@@ -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
}