Skip to content

Commit

Permalink
ApierV1.GetMaxSessionTime, make direction, tenant, account and subjec…
Browse files Browse the repository at this point in the history
…t optional in ApierV1.SetDerivedChargers
  • Loading branch information
danbogos committed Feb 18, 2015
1 parent 8adc935 commit 01f1b9a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 8 deletions.
38 changes: 38 additions & 0 deletions apier/v1/callsetup.go
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>
*/

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
}
32 changes: 28 additions & 4 deletions apier/v1/derivedcharging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())
Expand Down
1 change: 0 additions & 1 deletion config/config_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ func NewCgrJsonCfgFromFile(fpath string) (*CgrJsonCfg, error) {
return nil, err
}
defer cfgFile.Close()

return NewCgrJsonCfgFromReader(cfgFile)
}

Expand Down
7 changes: 4 additions & 3 deletions engine/responder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 01f1b9a

Please sign in to comment.