mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
Update AgentV1DisconnectSession api signature
Will accept utils.CGREvent instead of utils.AttrDisconnectSession as a parameter. SessionSv1.ForceDisconnect will take utils.SessionFilterWithEvent as a parameter instead of *utils.SessionFilter. Added possibility to pass DisconnectCause as an Event parameter. The forceSTerminate that's called when the session timer expires will have DisconnectCause 'SESSION_TIMEOUT' instead of 'FORCED_DISCONNECT'. Added Dispatcher methods for AlterSessions. Event will be merged with EventStart of the session before being sent to AgentV1DisconnectSession.
This commit is contained in:
committed by
Dan Christian Bogos
parent
41b9b719d5
commit
ee98dbe0ca
@@ -211,7 +211,7 @@ func (dS *DispatcherService) SessionSv1GetActiveSessionsCount(ctx *context.Conte
|
||||
}, utils.MetaSessionS, utils.SessionSv1GetActiveSessionsCount, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1ForceDisconnect(ctx *context.Context, args *utils.SessionFilter,
|
||||
func (dS *DispatcherService) SessionSv1ForceDisconnect(ctx *context.Context, args utils.SessionFilterWithEvent,
|
||||
reply *string) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
if args.Tenant != utils.EmptyString {
|
||||
@@ -229,6 +229,24 @@ func (dS *DispatcherService) SessionSv1ForceDisconnect(ctx *context.Context, arg
|
||||
}, utils.MetaSessionS, utils.SessionSv1ForceDisconnect, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1AlterSessions(ctx *context.Context, args utils.SessionFilterWithEvent,
|
||||
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 err = dS.authorize(utils.SessionSv1AlterSessions,
|
||||
tnt, utils.IfaceAsString(args.APIOpts[utils.OptsAPIKey]), utils.TimePointer(time.Now())); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return dS.Dispatch(&utils.CGREvent{
|
||||
Tenant: tnt,
|
||||
APIOpts: args.APIOpts,
|
||||
}, utils.MetaSessionS, utils.SessionSv1AlterSessions, args, reply)
|
||||
}
|
||||
|
||||
func (dS *DispatcherService) SessionSv1GetPassiveSessions(ctx *context.Context, args *utils.SessionFilter,
|
||||
reply *[]*sessions.ExternalSession) (err error) {
|
||||
tnt := dS.cfg.GeneralCfg().DefaultTenant
|
||||
|
||||
@@ -472,11 +472,13 @@ func TestDspSessionSv1GetActiveSessionsCountErrorNil(t *testing.T) {
|
||||
func TestDspSessionSv1ForceDisconnectNil(t *testing.T) {
|
||||
cgrCfg := config.NewDefaultCGRConfig()
|
||||
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
|
||||
CGREvent := &utils.SessionFilter{
|
||||
Tenant: "tenant",
|
||||
args := utils.SessionFilterWithEvent{
|
||||
SessionFilter: &utils.SessionFilter{
|
||||
Tenant: "tenant",
|
||||
},
|
||||
}
|
||||
var reply *string
|
||||
result := dspSrv.SessionSv1ForceDisconnect(context.Background(), CGREvent, reply)
|
||||
result := dspSrv.SessionSv1ForceDisconnect(context.Background(), args, reply)
|
||||
expected := "DISPATCHER_ERROR:NO_DATABASE_CONNECTION"
|
||||
if result == nil || result.Error() != expected {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
|
||||
@@ -487,11 +489,13 @@ func TestDspSessionSv1ForceDisconnectErrorNil(t *testing.T) {
|
||||
cgrCfg := config.NewDefaultCGRConfig()
|
||||
dspSrv := NewDispatcherService(nil, cgrCfg, nil, nil)
|
||||
cgrCfg.DispatcherSCfg().AttributeSConns = []string{"test"}
|
||||
CGREvent := &utils.SessionFilter{
|
||||
Tenant: "tenant",
|
||||
args := utils.SessionFilterWithEvent{
|
||||
SessionFilter: &utils.SessionFilter{
|
||||
Tenant: "tenant",
|
||||
},
|
||||
}
|
||||
var reply *string
|
||||
result := dspSrv.SessionSv1ForceDisconnect(context.Background(), CGREvent, reply)
|
||||
result := dspSrv.SessionSv1ForceDisconnect(context.Background(), args, reply)
|
||||
expected := "MANDATORY_IE_MISSING: [ApiKey]"
|
||||
if result == nil || result.Error() != expected {
|
||||
t.Errorf("\nExpected <%+v>, \nReceived <%+v>", expected, result)
|
||||
|
||||
Reference in New Issue
Block a user