From 17d415c2b84c819644ff73bc9c6b6a4ab2b15b49 Mon Sep 17 00:00:00 2001 From: andronache Date: Mon, 29 Mar 2021 17:18:28 +0300 Subject: [PATCH] Removing accounts --- apier/v1/accountprofiles.go | 66 ------------- apier/v1/accountprofiles_it_test.go | 10 -- apier/v1/api_interfaces_test.go | 5 - cmd/cgr-engine/cgr-engine.go | 1 - console/ping_test.go | 34 ------- services/accounts.go | 139 ---------------------------- services/accounts_it_test.go | 110 ---------------------- services/accounts_test.go | 83 ----------------- 8 files changed, 448 deletions(-) delete mode 100644 services/accounts.go delete mode 100644 services/accounts_it_test.go delete mode 100644 services/accounts_test.go diff --git a/apier/v1/accountprofiles.go b/apier/v1/accountprofiles.go index a1db781ed..a6c4600e7 100644 --- a/apier/v1/accountprofiles.go +++ b/apier/v1/accountprofiles.go @@ -21,8 +21,6 @@ package v1 import ( "time" - "github.com/cgrates/cgrates/accounts" - "github.com/cgrates/cgrates/utils" ) @@ -130,67 +128,3 @@ func (apierSv1 *APIerSv1) RemoveAccountProfile(arg *utils.TenantIDWithAPIOpts, r *reply = utils.OK return nil } - -// NewAccountSv1 initializes AccountSv1 -func NewAccountSv1(aS *accounts.AccountS) *AccountSv1 { - return &AccountSv1{aS: aS} -} - -// AccountSv1 exports RPC from RLs -type AccountSv1 struct { - aS *accounts.AccountS -} - -// Call implements rpcclient.ClientConnector interface for internal RPC -func (aSv1 *AccountSv1) Call(serviceMethod string, - args interface{}, reply interface{}) error { - return utils.APIerRPCCall(aSv1, serviceMethod, args, reply) -} - -// Ping return pong if the service is active -func (aSv1 *AccountSv1) Ping(ign *utils.CGREvent, reply *string) error { - *reply = utils.Pong - return nil -} - -// AccountProfilesForEvent returns the matching AccountProfile for Event -func (aSv1 *AccountSv1) AccountProfilesForEvent(args *utils.ArgsAccountsForEvent, - aps *[]*utils.AccountProfile) (err error) { - return aSv1.aS.V1AccountProfilesForEvent(args, aps) -} - -// MaxAbstracts returns the maximum abstracts for the event, based on matching Account -func (aSv1 *AccountSv1) MaxAbstracts(args *utils.ArgsAccountsForEvent, - eEc *utils.ExtEventCharges) (err error) { - return aSv1.aS.V1MaxAbstracts(args, eEc) -} - -// DebitAbstracts performs debit for the provided event -func (aSv1 *AccountSv1) DebitAbstracts(args *utils.ArgsAccountsForEvent, - eEc *utils.ExtEventCharges) (err error) { - return aSv1.aS.V1DebitAbstracts(args, eEc) -} - -// MaxConcretes returns the maximum concretes for the event, based on the matching Account -func (aSv1 *AccountSv1) MaxConcretes(args *utils.ArgsAccountsForEvent, - eEc *utils.ExtEventCharges) (err error) { - return aSv1.aS.V1MaxConcretes(args, eEc) -} - -// DebitConcretes performs debit of concrete units for the provided event -func (aSv1 *AccountSv1) DebitConcretes(args *utils.ArgsAccountsForEvent, - eEc *utils.ExtEventCharges) (err error) { - return aSv1.aS.V1DebitConcretes(args, eEc) -} - -// ActionSetBalance performs a set balance action -func (aSv1 *AccountSv1) ActionSetBalance(args *utils.ArgsActSetBalance, - eEc *string) (err error) { - return aSv1.aS.V1ActionSetBalance(args, eEc) -} - -// ActionRemoveBalance removes a balance from an account -func (aSv1 *AccountSv1) ActionRemoveBalance(args *utils.ArgsActRemoveBalances, - eEc *string) (err error) { - return aSv1.aS.V1ActionRemoveBalance(args, eEc) -} diff --git a/apier/v1/accountprofiles_it_test.go b/apier/v1/accountprofiles_it_test.go index 471047192..39d7145b0 100644 --- a/apier/v1/accountprofiles_it_test.go +++ b/apier/v1/accountprofiles_it_test.go @@ -49,7 +49,6 @@ var ( testAccountSRPCConn, testAccountSLoadFromFolder, testAccountSGetAccountProfile, - testAccountSPing, testAccountSSettAccountProfile, testAccountSGetAccountProfileIDs, testAccountSGetAccountProfileIDsCount, @@ -215,15 +214,6 @@ func testAccountSGetAccountProfile(t *testing.T) { } } -func testAccountSPing(t *testing.T) { - var resp string - if err := accSRPC.Call(utils.AccountSv1Ping, new(utils.CGREvent), &resp); err != nil { - t.Error(err) - } else if resp != utils.Pong { - t.Error("Unexpected reply returned", resp) - } -} - func testAccountSSettAccountProfile(t *testing.T) { apiAccPrf = &utils.APIAccountProfileWithOpts{ APIAccountProfile: &utils.APIAccountProfile{ diff --git a/apier/v1/api_interfaces_test.go b/apier/v1/api_interfaces_test.go index 3abd44b35..2fac17dc0 100644 --- a/apier/v1/api_interfaces_test.go +++ b/apier/v1/api_interfaces_test.go @@ -119,11 +119,6 @@ func TestRateSv1Interface(t *testing.T) { _ = RateSv1Interface(NewRateSv1(nil)) } -func TestAccountSv1Interface(t *testing.T) { - _ = AccountSv1Interface(NewDispatcherAccountSv1(nil)) - _ = AccountSv1Interface(NewAccountSv1(nil)) -} - func TestActionSv1Interface(t *testing.T) { _ = ActionSv1Interface(NewDispatcherActionSv1(nil)) _ = ActionSv1Interface(NewActionSv1(nil)) diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 0f072904f..21e3a3c35 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -681,7 +681,6 @@ func main() { server, internalRateSChan, anz, srvDep), services.NewSIPAgent(cfg, filterSChan, shdChan, connManager, srvDep), services.NewActionService(cfg, dmService, cacheS, filterSChan, connManager, server, internalActionSChan, anz, srvDep), - services.NewAccountService(cfg, dmService, cacheS, filterSChan, connManager, server, internalAccountSChan, anz, srvDep), ) srvManager.StartServices() // Start FilterS diff --git a/console/ping_test.go b/console/ping_test.go index cb9ffb645..458ad0ef7 100644 --- a/console/ping_test.go +++ b/console/ping_test.go @@ -574,40 +574,6 @@ func TestCmdPingRateSLow(t *testing.T) { } } -func TestCmdPingAccountSLow(t *testing.T) { - // commands map is initiated in init function - command := commands["ping"] - castCommand, canCast := command.(*CmdApierPing) - if !canCast { - t.Fatalf("cannot cast") - } - castCommand.item = utils.AccountSLow - result2 := command.RpcMethod() - if !reflect.DeepEqual(result2, utils.AccountSv1Ping) { - t.Errorf("Expected <%+v>, Received <%+v>", utils.AccountSv1Ping, result2) - } - m, ok := reflect.TypeOf(new(v1.AccountSv1)).MethodByName(strings.Split(command.RpcMethod(), utils.NestingSep)[1]) - if !ok { - t.Fatal("method not found") - } - if m.Type.NumIn() != 3 { // ApierSv1 is consider and we expect 3 inputs - t.Fatalf("invalid number of input parameters ") - } - // for coverage purpose - result := command.RpcParams(true) - if !reflect.DeepEqual(result, new(StringWrapper)) { - t.Errorf("Expected <%T>, Received <%T>", new(StringWrapper), result) - } - // verify the type of output parameter - if ok := m.Type.In(2).AssignableTo(reflect.TypeOf(command.RpcResult())); !ok { - t.Fatalf("cannot assign output parameter") - } - // for coverage purpose - if err := command.PostprocessRpcParams(); err != nil { - t.Fatal(err) - } -} - func TestCmdPingActionSLow(t *testing.T) { // commands map is initiated in init function command := commands["ping"] diff --git a/services/accounts.go b/services/accounts.go deleted file mode 100644 index 4f2b9f3c1..000000000 --- a/services/accounts.go +++ /dev/null @@ -1,139 +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 services - -import ( - "fmt" - "sync" - - "github.com/cgrates/cgrates/accounts" - - v1 "github.com/cgrates/cgrates/apier/v1" - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/cores" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/servmanager" - "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" -) - -// NewAccountService returns the Account Service -func NewAccountService(cfg *config.CGRConfig, dm *DataDBService, - cacheS *engine.CacheS, filterSChan chan *engine.FilterS, - connMgr *engine.ConnManager, server *cores.Server, - internalChan chan rpcclient.ClientConnector, - anz *AnalyzerService, srvDep map[string]*sync.WaitGroup) servmanager.Service { - return &AccountService{ - connChan: internalChan, - cfg: cfg, - dm: dm, - cacheS: cacheS, - filterSChan: filterSChan, - connMgr: connMgr, - server: server, - anz: anz, - srvDep: srvDep, - rldChan: make(chan struct{}, 1), - } -} - -// AccountService implements Service interface -type AccountService struct { - sync.RWMutex - cfg *config.CGRConfig - dm *DataDBService - cacheS *engine.CacheS - filterSChan chan *engine.FilterS - connMgr *engine.ConnManager - server *cores.Server - - rldChan chan struct{} - stopChan chan struct{} - - acts *accounts.AccountS - rpc *v1.AccountSv1 // useful on restart - connChan chan rpcclient.ClientConnector // publish the internal Subsystem when available - anz *AnalyzerService - srvDep map[string]*sync.WaitGroup -} - -// Start should handle the sercive start -func (acts *AccountService) Start() (err error) { - if acts.IsRunning() { - return utils.ErrServiceAlreadyRunning - } - - <-acts.cacheS.GetPrecacheChannel(utils.CacheAccountProfiles) - <-acts.cacheS.GetPrecacheChannel(utils.CacheAccountProfilesFilterIndexes) - - filterS := <-acts.filterSChan - acts.filterSChan <- filterS - dbchan := acts.dm.GetDMChan() - datadb := <-dbchan - dbchan <- datadb - - acts.Lock() - defer acts.Unlock() - acts.acts = accounts.NewAccountS(acts.cfg, filterS, acts.connMgr, datadb) - acts.stopChan = make(chan struct{}) - go acts.acts.ListenAndServe(acts.stopChan, acts.rldChan) - - utils.Logger.Info(fmt.Sprintf("<%s> starting <%s> subsystem", utils.CoreS, utils.AccountS)) - acts.rpc = v1.NewAccountSv1(acts.acts) - if !acts.cfg.DispatcherSCfg().Enabled { - acts.server.RpcRegister(acts.rpc) - } - acts.connChan <- acts.anz.GetInternalCodec(acts.rpc, utils.AccountS) - return -} - -// Reload handles the change of config -func (acts *AccountService) Reload() (err error) { - acts.rldChan <- struct{}{} - return // for the moment nothing to reload -} - -// Shutdown stops the service -func (acts *AccountService) Shutdown() (err error) { - acts.Lock() - close(acts.stopChan) - acts.acts.Shutdown() - acts.acts = nil - acts.rpc = nil - <-acts.connChan - acts.Unlock() - return -} - -// IsRunning returns if the service is running -func (acts *AccountService) IsRunning() bool { - acts.RLock() - defer acts.RUnlock() - return acts != nil && acts.acts != nil -} - -// ServiceName returns the service name -func (acts *AccountService) ServiceName() string { - return utils.AccountS -} - -// ShouldRun returns if the service should be running -func (acts *AccountService) ShouldRun() bool { - return acts.cfg.AccountSCfg().Enabled -} diff --git a/services/accounts_it_test.go b/services/accounts_it_test.go deleted file mode 100644 index eb9ed1a8a..000000000 --- a/services/accounts_it_test.go +++ /dev/null @@ -1,110 +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 services - -import ( - "path" - "sync" - "testing" - "time" - - "github.com/cgrates/rpcclient" - - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/cores" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/servmanager" - "github.com/cgrates/cgrates/utils" -) - -func TestAccountSReload(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - - utils.Logger, _ = utils.Newlogger(utils.MetaSysLog, cfg.GeneralCfg().NodeID) - utils.Logger.SetLogLevel(7) - - shdChan := utils.NewSyncedChan() - shdWg := new(sync.WaitGroup) - chS := engine.NewCacheS(cfg, nil, nil) - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil - close(chS.GetPrecacheChannel(utils.CacheAccountProfiles)) - close(chS.GetPrecacheChannel(utils.CacheAccountProfilesFilterIndexes)) - server := cores.NewServer(nil) - srvMngr := servmanager.NewServiceManager(cfg, shdChan, shdWg, nil) - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - db := NewDataDBService(cfg, nil, srvDep) - acctRPC := make(chan rpcclient.ClientConnector, 1) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - acctS := NewAccountService(cfg, db, chS, filterSChan, nil, server, acctRPC, anz, srvDep) - engine.NewConnManager(cfg, nil) - srvMngr.AddServices(acctS, - NewLoaderService(cfg, db, filterSChan, server, make(chan rpcclient.ClientConnector, 1), nil, anz, srvDep), db) - if err := srvMngr.StartServices(); err != nil { - t.Error(err) - } - if acctS.IsRunning() { - t.Errorf("Expected service to be down") - } - if db.IsRunning() { - t.Errorf("Expected service to be down") - } - - var reply string - if err := cfg.V1ReloadConfig(&config.ReloadArgs{ - Path: path.Join("/usr", "share", "cgrates", "conf", "samples", "tutmongo"), - Section: config.AccountSCfgJson, - }, &reply); err != nil { - t.Error(err) - } else if reply != utils.OK { - t.Errorf("Expecting OK ,received %s", reply) - } - select { - case d := <-acctRPC: - acctRPC <- d - case <-time.After(time.Second): - t.Fatal("It took to long to reload the cache") - } - if !acctS.IsRunning() { - t.Errorf("Expected service to be running") - } - if !db.IsRunning() { - t.Errorf("Expected service to be running") - } - err := acctS.Start() - if err == nil || err != utils.ErrServiceAlreadyRunning { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.ErrServiceAlreadyRunning, err) - } - err = acctS.Reload() - if err != nil { - t.Errorf("\nExpecting ,\n Received <%+v>", err) - } - cfg.AccountSCfg().Enabled = false - cfg.GetReloadChan(config.AccountSCfgJson) <- struct{}{} - time.Sleep(10 * time.Millisecond) - - if acctS.IsRunning() { - t.Errorf("Expected service to be down") - } - - shdChan.CloseOnce() - time.Sleep(10 * time.Millisecond) - -} diff --git a/services/accounts_test.go b/services/accounts_test.go deleted file mode 100644 index d30a87715..000000000 --- a/services/accounts_test.go +++ /dev/null @@ -1,83 +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 services - -import ( - "reflect" - "sync" - "testing" - - "github.com/cgrates/cgrates/accounts" - - "github.com/cgrates/cgrates/config" - "github.com/cgrates/cgrates/cores" - "github.com/cgrates/cgrates/engine" - "github.com/cgrates/cgrates/utils" - "github.com/cgrates/rpcclient" -) - -//TestAccountSCoverage for cover testing -func TestAccountSCoverage(t *testing.T) { - cfg := config.NewDefaultCGRConfig() - shdChan := utils.NewSyncedChan() - chS := engine.NewCacheS(cfg, nil, nil) - filterSChan := make(chan *engine.FilterS, 1) - filterSChan <- nil - server := cores.NewServer(nil) - srvDep := map[string]*sync.WaitGroup{utils.DataDB: new(sync.WaitGroup)} - db := NewDataDBService(cfg, nil, srvDep) - actRPC := make(chan rpcclient.ClientConnector, 1) - anz := NewAnalyzerService(cfg, server, filterSChan, shdChan, make(chan rpcclient.ClientConnector, 1), srvDep) - actS := NewAccountService(cfg, db, - chS, filterSChan, nil, server, actRPC, - anz, srvDep) - if actS == nil { - t.Errorf("\nExpecting ,\n Received <%+v>", utils.ToJSON(actS)) - } - //initialises an empty chan to call the reload function - testChan := make(chan struct{}) - //populates actRPC with something in order to call the close function - actRPC <- chS - actS2 := &AccountService{ - cfg: cfg, - dm: db, - cacheS: chS, - filterSChan: filterSChan, - server: server, - rldChan: testChan, - stopChan: make(chan struct{}, 1), - connChan: actRPC, - anz: anz, - srvDep: srvDep, - } - if actS2.IsRunning() { - t.Errorf("Expected service to be down") - } - actS2.acts = accounts.NewAccountS(cfg, &engine.FilterS{}, nil, &engine.DataManager{}) - if !actS2.IsRunning() { - t.Errorf("Expected service to be running") - } - serviceName := actS2.ServiceName() - if !reflect.DeepEqual(serviceName, utils.AccountS) { - t.Errorf("\nExpecting <%+v>,\n Received <%+v>", utils.AccountS, serviceName) - } - shouldRun := actS2.ShouldRun() - if !reflect.DeepEqual(shouldRun, false) { - t.Errorf("\nExpecting ,\n Received <%+v>", shouldRun) - } -}