-
Notifications
You must be signed in to change notification settings - Fork 212
Restcomm1147 rms resources leak on conf #2564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
6ab2108
Work in progress for RESTCOMM-1147, RMS resources leak
gvagenas 7a988ed
Fixes for SmsTest
gvagenas e9d3923
Merge branch 'master' into restcomm1147_rms_resources_leak_on_conf
gvagenas 110a6a2
Code cleanup.
gvagenas 2cb0698
Work in progress for MgcpMonitoringService
gvagenas 644664b
Merge branch 'issue1155_MgcpMonitoringService' into restcomm1147_rms_…
gvagenas 0355b20
Work in progress for MgcpMonitoringService
gvagenas e89b53e
Work in progress for MgcpMonitoring service
gvagenas e3734ae
Patch to monitor MGCP resources and be able to track MGCP resources leak
gvagenas e17ded6
Merge branch 'master' into restcomm1147_rms_resources_leak_on_conf
gvagenas fe49c02
Work in progress to remove endpoints on connection destroy
gvagenas aaebb11
Merge branch 'restcomm1158_removeEndpoints_onConnectionDestroy' into …
gvagenas b2b3ae5
Patch to remove endpoints on connection destroy
gvagenas 804ba65
Patch for DialConferenceTest
gvagenas 3164114
Addition to DialConferenceTest to assert MOH is properly stopped.
gvagenas b03a9e7
Testsuite enhancements for checking MGCP resources at the end of the …
gvagenas fba78b9
Patch to properly cleanup MGCP resources for Failed Calls
gvagenas 2c69abf
Enhancements to testsuite for DialActionTest and DialForkTest to asse…
gvagenas 5255baa
Merge branch 'master' of github.com:RestComm/Restcomm-Connect
gvagenas 5345768
Merge branch 'master' into restcomm1147_rms_resources_leak_on_conf
gvagenas 0e7dc36
Code cleanup and added comments
gvagenas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,11 +49,16 @@ | |
| 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 javax.sdp.SdpFactory; | ||
| import javax.sdp.SdpParseException; | ||
| import javax.sdp.SessionDescription; | ||
| import java.net.InetAddress; | ||
| import java.util.Collections; | ||
| import java.util.Map; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
|
|
@@ -89,30 +94,16 @@ public class MockMediaGateway extends RestcommUntypedActor { | |
| private RevolvingCounter connectionIdPool; | ||
| private RevolvingCounter endpointIdPool; | ||
|
|
||
| private static Map<MediaSession, ActorRef> endpoints; | ||
| private static Map<MediaSession, ActorRef> links; | ||
| private static Map<MediaSession, ActorRef> connections; | ||
| private Map<String, String> connEndpointMap; | ||
|
|
||
| private ActorRef monitoringService; | ||
|
|
||
| private ActorSystem system; | ||
|
|
||
| public MockMediaGateway() { | ||
| super(); | ||
| endpoints = new ConcurrentHashMap<MediaSession, ActorRef>(); | ||
| links = new ConcurrentHashMap<MediaSession, ActorRef>(); | ||
| connections = new ConcurrentHashMap<MediaSession, ActorRef>(); | ||
| system = context().system(); | ||
| } | ||
|
|
||
| public static Map<MediaSession, ActorRef> getEndpointsMap() { | ||
| return endpoints; | ||
| } | ||
|
|
||
| public static Map<MediaSession, ActorRef> getConnections() { | ||
| return connections; | ||
| } | ||
|
|
||
| public static Map<MediaSession, ActorRef> getLinks() { | ||
| return links; | ||
| connEndpointMap = new ConcurrentHashMap<String, String>(); | ||
| } | ||
|
|
||
| private ActorRef getConnection(final Object message) { | ||
|
|
@@ -127,7 +118,10 @@ public UntypedActor create() throws Exception { | |
| } | ||
| }); | ||
| ActorRef connection = system.actorOf(props); | ||
| connections.put(session, connection); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Added new Connection, path: %s",connection.path()); | ||
| logger.info(msg); | ||
| } | ||
| return connection; | ||
| } | ||
|
|
||
|
|
@@ -144,7 +138,10 @@ public Actor create() throws Exception { | |
| } | ||
| }); | ||
| ActorRef bridgeEndpoint = system.actorOf(props); | ||
| endpoints.put(session, bridgeEndpoint); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Added Bridge endpoint, path: %s",bridgeEndpoint.path()); | ||
| logger.info(msg); | ||
| } | ||
| return bridgeEndpoint; | ||
| } | ||
|
|
||
|
|
@@ -165,7 +162,10 @@ public UntypedActor create() throws Exception { | |
| } | ||
| }); | ||
| ActorRef conferenceEndpoint = system.actorOf(props); | ||
| endpoints.put(session, conferenceEndpoint); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Added Conference endpoint, path: %s", conferenceEndpoint.path()); | ||
| logger.info(msg); | ||
| } | ||
| return conferenceEndpoint; | ||
| } | ||
|
|
||
|
|
@@ -188,7 +188,10 @@ public UntypedActor create() throws Exception { | |
| } | ||
| }); | ||
| ActorRef ivrEndpoint = system.actorOf(props); | ||
| endpoints.put(session, ivrEndpoint); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Added Ivr endpoint, path: %s",ivrEndpoint.path()); | ||
| logger.info(msg); | ||
| } | ||
| return ivrEndpoint; | ||
| } | ||
|
|
||
|
|
@@ -205,7 +208,10 @@ public UntypedActor create() throws Exception { | |
| } | ||
| }); | ||
| ActorRef link = system.actorOf(props); | ||
| links.put(session, link); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Added new Link, path: %s",link.path()); | ||
| logger.info(msg); | ||
| } | ||
| return link; | ||
| } | ||
|
|
||
|
|
@@ -222,7 +228,10 @@ public UntypedActor create() throws Exception { | |
| } | ||
| }); | ||
| ActorRef packetRelayEndpoint = system.actorOf(props); | ||
| endpoints.put(session, packetRelayEndpoint); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Added PacketRelay endpoint, path: %s",packetRelayEndpoint.path()); | ||
| logger.info(msg); | ||
| } | ||
| return packetRelayEndpoint; | ||
| } | ||
|
|
||
|
|
@@ -264,6 +273,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 +308,24 @@ public void onReceive(final Object message) throws Exception { | |
| sender.tell(new MediaGatewayResponse<ActorRef>(endpoint), self); | ||
| } else if (DestroyConnection.class.equals(klass)) { | ||
| final DestroyConnection request = (DestroyConnection) message; | ||
| connections.values().remove(request.connection()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Connection destroyed, path %s",request.connection().path()); | ||
| logger.info(msg); | ||
| } | ||
| context.stop(request.connection()); | ||
| } else if (DestroyLink.class.equals(klass)) { | ||
| final DestroyLink request = (DestroyLink) message; | ||
| links.values().remove(request.link()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Link destroyed, path %s",request.link().path()); | ||
| logger.info(msg); | ||
| } | ||
| context.stop(request.link()); | ||
| } else if (DestroyEndpoint.class.equals(klass)) { | ||
| final DestroyEndpoint request = (DestroyEndpoint) message; | ||
| endpoints.values().remove(request.endpoint()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("MockMediaGateway, Endpoint destroyed, path %s",request.endpoint().path()); | ||
| logger.info(msg); | ||
| } | ||
| context.stop(request.endpoint()); | ||
| } else if (message instanceof JainMgcpCommandEvent) { | ||
| send(message, sender); | ||
|
|
@@ -336,14 +355,21 @@ private void createConnection(final Object message, final ActorRef sender) { | |
| buffer.append(endpointIdPool.get()); | ||
| endpointId = new EndpointIdentifier(buffer.toString(), domain); | ||
| } | ||
| connEndpointMap.put(connId.toString(), endpointId.getLocalEndpointName()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("About to add connId %s for endpoint %s", connId.toString(), endpointId.getLocalEndpointName()); | ||
| logger.info(msg); | ||
| } | ||
| monitoringService.tell(new MgcpEndpointAdded(connId.toString(), endpointId.getLocalEndpointName()), self()); | ||
| monitoringService.tell(new MgcpConnectionAdded(connId.toString(), endpointId.getLocalEndpointName()), self()); | ||
| response.setSpecificEndpointIdentifier(endpointId); | ||
| // Create a new secondary end point id if necessary. | ||
| EndpointIdentifier secondaryEndpointId = crcx.getSecondEndpointIdentifier(); | ||
| if (secondaryEndpointId != null) { | ||
| buffer = new StringBuilder(); | ||
| buffer.append(connectionIdPool.get()); | ||
| connId = new ConnectionIdentifier(buffer.toString()); | ||
| response.setSecondConnectionIdentifier(connId); | ||
| ConnectionIdentifier secondayConnId = new ConnectionIdentifier(buffer.toString()); | ||
| response.setSecondConnectionIdentifier(secondayConnId); | ||
| endpointName = secondaryEndpointId.getLocalEndpointName(); | ||
| if (endpointName.endsWith("$")) { | ||
| final String[] tokens = endpointName.split("/"); | ||
|
|
@@ -353,6 +379,13 @@ private void createConnection(final Object message, final ActorRef sender) { | |
| buffer.append(endpointIdPool.get()); | ||
| secondaryEndpointId = new EndpointIdentifier(buffer.toString(), domain); | ||
| } | ||
| connEndpointMap.put(secondayConnId.toString(), secondaryEndpointId.getLocalEndpointName()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("About to add connId %s for secondary endpoint %s associated with endpont %s", secondayConnId.toString(), secondaryEndpointId.getLocalEndpointName(), endpointId.getLocalEndpointName()); | ||
| logger.info(msg); | ||
| } | ||
| monitoringService.tell(new MgcpEndpointAdded(connId.toString(), secondaryEndpointId.getLocalEndpointName()), self()); | ||
| monitoringService.tell(new MgcpConnectionAdded(secondayConnId.toString(), secondaryEndpointId.getLocalEndpointName())); | ||
| response.setSecondEndpointIdentifier(secondaryEndpointId); | ||
| } | ||
| final ConnectionDescriptor descriptor = new ConnectionDescriptor(sdp); | ||
|
|
@@ -366,7 +399,11 @@ private void createConnection(final Object message, final ActorRef sender) { | |
| private void modifyConnection(final Object message, final ActorRef sender) { | ||
| final ActorRef self = self(); | ||
| final ModifyConnection mdcx = (ModifyConnection) message; | ||
| System.out.println(mdcx.toString()); | ||
| System.out.println("MDCX: \n" +mdcx.toString()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("Got MDCX for endpoint %s connId %s, mdcx: \n%s", mdcx.getEndpointIdentifier().getLocalEndpointName(), mdcx.getConnectionIdentifier(), mdcx); | ||
| logger.info(msg); | ||
| } | ||
| ReturnCode code; | ||
| SessionDescription sessionDescription = null; | ||
| boolean isNonValidSdp = false; | ||
|
|
@@ -400,6 +437,28 @@ private void modifyConnection(final Object message, final ActorRef sender) { | |
| private void deleteConnection(final Object message, final ActorRef sender) { | ||
| final ActorRef self = self(); | ||
| final DeleteConnection dlcx = (DeleteConnection) message; | ||
| if (dlcx.getConnectionIdentifier() == null) { | ||
| connEndpointMap.values().removeAll(Collections.singleton(dlcx.getEndpointIdentifier().getLocalEndpointName())); | ||
| monitoringService.tell(new MgcpConnectionDeleted(null, dlcx.getEndpointIdentifier().getLocalEndpointName()), self()); | ||
| monitoringService.tell(new MgcpEndpointDeleted(dlcx.getEndpointIdentifier().getLocalEndpointName()), self()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("Endpoint deleted %s", dlcx.getEndpointIdentifier().getLocalEndpointName()); | ||
| logger.info(msg); | ||
| } | ||
| } else { | ||
| connEndpointMap.remove(dlcx.getConnectionIdentifier().toString()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, can we save the result of this operation for logging later?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure as above |
||
| monitoringService.tell(new MgcpConnectionDeleted(dlcx.getConnectionIdentifier().toString(), null), self()); | ||
| //If all connections have been removed for a given Endpoint, we can consider that the endpoint is stopped (this is the RMS behavior) | ||
| //Here check if we have Endpoint ID on the map, and if not, tell MonitoringService that the endpoint stopped. | ||
| if (!connEndpointMap.values().contains(dlcx.getEndpointIdentifier().getLocalEndpointName())) { | ||
| monitoringService.tell(new MgcpEndpointDeleted(dlcx.getEndpointIdentifier().getLocalEndpointName()), self()); | ||
| if (logger.isInfoEnabled()) { | ||
| String msg = String.format("Endpoint deleted %s since because there are no more connections related to this endpoint", dlcx.getEndpointIdentifier().getLocalEndpointName()); | ||
| logger.info(msg); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| System.out.println(dlcx.toString()); | ||
| final ReturnCode code = ReturnCode.Transaction_Executed_Normally; | ||
| final DeleteConnectionResponse response = new DeleteConnectionResponse(self, code); | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we log the result of this operation, i think it could be worth to print it, whether we deleted something or not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jaimecasero you mean the operation to remove from the Map? Yes I can add this at the log statement later