diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 0088e0c45..f3ae04f73 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -796,26 +796,26 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, // create the TpReader loader := engine.NewTpReader(self.DataManager.DataDB(), engine.NewFileCSVStorage(utils.CSV_SEP, - path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV), - path.Join(attrs.FolderPath, utils.TIMINGS_CSV), - path.Join(attrs.FolderPath, utils.RATES_CSV), - path.Join(attrs.FolderPath, utils.DESTINATION_RATES_CSV), - path.Join(attrs.FolderPath, utils.RATING_PLANS_CSV), - path.Join(attrs.FolderPath, utils.RATING_PROFILES_CSV), - path.Join(attrs.FolderPath, utils.SHARED_GROUPS_CSV), - path.Join(attrs.FolderPath, utils.ACTIONS_CSV), - path.Join(attrs.FolderPath, utils.ACTION_PLANS_CSV), - path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV), - path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV), - path.Join(attrs.FolderPath, utils.ResourcesCsv), - path.Join(attrs.FolderPath, utils.StatsCsv), - path.Join(attrs.FolderPath, utils.ThresholdsCsv), - path.Join(attrs.FolderPath, utils.FiltersCsv), - path.Join(attrs.FolderPath, utils.SuppliersCsv), - path.Join(attrs.FolderPath, utils.AttributesCsv), - path.Join(attrs.FolderPath, utils.ChargersCsv), - path.Join(attrs.FolderPath, utils.DispatcherProfilesCsv), - path.Join(attrs.FolderPath, utils.DispatcherHostsCsv), + []string{path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.TIMINGS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.RATES_CSV)}, + []string{path.Join(attrs.FolderPath, utils.DESTINATION_RATES_CSV)}, + []string{path.Join(attrs.FolderPath, utils.RATING_PLANS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.RATING_PROFILES_CSV)}, + []string{path.Join(attrs.FolderPath, utils.SHARED_GROUPS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACTIONS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACTION_PLANS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ResourcesCsv)}, + []string{path.Join(attrs.FolderPath, utils.StatsCsv)}, + []string{path.Join(attrs.FolderPath, utils.ThresholdsCsv)}, + []string{path.Join(attrs.FolderPath, utils.FiltersCsv)}, + []string{path.Join(attrs.FolderPath, utils.SuppliersCsv)}, + []string{path.Join(attrs.FolderPath, utils.AttributesCsv)}, + []string{path.Join(attrs.FolderPath, utils.ChargersCsv)}, + []string{path.Join(attrs.FolderPath, utils.DispatcherProfilesCsv)}, + []string{path.Join(attrs.FolderPath, utils.DispatcherHostsCsv)}, ), "", self.Config.GeneralCfg().DefaultTimezone, self.CacheS, self.SchedulerS) //Load the data diff --git a/apier/v2/apier.go b/apier/v2/apier.go index d4f4735f6..e9560594c 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -108,26 +108,26 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, } loader := engine.NewTpReader(self.DataManager.DataDB(), engine.NewFileCSVStorage(utils.CSV_SEP, - path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV), - path.Join(attrs.FolderPath, utils.TIMINGS_CSV), - path.Join(attrs.FolderPath, utils.RATES_CSV), - path.Join(attrs.FolderPath, utils.DESTINATION_RATES_CSV), - path.Join(attrs.FolderPath, utils.RATING_PLANS_CSV), - path.Join(attrs.FolderPath, utils.RATING_PROFILES_CSV), - path.Join(attrs.FolderPath, utils.SHARED_GROUPS_CSV), - path.Join(attrs.FolderPath, utils.ACTIONS_CSV), - path.Join(attrs.FolderPath, utils.ACTION_PLANS_CSV), - path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV), - path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV), - path.Join(attrs.FolderPath, utils.ResourcesCsv), - path.Join(attrs.FolderPath, utils.StatsCsv), - path.Join(attrs.FolderPath, utils.ThresholdsCsv), - path.Join(attrs.FolderPath, utils.FiltersCsv), - path.Join(attrs.FolderPath, utils.SuppliersCsv), - path.Join(attrs.FolderPath, utils.AttributesCsv), - path.Join(attrs.FolderPath, utils.ChargersCsv), - path.Join(attrs.FolderPath, utils.DispatcherProfilesCsv), - path.Join(attrs.FolderPath, utils.DispatcherHostsCsv), + []string{path.Join(attrs.FolderPath, utils.DESTINATIONS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.TIMINGS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.RATES_CSV)}, + []string{path.Join(attrs.FolderPath, utils.DESTINATION_RATES_CSV)}, + []string{path.Join(attrs.FolderPath, utils.RATING_PLANS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.RATING_PROFILES_CSV)}, + []string{path.Join(attrs.FolderPath, utils.SHARED_GROUPS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACTIONS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACTION_PLANS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV)}, + []string{path.Join(attrs.FolderPath, utils.ResourcesCsv)}, + []string{path.Join(attrs.FolderPath, utils.StatsCsv)}, + []string{path.Join(attrs.FolderPath, utils.ThresholdsCsv)}, + []string{path.Join(attrs.FolderPath, utils.FiltersCsv)}, + []string{path.Join(attrs.FolderPath, utils.SuppliersCsv)}, + []string{path.Join(attrs.FolderPath, utils.AttributesCsv)}, + []string{path.Join(attrs.FolderPath, utils.ChargersCsv)}, + []string{path.Join(attrs.FolderPath, utils.DispatcherProfilesCsv)}, + []string{path.Join(attrs.FolderPath, utils.DispatcherHostsCsv)}, ), "", self.Config.GeneralCfg().DefaultTimezone, self.CacheS, self.SchedulerS) if err := loader.LoadAll(); err != nil { diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index 10c61b1d9..144d4954b 100755 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -24,6 +24,7 @@ import ( "log" "os" "path" + "path/filepath" "strings" "time" @@ -83,6 +84,7 @@ var ( "When true will not save loaded data to dataDb but just parse it for consistency and errors.") fieldSep = cgrLoaderFlags.String("field_sep", ",", `Separator for csv file (by default "," is used)`) + recursive = cgrLoaderFlags.Bool("recursive", false, "Loads data from folder recursive.") fromStorDB = cgrLoaderFlags.Bool("from_stordb", false, "Load the tariff plan from storDb to dataDb") toStorDB = cgrLoaderFlags.Bool("to_stordb", false, "Import the tariff plan from files to storDb") @@ -107,6 +109,27 @@ var ( loader engine.LoadReader ) +func getAllFolders(inPath string) (paths []string, err error) { + err = filepath.Walk(inPath, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if info.IsDir() { + paths = append(paths, path) + } + return nil + }) + return +} + +func appendName(paths []string, fileName string) (out []string) { + out = make([]string, len(paths)) + for i, path_ := range paths { + out[i] = path.Join(path_, fileName) + } + return +} + func main() { if err := cgrLoaderFlags.Parse(os.Args[1:]); err != nil { return @@ -284,27 +307,76 @@ func main() { if *fromStorDB { // Load Tariff Plan from storDb into dataDb loader = storDb } else { // Default load from csv files to dataDb + + destinations_paths := []string{path.Join(*dataPath, utils.DESTINATIONS_CSV)} + timings_paths := []string{path.Join(*dataPath, utils.TIMINGS_CSV)} + rates_paths := []string{path.Join(*dataPath, utils.RATES_CSV)} + destination_rates_paths := []string{path.Join(*dataPath, utils.DESTINATION_RATES_CSV)} + rating_plans_paths := []string{path.Join(*dataPath, utils.RATING_PLANS_CSV)} + rating_profiles_paths := []string{path.Join(*dataPath, utils.RATING_PROFILES_CSV)} + shared_groups_paths := []string{path.Join(*dataPath, utils.SHARED_GROUPS_CSV)} + actions_paths := []string{path.Join(*dataPath, utils.ACTIONS_CSV)} + action_plans_paths := []string{path.Join(*dataPath, utils.ACTION_PLANS_CSV)} + action_triggers_paths := []string{path.Join(*dataPath, utils.ACTION_TRIGGERS_CSV)} + account_actions_paths := []string{path.Join(*dataPath, utils.ACCOUNT_ACTIONS_CSV)} + resources_paths := []string{path.Join(*dataPath, utils.ResourcesCsv)} + stats_paths := []string{path.Join(*dataPath, utils.StatsCsv)} + thresholds_paths := []string{path.Join(*dataPath, utils.ThresholdsCsv)} + filters_paths := []string{path.Join(*dataPath, utils.FiltersCsv)} + suppliers_paths := []string{path.Join(*dataPath, utils.SuppliersCsv)} + attributes_paths := []string{path.Join(*dataPath, utils.AttributesCsv)} + chargers_paths := []string{path.Join(*dataPath, utils.ChargersCsv)} + dispatcherprofiles_paths := []string{path.Join(*dataPath, utils.DispatcherProfilesCsv)} + dispatcherhosts_paths := []string{path.Join(*dataPath, utils.DispatcherHostsCsv)} + + if *recursive { + allFoldersPath, err := getAllFolders(*dataPath) + if err != nil { + log.Fatal(err) + } + destinations_paths = appendName(allFoldersPath, utils.DESTINATIONS_CSV) + timings_paths = appendName(allFoldersPath, utils.TIMINGS_CSV) + rates_paths = appendName(allFoldersPath, utils.RATES_CSV) + destination_rates_paths = appendName(allFoldersPath, utils.DESTINATION_RATES_CSV) + rating_plans_paths = appendName(allFoldersPath, utils.RATING_PLANS_CSV) + rating_profiles_paths = appendName(allFoldersPath, utils.RATING_PROFILES_CSV) + shared_groups_paths = appendName(allFoldersPath, utils.SHARED_GROUPS_CSV) + actions_paths = appendName(allFoldersPath, utils.ACTIONS_CSV) + action_plans_paths = appendName(allFoldersPath, utils.ACTION_PLANS_CSV) + action_triggers_paths = appendName(allFoldersPath, utils.ACTION_TRIGGERS_CSV) + account_actions_paths = appendName(allFoldersPath, utils.ACCOUNT_ACTIONS_CSV) + resources_paths = appendName(allFoldersPath, utils.ResourcesCsv) + stats_paths = appendName(allFoldersPath, utils.StatsCsv) + thresholds_paths = appendName(allFoldersPath, utils.ThresholdsCsv) + filters_paths = appendName(allFoldersPath, utils.FiltersCsv) + suppliers_paths = appendName(allFoldersPath, utils.SuppliersCsv) + attributes_paths = appendName(allFoldersPath, utils.AttributesCsv) + chargers_paths = appendName(allFoldersPath, utils.ChargersCsv) + dispatcherprofiles_paths = appendName(allFoldersPath, utils.DispatcherProfilesCsv) + dispatcherhosts_paths = appendName(allFoldersPath, utils.DispatcherHostsCsv) + } + loader = engine.NewFileCSVStorage(ldrCfg.LoaderCgrCfg().FieldSeparator, - path.Join(*dataPath, utils.DESTINATIONS_CSV), - path.Join(*dataPath, utils.TIMINGS_CSV), - path.Join(*dataPath, utils.RATES_CSV), - path.Join(*dataPath, utils.DESTINATION_RATES_CSV), - path.Join(*dataPath, utils.RATING_PLANS_CSV), - path.Join(*dataPath, utils.RATING_PROFILES_CSV), - path.Join(*dataPath, utils.SHARED_GROUPS_CSV), - path.Join(*dataPath, utils.ACTIONS_CSV), - path.Join(*dataPath, utils.ACTION_PLANS_CSV), - path.Join(*dataPath, utils.ACTION_TRIGGERS_CSV), - path.Join(*dataPath, utils.ACCOUNT_ACTIONS_CSV), - path.Join(*dataPath, utils.ResourcesCsv), - path.Join(*dataPath, utils.StatsCsv), - path.Join(*dataPath, utils.ThresholdsCsv), - path.Join(*dataPath, utils.FiltersCsv), - path.Join(*dataPath, utils.SuppliersCsv), - path.Join(*dataPath, utils.AttributesCsv), - path.Join(*dataPath, utils.ChargersCsv), - path.Join(*dataPath, utils.DispatcherProfilesCsv), - path.Join(*dataPath, utils.DispatcherHostsCsv), + destinations_paths, + timings_paths, + rates_paths, + destination_rates_paths, + rating_plans_paths, + rating_profiles_paths, + shared_groups_paths, + actions_paths, + action_plans_paths, + action_triggers_paths, + account_actions_paths, + resources_paths, + stats_paths, + thresholds_paths, + filters_paths, + suppliers_paths, + attributes_paths, + chargers_paths, + dispatcherprofiles_paths, + dispatcherhosts_paths, ) } diff --git a/engine/libtest.go b/engine/libtest.go index edc1d5a18..4d507807e 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -127,27 +127,27 @@ func StopStartEngine(cfgPath string, waitEngine int) (*exec.Cmd, error) { func LoadTariffPlanFromFolder(tpPath, timezone string, dm *DataManager, disable_reverse bool, cacheS rpcclient.RpcClientConnection, schedulerS rpcclient.RpcClientConnection) error { loader := NewTpReader(dm.dataDB, NewFileCSVStorage(utils.CSV_SEP, - path.Join(tpPath, utils.DESTINATIONS_CSV), - path.Join(tpPath, utils.TIMINGS_CSV), - path.Join(tpPath, utils.RATES_CSV), - path.Join(tpPath, utils.DESTINATION_RATES_CSV), - path.Join(tpPath, utils.RATING_PLANS_CSV), - path.Join(tpPath, utils.RATING_PROFILES_CSV), - path.Join(tpPath, utils.SHARED_GROUPS_CSV), - path.Join(tpPath, utils.ACTIONS_CSV), - path.Join(tpPath, utils.ACTION_PLANS_CSV), - path.Join(tpPath, utils.ACTION_TRIGGERS_CSV), - path.Join(tpPath, utils.ACCOUNT_ACTIONS_CSV), + []string{path.Join(tpPath, utils.DESTINATIONS_CSV)}, + []string{path.Join(tpPath, utils.TIMINGS_CSV)}, + []string{path.Join(tpPath, utils.RATES_CSV)}, + []string{path.Join(tpPath, utils.DESTINATION_RATES_CSV)}, + []string{path.Join(tpPath, utils.RATING_PLANS_CSV)}, + []string{path.Join(tpPath, utils.RATING_PROFILES_CSV)}, + []string{path.Join(tpPath, utils.SHARED_GROUPS_CSV)}, + []string{path.Join(tpPath, utils.ACTIONS_CSV)}, + []string{path.Join(tpPath, utils.ACTION_PLANS_CSV)}, + []string{path.Join(tpPath, utils.ACTION_TRIGGERS_CSV)}, + []string{path.Join(tpPath, utils.ACCOUNT_ACTIONS_CSV)}, - path.Join(tpPath, utils.ResourcesCsv), - path.Join(tpPath, utils.StatsCsv), - path.Join(tpPath, utils.ThresholdsCsv), - path.Join(tpPath, utils.FiltersCsv), - path.Join(tpPath, utils.SuppliersCsv), - path.Join(tpPath, utils.AttributesCsv), - path.Join(tpPath, utils.ChargersCsv), - path.Join(tpPath, utils.DispatcherProfilesCsv), - path.Join(tpPath, utils.DispatcherHostsCsv), + []string{path.Join(tpPath, utils.ResourcesCsv)}, + []string{path.Join(tpPath, utils.StatsCsv)}, + []string{path.Join(tpPath, utils.ThresholdsCsv)}, + []string{path.Join(tpPath, utils.FiltersCsv)}, + []string{path.Join(tpPath, utils.SuppliersCsv)}, + []string{path.Join(tpPath, utils.AttributesCsv)}, + []string{path.Join(tpPath, utils.ChargersCsv)}, + []string{path.Join(tpPath, utils.DispatcherProfilesCsv)}, + []string{path.Join(tpPath, utils.DispatcherHostsCsv)}, ), "", timezone, cacheS, schedulerS) if err := loader.LoadAll(); err != nil { return utils.NewErrServerError(err) diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go index 3f786569a..4705eb97f 100644 --- a/engine/loader_it_test.go +++ b/engine/loader_it_test.go @@ -96,26 +96,26 @@ func TestLoaderITRemoveLoad(t *testing.T) { } }*/ loader = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSV_SEP, - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATIONS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.TIMINGS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATES_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATION_RATES_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PLANS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PROFILES_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SHARED_GROUPS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTIONS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_PLANS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ResourcesCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.FiltersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherProfilesCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv), + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATIONS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.TIMINGS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATES_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATION_RATES_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PLANS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PROFILES_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SHARED_GROUPS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTIONS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_PLANS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ResourcesCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.FiltersCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherProfilesCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv)}, ), "", "", nil, nil) if err = loader.LoadDestinations(); err != nil { @@ -192,26 +192,26 @@ func TestLoaderITLoadFromCSV(t *testing.T) { } }*/ loader = NewTpReader(dataDbCsv.DataDB(), NewFileCSVStorage(utils.CSV_SEP, - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATIONS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.TIMINGS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATES_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATION_RATES_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PLANS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PROFILES_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SHARED_GROUPS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTIONS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_PLANS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ResourcesCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.FiltersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherProfilesCsv), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv), + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATIONS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.TIMINGS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATES_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DESTINATION_RATES_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PLANS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.RATING_PROFILES_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SHARED_GROUPS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTIONS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_PLANS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ResourcesCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.FiltersCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.SuppliersCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.AttributesCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ChargersCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherProfilesCsv)}, + []string{path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DispatcherHostsCsv)}, ), "", "", nil, nil) if err = loader.LoadDestinations(); err != nil { diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 648e9c594..fcf07b6b5 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -32,26 +32,26 @@ type CSVStorage struct { sep rune readerFunc func(string, rune, int) (*csv.Reader, *os.File, error) // file names - destinationsFn string - ratesFn string - destinationratesFn string - timingsFn string - destinationratetimingsFn string - ratingprofilesFn string - sharedgroupsFn string - actionsFn string - actiontimingsFn string - actiontriggersFn string - accountactionsFn string - resProfilesFn string - statsFn string - thresholdsFn string - filterFn string - suppProfilesFn string - attributeProfilesFn string - chargerProfilesFn string - dispatcherProfilesFn string - dispatcherHostsFn string + destinationsFn []string + ratesFn []string + destinationratesFn []string + timingsFn []string + destinationratetimingsFn []string + ratingprofilesFn []string + sharedgroupsFn []string + actionsFn []string + actiontimingsFn []string + actiontriggersFn []string + accountactionsFn []string + resProfilesFn []string + statsFn []string + thresholdsFn []string + filterFn []string + suppProfilesFn []string + attributeProfilesFn []string + chargerProfilesFn []string + dispatcherProfilesFn []string + dispatcherHostsFn []string } func NewFileCSVStorage(sep rune, @@ -60,7 +60,7 @@ func NewFileCSVStorage(sep rune, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn, resProfilesFn, statsFn, thresholdsFn, filterFn, suppProfilesFn, attributeProfilesFn, - chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn string) *CSVStorage { + chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn []string) *CSVStorage { return &CSVStorage{ sep: sep, readerFunc: openFileCSVStorage, @@ -95,13 +95,13 @@ func NewStringCSVStorage(sep rune, thresholdsFn, filterFn, suppProfilesFn, attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn, dispatcherHostsFn string) *CSVStorage { - c := NewFileCSVStorage(sep, destinationsFn, timingsFn, - ratesFn, destinationratesFn, destinationratetimingsFn, - ratingprofilesFn, sharedgroupsFn, actionsFn, - actiontimingsFn, actiontriggersFn, accountactionsFn, - resProfilesFn, statsFn, thresholdsFn, filterFn, - suppProfilesFn, attributeProfilesFn, chargerProfilesFn, - dispatcherProfilesFn, dispatcherHostsFn) + c := NewFileCSVStorage(sep, []string{destinationsFn}, []string{timingsFn}, + []string{ratesFn}, []string{destinationratesFn}, []string{destinationratetimingsFn}, + []string{ratingprofilesFn}, []string{sharedgroupsFn}, []string{actionsFn}, + []string{actiontimingsFn}, []string{actiontriggersFn}, []string{accountactionsFn}, + []string{resProfilesFn}, []string{statsFn}, []string{thresholdsFn}, []string{filterFn}, + []string{suppProfilesFn}, []string{attributeProfilesFn}, []string{chargerProfilesFn}, + []string{dispatcherProfilesFn}, []string{dispatcherHostsFn}) c.readerFunc = openStringCSVStorage return c } @@ -164,7 +164,7 @@ func (csvs *CSVStorage) proccesData(listType interface{}, fns []string, process func (csvs *CSVStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, error) { var tpTimings TpTimings - if err := csvs.proccesData(TpTiming{}, []string{csvs.timingsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpTiming{}, csvs.timingsFn, func(tp interface{}) { tm := tp.(TpTiming) tm.Tpid = tpid tpTimings = append(tpTimings, tm) @@ -176,7 +176,7 @@ func (csvs *CSVStorage) GetTPTimings(tpid, id string) ([]*utils.ApierTPTiming, e func (csvs *CSVStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestination, error) { var tpDests TpDestinations - if err := csvs.proccesData(TpDestination{}, []string{csvs.destinationsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpDestination{}, csvs.destinationsFn, func(tp interface{}) { d := tp.(TpDestination) d.Tpid = tpid tpDests = append(tpDests, d) @@ -188,7 +188,7 @@ func (csvs *CSVStorage) GetTPDestinations(tpid, id string) ([]*utils.TPDestinati func (csvs *CSVStorage) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { var tpRates TpRates - if err := csvs.proccesData(TpRate{}, []string{csvs.ratesFn}, func(tp interface{}) { + if err := csvs.proccesData(TpRate{}, csvs.ratesFn, func(tp interface{}) { r := tp.(TpRate) r.Tpid = tpid tpRates = append(tpRates, r) @@ -200,7 +200,7 @@ func (csvs *CSVStorage) GetTPRates(tpid, id string) ([]*utils.TPRate, error) { func (csvs *CSVStorage) GetTPDestinationRates(tpid, id string, p *utils.Paginator) ([]*utils.TPDestinationRate, error) { var tpDestinationRates TpDestinationRates - if err := csvs.proccesData(TpDestinationRate{}, []string{csvs.destinationratesFn}, func(tp interface{}) { + if err := csvs.proccesData(TpDestinationRate{}, csvs.destinationratesFn, func(tp interface{}) { dr := tp.(TpDestinationRate) dr.Tpid = tpid tpDestinationRates = append(tpDestinationRates, dr) @@ -212,7 +212,7 @@ func (csvs *CSVStorage) GetTPDestinationRates(tpid, id string, p *utils.Paginato func (csvs *CSVStorage) GetTPRatingPlans(tpid, id string, p *utils.Paginator) ([]*utils.TPRatingPlan, error) { var tpRatingPlans TpRatingPlans - if err := csvs.proccesData(TpRatingPlan{}, []string{csvs.destinationratetimingsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpRatingPlan{}, csvs.destinationratetimingsFn, func(tp interface{}) { rp := tp.(TpRatingPlan) rp.Tpid = tpid tpRatingPlans = append(tpRatingPlans, rp) @@ -224,7 +224,7 @@ func (csvs *CSVStorage) GetTPRatingPlans(tpid, id string, p *utils.Paginator) ([ func (csvs *CSVStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) { var tpRatingProfiles TpRatingProfiles - if err := csvs.proccesData(TpRatingProfile{}, []string{csvs.ratingprofilesFn}, func(tp interface{}) { + if err := csvs.proccesData(TpRatingProfile{}, csvs.ratingprofilesFn, func(tp interface{}) { rpf := tp.(TpRatingProfile) if filter != nil { rpf.Tpid = filter.TPid @@ -239,7 +239,7 @@ func (csvs *CSVStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) ([]*u func (csvs *CSVStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGroups, error) { var tpSharedGroups TpSharedGroups - if err := csvs.proccesData(TpSharedGroup{}, []string{csvs.sharedgroupsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpSharedGroup{}, csvs.sharedgroupsFn, func(tp interface{}) { sg := tp.(TpSharedGroup) sg.Tpid = tpid tpSharedGroups = append(tpSharedGroups, sg) @@ -251,7 +251,7 @@ func (csvs *CSVStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro func (csvs *CSVStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error) { var tpActions TpActions - if err := csvs.proccesData(TpAction{}, []string{csvs.actionsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpAction{}, csvs.actionsFn, func(tp interface{}) { a := tp.(TpAction) a.Tpid = tpid tpActions = append(tpActions, a) @@ -263,7 +263,7 @@ func (csvs *CSVStorage) GetTPActions(tpid, id string) ([]*utils.TPActions, error func (csvs *CSVStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan, error) { var tpActionPlans TpActionPlans - if err := csvs.proccesData(TpActionPlan{}, []string{csvs.actiontimingsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpActionPlan{}, csvs.actiontimingsFn, func(tp interface{}) { ap := tp.(TpActionPlan) ap.Tpid = tpid tpActionPlans = append(tpActionPlans, ap) @@ -275,7 +275,7 @@ func (csvs *CSVStorage) GetTPActionPlans(tpid, id string) ([]*utils.TPActionPlan func (csvs *CSVStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionTriggers, error) { var tpActionTriggers TpActionTriggers - if err := csvs.proccesData(TpActionTrigger{}, []string{csvs.actiontriggersFn}, func(tp interface{}) { + if err := csvs.proccesData(TpActionTrigger{}, csvs.actiontriggersFn, func(tp interface{}) { at := tp.(TpActionTrigger) at.Tpid = tpid tpActionTriggers = append(tpActionTriggers, at) @@ -287,7 +287,7 @@ func (csvs *CSVStorage) GetTPActionTriggers(tpid, id string) ([]*utils.TPActionT func (csvs *CSVStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]*utils.TPAccountActions, error) { var tpAccountActions TpAccountActions - if err := csvs.proccesData(TpAccountAction{}, []string{csvs.accountactionsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpAccountAction{}, csvs.accountactionsFn, func(tp interface{}) { aa := tp.(TpAccountAction) if filter != nil { aa.Tpid = filter.TPid @@ -302,7 +302,7 @@ func (csvs *CSVStorage) GetTPAccountActions(filter *utils.TPAccountActions) ([]* func (csvs *CSVStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResourceProfile, error) { var tpResLimits TpResources - if err := csvs.proccesData(TpResource{}, []string{csvs.resProfilesFn}, func(tp interface{}) { + if err := csvs.proccesData(TpResource{}, csvs.resProfilesFn, func(tp interface{}) { tpLimit := tp.(TpResource) tpLimit.Tpid = tpid tpResLimits = append(tpResLimits, &tpLimit) @@ -314,7 +314,7 @@ func (csvs *CSVStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPReso func (csvs *CSVStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProfile, error) { var tpStats TpStats - if err := csvs.proccesData(TpStat{}, []string{csvs.statsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpStat{}, csvs.statsFn, func(tp interface{}) { tPstats := tp.(TpStat) tPstats.Tpid = tpid tpStats = append(tpStats, &tPstats) @@ -326,7 +326,7 @@ func (csvs *CSVStorage) GetTPStats(tpid, tenant, id string) ([]*utils.TPStatProf func (csvs *CSVStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThresholdProfile, error) { var tpThreshold TpThresholds - if err := csvs.proccesData(TpThreshold{}, []string{csvs.thresholdsFn}, func(tp interface{}) { + if err := csvs.proccesData(TpThreshold{}, csvs.thresholdsFn, func(tp interface{}) { tHresholdCfg := tp.(TpThreshold) tHresholdCfg.Tpid = tpid tpThreshold = append(tpThreshold, &tHresholdCfg) @@ -338,7 +338,7 @@ func (csvs *CSVStorage) GetTPThresholds(tpid, tenant, id string) ([]*utils.TPThr func (csvs *CSVStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilterProfile, error) { var tpFilter TpFilterS - if err := csvs.proccesData(TpFilter{}, []string{csvs.filterFn}, func(tp interface{}) { + if err := csvs.proccesData(TpFilter{}, csvs.filterFn, func(tp interface{}) { fIlterCfg := tp.(TpFilter) fIlterCfg.Tpid = tpid tpFilter = append(tpFilter, &fIlterCfg) @@ -350,7 +350,7 @@ func (csvs *CSVStorage) GetTPFilters(tpid, tenant, id string) ([]*utils.TPFilter func (csvs *CSVStorage) GetTPSuppliers(tpid, tenant, id string) ([]*utils.TPSupplierProfile, error) { var tpSPPs TpSuppliers - if err := csvs.proccesData(TpSupplier{}, []string{csvs.suppProfilesFn}, func(tp interface{}) { + if err := csvs.proccesData(TpSupplier{}, csvs.suppProfilesFn, func(tp interface{}) { suppProfile := tp.(TpSupplier) suppProfile.Tpid = tpid tpSPPs = append(tpSPPs, &suppProfile) @@ -362,7 +362,7 @@ func (csvs *CSVStorage) GetTPSuppliers(tpid, tenant, id string) ([]*utils.TPSupp func (csvs *CSVStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAttributeProfile, error) { var tpAls TPAttributes - if err := csvs.proccesData(TPAttribute{}, []string{csvs.attributeProfilesFn}, func(tp interface{}) { + if err := csvs.proccesData(TPAttribute{}, csvs.attributeProfilesFn, func(tp interface{}) { attributeProfile := tp.(TPAttribute) attributeProfile.Tpid = tpid tpAls = append(tpAls, &attributeProfile) @@ -374,7 +374,7 @@ func (csvs *CSVStorage) GetTPAttributes(tpid, tenant, id string) ([]*utils.TPAtt func (csvs *CSVStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPChargerProfile, error) { var tpCPPs TPChargers - if err := csvs.proccesData(TPCharger{}, []string{csvs.chargerProfilesFn}, func(tp interface{}) { + if err := csvs.proccesData(TPCharger{}, csvs.chargerProfilesFn, func(tp interface{}) { cpp := tp.(TPCharger) cpp.Tpid = tpid tpCPPs = append(tpCPPs, &cpp) @@ -386,7 +386,7 @@ func (csvs *CSVStorage) GetTPChargers(tpid, tenant, id string) ([]*utils.TPCharg func (csvs *CSVStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*utils.TPDispatcherProfile, error) { var tpDPPs TPDispatcherProfiles - if err := csvs.proccesData(TPDispatcherProfile{}, []string{csvs.dispatcherProfilesFn}, func(tp interface{}) { + if err := csvs.proccesData(TPDispatcherProfile{}, csvs.dispatcherProfilesFn, func(tp interface{}) { dpp := tp.(TPDispatcherProfile) dpp.Tpid = tpid tpDPPs = append(tpDPPs, &dpp) @@ -398,7 +398,7 @@ func (csvs *CSVStorage) GetTPDispatcherProfiles(tpid, tenant, id string) ([]*uti func (csvs *CSVStorage) GetTPDispatcherHosts(tpid, tenant, id string) ([]*utils.TPDispatcherHost, error) { var tpDDHs TPDispatcherHosts - if err := csvs.proccesData(TPDispatcherHost{}, []string{csvs.dispatcherHostsFn}, func(tp interface{}) { + if err := csvs.proccesData(TPDispatcherHost{}, csvs.dispatcherHostsFn, func(tp interface{}) { dpp := tp.(TPDispatcherHost) dpp.Tpid = tpid tpDDHs = append(tpDDHs, &dpp) diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 1cef509de..219325eae 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -65,26 +65,26 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{ func (self *TPCSVImporter) Run() error { self.csvr = NewFileCSVStorage(self.Sep, - path.Join(self.DirPath, utils.DESTINATIONS_CSV), - path.Join(self.DirPath, utils.TIMINGS_CSV), - path.Join(self.DirPath, utils.RATES_CSV), - path.Join(self.DirPath, utils.DESTINATION_RATES_CSV), - path.Join(self.DirPath, utils.RATING_PLANS_CSV), - path.Join(self.DirPath, utils.RATING_PROFILES_CSV), - path.Join(self.DirPath, utils.SHARED_GROUPS_CSV), - path.Join(self.DirPath, utils.ACTIONS_CSV), - path.Join(self.DirPath, utils.ACTION_PLANS_CSV), - path.Join(self.DirPath, utils.ACTION_TRIGGERS_CSV), - path.Join(self.DirPath, utils.ACCOUNT_ACTIONS_CSV), - path.Join(self.DirPath, utils.ResourcesCsv), - path.Join(self.DirPath, utils.StatsCsv), - path.Join(self.DirPath, utils.ThresholdsCsv), - path.Join(self.DirPath, utils.FiltersCsv), - path.Join(self.DirPath, utils.SuppliersCsv), - path.Join(self.DirPath, utils.AttributesCsv), - path.Join(self.DirPath, utils.ChargersCsv), - path.Join(self.DirPath, utils.DispatcherProfilesCsv), - path.Join(self.DirPath, utils.DispatcherHostsCsv), + []string{path.Join(self.DirPath, utils.DESTINATIONS_CSV)}, + []string{path.Join(self.DirPath, utils.TIMINGS_CSV)}, + []string{path.Join(self.DirPath, utils.RATES_CSV)}, + []string{path.Join(self.DirPath, utils.DESTINATION_RATES_CSV)}, + []string{path.Join(self.DirPath, utils.RATING_PLANS_CSV)}, + []string{path.Join(self.DirPath, utils.RATING_PROFILES_CSV)}, + []string{path.Join(self.DirPath, utils.SHARED_GROUPS_CSV)}, + []string{path.Join(self.DirPath, utils.ACTIONS_CSV)}, + []string{path.Join(self.DirPath, utils.ACTION_PLANS_CSV)}, + []string{path.Join(self.DirPath, utils.ACTION_TRIGGERS_CSV)}, + []string{path.Join(self.DirPath, utils.ACCOUNT_ACTIONS_CSV)}, + []string{path.Join(self.DirPath, utils.ResourcesCsv)}, + []string{path.Join(self.DirPath, utils.StatsCsv)}, + []string{path.Join(self.DirPath, utils.ThresholdsCsv)}, + []string{path.Join(self.DirPath, utils.FiltersCsv)}, + []string{path.Join(self.DirPath, utils.SuppliersCsv)}, + []string{path.Join(self.DirPath, utils.AttributesCsv)}, + []string{path.Join(self.DirPath, utils.ChargersCsv)}, + []string{path.Join(self.DirPath, utils.DispatcherProfilesCsv)}, + []string{path.Join(self.DirPath, utils.DispatcherHostsCsv)}, ) files, _ := ioutil.ReadDir(self.DirPath) var withErrors bool