瀏覽代碼

AMBARI-1944. All Service Smoke tests fail when run with service start. (swagle)

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/trunk@1468303 13f79535-47bb-0310-9956-ffa450edef68
Siddharth Wagle 12 年之前
父節點
當前提交
a6bec1ee66

+ 2 - 0
CHANGES.txt

@@ -745,6 +745,8 @@ Trunk (unreleased changes):
 
 
  BUG FIXES
  BUG FIXES
 
 
+ AMBARI-1944. All Service Smoke tests fail when run with service start. (swagle)
+
  AMBARI-1939. Make service restart feedback based on supports functionality. 
  AMBARI-1939. Make service restart feedback based on supports functionality. 
  (srimanth)
  (srimanth)
 
 

+ 64 - 87
ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java

@@ -1906,6 +1906,54 @@ public class AmbariManagementControllerImpl implements
     }
     }
   }
   }
 
 
+  private void findConfigurationPropertiesWithOverrides(
+    Map<String, Map<String, String>> configurations,
+    Map<String, Map<String, String>> configTags,
+    Cluster cluster, String serviceName, String hostName) throws AmbariException {
+    // Do not use host component config mappings.  Instead, the rules are:
+    // 1) Use the cluster desired config
+    // 2) override (1) with service-specific overrides
+    // 3) override (2) with host-specific overrides
+
+    // since we are dealing with host components in this loop, get the
+    // config mappings for the service this host component applies to
+
+    for (Entry<String, DesiredConfig> entry : cluster.getDesiredConfigs().entrySet()) {
+      String type = entry.getKey();
+      String tag = entry.getValue().getVersion();
+      // 1) start with cluster config
+      Config config = cluster.getConfig(type, tag);
+
+      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());
+
+      // 2) apply the service overrides, if any are defined with different tags
+      Service service = cluster.getService(serviceName);
+      Config svcConfig = service.getDesiredConfigs().get(type);
+      if (null != svcConfig && !svcConfig.getVersionTag().equals(tag)) {
+        props.putAll(svcConfig.getProperties());
+      }
+
+      // 3) apply the host overrides, if any
+      Host host = clusters.getHost(hostName);
+      DesiredConfig dc = host.getDesiredConfigs(cluster.getClusterId()).get(type);
+      if (null != dc) {
+        Config hostConfig = cluster.getConfig(type, dc.getVersion());
+        if (null != hostConfig) {
+          props.putAll(hostConfig.getProperties());
+          tags.put("host_override_tag", hostConfig.getVersionTag());
+        }
+      }
+
+      configurations.put(type, props);
+      configTags.put(type, tags);
+    }
+  }
+
   private List<Stage> doStageCreation(Cluster cluster,
   private List<Stage> doStageCreation(Cluster cluster,
       Map<State, List<Service>> changedServices,
       Map<State, List<Service>> changedServices,
       Map<State, List<ServiceComponent>> changedComps,
       Map<State, List<ServiceComponent>> changedComps,
@@ -2070,48 +2118,8 @@ public class AmbariManagementControllerImpl implements
             Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String,String>>();
             Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String,String>>();
             Map<String, Map<String, String>> configTags = new HashMap<String, Map<String,String>>();
             Map<String, Map<String, String>> configTags = new HashMap<String, Map<String,String>>();
 
 
-            // Do not use host component config mappings.  Instead, the rules are:
-            // 1) Use the cluster desired config
-            // 2) override (1) with service-specific overrides
-            // 3) override (2) with host-specific overrides
-
-            // since we are dealing with host components in this loop, get the
-            // config mappings for the service this host component applies to
-
-            for (Entry<String, DesiredConfig> entry : cluster.getDesiredConfigs().entrySet()) {
-              String type = entry.getKey();
-              String tag = entry.getValue().getVersion();
-              // 1) start with cluster config
-              Config config = cluster.getConfig(type, tag);
-
-              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());
-
-              // 2) apply the service overrides, if any are defined with different tags
-              Service service = cluster.getService(scHost.getServiceName());
-              Config svcConfig = service.getDesiredConfigs().get(type);
-              if (null != svcConfig && !svcConfig.getVersionTag().equals(tag)) {
-                props.putAll(svcConfig.getProperties());
-              }
-
-              // 3) apply the host overrides, if any
-              Host host = clusters.getHost(scHost.getHostName());
-              DesiredConfig dc = host.getDesiredConfigs(scHost.getClusterId()).get(type);
-              if (null != dc) {
-                Config hostConfig = cluster.getConfig(type, dc.getVersion());
-                if (null != hostConfig) {
-                  props.putAll(hostConfig.getProperties());
-                  tags.put("host_override_tag", hostConfig.getVersionTag());
-                }
-              }
-
-              configurations.put(type, props);
-              configTags.put(type, tags);
-            }
+            findConfigurationPropertiesWithOverrides(configurations, configTags,
+              cluster, scHost.getServiceName(), scHost.getHostName());
 
 
             // HACK HACK HACK
             // HACK HACK HACK
             if ((!scHost.getHostName().equals(jobtrackerHost))
             if ((!scHost.getHostName().equals(jobtrackerHost))
@@ -2153,19 +2161,21 @@ public class AmbariManagementControllerImpl implements
             new ServiceComponentHostOpInProgressEvent(null, clientHost,
             new ServiceComponentHostOpInProgressEvent(null, clientHost,
                 nowTimestamp), cluster.getClusterName(), serviceName);
                 nowTimestamp), cluster.getClusterName(), serviceName);
 
 
-        Map<String, Map<String, String>> configurations =
-            new TreeMap<String, Map<String, String>>();
-        Map<String, Config> allConfigs = cluster.getService(serviceName).getDesiredConfigs();
-        if (allConfigs != null) {
-          for (Map.Entry<String, Config> entry: allConfigs.entrySet()) {
-            configurations.put(entry.getValue().getType(), entry.getValue().getProperties());
-          }
-        }
+        // [ type -> [ key, value ] ]
+        Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String,String>>();
+        Map<String, Map<String, String>> configTags = new HashMap<String, Map<String,String>>();
+
+        findConfigurationPropertiesWithOverrides(configurations, configTags,
+          cluster, serviceName, clientHost);
 
 
         stage.getExecutionCommandWrapper(clientHost,
         stage.getExecutionCommandWrapper(clientHost,
             smokeTestRole).getExecutionCommand()
             smokeTestRole).getExecutionCommand()
             .setConfigurations(configurations);
             .setConfigurations(configurations);
 
 
+        stage.getExecutionCommandWrapper(clientHost,
+          smokeTestRole).getExecutionCommand()
+          .setConfigurationTags(configTags);
+
         // Generate cluster host info
         // Generate cluster host info
         stage.getExecutionCommandWrapper(clientHost, smokeTestRole)
         stage.getExecutionCommandWrapper(clientHost, smokeTestRole)
             .getExecutionCommand()
             .getExecutionCommand()
@@ -3971,44 +3981,11 @@ public class AmbariManagementControllerImpl implements
     
     
     // [ type -> [ key, value ] ]
     // [ type -> [ key, value ] ]
     Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String,String>>();
     Map<String, Map<String, String>> configurations = new TreeMap<String, Map<String,String>>();
+    Map<String, Map<String, String>> configTags = new TreeMap<String,
+      Map<String, String>>();
 
 
-    // Do not use service config mappings.  Instead, the rules are:
-    // 1) Use the cluster desired config
-    // 2) override (1) with service-specific overrides
-    // 3) override (2) with host-specific overrides
-    // Yes, we may be sending more configs than are actually used, but that is
-    // because of the new design
-
-    for (Entry<String, DesiredConfig> entry : cluster.getDesiredConfigs().entrySet()) {
-      String type = entry.getKey();
-      String tag = entry.getValue().getVersion();
-      // 1) start with cluster config
-      Config config = cluster.getConfig(type, tag);
-
-      if (null == config)
-        continue;
-
-      Map<String, String> props = new HashMap<String, String>(config.getProperties());
-
-      // 2) apply the service overrides, if any are defined with different tags
-      Service service = cluster.getService(actionRequest.getServiceName());
-      Config svcConfig = service.getDesiredConfigs().get(type);
-      if (null != svcConfig && !svcConfig.getVersionTag().equals(tag)) {
-        props.putAll(svcConfig.getProperties());
-      }
-
-      // 3) apply the host overrides, if any
-      Host host = clusters.getHost(hostName);
-      DesiredConfig dc = host.getDesiredConfigs(cluster.getClusterId()).get(type);
-      if (null != dc) {
-        Config hostConfig = cluster.getConfig(type, dc.getVersion());
-        if (null != hostConfig) {
-          props.putAll(hostConfig.getProperties());
-        }
-      }
-
-      configurations.put(type, props);
-    }
+    findConfigurationPropertiesWithOverrides(configurations, configTags,
+      cluster, actionRequest.getServiceName(), hostName);
 
 
     ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostName,
     ExecutionCommand execCmd = stage.getExecutionCommandWrapper(hostName,
       actionRequest.getActionName()).getExecutionCommand();
       actionRequest.getActionName()).getExecutionCommand();

+ 97 - 14
ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

@@ -190,7 +190,7 @@ public class AmbariManagementControllerTest {
   }
   }
 
 
   private long stopService(String clusterName, String serviceName,
   private long stopService(String clusterName, String serviceName,
-                           boolean reconfigureClients) throws
+      boolean runSmokeTests, boolean reconfigureClients) throws
     AmbariException {
     AmbariException {
     ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
     ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
       State.INSTALLED.toString());
       State.INSTALLED.toString());
@@ -199,7 +199,7 @@ public class AmbariManagementControllerTest {
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
     mapRequestProps.put("context", "Called from a test");
     RequestStatusResponse resp = controller.updateServices(requests,
     RequestStatusResponse resp = controller.updateServices(requests,
-      mapRequestProps, true, reconfigureClients);
+      mapRequestProps, runSmokeTests, reconfigureClients);
 
 
     Assert.assertEquals(State.INSTALLED,
     Assert.assertEquals(State.INSTALLED,
       clusters.getCluster(clusterName).getService(serviceName)
       clusters.getCluster(clusterName).getService(serviceName)
@@ -218,7 +218,7 @@ public class AmbariManagementControllerTest {
   }
   }
 
 
   private long startService(String clusterName, String serviceName,
   private long startService(String clusterName, String serviceName,
-                            boolean reconfigureClients) throws
+      boolean runSmokeTests, boolean reconfigureClients) throws
     AmbariException {
     AmbariException {
     ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
     ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
       State.STARTED.toString());
       State.STARTED.toString());
@@ -227,7 +227,7 @@ public class AmbariManagementControllerTest {
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
     mapRequestProps.put("context", "Called from a test");
     RequestStatusResponse resp = controller.updateServices(requests,
     RequestStatusResponse resp = controller.updateServices(requests,
-      mapRequestProps, true, reconfigureClients);
+      mapRequestProps, runSmokeTests, reconfigureClients);
 
 
     Assert.assertEquals(State.STARTED,
     Assert.assertEquals(State.STARTED,
       clusters.getCluster(clusterName).getService(serviceName)
       clusters.getCluster(clusterName).getService(serviceName)
@@ -246,7 +246,7 @@ public class AmbariManagementControllerTest {
   }
   }
 
 
   private long installService(String clusterName, String serviceName,
   private long installService(String clusterName, String serviceName,
-                              boolean reconfigureClients) throws
+      boolean runSmokeTests, boolean reconfigureClients) throws
     AmbariException {
     AmbariException {
     ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
     ServiceRequest r = new ServiceRequest(clusterName, serviceName, null,
       State.INSTALLED.toString());
       State.INSTALLED.toString());
@@ -255,7 +255,7 @@ public class AmbariManagementControllerTest {
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     Map<String, String> mapRequestProps = new HashMap<String, String>();
     mapRequestProps.put("context", "Called from a test");
     mapRequestProps.put("context", "Called from a test");
     RequestStatusResponse resp = controller.updateServices(requests,
     RequestStatusResponse resp = controller.updateServices(requests,
-      mapRequestProps, true, reconfigureClients);
+      mapRequestProps, runSmokeTests, reconfigureClients);
 
 
     Assert.assertEquals(State.INSTALLED,
     Assert.assertEquals(State.INSTALLED,
       clusters.getCluster(clusterName).getService(serviceName)
       clusters.getCluster(clusterName).getService(serviceName)
@@ -4458,18 +4458,18 @@ public class AmbariManagementControllerTest {
     controller.updateCluster(crReq, null);
     controller.updateCluster(crReq, null);
 
 
     // Install
     // Install
-    long requestId1 = installService(clusterName, serviceName1, false);
+    long requestId1 = installService(clusterName, serviceName1, true, false);
 
 
     List<Stage> stages = actionDB.getAllStages(requestId1);
     List<Stage> stages = actionDB.getAllStages(requestId1);
     Assert.assertEquals(2, stages.get(0).getOrderedHostRoleCommands().get(0)
     Assert.assertEquals(2, stages.get(0).getOrderedHostRoleCommands().get(0)
       .getExecutionCommandWrapper().getExecutionCommand()
       .getExecutionCommandWrapper().getExecutionCommand()
       .getConfigurationTags().size());
       .getConfigurationTags().size());
 
 
-    installService(clusterName, serviceName2, false);
+    installService(clusterName, serviceName2, false, false);
 
 
     // Start
     // Start
-    startService(clusterName, serviceName1, false);
-    startService(clusterName, serviceName2, false);
+    startService(clusterName, serviceName1, true, false);
+    startService(clusterName, serviceName2, true, false);
 
 
     // Reconfigure
     // Reconfigure
     configs.clear();
     configs.clear();
@@ -4481,12 +4481,12 @@ public class AmbariManagementControllerTest {
     controller.updateCluster(crReq, null);
     controller.updateCluster(crReq, null);
 
 
     // Stop HDFS & MAPREDUCE
     // Stop HDFS & MAPREDUCE
-    stopService(clusterName, serviceName1, false);
-    stopService(clusterName, serviceName2, false);
+    stopService(clusterName, serviceName1, false, false);
+    stopService(clusterName, serviceName2, false, false);
 
 
     // Start
     // Start
-    long requestId2 = startService(clusterName, serviceName1, true);
-    long requestId3 = startService(clusterName, serviceName2, true);
+    long requestId2 = startService(clusterName, serviceName1, true, true);
+    long requestId3 = startService(clusterName, serviceName2, true, true);
 
 
     stages = actionDB.getAllStages(requestId2);
     stages = actionDB.getAllStages(requestId2);
     stages.addAll(actionDB.getAllStages(requestId3));
     stages.addAll(actionDB.getAllStages(requestId3));
@@ -4615,6 +4615,89 @@ public class AmbariManagementControllerTest {
         taskStatuses.get(0).getRole());
         taskStatuses.get(0).getRole());
   }
   }
 
 
+  @Test
+  public void testConfigsAttachedToServiceChecks() throws AmbariException {
+    String clusterName = "foo1";
+    createCluster(clusterName);
+    clusters.getCluster(clusterName)
+      .setDesiredStackVersion(new StackId("HDP-0.1"));
+    String serviceName = "HDFS";
+    createService(clusterName, serviceName, null);
+    String componentName1 = "NAMENODE";
+    String componentName2 = "DATANODE";
+    String componentName3 = "HDFS_CLIENT";
+
+    Map<String, String> mapRequestProps = new HashMap<String, String>();
+    mapRequestProps.put("context", "Called from a test");
+
+    createServiceComponent(clusterName, serviceName, componentName1,
+      State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName2,
+      State.INIT);
+    createServiceComponent(clusterName, serviceName, componentName3,
+      State.INIT);
+
+    String host1 = "h1";
+    clusters.addHost(host1);
+    clusters.getHost("h1").setOsType("centos5");
+    clusters.getHost("h1").persist();
+    String host2 = "h2";
+    clusters.addHost(host2);
+    clusters.getHost("h2").setOsType("centos6");
+    clusters.getHost("h2").persist();
+
+    clusters.mapHostToCluster(host1, clusterName);
+    clusters.mapHostToCluster(host2, clusterName);
+
+
+    // null service should work
+    createServiceComponentHost(clusterName, null, componentName1,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName2,
+      host2, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+      host1, null);
+    createServiceComponentHost(clusterName, serviceName, componentName3,
+      host2, null);
+
+    // Create and attach config
+    Map<String, String> configs = new HashMap<String, String>();
+    configs.put("a", "b");
+
+    ConfigurationRequest cr1,cr2;
+    cr1 = new ConfigurationRequest(clusterName, "core-site","version1",
+      configs);
+    cr2 = new ConfigurationRequest(clusterName, "hdfs-site","version1",
+      configs);
+
+    ClusterRequest crReq = new ClusterRequest(null, clusterName, null, null);
+    crReq.setDesiredConfig(cr1);
+    controller.updateCluster(crReq, null);
+    crReq = new ClusterRequest(null, clusterName, null, null);
+    crReq.setDesiredConfig(cr2);
+    controller.updateCluster(crReq, null);
+
+    // Install
+    installService(clusterName, serviceName, false, false);
+    // Start
+    long requestId = startService(clusterName, serviceName, true, false);
+
+    List<Stage> stages = actionDB.getAllStages(requestId);
+    boolean serviceCheckFound = false;
+    for (Stage stage : stages) {
+      for (HostRoleCommand hrc : stage.getOrderedHostRoleCommands()) {
+        if (hrc.getRole().equals(Role.HDFS_SERVICE_CHECK)) {
+          serviceCheckFound = true;
+          Assert.assertEquals(2, hrc.getExecutionCommandWrapper()
+            .getExecutionCommand().getConfigurationTags().size());
+        }
+      }
+    }
+    Assert.assertEquals(true, serviceCheckFound);
+  }
+
   @Test
   @Test
   public void testStackVersionAsHostLevelParams() throws AmbariException {
   public void testStackVersionAsHostLevelParams() throws AmbariException {
     String clusterName = "foo1";
     String clusterName = "foo1";