You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2017/10/05 16:01:23 UTC
ambari git commit: AMBARI-22144. Hitting pause during upgrade jumps
progress to 100% (ncole)
Repository: ambari
Updated Branches:
refs/heads/branch-2.6 f1eaa6502 -> 34eb22abd
AMBARI-22144. Hitting pause during upgrade jumps progress to 100% (ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/34eb22ab
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/34eb22ab
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/34eb22ab
Branch: refs/heads/branch-2.6
Commit: 34eb22abdf9949120f699718123426d9982990b6
Parents: f1eaa65
Author: Nate Cole <nc...@hortonworks.com>
Authored: Thu Oct 5 08:59:23 2017 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Thu Oct 5 11:25:30 2017 -0400
----------------------------------------------------------------------
.../internal/UpgradeResourceProvider.java | 72 +++++++++++++++++++-
.../internal/UpgradeResourceProviderTest.java | 33 ++++++++-
2 files changed, 102 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/34eb22ab/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
index a28fb02..8ce6454 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeResourceProvider.java
@@ -197,7 +197,7 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
private static final String REQUEST_END_TIME_ID = "Upgrade/end_time";
private static final String REQUEST_EXCLUSIVE_ID = "Upgrade/exclusive";
- private static final String REQUEST_PROGRESS_PERCENT_ID = "Upgrade/progress_percent";
+ protected static final String REQUEST_PROGRESS_PERCENT_ID = "Upgrade/progress_percent";
private static final String REQUEST_STATUS_PROPERTY_ID = "Upgrade/request_status";
private static final Set<String> PK_PROPERTY_IDS = new HashSet<>(
@@ -415,14 +415,82 @@ public class UpgradeResourceProvider extends AbstractControllerResourceProvider
CalculatedStatus calc = CalculatedStatus.statusFromStageSummary(summary, summary.keySet());
+ if (calc.getStatus() == HostRoleStatus.ABORTED && entity.isSuspended()) {
+ double percent = calculateAbortedProgress(summary);
+ setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, percent*100, requestPropertyIds);
+ } else {
+ setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds);
+ }
+
setResourceProperty(r, REQUEST_STATUS_PROPERTY_ID, calc.getStatus(), requestPropertyIds);
- setResourceProperty(r, REQUEST_PROGRESS_PERCENT_ID, calc.getPercent(), requestPropertyIds);
}
}
return results;
}
+ /**
+ * Unlike in CalculatedStatus, we can't use ABORTED here as a COMPLETED state.
+ * Therefore, the values will be slightly off since in CalulatedStatus, ABORTED
+ * contributes all of its progress to the overall progress, but here it
+ * contributes none of it.
+ *
+ * Since this is specifically for ABORTED upgrades that are
+ * also suspended, the percentages should come out pretty close after ABORTED move back
+ * to PENDING.
+ *
+ * @return the percent complete, counting ABORTED as zero percent.
+ */
+ private double calculateAbortedProgress(Map<Long, HostRoleCommandStatusSummaryDTO> summary) {
+ // !!! use the raw states to determine percent completes
+ Map<HostRoleStatus, Integer> countTotals = new HashMap<>();
+ int totalTasks = 0;
+
+
+ for (HostRoleCommandStatusSummaryDTO statusSummary : summary.values()) {
+ totalTasks += statusSummary.getTaskTotal();
+ for (Map.Entry<HostRoleStatus, Integer> entry : statusSummary.getCounts().entrySet()) {
+ if (!countTotals.containsKey(entry.getKey())) {
+ countTotals.put(entry.getKey(), Integer.valueOf(0));
+ }
+ countTotals.put(entry.getKey(), countTotals.get(entry.getKey()) + entry.getValue());
+ }
+ }
+
+ double percent = 0d;
+
+ for (HostRoleStatus status : HostRoleStatus.values()) {
+ if (!countTotals.containsKey(status)) {
+ countTotals.put(status, Integer.valueOf(0));
+ }
+ double countValue = (double) countTotals.get(status);
+
+ // !!! calculation lifted from CalculatedStatus
+ switch (status) {
+ case ABORTED:
+ // !!! see javadoc
+ break;
+ case HOLDING:
+ case HOLDING_FAILED:
+ case HOLDING_TIMEDOUT:
+ case IN_PROGRESS:
+ case PENDING: // shouldn't be any, we're supposed to be ABORTED
+ percent += countValue * 0.35d;
+ break;
+ case QUEUED:
+ percent += countValue * 0.09d;
+ break;
+ default:
+ if (status.isCompletedState()) {
+ percent += countValue / (double) totalTasks;
+ }
+ break;
+ }
+ }
+
+ return percent;
+ }
+
@Override
public RequestStatus updateResources(final Request request, Predicate predicate)
throws SystemException, UnsupportedPropertyException, NoSuchResourceException,
http://git-wip-us.apache.org/repos/asf/ambari/blob/34eb22ab/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 7b93078..d789ab4 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
@@ -871,9 +871,40 @@ public class UpgradeResourceProviderTest extends EasyMockSupport {
UpgradeResourceProvider urp = createProvider(amc);
- // !!! make sure we can. actual abort is tested elsewhere
Request req = PropertyHelper.getUpdateRequest(requestProps, null);
urp.updateResources(req, null);
+
+ List<HostRoleCommandEntity> commands = hrcDAO.findByRequest(id);
+
+ int i = 0;
+ for (HostRoleCommandEntity command : commands) {
+ if (i < 3) {
+ command.setStatus(HostRoleStatus.COMPLETED);
+ } else {
+ command.setStatus(HostRoleStatus.ABORTED);
+ }
+ hrcDAO.merge(command);
+ i++;
+ }
+
+ req = PropertyHelper.getReadRequest(
+ UpgradeResourceProvider.UPGRADE_CLUSTER_NAME,
+ UpgradeResourceProvider.UPGRADE_ID,
+ UpgradeResourceProvider.REQUEST_PROGRESS_PERCENT_ID);
+
+ Predicate pred = new PredicateBuilder()
+ .property(UpgradeResourceProvider.UPGRADE_REQUEST_ID).equals(id.toString())
+ .and()
+ .property(UpgradeResourceProvider.UPGRADE_CLUSTER_NAME).equals("c1")
+ .toPredicate();
+
+ Set<Resource> resources = urp.getResources(req, pred);
+ assertEquals(1, resources.size());
+ res = resources.iterator().next();
+
+ Double value = (Double) res.getPropertyValue(UpgradeResourceProvider.REQUEST_PROGRESS_PERCENT_ID);
+
+ assertEquals(37.5d, value, 0.1d);
}