Moving the connection manager NB-API from the network configuration APIs to connectio...
[controller.git] / opendaylight / northbound / networkconfiguration / bridgedomain / src / main / java / org / opendaylight / controller / networkconfig / bridgedomain / northbound / BridgeDomainNorthbound.java
index 6b785b80700b417351bcfcee063cee69f9c2e22c..de9219c2a2ea825ca245ce0b32253290c3d11e2a 100644 (file)
@@ -29,10 +29,10 @@ import org.opendaylight.controller.connectionmanager.IConnectionManager;
 import org.opendaylight.controller.northbound.commons.exception.NotAcceptableException;
 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
-import org.opendaylight.controller.sal.networkconfig.bridgedomain.IBridgeDomainConfigService;
 import org.opendaylight.controller.sal.connection.ConnectionConstants;
 import org.opendaylight.controller.sal.core.Node;
+import org.opendaylight.controller.sal.networkconfig.bridgedomain.ConfigConstants;
+import org.opendaylight.controller.sal.networkconfig.bridgedomain.IBridgeDomainConfigService;
 import org.opendaylight.controller.sal.utils.NetUtils;
 import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.controller.sal.utils.Status;
@@ -56,7 +56,7 @@ public class BridgeDomainNorthbound {
 
     @Context
     public void setSecurityContext(SecurityContext context) {
-        username = context.getUserPrincipal().getName();
+        if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName();
     }
     protected String getUserName() {
         return username;
@@ -72,134 +72,15 @@ public class BridgeDomainNorthbound {
                 .getGlobalInstance(IConnectionManager.class, this);
     }
 
-    /**
-     * If a Network Configuration Service needs a special Management Connection and if the
-     * Node Type is unknown, use this REST api to connect to the management session.
-     * <pre>
-     * Example :
-     * Request : PUT http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/connect/mgmt1/1.1.1.1/6634
-     * Response : Node :
-     *                  xml : &lt;node type="STUB" id="mgmt1"/&gt;
-     *                  json: {"@type": "STUB","@id": "mgmt1"}
-     *</pre>
-     * @param nodeName User-Defined name of the node to connect with. This can be any alpha numeric value
-     * @param ipAddress IP Address of the Node to connect with.
-     * @param port Layer4 Port of the management session to connect with.
-     * @return Node If the connection is successful, HTTP 404 otherwise.
-     */
-
-    @Path("/connect/{nodeName}/{ipAddress}/{port}/")
-    @PUT
-    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    @TypeHint(Node.class)
-    @StatusCodes( {
-        @ResponseCode(code = 201, condition = "Node connected successfully"),
-        @ResponseCode(code = 404, condition = "Could not connect to the Node with the specified parameters"),
-        @ResponseCode(code = 406, condition = "Invalid IP Address or Port parameter passed."),
-        @ResponseCode(code = 503, condition = "Connection Manager Service not available")} )
-    public Node connect(
-            @PathParam(value = "nodeName") String nodeName,
-            @PathParam(value = "ipAddress") String ipAddress,
-            @PathParam(value = "port") String port) {
-
-        IConnectionManager connectionManager = getConnectionManager();
-        if (connectionManager == null) {
-            throw new ServiceUnavailableException("IConnectionManager not available.");
-        }
-
-        if (!NetUtils.isIPv4AddressValid(ipAddress)) {
-            throw new NotAcceptableException("Invalid ip address "+ipAddress);
-        }
-
-        try {
-            Integer.parseInt(port);
-        } catch (Exception e) {
-            throw new NotAcceptableException("Invalid Layer4 Port "+port);
-        }
-
-        Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
-        params.put(ConnectionConstants.ADDRESS, ipAddress);
-        params.put(ConnectionConstants.PORT, port);
-
-        Node node = null;
-        try {
-            node = connectionManager.connect(nodeName, params);
-            if (node == null) {
-                throw new ResourceNotFoundException("Failed to connect to Node at "+ipAddress+":"+port);
-            }
-            return node;
-        } catch (Exception e) {
-            throw new ResourceNotFoundException(e.getMessage());
-        }
-    }
-
-    /**
-     * If a Network Configuration Service needs a special Management Connection, and if the
-     * node Type is known, the user can choose to use this REST api to connect to the management session.
-     * <pre>
-     * Example :
-     * Request : PUT http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/connect/STUB/mgmt1/1.1.1.1/6634
-     * Response : Node :
-     *                  xml : &lt;node type="STUB" id="mgmt1"/&gt;
-     *                  json: {"@type": "STUB","@id": "mgmt1"}
-     *</pre>
-     * @param nodeName User-Defined name of the node to connect with. This can be any alpha numeric value
-     * @param ipAddress IP Address of the Node to connect with.
-     * @param port Layer4 Port of the management session to connect with.
-     * @return Node If the connection is successful, HTTP 404 otherwise.
-     */
-
-    @Path("/connect/{nodeType}/{nodeId}/{ipAddress}/{port}/")
-    @PUT
-    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
-    @TypeHint(Node.class)
-    @StatusCodes( {
-        @ResponseCode(code = 201, condition = "Node connected successfully"),
-        @ResponseCode(code = 404, condition = "Could not connect to the Node with the specified parameters"),
-        @ResponseCode(code = 406, condition = "Invalid IP Address or Port parameter passed."),
-        @ResponseCode(code = 503, condition = "Connection Manager Service not available")} )
-    public Node connect(
-            @PathParam(value = "nodeType") String nodeType,
-            @PathParam(value = "nodeId") String nodeId,
-            @PathParam(value = "ipAddress") String ipAddress,
-            @PathParam(value = "port") String port) {
-
-        IConnectionManager connectionManager = getConnectionManager();
-        if (connectionManager == null) {
-            throw new ServiceUnavailableException("IConnectionManager not available.");
-        }
-
-        if (!NetUtils.isIPv4AddressValid(ipAddress)) {
-            throw new NotAcceptableException("Invalid ip address "+ipAddress);
-        }
-
-        try {
-            Integer.parseInt(port);
-        } catch (Exception e) {
-            throw new NotAcceptableException("Invalid Layer4 Port "+port);
-        }
-
-        Map<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
-        params.put(ConnectionConstants.ADDRESS, ipAddress);
-        params.put(ConnectionConstants.PORT, port);
-
-        Node node = null;
-        try {
-            node = connectionManager.connect(nodeType, nodeId, params);
-            if (node == null) {
-                throw new ResourceNotFoundException("Failed to connect to Node at "+ipAddress+":"+port);
-            }
-            return node;
-        } catch (Exception e) {
-            throw new ResourceNotFoundException(e.getMessage());
-        }
-    }
-
     /**
      * Create a Bridge.
      * <pre>
+     *
      * Example :
-     * Request : POST http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/bridge/STUB/mgmt1/bridge1
+     *
+     * Request :
+     * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/bridge/STUB/mgmt1/bridge1
+     *
      *</pre>
      * @param nodeType Node Type of the node with the management session.
      * @param nodeId Node Identifier of the node with the management session.
@@ -239,8 +120,12 @@ public class BridgeDomainNorthbound {
    /**
     * Add a Port to a Bridge
     * <pre>
+    *
     * Example :
-    * Request : POST http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/port/STUB/mgmt1/bridge1/port1
+    *
+    * Request :
+    * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/port/STUB/mgmt1/bridge1/port1
+    *
     *</pre>
     * @param nodeType Node Type of the node with the management session.
     * @param nodeId Node Identifier of the node with the management session.
@@ -282,9 +167,12 @@ public class BridgeDomainNorthbound {
    /**
     * Add a Port,Vlan to a Bridge
     * <pre>
+    *
     * Example :
-    * Request : POST http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/port/STUB/mgmt1/bridge1/port2/200
-    *</pre>
+    * Request :
+    * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/port/STUB/mgmt1/bridge1/port2/200
+    *
+    * </pre>
     * @param nodeType Node Type of the node with the management session.
     * @param nodeId Node Identifier of the node with the management session.
     * @param bridgeName Name / Identifier of the bridge to which a Port is being added.