ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject ambari git commit: AMBARI-15397 Rolling Upgrade: incorrect display_status of upgrade groups (dsen)
Date Mon, 14 Mar 2016 18:44:56 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk cbd88027a -> b9d06931a


AMBARI-15397 Rolling Upgrade: incorrect display_status of upgrade groups (dsen)


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

Branch: refs/heads/trunk
Commit: b9d06931abf989eb8c6715ff9a4cc4c3f4f25ece
Parents: cbd8802
Author: Dmytro Sen <dsen@apache.org>
Authored: Mon Mar 14 20:42:10 2016 +0200
Committer: Dmytro Sen <dsen@apache.org>
Committed: Mon Mar 14 20:42:27 2016 +0200

----------------------------------------------------------------------
 .../controller/internal/CalculatedStatus.java   | 41 +++++++--------
 .../internal/CalculatedStatusTest.java          | 55 +++++++++++++++++++-
 2 files changed, 74 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b9d06931/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
index a722bc1..1d8df9b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/CalculatedStatus.java
@@ -300,10 +300,10 @@ public class CalculatedStatus {
   public static CalculatedStatus statusFromStageSummary(Map<Long, HostRoleCommandStatusSummaryDTO>
stageDto,
       Set<Long> stageIds) {
 
-    Collection<HostRoleStatus> stageStatuses = new HashSet<HostRoleStatus>();
-    Collection<HostRoleStatus> taskStatuses = new ArrayList<HostRoleStatus>();
+    Collection<HostRoleStatus> stageStatuses = new HashSet<>();
+    Collection<HostRoleStatus> stageDisplayStatuses = new HashSet<>();
+    Collection<HostRoleStatus> taskStatuses = new ArrayList<>();
 
-    HostRoleStatus displayStatus = null;
 
     for (Long stageId : stageIds) {
       if (!stageDto.containsKey(stageId)) {
@@ -315,20 +315,20 @@ public class CalculatedStatus {
       int total = summary.getTaskTotal();
       boolean skip = summary.isStageSkippable();
       Map<HostRoleStatus, Integer> counts = calculateStatusCounts(summary.getTaskStatuses());
-
       HostRoleStatus stageStatus = calculateSummaryStatus(counts, total, skip);
-      if (null == displayStatus) {
-        displayStatus = stageStatus;
-      }
-
-      displayStatus = calculateDisplayStatus(counts, displayStatus);
+      HostRoleStatus stageDisplayStatus = calculateSummaryDisplayStatus(counts, total, skip);
 
       stageStatuses.add(stageStatus);
+      stageDisplayStatuses.add(stageDisplayStatus);
       taskStatuses.addAll(summary.getTaskStatuses());
     }
 
     // calculate the overall status from the stage statuses
-    HostRoleStatus status = calculateSummaryStatus(calculateStatusCounts(stageStatuses),
stageStatuses.size(), false);
+    Map<HostRoleStatus, Integer> counts = calculateStatusCounts(stageStatuses);
+    Map<HostRoleStatus, Integer> displayCounts = calculateStatusCounts(stageDisplayStatuses);
+
+    HostRoleStatus status = calculateSummaryStatus(counts, stageStatuses.size(), false);
+    HostRoleStatus displayStatus = calculateSummaryDisplayStatus(displayCounts, stageDisplayStatuses.size(),
false);
 
     double progressPercent = calculateProgressPercent(calculateStatusCounts(taskStatuses),
taskStatuses.size());
 
@@ -391,19 +391,18 @@ public class CalculatedStatus {
   }
 
   /**
-   * Calculate a display status for upgrade group. Since we iterate over all
-   * tasks in all stages that belong to group, we have to pass a previous status
-   * from previous stages, so the most severe status is selected
+   * Calculate an overall display status based on the given status counts.
    *
-   * @param counters
-   *          counts of resources that are in various states
-   * @param previousStatus
-   *          previous status (from previous stages)
+   * @param counters   counts of resources that are in various states
+   * @param total      total number of resources in request
+   * @param skippable  true if a single failed status should NOT result in an overall failed
status return
    *
-   * @return display status based on statuses of tasks in different states.
+   * @return summary request status based on statuses of tasks in different states.
    */
-  private static HostRoleStatus calculateDisplayStatus(Map<HostRoleStatus, Integer>
counters, HostRoleStatus previousStatus) {
-    return previousStatus != null && previousStatus.equals(HostRoleStatus.SKIPPED_FAILED)
|| counters.get(HostRoleStatus.SKIPPED_FAILED) > 0 ? HostRoleStatus.SKIPPED_FAILED :
-           previousStatus != null && previousStatus.equals(HostRoleStatus.FAILED)
|| counters.get(HostRoleStatus.FAILED) > 0 ? HostRoleStatus.FAILED : previousStatus;
+  private static HostRoleStatus calculateSummaryDisplayStatus(Map<HostRoleStatus, Integer>
counters,
+                                                              int total, boolean skippable)
{
+    return counters.get(HostRoleStatus.SKIPPED_FAILED) > 0 ? HostRoleStatus.SKIPPED_FAILED
:
+           counters.get(HostRoleStatus.FAILED) > 0 ? HostRoleStatus.FAILED:
+           calculateSummaryStatus(counters, total, skippable);
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b9d06931/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
index 22f43c2..8d80fa6 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/CalculatedStatusTest.java
@@ -563,6 +563,59 @@ public class CalculatedStatusTest {
     assertEquals(HostRoleStatus.COMPLETED, calc.getStatus());
   }
 
+  /**
+   * Tests that upgrade group will correctly show status according to all stages.
+   *
+   * Example:
+   *
+   * If first stage have status COMPLETED and second IN_PROGRESS, overall group status should
be IN_PROGRESS
+   *
+   * @throws Exception
+   */
+  @Test
+  public void testSummaryStatus_UpgradeGroup() throws Exception {
+
+    final HostRoleCommandStatusSummaryDTO summary1 = createNiceMock(HostRoleCommandStatusSummaryDTO.class);
+    ArrayList<HostRoleStatus> taskStatuses1 = new ArrayList<HostRoleStatus>()
{{
+      add(HostRoleStatus.COMPLETED);
+      add(HostRoleStatus.COMPLETED);
+      add(HostRoleStatus.COMPLETED);
+    }};
+
+    final HostRoleCommandStatusSummaryDTO summary2 = createNiceMock(HostRoleCommandStatusSummaryDTO.class);
+    ArrayList<HostRoleStatus> taskStatuses2 = new ArrayList<HostRoleStatus>()
{{
+      add(HostRoleStatus.IN_PROGRESS);
+      add(HostRoleStatus.COMPLETED);
+      add(HostRoleStatus.COMPLETED);
+    }};
+
+    Map<Long, HostRoleCommandStatusSummaryDTO> stageDto = new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+      put(1l, summary1);
+      put(2l, summary2);
+    }};
+
+    Set<Long> stageIds = new HashSet<Long>() {{
+      add(1l);
+      add(2l);
+    }};
+
+    expect(summary1.getTaskTotal()).andReturn(taskStatuses1.size()).anyTimes();
+    expect(summary2.getTaskTotal()).andReturn(taskStatuses2.size()).anyTimes();
+
+    expect(summary1.isStageSkippable()).andReturn(true).anyTimes();
+    expect(summary2.isStageSkippable()).andReturn(true).anyTimes();
+
+    expect(summary1.getTaskStatuses()).andReturn(taskStatuses1).anyTimes();
+    expect(summary2.getTaskStatuses()).andReturn(taskStatuses2).anyTimes();
+
+    replay(summary1, summary2);
+
+    CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(stageDto, stageIds);
+
+    assertEquals(HostRoleStatus.IN_PROGRESS, calc.getDisplayStatus());
+    assertEquals(HostRoleStatus.IN_PROGRESS, calc.getStatus());
+  }
+
   private Collection<HostRoleCommandEntity> getTaskEntities(HostRoleStatus... statuses)
{
     Collection<HostRoleCommandEntity> entities = new LinkedList<HostRoleCommandEntity>();
 
@@ -639,4 +692,4 @@ public class CalculatedStatusTest {
       return hrc;
     }
   }
-}
\ No newline at end of file
+}


Mime
View raw message