From 34d85ca4fdea30451cabc51595beaff7e70ebbad Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 30 May 2016 23:11:07 +0300 Subject: [PATCH 1/4] stats tests fix --- engine/stats_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/engine/stats_test.go b/engine/stats_test.go index c618fb373..ab7988ae2 100644 --- a/engine/stats_test.go +++ b/engine/stats_test.go @@ -202,9 +202,9 @@ func TestStatsQueueIds(t *testing.T) { t.Error("Errorf getting queue ids: ", err) } result := len(ids) - expected := 2 + expected := 5 if result != expected { - t.Errorf("Errorf loading stats queues. Expected %v was %v", expected, result) + t.Errorf("Errorf loading stats queues. Expected %v was %v (%v)", expected, result, ids) } } @@ -225,7 +225,7 @@ func TestStatsAppendCdr(t *testing.T) { t.Error("Error appending cdr to stats: ", err) } t.Log(cdrStats.queues) - if len(cdrStats.queues) != 2 || + if len(cdrStats.queues) != 5 || len(cdrStats.queues["CDRST1"].Cdrs) != 0 || len(cdrStats.queues["CDRST2"].Cdrs) != 1 { t.Error("Error appending cdr to queue: ", utils.ToIJSON(cdrStats.queues)) @@ -280,7 +280,7 @@ func TestStatsReloadQueues(t *testing.T) { t.Error("Error getting queue ids: ", err) } result := len(ids) - expected := 2 + expected := 5 if result != expected { t.Errorf("Error loading stats queues. Expected %v was %v: %v", expected, result, ids) } @@ -316,7 +316,7 @@ func TestStatsReloadQueuesWithDefault(t *testing.T) { t.Error("Error getting queue ids: ", err) } result := len(ids) - expected := 2 + expected := 6 if result != expected { t.Errorf("Error loading stats queues. Expected %v was %v", expected, result) } @@ -348,7 +348,7 @@ func TestStatsReloadQueuesWithIds(t *testing.T) { t.Error("Error getting queue ids: ", err) } result := len(ids) - expected := 2 + expected := 6 if result != expected { t.Errorf("Error loading stats queues. Expected %v was %v", expected, result) } @@ -398,7 +398,7 @@ func TestStatsResetQueues(t *testing.T) { t.Error("Error getting queue ids: ", err) } result := len(ids) - expected := 2 + expected := 6 if result != expected { t.Errorf("Error loading stats queues. Expected %v was %v", expected, result) } @@ -430,7 +430,7 @@ func TestStatsResetQueuesWithIds(t *testing.T) { t.Error("Error getting queue ids: ", err) } result := len(ids) - expected := 2 + expected := 6 if result != expected { t.Errorf("Error loading stats queues. Expected %v was %v", expected, result) } From bd657a33b2e006bf7d2e856f7dbcff76ebcfe2cf Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 31 May 2016 09:09:21 +0300 Subject: [PATCH 2/4] added balance debit fixes #458 --- console/balance_debit.go | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 console/balance_debit.go diff --git a/console/balance_debit.go b/console/balance_debit.go new file mode 100644 index 000000000..9787ab821 --- /dev/null +++ b/console/balance_debit.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/apier/v1" + +func init() { + c := &CmdBalanceDebit{ + name: "balance_debit", + rpcMethod: "ApierV1.DebitBalance", + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdBalanceDebit struct { + name string + rpcMethod string + rpcParams *v1.AttrAddBalance + clientArgs []string + *CommandExecuter +} + +func (self *CmdBalanceDebit) Name() string { + return self.name +} + +func (self *CmdBalanceDebit) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdBalanceDebit) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &v1.AttrAddBalance{} + } + return self.rpcParams +} + +func (self *CmdBalanceDebit) PostprocessRpcParams() error { + return nil +} + +func (self *CmdBalanceDebit) RpcResult() interface{} { + var s string + return &s +} From b7e8e5b16091749888fe28591d1c2f10e6d7e728 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 31 May 2016 12:13:17 +0300 Subject: [PATCH 3/4] fix for rpc dynamic parameters parsing --- engine/action.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/action.go b/engine/action.go index aefd9cf34..03d81e289 100644 --- a/engine/action.go +++ b/engine/action.go @@ -674,10 +674,10 @@ func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Acti utils.Logger.Err(fmt.Sprintf("error executing *cgr_rpc template %s:", err.Error())) return err } - a.ExtraParameters = buf.String() - //utils.Logger.Info("ExtraParameters: " + a.ExtraParameters) + processedExtraParam := buf.String() + //utils.Logger.Info("ExtraParameters: " + parsedExtraParameters) req := RPCRequest{} - if err := json.Unmarshal([]byte(a.ExtraParameters), &req); err != nil { + if err := json.Unmarshal([]byte(processedExtraParam), &req); err != nil { return err } params, err := utils.GetRpcParams(req.Method) From b890e46ff56c74b92360faba61f620fdf3c3a1cb Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Tue, 31 May 2016 16:38:42 +0300 Subject: [PATCH 4/4] fix for non-recurrent stats action triggers --- engine/stats_queue.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/engine/stats_queue.go b/engine/stats_queue.go index 6260fd1ee..e6a2de71e 100644 --- a/engine/stats_queue.go +++ b/engine/stats_queue.go @@ -134,6 +134,17 @@ func (sq *StatsQueue) appendQcdr(qcdr *QCdr, runTrigger bool) { stats := sq.getStats() sq.conf.Triggers.Sort() for _, at := range sq.conf.Triggers { + // check is effective + if at.IsExpired(time.Now()) || !at.IsActive(time.Now()) { + continue + } + + if at.Executed { + // trigger is marked as executed, so skipp it until + // the next reset (see RESET_TRIGGERS action type) + continue + } + if at.MinQueuedItems > 0 && len(sq.Cdrs) < at.MinQueuedItems { continue }