Bläddra i källkod

AMBARI-3238. 1st host on a 2-node cluster goes to heartbeat lost state in UI after decommissioning datanode on 2nd host.

Sumit Mohanty 11 år sedan
förälder
incheckning
f88f7135fb

+ 13 - 5
ambari-agent/src/main/python/ambari_agent/PuppetExecutor.py

@@ -152,13 +152,21 @@ class PuppetExecutor:
   def isJavaAvailable(self, command):
     javaExecutablePath = "{0}/bin/java".format(command)
     return not self.sh.run([javaExecutablePath, '-version'])['exitCode']
-    
+
   def runCommand(self, command, tmpoutfile, tmperrfile):
     # After installing we must have jdk available for start/stop/smoke
-    java64_home = str(command['configurations']['global']['java64_home']).strip()
-    if command['roleCommand']!="INSTALL" and not self.isJavaAvailable(java64_home):
-      errMsg = JAVANOTVALID_MSG.format(java64_home)
-      return {'stdout': '', 'stderr': errMsg, 'exitcode': 1}
+    if command['roleCommand'] != "INSTALL":
+      java64_home = None
+      if ('global' in command['configurations']) and ('java64_home' in command['configurations']['global']):
+        java64_home = str(command['configurations']['global']['java64_home']).strip()
+      if java64_home is None or not self.isJavaAvailable(java64_home):
+        if java64_home is None:
+          errMsg = "Cannot access JDK! Make sure java64_home is specified in global config"
+        else:
+          errMsg = JAVANOTVALID_MSG.format(java64_home)
+        return {'stdout': '', 'stderr': errMsg, 'exitcode': 1}
+      pass
+    pass
 
     taskId = 0
     if command.has_key("taskId"):

+ 5 - 0
ambari-agent/src/test/python/TestPuppetExecutor.py

@@ -99,6 +99,11 @@ class TestPuppetExecutor(TestCase):
     self.assertEquals(res["stderr"], errMsg)
     self.assertFalse(puppetInstance.reposInstalled)
 
+    parsedJson['configurations'] = {'random':{'name1':'value2'}}
+    res = puppetInstance.runCommand(parsedJson, tmpdir + '/out.txt', tmpdir + '/err.txt')
+    self.assertEquals(res["exitcode"], 1)
+    self.assertEquals(res["stderr"], "Cannot access JDK! Make sure java64_home is specified in global config")
+
   @patch.object(PuppetExecutor, 'isJavaAvailable')
   @patch.object(RepoInstaller, 'generate_repo_manifests')
   @patch.object(PuppetExecutor, 'runPuppetFile')

+ 21 - 15
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -118,6 +118,8 @@ public class AmbariManagementControllerImpl implements
 
   private String baseLogDir = "/tmp/ambari";
 
+  private String clusterLevelTag = "tag";
+
   private final ActionManager actionManager;
 
   @SuppressWarnings("unused")
@@ -1893,12 +1895,13 @@ public class AmbariManagementControllerImpl implements
       // 1) start with cluster config
       Config config = cluster.getConfig(type, tag);
 
-      if (null == config)
+      if (null == config) {
         continue;
+      }
 
       Map<String, String> props = new HashMap<String, String>(config.getProperties());
       Map<String, String> tags = new HashMap<String, String>();
-      tags.put("tag", config.getVersionTag());
+      tags.put(clusterLevelTag, config.getVersionTag());
 
       // 2) apply the service overrides, if any are defined with different tags
       Service service = cluster.getService(serviceName);
@@ -1920,13 +1923,10 @@ public class AmbariManagementControllerImpl implements
         }
       }
 
-      //TODO store empty map for now
-//      configurations.put(type, props);
       configTags.put(type, tags);
     }
 
 
-
     // HACK HACK HACK if the service has configs that are NOT included
     // in cluster-level, then use them anyway.  THIS IS GENERALLY A BAD
     // IDEA, but is included for backward compatability.  Do not check host
@@ -1936,10 +1936,10 @@ public class AmbariManagementControllerImpl implements
     for (Config c : service.getDesiredConfigs().values()) {
       String type = c.getType();
       if (!configurations.containsKey(type)) {
-        configurations.put(type, new HashMap<String,String>(c.getProperties()));
+        configurations.put(type, new HashMap<String, String>(c.getProperties()));
 
-        HashMap<String,String> tags = new HashMap<String,String>();
-        tags.put("tag", c.getVersionTag());
+        HashMap<String, String> tags = new HashMap<String, String>();
+        tags.put(clusterLevelTag, c.getVersionTag());
         configTags.put(type, tags);
       }
     }
@@ -4215,6 +4215,7 @@ public class AmbariManagementControllerImpl implements
   private void addDecommissionDatanodeAction(
       ActionRequest decommissionRequest, Stage stage)
       throws AmbariException {
+    String hdfsExcludeFileType = "hdfs-exclude-file";
     // Find hdfs admin host, just decommission from namenode.
     String clusterName = decommissionRequest.getClusterName();
     Cluster cluster = clusters.getCluster(clusterName);
@@ -4236,17 +4237,22 @@ public class AmbariManagementControllerImpl implements
     }
 
     Config config = clusters.getCluster(clusterName).getConfig(
-        "hdfs-exclude-file", excludeFileTag);
+        hdfsExcludeFileType, excludeFileTag);
+
+    LOG.info("Decommissioning data nodes: " + config.getProperties().get("datanodes") +
+        " " + hdfsExcludeFileType + " tag: " + excludeFileTag);
 
     Map<String, Map<String, String>> configurations =
         new TreeMap<String, Map<String, String>>();
-    configurations.put(config.getType(), config.getProperties());
-
     Map<String, Map<String, String>> configTags = new TreeMap<String,
-      Map<String, String>>();
+        Map<String, String>>();
 
     findConfigurationPropertiesWithOverrides(configurations, configTags,
-      cluster, serviceName, namenodeHost);
+        cluster, serviceName, namenodeHost);
+    // Add the tag for hdfs-exclude-file
+    Map<String, String> excludeTags = new HashMap<String, String>();
+    excludeTags.put(clusterLevelTag, config.getVersionTag());
+    configTags.put(hdfsExcludeFileType, excludeTags);
 
     stage.addHostRoleExecutionCommand(
         namenodeHost,
@@ -4257,7 +4263,7 @@ public class AmbariManagementControllerImpl implements
         clusterName, serviceName);
 
     ExecutionCommand execCmd = stage.getExecutionCommandWrapper(namenodeHost,
-      Role.DECOMMISSION_DATANODE.toString()).getExecutionCommand();
+        Role.DECOMMISSION_DATANODE.toString()).getExecutionCommand();
 
     execCmd.setConfigurations(configurations);
     execCmd.setConfigurationTags(configTags);
@@ -4265,7 +4271,7 @@ public class AmbariManagementControllerImpl implements
     Map<String, String> params = new TreeMap<String, String>();
     params.put("jdk_location", this.jdkResourceUrl);
     params.put("stack_version", cluster.getDesiredStackVersion()
-      .getStackVersion());
+        .getStackVersion());
     execCmd.setHostLevelParams(params);
 
   }

+ 2 - 1
ambari-server/src/main/java/org/apache/ambari/server/metadata/ActionMetadata.java

@@ -53,7 +53,8 @@ public class ActionMetadata {
   }
 
   private void fillServiceActions() {
-    serviceActions.put("hdfs"       , Arrays.asList(Role.HDFS_SERVICE_CHECK.toString()));
+    serviceActions.put("hdfs"       , Arrays.asList(Role.HDFS_SERVICE_CHECK.toString(),
+                                                    Role.DECOMMISSION_DATANODE.toString()));
     serviceActions.put("hcfs"       , Arrays.asList(Role.HCFS_SERVICE_CHECK.toString()));
     serviceActions.put("hbase"      , Arrays.asList(Role.HBASE_SERVICE_CHECK.toString()));
     serviceActions.put("mapreduce"  , Arrays.asList(Role.MAPREDUCE_SERVICE_CHECK.toString()));

+ 2 - 1
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -5449,7 +5449,8 @@ public class AmbariManagementControllerTest {
     Assert.assertNotNull(execCmd.getConfigurationTags().get("hdfs-site"));
     Assert.assertEquals(1, storedTasks.size());
     Assert.assertEquals(host2, execCmd.getConfigurations().get
-      ("hdfs-exclude-file").get("datanodes"));
+        ("hdfs-exclude-file").get("datanodes"));
+    Assert.assertNotNull(execCmd.getConfigurationTags().get("hdfs-exclude-file"));
   }
 
   @Test