Revision: 15088
Author: [email protected]
Date: Sun Nov  7 22:30:09 2010
Log: Added AUEP Command. Yet to take care of InfoCodes.
http://code.google.com/p/mobicents/issues/detail?id=1890
http://code.google.com/p/mobicents/source/detail?r=15088

Added:
/trunk/servers/media/core/controllers/mgcp/src/main/java/org/mobicents/media/server/ctrl/mgcp/AuditEndpointAction.java /trunk/servers/media/core/server-impl/src/test/java/org/mobicents/media/server/impl/naming/InnerNamingServiceTestCase.java
Modified:
/trunk/servers/media/core/controllers/mgcp/src/main/java/org/mobicents/media/server/ctrl/mgcp/MgcpController.java /trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/Server.java /trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/impl/naming/InnerNamingService.java /trunk/servers/media/core/server-spi/src/main/java/org/mobicents/media/server/spi/MediaServer.java

=======================================
--- /dev/null
+++ /trunk/servers/media/core/controllers/mgcp/src/main/java/org/mobicents/media/server/ctrl/mgcp/AuditEndpointAction.java Sun Nov 7 22:30:09 2010
@@ -0,0 +1,106 @@
+package org.mobicents.media.server.ctrl.mgcp;
+
+import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
+import jain.protocol.ip.mgcp.message.AuditEndpoint;
+import jain.protocol.ip.mgcp.message.AuditEndpointResponse;
+import jain.protocol.ip.mgcp.message.parms.EndpointIdentifier;
+import jain.protocol.ip.mgcp.message.parms.InfoCode;
+import jain.protocol.ip.mgcp.message.parms.ReturnCode;
+
+import java.util.concurrent.Callable;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.mobicents.media.server.spi.Endpoint;
+import org.mobicents.media.server.spi.ResourceUnavailableException;
+
+/**
+ *
+ * @author amit bhayani
+ *
+ */
+public class AuditEndpointAction implements Callable {
+
+       private AuditEndpoint auep;
+       private MgcpController controller;
+
+       private String domainName = null;
+
+ private static Logger logger = Logger.getLogger(AuditConnectionAction.class);
+
+ protected AuditEndpointAction(MgcpController controller, AuditEndpoint req) {
+               this.controller = controller;
+               this.auep = req;
+
+ this.domainName = controller.getBindAddress() + ":" + controller.getPort();
+       }
+
+       public JainMgcpResponseEvent call() throws Exception {
+               InfoCode[] infCodes = auep.getRequestedInfo();
+               int txID = auep.getTransactionHandle();
+               String localName = 
auep.getEndpointIdentifier().getLocalEndpointName();
+
+               if (logger.isDebugEnabled()) {
+ logger.debug("AUEP Request TX= " + txID + ", endpt =" + auep.getEndpointIdentifier());
+                       StringBuffer s = new StringBuffer();
+                       for (InfoCode infCd : infCodes) {
+                               s.append(infCd.toString());
+                               s.append(",");
+                       }
+                       logger.debug("InfoCode[] = " + s.toString());
+               }
+
+               if (localName.contains("$")) {
+                       if (logger.isEnabledFor(Level.WARN)) {
+                               logger.warn("TX = " + txID
+ + ", The endpoint name is underspecified with 'any' wildcard, Response code: "
+                                               + ReturnCode.ENDPOINT_UNKNOWN);
+                       }
+ return new AuditEndpointResponse(auep.getSource(), ReturnCode.Endpoint_Unknown);
+               }
+
+               Endpoint[] endpoints = null;
+               if (localName.contains("*")) {
+ // retrieve all Endpoints that match this localName and return back the AUEP Response. Ignore the InfoCode[]
+                       // if any passed.
+                       // lookup endpoints
+                       try {
+                               endpoints = 
controller.getServer().lookupall(localName);
+                       } catch (ResourceUnavailableException e) {
+                               if (logger.isEnabledFor(Level.ERROR)) {
+ logger.error("TX = " + txID + ", There is no free endpoint: " + localName + ", ResponseCode: "
+                                                       + 
ReturnCode.ENDPOINT_UNKNOWN);
+                               }
+ return new AuditEndpointResponse(auep.getSource(), ReturnCode.Endpoint_Unknown);
+                       }
+
+                       if (endpoints == null) {
+ return new AuditEndpointResponse(auep.getSource(), ReturnCode.Endpoint_Unknown);
+                       }
+
+ EndpointIdentifier[] endpointIdentifierList = new EndpointIdentifier[endpoints.length];
+                       for (int i = 0; i < endpoints.length; i++) {
+ endpointIdentifierList[i] = new EndpointIdentifier(endpoints[i].getLocalName(), this.domainName);
+                       }
+
+ return new AuditEndpointResponse(auep.getSource(), ReturnCode.Transaction_Executed_Normally,
+                                       endpointIdentifierList);
+               }
+
+               Endpoint endpoint = null;
+               //Audit specific endpoint.
+               try {
+                       endpoint = controller.getServer().lookup(localName, 
true);
+               } catch (ResourceUnavailableException e) {
+                       if (logger.isEnabledFor(Level.ERROR)) {
+ logger.error("TX = " + txID + ", There is no free endpoint: " + localName + ", ResponseCode: "
+                                               + ReturnCode.ENDPOINT_UNKNOWN);
+                       }
+ return new AuditEndpointResponse(auep.getSource(), ReturnCode.Endpoint_Unknown);
+               }
+
+               //TODO : Take care of InfoCode[]
+ return new AuditEndpointResponse(auep.getSource(), ReturnCode.Transaction_Executed_Normally);
+       }
+
+}
=======================================
--- /dev/null
+++ /trunk/servers/media/core/server-impl/src/test/java/org/mobicents/media/server/impl/naming/InnerNamingServiceTestCase.java Sun Nov 7 22:30:09 2010
@@ -0,0 +1,189 @@
+package org.mobicents.media.server.impl.naming;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mobicents.media.MediaSink;
+import org.mobicents.media.MediaSource;
+import org.mobicents.media.server.spi.Connection;
+import org.mobicents.media.server.spi.Endpoint;
+import org.mobicents.media.server.spi.EndpointState;
+import org.mobicents.media.server.spi.MediaType;
+import org.mobicents.media.server.spi.NotificationListener;
+import org.mobicents.media.server.spi.ResourceUnavailableException;
+import org.mobicents.media.server.spi.TooManyConnectionsException;
+
+/**
+ *
+ * @author amit bhayani
+ *
+ */
+public class InnerNamingServiceTestCase {
+
+       private InnerNamingService innerNamingService = null;
+
+       public InnerNamingServiceTestCase() {
+       }
+
+       @BeforeClass
+       public static void setUpClass() throws Exception {
+       }
+
+       @AfterClass
+       public static void tearDownClass() throws Exception {
+       }
+
+       @Before
+       public void setUp() throws ResourceUnavailableException {
+               innerNamingService = new InnerNamingService();
+
+               for (int i = 0; i < 9; i++) {
+ innerNamingService.addEndpoint(new EndpointImpl("/mobicents/media/aap/" + i, EndpointState.BUSY));
+               }
+ innerNamingService.addEndpoint(new EndpointImpl("/mobicents/media/aap/9", EndpointState.READY));
+       }
+
+       @After
+       public void tearDown() {
+       }
+
+       /**
+        * Test of parse method, of class NameParser.
+        */
+       @Test
+       public void testFindAny() {
+               try {
+ Endpoint endPt = innerNamingService.lookup("/mobicents/media/aap/$", false);
+                       assertNotNull(endPt);
+                       assertEquals("/mobicents/media/aap/9", 
endPt.getLocalName());
+               } catch (ResourceUnavailableException e) {
+                       e.printStackTrace();
+                       assertTrue("Failed to get free endpoint: " + e, false);
+               }
+       }
+
+       @Test
+       public void testFindSpecificFree() {
+               try {
+ Endpoint endPt = innerNamingService.lookup("/mobicents/media/aap/9", false);
+                       assertNotNull(endPt);
+                       assertEquals("/mobicents/media/aap/9", 
endPt.getLocalName());
+                       assertEquals(EndpointState.READY, endPt.getState());
+               } catch (ResourceUnavailableException e) {
+                       e.printStackTrace();
+                       assertTrue("Failed to get free endpoint: " + e, false);
+               }
+
+               Endpoint endPt = null;
+               try {
+                       endPt = 
innerNamingService.lookup("/mobicents/media/aap/8", false);
+                       assertNull(endPt);
+               } catch (ResourceUnavailableException e) {
+                       //expected
+ assertTrue("Exception raised when looking up BUSY Endpoint but wanting free ", true);
+               }
+       }
+
+       @Test
+       public void testFindSpecificBusy() {
+               try {
+ Endpoint endPt = innerNamingService.lookup("/mobicents/media/aap/8", true);
+                       assertNotNull(endPt);
+                       assertEquals("/mobicents/media/aap/8", 
endPt.getLocalName());
+                       assertEquals(EndpointState.BUSY, endPt.getState());
+               } catch (ResourceUnavailableException e) {
+                       e.printStackTrace();
+                       assertTrue("Failed to get free endpoint: " + e, false);
+               }
+
+               try {
+ Endpoint endPt = innerNamingService.lookup("/mobicents/media/aap/9", true);
+                       assertNotNull(endPt);
+                       assertEquals("/mobicents/media/aap/9", 
endPt.getLocalName());
+                       assertEquals(EndpointState.READY, endPt.getState());
+               } catch (ResourceUnavailableException e) {
+                       e.printStackTrace();
+                       assertTrue("Failed to get free endpoint: " + e, false);
+               }
+       }
+
+       @Test
+       public void testFindAll() throws ResourceUnavailableException {
+ Endpoint[] endpoints = innerNamingService.lookupall("/mobicents/media/aap/*");
+                assertNotNull(endpoints);
+                assertEquals(10, endpoints.length);
+
+       }
+
+       class EndpointImpl implements Endpoint {
+
+               private String localName = null;
+               private EndpointState state;
+
+               EndpointImpl(String localName, EndpointState state) {
+                       this.localName = localName;
+                       this.state = state;
+               }
+
+               public void addNotificationListener(NotificationListener 
listener) {
+               }
+
+ public Connection createConnection() throws TooManyConnectionsException, ResourceUnavailableException {
+                       return null;
+               }
+
+ public Connection createLocalConnection() throws TooManyConnectionsException, ResourceUnavailableException {
+                       return null;
+               }
+
+               public void deleteAllConnections() {
+               }
+
+               public void deleteConnection(String connectionID) {
+
+               }
+
+ public String describe(MediaType mediaType) throws ResourceUnavailableException {
+                       return null;
+               }
+
+               public String getLocalName() {
+                       return localName;
+               }
+
+               public Collection<MediaType> getMediaTypes() {
+                       return null;
+               }
+
+               public MediaSink getSink(MediaType media) {
+                       return null;
+               }
+
+               public MediaSource getSource(MediaType media) {
+                       return null;
+               }
+
+               public EndpointState getState() {
+                       return state;
+               }
+
+               public void removeNotificationListener(NotificationListener 
listener) {
+               }
+
+               public void start() throws ResourceUnavailableException {
+               }
+
+               public void stop() {
+               }
+
+       }
+}
=======================================
--- /trunk/servers/media/core/controllers/mgcp/src/main/java/org/mobicents/media/server/ctrl/mgcp/MgcpController.java Tue Jul 6 22:34:57 2010 +++ /trunk/servers/media/core/controllers/mgcp/src/main/java/org/mobicents/media/server/ctrl/mgcp/MgcpController.java Sun Nov 7 22:30:09 2010
@@ -25,6 +25,7 @@
 import jain.protocol.ip.mgcp.JainMgcpProvider;
 import jain.protocol.ip.mgcp.JainMgcpResponseEvent;
 import jain.protocol.ip.mgcp.message.AuditConnection;
+import jain.protocol.ip.mgcp.message.AuditEndpoint;
 import jain.protocol.ip.mgcp.message.Constants;
 import jain.protocol.ip.mgcp.message.CreateConnection;
 import jain.protocol.ip.mgcp.message.DeleteConnection;
@@ -49,6 +50,7 @@
 import org.mobicents.protocols.mgcp.stack.JainMgcpStackImpl;

 /**
+ * @author amit bhayani
  * @author baranowb
  * @author kulikov
  */
@@ -211,6 +213,9 @@
             case Constants.CMD_AUDIT_CONNECTION:
action = new AuditConnectionAction(this, (AuditConnection)evt );
                break;
+            case Constants.CMD_AUDIT_ENDPOINT:
+               action = new AuditEndpointAction(this, (AuditEndpoint)evt );
+               break;
             default:
                 logger.error("Unknown message type: " + eventID);
                 return;
=======================================
--- /trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/Server.java Wed Jun 30 09:26:03 2010 +++ /trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/Server.java Sun Nov 7 22:30:09 2010
@@ -119,6 +119,10 @@
public Endpoint lookup(String name, boolean bussy) throws ResourceUnavailableException {
         return namingService.lookup(name, bussy);
     }
+
+ public Endpoint[] lookupall(String endpointName) throws ResourceUnavailableException {
+       return namingService.lookupall(endpointName);
+    }

     public int getEndpointCount() {
         return namingService.getEndpointCount();
=======================================
--- /trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/impl/naming/InnerNamingService.java Fri Jun 25 05:30:54 2010 +++ /trunk/servers/media/core/server-impl/src/main/java/org/mobicents/media/server/impl/naming/InnerNamingService.java Sun Nov 7 22:30:09 2010
@@ -21,6 +21,7 @@
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Set;

 import org.apache.log4j.Logger;
@@ -39,6 +40,8 @@

private HashMap<String, Endpoint> endpoints = new HashMap<String, Endpoint>();

+    private List<Endpoint> tempEndpoints = new ArrayList<Endpoint>();
+
     private int endpointCount = 0;
private final static Logger logger = Logger.getLogger(InnerNamingService.class);

@@ -85,6 +88,36 @@
         }
     // return null;
     }
+
+ public Endpoint[] lookupall(String endpointName) throws ResourceUnavailableException {
+        if (endpointName.endsWith("*")) {
+            return findAll(endpointName); // findAny(endpointName);
+        } else {
+            return null;
+        }
+    // return null;
+    }
+
+ public synchronized Endpoint[] findAll(String name) throws ResourceUnavailableException {
+
+        Endpoint[] endpts = null;
+        String prefix = name.substring(0, name.indexOf("*") - 1);
+        Set<String> keys = endpoints.keySet();
+        for (String key : keys) {
+            if (key.startsWith(prefix)) {
+               tempEndpoints.add(endpoints.get(key));
+            }
+        } // end of for
+
+        if(tempEndpoints.size() > 0){
+               endpts = new Endpoint[tempEndpoints.size()];
+               endpts = tempEndpoints.toArray(endpts);
+               tempEndpoints.clear();
+               return endpts;
+        } else
+
+        return null;
+    }

public synchronized Endpoint findAny(String name) throws ResourceUnavailableException {
         // TODO : Can name have two '$'? In this case the search will be
@@ -131,7 +164,7 @@
         if (endpt == null) {
throw new ResourceUnavailableException("No Endpoint found for " + name);
         }
-        if (endpt.getState() == EndpointState.READY && !allowInUse) {
+        if (endpt.getState() == EndpointState.BUSY && !allowInUse) {
throw new ResourceUnavailableException("Endpoint " + name + " is in use");
         } else {
 //            endpt.setInUse(true);
=======================================
--- /trunk/servers/media/core/server-spi/src/main/java/org/mobicents/media/server/spi/MediaServer.java Fri Jun 25 05:29:07 2010 +++ /trunk/servers/media/core/server-spi/src/main/java/org/mobicents/media/server/spi/MediaServer.java Sun Nov 7 22:30:09 2010
@@ -20,7 +20,7 @@
 import org.mobicents.media.server.spi.rtp.RtpManager;

 /**
- *
+ * @author amit bhayani
  * @author kulikov
  */
 public interface MediaServer {
@@ -29,5 +29,6 @@
     public RtpManager getRtpManager();

public Endpoint lookup(String name, boolean bussy) throws ResourceUnavailableException; + public Endpoint[] lookupall(String endpointName) throws ResourceUnavailableException;
     public int getEndpointCount();
 }

Reply via email to