diff --git a/apier/v1/apier.go b/apier/v1/apier.go index 26c50edf1..ffdfbd17e 100644 --- a/apier/v1/apier.go +++ b/apier/v1/apier.go @@ -46,7 +46,6 @@ type ApierV1 struct { CdrDb engine.CdrStorage Config *config.CGRConfig Responder *engine.Responder - Users rpcclient.RpcClientConnection CDRs rpcclient.RpcClientConnection // FixMe: populate it from cgr-engine ServManager *servmanager.ServiceManager // Need to have them capitalize so we can export in V2 HTTPPoster *engine.HTTPPoster @@ -986,13 +985,6 @@ func (self *ApierV1) GetCacheStats(attrs utils.AttrCacheStats, reply *utils.Cach cs.ChargerProfiles = len(engine.Cache.GetItemIDs(utils.CacheChargerProfiles, "")) cs.DispatcherProfiles = len(engine.Cache.GetItemIDs(utils.CacheDispatcherProfiles, "")) - if self.Users != nil { - var ups engine.UserProfiles - if err := self.Users.Call("UsersV1.GetUsers", &engine.UserProfile{}, &ups); err != nil { - return utils.NewErrServerError(err) - } - cs.Users = len(ups) - } *reply = *cs return nil } @@ -1173,7 +1165,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV), path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV), - path.Join(attrs.FolderPath, utils.USERS_CSV), path.Join(attrs.FolderPath, utils.ResourcesCsv), path.Join(attrs.FolderPath, utils.StatsCsv), path.Join(attrs.FolderPath, utils.ThresholdsCsv), @@ -1214,7 +1205,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, } } aps, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) - userKeys, _ := loader.GetLoadedIds(utils.USERS_PREFIX) // relase tp data loader.Init() @@ -1226,12 +1216,6 @@ func (self *ApierV1) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, sched.Reload() } } - if len(userKeys) != 0 && self.Users != nil { - var r string - if err := self.Users.Call("UsersV1.ReloadUsers", "", &r); err != nil { - return err - } - } *reply = utils.OK return nil } diff --git a/apier/v1/auth.go b/apier/v1/auth.go index 1c8d5e5ef..58d695c59 100644 --- a/apier/v1/auth.go +++ b/apier/v1/auth.go @@ -28,10 +28,6 @@ import ( // Returns MaxUsage (for calls in seconds), -1 for no limit func (self *ApierV1) GetMaxUsage(usageRecord engine.UsageRecord, maxUsage *int64) error { - err := engine.LoadUserProfile(&usageRecord, "ExtraFields") - if err != nil { - return utils.NewErrServerError(err) - } if usageRecord.ToR == "" { usageRecord.ToR = utils.VOICE } diff --git a/apier/v1/debit.go b/apier/v1/debit.go index db09f699e..a46543625 100644 --- a/apier/v1/debit.go +++ b/apier/v1/debit.go @@ -46,12 +46,6 @@ func (apier *ApierV1) DebitUsageWithOptions(args AttrDebitUsageWithOptions, repl return utils.NewErrMandatoryIeMissing(missing...) } - err := engine.LoadUserProfile(args.UsageRecord, "") - if err != nil { - *reply = err.Error() - return err - } - // Set values for optional parameters if usageRecord.ToR == "" { usageRecord.ToR = utils.VOICE diff --git a/apier/v1/tpusers.go b/apier/v1/tpusers.go deleted file mode 100644 index 4d6476c2a..000000000 --- a/apier/v1/tpusers.go +++ /dev/null @@ -1,95 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package v1 - -import ( - "github.com/cgrates/cgrates/utils" -) - -// Creates a new alias within a tariff plan -func (self *ApierV1) SetTPUser(attrs utils.TPUsers, reply *string) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid", "UserName", "Tenant"}); len(missing) != 0 { - return utils.NewErrMandatoryIeMissing(missing...) - } - if err := self.StorDb.SetTPUsers([]*utils.TPUsers{&attrs}); err != nil { - return utils.NewErrServerError(err) - } - *reply = utils.OK - return nil -} - -type AttrGetTPUser struct { - TPid string // Tariff plan id - Tenant string - UserName string -} - -// Queries specific User on Tariff plan -func (self *ApierV1) GetTPUser(attr AttrGetTPUser, reply *utils.TPUsers) error { - if missing := utils.MissingStructFields(&attr, []string{"TPid", "UserName", "Tenant"}); len(missing) != 0 { //Params missing - return utils.NewErrMandatoryIeMissing(missing...) - } - filter := &utils.TPUsers{TPid: attr.TPid, UserName: attr.UserName, Tenant: attr.Tenant} - if tms, err := self.StorDb.GetTPUsers(filter); err != nil { - if err.Error() != utils.ErrNotFound.Error() { - err = utils.NewErrServerError(err) - } - return err - } else { - *reply = *tms[0] - } - return nil -} - -type AttrGetTPUserIds struct { - TPid string // Tariff plan id - utils.Paginator -} - -// Queries alias identities on specific tariff plan. -func (self *ApierV1) GetTPUserIds(attrs AttrGetTPUserIds, reply *[]string) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid"}); len(missing) != 0 { //Params missing - return utils.NewErrMandatoryIeMissing(missing...) - } - if ids, err := self.StorDb.GetTpTableIds(attrs.TPid, utils.TBLTPUsers, utils.TPDistinctIds{"tenant", "user_name"}, nil, &attrs.Paginator); err != nil { - if err.Error() != utils.ErrNotFound.Error() { - err = utils.NewErrServerError(err) - } - return err - } else { - *reply = ids - } - return nil -} - -// Removes specific User on Tariff plan -func (self *ApierV1) RemTPUser(attrs AttrGetTPUser, reply *string) error { - if missing := utils.MissingStructFields(&attrs, []string{"TPid", "Tenant", "UserName"}); len(missing) != 0 { //Params missing - return utils.NewErrMandatoryIeMissing(missing...) - } - if err := self.StorDb.RemTpData(utils.TBLTPUsers, attrs.TPid, map[string]string{"tenant": attrs.Tenant, "user_name": attrs.UserName}); err != nil { - if err.Error() != utils.ErrNotFound.Error() { - err = utils.NewErrServerError(err) - } - return err - } else { - *reply = utils.OK - } - return nil -} diff --git a/apier/v1/tpusers_it_test.go b/apier/v1/tpusers_it_test.go deleted file mode 100644 index ca0c8e8e6..000000000 --- a/apier/v1/tpusers_it_test.go +++ /dev/null @@ -1,243 +0,0 @@ -// +build offline_tp - -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package v1 - -import ( - "net/rpc" - "net/rpc/jsonrpc" - "path" - "reflect" - "testing" - - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" -) - -var ( - tpUserCfgPath string - tpUserCfg *config.CGRConfig - tpUserRPC *rpc.Client - tpUserDataDir = "/usr/share/cgrates" - tpUser *utils.TPUsers - tpUserDelay int - tpUserConfigDIR string //run tests for specific configuration -) - -var sTestsTPUsers = []func(t *testing.T){ - testTPUsersInitCfg, - testTPUsersResetStorDb, - testTPUsersStartEngine, - testTPUsersRpcConn, - testTPUsersGetTPUserBeforeSet, - testTPUsersSetTPUser, - testTPUsersGetTPUserAfterSet, - testTPUsersGetTPUserID, - testTPUsersUpdateTPUser, - testTPUsersGetTPUserAfterUpdate, - testTPUsersRemTPUser, - testTPUsersGetTPUserAfterRemove, - testTPUsersKillEngine, -} - -//Test start here -func TestTPUserITMySql(t *testing.T) { - tpUserConfigDIR = "tutmysql" - for _, stest := range sTestsTPUsers { - t.Run(tpUserConfigDIR, stest) - } -} - -func TestTPUserITMongo(t *testing.T) { - tpUserConfigDIR = "tutmongo" - for _, stest := range sTestsTPUsers { - t.Run(tpUserConfigDIR, stest) - } -} - -func TestTPUserITPG(t *testing.T) { - tpUserConfigDIR = "tutpostgres" - for _, stest := range sTestsTPUsers { - t.Run(tpUserConfigDIR, stest) - } -} - -func testTPUsersInitCfg(t *testing.T) { - var err error - tpUserCfgPath = path.Join(tpUserDataDir, "conf", "samples", tpUserConfigDIR) - tpUserCfg, err = config.NewCGRConfigFromFolder(tpUserCfgPath) - if err != nil { - t.Error(err) - } - tpUserCfg.DataFolderPath = tpUserDataDir // Share DataFolderPath through config towards StoreDb for Flush() - config.SetCgrConfig(tpUserCfg) - switch tpUserConfigDIR { - case "tutmongo": // Mongo needs more time to reset db - tpUserDelay = 2000 - default: - tpUserDelay = 1000 - } -} - -// Wipe out the cdr database -func testTPUsersResetStorDb(t *testing.T) { - if err := engine.InitStorDb(tpUserCfg); err != nil { - t.Fatal(err) - } -} - -// Start CGR Engine -func testTPUsersStartEngine(t *testing.T) { - if _, err := engine.StopStartEngine(tpUserCfgPath, tpUserDelay); err != nil { - t.Fatal(err) - } -} - -// Connect rpc client to rater -func testTPUsersRpcConn(t *testing.T) { - var err error - tpUserRPC, err = jsonrpc.Dial("tcp", tpUserCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed - if err != nil { - t.Fatal(err) - } -} - -func testTPUsersGetTPUserBeforeSet(t *testing.T) { - var reply *utils.TPUsers - if err := tpUserRPC.Call("ApierV1.GetTPUser", AttrGetTPUser{TPid: "TPU1", Tenant: "Tentant1", UserName: "User1"}, &reply); err == nil || err.Error() != utils.ErrNotFound.Error() { - t.Error(err) - } -} - -func testTPUsersSetTPUser(t *testing.T) { - tpUser = &utils.TPUsers{ - TPid: "TPU1", - UserName: "User1", - Tenant: "Tenant1", - Masked: true, - Weight: 20, - Profile: []*utils.TPUserProfile{ - &utils.TPUserProfile{ - AttrName: "UserProfile1", - AttrValue: "ValUP1", - }, - &utils.TPUserProfile{ - AttrName: "UserProfile2", - AttrValue: "ValUP2", - }, - }, - } - var result string - if err := tpUserRPC.Call("ApierV1.SetTPUser", tpUser, &result); err != nil { - t.Error(err) - } else if result != utils.OK { - t.Error("Unexpected reply returned", result) - } -} - -func testTPUsersGetTPUserAfterSet(t *testing.T) { - var respond *utils.TPUsers - if err := tpUserRPC.Call("ApierV1.GetTPUser", &AttrGetTPUser{TPid: tpUser.TPid, UserName: tpUser.UserName, Tenant: tpUser.Tenant}, &respond); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(tpUser.TPid, respond.TPid) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.TPid, respond.TPid) - } else if !reflect.DeepEqual(tpUser.UserName, respond.UserName) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.UserName, respond.UserName) - } else if !reflect.DeepEqual(tpUser.Tenant, respond.Tenant) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.Tenant, respond.Tenant) - } else if !reflect.DeepEqual(tpUser.Weight, respond.Weight) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.Weight, respond.Weight) - } else if !reflect.DeepEqual(len(tpUser.Profile), len(respond.Profile)) { - t.Errorf("Expecting: %+v, received: %+v", len(tpUser.Profile), len(respond.Profile)) - } -} - -func testTPUsersGetTPUserID(t *testing.T) { - var result []string - expectedTPID := []string{"Tenant1:User1"} - if err := tpUserRPC.Call("ApierV1.GetTPUserIds", AttrGetTPUserIds{tpUser.TPid, utils.Paginator{}}, &result); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(result, expectedTPID) { - t.Errorf("Expecting: %+v, received: %+v", result, expectedTPID) - } -} - -func testTPUsersUpdateTPUser(t *testing.T) { - var result string - tpUser.Profile = []*utils.TPUserProfile{ - &utils.TPUserProfile{ - AttrName: "UserProfile1", - AttrValue: "ValUp1", - }, - &utils.TPUserProfile{ - AttrName: "UserProfile2", - AttrValue: "ValUP2", - }, - &utils.TPUserProfile{ - AttrName: "UserProfile3", - AttrValue: "ValUP3", - }, - } - if err := tpUserRPC.Call("ApierV1.SetTPUser", tpUser, &result); err != nil { - t.Error(err) - } else if result != utils.OK { - t.Error("Unexpected reply returned", result) - } -} - -func testTPUsersGetTPUserAfterUpdate(t *testing.T) { - var respond *utils.TPUsers - if err := tpUserRPC.Call("ApierV1.GetTPUser", &AttrGetTPUser{TPid: tpUser.TPid, Tenant: tpUser.Tenant, UserName: tpUser.UserName}, &respond); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(tpUser.TPid, respond.TPid) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.TPid, respond.TPid) - } else if !reflect.DeepEqual(tpUser.UserName, respond.UserName) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.UserName, respond.UserName) - } else if !reflect.DeepEqual(tpUser.Tenant, respond.Tenant) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.Tenant, respond.Tenant) - } else if !reflect.DeepEqual(tpUser.Weight, respond.Weight) { - t.Errorf("Expecting: %+v, received: %+v", tpUser.Weight, respond.Weight) - } else if !reflect.DeepEqual(len(tpUser.Profile), len(respond.Profile)) { - t.Errorf("Expecting: %+v, received: %+v", len(tpUser.Profile), len(respond.Profile)) - } -} - -func testTPUsersRemTPUser(t *testing.T) { - var resp string - if err := tpUserRPC.Call("ApierV1.RemTPUser", &AttrGetTPUser{TPid: tpUser.TPid, Tenant: tpUser.Tenant, UserName: tpUser.UserName}, &resp); err != nil { - t.Error(err) - } else if resp != utils.OK { - t.Error("Unexpected reply returned", resp) - } -} - -func testTPUsersGetTPUserAfterRemove(t *testing.T) { - var respond *utils.TPUsers - if err := tpUserRPC.Call("ApierV1.GetTPUser", &AttrGetTPUser{TPid: "TPU1", UserName: "User1", Tenant: "Tenant1"}, &respond); err == nil || err.Error() != utils.ErrNotFound.Error() { - t.Error(err) - } -} - -func testTPUsersKillEngine(t *testing.T) { - if err := engine.KillEngine(tpUserDelay); err != nil { - t.Error(err) - } -} diff --git a/apier/v1/versions_it_test.go b/apier/v1/versions_it_test.go index 116890493..7c467752f 100644 --- a/apier/v1/versions_it_test.go +++ b/apier/v1/versions_it_test.go @@ -121,7 +121,7 @@ func testVrsStorDB(t *testing.T) { expectedVrs := engine.Versions{"TpDerivedChargers": 1, "TpDestinations": 1, "TpResource": 1, "TpThresholds": 1, "TpActions": 1, "TpDestinationRates": 1, "TpFilters": 1, "TpRates": 1, "CDRs": 2, "TpActionTriggers": 1, "TpRatingPlans": 1, "TpSharedGroups": 1, "TpSuppliers": 1, "SessionSCosts": 3, "TpDerivedCharges": 1, "TpRatingProfiles": 1, "TpStats": 1, "TpTiming": 1, - "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1, "TpUsers": 1, + "CostDetails": 2, "TpAccountActions": 1, "TpActionPlans": 1, "TpChargers": 1, "TpRatingProfile": 1, "TpRatingPlan": 1, "TpResources": 1} if err := vrsRPC.Call("ApierV1.GetStorDBVersions", "", &result); err != nil { t.Error(err) diff --git a/apier/v2/apier.go b/apier/v2/apier.go index 9c856d801..6ad19aa63 100644 --- a/apier/v2/apier.go +++ b/apier/v2/apier.go @@ -136,7 +136,6 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, path.Join(attrs.FolderPath, utils.ACTION_TRIGGERS_CSV), path.Join(attrs.FolderPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(attrs.FolderPath, utils.DERIVED_CHARGERS_CSV), - path.Join(attrs.FolderPath, utils.USERS_CSV), path.Join(attrs.FolderPath, utils.ResourcesCsv), path.Join(attrs.FolderPath, utils.StatsCsv), path.Join(attrs.FolderPath, utils.ThresholdsCsv), @@ -178,7 +177,6 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, } } aps, _ := loader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) - userKeys, _ := loader.GetLoadedIds(utils.USERS_PREFIX) // relase tp data loader.Init() @@ -190,12 +188,6 @@ func (self *ApierV2) LoadTariffPlanFromFolder(attrs utils.AttrLoadTpFromFolder, sched.Reload() } } - if len(userKeys) != 0 && self.Users != nil { - var r string - if err := self.Users.Call("UsersV1.ReloadUsers", "", &r); err != nil { - return err - } - } loadHistList, err := self.DataManager.DataDB().GetLoadHistory(1, true, utils.NonTransactional) if err != nil { return err diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index b193896e5..f54a4c42c 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -501,14 +501,14 @@ func startHTTPAgent(internalSMGChan chan rpcclient.RpcClientConnection, func startCDRS(internalCdrSChan chan rpcclient.RpcClientConnection, cdrDb engine.CdrStorage, dm *engine.DataManager, internalRaterChan, internalPubSubSChan, internalAttributeSChan, - internalUserSChan, internalThresholdSChan, internalStatSChan, + internalThresholdSChan, internalStatSChan, internalChargerSChan chan rpcclient.RpcClientConnection, server *utils.Server, exitChan chan bool, filterSChan chan *engine.FilterS) { filterS := <-filterSChan filterSChan <- filterS var err error utils.Logger.Info("Starting CGRateS CDRS service.") - var ralConn, pubSubConn, usersConn, attrSConn, + var ralConn, pubSubConn, attrSConn, thresholdSConn, statsConn, chargerSConn *rpcclient.RpcClientPool if len(cfg.CdrsCfg().CDRSChargerSConns) != 0 { // Conn pool towards RAL chargerSConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST, @@ -568,20 +568,6 @@ func startCDRS(internalCdrSChan chan rpcclient.RpcClientConnection, return } } - if len(cfg.CdrsCfg().CDRSUserSConns) != 0 { // Users connection init - usersConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST, - cfg.TlsCfg().ClientKey, - cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate, - cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects, - cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout, - cfg.CdrsCfg().CDRSUserSConns, internalUserSChan, - cfg.GeneralCfg().InternalTtl) - if err != nil { - utils.Logger.Crit(fmt.Sprintf(" Could not connect to UserS: %s", err.Error())) - exitChan <- true - return - } - } if len(cfg.CdrsCfg().CDRSThresholdSConns) != 0 { // Stats connection init thresholdSConn, err = engine.NewRPCPool(rpcclient.POOL_FIRST, cfg.TlsCfg().ClientKey, @@ -611,7 +597,7 @@ func startCDRS(internalCdrSChan chan rpcclient.RpcClientConnection, } } cdrServer := engine.NewCDRServer(cfg, cdrDb, dm, - ralConn, pubSubConn, attrSConn, usersConn, + ralConn, pubSubConn, attrSConn, thresholdSConn, statsConn, chargerSConn, filterS) utils.Logger.Info("Registering CDRS HTTP Handlers.") cdrServer.RegisterHandlersToServer(server) @@ -647,19 +633,6 @@ func startPubSubServer(internalPubSubSChan chan rpcclient.RpcClientConnection, d internalPubSubSChan <- pubSubServer } -func startUsersServer(internalUserSChan chan rpcclient.RpcClientConnection, dm *engine.DataManager, server *utils.Server, exitChan chan bool) { - utils.Logger.Info("Starting User service.") - userServer, err := engine.NewUserMap(dm, cfg.UserServerIndexes) - if err != nil { - utils.Logger.Crit(fmt.Sprintf(" Could not start, error: %s", err.Error())) - exitChan <- true - return - } - utils.Logger.Info("Started User service.") - server.RpcRegisterName("UsersV1", userServer) - internalUserSChan <- userServer -} - // startAttributeService fires up the AttributeS func startAttributeService(internalAttributeSChan chan rpcclient.RpcClientConnection, cacheS *engine.CacheS, cfg *config.CGRConfig, dm *engine.DataManager, @@ -1060,7 +1033,7 @@ func startAnalyzerService(internalAnalyzerSChan chan rpcclient.RpcClientConnecti } func startRpc(server *utils.Server, internalRaterChan, - internalCdrSChan, internalPubSubSChan, internalUserSChan, internalRsChan, internalStatSChan, + internalCdrSChan, internalPubSubSChan, internalRsChan, internalStatSChan, internalAttrSChan, internalChargerSChan, internalThdSChan, internalSuplSChan, internalSMGChan, internalAnalyzerSChan chan rpcclient.RpcClientConnection, internalDispatcherSChan chan *dispatchers.DispatcherService, exitChan chan bool) { @@ -1071,8 +1044,6 @@ func startRpc(server *utils.Server, internalRaterChan, internalCdrSChan <- cdrs case pubsubs := <-internalPubSubSChan: internalPubSubSChan <- pubsubs - case users := <-internalUserSChan: - internalUserSChan <- users case smg := <-internalSMGChan: internalSMGChan <- smg case rls := <-internalRsChan: @@ -1308,8 +1279,7 @@ func main() { var loadDb engine.LoadStorage var cdrDb engine.CdrStorage var dm *engine.DataManager - if cfg.RalsCfg().RALsEnabled || cfg.PubSubServerEnabled || - cfg.UserServerEnabled || cfg.SchedulerCfg().Enabled || + if cfg.RalsCfg().RALsEnabled || cfg.PubSubServerEnabled || cfg.SchedulerCfg().Enabled || cfg.AttributeSCfg().Enabled || cfg.ResourceSCfg().Enabled || cfg.StatSCfg().Enabled || cfg.ThresholdSCfg().Enabled || cfg.SupplierSCfg().Enabled || cfg.DispatcherSCfg().Enabled { // Some services can run without db, ie: SessionS or CDRC dm, err = engine.ConfigureDataStorage(cfg.DataDbCfg().DataDbType, @@ -1376,7 +1346,6 @@ func main() { internalRaterChan := make(chan rpcclient.RpcClientConnection, 1) internalCdrSChan := make(chan rpcclient.RpcClientConnection, 1) internalPubSubSChan := make(chan rpcclient.RpcClientConnection, 1) - internalUserSChan := make(chan rpcclient.RpcClientConnection, 1) internalSMGChan := make(chan rpcclient.RpcClientConnection, 1) internalAttributeSChan := make(chan rpcclient.RpcClientConnection, 1) internalChargerSChan := make(chan rpcclient.RpcClientConnection, 1) @@ -1394,7 +1363,7 @@ func main() { // Start rater service if cfg.RalsCfg().RALsEnabled { go startRater(internalRaterChan, cacheS, internalThresholdSChan, - internalStatSChan, internalPubSubSChan, internalUserSChan, + internalStatSChan, internalPubSubSChan, srvManager, server, dm, loadDb, cdrDb, &stopHandled, exitChan, filterSChan) } @@ -1407,7 +1376,6 @@ func main() { if cfg.CdrsCfg().CDRSEnabled { go startCDRS(internalCdrSChan, cdrDb, dm, internalRaterChan, internalPubSubSChan, internalAttributeSChan, - internalUserSChan, internalThresholdSChan, internalStatSChan, internalChargerSChan, server, exitChan, filterSChan) } @@ -1459,10 +1427,6 @@ func main() { go startPubSubServer(internalPubSubSChan, dm, server, exitChan) } - // Start users service - if cfg.UserServerEnabled { - go startUsersServer(internalUserSChan, dm, server, exitChan) - } // Start FilterS go startFilterService(filterSChan, cacheS, internalStatSChan, cfg, dm, exitChan) @@ -1510,11 +1474,10 @@ func main() { // Serve rpc connections go startRpc(server, internalRaterChan, internalCdrSChan, - internalPubSubSChan, internalUserSChan, internalRsChan, - internalStatSChan, + internalPubSubSChan, internalRsChan, internalStatSChan, internalAttributeSChan, internalChargerSChan, internalThresholdSChan, - internalSupplierSChan, - internalSMGChan, internalAnalyzerSChan, internalDispatcherSChan, exitChan) + internalSupplierSChan, internalSMGChan, internalAnalyzerSChan, + internalDispatcherSChan, exitChan) <-exitChan if *cpuProfDir != "" { // wait to end cpuProfiling diff --git a/cmd/cgr-engine/rater.go b/cmd/cgr-engine/rater.go index 4d25629c3..2d1770b3d 100755 --- a/cmd/cgr-engine/rater.go +++ b/cmd/cgr-engine/rater.go @@ -31,8 +31,7 @@ import ( // Starts rater and reports on chan func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheS *engine.CacheS, - internalThdSChan, internalStatSChan, internalPubSubSChan, - internalUserSChan chan rpcclient.RpcClientConnection, + internalThdSChan, internalStatSChan, internalPubSubSChan chan rpcclient.RpcClientConnection, serviceManager *servmanager.ServiceManager, server *utils.Server, dm *engine.DataManager, loadDb engine.LoadStorage, cdrDb engine.CdrStorage, stopHandled *bool, exitChan chan bool, filterSChan chan *engine.FilterS) { @@ -120,28 +119,6 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheS *en }() } - var usersConns rpcclient.RpcClientConnection - if len(cfg.RalsCfg().RALsUserSConns) != 0 { // Connection to UserService - usersTaskChan := make(chan struct{}) - waitTasks = append(waitTasks, usersTaskChan) - go func() { - defer close(usersTaskChan) - var err error - if usersConns, err = engine.NewRPCPool(rpcclient.POOL_FIRST, - cfg.TlsCfg().ClientKey, - cfg.TlsCfg().ClientCerificate, cfg.TlsCfg().CaCertificate, - cfg.GeneralCfg().ConnectAttempts, cfg.GeneralCfg().Reconnects, - cfg.GeneralCfg().ConnectTimeout, cfg.GeneralCfg().ReplyTimeout, - cfg.RalsCfg().RALsUserSConns, internalUserSChan, - cfg.GeneralCfg().InternalTtl); err != nil { - utils.Logger.Crit(fmt.Sprintf(" Could not connect UserS, error: %s", err.Error())) - exitChan <- true - return - } else { - engine.SetUserService(usersConns) - } - }() - } // Wait for all connections to complete before going further for _, chn := range waitTasks { <-chn @@ -166,9 +143,7 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheS *en if stats != nil { engine.SetStatS(stats) } - if usersConns != nil { - apierRpcV1.Users = usersConns - } + apierRpcV2 := &v2.ApierV2{ ApierV1: *apierRpcV1} @@ -177,7 +152,6 @@ func startRater(internalRaterChan chan rpcclient.RpcClientConnection, cacheS *en server.RpcRegister(apierRpcV2) utils.RegisterRpcParams("PubSubV1", &engine.PubSub{}) - utils.RegisterRpcParams("UsersV1", &engine.UserMap{}) utils.RegisterRpcParams("", &v1.CDRsV1{}) utils.RegisterRpcParams("", &v2.CDRsV2{}) utils.RegisterRpcParams("", &v1.SMGenericV1{}) diff --git a/cmd/cgr-loader/cgr-loader.go b/cmd/cgr-loader/cgr-loader.go index f11c0bda7..791abc3aa 100755 --- a/cmd/cgr-loader/cgr-loader.go +++ b/cmd/cgr-loader/cgr-loader.go @@ -95,8 +95,6 @@ var ( flushStorDB = flag.Bool("flush_stordb", false, "Remove tariff plan data for id from the database") remove = flag.Bool("remove", false, "Will remove instead of adding data from DB") - usersAddress = flag.String("users", "", "Users service to contact for data reloads, empty to disable automatic data reloads") - err error dm *engine.DataManager storDb engine.LoadStorage @@ -291,7 +289,6 @@ func main() { path.Join(*dataPath, utils.ACTION_TRIGGERS_CSV), path.Join(*dataPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(*dataPath, utils.DERIVED_CHARGERS_CSV), - path.Join(*dataPath, utils.USERS_CSV), path.Join(*dataPath, utils.ResourcesCsv), path.Join(*dataPath, utils.StatsCsv), path.Join(*dataPath, utils.ThresholdsCsv), @@ -328,26 +325,6 @@ func main() { log.Print("WARNING: automatic cache reloading is disabled!") } - // FixMe: remove users reloading as soon as not longer supported - if *usersAddress != "" { // Init connection to rater so we can reload it's data - if len(ldrCfg.LoaderCgrCfg().CachesConns) != 0 && - *usersAddress == ldrCfg.LoaderCgrCfg().CachesConns[0].Address { - userS = cacheS - } else { - if userS, err = rpcclient.NewRpcClient("tcp", *usersAddress, - ldrCfg.LoaderCgrCfg().CachesConns[0].Tls, - ldrCfg.TlsCfg().ClientKey, ldrCfg.TlsCfg().ClientCerificate, - ldrCfg.TlsCfg().CaCertificate, 3, 3, - time.Duration(1*time.Second), time.Duration(5*time.Minute), - strings.TrimPrefix(*rpcEncoding, utils.Meta), nil, false); err != nil { - log.Fatalf("Could not connect to UserS API: %s", err.Error()) - return - } - } - } else { - log.Print("WARNING: Users automatic data reload is disabled!") - } - if !*remove { // write maps to database if err := tpReader.WriteToDatabase(*flush, *verbose, *disableReverse); err != nil { @@ -378,11 +355,6 @@ func main() { dppIDs, _ = tpReader.GetLoadedIds(utils.DispatcherProfilePrefix) } aps, _ := tpReader.GetLoadedIds(utils.ACTION_PLAN_PREFIX) - // for users reloading - var userIds []string - if userS != nil { - userIds, _ = tpReader.GetLoadedIds(utils.USERS_PREFIX) - } // release the reader with it's structures tpReader.Init() @@ -458,16 +430,6 @@ func main() { } } - if userS != nil && len(userIds) > 0 { - if *verbose { - log.Print("Reloading Users data") - } - var reply string - if err := userS.Call(utils.UsersV1ReloadUsers, "", &reply); err != nil { - log.Printf("WARNING: Failed reloading users data, error: %s\n", err.Error()) - } - } - } } else { if err := tpReader.RemoveFromDatabase(*verbose, *disableReverse); err != nil { diff --git a/config/cdrscfg.go b/config/cdrscfg.go index 400ed0918..c8ed80153 100644 --- a/config/cdrscfg.go +++ b/config/cdrscfg.go @@ -31,7 +31,6 @@ type CdrsCfg struct { CDRSRaterConns []*HaPoolConfig // address where to reach the Rater for cost calculation: <""|internal|x.y.z.y:1234> CDRSPubSubSConns []*HaPoolConfig // address where to reach the pubsub service: <""|internal|x.y.z.y:1234> CDRSAttributeSConns []*HaPoolConfig // address where to reach the users service: <""|internal|x.y.z.y:1234> - CDRSUserSConns []*HaPoolConfig // address where to reach the users service: <""|internal|x.y.z.y:1234> CDRSThresholdSConns []*HaPoolConfig // address where to reach the thresholds service CDRSStatSConns []*HaPoolConfig CDRSOnlineCDRExports []string // list of CDRE templates to use for real-time CDR exports @@ -84,13 +83,6 @@ func (cdrscfg *CdrsCfg) loadFromJsonCfg(jsnCdrsCfg *CdrsJsonCfg) (err error) { cdrscfg.CDRSAttributeSConns[idx].loadFromJsonCfg(jsnHaCfg) } } - if jsnCdrsCfg.Users_conns != nil { - cdrscfg.CDRSUserSConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Users_conns)) - for idx, jsnHaCfg := range *jsnCdrsCfg.Users_conns { - cdrscfg.CDRSUserSConns[idx] = NewDfltHaPoolConfig() - cdrscfg.CDRSUserSConns[idx].loadFromJsonCfg(jsnHaCfg) - } - } if jsnCdrsCfg.Thresholds_conns != nil { cdrscfg.CDRSThresholdSConns = make([]*HaPoolConfig, len(*jsnCdrsCfg.Thresholds_conns)) for idx, jsnHaCfg := range *jsnCdrsCfg.Thresholds_conns { diff --git a/config/cdrscfg_test.go b/config/cdrscfg_test.go index ef391b6d9..222276ef3 100644 --- a/config/cdrscfg_test.go +++ b/config/cdrscfg_test.go @@ -49,7 +49,6 @@ func TestCdrsCfgloadFromJsonCfg(t *testing.T) { ], "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> "attributes_conns": [], // address where to reach the attribute service, empty to disable attributes functionality: <""|*internal|x.y.z.y:1234> - "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> "stats_conns": [], // address where to reach the stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> "online_cdr_exports":[], // list of CDRE profiles to use for real-time CDR exports @@ -62,7 +61,6 @@ func TestCdrsCfgloadFromJsonCfg(t *testing.T) { CDRSRaterConns: []*HaPoolConfig{{Address: utils.MetaInternal}}, CDRSPubSubSConns: []*HaPoolConfig{}, CDRSAttributeSConns: []*HaPoolConfig{}, - CDRSUserSConns: []*HaPoolConfig{}, CDRSThresholdSConns: []*HaPoolConfig{}, CDRSStatSConns: []*HaPoolConfig{}, } diff --git a/config/config.go b/config/config.go index 26749a70a..113244ccb 100755 --- a/config/config.go +++ b/config/config.go @@ -313,8 +313,6 @@ type CGRConfig struct { // Deprecated SmOsipsConfig *SmOsipsConfig // SMOpenSIPS Configuration PubSubServerEnabled bool // Starts PubSub as server: . - UserServerEnabled bool // Starts User as server: - UserServerIndexes []string // List of user profile field indexes } func (self *CGRConfig) checkConfigSanity() error { @@ -334,13 +332,6 @@ func (self *CGRConfig) checkConfigSanity() error { } } } - if !self.UserServerEnabled { - for _, connCfg := range self.ralsCfg.RALsUserSConns { - if connCfg.Address == utils.MetaInternal { - return errors.New("User service not enabled but requested by RALs component.") - } - } - } if !self.thresholdSCfg.Enabled { for _, connCfg := range self.ralsCfg.RALsThresholdSConns { if connCfg.Address == utils.MetaInternal { @@ -379,13 +370,6 @@ func (self *CGRConfig) checkConfigSanity() error { } } } - if !self.UserServerEnabled { - for _, connCfg := range self.cdrsCfg.CDRSUserSConns { - if connCfg.Address == utils.MetaInternal { - return errors.New("UserS not enabled but requested by CDRS component.") - } - } - } if !self.statsCfg.Enabled { for _, connCfg := range self.cdrsCfg.CDRSStatSConns { if connCfg.Address == utils.MetaInternal { @@ -1052,18 +1036,6 @@ func (self *CGRConfig) loadFromJsonCfg(jsnCfg *CgrJsonCfg) (err error) { } } - jsnUserServCfg, err := jsnCfg.UserServJsonCfg() - if err != nil { - return err - } - if jsnUserServCfg != nil { - if jsnUserServCfg.Enabled != nil { - self.UserServerEnabled = *jsnUserServCfg.Enabled - } - if jsnUserServCfg.Indexes != nil { - self.UserServerIndexes = *jsnUserServCfg.Indexes - } - } ///depricated^^^ return nil } diff --git a/config/config_defaults.go b/config/config_defaults.go index 0241b5cea..73f1fde44 100755 --- a/config/config_defaults.go +++ b/config/config_defaults.go @@ -163,7 +163,6 @@ const CGRATES_CFG_JSON = ` "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> "stats_conns": [], // address where to reach the stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> - "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> "rp_subject_prefix_matching": false, // enables prefix matching for the rating profile subject "remove_expired":true, // enables remove of expired balances "max_computed_usage": { // do not compute usage higher than this, prevents memory overload @@ -186,7 +185,6 @@ const CGRATES_CFG_JSON = ` ], "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> "attributes_conns": [], // address where to reach the attribute service, empty to disable attributes functionality: <""|*internal|x.y.z.y:1234> - "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> "stats_conns": [], // address where to reach the stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> "online_cdr_exports":[], // list of CDRE profiles to use for real-time CDR exports @@ -451,12 +449,6 @@ const CGRATES_CFG_JSON = ` }, -"users": { - "enabled": false, // starts User service: . - "indexes": [], // user profile field indexes -}, - - "attributes": { // Attribute service "enabled": false, // starts attribute service: . //"string_indexed_fields": [], // query indexes based on these fields for faster processing diff --git a/config/config_json.go b/config/config_json.go index 6754c1d80..9d096513d 100644 --- a/config/config_json.go +++ b/config/config_json.go @@ -50,7 +50,6 @@ const ( HttpAgentJson = "http_agent" HISTSERV_JSN = "historys" PUBSUBSERV_JSN = "pubsubs" - USERSERV_JSN = "users" ATTRIBUTE_JSN = "attributes" RESOURCES_JSON = "resources" STATS_JSON = "stats" @@ -320,18 +319,6 @@ func (self CgrJsonCfg) PubSubServJsonCfg() (*PubSubServJsonCfg, error) { return cfg, nil } -func (self CgrJsonCfg) UserServJsonCfg() (*UserServJsonCfg, error) { - rawCfg, hasKey := self[USERSERV_JSN] - if !hasKey { - return nil, nil - } - cfg := new(UserServJsonCfg) - if err := json.Unmarshal(*rawCfg, cfg); err != nil { - return nil, err - } - return cfg, nil -} - func (cgrJsn CgrJsonCfg) AttributeServJsonCfg() (*AttributeSJsonCfg, error) { rawCfg, hasKey := cgrJsn[ATTRIBUTE_JSN] if !hasKey { diff --git a/config/config_json_test.go b/config/config_json_test.go index a8f8d4fc6..88b44e6a0 100755 --- a/config/config_json_test.go +++ b/config/config_json_test.go @@ -225,7 +225,6 @@ func TestDfRalsJsonCfg(t *testing.T) { Thresholds_conns: &[]*HaPoolJsonCfg{}, Stats_conns: &[]*HaPoolJsonCfg{}, Pubsubs_conns: &[]*HaPoolJsonCfg{}, - Users_conns: &[]*HaPoolJsonCfg{}, Rp_subject_prefix_matching: utils.BoolPointer(false), Remove_expired: utils.BoolPointer(true), Max_computed_usage: &map[string]string{ @@ -266,7 +265,6 @@ func TestDfCdrsJsonCfg(t *testing.T) { }}, Pubsubs_conns: &[]*HaPoolJsonCfg{}, Attributes_conns: &[]*HaPoolJsonCfg{}, - Users_conns: &[]*HaPoolJsonCfg{}, Thresholds_conns: &[]*HaPoolJsonCfg{}, Stats_conns: &[]*HaPoolJsonCfg{}, Online_cdr_exports: &[]string{}, @@ -738,18 +736,6 @@ func TestDfPubSubServJsonCfg(t *testing.T) { } } -func TestDfUserServJsonCfg(t *testing.T) { - eCfg := &UserServJsonCfg{ - Enabled: utils.BoolPointer(false), - Indexes: &[]string{}, - } - if cfg, err := dfCgrJsonCfg.UserServJsonCfg(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(eCfg, cfg) { - t.Error("Received: ", cfg) - } -} - func TestDfAttributeServJsonCfg(t *testing.T) { eCfg := &AttributeSJsonCfg{ Enabled: utils.BoolPointer(false), diff --git a/config/config_test.go b/config/config_test.go index 76d9b7160..6943a4d98 100755 --- a/config/config_test.go +++ b/config/config_test.go @@ -468,9 +468,6 @@ func TestCgrCfgJSONDefaultsRALs(t *testing.T) { if !reflect.DeepEqual(cgrCfg.RalsCfg().RALsPubSubSConns, eHaPoolcfg) { t.Errorf("Expecting: %+v , received: %+v", eHaPoolcfg, cgrCfg.RalsCfg().RALsPubSubSConns) } - if !reflect.DeepEqual(cgrCfg.RalsCfg().RALsUserSConns, eHaPoolcfg) { - t.Errorf("Expecting: %+v , received: %+v", eHaPoolcfg, cgrCfg.RalsCfg().RALsUserSConns) - } if cgrCfg.RalsCfg().RpSubjectPrefixMatching != false { t.Errorf("Expecting: false , received: %+v", cgrCfg.RalsCfg().RpSubjectPrefixMatching) } @@ -523,9 +520,6 @@ func TestCgrCfgJSONDefaultsCDRS(t *testing.T) { if !reflect.DeepEqual(cgrCfg.CdrsCfg().CDRSAttributeSConns, eHaPoolCfg) { t.Errorf("Expecting: %+v , received: %+v", eHaPoolCfg, cgrCfg.CdrsCfg().CDRSAttributeSConns) } - if !reflect.DeepEqual(cgrCfg.CdrsCfg().CDRSUserSConns, eHaPoolCfg) { - t.Errorf("Expecting: %+v , received: %+v", eHaPoolCfg, cgrCfg.CdrsCfg().CDRSUserSConns) - } if !reflect.DeepEqual(cgrCfg.CdrsCfg().CDRSThresholdSConns, eHaPoolCfg) { t.Errorf("Expecting: %+v , received: %+v", eHaPoolCfg, cgrCfg.CdrsCfg().CDRSThresholdSConns) } @@ -791,17 +785,6 @@ func TestCgrCfgJSONDefaultsPubSubS(t *testing.T) { } } -func TestCgrCfgJSONDefaultsUserS(t *testing.T) { - eStrSlc := []string{} - if cgrCfg.UserServerEnabled != false { - t.Error(cgrCfg.UserServerEnabled) - } - - if !reflect.DeepEqual(cgrCfg.UserServerIndexes, eStrSlc) { - t.Errorf("received: %+v, expecting: %+v", cgrCfg.UserServerIndexes, eStrSlc) - } -} - func TestCgrCfgJSONDefaultFiltersCfg(t *testing.T) { eFiltersCfg := &FilterSCfg{ StatSConns: []*HaPoolConfig{}, diff --git a/config/libconfig_json.go b/config/libconfig_json.go index 3db938736..a1379ea28 100755 --- a/config/libconfig_json.go +++ b/config/libconfig_json.go @@ -102,7 +102,6 @@ type RalsJsonCfg struct { Thresholds_conns *[]*HaPoolJsonCfg Stats_conns *[]*HaPoolJsonCfg Pubsubs_conns *[]*HaPoolJsonCfg - Users_conns *[]*HaPoolJsonCfg Rp_subject_prefix_matching *bool Remove_expired *bool Max_computed_usage *map[string]string @@ -124,7 +123,6 @@ type CdrsJsonCfg struct { Rals_conns *[]*HaPoolJsonCfg Pubsubs_conns *[]*HaPoolJsonCfg Attributes_conns *[]*HaPoolJsonCfg - Users_conns *[]*HaPoolJsonCfg Thresholds_conns *[]*HaPoolJsonCfg Stats_conns *[]*HaPoolJsonCfg Online_cdr_exports *[]string @@ -410,12 +408,6 @@ type PubSubServJsonCfg struct { Enabled *bool } -// Users server config section -type UserServJsonCfg struct { - Enabled *bool - Indexes *[]string -} - // Attribute service config section type AttributeSJsonCfg struct { Enabled *bool diff --git a/config/ralscfg.go b/config/ralscfg.go index 1bda35658..0e7b9c7f3 100644 --- a/config/ralscfg.go +++ b/config/ralscfg.go @@ -30,7 +30,6 @@ type RalsCfg struct { RALsThresholdSConns []*HaPoolConfig // address where to reach ThresholdS config RALsStatSConns []*HaPoolConfig RALsPubSubSConns []*HaPoolConfig - RALsUserSConns []*HaPoolConfig RpSubjectPrefixMatching bool // enables prefix matching for the rating profile subject RemoveExpired bool RALsMaxComputedUsage map[string]time.Duration @@ -65,13 +64,6 @@ func (ralsCfg *RalsCfg) loadFromJsonCfg(jsnRALsCfg *RalsJsonCfg) (err error) { ralsCfg.RALsPubSubSConns[idx].loadFromJsonCfg(jsnHaCfg) } } - if jsnRALsCfg.Users_conns != nil { - ralsCfg.RALsUserSConns = make([]*HaPoolConfig, len(*jsnRALsCfg.Users_conns)) - for idx, jsnHaCfg := range *jsnRALsCfg.Users_conns { - ralsCfg.RALsUserSConns[idx] = NewDfltHaPoolConfig() - ralsCfg.RALsUserSConns[idx].loadFromJsonCfg(jsnHaCfg) - } - } if jsnRALsCfg.Rp_subject_prefix_matching != nil { ralsCfg.RpSubjectPrefixMatching = *jsnRALsCfg.Rp_subject_prefix_matching } diff --git a/config/ralscfg_test.go b/config/ralscfg_test.go index bbd4ec2d3..242b78d27 100644 --- a/config/ralscfg_test.go +++ b/config/ralscfg_test.go @@ -60,7 +60,6 @@ func TestRalsCfgFromJsonCfg(t *testing.T) { RALsThresholdSConns: []*HaPoolConfig{}, RALsStatSConns: []*HaPoolConfig{}, RALsPubSubSConns: []*HaPoolConfig{}, - RALsUserSConns: []*HaPoolConfig{}, RpSubjectPrefixMatching: false, RALsMaxComputedUsage: map[string]time.Duration{ utils.ANY: time.Duration(189 * time.Hour), diff --git a/console/user_addindex.go b/console/user_addindex.go deleted file mode 100644 index 8bde8d1ee..000000000 --- a/console/user_addindex.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package console - -func init() { - c := &CmdUserAddIndex{ - name: "user_addindex", - rpcMethod: "UsersV1.AddIndex", - } - commands[c.Name()] = c - c.CommandExecuter = &CommandExecuter{c} -} - -// Commander implementation -type CmdUserAddIndex struct { - name string - rpcMethod string - rpcParams *StringSliceWrapper - *CommandExecuter -} - -func (self *CmdUserAddIndex) Name() string { - return self.name -} - -func (self *CmdUserAddIndex) RpcMethod() string { - return self.rpcMethod -} - -func (self *CmdUserAddIndex) RpcParams(reset bool) interface{} { - if reset || self.rpcParams == nil { - self.rpcParams = &StringSliceWrapper{} - } - return self.rpcParams -} - -func (self *CmdUserAddIndex) PostprocessRpcParams() error { - return nil -} - -func (self *CmdUserAddIndex) RpcResult() interface{} { - var s string - return &s -} diff --git a/console/user_indexes.go b/console/user_indexes.go deleted file mode 100644 index 80d2c2683..000000000 --- a/console/user_indexes.go +++ /dev/null @@ -1,60 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package console - -func init() { - c := &CmdUserShowIndexes{ - name: "user_indexes", - rpcMethod: "UsersV1.GetIndexes", - } - commands[c.Name()] = c - c.CommandExecuter = &CommandExecuter{c} -} - -// Commander implementation -type CmdUserShowIndexes struct { - name string - rpcMethod string - rpcParams *EmptyWrapper - *CommandExecuter -} - -func (self *CmdUserShowIndexes) Name() string { - return self.name -} - -func (self *CmdUserShowIndexes) RpcMethod() string { - return self.rpcMethod -} - -func (self *CmdUserShowIndexes) RpcParams(reset bool) interface{} { - if reset || self.rpcParams == nil { - self.rpcParams = &EmptyWrapper{} - } - return self.rpcParams -} - -func (self *CmdUserShowIndexes) PostprocessRpcParams() error { - return nil -} - -func (self *CmdUserShowIndexes) RpcResult() interface{} { - s := map[string][]string{} - return &s -} diff --git a/console/user_remove.go b/console/user_remove.go deleted file mode 100644 index 90e2d2b88..000000000 --- a/console/user_remove.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package console - -import "github.com/cgrates/cgrates/engine" - -func init() { - c := &CmdUserRemove{ - name: "user_remove", - rpcMethod: "UsersV1.RemoveUser", - } - commands[c.Name()] = c - c.CommandExecuter = &CommandExecuter{c} -} - -// Commander implementation -type CmdUserRemove struct { - name string - rpcMethod string - rpcParams *engine.UserProfile - *CommandExecuter -} - -func (self *CmdUserRemove) Name() string { - return self.name -} - -func (self *CmdUserRemove) RpcMethod() string { - return self.rpcMethod -} - -func (self *CmdUserRemove) RpcParams(reset bool) interface{} { - if reset || self.rpcParams == nil { - self.rpcParams = &engine.UserProfile{} - } - return self.rpcParams -} - -func (self *CmdUserRemove) PostprocessRpcParams() error { - return nil -} - -func (self *CmdUserRemove) RpcResult() interface{} { - var s string - return &s -} diff --git a/console/user_set.go b/console/user_set.go deleted file mode 100644 index 9e40a347b..000000000 --- a/console/user_set.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package console - -import "github.com/cgrates/cgrates/engine" - -func init() { - c := &CmdSetUser{ - name: "user_set", - rpcMethod: "UsersV1.SetUser", - } - commands[c.Name()] = c - c.CommandExecuter = &CommandExecuter{c} -} - -// Commander implementation -type CmdSetUser struct { - name string - rpcMethod string - rpcParams *engine.UserProfile - *CommandExecuter -} - -func (self *CmdSetUser) Name() string { - return self.name -} - -func (self *CmdSetUser) RpcMethod() string { - return self.rpcMethod -} - -func (self *CmdSetUser) RpcParams(reset bool) interface{} { - if reset || self.rpcParams == nil { - self.rpcParams = &engine.UserProfile{} - } - return self.rpcParams -} - -func (self *CmdSetUser) PostprocessRpcParams() error { - return nil -} - -func (self *CmdSetUser) RpcResult() interface{} { - var s string - return &s -} diff --git a/console/user_update.go b/console/user_update.go deleted file mode 100644 index 125c9b035..000000000 --- a/console/user_update.go +++ /dev/null @@ -1,62 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package console - -import "github.com/cgrates/cgrates/engine" - -func init() { - c := &CmdUpdateUser{ - name: "user_update", - rpcMethod: "UsersV1.UpdateUser", - } - commands[c.Name()] = c - c.CommandExecuter = &CommandExecuter{c} -} - -// Commander implementation -type CmdUpdateUser struct { - name string - rpcMethod string - rpcParams *engine.UserProfile - *CommandExecuter -} - -func (self *CmdUpdateUser) Name() string { - return self.name -} - -func (self *CmdUpdateUser) RpcMethod() string { - return self.rpcMethod -} - -func (self *CmdUpdateUser) RpcParams(reset bool) interface{} { - if reset || self.rpcParams == nil { - self.rpcParams = &engine.UserProfile{} - } - return self.rpcParams -} - -func (self *CmdUpdateUser) PostprocessRpcParams() error { - return nil -} - -func (self *CmdUpdateUser) RpcResult() interface{} { - var s string - return &s -} diff --git a/console/users.go b/console/users.go deleted file mode 100644 index 35909ecf1..000000000 --- a/console/users.go +++ /dev/null @@ -1,63 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package console - -import "github.com/cgrates/cgrates/engine" - -func init() { - c := &CmdGetUsers{ - name: "users", - rpcMethod: "UsersV1.GetUsers", - rpcParams: &engine.UserProfile{}, - } - commands[c.Name()] = c - c.CommandExecuter = &CommandExecuter{c} -} - -// Commander implementation -type CmdGetUsers struct { - name string - rpcMethod string - rpcParams *engine.UserProfile - *CommandExecuter -} - -func (self *CmdGetUsers) Name() string { - return self.name -} - -func (self *CmdGetUsers) RpcMethod() string { - return self.rpcMethod -} - -func (self *CmdGetUsers) RpcParams(reset bool) interface{} { - if reset || self.rpcParams == nil { - self.rpcParams = &engine.UserProfile{} - } - return self.rpcParams -} - -func (self *CmdGetUsers) PostprocessRpcParams() error { - return nil -} - -func (self *CmdGetUsers) RpcResult() interface{} { - s := engine.UserProfiles{} - return &s -} diff --git a/data/conf/cgrates/cgrates.json b/data/conf/cgrates/cgrates.json index 8ac8c3a0e..805dcfa06 100644 --- a/data/conf/cgrates/cgrates.json +++ b/data/conf/cgrates/cgrates.json @@ -142,7 +142,6 @@ // "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> // "stats_conns": [], // address where to reach the stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> // "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> -// "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> // "rp_subject_prefix_matching": false, // enables prefix matching for the rating profile subject // "max_computed_usage": { // do not compute usage higher than this, prevents memory overload // "*any": "189h", @@ -164,7 +163,6 @@ // ], // "pubsubs_conns": [], // address where to reach the pubusb service, empty to disable pubsub functionality: <""|*internal|x.y.z.y:1234> // "attributes_conns": [], // address where to reach the attribute service, empty to disable attributes functionality: <""|*internal|x.y.z.y:1234> -// "users_conns": [], // address where to reach the user service, empty to disable user profile functionality: <""|*internal|x.y.z.y:1234> // "thresholds_conns": [], // address where to reach the thresholds service, empty to disable thresholds functionality: <""|*internal|x.y.z.y:1234> // "stats_conns": [], // address where to reach the stat service, empty to disable stats functionality: <""|*internal|x.y.z.y:1234> // "online_cdr_exports":[], // list of CDRE profiles to use for real-time CDR exports @@ -427,12 +425,6 @@ // }, -// "users": { -// "enabled": false, // starts User service: . -// "indexes": [], // user profile field indexes -// }, - - // "attributes": { // Attribute service // "enabled": false, // starts attribute service: . // //"string_indexed_fields": [], // query indexes based on these fields for faster processing diff --git a/data/conf/samples/actions/cgradmin.json b/data/conf/samples/actions/cgradmin.json index c8fe15246..76da30dbd 100644 --- a/data/conf/samples/actions/cgradmin.json +++ b/data/conf/samples/actions/cgradmin.json @@ -25,9 +25,6 @@ "pubsubs_conns": [ {"address": "*internal"} ], - "users_conns": [ - {"address": "*internal"} - ], }, "scheduler": { diff --git a/data/conf/samples/cgradmin/cgradmin.json b/data/conf/samples/cgradmin/cgradmin.json index 6498dd4a6..8a90ea44c 100644 --- a/data/conf/samples/cgradmin/cgradmin.json +++ b/data/conf/samples/cgradmin/cgradmin.json @@ -33,9 +33,6 @@ "pubsubs_conns": [ {"address": "*internal"} ], - "users_conns": [ - {"address": "*internal"} - ], }, "scheduler": { diff --git a/data/conf/samples/hapool/cgrrater1/cgr.json b/data/conf/samples/hapool/cgrrater1/cgr.json index ea3b086d4..899489bd1 100644 --- a/data/conf/samples/hapool/cgrrater1/cgr.json +++ b/data/conf/samples/hapool/cgrrater1/cgr.json @@ -10,9 +10,6 @@ "pubsubs_conns": [ {"address": "*internal"} ], - "users_conns": [ - {"address": "*internal"} - ], }, "scheduler": { diff --git a/data/conf/samples/hapool/cgrrater2/cgr.json b/data/conf/samples/hapool/cgrrater2/cgr.json index 655bb3da0..84928d173 100644 --- a/data/conf/samples/hapool/cgrrater2/cgr.json +++ b/data/conf/samples/hapool/cgrrater2/cgr.json @@ -11,9 +11,6 @@ "pubsubs_conns": [ {"address": "*internal"} ], - "users_conns": [ - {"address": "*internal"} - ], }, "scheduler": { diff --git a/data/conf/samples/mongoreplica/cgrates.json b/data/conf/samples/mongoreplica/cgrates.json index d2435e207..92e98f27d 100755 --- a/data/conf/samples/mongoreplica/cgrates.json +++ b/data/conf/samples/mongoreplica/cgrates.json @@ -73,9 +73,6 @@ "pubsubs_conns": [ {"address": "*internal"} ], - "users_conns": [ - {"address": "*internal"} - ], }, diff --git a/data/conf/samples/smgeneric/cgrates.json b/data/conf/samples/smgeneric/cgrates.json index d87ca1efd..6b413c6ee 100644 --- a/data/conf/samples/smgeneric/cgrates.json +++ b/data/conf/samples/smgeneric/cgrates.json @@ -42,9 +42,6 @@ "rals": { "enabled": true, // enable Rater service: - "users_conns": [ - {"address": "*internal"} - ], }, diff --git a/data/conf/samples/tutpostgres/cgrates.json b/data/conf/samples/tutpostgres/cgrates.json index 7307a62dd..e5a4d4590 100644 --- a/data/conf/samples/tutpostgres/cgrates.json +++ b/data/conf/samples/tutpostgres/cgrates.json @@ -34,9 +34,6 @@ "pubsubs_conns": [ {"address": "*internal"} ], - "users_conns": [ - {"address": "*internal"} - ], }, diff --git a/data/storage/postgres/create_tariffplan_tables.sql b/data/storage/postgres/create_tariffplan_tables.sql index c68bd9055..0f9f915f0 100644 --- a/data/storage/postgres/create_tariffplan_tables.sql +++ b/data/storage/postgres/create_tariffplan_tables.sql @@ -275,26 +275,6 @@ CREATE TABLE tp_derived_chargers ( CREATE INDEX tpderivedchargers_tpid_idx ON tp_derived_chargers (tpid); CREATE INDEX tpderivedchargers_idx ON tp_derived_chargers (tpid,loadid,direction,tenant,category,account,subject); --- --- Table structure for table `tp_users` --- - -DROP TABLE IF EXISTS tp_users; -CREATE TABLE tp_users ( - id SERIAL PRIMARY KEY, - tpid VARCHAR(64) NOT NULL, - tenant VARCHAR(64) NOT NULL, - user_name VARCHAR(64) NOT NULL, - masked BOOLEAN NOT NULL, - attribute_name VARCHAR(64) NOT NULL, - attribute_value VARCHAR(64) NOT NULL, - weight NUMERIC(8,2) NOT NULL, - created_at TIMESTAMP WITH TIME ZONE -); -CREATE INDEX tpusers_tpid_idx ON tp_users (tpid); -CREATE INDEX tpusers_idx ON tp_users (tpid,tenant,user_name); - - -- -- Table structure for table `tp_resources` -- diff --git a/docs/architecture.rst b/docs/architecture.rst index 393b65c8f..b9e1242c2 100644 --- a/docs/architecture.rst +++ b/docs/architecture.rst @@ -386,8 +386,6 @@ Can be used to: Timezone for timestamps where not specified <""|UTC|Local|$IANA_TZ_DB> (default "Local") -to_stordb Import the tariff plan from files to storDb - -users_address string - Users service to contact for data reloads, empty to disable automatic data reloads (default "127.0.0.1:2013") -validate When true will run various check on the loaded data to check for structural errors -verbose diff --git a/engine/cdrs.go b/engine/cdrs.go index fac29ffad..0dbac279a 100644 --- a/engine/cdrs.go +++ b/engine/cdrs.go @@ -1,17 +1,14 @@ /* Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments Copyright (C) ITsysCOM GmbH - 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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License along with this program. If not, see */ @@ -72,7 +69,7 @@ func fsCdrHandler(w http.ResponseWriter, r *http.Request) { // NewCDRServer is a constructor for CDRServer func NewCDRServer(cgrCfg *config.CGRConfig, cdrDb CdrStorage, dm *DataManager, rater, pubsub, - attrS, users, thdS, statS, chargerS rpcclient.RpcClientConnection, filterS *FilterS) *CDRServer { + attrS, thdS, statS, chargerS rpcclient.RpcClientConnection, filterS *FilterS) *CDRServer { if rater != nil && reflect.ValueOf(rater).IsNil() { rater = nil } @@ -82,9 +79,6 @@ func NewCDRServer(cgrCfg *config.CGRConfig, cdrDb CdrStorage, dm *DataManager, r if attrS != nil && reflect.ValueOf(attrS).IsNil() { attrS = nil } - if users != nil && reflect.ValueOf(users).IsNil() { - users = nil - } if thdS != nil && reflect.ValueOf(thdS).IsNil() { thdS = nil } @@ -96,7 +90,6 @@ func NewCDRServer(cgrCfg *config.CGRConfig, cdrDb CdrStorage, dm *DataManager, r } return &CDRServer{cgrCfg: cgrCfg, cdrDb: cdrDb, dm: dm, rals: rater, pubsub: pubsub, attrS: attrS, - users: users, statS: statS, thdS: thdS, chargerS: chargerS, guard: guardian.Guardian, respCache: utils.NewResponseCache(cgrCfg.GeneralCfg().ResponseCacheTTL), @@ -112,7 +105,6 @@ type CDRServer struct { rals rpcclient.RpcClientConnection pubsub rpcclient.RpcClientConnection attrS rpcclient.RpcClientConnection - users rpcclient.RpcClientConnection thdS rpcclient.RpcClientConnection statS rpcclient.RpcClientConnection chargerS rpcclient.RpcClientConnection diff --git a/engine/datamanager.go b/engine/datamanager.go index 0945f22d5..e30b6bc18 100644 --- a/engine/datamanager.go +++ b/engine/datamanager.go @@ -955,22 +955,6 @@ func (dm *DataManager) RemoveRatingProfile(key string, return } -func (dm *DataManager) SetUser(up *UserProfile) (err error) { - return dm.DataDB().SetUserDrv(up) -} - -func (dm *DataManager) GetUser(key string) (up *UserProfile, err error) { - return dm.DataDB().GetUserDrv(key) -} - -func (dm *DataManager) GetUsers() (result []*UserProfile, err error) { - return dm.DataDB().GetUsersDrv() -} - -func (dm *DataManager) RemoveUser(key string) error { - return dm.DataDB().RemoveUserDrv(key) -} - func (dm *DataManager) GetSubscribers() (result map[string]*SubscriberData, err error) { return dm.DataDB().GetSubscribersDrv() } diff --git a/engine/libtest.go b/engine/libtest.go index 768787973..41c6ccc03 100644 --- a/engine/libtest.go +++ b/engine/libtest.go @@ -137,7 +137,6 @@ func LoadTariffPlanFromFolder(tpPath, timezone string, dm *DataManager, disable_ path.Join(tpPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(tpPath, utils.DERIVED_CHARGERS_CSV), - path.Join(tpPath, utils.USERS_CSV), path.Join(tpPath, utils.ResourcesCsv), path.Join(tpPath, utils.StatsCsv), path.Join(tpPath, utils.ThresholdsCsv), diff --git a/engine/loader_csv_test.go b/engine/loader_csv_test.go index e1f525ba2..3c88e52c4 100644 --- a/engine/loader_csv_test.go +++ b/engine/loader_csv_test.go @@ -226,13 +226,6 @@ cgrates.org,round,TOPUP10_AT,,false,false *out,cgrates.org,call,dan,dan,,extra1,^filteredHeader1/filterValue1/,^prepaid,,,,rif,rif,,,,,,,,, *out,cgrates.org,call,dan,dan,,extra2,,,,,,ivo,ivo,,,,,,,,, *out,cgrates.org,call,dan,*any,,extra1,,,,,,rif2,rif2,,,,,,,,, -` - users = ` -#Tenant[0],UserName[1],AttributeName[2],AttributeValue[3],Weight[4] -cgrates.org,rif,false,test0,val0,10 -cgrates.org,rif,,test1,val1,10 -cgrates.org,dan,,another,value,10 -cgrates.org,mas,true,another,value,10 ` resProfiles = ` #Tenant[0],Id[1],FilterIDs[2],ActivationInterval[3],TTL[4],Limit[5],AllocationMessage[6],Blocker[7],Stored[8],Weight[9],Thresholds[10] @@ -289,7 +282,7 @@ var csvr *TpReader func init() { csvr = NewTpReader(dm.dataDB, NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, - accountActions, derivedCharges, users, resProfiles, stats, thresholds, + accountActions, derivedCharges, resProfiles, stats, thresholds, filters, sppProfiles, attributeProfiles, chargerProfiles, dispatcherProfiles), testTPID, "") if err := csvr.LoadDestinations(); err != nil { @@ -328,9 +321,6 @@ func init() { if err := csvr.LoadDerivedChargers(); err != nil { log.Print("error in LoadDerivedChargers:", err) } - if err := csvr.LoadUsers(); err != nil { - log.Print("error in LoadUsers:", err) - } if err := csvr.LoadFilters(); err != nil { log.Print("error in LoadFilter:", err) } @@ -1237,24 +1227,6 @@ func TestLoadDerivedChargers(t *testing.T) { } } -func TestLoadUsers(t *testing.T) { - if len(csvr.users) != 3 { - t.Error("Failed to load users: ", csvr.users) - } - user1 := &UserProfile{ - Tenant: "cgrates.org", - UserName: "rif", - Profile: map[string]string{ - "test0": "val0", - "test1": "val1", - }, - } - - if !reflect.DeepEqual(csvr.users[user1.GetId()], user1) { - t.Errorf("Unexpected user %+v", csvr.users[user1.GetId()]) - } -} - func TestLoadResourceProfiles(t *testing.T) { eResProfiles := map[utils.TenantID]*utils.TPResource{ utils.TenantID{Tenant: "cgrates.org", ID: "ResGroup21"}: &utils.TPResource{ diff --git a/engine/loader_it_test.go b/engine/loader_it_test.go index 8753e61b3..fc061a681 100644 --- a/engine/loader_it_test.go +++ b/engine/loader_it_test.go @@ -108,7 +108,6 @@ func TestLoaderITRemoveLoad(t *testing.T) { path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DERIVED_CHARGERS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.USERS_CSV), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ResourcesCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv), @@ -152,9 +151,6 @@ func TestLoaderITRemoveLoad(t *testing.T) { if err = loader.LoadDerivedChargers(); err != nil { t.Error("Failed loading derived chargers: ", err.Error()) } - if err = loader.LoadUsers(); err != nil { - t.Error("Failed loading users: ", err.Error()) - } if err = loader.LoadFilters(); err != nil { t.Error("Failed loading filters: ", err.Error()) } @@ -208,7 +204,6 @@ func TestLoaderITLoadFromCSV(t *testing.T) { path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACTION_TRIGGERS_CSV), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ACCOUNT_ACTIONS_CSV), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.DERIVED_CHARGERS_CSV), - path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.USERS_CSV), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ResourcesCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.StatsCsv), path.Join(*dataDir, "tariffplans", *tpCsvScenario, utils.ThresholdsCsv), @@ -252,9 +247,6 @@ func TestLoaderITLoadFromCSV(t *testing.T) { if err = loader.LoadDerivedChargers(); err != nil { t.Error("Failed loading derived chargers: ", err.Error()) } - if err = loader.LoadUsers(); err != nil { - t.Error("Failed loading users: ", err.Error()) - } if err = loader.LoadFilters(); err != nil { t.Error("Failed loading filters: ", err.Error()) } @@ -385,16 +377,6 @@ func TestLoaderITWriteToDatabase(t *testing.T) { } } - for k, u := range loader.users { - rcv, err := loader.dm.GetUser(k) - if err != nil { - t.Error("Failed GetUser: ", err.Error()) - } - if !reflect.DeepEqual(u, rcv) { - t.Errorf("Expecting: %v, received: %v", u, rcv) - } - } - for tenantid, rl := range loader.resProfiles { rcv, err := loader.dm.GetResourceProfile(tenantid.Tenant, tenantid.ID, false, false, utils.NonTransactional) if err != nil { @@ -551,9 +533,6 @@ func TestLoaderITLoadFromStorDb(t *testing.T) { if err := loader.LoadDerivedChargers(); err != nil && err.Error() != utils.NotFoundCaps { t.Error("Failed loading derived chargers: ", err.Error()) } - if err := loader.LoadUsers(); err != nil && err.Error() != utils.NotFoundCaps { - t.Error("Failed loading users: ", err.Error()) - } } func TestLoaderITLoadIndividualProfiles(t *testing.T) { @@ -596,18 +575,7 @@ func TestLoaderITLoadIndividualProfiles(t *testing.T) { } } } - // Load users - if us, err := storDb.GetTPUsers(&utils.TPUsers{TPid: utils.TEST_SQL}); err != nil { - t.Fatal("Could not retrieve users, error: ", err.Error()) - } else if len(us) == 0 { - t.Fatal("Could not retrieve users") - } else { - for _, u := range us { - if found, err := loader.LoadUsersFiltered(u); found && err != nil { - t.Fatalf("Could not user with id: %s, error: %s", u.GetId(), err.Error()) - } - } - } + // Load account actions if aas, err := storDb.GetTPAccountActions(&utils.TPAccountActions{TPid: utils.TEST_SQL, LoadId: loadId}); err != nil { t.Fatal("Could not retrieve account action profiles, error: ", err.Error()) diff --git a/engine/model_helpers.go b/engine/model_helpers.go index 8ba4da72e..cb630718c 100644 --- a/engine/model_helpers.go +++ b/engine/model_helpers.go @@ -1236,90 +1236,6 @@ func ValueOrDefault(val string, deflt string) string { return val } -type TpUsers []TpUser - -func (tps TpUsers) AsMapTPUsers() (map[string]*utils.TPUsers, error) { - result := make(map[string]*utils.TPUsers) - for _, tp := range tps { - var u *utils.TPUsers - var found bool - if u, found = result[tp.GetId()]; !found { - u = &utils.TPUsers{ - TPid: tp.Tpid, - Tenant: tp.Tenant, - UserName: tp.UserName, - Masked: tp.Masked, - Weight: tp.Weight, - } - result[tp.GetId()] = u - } - u.Profile = append(u.Profile, - &utils.TPUserProfile{ - AttrName: tp.AttributeName, - AttrValue: tp.AttributeValue, - }) - } - return result, nil -} - -func (tps TpUsers) AsTPUsers() (result []*utils.TPUsers, err error) { - if atps, err := tps.AsMapTPUsers(); err != nil { - return nil, err - } else { - for _, tp := range atps { - result = append(result, tp) - } - return result, nil - } -} - -func MapTPUsers(s []*utils.TPUsers) (map[string]*utils.TPUsers, error) { - result := make(map[string]*utils.TPUsers) - for _, e := range s { - if _, found := result[e.GetId()]; !found { - result[e.GetId()] = e - } else { - return nil, fmt.Errorf("Non unique ID %+v", e.GetId()) - } - } - return result, nil -} - -func APItoModelUsers(us *utils.TPUsers) (result TpUsers) { - if us != nil { - for _, p := range us.Profile { - result = append(result, TpUser{ - Tpid: us.TPid, - Tenant: us.Tenant, - UserName: us.UserName, - Masked: us.Masked, - Weight: us.Weight, - AttributeName: p.AttrName, - AttributeValue: p.AttrValue, - }) - } - if len(us.Profile) == 0 { - result = append(result, TpUser{ - Tpid: us.TPid, - Tenant: us.Tenant, - UserName: us.UserName, - Masked: us.Masked, - Weight: us.Weight, - }) - } - } - return -} - -func APItoModelUsersA(ts []*utils.TPUsers) (result TpUsers) { - for _, t := range ts { - for _, st := range APItoModelUsers(t) { - result = append(result, st) - } - } - return result -} - type TpResources []*TpResource func (tps TpResources) AsTPResources() (result []*utils.TPResource) { diff --git a/engine/onstor_it_test.go b/engine/onstor_it_test.go index b5b1d136c..1303e426d 100644 --- a/engine/onstor_it_test.go +++ b/engine/onstor_it_test.go @@ -83,7 +83,6 @@ var sTestsOnStorIT = []func(t *testing.T){ //testOnStorITCacheActionTriggers, //testOnStorITCRUDActionTriggers, - //testOnStorITCRUDUser, } func TestOnStorITRedis(t *testing.T) { @@ -1233,38 +1232,6 @@ func testOnStorITCRUDSubscribers(t *testing.T) { } } -func testOnStorITCRUDUser(t *testing.T) { - usr := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - if _, rcvErr := onStor.GetUser(usr.GetId()); rcvErr != utils.ErrNotFound { - t.Error(rcvErr) - } - if err := onStor.SetUser(usr); err != nil { - t.Error(err) - } - if rcv, err := onStor.GetUser(usr.GetId()); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(usr, rcv) { - t.Errorf("Expecting: %v, received: %v", usr, rcv) - } - if rcv, err := onStor.GetUsers(); err != nil { - t.Error(err) - } else if !reflect.DeepEqual(usr, rcv[0]) { - t.Errorf("Expecting: %v, received: %v", usr, rcv[0]) - } - if err := onStor.RemoveUser(usr.GetId()); err != nil { - t.Error(err) - } - if _, rcvErr := onStor.GetUser(usr.GetId()); rcvErr != utils.ErrNotFound { - t.Error(rcvErr) - } -} - func testOnStorITResourceProfile(t *testing.T) { rL := &ResourceProfile{ Tenant: "cgrates.org", diff --git a/engine/responder.go b/engine/responder.go index 0273685e5..7dfa10c2f 100644 --- a/engine/responder.go +++ b/engine/responder.go @@ -78,10 +78,6 @@ func (rs *Responder) GetCost(arg *CallDescriptor, reply *CallCost) (err error) { if arg.Subject == "" { arg.Subject = arg.Account } - // replace user profile fields - if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil { - return err - } if !rs.usageAllowed(arg.TOR, arg.GetDuration()) { return utils.ErrMaxUsageExceeded } @@ -101,10 +97,6 @@ func (rs *Responder) Debit(arg *CallDescriptor, reply *CallCost) (err error) { if arg.Subject == "" { arg.Subject = arg.Account } - // replace user profile fields - if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil { - return err - } if !rs.usageAllowed(arg.TOR, arg.GetDuration()) { return utils.ErrMaxUsageExceeded } @@ -128,10 +120,6 @@ func (rs *Responder) MaxDebit(arg *CallDescriptor, reply *CallCost) (err error) if arg.Subject == "" { arg.Subject = arg.Account } - // replace user profile fields - if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil { - return err - } if !rs.usageAllowed(arg.TOR, arg.GetDuration()) { return utils.ErrMaxUsageExceeded } @@ -162,10 +150,6 @@ func (rs *Responder) RefundIncrements(arg *CallDescriptor, reply *Account) (err if arg.Subject == "" { arg.Subject = arg.Account } - // replace user profile fields - if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil { - return err - } if !rs.usageAllowed(arg.TOR, arg.GetDuration()) { err = utils.ErrMaxUsageExceeded rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{ @@ -199,10 +183,6 @@ func (rs *Responder) RefundRounding(arg *CallDescriptor, reply *float64) (err er if arg.Subject == "" { arg.Subject = arg.Account } - // replace user profile fields - if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil { - return err - } if !rs.usageAllowed(arg.TOR, arg.GetDuration()) { return utils.ErrMaxUsageExceeded } @@ -218,10 +198,6 @@ func (rs *Responder) GetMaxSessionTime(arg *CallDescriptor, reply *time.Duration if arg.Subject == "" { arg.Subject = arg.Account } - // replace user profile fields - if err := LoadUserProfile(arg, utils.EXTRA_FIELDS); err != nil { - return err - } if !rs.usageAllowed(arg.TOR, arg.GetDuration()) { return utils.ErrMaxUsageExceeded } @@ -242,11 +218,6 @@ func (rs *Responder) GetDerivedMaxSessionTime(ev *CDR, reply *time.Duration) (er if ev.Subject == "" { ev.Subject = ev.Account } - // replace user profile fields - if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil { - rs.getCache().Cache(cacheKey, &utils.ResponseCacheItem{Err: err}) - return err - } if !rs.usageAllowed(ev.ToR, ev.Usage) { return utils.ErrMaxUsageExceeded } @@ -338,11 +309,6 @@ func (rs *Responder) GetSessionRuns(ev *CDR, sRuns *[]*SessionRun) (err error) { ev.Subject = ev.Account } //utils.Logger.Info(fmt.Sprintf("DC before: %+v", ev)) - // replace user profile fields - if err := LoadUserProfile(ev, utils.EXTRA_FIELDS); err != nil { - return err - } - //utils.Logger.Info(fmt.Sprintf("DC after: %+v", ev)) attrsDC := &utils.AttrDerivedChargers{Tenant: ev.Tenant, Category: ev.Category, Direction: utils.OUT, Account: ev.Account, Subject: ev.Subject, diff --git a/engine/storage_csv.go b/engine/storage_csv.go index a09aedd0e..38cd2ba74 100644 --- a/engine/storage_csv.go +++ b/engine/storage_csv.go @@ -36,7 +36,7 @@ type CSVStorage struct { destinationratetimingsFn, ratingprofilesFn, sharedgroupsFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn, derivedChargersFn, - usersFn, resProfilesFn, statsFn, thresholdsFn, + resProfilesFn, statsFn, thresholdsFn, filterFn, suppProfilesFn, attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn string } @@ -45,9 +45,9 @@ func NewFileCSVStorage(sep rune, destinationsFn, timingsFn, ratesFn, destinationratesFn, destinationratetimingsFn, ratingprofilesFn, sharedgroupsFn, actionsFn, actiontimingsFn, actiontriggersFn, accountactionsFn, - derivedChargersFn, usersFn, - resProfilesFn, statsFn, thresholdsFn, filterFn, suppProfilesFn, - attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn string) *CSVStorage { + derivedChargersFn, resProfilesFn, statsFn, thresholdsFn, + filterFn, suppProfilesFn, attributeProfilesFn, + chargerProfilesFn, dispatcherProfilesFn string) *CSVStorage { return &CSVStorage{ sep: sep, readerFunc: openFileCSVStorage, @@ -63,7 +63,6 @@ func NewFileCSVStorage(sep rune, actiontriggersFn: actiontriggersFn, accountactionsFn: accountactionsFn, derivedChargersFn: derivedChargersFn, - usersFn: usersFn, resProfilesFn: resProfilesFn, statsFn: statsFn, thresholdsFn: thresholdsFn, @@ -79,7 +78,7 @@ func NewStringCSVStorage(sep rune, destinationsFn, timingsFn, ratesFn, destinationratesFn, destinationratetimingsFn, ratingprofilesFn, sharedgroupsFn, actionsFn, actiontimingsFn, actiontriggersFn, - accountactionsFn, derivedChargersFn, usersFn, + accountactionsFn, derivedChargersFn, resProfilesFn, statsFn, thresholdsFn, filterFn, suppProfilesFn, attributeProfilesFn, chargerProfilesFn, @@ -87,11 +86,10 @@ func NewStringCSVStorage(sep rune, c := NewFileCSVStorage(sep, destinationsFn, timingsFn, ratesFn, destinationratesFn, destinationratetimingsFn, ratingprofilesFn, sharedgroupsFn, actionsFn, - actiontimingsFn, actiontriggersFn, - accountactionsFn, derivedChargersFn, - usersFn, resProfilesFn, - statsFn, thresholdsFn, filterFn, suppProfilesFn, - attributeProfilesFn, chargerProfilesFn, dispatcherProfilesFn) + actiontimingsFn, actiontriggersFn, accountactionsFn, + derivedChargersFn, resProfilesFn, statsFn, + thresholdsFn, filterFn, suppProfilesFn, attributeProfilesFn, + chargerProfilesFn, dispatcherProfilesFn) c.readerFunc = openStringCSVStorage return c } @@ -501,40 +499,6 @@ func (csvs *CSVStorage) GetTPDerivedChargers(filter *utils.TPDerivedChargers) ([ } } -func (csvs *CSVStorage) GetTPUsers(filter *utils.TPUsers) ([]*utils.TPUsers, error) { - csvReader, fp, err := csvs.readerFunc(csvs.usersFn, csvs.sep, getColumnCount(TpUser{})) - if err != nil { - //log.Print("Could not load users file: ", err) - // allow writing of the other values - return nil, nil - } - if fp != nil { - defer fp.Close() - } - var tpUsers TpUsers - for record, err := csvReader.Read(); err != io.EOF; record, err = csvReader.Read() { - if err != nil { - log.Printf("bad line in %s, %s\n", csvs.usersFn, err.Error()) - return nil, err - } - if tpUser, err := csvLoad(TpUser{}, record); err != nil { - log.Print("error loading user: ", err) - return nil, err - } else { - u := tpUser.(TpUser) - if filter != nil { - u.Tpid = filter.TPid - } - tpUsers = append(tpUsers, u) - } - } - if us, err := tpUsers.AsTPUsers(); err != nil { - return nil, err - } else { - return us, nil - } -} - func (csvs *CSVStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResource, error) { csvReader, fp, err := csvs.readerFunc(csvs.resProfilesFn, csvs.sep, getColumnCount(TpResource{})) if err != nil { diff --git a/engine/storage_interface.go b/engine/storage_interface.go index 48e43707b..21b1e59e9 100644 --- a/engine/storage_interface.go +++ b/engine/storage_interface.go @@ -89,10 +89,6 @@ type DataDB interface { GetSubscribersDrv() (map[string]*SubscriberData, error) SetSubscriberDrv(string, *SubscriberData) error RemoveSubscriberDrv(string) error - SetUserDrv(*UserProfile) error - GetUserDrv(string) (*UserProfile, error) - GetUsersDrv() ([]*UserProfile, error) - RemoveUserDrv(string) error GetResourceProfileDrv(string, string) (*ResourceProfile, error) SetResourceProfileDrv(*ResourceProfile) error RemoveResourceProfileDrv(string, string) error @@ -173,7 +169,6 @@ type LoadReader interface { GetTPRatingPlans(string, string, *utils.Paginator) ([]*utils.TPRatingPlan, error) GetTPRatingProfiles(*utils.TPRatingProfile) ([]*utils.TPRatingProfile, error) GetTPSharedGroups(string, string) ([]*utils.TPSharedGroups, error) - GetTPUsers(*utils.TPUsers) ([]*utils.TPUsers, error) GetTPDerivedChargers(*utils.TPDerivedChargers) ([]*utils.TPDerivedChargers, error) GetTPActions(string, string) ([]*utils.TPActions, error) GetTPActionPlans(string, string) ([]*utils.TPActionPlan, error) @@ -198,7 +193,6 @@ type LoadWriter interface { SetTPRatingPlans([]*utils.TPRatingPlan) error SetTPRatingProfiles([]*utils.TPRatingProfile) error SetTPSharedGroups([]*utils.TPSharedGroups) error - SetTPUsers([]*utils.TPUsers) error SetTPDerivedChargers([]*utils.TPDerivedChargers) error SetTPActions([]*utils.TPActions) error SetTPActionPlans([]*utils.TPActionPlan) error diff --git a/engine/storage_map_datadb.go b/engine/storage_map_datadb.go index 1f8a3b87b..a4fde16e8 100644 --- a/engine/storage_map_datadb.go +++ b/engine/storage_map_datadb.go @@ -566,50 +566,6 @@ func (ms *MapStorage) RemoveSubscriberDrv(key string) (err error) { return } -func (ms *MapStorage) SetUserDrv(up *UserProfile) error { - ms.mu.Lock() - defer ms.mu.Unlock() - result, err := ms.ms.Marshal(up) - if err != nil { - return err - } - ms.dict[utils.USERS_PREFIX+up.GetId()] = result - return nil -} - -func (ms *MapStorage) GetUserDrv(key string) (up *UserProfile, err error) { - ms.mu.RLock() - defer ms.mu.RUnlock() - up = &UserProfile{} - if values, ok := ms.dict[utils.USERS_PREFIX+key]; ok { - err = ms.ms.Unmarshal(values, &up) - } else { - return nil, utils.ErrNotFound - } - return -} - -func (ms *MapStorage) GetUsersDrv() (result []*UserProfile, err error) { - ms.mu.RLock() - defer ms.mu.RUnlock() - for key, value := range ms.dict { - if strings.HasPrefix(key, utils.USERS_PREFIX) { - up := &UserProfile{} - if err = ms.ms.Unmarshal(value, up); err == nil { - result = append(result, up) - } - } - } - return -} - -func (ms *MapStorage) RemoveUserDrv(key string) error { - ms.mu.Lock() - defer ms.mu.Unlock() - delete(ms.dict, utils.USERS_PREFIX+key) - return nil -} - func (ms *MapStorage) GetLoadHistory(limitItems int, skipCache bool, transactionID string) ([]*utils.LoadInstance, error) { ms.mu.RLock() diff --git a/engine/storage_map_stordb.go b/engine/storage_map_stordb.go index e9443a0a1..1d262a4a1 100755 --- a/engine/storage_map_stordb.go +++ b/engine/storage_map_stordb.go @@ -52,9 +52,6 @@ func (ms *MapStorage) GetTPRatingProfiles(filter *utils.TPRatingProfile) (rProfi func (ms *MapStorage) GetTPSharedGroups(tpid, id string) (sGroups []*utils.TPSharedGroups, err error) { return nil, utils.ErrNotImplemented } -func (ms *MapStorage) GetTPUsers(filter *utils.TPUsers) (users []*utils.TPUsers, err error) { - return nil, utils.ErrNotImplemented -} func (ms *MapStorage) GetTPDerivedChargers(*utils.TPDerivedChargers) (dCharges []*utils.TPDerivedChargers, err error) { return nil, utils.ErrNotImplemented } @@ -120,9 +117,6 @@ func (ms *MapStorage) SetTPRatingProfiles(ratingProfiles []*utils.TPRatingProfil func (ms *MapStorage) SetTPSharedGroups(groups []*utils.TPSharedGroups) (err error) { return utils.ErrNotImplemented } -func (ms *MapStorage) SetTPUsers(users []*utils.TPUsers) (err error) { - return utils.ErrNotImplemented -} func (ms *MapStorage) SetTPDerivedChargers(dc []*utils.TPDerivedChargers) (err error) { return utils.ErrNotImplemented diff --git a/engine/storage_mongo_datadb.go b/engine/storage_mongo_datadb.go index 39a405761..a10d9f53a 100644 --- a/engine/storage_mongo_datadb.go +++ b/engine/storage_mongo_datadb.go @@ -57,7 +57,6 @@ const ( colShg = "shared_groups" colDcs = "derived_chargers" colPbs = "pubsub" - colUsr = "users" colLht = "load_history" colVer = "versions" colRsP = "resource_profiles" @@ -239,7 +238,7 @@ func (ms *MongoStorage) GetContext() context.Context { func (ms *MongoStorage) EnsureIndexes() (err error) { if ms.storageType == utils.DataDB { for _, col := range []string{colAct, colApl, colAAp, colAtr, - colDcs, colRpl, colDst, colRds, colUsr, colLht} { + colDcs, colRpl, colDst, colRds, colLht} { if err = ms.EnusureIndex(col, true, "key"); err != nil { return } @@ -272,11 +271,6 @@ func (ms *MongoStorage) EnsureIndexes() (err error) { return } - if err = ms.EnusureIndex(utils.TBLTPUsers, true, "tpid", "tenant", - "username"); err != nil { - return - } - if err = ms.EnusureIndex(utils.TBLTPDerivedChargers, true, "tpid", "tenant", "category", "subject", "account", "loadid"); err != nil { return @@ -331,7 +325,6 @@ func (ms *MongoStorage) getColNameForPrefix(prefix string) (string, bool) { utils.SHARED_GROUP_PREFIX: colShg, utils.DERIVEDCHARGERS_PREFIX: colDcs, utils.PUBSUB_SUBSCRIBERS_PREFIX: colPbs, - utils.USERS_PREFIX: colUsr, utils.LOADINST_KEY: colLht, utils.VERSION_PREFIX: colVer, utils.TimingsPrefix: colTmg, @@ -1151,71 +1144,6 @@ func (ms *MongoStorage) RemoveSubscriberDrv(key string) (err error) { }) } -func (ms *MongoStorage) GetUserDrv(key string) (up *UserProfile, err error) { - var kv struct { - Key string - Value *UserProfile - } - if err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur := ms.getCol(colUsr).FindOne(sctx, bson.M{"key": key}) - if err := cur.Decode(&kv); err != nil { - if err == mongo.ErrNoDocuments { - return utils.ErrNotFound - } - return err - } - return nil - }); err != nil { - return nil, err - } - return kv.Value, nil -} - -func (ms *MongoStorage) GetUsersDrv() (result []*UserProfile, err error) { - err = ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur, err := ms.getCol(colUsr).Find(sctx, bson.D{}) - if err != nil { - return err - } - for cur.Next(sctx) { - var kv struct { - Key string - Value *UserProfile - } - err := cur.Decode(&kv) - if err != nil { - return err - } - result = append(result, kv.Value) - } - return cur.Close(sctx) - }) - return -} - -func (ms *MongoStorage) SetUserDrv(up *UserProfile) (err error) { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - _, err = ms.getCol(colUsr).UpdateOne(sctx, bson.M{"key": up.GetId()}, - bson.M{"$set": struct { - Key string - Value *UserProfile - }{Key: up.GetId(), Value: up}}, - options.Update().SetUpsert(true), - ) - return err - }) -} - -func (ms *MongoStorage) RemoveUserDrv(key string) (err error) { - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - dr, err := ms.getCol(colUsr).DeleteOne(sctx, bson.M{"key": key}) - if dr.DeletedCount == 0 { - return utils.ErrNotFound - } - return err - }) -} - // Limit will only retrieve the last n items out of history, newest first func (ms *MongoStorage) GetLoadHistory(limit int, skipCache bool, transactionID string) (loadInsts []*utils.LoadInstance, err error) { diff --git a/engine/storage_mongo_stordb.go b/engine/storage_mongo_stordb.go index 099c48e10..158cf75eb 100644 --- a/engine/storage_mongo_stordb.go +++ b/engine/storage_mongo_stordb.go @@ -89,11 +89,7 @@ func (ms *MongoStorage) GetTpTableIds(tpid, table string, distinct utils.TPDisti for k, v := range filter { findMap[k] = v } - for k, v := range distinct { //fix for MongoStorage on TPUsers - if v == "user_name" { - distinct[k] = "username" - } - } + if pag != nil && pag.SearchTerm != "" { var searchItems []bson.M for _, d := range distinct { @@ -374,36 +370,6 @@ func (ms *MongoStorage) GetTPSharedGroups(tpid, id string) ([]*utils.TPSharedGro return results, err } -func (ms *MongoStorage) GetTPUsers(tp *utils.TPUsers) ([]*utils.TPUsers, error) { - filter := bson.M{"tpid": tp.TPid} - if tp.Tenant != "" { - filter["tenant"] = tp.Tenant - } - if tp.UserName != "" { - filter["username"] = tp.UserName - } - var results []*utils.TPUsers - err := ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - cur, err := ms.getCol(utils.TBLTPUsers).Find(sctx, filter) - if err != nil { - return err - } - for cur.Next(sctx) { - var el utils.TPUsers - err := cur.Decode(&el) - if err != nil { - return err - } - results = append(results, &el) - } - if len(results) == 0 { - return utils.ErrNotFound - } - return cur.Close(sctx) - }) - return results, err -} - func (ms *MongoStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResource, error) { filter := bson.M{"tpid": tpid} if id != "" { @@ -649,12 +615,6 @@ func (ms *MongoStorage) RemTpData(table, tpid string, args map[string]string) er if args == nil { args = make(map[string]string) } - for arg, val := range args { //fix for Mongo TPUsers tables - if arg == "user_name" { - delete(args, arg) - args["username"] = val - } - } if _, has := args["tag"]; has { // API uses tag to be compatible with SQL models, fix it here args["id"] = args["tag"] @@ -821,31 +781,6 @@ func (ms *MongoStorage) SetTPSharedGroups(tps []*utils.TPSharedGroups) error { }) } -func (ms *MongoStorage) SetTPUsers(tps []*utils.TPUsers) error { - if len(tps) == 0 { - return nil - } - m := make(map[string]bool) - return ms.client.UseSession(ms.ctx, func(sctx mongo.SessionContext) (err error) { - for _, tp := range tps { - if found, _ := m[tp.GetId()]; !found { - m[tp.GetId()] = true - if _, err := ms.getCol(utils.TBLTPUsers).DeleteMany(sctx, bson.M{ - "tpid": tp.TPid, - "tenant": tp.Tenant, - "username": tp.UserName, - }); err != nil { - return err - } - } - if _, err := ms.getCol(utils.TBLTPUsers).InsertOne(sctx, tp); err != nil { - return err - } - } - return nil - }) -} - func (ms *MongoStorage) SetTPDerivedChargers(tps []*utils.TPDerivedChargers) error { if len(tps) == 0 { return nil diff --git a/engine/storage_redis.go b/engine/storage_redis.go index f03849017..f1e15c9c6 100644 --- a/engine/storage_redis.go +++ b/engine/storage_redis.go @@ -744,50 +744,6 @@ func (rs *RedisStorage) RemoveSubscriberDrv(key string) (err error) { return } -func (rs *RedisStorage) SetUserDrv(up *UserProfile) (err error) { - var result []byte - if result, err = rs.ms.Marshal(up); err != nil { - return - } - return rs.Cmd("SET", utils.USERS_PREFIX+up.GetId(), result).Err -} - -func (rs *RedisStorage) GetUserDrv(key string) (up *UserProfile, err error) { - var values []byte - if values, err = rs.Cmd("GET", utils.USERS_PREFIX+key).Bytes(); err != nil { - if err == redis.ErrRespNil { // did not find the destination - err = utils.ErrNotFound - } - return - } - up = new(UserProfile) - if err = rs.ms.Unmarshal(values, &up); err != nil { - return nil, err - } - return -} - -func (rs *RedisStorage) GetUsersDrv() (result []*UserProfile, err error) { - keys, err := rs.Cmd("KEYS", utils.USERS_PREFIX+"*").List() - if err != nil { - return nil, err - } - for _, key := range keys { - if values, err := rs.Cmd("GET", key).Bytes(); err == nil { - up := &UserProfile{} - err = rs.ms.Unmarshal(values, up) - result = append(result, up) - } else { - return nil, utils.ErrNotFound - } - } - return -} - -func (rs *RedisStorage) RemoveUserDrv(key string) error { - return rs.Cmd("DEL", utils.USERS_PREFIX+key).Err -} - // Limit will only retrieve the last n items out of history, newest first func (rs *RedisStorage) GetLoadHistory(limit int, skipCache bool, transactionID string) ([]*utils.LoadInstance, error) { diff --git a/engine/storage_sql.go b/engine/storage_sql.go index 79784bd92..a6d797aa2 100644 --- a/engine/storage_sql.go +++ b/engine/storage_sql.go @@ -105,7 +105,7 @@ func (self *SQLStorage) IsDBEmpty() (resp bool, err error) { utils.TBLTPTimings, utils.TBLTPDestinations, utils.TBLTPRates, utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, utils.TBLTPSharedGroups, utils.TBLTPActions, utils.TBLTPActionTriggers, - utils.TBLTPAccountActions, utils.TBLTPDerivedChargers, utils.TBLTPUsers, + utils.TBLTPAccountActions, utils.TBLTPDerivedChargers, utils.TBLTPResources, utils.TBLTPStats, utils.TBLTPThresholds, utils.TBLTPFilters, utils.SessionCostsTBL, utils.CDRsTBL, utils.TBLTPActionPlans, utils.TBLVersions, utils.TBLTPSuppliers, utils.TBLTPAttributes, utils.TBLTPChargers, @@ -127,7 +127,7 @@ func (self *SQLStorage) GetTpIds(colName string) ([]string, error) { 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) UNION (SELECT tpid FROM %s)", + "(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, @@ -139,7 +139,6 @@ func (self *SQLStorage) GetTpIds(colName string) ([]string, error) { utils.TBLTPActionTriggers, utils.TBLTPAccountActions, utils.TBLTPDerivedChargers, - utils.TBLTPUsers, utils.TBLTPResources, utils.TBLTPStats, utils.TBLTPThresholds, @@ -238,7 +237,7 @@ func (self *SQLStorage) RemTpData(table, tpid string, args map[string]string) er utils.TBLTPDestinationRates, utils.TBLTPRatingPlans, utils.TBLTPRateProfiles, utils.TBLTPSharedGroups, utils.TBLTPActions, utils.TBLTPActionPlans, utils.TBLTPActionTriggers, utils.TBLTPAccountActions, - utils.TBLTPDerivedChargers, utils.TBLTPUsers, utils.TBLTPResources, + utils.TBLTPDerivedChargers, utils.TBLTPResources, utils.TBLTPStats, utils.TBLTPFilters, utils.TBLTPSuppliers, utils.TBLTPAttributes, utils.TBLTPChargers, utils.TBLTPDispatchers} { if err := tx.Table(tblName).Where("tpid = ?", tpid).Delete(nil).Error; err != nil { @@ -1390,53 +1389,6 @@ func (self *SQLStorage) GetTPDerivedChargers(filter *utils.TPDerivedChargers) ([ } } -func (self *SQLStorage) SetTPUsers(users []*utils.TPUsers) error { - if len(users) == 0 { - return nil - } - m := make(map[string]bool) - tx := self.db.Begin() - for _, user := range users { - if found, _ := m[user.Tenant]; !found { - m[user.Tenant] = true - if err := tx.Where(&TpUser{Tpid: user.TPid, Tenant: user.Tenant, UserName: user.UserName}).Delete(&TpUser{}).Error; err != nil { - tx.Rollback() - return err - } - } - for _, u := range APItoModelUsers(user) { - if err := tx.Save(&u).Error; err != nil { - tx.Rollback() - return err - } - } - } - tx.Commit() - return nil -} - -func (self *SQLStorage) GetTPUsers(filter *utils.TPUsers) ([]*utils.TPUsers, error) { - var tpUsers TpUsers - q := self.db.Where("tpid = ?", filter.TPid) - if len(filter.Tenant) != 0 { - q = q.Where("tenant = ?", filter.Tenant) - } - if len(filter.UserName) != 0 { - q = q.Where("user_name = ?", filter.UserName) - } - if err := q.Find(&tpUsers).Error; err != nil { - return nil, err - } - if us, err := tpUsers.AsTPUsers(); err != nil { - return nil, err - } else { - if len(us) == 0 { - return us, utils.ErrNotFound - } - return us, nil - } -} - func (self *SQLStorage) GetTPResources(tpid, tenant, id string) ([]*utils.TPResource, error) { var rls TpResources q := self.db.Where("tpid = ?", tpid) diff --git a/engine/stordb_it_test.go b/engine/stordb_it_test.go index 870127827..10141ecc0 100644 --- a/engine/stordb_it_test.go +++ b/engine/stordb_it_test.go @@ -53,7 +53,6 @@ var sTestsStorDBit = []func(t *testing.T){ testStorDBitCRUDTpActionTriggers, testStorDBitCRUDTpAccountActions, testStorDBitCRUDTpDerivedChargers, - testStorDBitCRUDTpUsers, testStorDBitCRUDTpResources, testStorDBitCRUDTpStats, testStorDBitCRUDCDRs, @@ -1092,78 +1091,6 @@ func testStorDBitCRUDTpDerivedChargers(t *testing.T) { } } -func testStorDBitCRUDTpUsers(t *testing.T) { - // READ - var filter = utils.TPUsers{ - TPid: "testTPid", - } - if _, err := storDB.GetTPUsers(&filter); err != utils.ErrNotFound { - t.Error(err) - } - // WRITE - var snd = []*utils.TPUsers{ - { - TPid: "testTPid", - Tenant: "cgrates.org", - Masked: true, - UserName: "1001", - Weight: 0.1, - Profile: []*utils.TPUserProfile{ - { - AttrName: "Account", - AttrValue: "1001", - }, - }, - }, - { - TPid: "testTPid", - Tenant: "cgrates.org", - Masked: true, - UserName: "1002", - Weight: 0.1, - Profile: []*utils.TPUserProfile{ - { - AttrName: "Account", - AttrValue: "1001", - }, - }, - }, - } - if err := storDB.SetTPUsers(snd); err != nil { - t.Error(err) - } - // READ - if rcv, err := storDB.GetTPUsers(&filter); err != nil { - t.Error(err) - } else { - if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { - t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v\n||\n%+v", utils.ToIJSON(snd[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1])) - } - } - // UPDATE - snd[0].Masked = false - snd[1].Masked = false - if err := storDB.SetTPUsers(snd); err != nil { - t.Error(err) - } - // READ - if rcv, err := storDB.GetTPUsers(&filter); err != nil { - t.Error(err) - } else { - if !(reflect.DeepEqual(snd[0], rcv[0]) || reflect.DeepEqual(snd[0], rcv[1])) { - t.Errorf("\nExpecting:\n%+v\nReceived:\n%+v\n||\n%+v", utils.ToIJSON(snd[0]), utils.ToIJSON(rcv[0]), utils.ToIJSON(rcv[1])) - } - } - // REMOVE - if err := storDB.RemTpData("", "testTPid", nil); err != nil { - t.Error(err) - } - // READ - if _, err := storDB.GetTPUsers(&filter); err != utils.ErrNotFound { - t.Error(err) - } -} - func testStorDBitCRUDTpResources(t *testing.T) { // READ if _, err := storDB.GetTPResources("testTPid", "", ""); err != utils.ErrNotFound { diff --git a/engine/tpexporter.go b/engine/tpexporter.go index 18b608a5c..bf92b706c 100644 --- a/engine/tpexporter.go +++ b/engine/tpexporter.go @@ -295,17 +295,6 @@ func (self *TPExporter) Run() error { } } - storDataUsers, err := self.storDb.GetTPUsers(&utils.TPUsers{TPid: self.tpID}) - if err != nil && err.Error() != utils.ErrNotFound.Error() { - return err - } - for _, sd := range storDataUsers { - sdModels := APItoModelUsers(sd) - for _, sdModel := range sdModels { - toExportMap[utils.USERS_CSV] = append(toExportMap[utils.USERS_CSV], sdModel) - } - } - for fileName, storData := range toExportMap { if err := self.writeOut(fileName, storData); err != nil { self.removeFiles() diff --git a/engine/tpimporter_csv.go b/engine/tpimporter_csv.go index 3a4447c33..59e28e5d7 100644 --- a/engine/tpimporter_csv.go +++ b/engine/tpimporter_csv.go @@ -53,7 +53,6 @@ var fileHandlers = map[string]func(*TPCSVImporter, string) error{ utils.ACTION_TRIGGERS_CSV: (*TPCSVImporter).importActionTriggers, utils.ACCOUNT_ACTIONS_CSV: (*TPCSVImporter).importAccountActions, utils.DERIVED_CHARGERS_CSV: (*TPCSVImporter).importDerivedChargers, - utils.USERS_CSV: (*TPCSVImporter).importUsers, utils.ResourcesCsv: (*TPCSVImporter).importResources, utils.StatsCsv: (*TPCSVImporter).importStats, utils.ThresholdsCsv: (*TPCSVImporter).importThresholds, @@ -78,7 +77,6 @@ func (self *TPCSVImporter) Run() error { path.Join(self.DirPath, utils.ACTION_TRIGGERS_CSV), path.Join(self.DirPath, utils.ACCOUNT_ACTIONS_CSV), path.Join(self.DirPath, utils.DERIVED_CHARGERS_CSV), - path.Join(self.DirPath, utils.USERS_CSV), path.Join(self.DirPath, utils.ResourcesCsv), path.Join(self.DirPath, utils.StatsCsv), path.Join(self.DirPath, utils.ThresholdsCsv), @@ -297,21 +295,6 @@ func (self *TPCSVImporter) importDerivedChargers(fn string) error { return self.StorDb.SetTPDerivedChargers(tps) } -func (self *TPCSVImporter) importUsers(fn string) error { - if self.Verbose { - log.Printf("Processing file: <%s> ", fn) - } - tps, err := self.csvr.GetTPUsers(nil) - if err != nil { - return err - } - for i := 0; i < len(tps); i++ { - tps[i].TPid = self.TPid - } - - return self.StorDb.SetTPUsers(tps) -} - func (self *TPCSVImporter) importResources(fn string) error { if self.Verbose { log.Printf("Processing file: <%s> ", fn) diff --git a/engine/tpreader.go b/engine/tpreader.go index 0b0132878..74b03267b 100644 --- a/engine/tpreader.go +++ b/engine/tpreader.go @@ -46,7 +46,6 @@ type TpReader struct { ratingProfiles map[string]*RatingProfile sharedGroups map[string]*SharedGroup derivedChargers map[string]*utils.DerivedChargers - users map[string]*UserProfile resProfiles map[utils.TenantID]*utils.TPResource sqProfiles map[utils.TenantID]*utils.TPStats thProfiles map[utils.TenantID]*utils.TPThreshold @@ -126,7 +125,6 @@ func (tpr *TpReader) Init() { tpr.ratingProfiles = make(map[string]*RatingProfile) tpr.sharedGroups = make(map[string]*SharedGroup) tpr.accountActions = make(map[string]*Account) - tpr.users = make(map[string]*UserProfile) tpr.derivedChargers = make(map[string]*utils.DerivedChargers) tpr.resProfiles = make(map[utils.TenantID]*utils.TPResource) tpr.sqProfiles = make(map[utils.TenantID]*utils.TPStats) @@ -1144,51 +1142,6 @@ func (tpr *TpReader) LoadDerivedChargers() (err error) { return tpr.LoadDerivedChargersFiltered(&utils.TPDerivedChargers{TPid: tpr.tpid}, false) } -func (tpr *TpReader) LoadUsersFiltered(filter *utils.TPUsers) (bool, error) { - tpUsers, err := tpr.lr.GetTPUsers(filter) - if err != nil { - return false, err - } - for _, tpUser := range tpUsers { - user := &UserProfile{ - Tenant: tpUser.Tenant, - UserName: tpUser.UserName, - Profile: make(map[string]string), - } - for _, up := range tpUser.Profile { - user.Profile[up.AttrName] = up.AttrValue - } - tpr.dm.SetUser(user) - } - return len(tpUsers) > 0, err -} - -func (tpr *TpReader) LoadUsers() error { - tps, err := tpr.lr.GetTPUsers(&utils.TPUsers{TPid: tpr.tpid}) - if err != nil { - return err - } - userMap, err := MapTPUsers(tps) - if err != nil { - return err - } - for key, usr := range userMap { - up, found := tpr.users[key] - if !found { - up = &UserProfile{ - Tenant: usr.Tenant, - UserName: usr.UserName, - Profile: make(map[string]string), - } - tpr.users[key] = up - } - for _, p := range usr.Profile { - up.Profile[p.AttrName] = p.AttrValue - } - } - return err -} - func (tpr *TpReader) LoadResourceProfilesFiltered(tag string) (err error) { rls, err := tpr.lr.GetTPResources(tpr.tpid, "", tag) if err != nil { @@ -1411,9 +1364,6 @@ func (tpr *TpReader) LoadAll() (err error) { if err = tpr.LoadDerivedChargers(); err != nil && err.Error() != utils.NotFoundCaps { return } - if err = tpr.LoadUsers(); err != nil && err.Error() != utils.NotFoundCaps { - return - } if err = tpr.LoadFilters(); err != nil && err.Error() != utils.NotFoundCaps { return } @@ -1619,18 +1569,6 @@ func (tpr *TpReader) WriteToDatabase(flush, verbose, disable_reverse bool) (err log.Print("\t", key) } } - if verbose { - log.Print("Users:") - } - for _, u := range tpr.users { - err = tpr.dm.SetUser(u) - if err != nil { - return err - } - if verbose { - log.Print("\t", u.GetId()) - } - } if verbose { log.Print("Filters:") } @@ -1979,14 +1917,6 @@ func (tpr *TpReader) GetLoadedIds(categ string) ([]string, error) { i++ } return keys, nil - case utils.USERS_PREFIX: - keys := make([]string, len(tpr.users)) - i := 0 - for k := range tpr.users { - keys[i] = k - i++ - } - return keys, nil case utils.ResourceProfilesPrefix: keys := make([]string, len(tpr.resProfiles)) i := 0 @@ -2181,18 +2111,6 @@ func (tpr *TpReader) RemoveFromDatabase(verbose, disable_reverse bool) (err erro log.Print("\t", key) } } - if verbose { - log.Print("Users:") - } - for _, u := range tpr.users { - err = tpr.dm.RemoveUser(u.GetId()) - if err != nil { - return err - } - if verbose { - log.Print("\t", u.GetId()) - } - } if verbose { log.Print("Filters:") } diff --git a/engine/users.go b/engine/users.go deleted file mode 100644 index e2efce4aa..000000000 --- a/engine/users.go +++ /dev/null @@ -1,508 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package engine - -import ( - "fmt" - "reflect" - "sort" - "strings" - "sync" - - "github.com/cgrates/cgrates/utils" -) - -type UserProfile struct { - Tenant string - UserName string - Masked bool - Profile map[string]string - Weight float64 - ponder int -} - -type UserProfiles []*UserProfile - -func (ups UserProfiles) Len() int { - return len(ups) -} - -func (ups UserProfiles) Swap(i, j int) { - ups[i], ups[j] = ups[j], ups[i] -} - -func (ups UserProfiles) Less(j, i int) bool { // get higher Weight and ponder in front - return ups[i].Weight < ups[j].Weight || - (ups[i].Weight == ups[j].Weight && ups[i].ponder < ups[j].ponder) -} - -func (ups UserProfiles) Sort() { - sort.Sort(ups) -} - -func (ud *UserProfile) GetId() string { - return utils.ConcatenatedKey(ud.Tenant, ud.UserName) -} - -func (ud *UserProfile) SetId(id string) error { - vals := strings.Split(id, utils.CONCATENATED_KEY_SEP) - if len(vals) != 2 { - return utils.ErrInvalidKey - } - ud.Tenant = vals[0] - ud.UserName = vals[1] - return nil -} - -type UserService interface { - SetUser(UserProfile, *string) error - RemoveUser(UserProfile, *string) error - UpdateUser(UserProfile, *string) error - GetUsers(UserProfile, *UserProfiles) error - AddIndex([]string, *string) error - GetIndexes(string, *map[string][]string) error - ReloadUsers(string, *string) error -} - -type prop struct { - masked bool - weight float64 -} - -type UserMap struct { - table map[string]map[string]string - properties map[string]*prop - index map[string]map[string]bool - indexKeys []string - dm *DataManager - mu sync.RWMutex -} - -func NewUserMap(dm *DataManager, indexes []string) (*UserMap, error) { - um := newUserMap(dm, indexes) - var reply string - if err := um.ReloadUsers("", &reply); err != nil { - return nil, err - } - return um, nil -} - -func newUserMap(dm *DataManager, indexes []string) *UserMap { - return &UserMap{ - table: make(map[string]map[string]string), - properties: make(map[string]*prop), - index: make(map[string]map[string]bool), - indexKeys: indexes, - dm: dm, - } -} - -func (um *UserMap) ReloadUsers(in string, reply *string) (err error) { - um.mu.Lock() - // backup old data - oldTable := um.table - oldIndex := um.index - oldProperties := um.properties - um.table = make(map[string]map[string]string) - um.index = make(map[string]map[string]bool) - um.properties = make(map[string]*prop) - - // load from db - ups, err := um.dm.GetUsers() - if err != nil { // restore old data before return - um.table = oldTable - um.index = oldIndex - um.properties = oldProperties - um.mu.Unlock() - return err - } - for _, up := range ups { - um.table[up.GetId()] = up.Profile - um.properties[up.GetId()] = &prop{weight: up.Weight, masked: up.Masked} - } - um.mu.Unlock() - - if len(um.indexKeys) != 0 { - var s string - if err := um.AddIndex(um.indexKeys, &s); err != nil { - utils.Logger.Err(fmt.Sprintf("Error adding %v indexes to user profile service: %v", um.indexKeys, err)) - um.mu.Lock() - um.table = oldTable - um.index = oldIndex - um.properties = oldProperties - um.mu.Unlock() - return err - } - } - - *reply = utils.OK - return nil -} - -func (um *UserMap) SetUser(up *UserProfile, reply *string) error { - um.mu.Lock() - defer um.mu.Unlock() - if err := um.dm.SetUser(up); err != nil { - *reply = err.Error() - return err - } - um.table[up.GetId()] = up.Profile - um.properties[up.GetId()] = &prop{weight: up.Weight, masked: up.Masked} - um.addIndex(up, um.indexKeys) - *reply = utils.OK - return nil -} - -func (um *UserMap) RemoveUser(up *UserProfile, reply *string) error { - um.mu.Lock() - defer um.mu.Unlock() - if err := um.dm.RemoveUser(up.GetId()); err != nil { - *reply = err.Error() - return err - } - delete(um.table, up.GetId()) - delete(um.properties, up.GetId()) - um.deleteIndex(up) - *reply = utils.OK - return nil -} - -func (um *UserMap) UpdateUser(up *UserProfile, reply *string) error { - um.mu.Lock() - defer um.mu.Unlock() - m, found := um.table[up.GetId()] - if !found { - *reply = utils.ErrNotFound.Error() - return utils.ErrNotFound - } - properties := um.properties[up.GetId()] - if m == nil { - m = make(map[string]string) - } - oldM := make(map[string]string, len(m)) - for k, v := range m { - oldM[k] = v - } - oldUp := &UserProfile{ - Tenant: up.Tenant, - UserName: up.UserName, - Masked: properties.masked, - Weight: properties.weight, - Profile: oldM, - } - for key, value := range up.Profile { - m[key] = value - } - finalUp := &UserProfile{ - Tenant: up.Tenant, - UserName: up.UserName, - Masked: up.Masked, - Weight: up.Weight, - Profile: m, - } - if err := um.dm.SetUser(finalUp); err != nil { - *reply = err.Error() - return err - } - um.table[up.GetId()] = m - um.properties[up.GetId()] = &prop{weight: up.Weight, masked: up.Masked} - um.deleteIndex(oldUp) - um.addIndex(finalUp, um.indexKeys) - *reply = utils.OK - return nil -} - -func (um *UserMap) GetUsers(up *UserProfile, results *UserProfiles) error { - um.mu.RLock() - defer um.mu.RUnlock() - table := um.table // no index - - indexUnionKeys := make(map[string]bool) - // search index - if up.Tenant != "" { - if keys, found := um.index[utils.ConcatenatedKey("Tenant", up.Tenant)]; found { - for key := range keys { - indexUnionKeys[key] = true - } - } - } - if up.UserName != "" { - if keys, found := um.index[utils.ConcatenatedKey("UserName", up.UserName)]; found { - for key := range keys { - indexUnionKeys[key] = true - } - } - } - for k, v := range up.Profile { - if keys, found := um.index[utils.ConcatenatedKey(k, v)]; found { - for key := range keys { - indexUnionKeys[key] = true - } - } - } - if len(indexUnionKeys) != 0 { - table = make(map[string]map[string]string) - for key := range indexUnionKeys { - table[key] = um.table[key] - } - } - - candidates := make(UserProfiles, 0) // It should not return nil in case of no users but [] - for key, values := range table { - // skip masked if not asked for - if up.Masked == false && um.properties[key] != nil && um.properties[key].masked == true { - continue - } - ponder := 0 - tableUP := &UserProfile{ - Profile: values, - } - tableUP.SetId(key) - if up.Tenant != "" && tableUP.Tenant != "" && up.Tenant != tableUP.Tenant { - continue - } - if tableUP.Tenant != "" { - ponder += 1 - } - if up.UserName != "" && tableUP.UserName != "" && up.UserName != tableUP.UserName { - continue - } - if tableUP.UserName != "" { - ponder += 1 - } - valid := true - for k, v := range up.Profile { - if tableUP.Profile[k] != "" && tableUP.Profile[k] != v { - valid = false - break - } - if tableUP.Profile[k] != "" { - ponder += 1 - } - } - if !valid { - continue - } - // all filters passed, add to candidates - nup := &UserProfile{ - Profile: make(map[string]string), - } - if um.properties[key] != nil { - nup.Masked = um.properties[key].masked - nup.Weight = um.properties[key].weight - } - nup.SetId(key) - nup.ponder = ponder - for k, v := range tableUP.Profile { - nup.Profile[k] = v - } - candidates = append(candidates, nup) - } - candidates.Sort() - *results = candidates - return nil -} - -// AddIndex is a method to dynamically add indexes to already existing ones -func (um *UserMap) AddIndex(indexes []string, reply *string) error { - um.mu.Lock() - defer um.mu.Unlock() - for key, values := range um.table { - up := &UserProfile{Profile: values} - up.SetId(key) - um.addIndex(up, indexes) - } - for _, idxKey := range indexes { - if !utils.IsSliceMember(um.indexKeys, idxKey) { - um.indexKeys = append(um.indexKeys, idxKey) - } - } - *reply = utils.OK - return nil -} - -func (um *UserMap) addIndex(up *UserProfile, indexes []string) { - key := up.GetId() - for _, index := range indexes { - if index == "Tenant" { - if up.Tenant != "" { - indexKey := utils.ConcatenatedKey(index, up.Tenant) - if um.index[indexKey] == nil { - um.index[indexKey] = make(map[string]bool) - } - um.index[indexKey][key] = true - } - continue - } - if index == "UserName" { - if up.UserName != "" { - indexKey := utils.ConcatenatedKey(index, up.UserName) - if um.index[indexKey] == nil { - um.index[indexKey] = make(map[string]bool) - } - um.index[indexKey][key] = true - } - continue - } - - for k, v := range up.Profile { - if k == index && v != "" { - indexKey := utils.ConcatenatedKey(k, v) - if um.index[indexKey] == nil { - um.index[indexKey] = make(map[string]bool) - } - um.index[indexKey][key] = true - } - } - } -} - -func (um *UserMap) deleteIndex(up *UserProfile) { - key := up.GetId() - for _, index := range um.indexKeys { - if index == "Tenant" { - if up.Tenant != "" { - indexKey := utils.ConcatenatedKey(index, up.Tenant) - delete(um.index[indexKey], key) - if len(um.index[indexKey]) == 0 { - delete(um.index, indexKey) - } - } - continue - } - if index == "UserName" { - if up.UserName != "" { - indexKey := utils.ConcatenatedKey(index, up.UserName) - delete(um.index[indexKey], key) - if len(um.index[indexKey]) == 0 { - delete(um.index, indexKey) - } - } - continue - } - for k, v := range up.Profile { - if k == index && v != "" { - indexKey := utils.ConcatenatedKey(k, v) - delete(um.index[indexKey], key) - if len(um.index[indexKey]) == 0 { - delete(um.index, indexKey) - } - } - } - } -} - -func (um *UserMap) GetIndexes(in string, reply *map[string][]string) error { - um.mu.RLock() - defer um.mu.RUnlock() - indexes := make(map[string][]string) - for key, values := range um.index { - var vs []string - for val := range values { - vs = append(vs, val) - } - indexes[key] = vs - } - *reply = indexes - return nil -} - -func (um *UserMap) Call(serviceMethod string, args interface{}, reply interface{}) error { - parts := strings.Split(serviceMethod, ".") - if len(parts) != 2 { - return utils.ErrNotImplemented - } - // get method - method := reflect.ValueOf(um).MethodByName(parts[1]) - if !method.IsValid() { - return utils.ErrNotImplemented - } - - // construct the params - params := []reflect.Value{reflect.ValueOf(args), reflect.ValueOf(reply)} - - ret := method.Call(params) - if len(ret) != 1 { - return utils.ErrServerError - } - if ret[0].Interface() == nil { - return nil - } - err, ok := ret[0].Interface().(error) - if !ok { - return utils.ErrServerError - } - return err -} - -// extraFields - Field name in the interface containing extraFields information -func LoadUserProfile(in interface{}, extraFields string) error { - if userService == nil { // no user service => no fun - return nil - } - m := utils.ToMapStringString(in) - var needsUsers bool - for _, val := range m { - if val == utils.USERS { - needsUsers = true - break - } - } - if !needsUsers { // Do not process further if user profile is not needed - return nil - } - up := &UserProfile{ - Masked: false, // do not get masked users - Profile: make(map[string]string), - } - tenant := m["Tenant"] - if tenant != "" && tenant != utils.USERS { - up.Tenant = tenant - } - delete(m, "Tenant") - - // clean empty and *user fields - for key, val := range m { - if val != "" && val != utils.USERS { - up.Profile[key] = val - } - } - // add extra fields - if extraFields != "" { - extra := utils.GetMapExtraFields(in, extraFields) - for key, val := range extra { - if val != "" && val != utils.USERS { - up.Profile[key] = val - } - } - } - ups := UserProfiles{} - if err := userService.Call("UsersV1.GetUsers", up, &ups); err != nil { - return err - } - if len(ups) > 0 { - up = ups[0] - m := up.Profile - m["Tenant"] = up.Tenant - utils.FromMapStringString(m, in) - utils.SetMapExtraFields(in, m, extraFields) - return nil - } - return utils.ErrUserNotFound -} diff --git a/engine/users_test.go b/engine/users_test.go deleted file mode 100644 index 168d73194..000000000 --- a/engine/users_test.go +++ /dev/null @@ -1,865 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ -package engine - -import ( - "reflect" - "testing" - "time" - - "github.com/cgrates/cgrates/utils" -) - -var testMap = UserMap{ - table: map[string]map[string]string{ - "test:user": map[string]string{"t": "v"}, - ":user": map[string]string{"t": "v"}, - "test:": map[string]string{"t": "v"}, - "test1:user1": map[string]string{"t": "v", "x": "y"}, - "test:masked": map[string]string{"t": "v"}, - }, - index: make(map[string]map[string]bool), - properties: map[string]*prop{ - "test:masked": &prop{masked: true}, - }, -} - -var testMap2 = UserMap{ - table: map[string]map[string]string{ - "an:u1": map[string]string{"a": "b", "c": "d"}, - "an:u2": map[string]string{"a": "b"}, - }, - index: make(map[string]map[string]bool), - properties: map[string]*prop{ - "an:u2": &prop{weight: 10}, - }, -} - -func TestUsersAdd(t *testing.T) { - tm := newUserMap(dm, nil) - var r string - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - tm.SetUser(up, &r) - p, found := tm.table[up.GetId()] - if r != utils.OK || - !found || - p["t"] != "v" || - len(tm.table) != 1 || - len(p) != 1 { - t.Error("Error setting user: ", tm, len(tm.table)) - } -} - -func TestUsersUpdate(t *testing.T) { - tm := newUserMap(dm, nil) - var r string - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - tm.SetUser(up, &r) - p, found := tm.table[up.GetId()] - if r != utils.OK || - !found || - p["t"] != "v" || - len(tm.table) != 1 || - len(p) != 1 { - t.Error("Error setting user: ", tm) - } - up.Profile["x"] = "y" - tm.UpdateUser(up, &r) - p, found = tm.table[up.GetId()] - if r != utils.OK || - !found || - p["x"] != "y" || - len(tm.table) != 1 || - len(p) != 2 { - t.Error("Error updating user: ", tm) - } -} - -func TestUsersUpdateNotFound(t *testing.T) { - tm := newUserMap(dm, nil) - var r string - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - tm.SetUser(up, &r) - up.UserName = "test1" - err = tm.UpdateUser(up, &r) - if err != utils.ErrNotFound { - t.Error("Error detecting user not found on update: ", err) - } -} - -func TestUsersUpdateInit(t *testing.T) { - tm := newUserMap(dm, nil) - var r string - up := &UserProfile{ - Tenant: "test", - UserName: "user", - } - tm.SetUser(up, &r) - up = &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - tm.UpdateUser(up, &r) - p, found := tm.table[up.GetId()] - if r != utils.OK || - !found || - p["t"] != "v" || - len(tm.table) != 1 || - len(p) != 1 { - t.Error("Error updating user: ", tm) - } -} - -func TestUsersRemove(t *testing.T) { - tm := newUserMap(dm, nil) - var r string - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - tm.SetUser(up, &r) - p, found := tm.table[up.GetId()] - if r != utils.OK || - !found || - p["t"] != "v" || - len(tm.table) != 1 || - len(p) != 1 { - t.Error("Error setting user: ", tm) - } - tm.RemoveUser(up, &r) - p, found = tm.table[up.GetId()] - if r != utils.OK || - found || - len(tm.table) != 0 { - t.Error("Error removing user: ", tm) - } -} - -func TestUsersGetFull(t *testing.T) { - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetFullMasked(t *testing.T) { - up := &UserProfile{ - Tenant: "test", - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetFullUnMasked(t *testing.T) { - up := &UserProfile{ - Tenant: "test", - Masked: true, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 4 { - for _, r := range results { - t.Logf("U: %+v", r) - } - t.Error("error getting users: ", results) - } -} - -func TestUsersGetTenant(t *testing.T) { - up := &UserProfile{ - Tenant: "testX", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 1 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetUserName(t *testing.T) { - up := &UserProfile{ - Tenant: "test", - UserName: "userX", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 1 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetNotFoundProfile(t *testing.T) { - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "o": "p", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingTenant(t *testing.T) { - up := &UserProfile{ - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingUserName(t *testing.T) { - up := &UserProfile{ - Tenant: "test", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingId(t *testing.T) { - up := &UserProfile{ - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 4 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingIdTwo(t *testing.T) { - up := &UserProfile{ - Profile: map[string]string{ - "t": "v", - "x": "y", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 4 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingIdTwoSort(t *testing.T) { - up := &UserProfile{ - Profile: map[string]string{ - "t": "v", - "x": "y", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 4 { - t.Error("error getting users: ", results) - } - if results[0].GetId() != "test1:user1" { - t.Errorf("Error sorting profiles: %+v", results[0]) - } -} - -func TestUsersGetMissingIdTwoSortWeight(t *testing.T) { - up := &UserProfile{ - Profile: map[string]string{ - "a": "b", - "c": "d", - }, - } - results := UserProfiles{} - testMap2.GetUsers(up, &results) - if len(results) != 2 { - t.Error("error getting users: ", results) - } - if results[0].GetId() != "an:u2" { - t.Errorf("Error sorting profiles: %+v", results[0]) - } -} - -func TestUsersAddIndex(t *testing.T) { - var r string - testMap.AddIndex([]string{"t"}, &r) - if r != utils.OK || - len(testMap.index) != 1 || - len(testMap.index[utils.ConcatenatedKey("t", "v")]) != 5 { - t.Error("error adding index: ", testMap.index) - } -} - -func TestUsersAddIndexFull(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - if r != utils.OK || - len(testMap.index) != 7 || - len(testMap.index[utils.ConcatenatedKey("t", "v")]) != 5 { - t.Error("error adding index: ", testMap.index) - } -} - -func TestUsersAddIndexNone(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"test"}, &r) - if r != utils.OK || - len(testMap.index) != 0 { - t.Error("error adding index: ", testMap.index) - } -} - -func TestUsersGetFullindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetTenantindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Tenant: "testX", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 1 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetUserNameindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Tenant: "test", - UserName: "userX", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 1 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetNotFoundProfileindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "o": "p", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingTenantindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingUserNameindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Tenant: "test", - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 3 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingIdindex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Profile: map[string]string{ - "t": "v", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 4 { - t.Error("error getting users: ", results) - } -} - -func TestUsersGetMissingIdTwoINdex(t *testing.T) { - var r string - testMap.index = make(map[string]map[string]bool) // reset index - testMap.AddIndex([]string{"t", "x", "UserName", "Tenant"}, &r) - up := &UserProfile{ - Profile: map[string]string{ - "t": "v", - "x": "y", - }, - } - results := UserProfiles{} - testMap.GetUsers(up, &results) - if len(results) != 4 { - t.Error("error getting users: ", results) - } -} - -func TestUsersAddUpdateRemoveIndexes(t *testing.T) { - tm := newUserMap(dm, nil) - var r string - tm.AddIndex([]string{"t"}, &r) - if len(tm.index) != 0 { - t.Error("error adding indexes: ", tm.index) - } - tm.SetUser(&UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - }, &r) - if len(tm.index) != 1 || !tm.index["t:v"]["test:user"] { - t.Error("error adding indexes: ", tm.index) - } - tm.SetUser(&UserProfile{ - Tenant: "test", - UserName: "best", - Profile: map[string]string{ - "t": "v", - }, - }, &r) - if len(tm.index) != 1 || - !tm.index["t:v"]["test:user"] || - !tm.index["t:v"]["test:best"] { - t.Error("error adding indexes: ", tm.index) - } - tm.UpdateUser(&UserProfile{ - Tenant: "test", - UserName: "best", - Profile: map[string]string{ - "t": "v1", - }, - }, &r) - if len(tm.index) != 2 || - !tm.index["t:v"]["test:user"] || - !tm.index["t:v1"]["test:best"] { - t.Error("error adding indexes: ", tm.index) - } - tm.UpdateUser(&UserProfile{ - Tenant: "test", - UserName: "best", - Profile: map[string]string{ - "t": "v", - }, - }, &r) - if len(tm.index) != 1 || - !tm.index["t:v"]["test:user"] || - !tm.index["t:v"]["test:best"] { - t.Error("error adding indexes: ", tm.index) - } - tm.RemoveUser(&UserProfile{ - Tenant: "test", - UserName: "best", - Profile: map[string]string{ - "t": "v", - }, - }, &r) - if len(tm.index) != 1 || - !tm.index["t:v"]["test:user"] || - tm.index["t:v"]["test:best"] { - t.Error("error adding indexes: ", tm.index) - } - tm.RemoveUser(&UserProfile{ - Tenant: "test", - UserName: "user", - Profile: map[string]string{ - "t": "v", - }, - }, &r) - if len(tm.index) != 0 { - t.Error("error adding indexes: ", tm.index) - } -} - -func TestUsersUsageRecordGetLoadUserProfile(t *testing.T) { - userService = &UserMap{ - table: map[string]map[string]string{ - "test:user": map[string]string{utils.ToR: "01", "RequestType": "1", "Direction": "*out", "Category": "c1", "Account": "dan", "Subject": "0723", "Destination": "+401", "SetupTime": "s1", "AnswerTime": "t1", "Usage": "10"}, - ":user": map[string]string{utils.ToR: "02", "RequestType": "2", "Direction": "*out", "Category": "c2", "Account": "ivo", "Subject": "0724", "Destination": "+402", "SetupTime": "s2", "AnswerTime": "t2", "Usage": "11"}, - "test:": map[string]string{utils.ToR: "03", "RequestType": "3", "Direction": "*out", "Category": "c3", "Account": "elloy", "Subject": "0725", "Destination": "+403", "SetupTime": "s3", "AnswerTime": "t3", "Usage": "12"}, - "test1:user1": map[string]string{utils.ToR: "04", "RequestType": "4", "Direction": "*out", "Category": "call", "Account": "rif", "Subject": "0726", "Destination": "+404", "SetupTime": "s4", "AnswerTime": "t4", "Usage": "13"}, - }, - index: make(map[string]map[string]bool), - } - - ur := &UsageRecord{ - ToR: utils.USERS, - RequestType: utils.USERS, - Tenant: "", - Category: "call", - Account: utils.USERS, - Subject: utils.USERS, - Destination: utils.USERS, - SetupTime: utils.USERS, - AnswerTime: utils.USERS, - Usage: "13", - } - - err := LoadUserProfile(ur, "") - if err != nil { - t.Error("Error loading user profile: ", err) - } - expected := &UsageRecord{ - ToR: "04", - RequestType: "4", - Tenant: "", - Category: "call", - Account: "rif", - Subject: "0726", - Destination: "+404", - SetupTime: "s4", - AnswerTime: "t4", - Usage: "13", - } - if !reflect.DeepEqual(ur, expected) { - t.Errorf("Expected: %+v got: %+v", expected, ur) - } -} - -func TestUsersExternalCDRGetLoadUserProfileExtraFields(t *testing.T) { - userService = &UserMap{ - table: map[string]map[string]string{ - "test:user": map[string]string{utils.ToR: "01", "RequestType": "1", "Direction": "*out", "Category": "c1", "Account": "dan", "Subject": "0723", "Destination": "+401", "SetupTime": "s1", "AnswerTime": "t1", "Usage": "10"}, - ":user": map[string]string{utils.ToR: "02", "RequestType": "2", "Direction": "*out", "Category": "c2", "Account": "ivo", "Subject": "0724", "Destination": "+402", "SetupTime": "s2", "AnswerTime": "t2", "Usage": "11"}, - "test:": map[string]string{utils.ToR: "03", "RequestType": "3", "Direction": "*out", "Category": "c3", "Account": "elloy", "Subject": "0725", "Destination": "+403", "SetupTime": "s3", "AnswerTime": "t3", "Usage": "12"}, - "test1:user1": map[string]string{utils.ToR: "04", "RequestType": "4", "Direction": "*out", "Category": "call", "Account": "rif", "Subject": "0726", "Destination": "+404", "SetupTime": "s4", "AnswerTime": "t4", "Usage": "13", "Test": "1"}, - }, - index: make(map[string]map[string]bool), - } - - ur := &ExternalCDR{ - ToR: utils.USERS, - RequestType: utils.USERS, - Tenant: "", - Category: "call", - Account: utils.USERS, - Subject: utils.USERS, - Destination: utils.USERS, - SetupTime: utils.USERS, - AnswerTime: utils.USERS, - Usage: "13", - ExtraFields: map[string]string{ - "Test": "1", - }, - } - - err := LoadUserProfile(ur, "ExtraFields") - if err != nil { - t.Error("Error loading user profile: ", err) - } - expected := &ExternalCDR{ - ToR: "04", - RequestType: "4", - Tenant: "", - Category: "call", - Account: "rif", - Subject: "0726", - Destination: "+404", - SetupTime: "s4", - AnswerTime: "t4", - Usage: "13", - ExtraFields: map[string]string{ - "Test": "1", - }, - } - if !reflect.DeepEqual(ur, expected) { - t.Errorf("Expected: %+v got: %+v", expected, ur) - } -} - -func TestUsersExternalCDRGetLoadUserProfileExtraFieldsNotFound(t *testing.T) { - userService = &UserMap{ - table: map[string]map[string]string{ - "test:user": map[string]string{utils.ToR: "01", "RequestType": "1", "Direction": "*out", "Category": "c1", "Account": "dan", "Subject": "0723", "Destination": "+401", "SetupTime": "s1", "AnswerTime": "t1", "Usage": "10"}, - ":user": map[string]string{utils.ToR: "02", "RequestType": "2", "Direction": "*out", "Category": "c2", "Account": "ivo", "Subject": "0724", "Destination": "+402", "SetupTime": "s2", "AnswerTime": "t2", "Usage": "11"}, - "test:": map[string]string{utils.ToR: "03", "RequestType": "3", "Direction": "*out", "Category": "c3", "Account": "elloy", "Subject": "0725", "Destination": "+403", "SetupTime": "s3", "AnswerTime": "t3", "Usage": "12"}, - "test1:user1": map[string]string{utils.ToR: "04", "RequestType": "4", "Direction": "*out", "Category": "call", "Account": "rif", "Subject": "0726", "Destination": "+404", "SetupTime": "s4", "AnswerTime": "t4", "Usage": "13", "Test": "2"}, - }, - index: make(map[string]map[string]bool), - } - - ur := &ExternalCDR{ - ToR: utils.USERS, - RequestType: utils.USERS, - Tenant: "", - Category: "call", - Account: utils.USERS, - Subject: utils.USERS, - Destination: utils.USERS, - SetupTime: utils.USERS, - AnswerTime: utils.USERS, - Usage: "13", - ExtraFields: map[string]string{ - "Test": "1", - }, - } - - err := LoadUserProfile(ur, "ExtraFields") - if err != utils.ErrUserNotFound { - t.Error("Error detecting err in loading user profile: ", err) - } -} - -func TestUsersExternalCDRGetLoadUserProfileExtraFieldsSet(t *testing.T) { - userService = &UserMap{ - table: map[string]map[string]string{ - "test:user": map[string]string{utils.ToR: "01", "RequestType": "1", "Direction": "*out", "Category": "c1", "Account": "dan", "Subject": "0723", "Destination": "+401", "SetupTime": "s1", "AnswerTime": "t1", "Usage": "10"}, - ":user": map[string]string{utils.ToR: "02", "RequestType": "2", "Direction": "*out", "Category": "c2", "Account": "ivo", "Subject": "0724", "Destination": "+402", "SetupTime": "s2", "AnswerTime": "t2", "Usage": "11"}, - "test:": map[string]string{utils.ToR: "03", "RequestType": "3", "Direction": "*out", "Category": "c3", "Account": "elloy", "Subject": "0725", "Destination": "+403", "SetupTime": "s3", "AnswerTime": "t3", "Usage": "12"}, - "test1:user1": map[string]string{utils.ToR: "04", "RequestType": "4", "Direction": "*out", "Category": "call", "Account": "rif", "Subject": "0726", "Destination": "+404", "SetupTime": "s4", "AnswerTime": "t4", "Usage": "13", "Test": "1", "Best": "BestValue"}, - }, - index: make(map[string]map[string]bool), - } - - ur := &ExternalCDR{ - ToR: utils.USERS, - RequestType: utils.USERS, - Tenant: "", - Category: "call", - Account: utils.USERS, - Subject: utils.USERS, - Destination: utils.USERS, - SetupTime: utils.USERS, - AnswerTime: utils.USERS, - Usage: "13", - ExtraFields: map[string]string{ - "Test": "1", - "Best": utils.USERS, - }, - } - - err := LoadUserProfile(ur, "ExtraFields") - if err != nil { - t.Error("Error loading user profile: ", err) - } - expected := &ExternalCDR{ - ToR: "04", - RequestType: "4", - Tenant: "", - Category: "call", - Account: "rif", - Subject: "0726", - Destination: "+404", - SetupTime: "s4", - AnswerTime: "t4", - Usage: "13", - ExtraFields: map[string]string{ - "Test": "1", - "Best": "BestValue", - }, - } - if !reflect.DeepEqual(ur, expected) { - t.Errorf("Expected: %+v got: %+v", expected, ur) - } -} - -func TestUsersCallDescLoadUserProfile(t *testing.T) { - userService = &UserMap{ - table: map[string]map[string]string{ - "cgrates.org:dan": map[string]string{"RequestType": "*prepaid", "Category": "call1", "Account": "dan", "Subject": "dan", "Cli": "+4986517174963"}, - "cgrates.org:danvoice": map[string]string{utils.ToR: "*voice", "RequestType": "*prepaid", "Category": "call1", "Account": "dan", "Subject": "0723"}, - "cgrates:rif": map[string]string{"RequestType": "*postpaid", "Direction": "*out", "Category": "call", "Account": "rif", "Subject": "0726"}, - }, - index: make(map[string]map[string]bool), - } - startTime := time.Now() - cd := &CallDescriptor{ - TOR: "*sms", - Tenant: utils.USERS, - Category: utils.USERS, - Subject: utils.USERS, - Account: utils.USERS, - Destination: "+4986517174963", - TimeStart: startTime, - TimeEnd: startTime.Add(time.Duration(1) * time.Minute), - ExtraFields: map[string]string{"Cli": "+4986517174963"}, - } - expected := &CallDescriptor{ - TOR: "*sms", - Tenant: "cgrates.org", - Category: "call1", - Account: "dan", - Subject: "dan", - Destination: "+4986517174963", - TimeStart: startTime, - TimeEnd: startTime.Add(time.Duration(1) * time.Minute), - ExtraFields: map[string]string{"Cli": "+4986517174963"}, - } - err := LoadUserProfile(cd, "ExtraFields") - if err != nil { - t.Error("Error loading user profile: ", err) - } - if !reflect.DeepEqual(expected, cd) { - t.Errorf("Expected: %+v got: %+v", expected, cd) - } -} - -func TestUsersCDRLoadUserProfile(t *testing.T) { - userService = &UserMap{ - table: map[string]map[string]string{ - "cgrates.org:dan": map[string]string{"RequestType": "*prepaid", "Category": "call1", "Account": "dan", "Subject": "dan", "Cli": "+4986517174963"}, - "cgrates.org:danvoice": map[string]string{utils.ToR: "*voice", "RequestType": "*prepaid", "Category": "call1", "Account": "dan", "Subject": "0723"}, - "cgrates:rif": map[string]string{"RequestType": "*postpaid", "Direction": "*out", "Category": "call", "Account": "rif", "Subject": "0726"}, - }, - index: make(map[string]map[string]bool), - } - startTime := time.Now() - cdr := &CDR{ - ToR: "*sms", - RequestType: utils.USERS, - Tenant: utils.USERS, - Category: utils.USERS, - Account: utils.USERS, - Subject: utils.USERS, - Destination: "+4986517174963", - SetupTime: startTime, - AnswerTime: startTime, - Usage: time.Duration(1) * time.Minute, - ExtraFields: map[string]string{"Cli": "+4986517174963"}, - } - expected := &CDR{ - ToR: "*sms", - RequestType: "*prepaid", - Tenant: "cgrates.org", - Category: "call1", - Account: "dan", - Subject: "dan", - Destination: "+4986517174963", - SetupTime: startTime, - AnswerTime: startTime, - Usage: time.Duration(1) * time.Minute, - ExtraFields: map[string]string{"Cli": "+4986517174963"}, - } - err := LoadUserProfile(cdr, "ExtraFields") - if err != nil { - t.Error("Error loading user profile: ", err) - } - if !reflect.DeepEqual(expected, cdr) { - t.Errorf("Expected: %+v got: %+v", expected, cdr) - } -} diff --git a/engine/version.go b/engine/version.go index 1e8e49e5a..7271bb86b 100644 --- a/engine/version.go +++ b/engine/version.go @@ -148,7 +148,6 @@ func CurrentDataDBVersions() Versions { utils.Timing: 1, utils.RQF: 1, utils.Resource: 1, - utils.User: 2, utils.Subscribers: 1, utils.DerivedChargersV: 2, utils.Destinations: 1, @@ -182,7 +181,6 @@ func CurrentStorDBVersions() Versions { utils.TpRates: 1, utils.TpTiming: 1, utils.TpResource: 1, - utils.TpUsers: 1, utils.TpDerivedChargersV: 1, utils.TpDestinations: 1, utils.TpRatingPlan: 1, diff --git a/general_tests/acntacts_test.go b/general_tests/acntacts_test.go index 1c4142f0b..3623e89f1 100644 --- a/general_tests/acntacts_test.go +++ b/general_tests/acntacts_test.go @@ -48,7 +48,6 @@ ENABLE_ACNT,*enable_account,,,,,,,,,,,,,false,false,10` actionTriggers := `` accountActions := `cgrates.org,1,TOPUP10_AT,,,` derivedCharges := `` - users := `` resLimits := `` stats := `` thresholds := `` @@ -59,7 +58,7 @@ ENABLE_ACNT,*enable_account,,,,,,,,,,,,,false,false,10` csvr := engine.NewTpReader(dbAcntActs.DataDB(), engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions, derivedCharges, - users, resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") + resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") if err := csvr.LoadAll(); err != nil { t.Fatal(err) } diff --git a/general_tests/auth_test.go b/general_tests/auth_test.go index c2f76f03e..d445bdb91 100644 --- a/general_tests/auth_test.go +++ b/general_tests/auth_test.go @@ -56,7 +56,6 @@ cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_ANY,` actionTriggers := `` accountActions := `cgrates.org,testauthpostpaid1,TOPUP10_AT,,,` derivedCharges := `` - users := `` resLimits := `` stats := `` thresholds := `` @@ -66,7 +65,7 @@ cgrates.org,call,*any,2013-01-06T00:00:00Z,RP_ANY,` chargerProfiles := `` csvr := engine.NewTpReader(dbAuth.DataDB(), engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions, - derivedCharges, users, resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") + derivedCharges, resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") if err := csvr.LoadAll(); err != nil { t.Fatal(err) } diff --git a/general_tests/costs1_test.go b/general_tests/costs1_test.go index c954c5e15..3b52cb9cf 100644 --- a/general_tests/costs1_test.go +++ b/general_tests/costs1_test.go @@ -51,7 +51,7 @@ RP_SMS1,DR_SMS_1,ALWAYS,10` cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1, cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,` csvr := engine.NewTpReader(dataDB.DataDB(), engine.NewStringCSVStorage(',', dests, timings, rates, destinationRates, ratingPlans, ratingProfiles, - "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") + "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { t.Fatal(err) diff --git a/general_tests/datachrg1_test.go b/general_tests/datachrg1_test.go index 70d2adacd..17a29807c 100644 --- a/general_tests/datachrg1_test.go +++ b/general_tests/datachrg1_test.go @@ -42,7 +42,7 @@ DR_DATA_2,*any,RT_DATA_1c,*up,4,0,` RP_DATA1,DR_DATA_2,TM2,10` ratingProfiles := `cgrates.org,data,*any,2012-01-01T00:00:00Z,RP_DATA1,` csvr := engine.NewTpReader(dataDB.DataDB(), engine.NewStringCSVStorage(',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles, - "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") + "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { t.Fatal(err) } diff --git a/general_tests/ddazmbl1_test.go b/general_tests/ddazmbl1_test.go index 104e95b82..b59b9d9ca 100644 --- a/general_tests/ddazmbl1_test.go +++ b/general_tests/ddazmbl1_test.go @@ -55,7 +55,6 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` actionTriggers := `` accountActions := `cgrates.org,12344,TOPUP10_AT,,,` derivedCharges := `` - users := `` resLimits := `` stats := `` thresholds := `` @@ -67,7 +66,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, accountActions, - derivedCharges, users, resLimits, stats, + derivedCharges, resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") if err := csvr.LoadDestinations(); err != nil { t.Fatal(err) diff --git a/general_tests/ddazmbl2_test.go b/general_tests/ddazmbl2_test.go index 0bd2708c4..944481e78 100644 --- a/general_tests/ddazmbl2_test.go +++ b/general_tests/ddazmbl2_test.go @@ -55,7 +55,6 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` actionTriggers := `` accountActions := `cgrates.org,12345,TOPUP10_AT,,,` derivedCharges := `` - users := `` resLimits := `` stats := `` thresholds := `` @@ -65,7 +64,7 @@ TOPUP10_AT,TOPUP10_AC1,ASAP,10` chargerProfiles := `` csvr := engine.NewTpReader(dataDB2.DataDB(), engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, - actionTriggers, accountActions, derivedCharges, users, resLimits, + actionTriggers, accountActions, derivedCharges, resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") if err := csvr.LoadDestinations(); err != nil { t.Fatal(err) diff --git a/general_tests/ddazmbl3_test.go b/general_tests/ddazmbl3_test.go index 2c4b8e9a4..7e132a450 100644 --- a/general_tests/ddazmbl3_test.go +++ b/general_tests/ddazmbl3_test.go @@ -53,7 +53,6 @@ cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,` actionTriggers := `` accountActions := `cgrates.org,12346,TOPUP10_AT,,,` derivedCharges := `` - users := `` resLimits := `` stats := `` thresholds := `` @@ -63,7 +62,7 @@ cgrates.org,call,discounted_minutes,2013-01-06T00:00:00Z,RP_UK_Mobile_BIG5_PKG,` chargerProfiles := `` csvr := engine.NewTpReader(dataDB3.DataDB(), engine.NewStringCSVStorage(',', destinations, timings, rates, destinationRates, ratingPlans, ratingProfiles, sharedGroups, actions, actionPlans, actionTriggers, - accountActions, derivedCharges, users, resLimits, stats, + accountActions, derivedCharges, resLimits, stats, thresholds, filters, suppliers, attrProfiles, chargerProfiles, ``), "", "") if err := csvr.LoadDestinations(); err != nil { t.Fatal(err) diff --git a/general_tests/smschrg1_test.go b/general_tests/smschrg1_test.go index fb34e5f73..3d65dc079 100644 --- a/general_tests/smschrg1_test.go +++ b/general_tests/smschrg1_test.go @@ -40,7 +40,7 @@ func TestSMSLoadCsvTpSmsChrg1(t *testing.T) { ratingPlans := `RP_SMS1,DR_SMS_1,ALWAYS,10` ratingProfiles := `cgrates.org,sms,*any,2012-01-01T00:00:00Z,RP_SMS1,` csvr := engine.NewTpReader(dataDB.DataDB(), engine.NewStringCSVStorage(',', "", timings, rates, destinationRates, ratingPlans, ratingProfiles, - "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") + "", "", "", "", "", "", "", "", "", "", "", "", "", ""), "", "") if err := csvr.LoadTimings(); err != nil { t.Fatal(err) } diff --git a/general_tests/tut_smgeneric_it_test.go b/general_tests/tut_smgeneric_it_test.go index 9641abf40..7c6d0479b 100644 --- a/general_tests/tut_smgeneric_it_test.go +++ b/general_tests/tut_smgeneric_it_test.go @@ -99,9 +99,9 @@ func TestTutSMGCacheStats(t *testing.T) { } var rcvStats *utils.CacheStats expectedStats := &utils.CacheStats{Destinations: 5, ReverseDestinations: 7, RatingPlans: 4, RatingProfiles: 5, - Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, - Users: 3, ResourceProfiles: 3, Resources: 3, StatQueues: 1, - StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, SupplierProfiles: 3, AttributeProfiles: 1} + Actions: 9, ActionPlans: 4, AccountActionPlans: 5, SharedGroups: 1, DerivedChargers: 1, ResourceProfiles: 3, + Resources: 3, StatQueues: 1, StatQueueProfiles: 1, Thresholds: 7, ThresholdProfiles: 7, Filters: 16, + SupplierProfiles: 3, AttributeProfiles: 1} var args utils.AttrCacheStats if err := tutSMGRpc.Call("ApierV2.GetCacheStats", args, &rcvStats); err != nil { t.Error("Got error on ApierV2.GetCacheStats: ", err.Error()) diff --git a/migrator/alias.go b/migrator/alias.go index df9b1087a..7002a7fde 100644 --- a/migrator/alias.go +++ b/migrator/alias.go @@ -19,8 +19,9 @@ along with this program. If not, see package migrator import ( - "fmt" + //"log" + "fmt" "strings" "github.com/cgrates/cgrates/config" @@ -183,30 +184,33 @@ func (m *Migrator) migrateAlias2Attributes() (err error) { // } func (m *Migrator) migrateAlias() (err error) { - var vrs engine.Versions - current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") - } - switch vrs[Alias] { - case current[Alias]: - if m.sameDataDB { - return + return m.migrateAlias2Attributes() + /* + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") + if err != nil { + return utils.NewCGRError(utils.Migrator, + utils.ServerErrorCaps, + err.Error(), + fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, + utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, + "version number is not defined for ActionTriggers model") } - return utils.ErrNotImplemented - case 1: - return m.migrateAlias2Attributes() - } - return + switch vrs[Alias] { + case current[Alias]: + if m.sameDataDB { + return + } + return utils.ErrNotImplemented + case 1: + return m.migrateAlias2Attributes() + } + return + */ } func (m *Migrator) migrateReverseAlias() (err error) { diff --git a/migrator/migrator.go b/migrator/migrator.go index f36fadbb0..8982bde9a 100755 --- a/migrator/migrator.go +++ b/migrator/migrator.go @@ -48,7 +48,7 @@ func NewMigrator( return m, err } -var MetaAlias = "*Alias" +var MetaAlias = "*aliases" type Migrator struct { dmIN MigratorDataDB @@ -121,7 +121,7 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateReverseDestinations() case utils.MetaTiming: err = m.migrateTimings() - case utils.MetaRQF: + case utils.MetaReqFilters: err = m.migrateRequestFilter() case utils.MetaResource: err = m.migrateResources() @@ -172,8 +172,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { err = m.migrateTPrates() case utils.MetaTpTiming: err = m.migrateTpTimings() - case utils.MetaTpUsers: - err = m.migrateTPusers() case utils.MetaTpDestinations: err = m.migrateTPDestinations() case utils.MetaTpChargers: @@ -225,7 +223,7 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { log.Print("ERROR: ", utils.MetaTiming, " ", err) } if err := m.migrateRequestFilter(); err != nil { - log.Print("ERROR: ", utils.MetaRQF, " ", err) + log.Print("ERROR: ", utils.MetaReqFilters, " ", err) } if err := m.migrateResources(); err != nil { log.Print("ERROR: ", utils.MetaResource, " ", err) @@ -293,9 +291,6 @@ func (m *Migrator) Migrate(taskIDs []string) (err error, stats map[string]int) { if err := m.migrateTpTimings(); err != nil { log.Print("ERROR: ", utils.MetaTpTiming, " ", err) } - if err := m.migrateTPusers(); err != nil { - log.Print("ERROR: ", utils.MetaTpUsers, " ", err) - } if err := m.migrateTPderivedchargers(); err != nil { log.Print("ERROR: ", utils.MetaTpDerivedChargersV, " ", err) } diff --git a/migrator/tp_users.go b/migrator/tp_users.go deleted file mode 100644 index 12220ad00..000000000 --- a/migrator/tp_users.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package migrator - -import ( - "fmt" - - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" -) - -func (m *Migrator) migrateCurrentTPusers() (err error) { - tpids, err := m.storDBIn.StorDB().GetTpIds(utils.TBLTPUsers) - if err != nil { - return err - } - - for _, tpid := range tpids { - users, err := m.storDBIn.StorDB().GetTPUsers(&utils.TPUsers{TPid: tpid}) - if err != nil { - return err - } - if users != nil { - if m.dryRun != true { - if err := m.storDBOut.StorDB().SetTPUsers(users); err != nil { - return err - } - for _, user := range users { - if err := m.storDBIn.StorDB().RemTpData(utils.TBLTPUsers, user.TPid, - map[string]string{"tenant": user.Tenant, "user_name": user.UserName}); err != nil { - return err - } - } - m.stats[utils.TpUsers] += 1 - } - } - - } - return -} - -func (m *Migrator) migrateTPusers() (err error) { - var vrs engine.Versions - current := engine.CurrentStorDBVersions() - vrs, err = m.storDBOut.StorDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, - utils.ServerErrorCaps, - err.Error(), - fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, - utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, - "version number is not defined for ActionTriggers model") - } - switch vrs[utils.TpUsers] { - case current[utils.TpUsers]: - if m.sameStorDB { - return - } - if err := m.migrateCurrentTPusers(); err != nil { - return err - } - return - } - return -} diff --git a/migrator/tp_users_it_test.go b/migrator/tp_users_it_test.go deleted file mode 100644 index b52f6f9b1..000000000 --- a/migrator/tp_users_it_test.go +++ /dev/null @@ -1,159 +0,0 @@ -// +build integration - -/* -Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments -Copyright (C) ITsysCOM GmbH - -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 -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see -*/ - -package migrator - -import ( - "log" - "path" - "reflect" - "testing" - - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" -) - -var ( - tpUserPathIn string - tpUserPathOut string - tpUserCfgIn *config.CGRConfig - tpUserCfgOut *config.CGRConfig - tpUserMigrator *Migrator - tpUsers []*utils.TPUsers -) - -var sTestsTpUserIT = []func(t *testing.T){ - testTpUserITConnect, - testTpUserITFlush, - testTpUserITPopulate, - testTpUserITMove, - testTpUserITCheckData, -} - -func TestTpUserMove(t *testing.T) { - for _, stest := range sTestsTpUserIT { - t.Run("TestTpUserMove", stest) - } -} - -func testTpUserITConnect(t *testing.T) { - var err error - tpUserPathIn = path.Join(*dataDir, "conf", "samples", "tutmongo") - tpUserCfgIn, err = config.NewCGRConfigFromFolder(tpUserPathIn) - if err != nil { - t.Fatal(err) - } - tpUserPathOut = path.Join(*dataDir, "conf", "samples", "tutmysql") - tpUserCfgOut, err = config.NewCGRConfigFromFolder(tpUserPathOut) - if err != nil { - t.Fatal(err) - } - storDBIn, err := NewMigratorStorDB(tpUserCfgIn.StorDbCfg().StorDBType, - tpUserCfgIn.StorDbCfg().StorDBHost, tpUserCfgIn.StorDbCfg().StorDBPort, - tpUserCfgIn.StorDbCfg().StorDBName, tpUserCfgIn.StorDbCfg().StorDBUser, - tpUserCfgIn.StorDbCfg().StorDBPass, - config.CgrConfig().StorDbCfg().StorDBMaxOpenConns, - config.CgrConfig().StorDbCfg().StorDBMaxIdleConns, - config.CgrConfig().StorDbCfg().StorDBConnMaxLifetime, - config.CgrConfig().StorDbCfg().StorDBCDRSIndexes) - if err != nil { - log.Fatal(err) - } - storDBOut, err := NewMigratorStorDB(tpUserCfgOut.StorDbCfg().StorDBType, - tpUserCfgOut.StorDbCfg().StorDBHost, tpUserCfgOut.StorDbCfg().StorDBPort, - tpUserCfgOut.StorDbCfg().StorDBName, tpUserCfgOut.StorDbCfg().StorDBUser, - tpUserCfgOut.StorDbCfg().StorDBPass, - config.CgrConfig().StorDbCfg().StorDBMaxOpenConns, - config.CgrConfig().StorDbCfg().StorDBMaxIdleConns, - config.CgrConfig().StorDbCfg().StorDBConnMaxLifetime, - config.CgrConfig().StorDbCfg().StorDBCDRSIndexes) - if err != nil { - log.Fatal(err) - } - tpUserMigrator, err = NewMigrator(nil, nil, storDBIn, storDBOut, false, false, false) - if err != nil { - log.Fatal(err) - } -} - -func testTpUserITFlush(t *testing.T) { - if err := tpUserMigrator.storDBIn.StorDB().Flush( - path.Join(tpUserCfgIn.DataFolderPath, "storage", tpUserCfgIn.StorDbCfg().StorDBType)); err != nil { - t.Error(err) - } - - if err := tpUserMigrator.storDBOut.StorDB().Flush( - path.Join(tpUserCfgOut.DataFolderPath, "storage", tpUserCfgOut.StorDbCfg().StorDBType)); err != nil { - t.Error(err) - } -} - -func testTpUserITPopulate(t *testing.T) { - tpUsers = []*utils.TPUsers{ - { - TPid: "TPU1", - UserName: "User1", - Tenant: "Tenant1", - Masked: true, - Weight: 20, - Profile: []*utils.TPUserProfile{ - { - AttrName: "UserProfile1", - AttrValue: "ValUP1", - }, - { - AttrName: "UserProfile2", - AttrValue: "ValUP2", - }, - }, - }, - } - if err := tpUserMigrator.storDBIn.StorDB().SetTPUsers(tpUsers); err != nil { - t.Error("Error when setting TpUsers ", err.Error()) - } - currentVersion := engine.CurrentStorDBVersions() - err := tpUserMigrator.storDBOut.StorDB().SetVersions(currentVersion, false) - if err != nil { - t.Error("Error when setting version for TpUsers ", err.Error()) - } -} - -func testTpUserITMove(t *testing.T) { - err, _ := tpUserMigrator.Migrate([]string{utils.MetaTpUsers}) - if err != nil { - t.Error("Error when migrating TpUsers ", err.Error()) - } -} - -func testTpUserITCheckData(t *testing.T) { - filter := &utils.TPUsers{TPid: tpUsers[0].TPid} - result, err := tpUserMigrator.storDBOut.StorDB().GetTPUsers(filter) - if err != nil { - t.Error("Error when getting TpUsers ", err.Error()) - } - if !reflect.DeepEqual(tpUsers[0], result[0]) { - t.Errorf("Expecting: %+v, received: %+v", tpUsers[0], result[0]) - } - result, err = tpUserMigrator.storDBIn.StorDB().GetTPUsers(filter) - if err != utils.ErrNotFound { - t.Error(err) - } -} diff --git a/migrator/user.go b/migrator/user.go index f627d0367..f6f16c57d 100644 --- a/migrator/user.go +++ b/migrator/user.go @@ -109,48 +109,52 @@ func (m *Migrator) migrateV1User2AttributeProfile() (err error) { return } -func (m *Migrator) migrateCurrentUser() (err error) { - var ids []string - ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.USERS_PREFIX) - if err != nil { - return err - } - for _, id := range ids { - idg := strings.TrimPrefix(id, utils.USERS_PREFIX) - usr, err := m.dmIN.DataManager().GetUser(idg) - if err != nil { - return err - } - if usr != nil { - if m.dryRun != true { - if err := m.dmOut.DataManager().SetUser(usr); err != nil { - return err - } - m.stats[utils.User] += 1 - } - } - } - return -} +// func (m *Migrator) migrateCurrentUser() (err error) { +// var ids []string +// ids, err = m.dmIN.DataManager().DataDB().GetKeysForPrefix(utils.USERS_PREFIX) +// if err != nil { +// return err +// } +// for _, id := range ids { +// idg := strings.TrimPrefix(id, utils.USERS_PREFIX) +// usr, err := m.dmIN.DataManager().GetUser(idg) +// if err != nil { +// return err +// } +// if usr != nil { +// if m.dryRun != true { +// if err := m.dmOut.DataManager().SetUser(usr); err != nil { +// return err +// } +// m.stats[utils.User] += 1 +// } +// } +// } +// return +// } func (m *Migrator) migrateUser() (err error) { - var vrs engine.Versions - current := engine.CurrentDataDBVersions() - vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") - if err != nil { - return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, - err.Error(), fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) - } else if len(vrs) == 0 { - return utils.NewCGRError(utils.Migrator, utils.MandatoryIEMissingCaps, - utils.UndefinedVersion, "version number is not defined for Users model") - } - switch vrs[utils.User] { - case 1: - return m.migrateV1User2AttributeProfile() - case current[utils.User]: - if !m.sameStorDB { - return m.migrateCurrentUser() + return m.migrateV1User2AttributeProfile() + /* + var vrs engine.Versions + current := engine.CurrentDataDBVersions() + vrs, err = m.dmIN.DataManager().DataDB().GetVersions("") + if err != nil { + return utils.NewCGRError(utils.Migrator, utils.ServerErrorCaps, + err.Error(), fmt.Sprintf("error: <%s> when querying oldDataDB for versions", err.Error())) + } else if len(vrs) == 0 { + return utils.NewCGRError(utils.Migrator, utils.MandatoryIEMissingCaps, + utils.UndefinedVersion, "version number is not defined for Users model") } - } - return + switch vrs[utils.User] { + case 1: + return m.migrateV1User2AttributeProfile() + case current[utils.User]: + if !m.sameStorDB { + return utils.ErrNotImplemented + // return m.migrateCurrentUser() + } + } + return + */ } diff --git a/utils/apitpdata.go b/utils/apitpdata.go index 2693249d6..7a68aae0c 100755 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -353,34 +353,6 @@ type TPSharedGroup struct { RatingSubject string } -type TPUsers struct { - TPid string - Tenant string - UserName string - Masked bool - Weight float64 - Profile []*TPUserProfile -} - -type TPUserProfile struct { - AttrName string - AttrValue string -} - -func (u *TPUsers) GetId() string { - return ConcatenatedKey(u.Tenant, u.UserName) -} - -func (tu *TPUsers) SetId(id string) error { - vals := strings.Split(id, CONCATENATED_KEY_SEP) - if len(vals) != 2 { - return ErrInvalidKey - } - tu.Tenant = vals[0] - tu.UserName = vals[1] - return nil -} - type TPDerivedChargers struct { TPid string LoadId string @@ -597,7 +569,6 @@ type CacheStats struct { AccountActionPlans int SharedGroups int DerivedChargers int - Users int ResourceProfiles int Resources int StatQueues int diff --git a/utils/consts.go b/utils/consts.go index 99e8736da..f6faae712 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -129,7 +129,6 @@ const ( UNLIMITED = "*unlimited" ZERO = "*zero" ASAP = "*asap" - USERS = "*users" STATS_CHAR = "#" COMMENT_CHAR = '#' CSV_SEP = ',' @@ -471,17 +470,17 @@ const ( RatingPlan = "RatingPlan" RatingProfile = "RatingProfile" MetaRatingPlans = "*ratingplans" - MetaRatingProfile = "*ratingprofile" + MetaRatingProfile = "*ratingprofiles" MetaDestinations = "*destinations" MetaReverseDestinations = "*reversedestinations" MetaLCR = "*lcr" MetaCdrStats = "*cdrstats" - MetaTiming = "*Timing" - MetaRQF = "*RQF" - MetaResource = "*Resource" - MetaUser = "*User" - MetaSubscribers = "*Subscribers" - MetaDerivedChargersV = "*DerivedChargers" + MetaTiming = "*timings" + MetaReqFilters = "*reqfilters" + MetaResource = "*resources" + MetaUser = "*users" + MetaSubscribers = "*subscribers" + MetaDerivedChargersV = "*derivedchargers" MetaStorDB = "*stordb" MetaDataDB = "*datadb" MetaWeight = "*weight" @@ -624,13 +623,12 @@ const ( MetaTpResources = "*tp_resources" MetaTpRates = "*tp_rates" MetaTpTiming = "*tp_timing" - MetaTpResource = "*tp_resource" - MetaTpUsers = "*tp_users" + MetaTpResource = "*tp_resources" MetaTpDerivedChargersV = "*tp_derived_chargers" MetaTpCdrStats = "*tp_cdrstats" MetaTpDestinations = "*tp_destinations" - MetaTpRatingPlan = "*tp_rating_plan" - MetaTpRatingProfile = "*tp_rating_profile" + MetaTpRatingPlan = "*tp_rating_plans" + MetaTpRatingProfile = "*tp_rating_profiles" MetaTpChargers = "*tp_chargers" MetaTpDispatchers = "*tp_dispatchers" MetaDurationSeconds = "*duration_seconds" @@ -662,7 +660,6 @@ const ( TpRates = "TpRates" TpTiming = "TpTiming" TpResource = "TpResource" - TpUsers = "TpUsers" TpDerivedChargersV = "TpDerivedChargers" TpCdrStats = "TpCdrStats" TpDestinations = "TpDestinations" @@ -707,11 +704,6 @@ const ( ApierV2LoadTariffPlanFromFolder = "ApierV2.LoadTariffPlanFromFolder" ) -// UserS APIs -const ( - UsersV1ReloadUsers = "UsersV1.ReloadUsers" -) - // SupplierS APIs const ( SupplierSv1GetSuppliers = "SupplierSv1.GetSuppliers" @@ -876,7 +868,6 @@ const ( ACTION_TRIGGERS_CSV = "ActionTriggers.csv" ACCOUNT_ACTIONS_CSV = "AccountActions.csv" DERIVED_CHARGERS_CSV = "DerivedChargers.csv" - USERS_CSV = "Users.csv" ResourcesCsv = "Resources.csv" StatsCsv = "Stats.csv" ThresholdsCsv = "Thresholds.csv" @@ -901,7 +892,6 @@ const ( TBLTPActionTriggers = "tp_action_triggers" TBLTPAccountActions = "tp_account_actions" TBLTPDerivedChargers = "tp_derived_chargers" - TBLTPUsers = "tp_users" TBLTPResources = "tp_resources" TBLTPStats = "tp_stats" TBLTPThresholds = "tp_thresholds"