Merge "Remove powermock dependency from md-sal." jenkins-controller-bulk-release-prepare-only-2-3
authorGiovanni Meo <gmeo@cisco.com>
Fri, 24 Jan 2014 10:03:28 +0000 (10:03 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 24 Jan 2014 10:03:28 +0000 (10:03 +0000)
opendaylight/clustering/integrationtest/src/test/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusteringServicesIT.java
opendaylight/configuration/api/src/main/java/org/opendaylight/controller/configuration/ConfigurationObject.java [new file with mode: 0644]
opendaylight/containermanager/api/pom.xml
opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerConfig.java
opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerFlowConfig.java
opendaylight/forwarding/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/StaticRouteConfig.java
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowConfig.java
opendaylight/switchmanager/api/src/main/java/org/opendaylight/controller/switchmanager/SubnetConfig.java

index fa2e2ee..9c9831f 100644 (file)
@@ -99,6 +99,7 @@ public class ClusteringServicesIT {
             mavenBundle("org.opendaylight.controller", "sal").versionAsInProject(),\r
             mavenBundle("org.opendaylight.controller",\r
                         "sal.implementation").versionAsInProject(),\r
+            mavenBundle("org.opendaylight.controller", "configuration").versionAsInProject(),\r
             mavenBundle("org.opendaylight.controller", "containermanager").versionAsInProject(),\r
             mavenBundle("org.opendaylight.controller",\r
                         "containermanager.it.implementation").versionAsInProject(),\r
@@ -133,10 +134,10 @@ public class ClusteringServicesIT {
         assertNotNull(bc);\r
         boolean debugit = false;\r
         Bundle b[] = bc.getBundles();\r
-        for (int i = 0; i < b.length; i++) {\r
-            int state = b[i].getState();\r
+        for (Bundle element : b) {\r
+            int state = element.getState();\r
             if (state != Bundle.ACTIVE && state != Bundle.RESOLVED) {\r
-                log.debug("Bundle:" + b[i].getSymbolicName() + " state:"\r
+                log.debug("Bundle:" + element.getSymbolicName() + " state:"\r
                           + stateToString(state));\r
                 debugit = true;\r
             }\r
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 (file)
index 0000000..34542de
--- /dev/null
@@ -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;
+    }
+}
index 744198a..b6c4d4c 100644 (file)
@@ -28,6 +28,7 @@
         <configuration>
           <instructions>
             <Import-Package>
+              org.opendaylight.controller.configuration,
               org.opendaylight.controller.sal.authorization,
               org.opendaylight.controller.sal.utils,
               org.opendaylight.controller.sal.core,
@@ -55,5 +56,9 @@
       <groupId>org.opendaylight.controller</groupId>
       <artifactId>sal</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>configuration</artifactId>
+    </dependency>
   </dependencies>
 </project>
index 99568df..3c086cb 100644 (file)
@@ -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");
     }
 
index 9d65ad3..6abd1ac 100644 (file)
@@ -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
      *
index a4505c8..7726c0f 100644 (file)
@@ -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;
     }
 
index de6b818..c56eb60 100644 (file)
@@ -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");
             }
 
index 4f06b79..b3dead5 100644 (file)
@@ -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);