mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Add SchedulerSv1 in Dispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
2a1b9a198a
commit
dfeef24ca9
@@ -638,3 +638,22 @@ func (dS *DispatcherGuardianSv1) RemoteUnlock(attr *dispatchers.AttrRemoteUnlock
|
||||
func (dS *DispatcherGuardianSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dS.dS.GuardianSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
func NewDispatcherSchedulerSv1(dps *dispatchers.DispatcherService) *DispatcherSchedulerSv1 {
|
||||
return &DispatcherSchedulerSv1{dS: dps}
|
||||
}
|
||||
|
||||
// Exports RPC from SchedulerSv1
|
||||
type DispatcherSchedulerSv1 struct {
|
||||
dS *dispatchers.DispatcherService
|
||||
}
|
||||
|
||||
// Reload reloads scheduler instructions
|
||||
func (dS *DispatcherSchedulerSv1) Reload(attr *dispatchers.StringkWithApiKey, reply *string) (err error) {
|
||||
return dS.dS.SchedulerSv1Reload(attr, reply)
|
||||
}
|
||||
|
||||
// Ping used to detreminate if component is active
|
||||
func (dS *DispatcherSchedulerSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
|
||||
return dS.dS.SchedulerSv1Ping(args, reply)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
|
||||
package v1
|
||||
|
||||
import "github.com/cgrates/cgrates/servmanager"
|
||||
import (
|
||||
"github.com/cgrates/cgrates/servmanager"
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
func NewSchedulerSv1(schdS *servmanager.SchedulerS) *SchedulerSv1 {
|
||||
return &SchedulerSv1{schdS: schdS}
|
||||
@@ -33,3 +36,8 @@ type SchedulerSv1 struct {
|
||||
func (schdSv1 *SchedulerSv1) Reload(arg string, reply *string) error {
|
||||
return schdSv1.schdS.V1Reload(arg, reply)
|
||||
}
|
||||
|
||||
func (schdSv1 *SchedulerSv1) Ping(ign *utils.CGREvent, reply *string) error {
|
||||
*reply = utils.Pong
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1007,6 +1007,9 @@ func startDispatcherService(internalDispatcherSChan chan *dispatchers.Dispatcher
|
||||
server.RpcRegisterName(utils.GuardianSv1,
|
||||
v1.NewDispatcherGuardianSv1(dspS))
|
||||
|
||||
server.RpcRegisterName(utils.SchedulerSv1,
|
||||
v1.NewDispatcherSchedulerSv1(dspS))
|
||||
|
||||
internalDispatcherSChan <- dspS
|
||||
}
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ func (self *CmdApierPing) RpcMethod() string {
|
||||
return utils.DispatcherSv1Ping
|
||||
case utils.AnalyzerSLow:
|
||||
return utils.AnalyzerSv1Ping
|
||||
case utils.SchedulerSLow:
|
||||
return utils.SchedulerSv1Ping
|
||||
default:
|
||||
}
|
||||
return self.rpcMethod
|
||||
|
||||
@@ -11,3 +11,4 @@ cgrates.org,ATTR_API_SES_AUTH,*auth,*string:~APIKey:ses12345,,,APIMethods,Sessio
|
||||
cgrates.org,ATTR_API_RSP_AUTH,*auth,*string:~APIKey:rsp12345,,,APIMethods,Responder.Status&Responder.GetTimeout&Responder.Shutdown&Responder.Ping,false,20
|
||||
cgrates.org,ATTR_API_CHC_AUTH,*auth,*string:~APIKey:chc12345,,,APIMethods,CacheSv1.Ping&CacheSv1.GetCacheStats&CacheSv1.LoadCache&CacheSv1.PrecacheStatus&CacheSv1.GetItemIDs&CacheSv1.HasItem&CacheSv1.GetItemExpiryTime&CacheSv1.ReloadCache&CacheSv1.RemoveItem&CacheSv1.FlushCache&CacheSv1.Clear,false,20
|
||||
cgrates.org,ATTR_API_GRD_AUTH,*auth,*string:~APIKey:grd12345,,,APIMethods,GuardianSv1.Ping&GuardianSv1.RemoteLock&GuardianSv1.RemoteUnlock,false,20
|
||||
cgrates.org,ATTR_API_SCHD_AUTH,*auth,*string:~APIKey:sched12345,,,APIMethods,SchedulerSv1.Ping,false,20
|
||||
|
||||
|
49
dispatchers/scheduler.go
Normal file
49
dispatchers/scheduler.go
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
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"
|
||||
)
|
||||
|
||||
func (dS *DispatcherService) SchedulerSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.SchedulerSv1Ping,
|
||||
args.CGREvent.Tenant,
|
||||
args.APIKey, args.CGREvent.Time); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&args.CGREvent, utils.MetaScheduler, args.RouteID,
|
||||
utils.SchedulerSv1Ping, args.CGREvent, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SchedulerSv1Reload(args *StringkWithApiKey, reply *string) (err error) {
|
||||
if dS.attrS != nil {
|
||||
if err = dS.authorize(utils.SchedulerSv1Ping,
|
||||
args.TenantArg.Tenant,
|
||||
args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaScheduler,
|
||||
args.RouteID, utils.SchedulerSv1Reload, args.Arg, reply)
|
||||
}
|
||||
57
dispatchers/scheduler_it_test.go
Normal file
57
dispatchers/scheduler_it_test.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// +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 <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package dispatchers
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/cgrates/cgrates/utils"
|
||||
)
|
||||
|
||||
var sTestsDspSched = []func(t *testing.T){
|
||||
testDspSchedPing,
|
||||
}
|
||||
|
||||
//Test start here
|
||||
func TestDspSchedulerSTMySQL(t *testing.T) {
|
||||
testDsp(t, sTestsDspSched, "TestDspSchedulerSTMySQL", "all", "all2", "attributes", "dispatchers", "tutorial", "oldtutorial", "dispatchers")
|
||||
}
|
||||
|
||||
func testDspSchedPing(t *testing.T) {
|
||||
var reply string
|
||||
if err := allEngine.RCP.Call(utils.SchedulerSv1Ping, new(utils.CGREvent), &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
if err := dispEngine.RCP.Call(utils.SchedulerSv1Ping, &CGREvWithApiKey{
|
||||
CGREvent: utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
},
|
||||
DispatcherResource: DispatcherResource{
|
||||
APIKey: "sched12345",
|
||||
},
|
||||
}, &reply); err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.Pong {
|
||||
t.Errorf("Received: %s", reply)
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,12 @@ type AttrRemoteUnlockWithApiKey struct {
|
||||
RefID string
|
||||
}
|
||||
|
||||
type StringkWithApiKey struct {
|
||||
DispatcherResource
|
||||
utils.TenantArg
|
||||
Arg string
|
||||
}
|
||||
|
||||
func ParseStringMap(s string) utils.StringMap {
|
||||
if s == utils.ZERO {
|
||||
return make(utils.StringMap)
|
||||
|
||||
@@ -611,6 +611,7 @@ const (
|
||||
ThresholdsLow = "thresholds"
|
||||
DispatcherSLow = "dispatchers"
|
||||
AnalyzerSLow = "analyzers"
|
||||
SchedulerSLow = "schedulers"
|
||||
LoaderSLow = "loaders"
|
||||
)
|
||||
|
||||
@@ -863,7 +864,8 @@ const (
|
||||
|
||||
// Scheduler
|
||||
const (
|
||||
SchedulerPing = "Scheduler.Ping"
|
||||
SchedulerSv1 = "SchedulerSv1"
|
||||
SchedulerSv1Ping = "SchedulerSv1.Ping"
|
||||
SchedulerSv1Reload = "SchedulerSv1.Reload"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user