From 01f1b9aa64d191c67f1b432230a565d1cf048dc9 Mon Sep 17 00:00:00 2001 From: DanB Date: Wed, 18 Feb 2015 19:35:12 +0100 Subject: [PATCH] ApierV1.GetMaxSessionTime, make direction, tenant, account and subject optional in ApierV1.SetDerivedChargers --- apier/v1/callsetup.go | 38 +++++++++++++++++++++++++++++++++++++ apier/v1/derivedcharging.go | 32 +++++++++++++++++++++++++++---- config/config_json.go | 1 - engine/responder.go | 7 ++++--- 4 files changed, 70 insertions(+), 8 deletions(-) create mode 100644 apier/v1/callsetup.go diff --git a/apier/v1/callsetup.go b/apier/v1/callsetup.go new file mode 100644 index 000000000..9aa10bea3 --- /dev/null +++ b/apier/v1/callsetup.go @@ -0,0 +1,38 @@ +/* +Real-time Charging System 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 v1 + +import ( + "github.com/cgrates/cgrates/utils" + "time" +) + +// Returns MaxSessionTime in seconds, -1 for no limit +func (self *ApierV1) GetMaxSessionTime(cdr utils.StoredCdr, maxSessionTime *float64) error { + var maxDur float64 + if err := self.Responder.GetDerivedMaxSessionTime(&cdr, &maxDur); err != nil { + return err + } + if maxDur == -1.0 { + *maxSessionTime = -1.0 + return nil + } + *maxSessionTime = time.Duration(maxDur).Seconds() + return nil +} diff --git a/apier/v1/derivedcharging.go b/apier/v1/derivedcharging.go index 25dfb7a81..637004590 100644 --- a/apier/v1/derivedcharging.go +++ b/apier/v1/derivedcharging.go @@ -43,8 +43,20 @@ type AttrSetDerivedChargers struct { } func (self *ApierV1) SetDerivedChargers(attrs AttrSetDerivedChargers, reply *string) (err error) { - if missing := utils.MissingStructFields(&attrs, []string{"Tenant", "Category", "Direction", "Account", "Subject", "DerivedChargers"}); len(missing) != 0 { - return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing) + if len(attrs.Direction) == 0 { + attrs.Direction = utils.OUT + } + if len(attrs.Tenant) == 0 { + attrs.Tenant = utils.ANY + } + if len(attrs.Category) == 0 { + attrs.Category = utils.ANY + } + if len(attrs.Account) == 0 { + attrs.Account = utils.ANY + } + if len(attrs.Subject) == 0 { + attrs.Subject = utils.ANY } for _, dc := range attrs.DerivedChargers { if _, err = utils.ParseRSRFields(dc.RunFilters, utils.INFIELD_SEP); err != nil { // Make sure rules are OK before loading in db @@ -67,8 +79,20 @@ type AttrRemDerivedChargers struct { } func (self *ApierV1) RemDerivedChargers(attrs AttrRemDerivedChargers, reply *string) error { - if missing := utils.MissingStructFields(&attrs, []string{"Direction", "Tenant", "Category", "Account", "Subject"}); len(missing) != 0 { //Params missing - return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing) + if len(attrs.Direction) == 0 { + attrs.Direction = utils.OUT + } + if len(attrs.Tenant) == 0 { + attrs.Tenant = utils.ANY + } + if len(attrs.Category) == 0 { + attrs.Category = utils.ANY + } + if len(attrs.Account) == 0 { + attrs.Account = utils.ANY + } + if len(attrs.Subject) == 0 { + attrs.Subject = utils.ANY } if err := self.AccountDb.SetDerivedChargers(utils.DerivedChargersKey(attrs.Direction, attrs.Tenant, attrs.Category, attrs.Account, attrs.Subject), nil); err != nil { return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error()) diff --git a/config/config_json.go b/config/config_json.go index 3ab8831b2..84ed4c452 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -68,7 +68,6 @@ func NewCgrJsonCfgFromFile(fpath string) (*CgrJsonCfg, error) { return nil, err } defer cfgFile.Close() - return NewCgrJsonCfgFromReader(cfgFile) } diff --git a/engine/responder.go b/engine/responder.go index af0c81b1e..a07d3a8dd 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -219,8 +219,9 @@ func (rs *Responder) GetSessionRuns(ev utils.Event, sRuns *[]*SessionRun) error } func (rs *Responder) GetDerivedChargers(attrs utils.AttrDerivedChargers, dcs *utils.DerivedChargers) error { - // ToDo: Make it work with balancer if needed - + if rs.Bal != nil { + return errors.New("BALANCER_UNSUPPORTED_METHOD") + } if dcsH, err := HandleGetDerivedChargers(accountingStorage, attrs); err != nil { return err } else if dcsH != nil { @@ -231,7 +232,7 @@ func (rs *Responder) GetDerivedChargers(attrs utils.AttrDerivedChargers, dcs *ut func (rs *Responder) ProcessCdr(cdr *utils.StoredCdr, reply *string) error { if rs.CdrSrv == nil { - return errors.New("CdrServerNotRunning") + return errors.New("CDR_SERVER_NOT_RUNNING") } if err := rs.CdrSrv.ProcessCdr(cdr); err != nil { return err