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 2015/12/23 16:07:19 UTC
[40/51] [abbrv] ambari git commit: AMBARI-14471 - Expose UpgradeItem
Display Status In API Requests (jonathanhurley)
AMBARI-14471 - Expose UpgradeItem Display Status In API Requests (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c947fcdf
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c947fcdf
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c947fcdf
Branch: refs/heads/branch-dev-patch-upgrade
Commit: c947fcdf93ec4da8be0654b85fb1ddb467fc239b
Parents: 1ed72b8
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Tue Dec 22 11:27:04 2015 -0500
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Tue Dec 22 17:00:42 2015 -0500
----------------------------------------------------------------------
.../controller/internal/CalculatedStatus.java | 25 ++++----
.../internal/StageResourceProvider.java | 8 ++-
.../internal/UpgradeItemResourceProvider.java | 1 +
.../internal/StageResourceProviderTest.java | 64 +++++++++++++++++++-
4 files changed, 82 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/c947fcdf/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 0a2a414..a722bc1 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
@@ -315,12 +315,15 @@ public class CalculatedStatus {
int total = summary.getTaskTotal();
boolean skip = summary.isStageSkippable();
Map<HostRoleStatus, Integer> counts = calculateStatusCounts(summary.getTaskStatuses());
- displayStatus = calculateDisplayStatus(counts, displayStatus);
HostRoleStatus stageStatus = calculateSummaryStatus(counts, total, skip);
+ if (null == displayStatus) {
+ displayStatus = stageStatus;
+ }
- stageStatuses.add(stageStatus);
+ displayStatus = calculateDisplayStatus(counts, displayStatus);
+ stageStatuses.add(stageStatus);
taskStatuses.addAll(summary.getTaskStatuses());
}
@@ -388,19 +391,19 @@ 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 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
*
- * @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 previousStatus
+ * previous status (from previous stages)
*
- * @return display status based on statuses of tasks in different states. May be SKIPPED_FAILED, FAILED
- * or null if there is no failures at all
+ * @return display 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 :
- null;
+ previousStatus != null && previousStatus.equals(HostRoleStatus.FAILED) || counters.get(HostRoleStatus.FAILED) > 0 ? HostRoleStatus.FAILED : previousStatus;
}
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c947fcdf/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
index 492ac34..8ebcd7b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StageResourceProvider.java
@@ -90,6 +90,7 @@ public class StageResourceProvider extends AbstractControllerResourceProvider im
public static final String STAGE_SKIPPABLE = "Stage/skippable";
public static final String STAGE_PROGRESS_PERCENT = "Stage/progress_percent";
public static final String STAGE_STATUS = "Stage/status";
+ public static final String STAGE_DISPLAY_STATUS = "Stage/display_status";
public static final String STAGE_START_TIME = "Stage/start_time";
public static final String STAGE_END_TIME = "Stage/end_time";
@@ -117,6 +118,7 @@ public class StageResourceProvider extends AbstractControllerResourceProvider im
PROPERTY_IDS.add(STAGE_SKIPPABLE);
PROPERTY_IDS.add(STAGE_PROGRESS_PERCENT);
PROPERTY_IDS.add(STAGE_STATUS);
+ PROPERTY_IDS.add(STAGE_DISPLAY_STATUS);
PROPERTY_IDS.add(STAGE_START_TIME);
PROPERTY_IDS.add(STAGE_END_TIME);
@@ -303,7 +305,8 @@ public class StageResourceProvider extends AbstractControllerResourceProvider im
}
setResourceProperty(resource, STAGE_PROGRESS_PERCENT, status.getPercent(), requestedIds);
- setResourceProperty(resource, STAGE_STATUS, status.getStatus().toString(), requestedIds);
+ setResourceProperty(resource, STAGE_STATUS, status.getStatus(), requestedIds);
+ setResourceProperty(resource, STAGE_DISPLAY_STATUS, status.getDisplayStatus(), requestedIds);
return resource;
}
@@ -370,7 +373,8 @@ public class StageResourceProvider extends AbstractControllerResourceProvider im
CalculatedStatus status = CalculatedStatus.statusFromStageSummary(summary, Collections.singleton(entity.getStageId()));
setResourceProperty(resource, STAGE_PROGRESS_PERCENT, status.getPercent(), requestedIds);
- setResourceProperty(resource, STAGE_STATUS, status.getStatus().toString(), requestedIds);
+ setResourceProperty(resource, STAGE_STATUS, status.getStatus(), requestedIds);
+ setResourceProperty(resource, STAGE_DISPLAY_STATUS, status.getDisplayStatus(), requestedIds);
return resource;
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c947fcdf/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
index 48b040e..a45b1ac 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/UpgradeItemResourceProvider.java
@@ -93,6 +93,7 @@ public class UpgradeItemResourceProvider extends ReadOnlyResourceProvider {
for (String p : StageResourceProvider.PROPERTY_IDS) {
STAGE_MAPPED_IDS.put(p, p.replace("Stage/", "UpgradeItem/"));
}
+
PROPERTY_IDS.addAll(STAGE_MAPPED_IDS.values());
// keys
http://git-wip-us.apache.org/repos/asf/ambari/blob/c947fcdf/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StageResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StageResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StageResourceProviderTest.java
index 58454e9..435587d 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StageResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/StageResourceProviderTest.java
@@ -25,6 +25,7 @@ import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.junit.Assert.fail;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -52,6 +53,7 @@ import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
import org.apache.ambari.server.orm.entities.StageEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.topology.TopologyManager;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Before;
@@ -72,6 +74,7 @@ public class StageResourceProviderTest {
private AmbariManagementController managementController = null;
private Injector injector;
private HostRoleCommandDAO hrcDao = null;
+ private TopologyManager topologyManager = null;
@Before
public void before() {
@@ -79,6 +82,9 @@ public class StageResourceProviderTest {
clusters = createStrictMock(Clusters.class);
cluster = createStrictMock(Cluster.class);
hrcDao = createStrictMock(HostRoleCommandDAO.class);
+ topologyManager = EasyMock.createNiceMock(TopologyManager.class);
+
+ expect(topologyManager.getStages()).andReturn(new ArrayList<StageEntity>()).anyTimes();
expect(hrcDao.findAggregateCounts(EasyMock.anyObject(Long.class))).andReturn(
new HashMap<Long, HostRoleCommandStatusSummaryDTO>() {
@@ -88,7 +94,7 @@ public class StageResourceProviderTest {
}
}).anyTimes();
- replay(hrcDao);
+ replay(hrcDao, topologyManager);
managementController = createNiceMock(AmbariManagementController.class);
@@ -144,7 +150,6 @@ public class StageResourceProviderTest {
}
@Test
- @Ignore
public void testGetResources() throws Exception {
StageResourceProvider provider = new StageResourceProvider(managementController);
@@ -167,14 +172,66 @@ public class StageResourceProviderTest {
Resource resource = resources.iterator().next();
Assert.assertEquals(100.0, resource.getPropertyValue(StageResourceProvider.STAGE_PROGRESS_PERCENT));
- Assert.assertEquals("COMPLETED", resource.getPropertyValue(StageResourceProvider.STAGE_STATUS));
+ Assert.assertEquals(HostRoleStatus.COMPLETED, resource.getPropertyValue(StageResourceProvider.STAGE_STATUS));
+ Assert.assertEquals(HostRoleStatus.COMPLETED, resource.getPropertyValue(StageResourceProvider.STAGE_DISPLAY_STATUS));
Assert.assertEquals(1000L, resource.getPropertyValue(StageResourceProvider.STAGE_START_TIME));
Assert.assertEquals(2500L, resource.getPropertyValue(StageResourceProvider.STAGE_END_TIME));
verify(dao, clusters, cluster);
+ }
+
+ /**
+ * Tests getting the display status of a stage which can differ from the final
+ * status.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testGetDisplayStatus() throws Exception {
+ // clear the HRC call so that it has the correct summary fields to represent
+ // 1 skipped and 1 completed task
+ EasyMock.reset(hrcDao);
+ expect(hrcDao.findAggregateCounts(EasyMock.anyObject(Long.class))).andReturn(
+ new HashMap<Long, HostRoleCommandStatusSummaryDTO>() {
+ {
+ put(0L, new HostRoleCommandStatusSummaryDTO(0, 1000L, 2500L, 0, 0, 1, 0, 0, 0, 0, 0, 0,
+ 0, 0, 1));
+ }
+ }).anyTimes();
+
+ replay(hrcDao);
+
+ StageResourceProvider provider = new StageResourceProvider(managementController);
+
+ Request request = createNiceMock(Request.class);
+ Predicate predicate = createNiceMock(Predicate.class);
+
+ // make the stage skippable so it resolves to COMPLETED even though it has a
+ // skipped failure
+ List<StageEntity> entities = getStageEntities(HostRoleStatus.SKIPPED_FAILED);
+ entities.get(0).setSkippable(true);
+
+ expect(dao.findAll(request, predicate)).andReturn(entities);
+
+ expect(clusters.getClusterById(anyLong())).andReturn(cluster).anyTimes();
+ expect(cluster.getClusterName()).andReturn("c1").anyTimes();
+
+ replay(dao, clusters, cluster, request, predicate);
+ Set<Resource> resources = provider.getResources(request, predicate);
+
+ Assert.assertEquals(1, resources.size());
+
+ Resource resource = resources.iterator().next();
+
+ // verify the two statuses
+ Assert.assertEquals(HostRoleStatus.COMPLETED, resource.getPropertyValue(StageResourceProvider.STAGE_STATUS));
+ Assert.assertEquals(HostRoleStatus.SKIPPED_FAILED, resource.getPropertyValue(StageResourceProvider.STAGE_DISPLAY_STATUS));
+
+ verify(dao, clusters, cluster);
}
+
@Test
@Ignore
public void testQueryForResources() throws Exception {
@@ -267,6 +324,7 @@ public class StageResourceProviderTest {
binder.bind(HostRoleCommandDAO.class).toInstance(hrcDao);
binder.bind(AmbariManagementController.class).toInstance(managementController);
binder.bind(ActionMetadata.class);
+ binder.bind(TopologyManager.class).toInstance(topologyManager);
}
}
}
\ No newline at end of file