mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
When use LoadRatingPlan API check if the destination exists in dataDB in case is missing from storDB
This commit is contained in:
committed by
Dan Christian Bogos
parent
04a6e94a23
commit
2bd94dffdd
@@ -60,6 +60,8 @@ var (
|
||||
testAPIerGetActionPlanIDs,
|
||||
testAPIerGetRatingPlanIDs,
|
||||
testAPIerSetActionPlanDfltTime,
|
||||
testAPIerLoadRatingPlan,
|
||||
testAPIerLoadRatingPlan2,
|
||||
testAPIerKillEngine,
|
||||
}
|
||||
)
|
||||
@@ -419,6 +421,92 @@ func testAPIerSetActionPlanDfltTime(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testAPIerLoadRatingPlan(t *testing.T) {
|
||||
attrs := utils.AttrSetDestination{Id: "DEST_CUSTOM", Prefixes: []string{"+4986517174963", "+4986517174960"}}
|
||||
var reply string
|
||||
if err := apierRPC.Call(utils.APIerSv1SetDestination, &attrs, &reply); err != nil {
|
||||
t.Error("Unexpected error", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply returned", reply)
|
||||
}
|
||||
|
||||
rt := &utils.TPRateRALs{TPid: "TP_SAMPLE", ID: "SAMPLE_RATE_ID", RateSlots: []*utils.RateSlot{
|
||||
{ConnectFee: 0, Rate: 0, RateUnit: "1s", RateIncrement: "1s", GroupIntervalStart: "0s"},
|
||||
}}
|
||||
if err := apierRPC.Call(utils.APIerSv1SetTPRate, rt, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.SetTPRate: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received when calling APIerSv1.SetTPRate: ", reply)
|
||||
}
|
||||
|
||||
dr := &utils.TPDestinationRate{TPid: "TP_SAMPLE", ID: "DR_SAMPLE_DESTINATION_RATE", DestinationRates: []*utils.DestinationRate{
|
||||
{DestinationId: "DEST_CUSTOM", RateId: "SAMPLE_RATE_ID",
|
||||
RoundingMethod: "*up", RoundingDecimals: 4},
|
||||
}}
|
||||
if err := apierRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply)
|
||||
}
|
||||
|
||||
rp := &utils.TPRatingPlan{TPid: "TP_SAMPLE", ID: "RPl_SAMPLE_RATING_PLAN",
|
||||
RatingPlanBindings: []*utils.TPRatingPlanBinding{
|
||||
{DestinationRatesId: "DR_SAMPLE_DESTINATION_RATE", TimingId: utils.META_ANY,
|
||||
Weight: 10},
|
||||
}}
|
||||
|
||||
if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply)
|
||||
}
|
||||
|
||||
if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan, &AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPl_SAMPLE_RATING_PLAN"}, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.LoadRatingPlan: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Calling APIerSv1.LoadRatingPlan got reply: ", reply)
|
||||
}
|
||||
|
||||
rpRply := new(engine.RatingPlan)
|
||||
rplnId := "RPl_SAMPLE_RATING_PLAN"
|
||||
if err := apierRPC.Call(utils.APIerSv1GetRatingPlan, &rplnId, rpRply); err != nil {
|
||||
t.Error("Got error on APIerSv1.GetRatingPlan: ", err.Error())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testAPIerLoadRatingPlan2(t *testing.T) {
|
||||
var reply string
|
||||
|
||||
dr := &utils.TPDestinationRate{TPid: "TP_SAMPLE", ID: "DR_WITH_ERROR", DestinationRates: []*utils.DestinationRate{
|
||||
{DestinationId: "DST_NOT_FOUND", RateId: "SAMPLE_RATE_ID",
|
||||
RoundingMethod: "*up", RoundingDecimals: 4},
|
||||
}}
|
||||
if err := apierRPC.Call(utils.APIerSv1SetTPDestinationRate, dr, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.SetTPDestinationRate: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received when calling APIerSv1.SetTPDestinationRate: ", reply)
|
||||
}
|
||||
|
||||
rp := &utils.TPRatingPlan{TPid: "TP_SAMPLE", ID: "RPL_WITH_ERROR",
|
||||
RatingPlanBindings: []*utils.TPRatingPlanBinding{
|
||||
{DestinationRatesId: "DR_WITH_ERROR", TimingId: utils.META_ANY,
|
||||
Weight: 10},
|
||||
}}
|
||||
|
||||
if err := apierRPC.Call(utils.APIerSv1SetTPRatingPlan, rp, &reply); err != nil {
|
||||
t.Error("Got error on APIerSv1.SetTPRatingPlan: ", err.Error())
|
||||
} else if reply != utils.OK {
|
||||
t.Error("Unexpected reply received when calling APIerSv1.SetTPRatingPlan: ", reply)
|
||||
}
|
||||
|
||||
if err := apierRPC.Call(utils.APIerSv1LoadRatingPlan,
|
||||
&AttrLoadRatingPlan{TPid: "TP_SAMPLE", RatingPlanId: "RPL_WITH_ERROR"}, &reply); err == nil {
|
||||
t.Error("Expected to get error: ", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func testAPIerKillEngine(t *testing.T) {
|
||||
if err := engine.KillEngine(*waitRater); err != nil {
|
||||
t.Error(err)
|
||||
|
||||
@@ -262,26 +262,28 @@ func (tpr *TpReader) LoadRatingPlansFiltered(tag string) (bool, error) {
|
||||
if drate.DestinationId == utils.ANY {
|
||||
continue // no need of loading the destinations in this case
|
||||
}
|
||||
|
||||
tpDests, err := tpr.lr.GetTPDestinations(tpr.tpid, drate.DestinationId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
if err.Error() == utils.ErrNotFound.Error() { // if the destination doesn't exists in stordb check it in dataDB
|
||||
if tpr.dm.dataDB != nil {
|
||||
if dbExists, err := tpr.dm.HasData(utils.DESTINATION_PREFIX, drate.DestinationId, ""); err != nil {
|
||||
return false, err
|
||||
} else if dbExists {
|
||||
continue
|
||||
} else if !dbExists { // if the error doesn't exists in datadb return error
|
||||
return false, fmt.Errorf("could not get destination for tag %v", drate.DestinationId)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
dms := make([]*Destination, len(tpDests))
|
||||
for i, tpDst := range tpDests {
|
||||
dms[i] = NewDestinationFromTPDestination(tpDst)
|
||||
}
|
||||
destsExist := len(dms) != 0
|
||||
if !destsExist && tpr.dm.dataDB != nil {
|
||||
if dbExists, err := tpr.dm.HasData(utils.DESTINATION_PREFIX, drate.DestinationId, ""); err != nil {
|
||||
return false, err
|
||||
} else if dbExists {
|
||||
destsExist = true
|
||||
}
|
||||
continue
|
||||
}
|
||||
if !destsExist {
|
||||
return false, fmt.Errorf("could not get destination for tag %v", drate.DestinationId)
|
||||
}
|
||||
for _, destination := range dms {
|
||||
tpr.dm.SetDestination(destination, utils.NonTransactional)
|
||||
tpr.dm.SetReverseDestination(destination, utils.NonTransactional)
|
||||
|
||||
Reference in New Issue
Block a user