Various bug fixups, LoadRatingProfileFiltered loads now also RatingPlan if defined

This commit is contained in:
DanB
2013-11-25 13:22:53 +01:00
parent ade79936b5
commit d3ddffd55e
14 changed files with 50 additions and 30 deletions

View File

@@ -156,11 +156,11 @@ func (self *ApierV1) SetRatingPlan(attrs AttrSetRatingPlan, reply *string) error
return fmt.Errorf("%s:%v", utils.ERR_MANDATORY_IE_MISSING, missing)
}
dbReader := engine.NewDbReader(self.StorDb, self.DataDb, attrs.TPid)
if err := dbReader.LoadRatingPlanByTag(attrs.RatingPlanId); err != nil {
if loaded, err := dbReader.LoadRatingPlanByTag(attrs.RatingPlanId); err != nil {
return fmt.Errorf("%s:%s", utils.ERR_SERVER_ERROR, err.Error())
} else if !loaded {
return errors.New("NOT_FOUND")
}
*reply = OK
return nil
}

View File

@@ -729,3 +729,11 @@ func TestApierLoadTariffPlanFromFolder(t *testing.T) {
t.Error("Calling ApierV1.LoadTariffPlanFromFolder got reply: ", reply)
}
}
// Simply kill the engine after we are done with tests within this file
func TestStopEngine(t *testing.T) {
if !*testLocal {
return
}
exec.Command("pkill", "cgr-engine").Run()
}

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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
@@ -52,7 +52,7 @@ func (self *CmdSetAccountActions) FromArgs(args []string) error {
}
// Args look OK, set defaults before going further
self.defaults()
self.rpcParams = &utils.TPAccountActions{TPid: args[2], LoadId: args[3], Tenant: args[4], Account: args[5], Direction:"*out"}
self.rpcParams = &utils.TPAccountActions{TPid: args[2], LoadId: args[3], Tenant: args[4], Account: args[5], Direction: "*out"}
return nil
}

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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
@@ -52,7 +52,7 @@ func (self *CmdSetrRatingProfile) FromArgs(args []string) error {
}
// Args look OK, set defaults before going further
self.defaults()
self.rpcParams = &utils.TPRatingProfile{TPid: args[2], LoadId: args[3], Tenant: args[4], TOR: args[5], Direction: "*out"}
self.rpcParams = &utils.TPRatingProfile{TPid: args[2], LoadId: args[3], Tenant: args[4], TOR: args[5], Direction: "*out", Subject: args[6]}
return nil
}

View File

@@ -1,6 +1,6 @@
/*
Rating system designed to be used in VoIP Carriers World
Copyright (C) 2013 ITsysCOM
Copyright (C) 2013 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

View File

@@ -241,10 +241,13 @@ func (dbr *DbReader) LoadRatingProfiles() error {
return nil
}
func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
// Returns true, nil in case of load success, false, nil in case of RatingPlan not found in storDb
func (dbr *DbReader) LoadRatingPlanByTag(tag string) (bool, error) {
mpRpls, err := dbr.storDb.GetTpRatingPlans(dbr.tpid, tag)
if err != nil || len(mpRpls) == 0 {
return fmt.Errorf("No RatingPlan profile with id %s: %v", tag, err)
if err != nil {
return false, err
} else if len(mpRpls) == 0 {
return false, nil
}
for tag, rplBnds := range mpRpls {
ratingPlan := &RatingPlan{Id: tag}
@@ -253,18 +256,18 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
tm, err := dbr.storDb.GetTpTimings(dbr.tpid, rp.TimingId)
Logger.Debug(fmt.Sprintf("Timing: %v", tm))
if err != nil || len(tm) == 0 {
return fmt.Errorf("No Timings profile with id %s: %v", rp.TimingId, err)
return false, fmt.Errorf("No Timings profile with id %s: %v", rp.TimingId, err)
}
rp.SetTiming(tm[rp.TimingId])
drm, err := dbr.storDb.GetTpDestinationRates(dbr.tpid, rp.DestinationRatesId)
if err != nil || len(drm) == 0 {
return fmt.Errorf("No DestinationRates profile with id %s: %v", rp.DestinationRatesId, err)
return false, fmt.Errorf("No DestinationRates profile with id %s: %v", rp.DestinationRatesId, err)
}
for _, drate := range drm[rp.DestinationRatesId].DestinationRates {
Logger.Debug(fmt.Sprintf("Destination rate: %v", drate))
rt, err := dbr.storDb.GetTpRates(dbr.tpid, drate.RateId)
if err != nil || len(rt) == 0 {
return fmt.Errorf("No Rates profile with id %s: %v", drate.RateId, err)
return false, fmt.Errorf("No Rates profile with id %s: %v", drate.RateId, err)
}
Logger.Debug(fmt.Sprintf("Rate: %v", rt))
drate.Rate = rt[drate.RateId]
@@ -272,12 +275,12 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
dms, err := dbr.storDb.GetTpDestinations(dbr.tpid, drate.DestinationId)
if err != nil {
return err
return false, err
} else if len(dms) == 0 {
if dbExists, err := dbr.dataDb.ExistsData(DESTINATION_PREFIX, drate.DestinationId); err != nil {
return err
return false, err
} else if !dbExists {
return fmt.Errorf("Could not get destination for tag %v", drate.DestinationId)
return false, fmt.Errorf("Could not get destination for tag %v", drate.DestinationId)
}
continue
}
@@ -289,10 +292,10 @@ func (dbr *DbReader) LoadRatingPlanByTag(tag string) error {
}
}
if err := dbr.dataDb.SetRatingPlan(ratingPlan); err != nil {
return err
return false, err
}
}
return nil
return true, nil
}
func (dbr *DbReader) LoadRatingProfileFiltered(qriedRpf *utils.TPRatingProfile) error {
@@ -310,11 +313,15 @@ func (dbr *DbReader) LoadRatingProfileFiltered(qriedRpf *utils.TPRatingProfile)
return errors.New(fmt.Sprintf("Cannot parse activation time from %v", tpRa.ActivationTime))
}
_, exists := dbr.ratingPlans[tpRa.RatingPlanId]
if !exists {
if dbExists, err := dbr.dataDb.ExistsData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
if !exists { // Try loading locally, on errrors, give up
if loaded, err := dbr.LoadRatingPlanByTag(tpRa.RatingPlanId); err != nil {
return err
} else if !dbExists {
return errors.New(fmt.Sprintf("Could not load rating plans for tag: %v", tpRa.RatingPlanId))
} else if !loaded { // Not found
if dbExists, err := dbr.dataDb.ExistsData(RATING_PLAN_PREFIX, tpRa.RatingPlanId); err != nil {
return err
} else if !dbExists {
return errors.New(fmt.Sprintf("Could not load rating plans for tag: %v", tpRa.RatingPlanId))
}
}
}
resultRatingProfile.RatingPlanActivations = append(resultRatingProfile.RatingPlanActivations,

View File

@@ -219,8 +219,10 @@ func TestLoadIndividualProfiles(t *testing.T) {
t.Fatal("Could not retrieve rating plans")
} else {
for tag := range ratingPlans {
if err := loader.LoadRatingPlanByTag(tag); err != nil {
if loaded, err := loader.LoadRatingPlanByTag(tag); err != nil {
t.Fatalf("Could not load ratingPlan for tag: %s, error: %s", tag, err.Error())
} else if !loaded {
t.Fatal("Cound not find ratingPLan with id:", tag)
}
}
}

View File

@@ -215,6 +215,9 @@ func (rs *RedisStorage) GetDestination(key string) (dest *Destination, err error
func (rs *RedisStorage) SetDestination(dest *Destination) (err error) {
result, err := rs.ms.Marshal(dest)
if err != nil {
return err
}
var b bytes.Buffer
w := zlib.NewWriter(&b)
w.Write(result)