diff --git a/apier/v1/chargers_it_test.go b/apier/v1/chargers_it_test.go
index 4dd466dc5..fabf0f006 100755
--- a/apier/v1/chargers_it_test.go
+++ b/apier/v1/chargers_it_test.go
@@ -309,7 +309,7 @@ func testChargerSRemChargerProfile(t *testing.T) {
func testChargerSPing(t *testing.T) {
var resp string
- if err := chargerRPC.Call(utils.ChargerSv1Ping, "", &resp); err != nil {
+ if err := chargerRPC.Call(utils.ChargerSv1Ping, &utils.CGREvent{}, &resp); err != nil {
t.Error(err)
} else if resp != utils.Pong {
t.Error("Unexpected reply returned", resp)
diff --git a/apier/v1/dispatcher.go b/apier/v1/dispatcher.go
index f2b171e06..fd4acadc8 100755
--- a/apier/v1/dispatcher.go
+++ b/apier/v1/dispatcher.go
@@ -21,6 +21,7 @@ package v1
import (
"github.com/cgrates/cgrates/dispatchers"
"github.com/cgrates/cgrates/engine"
+ "github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
@@ -205,57 +206,6 @@ func (dA *DispatcherAttributeSv1) ProcessEvent(args *dispatchers.ArgsAttrProcess
return dA.dA.AttributeSv1ProcessEvent(args, reply)
}
-/*
-func NewDispatcherSessionSv1(dps *dispatchers.DispatcherService) *DispatcherSessionSv1 {
- return &DispatcherSessionSv1{dS: dps}
-}
-
-// Exports RPC from RLs
-type DispatcherSessionSv1 struct {
- dS *dispatchers.DispatcherService
-}
-
-// Ping implements SessionSv1Ping
-func (dS *DispatcherSessionSv1) Ping(ign string, reply *string) error {
- return dS.dS.SessionSv1Ping(ign, reply)
-}
-
-// AuthorizeEventWithDigest implements SessionSv1AuthorizeEventWithDigest
-func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(args *dispatchers.AuthorizeArgsWithApiKey,
- reply *sessions.V1AuthorizeReplyWithDigest) error {
- return dS.dS.SessionSv1AuthorizeEventWithDigest(args, reply)
-}
-
-// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
-func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(args *dispatchers.InitArgsWithApiKey,
- reply *sessions.V1InitSessionReply) (err error) {
- return dS.dS.SessionSv1InitiateSessionWithDigest(args, reply)
-}
-
-// ProcessCDR implements SessionSv1ProcessCDR
-func (dS *DispatcherSessionSv1) ProcessCDR(args *dispatchers.CGREvWithApiKey,
- reply *string) (err error) {
- return dS.dS.SessionSv1ProcessCDR(args, reply)
-}
-
-// ProcessEvent implements SessionSv1ProcessEvent
-func (dS *DispatcherSessionSv1) ProcessEvent(args *dispatchers.ProcessEventWithApiKey,
- reply *sessions.V1ProcessEventReply) (err error) {
- return dS.dS.SessionSv1ProcessEvent(args, reply)
-}
-
-// TerminateSession implements SessionSv1TerminateSession
-func (dS *DispatcherSessionSv1) TerminateSession(args *dispatchers.TerminateSessionWithApiKey,
- reply *string) (err error) {
- return dS.dS.SessionSv1TerminateSession(args, reply)
-}
-
-// UpdateSession implements SessionSv1UpdateSession
-func (dS *DispatcherSessionSv1) UpdateSession(args *dispatchers.UpdateSessionWithApiKey,
- reply *sessions.V1UpdateSessionReply) (err error) {
- return dS.dS.SessionSv1UpdateSession(args, reply)
-}
-*/
func NewDispatcherChargerSv1(dps *dispatchers.DispatcherService) *DispatcherChargerSv1 {
return &DispatcherChargerSv1{dC: dps}
}
@@ -281,3 +231,64 @@ func (dC *DispatcherChargerSv1) ProcessEvent(args *dispatchers.CGREvWithApiKey,
reply *[]*engine.AttrSProcessEventReply) (err error) {
return dC.dC.ChargerSv1ProcessEvent(args, reply)
}
+
+func NewDispatcherSessionSv1(dps *dispatchers.DispatcherService) *DispatcherSessionSv1 {
+ return &DispatcherSessionSv1{dS: dps}
+}
+
+// Exports RPC from RLs
+type DispatcherSessionSv1 struct {
+ dS *dispatchers.DispatcherService
+}
+
+// Ping implements SessionSv1Ping
+func (dS *DispatcherSessionSv1) Ping(args *dispatchers.CGREvWithApiKey, reply *string) error {
+ return dS.dS.SessionSv1Ping(args, reply)
+}
+
+// AuthorizeEventWithDigest implements SessionSv1AuthorizeEventWithDigest
+func (dS *DispatcherSessionSv1) AuthorizeEventWithDigest(args *dispatchers.AuthorizeArgsWithApiKey,
+ reply *sessions.V1AuthorizeReplyWithDigest) error {
+ return dS.dS.SessionSv1AuthorizeEventWithDigest(args, reply)
+}
+
+func (dS *DispatcherSessionSv1) AuthorizeEvent(args *dispatchers.AuthorizeArgsWithApiKey,
+ reply *sessions.V1AuthorizeReply) error {
+ return dS.dS.SessionSv1AuthorizeEvent(args, reply)
+}
+
+// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
+func (dS *DispatcherSessionSv1) InitiateSessionWithDigest(args *dispatchers.InitArgsWithApiKey,
+ reply *sessions.V1InitReplyWithDigest) (err error) {
+ return dS.dS.SessionSv1InitiateSessionWithDigest(args, reply)
+}
+
+// InitiateSessionWithDigest implements SessionSv1InitiateSessionWithDigest
+func (dS *DispatcherSessionSv1) InitiateSession(args *dispatchers.InitArgsWithApiKey,
+ reply *sessions.V1InitSessionReply) (err error) {
+ return dS.dS.SessionSv1InitiateSession(args, reply)
+}
+
+// ProcessCDR implements SessionSv1ProcessCDR
+func (dS *DispatcherSessionSv1) ProcessCDR(args *dispatchers.CGREvWithApiKey,
+ reply *string) (err error) {
+ return dS.dS.SessionSv1ProcessCDR(args, reply)
+}
+
+// ProcessEvent implements SessionSv1ProcessEvent
+func (dS *DispatcherSessionSv1) ProcessEvent(args *dispatchers.ProcessEventWithApiKey,
+ reply *sessions.V1ProcessEventReply) (err error) {
+ return dS.dS.SessionSv1ProcessEvent(args, reply)
+}
+
+// TerminateSession implements SessionSv1TerminateSession
+func (dS *DispatcherSessionSv1) TerminateSession(args *dispatchers.TerminateSessionWithApiKey,
+ reply *string) (err error) {
+ return dS.dS.SessionSv1TerminateSession(args, reply)
+}
+
+// UpdateSession implements SessionSv1UpdateSession
+func (dS *DispatcherSessionSv1) UpdateSession(args *dispatchers.UpdateSessionWithApiKey,
+ reply *sessions.V1UpdateSessionReply) (err error) {
+ return dS.dS.SessionSv1UpdateSession(args, reply)
+}
diff --git a/apier/v1/sessions.go b/apier/v1/sessions.go
index f261016bc..908c2ab85 100644
--- a/apier/v1/sessions.go
+++ b/apier/v1/sessions.go
@@ -173,11 +173,11 @@ func (ssv1 *SessionSv1) BiRPCv1RegisterInternalBiJSONConn(clnt *rpc2.Client, arg
return ssv1.SMG.BiRPCv1RegisterInternalBiJSONConn(clnt, args, rply)
}
-func (ssv1 *SessionSv1) BiRPCPing(clnt *rpc2.Client, ign string, reply *string) error {
+func (ssv1 *SessionSv1) BiRPCPing(clnt *rpc2.Client, ign *utils.CGREvent, reply *string) error {
return ssv1.Ping(ign, reply)
}
-func (ssv1 *SessionSv1) Ping(ign string, reply *string) error {
+func (ssv1 *SessionSv1) Ping(ign *utils.CGREvent, reply *string) error {
*reply = utils.Pong
return nil
}
diff --git a/apier/v1/sessionsv1_it_test.go b/apier/v1/sessionsv1_it_test.go
index 25e9ea7b2..855c25eb7 100644
--- a/apier/v1/sessionsv1_it_test.go
+++ b/apier/v1/sessionsv1_it_test.go
@@ -107,7 +107,7 @@ func TestSSv1ItRpcConn(t *testing.T) {
func TestSSv1ItPing(t *testing.T) {
var resp string
- if err := sSv1BiRpc.Call(utils.SessionSv1Ping, "", &resp); err != nil {
+ if err := sSv1BiRpc.Call(utils.SessionSv1Ping, &utils.CGREvent{}, &resp); err != nil {
t.Error(err)
} else if resp != utils.Pong {
t.Error("Unexpected reply returned", resp)
diff --git a/cmd/cgr-engine/cgr-engine.go b/cmd/cgr-engine/cgr-engine.go
index b3c5aa1ef..50fce1468 100644
--- a/cmd/cgr-engine/cgr-engine.go
+++ b/cmd/cgr-engine/cgr-engine.go
@@ -1038,12 +1038,10 @@ func startDispatcherService(internalDispatcherSChan chan *dispatchers.Dispatcher
server.RpcRegisterName(utils.AttributeSv1,
v1.NewDispatcherAttributeSv1(dspS))
- /*
- if !cfg.SessionSCfg().Enabled && len(cfg.DispatcherSCfg().SessionSConns) != 0 {
- server.RpcRegisterName(utils.SessionSv1,
- v1.NewDispatcherSessionSv1(dspS))
- }
- */
+
+ server.RpcRegisterName(utils.SessionSv1,
+ v1.NewDispatcherSessionSv1(dspS))
+
server.RpcRegisterName(utils.ChargerSv1,
v1.NewDispatcherChargerSv1(dspS))
diff --git a/data/conf/samples/dispatchers/all/cgrates.json b/data/conf/samples/dispatchers/all/cgrates.json
index bf8205496..3f9391658 100644
--- a/data/conf/samples/dispatchers/all/cgrates.json
+++ b/data/conf/samples/dispatchers/all/cgrates.json
@@ -22,7 +22,7 @@
},
"stor_db": {
- "db_type":"*internal",
+ "db_password": "CGRateS.org",
},
"attributes": {
@@ -56,4 +56,28 @@
"enabled": true,
},
+"cdrs": {
+ "enabled": true,
+ "chargers_conns":[
+ {"address": "*internal"},
+ ],
+},
+
+"sessions": {
+ "enabled": true,
+ "listen_bijson": ":6014",
+ "suppliers_conns": [
+ {"address": "*internal"}
+ ],
+ "resources_conns": [
+ {"address": "*internal"}
+ ],
+ "attributes_conns": [
+ {"address": "*internal"}
+ ],
+ "rals_conns": [
+ {"address": "*internal"}
+ ],
+},
+
}
diff --git a/data/conf/samples/dispatchers/all2/cgrates.json b/data/conf/samples/dispatchers/all2/cgrates.json
index 9897e6c31..19c9f9838 100644
--- a/data/conf/samples/dispatchers/all2/cgrates.json
+++ b/data/conf/samples/dispatchers/all2/cgrates.json
@@ -56,4 +56,28 @@
"enabled": true,
},
+"cdrs": {
+ "enabled": true,
+ "chargers_conns":[
+ {"address": "*internal"},
+ ],
+},
+
+"sessions": {
+ "enabled": true,
+ "listen_bijson": ":7014",
+ "suppliers_conns": [
+ {"address": "*internal"}
+ ],
+ "resources_conns": [
+ {"address": "*internal"}
+ ],
+ "attributes_conns": [
+ {"address": "*internal"}
+ ],
+ "rals_conns": [
+ {"address": "*internal"}
+ ],
+},
+
}
diff --git a/data/tariffplans/dispatchers/Attributes.csv b/data/tariffplans/dispatchers/Attributes.csv
index d74d58242..6683e3f89 100644
--- a/data/tariffplans/dispatchers/Attributes.csv
+++ b/data/tariffplans/dispatchers/Attributes.csv
@@ -7,4 +7,5 @@ cgrates.org,ATTR_API_THR_AUTH,*auth,*string:APIKey:thr12345,,APIMethods,*any,Thr
cgrates.org,ATTR_API_SUP_AUTH,*auth,*string:APIKey:sup12345,,APIMethods,*any,SupplierSv1.Ping&SupplierSv1.GetSuppliers,true,false,20
cgrates.org,ATTR_API_STAT_AUTH,*auth,*string:APIKey:stat12345,,APIMethods,*any,StatSv1.Ping&StatSv1.GetStatQueuesForEvent&StatSv1.GetQueueStringMetrics&StatSv1.ProcessEvent,true,false,20
cgrates.org,ATTR_API_RES_AUTH,*auth,*string:APIKey:res12345,,APIMethods,*any,ResourceSv1.Ping&ResourceSv1.GetResourcesForEvent,true,false,20
+cgrates.org,ATTR_API_SES_AUTH,*auth,*string:APIKey:ses12345,,APIMethods,*any,SessionSv1.Ping&SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent,true,false,20
diff --git a/dispatchers/attributes_it_test.go b/dispatchers/attributes_it_test.go
index 4b76164da..2ec082b3c 100755
--- a/dispatchers/attributes_it_test.go
+++ b/dispatchers/attributes_it_test.go
@@ -125,6 +125,7 @@ func (d *testDispatcher) loadData(t *testing.T, path string) {
//Test start here
func TestDspAttributeS(t *testing.T) {
+ engine.KillEngine(0)
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
@@ -140,6 +141,7 @@ func TestDspAttributeS(t *testing.T) {
dispEngine.stopEngine(t)
allEngine.stopEngine(t)
allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspAttrPingFailover(t *testing.T) {
@@ -156,38 +158,29 @@ func testDspAttrPingFailover(t *testing.T) {
t.Errorf("Received: %s", reply)
}
reply = ""
- if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &CGREvWithApiKey{
+ ev := CGREvWithApiKey{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "attr12345",
- }, &reply); err != nil {
+ DispatcherResource: DispatcherResource{
+ APIKey: "attr12345",
+ },
+ }
+ if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
allEngine.stopEngine(t)
reply = ""
- if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &CGREvWithApiKey{
- CGREvent: utils.CGREvent{
- ID: "PING",
- Tenant: "cgrates.org",
- },
- APIKey: "attr12345",
- }, &reply); err != nil {
+ if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &ev, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
allEngine2.stopEngine(t)
reply = ""
- if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &CGREvWithApiKey{
- CGREvent: utils.CGREvent{
- ID: "PING",
- Tenant: "cgrates.org",
- },
- APIKey: "attr12345",
- }, &reply); err == nil {
+ if err := dispEngine.RCP.Call(utils.AttributeSv1Ping, &ev, &reply); err == nil {
t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
}
allEngine.startEngine(t)
@@ -196,7 +189,9 @@ func testDspAttrPingFailover(t *testing.T) {
func testDspAttrGetAttrFailover(t *testing.T) {
args := &CGREvWithApiKey{
- APIKey: "attr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "attr12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
@@ -292,7 +287,9 @@ func testDspAttrPing(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "attr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "attr12345",
+ },
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
@@ -320,7 +317,9 @@ func testDspAttrTestMissingApiKey(t *testing.T) {
func testDspAttrTestUnknownApiKey(t *testing.T) {
args := &CGREvWithApiKey{
- APIKey: "1234",
+ DispatcherResource: DispatcherResource{
+ APIKey: "1234",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
@@ -339,7 +338,9 @@ func testDspAttrTestUnknownApiKey(t *testing.T) {
func testDspAttrTestAuthKey(t *testing.T) {
args := &CGREvWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
@@ -358,7 +359,9 @@ func testDspAttrTestAuthKey(t *testing.T) {
func testDspAttrTestAuthKey2(t *testing.T) {
args := &CGREvWithApiKey{
- APIKey: "attr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "attr12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
@@ -422,7 +425,9 @@ func testDspAttrTestAuthKey2(t *testing.T) {
func testDspAttrTestAuthKey3(t *testing.T) {
args := &CGREvWithApiKey{
- APIKey: "attr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "attr12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "testAttributeSGetAttributeForEvent",
diff --git a/dispatchers/chargers_it_test.go b/dispatchers/chargers_it_test.go
index fbcf20442..e231aef3f 100755
--- a/dispatchers/chargers_it_test.go
+++ b/dispatchers/chargers_it_test.go
@@ -41,6 +41,7 @@ var sTestsDspCpp = []func(t *testing.T){
//Test start here
func TestDspChargerS(t *testing.T) {
+ engine.KillEngine(0)
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
@@ -56,6 +57,7 @@ func TestDspChargerS(t *testing.T) {
dispEngine.stopEngine(t)
allEngine.stopEngine(t)
allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspCppPingFailover(t *testing.T) {
@@ -69,7 +71,9 @@ func testDspCppPingFailover(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "chrg12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "chrg12345",
+ },
}
if err := dispEngine.RCP.Call(utils.ChargerSv1Ping, &ev, &reply); err != nil {
t.Error(err)
@@ -92,7 +96,9 @@ func testDspCppPingFailover(t *testing.T) {
func testDspCppGetChtgFailover(t *testing.T) {
args := CGREvWithApiKey{
- APIKey: "chrg12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "chrg12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
@@ -141,7 +147,9 @@ func testDspCppPing(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "chrg12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "chrg12345",
+ },
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
@@ -151,7 +159,9 @@ func testDspCppPing(t *testing.T) {
func testDspCppTestAuthKey(t *testing.T) {
args := CGREvWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
@@ -169,7 +179,9 @@ func testDspCppTestAuthKey(t *testing.T) {
func testDspCppTestAuthKey2(t *testing.T) {
args := CGREvWithApiKey{
- APIKey: "chrg12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "chrg12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "event1",
diff --git a/dispatchers/resources_it_test.go b/dispatchers/resources_it_test.go
index 774751354..16c3fe651 100755
--- a/dispatchers/resources_it_test.go
+++ b/dispatchers/resources_it_test.go
@@ -40,6 +40,7 @@ var sTestsDspRes = []func(t *testing.T){
//Test start here
func TestDspResourceS(t *testing.T) {
+ engine.KillEngine(0)
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
@@ -55,6 +56,7 @@ func TestDspResourceS(t *testing.T) {
dispEngine.stopEngine(t)
allEngine.stopEngine(t)
allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspResPingFailover(t *testing.T) {
@@ -68,7 +70,9 @@ func testDspResPingFailover(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "res12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "res12345",
+ },
}
if err := dispEngine.RCP.Call(utils.ResourceSv1Ping, &ev, &reply); err != nil {
t.Error(err)
@@ -100,7 +104,9 @@ func testDspResPing(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "res12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "res12345",
+ },
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
@@ -111,7 +117,9 @@ func testDspResPing(t *testing.T) {
func testDspResTestAuthKey(t *testing.T) {
var rs *engine.Resources
args := &ArgsV1ResUsageWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -133,7 +141,9 @@ func testDspResTestAuthKey(t *testing.T) {
func testDspResTestAuthKey2(t *testing.T) {
var rs *engine.Resources
args := &ArgsV1ResUsageWithApiKey{
- APIKey: "res12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "res12345",
+ },
ArgRSv1ResourceUsage: utils.ArgRSv1ResourceUsage{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
diff --git a/dispatchers/sessions.go b/dispatchers/sessions.go
index d53d519c7..811ede1fe 100755
--- a/dispatchers/sessions.go
+++ b/dispatchers/sessions.go
@@ -18,88 +18,138 @@ along with this program. If not, see
package dispatchers
-/*
import (
+ "time"
+
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
-func (dS *DispatcherService) SessionSv1Ping(ign string, rpl *string) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
+func (dS *DispatcherService) SessionSv1Ping(args *CGREvWithApiKey, reply *string) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1Ping,
+ args.CGREvent.Tenant,
+ args.APIKey, args.CGREvent.Time); err != nil {
+ return
+ }
}
- return dS.sessionS.Call(utils.SessionSv1Ping, ign, rpl)
+ return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1Ping, args.CGREvent, reply)
+}
+
+func (dS *DispatcherService) SessionSv1AuthorizeEvent(args *AuthorizeArgsWithApiKey,
+ reply *sessions.V1AuthorizeReply) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1AuthorizeEvent,
+ args.V1AuthorizeArgs.CGREvent.Tenant,
+ args.APIKey, args.V1AuthorizeArgs.CGREvent.Time); err != nil {
+ return
+ }
+ }
+ return dS.Dispatch(&args.V1AuthorizeArgs.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1AuthorizeEvent, args.V1AuthorizeArgs, reply)
}
func (dS *DispatcherService) SessionSv1AuthorizeEventWithDigest(args *AuthorizeArgsWithApiKey,
reply *sessions.V1AuthorizeReplyWithDigest) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1AuthorizeEventWithDigest,
+ args.V1AuthorizeArgs.CGREvent.Tenant,
+ args.APIKey, args.V1AuthorizeArgs.CGREvent.Time); err != nil {
+ return
+ }
}
- if err = dS.authorize(utils.SessionSv1AuthorizeEventWithDigest, args.V1AuthorizeArgs.CGREvent.Tenant,
- args.APIKey, args.V1AuthorizeArgs.CGREvent.Time); err != nil {
- return
+ return dS.Dispatch(&args.V1AuthorizeArgs.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1AuthorizeEventWithDigest, args.V1AuthorizeArgs, reply)
+}
+
+func (dS *DispatcherService) SessionSv1InitiateSession(args *InitArgsWithApiKey,
+ reply *sessions.V1InitSessionReply) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1InitiateSession,
+ args.V1InitSessionArgs.CGREvent.Tenant,
+ args.APIKey, args.V1InitSessionArgs.CGREvent.Time); err != nil {
+ return
+ }
}
- return dS.sessionS.Call(utils.SessionSv1AuthorizeEventWithDigest, args.V1AuthorizeArgs, reply)
+ return dS.Dispatch(&args.V1InitSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1InitiateSession, args.V1InitSessionArgs, reply)
}
func (dS *DispatcherService) SessionSv1InitiateSessionWithDigest(args *InitArgsWithApiKey,
- reply *sessions.V1InitSessionReply) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
+ reply *sessions.V1InitReplyWithDigest) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1InitiateSessionWithDigest,
+ args.V1InitSessionArgs.CGREvent.Tenant,
+ args.APIKey, args.V1InitSessionArgs.CGREvent.Time); err != nil {
+ return
+ }
}
- if err = dS.authorize(utils.SessionSv1InitiateSessionWithDigest, args.V1InitSessionArgs.CGREvent.Tenant,
- args.APIKey, args.V1InitSessionArgs.CGREvent.Time); err != nil {
- return
- }
- return dS.sessionS.Call(utils.SessionSv1InitiateSessionWithDigest, args.V1InitSessionArgs, reply)
-}
-
-func (dS *DispatcherService) SessionSv1ProcessCDR(args *CGREvWithApiKey,
- reply *string) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
- }
- if err = dS.authorize(utils.SessionSv1ProcessCDR, args.CGREvent.Tenant,
- args.APIKey, args.CGREvent.Time); err != nil {
- return
- }
- return dS.sessionS.Call(utils.SessionSv1ProcessCDR, args.CGREvent, reply)
-}
-
-func (dS *DispatcherService) SessionSv1ProcessEvent(args *ProcessEventWithApiKey,
- reply *sessions.V1ProcessEventReply) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
- }
- if err = dS.authorize(utils.SessionSv1ProcessEvent, args.V1ProcessEventArgs.CGREvent.Tenant,
- args.APIKey, args.V1ProcessEventArgs.CGREvent.Time); err != nil {
- return
- }
- return dS.sessionS.Call(utils.SessionSv1ProcessEvent, args.V1ProcessEventArgs, reply)
-}
-
-func (dS *DispatcherService) SessionSv1TerminateSession(args *TerminateSessionWithApiKey,
- reply *string) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
- }
- if err = dS.authorize(utils.SessionSv1TerminateSession, args.V1TerminateSessionArgs.CGREvent.Tenant,
- args.APIKey, args.V1TerminateSessionArgs.CGREvent.Time); err != nil {
- return
- }
- return dS.sessionS.Call(utils.SessionSv1TerminateSession, args.V1TerminateSessionArgs, reply)
+ return dS.Dispatch(&args.V1InitSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1InitiateSessionWithDigest, args.V1InitSessionArgs, reply)
}
func (dS *DispatcherService) SessionSv1UpdateSession(args *UpdateSessionWithApiKey,
reply *sessions.V1UpdateSessionReply) (err error) {
- if dS.sessionS == nil {
- return utils.NewErrNotConnected(utils.SessionS)
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1UpdateSession,
+ args.V1UpdateSessionArgs.CGREvent.Tenant,
+ args.APIKey, args.V1UpdateSessionArgs.CGREvent.Time); err != nil {
+ return
+ }
}
- if err = dS.authorize(utils.SessionSv1UpdateSession, args.V1UpdateSessionArgs.CGREvent.Tenant,
- args.APIKey, args.V1UpdateSessionArgs.CGREvent.Time); err != nil {
- return
- }
- return dS.sessionS.Call(utils.SessionSv1UpdateSession, args.V1UpdateSessionArgs, reply)
+ return dS.Dispatch(&args.V1UpdateSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1UpdateSession, args.V1UpdateSessionArgs, reply)
+}
+
+func (dS *DispatcherService) SessionSv1SyncSessions(args *TntWithApiKey,
+ reply *sessions.V1UpdateSessionReply) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1SyncSessions,
+ args.TenantArg.Tenant,
+ args.APIKey, utils.TimePointer(time.Now())); err != nil {
+ return
+ }
+ }
+ return dS.Dispatch(&utils.CGREvent{Tenant: args.TenantArg.Tenant}, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1SyncSessions, &args.TenantArg.Tenant, reply)
+}
+
+func (dS *DispatcherService) SessionSv1TerminateSession(args *TerminateSessionWithApiKey,
+ reply *string) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1TerminateSession,
+ args.V1TerminateSessionArgs.CGREvent.Tenant,
+ args.APIKey, args.V1TerminateSessionArgs.CGREvent.Time); err != nil {
+ return
+ }
+ }
+ return dS.Dispatch(&args.V1TerminateSessionArgs.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1TerminateSession, args.V1TerminateSessionArgs, reply)
+}
+
+func (dS *DispatcherService) SessionSv1ProcessCDR(args *CGREvWithApiKey,
+ reply *string) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1ProcessCDR,
+ args.CGREvent.Tenant,
+ args.APIKey, args.CGREvent.Time); err != nil {
+ return
+ }
+ }
+ return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1ProcessCDR, args.CGREvent, reply)
+}
+
+func (dS *DispatcherService) SessionSv1ProcessEvent(args *ProcessEventWithApiKey,
+ reply *sessions.V1ProcessEventReply) (err error) {
+ if dS.attrS != nil {
+ if err = dS.authorize(utils.SessionSv1ProcessEvent,
+ args.V1ProcessEventArgs.CGREvent.Tenant,
+ args.APIKey, args.V1ProcessEventArgs.CGREvent.Time); err != nil {
+ return
+ }
+ }
+ return dS.Dispatch(&args.CGREvent, utils.MetaSessionS, args.RouteID,
+ utils.SessionSv1ProcessEvent, args.V1ProcessEventArgs, reply)
}
-*/
diff --git a/dispatchers/sessions_it_test.go b/dispatchers/sessions_it_test.go
index 0b484a772..c8bb182fc 100755
--- a/dispatchers/sessions_it_test.go
+++ b/dispatchers/sessions_it_test.go
@@ -21,175 +21,113 @@ along with this program. If not, see
package dispatchers
import (
- "net/rpc"
- "net/rpc/jsonrpc"
"path"
"reflect"
+ "sort"
+ "strings"
"testing"
"time"
- "github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/engine"
"github.com/cgrates/cgrates/sessions"
"github.com/cgrates/cgrates/utils"
)
-var (
- dspSessionCfgPath string
- dspSessionCfg *config.CGRConfig
- dspSessionRPC *rpc.Client
- instSessionCfgPath string
- instSessionCfg *config.CGRConfig
- instSessionRPC *rpc.Client
-)
-
var sTestsDspSession = []func(t *testing.T){
- // testDspSessionInitCfg,
- // testDspSessionInitDataDb,
- // testDspSessionResetStorDb,
- // testDspSessionStartEngine,
- // testDspSessionRPCConn,
- // testDspSessionPing,
- // testDspSessionLoadData,
- // testDspSessionAddAttributesWithPermision,
- // testDspSessionTestAuthKey,
- // testDspSessionAddAttributesWithPermision2,
- // testDspSessionAuthorize,
- // testDspSessionInit,
- // testDspSessionUpdate,
- // testDspSessionTerminate,
- // testDspSessionProcessCDR,
- // testDspSessionKillEngine,
+ testDspSessionPingFailover,
+
+ testDspSessionPing,
+ testDspSessionTestAuthKey,
+ testDspSessionAuthorize,
+ testDspSessionInit,
+ testDspSessionUpdate,
+ testDspSessionTerminate,
+ testDspSessionProcessCDR,
+ testDspSessionProcessEvent,
}
//Test start here
func TestDspSessionS(t *testing.T) {
+ engine.KillEngine(0)
+ allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
+ allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
+ attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
+ dispEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "dispatchers"), true, true)
+ allEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "testit"))
+ allEngine2.loadData(t, path.Join(dspDataDir, "tariffplans", "oldtutorial"))
+ attrEngine.loadData(t, path.Join(dspDataDir, "tariffplans", "dispatchers"))
+ time.Sleep(500 * time.Millisecond)
for _, stest := range sTestsDspSession {
t.Run("", stest)
}
-}
-
-func testDspSessionInitCfg(t *testing.T) {
- var err error
- dspSessionCfgPath = path.Join(dspDataDir, "conf", "samples", "dispatcher")
- dspSessionCfg, err = config.NewCGRConfigFromFolder(dspSessionCfgPath)
- if err != nil {
- t.Error(err)
- }
- dspSessionCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
- config.SetCgrConfig(dspSessionCfg)
- instSessionCfgPath = path.Join(dspDataDir, "conf", "samples", "sessions")
- instSessionCfg, err = config.NewCGRConfigFromFolder(instSessionCfgPath)
- if err != nil {
- t.Error(err)
- }
- instSessionCfg.DataFolderPath = dspDataDir // Share DataFolderPath through config towards StoreDb for Flush()
- config.SetCgrConfig(instSessionCfg)
-}
-
-func testDspSessionInitDataDb(t *testing.T) {
- if err := engine.InitDataDb(instSessionCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Wipe out the cdr database
-func testDspSessionResetStorDb(t *testing.T) {
- if err := engine.InitStorDb(instSessionCfg); err != nil {
- t.Fatal(err)
- }
-}
-
-// Start CGR Engine
-func testDspSessionStartEngine(t *testing.T) {
- if _, err := engine.StartEngine(instSessionCfgPath, dspDelay); err != nil {
- t.Fatal(err)
- }
- if _, err := engine.StartEngine(dspSessionCfgPath, dspDelay); err != nil {
- t.Fatal(err)
- }
-}
-
-// Connect rpc client to rater
-func testDspSessionRPCConn(t *testing.T) {
- var err error
-
- instSessionRPC, err = jsonrpc.Dial("tcp", instSessionCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
- dspSessionRPC, err = jsonrpc.Dial("tcp", dspSessionCfg.ListenCfg().RPCJSONListen) // We connect over JSON so we can also troubleshoot if needed
- if err != nil {
- t.Fatal(err)
- }
-
+ attrEngine.stopEngine(t)
+ dispEngine.stopEngine(t)
+ allEngine.stopEngine(t)
+ allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspSessionPing(t *testing.T) {
var reply string
- if err := instSessionRPC.Call(utils.SessionSv1Ping, "", &reply); err != nil {
+ if err := allEngine.RCP.Call(utils.SessionSv1Ping, &utils.CGREvent{}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
- if err := dspSessionRPC.Call(utils.SessionSv1Ping, "", &reply); err != nil {
+ if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &CGREvWithApiKey{
+ CGREvent: utils.CGREvent{
+ Tenant: "cgrates.org",
+ },
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
+ }, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
t.Errorf("Received: %s", reply)
}
}
-func testDspSessionLoadData(t *testing.T) {
+func testDspSessionPingFailover(t *testing.T) {
var reply string
- attrs := &utils.AttrLoadTpFromFolder{
- FolderPath: path.Join(dspDataDir, "tariffplans", "testit")}
- if err := instSessionRPC.Call("ApierV1.LoadTariffPlanFromFolder", attrs, &reply); err != nil {
+ if err := allEngine.RCP.Call(utils.SessionSv1Ping, &utils.CGREvent{}, &reply); err != nil {
t.Error(err)
+ } else if reply != utils.Pong {
+ t.Errorf("Received: %s", reply)
}
- time.Sleep(500 * time.Millisecond)
-}
-
-func testDspSessionAddAttributesWithPermision(t *testing.T) {
- alsPrf := &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "AuthKey",
- Contexts: []string{utils.MetaAuth},
- FilterIDs: []string{"*string:APIKey:12345"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
+ ev := CGREvWithApiKey{
+ CGREvent: utils.CGREvent{
+ Tenant: "cgrates.org",
},
- Attributes: []*engine.Attribute{
- {
- FieldName: utils.APIMethods,
- Initial: utils.META_ANY,
- Substitute: config.NewRSRParsersMustCompile("ThresholdSv1.GetThSessionholdsForEvent", true, utils.INFIELD_SEP),
- Append: true,
- },
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
},
- Weight: 20,
}
- var result string
- if err := instSessionRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
+ if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &ev, &reply); err != nil {
t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
+ } else if reply != utils.Pong {
+ t.Errorf("Received: %s", reply)
}
- alsPrf.Compile()
- var reply *engine.AttributeProfile
- if err := instSessionRPC.Call("ApierV1.GetAttributeProfile",
- &utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
+ allEngine.stopEngine(t)
+ if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &ev, &reply); err != nil {
t.Error(err)
+ } else if reply != utils.Pong {
+ t.Errorf("Received: %s", reply)
}
- reply.Compile()
- if !reflect.DeepEqual(alsPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
+ allEngine2.stopEngine(t)
+ if err := dispEngine.RCP.Call(utils.SessionSv1Ping, &ev, &reply); err == nil {
+ t.Errorf("Expected error but recived %v and reply %v\n", err, reply)
}
+ allEngine.startEngine(t)
+ allEngine2.startEngine(t)
}
func testDspSessionTestAuthKey(t *testing.T) {
authUsage := 5 * time.Minute
args := AuthorizeArgsWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
V1AuthorizeArgs: sessions.V1AuthorizeArgs{
GetMaxUsage: true,
AuthorizeResources: true,
@@ -213,53 +151,18 @@ func testDspSessionTestAuthKey(t *testing.T) {
},
}
var rply sessions.V1AuthorizeReplyWithDigest
- if err := dspSessionRPC.Call(utils.SessionSv1AuthorizeEventWithDigest,
+ if err := dispEngine.RCP.Call(utils.SessionSv1AuthorizeEventWithDigest,
args, &rply); err == nil || err.Error() != utils.ErrUnauthorizedApi.Error() {
t.Error(err)
}
}
-func testDspSessionAddAttributesWithPermision2(t *testing.T) {
- alsPrf := &engine.AttributeProfile{
- Tenant: "cgrates.org",
- ID: "AuthKey",
- Contexts: []string{utils.MetaAuth},
- FilterIDs: []string{"*string:APIKey:12345"},
- ActivationInterval: &utils.ActivationInterval{
- ActivationTime: time.Date(2014, 7, 14, 14, 35, 0, 0, time.UTC),
- },
- Attributes: []*engine.Attribute{
- {
- FieldName: utils.APIMethods,
- Initial: utils.META_ANY,
- Substitute: config.NewRSRParsersMustCompile("SessionSv1.AuthorizeEventWithDigest&SessionSv1.InitiateSessionWithDigest&SessionSv1.UpdateSession&SessionSv1.TerminateSession&SessionSv1.ProcessCDR&SessionSv1.ProcessEvent", true, utils.INFIELD_SEP),
- Append: true,
- },
- },
- Weight: 20,
- }
- var result string
- if err := instSessionRPC.Call("ApierV1.SetAttributeProfile", alsPrf, &result); err != nil {
- t.Error(err)
- } else if result != utils.OK {
- t.Error("Unexpected reply returned", result)
- }
- alsPrf.Compile()
- var reply *engine.AttributeProfile
- if err := instSessionRPC.Call("ApierV1.GetAttributeProfile",
- &utils.TenantID{Tenant: "cgrates.org", ID: "AuthKey"}, &reply); err != nil {
- t.Error(err)
- }
- reply.Compile()
- if !reflect.DeepEqual(alsPrf, reply) {
- t.Errorf("Expecting : %+v, received: %+v", alsPrf, reply)
- }
-}
-
func testDspSessionAuthorize(t *testing.T) {
authUsage := 5 * time.Minute
argsAuth := &AuthorizeArgsWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
V1AuthorizeArgs: sessions.V1AuthorizeArgs{
GetMaxUsage: true,
AuthorizeResources: true,
@@ -283,30 +186,36 @@ func testDspSessionAuthorize(t *testing.T) {
},
}
var rply sessions.V1AuthorizeReplyWithDigest
- if err := dspSessionRPC.Call(utils.SessionSv1AuthorizeEventWithDigest,
+ if err := dispEngine.RCP.Call(utils.SessionSv1AuthorizeEventWithDigest,
argsAuth, &rply); err != nil {
t.Error(err)
+ return
}
if *rply.MaxUsage != authUsage.Seconds() {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
+ t.Errorf("Unexpected MaxUsage: %v", *rply.MaxUsage)
}
if *rply.ResourceAllocation == "" {
t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
}
- eSplrs := utils.StringPointer("supplier1,supplier2")
- if *eSplrs != *rply.SuppliersDigest {
- t.Errorf("expecting: %v, received: %v", *eSplrs, *rply.SuppliersDigest)
+ eSplrs := "supplier1,supplier2"
+ tp := strings.Split(*rply.SuppliersDigest, ",")
+ sort.Strings(tp)
+ *rply.SuppliersDigest = strings.Join(tp, ",")
+ if eSplrs != *rply.SuppliersDigest {
+ t.Errorf("expecting: %v, received: %v", eSplrs, *rply.SuppliersDigest)
}
- eAttrs := utils.StringPointer("OfficeGroup:Marketing")
- if *eAttrs != *rply.AttributesDigest {
- t.Errorf("expecting: %v, received: %v", *eAttrs, *rply.AttributesDigest)
+ eAttrs := "OfficeGroup:Marketing"
+ if eAttrs != *rply.AttributesDigest {
+ t.Errorf("expecting: %v, received: %v", eAttrs, *rply.AttributesDigest)
}
}
func testDspSessionInit(t *testing.T) {
initUsage := time.Duration(5 * time.Minute)
argsInit := &InitArgsWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
V1InitSessionArgs: sessions.V1InitSessionArgs{
InitSession: true,
AllocateResources: true,
@@ -330,12 +239,12 @@ func testDspSessionInit(t *testing.T) {
},
}
var rply sessions.V1InitReplyWithDigest
- if err := dspSessionRPC.Call(utils.SessionSv1InitiateSessionWithDigest,
+ if err := dispEngine.RCP.Call(utils.SessionSv1InitiateSessionWithDigest,
argsInit, &rply); err != nil {
- t.Error(err)
+ t.Fatal(err)
}
if *rply.MaxUsage != initUsage.Seconds() {
- t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
+ t.Errorf("Unexpected MaxUsage: %v", *rply.MaxUsage)
}
if *rply.ResourceAllocation != "RES_ACNT_1001" {
t.Errorf("Unexpected ResourceAllocation: %s", *rply.ResourceAllocation)
@@ -345,7 +254,9 @@ func testDspSessionInit(t *testing.T) {
func testDspSessionUpdate(t *testing.T) {
reqUsage := 5 * time.Minute
argsUpdate := &UpdateSessionWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
V1UpdateSessionArgs: sessions.V1UpdateSessionArgs{
GetAttributes: true,
UpdateSession: true,
@@ -368,7 +279,7 @@ func testDspSessionUpdate(t *testing.T) {
},
}
var rply sessions.V1UpdateSessionReply
- if err := dspSessionRPC.Call(utils.SessionSv1UpdateSession,
+ if err := dispEngine.RCP.Call(utils.SessionSv1UpdateSession,
argsUpdate, &rply); err != nil {
t.Error(err)
}
@@ -406,7 +317,9 @@ func testDspSessionUpdate(t *testing.T) {
func testDspSessionTerminate(t *testing.T) {
args := &TerminateSessionWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
V1TerminateSessionArgs: sessions.V1TerminateSessionArgs{
TerminateSession: true,
ReleaseResources: true,
@@ -429,7 +342,7 @@ func testDspSessionTerminate(t *testing.T) {
},
}
var rply string
- if err := dspSessionRPC.Call(utils.SessionSv1TerminateSession,
+ if err := dispEngine.RCP.Call(utils.SessionSv1TerminateSession,
args, &rply); err != nil {
t.Error(err)
}
@@ -440,7 +353,9 @@ func testDspSessionTerminate(t *testing.T) {
func testDspSessionProcessCDR(t *testing.T) {
args := CGREvWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
ID: "TestSSv1ItProcessCDR",
@@ -460,9 +375,9 @@ func testDspSessionProcessCDR(t *testing.T) {
}
var rply string
- if err := dspSessionRPC.Call(utils.SessionSv1ProcessCDR,
+ if err := dispEngine.RCP.Call(utils.SessionSv1ProcessCDR,
args, &rply); err != nil {
- t.Error(err)
+ t.Fatal(err)
}
if rply != utils.OK {
t.Errorf("Unexpected reply: %s", rply)
@@ -471,8 +386,24 @@ func testDspSessionProcessCDR(t *testing.T) {
func testDspSessionProcessEvent(t *testing.T) {
initUsage := 5 * time.Minute
+ attrSetBalance := utils.AttrSetBalance{
+ Tenant: "cgrates.org",
+ Account: "1001",
+ BalanceType: utils.VOICE,
+ BalanceID: utils.StringPointer("TestDynamicDebitBalance"),
+ Value: utils.Float64Pointer(float64(initUsage)),
+ RatingSubject: utils.StringPointer("*zero5ms"),
+ }
+ var reply string
+ if err := allEngine.RCP.Call("ApierV2.SetBalance", attrSetBalance, &reply); err != nil {
+ t.Error(err)
+ } else if reply != utils.OK {
+ t.Errorf("Received: %s", reply)
+ }
args := ProcessEventWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "ses12345",
+ },
V1ProcessEventArgs: sessions.V1ProcessEventArgs{
AllocateResources: true,
Debit: true,
@@ -481,6 +412,7 @@ func testDspSessionProcessEvent(t *testing.T) {
Tenant: "cgrates.org",
ID: "TestSSv1ItProcessEvent",
Event: map[string]interface{}{
+ "CGRID": "c87609aa1cb6e9529ab1836cfeeeb0ab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
@@ -496,9 +428,9 @@ func testDspSessionProcessEvent(t *testing.T) {
},
}
var rply sessions.V1ProcessEventReply
- if err := dspSessionRPC.Call(utils.SessionSv1ProcessEvent,
+ if err := dispEngine.RCP.Call(utils.SessionSv1ProcessEvent,
args, &rply); err != nil {
- t.Error(err)
+ t.Fatal(err)
}
if *rply.MaxUsage != initUsage {
t.Errorf("Unexpected MaxUsage: %v", rply.MaxUsage)
@@ -514,6 +446,7 @@ func testDspSessionProcessEvent(t *testing.T) {
ID: "TestSSv1ItProcessEvent",
Context: utils.StringPointer(utils.MetaSessionS),
Event: map[string]interface{}{
+ "CGRID": "c87609aa1cb6e9529ab1836cfeeeb0ab7aa7ebaf",
utils.Tenant: "cgrates.org",
utils.Category: "call",
utils.ToR: utils.VOICE,
@@ -533,12 +466,3 @@ func testDspSessionProcessEvent(t *testing.T) {
utils.ToJSON(eAttrs), utils.ToJSON(rply.Attributes))
}
}
-
-func testDspSessionKillEngine(t *testing.T) {
- if err := engine.KillEngine(dspDelay); err != nil {
- t.Error(err)
- }
- if err := engine.KillEngine(dspDelay); err != nil {
- t.Error(err)
- }
-}
diff --git a/dispatchers/stats_it_test.go b/dispatchers/stats_it_test.go
index d1cd21198..7077f7a09 100755
--- a/dispatchers/stats_it_test.go
+++ b/dispatchers/stats_it_test.go
@@ -41,6 +41,7 @@ var sTestsDspSts = []func(t *testing.T){
//Test start here
func TestDspStatS(t *testing.T) {
+ engine.KillEngine(0)
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
@@ -56,6 +57,7 @@ func TestDspStatS(t *testing.T) {
dispEngine.stopEngine(t)
allEngine.stopEngine(t)
allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspStsPingFailover(t *testing.T) {
@@ -69,7 +71,9 @@ func testDspStsPingFailover(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
}
if err := dispEngine.RCP.Call(utils.StatSv1Ping, &ev, &reply); err != nil {
t.Error(err)
@@ -95,7 +99,9 @@ func testDspStsGetStatFailover(t *testing.T) {
var metrics map[string]string
expected := []string{"Stats1"}
args := ArgsStatProcessEventWithApiKey{
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -118,7 +124,9 @@ func testDspStsGetStatFailover(t *testing.T) {
}
args2 := TntIDWithApiKey{
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
TenantID: utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats1",
@@ -151,7 +159,9 @@ func testDspStsPing(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
@@ -162,7 +172,9 @@ func testDspStsPing(t *testing.T) {
func testDspStsTestAuthKey(t *testing.T) {
var reply []string
args := ArgsStatProcessEventWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -180,7 +192,9 @@ func testDspStsTestAuthKey(t *testing.T) {
}
args2 := TntIDWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
TenantID: utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats2",
@@ -199,7 +213,9 @@ func testDspStsTestAuthKey2(t *testing.T) {
var metrics map[string]string
expected := []string{"Stats2"}
args := ArgsStatProcessEventWithApiKey{
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -221,7 +237,9 @@ func testDspStsTestAuthKey2(t *testing.T) {
}
args2 := TntIDWithApiKey{
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
TenantID: utils.TenantID{
Tenant: "cgrates.org",
ID: "Stats2",
@@ -240,7 +258,9 @@ func testDspStsTestAuthKey2(t *testing.T) {
}
args = ArgsStatProcessEventWithApiKey{
- APIKey: "stat12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "stat12345",
+ },
StatsArgsProcessEvent: engine.StatsArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
diff --git a/dispatchers/suppliers_it_test.go b/dispatchers/suppliers_it_test.go
index 667e25c36..c66fe0efa 100755
--- a/dispatchers/suppliers_it_test.go
+++ b/dispatchers/suppliers_it_test.go
@@ -41,6 +41,7 @@ var sTestsDspSup = []func(t *testing.T){
//Test start here
func TestDspSupplierS(t *testing.T) {
+ engine.KillEngine(0)
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
@@ -56,6 +57,7 @@ func TestDspSupplierS(t *testing.T) {
dispEngine.stopEngine(t)
allEngine.stopEngine(t)
allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspSupPing(t *testing.T) {
@@ -69,7 +71,9 @@ func testDspSupPing(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "sup12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "sup12345",
+ },
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
@@ -88,7 +92,9 @@ func testDspSupPingFailover(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "sup12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "sup12345",
+ },
}
if err := dispEngine.RCP.Call(utils.SupplierSv1Ping, &ev, &reply); err != nil {
t.Error(err)
@@ -149,7 +155,9 @@ func testDspSupGetSupFailover(t *testing.T) {
},
}
args := &ArgsGetSuppliersWithApiKey{
- APIKey: "sup12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "sup12345",
+ },
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -185,7 +193,9 @@ func testDspSupGetSupFailover(t *testing.T) {
func testDspSupTestAuthKey(t *testing.T) {
var rpl *engine.SortedSuppliers
args := &ArgsGetSuppliersWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -234,7 +244,9 @@ func testDspSupTestAuthKey2(t *testing.T) {
},
}
args := &ArgsGetSuppliersWithApiKey{
- APIKey: "sup12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "sup12345",
+ },
ArgsGetSuppliers: engine.ArgsGetSuppliers{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
diff --git a/dispatchers/thresholds_it_test.go b/dispatchers/thresholds_it_test.go
index e298fa844..293da4ee7 100755
--- a/dispatchers/thresholds_it_test.go
+++ b/dispatchers/thresholds_it_test.go
@@ -41,6 +41,7 @@ var sTestsDspTh = []func(t *testing.T){
//Test start here
func TestDspThresholdS(t *testing.T) {
+ engine.KillEngine(0)
allEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all"), true, true)
allEngine2 = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "all2"), true, true)
attrEngine = newTestEngine(t, path.Join(dspDataDir, "conf", "samples", "dispatchers", "attributes"), true, true)
@@ -56,6 +57,7 @@ func TestDspThresholdS(t *testing.T) {
dispEngine.stopEngine(t)
allEngine.stopEngine(t)
allEngine2.stopEngine(t)
+ engine.KillEngine(0)
}
func testDspThPingFailover(t *testing.T) {
@@ -69,7 +71,9 @@ func testDspThPingFailover(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "thr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "thr12345",
+ },
}
if err := dispEngine.RCP.Call(utils.ThresholdSv1Ping, &ev, &reply); err != nil {
t.Error(err)
@@ -95,7 +99,9 @@ func testDspThProcessEventFailover(t *testing.T) {
eIDs := []string{"THD_ACNT_1001"}
nowTime := time.Now()
args := &ArgsProcessEventWithApiKey{
- APIKey: "thr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "thr12345",
+ },
ArgsProcessEvent: engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -132,7 +138,9 @@ func testDspThPing(t *testing.T) {
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
},
- APIKey: "thr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "thr12345",
+ },
}, &reply); err != nil {
t.Error(err)
} else if reply != utils.Pong {
@@ -144,7 +152,9 @@ func testDspThTestAuthKey(t *testing.T) {
var ids []string
nowTime := time.Now()
args := &ArgsProcessEventWithApiKey{
- APIKey: "12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "12345",
+ },
ArgsProcessEvent: engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
@@ -172,7 +182,9 @@ func testDspThTestAuthKey2(t *testing.T) {
eIDs := []string{"THD_ACNT_1002"}
nowTime := time.Now()
args := &ArgsProcessEventWithApiKey{
- APIKey: "thr12345",
+ DispatcherResource: DispatcherResource{
+ APIKey: "thr12345",
+ },
ArgsProcessEvent: engine.ArgsProcessEvent{
CGREvent: utils.CGREvent{
Tenant: "cgrates.org",
diff --git a/migrator/tp_dispatchers_it_test.go b/migrator/tp_dispatchers_it_test.go
index 6525f1936..12ad1323d 100644
--- a/migrator/tp_dispatchers_it_test.go
+++ b/migrator/tp_dispatchers_it_test.go
@@ -143,7 +143,7 @@ func testTpDispITMove(t *testing.T) {
func testTpDispITCheckData(t *testing.T) {
result, err := tpDispMigrator.storDBOut.StorDB().GetTPDispatchers("TP1", "cgrates.org", "Dsp1")
if err != nil {
- t.Error("Error when getting TpDispatchers ", err.Error())
+ t.Fatal("Error when getting TpDispatchers ", err.Error())
}
if !reflect.DeepEqual(tpDisps[0], result[0]) {
t.Errorf("Expecting: %+v, received: %+v",