From 261d160ee7dced78a2658943b5572a71ebb2fad9 Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Sun, 19 Nov 2017 19:52:00 +0000 Subject: [PATCH] Updated cgr-migrator params and refactored GetTpIds --- cmd/cgr-migrator/cgr-migrator.go | 25 ++++++------ engine/storage_csv.go | 2 +- engine/storage_mongo_stordb.go | 6 +-- engine/storage_sql.go | 66 +++++++++++++++----------------- 4 files changed, 46 insertions(+), 53 deletions(-) diff --git a/cmd/cgr-migrator/cgr-migrator.go b/cmd/cgr-migrator/cgr-migrator.go index 5f60807bd..07f97a76d 100755 --- a/cmd/cgr-migrator/cgr-migrator.go +++ b/cmd/cgr-migrator/cgr-migrator.go @@ -52,22 +52,21 @@ var ( outStorDBUser = flag.String("out_stordb_user", config.CgrConfig().StorDBUser, "The storDb user to sign in as.") outStorDBPass = flag.String("out_stordb_passwd", config.CgrConfig().StorDBPass, "The storDb user's password.") - inDataDBType = flag.String("in_datadb_type", "", "The type of the DataDb Database ") - inDataDBHost = flag.String("in_datadb_host", config.CgrConfig().DataDbHost, "The DataDb host to connect to.") - inDataDBPort = flag.String("in_datadb_port", config.CgrConfig().DataDbPort, "The DataDb port to bind to.") - inDataDBName = flag.String("in_datadb_name", config.CgrConfig().DataDbName, "The name/number of the DataDb to connect to.") - inDataDBUser = flag.String("in_datadb_user", config.CgrConfig().DataDbUser, "The DataDb user to sign in as.") - inDataDBPass = flag.String("in_datadb_passwd", config.CgrConfig().DataDbPass, "The DataDb user's password.") + inDataDBType = flag.String("datadb_type", "", "The type of the DataDb Database ") + inDataDBHost = flag.String("datadb_host", config.CgrConfig().DataDbHost, "The DataDb host to connect to.") + inDataDBPort = flag.String("datadb_port", config.CgrConfig().DataDbPort, "The DataDb port to bind to.") + inDataDBName = flag.String("datadb_name", config.CgrConfig().DataDbName, "The name/number of the DataDb to connect to.") + inDataDBUser = flag.String("datadb_user", config.CgrConfig().DataDbUser, "The DataDb user to sign in as.") + inDataDBPass = flag.String("datadb_passwd", config.CgrConfig().DataDbPass, "The DataDb user's password.") - inStorDBType = flag.String("in_stordb_type", "", "The type of the storDb Database ") - inStorDBHost = flag.String("in_stordb_host", config.CgrConfig().StorDBHost, "The storDb host to connect to.") - inStorDBPort = flag.String("in_stordb_port", config.CgrConfig().StorDBPort, "The storDb port to bind to.") - inStorDBName = flag.String("in_stordb_name", config.CgrConfig().StorDBName, "The name/number of the storDb to connect to.") - inStorDBUser = flag.String("in_stordb_user", config.CgrConfig().StorDBUser, "The storDb user to sign in as.") - inStorDBPass = flag.String("in_stordb_passwd", config.CgrConfig().StorDBPass, "The storDb user's password.") + inStorDBType = flag.String("stordb_type", "", "The type of the storDb Database ") + inStorDBHost = flag.String("stordb_host", config.CgrConfig().StorDBHost, "The storDb host to connect to.") + inStorDBPort = flag.String("stordb_port", config.CgrConfig().StorDBPort, "The storDb port to bind to.") + inStorDBName = flag.String("stordb_name", config.CgrConfig().StorDBName, "The name/number of the storDb to connect to.") + inStorDBUser = flag.String("stordb_user", config.CgrConfig().StorDBUser, "The storDb user to sign in as.") + inStorDBPass = flag.String("stordb_passwd", config.CgrConfig().StorDBPass, "The storDb user's password.") loadHistorySize = flag.Int("load_history_size", config.CgrConfig().LoadHistorySize, "Limit the number of records in the load history") - inLoadHistorySize = flag.Int("in_load_history_size", 0, "Limit the number of records in the load history") dbDataEncoding = flag.String("dbData_encoding", config.CgrConfig().DBDataEncoding, "The encoding used to store object Data in strings") inDBDataEncoding = flag.String("in_dbData_encoding", "", "The encoding used to store object Data in strings") diff --git a/engine/storage_csv.go b/engine/storage_csv.go index 8359a36b5..d6e3fc9da 100755 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -705,7 +705,7 @@ func (csvs *CSVStorage) GetTPFilters(tpid, id string) ([]*utils.TPFilter, error) return tpFilter.AsTPFilter(), nil } -func (csvs *CSVStorage) GetTpIds(x string) ([]string, error) { +func (csvs *CSVStorage) GetTpIds(colName string) ([]string, error) { return nil, utils.ErrNotImplemented } diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index c063cb48b..4e63bf9b8 100755 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -28,15 +28,15 @@ import ( "time" ) -func (ms *MongoStorage) GetTpIds(colname string) ([]string, error) { +func (ms *MongoStorage) GetTpIds(colName string) ([]string, error) { tpidMap := make(map[string]bool) session := ms.session.Copy() db := session.DB(ms.db) defer session.Close() var tpids []string var err error - cols := []string{colname} - if colname == "" { + cols := []string{colName} + if colName == "" { cols, err = db.CollectionNames() if err != nil { return nil, err diff --git a/engine/storage_sql.go b/engine/storage_sql.go index ddf12610a..55c97e84c 100755 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -120,45 +120,39 @@ func (self *SQLStorage) IsDBEmpty() (resp bool, err error) { // update // Return a list with all TPids defined in the system, even if incomplete, isolated in some table. -func (self *SQLStorage) GetTpIds(colname string) ([]string, error) { +func (self *SQLStorage) GetTpIds(colName string) ([]string, error) { var rows *sql.Rows var err error - if colname != "" { - rows, err = self.Db.Query( - fmt.Sprintf(" (SELECT tpid FROM %s)", colname)) - if err != nil { - return nil, err - } - defer rows.Close() - } else { - rows, err = self.Db.Query( - fmt.Sprintf( - "(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)", - utils.TBLTPTimings, - utils.TBLTPDestinations, - utils.TBLTPRates, - utils.TBLTPDestinationRates, - utils.TBLTPRatingPlans, - utils.TBLTPRateProfiles, - utils.TBLTPSharedGroups, - utils.TBLTPCdrStats, - utils.TBLTPLcrs, - utils.TBLTPActions, - utils.TBLTPActionTriggers, - utils.TBLTPAccountActions, - utils.TBLTPDerivedChargers, - utils.TBLTPUsers, - utils.TBLTPAliases, - utils.TBLTPResources, - utils.TBLTPStats, - utils.TBLTPThresholds, - utils.TBLTPFilters, - utils.TBLTPActionPlans)) - if err != nil { - return nil, err - } - defer rows.Close() + qryStr := fmt.Sprintf(" (SELECT tpid FROM %s)", colName) + if colName == "" { + qryStr = fmt.Sprintf( + "(SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s) UNION (SELECT tpid FROM %s)", + utils.TBLTPTimings, + utils.TBLTPDestinations, + utils.TBLTPRates, + utils.TBLTPDestinationRates, + utils.TBLTPRatingPlans, + utils.TBLTPRateProfiles, + utils.TBLTPSharedGroups, + utils.TBLTPCdrStats, + utils.TBLTPLcrs, + utils.TBLTPActions, + utils.TBLTPActionTriggers, + utils.TBLTPAccountActions, + utils.TBLTPDerivedChargers, + utils.TBLTPUsers, + utils.TBLTPAliases, + utils.TBLTPResources, + utils.TBLTPStats, + utils.TBLTPThresholds, + utils.TBLTPFilters, + utils.TBLTPActionPlans) } + rows, err = self.Db.Query(qryStr) + if err != nil { + return nil, err + } + defer rows.Close() ids := make([]string, 0) i := 0 for rows.Next() {