Container Manager to expose inContainerMode() 17/1517/2
authorAlessandro Boch <aboch@cisco.com>
Mon, 30 Sep 2013 17:33:37 +0000 (10:33 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 30 Sep 2013 19:29:56 +0000 (19:29 +0000)
- So that IContainerLocalListener can poll the information when starting in default container

Change-Id: I3d8ceec9adef58915379eda3d3adc752175ea74c
Signed-off-by: Alessandro Boch <aboch@cisco.com>
opendaylight/containermanager/api/src/main/java/org/opendaylight/controller/containermanager/IContainerManager.java
opendaylight/containermanager/implementation/src/main/java/org/opendaylight/controller/containermanager/internal/ContainerManager.java
opendaylight/containermanager/it.implementation/src/main/java/org/opendaylight/controller/containermanager/internal/ContainerManager.java
opendaylight/forwardingrulesmanager/implementation/pom.xml
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/Activator.java
opendaylight/forwardingrulesmanager/implementation/src/main/java/org/opendaylight/controller/forwardingrulesmanager/internal/ForwardingRulesManager.java

index 5daaf00ece4fb4956695c74349d53d471270895a..b2e2a7631b483a977f71e5bbedb4fc7f240243d5 100644 (file)
@@ -187,4 +187,11 @@ public interface IContainerManager {
      * @return  List of Container name strings.
      */
     public List<String> getContainerNames();
+
+    /**
+     * Returns whether the controller is running in container mode
+     *
+     * @return true if controller is in container mode, false otherwise
+     */
+    public boolean inContainerMode();
 }
index d420bdd0a97a3033a923b02be374384de6b0ceb7..c2610732350fdb027bf7fc8458343081c3db05fa 100644 (file)
@@ -232,7 +232,7 @@ public class ContainerManager extends Authorization<String> implements IContaine
 
         roles = (ConcurrentMap<String, AppRoleLevel>) clusterServices.getCache("containermgr.roles");
 
-        if (containerConfigs.size() > 0) {
+        if (inContainerMode()) {
             for (Map.Entry<String, ContainerConfig> entry : containerConfigs.entrySet()) {
                 // Notify global and local listeners about the mode change
                 notifyContainerChangeInternal(entry.getValue(), UpdateType.ADDED, true);
@@ -1402,10 +1402,6 @@ public class ContainerManager extends Authorization<String> implements IContaine
             return;
         }
         String staticVlan = ci.nextArgument();
-        if (staticVlan == null) {
-            ci.print("Static Vlan not specified");
-            return;
-        }
         ContainerConfig containerConfig = new ContainerConfig(containerName, staticVlan, null, null);
         ci.println(this.addRemoveContainer(containerConfig, false));
     }
@@ -1667,4 +1663,9 @@ public class ContainerManager extends Authorization<String> implements IContaine
     public boolean hasNonDefaultContainer() {
         return !containerConfigs.keySet().isEmpty();
     }
+
+    @Override
+    public boolean inContainerMode() {
+        return this.containerConfigs.size() > 0;
+    }
 }
index 24ef0c08ef9d78a4f3410ded6f998af0281065d3..f2219e53b84506d11296e30783723e6acd03e877 100644 (file)
@@ -43,7 +43,7 @@ public class ContainerManager implements IContainerManager {
      * This is configuration world: container names (also the map key)
      * are maintained as they were configured by user, same case
      */
-    private Set<IContainerAware> iContainerAware = (Set<IContainerAware>) Collections
+    private Set<IContainerAware> iContainerAware = Collections
             .synchronizedSet(new HashSet<IContainerAware>());
     private Set<IContainerListener> iContainerListener = Collections
             .synchronizedSet(new HashSet<IContainerListener>());
@@ -213,4 +213,10 @@ public class ContainerManager implements IContainerManager {
         return null;
     }
 
+    @Override
+    public boolean inContainerMode() {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
 }
index 9009bc30bd1a6a4f409eaf8524d0d1312e0e3e10..2e12cf4b3b4065647f6f49eab59a3ee1e9f965e8 100644 (file)
@@ -52,6 +52,7 @@
             <Import-Package>
               org.opendaylight.controller.clustering.services,
               org.opendaylight.controller.configuration,
+              org.opendaylight.controller.containermanager,
               org.opendaylight.controller.hosttracker,
               org.opendaylight.controller.hosttracker.hostAware,
               org.opendaylight.controller.switchmanager,
@@ -67,7 +68,6 @@
               javax.xml.bind.annotation,
               javax.xml.bind,
               org.apache.felix.dm,
-              org.apache.commons.lang3.builder,
               org.osgi.service.component,
               org.slf4j,
               org.eclipse.osgi.framework.console,
       <artifactId>connectionmanager</artifactId>
       <version>0.1.1-SNAPSHOT</version>
     </dependency>
+    <dependency>
+      <groupId>org.opendaylight.controller</groupId>
+      <artifactId>containermanager</artifactId>
+      <version>0.5.1-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>
index 7b37b4187ce91285e44f14de745d5363d79d0a7c..3ac16f467cc2c2f2f27e1099027fb2512d503b8f 100644 (file)
@@ -18,6 +18,7 @@ import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
 import org.opendaylight.controller.connectionmanager.IConnectionManager;
+import org.opendaylight.controller.containermanager.IContainerManager;
 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManager;
 import org.opendaylight.controller.forwardingrulesmanager.IForwardingRulesManagerAware;
 import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase;
@@ -25,6 +26,7 @@ import org.opendaylight.controller.sal.core.IContainer;
 import org.opendaylight.controller.sal.core.IContainerLocalListener;
 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerListener;
 import org.opendaylight.controller.sal.flowprogrammer.IFlowProgrammerService;
+import org.opendaylight.controller.sal.utils.GlobalConstants;
 import org.opendaylight.controller.switchmanager.IInventoryListener;
 import org.opendaylight.controller.switchmanager.ISwitchManager;
 import org.opendaylight.controller.switchmanager.ISwitchManagerAware;
@@ -94,8 +96,11 @@ public class Activator extends ComponentActivatorAbstractBase {
             c.add(createContainerServiceDependency(containerName).setService(IContainer.class)
                     .setCallbacks("setIContainer", "unsetIContainer").setRequired(true));
             c.add(createServiceDependency().setService(IConnectionManager.class)
-                    .setCallbacks("setIConnectionManager", "unsetIConnectionManager")
-                    .setRequired(true));
+                    .setCallbacks("setIConnectionManager", "unsetIConnectionManager").setRequired(true));
+            if (GlobalConstants.DEFAULT.toString().equals(containerName)) {
+                c.add(createServiceDependency().setService(IContainerManager.class)
+                        .setCallbacks("setIContainerManager", "unsetIContainerManager").setRequired(true));
+            }
         }
     }
 }
index 7676f0e7c405d116537d2c0160f3605c805a0054..45973fe167356b470b97f6bc7d287f59af769d31 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.controller.clustering.services.IClusterContainerServices
 import org.opendaylight.controller.clustering.services.IClusterServices;
 import org.opendaylight.controller.configuration.IConfigurationContainerAware;
 import org.opendaylight.controller.connectionmanager.IConnectionManager;
+import org.opendaylight.controller.containermanager.IContainerManager;
 import org.opendaylight.controller.forwardingrulesmanager.FlowConfig;
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntry;
 import org.opendaylight.controller.forwardingrulesmanager.FlowEntryInstall;
@@ -117,6 +118,7 @@ public class ForwardingRulesManager implements
     private ConcurrentMap<String, PortGroupConfig> portGroupConfigs;
     private ConcurrentMap<PortGroupConfig, Map<Node, PortGroup>> portGroupData;
     private ConcurrentMap<String, Object> TSPolicies;
+    private IContainerManager containerManager;
     private boolean inContainerMode; // being used by global instance only
     protected boolean stopping;
 
@@ -2636,6 +2638,14 @@ public class ForwardingRulesManager implements
      *
      */
     void start() {
+        /*
+         * If running in default container, need to know if controller is in
+         * container mode
+         */
+        if (GlobalConstants.DEFAULT.toString().equals(this.getContainerName())) {
+            inContainerMode = containerManager.inContainerMode();
+        }
+
         // Initialize graceful stop flag
         stopping = false;
 
@@ -3210,6 +3220,16 @@ public class ForwardingRulesManager implements
         this.connectionManager = s;
     }
 
+    public void unsetIContainerManager(IContainerManager s) {
+        if (s == this.containerManager) {
+            this.containerManager = null;
+        }
+    }
+
+    public void setIContainerManager(IContainerManager s) {
+        this.containerManager = s;
+    }
+
     @Override
     public void entryCreated(Object key, String cacheName, boolean originLocal) {
         /*