diff --git a/apis/stats_it_test.go b/apis/stats_it_test.go index 4a2826e16..0914721e8 100644 --- a/apis/stats_it_test.go +++ b/apis/stats_it_test.go @@ -818,7 +818,6 @@ func testStatsProcessEvent(t *testing.T) { utils.AccountField: "1001", }, APIOpts: map[string]interface{}{ - utils.MetaUsage: 30 * time.Second, utils.OptsStatsProfileIDs: []string{"SQ_3"}, utils.MetaUsage: 30 * time.Second, }, diff --git a/data/conf/samples/ees/cgrates.json b/data/conf/samples/ees/cgrates.json index 0819a66db..24a857422 100644 --- a/data/conf/samples/ees/cgrates.json +++ b/data/conf/samples/ees/cgrates.json @@ -19,24 +19,10 @@ "db_name": "10", }, - - - - -"rals": { - "enabled": true, -}, - - -"schedulers": { - "enabled": true, -}, - - "cdrs": { "enabled": true, "chargers_conns": ["*localhost"], - "rals_conns": ["*internal"], + "rates_conns": ["*internal"], "session_cost_retries": 0, }, @@ -530,7 +516,6 @@ "admins": { "enabled": true, - "scheduler_conns": ["*internal"], }, diff --git a/rates/rates_test.go b/rates/rates_test.go index ec6ed5005..8dfa8c74d 100644 --- a/rates/rates_test.go +++ b/rates/rates_test.go @@ -1170,6 +1170,7 @@ func TestCDRProcessRatesCostForEvent(t *testing.T) { }, }, }, + utils.MetaCost: utils.NewDecimal(int64(15*time.Second)/10, 0), utils.MetaUsage: 15 * time.Second, }, } diff --git a/utils/blockers.go b/utils/blockers.go new file mode 100644 index 000000000..4c68e65b5 --- /dev/null +++ b/utils/blockers.go @@ -0,0 +1,78 @@ +/* +Real-time Online/Offline Charging System (OCS) 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 utils + +import ( + "fmt" + "strconv" + "strings" +) + +type Blockers []*DynamicBlocker + +// NewBlockersFromString will build the Blockers that contains slices of FilterIDs and Blocker from a single value. This process is helped by separators +func NewBlockersFromString(value, blkSep, fltrSep string) (blkrs Blockers, err error) { + if len(value) == 0 { + return Blockers{{}}, nil + } + valSeparated := strings.Split(value, blkSep) + lenVals := len(valSeparated) + if lenVals%2 != 0 { + return nil, fmt.Errorf("invalid DynamicBlocker format for string <%s>", value) + } + for idx := 0; idx < lenVals; idx += 2 { + var fltrIDs []string + if len(valSeparated[idx]) != 0 { + fltrIDs = strings.Split(valSeparated[idx], fltrSep) + } + var blocker bool + if len(valSeparated[idx+1]) != 0 { + if blocker, err = strconv.ParseBool(valSeparated[idx+1]); err != nil { + return nil, fmt.Errorf("cannot convert bool with value: <%v> into Blocker", valSeparated[idx+1]) + } + } + blkrs = append(blkrs, &DynamicBlocker{FilterIDs: fltrIDs, Blocker: blocker}) + } + return +} + +// String +func (blkrs Blockers) String(blkSep, fltrSep string) (value string) { + if len(blkrs) == 0 { + return + } + strBlockers := make([]string, len(blkrs)) + for idx, val := range blkrs { + strBlockers[idx] = val.String(blkSep, fltrSep) + } + return strings.Join(strBlockers, blkSep) +} + +type DynamicBlocker struct { + FilterIDs []string + Blocker bool +} + +func (blckr DynamicBlocker) String(blkSep, fltrSep string) (out string) { + blocker := "false" + if blckr.Blocker == true { + blocker = "true" + } + return strings.Join(blckr.FilterIDs, fltrSep) + blkSep + blocker +} diff --git a/utils/blockers_test.go b/utils/blockers_test.go new file mode 100644 index 000000000..6af7d0ba0 --- /dev/null +++ b/utils/blockers_test.go @@ -0,0 +1,83 @@ +/* +Real-time Online/Offline Charging System (OCS) 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 utils + +import ( + "reflect" + "testing" +) + +func TestNewBlockersFromString(t *testing.T) { + blkrs := Blockers{ + { + FilterIDs: []string{"*string:~*opts.*cost:0"}, + Blocker: false, + }, + { + FilterIDs: []string{"*suffix:~*req.Destination:+4432", "eq:~*opts.*usage:10s"}, + Blocker: false, + }, + { + FilterIDs: []string{"*notstring:~*req.RequestType:*prepaid"}, + Blocker: true, + }, + { + Blocker: false, + }, + } + blkrsStr := "*string:~*opts.*cost:0;false;*suffix:~*req.Destination:+4432&eq:~*opts.*usage:10s;false;*notstring:~*req.RequestType:*prepaid;true;;false" + if rcv, err := NewBlockersFromString(blkrsStr, InfieldSep, ANDSep); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(rcv, blkrs) { + t.Errorf("Expected %v \n received %v", ToJSON(blkrs), ToJSON(rcv)) + } + +} + +func TestNewBlockersFromString2(t *testing.T) { + blkrs := Blockers{ + { + FilterIDs: []string{"*string:~*opts.*cost:0"}, + Blocker: false, + }, + {}, + } + blkrsStr := "*string:~*opts.*cost:0;false;;" + if rcv, err := NewBlockersFromString(blkrsStr, InfieldSep, ANDSep); err != nil { + t.Error(err) + } else if !reflect.DeepEqual(rcv, blkrs) { + t.Errorf("Expected %+v \n ,received %+v", ToJSON(blkrs), ToJSON(rcv)) + } +} + +func TestNewBlockersFromStringErrSeparator(t *testing.T) { + blkrsStr := "*string:~*opts.*cost:0;false;;;" + exp := "invalid DynamicBlocker format for string <*string:~*opts.*cost:0;false;;;>" + if _, err := NewBlockersFromString(blkrsStr, InfieldSep, ANDSep); err.Error() != exp { + t.Errorf("Expected %s \n received %s", exp, err.Error()) + } +} + +func TestNewBlockersFromStringFormatBool(t *testing.T) { + blkrsStr := "*string:~*opts.*cost:0;tttrrruuue" + exp := "cannot convert bool with value: into Blocker" + if _, err := NewBlockersFromString(blkrsStr, InfieldSep, ANDSep); err.Error() != exp { + t.Errorf("Expected %s \n received %s", exp, err.Error()) + } +}