mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
Populate *ddc out of StatS
This commit is contained in:
committed by
Dan Christian Bogos
parent
d5294b2a6f
commit
c5abdbd9c2
@@ -524,7 +524,7 @@ func setddestinations(ub *Account, a *Action, acs Actions, extraData interface{}
|
||||
for _, bchain := range ub.BalanceMap {
|
||||
for _, b := range bchain {
|
||||
for destID := range b.DestinationIDs {
|
||||
if strings.HasPrefix(destID, "*ddc") {
|
||||
if strings.HasPrefix(destID, utils.MetaDDC) {
|
||||
ddcDestID = destID
|
||||
break
|
||||
}
|
||||
@@ -538,15 +538,30 @@ func setddestinations(ub *Account, a *Action, acs Actions, extraData interface{}
|
||||
}
|
||||
}
|
||||
if ddcDestID != "" {
|
||||
// make slice from prefixes
|
||||
// Review here prefixes
|
||||
// prefixes := make([]string, len(sq.Metrics))
|
||||
// i := 0
|
||||
// for p := range sq.Metrics {
|
||||
// prefixes[i] = p
|
||||
// i++
|
||||
// }
|
||||
newDest := &Destination{Id: ddcDestID}
|
||||
destinations := utils.NewStringSet(nil)
|
||||
for _, statID := range strings.Split(a.ExtraParameters, utils.INFIELD_SEP) {
|
||||
if statID == utils.EmptyString {
|
||||
continue
|
||||
}
|
||||
var sts *StatQueue
|
||||
if sts, err = dm.GetStatQueue(config.CgrConfig().GeneralCfg().DefaultTenant, statID,
|
||||
true, false, utils.NonTransactional); err != nil {
|
||||
return
|
||||
}
|
||||
ddcIface, has := sts.SQMetrics[utils.MetaDDC]
|
||||
if !has {
|
||||
continue
|
||||
}
|
||||
ddcMetric := ddcIface.(*StatDDC)
|
||||
|
||||
// make slice from prefixes
|
||||
// Review here prefixes
|
||||
for p := range ddcMetric.FieldValues {
|
||||
destinations.Add(p)
|
||||
}
|
||||
}
|
||||
|
||||
newDest := &Destination{Id: ddcDestID, Prefixes: destinations.AsSlice()}
|
||||
oldDest, err := dm.GetDestination(ddcDestID, false, utils.NonTransactional)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1479,8 +1479,6 @@ func TestTopupActionLoaded(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Need to be reviewed with extra data instead of cdrstats
|
||||
func TestActionSetDDestination(t *testing.T) {
|
||||
acc := &Account{BalanceMap: map[string]Balances{
|
||||
utils.MONETARY: Balances{&Balance{DestinationIDs: utils.NewStringMap("*ddc_test")}}}}
|
||||
@@ -1501,7 +1499,20 @@ func TestActionSetDDestination(t *testing.T) {
|
||||
if !found || len(x1.([]string)) != 1 {
|
||||
t.Error("Error cacheing destination: ", x1)
|
||||
}
|
||||
setddestinations(acc, &CDRStatsQueueTriggered{Metrics: map[string]float64{"333": 1, "666": 1}}, nil, nil)
|
||||
|
||||
if err := dm.SetStatQueue(&StatQueue{Tenant: "cgrates.org", ID: "StatDestination",
|
||||
SQMetrics: map[string]StatMetric{
|
||||
utils.MetaDDC: &StatDDC{FieldValues: map[string]map[string]struct{}{
|
||||
"333": {"Ev1": struct{}{}},
|
||||
"666": {"Ev2": struct{}{}},
|
||||
}},
|
||||
}}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if err := setddestinations(acc, &Action{ExtraParameters: "StatDestination"}, nil, nil); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
d, err := dm.GetDestination("*ddc_test", false, utils.NonTransactional)
|
||||
if err != nil ||
|
||||
d.Id != origD.Id ||
|
||||
@@ -1531,7 +1542,6 @@ func TestActionSetDDestination(t *testing.T) {
|
||||
t.Error("Error cacheing destination: ", x1)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestActionTransactionFuncType(t *testing.T) {
|
||||
err := dm.SetAccount(&Account{
|
||||
|
||||
Reference in New Issue
Block a user