Provide northbound for controller properties 43/2143/5
authorKatelyn Kasperowicz <kkaspero@cisco.com>
Wed, 23 Oct 2013 22:20:50 +0000 (15:20 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 29 Oct 2013 21:09:37 +0000 (21:09 +0000)
Change-Id: Ie68e557287ae72bd6456ad8d63c7d1804429b64d
Signed-off-by: Katelyn Kasperowicz <kkaspero@cisco.com>
18 files changed:
opendaylight/commons/opendaylight/pom.xml
opendaylight/distribution/opendaylight/pom.xml
opendaylight/forwardingrulesmanager/integrationtest/pom.xml
opendaylight/hosttracker/integrationtest/pom.xml
opendaylight/northbound/controllermanager/enunciate.xml [new file with mode: 0644]
opendaylight/northbound/controllermanager/pom.xml [new file with mode: 0644]
opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java [new file with mode: 0644]
opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerProperties.java [new file with mode: 0644]
opendaylight/northbound/controllermanager/src/main/resources/WEB-INF/web.xml [new file with mode: 0644]
opendaylight/northbound/controllermanager/src/test/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthboundTest.java [new file with mode: 0644]
opendaylight/northbound/integrationtest/pom.xml
opendaylight/statisticsmanager/integrationtest/pom.xml
opendaylight/switchmanager/api/pom.xml
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java
opendaylight/switchmanager/implementation/pom.xml
opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java
opendaylight/switchmanager/integrationtest/pom.xml
pom.xml

index 0221552686a942a9d7871ceff34619b683729c2c..7cd3beaac98aeeb2f085805a04770cae30c8deef 100644 (file)
@@ -80,7 +80,7 @@
     <netconf.version>0.2.2-SNAPSHOT</netconf.version>
     <mdsal.version>1.0-SNAPSHOT</mdsal.version>
     <containermanager.version>0.5.1-SNAPSHOT</containermanager.version>
     <netconf.version>0.2.2-SNAPSHOT</netconf.version>
     <mdsal.version>1.0-SNAPSHOT</mdsal.version>
     <containermanager.version>0.5.1-SNAPSHOT</containermanager.version>
-    <switchmanager.api.version>0.5.1-SNAPSHOT</switchmanager.api.version>
+    <switchmanager.api.version>0.6.1-SNAPSHOT</switchmanager.api.version>
     <connectionmanager.version>0.1.1-SNAPSHOT</connectionmanager.version>
     <sal.version>0.6.0-SNAPSHOT</sal.version>
     <sal.networkconfiguration.version>0.0.2-SNAPSHOT</sal.networkconfiguration.version>
     <connectionmanager.version>0.1.1-SNAPSHOT</connectionmanager.version>
     <sal.version>0.6.0-SNAPSHOT</sal.version>
     <sal.networkconfiguration.version>0.0.2-SNAPSHOT</sal.networkconfiguration.version>
index 81164ae75223f88afad9bac5b6d2df3b439af567..705bce7b895b57cf2b5e42792ab3ad7a43e9303d 100644 (file)
       <artifactId>usermanager.northbound</artifactId>
       <version>0.0.1-SNAPSHOT</version>
     </dependency>
       <artifactId>usermanager.northbound</artifactId>
       <version>0.0.1-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>controllermanager.northbound</artifactId>
+      <version>0.0.1-SNAPSHOT</version>
+    </dependency>
     <!-- Debug and logging -->
 
     <dependency>
     <!-- Debug and logging -->
 
     <dependency>
index fa6f0ab34342c6d7ea3f687d06cea5757f26b52e..15b31d5ea675370a1588006d94a5f5695d8e3353 100644 (file)
@@ -71,6 +71,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index d41222c96e4a8f3b159f9cf59752276989e85616..7274ef8e55556d284ab46c12c4ecdf397addd92a 100644 (file)
@@ -70,6 +70,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
diff --git a/opendaylight/northbound/controllermanager/enunciate.xml b/opendaylight/northbound/controllermanager/enunciate.xml
new file mode 100644 (file)
index 0000000..13a2d27
--- /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/controllermanager"/>
+  </services>
+
+  <modules>
+    <docs docsDir="rest" title="Controller Manager REST API" includeExampleXml="true" includeExampleJson="true"/>
+  </modules>
+</enunciate>
diff --git a/opendaylight/northbound/controllermanager/pom.xml b/opendaylight/northbound/controllermanager/pom.xml
new file mode 100644 (file)
index 0000000..d1299a2
--- /dev/null
@@ -0,0 +1,126 @@
+<?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>
+  <artifactId>controllermanager.northbound</artifactId>
+  <version>0.0.1-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+  <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>
+
+  <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>
+            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+            <Import-Package>
+              org.opendaylight.controller.sal.core,
+              org.opendaylight.controller.sal.utils,
+              org.opendaylight.controller.containermanager,
+              org.opendaylight.controller.switchmanager,
+              org.opendaylight.controller.usermanager,
+              org.apache.commons.lang3.tuple,
+              org.apache.commons.logging,
+              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,
+              javax.ws.rs,
+              javax.ws.rs.core,
+              javax.xml.bind.annotation,
+              javax.xml.bind,
+              org.slf4j,
+              org.apache.catalina.filters,
+              org.codehaus.jackson.jaxrs,
+              org.codehaus.jackson.annotate,
+              !org.codehaus.enunciate.jaxrs
+            </Import-Package>
+            <Web-ContextPath>/controller/nb/v2/controllermanager</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.thirdparty</groupId>
+      <artifactId>com.sun.jersey.jersey-servlet</artifactId>
+      <version>1.18-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>containermanager</artifactId>
+      <version>0.5.1-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>sal</artifactId>
+      <version>0.5.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>commons.northbound</artifactId>
+      <version>0.4.1-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-web</artifactId>
+      <version>${spring.version}</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.codehaus.enunciate</groupId>
+      <artifactId>enunciate-core-annotations</artifactId>
+      <version>${enunciate.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller.thirdparty</groupId>
+      <artifactId>org.apache.catalina.filters.CorsFilter</artifactId>
+      <version>7.0.43-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java b/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java
new file mode 100644 (file)
index 0000000..c515396
--- /dev/null
@@ -0,0 +1,272 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, 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.controllermanager.northbound;
+
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+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 javax.ws.rs.core.UriInfo;
+
+import org.codehaus.enunciate.jaxrs.ResponseCode;
+import org.codehaus.enunciate.jaxrs.StatusCodes;
+import org.codehaus.enunciate.jaxrs.TypeHint;
+import org.opendaylight.controller.containermanager.IContainerManager;
+import org.opendaylight.controller.northbound.commons.RestMessages;
+import org.opendaylight.controller.northbound.commons.exception.BadRequestException;
+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.core.Property;
+import org.opendaylight.controller.sal.utils.GlobalConstants;
+import org.opendaylight.controller.sal.utils.ServiceHelper;
+import org.opendaylight.controller.sal.utils.Status;
+import org.opendaylight.controller.switchmanager.ISwitchManager;
+
+/**
+ * The class provides Northbound REST APIs to manager the controller. Currently
+ * it supports getting controller property(ies), setting a property, and
+ * removing a property
+ *
+ */
+
+@Path("/")
+public class ControllerManagerNorthbound {
+
+    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 ISwitchManager getISwitchManagerService(String containerName) {
+        ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(ISwitchManager.class, containerName,
+                this);
+
+        if (switchManager == null) {
+            throw new ServiceUnavailableException("Switch Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+
+        return switchManager;
+    }
+
+    /**
+     * Retrieve a property or all properties for the controller in the network
+     *
+     * @param containerName
+     *            Name of the Container (Eg. 'default')
+     * @param propertyName
+     *            Name of the Property specified by
+     *            {@link org.opendaylight.controller.sal.core.Property} and its
+     *            extended classes
+     *
+     *            Example:
+     *
+     *            Request URL:
+     *            http://localhost:8080/controller/nb/v2/controllermanager/default/properties/?propertyName=macAddress
+     *
+     *            Response Body in XML:
+     *            <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+     *            <controllerProperties>
+     *                  <properties>
+     *                           <macAddress>
+     *                                   <value>3e:04:ef:11:13:80</value>
+     *                          </macAddress>
+     *                   </properties>
+     *            </controllerProperties>
+     *
+     *            Response Body in JSON:
+     *            { "controllerProperties":
+     *                  {"properties":
+     *                          { "macAddress":
+     *                                  { "value": "3e:04:ef:11:13:80" }
+     *                           }
+     *                   }
+     *            }
+     *
+     */
+    @Path("/{containerName}/properties/")
+    @GET
+    @TypeHint(Property.class)
+    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"),
+            @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+            @ResponseCode(code = 404, condition = "The containerName or property is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+    public ControllerProperties getControllerProperties(@PathParam("containerName") String containerName,
+            @QueryParam("propertyName") String propertyName) {
+
+        if (!isValidContainer(containerName)) {
+            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
+        }
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                    + containerName);
+        }
+
+        ISwitchManager switchManager = getISwitchManagerService(containerName);
+
+        if (propertyName == null) {
+            Map<String, Property> propertyMap = switchManager.getControllerProperties();
+            Set<Property> properties = new HashSet<Property>(propertyMap.values());
+            return new ControllerProperties(properties);
+        }
+
+        Set<Property> properties = new HashSet<Property>();
+        Property property = switchManager.getControllerProperty(propertyName);
+        if (property == null) {
+            throw new ResourceNotFoundException("Unable to find property with name: " + propertyName);
+        }
+        properties.add(property);
+
+        return new ControllerProperties(properties);
+
+    }
+
+    /**
+     * Add a controller property to the controller. This method overrides
+     * previously set property values if the property already exist.
+     *
+     * @param containerName
+     *            Name of the Container (Eg. 'default')
+     * @param propertyName
+     *            Name of the Property specified by
+     *            {@link org.opendaylight.controller.sal.core.Property} and its
+     *            extended classes
+     * @param propertyValue
+     *            Value of the Property specified by
+     *            {@link org.opendaylight.controller.sal.core.Property} and its
+     *            extended classes
+     * @return Response as dictated by the HTTP Response Status code
+     *
+     *         Example:
+     *
+     *         Request URL:
+     *         http://localhost:8080/controller/nb/v2/controllermanager/default/properties/description/defaultController
+     */
+    @Path("/{containerName}/properties/{propertyName}/{propertyValue}")
+    @PUT
+    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
+    @StatusCodes({ @ResponseCode(code = 201, condition = "Operation successful"),
+            @ResponseCode(code = 400, condition = "Invalid property parameters"),
+            @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+            @ResponseCode(code = 404, condition = "The containerName or property is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+    public Response setControllerProperty(@Context UriInfo uriInfo, @PathParam("containerName") String containerName,
+            @PathParam("propertyName") String propertyName, @PathParam("propertyValue") String propertyValue) {
+
+        if (!isValidContainer(containerName)) {
+            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
+        }
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                    + containerName);
+        }
+
+        ISwitchManager switchManager = getISwitchManagerService(containerName);
+
+        Property prop = switchManager.createProperty(propertyName, propertyValue);
+        if (prop == null) {
+            throw new BadRequestException("Property with name " + propertyName + " cannot be created.");
+        }
+
+        Status status = switchManager.setControllerProperty(prop);
+
+        if (status.isSuccess()) {
+            NorthboundUtils.auditlog("Controller Property", username, "updated", propertyName);
+            return Response.created(uriInfo.getRequestUri()).build();
+        }
+        return NorthboundUtils.getResponse(status);
+    }
+
+    /**
+     * Delete a property of the controller
+     *
+     * @param containerName
+     *            Name of the Container (Eg. 'default')
+     * @param propertyName
+     *            Name of the Property specified by
+     *            {@link org.opendaylight.controller.sal.core.Property} and its
+     *            extended classes
+     * @return Response as dictated by the HTTP Response Status code
+     *
+     *         Example:
+     *
+     *         Request URL:
+     *         http://localhost:8080/controller/nb/v2/controllermanager/default/properties/description
+     */
+    @Path("/{containerName}/properties/{propertyName}")
+    @DELETE
+    @StatusCodes({ @ResponseCode(code = 204, condition = "Property removed successfully"),
+            @ResponseCode(code = 401, condition = "User not authorized to perform this operation"),
+            @ResponseCode(code = 404, condition = "The containerName is not found"),
+            @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") })
+    public Response removeControllerProperty(@PathParam("containerName") String containerName,
+            @PathParam("propertyName") String propertyName) {
+
+        if (!isValidContainer(containerName)) {
+            throw new ResourceNotFoundException("Container " + containerName + " does not exist.");
+        }
+
+        if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) {
+            throw new UnauthorizedException("User is not authorized to perform this operation on container "
+                    + containerName);
+        }
+
+        ISwitchManager switchManager = getISwitchManagerService(containerName);
+
+        Status status = switchManager.removeControllerProperty(propertyName);
+
+        if (status.isSuccess()) {
+            NorthboundUtils.auditlog("Controller Property", username, "removed", propertyName);
+
+            return Response.noContent().build();
+        }
+        return NorthboundUtils.getResponse(status);
+    }
+
+    private boolean isValidContainer(String containerName) {
+        if (containerName.equals(GlobalConstants.DEFAULT.toString())) {
+            return true;
+        }
+        IContainerManager containerManager = (IContainerManager) ServiceHelper.getGlobalInstance(
+                IContainerManager.class, this);
+        if (containerManager == null) {
+            throw new ServiceUnavailableException("Container Manager " + RestMessages.SERVICEUNAVAILABLE.toString());
+        }
+        if (containerManager.getContainerNames().contains(containerName)) {
+            return true;
+        }
+        return false;
+    }
+
+}
diff --git a/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerProperties.java b/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerProperties.java
new file mode 100644 (file)
index 0000000..ac0d039
--- /dev/null
@@ -0,0 +1,63 @@
+package org.opendaylight.controller.controllermanager.northbound;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.opendaylight.controller.sal.core.Property;
+
+/**
+ * The class describes set of properties attached to a controller
+ */
+
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.NONE)
+public class ControllerProperties {
+
+    @XmlElementRef
+    @XmlElementWrapper
+    @JsonIgnore
+    /**
+     * Set to store the controller properties
+     */
+    private Set<Property> properties;
+
+    // JAXB required constructor
+    private ControllerProperties() {
+        this.properties = null;
+    }
+
+    public ControllerProperties(Set<Property> properties) {
+        this.properties = properties;
+    }
+
+    @JsonProperty(value="properties")
+    public Map<String, Property> getMapProperties() {
+        Map<String, Property> map = new HashMap<String, Property>();
+        for (Property p : properties) {
+            map.put(p.getName(), p);
+        }
+        return map;
+    }
+
+    public void setMapProperties(Map<String, Property> propertiesMap) {
+        this.properties = new HashSet<Property>(propertiesMap.values());
+    }
+
+    public Set<Property> getProperties() {
+        return properties;
+    }
+
+    public void setProperties(Set<Property> properties) {
+        this.properties = properties;
+    }
+}
diff --git a/opendaylight/northbound/controllermanager/src/main/resources/WEB-INF/web.xml b/opendaylight/northbound/controllermanager/src/main/resources/WEB-INF/web.xml
new file mode 100644 (file)
index 0000000..2efd81c
--- /dev/null
@@ -0,0 +1,89 @@
+<?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>JAXRSSwitchManager</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>JAXRSSwitchManager</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>
+            <role-name>Container-User</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>
+        <security-role>
+                <role-name>Container-User</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
diff --git a/opendaylight/northbound/controllermanager/src/test/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthboundTest.java b/opendaylight/northbound/controllermanager/src/test/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthboundTest.java
new file mode 100644 (file)
index 0000000..a57e615
--- /dev/null
@@ -0,0 +1,24 @@
+package org.opendaylight.controller.controllermanager.northbound;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.sal.core.Property;
+
+public class ControllerManagerNorthboundTest extends TestCase {
+
+    @Test
+    public void testControllerProperties() {
+        ControllerProperties controllerProperties = new ControllerProperties(null);
+        Assert.assertTrue(controllerProperties.getProperties() == null);
+
+        Set<Property> properties = new HashSet<Property>();
+        controllerProperties.setProperties(properties);
+        Assert.assertTrue(controllerProperties.getProperties().equals(properties));
+    }
+
+}
index 7bb06c461d57868496d0498194f48d9535699752..4b79865ca95753a114c2212316e67680512b83ff 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index c8b458ea777c3b0e3e4d377e18b459627a6facb1..c9103994a03fb8910849e74ad50d54c9d39231e5 100644 (file)
@@ -75,6 +75,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
     </dependency>
 
       <dependency>
     </dependency>
 
       <dependency>
index bf6d1b7bda707c9cb909e6454b1fcb3c9eaf8ae1..cf4c5149657d453bcff2a72c06cdf383f1841e0f 100644 (file)
@@ -16,7 +16,7 @@
   </scm>
 
   <artifactId>switchmanager</artifactId>
   </scm>
 
   <artifactId>switchmanager</artifactId>
-  <version>0.5.1-SNAPSHOT</version>
+  <version>0.6.1-SNAPSHOT</version>
   <packaging>bundle</packaging>
 
   <properties>
   <packaging>bundle</packaging>
 
   <properties>
index 9ac0b5055f071de56ad2afd87e0e65bb8ef3da29..8815e5e8c08a1b2f52ddabdcf9c6a28363b79419 100644 (file)
@@ -385,4 +385,44 @@ public interface ISwitchManager {
      */
     @Deprecated
     public String getNodeDescription(Node node);
      */
     @Deprecated
     public String getNodeDescription(Node node);
+
+    /**
+     * Return all the properties of the controller
+     *
+     * @return map of {@link org.opendaylight.controller.sal.core.Property} such
+     *         as {@link org.opendaylight.controller.sal.core.Description}
+     *         and/or {@link org.opendaylight.controller.sal.core.Tier} etc.
+     */
+    public Map<String, Property> getControllerProperties();
+
+    /**
+     * Return a specific property of the controller given the property name
+     *
+     * @param propName
+     *            the property name specified by
+     *            {@link org.opendaylight.controller.sal.core.Property} and its
+     *            extended classes
+     * @return {@link org.opendaylight.controller.sal.core.Property}
+     */
+    public Property getControllerProperty(String propertyName);
+
+    /**
+     * Set a specific property of the controller
+     *
+     * @param property
+     *            {@link org.opendaylight.controller.sal.core.Property}
+     * @return
+     */
+    public Status setControllerProperty(Property property);
+
+    /**
+     * Remove a property of a node
+     *
+     * @param propertyName
+     *            the property name specified by
+     *            {@link org.opendaylight.controller.sal.core.Property} and its
+     *            extended classes
+     * @return success or failed reason
+     */
+    public Status removeControllerProperty(String propertyName);
 }
 }
index e76bf9aff1f3e67c0a9e99fbef457c23262bf0fd..1a787c7dc12ed38f25df230b39cb25fc92b61509 100644 (file)
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
     </dependency>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
index bb54857c1f9461919e4ddc48a79038e1e8a42cad..99482debd6d7e51c84415d3064ed38d05b5ca77e 100644 (file)
@@ -1182,8 +1182,46 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
 
     @Override
     public Set<Node> getNodes() {
 
     @Override
     public Set<Node> getNodes() {
-        return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet())
-                : new HashSet<Node>();
+        return (nodeProps != null) ? new HashSet<Node>(nodeProps.keySet()) : new HashSet<Node>();
+    }
+
+    @Override
+    public Map<String, Property> getControllerProperties() {
+        return new HashMap<String, Property>(this.controllerProps);
+    }
+
+    @Override
+    public Property getControllerProperty(String propertyName) {
+        if (propertyName != null) {
+            HashMap<String, Property> propertyMap =  new HashMap<String, Property>(this.controllerProps);
+            return propertyMap.get(propertyName);
+        }
+        return null;
+    }
+
+    @Override
+    public Status setControllerProperty(Property property) {
+        if (property != null) {
+            this.controllerProps.put(property.getName(), property);
+            return new Status(StatusCode.SUCCESS);
+        }
+        return new Status(StatusCode.BADREQUEST, "Invalid property provided when setting property");
+    }
+
+    @Override
+    public Status removeControllerProperty(String propertyName) {
+        if (propertyName != null) {
+            if (this.controllerProps.containsKey(propertyName)) {
+                this.controllerProps.remove(propertyName);
+                if (!this.controllerProps.containsKey(propertyName)) {
+                    return new Status(StatusCode.SUCCESS);
+                }
+            }
+            String msg = "Unable to remove property " + propertyName + " from Controller";
+            return new Status(StatusCode.BADREQUEST, msg);
+        }
+        String msg = "Invalid property provided when removing property from Controller";
+        return new Status(StatusCode.BADREQUEST, msg);
     }
 
     /*
     }
 
     /*
@@ -2024,8 +2062,9 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
     }
 
     /**
     }
 
     /**
-     * Creates a Name/Tier/Bandwidth Property object based on given property
-     * name and value. Other property types are not supported yet.
+     * Creates a Name/Tier/Bandwidth/MacAddress(controller property) Property
+     * object based on given property name and value. Other property types are
+     * not supported yet.
      *
      * @param propName
      *            Name of the Property
      *
      * @param propName
      *            Name of the Property
@@ -2056,7 +2095,10 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
             } else if (propName.equalsIgnoreCase(ForwardingMode.name)) {
                 int mode = Integer.parseInt(propValue);
                 return new ForwardingMode(mode);
             } else if (propName.equalsIgnoreCase(ForwardingMode.name)) {
                 int mode = Integer.parseInt(propValue);
                 return new ForwardingMode(mode);
-            } else {
+            } else if (propName.equalsIgnoreCase(MacAddress.name)){
+                return new MacAddress(propValue);
+            }
+            else {
                 log.debug("Not able to create {} property", propName);
             }
         } catch (Exception e) {
                 log.debug("Not able to create {} property", propName);
             }
         } catch (Exception e) {
@@ -2066,6 +2108,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa
         return null;
     }
 
         return null;
     }
 
+
     @SuppressWarnings("deprecation")
     @Override
     public String getNodeDescription(Node node) {
     @SuppressWarnings("deprecation")
     @Override
     public String getNodeDescription(Node node) {
index 4a14c1513afb6d3f100d8b2023e1104cd72dacb8..5d8ce9b303067c68e79cc82fbf2a3293ac1e72ce 100644 (file)
@@ -21,6 +21,7 @@
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
     <dependency>
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>switchmanager</artifactId>
+      <version>0.6.1-SNAPSHOT</version>
     </dependency>
       <dependency>
       <groupId>org.opendaylight.controller</groupId>
     </dependency>
       <dependency>
       <groupId>org.opendaylight.controller</groupId>
diff --git a/pom.xml b/pom.xml
index ec045f10cd915eab9f50bafcc0888b6a37caa62f..5899d563e8dd2d1d5a38e8bc7e0288dbcc39bf4c 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <module>opendaylight/northbound/jolokia</module>
     <module>opendaylight/northbound/connectionmanager</module>
     <module>opendaylight/northbound/usermanager</module>
     <module>opendaylight/northbound/jolokia</module>
     <module>opendaylight/northbound/connectionmanager</module>
     <module>opendaylight/northbound/usermanager</module>
+    <module>opendaylight/northbound/controllermanager</module>
 
     <!-- Northbound integration tests -->
     <module>opendaylight/northbound/integrationtest</module>
 
     <!-- Northbound integration tests -->
     <module>opendaylight/northbound/integrationtest</module>