mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Added SessionSv1.ActivateSessions and SessionSv1.DeactivateSessions in dispatcher
This commit is contained in:
committed by
Dan Christian Bogos
parent
7ad109d7bc
commit
62d8f0a755
@@ -92,6 +92,8 @@ type SessionSv1Interface interface {
|
||||
Ping(ign *utils.CGREventWithArgDispatcher, reply *string) error
|
||||
ReplicateSessions(args dispatchers.ArgsReplicateSessionsWithApiKey, rply *string) error
|
||||
SetPassiveSession(args *sessions.Session, reply *string) error
|
||||
ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error
|
||||
DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error
|
||||
}
|
||||
|
||||
type ResponderInterface interface {
|
||||
|
||||
@@ -502,6 +502,13 @@ func (dS *DispatcherSessionSv1) SetPassiveSession(args *sessions.Session,
|
||||
return dS.dS.SessionSv1SetPassiveSession(args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherSessionSv1) ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error {
|
||||
return dS.dS.SessionSv1ActivateSessions(args, reply)
|
||||
}
|
||||
func (dS *DispatcherSessionSv1) DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error {
|
||||
return dS.dS.SessionSv1DeactivateSessions(args, reply)
|
||||
}
|
||||
|
||||
func NewDispatcherResponder(dps *dispatchers.DispatcherService) *DispatcherResponder {
|
||||
return &DispatcherResponder{dS: dps}
|
||||
}
|
||||
|
||||
@@ -121,12 +121,13 @@ func (ssv1 *SessionSv1) SetPassiveSession(args *sessions.Session,
|
||||
return ssv1.Ss.BiRPCv1SetPassiveSession(nil, args, reply)
|
||||
}
|
||||
|
||||
func (ssv1 *SessionSv1) ActivateSessions(args []string, reply *string) error {
|
||||
// ActivateSessions is called to activate a list/all sessions
|
||||
func (ssv1 *SessionSv1) ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error {
|
||||
return ssv1.Ss.BiRPCv1ActivateSessions(nil, args, reply)
|
||||
}
|
||||
|
||||
// DeactivateSessions is called to deactivate a list/all active sessios
|
||||
func (ssv1 *SessionSv1) DeactivateSessions(args []string, reply *string) error {
|
||||
func (ssv1 *SessionSv1) DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) error {
|
||||
return ssv1.Ss.BiRPCv1DeactivateSessions(nil, args, reply)
|
||||
}
|
||||
|
||||
|
||||
@@ -148,11 +148,11 @@ func (ssv1 *SessionSv1) BiRPCv1SetPassiveSession(clnt *rpc2.Client,
|
||||
}
|
||||
|
||||
func (ssv1 *SessionSv1) BiRPCv1ActivateSessions(clnt *rpc2.Client,
|
||||
args []string, reply *string) error {
|
||||
args *utils.SessionIDsWithArgsDispatcher, reply *string) error {
|
||||
return ssv1.Ss.BiRPCv1ActivateSessions(clnt, args, reply)
|
||||
}
|
||||
|
||||
func (ssv1 *SessionSv1) BiRPCv1DeactivateSessions(clnt *rpc2.Client,
|
||||
args []string, reply *string) error {
|
||||
args *utils.SessionIDsWithArgsDispatcher, reply *string) error {
|
||||
return ssv1.Ss.BiRPCv1DeactivateSessions(clnt, args, reply)
|
||||
}
|
||||
|
||||
@@ -1025,7 +1025,7 @@ func testSSv1ItDeactivateSessions(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
var reply string
|
||||
err := sSv1BiRpc.Call(utils.SessionSv1DeactivateSessions, []string{}, &reply)
|
||||
err := sSv1BiRpc.Call(utils.SessionSv1DeactivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &reply)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
|
||||
@@ -417,3 +417,47 @@ func (dS *DispatcherService) SessionSv1SetPassiveSession(args *sessions.Session,
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaSessionS, routeID,
|
||||
utils.SessionSv1SetPassiveSession, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1ActivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args.Tenant != utils.EmptyString {
|
||||
tnt = args.Tenant
|
||||
}
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if args.ArgDispatcher == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
|
||||
}
|
||||
if err = dS.authorize(utils.SessionSv1ActivateSessions,
|
||||
tnt, args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var routeID *string
|
||||
if args.ArgDispatcher != nil {
|
||||
routeID = args.ArgDispatcher.RouteID
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaSessionS, routeID,
|
||||
utils.SessionSv1ActivateSessions, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1DeactivateSessions(args *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args.Tenant != utils.EmptyString {
|
||||
tnt = args.Tenant
|
||||
}
|
||||
if len(dS.cfg.DispatcherSCfg().AttributeSConns) != 0 {
|
||||
if args.ArgDispatcher == nil {
|
||||
return utils.NewErrMandatoryIeMissing(utils.ArgDispatcherField)
|
||||
}
|
||||
if err = dS.authorize(utils.SessionSv1DeactivateSessions,
|
||||
tnt, args.APIKey, utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
var routeID *string
|
||||
if args.ArgDispatcher != nil {
|
||||
routeID = args.ArgDispatcher.RouteID
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREvent{Tenant: tnt}, utils.MetaSessionS, routeID,
|
||||
utils.SessionSv1DeactivateSessions, args, reply)
|
||||
}
|
||||
|
||||
@@ -314,7 +314,7 @@ func testSessionSRplActivateSlave(t *testing.T) {
|
||||
}
|
||||
// activate sessions on slave
|
||||
var rplActivate string
|
||||
if err := smgRplcSlvRPC.Call(utils.SessionSv1ActivateSessions, []string{}, &rplActivate); err != nil {
|
||||
if err := smgRplcSlvRPC.Call(utils.SessionSv1ActivateSessions, &utils.SessionIDsWithArgsDispatcher{}, &rplActivate); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
|
||||
@@ -3293,18 +3293,18 @@ func (sS *SessionS) BiRPCv1RegisterInternalBiJSONConn(clnt rpcclient.ClientConne
|
||||
// BiRPCv1ActivateSessions is called to activate a list/all sessions
|
||||
// returns utils.ErrPartiallyExecuted in case of errors
|
||||
func (sS *SessionS) BiRPCv1ActivateSessions(clnt rpcclient.ClientConnector,
|
||||
sIDs []string, reply *string) (err error) {
|
||||
if len(sIDs) == 0 {
|
||||
sIDs *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) {
|
||||
if len(sIDs.IDs) == 0 {
|
||||
sS.pSsMux.RLock()
|
||||
i := 0
|
||||
sIDs = make([]string, len(sS.pSessions))
|
||||
sIDs.IDs = make([]string, len(sS.pSessions))
|
||||
for sID := range sS.pSessions {
|
||||
sIDs[i] = sID
|
||||
sIDs.IDs[i] = sID
|
||||
i++
|
||||
}
|
||||
sS.pSsMux.RUnlock()
|
||||
}
|
||||
for _, sID := range sIDs {
|
||||
for _, sID := range sIDs.IDs {
|
||||
if s := sS.transitSState(sID, false); s == nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<%s> no passive session with id: <%s>", utils.SessionS, sID))
|
||||
err = utils.ErrPartiallyExecuted
|
||||
@@ -3319,18 +3319,18 @@ func (sS *SessionS) BiRPCv1ActivateSessions(clnt rpcclient.ClientConnector,
|
||||
// BiRPCv1DeactivateSessions is called to deactivate a list/all active sessios
|
||||
// returns utils.ErrPartiallyExecuted in case of errors
|
||||
func (sS *SessionS) BiRPCv1DeactivateSessions(clnt rpcclient.ClientConnector,
|
||||
sIDs []string, reply *string) (err error) {
|
||||
if len(sIDs) == 0 {
|
||||
sIDs *utils.SessionIDsWithArgsDispatcher, reply *string) (err error) {
|
||||
if len(sIDs.IDs) == 0 {
|
||||
sS.aSsMux.RLock()
|
||||
i := 0
|
||||
sIDs = make([]string, len(sS.aSessions))
|
||||
sIDs.IDs = make([]string, len(sS.aSessions))
|
||||
for sID := range sS.aSessions {
|
||||
sIDs[i] = sID
|
||||
sIDs.IDs[i] = sID
|
||||
i++
|
||||
}
|
||||
sS.aSsMux.RUnlock()
|
||||
}
|
||||
for _, sID := range sIDs {
|
||||
for _, sID := range sIDs.IDs {
|
||||
if s := sS.transitSState(sID, true); s == nil {
|
||||
utils.Logger.Warning(fmt.Sprintf("<%s> no active session with id: <%s>", utils.SessionS, sID))
|
||||
err = utils.ErrPartiallyExecuted
|
||||
|
||||
@@ -497,7 +497,9 @@ func testSessionSRplActivateSessions(t *testing.T) {
|
||||
var aSessions []*ExternalSession
|
||||
var reply string
|
||||
// Activate first session (with ID: ede927f8e42318a8db02c0f74adc2d9e16770339)
|
||||
args := []string{"ede927f8e42318a8db02c0f74adc2d9e16770339"}
|
||||
args := &utils.SessionIDsWithArgsDispatcher{
|
||||
IDs: []string{"ede927f8e42318a8db02c0f74adc2d9e16770339"},
|
||||
}
|
||||
if err := smgRplcMstrRPC.Call(utils.SessionSv1ActivateSessions, args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
@@ -524,7 +526,9 @@ func testSessionSRplActivateSessions(t *testing.T) {
|
||||
// t.Errorf("Expecting: 1 session, received: %+v sessions", len(aSessions))
|
||||
// }
|
||||
//activate the second session (with ID: 3b0417028f8cefc0e02ddbd37a6dda6fbef4f5e0)
|
||||
args = []string{"3b0417028f8cefc0e02ddbd37a6dda6fbef4f5e0"}
|
||||
args = &utils.SessionIDsWithArgsDispatcher{
|
||||
IDs: []string{"3b0417028f8cefc0e02ddbd37a6dda6fbef4f5e0"},
|
||||
}
|
||||
if err := smgRplcMstrRPC.Call(utils.SessionSv1ActivateSessions, args, &reply); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
@@ -1387,3 +1387,8 @@ type RatingPlanCostArg struct {
|
||||
Usage string
|
||||
*ArgDispatcher
|
||||
}
|
||||
type SessionIDsWithArgsDispatcher struct {
|
||||
IDs []string
|
||||
Tenant string
|
||||
*ArgDispatcher
|
||||
}
|
||||
Reference in New Issue
Block a user