From 3fafb012909d57c8424ef10ede9d4b6dddadb40b Mon Sep 17 00:00:00 2001 From: edwardro22 Date: Tue, 23 Jan 2018 12:52:12 +0200 Subject: [PATCH] Added GetPassiveSessions API --- apier/v1/sessions.go | 10 ++++++ apier/v1/smgenericbirpcv1.go | 6 ++-- console/passive_sessions.go | 67 ++++++++++++++++++++++++++++++++++++ utils/consts.go | 1 + 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 console/passive_sessions.go diff --git a/apier/v1/sessions.go b/apier/v1/sessions.go index 2c9149c1b..9bfe01bf5 100644 --- a/apier/v1/sessions.go +++ b/apier/v1/sessions.go @@ -44,6 +44,7 @@ func (ssv1 *SessionSv1) Handlers() map[string]interface{} { utils.SessionSv1ProcessCDR: ssv1.BiRpcProcessCDR, utils.SessionSv1ProcessEvent: ssv1.BiRpcProcessEvent, utils.SessionSv1GetActiveSessions: ssv1.BiRPCV1GetActiveSessions, + utils.SessionSv1GetPassiveSessions: ssv1.BiRPCV1GetPassiveSessions, } } @@ -85,6 +86,10 @@ func (ssv1 *SessionSv1) GetActiveSessions(args map[string]string, rply *[]*sessi return ssv1.SMG.BiRPCV1GetActiveSessions(nil, args, rply) } +func (ssv1 *SessionSv1) GetPassiveSessions(args map[string]string, rply *[]*sessionmanager.ActiveSession) error { + return ssv1.SMG.BiRPCV1GetPassiveSessions(nil, args, rply) +} + func (ssv1 *SessionSv1) BiRpcAuthorizeEvent(clnt *rpc2.Client, args *sessionmanager.V1AuthorizeArgs, rply *sessionmanager.V1AuthorizeReply) error { return ssv1.SMG.BiRPCv1AuthorizeEvent(clnt, args, rply) @@ -123,3 +128,8 @@ func (ssv1 *SessionSv1) BiRPCV1GetActiveSessions(clnt *rpc2.Client, args map[str rply *[]*sessionmanager.ActiveSession) error { return ssv1.SMG.BiRPCV1GetActiveSessions(clnt, args, rply) } + +func (ssv1 *SessionSv1) BiRPCV1GetPassiveSessions(clnt *rpc2.Client, args map[string]string, + rply *[]*sessionmanager.ActiveSession) error { + return ssv1.SMG.BiRPCV1GetPassiveSessions(clnt, args, rply) +} diff --git a/apier/v1/smgenericbirpcv1.go b/apier/v1/smgenericbirpcv1.go index b14e2030c..305980546 100644 --- a/apier/v1/smgenericbirpcv1.go +++ b/apier/v1/smgenericbirpcv1.go @@ -42,7 +42,7 @@ func (self *SMGenericBiRpcV1) Handlers() map[string]interface{} { "SMGenericV1.ProcessCDR": self.ProcessCDR, "SMGenericV1.GetActiveSessions": self.GetActiveSessions, "SMGenericV1.GetActiveSessionsCount": self.GetActiveSessionsCount, - "SMGenericV1.Getá¹”assiveSessions": self.Getá¹”assiveSessions, + "SMGenericV1.GetPassiveSessions": self.GetPassiveSessions, "SMGenericV1.GetPassiveSessionsCount": self.GetPassiveSessionsCount, "SMGenericV1.ReplicateActiveSessions": self.ReplicateActiveSessions, } @@ -86,8 +86,8 @@ func (self *SMGenericBiRpcV1) GetActiveSessionsCount(clnt *rpc2.Client, attrs ma return self.sm.BiRPCV1GetActiveSessionsCount(clnt, attrs, reply) } -func (self *SMGenericBiRpcV1) Getá¹”assiveSessions(clnt *rpc2.Client, attrs map[string]string, reply *[]*sessionmanager.ActiveSession) error { - return self.sm.BiRPCV1GetActiveSessions(clnt, attrs, reply) +func (self *SMGenericBiRpcV1) GetPassiveSessions(clnt *rpc2.Client, attrs map[string]string, reply *[]*sessionmanager.ActiveSession) error { + return self.sm.BiRPCV1GetPassiveSessions(clnt, attrs, reply) } func (self *SMGenericBiRpcV1) GetPassiveSessionsCount(clnt *rpc2.Client, attrs map[string]string, reply *int) error { diff --git a/console/passive_sessions.go b/console/passive_sessions.go new file mode 100644 index 000000000..bdbd1d2c9 --- /dev/null +++ b/console/passive_sessions.go @@ -0,0 +1,67 @@ +/* +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 console + +import ( + "github.com/cgrates/cgrates/sessionmanager" + "github.com/cgrates/cgrates/utils" +) + +func init() { + c := &CmdPassiveSessions{ + name: "passive_sessions", + rpcMethod: utils.SessionSv1GetPassiveSessions, + } + commands[c.Name()] = c + c.CommandExecuter = &CommandExecuter{c} +} + +// Commander implementation +type CmdPassiveSessions struct { + name string + rpcMethod string + rpcParams interface{} + *CommandExecuter +} + +func (self *CmdPassiveSessions) Name() string { + return self.name +} + +func (self *CmdPassiveSessions) RpcMethod() string { + return self.rpcMethod +} + +func (self *CmdPassiveSessions) RpcParams(reset bool) interface{} { + if reset || self.rpcParams == nil { + self.rpcParams = &map[string]string{} + } + return self.rpcParams +} + +func (self *CmdPassiveSessions) PostprocessRpcParams() error { + param := self.rpcParams.(*map[string]string) + self.rpcParams = param + return nil +} + +func (self *CmdPassiveSessions) RpcResult() interface{} { + var sessions *[]*sessionmanager.ActiveSession + return &sessions +} diff --git a/utils/consts.go b/utils/consts.go index c5f1cd5c3..8e4acfe00 100755 --- a/utils/consts.go +++ b/utils/consts.go @@ -604,6 +604,7 @@ const ( SessionSv1ProcessEvent = "SessionSv1.ProcessEvent" SessionSv1DisconnectSession = "SessionSv1.DisconnectSession" SessionSv1GetActiveSessions = "SessionSv1.GetActiveSessions" + SessionSv1GetPassiveSessions = "SessionSv1.GetPassiveSessions" SMGenericV1InitiateSession = "SMGenericV1.InitiateSession" SMGenericV2InitiateSession = "SMGenericV2.InitiateSession" SMGenericV2UpdateSession = "SMGenericV2.UpdateSession"