Skip to content

Commit

Permalink
Add functionality for RemoveRateProfileRates in LoaderS
Browse files Browse the repository at this point in the history
  • Loading branch information
TeoV committed Jul 2, 2020
1 parent d77f5ab commit 64db8af
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 11 additions & 0 deletions loaders/libloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ func (ld LoaderData) TenantIDStruct() utils.TenantID {
}
}

func (ld LoaderData) GetRateIDs() ([]string, error) {
if _, has := ld[utils.RateIDs]; !has {
return nil, fmt.Errorf("cannot find RateIDs in <%+v>", ld)
}
if rateIDs, canCast := ld[utils.RateIDs].([]string); !canCast {
return nil, fmt.Errorf("cannot cast <%+v> to []string", ld)
} else {
return rateIDs, nil
}
}

// UpdateFromCSV will update LoaderData with data received from fileName,
// contained in record and processed with cfgTpl
func (ld LoaderData) UpdateFromCSV(fileName string, record []string,
Expand Down
21 changes: 17 additions & 4 deletions loaders/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa
}
}
case utils.MetaRateProfiles:
for tntID, _ := range lds {
for tntID, ldData := range lds {
if ldr.dryRun {
utils.Logger.Info(
fmt.Sprintf("<%s-%s> DRY_RUN: RateProfileIDs: %s",
Expand All @@ -889,10 +889,23 @@ func (ldr *Loader) removeLoadedData(loaderType string, lds map[string][]LoaderDa
tntIDStruct := utils.NewTenantID(tntID)
// get IDs so we can reload in cache
ids = append(ids, tntID)
if err := ldr.dm.RemoveRateProfile(tntIDStruct.Tenant,
tntIDStruct.ID, utils.NonTransactional, true); err != nil {
return err

if ldr.flagsTpls[loaderType].GetBool(utils.MetaPartial) {
if rateIDs, err := ldData[0].GetRateIDs(); err != nil {
return err
} else {
if err := ldr.dm.RemoveRateProfileRates(tntIDStruct.Tenant,
tntIDStruct.ID, rateIDs, true); err != nil {
return err
}
}
} else {
if err := ldr.dm.RemoveRateProfile(tntIDStruct.Tenant,
tntIDStruct.ID, utils.NonTransactional, true); err != nil {
return err
}
}

cacheArgs.RateProfileIDs = ids
cachePartition = utils.CacheRateProfiles
}
Expand Down
1 change: 1 addition & 0 deletions utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ const (
RoundingDecimals = "RoundingDecimals"
MaxCostStrategy = "MaxCostStrategy"
RateID = "RateID"
RateIDs = "RateIDs"
RateFilterIDs = "RateFilterIDs"
RateActivationStart = "RateActivationStart"
RateWeight = "RateWeight"
Expand Down

0 comments on commit 64db8af

Please sign in to comment.