From d93a0917a87b0aecc48729db348d3fd78be59a15 Mon Sep 17 00:00:00 2001 From: Trial97 Date: Thu, 19 Sep 2019 14:56:15 +0300 Subject: [PATCH] Added dummy service for CDRServer --- cmd/cgr-engine/cgr-engine.go | 2 +- services/cdrs.go | 86 ++++++++++++++++++++++++++++++++++ services/schedulers.go | 2 +- services/schedulers_it_test.go | 5 -- servmanager/servmanager.go | 4 +- utils/consts.go | 1 + 6 files changed, 91 insertions(+), 9 deletions(-) create mode 100644 services/cdrs.go diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go index 00f606609..ea2125e3d 100644 --- a/cmd/cgr-engine/cgr-engine.go +++ b/cmd/cgr-engine/cgr-engine.go @@ -1345,7 +1345,7 @@ func main() { reS := services.NewResourceService() supS := services.NewSupplierService() schS := services.NewSchedulerService() - srvManager.AddService(attrS, chrS, tS, stS, reS, supS, schS) + srvManager.AddService(attrS, chrS, tS, stS, reS, supS, schS, services.NewCDRServer(internalCdrSChan)) internalAttributeSChan = attrS.GetIntenternalChan() internalChargerSChan = chrS.GetIntenternalChan() internalThresholdSChan = tS.GetIntenternalChan() diff --git a/services/cdrs.go b/services/cdrs.go new file mode 100644 index 000000000..d265ce438 --- /dev/null +++ b/services/cdrs.go @@ -0,0 +1,86 @@ +/* +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 ( + "github.com/cgrates/cgrates/servmanager" + "github.com/cgrates/cgrates/utils" + "github.com/cgrates/rpcclient" +) + +// NewCDRServer returns the CDR Service +func NewCDRServer(connChan chan rpcclient.RpcClientConnection) servmanager.Service { + return &CDRServer{ + connChan: connChan, + } +} + +// CDRServer implements Service interface +// ToDo: Add the rest of functionality +// only the chanel without reload functionality +type CDRServer struct { + // cdrS *engine.CDRServer + // rpc *v1.CDRsV1 + connChan chan rpcclient.RpcClientConnection +} + +// Start should handle the sercive start +func (cdrS *CDRServer) Start(sp servmanager.ServiceProvider, waitCache bool) (err error) { + // if cdrS.IsRunning() { + // return fmt.Errorf("service aleady running") + // } + return utils.ErrNotImplemented +} + +// GetIntenternalChan returns the internal connection chanel +func (cdrS *CDRServer) GetIntenternalChan() (conn chan rpcclient.RpcClientConnection) { + return cdrS.connChan +} + +// Reload handles the change of config +func (cdrS *CDRServer) Reload(sp servmanager.ServiceProvider) (err error) { + return utils.ErrNotImplemented +} + +// Shutdown stops the service +func (cdrS *CDRServer) Shutdown() (err error) { + return utils.ErrNotImplemented + // if err = cdrS.cdrS.Shutdown(); err != nil { + // return + // } + // cdrS.cdrS = nil + // cdrS.rpc = nil + // <-cdrS.connChan + // return +} + +// GetRPCInterface returns the interface to register for server +func (cdrS *CDRServer) GetRPCInterface() interface{} { + return nil //cdrS.rpc +} + +// IsRunning returns if the service is running +func (cdrS *CDRServer) IsRunning() bool { + return cdrS != nil // && cdrS.cdrS != nil +} + +// ServiceName returns the service name +func (cdrS *CDRServer) ServiceName() string { + return utils.CDRServer +} diff --git a/services/schedulers.go b/services/schedulers.go index 2dcda1760..0a34a6725 100644 --- a/services/schedulers.go +++ b/services/schedulers.go @@ -67,7 +67,7 @@ func (schS *SchedulerService) Start(sp servmanager.ServiceProvider, waitCache bo schS.connChan <- schS.rpc // Create connection to CDR Server and share it in engine(used for *cdrlog action) - cdrsConn, err := sp.GetConnection(utils.CDRs, sp.GetConfig().SchedulerCfg().CDRsConns) + cdrsConn, err := sp.GetConnection(utils.CDRServer, sp.GetConfig().SchedulerCfg().CDRsConns) if err != nil { utils.Logger.Crit(fmt.Sprintf("<%s> Could not connect to CDRServer: %s", utils.SchedulerS, err.Error())) return diff --git a/services/schedulers_it_test.go b/services/schedulers_it_test.go index 656aa4aa1..5f4d768fa 100644 --- a/services/schedulers_it_test.go +++ b/services/schedulers_it_test.go @@ -20,7 +20,6 @@ along with this program. If not, see package services import ( - "fmt" "path" "testing" "time" @@ -78,14 +77,10 @@ func TestSchedulerSReload(t *testing.T) { t.Errorf("Expected service to be running") } cfg.SchedulerCfg().Enabled = false - fmt.Println("1") cfg.GetReloadChan(config.SCHEDULER_JSN) <- struct{}{} - fmt.Println("2") time.Sleep(10 * time.Millisecond) if schS.IsRunning() { t.Errorf("Expected service to be down") } - fmt.Println("3") engineShutdown <- true - fmt.Println("4") } diff --git a/servmanager/servmanager.go b/servmanager/servmanager.go index 7ebfd1cde..3a3b14b58 100644 --- a/servmanager/servmanager.go +++ b/servmanager/servmanager.go @@ -208,8 +208,8 @@ func (srvMngr *ServiceManager) GetConnection(subsystem string, conns []*config.R // srvMngr.RLock() // defer srvMngr.RUnlock() service, has := srvMngr.subsystems[subsystem] - if !has { // used to bypass the not implemented services - return nil, nil + if !has { // used to not cause panics because of services that are not already migrated + return nil, errors.New(utils.UnsupportedServiceIDCaps) } internalChan := service.GetIntenternalChan() if srvMngr.GetConfig().DispatcherSCfg().Enabled { diff --git a/utils/consts.go b/utils/consts.go index b386a4e6e..24bb3321c 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -600,6 +600,7 @@ const ( ChargerS = "ChargerS" CacheS = "CacheS" AnalyzerS = "AnalyzerS" + CDRServer = "CDRServer" ) // Lower service names