AMBARI-20401 - HOU wizard wrongly shows hosts with only client components at 
the start of 'Upgrade Hosts' group (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/fd257ec2
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/fd257ec2
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/fd257ec2

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: fd257ec2ab0aa88f9971c7f4a330b19b6cefd751
Parents: 01ef695
Author: Jonathan Hurley <[email protected]>
Authored: Fri Mar 10 17:06:42 2017 -0500
Committer: Jonathan Hurley <[email protected]>
Committed: Fri Mar 10 20:30:21 2017 -0500

----------------------------------------------------------------------
 .../state/stack/upgrade/HostOrderGrouping.java  | 15 ++++--
 .../internal/UpgradeResourceProviderTest.java   | 54 ++++++++++++++++++++
 2 files changed, 64 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/fd257ec2/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
 
b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
index 7734731..97864a6 100644
--- 
a/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
+++ 
b/ambari-server/src/main/java/org/apache/ambari/server/state/stack/upgrade/HostOrderGrouping.java
@@ -205,10 +205,6 @@ public class HostOrderGrouping extends Grouping {
           continue;
         }
 
-        // build the single STOP stage
-        StageWrapper stopWrapper = new StageWrapper(StageWrapper.Type.STOP, 
String.format("Stop on %s", hostName),
-            stopTasks.toArray(new TaskWrapper[stopTasks.size()]));
-
         // now process the HRCs created so that we can create the appropriate
         // stage/task wrappers for the RESTARTs
         RoleGraphFactory roleGraphFactory = 
upgradeContext.getRoleGraphFactory();
@@ -267,10 +263,19 @@ public class HostOrderGrouping extends Grouping {
         structuredOut.addProperty(HOST, hostName);
         mt.structuredOut = structuredOut.toString();
 
+        // build the single STOP stage, but only if there are components to
+        // stop; client-only hosts have no components which need stopping
+        if (!stopTasks.isEmpty()) {
+          StageWrapper stopWrapper = new StageWrapper(StageWrapper.Type.STOP,
+              String.format("Stop on %s", hostName),
+              stopTasks.toArray(new TaskWrapper[stopTasks.size()]));
+
+          wrappers.add(stopWrapper);
+        }
+
         StageWrapper manualWrapper = new 
StageWrapper(StageWrapper.Type.SERVER_SIDE_ACTION, "Manual Confirmation",
             new TaskWrapper(null, null, Collections.<String>emptySet(), mt));
 
-        wrappers.add(stopWrapper);
         wrappers.add(manualWrapper);
 
         // !!! TODO install_packages for hdp and conf-select changes.  
Hopefully these will no-op.

http://git-wip-us.apache.org/repos/asf/ambari/blob/fd257ec2/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
----------------------------------------------------------------------
diff --git 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
index 62e55c4..3e70989 100644
--- 
a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
+++ 
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/UpgradeResourceProviderTest.java
@@ -1562,6 +1562,60 @@ public class UpgradeResourceProviderTest {
     assertEquals("UNKNOWN", hostComponent.getVersion());
   }
 
+  /**
+   * Ensures that stages created with an HOU are sequential and do not skip any
+   * IDs. When there are stages with IDs like (1,2,3,5,6,7,10), the request 
will
+   * get stuck in a PENDING state. This affects HOU specifically since they can
+   * potentially try to create empty stages which won't get persisted (such as 
a
+   * STOP on client-only hosts).
+   *
+   * @throws Exception
+   */
+  @Test()
+  public void testEmptyGroupingsDoNotSkipStageIds() throws Exception {
+
+    StageDAO stageDao = injector.getInstance(StageDAO.class);
+    Assert.assertEquals(0, stageDao.findAll().size());
+
+    // strip out all non-client components - clients don't have STOP commands
+    Cluster cluster = clusters.getCluster("c1");
+    List<ServiceComponentHost> schs = cluster.getServiceComponentHosts("h1");
+    for (ServiceComponentHost sch : schs) {
+      if (sch.isClientComponent()) {
+        continue;
+      }
+
+      cluster.removeServiceComponentHost(sch);
+    }
+
+    // define host order
+    Set<Map<String, List<String>>> hostsOrder = new LinkedHashSet<>();
+    Map<String, List<String>> hostGrouping = new HashMap<>();
+    hostGrouping = new HashMap<>();
+    hostGrouping.put("hosts", Lists.newArrayList("h1"));
+    hostsOrder.add(hostGrouping);
+
+    Map<String, Object> requestProps = new HashMap<>();
+    requestProps.put(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME, "c1");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_VERSION, "2.2.0.0");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_PACK, 
"upgrade_test_host_ordered");
+    requestProps.put(UpgradeResourceProvider.UPGRADE_TYPE, 
UpgradeType.HOST_ORDERED.toString());
+    
requestProps.put(UpgradeResourceProvider.UPGRADE_SKIP_PREREQUISITE_CHECKS,Boolean.TRUE.toString());
+    requestProps.put(UpgradeResourceProvider.UPGRADE_DIRECTION, 
Direction.UPGRADE.name());
+    requestProps.put(UpgradeResourceProvider.UPGRADE_HOST_ORDERED_HOSTS, 
hostsOrder);
+
+    ResourceProvider upgradeResourceProvider = createProvider(amc);
+    Request request = 
PropertyHelper.getCreateRequest(Collections.singleton(requestProps), null);
+    upgradeResourceProvider.createResources(request);
+
+    List<StageEntity> stages = 
stageDao.findByRequestId(cluster.getUpgradeEntity().getRequestId());
+    Assert.assertEquals(3, stages.size());
+
+    long expectedStageId = 1L;
+    for (StageEntity stage : stages) {
+      Assert.assertEquals(expectedStageId++, stage.getStageId().longValue());
+    }
+  }
 
   private String parseSingleMessage(String msgStr){
     JsonParser parser = new JsonParser();

Reply via email to