On container removal, remove startup files from the cluster
[controller.git] / opendaylight / containermanager / implementation / src / main / java / org / opendaylight / controller / containermanager / internal / ContainerManager.java
index d420bdd0a97a3033a923b02be374384de6b0ceb7..7319d5a15d360ed7d5f834c8144bd35f562d9691 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);
@@ -621,9 +621,9 @@ public class ContainerManager extends Authorization<String> implements IContaine
                     String msg = null;
                     ContainerData other = containerData.get(otherContainerName);
                     if (flowSpecList.isEmpty()) {
-                        msg = String.format("Port %s is shared and flow spec is emtpy for this container", port);
+                        msg = String.format("Port %s is shared and flow spec is empty for this container", port);
                     } else if (other.isFlowSpecEmpty()) {
-                        msg = String.format("Port %s is shared and flow spec is emtpy for the other container", port);
+                        msg = String.format("Port %s is shared and flow spec is empty for the other container", port);
                     } else if (!checkCommonContainerFlow(flowSpecList, other.getContainerFlowSpecs()).isSuccess()) {
                         msg = String.format("Port %s is shared and other container has common flow spec", port);
                     }
@@ -761,7 +761,7 @@ public class ContainerManager extends Authorization<String> implements IContaine
         File directory = new File(startupLocation);
         String[] fileList = directory.list();
 
-        logger.trace("Deleteing startup configuration files for container {}", containerName);
+        logger.trace("Deleting startup configuration files for container {}", containerName);
         if (fileList != null) {
             for (String fileName : fileList) {
                 if (fileName.contains(containerPrint)) {
@@ -826,15 +826,12 @@ public class ContainerManager extends Authorization<String> implements IContaine
      * @param containerName
      * @param delete
      */
-    private void updateResourceGroups(String containerName, boolean delete) {
-        String containerProfile = System.getProperty("container.profile");
-        if (containerProfile == null) {
-            containerProfile = "Container";
-        }
+    private void updateResourceGroups(ContainerConfig containerConf, boolean delete) {
         // Container Roles and Container Resource Group
-        String groupName = containerProfile+"-" + containerName;
-        String containerAdminRole = containerProfile+"-" + containerName + "-Admin";
-        String containerOperatorRole = containerProfile+"-" + containerName + "-Operator";
+        String containerName = containerConf.getContainer();
+        String groupName = containerConf.getContainerGroupName();
+        String containerAdminRole = containerConf.getContainerAdminRole();
+        String containerOperatorRole = containerConf.getContainerOperatorRole();
         Set<String> allContainerSet = resourceGroups.get(allResourcesGroupName);
         if (delete) {
             resourceGroups.remove(groupName);
@@ -932,7 +929,7 @@ public class ContainerManager extends Authorization<String> implements IContaine
 
     private Status addRemoveContainerEntries(String containerName, List<String> nodeConnectorsString, boolean delete) {
         // Construct action message
-        String action = String.format("Node conenctor(s) %s container %s: %s", delete ? "removal from" : "addition to",
+        String action = String.format("Node connector(s) %s container %s: %s", delete ? "removal from" : "addition to",
                 containerName, nodeConnectorsString);
 
         // Validity Check
@@ -1019,6 +1016,19 @@ public class ContainerManager extends Authorization<String> implements IContaine
         notifyContainerModeChange(delete, notifyLocal);
         // Notify listeners
         notifyContainerAwareListeners(container, delete);
+
+        /*
+         * This is a quick fix until configuration service becomes the
+         * centralized configuration management place. Here container manager
+         * will remove the startup files for all the bundles that are present in
+         * the container being deleted. Do the cleanup here in Container manger
+         * as do not want to put this temporary code in Configuration manager
+         * yet which is ODL.
+         */
+        if (delete) {
+            // TODO: remove when Config Mgr takes over
+            removeComponentsStartUpfiles(containerName);
+        }
     }
 
     private void notifyContainerEntryChangeInternal(String containerName, List<NodeConnector> ncList, UpdateType update, boolean notifyLocal) {
@@ -1194,19 +1204,6 @@ public class ContainerManager extends Authorization<String> implements IContaine
             return status;
         }
 
-        /*
-         * This is a quick fix until configuration service becomes the
-         * centralized configuration management place. Here container manager will
-         * remove the startup files for all the bundles that are present in the
-         * container being deleted. Do the cleanup here in Container manger as do not
-         * want to put this temporary code in Configuration manager yet which is
-         * ODL.
-         */
-        if (delete) {
-            // TODO: remove when Config Mgr takes over
-            removeComponentsStartUpfiles(containerName);
-        }
-
         /*
          * Update Configuration: This will trigger the notifications on cache
          * update callback locally and on the other cluster nodes
@@ -1218,7 +1215,7 @@ public class ContainerManager extends Authorization<String> implements IContaine
         }
 
         // Automatically create and populate user and resource groups
-        updateResourceGroups(containerName, delete);
+        updateResourceGroups(containerConf, delete);
 
         // Notify global and local listeners
         UpdateType update = (delete) ? UpdateType.REMOVED : UpdateType.ADDED;
@@ -1402,10 +1399,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 +1660,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;
+    }
 }