Adding responder GetLCR static sample

This commit is contained in:
DanB
2015-04-10 08:39:09 +02:00
parent 229af3198a
commit c281916089
4 changed files with 152 additions and 5 deletions

View File

@@ -660,6 +660,7 @@ func (cd *CallDescriptor) GetLCRFromStorage() (*LCR, error) {
utils.LCRKey(cd.Direction, cd.Tenant, cd.Category, utils.ANY, utils.ANY),
utils.LCRKey(cd.Direction, cd.Tenant, utils.ANY, utils.ANY, utils.ANY),
utils.LCRKey(cd.Direction, utils.ANY, utils.ANY, utils.ANY, utils.ANY),
utils.LCRKey(utils.ANY, utils.ANY, utils.ANY, utils.ANY, utils.ANY),
}
for _, key := range keyVariants {
if lcr, err := dataStorage.GetLCR(key, false); err != nil && err.Error() != utils.ERR_NOT_FOUND {

View File

@@ -160,3 +160,150 @@ func TestGetSessionRuns(t *testing.T) {
t.Errorf("Received: %+v", sesRuns)
}
}
/*
func TestGetLCRStatic(t *testing.T) {
dstDe := &Destination{Id: "GERMANY", Prefixes: []string{"+49"}}
if err := dataStorage.SetDestination(dstDe); err != nil {
t.Error(err)
}
rp1 := &RatingPlan{
Id: "RP1",
Timings: map[string]*RITiming{
"30eab300": &RITiming{
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: "00:00:00",
},
},
Ratings: map[string]*RIRate{
"b457f86d": &RIRate{
ConnectFee: 0,
Rates: []*Rate{
&Rate{
GroupIntervalStart: 0,
Value: 0.01,
RateIncrement: time.Second,
RateUnit: time.Second,
},
},
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
},
DestinationRates: map[string]RPRateList{
dstDe.Id: []*RPRate{
&RPRate{
Timing: "30eab300",
Rating: "b457f86d",
Weight: 10,
},
},
},
}
rp2 := &RatingPlan{
Id: "RP2",
Timings: map[string]*RITiming{
"30eab300": &RITiming{
Years: utils.Years{},
Months: utils.Months{},
MonthDays: utils.MonthDays{},
WeekDays: utils.WeekDays{},
StartTime: "00:00:00",
},
},
Ratings: map[string]*RIRate{
"b457f86d": &RIRate{
ConnectFee: 0,
Rates: []*Rate{
&Rate{
GroupIntervalStart: 0,
Value: 0.02,
RateIncrement: time.Second,
RateUnit: time.Second,
},
},
RoundingMethod: utils.ROUNDING_MIDDLE,
RoundingDecimals: 4,
},
},
DestinationRates: map[string]RPRateList{
"GERMANY": []*RPRate{
&RPRate{
Timing: "30eab300",
Rating: "b457f86d",
Weight: 10,
},
},
},
}
if err := dataStorage.SetRatingPlan(rp1); err != nil {
t.Error(err)
}
danRpfl := &RatingProfile{Id: "*out:cgrates.org:call:dan",
RatingPlanActivations: RatingPlanActivations{&RatingPlanActivation{
ActivationTime: time.Date(2015, 01, 01, 8, 0, 0, 0, time.UTC),
RatingPlanId: rp1.Id,
FallbackKeys: []string{},
CdrStatQueueIds: []string{},
}},
}
rifRpfl := &RatingProfile{Id: "*out:cgrates.org:call:rif",
RatingPlanActivations: RatingPlanActivations{&RatingPlanActivation{
ActivationTime: time.Date(2015, 01, 01, 8, 0, 0, 0, time.UTC),
RatingPlanId: rp2.Id,
FallbackKeys: []string{},
CdrStatQueueIds: []string{},
}},
}
for _, rpfl := range []*RatingProfile{danRpfl, rifRpfl} {
if err := dataStorage.SetRatingProfile(rpfl); err != nil {
t.Error(err)
}
}
lcrSet := &LCR{Direction: utils.ANY, Tenant: utils.ANY, Category: utils.ANY, Account: utils.ANY, Subject: utils.ANY,
Activations: []*LCRActivation{
&LCRActivation{
ActivationTime: time.Date(2015, 01, 01, 8, 0, 0, 0, time.UTC),
Entries: []*LCREntry{
&LCREntry{DestinationId: utils.ANY, RPCategory: "call", Strategy: LCR_STRATEGY_STATIC, StrategyParams: "dan;rif", Weight: 10.0}},
},
},
}
if err := dataStorage.SetLCR(lcrSet); err != nil {
t.Error(err)
}
if err := dataStorage.CacheRating([]string{DESTINATION_PREFIX + dstDe.Id},
[]string{RATING_PLAN_PREFIX + rp1.Id, RATING_PLAN_PREFIX + rp2.Id},
[]string{RATING_PROFILE_PREFIX + danRpfl.Id, RATING_PROFILE_PREFIX + rifRpfl.Id},
[]string{},
[]string{LCR_PREFIX + lcrSet.GetId()}); err != nil {
t.Error(err)
}
cd := &CallDescriptor{
TimeStart: time.Date(2015, 04, 06, 17, 40, 0, 0, time.UTC),
TimeEnd: time.Date(2015, 04, 06, 17, 41, 0, 0, time.UTC),
Tenant: "cgrates.org",
Direction: utils.OUT,
Category: "call",
Destination: "+4986517174963",
Account: "dan",
Subject: "dan",
}
eLcr := &LCRCost{
Entry: &LCREntry{DestinationId: utils.ANY, RPCategory: "call", Strategy: LCR_STRATEGY_STATIC, StrategyParams: "dan;rif", Weight: 10.0},
SupplierCosts: []*LCRSupplierCost{
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:dan", Cost: 0.6, Duration: "60s"},
&LCRSupplierCost{Supplier: "*out:cgrates.org:call:rif", Cost: 1.2, Duration: "60s"},
},
}
var lcr LCRCost
if err := rsponder.GetLCR(cd, &lcr); err != nil {
t.Error(err)
} else if !reflect.DeepEqual(eLcr, lcr) {
t.Errorf("Received: %+v", lcr)
}
}
*/

View File

@@ -34,8 +34,7 @@ func NewMySQLStorage(host, port, name, user, password string, maxConn, maxIdleCo
if err != nil {
return nil, err
}
err = db.DB().Ping()
if err != nil {
if err = db.DB().Ping(); err != nil {
return nil, err
}
db.DB().SetMaxIdleConns(maxIdleConn)

View File

@@ -139,14 +139,14 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys []s
Logger.Info("Finished rating profile caching.")
}
if lcrKeys == nil {
Logger.Info("Caching LCRs")
Logger.Info("Caching LCR rules.")
if lcrKeys, err = rs.db.Keys(LCR_PREFIX + "*"); err != nil {
cache2go.RollbackTransaction()
return err
}
cache2go.RemPrefixKey(LCR_PREFIX)
} else if len(lcrKeys) != 0 {
Logger.Info(fmt.Sprintf("Caching LCR: %v", lcrKeys))
Logger.Info(fmt.Sprintf("Caching LCR rules: %v", lcrKeys))
}
for _, key := range lcrKeys {
cache2go.RemKey(key)
@@ -156,7 +156,7 @@ func (rs *RedisStorage) CacheRating(dKeys, rpKeys, rpfKeys, alsKeys, lcrKeys []s
}
}
if len(lcrKeys) != 0 {
Logger.Info("Finished rating profile caching.")
Logger.Info("Finished LCR rules caching.")
}
if alsKeys == nil {
Logger.Info("Caching all rating subject aliases.")