From cdc6b7de2e3aaf912dcf8ddfb0b9fad0fb7d0128 Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Thu, 28 Jan 2016 16:13:37 +0200 Subject: [PATCH] added call descriptor runid --- engine/calldesc.go | 3 ++- engine/responder.go | 16 ++++++++------ engine/responder_test.go | 6 ++--- general_tests/tutorial_local_test.go | 33 ++++++++++++++++++---------- sessionmanager/session.go | 2 +- 5 files changed, 37 insertions(+), 23 deletions(-) diff --git a/engine/calldesc.go b/engine/calldesc.go index 40fdb7e79..051d98940 100644 --- a/engine/calldesc.go +++ b/engine/calldesc.go @@ -153,7 +153,8 @@ type CallDescriptor struct { MaxRate float64 MaxRateUnit time.Duration MaxCostSoFar float64 - CgrId string + CgrID string + RunID string account *Account testCallcost *CallCost // testing purpose only! } diff --git a/engine/responder.go b/engine/responder.go index d9f9510f1..a40a4bfee 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -186,7 +186,7 @@ func (rs *Responder) FakeDebit(arg *CallDescriptor, reply *CallCost) (err error) } func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error) { - if item, err := rs.getCache().Get(utils.MAX_DEBIT_CACHE_PREFIX + arg.CgrId); err == nil && item != nil { + if item, err := rs.getCache().Get(utils.MAX_DEBIT_CACHE_PREFIX + arg.CgrID + arg.RunID); err == nil && item != nil { *reply = *(item.Value.(*CallCost)) return item.Err } @@ -216,7 +216,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error) } else { r, e := arg.MaxDebit() if e != nil { - rs.getCache().Cache(utils.MAX_DEBIT_CACHE_PREFIX+arg.CgrId, &cache2go.CacheItem{ + rs.getCache().Cache(utils.MAX_DEBIT_CACHE_PREFIX+arg.CgrID+arg.RunID, &cache2go.CacheItem{ Err: e, }) return e @@ -224,7 +224,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error) *reply = *r } } - rs.getCache().Cache(utils.MAX_DEBIT_CACHE_PREFIX+arg.CgrId, &cache2go.CacheItem{ + rs.getCache().Cache(utils.MAX_DEBIT_CACHE_PREFIX+arg.CgrID+arg.RunID, &cache2go.CacheItem{ Value: reply, Err: err, }) @@ -232,7 +232,7 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error) } func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err error) { - if item, err := rs.getCache().Get(utils.REFUND_INCR_CACHE_PREFIX + arg.CgrId); err == nil && item != nil { + if item, err := rs.getCache().Get(utils.REFUND_INCR_CACHE_PREFIX + arg.CgrID + arg.RunID); err == nil && item != nil { *reply = *(item.Value.(*float64)) return item.Err } @@ -261,7 +261,7 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *float64) (err } else { *reply, err = arg.RefundIncrements() } - rs.getCache().Cache(utils.REFUND_INCR_CACHE_PREFIX+arg.CgrId, &cache2go.CacheItem{ + rs.getCache().Cache(utils.REFUND_INCR_CACHE_PREFIX+arg.CgrID+arg.RunID, &cache2go.CacheItem{ Value: reply, Err: err, }) @@ -358,7 +358,8 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *float64) error { usage = config.CgrConfig().MaxCallDuration } cd := &CallDescriptor{ - CgrId: ev.GetCgrId(rs.Timezone), + CgrID: ev.GetCgrId(rs.Timezone), + RunID: ev.RunID, TOR: ev.ToR, Direction: ev.GetDirection(dc.DirectionField), Tenant: ev.GetTenant(dc.TenantField), @@ -445,7 +446,8 @@ func (rs *Responder) GetSessionRuns(ev *CDR, sRuns *[]*SessionRun) error { return errors.New("Error parsing answer event end time") } cd := &CallDescriptor{ - CgrId: ev.GetCgrId(rs.Timezone), + CgrID: ev.GetCgrId(rs.Timezone), + RunID: ev.RunID, TOR: ev.ToR, Direction: ev.GetDirection(dc.DirectionField), Tenant: ev.GetTenant(dc.TenantField), diff --git a/engine/responder_test.go b/engine/responder_test.go index b896a15c8..fc54bd46f 100644 --- a/engine/responder_test.go +++ b/engine/responder_test.go @@ -151,13 +151,13 @@ func TestResponderGetSessionRuns(t *testing.T) { sesRuns := make([]*SessionRun, 0) eSRuns := []*SessionRun{ &SessionRun{DerivedCharger: extra1DC, - CallDescriptor: &CallDescriptor{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), Direction: "*out", Category: "0", + CallDescriptor: &CallDescriptor{CgrID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), RunID: "*default", Direction: "*out", Category: "0", Tenant: "vdf", Subject: "rif", Account: "minitsboy", Destination: "0256", TimeStart: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), TimeEnd: time.Date(2013, 11, 7, 8, 42, 36, 0, time.UTC), TOR: utils.VOICE, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}}, &SessionRun{DerivedCharger: extra2DC, - CallDescriptor: &CallDescriptor{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), Direction: "*out", Category: "call", + CallDescriptor: &CallDescriptor{CgrID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), RunID: "*default", Direction: "*out", Category: "call", Tenant: "vdf", Subject: "ivo", Account: "ivo", Destination: "1002", TimeStart: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), TimeEnd: time.Date(2013, 11, 7, 8, 42, 36, 0, time.UTC), TOR: utils.VOICE, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}}, &SessionRun{DerivedCharger: dfDC, - CallDescriptor: &CallDescriptor{CgrId: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), Direction: "*out", Category: "call", + CallDescriptor: &CallDescriptor{CgrID: utils.Sha1("dsafdsaf", time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC).String()), RunID: "*default", Direction: "*out", Category: "call", Tenant: "vdf", Subject: "dan2", Account: "dan2", Destination: "1002", TimeStart: time.Date(2013, 11, 7, 8, 42, 26, 0, time.UTC), TimeEnd: time.Date(2013, 11, 7, 8, 42, 36, 0, time.UTC), TOR: utils.VOICE, ExtraFields: map[string]string{"field_extr1": "val_extr1", "fieldextr2": "valextr2"}}}} if err := rsponder.GetSessionRuns(cdr, &sesRuns); err != nil { t.Error(err) diff --git a/general_tests/tutorial_local_test.go b/general_tests/tutorial_local_test.go index fe515fde2..30409089c 100644 --- a/general_tests/tutorial_local_test.go +++ b/general_tests/tutorial_local_test.go @@ -754,7 +754,8 @@ func TestTutLocalLcrStatic(t *testing.T) { }, } var lcr engine.LCRCost - cd.CgrId = "1" + cd.CgrID = "1" + cd.RunID = "1" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { @@ -779,7 +780,8 @@ func TestTutLocalLcrStatic(t *testing.T) { &engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl2", Cost: 1.2, Duration: 60 * time.Second}, }, } - cd.CgrId = "2" + cd.CgrID = "2" + cd.RunID = "2" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { @@ -858,7 +860,8 @@ func TestTutLocalLcrQos(t *testing.T) { } var lcr engine.LCRCost // Since there is no real quality difference, the suppliers will come in random order here - cd.CgrId = "3" + cd.CgrID = "3" + cd.RunID = "3" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { @@ -897,7 +900,8 @@ func TestTutLocalLcrQos(t *testing.T) { QOS: map[string]float64{engine.TCD: 90, engine.ACC: 0.325, engine.TCC: 0.325, engine.ASR: 100, engine.ACD: 90}}, }, } - cd.CgrId = "4" + cd.CgrID = "4" + cd.RunID = "4" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { @@ -925,7 +929,8 @@ func TestTutLocalLcrQos(t *testing.T) { QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}}, }, } - cd.CgrId = "5" + cd.CgrID = "5" + cd.RunID = "5" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { @@ -961,7 +966,8 @@ func TestTutLocalLcrQosThreshold(t *testing.T) { }, } var lcr engine.LCRCost - cd.CgrId = "6" + cd.CgrID = "6" + cd.RunID = "6" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) { @@ -987,7 +993,8 @@ func TestTutLocalLcrQosThreshold(t *testing.T) { QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}}, }, } - cd.CgrId = "7" + cd.CgrID = "7" + cd.RunID = "7" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) { @@ -1024,7 +1031,8 @@ func TestTutLocalLcrQosThreshold(t *testing.T) { }, } */ - cd.CgrId = "8" + cd.CgrID = "8" + cd.RunID = "8" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) { @@ -1049,7 +1057,8 @@ func TestTutLocalLcrQosThreshold(t *testing.T) { QOS: map[string]float64{engine.TCD: 240, engine.ACC: 0.35, engine.TCC: 0.7, engine.ASR: 100, engine.ACD: 120}}, }, } - cd.CgrId = "9" + cd.CgrID = "9" + cd.RunID = "9" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eLcr.Entry, lcr.Entry) { @@ -1084,7 +1093,8 @@ func TestTutLocalLeastCost(t *testing.T) { }, } var lcr engine.LCRCost - cd.CgrId = "10" + cd.CgrID = "10" + cd.RunID = "10" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { @@ -1116,7 +1126,8 @@ func TestTutLocalLeastCost(t *testing.T) { &engine.LCRSupplierCost{Supplier: "*out:cgrates.org:lcr_profile1:suppl1", Cost: 1.2, Duration: 60 * time.Second}, }, } - cd.CgrId = "11" + cd.CgrID = "11" + cd.RunID = "11" if err := tutLocalRpc.Call("Responder.GetLCR", cd, &lcr); err != nil { t.Error(err) } else if !reflect.DeepEqual(eStLcr.Entry, lcr.Entry) { diff --git a/sessionmanager/session.go b/sessionmanager/session.go index 31f765250..061ea84ca 100644 --- a/sessionmanager/session.go +++ b/sessionmanager/session.go @@ -70,7 +70,7 @@ func NewSession(ev engine.Event, connId string, sm SessionManager) *Session { // the debit loop method (to be stoped by sending somenthing on stopDebit channel) func (s *Session) debitLoop(runIdx int) { nextCd := s.sessionRuns[runIdx].CallDescriptor - nextCd.CgrId = s.eventStart.GetCgrId("") + nextCd.CgrID = s.eventStart.GetCgrId("") index := 0.0 debitPeriod := s.sessionManager.DebitInterval() for {