From b2b9f320d79eac0253f2417b11eb74bdbc095c66 Mon Sep 17 00:00:00 2001 From: Katelyn Kasperowicz Date: Wed, 23 Oct 2013 15:20:50 -0700 Subject: [PATCH] Provide northbound for controller properties Change-Id: Ie68e557287ae72bd6456ad8d63c7d1804429b64d Signed-off-by: Katelyn Kasperowicz --- opendaylight/commons/opendaylight/pom.xml | 2 +- .../distribution/opendaylight/pom.xml | 5 + .../integrationtest/pom.xml | 1 + .../hosttracker/integrationtest/pom.xml | 1 + .../controllermanager/enunciate.xml | 12 + .../northbound/controllermanager/pom.xml | 126 ++++++++ .../ControllerManagerNorthbound.java | 272 ++++++++++++++++++ .../northbound/ControllerProperties.java | 63 ++++ .../src/main/resources/WEB-INF/web.xml | 89 ++++++ .../ControllerManagerNorthboundTest.java | 24 ++ .../northbound/integrationtest/pom.xml | 1 + .../statisticsmanager/integrationtest/pom.xml | 1 + opendaylight/switchmanager/api/pom.xml | 2 +- .../switchmanager/ISwitchManager.java | 40 +++ .../switchmanager/implementation/pom.xml | 1 + .../switchmanager/internal/SwitchManager.java | 53 +++- .../switchmanager/integrationtest/pom.xml | 1 + pom.xml | 1 + 18 files changed, 688 insertions(+), 7 deletions(-) create mode 100644 opendaylight/northbound/controllermanager/enunciate.xml create mode 100644 opendaylight/northbound/controllermanager/pom.xml create mode 100644 opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java create mode 100644 opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerProperties.java create mode 100644 opendaylight/northbound/controllermanager/src/main/resources/WEB-INF/web.xml create mode 100644 opendaylight/northbound/controllermanager/src/test/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthboundTest.java diff --git a/opendaylight/commons/opendaylight/pom.xml b/opendaylight/commons/opendaylight/pom.xml index 0221552686..7cd3beaac9 100644 --- a/opendaylight/commons/opendaylight/pom.xml +++ b/opendaylight/commons/opendaylight/pom.xml @@ -80,7 +80,7 @@ 0.2.2-SNAPSHOT 1.0-SNAPSHOT 0.5.1-SNAPSHOT - 0.5.1-SNAPSHOT + 0.6.1-SNAPSHOT 0.1.1-SNAPSHOT 0.6.0-SNAPSHOT 0.0.2-SNAPSHOT diff --git a/opendaylight/distribution/opendaylight/pom.xml b/opendaylight/distribution/opendaylight/pom.xml index 81164ae752..705bce7b89 100644 --- a/opendaylight/distribution/opendaylight/pom.xml +++ b/opendaylight/distribution/opendaylight/pom.xml @@ -633,6 +633,11 @@ usermanager.northbound 0.0.1-SNAPSHOT + + org.opendaylight.controller + controllermanager.northbound + 0.0.1-SNAPSHOT + diff --git a/opendaylight/forwardingrulesmanager/integrationtest/pom.xml b/opendaylight/forwardingrulesmanager/integrationtest/pom.xml index fa6f0ab343..15b31d5ea6 100644 --- a/opendaylight/forwardingrulesmanager/integrationtest/pom.xml +++ b/opendaylight/forwardingrulesmanager/integrationtest/pom.xml @@ -71,6 +71,7 @@ org.opendaylight.controller switchmanager + 0.6.1-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/hosttracker/integrationtest/pom.xml b/opendaylight/hosttracker/integrationtest/pom.xml index d41222c96e..7274ef8e55 100644 --- a/opendaylight/hosttracker/integrationtest/pom.xml +++ b/opendaylight/hosttracker/integrationtest/pom.xml @@ -70,6 +70,7 @@ org.opendaylight.controller switchmanager + 0.6.1-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/northbound/controllermanager/enunciate.xml b/opendaylight/northbound/controllermanager/enunciate.xml new file mode 100644 index 0000000000..13a2d27c41 --- /dev/null +++ b/opendaylight/northbound/controllermanager/enunciate.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + diff --git a/opendaylight/northbound/controllermanager/pom.xml b/opendaylight/northbound/controllermanager/pom.xml new file mode 100644 index 0000000000..d1299a2559 --- /dev/null +++ b/opendaylight/northbound/controllermanager/pom.xml @@ -0,0 +1,126 @@ + + + 4.0.0 + + org.opendaylight.controller + commons.opendaylight + 1.4.1-SNAPSHOT + ../../commons/opendaylight + + controllermanager.northbound + 0.0.1-SNAPSHOT + bundle + + 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 + + + + + + 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 + + + ${project.artifactId} + + 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 + + /controller/nb/v2/controllermanager + ,${classes;ANNOTATION;javax.ws.rs.Path} + + ${project.basedir}/src/main/resources/META-INF + + + + + + + org.opendaylight.controller.thirdparty + com.sun.jersey.jersey-servlet + 1.18-SNAPSHOT + + + + org.opendaylight.controller + containermanager + 0.5.1-SNAPSHOT + + + org.opendaylight.controller + switchmanager + 0.6.1-SNAPSHOT + + + + org.opendaylight.controller + sal + 0.5.1-SNAPSHOT + + + + org.opendaylight.controller + commons.northbound + 0.4.1-SNAPSHOT + + + + org.springframework + spring-web + ${spring.version} + provided + + + + org.codehaus.enunciate + enunciate-core-annotations + ${enunciate.version} + + + junit + junit + + + org.opendaylight.controller.thirdparty + org.apache.catalina.filters.CorsFilter + 7.0.43-SNAPSHOT + + + 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 index 0000000000..c515396212 --- /dev/null +++ b/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthbound.java @@ -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: + * + * + * + * + * 3e:04:ef:11:13:80 + * + * + * + * + * 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 propertyMap = switchManager.getControllerProperties(); + Set properties = new HashSet(propertyMap.values()); + return new ControllerProperties(properties); + } + + Set properties = new HashSet(); + 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 index 0000000000..ac0d039746 --- /dev/null +++ b/opendaylight/northbound/controllermanager/src/main/java/org/opendaylight/controller/controllermanager/northbound/ControllerProperties.java @@ -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 properties; + + // JAXB required constructor + private ControllerProperties() { + this.properties = null; + } + + public ControllerProperties(Set properties) { + this.properties = properties; + } + + @JsonProperty(value="properties") + public Map getMapProperties() { + Map map = new HashMap(); + for (Property p : properties) { + map.put(p.getName(), p); + } + return map; + } + + public void setMapProperties(Map propertiesMap) { + this.properties = new HashSet(propertiesMap.values()); + } + + public Set getProperties() { + return properties; + } + + public void setProperties(Set 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 index 0000000000..2efd81c44e --- /dev/null +++ b/opendaylight/northbound/controllermanager/src/main/resources/WEB-INF/web.xml @@ -0,0 +1,89 @@ + + + + JAXRSSwitchManager + com.sun.jersey.spi.container.servlet.ServletContainer + + javax.ws.rs.Application + org.opendaylight.controller.northbound.commons.NorthboundApplication + + 1 + + + + JAXRSSwitchManager + /* + + + + 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 + Container-User + + + + + System-Admin + + + Network-Admin + + + Network-Operator + + + Container-User + + + + BASIC + opendaylight + + \ 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 index 0000000000..a57e615618 --- /dev/null +++ b/opendaylight/northbound/controllermanager/src/test/java/org/opendaylight/controller/controllermanager/northbound/ControllerManagerNorthboundTest.java @@ -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 properties = new HashSet(); + controllerProperties.setProperties(properties); + Assert.assertTrue(controllerProperties.getProperties().equals(properties)); + } + +} diff --git a/opendaylight/northbound/integrationtest/pom.xml b/opendaylight/northbound/integrationtest/pom.xml index 7bb06c461d..4b79865ca9 100644 --- a/opendaylight/northbound/integrationtest/pom.xml +++ b/opendaylight/northbound/integrationtest/pom.xml @@ -134,6 +134,7 @@ org.opendaylight.controller switchmanager + 0.6.1-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/statisticsmanager/integrationtest/pom.xml b/opendaylight/statisticsmanager/integrationtest/pom.xml index c8b458ea77..c9103994a0 100644 --- a/opendaylight/statisticsmanager/integrationtest/pom.xml +++ b/opendaylight/statisticsmanager/integrationtest/pom.xml @@ -75,6 +75,7 @@ org.opendaylight.controller switchmanager + 0.6.1-SNAPSHOT diff --git a/opendaylight/switchmanager/api/pom.xml b/opendaylight/switchmanager/api/pom.xml index bf6d1b7bda..cf4c514965 100644 --- a/opendaylight/switchmanager/api/pom.xml +++ b/opendaylight/switchmanager/api/pom.xml @@ -16,7 +16,7 @@ switchmanager - 0.5.1-SNAPSHOT + 0.6.1-SNAPSHOT bundle diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java index 9ac0b5055f..8815e5e8c0 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/ISwitchManager.java @@ -385,4 +385,44 @@ public interface ISwitchManager { */ @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 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); } diff --git a/opendaylight/switchmanager/implementation/pom.xml b/opendaylight/switchmanager/implementation/pom.xml index e76bf9aff1..1a787c7dc1 100644 --- a/opendaylight/switchmanager/implementation/pom.xml +++ b/opendaylight/switchmanager/implementation/pom.xml @@ -112,6 +112,7 @@ org.opendaylight.controller switchmanager + 0.6.1-SNAPSHOT org.opendaylight.controller diff --git a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java index bb54857c1f..99482debd6 100644 --- a/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java +++ b/opendaylight/switchmanager/implementation/src/main/java/org/opendaylight/controller/switchmanager/internal/SwitchManager.java @@ -1182,8 +1182,46 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa @Override public Set getNodes() { - return (nodeProps != null) ? new HashSet(nodeProps.keySet()) - : new HashSet(); + return (nodeProps != null) ? new HashSet(nodeProps.keySet()) : new HashSet(); + } + + @Override + public Map getControllerProperties() { + return new HashMap(this.controllerProps); + } + + @Override + public Property getControllerProperty(String propertyName) { + if (propertyName != null) { + HashMap propertyMap = new HashMap(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 @@ -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 { + } else if (propName.equalsIgnoreCase(MacAddress.name)){ + return new MacAddress(propValue); + } + else { log.debug("Not able to create {} property", propName); } } catch (Exception e) { @@ -2066,6 +2108,7 @@ public class SwitchManager implements ISwitchManager, IConfigurationContainerAwa return null; } + @SuppressWarnings("deprecation") @Override public String getNodeDescription(Node node) { diff --git a/opendaylight/switchmanager/integrationtest/pom.xml b/opendaylight/switchmanager/integrationtest/pom.xml index 4a14c1513a..5d8ce9b303 100644 --- a/opendaylight/switchmanager/integrationtest/pom.xml +++ b/opendaylight/switchmanager/integrationtest/pom.xml @@ -21,6 +21,7 @@ org.opendaylight.controller switchmanager + 0.6.1-SNAPSHOT org.opendaylight.controller diff --git a/pom.xml b/pom.xml index ec045f10cd..5899d563e8 100644 --- a/pom.xml +++ b/pom.xml @@ -115,6 +115,7 @@ opendaylight/northbound/jolokia opendaylight/northbound/connectionmanager opendaylight/northbound/usermanager + opendaylight/northbound/controllermanager opendaylight/northbound/integrationtest -- 2.36.6