From: Madhu Venugopal Date: Wed, 16 Oct 2013 10:08:48 +0000 (-0700) Subject: Moving the connection manager NB-API from the network configuration APIs to connectio... X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-1~618 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=99050b4a43221f1e82f2fb61bc4ea162c2c7e283 Moving the connection manager NB-API from the network configuration APIs to connectionmanager API. Also cleaned up these APIs as per the NBAPI conventions. Change-Id: Ie633374210ce594d0df0b7a86f4fdc553ef64ade Signed-off-by: Madhu Venugopal --- diff --git a/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java b/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java index 1beb7fe0bb..e5bf5258c5 100644 --- a/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java +++ b/opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java @@ -235,19 +235,31 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene @Override public Node connect(String connectionIdentifier, Map params) { if (connectionService == null) return null; - return connectionService.connect(connectionIdentifier, params); + Node node = connectionService.connect(connectionIdentifier, params); + AbstractScheme scheme = schemes.get(activeScheme); + if (scheme != null && node != null) scheme.addNode(node); + return node; } @Override public Node connect(String type, String connectionIdentifier, Map params) { if (connectionService == null) return null; - return connectionService.connect(type, connectionIdentifier, params); + Node node = connectionService.connect(connectionIdentifier, params); + AbstractScheme scheme = schemes.get(activeScheme); + if (scheme != null && node != null) scheme.addNode(node); + return node; } @Override public Status disconnect (Node node) { + if (node == null) return new Status(StatusCode.BADREQUEST); if (connectionService == null) return new Status(StatusCode.NOSERVICE); - return connectionService.disconnect(node); + Status status = connectionService.disconnect(node); + if (status.isSuccess()) { + AbstractScheme scheme = schemes.get(activeScheme); + if (scheme != null) scheme.removeNode(node); + } + return status; } @Override diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index a0cb9f03e9..1744144333 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -608,6 +608,11 @@ httpservice-bridge 0.0.1-SNAPSHOT + + org.opendaylight.controller + connectionmanager.northbound + ${connectionmanager.version} + diff --git a/opendaylight/northbound/connectionmanager/enunciate.xml b/opendaylight/northbound/connectionmanager/enunciate.xml new file mode 100644 index 0000000000..124f2d84e8 --- /dev/null +++ b/opendaylight/northbound/connectionmanager/enunciate.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/opendaylight/northbound/connectionmanager/pom.xml b/opendaylight/northbound/connectionmanager/pom.xml new file mode 100644 index 0000000000..0ddfcdb3e1 --- /dev/null +++ b/opendaylight/northbound/connectionmanager/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.1-SNAPSHOT + ../../commons/opendaylight + + + scm:git:ssh://git.opendaylight.org:29418/controller.git + scm:git:ssh://git.opendaylight.org:29418/controller.git + https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main + HEAD + + + connectionmanager.northbound + 0.1.1-SNAPSHOT + bundle + + + + org.codehaus.enunciate + maven-enunciate-plugin + ${enunciate.version} + + + org.opendaylight.controller + sal + 0.5.1-SNAPSHOT + + + + + org.apache.felix + maven-bundle-plugin + ${bundle.plugin.version} + true + + + + + + org.opendaylight.controller.sal.core, + org.opendaylight.controller.sal.utils, + org.opendaylight.controller.containermanager, + org.opendaylight.controller.usermanager, + com.sun.jersey.spi.container.servlet, + org.opendaylight.controller.northbound.commons, + org.opendaylight.controller.northbound.commons.exception, + org.opendaylight.controller.northbound.commons.utils, + org.opendaylight.controller.sal.authorization, + org.opendaylight.controller.connectionmanager, + org.opendaylight.controller.sal.connection, + org.slf4j, + javax.ws.rs, + javax.ws.rs.core, + javax.xml.bind.annotation, + javax.xml.bind, + org.apache.catalina.filters, + org.codehaus.jackson.jaxrs, + !org.codehaus.enunciate.jaxrs + + + + /controller/nb/v2/connectionmanager + ,${classes;ANNOTATION;javax.ws.rs.Path} + + ${project.basedir}/src/main/resources/META-INF + + + + + + + org.opendaylight.controller + sal + 0.5.1-SNAPSHOT + + + org.opendaylight.controller + sal.connection + 0.1.1-SNAPSHOT + + + org.opendaylight.controller + connectionmanager + 0.1.1-SNAPSHOT + + + org.opendaylight.controller + containermanager + 0.5.1-SNAPSHOT + + + org.codehaus.enunciate + enunciate-core-annotations + ${enunciate.version} + + + org.opendaylight.controller + commons.northbound + 0.4.1-SNAPSHOT + + + diff --git a/opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/ConnectionManagerNorthbound.java b/opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/ConnectionManagerNorthbound.java new file mode 100644 index 0000000000..c069f82a84 --- /dev/null +++ b/opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/ConnectionManagerNorthbound.java @@ -0,0 +1,347 @@ + +/* + * Copyright (c) 2013 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.controller.connectionmanager.northbound; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.SecurityContext; + +import org.codehaus.enunciate.jaxrs.ResponseCode; +import org.codehaus.enunciate.jaxrs.StatusCodes; +import org.codehaus.enunciate.jaxrs.TypeHint; +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.northbound.commons.exception.UnauthorizedException; +import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils; +import org.opendaylight.controller.sal.authorization.Privilege; +import org.opendaylight.controller.sal.connection.ConnectionConstants; +import org.opendaylight.controller.sal.core.Node; +import org.opendaylight.controller.sal.utils.NetUtils; +import org.opendaylight.controller.sal.utils.ServiceHelper; +import org.opendaylight.controller.sal.utils.Status; + +/** + * Connection Manager Northbound APIs + */ +@Path("/") +public class ConnectionManagerNorthbound { + private String username; + + @Context + public void setSecurityContext(SecurityContext context) { + if (context != null && context.getUserPrincipal() != null) username = context.getUserPrincipal().getName(); + } + protected String getUserName() { + return username; + } + + private IConnectionManager getConnectionManager() { + return (IConnectionManager) ServiceHelper + .getGlobalInstance(IConnectionManager.class, this); + } + + /** + * + * Retrieve a list of all the nodes connected to a given controller in the cluster. + * + * @param controllerAddress Optional parameter to retrieve the nodes connected to another + * controller in the cluster + * @return A list of Nodes {@link org.opendaylight.controller.sal.core.Node} + * + *
+     *
+     * Example:
+     *
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/connectionmanager/nodes?controller=1.1.1.1
+     *
+     * Response body in XML:
+     *  <list>
+     *       <node>
+     *           <id>00:00:00:00:00:00:00:52</id>
+     *           <type>OF</type>
+     *       </node>
+     *       <node>
+     *           <id>00:00:00:00:00:00:00:3e</id>
+     *           <type>OF</type>
+     *       </node>
+     *   </list>
+     *
+     *  Response body in JSON:
+     *  {
+     *       "node": [
+     *           {
+     *               "type": "OF",
+     *               "id": "00:00:00:00:00:00:00:52"
+     *           },
+     *           {
+     *               "type": "OF",
+     *               "id": "00:00:00:00:00:00:00:3e"
+     *           }
+     *       ]
+     *   }
+     * 
+ */ + @Path("/nodes") + @GET + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @TypeHint(Nodes.class) + @StatusCodes( { + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @ResponseCode(code = 406, condition = "Invalid Controller IP Address passed."), + @ResponseCode(code = 503, condition = "Connection Manager Service not available")}) + + public Nodes getNodes(@DefaultValue("") @QueryParam("controller") String controllerAddress) { + if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.READ, this)) { + throw new UnauthorizedException("User is not authorized to perform this operation on container"); + } + + IConnectionManager connectionManager = getConnectionManager(); + if (connectionManager == null) { + throw new ServiceUnavailableException("IConnectionManager not available."); + } + + if ((controllerAddress != null) && (controllerAddress.trim().length() > 0) && + !NetUtils.isIPv4AddressValid(controllerAddress)) { + throw new NotAcceptableException("Invalid ip address "+controllerAddress); + } + Set nodeSet = null; + + if (controllerAddress != null) { + try { + nodeSet = connectionManager.getNodes(InetAddress.getByName(controllerAddress)); + } catch (UnknownHostException e) { + throw new NotAcceptableException("Invalid ip address "+controllerAddress); + } + } else { + nodeSet = connectionManager.getLocalNodes(); + } + return new Nodes(nodeSet); + } + + /** + * If a Network Configuration Service needs a Management Connection and if the + * Node Type is unknown, use this REST api to connect to the management session. + *
+     *
+     * Example :
+     *
+     * Request :
+     * PUT http://localhost:8080/controller/nb/v2/connectionmanager/node/mgmt1/address/1.1.1.1/port/6634
+     *
+     * Response :
+     * Node :
+     * xml :
+     * <node>
+     *    <id>mgmt1</id>
+     *    <type>STUB</type>
+     * </node>
+     *
+     * json:
+     * {"id": "mgmt1","type": "STUB"}
+     *
+     *
+ * @param nodeId 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("/node/{nodeId}/address/{ipAddress}/port/{port}/") + @PUT + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @TypeHint(Node.class) + @StatusCodes( { + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @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 = "nodeId") String nodeId, + @PathParam(value = "ipAddress") String ipAddress, + @PathParam(value = "port") String port) { + + if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) { + throw new UnauthorizedException("User is not authorized to perform this operation on container"); + } + + 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 params = new HashMap(); + params.put(ConnectionConstants.ADDRESS, ipAddress); + params.put(ConnectionConstants.PORT, port); + + Node node = null; + try { + node = connectionManager.connect(nodeId, params); + if (node == null) { + throw new ResourceNotFoundException("Failed to connect to Node at "+ipAddress+":"+port); + } + return node; + } catch (Exception e) { + throw new ResourceNotFoundException("Failed to connect to Node with Exception "+e.getMessage()); + } + } + + /** + * If a Network Configuration Service needs a Management Connection, and if the + * node Type is known, the user can choose to use this REST api to connect to the management session. + *
+     *
+     * Example :
+     *
+     * Request :
+     * PUT http://localhost:8080/controller/nb/v2/connectionmanager/node/STUB/mgmt1/address/1.1.1.1/port/6634
+     *
+     * Response : Node :
+     * xml :
+     * <node>
+     *    <id>mgmt1</id>
+     *    <type>STUB</type>
+     * </node>
+     *
+     * json:
+     * {"id": "mgmt1","type": "STUB"}
+     *
+     *
+ * @param nodeType Type of the Node the connection is made for. + * @param nodeId 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("/node/{nodeType}/{nodeId}/address/{ipAddress}/port/{port}/") + @PUT + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @TypeHint(Node.class) + @StatusCodes( { + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @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) { + + if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) { + throw new UnauthorizedException("User is not authorized to perform this operation on container"); + } + + 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 params = new HashMap(); + 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()); + } + } + + /** + * Disconnect an existing Connection. + *
+     *
+     * Example :
+     *
+     * Request :
+     * DELETE http://localhost:8080/controller/nb/v2/connectionmanager/node/STUB/mgmt1
+     *
+     *
+ * @param nodeType Type of the Node + * @param nodeId Connection's NodeId. + */ + + @Path("/node/{nodeType}/{nodeId}/") + @DELETE + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @TypeHint(Response.class) + @StatusCodes( { + @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), + @ResponseCode(code = 200, condition = "Node disconnected successfully"), + @ResponseCode(code = 404, condition = "Could not find a connection with the specified Node identifier"), + @ResponseCode(code = 503, condition = "Connection Manager Service not available")} ) + public Response disconnect( + @PathParam(value = "nodeType") String nodeType, + @PathParam(value = "nodeId") String nodeId) { + + if (!NorthboundUtils.isAuthorized(getUserName(), "default", Privilege.WRITE, this)) { + throw new UnauthorizedException("User is not authorized to perform this operation on container"); + } + IConnectionManager connectionManager = getConnectionManager(); + if (connectionManager == null) { + throw new ServiceUnavailableException("IConnectionManager not available."); + } + + try { + Node node = new Node(nodeType, nodeId); + Status status = connectionManager.disconnect(node); + if (status.isSuccess()) { + return Response.ok().build(); + } + return NorthboundUtils.getResponse(status); + } catch (Exception e) { + throw new ResourceNotFoundException(e.getMessage()); + } + } +} diff --git a/opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/Nodes.java b/opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/Nodes.java new file mode 100644 index 0000000000..aefd4b2451 --- /dev/null +++ b/opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/Nodes.java @@ -0,0 +1,40 @@ +package org.opendaylight.controller.connectionmanager.northbound; +/* + * Copyright (c) 2013 Red Hat, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +import java.util.Set; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +import org.opendaylight.controller.sal.core.Node; + +@XmlRootElement(name="list") +@XmlAccessorType(XmlAccessType.NONE) + +public class Nodes { + @XmlElement + Set node; + //To satisfy JAXB + private Nodes() { + } + + public Nodes(Set nodes) { + this.node = nodes; + } + + public Set getNode() { + return node; + } + + public void setNode(Set nodes) { + this.node = nodes; + } +} diff --git a/opendaylight/northbound/connectionmanager/src/main/resources/WEB-INF/web.xml b/opendaylight/northbound/connectionmanager/src/main/resources/WEB-INF/web.xml new file mode 100644 index 0000000000..f0b23aaf6c --- /dev/null +++ b/opendaylight/northbound/connectionmanager/src/main/resources/WEB-INF/web.xml @@ -0,0 +1,83 @@ + + + + ConnectionManager + com.sun.jersey.spi.container.servlet.ServletContainer + + javax.ws.rs.Application + org.opendaylight.controller.northbound.commons.NorthboundApplication + + 1 + + + ConnectionManager + /* + + + CorsFilter + org.apache.catalina.filters.CorsFilter + + cors.allowed.origins + * + + + cors.allowed.methods + GET,POST,HEAD,OPTIONS,PUT,DELETE + + + cors.allowed.headers + Content-Type,X-Requested-With,accept,authorization, origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers + + + cors.exposed.headers + Access-Control-Allow-Origin,Access-Control-Allow-Credentials + + + cors.support.credentials + true + + + cors.preflight.maxage + 10 + + + + CorsFilter + /* + + + + + NB api + /* + POST + GET + PUT + PATCH + DELETE + HEAD + + + System-Admin + Network-Admin + Network-Operator + + + + + System-Admin + + + Network-Admin + + + Network-Operator + + + + BASIC + opendaylight + + \ No newline at end of file diff --git a/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java b/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java index da7faa2c78..de9219c2a2 100644 --- a/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java +++ b/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java @@ -72,152 +72,6 @@ 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. - *
-     *
-     * Example :
-     *
-     * Request :
-     * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/connect/mgmt1/1.1.1.1/6634
-     *
-     * Response :
-     * Node :
-     * xml :
-     * <node>
-     *    <id>mgmt1</id>
-     *    <type>STUB</type>
-     * </node>
-     *
-     * json:
-     * {"id": "mgmt1","type": "STUB"}
-     *
-     *
- * @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 params = new HashMap(); - 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. - *
-     *
-     * Example :
-     *
-     * Request :
-     * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/connect/STUB/mgmt1/1.1.1.1/6634
-     *
-     * Response : Node :
-     * xml :
-     * <node>
-     *    <id>mgmt1</id>
-     *    <type>STUB</type>
-     * </node>
-     *
-     * json:
-     * {"id": "mgmt1","type": "STUB"}
-     *
-     *
- * @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 params = new HashMap(); - 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. *
diff --git a/pom.xml b/pom.xml
index 3923bfd995..f45fb62c61 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,6 +113,7 @@
     opendaylight/northbound/containermanager
     opendaylight/northbound/networkconfiguration/bridgedomain
     opendaylight/northbound/httpservice-bridge
+    opendaylight/northbound/connectionmanager
 
     
     opendaylight/northbound/integrationtest