mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 18:46:24 +05:00
Added RalS as service in ServiceManager
This commit is contained in:
committed by
Dan Christian Bogos
parent
a92348a905
commit
e4abc4ea07
@@ -24,7 +24,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/config"
|
||||
"github.com/cgrates/cgrates/engine"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
@@ -46,10 +45,22 @@ func TestCdrsReload(t *testing.T) {
|
||||
|
||||
close(chS.GetPrecacheChannel(utils.CacheChargerProfiles))
|
||||
close(chS.GetPrecacheChannel(utils.CacheChargerFilterIndexes))
|
||||
|
||||
close(chS.GetPrecacheChannel(utils.CacheDestinations))
|
||||
close(chS.GetPrecacheChannel(utils.CacheReverseDestinations))
|
||||
close(chS.GetPrecacheChannel(utils.CacheRatingPlans))
|
||||
close(chS.GetPrecacheChannel(utils.CacheRatingProfiles))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActions))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActionPlans))
|
||||
close(chS.GetPrecacheChannel(utils.CacheAccountActionPlans))
|
||||
close(chS.GetPrecacheChannel(utils.CacheActionTriggers))
|
||||
close(chS.GetPrecacheChannel(utils.CacheSharedGroups))
|
||||
close(chS.GetPrecacheChannel(utils.CacheTimings))
|
||||
|
||||
cfg.ChargerSCfg().Enabled = true
|
||||
cfg.RalsCfg().RALsEnabled = true
|
||||
responderChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
responderChan <- v1.NewResourceSv1(nil)
|
||||
cacheSChan := make(chan rpcclient.RpcClientConnection, 1)
|
||||
cacheSChan <- chS
|
||||
server := utils.NewServer()
|
||||
srvMngr := servmanager.NewServiceManager(cfg /*dm*/, nil,
|
||||
/*cdrStorage*/ nil,
|
||||
@@ -57,7 +68,7 @@ func TestCdrsReload(t *testing.T) {
|
||||
server, nil, engineShutdown)
|
||||
srvMngr.SetCacheS(chS)
|
||||
cdrS := NewCDRServer()
|
||||
srvMngr.AddService(cdrS, NewResponderService(responderChan), NewChargerService())
|
||||
srvMngr.AddService(cdrS, NewRalService(srvMngr), NewChargerService(), &CacheService{connChan: cacheSChan}, NewSchedulerService())
|
||||
if err = srvMngr.StartServices(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
152
services/rals.go
Normal file
152
services/rals.go
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
"github.com/cgrates/rpcclient"
|
||||
)
|
||||
|
||||
// NewRalService returns the Ral Service
|
||||
func NewRalService(sp servmanager.ServiceProvider) servmanager.Service {
|
||||
apiv1 := NewApierV1Service()
|
||||
apiv2 := NewApierV2Service(apiv1)
|
||||
resp := NewResponderService()
|
||||
sp.AddService(apiv1, apiv2, resp)
|
||||
return &RalService{
|
||||
apiv1: apiv1,
|
||||
apiv2: apiv2,
|
||||
responder: resp,
|
||||
connChan: make(chan rpcclient.RpcClientConnection, 1),
|
||||
}
|
||||
}
|
||||
|
||||
// RalService implements Service interface
|
||||
type RalService struct {
|
||||
sync.RWMutex
|
||||
rals *v1.RALsV1
|
||||
apiv1 *ApierV1Service
|
||||
apiv2 *ApierV2Service
|
||||
responder *ResponderService
|
||||
connChan chan rpcclient.RpcClientConnection
|
||||
}
|
||||
|
||||
// Start should handle the sercive start
|
||||
// For this service the start should be called from RAL Service
|
||||
func (rals *RalService) Start(sp servmanager.ServiceProvider, waitCache bool) (err error) {
|
||||
if rals.IsRunning() {
|
||||
return fmt.Errorf("service aleady running")
|
||||
}
|
||||
|
||||
rals.Lock()
|
||||
defer rals.Unlock()
|
||||
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheDestinations)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheReverseDestinations)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheRatingPlans)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheRatingProfiles)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheActions)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheActionPlans)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheAccountActionPlans)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheActionTriggers)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheSharedGroups)
|
||||
<-sp.GetCacheS().GetPrecacheChannel(utils.CacheTimings)
|
||||
|
||||
if err = rals.responder.Start(sp, waitCache); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = rals.apiv1.Start(sp, waitCache); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = rals.apiv2.Start(sp, waitCache); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
rals.rals = v1.NewRALsV1()
|
||||
|
||||
if !sp.GetConfig().DispatcherSCfg().Enabled {
|
||||
sp.GetServer().RpcRegister(rals.rals)
|
||||
}
|
||||
|
||||
utils.RegisterRpcParams(utils.RALsV1, rals.rals)
|
||||
|
||||
rals.connChan <- rals.rals
|
||||
return
|
||||
}
|
||||
|
||||
// GetIntenternalChan returns the internal connection chanel
|
||||
func (rals *RalService) GetIntenternalChan() (conn chan rpcclient.RpcClientConnection) {
|
||||
return rals.connChan
|
||||
}
|
||||
|
||||
// Reload handles the change of config
|
||||
func (rals *RalService) Reload(sp servmanager.ServiceProvider) (err error) {
|
||||
if err = rals.apiv1.Reload(sp); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.apiv2.Reload(sp); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.responder.Reload(sp); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Shutdown stops the service
|
||||
func (rals *RalService) Shutdown() (err error) {
|
||||
rals.Lock()
|
||||
defer rals.Unlock()
|
||||
if err = rals.apiv1.Shutdown(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.apiv2.Shutdown(); err != nil {
|
||||
return
|
||||
}
|
||||
if err = rals.responder.Shutdown(); err != nil {
|
||||
return
|
||||
}
|
||||
rals.rals = nil
|
||||
<-rals.connChan
|
||||
return
|
||||
}
|
||||
|
||||
// GetRPCInterface returns the interface to register for server
|
||||
func (rals *RalService) GetRPCInterface() interface{} {
|
||||
return rals.rals
|
||||
}
|
||||
|
||||
// IsRunning returns if the service is running
|
||||
func (rals *RalService) IsRunning() bool {
|
||||
rals.RLock()
|
||||
defer rals.RUnlock()
|
||||
return rals != nil && rals.rals != nil
|
||||
}
|
||||
|
||||
// ServiceName returns the service name
|
||||
func (rals *RalService) ServiceName() string {
|
||||
return utils.RALService
|
||||
}
|
||||
@@ -29,9 +29,9 @@ import (
|
||||
)
|
||||
|
||||
// NewResponderService returns the Resonder Service
|
||||
func NewResponderService(connChan chan rpcclient.RpcClientConnection) *ResponderService {
|
||||
func NewResponderService() *ResponderService {
|
||||
return &ResponderService{
|
||||
connChan: connChan,
|
||||
connChan: make(chan rpcclient.RpcClientConnection, 1),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,6 @@ func (resp *ResponderService) Start(sp servmanager.ServiceProvider, waitCache bo
|
||||
if resp.IsRunning() {
|
||||
return fmt.Errorf("service aleady running")
|
||||
}
|
||||
var waitTasks []chan struct{}
|
||||
cacheTaskChan := make(chan struct{})
|
||||
waitTasks = append(waitTasks, cacheTaskChan)
|
||||
|
||||
var thdS, stats rpcclient.RpcClientConnection
|
||||
if thdS, err = sp.GetConnection(utils.ThresholdS, sp.GetConfig().RalsCfg().RALsThresholdSConns); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user