Merge "In o.o.c.switchmanager.SpanConfig, handle node connector string format correctly."
authorGiovanni Meo <gmeo@cisco.com>
Wed, 18 Sep 2013 10:27:47 +0000 (10:27 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 18 Sep 2013 10:27:47 +0000 (10:27 +0000)
81 files changed:
opendaylight/clustering/integrationtest/pom.xml
opendaylight/clustering/services_implementation/pom.xml
opendaylight/clustering/services_implementation/src/main/java/org/opendaylight/controller/clustering/services_implementation/internal/ClusterManagerCommon.java
opendaylight/clustering/stub/src/main/java/org/opendaylight/controller/clustering/stub/internal/ClusterManagerCommon.java
opendaylight/commons/opendaylight/pom.xml
opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/ContainerConfig.java
opendaylight/containermanager/it.implementation/src/main/java/org/opendaylight/controller/containermanager/internal/ContainerManager.java
opendaylight/distribution/opendaylight/pom.xml
opendaylight/forwardingrulesmanager/api/src/main/java/org/opendaylight/controller/forwardingrulesmanager/FlowEntryInstall.java
opendaylight/forwardingrulesmanager/implementation/pom.xml
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/implementation/data/FlowEntryDistributionOrder.java
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java
opendaylight/forwardingrulesmanager/integrationtest/pom.xml
opendaylight/hosttracker/implementation/pom.xml
opendaylight/hosttracker/integrationtest/pom.xml
opendaylight/hosttracker_new/implementation/pom.xml
opendaylight/northbound/bundlescanner/api/pom.xml [new file with mode: 0644]
opendaylight/northbound/bundlescanner/api/src/main/java/org/opendaylight/controller/northbound/bundlescanner/IBundleScanService.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/pom.xml [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/Activator.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleInfo.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanServiceImpl.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Animal.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/BasePerson.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Mammal.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/NoAnnotation.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/NonRelevantAnnotation.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Person.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_misc/Misc.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub1/NoAnnotation.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub1/Zoo.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/Agent.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/Customer.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/NoAnnotation.java [new file with mode: 0644]
opendaylight/northbound/bundlescanner/implementation/src/test/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScannerTest.java [new file with mode: 0644]
opendaylight/northbound/commons/pom.xml
opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java [new file with mode: 0644]
opendaylight/northbound/containermanager/pom.xml
opendaylight/northbound/flowprogrammer/pom.xml
opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthboundRSApplication.java [deleted file]
opendaylight/northbound/flowprogrammer/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/hosttracker/pom.xml
opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthboundRSApplication.java [deleted file]
opendaylight/northbound/hosttracker/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/integrationtest/pom.xml
opendaylight/northbound/integrationtest/src/test/java/org/opendaylight/controller/northbound/integrationtest/NorthboundIT.java
opendaylight/northbound/networkconfiguration/bridgedomain/pom.xml
opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthboundApplication.java [deleted file]
opendaylight/northbound/networkconfiguration/bridgedomain/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/staticrouting/pom.xml
opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthboundRSApplication.java [deleted file]
opendaylight/northbound/staticrouting/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/statistics/pom.xml
opendaylight/northbound/statistics/src/main/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundRSApplication.java [deleted file]
opendaylight/northbound/statistics/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/subnets/pom.xml
opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthboundRSApplication.java [deleted file]
opendaylight/northbound/subnets/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/switchmanager/pom.xml
opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthboundRSApplication.java [deleted file]
opendaylight/northbound/switchmanager/src/main/resources/WEB-INF/web.xml
opendaylight/northbound/topology/pom.xml
opendaylight/northbound/topology/src/main/java/org/opendaylight/controller/topology/northbound/TopologyNorthboundRSApplication.java [deleted file]
opendaylight/northbound/topology/src/main/resources/WEB-INF/web.xml
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/ISwitch.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/FlowStatisticsConverter.java
opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/internal/InventoryServiceShim.java
opendaylight/sal/implementation/src/main/java/org/opendaylight/controller/sal/implementation/internal/FlowProgrammerService.java
opendaylight/samples/northbound/loadbalancer/pom.xml
opendaylight/samples/northbound/loadbalancer/src/main/java/org/opendaylight/controller/samples/loadbalancer/northbound/LoadBalancerNorthboundRSApplication.java [deleted file]
opendaylight/samples/northbound/loadbalancer/src/main/resources/WEB-INF/web.xml
opendaylight/statisticsmanager/implementation/pom.xml
opendaylight/statisticsmanager/integrationtest/pom.xml
opendaylight/switchmanager/api/pom.xml
opendaylight/switchmanager/implementation/pom.xml
opendaylight/switchmanager/integrationtest/pom.xml
opendaylight/usermanager/implementation/src/main/java/org/opendaylight/controller/usermanager/internal/UserManager.java
opendaylight/web/topology/src/main/java/org/opendaylight/controller/topology/web/Topology.java
third-party/openflowj/src/main/java/org/openflow/protocol/OFType.java

index 0fadb128901cd16749511f32c58e2ea71973fc75..93b3624c82e69e5b12c2f759ae4211656048b5f2 100644 (file)
@@ -69,7 +69,7 @@
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
-        <version>0.5.3.201107060350</version>
+        <version>${jacoco.version}</version>
         <configuration>
           <destFile>../implementation/target/jacoco-it.exec</destFile>
           <includes>org.opendaylight.controller.*</includes>
index c0a8064493d6d303ba24fb75466751f8f8c75aa0..d6bd287434a499c19b1aa1576b0aa11ee303344d 100644 (file)
@@ -30,7 +30,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
index fabf3e9f1d704413346d97b98c561e8d2adc8a16..90299e5ac960dcbd34c63df4cd8418c5b57ddf5f 100644 (file)
@@ -39,7 +39,7 @@ import org.opendaylight.controller.clustering.services.ListenRoleChangeAddExcept
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-abstract public class ClusterManagerCommon implements IClusterServicesCommon {
+public abstract class ClusterManagerCommon implements IClusterServicesCommon {
     protected String containerName = null;
     private IClusterServices clusterService = null;
     protected static final Logger logger = LoggerFactory
index 035b0d3433e413b928e4ce753f9bea1d034e0218..975f97c8e5104a75ef56080ca5d59717098cb38c 100644 (file)
@@ -45,7 +45,7 @@ import org.apache.felix.dm.Component;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-abstract public class ClusterManagerCommon implements IClusterServicesCommon {
+public abstract class ClusterManagerCommon implements IClusterServicesCommon {
     protected String containerName = "";
     protected static final Logger logger = LoggerFactory
             .getLogger(ClusterManagerCommon.class);
index 075ccb1bfa58bff729814c4ccd65eaa2dbb17458..9d7950af7395fd1c1f5a5fa79012574eee321870 100644 (file)
@@ -55,6 +55,7 @@
     <sample-toaster.version>1.0-SNAPSHOT</sample-toaster.version>
     <releaseplugin.version>2.3.2</releaseplugin.version>
     <commons.lang.version>3.1</commons.lang.version>
+    <jacoco.version>0.5.3.201107060350</jacoco.version>
   </properties>
 
   <pluginRepositories>
       <artifactId>jersey-json</artifactId>
       <version>${jersey.version}</version>
     </dependency>
+    <dependency>
+        <groupId>org.ow2.asm</groupId>
+        <artifactId>asm-all</artifactId>
+        <version>4.1</version>
+    </dependency>
   </dependencies>
 </project>
index 01715cc1bf1e98960266f1832460aec1b74942e2..89bf424e67a4465c885c82b2ec3206d559709064 100644 (file)
@@ -223,7 +223,7 @@ public class ContainerConfig implements Serializable {
      */
     private Status validateName() {
         // No Container configuration allowed to container default
-        return (container.matches(regexName) && !container.equalsIgnoreCase(GlobalConstants.DEFAULT.toString())) ?
+        return ((container != null) && container.matches(regexName) && !container.equalsIgnoreCase(GlobalConstants.DEFAULT.toString())) ?
                 new Status(StatusCode.SUCCESS) : new Status(StatusCode.BADREQUEST, "Invalid container name");
     }
 
@@ -386,11 +386,38 @@ public class ContainerConfig implements Serializable {
                             config.getName()));
                 }
             }
+        } else {
+            // Check for conflicting names with existing cFlows
+            List<String> conflicting = new ArrayList<String>(existingNames);
+            conflicting.retainAll(proposedNames);
+            if (!conflicting.isEmpty()) {
+                return new Status(StatusCode.CONFLICT,
+                        "Invalid Flow Spec configuration: flow spec name(s) conflict with existing flow specs: "
+                                + conflicting.toString());
+            }
+
+            /*
+             * Check for conflicting flow spec match (we only check for strict
+             * equality). Remove this in case (*) is reintroduced
+             */
+            if (this.containerFlows != null && !this.containerFlows.isEmpty()) {
+                Set<Match> existingMatches = new HashSet<Match>();
+                for (ContainerFlowConfig existing : this.containerFlows) {
+                    existingMatches.addAll(existing.getMatches());
+                }
+                for (ContainerFlowConfig proposed : cFlowConfigs) {
+                    if (existingMatches.removeAll(proposed.getMatches())) {
+                        return new Status(StatusCode.CONFLICT, String.format(
+                                "Invalid Flow Spec configuration: %s conflicts with existing flow spec",
+                                proposed.getName()));
+                    }
+                }
+            }
         }
+
         /*
          * Revisit the following flow-spec confict validation later based on more testing.
-         */
-         /*
+         * (*)
         if (!delete) {
             // Check for overlapping container flows in the request
             int size = cFlowConfigs.size();
index b5624af6afc8e916572bad446ab1e1438a166b3a..24ef0c08ef9d78a4f3410ded6f998af0281065d3 100644 (file)
@@ -192,8 +192,7 @@ public class ContainerManager implements IContainerManager {
 
     @Override
     public boolean doesContainerExist(String ContainerId) {
-        // TODO Auto-generated method stub
-        return false;
+        return GlobalConstants.DEFAULT.toString().equalsIgnoreCase(ContainerId);
     }
 
     @Override
index 56ca0c951be5a0c2a0664a70e7f6ac5aa4ada061..1fb131e4aff8fc6e5c505e6437bc8a5dc6c2e2b9 100644 (file)
 
     <!-- Northbound bundles -->
     <module>../../northbound/commons</module>
+    <module>../../northbound/bundlescanner/api</module>
+    <module>../../northbound/bundlescanner/implementation</module>
     <module>../../northbound/topology</module>
     <module>../../northbound/staticrouting</module>
     <module>../../northbound/statistics</module>
index ee2113db8287066f7337a147ade4e7d9048bf2ea..1318c97ce22e40016fb113a4d1c46d524eba7c1b 100644 (file)
@@ -28,8 +28,8 @@ public class FlowEntryInstall implements Serializable {
     private final FlowEntry original;
     private final ContainerFlow cFlow;
     private final FlowEntry install;
-    transient private long requestId; // async request id
-    transient private boolean deletePending;
+    private transient long requestId; // async request id
+    private transient boolean deletePending;
 
     public FlowEntryInstall(FlowEntry original, ContainerFlow cFlow) {
         this.original = original;
index ea55ac8b08951f14191cbcd900a6309c7154fcfc..d146eead6f0168e7e25cdd290459fb5ff20be7d2 100644 (file)
@@ -33,7 +33,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
index 5220428199c41920b50d2fcbc676e98ea52f3959..672a290a2427f6bb1676ab31f3b72e21ffaa922e 100644 (file)
@@ -27,9 +27,9 @@ public final class FlowEntryDistributionOrder implements Serializable {
      * Serialization UID
      */
     private static final long serialVersionUID = 416280377113255147L;
-    final private FlowEntryInstall entry;
-    final private UpdateType upType;
-    final private InetAddress requestorController;
+    private final FlowEntryInstall entry;
+    private final UpdateType upType;
+    private final InetAddress requestorController;
 
     /**
      * @return the entry
index 58d23655cac5a17353989c5cfd36d71a7a14ea74..4e6818c3062511b01c9b8f73d3f5fa610c73134d 100644 (file)
@@ -1867,9 +1867,13 @@ public class ForwardingRulesManager implements
             }
         }
         if (target != null) {
-            // Program the network node
-            Status status = (target.installInHw()) ? this.uninstallFlowEntry(target.getFlowEntry()) : this
-                    .installFlowEntry(target.getFlowEntry());
+            Status status = target.validate(container);
+            if (!status.isSuccess()) {
+                log.warn(status.getDescription());
+                return status;
+            }
+            status = (target.installInHw()) ? this.uninstallFlowEntry(target.getFlowEntry()) : this
+                                    .installFlowEntry(target.getFlowEntry());
             if (status.isSuccess()) {
                 // Update Configuration database
                 target.setStatus(SUCCESS);
index 77792435991ce414a6edf14590b7f9fe071a9b56..770fef03f261dc7f6435eb8ac5644f53afd306ca 100644 (file)
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
-        <version>0.5.3.201107060350</version>
+        <version>${jacoco.version}</version>
         <configuration>
           <destFile>../implementation/target/jacoco-it.exec</destFile>
           <includes>org.opendaylight.controller.*</includes>
index 268dd4f67f6039f9bde419b8a726d4fe23063ac7..e93559b42ccae19ac461607d5680b4a3db1e0ec6 100644 (file)
@@ -33,7 +33,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
index 81551650c34fe2a0eb49d0afeb2405ec75de4549..f2fefcdabcc05e7265ba811dbb9acd90fc14e4e1 100644 (file)
       <plugin>\r
         <groupId>org.jacoco</groupId>\r
         <artifactId>jacoco-maven-plugin</artifactId>\r
-        <version>0.5.3.201107060350</version>\r
+        <version>${jacoco.version}</version>\r
         <configuration>\r
           <destFile>../implementation/target/jacoco-it.exec</destFile>\r
           <includes>org.opendaylight.controller.*</includes>\r
index af2ea7b3475970cde2db15dfd660e13cdf177144..a4ff57b7f04348af9b9fbbee2a8b7f345905ef93 100644 (file)
@@ -33,7 +33,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
diff --git a/opendaylight/northbound/bundlescanner/api/pom.xml b/opendaylight/northbound/bundlescanner/api/pom.xml
new file mode 100644 (file)
index 0000000..2c96ec2
--- /dev/null
@@ -0,0 +1,46 @@
+<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.0-SNAPSHOT</version>
+    <relativePath>../../../commons/opendaylight</relativePath>
+  </parent>
+
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+  </scm>
+
+  <artifactId>bundlescanner</artifactId>
+  <version>0.4.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <build>
+    <plugins>
+       <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.6</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>
+              org.osgi.framework,
+              org.slf4j,
+              javax.ws.rs,
+              javax.ws.rs.core,
+              javax.xml.bind.annotation,
+              javax.xml.bind,
+            </Import-Package>
+            <Export-Package>
+                org.opendaylight.controller.northbound.bundlescanner
+            </Export-Package>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/opendaylight/northbound/bundlescanner/api/src/main/java/org/opendaylight/controller/northbound/bundlescanner/IBundleScanService.java b/opendaylight/northbound/bundlescanner/api/src/main/java/org/opendaylight/controller/northbound/bundlescanner/IBundleScanService.java
new file mode 100644 (file)
index 0000000..5cb0b63
--- /dev/null
@@ -0,0 +1,34 @@
+/**
+ * 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.northbound.bundlescanner;
+
+import java.util.List;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * The bundle scan service provides services which allow introspection of
+ * bundle classes for detecting annotated classes. The scanning is performed
+ * when a bundle is RESOLVED.
+ */
+public interface IBundleScanService {
+    /**
+     * The list of annotations to be scanned
+     */
+    public final String[] ANNOTATIONS_TO_SCAN = {
+        "javax.xml.bind.annotation.*", // JAXB annotatinos
+        "javax.ws.rs.*"                // JAX-RS annotatinos
+    };
+
+
+    public List<Class<?>> getAnnotatedClasses(
+            BundleContext context,
+            String[] annotations,
+            boolean includeDependentBundleClasses);
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/pom.xml b/opendaylight/northbound/bundlescanner/implementation/pom.xml
new file mode 100644 (file)
index 0000000..ceea28e
--- /dev/null
@@ -0,0 +1,73 @@
+<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.0-SNAPSHOT</version>
+    <relativePath>../../../commons/opendaylight</relativePath>
+  </parent>
+
+  <scm>
+    <connection>scm:git:ssh://git.opendaylight.org:29418/controller.git</connection>
+    <developerConnection>scm:git:ssh://git.opendaylight.org:29418/controller.git</developerConnection>
+    <url>https://wiki.opendaylight.org/view/OpenDaylight_Controller:Main</url>
+  </scm>
+
+  <artifactId>bundlescanner.implementation</artifactId>
+  <version>0.4.0-SNAPSHOT</version>
+  <packaging>bundle</packaging>
+
+  <build>
+    <plugins>
+       <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>2.3.6</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Import-Package>
+              org.apache.felix.dm,
+              org.objectweb.asm,
+              org.opendaylight.controller.sal.core,
+              org.opendaylight.controller.northbound.bundlescanner,
+              org.osgi.framework,
+              org.slf4j,
+              javax.ws.rs,
+              javax.ws.rs.core,
+              javax.xml.bind.annotation,
+              javax.xml.bind,
+            </Import-Package>
+            <Bundle-Activator>
+                org.opendaylight.controller.northbound.bundlescanner.internal.Activator
+            </Bundle-Activator>
+          </instructions>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+  <dependencies>
+      <dependency>
+          <groupId>org.ow2.asm</groupId>
+          <artifactId>asm-all</artifactId>
+          <version>4.1</version>
+      </dependency>
+      <dependency>
+        <groupId>org.springframework.osgi</groupId>
+        <artifactId>spring-osgi-mock</artifactId>
+        <version>1.2.1</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>bundlescanner</artifactId>
+        <version>0.4.0-SNAPSHOT</version>
+      </dependency>
+      <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>sal</artifactId>
+        <version>0.5.0-SNAPSHOT</version>
+      </dependency>
+  </dependencies>
+</project>
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/Activator.java b/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/Activator.java
new file mode 100644 (file)
index 0000000..6b0718c
--- /dev/null
@@ -0,0 +1,42 @@
+/**
+ * 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.northbound.bundlescanner.internal;
+
+import org.apache.felix.dm.Component;
+import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService;
+import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
+
+/**
+ * The activator registers the BundleScanner.
+ */
+public class Activator extends ComponentActivatorAbstractBase {
+
+    @Override
+    protected void init() {
+    }
+
+    @Override
+    protected void destroy() {
+    }
+
+    @Override
+    protected Object[] getGlobalImplementations() {
+        return new Object[] { BundleScanServiceImpl.class };
+    }
+
+    @Override
+    protected void configureGlobalInstance(Component c, Object imp) {
+        if (!imp.equals(BundleScanServiceImpl.class)) return;
+        // export service
+        c.setInterface(
+                new String[] { IBundleScanService.class.getName() },
+                null);
+    }
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleInfo.java b/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleInfo.java
new file mode 100644 (file)
index 0000000..a108931
--- /dev/null
@@ -0,0 +1,162 @@
+/**
+ * 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.northbound.bundlescanner.internal;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.osgi.framework.Bundle;
+import org.osgi.framework.Constants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * BundleInfo holds information related to the bundle obtained during the
+ * bundle scan process.
+ */
+/*package*/ class BundleInfo {
+    private static final Logger LOGGER = LoggerFactory.getLogger(BundleInfo.class);
+
+    private final Bundle bundle;
+    private final Map<String, Set<String>> annotatedClasses;
+    private final Set<String> exportPkgs;
+    private final Set<String> importPkgs;
+
+    public BundleInfo(Bundle bundle, Map<String, Set<String>> classes) {
+        this.bundle = bundle;
+        this.annotatedClasses = classes;
+        Dictionary<String, String> dict = bundle.getHeaders();
+        this.importPkgs = parsePackages(dict.get(Constants.IMPORT_PACKAGE));
+        this.exportPkgs = parsePackages(dict.get(Constants.EXPORT_PACKAGE));
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(super.toString());
+        sb.append("{name:").append(bundle.getSymbolicName())
+          .append(" id:").append(getId())
+          .append(" annotated-classes:").append(annotatedClasses)
+          .append(" imports:").append(importPkgs)
+          .append(" exports:").append(exportPkgs).append("}");
+        return sb.toString();
+    }
+
+    public Bundle getBundle() {
+        return bundle;
+    }
+
+    public long getId() {
+        return bundle.getBundleId();
+    }
+
+    public List<Class<?>> getAnnotatedClasses(Pattern pattern) {
+        List<String> result = new ArrayList<String>();
+        for (Map.Entry<String, Set<String>> entry : annotatedClasses.entrySet()) {
+            if (matches(pattern, entry.getValue())) {
+                result.add(entry.getKey());
+            }
+        }
+        return BundleScanner.loadClasses(bundle, result);
+    }
+
+    private boolean matches(Pattern pattern, Set<String> values) {
+        if (pattern == null) return true;
+        //LOGGER.debug("Matching: {} {}", pattern.toString(), values);
+        for (String s : values) {
+            if (pattern.matcher(s).find()) return true;
+        }
+        return false;
+    }
+
+    public List<Class<?>> getAnnotatedClasses(
+            Collection<BundleInfo> allbundles,
+            Pattern pattern)
+    {
+        List<Class<?>> classes = getAnnotatedClasses(pattern);
+        processAnnotatedClassesInternal(this, allbundles, pattern,
+                new HashSet<BundleInfo>(), classes);
+        return classes;
+    }
+
+    private List<String> getExportedAnnotatedClasses(Pattern pattern) {
+        List<String> classes = new ArrayList<String>();
+        for (Map.Entry<String, Set<String>> entry : annotatedClasses.entrySet()) {
+            String cls = entry.getKey();
+            int idx = cls.lastIndexOf(".");
+            String pkg = (idx == -1 ? "" : cls.substring(0, idx));
+            // for a class to match, the package has to be exported and
+            // annotations should match the given pattern
+            if (exportPkgs.contains(pkg) && matches(pattern, entry.getValue())) {
+                classes.add(cls);
+            }
+        }
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("Found in bundle:{} exported classes:[{}]",
+                    getBundle().getSymbolicName(), classes);
+        }
+        return classes;
+    }
+
+    private static void processAnnotatedClassesInternal(
+            BundleInfo target,
+            Collection<BundleInfo> bundlesToScan,
+            Pattern pattern,
+            Collection<BundleInfo> visited,
+            List<Class<?>> classes)
+    {
+        for (BundleInfo other : bundlesToScan) {
+            if (other.getId() == target.getId()) continue;
+            if (target.isDependantOn(other)) {
+                if (!visited.contains(other)) {
+                    classes.addAll(BundleScanner.loadClasses(other.getBundle(),
+                            other.getExportedAnnotatedClasses(pattern)));
+                    visited.add(other);
+                    processAnnotatedClassesInternal(other, bundlesToScan,
+                            pattern, visited, classes);
+                }
+            }
+        }
+    }
+
+    private boolean isDependantOn(BundleInfo other) {
+        for (String pkg : importPkgs) {
+            if (other.exportPkgs.contains(pkg)) return true;
+        }
+        return false;
+    }
+
+    public List<BundleInfo> getDependencies(Collection<BundleInfo> bundles) {
+        List<BundleInfo> result = new ArrayList<BundleInfo>();
+        for(BundleInfo bundle : bundles) {
+            if (isDependantOn(bundle)) result.add(bundle);
+        }
+        return result;
+    }
+
+
+    private static Set<String> parsePackages(String packageString) {
+        if (packageString == null) return Collections.emptySet();
+        String[] packages = packageString.split(",");
+        Set<String> result = new HashSet<String>();
+        for (int i=0; i<packages.length; i++) {
+            String[] nameAndAttrs = packages[i].split(";");
+            String packageName = nameAndAttrs[0].trim();
+            result.add(packageName);
+        }
+        return result;
+    }
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanServiceImpl.java b/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanServiceImpl.java
new file mode 100644 (file)
index 0000000..ad6d8e9
--- /dev/null
@@ -0,0 +1,22 @@
+package org.opendaylight.controller.northbound.bundlescanner.internal;
+
+import java.util.List;
+
+import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService;
+import org.osgi.framework.BundleContext;
+
+public class BundleScanServiceImpl implements IBundleScanService {
+
+    public BundleScanServiceImpl() {}
+
+
+    @Override
+    public List<Class<?>> getAnnotatedClasses(BundleContext context,
+            String[] annotations,
+            boolean includeDependentBundleClasses)
+    {
+        return BundleScanner.getInstance().getAnnotatedClasses(
+                context, annotations, includeDependentBundleClasses);
+    }
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java b/opendaylight/northbound/bundlescanner/implementation/src/main/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScanner.java
new file mode 100644 (file)
index 0000000..3e517e9
--- /dev/null
@@ -0,0 +1,277 @@
+/**
+ * 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.northbound.bundlescanner.internal;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassReader;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Opcodes;
+import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.SynchronousBundleListener;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * The custom bundle scanner scans annotations on bundles and is used for
+ * constructing JAXBContext instances. It listens for bundle events and updates
+ * the metadata in realtime.
+ */
+/*package*/ class BundleScanner implements SynchronousBundleListener {
+    private static final Logger LOGGER = LoggerFactory.getLogger(BundleScanner.class);
+    private static BundleScanner INSTANCE; // singleton
+
+    private final Pattern annotationPattern;
+    private final Map<Long,BundleInfo> bundleAnnotations =
+            new HashMap<Long, BundleInfo>();
+
+    public static synchronized BundleScanner getInstance() {
+        if (INSTANCE == null) {
+            INSTANCE = new BundleScanner();
+        }
+        return INSTANCE;
+    }
+
+    /*package*/ BundleScanner(Bundle[] bundles) {
+        annotationPattern = mergePatterns(IBundleScanService.ANNOTATIONS_TO_SCAN, true);
+        init(bundles);
+    }
+
+    /*package*/ BundleScanner() {
+        this(FrameworkUtil.getBundle(BundleScanner.class).getBundleContext().getBundles());
+    }
+
+    public List<Class<?>> getAnnotatedClasses(BundleContext context,
+            String[] annotations,
+            boolean includeDependentBundleClasses)
+    {
+        BundleInfo info = bundleAnnotations.get(context.getBundle().getBundleId());
+        if (info == null) return Collections.emptyList();
+        Pattern pattern = mergePatterns(annotations, false);
+        List<Class<?>> result = null;
+        if (includeDependentBundleClasses) {
+            result = info.getAnnotatedClasses(bundleAnnotations.values(), pattern);
+        } else {
+            result = info.getAnnotatedClasses(pattern);
+        }
+        LOGGER.debug("Annotated classes detected: {} matching: {}", result, pattern);
+        return result;
+    }
+
+    ////////////////////////////////////////////////////////////////
+    // SynchronousBundleListener implementation
+    ////////////////////////////////////////////////////////////////
+
+    @Override
+    public void bundleChanged(BundleEvent event) {
+        Bundle bundle = event.getBundle();
+        long id = bundle.getBundleId();
+        switch(event.getType()) {
+            case BundleEvent.RESOLVED :
+                scan(bundle);
+                return;
+            case BundleEvent.UNRESOLVED :
+            case BundleEvent.UNINSTALLED :
+                bundleAnnotations.remove(id);
+                return;
+        }
+    }
+
+
+    ////////////////////////////////////////////////////////////////
+    //  ClassVisitor implementation
+    ////////////////////////////////////////////////////////////////
+
+    private static class AnnotationDetector extends ClassVisitor {
+        private final Map<String, Set<String>> matchedClasses =
+                new HashMap<String, Set<String>>();
+
+        private final Pattern annotationsPattern;
+        private Set<String> annotations;
+        private String className;
+        private boolean accessible;
+        private boolean matchedAnnotation;
+
+        public AnnotationDetector(Pattern pattern) {
+            super(Opcodes.ASM4);
+            this.annotationsPattern = pattern;
+        }
+
+        public Map<String, Set<String>> getMatchedClasses() {
+            return new HashMap<String, Set<String>>(matchedClasses);
+        }
+
+        @Override
+        public void visit(int version, int access, String name, String signature,
+                String superName, String[] interfaces)
+        {
+            //LOGGER.debug("Visiting class:" + name);
+            className = name;
+            accessible = ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC);
+            matchedAnnotation = false;
+            annotations = new HashSet<String>();
+        }
+
+        @Override
+        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+            //LOGGER.debug("Visiting annotation:" + desc);
+            annotations.add(signature2class(desc));
+            if (!matchedAnnotation) {
+                matchedAnnotation = (annotationsPattern == null ||
+                        annotationsPattern.matcher(desc).find());
+            }
+            return null;
+        }
+
+        @Override
+        public void visitEnd() {
+            if (matchedAnnotation && accessible) {
+                className = path2class(className);
+                matchedClasses.put(className, new HashSet<String>(annotations));
+            }
+        }
+    }
+
+    ////////////////////////////////////////////////////////////////
+    // Helpers
+    ////////////////////////////////////////////////////////////////
+
+    private synchronized void init(Bundle[] bundles) {
+        for (Bundle bundle : bundles) {
+            int state = bundle.getState();
+            if (state == Bundle.RESOLVED ||
+                state == Bundle.STARTING ||
+                state == Bundle.ACTIVE)
+            {
+                scan(bundle);
+            }
+        }
+    }
+
+    private static String path2class(String path) {
+        return path.replace(".class", "").replaceAll("/", ".");
+    }
+
+    private static String class2path(String clz) {
+        return clz.replaceAll("\\.", "/");
+    }
+
+    @SuppressWarnings("unused")
+    private static String class2signature(String clz) {
+        return "L" + class2path(clz) + ";";
+    }
+
+    private static String signature2class(String sig) {
+        if (sig.startsWith("L") && sig.endsWith(";")) {
+            sig = sig.substring(1, sig.length()-1);
+        }
+        return path2class(sig);
+    }
+
+   private static List<URL> getBundleClasses(Bundle bundle, String[] pkgs) {
+        List<URL> result = new ArrayList<URL>();
+        boolean recurse = false;
+        if (pkgs == null) {
+            recurse = true;
+            pkgs = new String[] { "/" } ;
+        }
+        for (String pkg : pkgs) {
+            pkg = class2path(pkg);
+            final Enumeration<URL> e = bundle.findEntries(pkg, "*.class", recurse);
+            if (e != null) {
+                while (e.hasMoreElements()) {
+                    URL url = e.nextElement();
+                    result.add(url);
+                }
+            }
+        }
+        return result;
+    }
+
+    private synchronized void scan(Bundle bundle) {
+        AnnotationDetector detector = new AnnotationDetector(annotationPattern);
+        try {
+            for (URL u : getBundleClasses(bundle, null)) {
+                InputStream is = u.openStream();
+                new ClassReader(is).accept(detector, 0);
+                is.close();
+            }
+        } catch (IOException ioe) {
+            LOGGER.error("Error scanning classes in bundle: {}", bundle.getSymbolicName(), ioe);
+        }
+        Map<String, Set<String>> classes = detector.getMatchedClasses();
+        if (classes != null && classes.size() > 0) {
+            BundleInfo info = new BundleInfo(bundle, classes);
+            bundleAnnotations.put(bundle.getBundleId(),info);
+            if (LOGGER.isDebugEnabled()) {
+                LOGGER.debug("bindings found in bundle: {}[{}] " +
+                        "dependencies {} classes {}", bundle.getSymbolicName(),
+                        bundle.getBundleId(),
+                        info.getDependencies(bundleAnnotations.values()),
+                        classes);
+            }
+        }
+        // find bundle dependencies
+    }
+
+    public static List<Class<?>> loadClasses(Bundle bundle,
+            Collection<String> annotatedClasses)
+    {
+        List<Class<?>> result = new ArrayList<Class<?>>();
+        for (String name : annotatedClasses) {
+            try {
+                result.add(bundle.loadClass(name));
+            } catch (Exception e) {
+                LOGGER.error("Unable to load class: {}", name, e);
+            }
+        }
+        return result;
+    }
+
+    public static Pattern mergePatterns(String[] patterns, boolean convert2signature) {
+        if (patterns == null || patterns.length == 0) {
+            return null;
+        }
+        StringBuilder regex = new StringBuilder();
+        for (String c : patterns) {
+            if (c.endsWith("*")) {
+                c = c.substring(0, c.length() - 1);
+            }
+            if (regex.length() > 0) regex.append("|");
+            regex.append("^");
+            if (convert2signature) {
+                regex.append("L").append(c.replaceAll("\\.", "/"));
+            } else {
+                regex.append(c);
+            }
+        }
+        if (LOGGER.isDebugEnabled()) {
+            LOGGER.debug("Merged regex: [{}]", regex.toString());
+        }
+        return Pattern.compile(regex.toString());
+    }
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Animal.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Animal.java
new file mode 100644 (file)
index 0000000..e9fb31f
--- /dev/null
@@ -0,0 +1,6 @@
+package bundle_base;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public abstract class Animal { }
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/BasePerson.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/BasePerson.java
new file mode 100644 (file)
index 0000000..831d66b
--- /dev/null
@@ -0,0 +1,10 @@
+package bundle_base;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSeeAlso;
+
+@XmlRootElement
+public class BasePerson { }
\ No newline at end of file
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Mammal.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Mammal.java
new file mode 100644 (file)
index 0000000..53ab14d
--- /dev/null
@@ -0,0 +1,6 @@
+package bundle_base;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class Mammal extends Animal { }
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/NoAnnotation.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/NoAnnotation.java
new file mode 100644 (file)
index 0000000..b8f3d10
--- /dev/null
@@ -0,0 +1,3 @@
+package bundle_base;
+
+public class NoAnnotation { }
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/NonRelevantAnnotation.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/NonRelevantAnnotation.java
new file mode 100644 (file)
index 0000000..9429345
--- /dev/null
@@ -0,0 +1,6 @@
+package bundle_base;
+
+@Deprecated
+public class NonRelevantAnnotation {
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Person.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_base/Person.java
new file mode 100644 (file)
index 0000000..9a6acc0
--- /dev/null
@@ -0,0 +1,27 @@
+package bundle_base;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+@XmlTransient
+@Deprecated
+public class Person extends BasePerson {
+
+    @XmlElement
+    protected String name;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @XmlRootElement
+    public static class Info { }
+
+    @XmlRootElement
+    private static class PrivateInfo { }
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_misc/Misc.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_misc/Misc.java
new file mode 100644 (file)
index 0000000..cb33ce9
--- /dev/null
@@ -0,0 +1,7 @@
+package bundle_misc;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement
+public class Misc {
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub1/NoAnnotation.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub1/NoAnnotation.java
new file mode 100644 (file)
index 0000000..9a08fc9
--- /dev/null
@@ -0,0 +1,5 @@
+package bundle_sub1;
+
+public class NoAnnotation {
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub1/Zoo.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub1/Zoo.java
new file mode 100644 (file)
index 0000000..1eadad6
--- /dev/null
@@ -0,0 +1,26 @@
+package bundle_sub1;
+
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import bundle_base.Animal;
+import bundle_base.Mammal;
+
+
+@XmlRootElement
+public class Zoo {
+    private Animal creature;
+
+    @XmlElementRef
+    public Animal getCreature() {
+        return creature;
+    }
+
+    public void setCreature(Animal creature) {
+        this.creature = creature;
+    }
+
+    public Zoo() {
+        creature = new Mammal();
+    }
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/Agent.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/Agent.java
new file mode 100644 (file)
index 0000000..2b98270
--- /dev/null
@@ -0,0 +1,11 @@
+package bundle_sub2;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import bundle_base.Person;
+
+
+@XmlRootElement
+public class Agent extends Person {
+
+}
\ No newline at end of file
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/Customer.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/Customer.java
new file mode 100644 (file)
index 0000000..a3f5dca
--- /dev/null
@@ -0,0 +1,56 @@
+package bundle_sub2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementRef;
+import javax.xml.bind.annotation.XmlElementWrapper;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import bundle_base.BasePerson;
+import bundle_base.Person;
+
+
+@XmlRootElement
+public class Customer extends Person {
+
+    private String password;
+    private List<String> phoneNumbers;
+    @XmlElementRef
+    @XmlElementWrapper
+    private final List<BasePerson> agents = new ArrayList<BasePerson>();
+
+    @XmlTransient
+    public String getPassword() {
+        return password;
+    }
+
+    public void setPassword(String password) {
+        this.password = password;
+    }
+
+    @XmlElement(name = "phone-number")
+    public List<String> getPhoneNumbers() {
+        return phoneNumbers;
+    }
+
+    public void setPhoneNumbers(List<String> phoneNumbers) {
+        this.phoneNumbers = phoneNumbers;
+    }
+
+    public void addAgent(Person mgr) {
+        this.agents.add(mgr);
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder(super.toString());
+        sb.append(" password:").append(password);
+        sb.append(" phoneNumbers:").append(phoneNumbers);
+        sb.append(" agents:").append(agents);
+        return sb.toString();
+    }
+}
+
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/NoAnnotation.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/bundle_sub2/NoAnnotation.java
new file mode 100644 (file)
index 0000000..430f10b
--- /dev/null
@@ -0,0 +1,5 @@
+package bundle_sub2;
+
+public class NoAnnotation {
+
+}
diff --git a/opendaylight/northbound/bundlescanner/implementation/src/test/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScannerTest.java b/opendaylight/northbound/bundlescanner/implementation/src/test/java/org/opendaylight/controller/northbound/bundlescanner/internal/BundleScannerTest.java
new file mode 100644 (file)
index 0000000..0d7d7da
--- /dev/null
@@ -0,0 +1,212 @@
+package org.opendaylight.controller.northbound.bundlescanner.internal;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import javax.xml.bind.JAXBException;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleEvent;
+import org.osgi.framework.Constants;
+import org.springframework.osgi.mock.MockBundle;
+import org.springframework.osgi.mock.MockBundleContext;
+import org.springframework.osgi.mock.MockFrameworkUtil;
+
+public class BundleScannerTest {
+
+    private static BundleScanner bundleScanner;
+    private static List<Bundle> bundles;
+    @Rule
+    public final TestName testName = new TestName();
+
+    @BeforeClass
+    public static void init() throws Exception {
+        bundles = makeMockBundles();
+        bundleScanner = new BundleScanner(bundles.toArray(new Bundle[bundles.size()]));
+    }
+
+    @AfterClass
+    public static void destroy() throws Exception {
+    }
+
+    @Before
+    public void setup() {
+        System.out.println("==== " + testName.getMethodName());
+    }
+
+    @Test
+    public void testValidateBundles() {
+        assertNotNull(bundleScanner);
+        BundleContext context = bundles.get(0).getBundleContext();
+        assertNotNull(context.getBundle());
+        assertNotNull(context.getBundles());
+        assertNotNull(context.getBundles().length >= 4);
+    }
+
+    @Test
+    public void testBundleEvents() throws Exception {
+        MockBundle newBundle = new TestMockBundle("misc", "", "bundle_misc");
+        assertTrue(bundleScanner.getAnnotatedClasses(
+                newBundle.getBundleContext(), null, false).size() == 0);
+        BundleEvent event = new BundleEvent(BundleEvent.RESOLVED, newBundle);
+        bundleScanner.bundleChanged(event);
+        assertTrue(bundleScanner.getAnnotatedClasses(
+                newBundle.getBundleContext(), null, false).size() == 1);
+    }
+
+    @Test
+    public void testAnnotatedClassesWithDependencies() throws Exception {
+        for (Bundle bundle : bundles) {
+            List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
+                    bundle.getBundleContext(), null, true);
+            String name = bundle.getSymbolicName();
+            System.out.println("name:" + name + " classes:" + classes.size());
+            if ("misc".equals(name)) {
+                assertTrue(classes.size() == 1);
+            } else if ("base".equals(name)) {
+                assertTrue(classes.size() == 5);
+            } else if ("sub1".equals(name)) {
+                assertTrue(classes.size() == 6);
+            } else if ("sub2".equals(name)) {
+                assertTrue(classes.size() == 7);
+            }
+        }
+    }
+
+    @Test
+    public void testExactFiltering() {
+        Bundle bundle = findBundle("sub1");
+        String[] annos = { "javax.xml.bind.annotation.XmlTransient" };
+        List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
+                bundle.getBundleContext(), annos, true);
+        assertTrue(classes.size() == 1);
+    }
+
+    @Test
+    public void testNonExactFiltering() {
+        Bundle bundle = findBundle("sub1");
+        String[] annos = { "javax.xml.bind.annotation.*" };
+        List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
+                bundle.getBundleContext(), annos, true);
+        assertTrue(classes.size() == 6);
+    }
+
+    @Test
+    public void testFilteringUnmatched() {
+        Bundle bundle = findBundle("sub1");
+        String[] annos = { "non.existent.pkg" };
+        List<Class<?>> classes = bundleScanner.getAnnotatedClasses(
+                bundle.getBundleContext(), annos, true);
+        assertTrue(classes.size() == 0);
+    }
+
+    @Test
+    public void testRegexMerge() {
+        Pattern pattern = BundleScanner.mergePatterns(
+                new String[] {
+                        "javax.xml.bind.annotation.*",
+                        "javax.ws.rs.Path"
+                    },
+                true
+            );
+        assertTrue(pattern.matcher("Ljavax/xml/bind/annotation/FOO;").find());
+        assertFalse(pattern.matcher("Ljavax/servlet/FOO;").find());
+    }
+
+    private static Bundle findBundle(String symName) {
+        for (Bundle bundle : bundles) {
+            if (bundle.getSymbolicName().equals(symName)) return bundle;
+        }
+        return null;
+    }
+
+    private static List<Bundle> makeMockBundles() throws Exception {
+        List<Bundle> result = new ArrayList<Bundle>();
+        result.add(new MockBundle());
+        result.add(new TestMockBundle("base", "", "bundle_base"));
+        result.add(new TestMockBundle("sub1", "bundle_base", "bundle_sub1"));
+        result.add(new TestMockBundle("sub2", "bundle_base", "bundle_sub2"));
+        return result;
+    }
+
+    private static List<URL> findClasses(String pkg) throws URISyntaxException {
+        if (pkg == null) return Collections.EMPTY_LIST;
+        String npkg = pkg.replaceAll("\\.", "/");
+        URL dirUrl = BundleScannerTest.class.getClassLoader().getResource(npkg);
+        final List<URL> result = new ArrayList<URL>();
+        File dir = new File(dirUrl.toURI());
+        dir.listFiles(new FileFilter() {
+
+            @Override
+            public boolean accept(File file) {
+                if (file.isFile() && file.getName().endsWith(".class")) {
+                    try {
+                        result.add(file.toURI().toURL());
+                    } catch (MalformedURLException e) {
+                        throw new IllegalStateException(e);
+                    }
+                }
+                return false;
+            }
+
+        });
+        return result;
+    }
+
+    public static class TestMockBundle extends MockBundle {
+        List<URL> classes;
+        public TestMockBundle(String name, String imports, String exports) throws Exception {
+            super(name, makeHeaders(name, imports, exports), new MockBundleContext() {
+                @Override
+                public Bundle[] getBundles() {
+                    return bundles.toArray(new Bundle[bundles.size()]);
+                }
+            });
+            MockBundleContext ctx = (MockBundleContext) this.getBundleContext();
+            ctx.setBundle(this);
+            this.classes = findClasses(exports);
+        }
+
+        private static Dictionary<String,String> makeHeaders(
+                String name, String imports, String exports)
+        {
+            Dictionary<String,String> headers = new Hashtable<String,String>();
+            headers.put(Constants.IMPORT_PACKAGE, imports);
+            headers.put(Constants.EXPORT_PACKAGE, exports);
+            headers.put(Constants.BUNDLE_SYMBOLICNAME, name);
+            return headers;
+        }
+
+        @Override
+        public Enumeration findEntries(String path, String filePattern, boolean recurse) {
+            return Collections.enumeration(classes);
+        }
+
+        @Override
+        public long getBundleId() {
+            return hashCode();
+        }
+    }
+}
index b88375ffdc9390c8dba9801f65fd69076f68a588..692b17a9a6c5409bdb38d1e729b504a5177a4f27 100644 (file)
             </Export-Package>
             <Import-Package>
               javax.ws.rs,
+              javax.ws.rs.ext,
               javax.ws.rs.core,
+              javax.xml.bind,
               javax.xml.bind.annotation,
+              org.objectweb.asm,
               org.opendaylight.controller.sal.utils,
               org.opendaylight.controller.sal.authorization,
               org.opendaylight.controller.containermanager,
               org.opendaylight.controller.usermanager,
+              org.opendaylight.controller.northbound.bundlescanner,
+              org.osgi.framework,
+              org.osgi.service.packageadmin,
+              org.osgi.util.tracker,
               javax.servlet.http,
+              org.codehaus.jackson.jaxrs,
               org.slf4j
             </Import-Package>
           </instructions>
       <artifactId>usermanager</artifactId>
       <version>0.4.0-SNAPSHOT</version>
     </dependency>
+    <dependency>
+        <groupId>org.opendaylight.controller</groupId>
+        <artifactId>bundlescanner</artifactId>
+        <version>0.4.0-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>
diff --git a/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java b/opendaylight/northbound/commons/src/main/java/org/opendaylight/controller/northbound/commons/NorthboundApplication.java
new file mode 100644 (file)
index 0000000..1d3919f
--- /dev/null
@@ -0,0 +1,148 @@
+/**
+ * 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.northbound.commons;
+
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.ws.rs.core.Application;
+import javax.ws.rs.ext.ContextResolver;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
+import org.opendaylight.controller.northbound.bundlescanner.IBundleScanService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.BundleReference;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceException;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Instance of javax.ws.rs.core.Application used to return the classes
+ * that will be instantiated for JAXRS processing. This hooks onto the
+ * bundle scanner service to provide JAXB classes to JAX-RS for prorcessing.
+ */
+@SuppressWarnings("unchecked")
+public class NorthboundApplication extends Application {
+    public static final String JAXRS_RESOURCES_MANIFEST_NAME = "Jaxrs-Resources";
+    private static final Logger LOGGER = LoggerFactory.getLogger(NorthboundApplication.class);
+
+    ////////////////////////////////////////////////////////////////
+    //  Application overrides
+    ////////////////////////////////////////////////////////////////
+
+    @Override
+    public Set<Object> getSingletons() {
+        Set<Object> singletons = new HashSet<Object>();
+        singletons.add(new ContextResolver<JAXBContext>() {
+            @Override
+            public JAXBContext getContext(Class<?> type) {
+                return newJAXBContext();
+            }
+
+        } );
+        singletons.add(new JacksonJaxbJsonProvider());
+        return singletons;
+    }
+
+    @Override
+    public Set<Class<?>> getClasses() {
+        Set<Class<?>> result = new HashSet<Class<?>>();
+        result.addAll(findJAXRSResourceClasses());
+        return result;
+    }
+
+    private BundleContext getBundleContext() {
+        ClassLoader tlcl = Thread.currentThread().getContextClassLoader();
+        Bundle bundle = null;
+
+        if (tlcl instanceof BundleReference) {
+            bundle = ((BundleReference) tlcl).getBundle();
+        } else {
+            LOGGER.warn("Unable to determine the bundle context based on " +
+                        "thread context classloader.");
+            bundle = FrameworkUtil.getBundle(this.getClass());
+        }
+        return (bundle == null ? null : bundle.getBundleContext());
+    }
+
+    private static final IBundleScanService lookupBundleScanner(BundleContext ctx) {
+        ServiceReference svcRef = ctx.getServiceReference(IBundleScanService.class);
+        if (svcRef == null) {
+            throw new ServiceException("Unable to lookup IBundleScanService");
+        }
+        return IBundleScanService.class.cast(ctx.getService(svcRef));
+    }
+
+    private final JAXBContext newJAXBContext() {
+        BundleContext ctx = getBundleContext();
+        IBundleScanService svc = lookupBundleScanner(ctx);
+        try {
+            List<Class<?>> cls = svc.getAnnotatedClasses(ctx,
+                    new String[] { XmlRootElement.class.getPackage().getName() },
+                    true);
+            return JAXBContext.newInstance(cls.toArray(new Class[cls.size()]));
+        } catch (JAXBException je) {
+            LOGGER.error("Error creating JAXBContext", je);
+            return null;
+        }
+    }
+
+    private final Set<Class<?>> findJAXRSResourceClasses() {
+        BundleContext ctx = getBundleContext();
+        String bundleName = ctx.getBundle().getSymbolicName();
+        Set<Class<?>> result = new HashSet<Class<?>>();
+        ServiceException recordException = null;
+        try {
+            IBundleScanService svc = lookupBundleScanner(ctx);
+            result.addAll(svc.getAnnotatedClasses(ctx,
+                    new String[] { javax.ws.rs.Path.class.getName() }, false));
+        } catch (ServiceException se) {
+            recordException = se;
+            LOGGER.debug("Error finding JAXRS resource annotated classes in " +
+                    "bundle: {} error: {}.", bundleName, se.getMessage());
+            // the bundle scan service cannot be lookedup. Lets attempt to
+            // lookup the resources from the bundle manifest header
+            Dictionary<String,String> headers = ctx.getBundle().getHeaders();
+            String header = headers.get(JAXRS_RESOURCES_MANIFEST_NAME);
+            if (header != null) {
+                for (String s : header.split(",")) {
+                    s = s.trim();
+                    if (s.length() > 0) {
+                        try {
+                            result.add(ctx.getBundle().loadClass(s));
+                        } catch (ClassNotFoundException cnfe) {
+                            LOGGER.error("Cannot load class: {} in bundle: {} " +
+                                    "defined as MANIFEST JAX-RS resource", s, bundleName, cnfe);
+                        }
+                    }
+                }
+            }
+
+        }
+
+        if (result.size() == 0) {
+            if (recordException != null) {
+                throw recordException;
+            } else {
+                throw new ServiceException("No resource classes found in bundle:" +
+                        ctx.getBundle().getSymbolicName());
+            }
+        }
+        return result;
+    }
+
+}
index 067e5f19b92a09a1ad5764e3e87cc661c22be1c2..75341a6fdf6317390f80f757402a09c8b952f35d 100644 (file)
@@ -49,6 +49,7 @@
               !org.codehaus.enunciate.jaxrs
             </Import-Package>
             <Web-ContextPath>/controller/nb/v2/containermanager</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
         </configuration>
       </plugin>
index 2c729ba115d2ae0477d1158388f82a104316255c..addf857aa10d5af113b3a41be643eebb92fa5784 100644 (file)
@@ -61,6 +61,7 @@
             <Export-Package>
             </Export-Package>
             <Web-ContextPath>/controller/nb/v2/flowprogrammer</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthboundRSApplication.java b/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthboundRSApplication.java
deleted file mode 100644 (file)
index 68c0ec1..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * 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.flowprogrammer.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class FlowProgrammerNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(FlowProgrammerNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index 5b3cec2292163b1a4ca7836dae4ea35d9e26f630..f5c1ae5f9234afd435928bb9f2b8e0e1770af4d2 100644 (file)
@@ -8,7 +8,7 @@
           <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.flowprogrammer.northbound.FlowProgrammerNorthboundRSApplication</param-value>
+            <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
           </init-param>
           <load-on-startup>1</load-on-startup>
         </servlet>
index c1f6598a8a5b5e977cbede6bf750b1911bee6303..e0315fb1ee2bb743c7788a98795bca7102a8139b 100644 (file)
@@ -62,6 +62,7 @@
               !org.codehaus.enunciate.jaxrs
             </Import-Package>
             <Web-ContextPath>/controller/nb/v2/hosttracker</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthboundRSApplication.java b/opendaylight/northbound/hosttracker/src/main/java/org/opendaylight/controller/hosttracker/northbound/HostTrackerNorthboundRSApplication.java
deleted file mode 100644 (file)
index 5d50dbf..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * 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.hosttracker.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * This class is an instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class HostTrackerNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(HostTrackerNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index 01b8fedce125301acaf2bc3b1c8adf2bbea9d3fa..d4ace8d89d8fb4fb0372e12ae5023702c0ed2835 100644 (file)
@@ -7,7 +7,7 @@
     <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.hosttracker.northbound.HostTrackerNorthboundRSApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index f0c04ae5e2bde9d3264dbb3a256b834239a70d16..9f4e05dff0ba81df97abb2fde6159667608da026 100644 (file)
       <version>0.4.0-SNAPSHOT</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>bundlescanner</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>bundlescanner.implementation</artifactId>
+      <version>0.4.0-SNAPSHOT</version>
+    </dependency>
 
     <dependency>
       <groupId>org.codehaus.enunciate</groupId>
       <version>${url.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>org.ow2.asm</groupId>
+      <artifactId>asm-all</artifactId>
+      <version>4.1</version>
+    </dependency>
     <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>org.springframework.asm</artifactId>
index b0a5f201b25739c819c7f64d1034b90cb0f669ca..4404951135391f632a968aae8345e472e8f413c0 100644 (file)
@@ -1426,6 +1426,8 @@ public class NorthboundIT {
                 mavenBundle("org.opendaylight.controller", "logging.bridge").versionAsInProject(),
 //                mavenBundle("org.opendaylight.controller", "clustering.test").versionAsInProject(),
                 mavenBundle("org.opendaylight.controller", "forwarding.staticrouting").versionAsInProject(),
+                mavenBundle("org.opendaylight.controller", "bundlescanner").versionAsInProject(),
+                mavenBundle("org.opendaylight.controller", "bundlescanner.implementation").versionAsInProject(),
 
                 // Northbound bundles
                 mavenBundle("org.opendaylight.controller", "commons.northbound").versionAsInProject(),
@@ -1508,6 +1510,8 @@ public class NorthboundIT {
                 mavenBundle("org.ops4j.pax.exam", "pax-exam-link-mvn").versionAsInProject(),
                 mavenBundle("org.ops4j.pax.url", "pax-url-aether").versionAsInProject(),
 
+                mavenBundle("org.ow2.asm", "asm-all").versionAsInProject(),
+
                 mavenBundle("org.springframework", "org.springframework.asm").versionAsInProject(),
                 mavenBundle("org.springframework", "org.springframework.aop").versionAsInProject(),
                 mavenBundle("org.springframework", "org.springframework.context").versionAsInProject(),
index a8d81a73673786f8bb7083ff0c01676cead8f1f3..c1eb56aa29d1f14bdf003083b974229510f41633 100644 (file)
@@ -64,6 +64,7 @@
             <Export-Package>
             </Export-Package>
             <Web-ContextPath>/controller/nb/v2/networkconfig/bridgedomain</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthboundApplication.java b/opendaylight/northbound/networkconfiguration/bridgedomain/src/main/java/org/opendaylight/controller/networkconfig/bridgedomain/northbound/BridgeDomainNorthboundApplication.java
deleted file mode 100644 (file)
index 0d98d22..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * 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.networkconfig.bridgedomain.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class BridgeDomainNorthboundApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(BridgeDomainNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index f4de222acc0f33140565c98dec2420ff2f11c9a4..bb871a1a77a0f725f1f7510f7095b7ec65131474 100644 (file)
@@ -7,7 +7,7 @@
     <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.networkconfig.bridgedomain.northbound.BridgeDomainNorthboundApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index eb285f2e818805179b6253cb8db4f5ea8f384e27..1028ca59abbd045b61aeb768bcb6cb1b33496416 100644 (file)
@@ -62,6 +62,7 @@
             <Export-Package>
             </Export-Package>
             <Web-ContextPath>/controller/nb/v2/staticroute</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthboundRSApplication.java b/opendaylight/northbound/staticrouting/src/main/java/org/opendaylight/controller/forwarding/staticrouting/northbound/StaticRoutingNorthboundRSApplication.java
deleted file mode 100644 (file)
index a98a124..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * 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.forwarding.staticrouting.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class StaticRoutingNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(StaticRoutingNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index 0bf186b50e0c6616504c896219252d0f6ef4d52c..9f7c21a8b0cc9ef0a03e4645396df30089931cda 100644 (file)
@@ -7,7 +7,7 @@
     <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.forwarding.staticrouting.northbound.StaticRoutingNorthboundRSApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index 76129f4cb141eece18d37abb0c7c5bd66a4f1b98..74f64c2457189905db3cd215070f0cb032b39c9e 100644 (file)
@@ -70,6 +70,7 @@
             <Export-Package>
             </Export-Package>
             <Web-ContextPath>/controller/nb/v2/statistics</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/statistics/src/main/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundRSApplication.java b/opendaylight/northbound/statistics/src/main/java/org/opendaylight/controller/statistics/northbound/StatisticsNorthboundRSApplication.java
deleted file mode 100644 (file)
index 2b6dccc..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.statistics.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class StatisticsNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(StatisticsNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index db0460ba56db2c4b2541cbecaa94d45df3fe4158..179db608adffdfb043002cfba7b60a78867fe0cc 100644 (file)
@@ -7,7 +7,7 @@
     <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.statistics.northbound.StatisticsNorthboundRSApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index c3ad783773c34f040b48eab10a73d8ec3402fa00..ba58e06ecbdc6f5841769e398b44fe1f103179c1 100644 (file)
@@ -77,6 +77,7 @@
             <Export-Package>
             </Export-Package>
             <Web-ContextPath>/controller/nb/v2/subnetservice</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthboundRSApplication.java b/opendaylight/northbound/subnets/src/main/java/org/opendaylight/controller/subnets/northbound/SubnetsNorthboundRSApplication.java
deleted file mode 100644 (file)
index e03cac6..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.subnets.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class SubnetsNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(SubnetsNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index a5c70ee9d82bc232a9b0578a88bd76f37973fb5f..2300b8da400d6f15f46812f868c3e262b30b32df 100644 (file)
@@ -7,7 +7,7 @@
     <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.subnets.northbound.SubnetsNorthboundRSApplication</param-value>
+      <param-value> org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index a416414d06607208b430b2d14932e986937b847b..d46b17e4f7e2d27bebf7bfb401be64bd038b6806 100644 (file)
@@ -61,6 +61,7 @@
               !org.codehaus.enunciate.jaxrs
             </Import-Package>
             <Web-ContextPath>/controller/nb/v2/switchmanager</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthboundRSApplication.java b/opendaylight/northbound/switchmanager/src/main/java/org/opendaylight/controller/switchmanager/northbound/SwitchNorthboundRSApplication.java
deleted file mode 100644 (file)
index 1cdfd31..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * 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.switchmanager.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class SwitchNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(SwitchNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index ea6fcc99b2ab475cec28d4d93ee4d778bd36b1ea..cce0dfb259bc8f0d30f6e99f8b41fc9867735e77 100644 (file)
@@ -7,7 +7,7 @@
     <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.switchmanager.northbound.SwitchNorthboundRSApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index 803a28079e47939a2b09bdf62db76769e4855349..ec3489aca2855b6da48f82364c9b175dda8ff6de 100644 (file)
@@ -64,6 +64,7 @@
               !org.codehaus.enunciate.jaxrs
             </Import-Package>
             <Web-ContextPath>/controller/nb/v2/topology</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/northbound/topology/src/main/java/org/opendaylight/controller/topology/northbound/TopologyNorthboundRSApplication.java b/opendaylight/northbound/topology/src/main/java/org/opendaylight/controller/topology/northbound/TopologyNorthboundRSApplication.java
deleted file mode 100644 (file)
index 992cf6a..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-
-/*
- * 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.topology.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * Instance of javax.ws.rs.core.Application used to return the classes
- * that will be instantiated for JAXRS processing, this is necessary
- * because the package scanning in jersey doesn't yet work in OSGi
- * environment.
- *
- */
-public class TopologyNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(TopologyNorthboundJAXRS.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index bc818c8c6d46e1a3d86d46f162a9bd628e51e8a5..29f2049c2715f95b2fdc99ea287617f1d061ea7f 100644 (file)
@@ -7,7 +7,7 @@
     <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.topology.northbound.TopologyNorthboundRSApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index af3641823c874e485c01e19f627b2963ff9bf953..d924b66a0991d50edd74b925e14a7e1809a7e321 100644 (file)
@@ -232,4 +232,9 @@ public interface ISwitch {
      * until the Barrier reply arrives.
      */
     public Object asyncSendBarrierMessage();
+
+    /**
+     * Send a FLOW_MOD message with a wildcard match and action=DELETE.
+     */
+    public void deleteAllFlows();
 }
index 91909d20f53a5bde5adea2b7020c38a78406f080..6e000022df12909e1f4facdcbcf4236d20d3fd69 100644 (file)
@@ -372,12 +372,6 @@ public class SwitchHandler implements ISwitch {
                 // send feature request
                 OFMessage featureRequest = factory.getMessage(OFType.FEATURES_REQUEST);
                 asyncFastSend(featureRequest);
-                // delete all pre-existing flows
-                OFMatch match = new OFMatch().setWildcards(OFMatch.OFPFW_ALL);
-                OFFlowMod flowMod = (OFFlowMod) factory.getMessage(OFType.FLOW_MOD);
-                flowMod.setMatch(match).setCommand(OFFlowMod.OFPFC_DELETE).setOutPort(OFPort.OFPP_NONE)
-                        .setLength((short) OFFlowMod.MINIMUM_LENGTH);
-                asyncFastSend(flowMod);
                 this.state = SwitchState.WAIT_FEATURES_REPLY;
                 startSwitchTimer();
                 break;
@@ -925,4 +919,14 @@ public class SwitchHandler implements ISwitch {
             return result;
         }
     }
+
+    @Override
+    public void deleteAllFlows() {
+        logger.trace("deleteAllFlows on switch {}", HexString.toHexString(this.sid));
+        OFMatch match = new OFMatch().setWildcards(OFMatch.OFPFW_ALL);
+        OFFlowMod flowMod = (OFFlowMod) factory.getMessage(OFType.FLOW_MOD);
+        flowMod.setMatch(match).setCommand(OFFlowMod.OFPFC_DELETE).setOutPort(OFPort.OFPP_NONE)
+                .setLength((short) OFFlowMod.MINIMUM_LENGTH);
+        asyncFastSend(flowMod);
+    }
 }
index 82dbf670a9517ee1b998442f2d524f37628f5815..6873b528a2631f2d01480387f46be430e58b57c0 100644 (file)
@@ -59,6 +59,7 @@ public class FlowStatisticsConverter {
                     flow.setPriority(ofFlowStat.getPriority());
                     flow.setIdleTimeout(ofFlowStat.getIdleTimeout());
                     flow.setHardTimeout(ofFlowStat.getHardTimeout());
+                    flow.setId(ofFlowStat.getCookie());
                     flowOnNode = new FlowOnNode(flow);
                     flowOnNode.setByteCount(ofFlowStat.getByteCount());
                     flowOnNode.setPacketCount(ofFlowStat.getPacketCount());
@@ -74,6 +75,7 @@ public class FlowStatisticsConverter {
                     flow.setPriority(v6StatsReply.getPriority());
                     flow.setIdleTimeout(v6StatsReply.getIdleTimeout());
                     flow.setHardTimeout(v6StatsReply.getHardTimeout());
+                    flow.setId(v6StatsReply.getCookie());
                     flowOnNode = new FlowOnNode(flow);
                     flowOnNode.setByteCount(v6StatsReply.getByteCount());
                     flowOnNode.setPacketCount(v6StatsReply.getPacketCount());
index 8db83f0fc7e2449b99079aadf5dfc709204f2f35..15bba670d2a7b9e4387317e91f12e50e18cb5e29 100644 (file)
@@ -239,6 +239,11 @@ public class InventoryServiceShim implements IContainerListener,
         if (sw == null) {
             return;
         }
+        Node node = NodeCreator.createOFNode(sw.getId());
+        if ((nodeProps.get(node) != null)  && (connectionOutService.isLocal(node))) {
+            logger.debug("Ignore switchAdded {}", sw);
+            return;
+        }
 
         // Add all the nodeConnectors of this switch
         Map<NodeConnector, Set<Property>> ncProps = InventoryServiceHelper
@@ -437,7 +442,6 @@ public class InventoryServiceShim implements IContainerListener,
             for (String container : containers) {
                 notifyInventoryShimInternalListener(container, node, type, props);
             }
-
             // Notify external listener
             notifyInventoryShimExternalListener(node, type, props);
 
@@ -511,6 +515,11 @@ public class InventoryServiceShim implements IContainerListener,
             props.add(b);
         }
 
+        if ((nodeProps.get(node) == null) &&  (connectionOutService.isLocal(node)))  {
+            // The switch is connected for the first time, flush all flows
+            // that may exist on this switch
+            sw.deleteAllFlows();
+       }
         nodeProps.put(node, props);
         // Notify all internal and external listeners
         notifyInventoryShimListener(node, type, props);
index a7bdb9da8bf32072b73b45a3128b412b9f18f88a..854125b3567a196b940556363ed56c82e99d50c0 100644 (file)
@@ -432,6 +432,7 @@ public class FlowProgrammerService implements IFlowProgrammerService,
         Flow flow = new Flow(match, actions);
         flow.setPriority((short) 100);
         flow.setHardTimeout((short) 360);
+        flow.setId(1234L);
 
         return flow;
     }
@@ -489,6 +490,7 @@ public class FlowProgrammerService implements IFlowProgrammerService,
         Flow flow = new Flow(match, actions);
         flow.setPriority((short) 300);
         flow.setHardTimeout((short) 240);
+        flow.setId(65536L);
 
         return flow;
     }
index 2ccb4409520557ef750e3c0d1861c4f9e558898c..e001dc8e58765a619e1508c1dc30f5f4cf0362be 100644 (file)
@@ -62,6 +62,7 @@
               !org.codehaus.enunciate.jaxrs
             </Import-Package>
             <Web-ContextPath>/one/nb/v2/lb</Web-ContextPath>
+            <Jaxrs-Resources>,${classes;ANNOTATION;javax.ws.rs.Path}</Jaxrs-Resources>
           </instructions>
           <manifestLocation>${project.basedir}/src/main/resources/META-INF</manifestLocation>
         </configuration>
diff --git a/opendaylight/samples/northbound/loadbalancer/src/main/java/org/opendaylight/controller/samples/loadbalancer/northbound/LoadBalancerNorthboundRSApplication.java b/opendaylight/samples/northbound/loadbalancer/src/main/java/org/opendaylight/controller/samples/loadbalancer/northbound/LoadBalancerNorthboundRSApplication.java
deleted file mode 100644 (file)
index 2f5aaca..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * Copyright IBM Corporation, 2013.  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.samples.loadbalancer.northbound;
-
-import java.util.HashSet;
-import java.util.Set;
-import javax.ws.rs.core.Application;
-
-import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;
-
-/**
- * This class is an instance of javax.ws.rs.core.Application and is used to return the classes
- * that will be instantiated for JAXRS processing. This is necessary
- * because package scanning in jersey doesn't yet work in OSGi environment.
- *
- */
-public class LoadBalancerNorthboundRSApplication extends Application {
-    @Override
-    public Set<Class<?>> getClasses() {
-        Set<Class<?>> classes = new HashSet<Class<?>>();
-        classes.add(LoadBalancerNorthbound.class);
-        classes.add(JacksonJaxbJsonProvider.class);
-        return classes;
-    }
-}
index 0e8f8c1b5646b7eafcb223a7c4d5dd009cda52df..ae2fce582ae34b9fc49c5a4c32381f1d83dfa25f 100644 (file)
@@ -7,7 +7,7 @@
     <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.samples.loadbalancer.northbound.LoadBalancerNorthboundRSApplication</param-value>
+      <param-value>org.opendaylight.controller.northbound.commons.NorthboundApplication</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>
index 8be254e6b5eef24bae8eaf087289a81fbf3a851e..a6c938a2eb4f5137ccb15f22830580a9b613c1eb 100644 (file)
@@ -31,7 +31,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
index 527dd0a02b3671451d6e612d3df25d69c7b0d1ba..e0251f8a27c82a852ed9705ce04216a7863b5131 100644 (file)
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
-        <version>0.5.3.201107060350</version>
+        <version>${jacoco.version}</version>
         <configuration>
           <destFile>../implementation/target/jacoco-it.exec</destFile>
           <includes>org.opendaylight.controller.*</includes>
index 607c42858e7b4ee52d8e9974c4d677ce1d61cc2f..14a056d5fee3b50ba27f2fe240d378495dc7ad85 100644 (file)
@@ -32,7 +32,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
index 1b09f3c34d62a26a204288c9143fc8b1e54f3dd4..ee126f3408ce51d6b1036f351f4ffb7a1be218b8 100644 (file)
@@ -32,7 +32,7 @@
         <plugin>
           <groupId>org.jacoco</groupId>
           <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
+          <version>${jacoco.version}</version>
         </plugin>
       </plugins>
     </pluginManagement>
index d571d9df532d682650033bdf0ae94eca349d176a..4ebe9bbc9380dab400625d7ed069d971dcd1a81a 100644 (file)
   </properties>
 
   <build>
-    <pluginManagement>
-      <plugins>
-        <plugin>
-          <groupId>org.jacoco</groupId>
-          <artifactId>jacoco-maven-plugin</artifactId>
-          <version>0.5.3.201107060350</version>
-        </plugin>
-      </plugins>
-    </pluginManagement>
     <plugins>
       <plugin>
         <groupId>org.jacoco</groupId>
         <artifactId>jacoco-maven-plugin</artifactId>
-        <version>0.5.3.201107060350</version>
+        <version>${jacoco.version}</version>
         <configuration>
           <destFile>../implementation/target/jacoco-it.exec</destFile>
           <includes>org.opendaylight.controller.*</includes>
index 736568c74ca67911db80bf6ee7efc6c0073a2e3c..e53e962aa82590db6d48890278657926de57dfb0 100644 (file)
@@ -8,6 +8,8 @@
 
 package org.opendaylight.controller.usermanager.internal;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.ObjectInputStream;
@@ -72,13 +74,14 @@ import org.springframework.security.web.context.SecurityContextRepository;
 public class UserManager implements IUserManager, IObjectReader,
         IConfigurationAware, CommandProvider, AuthenticationProvider {
     private static final Logger logger = LoggerFactory.getLogger(UserManager.class);
-    private static final String defaultAdmin = "admin";
-    private static final String defaultAdminPassword = "admin";
-    private static final String defaultAdminRole = UserLevel.NETWORKADMIN.toString();
+    private static final String DEFAULT_ADMIN = "admin";
+    private static final String DEFAULT_ADMIN_PASSWORD = "admin";
+    private static final String DEFAULT_ADMIN_ROLE = UserLevel.NETWORKADMIN.toString();
     private static final String ROOT = GlobalConstants.STARTUPHOME.toString();
-    private static final String usersFileName = ROOT + "users.conf";
-    private static final String serversFileName = ROOT + "servers.conf";
-    private static final String authFileName = ROOT + "authorization.conf";
+    private static final String USERS_FILE_NAME = ROOT + "users.conf";
+    private static final String SERVERS_FILE_NAME = ROOT + "servers.conf";
+    private static final String AUTH_FILE_NAME = ROOT + "authorization.conf";
+    private static final String RECOVERY_FILE = ROOT + "NETWORK_ADMIN_PASSWORD_RECOVERY";
     private ConcurrentMap<String, UserConfig> localUserConfigList;
     private ConcurrentMap<String, ServerConfig> remoteServerConfigList;
     // local authorization info for remotely authenticated users
@@ -203,10 +206,37 @@ public class UserManager implements IUserManager, IObjectReader,
     private void checkDefaultNetworkAdmin() {
         // If startup config is not there, it's old or it was deleted,
         // need to add Default Network Admin User
-        if (!localUserConfigList.containsKey(defaultAdmin)) {
+        if (!localUserConfigList.containsKey(DEFAULT_ADMIN)) {
             List<String> roles = new ArrayList<String>(1);
-            roles.add(defaultAdminRole);
-            localUserConfigList.put(defaultAdmin, new UserConfig(defaultAdmin, defaultAdminPassword, roles));
+            roles.add(DEFAULT_ADMIN_ROLE);
+            localUserConfigList.put(DEFAULT_ADMIN, new UserConfig(DEFAULT_ADMIN, DEFAULT_ADMIN_PASSWORD, roles));
+        }
+    }
+
+    private void checkPasswordRecovery() {
+        final String fileDescription = "Default Network Administrator password recovery file";
+        try {
+            FileInputStream fis = new FileInputStream(UserManager.RECOVERY_FILE);
+            /*
+             * Recovery file detected, remove current default network
+             * administrator entry from local users configuration list.
+             * Warn user and delete recovery file.
+             */
+            this.localUserConfigList.remove(UserManager.DEFAULT_ADMIN);
+            logger.info("Default Network Administrator password has been reset to factory default.");
+            logger.info("Please change the default Network Administrator password as soon as possible");
+            File filePointer = new File(UserManager.RECOVERY_FILE);
+            boolean status = filePointer.delete();
+            if (!status) {
+                logger.warn("Failed to delete {}", fileDescription);
+            } else {
+                logger.trace("{} deleted", fileDescription);
+            }
+            fis.close();
+        } catch (FileNotFoundException fnf) {
+            logger.trace("{} not present", fileDescription);
+        } catch (IOException e) {
+            logger.warn("Failed to close file stream for {}", fileDescription);
         }
     }
 
@@ -363,7 +393,7 @@ public class UserManager implements IUserManager, IObjectReader,
     private Status saveLocalUserListInternal() {
         ObjectWriter objWriter = new ObjectWriter();
         return objWriter.write(new ConcurrentHashMap<String, UserConfig>(
-                localUserConfigList), usersFileName);
+                localUserConfigList), USERS_FILE_NAME);
     }
 
     @Override
@@ -374,7 +404,7 @@ public class UserManager implements IUserManager, IObjectReader,
     private Status saveAAAServerListInternal() {
         ObjectWriter objWriter = new ObjectWriter();
         return objWriter.write(new ConcurrentHashMap<String, ServerConfig>(
-                remoteServerConfigList), serversFileName);
+                remoteServerConfigList), SERVERS_FILE_NAME);
     }
 
     @Override
@@ -386,7 +416,7 @@ public class UserManager implements IUserManager, IObjectReader,
         ObjectWriter objWriter = new ObjectWriter();
         return objWriter.write(
                 new ConcurrentHashMap<String, AuthorizationConfig>(
-                        authorizationConfList), authFileName);
+                        authorizationConfList), AUTH_FILE_NAME);
     }
 
     @Override
@@ -401,7 +431,7 @@ public class UserManager implements IUserManager, IObjectReader,
     private void loadUserConfig() {
         ObjectReader objReader = new ObjectReader();
         ConcurrentMap<String, UserConfig> confList = (ConcurrentMap<String, UserConfig>) objReader
-                .read(this, usersFileName);
+                .read(this, USERS_FILE_NAME);
 
         if (confList == null) {
             return;
@@ -416,7 +446,7 @@ public class UserManager implements IUserManager, IObjectReader,
     private void loadServerConfig() {
         ObjectReader objReader = new ObjectReader();
         ConcurrentMap<String, ServerConfig> confList = (ConcurrentMap<String, ServerConfig>) objReader
-                .read(this, serversFileName);
+                .read(this, SERVERS_FILE_NAME);
 
         if (confList == null) {
             return;
@@ -431,7 +461,7 @@ public class UserManager implements IUserManager, IObjectReader,
     private void loadAuthConfig() {
         ObjectReader objReader = new ObjectReader();
         ConcurrentMap<String, AuthorizationConfig> confList = (ConcurrentMap<String, AuthorizationConfig>) objReader
-                .read(this, authFileName);
+                .read(this, AUTH_FILE_NAME);
 
         if (confList == null) {
             return;
@@ -455,7 +485,7 @@ public class UserManager implements IUserManager, IObjectReader,
         String user = AAAconf.getUser();
 
         // Check default admin user
-        if (user.equals(UserManager.defaultAdmin)) {
+        if (user.equals(UserManager.DEFAULT_ADMIN)) {
             String msg = "Invalid Request: Default Network Admin  User cannot be " + ((delete)? "removed" : "added");
             logger.debug(msg);
             return new Status(StatusCode.NOTALLOWED, msg);
@@ -791,12 +821,14 @@ public class UserManager implements IUserManager, IObjectReader,
         // Read startup configuration and populate databases
         loadConfigurations();
 
+        // Check if a password recovery was triggered for default network admin user
+        checkPasswordRecovery();
+
         // Make sure default Network Admin account is there
         checkDefaultNetworkAdmin();
-        BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass())
-                .getBundleContext();
-        bundleContext.registerService(CommandProvider.class.getName(), this,
-                null);
+
+        BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+        bundleContext.registerService(CommandProvider.class.getName(), this, null);
     }
 
     /**
index fed81eb2ae886aa6bbbb062a8499aa3be90f8026..a6c390d799bb1fa54ac1329436ab2a3b47d2b037 100644 (file)
@@ -340,29 +340,31 @@ public class Topology implements IObjectReader, IConfigurationAware {
             ITopologyManager topology, String containerName) {
         for (Map.Entry<Node, Set<NodeConnector>> e : hostEdges.entrySet()) {
             for (NodeConnector connector : e.getValue()) {
-                Host host = topology.getHostAttachedToNodeConnector(connector);
-                EthernetAddress dmac = (EthernetAddress) host.getDataLayerAddress();
+                List<Host> hosts = topology.getHostsAttachedToNodeConnector(connector);
+                for (Host host : hosts) {
+                    EthernetAddress dmac = (EthernetAddress) host.getDataLayerAddress();
 
-                ByteBuffer addressByteBuffer = ByteBuffer.allocate(8);
-                addressByteBuffer.putShort((short) 0);
-                addressByteBuffer.put(dmac.getValue());
-                addressByteBuffer.rewind();
+                    ByteBuffer addressByteBuffer = ByteBuffer.allocate(8);
+                    addressByteBuffer.putShort((short) 0);
+                    addressByteBuffer.put(dmac.getValue());
+                    addressByteBuffer.rewind();
 
-                long hid = addressByteBuffer.getLong();
-                String hostId = String.valueOf(hid);
+                    long hid = addressByteBuffer.getLong();
+                    String hostId = String.valueOf(hid);
 
-                NodeBean hostBean = new NodeBean(hostId, host.getNetworkAddressAsString(), NodeType.HOST);
-                List<Map<String, Object>> adjacencies = new LinkedList<Map<String, Object>>();
-                EdgeBean edge = new EdgeBean(connector, hid);
-                adjacencies.add(edge.out());
-                hostBean.setLinks(adjacencies);
+                    NodeBean hostBean = new NodeBean(hostId, host.getNetworkAddressAsString(), NodeType.HOST);
+                    List<Map<String, Object>> adjacencies = new LinkedList<Map<String, Object>>();
+                    EdgeBean edge = new EdgeBean(connector, hid);
+                    adjacencies.add(edge.out());
+                    hostBean.setLinks(adjacencies);
 
-                if (metaCache.get(containerName).containsKey(hostId)) {
+                    if (metaCache.get(containerName).containsKey(hostId)) {
                         Map<String, Object> hostEntry = metaCache.get(containerName).get(hostId);
                         hostEntry.put("adjacencies", adjacencies);
                         stagedNodes.put(hostId, hostEntry);
-                } else {
+                    } else {
                         newNodes.put(String.valueOf(hid), hostBean.out());
+                    }
                 }
             }
         }
index 92a2e866f02840f57c2f70dcf4f8b383eb6dccd9..603f4ccb9e529f20251148e3db452d755eb6e3c3 100644 (file)
@@ -158,7 +158,7 @@ public enum OFType {
      * @param i OpenFlow wire protocol type
      * @param t type
      */
-    static public void addMapping(byte i, OFType t) {
+    public static void addMapping(byte i, OFType t) {
         if (mapping == null)
             mapping = new OFType[32];
         OFType.mapping[i] = t;
@@ -169,7 +169,7 @@ public enum OFType {
      *
      * @param i OpenFlow wire protocol type
      */
-    static public void removeMapping(byte i) {
+    public static void removeMapping(byte i) {
         OFType.mapping[i] = null;
     }
 
@@ -181,7 +181,7 @@ public enum OFType {
      * @return OFType enum type
      */
 
-    static public OFType valueOf(Byte i) {
+    public static OFType valueOf(Byte i) {
         return OFType.mapping[i];
     }