Moving the connection manager NB-API from the network configuration APIs to connectio... 24/1924/3
authorMadhu Venugopal <mavenugo@gmail.com>
Wed, 16 Oct 2013 10:08:48 +0000 (03:08 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 16 Oct 2013 20:42:03 +0000 (20:42 +0000)
Also cleaned up these APIs as per the NBAPI conventions.

Change-Id: Ie633374210ce594d0df0b7a86f4fdc553ef64ade
Signed-off-by: Madhu Venugopal <mavenugo@gmail.com>
opendaylight/connectionmanager/implementation/src/main/java/org/opendaylight/controller/connectionmanager/internal/ConnectionManager.java
opendaylight/distribution/opendaylight/pom.xml
opendaylight/northbound/connectionmanager/enunciate.xml [new file with mode: 0644]
opendaylight/northbound/connectionmanager/pom.xml [new file with mode: 0644]
opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/ConnectionManagerNorthbound.java [new file with mode: 0644]
opendaylight/northbound/connectionmanager/src/main/java/org/opendaylight/controller/connectionmanager/northbound/Nodes.java [new file with mode: 0644]
opendaylight/northbound/connectionmanager/src/main/resources/WEB-INF/web.xml [new file with mode: 0644]
opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthbound.java
pom.xml

index 1beb7fe0bb609860865ed52347f27bfe126aeb2e..e5bf5258c5faa86fff78f5959692494f0049052f 100644 (file)
@@ -235,19 +235,31 @@ public class ConnectionManager implements IConnectionManager, IConnectionListene
     @Override
     public Node connect(String connectionIdentifier, Map<ConnectionConstants, String> 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<ConnectionConstants, String> 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
index a0cb9f03e9bfd3a5b37b504b13e0f67425bbedfd..174414433340124077df3ad0344fb88c9ab94eda 100644 (file)
       <artifactId>httpservice-bridge</artifactId>
       <version>0.0.1-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>connectionmanager.northbound</artifactId>
+      <version>${connectionmanager.version}</version>
+    </dependency>
 
     <!-- Debug and logging -->
 
diff --git a/opendaylight/northbound/connectionmanager/enunciate.xml b/opendaylight/northbound/connectionmanager/enunciate.xml
new file mode 100644 (file)
index 0000000..124f2d8
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<enunciate label="full" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:noNamespaceSchemaLocation="http://enunciate.codehaus.org/schemas/enunciate-1.26.xsd">
+
+  <services>
+    <rest defaultRestSubcontext="/controller/nb/v2/connectionmanager"/>
+  </services>
+
+  <modules>
+    <docs docsDir="rest" title="Connection Manager REST API" includeExampleXml="true" includeExampleJson="true"/>
+  </modules>
+</enunciate>
diff --git a/opendaylight/northbound/connectionmanager/pom.xml b/opendaylight/northbound/connectionmanager/pom.xml
new file mode 100644 (file)
index 0000000..0ddfcdb
--- /dev/null
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.opendaylight.controller</groupId>
+    <artifactId>commons.opendaylight</artifactId>
+    <version>1.4.1-SNAPSHOT</version>
+    <relativePath>../../commons/opendaylight</relativePath>
+  </parent>
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+    <tag>HEAD</tag>
+  </scm>
+
+  <artifactId>connectionmanager.northbound</artifactId>
+  <version>0.1.1-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.codehaus.enunciate</groupId>
+        <artifactId>maven-enunciate-plugin</artifactId>
+        <version>${enunciate.version}</version>
+        <dependencies>
+          <dependency>
+            <groupId>org.opendaylight.controller</groupId>
+            <artifactId>sal</artifactId>
+            <version>0.5.1-SNAPSHOT</version>
+          </dependency>
+        </dependencies>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>${bundle.plugin.version}</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Export-Package>
+            </Export-Package>
+            <Import-Package>
+              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
+            </Import-Package>
+            <Export-Package>
+            </Export-Package>
+            <Web-ContextPath>/controller/nb/v2/connectionmanager</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
+          </instructions>
+          <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal</artifactId>
+      <version>0.5.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal.connection</artifactId>
+      <version>0.1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>connectionmanager</artifactId>
+      <version>0.1.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>containermanager</artifactId>
+      <version>0.5.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.enunciate</groupId>
+      <artifactId>enunciate-core-annotations</artifactId>
+      <version>${enunciate.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>commons.northbound</artifactId>
+      <version>0.4.1-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>
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 (file)
index 0000000..c069f82
--- /dev/null
@@ -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}
+     *
+     * <pre>
+     *
+     * Example:
+     *
+     * Request URL:
+     * http://localhost:8080/controller/nb/v2/connectionmanager/nodes?controller=1.1.1.1
+     *
+     * Response body in XML:
+     *  &lt;list&gt;
+     *       &lt;node&gt;
+     *           &lt;id&gt;00:00:00:00:00:00:00:52&lt;/id&gt;
+     *           &lt;type&gt;OF&lt;/type&gt;
+     *       &lt;/node&gt;
+     *       &lt;node&gt;
+     *           &lt;id&gt;00:00:00:00:00:00:00:3e&lt;/id&gt;
+     *           &lt;type&gt;OF&lt;/type&gt;
+     *       &lt;/node&gt;
+     *   &lt;/list&gt;
+     *
+     *  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"
+     *           }
+     *       ]
+     *   }
+     * </pre>
+     */
+    @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<Node> 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.
+     * <pre>
+     *
+     * Example :
+     *
+     * Request :
+     * PUT http://localhost:8080/controller/nb/v2/connectionmanager/node/mgmt1/address/1.1.1.1/port/6634
+     *
+     * Response :
+     * Node :
+     * xml :
+     * &lt;node&gt;
+     *    &lt;id&gt;mgmt1&lt;/id&gt;
+     *    &lt;type&gt;STUB&lt;/type&gt;
+     * &lt;/node&gt;
+     *
+     * json:
+     * {"id": "mgmt1","type": "STUB"}
+     *
+     *</pre>
+     * @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<ConnectionConstants, String> params = new HashMap<ConnectionConstants, String>();
+        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.
+     * <pre>
+     *
+     * Example :
+     *
+     * Request :
+     * PUT http://localhost:8080/controller/nb/v2/connectionmanager/node/STUB/mgmt1/address/1.1.1.1/port/6634
+     *
+     * Response : Node :
+     * xml :
+     * &lt;node&gt;
+     *    &lt;id&gt;mgmt1&lt;/id&gt;
+     *    &lt;type&gt;STUB&lt;/type&gt;
+     * &lt;/node&gt;
+     *
+     * json:
+     * {"id": "mgmt1","type": "STUB"}
+     *
+     *</pre>
+     * @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<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());
+        }
+    }
+
+    /**
+     * Disconnect an existing Connection.
+     * <pre>
+     *
+     * Example :
+     *
+     * Request :
+     * DELETE http://localhost:8080/controller/nb/v2/connectionmanager/node/STUB/mgmt1
+     *
+     *</pre>
+     * @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 (file)
index 0000000..aefd4b2
--- /dev/null
@@ -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> node;
+    //To satisfy JAXB
+    private Nodes() {
+    }
+
+    public Nodes(Set<Node> nodes) {
+        this.node = nodes;
+    }
+
+    public Set<Node> getNode() {
+        return node;
+    }
+
+    public void setNode(Set<Node> 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 (file)
index 0000000..f0b23aa
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+        version="3.0">
+  <servlet>
+    <servlet-name>ConnectionManager</servlet-name>
+    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+    <init-param>
+      <param-name>javax.ws.rs.Application</param-name>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
+    </init-param>
+    <load-on-startup>1</load-on-startup>
+  </servlet>
+  <servlet-mapping>
+    <servlet-name>ConnectionManager</servlet-name>
+    <url-pattern>/*</url-pattern>
+  </servlet-mapping>
+  <filter>
+    <filter-name>CorsFilter</filter-name>
+    <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
+    <init-param>
+      <param-name>cors.allowed.origins</param-name>
+      <param-value>*</param-value>
+    </init-param>
+    <init-param>
+      <param-name>cors.allowed.methods</param-name>
+      <param-value>GET,POST,HEAD,OPTIONS,PUT,DELETE</param-value>
+    </init-param>
+    <init-param>
+      <param-name>cors.allowed.headers</param-name>
+      <param-value>Content-Type,X-Requested-With,accept,authorization, origin,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
+    </init-param>
+    <init-param>
+      <param-name>cors.exposed.headers</param-name>
+      <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
+    </init-param>
+    <init-param>
+      <param-name>cors.support.credentials</param-name>
+      <param-value>true</param-value>
+    </init-param>
+    <init-param>
+      <param-name>cors.preflight.maxage</param-name>
+      <param-value>10</param-value>
+    </init-param>
+  </filter>
+  <filter-mapping>
+    <filter-name>CorsFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+  </filter-mapping>
+
+  <security-constraint>
+    <web-resource-collection>
+      <web-resource-name>NB api</web-resource-name>
+      <url-pattern>/*</url-pattern>
+      <http-method>POST</http-method>
+      <http-method>GET</http-method>
+      <http-method>PUT</http-method>
+      <http-method>PATCH</http-method>
+      <http-method>DELETE</http-method>
+      <http-method>HEAD</http-method>
+    </web-resource-collection>
+    <auth-constraint>
+      <role-name>System-Admin</role-name>
+      <role-name>Network-Admin</role-name>
+      <role-name>Network-Operator</role-name>
+    </auth-constraint>
+  </security-constraint>
+
+  <security-role>
+    <role-name>System-Admin</role-name>
+  </security-role>
+  <security-role>
+    <role-name>Network-Admin</role-name>
+  </security-role>
+  <security-role>
+    <role-name>Network-Operator</role-name>
+  </security-role>
+
+  <login-config>
+    <auth-method>BASIC</auth-method>
+    <realm-name>opendaylight</realm-name>
+  </login-config>
+</web-app>
\ No newline at end of file
index da7faa2c78d9cf9b4155ce244cbd190ea649b4a8..de9219c2a2ea825ca245ce0b32253290c3d11e2a 100644 (file)
@@ -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.
-     * <pre>
-     *
-     * Example :
-     *
-     * Request :
-     * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/connect/mgmt1/1.1.1.1/6634
-     *
-     * Response :
-     * Node :
-     * xml :
-     * &lt;node&gt;
-     *    &lt;id&gt;mgmt1&lt;/id&gt;
-     *    &lt;type&gt;STUB&lt;/type&gt;
-     * &lt;/node&gt;
-     *
-     * json:
-     * {"id": "mgmt1","type": "STUB"}
-     *
-     *</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 :
-     * http://localhost:8080/controller/nb/v2/networkconfig/bridgedomain/connect/STUB/mgmt1/1.1.1.1/6634
-     *
-     * Response : Node :
-     * xml :
-     * &lt;node&gt;
-     *    &lt;id&gt;mgmt1&lt;/id&gt;
-     *    &lt;type&gt;STUB&lt;/type&gt;
-     * &lt;/node&gt;
-     *
-     * json:
-     * {"id": "mgmt1","type": "STUB"}
-     *
-     *</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>
diff --git a/pom.xml b/pom.xml
index 3923bfd995367214fd52b0f88f1721e985b50db2..f45fb62c615e21c41370adeaadd3adc9bb1bde7b 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <module>opendaylight/northbound/containermanager</module>
     <module>opendaylight/northbound/networkconfiguration/bridgedomain</module>
     <module>opendaylight/northbound/httpservice-bridge</module>
+    <module>opendaylight/northbound/connectionmanager</module>
 
     <!-- Northbound integration tests -->
     <module>opendaylight/northbound/integrationtest</module>