Moved ServiceManager as standalone API object

This commit is contained in:
Tripon Alexandru-Ionut
2019-04-10 14:53:45 +03:00
committed by Dan Christian Bogos
parent 5ab62a688d
commit 625addef39
5 changed files with 81 additions and 18 deletions

View File

@@ -909,18 +909,6 @@ func (self *ApierV1) RemoveActions(attr AttrRemoveActions, reply *string) error
return nil
}
func (v1 *ApierV1) StartService(args servmanager.ArgStartService, reply *string) (err error) {
return v1.ServManager.V1StartService(args, reply)
}
func (v1 *ApierV1) StopService(args servmanager.ArgStartService, reply *string) (err error) {
return v1.ServManager.V1StopService(args, reply)
}
func (v1 *ApierV1) ServiceStatus(args servmanager.ArgStartService, reply *string) (err error) {
return v1.ServManager.V1ServiceStatus(args, reply)
}
type ArgsReplyFailedPosts struct {
FailedRequestsInDir *string // if defined it will be our source of requests to be replayed
FailedRequestsOutDir *string // if defined it will become our destination for files failing to be replayed, *none to be discarded

View File

@@ -1673,35 +1673,35 @@ func TestApierLoadTariffPlanFromStorDb(t *testing.T) {
func TestApierStartStopServiceStatus(t *testing.T) {
var reply string
if err := rater.Call("ApierV1.ServiceStatus", servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServManagerV1ServiceStatus, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
&reply); err != nil {
t.Error(err)
} else if reply != utils.RunningCaps {
t.Errorf("Received: <%s>", reply)
}
if err := rater.Call("ApierV1.StopService", servmanager.ArgStartService{ServiceID: "INVALID"},
if err := rater.Call(utils.ServManagerV1StopService, servmanager.ArgStartService{ServiceID: "INVALID"},
&reply); err == nil || err.Error() != utils.UnsupportedServiceIDCaps {
t.Error(err)
}
if err := rater.Call("ApierV1.StopService", servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServManagerV1StopService, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
&reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Received: <%s>", reply)
}
if err := rater.Call("ApierV1.ServiceStatus", servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServManagerV1ServiceStatus, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
&reply); err != nil {
t.Error(err)
} else if reply != utils.StoppedCaps {
t.Errorf("Received: <%s>", reply)
}
if err := rater.Call("ApierV1.StartService", servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServManagerV1StartService, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
&reply); err != nil {
t.Error(err)
} else if reply != utils.OK {
t.Errorf("Received: <%s>", reply)
}
if err := rater.Call("ApierV1.ServiceStatus", servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServManagerV1ServiceStatus, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
&reply); err != nil {
t.Error(err)
} else if reply != utils.RunningCaps {

56
apier/v1/servmanager.go Normal file
View File

@@ -0,0 +1,56 @@
/*
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 v1
import (
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
)
func NewServManagerV1(sm *servmanager.ServiceManager) *ServManagerV1 {
return &ServManagerV1{sm: sm}
}
type ServManagerV1 struct {
sm *servmanager.ServiceManager // Need to have them capitalize so we can export in V2
}
func (servManager *ServManagerV1) StartService(args servmanager.ArgStartService, reply *string) (err error) {
return servManager.sm.V1StartService(args, reply)
}
func (servManager *ServManagerV1) StopService(args servmanager.ArgStartService, reply *string) (err error) {
return servManager.sm.V1StopService(args, reply)
}
func (servManager *ServManagerV1) ServiceStatus(args servmanager.ArgStartService, reply *string) (err error) {
return servManager.sm.V1ServiceStatus(args, reply)
}
// Ping return pong if the service is active
func (servManager *ServManagerV1) Ping(ign *utils.CGREventWithArgDispatcher, reply *string) error {
*reply = utils.Pong
return nil
}
// Call implements rpcclient.RpcClientConnection interface for internal RPC
func (servManager *ServManagerV1) Call(serviceMethod string,
args interface{}, reply interface{}) error {
return utils.APIerRPCCall(servManager, serviceMethod, args, reply)
}

View File

@@ -1119,6 +1119,14 @@ func initSchedulerS(internalSchedSChan chan rpcclient.RpcClientConnection,
internalSchedSChan <- schdS
}
func initServManagerV1(internalServiceManagerChan chan rpcclient.RpcClientConnection,
srvMngr *servmanager.ServiceManager, server *utils.Server) {
if !cfg.DispatcherSCfg().Enabled {
server.RpcRegister(v1.NewServManagerV1(srvMngr))
}
internalServiceManagerChan <- srvMngr
}
func startRpc(server *utils.Server, internalRaterChan,
internalCdrSChan, internalRsChan, internalStatSChan,
internalAttrSChan, internalChargerSChan, internalThdSChan, internalSuplSChan,
@@ -1444,6 +1452,7 @@ func main() {
internalLoaderSChan := make(chan rpcclient.RpcClientConnection, 1)
internalApierV1Chan := make(chan rpcclient.RpcClientConnection, 1)
internalApierV2Chan := make(chan rpcclient.RpcClientConnection, 1)
internalServeManagerChan := make(chan rpcclient.RpcClientConnection, 1)
// init internalRPCSet
engine.IntRPC = engine.NewRPCClientSet()
@@ -1465,6 +1474,7 @@ func main() {
engine.IntRPC.AddInternalRPCClient(utils.StatSv1, internalStatSChan)
engine.IntRPC.AddInternalRPCClient(utils.SupplierSv1, internalSupplierSChan)
engine.IntRPC.AddInternalRPCClient(utils.ThresholdSv1, internalThresholdSChan)
engine.IntRPC.AddInternalRPCClient(utils.ServManagerV1, internalServeManagerChan)
}
// init CacheS
@@ -1475,6 +1485,7 @@ func main() {
// Start ServiceManager
srvManager := servmanager.NewServiceManager(cfg, dm, exitChan, cacheS)
initServManagerV1(internalServeManagerChan, srvManager, server)
// init SchedulerS
initSchedulerS(internalSchedSChan, srvManager, server)

View File

@@ -730,6 +730,14 @@ const (
ApierV2CountCDRs = "ApierV2.CountCDRs"
)
const (
ServManagerV1 = "ServManagerV1"
ServManagerV1StartService = "ServManagerV1.StartService"
ServManagerV1StopService = "ServManagerV1.StopService"
ServManagerV1ServiceStatus = "ServManagerV1.ServiceStatus"
ServManagerV1Ping = "ServManagerV1.Ping"
)
// SupplierS APIs
const (
SupplierSv1GetSuppliers = "SupplierSv1.GetSuppliers"