Added ServiceManagerV1 to DispatcherService

This commit is contained in:
Tripon Alexandru-Ionut
2019-04-17 18:56:05 +03:00
committed by Dan Christian Bogos
parent 23ba89294a
commit 6874d62b5d
8 changed files with 147 additions and 12 deletions

View File

@@ -1682,35 +1682,35 @@ func TestApierLoadTariffPlanFromStorDb(t *testing.T) {
func TestApierStartStopServiceStatus(t *testing.T) {
var reply string
if err := rater.Call(utils.ServiceManagerV1ServiceStatus, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithApiKey{ArgStartService: 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(utils.ServiceManagerV1StopService, servmanager.ArgStartService{ServiceID: "INVALID"},
if err := rater.Call(utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithApiKey{ArgStartService: servmanager.ArgStartService{ServiceID: "INVALID"}},
&reply); err == nil || err.Error() != utils.UnsupportedServiceIDCaps {
t.Error(err)
}
if err := rater.Call(utils.ServiceManagerV1StopService, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServiceManagerV1StopService, dispatchers.ArgStartServiceWithApiKey{ArgStartService: 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(utils.ServiceManagerV1ServiceStatus, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithApiKey{ArgStartService: 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(utils.ServiceManagerV1StartService, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServiceManagerV1StartService, dispatchers.ArgStartServiceWithApiKey{ArgStartService: 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(utils.ServiceManagerV1ServiceStatus, servmanager.ArgStartService{ServiceID: utils.MetaScheduler},
if err := rater.Call(utils.ServiceManagerV1ServiceStatus, dispatchers.ArgStartServiceWithApiKey{ArgStartService: servmanager.ArgStartService{ServiceID: utils.MetaScheduler}},
&reply); err != nil {
t.Error(err)
} else if reply != utils.RunningCaps {

View File

@@ -721,3 +721,26 @@ func (dS *DispatcherSCDRsV1) ProcessEvent(args *engine.ArgV1ProcessEvent, reply
func (dS *DispatcherSCDRsV1) ProcessCDR(args *engine.CDRWithArgDispatcher, reply *string) error {
return dS.dS.CDRsV1ProcessCDR(args, reply)
}
func NewDispatcherSServiceManagerV1(dps *dispatchers.DispatcherService) *DispatcherSServiceManagerV1 {
return &DispatcherSServiceManagerV1{dS: dps}
}
// Exports RPC from ServiceManagerV1
type DispatcherSServiceManagerV1 struct {
dS *dispatchers.DispatcherService
}
// Ping used to detreminate if component is active
func (dS *DispatcherSServiceManagerV1) Ping(args *utils.CGREventWithArgDispatcher, reply *string) error {
return dS.dS.ServiceManagerV1Ping(args, reply)
}
func (dS *DispatcherSServiceManagerV1) StartService(args dispatchers.ArgStartServiceWithApiKey, reply *string) error {
return dS.dS.ServiceManagerV1StartService(args, reply)
}
func (dS *DispatcherSServiceManagerV1) StopService(args dispatchers.ArgStartServiceWithApiKey, reply *string) error {
return dS.dS.ServiceManagerV1StopService(args, reply)
}
func (dS *DispatcherSServiceManagerV1) ServiceStatus(args dispatchers.ArgStartServiceWithApiKey, reply *string) error {
return dS.dS.ServiceManagerV1ServiceStatus(args, reply)
}

View File

@@ -137,3 +137,10 @@ type CDRsV1Interface interface {
RateCDRs(arg *engine.ArgRateCDRs, reply *string) error
StoreSessionCost(attr *engine.AttrCDRSStoreSMCost, reply *string) error
}
type ServiceManagerV1Interface interface {
StartService(args dispatchers.ArgStartServiceWithApiKey, reply *string) error
StopService(args dispatchers.ArgStartServiceWithApiKey, reply *string) error
ServiceStatus(args dispatchers.ArgStartServiceWithApiKey, reply *string) error
Ping(ign *utils.CGREventWithArgDispatcher, reply *string) error
}

View File

@@ -83,3 +83,8 @@ func TestCDRsV1Interface(t *testing.T) {
_ = CDRsV1Interface(NewDispatcherSCDRsV1(nil))
_ = CDRsV1Interface(NewCDRsV1(nil))
}
func TestServiceManagerV1Interface(t *testing.T) {
_ = ServiceManagerV1Interface(NewDispatcherSServiceManagerV1(nil))
_ = ServiceManagerV1Interface(NewServiceManagerV1(nil))
}

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package v1
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/utils"
)
@@ -31,16 +32,16 @@ type ServiceManagerV1 struct {
sm *servmanager.ServiceManager // Need to have them capitalize so we can export in V2
}
func (servManager *ServiceManagerV1) StartService(args servmanager.ArgStartService, reply *string) (err error) {
return servManager.sm.V1StartService(args, reply)
func (servManager *ServiceManagerV1) StartService(args dispatchers.ArgStartServiceWithApiKey, reply *string) (err error) {
return servManager.sm.V1StartService(args.ArgStartService, reply)
}
func (servManager *ServiceManagerV1) StopService(args servmanager.ArgStartService, reply *string) (err error) {
return servManager.sm.V1StopService(args, reply)
func (servManager *ServiceManagerV1) StopService(args dispatchers.ArgStartServiceWithApiKey, reply *string) (err error) {
return servManager.sm.V1StopService(args.ArgStartService, reply)
}
func (servManager *ServiceManagerV1) ServiceStatus(args servmanager.ArgStartService, reply *string) (err error) {
return servManager.sm.V1ServiceStatus(args, reply)
func (servManager *ServiceManagerV1) ServiceStatus(args dispatchers.ArgStartServiceWithApiKey, reply *string) (err error) {
return servManager.sm.V1ServiceStatus(args.ArgStartService, reply)
}
// Ping return pong if the service is active

View File

@@ -0,0 +1,90 @@
/*
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 dispatchers
import (
"time"
"github.com/cgrates/cgrates/utils"
)
// ServiceManagerV1Ping interogates ServiceManager server responsible to process the event
func (dS *DispatcherService) ServiceManagerV1Ping(args *utils.CGREventWithArgDispatcher,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ServiceManagerV1Ping,
args.Tenant,
args.APIKey, args.Time); err != nil {
return
}
}
return dS.Dispatch(args.CGREvent, utils.MetaServiceManager, args.RouteID,
utils.ServiceManagerV1Ping, args, reply)
}
func (dS *DispatcherService) ServiceManagerV1StartService(args ArgStartServiceWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ServiceManagerV1StartService,
args.TenantArg.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaServiceManager, args.RouteID,
utils.ServiceManagerV1StartService, args, reply)
}
func (dS *DispatcherService) ServiceManagerV1StopService(args ArgStartServiceWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ServiceManagerV1StopService,
args.TenantArg.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaServiceManager, args.RouteID,
utils.ServiceManagerV1StopService, args, reply)
}
func (dS *DispatcherService) ServiceManagerV1ServiceStatus(args ArgStartServiceWithApiKey,
reply *string) (err error) {
if args.ArgDispatcher == nil {
return utils.NewErrMandatoryIeMissing("ArgDispatcher")
}
if dS.attrS != nil {
if err = dS.authorize(utils.ServiceManagerV1ServiceStatus,
args.TenantArg.Tenant,
args.APIKey, utils.TimePointer(time.Now())); err != nil {
return
}
}
return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaServiceManager, args.RouteID,
utils.ServiceManagerV1ServiceStatus, args, reply)
}

View File

@@ -22,6 +22,8 @@ import (
"strings"
"time"
"github.com/cgrates/cgrates/servmanager"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
@@ -99,6 +101,12 @@ type StringWithApiKey struct {
Arg string
}
type ArgStartServiceWithApiKey struct {
*utils.ArgDispatcher
utils.TenantArg
servmanager.ArgStartService
}
func ParseStringMap(s string) utils.StringMap {
if s == utils.ZERO {
return make(utils.StringMap)

View File

@@ -388,6 +388,7 @@ const (
MetaThresholds = "*thresholds"
MetaSuppliers = "*suppliers"
MetaAttributes = "*attributes"
MetaServiceManager = "*servicemanager"
MetaChargers = "*chargers"
MetaDispatchers = "*dispatchers"
MetaDispatcherHosts = "*dispatcher_hosts"