mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-15 21:29:52 +05:00
Added a new API: SessionSv1.DeactivateSession
This commit is contained in:
@@ -125,6 +125,11 @@ func (ssv1 *SessionSv1) ActivateSessions(args []string, 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 {
|
||||
return ssv1.Ss.BiRPCv1DeactivateSessions(nil, args, reply)
|
||||
}
|
||||
|
||||
// Call implements rpcclient.RpcClientConnection interface for internal RPC
|
||||
func (ssv1 *SessionSv1) Call(serviceMethod string,
|
||||
args interface{}, reply interface{}) error {
|
||||
|
||||
@@ -150,3 +150,8 @@ func (ssv1 *SessionSv1) BiRPCv1ActivateSessions(clnt *rpc2.Client,
|
||||
args []string, reply *string) error {
|
||||
return ssv1.Ss.BiRPCv1ActivateSessions(clnt, args, reply)
|
||||
}
|
||||
|
||||
func (ssv1 *SessionSv1) BiRPCv1DeactivateSessions(clnt *rpc2.Client,
|
||||
args []string, reply *string) error {
|
||||
return ssv1.Ss.BiRPCv1DeactivateSessions(clnt, args, reply)
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ var (
|
||||
testSSv1ItCDRsGetCdrs,
|
||||
testSSv1ItForceUpdateSession,
|
||||
testSSv1ItDynamicDebit,
|
||||
testSSv1ItDeactivateSessions,
|
||||
testSSv1ItStopCgrEngine,
|
||||
}
|
||||
)
|
||||
@@ -953,6 +954,65 @@ func testSSv1ItDynamicDebit(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func testSSv1ItDeactivateSessions(t *testing.T) {
|
||||
initUsage := 5 * time.Minute
|
||||
args := &sessions.V1InitSessionArgs{
|
||||
InitSession: true,
|
||||
AllocateResources: true,
|
||||
GetAttributes: true,
|
||||
CGREvent: &utils.CGREvent{
|
||||
Tenant: "cgrates.org",
|
||||
ID: "TestSSv1ItInitiateSession",
|
||||
Event: map[string]interface{}{
|
||||
utils.Tenant: "cgrates.org",
|
||||
utils.ToR: utils.VOICE,
|
||||
utils.OriginID: "TestSSv1It1",
|
||||
utils.RequestType: sSV1RequestType,
|
||||
utils.Account: "1001",
|
||||
utils.Subject: "ANY2CNT",
|
||||
utils.Destination: "1002",
|
||||
utils.SetupTime: time.Date(2018, time.January, 7, 16, 60, 0, 0, time.UTC),
|
||||
utils.AnswerTime: time.Date(2018, time.January, 7, 16, 60, 10, 0, time.UTC),
|
||||
utils.Usage: initUsage,
|
||||
},
|
||||
},
|
||||
}
|
||||
var rply sessions.V1InitSessionReply
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1InitiateSession,
|
||||
args, &rply); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
aSessions := make([]*sessions.ExternalSession, 0)
|
||||
pSessions := make([]*sessions.ExternalSession, 0)
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 2 {
|
||||
t.Errorf("wrong active sessions: %s \n , and len(aSessions) %+v", utils.ToJSON(aSessions), len(aSessions))
|
||||
}
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{}, &pSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(pSessions) != 0 {
|
||||
t.Errorf("Expecting: 0, received: %+v", len(pSessions))
|
||||
}
|
||||
var reply string
|
||||
err := sSv1BiRpc.Call(utils.SessionSv1DeactivateSessions, nil, &reply)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if reply != utils.OK {
|
||||
t.Errorf("Expecting: OK, received : %+v", reply)
|
||||
}
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetActiveSessions, &utils.SessionFilter{}, &aSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(aSessions) != 0 {
|
||||
t.Errorf("Expecting: 0, received: %+v", len(aSessions))
|
||||
}
|
||||
if err := sSv1BiRpc.Call(utils.SessionSv1GetPassiveSessions, &utils.SessionFilter{}, &pSessions); err != nil {
|
||||
t.Error(err)
|
||||
} else if len(pSessions) != 2 {
|
||||
t.Errorf("Expecting: 2, received: %+v", len(pSessions))
|
||||
}
|
||||
}
|
||||
|
||||
func testSSv1ItStopCgrEngine(t *testing.T) {
|
||||
if err := sSv1BiRpc.Close(); err != nil { // Close the connection so we don't get EOF warnings from client
|
||||
t.Error(err)
|
||||
|
||||
@@ -3310,6 +3310,32 @@ func (sS *SessionS) BiRPCv1ActivateSessions(clnt rpcclient.RpcClientConnection,
|
||||
return
|
||||
}
|
||||
|
||||
// BiRPCv1DeactivateSessions is called to deactivate a list/all active sessios
|
||||
// returns utils.ErrPartiallyExecuted in case of errors
|
||||
func (sS *SessionS) BiRPCv1DeactivateSessions(clnt rpcclient.RpcClientConnection,
|
||||
sIDs []string, reply *string) (err error) {
|
||||
if len(sIDs) == 0 {
|
||||
sS.aSsMux.RLock()
|
||||
i := 0
|
||||
sIDs = make([]string, len(sS.aSessions))
|
||||
for sID := range sS.aSessions {
|
||||
sIDs[i] = sID
|
||||
i++
|
||||
}
|
||||
sS.aSsMux.RUnlock()
|
||||
}
|
||||
for _, sID := range sIDs {
|
||||
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
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
*reply = utils.OK
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// processThreshold will receive the event and send it to ThresholdS to be processed
|
||||
func (sS *SessionS) processThreshold(cgrEv *utils.CGREvent, argDisp *utils.ArgDispatcher, thIDs []string) (tIDs []string, err error) {
|
||||
if sS.thdS == nil {
|
||||
|
||||
@@ -1243,6 +1243,7 @@ const (
|
||||
SessionSv1RegisterInternalBiJSONConn = "SessionSv1.RegisterInternalBiJSONConn"
|
||||
SessionSv1ReplicateSessions = "SessionSv1.ReplicateSessions"
|
||||
SessionSv1ActivateSessions = "SessionSv1.ActivateSessions"
|
||||
SessionSv1DeactivateSessions = "SessionSv1.DeactivateSessions"
|
||||
SMGenericV1InitiateSession = "SMGenericV1.InitiateSession"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user