From: Giovanni Meo Date: Fri, 24 Jan 2014 10:03:28 +0000 (+0000) Subject: Merge "Remove powermock dependency from md-sal." X-Git-Tag: jenkins-controller-bulk-release-prepare-only-2-3^0 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=642eb8ecef35197915cd766dd60439812122b0c5;hp=3e29efdc05872e00c92c84a27ec6889f4e877cff Merge "Remove powermock dependency from md-sal." --- diff --git a/opendaylight/clustering/integrationtest/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusteringServicesIT.java b/opendaylight/clustering/integrationtest/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusteringServicesIT.java index fa2e2ee8fa..9c9831f4f5 100644 --- a/opendaylight/clustering/integrationtest/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusteringServicesIT.java +++ b/opendaylight/clustering/integrationtest/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusteringServicesIT.java @@ -99,6 +99,7 @@ public class ClusteringServicesIT { mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(), mavenBundle("org.opendaylight.controller", "sal.implementation").versionAsInProject(), + mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(), mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(), mavenBundle("org.opendaylight.controller", "containermanager.it.implementation").versionAsInProject(), @@ -133,10 +134,10 @@ public class ClusteringServicesIT { assertNotNull(bc); boolean debugit = false; Bundle b[] = bc.getBundles(); - for (int i = 0; i < b.length; i++) { - int state = b[i].getState(); + for (Bundle element : b) { + int state = element.getState(); if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) { - log.debug("Bundle:" + b[i].getSymbolicName() + " state:" + log.debug("Bundle:" + element.getSymbolicName() + " state:" + stateToString(state)); debugit = true; } diff --git a/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java b/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java new file mode 100644 index 0000000000..34542de896 --- /dev/null +++ b/opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java @@ -0,0 +1,46 @@ +/* + * 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.configuration; + +import java.io.Serializable; + +public abstract class ConfigurationObject implements Serializable { + private static final long serialVersionUID = 1L; + private static final String DEFAULT_REGEX = "^[\\w-\\+\\*\\/\\.\\(\\)\\[\\]\\@]{1,256}$"; + private static final String REGEX_PROP_NAME = "resourceNameRegularExpression"; + private static String regex; + + static { + String customRegex = System.getProperty(REGEX_PROP_NAME); + regex = (customRegex != null) ? customRegex : DEFAULT_REGEX; + } + + /** + * Checks if the provided resource name matches the controller resource name + * regular expression + * + * @param name + * The resource name to test + * @return true if the resource name is not null and matches the controller + * resource name regular expression, false otherwise + */ + protected boolean isValidResourceName(String name) { + return (name != null) ? name.matches(regex) : false; + } + + /** + * Return the regular expression currently in use for testing the controller + * resource names + * + * @return The regular expression + */ + public static String getRegularExpression() { + return regex; + } +} diff --git a/opendaylight/containermanager/api/pom.xml b/opendaylight/containermanager/api/pom.xml index 744198acf8..b6c4d4c2a3 100644 --- a/opendaylight/containermanager/api/pom.xml +++ b/opendaylight/containermanager/api/pom.xml @@ -28,6 +28,7 @@ + org.opendaylight.controller.configuration, org.opendaylight.controller.sal.authorization, org.opendaylight.controller.sal.utils, org.opendaylight.controller.sal.core, @@ -55,5 +56,9 @@ org.opendaylight.controller sal + + org.opendaylight.controller + configuration + diff --git a/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerConfig.java b/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerConfig.java index 99568dfcce..3c086cbce0 100644 --- a/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerConfig.java +++ b/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerConfig.java @@ -20,6 +20,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.sal.core.ContainerFlow; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.match.Match; @@ -37,7 +38,7 @@ import org.opendaylight.controller.sal.utils.StatusCode; */ @XmlRootElement(name = "containerConfig") @XmlAccessorType(XmlAccessType.NONE) -public class ContainerConfig implements Serializable { +public class ContainerConfig extends ConfigurationObject implements Serializable { private static final long serialVersionUID = 2L; private static final String regexName = "^\\w+$"; private static final String containerProfile = System.getProperty("container.profile") == null ? "Container" @@ -227,7 +228,7 @@ public class ContainerConfig implements Serializable { */ private Status validateName() { // No Container configuration allowed to container default - return ((container != null) && container.matches(regexName) && !container.equalsIgnoreCase(GlobalConstants.DEFAULT.toString())) ? + return (isValidResourceName(container) && !container.equalsIgnoreCase(GlobalConstants.DEFAULT.toString())) ? new Status(StatusCode.SUCCESS) : new Status(StatusCode.BADREQUEST, "Invalid container name"); } diff --git a/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java b/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java index 9d65ad343c..6abd1acd40 100644 --- a/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java +++ b/opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java @@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.sal.match.Match; import org.opendaylight.controller.sal.match.MatchType; import org.opendaylight.controller.sal.packet.BitBufferHelper; @@ -44,15 +45,12 @@ import org.slf4j.LoggerFactory; */ @XmlRootElement (name = "flow-spec-config") @XmlAccessorType(XmlAccessType.NONE) -public class ContainerFlowConfig implements Serializable { +public class ContainerFlowConfig extends ConfigurationObject implements Serializable { private static Logger log = LoggerFactory.getLogger(ContainerFlowConfig.class); /** The Constant serialVersionUID. */ private static final long serialVersionUID = 1L; - /** The Constant regexName. */ - private static final String regexName = "^[\\w-+.@]+$"; - /** Flow Spec name. */ @XmlElement private String name; @@ -596,7 +594,7 @@ public class ContainerFlowConfig implements Serializable { * @return true, if is valid */ public Status validate() { - if (!hasValidName()) { + if (!isValidResourceName(name)) { return new Status(StatusCode.BADREQUEST, "Invalid name"); } Status status = validateVlan(); @@ -619,15 +617,6 @@ public class ContainerFlowConfig implements Serializable { return new Status(StatusCode.SUCCESS); } - /** - * Checks if this flow specification configuration has a valid name. - * - * @return true, if successful - */ - private boolean hasValidName() { - return (name != null && !name.isEmpty() && name.matches(regexName)); - } - /** * Validates the vlan number * diff --git a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/StaticRouteConfig.java b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/StaticRouteConfig.java index a4505c8b1c..7726c0f4e7 100644 --- a/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/StaticRouteConfig.java +++ b/opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/StaticRouteConfig.java @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.sal.utils.GUIField; import org.opendaylight.controller.sal.utils.Status; import org.opendaylight.controller.sal.utils.StatusCode; @@ -25,7 +26,7 @@ import org.opendaylight.controller.sal.utils.StatusCode; /** * This class defines all the necessary configuration information for a static route. */ -public class StaticRouteConfig implements Serializable { +public class StaticRouteConfig extends ConfigurationObject implements Serializable { private static final long serialVersionUID = 1L; private static final String regexSubnet = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." @@ -150,7 +151,7 @@ public class StaticRouteConfig implements Serializable { * @return SUCCESS if the config is valid */ public Status isValid() { - if ((name == null) || (name.trim().length() < 1)) { + if (!isValidResourceName(name)) { return new Status(StatusCode.BADREQUEST, "Invalid Static Route name"); } @@ -207,8 +208,9 @@ public class StaticRouteConfig implements Serializable { if (getNextHopType().equalsIgnoreCase( StaticRoute.NextHopType.SWITCHPORT.toString())) { String pieces[] = nextHop.split("/"); - if (pieces.length < 2) + if (pieces.length < 2) { return false; + } return isValidSwitchId(pieces[0]); } return false; @@ -350,20 +352,26 @@ public class StaticRouteConfig implements Serializable { } StaticRouteConfig other = (StaticRouteConfig) obj; if (name == null) { - if (other.name != null) + if (other.name != null) { return false; - } else if (!name.equals(other.name)) + } + } else if (!name.equals(other.name)) { return false; + } if (nextHop == null) { - if (other.nextHop != null) + if (other.nextHop != null) { return false; - } else if (!nextHop.equals(other.nextHop)) + } + } else if (!nextHop.equals(other.nextHop)) { return false; + } if (staticRoute == null) { - if (other.staticRoute != null) + if (other.staticRoute != null) { return false; - } else if (!staticRoute.equals(other.staticRoute)) + } + } else if (!staticRoute.equals(other.staticRoute)) { return false; + } return true; } diff --git a/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java index de6b8182b0..c56eb60a6b 100644 --- a/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java +++ b/opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java @@ -8,6 +8,7 @@ package org.opendaylight.controller.forwardingrulesmanager; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.sal.action.Action; import org.opendaylight.controller.sal.action.ActionType; import org.opendaylight.controller.sal.action.Controller; @@ -67,10 +68,9 @@ import java.util.regex.Pattern; */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class FlowConfig implements Serializable { +public class FlowConfig extends ConfigurationObject implements Serializable { private static final long serialVersionUID = 1L; private static final Logger log = LoggerFactory.getLogger(FlowConfig.class); - private static final String NAMEREGEX = "^[a-zA-Z0-9]+$"; public static final String STATICFLOWGROUP = "__StaticFlows__"; public static final String INTERNALSTATICFLOWGROUP = "__InternalStaticFlows__"; public static final String INTERNALSTATICFLOWBEGIN = "__"; @@ -687,7 +687,8 @@ public class FlowConfig implements Serializable { Switch sw = null; try { - if (name == null || name.trim().isEmpty() || !name.matches(FlowConfig.NAMEREGEX)) { + // Flow name cannot be internal flow signature + if (!isValidResourceName(name) || isInternalFlow()) { return new Status(StatusCode.BADREQUEST, "Invalid name"); } diff --git a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java index 4f06b79f49..b3dead5fa4 100644 --- a/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java +++ b/opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java @@ -20,6 +20,7 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; +import org.opendaylight.controller.configuration.ConfigurationObject; import org.opendaylight.controller.sal.core.NodeConnector; import org.opendaylight.controller.sal.packet.BitBufferHelper; import org.opendaylight.controller.sal.utils.GUIField; @@ -32,7 +33,7 @@ import org.opendaylight.controller.sal.utils.StatusCode; */ @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) -public class SubnetConfig implements Cloneable, Serializable { +public class SubnetConfig extends ConfigurationObject implements Cloneable, Serializable { private static final long serialVersionUID = 1L; private static final String prettyFields[] = { GUIField.NAME.toString(), GUIField.GATEWAYIP.toString(), GUIField.NODEPORTS.toString() }; @@ -148,7 +149,7 @@ public class SubnetConfig implements Cloneable, Serializable { } private Status validateName() { - if (name == null || name.trim().isEmpty()) { + if (!isValidResourceName(name)) { return new Status(StatusCode.BADREQUEST, "Invalid name"); } return new Status(StatusCode.SUCCESS);