From 6ab21084ce90849a94116db3043eacbf0ab756f0 Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Sun, 1 Oct 2017 09:55:49 +0300 Subject: [PATCH 01/15] Work in progress for RESTCOMM-1147, RMS resources leak --- .../org/restcomm/connect/telephony/Call.java | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java index 3d2d69b590..59607ac17a 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java @@ -1744,17 +1744,8 @@ public void execute(Object message) throws Exception { } msController.tell(new CloseMediaSession(), source); - if (fail) { - if (logger.isDebugEnabled()) { - logger.debug("At Call Stopping state, moving to Failed state"); - } - fsm.transition(message, failed); - } else { - if (logger.isDebugEnabled()) { - logger.debug("At Call Stopping state, moving to Completed state"); - } - fsm.transition(message, completed); - } + //Don't wait for ever for the CallController response + context().setReceiveTimeout(Duration.create(2000, TimeUnit.SECONDS)); } } @@ -1976,10 +1967,22 @@ private void onReceiveTimeout(ReceiveTimeout message, ActorRef self, ActorRef se observer.tell(infoResponse, self()); } + } else if (is(stopping)) { + if (fail) { + if (logger.isDebugEnabled()) { + logger.debug("At Call Stopping state, moving to Failed state"); + } + fsm.transition(message, failed); + } else { + if (logger.isDebugEnabled()) { + logger.debug("At Call Stopping state, moving to Completed state"); + } + fsm.transition(message, completed); + } } else if(logger.isInfoEnabled()) { - logger.info("Timeout received for Call : "+self().path()+" isTerminated(): "+self().isTerminated()+". Sender: " + sender.path().toString() + " State: " + this.fsm.state() - + " Direction: " + direction + " From: " + from + " To: " + to); - } + logger.info("Timeout received for Call : "+self().path()+" isTerminated(): "+self().isTerminated()+". Sender: " + sender.path().toString() + " State: " + this.fsm.state() + + " Direction: " + direction + " From: " + from + " To: " + to); + } } private void onSipServletRequest(SipServletRequest message, ActorRef self, ActorRef sender) throws Exception { @@ -2508,6 +2511,19 @@ private void onMediaServerControllerStateChanged(MediaServerControllerStateChang String msg = String.format("On MediaServerContollerStateChanged, message: INACTIVE, Call state: %s, Fail: %s", fsm.state(), fail); logger.debug(msg); } + + if (fail) { + if (logger.isDebugEnabled()) { + logger.debug("At Call Stopping state, moving to Failed state"); + } + fsm.transition(message, failed); + } else { + if (logger.isDebugEnabled()) { + logger.debug("At Call Stopping state, moving to Completed state"); + } + fsm.transition(message, completed); + } + // if (fail) { // fsm.transition(message, failed); // } else { @@ -2600,7 +2616,8 @@ private void onLeft(Left message, ActorRef self, ActorRef sender) throws Excepti if (!liveCallModification) { // After leaving let the Interpreter know the Call is ready. - fsm.transition(message, completed); +// fsm.transition(message, completed); + fsm.transition(message, stopping); } else { if (muted) { // Forward to media server controller From 7a988edfab2109bc70d200e81311041bfeed8f5f Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Tue, 3 Oct 2017 13:09:23 +0300 Subject: [PATCH 02/15] Fixes for SmsTest --- .../org/restcomm/connect/sms/SmsSession.java | 2 +- .../connect/testsuite/sms/SmsTest.java | 42 +++++++++---------- .../src/test/resources/log4j.xml_local | 31 ++++++++++++++ 3 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local diff --git a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java index 19d386f5b0..7e74bb1513 100644 --- a/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java +++ b/restcomm/restcomm.sms/src/main/java/org/restcomm/connect/sms/SmsSession.java @@ -300,7 +300,7 @@ private void outbound(final Object message) { // 2, SMPP is activated if (toClient == null && smppActivated) { if(logger.isInfoEnabled()) { - logger.info("Destination is not a local registered client, therefore, sending through SMPP to: " + last.to() ); + logger.info("Destination is not a local registered client, therefore, sending through SMPP to: {} " + last.to() ); } if (sendUsingSmpp(last.from(), last.to(), last.body(), tlvSet, charset)) return; diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsTest.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsTest.java index e13dc2b6a7..578b260afb 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsTest.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/sms/SmsTest.java @@ -158,8 +158,8 @@ public static void beforeClass() throws Exception { tool7 = new SipStackTool("SmsTest7"); tool8 = new SipStackTool("SmsTest8"); } - - public static void reconfigurePorts() { + + public static void reconfigurePorts() { if (System.getProperty("arquillian_sip_port") != null) { restcommPort = Integer.valueOf(System.getProperty("arquillian_sip_port")); restcommContact = "127.0.0.1:" + restcommPort; @@ -478,11 +478,11 @@ public void TestIncomingSmsSendToNumber1313WithCustomHeaders() throws ParseExcep @Test public void testP2PSendSMS_GeorgeClient_ToFotiniClient() throws ParseException { - SipURI uri = georgeSipStack.getAddressFactory().createSipURI(null, restcommContact); + SipURI uri = aliceSipStack.getAddressFactory().createSipURI(null, restcommContact); //Register George phone - assertTrue(georgePhone.register(uri, "george", "1234", georgeContact, 3600, 3600)); - Credential georgeCredentials = new Credential("127.0.0.1", "george", "1234"); - georgePhone.addUpdateCredential(georgeCredentials); + assertTrue(alicePhone.register(uri, "alice", "1234", aliceContact, 3600, 3600)); + Credential aliceCredentials = new Credential("127.0.0.1", "alice", "1234"); + alicePhone.addUpdateCredential(aliceCredentials); //Register Fotini phone assertTrue(fotiniPhone.register(uri, "fotini", "1234", fotiniContact, 3600, 3600)); @@ -494,17 +494,17 @@ public void testP2PSendSMS_GeorgeClient_ToFotiniClient() throws ParseException { fotiniCall.listenForMessage(); //Prepare George to send message - SipCall georgeCall = georgePhone.createSipCall(); - georgeCall.initiateOutgoingMessage(georgeContact, "sip:fotini@" + restcommContact, null, null, null, greekHugeMessage); - assertLastOperationSuccess(georgeCall); - georgeCall.waitForAuthorisation(30 * 1000); - assertTrue(georgeCall.waitOutgoingMessageResponse(3000)); - assertEquals(Response.TRYING, georgeCall.getLastReceivedResponse().getStatusCode()); + SipCall aliceCall = alicePhone.createSipCall(); + aliceCall.initiateOutgoingMessage(aliceContact, "sip:fotini@" + restcommContact, null, null, null, greekHugeMessage); + assertLastOperationSuccess(aliceCall); + aliceCall.waitForAuthorisation(30 * 1000); + assertTrue(aliceCall.waitOutgoingMessageResponse(3000)); + assertEquals(Response.TRYING, aliceCall.getLastReceivedResponse().getStatusCode()); assertTrue(fotiniCall.waitForMessage(30 * 1000)); assertTrue(fotiniCall.sendMessageResponse(200, "OK-Fotini-Mesasge-Receieved", 1800)); - assertTrue(georgeCall.waitOutgoingMessageResponse(3000)); - assertTrue(georgeCall.getLastReceivedResponse().getStatusCode() == Response.OK); + assertTrue(aliceCall.waitOutgoingMessageResponse(3000)); + assertTrue(aliceCall.getLastReceivedResponse().getStatusCode() == Response.OK); List msgsFromGeorge = fotiniCall.getAllReceivedMessagesContent(); assertTrue(msgsFromGeorge.size() > 0); @@ -575,7 +575,7 @@ public void testP2PSendSMS_GeorgeClient_ToFotiniClient_EmptyContent() throws Par public static WebArchive createWebArchiveNoGw() { logger.info("Packaging Test App"); reconfigurePorts(); - + Map webInfResources = new HashMap(); webInfResources.put("restcomm_SmsTest.xml", "conf/restcomm.xml"); webInfResources.put("restcomm.script_SmsTest", "data/hsql/restcomm.script"); @@ -584,7 +584,7 @@ public static WebArchive createWebArchiveNoGw() { webInfResources.put("akka_application.conf", "classes/application.conf"); Map replacements = new HashMap(); - //replace mediaport 2727 + //replace mediaport 2727 replacements.put("2727", String.valueOf(mediaPort)); replacements.put("8080", String.valueOf(restcommHTTPPort)); replacements.put("5080", String.valueOf(restcommPort)); @@ -596,14 +596,14 @@ public static WebArchive createWebArchiveNoGw() { replacements.put("5094", String.valueOf(alicePort2)); replacements.put("5095", String.valueOf(bobPort2)); replacements.put("5096", String.valueOf(georgePort2)); - replacements.put("5097", String.valueOf(fotiniPort2)); - + replacements.put("5097", String.valueOf(fotiniPort2)); + List resources = new ArrayList(Arrays.asList( "send-sms-test.xml", - "send-sms-test-greek.xml", - "send-sms-test-greek_huge.xml", - "send-sms-test2.xml", + "send-sms-test-greek.xml", + "send-sms-test-greek_huge.xml", + "send-sms-test2.xml", "dial-client-entry.xml" )); return WebArchiveUtil.createWebArchiveNoGw(webInfResources, diff --git a/restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local b/restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local new file mode 100644 index 0000000000..40d05b6a28 --- /dev/null +++ b/restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 110a6a2a7d874fd74c8c135a8ba4e03d9ec24e3c Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Tue, 3 Oct 2017 13:50:34 +0300 Subject: [PATCH 03/15] Code cleanup. This refer to RESTCOMM-1147 --- .../src/main/java/org/restcomm/connect/telephony/Call.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java index 59607ac17a..3a5de7df6f 100644 --- a/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java +++ b/restcomm/restcomm.telephony/src/main/java/org/restcomm/connect/telephony/Call.java @@ -1966,7 +1966,6 @@ private void onReceiveTimeout(ReceiveTimeout message, ActorRef self, ActorRef se for (final ActorRef observer : observers) { observer.tell(infoResponse, self()); } - } else if (is(stopping)) { if (fail) { if (logger.isDebugEnabled()) { @@ -2616,7 +2615,6 @@ private void onLeft(Left message, ActorRef self, ActorRef sender) throws Excepti if (!liveCallModification) { // After leaving let the Interpreter know the Call is ready. -// fsm.transition(message, completed); fsm.transition(message, stopping); } else { if (muted) { From 2cb0698d399f9024ae8a815dfa7c3987a0703274 Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Tue, 3 Oct 2017 20:56:43 +0300 Subject: [PATCH 04/15] Work in progress for MgcpMonitoringService This refer to RESTCOMM-1155 --- .../connect/application/Bootstrapper.java | 10 +-- .../connect/http/SupervisorEndpoint.java | 21 +++++- .../connect/mgcp/MockMediaGateway.java | 46 +++++------- .../connect/mgcp/PowerOnMediaGateway.java | 16 +++- .../mgcp/stats/MgcpConnectionAdded.java | 22 ++++++ .../mgcp/stats/MgcpConnectionDeleted.java | 15 ++++ .../connect/mgcp/stats/MgcpEndpointAdded.java | 22 ++++++ .../mgcp/stats/MgcpEndpointDeleted.java | 15 ++++ .../connect/mgcp/stats/MgcpLinkAdded.java | 22 ++++++ .../connect/mgcp/stats/MgcpLinkDeleted.java | 15 ++++ restcomm/restcomm.monitoring.service/pom.xml | 6 ++ .../monitoringservice/MonitoringMetrics.java | 3 + .../monitoringservice/MonitoringService.java | 73 +++++++++++++++++++ .../mrb/api/StartMediaResourceBroker.java | 9 ++- .../mrb/MediaResourceBrokerGeneric.java | 3 + .../connect/telephony/api/GetStatistics.java | 8 +- .../telephony/TestMgcpOperations.java | 59 ++++++++++++--- .../tools/MonitoringServiceTool.java | 7 +- .../src/test/resources/log4j.xml | 57 ++++++++------- .../{log4j.xml_local => log4j.xml.cloud} | 9 +-- .../resources/restcomm.script_mgcpoperations | 33 +++++++++ 21 files changed, 386 insertions(+), 85 deletions(-) create mode 100644 restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionAdded.java create mode 100644 restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionDeleted.java create mode 100644 restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java create mode 100644 restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java create mode 100644 restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java create mode 100644 restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java rename restcomm/restcomm.testsuite/src/test/resources/{log4j.xml_local => log4j.xml.cloud} (76%) create mode 100644 restcomm/restcomm.testsuite/src/test/resources/restcomm.script_mgcpoperations diff --git a/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java b/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java index 9a533dcdb0..f632bb3d8f 100644 --- a/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java +++ b/restcomm/restcomm.application/src/main/java/org/restcomm/connect/application/Bootstrapper.java @@ -79,7 +79,7 @@ public void destroy() { system.awaitTermination(); } - private MediaServerControllerFactory mediaServerControllerFactory(final Configuration configuration, ClassLoader loader, DaoManager storage) + private MediaServerControllerFactory mediaServerControllerFactory(final Configuration configuration, ClassLoader loader, DaoManager storage, ActorRef monitoring) throws ServletException { Configuration settings ; String compatibility = configuration.subset("mscontrol").getString("compatibility", "rms"); @@ -89,7 +89,7 @@ private MediaServerControllerFactory mediaServerControllerFactory(final Configur case "rms": try { settings = configuration.subset("media-server-manager"); - ActorRef mrb = mediaResourceBroker(settings, storage, loader); + ActorRef mrb = mediaResourceBroker(settings, storage, loader, monitoring); factory = new MmsControllerFactory(mrb); } catch (UnknownHostException e) { throw new ServletException(e); @@ -200,7 +200,7 @@ private SipURI outboundInterface(ServletContext context, String transport) { return result; } - private ActorRef mediaResourceBroker(final Configuration configuration, final DaoManager storage, final ClassLoader loader) throws UnknownHostException{ + private ActorRef mediaResourceBroker(final Configuration configuration, final DaoManager storage, final ClassLoader loader, final ActorRef monitoring) throws UnknownHostException{ final Props props = new Props(new UntypedActorFactory() { private static final long serialVersionUID = 1L; @@ -211,7 +211,7 @@ public UntypedActor create() throws Exception { } }); ActorRef mrb = system.actorOf(props); - mrb.tell(new StartMediaResourceBroker(configuration, storage, loader), null); + mrb.tell(new StartMediaResourceBroker(configuration, storage, loader, monitoring), null); return mrb; } @@ -387,7 +387,7 @@ public void servletInitialized(SipServletContextEvent event) { // Create the media server controller factory MediaServerControllerFactory mscontrollerFactory = null; try { - mscontrollerFactory = mediaServerControllerFactory(xml, loader, storage); + mscontrollerFactory = mediaServerControllerFactory(xml, loader, storage, monitoring); } catch (ServletException exception) { logger.error("ServletException during initialization: ", exception); } diff --git a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SupervisorEndpoint.java b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SupervisorEndpoint.java index af32fe768d..080a74504f 100644 --- a/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SupervisorEndpoint.java +++ b/restcomm/restcomm.http/src/main/java/org/restcomm/connect/http/SupervisorEndpoint.java @@ -134,14 +134,19 @@ protected Response getMetrics(final String accountSid, final UriInfo info, final checkAuthenticatedAccount(); allowOnlySuperAdmin(); boolean withLiveCallDetails = false; + boolean withMgcpStats = false; if (info != null && info.getQueryParameters().containsKey("LiveCallDetails") ) { withLiveCallDetails = Boolean.parseBoolean(info.getQueryParameters().getFirst("LiveCallDetails")); } + + if (info != null && info.getQueryParameters().containsKey("MgcpStats") ) { + withMgcpStats = Boolean.parseBoolean(info.getQueryParameters().getFirst("MgcpStats")); + } //Get the list of live calls from Monitoring Service MonitoringServiceResponse monitoringServiceResponse; try { final Timeout expires = new Timeout(Duration.create(5, TimeUnit.SECONDS)); - GetStatistics getStatistics = new GetStatistics(withLiveCallDetails, accountSid); + GetStatistics getStatistics = new GetStatistics(withLiveCallDetails, withMgcpStats, accountSid); Future future = (Future) ask(monitoringService, getStatistics, expires); monitoringServiceResponse = (MonitoringServiceResponse) Await.result(future, Duration.create(5, TimeUnit.SECONDS)); } catch (Exception exception) { @@ -202,14 +207,19 @@ protected Response registerForUpdates(final String accountSid, final UriInfo inf checkAuthenticatedAccount(); allowOnlySuperAdmin(); boolean withLiveCallDetails = false; + boolean withMgcpStats = false; if (info != null && info.getQueryParameters().containsKey("LiveCallDetails") ) { withLiveCallDetails = Boolean.parseBoolean(info.getQueryParameters().getFirst("LiveCallDetails")); } + + if (info != null && info.getQueryParameters().containsKey("MgcpStats") ) { + withMgcpStats = Boolean.parseBoolean(info.getQueryParameters().getFirst("MgcpStats")); + } //Get the list of live calls from Monitoring Service MonitoringServiceResponse monitoringServiceResponse; try { final Timeout expires = new Timeout(Duration.create(60, TimeUnit.SECONDS)); - GetStatistics getStatistics = new GetStatistics(withLiveCallDetails, accountSid); + GetStatistics getStatistics = new GetStatistics(withLiveCallDetails, withMgcpStats, accountSid); Future future = (Future) ask(monitoringService, getStatistics, expires); monitoringServiceResponse = (MonitoringServiceResponse) Await.result(future, Duration.create(10, TimeUnit.SECONDS)); } catch (Exception exception) { @@ -238,14 +248,19 @@ protected Response registerForCallUpdates(final String accountSid, final String final String url = data.getFirst("Url"); final String refresh = data.getFirst("Refresh"); boolean withLiveCallDetails = false; + boolean withMgcpStats = false; if (data != null && data.containsKey("LiveCallDetails")) { withLiveCallDetails = Boolean.parseBoolean(data.getFirst("LiveCallDetails")); } + + if (data != null && data.containsKey("MgcpStats") ) { + withMgcpStats = Boolean.parseBoolean(data.getFirst("MgcpStats")); + } //Get the list of live calls from Monitoring Service MonitoringServiceResponse monitoringServiceResponse; try { final Timeout expires = new Timeout(Duration.create(60, TimeUnit.SECONDS)); - GetStatistics getStatistics = new GetStatistics(withLiveCallDetails, accountSid); + GetStatistics getStatistics = new GetStatistics(withLiveCallDetails, withMgcpStats, accountSid); Future future = (Future) ask(monitoringService, getStatistics, expires); monitoringServiceResponse = (MonitoringServiceResponse) Await.result(future, Duration.create(10, TimeUnit.SECONDS)); } catch (Exception exception) { diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java index f6b3985261..e856b059d0 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java @@ -49,13 +49,17 @@ import org.mobicents.protocols.mgcp.jain.pkg.AUPackage; import org.restcomm.connect.commons.faulttolerance.RestcommUntypedActor; import org.restcomm.connect.commons.util.RevolvingCounter; +import org.restcomm.connect.mgcp.stats.MgcpConnectionAdded; +import org.restcomm.connect.mgcp.stats.MgcpConnectionDeleted; +import org.restcomm.connect.mgcp.stats.MgcpEndpointAdded; +import org.restcomm.connect.mgcp.stats.MgcpEndpointDeleted; +import org.restcomm.connect.mgcp.stats.MgcpLinkAdded; +import org.restcomm.connect.mgcp.stats.MgcpLinkDeleted; import javax.sdp.SdpFactory; import javax.sdp.SdpParseException; import javax.sdp.SessionDescription; import java.net.InetAddress; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; /** * @author quintana.thomas@gmail.com (Thomas Quintana) @@ -89,32 +93,15 @@ public class MockMediaGateway extends RestcommUntypedActor { private RevolvingCounter connectionIdPool; private RevolvingCounter endpointIdPool; - private static Map endpoints; - private static Map links; - private static Map connections; + private ActorRef monitoringService; private ActorSystem system; public MockMediaGateway() { super(); - endpoints = new ConcurrentHashMap(); - links = new ConcurrentHashMap(); - connections = new ConcurrentHashMap(); system = context().system(); } - public static Map getEndpointsMap() { - return endpoints; - } - - public static Map getConnections() { - return connections; - } - - public static Map getLinks() { - return links; - } - private ActorRef getConnection(final Object message) { final CreateConnection request = (CreateConnection) message; final MediaSession session = request.session(); @@ -127,7 +114,7 @@ public UntypedActor create() throws Exception { } }); ActorRef connection = system.actorOf(props); - connections.put(session, connection); + monitoringService.tell(new MgcpConnectionAdded(session, connection), self()); return connection; } @@ -144,7 +131,7 @@ public Actor create() throws Exception { } }); ActorRef bridgeEndpoint = system.actorOf(props); - endpoints.put(session, bridgeEndpoint); + monitoringService.tell(new MgcpEndpointAdded(session, bridgeEndpoint), self()); return bridgeEndpoint; } @@ -165,7 +152,7 @@ public UntypedActor create() throws Exception { } }); ActorRef conferenceEndpoint = system.actorOf(props); - endpoints.put(session, conferenceEndpoint); + monitoringService.tell(new MgcpEndpointAdded(session, conferenceEndpoint), self()); return conferenceEndpoint; } @@ -188,7 +175,7 @@ public UntypedActor create() throws Exception { } }); ActorRef ivrEndpoint = system.actorOf(props); - endpoints.put(session, ivrEndpoint); + monitoringService.tell(new MgcpEndpointAdded(session, ivrEndpoint), self()); return ivrEndpoint; } @@ -205,7 +192,7 @@ public UntypedActor create() throws Exception { } }); ActorRef link = system.actorOf(props); - links.put(session, link); + monitoringService.tell(new MgcpLinkAdded(session, link), self()); return link; } @@ -222,7 +209,7 @@ public UntypedActor create() throws Exception { } }); ActorRef packetRelayEndpoint = system.actorOf(props); - endpoints.put(session, packetRelayEndpoint); + monitoringService.tell(new MgcpEndpointAdded(session, packetRelayEndpoint), self()); return packetRelayEndpoint; } @@ -264,6 +251,7 @@ private void powerOn(final Object message) { requestIdPool = new RevolvingCounter(1, Integer.MAX_VALUE); sessionIdPool = new RevolvingCounter(1, Integer.MAX_VALUE); transactionIdPool = new RevolvingCounter(1, Integer.MAX_VALUE); + monitoringService = request.getMonitoringService(); } @Override @@ -298,15 +286,15 @@ public void onReceive(final Object message) throws Exception { sender.tell(new MediaGatewayResponse(endpoint), self); } else if (DestroyConnection.class.equals(klass)) { final DestroyConnection request = (DestroyConnection) message; - connections.values().remove(request.connection()); + monitoringService.tell(new MgcpConnectionDeleted(request.connection()), self()); context.stop(request.connection()); } else if (DestroyLink.class.equals(klass)) { final DestroyLink request = (DestroyLink) message; - links.values().remove(request.link()); + monitoringService.tell(new MgcpLinkDeleted(request.link()), self()); context.stop(request.link()); } else if (DestroyEndpoint.class.equals(klass)) { final DestroyEndpoint request = (DestroyEndpoint) message; - endpoints.values().remove(request.endpoint()); + monitoringService.tell(new MgcpEndpointDeleted(request.endpoint()), self()); context.stop(request.endpoint()); } else if (message instanceof JainMgcpCommandEvent) { send(message, sender); diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/PowerOnMediaGateway.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/PowerOnMediaGateway.java index e2d3b64d37..7863a8f365 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/PowerOnMediaGateway.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/PowerOnMediaGateway.java @@ -19,6 +19,7 @@ */ package org.restcomm.connect.mgcp; +import akka.actor.ActorRef; import jain.protocol.ip.mgcp.JainMgcpProvider; import jain.protocol.ip.mgcp.JainMgcpStack; import org.restcomm.connect.commons.annotations.concurrency.Immutable; @@ -43,10 +44,11 @@ public final class PowerOnMediaGateway { private final long timeout; private final JainMgcpStack stack; private final JainMgcpProvider provider; + private final ActorRef monitoringService; public PowerOnMediaGateway(final String name, final InetAddress localIp, final int localPort, final InetAddress remoteIp, final int remotePort, final boolean useNat, final InetAddress externalIp, final long timeout, final JainMgcpStack stack, - final JainMgcpProvider provider) { + final JainMgcpProvider provider, final ActorRef monitoringService) { super(); this.name = name; this.localIp = localIp; @@ -58,6 +60,7 @@ public PowerOnMediaGateway(final String name, final InetAddress localIp, final i this.timeout = timeout; this.stack = stack; this.provider = provider; + this.monitoringService = monitoringService; } public static Builder builder() { @@ -104,6 +107,10 @@ public JainMgcpProvider getProvider() { return provider; } + public ActorRef getMonitoringService () { + return monitoringService; + } + public static final class Builder { private String name; private InetAddress localIp; @@ -115,13 +122,14 @@ public static final class Builder { private long timeout; private JainMgcpStack stack; private JainMgcpProvider provider; + private ActorRef monitoringService; private Builder() { super(); } public PowerOnMediaGateway build() { - return new PowerOnMediaGateway(name, localIp, localPort, remoteIp, remotePort, useNat, externalIp, timeout, stack, provider); + return new PowerOnMediaGateway(name, localIp, localPort, remoteIp, remotePort, useNat, externalIp, timeout, stack, provider, monitoringService); } public void setName(final String name) { @@ -163,5 +171,9 @@ public void setStack(JainMgcpStack stack) { public void setProvider(JainMgcpProvider provider) { this.provider = provider; } + + public void setMonitoringService (ActorRef monitoringService) { + this.monitoringService = monitoringService; + } } } diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionAdded.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionAdded.java new file mode 100644 index 0000000000..dba0ebb513 --- /dev/null +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionAdded.java @@ -0,0 +1,22 @@ +package org.restcomm.connect.mgcp.stats; + +import akka.actor.ActorRef; +import org.restcomm.connect.mgcp.MediaSession; + +public class MgcpConnectionAdded { + private final MediaSession session; + private final ActorRef connection; + + public MgcpConnectionAdded (MediaSession session, ActorRef connection) { + this.session = session; + this.connection = connection; + } + + public MediaSession getSession () { + return session; + } + + public ActorRef getConnection () { + return connection; + } +} diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionDeleted.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionDeleted.java new file mode 100644 index 0000000000..bfd6119a1a --- /dev/null +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpConnectionDeleted.java @@ -0,0 +1,15 @@ +package org.restcomm.connect.mgcp.stats; + +import akka.actor.ActorRef; + +public class MgcpConnectionDeleted { + private final ActorRef connection; + + public MgcpConnectionDeleted (ActorRef connection) { + this.connection = connection; + } + + public ActorRef getConnection () { + return connection; + } +} diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java new file mode 100644 index 0000000000..f2791d0f57 --- /dev/null +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java @@ -0,0 +1,22 @@ +package org.restcomm.connect.mgcp.stats; + +import akka.actor.ActorRef; +import org.restcomm.connect.mgcp.MediaSession; + +public class MgcpEndpointAdded { + private final MediaSession session; + private final ActorRef connection; + + public MgcpEndpointAdded (MediaSession session, ActorRef connection) { + this.session = session; + this.connection = connection; + } + + public MediaSession getSession () { + return session; + } + + public ActorRef getConnection () { + return connection; + } +} diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java new file mode 100644 index 0000000000..a223e0ee0d --- /dev/null +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java @@ -0,0 +1,15 @@ +package org.restcomm.connect.mgcp.stats; + +import akka.actor.ActorRef; + +public class MgcpEndpointDeleted { + private final ActorRef connection; + + public MgcpEndpointDeleted (ActorRef connection) { + this.connection = connection; + } + + public ActorRef getConnection () { + return connection; + } +} diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java new file mode 100644 index 0000000000..4321bdcf82 --- /dev/null +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java @@ -0,0 +1,22 @@ +package org.restcomm.connect.mgcp.stats; + +import akka.actor.ActorRef; +import org.restcomm.connect.mgcp.MediaSession; + +public class MgcpLinkAdded { + private final MediaSession session; + private final ActorRef connection; + + public MgcpLinkAdded (MediaSession session, ActorRef connection) { + this.session = session; + this.connection = connection; + } + + public MediaSession getSession () { + return session; + } + + public ActorRef getConnection () { + return connection; + } +} diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java new file mode 100644 index 0000000000..dc328cd8c4 --- /dev/null +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java @@ -0,0 +1,15 @@ +package org.restcomm.connect.mgcp.stats; + +import akka.actor.ActorRef; + +public class MgcpLinkDeleted { + private final ActorRef connection; + + public MgcpLinkDeleted (ActorRef connection) { + this.connection = connection; + } + + public ActorRef getConnection () { + return connection; + } +} diff --git a/restcomm/restcomm.monitoring.service/pom.xml b/restcomm/restcomm.monitoring.service/pom.xml index 4a9e42c48d..9811ea06e7 100644 --- a/restcomm/restcomm.monitoring.service/pom.xml +++ b/restcomm/restcomm.monitoring.service/pom.xml @@ -80,5 +80,11 @@ ${jain-sip-api.version} provided + + + org.restcomm + restcomm-connect.mgcp + ${project.version} + diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java index a7f0fdf1a9..a92c5b93fc 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java @@ -27,4 +27,7 @@ public class MonitoringMetrics { public static String COUNTERS_MAP_TEXT_MESSAGE_INBOUND_TO_PROXY_OUT="TextMessageInboundToProxyOut"; public static String COUNTERS_MAP_TEXT_MESSAGE_NOT_FOUND="TextMessageNotFound"; public static String COUNTERS_MAP_TEXT_MESSAGE_OUTBOUND="TextMessageOutbound"; + public static String COUNTERS_MAP_MGCP_ENDPOINTS="MgcpEndpoints"; + public static String COUNTERS_MAP_MGCP_CONNECTIONS="MgcpConnections"; + public static String COUNTERS_MAP_MGCP_LINKS="MgcpLinks"; } diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java index 5003bcf1ce..3a198ba351 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java @@ -29,6 +29,12 @@ import org.restcomm.connect.commons.patterns.StopObserving; import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.entities.InstanceId; +import org.restcomm.connect.mgcp.stats.MgcpConnectionAdded; +import org.restcomm.connect.mgcp.stats.MgcpConnectionDeleted; +import org.restcomm.connect.mgcp.stats.MgcpEndpointAdded; +import org.restcomm.connect.mgcp.stats.MgcpEndpointDeleted; +import org.restcomm.connect.mgcp.stats.MgcpLinkAdded; +import org.restcomm.connect.mgcp.stats.MgcpLinkDeleted; import org.restcomm.connect.telephony.api.CallInfo; import org.restcomm.connect.telephony.api.CallResponse; import org.restcomm.connect.telephony.api.CallStateChanged; @@ -84,6 +90,16 @@ public class MonitoringService extends RestcommUntypedActor { private final AtomicInteger maxConcurrentCalls; private final AtomicInteger maxConcurrentIncomingCalls; private final AtomicInteger maxConcurrentOutgoingCalls; + + private final AtomicInteger mgcpEndpoints; + private final AtomicInteger mgcpLinks; + private final AtomicInteger mgcpConnections; +// private final Map mgcpEndpointMap; +// private final Map mgcpLinkMap; +// private final Map mgcpConnectionMap; + + + private InstanceId instanceId; @@ -113,6 +129,15 @@ public MonitoringService(final DaoManager daoManager) { maxConcurrentCalls = new AtomicInteger(0); maxConcurrentIncomingCalls = new AtomicInteger(0); maxConcurrentOutgoingCalls = new AtomicInteger(0); + + mgcpEndpoints = new AtomicInteger(0); + mgcpLinks = new AtomicInteger(0); + mgcpConnections = new AtomicInteger(0); + +// mgcpEndpointMap = new ConcurrentHashMap(); +// mgcpLinkMap = new ConcurrentHashMap(); +// mgcpConnectionMap = new ConcurrentHashMap(); + if(logger.isInfoEnabled()){ logger.info("Monitoring Service started"); } @@ -156,9 +181,51 @@ public void onReceive(Object message) throws Exception { logger.debug("MonitoringService onGetCall, message is null, sender: "+sender.path()); } } + } else if (MgcpConnectionAdded.class.equals(klass)) { + mgcpConnections.incrementAndGet(); + } else if (MgcpConnectionDeleted.class.equals(klass)) { + mgcpConnections.decrementAndGet(); + } else if (MgcpEndpointAdded.class.equals(klass)) { + mgcpEndpoints.incrementAndGet(); + } else if (MgcpEndpointDeleted.class.equals(klass)) { + mgcpEndpoints.decrementAndGet(); + } else if (MgcpLinkAdded.class.equals(klass)) { + mgcpLinks.incrementAndGet(); + } else if (MgcpLinkDeleted.class.equals(klass)) { + mgcpLinks.decrementAndGet(); } } +// private void processMgcpConnectionAdded(final MgcpConnectionAdded mgcpConnectionAdded) { +// mgcpConnections.incrementAndGet(); +// mgcpConnectionMap.put(mgcpConnectionAdded.getConnection(), mgcpConnectionAdded.getSession()); +// } +// +// private void processMgcpConnectionDeleted(final MgcpConnectionDeleted mgcpConnectionDeleted) { +// mgcpConnections.decrementAndGet(); +// mgcpConnectionMap.remove(mgcpConnectionDeleted.getConnection()); +// } +// +// private void processMgcpEndpointAdded(final MgcpEndpointAdded mgcpEndpointAdded) { +// mgcpEndpoints.incrementAndGet(); +// mgcpEndpointMap.put(mgcpEndpointAdded.getConnection(), mgcpEndpointAdded.getSession()); +// } +// +// private void processMgcpEndpointDeleted(final MgcpEndpointDeleted mgcpEndpointDeleted) { +// mgcpEndpoints.decrementAndGet(); +// mgcpEndpointMap.remove(mgcpEndpointDeleted.getConnection()); +// } +// +// private void processMgcpLinkAdded(final MgcpLinkAdded mgcpLinkAdded) { +// mgcpLinks.incrementAndGet(); +// mgcpLinkMap.put(mgcpLinkAdded.getConnection(), mgcpLinkAdded.getSession()); +// } +// +// private void processMgcpLinkDeleted(final MgcpLinkDeleted mgcpLinkDeleted) { +// mgcpLinks.decrementAndGet(); +// mgcpLinkMap.remove(mgcpLinkDeleted.getConnection()); +// } + private void onGetCall(Object message, ActorRef self, ActorRef sender) throws ServletParseException { GetCall getCall = (GetCall)message; String location = getCall.getIdentifier(); @@ -428,6 +495,12 @@ private void onGetStatistics (GetStatistics message, ActorRef self, ActorRef sen countersMap.put(MonitoringMetrics.COUNTERS_MAP_TEXT_MESSAGE_NOT_FOUND, textNotFound.get()); countersMap.put(MonitoringMetrics.COUNTERS_MAP_TEXT_MESSAGE_OUTBOUND, textOutbound.get()); + if (message.isWithMgcpStats()) { + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS, mgcpEndpoints.get()); + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_CONNECTIONS, mgcpConnections.get()); + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_LINKS, mgcpLinks.get()); + } + MonitoringServiceResponse callInfoList = null; if (message.isWithLiveCallDetails()) { callInfoList = new MonitoringServiceResponse(instanceId, callDetailsList, countersMap, durationMap, true, null); diff --git a/restcomm/restcomm.mrb.api/src/main/java/org/restcomm/connect/mrb/api/StartMediaResourceBroker.java b/restcomm/restcomm.mrb.api/src/main/java/org/restcomm/connect/mrb/api/StartMediaResourceBroker.java index 7821c1018e..bd02c8c941 100644 --- a/restcomm/restcomm.mrb.api/src/main/java/org/restcomm/connect/mrb/api/StartMediaResourceBroker.java +++ b/restcomm/restcomm.mrb.api/src/main/java/org/restcomm/connect/mrb/api/StartMediaResourceBroker.java @@ -19,6 +19,7 @@ */ package org.restcomm.connect.mrb.api; +import akka.actor.ActorRef; import org.apache.commons.configuration.Configuration; import org.restcomm.connect.commons.annotations.concurrency.Immutable; import org.restcomm.connect.dao.DaoManager; @@ -31,12 +32,14 @@ public final class StartMediaResourceBroker { private final Configuration configuration; private final DaoManager storage; private final ClassLoader loader; + private final ActorRef monitoringService; - public StartMediaResourceBroker(final Configuration configuration, final DaoManager storage, final ClassLoader loader) { + public StartMediaResourceBroker(final Configuration configuration, final DaoManager storage, final ClassLoader loader, final ActorRef monitoringService) { super(); this.configuration = configuration; this.storage = storage; this.loader = loader; + this.monitoringService = monitoringService; } public Configuration configuration(){ @@ -50,4 +53,8 @@ public DaoManager storage(){ public ClassLoader loader(){ return this.loader; } + + public ActorRef getMonitoringService () { + return monitoringService; + } } diff --git a/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java b/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java index 70eecd086d..9b5c3488f4 100644 --- a/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java +++ b/restcomm/restcomm.mrb/src/main/java/org/restcomm/connect/mrb/MediaResourceBrokerGeneric.java @@ -69,6 +69,7 @@ public class MediaResourceBrokerGeneric extends RestcommUntypedActor { protected Configuration configuration; protected DaoManager storage; protected ClassLoader loader; + protected ActorRef monitoringService; protected ActorRef localMediaGateway; protected String localMsId; protected Map mediaGatewayMap; @@ -113,6 +114,7 @@ protected void onStartMediaResourceBroker(StartMediaResourceBroker message, Acto this.configuration = message.configuration(); this.storage = message.storage(); this.loader = message.loader(); + this.monitoringService = message.getMonitoringService(); localMediaServerEntity = uploadLocalMediaServersInDataBase(); bindMGCPStack(localMediaServerEntity.getLocalIpAddress(), localMediaServerEntity.getLocalPort()); @@ -184,6 +186,7 @@ protected ActorRef turnOnMediaGateway(MediaServerEntity mediaServerEntity) throw builder.setTimeout(Long.parseLong(mediaServerEntity.getResponseTimeout())); builder.setStack(mgcpStack); builder.setProvider(mgcpProvider); + builder.setMonitoringService(monitoringService); final PowerOnMediaGateway powerOn = builder.build(); gateway.tell(powerOn, null); diff --git a/restcomm/restcomm.telephony.api/src/main/java/org/restcomm/connect/telephony/api/GetStatistics.java b/restcomm/restcomm.telephony.api/src/main/java/org/restcomm/connect/telephony/api/GetStatistics.java index e0660c5589..ad0fa8f2e9 100644 --- a/restcomm/restcomm.telephony.api/src/main/java/org/restcomm/connect/telephony/api/GetStatistics.java +++ b/restcomm/restcomm.telephony.api/src/main/java/org/restcomm/connect/telephony/api/GetStatistics.java @@ -5,15 +5,21 @@ */ public class GetStatistics { private final boolean withLiveCallDetails; + private final boolean withMgcpStats; private final String accountSid; - public GetStatistics (final boolean withLiveCallDetails, final String accountSid) { + public GetStatistics (final boolean withLiveCallDetails, final boolean withMgcpStats, final String accountSid) { this.withLiveCallDetails = withLiveCallDetails; + this.withMgcpStats = withMgcpStats; this.accountSid = accountSid; } public boolean isWithLiveCallDetails () { return withLiveCallDetails; } + public boolean isWithMgcpStats () { + return withMgcpStats; + } + public String getAccountSid () { return accountSid; } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/telephony/TestMgcpOperations.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/telephony/TestMgcpOperations.java index 51af4538d1..40166db667 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/telephony/TestMgcpOperations.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/telephony/TestMgcpOperations.java @@ -2,6 +2,7 @@ import akka.actor.ActorRef; import com.github.tomakehurst.wiremock.junit.WireMockRule; +import com.google.gson.JsonObject; import org.apache.log4j.Logger; import org.cafesip.sipunit.Credential; import org.cafesip.sipunit.SipCall; @@ -21,8 +22,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.restcomm.connect.commons.Version; -import org.restcomm.connect.mgcp.MediaSession; -import org.restcomm.connect.mgcp.MockMediaGateway; +import org.restcomm.connect.testsuite.tools.MonitoringServiceTool; import javax.sip.message.Response; import java.net.URL; @@ -153,6 +153,7 @@ public synchronized void testDialHelloPlay() throws InterruptedException, ParseE bobPhone.addUpdateCredential(c); final SipCall bobCall = bobPhone.createSipCall(); + bobCall.listenForDisconnect(); bobCall.initiateOutgoingCall(bobContact, "sip:1234@127.0.0.1:5080", null, body, "application", "sdp", null, null); assertLastOperationSuccess(bobCall); assertTrue(bobCall.waitForAuthorisation(5000)); @@ -171,16 +172,56 @@ public synchronized void testDialHelloPlay() throws InterruptedException, ParseE bobCall.sendInviteOkAck(); assertTrue(!(bobCall.getLastReceivedResponse().getStatusCode() >= 400)); - bobCall.listenForDisconnect(); + Thread.sleep(500); + + JsonObject metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken); + assertNotNull(metrics); + int mgcpEndpoints = metrics.getAsJsonObject("Metrics").get("MgcpEndpoints").getAsInt(); + int mgcpConnections = metrics.getAsJsonObject("Metrics").get("MgcpConnections").getAsInt(); + int mgcpLinks = metrics.getAsJsonObject("Metrics").get("MgcpLinks").getAsInt(); + int liveCalls = metrics.getAsJsonObject("Metrics").get("LiveCalls").getAsInt(); + + logger.info("MgcpEndpoints: "+mgcpEndpoints); + logger.info("MgcpConnections: "+mgcpConnections); + logger.info("MgcpLinks: "+mgcpLinks); + logger.info("LiveCalls: "+liveCalls); +// int liveCallsArraySize = metrics.getAsJsonArray("LiveCallDetails").size(); +// logger.info("LiveCallsArraySize: "+liveCallsArraySize); +// assertTrue(liveCalls==0); +// assertTrue(liveCallsArraySize==0); +// int maxConcurrentCalls = metrics.getAsJsonObject("Metrics").get("MaximumConcurrentCalls").getAsInt(); +// int maxConcurrentIncomingCalls = metrics.getAsJsonObject("Metrics").get("MaximumConcurrentIncomingCalls").getAsInt(); +// int maxConcurrentOutgoingCalls = metrics.getAsJsonObject("Metrics").get("MaximumConcurrentIncomingCalls").getAsInt(); +// assertTrue(maxConcurrentCalls==0); +// assertTrue(maxConcurrentIncomingCalls==0); +// assertTrue(maxConcurrentOutgoingCalls==0); + + + assertTrue(bobCall.waitForDisconnect(10000)); - Map endpoints = MockMediaGateway.getEndpointsMap(); - assertNotNull(endpoints); - assertTrue(endpoints.size() == 0); + Thread.sleep(1000); + + metrics = MonitoringServiceTool.getInstance().getMetrics(deploymentUrl.toString(),adminAccountSid, adminAuthToken); + assertNotNull(metrics); + mgcpEndpoints = metrics.getAsJsonObject("Metrics").get("MgcpEndpoints").getAsInt(); + mgcpConnections = metrics.getAsJsonObject("Metrics").get("MgcpConnections").getAsInt(); + mgcpLinks = metrics.getAsJsonObject("Metrics").get("MgcpLinks").getAsInt(); + liveCalls = metrics.getAsJsonObject("Metrics").get("LiveCalls").getAsInt(); + + logger.info("MgcpEndpoints at the end: "+mgcpEndpoints); + logger.info("MgcpConnections at the end: "+mgcpConnections); + logger.info("MgcpLinks at the end: "+mgcpLinks); + logger.info("Live calls at the end: "+liveCalls); + + assertEquals(0, liveCalls); + assertEquals(0, mgcpEndpoints); + assertEquals(0, mgcpLinks); + assertEquals(0, mgcpConnections); } - @Deployment(name = "TestDialVerbPartOne", managed = true, testable = false) + @Deployment(name = "TestMgcpOperations", managed = true, testable = false) public static WebArchive createWebArchiveNoGw() { logger.info("Packaging Test App"); WebArchive archive = ShrinkWrap.create(WebArchive.class, "restcomm.war"); @@ -190,10 +231,10 @@ public static WebArchive createWebArchiveNoGw() { archive = archive.merge(restcommArchive); archive.delete("/WEB-INF/sip.xml"); archive.delete("/WEB-INF/conf/restcomm.xml"); -// archive.delete("/WEB-INF/data/hsql/restcomm.script"); + archive.delete("/WEB-INF/data/hsql/restcomm.script"); archive.addAsWebInfResource("sip.xml"); archive.addAsWebInfResource("restcomm.xml", "conf/restcomm.xml"); -// archive.addAsWebInfResource("restcomm.script_dialTest_new", "data/hsql/restcomm.script"); + archive.addAsWebInfResource("restcomm.script_mgcpoperations", "data/hsql/restcomm.script"); logger.info("Packaged Test App"); return archive; } diff --git a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java index 0fd6dc845d..e3b16f0fb2 100644 --- a/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java +++ b/restcomm/restcomm.testsuite/src/test/java/org/restcomm/connect/testsuite/tools/MonitoringServiceTool.java @@ -52,10 +52,10 @@ public JsonObject getLiveCalls(String deploymentUrl, String username, String aut } public JsonObject getMetrics(String deploymentUrl, String username, String authToken) { - return getMetrics(deploymentUrl, username, authToken, true); + return getMetrics(deploymentUrl, username, authToken, true, true); } - public JsonObject getMetrics(String deploymentUrl, String username, String authToken, boolean callDetails) { + public JsonObject getMetrics(String deploymentUrl, String username, String authToken, boolean callDetails, boolean mgcpStats) { Client jerseyClient = Client.create(); jerseyClient.addFilter(new HTTPBasicAuthFilter(username, authToken)); String url = getAccountsUrl(deploymentUrl, username); @@ -64,6 +64,9 @@ public JsonObject getMetrics(String deploymentUrl, String username, String authT if (callDetails) { webResource = webResource.queryParam("LiveCallDetails","true"); } + if (mgcpStats) { + webResource = webResource.queryParam("MgcpStats", "true"); + } String response = null; response = webResource.accept(MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).get(String.class); diff --git a/restcomm/restcomm.testsuite/src/test/resources/log4j.xml b/restcomm/restcomm.testsuite/src/test/resources/log4j.xml index 2458ae96f8..40d05b6a28 100644 --- a/restcomm/restcomm.testsuite/src/test/resources/log4j.xml +++ b/restcomm/restcomm.testsuite/src/test/resources/log4j.xml @@ -1,26 +1,31 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local b/restcomm/restcomm.testsuite/src/test/resources/log4j.xml.cloud similarity index 76% rename from restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local rename to restcomm/restcomm.testsuite/src/test/resources/log4j.xml.cloud index 40d05b6a28..18393d7f38 100644 --- a/restcomm/restcomm.testsuite/src/test/resources/log4j.xml_local +++ b/restcomm/restcomm.testsuite/src/test/resources/log4j.xml.cloud @@ -14,18 +14,13 @@ - - - - - - + - diff --git a/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_mgcpoperations b/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_mgcpoperations new file mode 100644 index 0000000000..5035c16551 --- /dev/null +++ b/restcomm/restcomm.testsuite/src/test/resources/restcomm.script_mgcpoperations @@ -0,0 +1,33 @@ +CREATE SCHEMA PUBLIC AUTHORIZATION DBA +CREATE MEMORY TABLE "restcomm_instance_id"("instance_id" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL, "host" VARCHAR(255) NOT NULL) +CREATE MEMORY TABLE "restcomm_organizations"("sid" VARCHAR(34) NOT NULL PRIMARY KEY, "domain_name" VARCHAR(255) NOT NULL UNIQUE, "date_created" DATETIME NOT NULL, "date_updated" DATETIME NOT NULL, "status" VARCHAR(16)) +CREATE MEMORY TABLE "restcomm_accounts"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"email_address" LONGVARCHAR NOT NULL,"friendly_name" VARCHAR(64) NOT NULL,"parent_sid" VARCHAR(34),"type" VARCHAR(8) NOT NULL,"status" VARCHAR(16) NOT NULL,"auth_token" VARCHAR(32) NOT NULL,"role" VARCHAR(64) NOT NULL,"uri" LONGVARCHAR NOT NULL, "organization_sid" VARCHAR(34) DEFAULT 'ORafbe225ad37541eba518a74248f0ac4c') +CREATE MEMORY TABLE "restcomm_announcements"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"account_sid" VARCHAR(34),"gender" VARCHAR(8) NOT NULL,"language" VARCHAR(16) NOT NULL,"text" VARCHAR(32) NOT NULL,"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_available_phone_numbers"("friendly_name" VARCHAR(64) NOT NULL,"phone_number" VARCHAR(15) NOT NULL PRIMARY KEY,"lata" SMALLINT,"rate_center" VARCHAR(32),"latitude" DOUBLE,"longitude" DOUBLE,"region" VARCHAR(2),"postal_code" INTEGER,"iso_country" VARCHAR(2) NOT NULL,"voice_capable" BOOLEAN, "sms_capable" BOOLEAN, "mms_capable" BOOLEAN, "fax_capable" BOOLEAN,"cost" VARCHAR(10)) +CREATE MEMORY TABLE "restcomm_outgoing_caller_ids"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"friendly_name" VARCHAR(64) NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"phone_number" VARCHAR(15) NOT NULL,"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_http_cookies"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"comment" LONGVARCHAR,"domain" LONGVARCHAR,"expiration_date" DATETIME,"name" LONGVARCHAR NOT NULL,"path" LONGVARCHAR,"value" LONGVARCHAR,"version" INT) +CREATE MEMORY TABLE "restcomm_incoming_phone_numbers"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"friendly_name" VARCHAR(64) NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"phone_number" VARCHAR(30) NOT NULL,"api_version" VARCHAR(10) NOT NULL,"voice_caller_id_lookup" BOOLEAN NOT NULL,"voice_url" LONGVARCHAR,"voice_method" VARCHAR(4),"voice_fallback_url" LONGVARCHAR,"voice_fallback_method" VARCHAR(4),"status_callback" LONGVARCHAR,"status_callback_method" VARCHAR(4),"voice_application_sid" VARCHAR(34),"sms_url" LONGVARCHAR,"sms_method" VARCHAR(4),"sms_fallback_url" LONGVARCHAR,"sms_fallback_method" VARCHAR(4),"sms_application_sid" VARCHAR(34),"uri" LONGVARCHAR NOT NULL, "voice_capable" BOOLEAN, "sms_capable" BOOLEAN, "mms_capable" BOOLEAN, "fax_capable" BOOLEAN, "pure_sip" BOOLEAN,"cost" VARCHAR(10), "ussd_url" LONGVARCHAR, "ussd_method" VARCHAR(4), "ussd_fallback_url" LONGVARCHAR, "ussd_fallback_method" VARCHAR(4), "ussd_application_sid" VARCHAR(34), "refer_url" LONGVARCHAR, "refer_method" VARCHAR(4), "refer_application_sid" VARCHAR(34), "organization_sid" VARCHAR(34) NOT NULL) +CREATE MEMORY TABLE "restcomm_applications"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"friendly_name" VARCHAR(64) NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"api_version" VARCHAR(10) NOT NULL,"voice_caller_id_lookup" BOOLEAN NOT NULL,"uri" LONGVARCHAR NOT NULL,"rcml_url" LONGVARCHAR, "kind" VARCHAR(5)) +CREATE MEMORY TABLE "restcomm_call_detail_records"("sid" VARCHAR(1000) NOT NULL PRIMARY KEY,"parent_call_sid" VARCHAR(1000),"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"sender" VARCHAR(30) NOT NULL,"recipient" VARCHAR(64) NOT NULL,"phone_number_sid" VARCHAR(34),"status" VARCHAR(20) NOT NULL,"start_time" DATETIME,"end_time" DATETIME,"duration" INTEGER,"price" VARCHAR(8),"direction" VARCHAR(20) NOT NULL,"answered_by" VARCHAR(64),"api_version" VARCHAR(10) NOT NULL,"forwarded_from" VARCHAR(30),"caller_name" VARCHAR(50),"uri" LONGVARCHAR NOT NULL, "call_path" VARCHAR(255),"ring_duration" INTEGER, "instanceid" VARCHAR(255) NOT NULL, "conference_sid" VARCHAR(34),"muted" BOOLEAN, "start_conference_on_enter" BOOLEAN, "end_conference_on_exit" BOOLEAN, "on_hold" BOOLEAN, "ms_id" VARCHAR(34)) +CREATE MEMORY TABLE "restcomm_conference_detail_records" ( "sid" VARCHAR(34) NOT NULL PRIMARY KEY, "date_created" DATETIME NOT NULL, "date_updated" DATETIME NOT NULL, "account_sid" VARCHAR(34) NOT NULL, "status" VARCHAR(100) NOT NULL, "friendly_name" VARCHAR(60), "api_version" VARCHAR(10) NOT NULL, "uri" LONGVARCHAR NOT NULL, "master_ms_id" VARCHAR(34),"master_conference_endpoint_id" VARCHAR(20),"master_present" BOOLEAN DEFAULT TRUE, "master_ivr_endpoint_id" VARCHAR(20),"master_ivr_endpoint_session_id" VARCHAR(200),"master_bridge_endpoint_id" VARCHAR(20),"master_bridge_endpoint_session_id" VARCHAR(200),"master_bridge_conn_id" VARCHAR(200),"master_ivr_conn_id" VARCHAR(200)) +CREATE MEMORY TABLE "restcomm_clients"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"api_version" VARCHAR(10) NOT NULL,"friendly_name" VARCHAR(64) NOT NULL,"login" VARCHAR(64) NOT NULL,"password" VARCHAR(64) NOT NULL,"status" INTEGER NOT NULL,"voice_url" LONGVARCHAR,"voice_method" VARCHAR(4),"voice_fallback_url" LONGVARCHAR,"voice_fallback_method" VARCHAR(4),"voice_application_sid" VARCHAR(34),"uri" LONGVARCHAR NOT NULL, "push_client_identity" VARCHAR(34)) +CREATE MEMORY TABLE "restcomm_registrations"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"date_expires" DATETIME NOT NULL,"address_of_record" LONGVARCHAR NOT NULL,"display_name" VARCHAR(255),"user_name" VARCHAR(64) NOT NULL,"user_agent" LONGVARCHAR,"ttl" INTEGER NOT NULL,"location" LONGVARCHAR NOT NULL, "webrtc" BOOLEAN DEFAULT FALSE, "instanceid" VARCHAR(255), "isLBPresent" BOOLEAN DEFAULT FALSE, "organization_sid" VARCHAR(34)) +CREATE MEMORY TABLE "restcomm_short_codes"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"friendly_name" VARCHAR(64) NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"short_code" INTEGER NOT NULL,"api_version" VARCHAR(10) NOT NULL,"sms_url" LONGVARCHAR,"sms_method" VARCHAR(4),"sms_fallback_url" LONGVARCHAR,"sms_fallback_method" VARCHAR(4),"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_sms_messages"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"date_sent" DATETIME,"account_sid" VARCHAR(34) NOT NULL,"sender" VARCHAR(15) NOT NULL,"recipient" VARCHAR(64) NOT NULL,"body" VARCHAR(999) NOT NULL,"status" VARCHAR(20) NOT NULL,"direction" VARCHAR(14) NOT NULL,"price" VARCHAR(8) NOT NULL,"api_version" VARCHAR(10) NOT NULL,"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_recordings"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"call_sid" VARCHAR(1000) NOT NULL,"duration" DOUBLE NOT NULL,"api_version" VARCHAR(10) NOT NULL,"uri" LONGVARCHAR NOT NULL, "file_uri" LONGVARCHAR) +CREATE MEMORY TABLE "restcomm_transcriptions"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"status" VARCHAR(11) NOT NULL,"recording_sid" VARCHAR(34) NOT NULL,"duration" DOUBLE NOT NULL,"transcription_text" LONGVARCHAR,"price" VARCHAR(8) NOT NULL,"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_notifications"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"call_sid" VARCHAR(1000),"api_version" VARCHAR(10) NOT NULL,"log" TINYINT NOT NULL,"error_code" SMALLINT NOT NULL,"more_info" LONGVARCHAR NOT NULL,"message_text" LONGVARCHAR NOT NULL,"message_date" DATETIME NOT NULL,"request_url" LONGVARCHAR NOT NULL,"request_method" VARCHAR(4) NOT NULL,"request_variables" LONGVARCHAR NOT NULL,"response_headers" LONGVARCHAR,"response_body" LONGVARCHAR,"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_sand_boxes"("date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"pin" VARCHAR(8) NOT NULL,"account_sid" VARCHAR(34) NOT NULL PRIMARY KEY,"phone_number" VARCHAR(15) NOT NULL,"application_sid" VARCHAR(34) NOT NULL,"api_version" VARCHAR(10) NOT NULL,"voice_url" LONGVARCHAR,"voice_method" VARCHAR(4),"sms_url" LONGVARCHAR,"sms_method" VARCHAR(4),"status_callback" LONGVARCHAR,"status_callback_method" VARCHAR(4),"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_gateways"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"friendly_name" VARCHAR(255),"user_name" VARCHAR(255),"password" VARCHAR(255),"proxy" LONGVARCHAR NOT NULL,"register" BOOLEAN NOT NULL,"ttl" INT NOT NULL,"uri" LONGVARCHAR NOT NULL) +CREATE MEMORY TABLE "restcomm_media_servers" ( "ms_id" INT GENERATED BY DEFAULT AS IDENTITY (START WITH 1, INCREMENT BY 1) NOT NULL, "local_ip" VARCHAR(34) NOT NULL, "local_port" INT NOT NULL, "remote_ip" VARCHAR(34) NOT NULL UNIQUE, "remote_port" INT NOT NULL, "compatibility" VARCHAR(34) DEFAULT 'rms', "response_timeout" VARCHAR(34), "external_address" VARCHAR(34)) +CREATE MEMORY TABLE "restcomm_media_resource_broker_entity" ("conference_sid" VARCHAR(34) NOT NULL, "slave_ms_id" VARCHAR(34) NOT NULL, "slave_ms_bridge_ep_id" VARCHAR(34),"slave_ms_cnf_ep_id" VARCHAR(34),"is_bridged_together" BOOLEAN DEFAULT FALSE,PRIMARY KEY ("conference_sid" , "slave_ms_id")) +CREATE MEMORY TABLE PUBLIC."restcomm_extensions_configuration"("sid" VARCHAR(34) NOT NULL PRIMARY KEY,"extension" VARCHAR(255) NOT NULL,"configuration_data" VARCHAR(16777216),"configuration_type" VARCHAR(255) NOT NULL,"date_created" TIMESTAMP NOT NULL,"date_updated" TIMESTAMP, "enabled" BOOLEAN DEFAULT TRUE NOT NULL) +CREATE MEMORY TABLE "restcomm_geolocation"("sid" VARCHAR(34) NOT NULL PRIMARY KEY, "date_created" DATETIME NOT NULL, "date_updated" DATETIME NOT NULL, "date_executed" DATETIME NOT NULL, "account_sid" VARCHAR(34) NOT NULL, "source" VARCHAR(30), "device_identifier" VARCHAR(30) NOT NULL, "geolocation_type" VARCHAR(15) NOT NULL, "response_status" VARCHAR(30), "cell_id" VARCHAR(10), "location_area_code" VARCHAR(10), "mobile_country_code" INTEGER, "mobile_network_code" VARCHAR(3), "network_entity_address" BIGINT, "age_of_location_info" INTEGER, "device_latitude" VARCHAR(15), "device_longitude" VARCHAR(15), "accuracy" BIGINT, "physical_address" VARCHAR(50), "internet_address" VARCHAR(50), "formatted_address" VARCHAR(200), "location_timestamp" DATETIME, "event_geofence_latitude" VARCHAR(15), "event_geofence_longitude" VARCHAR(15), "radius" BIGINT, "geolocation_positioning_type" VARCHAR(15), "last_geolocation_response" VARCHAR(10), "cause" VARCHAR(150), "api_version" VARCHAR(10) NOT NULL, "uri" LONGVARCHAR NOT NULL) +CREATE USER SA PASSWORD "" +GRANT DBA TO SA +SET WRITE_DELAY 10 +SET SCHEMA PUBLIC +INSERT INTO "restcomm_organizations" VALUES('ORafbe225ad37541eba518a74248f0ac4c', 'default.restcomm.com', '2017-04-19 00:00:00.000000000','2017-04-19 00:00:00.000000000', 'active') +INSERT INTO "restcomm_accounts" VALUES('ACae6e420f425248d6a26948c17a9e2acf','2012-04-24 22:51:29.372000000','2012-04-24 22:51:29.372000000','administrator@company.com','Default Administrator Account',NULL,'Full','active','77f8c12cc7b8f8423e5c38b035249166','Administrator','/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf','ORafbe225ad37541eba518a74248f0ac4c') +INSERT INTO "restcomm_incoming_phone_numbers" VALUES('PNdd7a0a0248244615978bd5781598e5eb','2013-10-04 17:42:02.500000000','2013-10-04 17:42:02.500000000','This app plays pre-recorded audio file','ACae6e420f425248d6a26948c17a9e2acf','+1234','2012-04-24',FALSE,'/restcomm/demos/hello-play.xml','POST',NULL,'POST',NULL,'POST',NULL,NULL,'POST',NULL,'POST',NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/IncomingPhoneNumbers/PNdd7a0a0248244615978bd5781598e5eb',NULL,NULL,NULL,NULL, TRUE,'0.0',NULL,NULL,NULL,NULL,NULL, NULL, NULL, NULL, 'ORafbe225ad37541eba518a74248f0ac4c') +INSERT INTO "restcomm_clients" VALUES('CL3003328d0de04ba68f38de85b732ed56','2013-11-04 16:33:39.248000000','2013-11-04 16:33:39.248000000','ACae6e420f425248d6a26948c17a9e2acf','2012-04-24','bob','bob','1234',1,NULL,'POST',NULL,'POST',NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Clients/CL3003328d0de04ba68f38de85b732ed56',NULL) From 0355b201047ad162ed9ead4f5c77877468ed95b0 Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Wed, 4 Oct 2017 09:45:10 +0300 Subject: [PATCH 05/15] Work in progress for MgcpMonitoringService This refer to RESTCOMM-1155 --- .../monitoringservice/MonitoringService.java | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java index 3a198ba351..b891d4bcaf 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java @@ -29,6 +29,7 @@ import org.restcomm.connect.commons.patterns.StopObserving; import org.restcomm.connect.dao.DaoManager; import org.restcomm.connect.dao.entities.InstanceId; +import org.restcomm.connect.mgcp.MediaSession; import org.restcomm.connect.mgcp.stats.MgcpConnectionAdded; import org.restcomm.connect.mgcp.stats.MgcpConnectionDeleted; import org.restcomm.connect.mgcp.stats.MgcpEndpointAdded; @@ -94,9 +95,9 @@ public class MonitoringService extends RestcommUntypedActor { private final AtomicInteger mgcpEndpoints; private final AtomicInteger mgcpLinks; private final AtomicInteger mgcpConnections; -// private final Map mgcpEndpointMap; -// private final Map mgcpLinkMap; -// private final Map mgcpConnectionMap; + private final Map mgcpEndpointMap; + private final Map mgcpLinkMap; + private final Map mgcpConnectionMap; @@ -134,9 +135,9 @@ public MonitoringService(final DaoManager daoManager) { mgcpLinks = new AtomicInteger(0); mgcpConnections = new AtomicInteger(0); -// mgcpEndpointMap = new ConcurrentHashMap(); -// mgcpLinkMap = new ConcurrentHashMap(); -// mgcpConnectionMap = new ConcurrentHashMap(); + mgcpEndpointMap = new ConcurrentHashMap(); + mgcpLinkMap = new ConcurrentHashMap(); + mgcpConnectionMap = new ConcurrentHashMap(); if(logger.isInfoEnabled()){ logger.info("Monitoring Service started"); @@ -182,17 +183,29 @@ public void onReceive(Object message) throws Exception { } } } else if (MgcpConnectionAdded.class.equals(klass)) { + MgcpConnectionAdded mgcpConnectionAdded = (MgcpConnectionAdded)message; mgcpConnections.incrementAndGet(); + mgcpConnectionMap.put(mgcpConnectionAdded.getConnection(), mgcpConnectionAdded.getSession()); } else if (MgcpConnectionDeleted.class.equals(klass)) { + MgcpConnectionDeleted mgcpConnectionDeleted = (MgcpConnectionDeleted)message; mgcpConnections.decrementAndGet(); + mgcpConnectionMap.remove(mgcpConnectionDeleted.getConnection()); } else if (MgcpEndpointAdded.class.equals(klass)) { + MgcpEndpointAdded mgcpEndpointAdded = (MgcpEndpointAdded)message; mgcpEndpoints.incrementAndGet(); + mgcpEndpointMap.put(mgcpEndpointAdded.getConnection(), mgcpEndpointAdded.getSession()); } else if (MgcpEndpointDeleted.class.equals(klass)) { + MgcpEndpointDeleted mgcpEndpointDeleted = (MgcpEndpointDeleted)message; mgcpEndpoints.decrementAndGet(); + mgcpEndpointMap.remove(mgcpEndpointDeleted.getConnection()); } else if (MgcpLinkAdded.class.equals(klass)) { + MgcpLinkAdded mgcpLinkAdded = (MgcpLinkAdded)message; mgcpLinks.incrementAndGet(); + mgcpLinkMap.put(mgcpLinkAdded.getConnection(), mgcpLinkAdded.getSession()); } else if (MgcpLinkDeleted.class.equals(klass)) { + MgcpLinkDeleted mgcpLinkDeleted = (MgcpLinkDeleted)message; mgcpLinks.decrementAndGet(); + mgcpLinkMap.remove(mgcpLinkDeleted.getConnection()); } } @@ -208,7 +221,7 @@ public void onReceive(Object message) throws Exception { // // private void processMgcpEndpointAdded(final MgcpEndpointAdded mgcpEndpointAdded) { // mgcpEndpoints.incrementAndGet(); -// mgcpEndpointMap.put(mgcpEndpointAdded.getConnection(), mgcpEndpointAdded.getSession()); +// mgcpConnectionMap.remove(mgcpConnectionDeleted.getConnection()); // } // // private void processMgcpEndpointDeleted(final MgcpEndpointDeleted mgcpEndpointDeleted) { From e89b53e5607345c4b691437194c8646daffad20b Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Wed, 4 Oct 2017 10:49:08 +0300 Subject: [PATCH 06/15] Work in progress for MgcpMonitoring service This refer to RESTCOMM-1155 --- .../connect/mgcp/MockMediaGateway.java | 36 +++++++++++++++++++ .../connect/mgcp/stats/MgcpEndpointAdded.java | 10 +++--- .../mgcp/stats/MgcpEndpointDeleted.java | 10 +++--- .../connect/mgcp/stats/MgcpLinkAdded.java | 10 +++--- .../connect/mgcp/stats/MgcpLinkDeleted.java | 10 +++--- .../monitoringservice/MonitoringService.java | 8 ++--- 6 files changed, 60 insertions(+), 24 deletions(-) diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java index e856b059d0..91f1d5c6eb 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java @@ -114,6 +114,10 @@ public UntypedActor create() throws Exception { } }); ActorRef connection = system.actorOf(props); + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Added new Connection, path: %s",connection.path()); + logger.info(msg); + } monitoringService.tell(new MgcpConnectionAdded(session, connection), self()); return connection; } @@ -131,6 +135,10 @@ public Actor create() throws Exception { } }); ActorRef bridgeEndpoint = system.actorOf(props); + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Added Bridge endpoint, path: %s",bridgeEndpoint.path()); + logger.info(msg); + } monitoringService.tell(new MgcpEndpointAdded(session, bridgeEndpoint), self()); return bridgeEndpoint; } @@ -152,6 +160,10 @@ public UntypedActor create() throws Exception { } }); ActorRef conferenceEndpoint = system.actorOf(props); + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Added Conference endpoint, path: %s", conferenceEndpoint.path()); + logger.info(msg); + } monitoringService.tell(new MgcpEndpointAdded(session, conferenceEndpoint), self()); return conferenceEndpoint; } @@ -175,6 +187,10 @@ public UntypedActor create() throws Exception { } }); ActorRef ivrEndpoint = system.actorOf(props); + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Added Ivr endpoint, path: %s",ivrEndpoint.path()); + logger.info(msg); + } monitoringService.tell(new MgcpEndpointAdded(session, ivrEndpoint), self()); return ivrEndpoint; } @@ -192,6 +208,10 @@ public UntypedActor create() throws Exception { } }); ActorRef link = system.actorOf(props); + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Added new Link, path: %s",link.path()); + logger.info(msg); + } monitoringService.tell(new MgcpLinkAdded(session, link), self()); return link; } @@ -209,6 +229,10 @@ public UntypedActor create() throws Exception { } }); ActorRef packetRelayEndpoint = system.actorOf(props); + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Added PacketRelay endpoint, path: %s",packetRelayEndpoint.path()); + logger.info(msg); + } monitoringService.tell(new MgcpEndpointAdded(session, packetRelayEndpoint), self()); return packetRelayEndpoint; } @@ -286,14 +310,26 @@ public void onReceive(final Object message) throws Exception { sender.tell(new MediaGatewayResponse(endpoint), self); } else if (DestroyConnection.class.equals(klass)) { final DestroyConnection request = (DestroyConnection) message; + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Connection destroyed, path %s",request.connection().path()); + logger.info(msg); + } monitoringService.tell(new MgcpConnectionDeleted(request.connection()), self()); context.stop(request.connection()); } else if (DestroyLink.class.equals(klass)) { final DestroyLink request = (DestroyLink) message; + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Link destroyed, path %s",request.link().path()); + logger.info(msg); + } monitoringService.tell(new MgcpLinkDeleted(request.link()), self()); context.stop(request.link()); } else if (DestroyEndpoint.class.equals(klass)) { final DestroyEndpoint request = (DestroyEndpoint) message; + if (logger.isInfoEnabled()) { + String msg = String.format("MockMediaGateway, Endpoint destroyed, path %s",request.endpoint().path()); + logger.info(msg); + } monitoringService.tell(new MgcpEndpointDeleted(request.endpoint()), self()); context.stop(request.endpoint()); } else if (message instanceof JainMgcpCommandEvent) { diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java index f2791d0f57..0c2fdbc03a 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java @@ -5,18 +5,18 @@ public class MgcpEndpointAdded { private final MediaSession session; - private final ActorRef connection; + private final ActorRef endpoint; - public MgcpEndpointAdded (MediaSession session, ActorRef connection) { + public MgcpEndpointAdded (MediaSession session, ActorRef endpoint) { this.session = session; - this.connection = connection; + this.endpoint = endpoint; } public MediaSession getSession () { return session; } - public ActorRef getConnection () { - return connection; + public ActorRef getEndpoint () { + return endpoint; } } diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java index a223e0ee0d..f787571d5a 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointDeleted.java @@ -3,13 +3,13 @@ import akka.actor.ActorRef; public class MgcpEndpointDeleted { - private final ActorRef connection; + private final ActorRef endpoint; - public MgcpEndpointDeleted (ActorRef connection) { - this.connection = connection; + public MgcpEndpointDeleted (ActorRef endpoint) { + this.endpoint = endpoint; } - public ActorRef getConnection () { - return connection; + public ActorRef getEndpoint () { + return endpoint; } } diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java index 4321bdcf82..7225e1bf73 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkAdded.java @@ -5,18 +5,18 @@ public class MgcpLinkAdded { private final MediaSession session; - private final ActorRef connection; + private final ActorRef link; - public MgcpLinkAdded (MediaSession session, ActorRef connection) { + public MgcpLinkAdded (MediaSession session, ActorRef link) { this.session = session; - this.connection = connection; + this.link = link; } public MediaSession getSession () { return session; } - public ActorRef getConnection () { - return connection; + public ActorRef getLink () { + return link; } } diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java index dc328cd8c4..fb77cc676b 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpLinkDeleted.java @@ -3,13 +3,13 @@ import akka.actor.ActorRef; public class MgcpLinkDeleted { - private final ActorRef connection; + private final ActorRef link; - public MgcpLinkDeleted (ActorRef connection) { - this.connection = connection; + public MgcpLinkDeleted (ActorRef link) { + this.link = link; } - public ActorRef getConnection () { - return connection; + public ActorRef getLink () { + return link; } } diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java index b891d4bcaf..faf6c9267b 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java @@ -193,19 +193,19 @@ public void onReceive(Object message) throws Exception { } else if (MgcpEndpointAdded.class.equals(klass)) { MgcpEndpointAdded mgcpEndpointAdded = (MgcpEndpointAdded)message; mgcpEndpoints.incrementAndGet(); - mgcpEndpointMap.put(mgcpEndpointAdded.getConnection(), mgcpEndpointAdded.getSession()); + mgcpEndpointMap.put(mgcpEndpointAdded.getEndpoint(), mgcpEndpointAdded.getSession()); } else if (MgcpEndpointDeleted.class.equals(klass)) { MgcpEndpointDeleted mgcpEndpointDeleted = (MgcpEndpointDeleted)message; mgcpEndpoints.decrementAndGet(); - mgcpEndpointMap.remove(mgcpEndpointDeleted.getConnection()); + mgcpEndpointMap.remove(mgcpEndpointDeleted.getEndpoint()); } else if (MgcpLinkAdded.class.equals(klass)) { MgcpLinkAdded mgcpLinkAdded = (MgcpLinkAdded)message; mgcpLinks.incrementAndGet(); - mgcpLinkMap.put(mgcpLinkAdded.getConnection(), mgcpLinkAdded.getSession()); + mgcpLinkMap.put(mgcpLinkAdded.getLink(), mgcpLinkAdded.getSession()); } else if (MgcpLinkDeleted.class.equals(klass)) { MgcpLinkDeleted mgcpLinkDeleted = (MgcpLinkDeleted)message; mgcpLinks.decrementAndGet(); - mgcpLinkMap.remove(mgcpLinkDeleted.getConnection()); + mgcpLinkMap.remove(mgcpLinkDeleted.getLink()); } } From e3734aee36b9757f2cf0d13c09c0bffa71e70532 Mon Sep 17 00:00:00 2001 From: George Vagenas Date: Wed, 4 Oct 2017 12:02:09 +0300 Subject: [PATCH 07/15] Patch to monitor MGCP resources and be able to track MGCP resources leak This close RESTCOMM-1155 --- .../connect/mgcp/MockMediaGateway.java | 8 +- .../connect/mgcp/stats/MgcpEndpointAdded.java | 11 ++- .../monitoringservice/MonitoringMetrics.java | 6 +- .../monitoringservice/MonitoringService.java | 88 +++++++++++-------- restcomm/restcomm.testsuite/pom.xml | 9 +- .../telephony/TestMgcpOperations.java | 16 ++++ 6 files changed, 96 insertions(+), 42 deletions(-) diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java index 91f1d5c6eb..d7bb1c120e 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/MockMediaGateway.java @@ -139,7 +139,7 @@ public Actor create() throws Exception { String msg = String.format("MockMediaGateway, Added Bridge endpoint, path: %s",bridgeEndpoint.path()); logger.info(msg); } - monitoringService.tell(new MgcpEndpointAdded(session, bridgeEndpoint), self()); + monitoringService.tell(new MgcpEndpointAdded(session, bridgeEndpoint, MgcpEndpointAdded.Type.BRIDGE), self()); return bridgeEndpoint; } @@ -164,7 +164,7 @@ public UntypedActor create() throws Exception { String msg = String.format("MockMediaGateway, Added Conference endpoint, path: %s", conferenceEndpoint.path()); logger.info(msg); } - monitoringService.tell(new MgcpEndpointAdded(session, conferenceEndpoint), self()); + monitoringService.tell(new MgcpEndpointAdded(session, conferenceEndpoint, MgcpEndpointAdded.Type.CONFERENCE), self()); return conferenceEndpoint; } @@ -191,7 +191,7 @@ public UntypedActor create() throws Exception { String msg = String.format("MockMediaGateway, Added Ivr endpoint, path: %s",ivrEndpoint.path()); logger.info(msg); } - monitoringService.tell(new MgcpEndpointAdded(session, ivrEndpoint), self()); + monitoringService.tell(new MgcpEndpointAdded(session, ivrEndpoint, MgcpEndpointAdded.Type.IVR), self()); return ivrEndpoint; } @@ -233,7 +233,7 @@ public UntypedActor create() throws Exception { String msg = String.format("MockMediaGateway, Added PacketRelay endpoint, path: %s",packetRelayEndpoint.path()); logger.info(msg); } - monitoringService.tell(new MgcpEndpointAdded(session, packetRelayEndpoint), self()); + monitoringService.tell(new MgcpEndpointAdded(session, packetRelayEndpoint, MgcpEndpointAdded.Type.PACKETRELAY), self()); return packetRelayEndpoint; } diff --git a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java index 0c2fdbc03a..4caf16d96a 100644 --- a/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java +++ b/restcomm/restcomm.mgcp/src/main/java/org/restcomm/connect/mgcp/stats/MgcpEndpointAdded.java @@ -4,12 +4,17 @@ import org.restcomm.connect.mgcp.MediaSession; public class MgcpEndpointAdded { + public enum Type { + BRIDGE, IVR, PACKETRELAY, CONFERENCE + }; private final MediaSession session; private final ActorRef endpoint; + private final Type type; - public MgcpEndpointAdded (MediaSession session, ActorRef endpoint) { + public MgcpEndpointAdded (MediaSession session, ActorRef endpoint, Type type) { this.session = session; this.endpoint = endpoint; + this.type = type; } public MediaSession getSession () { @@ -19,4 +24,8 @@ public MediaSession getSession () { public ActorRef getEndpoint () { return endpoint; } + + public Type getType () { + return type; + } } diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java index a92c5b93fc..a214a035c6 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringMetrics.java @@ -27,7 +27,11 @@ public class MonitoringMetrics { public static String COUNTERS_MAP_TEXT_MESSAGE_INBOUND_TO_PROXY_OUT="TextMessageInboundToProxyOut"; public static String COUNTERS_MAP_TEXT_MESSAGE_NOT_FOUND="TextMessageNotFound"; public static String COUNTERS_MAP_TEXT_MESSAGE_OUTBOUND="TextMessageOutbound"; - public static String COUNTERS_MAP_MGCP_ENDPOINTS="MgcpEndpoints"; public static String COUNTERS_MAP_MGCP_CONNECTIONS="MgcpConnections"; public static String COUNTERS_MAP_MGCP_LINKS="MgcpLinks"; + public static String COUNTERS_MAP_MGCP_ENDPOINTS="MgcpEndpoints"; + public static String COUNTERS_MAP_MGCP_ENDPOINTS_BRIDGE="MgcpEndpointsBridge"; + public static String COUNTERS_MAP_MGCP_ENDPOINTS_IVR="MgcpEndpointsIvr"; + public static String COUNTERS_MAP_MGCP_ENDPOINTS_PACKETRELAY="MgcpEndpointsPacketRelay"; + public static String COUNTERS_MAP_MGCP_ENDPOINTS_CONFERENCE="MgcpEndpointsConference"; } diff --git a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java index faf6c9267b..0a79486e13 100644 --- a/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java +++ b/restcomm/restcomm.monitoring.service/src/main/java/org/restcomm/connect/monitoringservice/MonitoringService.java @@ -93,9 +93,13 @@ public class MonitoringService extends RestcommUntypedActor { private final AtomicInteger maxConcurrentOutgoingCalls; private final AtomicInteger mgcpEndpoints; + private final AtomicInteger mgcpEndpointsBridge; + private final AtomicInteger mgcpEndpointsIvr; + private final AtomicInteger mgcpEndpointsConference; + private final AtomicInteger mgcpEndpointsPacketRelay; private final AtomicInteger mgcpLinks; private final AtomicInteger mgcpConnections; - private final Map mgcpEndpointMap; + private final Map mgcpEndpointMap; private final Map mgcpLinkMap; private final Map mgcpConnectionMap; @@ -132,10 +136,14 @@ public MonitoringService(final DaoManager daoManager) { maxConcurrentOutgoingCalls = new AtomicInteger(0); mgcpEndpoints = new AtomicInteger(0); + mgcpEndpointsBridge = new AtomicInteger(0); + mgcpEndpointsIvr = new AtomicInteger(0); + mgcpEndpointsConference = new AtomicInteger(0); + mgcpEndpointsPacketRelay = new AtomicInteger(0); mgcpLinks = new AtomicInteger(0); mgcpConnections = new AtomicInteger(0); - mgcpEndpointMap = new ConcurrentHashMap(); + mgcpEndpointMap = new ConcurrentHashMap(); mgcpLinkMap = new ConcurrentHashMap(); mgcpConnectionMap = new ConcurrentHashMap(); @@ -185,6 +193,7 @@ public void onReceive(Object message) throws Exception { } else if (MgcpConnectionAdded.class.equals(klass)) { MgcpConnectionAdded mgcpConnectionAdded = (MgcpConnectionAdded)message; mgcpConnections.incrementAndGet(); + mgcpConnectionMap.put(mgcpConnectionAdded.getConnection(), mgcpConnectionAdded.getSession()); } else if (MgcpConnectionDeleted.class.equals(klass)) { MgcpConnectionDeleted mgcpConnectionDeleted = (MgcpConnectionDeleted)message; @@ -193,11 +202,44 @@ public void onReceive(Object message) throws Exception { } else if (MgcpEndpointAdded.class.equals(klass)) { MgcpEndpointAdded mgcpEndpointAdded = (MgcpEndpointAdded)message; mgcpEndpoints.incrementAndGet(); - mgcpEndpointMap.put(mgcpEndpointAdded.getEndpoint(), mgcpEndpointAdded.getSession()); + switch (mgcpEndpointAdded.getType()) { + case IVR: + mgcpEndpointsIvr.incrementAndGet(); + break; + case BRIDGE: + mgcpEndpointsBridge.incrementAndGet(); + break; + case CONFERENCE: + mgcpEndpointsConference.incrementAndGet(); + break; + case PACKETRELAY: + mgcpEndpointsPacketRelay.incrementAndGet(); + break; + default: + break; + } + mgcpEndpointMap.put(mgcpEndpointAdded.getEndpoint(), mgcpEndpointAdded.getType()); } else if (MgcpEndpointDeleted.class.equals(klass)) { MgcpEndpointDeleted mgcpEndpointDeleted = (MgcpEndpointDeleted)message; mgcpEndpoints.decrementAndGet(); - mgcpEndpointMap.remove(mgcpEndpointDeleted.getEndpoint()); + MgcpEndpointAdded.Type type = mgcpEndpointMap.remove(mgcpEndpointDeleted.getEndpoint()); + switch (type) { + case IVR: + mgcpEndpointsIvr.decrementAndGet(); + break; + case BRIDGE: + mgcpEndpointsBridge.decrementAndGet(); + break; + case CONFERENCE: + mgcpEndpointsConference.decrementAndGet(); + break; + case PACKETRELAY: + mgcpEndpointsPacketRelay.decrementAndGet(); + break; + default: + break; + } + } else if (MgcpLinkAdded.class.equals(klass)) { MgcpLinkAdded mgcpLinkAdded = (MgcpLinkAdded)message; mgcpLinks.incrementAndGet(); @@ -209,36 +251,6 @@ public void onReceive(Object message) throws Exception { } } -// private void processMgcpConnectionAdded(final MgcpConnectionAdded mgcpConnectionAdded) { -// mgcpConnections.incrementAndGet(); -// mgcpConnectionMap.put(mgcpConnectionAdded.getConnection(), mgcpConnectionAdded.getSession()); -// } -// -// private void processMgcpConnectionDeleted(final MgcpConnectionDeleted mgcpConnectionDeleted) { -// mgcpConnections.decrementAndGet(); -// mgcpConnectionMap.remove(mgcpConnectionDeleted.getConnection()); -// } -// -// private void processMgcpEndpointAdded(final MgcpEndpointAdded mgcpEndpointAdded) { -// mgcpEndpoints.incrementAndGet(); -// mgcpConnectionMap.remove(mgcpConnectionDeleted.getConnection()); -// } -// -// private void processMgcpEndpointDeleted(final MgcpEndpointDeleted mgcpEndpointDeleted) { -// mgcpEndpoints.decrementAndGet(); -// mgcpEndpointMap.remove(mgcpEndpointDeleted.getConnection()); -// } -// -// private void processMgcpLinkAdded(final MgcpLinkAdded mgcpLinkAdded) { -// mgcpLinks.incrementAndGet(); -// mgcpLinkMap.put(mgcpLinkAdded.getConnection(), mgcpLinkAdded.getSession()); -// } -// -// private void processMgcpLinkDeleted(final MgcpLinkDeleted mgcpLinkDeleted) { -// mgcpLinks.decrementAndGet(); -// mgcpLinkMap.remove(mgcpLinkDeleted.getConnection()); -// } - private void onGetCall(Object message, ActorRef self, ActorRef sender) throws ServletParseException { GetCall getCall = (GetCall)message; String location = getCall.getIdentifier(); @@ -509,9 +521,15 @@ private void onGetStatistics (GetStatistics message, ActorRef self, ActorRef sen countersMap.put(MonitoringMetrics.COUNTERS_MAP_TEXT_MESSAGE_OUTBOUND, textOutbound.get()); if (message.isWithMgcpStats()) { - countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS, mgcpEndpoints.get()); countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_CONNECTIONS, mgcpConnections.get()); countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_LINKS, mgcpLinks.get()); + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS, mgcpEndpoints.get()); + if (mgcpEndpoints.get()>0) { + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS_BRIDGE, mgcpEndpointsBridge.get()); + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS_IVR, mgcpEndpointsIvr.get()); + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS_CONFERENCE, mgcpEndpointsConference.get()); + countersMap.put(MonitoringMetrics.COUNTERS_MAP_MGCP_ENDPOINTS_PACKETRELAY, mgcpEndpointsPacketRelay.get()); + } } MonitoringServiceResponse callInfoList = null; diff --git a/restcomm/restcomm.testsuite/pom.xml b/restcomm/restcomm.testsuite/pom.xml index 64ef607b4e..a21753bcd1 100644 --- a/restcomm/restcomm.testsuite/pom.xml +++ b/restcomm/restcomm.testsuite/pom.xml @@ -278,7 +278,7 @@ mockito-all 1.8.5 test - +