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/03/12 19:43:08 UTC
ambari git commit: AMBARI-10044. Performance: Request endpoint takes
too long for large cluster (ncole)
Repository: ambari
Updated Branches:
refs/heads/trunk bdfd5d054 -> 751b31047
AMBARI-10044. Performance: Request endpoint takes too long for large cluster (ncole)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/751b3104
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/751b3104
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/751b3104
Branch: refs/heads/trunk
Commit: 751b310478dd0b8de51724e668113629de0e4c7d
Parents: bdfd5d0
Author: Nate Cole <nc...@hortonworks.com>
Authored: Thu Mar 12 12:14:53 2015 -0400
Committer: Nate Cole <nc...@hortonworks.com>
Committed: Thu Mar 12 14:36:53 2015 -0400
----------------------------------------------------------------------
.../ambari/server/actionmanager/Request.java | 78 ++--
.../controller/internal/CalculatedStatus.java | 16 +-
.../internal/RequestResourceProvider.java | 129 +++---
.../dao/HostRoleCommandStatusSummaryDTO.java | 79 ++++
.../internal/RequestResourceProviderTest.java | 388 ++++++-------------
5 files changed, 328 insertions(+), 362 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/751b3104/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
index 09633c7..ab81dfd 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/Request.java
@@ -157,7 +157,7 @@ public class Request {
this.requestId = entity.getRequestId();
this.clusterId = entity.getClusterId();
-
+
if (-1L != this.clusterId) {
try {
this.clusterName = clusters.getClusterById(this.clusterId).getClusterName();
@@ -185,31 +185,13 @@ public class Request {
Stage stage = stageFactory.createExisting(stageEntity);
stages.add(stage);
}
- Collection<RequestResourceFilterEntity> resourceFilterEntities = entity.getResourceFilterEntities();
- if (resourceFilterEntities != null) {
- this.resourceFilters = new ArrayList<RequestResourceFilter>();
- for (RequestResourceFilterEntity resourceFilterEntity : resourceFilterEntities) {
- RequestResourceFilter resourceFilter =
- new RequestResourceFilter(
- resourceFilterEntity.getServiceName(),
- resourceFilterEntity.getComponentName(),
- getHostsList(resourceFilterEntity.getHosts()));
- this.resourceFilters.add(resourceFilter);
- }
- }
- RequestOperationLevelEntity operationLevelEntity = entity.getRequestOperationLevel();
- if (operationLevelEntity != null) {
- this.operationLevel = new RequestOperationLevel(
- Resource.Type.valueOf(operationLevelEntity.getLevel()),
- operationLevelEntity.getClusterName(),
- operationLevelEntity.getServiceName(),
- operationLevelEntity.getHostComponentName(),
- operationLevelEntity.getHostName()
- );
- }
+
+ resourceFilters = filtersFromEntity(entity);
+
+ operationLevel = operationLevelFromEntity(entity);
}
- private List<String> getHostsList(String hosts) {
+ private static List<String> getHostsList(String hosts) {
List<String> hostList = new ArrayList<String>();
if (hosts != null && !hosts.isEmpty()) {
for (String host : hosts.split(",")) {
@@ -405,4 +387,52 @@ public class Request {
public void setExclusive(boolean isExclusive) {
this.exclusive = isExclusive;
}
+
+ /**
+ * @param entity the request entity
+ * @return a list of {@link RequestResourceFilter} from the entity, or {@code null}
+ * if none are defined
+ */
+ public static List<RequestResourceFilter> filtersFromEntity (RequestEntity entity) {
+ List<RequestResourceFilter> resourceFilters = null;
+
+ Collection<RequestResourceFilterEntity> resourceFilterEntities = entity.getResourceFilterEntities();
+ if (resourceFilterEntities != null) {
+ resourceFilters = new ArrayList<RequestResourceFilter>();
+ for (RequestResourceFilterEntity resourceFilterEntity : resourceFilterEntities) {
+ RequestResourceFilter resourceFilter =
+ new RequestResourceFilter(
+ resourceFilterEntity.getServiceName(),
+ resourceFilterEntity.getComponentName(),
+ getHostsList(resourceFilterEntity.getHosts()));
+ resourceFilters.add(resourceFilter);
+ }
+ }
+
+ return resourceFilters;
+ }
+
+ /**
+ * @param entity the request entity
+ * @return the {@link RequestOperationLevel} from the entity, or {@code null}
+ * if none is defined
+ */
+ public static RequestOperationLevel operationLevelFromEntity(RequestEntity entity) {
+ RequestOperationLevel level = null;
+
+ RequestOperationLevelEntity operationLevelEntity = entity.getRequestOperationLevel();
+ if (operationLevelEntity != null) {
+ level = new RequestOperationLevel(
+ Resource.Type.valueOf(operationLevelEntity.getLevel()),
+ operationLevelEntity.getClusterName(),
+ operationLevelEntity.getServiceName(),
+ operationLevelEntity.getHostComponentName(),
+ operationLevelEntity.getHostName());
+ }
+
+ return level;
+ }
+
+
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/751b3104/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 9a9bc8a..34fed41 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
@@ -22,8 +22,8 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import org.apache.ambari.server.actionmanager.HostRoleCommand;
@@ -240,7 +240,7 @@ public class CalculatedStatus {
public static Map<HostRoleStatus, Integer> calculateTaskStatusCounts(
Map<Long, HostRoleCommandStatusSummaryDTO> stageDto, Set<Long> stageIds) {
- Map<HostRoleStatus, Integer> result = new HashMap<HostRoleStatus, Integer>();
+ List<HostRoleStatus> status = new ArrayList<HostRoleStatus>();
for (Long stageId : stageIds) {
if (!stageDto.containsKey(stageId)) {
@@ -249,18 +249,10 @@ public class CalculatedStatus {
HostRoleCommandStatusSummaryDTO dto = stageDto.get(stageId);
- for (Entry<HostRoleStatus, Integer> entry : dto.getCounts().entrySet()) {
- if (!result.containsKey(entry.getKey())) {
- result.put(entry.getKey(), 0);
- }
-
- Integer old = result.get(entry.getKey());
- result.put(entry.getKey(), old + entry.getValue());
- }
-
+ status.addAll(dto.getTaskStatuses());
}
- return result;
+ return calculateStatusCounts(status);
}
/**
http://git-wip-us.apache.org/repos/asf/ambari/blob/751b3104/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
index 4671ab5..82ba160 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/RequestResourceProvider.java
@@ -17,11 +17,21 @@
*/
package org.apache.ambari.server.controller.internal;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
import org.apache.ambari.server.AmbariException;
+import org.apache.ambari.server.StaticallyInject;
import org.apache.ambari.server.actionmanager.ActionManager;
-import org.apache.ambari.server.actionmanager.HostRoleCommand;
import org.apache.ambari.server.actionmanager.HostRoleStatus;
-import org.apache.ambari.server.actionmanager.Stage;
import org.apache.ambari.server.api.services.BaseRequest;
import org.apache.ambari.server.controller.AmbariManagementController;
import org.apache.ambari.server.controller.ExecuteActionRequest;
@@ -36,25 +46,27 @@ import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.ResourceAlreadyExistsException;
import org.apache.ambari.server.controller.spi.SystemException;
import org.apache.ambari.server.controller.spi.UnsupportedPropertyException;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.dao.HostRoleCommandStatusSummaryDTO;
+import org.apache.ambari.server.orm.dao.RequestDAO;
+import org.apache.ambari.server.orm.entities.RequestEntity;
+import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import com.google.inject.Inject;
/**
* Resource provider for request resources.
*/
+@StaticallyInject
public class RequestResourceProvider extends AbstractControllerResourceProvider {
+ @Inject
+ private static RequestDAO s_requestDAO = null;
+
+ @Inject
+ private static HostRoleCommandDAO s_hostRoleCommandDAO = null;
+
// ----- Property ID constants ---------------------------------------------
// Requests
public static final String REQUEST_CLUSTER_NAME_PROPERTY_ID = "Requests/cluster_name";
@@ -371,11 +383,14 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
Set<Resource> response = new HashSet<Resource>();
ActionManager actionManager = getManagementController().getActionManager();
+ Long clusterId = null;
+
if (clusterName != null) {
Clusters clusters = getManagementController().getClusters();
//validate that cluster exists, throws exception if it doesn't.
try {
- clusters.getCluster(clusterName);
+ Cluster cluster = clusters.getCluster(clusterName);
+ clusterId = cluster.getClusterId();
} catch (AmbariException e) {
throw new NoSuchParentResourceException(e.getMessage(), e);
}
@@ -397,11 +412,11 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
ascOrder != null ? ascOrder : false);
LOG.debug("List<Long> requestIds = actionManager.getRequestsByStatus = {}", requestIds.size());
- response.addAll(getRequestResources(clusterName, actionManager, requestIds,
+ response.addAll(getRequestResources(clusterId, clusterName, requestIds,
requestedPropertyIds));
} else {
Collection<Resource> responses = getRequestResources(
- clusterName, actionManager, Collections.singletonList(requestId), requestedPropertyIds);
+ clusterId, clusterName, Collections.singletonList(requestId), requestedPropertyIds);
if (responses.isEmpty()) {
throw new NoSuchResourceException("Request resource doesn't exist.");
@@ -412,39 +427,39 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
}
// Get all of the request resources for the given set of request ids
- private Collection<Resource> getRequestResources(String clusterName,
- ActionManager actionManager,
- List<Long> requestIds,
- Set<String> requestedPropertyIds) {
-
- List<org.apache.ambari.server.actionmanager.Request> requests = actionManager.getRequests(requestIds);
- LOG.debug("requests = actionManager.getRequests(requestIds)={}", requests.size());
+ private Collection<Resource> getRequestResources(Long clusterId, String clusterName,
+ List<Long> requestIds, Set<String> requestedPropertyIds) {
Map<Long, Resource> resourceMap = new HashMap<Long, Resource>();
- for (org.apache.ambari.server.actionmanager.Request request : requests) {
- if ((null == clusterName && null == request.getClusterName()) ||
- (null != clusterName && null != request.getClusterName() && clusterName.equals(request.getClusterName())))
- resourceMap.put(request.getRequestId(), getRequestResource(request, requestedPropertyIds));
+ List<RequestEntity> requests = s_requestDAO.findByPks(requestIds);
+ for (RequestEntity re : requests) {
+ if ((null == clusterId && (null == re.getClusterId() || -1L == re.getClusterId())) ||
+ (null != clusterId && null != re.getRequestId() && re.getClusterId().equals(clusterId))) {
+ Resource r = getRequestResource(re, clusterName, requestedPropertyIds);
+ resourceMap.put(re.getRequestId(), r);
+ }
}
return resourceMap.values();
}
- private Resource getRequestResource(final org.apache.ambari.server.actionmanager.Request request,
- Set<String> requestedPropertyIds) {
+ private Resource getRequestResource(RequestEntity entity, String clusterName,
+ Set<String> requestedPropertyIds) {
Resource resource = new ResourceImpl(Resource.Type.Request);
- if (null != request.getClusterName())
- setResourceProperty(resource, REQUEST_CLUSTER_NAME_PROPERTY_ID, request.getClusterName(), requestedPropertyIds);
+ if (null != clusterName)
+ setResourceProperty(resource, REQUEST_CLUSTER_NAME_PROPERTY_ID, clusterName, requestedPropertyIds);
- setResourceProperty(resource, REQUEST_ID_PROPERTY_ID, request.getRequestId(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_CONTEXT_ID, request.getRequestContext(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_TYPE_ID, request.getRequestType(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_INPUTS_ID, request.getInputs(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_RESOURCE_FILTER_ID, request.getResourceFilters(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_ID_PROPERTY_ID, entity.getRequestId(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_CONTEXT_ID, entity.getRequestContext(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_TYPE_ID, entity.getRequestType(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_INPUTS_ID, entity.getInputs(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_RESOURCE_FILTER_ID,
+ org.apache.ambari.server.actionmanager.Request.filtersFromEntity(entity),
+ requestedPropertyIds);
- RequestOperationLevel operationLevel = request.getOperationLevel();
+ RequestOperationLevel operationLevel = org.apache.ambari.server.actionmanager.Request.operationLevelFromEntity(entity);
String opLevelStr = null;
if (operationLevel != null) {
opLevelStr = RequestOperationLevel.getExternalLevelName(
@@ -452,29 +467,31 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
}
setResourceProperty(resource, REQUEST_OPERATION_LEVEL_ID, opLevelStr, requestedPropertyIds);
- setResourceProperty(resource, REQUEST_CREATE_TIME_ID, request.getCreateTime(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_START_TIME_ID, request.getStartTime(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_END_TIME_ID, request.getEndTime(), requestedPropertyIds);
- setResourceProperty(resource, REQUEST_EXCLUSIVE_ID, request.isExclusive(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_CREATE_TIME_ID, entity.getCreateTime(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_START_TIME_ID, entity.getStartTime(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_END_TIME_ID, entity.getEndTime(), requestedPropertyIds);
+ setResourceProperty(resource, REQUEST_EXCLUSIVE_ID, entity.isExclusive(), requestedPropertyIds);
- if (request.getRequestScheduleId() != null) {
- setResourceProperty(resource, REQUEST_SOURCE_SCHEDULE_ID, request.getRequestScheduleId(), requestedPropertyIds);
+ if (entity.getRequestScheduleId() != null) {
+ setResourceProperty(resource, REQUEST_SOURCE_SCHEDULE_ID, entity.getRequestScheduleId(), requestedPropertyIds);
} else {
setResourceProperty(resource, REQUEST_SOURCE_SCHEDULE, null, requestedPropertyIds);
}
- Collection<HostRoleCommand> commands = request.getCommands();
- Collection<Stage> stages = request.getStages();
- CalculatedStatus status = CalculatedStatus.statusFromStages(stages);
+ Map<Long, HostRoleCommandStatusSummaryDTO> summary = s_hostRoleCommandDAO.findAggregateCounts(entity.getRequestId());
+ CalculatedStatus status = CalculatedStatus.statusFromStageSummary(summary, summary.keySet());
setResourceProperty(resource, REQUEST_STATUS_PROPERTY_ID, status.getStatus().toString(), requestedPropertyIds);
setResourceProperty(resource, REQUEST_PROGRESS_PERCENT_ID, status.getPercent(), requestedPropertyIds);
- int taskCount = commands.size();
+ int taskCount = 0;
+ for (HostRoleCommandStatusSummaryDTO dto : summary.values()) {
+ taskCount += dto.getTaskTotal();
+ }
- Map<HostRoleStatus, Integer> hostRoleStatusCounters =
- CalculatedStatus.calculateStatusCounts(getHostRoleStatuses(commands));
+ Map<HostRoleStatus, Integer> hostRoleStatusCounters = CalculatedStatus.calculateTaskStatusCounts(
+ summary, summary.keySet());
setResourceProperty(resource, REQUEST_TASK_CNT_ID, taskCount, requestedPropertyIds);
setResourceProperty(resource, REQUEST_FAILED_TASK_CNT_ID,
@@ -491,19 +508,5 @@ public class RequestResourceProvider extends AbstractControllerResourceProvider
return resource;
}
- /**
- * Get a collection of statuses from the given collection of tasks.
- *
- * @param tasks the tasks
- *
- * @return a collection of statuses
- */
- private static Collection<HostRoleStatus> getHostRoleStatuses(Collection<HostRoleCommand> tasks) {
- Collection<HostRoleStatus> hostRoleStatuses = new LinkedList<HostRoleStatus>();
- for (HostRoleCommand hostRoleCommand : tasks) {
- hostRoleStatuses.add(hostRoleCommand.getStatus());
- }
- return hostRoleStatuses;
- }
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/751b3104/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandStatusSummaryDTO.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandStatusSummaryDTO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandStatusSummaryDTO.java
index ef867b0..54ade92 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandStatusSummaryDTO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandStatusSummaryDTO.java
@@ -140,4 +140,83 @@ public class HostRoleCommandStatusSummaryDTO {
return m_maxTime;
}
+ /**
+ * For testing, create an empty summary.
+ */
+ public static HostRoleCommandStatusSummaryDTO create() {
+ return new HostRoleCommandStatusSummaryDTO(
+ 0L, // skippable,
+ 0L, // minStartTime,
+ 0L, // maxEndTime,
+ 0L, // stageId,
+ 0L, // aborted,
+ 0L, // completed,
+ 0L, // failed,
+ 0L, // holding,
+ 0L, // holdingFailed,
+ 0L, // holdingTimedout,
+ 0L, // inProgress,
+ 0L, // pending,
+ 0L, // queued,
+ 0L); // timedout
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#COMPLETED} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO completed(int count) {
+ put(HostRoleStatus.COMPLETED, Integer.valueOf(count));
+ return this;
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#FAILED} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO failed(int count) {
+ put(HostRoleStatus.FAILED, Integer.valueOf(count));
+ return this;
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#ABORTED} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO aborted(int count) {
+ put(HostRoleStatus.ABORTED, count);
+ return this;
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#TIMEDOUT} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO timedout(int count) {
+ put(HostRoleStatus.TIMEDOUT, count);
+ return this;
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#IN_PROGRESS} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO inProgress(int count) {
+ put(HostRoleStatus.IN_PROGRESS, count);
+ return this;
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#PENDING} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO pending(int count) {
+ put(HostRoleStatus.PENDING, count);
+ return this;
+ }
+
+ /**
+ * For testing, set the number of {@link HostRoleStatus#QUEUED} tasks
+ */
+ public HostRoleCommandStatusSummaryDTO queued(int count) {
+ put(HostRoleStatus.QUEUED, count);
+ return this;
+ }
+
+
+
}
http://git-wip-us.apache.org/repos/asf/ambari/blob/751b3104/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
index 13943f2..43151bb 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/RequestResourceProviderTest.java
@@ -27,6 +27,7 @@ import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.reset;
import static org.easymock.EasyMock.verify;
+import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -55,16 +56,42 @@ import org.apache.ambari.server.controller.spi.Resource;
import org.apache.ambari.server.controller.spi.ResourceProvider;
import org.apache.ambari.server.controller.utilities.PredicateBuilder;
import org.apache.ambari.server.controller.utilities.PropertyHelper;
+import org.apache.ambari.server.orm.dao.HostRoleCommandDAO;
+import org.apache.ambari.server.orm.dao.HostRoleCommandStatusSummaryDTO;
+import org.apache.ambari.server.orm.dao.RequestDAO;
+import org.apache.ambari.server.orm.entities.RequestEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.easymock.Capture;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
/**
* RequestResourceProvider tests.
*/
public class RequestResourceProviderTest {
+
+ private RequestDAO requestDAO;
+ private HostRoleCommandDAO hrcDAO;
+
+ @Before
+ public void before() throws Exception {
+
+ requestDAO = createNiceMock(RequestDAO.class);
+ hrcDAO = createNiceMock(HostRoleCommandDAO.class);
+
+ // !!! don't mess with injectors for this test
+ Field field = RequestResourceProvider.class.getDeclaredField("s_requestDAO");
+ field.setAccessible(true);
+ field.set(null, requestDAO);
+
+ field = RequestResourceProvider.class.getDeclaredField("s_hostRoleCommandDAO");
+ field.setAccessible(true);
+ field.set(null, hrcDAO);
+ }
+
+
@Test
public void testCreateResources() throws Exception {
Resource.Type type = Resource.Type.Request;
@@ -109,10 +136,16 @@ public class RequestResourceProviderTest {
public void testGetResourcesWithRequestInfo() throws Exception {
Resource.Type type = Resource.Type.Request;
+ expect(requestDAO.findByPks(Collections.<Long> emptyList())).andReturn(Collections.<RequestEntity>emptyList()).anyTimes();
+ replay(requestDAO);
+
ActionManager actionManager = createNiceMock(ActionManager.class);
+ Cluster cluster = createNiceMock(Cluster.class);
+ expect(cluster.getClusterId()).andReturn(1L).anyTimes();
+
Clusters clusters = createNiceMock(Clusters.class);
- expect(clusters.getCluster("foo_cluster")).andReturn(null).anyTimes();
+ expect(clusters.getCluster("foo_cluster")).andReturn(cluster).anyTimes();
AmbariManagementController managementController =
createMock(AmbariManagementController.class);
@@ -120,7 +153,7 @@ public class RequestResourceProviderTest {
.anyTimes();
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
- replay(managementController, clusters);
+ replay(managementController, clusters, cluster);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(type,
PropertyHelper.getPropertyIds(type), PropertyHelper.getKeyPropertyIds(type),
@@ -140,10 +173,7 @@ public class RequestResourceProviderTest {
request = PropertyHelper.getReadRequest(new HashSet<String>(),
requestInfoProperties, null, null, null);
- expect(actionManager.getRequests(Collections.<Long> emptyList()))
- .andReturn(Collections.<org.apache.ambari.server.actionmanager.Request> emptyList());
- expect(actionManager.getRequestsByStatus(null,
- BaseRequest.DEFAULT_PAGE_SIZE, false))
+ expect(actionManager.getRequestsByStatus(null, BaseRequest.DEFAULT_PAGE_SIZE, false))
.andReturn(Collections.<Long> emptyList());
replay(actionManager);
@@ -154,8 +184,6 @@ public class RequestResourceProviderTest {
requestInfoProperties.put(BaseRequest.PAGE_SIZE_PROPERTY_KEY, "20");
request = PropertyHelper.getReadRequest(new HashSet<String>(),
requestInfoProperties, null, null, null);
- expect(actionManager.getRequests(Collections.<Long> emptyList()))
- .andReturn(Collections.<org.apache.ambari.server.actionmanager.Request> emptyList());
expect(actionManager.getRequestsByStatus(null, 20, false))
.andReturn(Collections.<Long> emptyList());
replay(actionManager);
@@ -166,8 +194,6 @@ public class RequestResourceProviderTest {
requestInfoProperties.put(BaseRequest.ASC_ORDER_PROPERTY_KEY, "true");
request = PropertyHelper.getReadRequest(new HashSet<String>(),
requestInfoProperties, null, null, null);
- expect(actionManager.getRequests(Collections.<Long> emptyList()))
- .andReturn(Collections.<org.apache.ambari.server.actionmanager.Request> emptyList());
expect(actionManager.getRequestsByStatus(null, 20, true))
.andReturn(Collections.<Long> emptyList());
replay(actionManager);
@@ -182,34 +208,22 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
- hostRoleCommands.add(hostRoleCommand);
+ RequestEntity requestMock = createNiceMock(RequestEntity.class);
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
-
- org.apache.ambari.server.actionmanager.Request requestMock =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock.getStages()).andReturn(stages).anyTimes();
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager);
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock)).anyTimes();
- expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock)).anyTimes();
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1));
+ }}).anyTimes();
// replay
- replay(managementController, actionManager, hostRoleCommand, requestMock, stage);
+ replay(managementController, actionManager, requestDAO, hrcDAO, requestMock);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -234,7 +248,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand, stage);
+ verify(managementController, actionManager, requestDAO, hrcDAO);
}
@Test
@@ -243,35 +257,23 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
- hostRoleCommands.add(hostRoleCommand);
-
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
- org.apache.ambari.server.actionmanager.Request requestMock =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock.getStages()).andReturn(stages).anyTimes();
+ RequestEntity requestMock = createNiceMock(RequestEntity.class);
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
expect(requestMock.getRequestScheduleId()).andReturn(11L).anyTimes();
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager);
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock)).anyTimes();
- expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock)).anyTimes();
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1));
+ }}).anyTimes();
// replay
- replay(managementController, actionManager, hostRoleCommand, requestMock, stage);
+ replay(managementController, actionManager, requestDAO, hrcDAO, requestMock);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -299,7 +301,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand, stage);
+ verify(managementController, actionManager, requestDAO, hrcDAO);
}
@Test
@@ -308,35 +310,23 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
- hostRoleCommands.add(hostRoleCommand);
+ RequestEntity requestMock = createNiceMock(RequestEntity.class);
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
-
- org.apache.ambari.server.actionmanager.Request requestMock =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock.getStages()).andReturn(stages).anyTimes();
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
expect(requestMock.getRequestScheduleId()).andReturn(null).anyTimes();
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager);
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock)).anyTimes();
- expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock)).anyTimes();
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1));
+ }}).anyTimes();
// replay
- replay(managementController, actionManager, hostRoleCommand, requestMock, stage);
+ replay(managementController, actionManager, requestMock, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -364,7 +354,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand, stage);
+ verify(managementController, actionManager, requestMock, requestDAO, hrcDAO);
}
@Test
@@ -373,23 +363,14 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
Clusters clusters = createNiceMock(Clusters.class);
Cluster cluster = createNiceMock(Cluster.class);
- List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
- hostRoleCommands.add(hostRoleCommand);
-
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
+ expect(cluster.getClusterId()).andReturn(50L).anyTimes();
- org.apache.ambari.server.actionmanager.Request requestMock =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock.getStages()).andReturn(stages).anyTimes();
+ RequestEntity requestMock = createNiceMock(RequestEntity.class);
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
- expect(requestMock.getClusterName()).andReturn("c1").anyTimes();
+ expect(requestMock.getClusterId()).andReturn(50L).anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
@@ -399,14 +380,14 @@ public class RequestResourceProviderTest {
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
expect(clusters.getCluster("c1")).andReturn(cluster).anyTimes();
expect(clusters.getCluster("bad-cluster")).andThrow(new AmbariException("bad cluster!")).anyTimes();
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock));
- expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock));
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1));
+ }}).anyTimes();
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
// replay
- replay(managementController, actionManager, hostRoleCommand, clusters, cluster, requestMock, stage);
+ replay(managementController, actionManager, clusters, cluster, requestMock, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -444,7 +425,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand, clusters, cluster, stage);
+ verify(managementController, actionManager, clusters, cluster, requestMock, requestDAO, hrcDAO);
}
@Test
@@ -453,44 +434,27 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
- Stage stage2 = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
- hostRoleCommands.add(hostRoleCommand);
-
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
- stages.add(stage2);
- org.apache.ambari.server.actionmanager.Request requestMock =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock.getStages()).andReturn(stages).anyTimes();
+ RequestEntity requestMock = createNiceMock(RequestEntity.class);
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
- org.apache.ambari.server.actionmanager.Request requestMock1 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock1.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock1.getStages()).andReturn(stages).anyTimes();
+ RequestEntity requestMock1 = createNiceMock(RequestEntity.class);
expect(requestMock1.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock1.getRequestId()).andReturn(101L).anyTimes();
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(stage2.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
-
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
- expect(actionManager.getRequests(capture(requestIdsCapture))).
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).
andReturn(Arrays.asList(requestMock, requestMock1)).anyTimes();
- expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1));
+ }}).anyTimes();
// replay
- replay(managementController, actionManager, hostRoleCommand, requestMock, requestMock1, stage, stage2);
+ replay(managementController, actionManager, requestMock, requestMock1, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -515,7 +479,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand, stage, stage2);
+ verify(managementController, actionManager, requestMock, requestMock1, requestDAO, hrcDAO);
}
@Test
@@ -524,61 +488,27 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand0 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand1 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand2 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand3 = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
- Stage stage2 = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands0 = new LinkedList<HostRoleCommand>();
- hostRoleCommands0.add(hostRoleCommand0);
- hostRoleCommands0.add(hostRoleCommand1);
-
- List<HostRoleCommand> hostRoleCommands1 = new LinkedList<HostRoleCommand>();
- hostRoleCommands1.add(hostRoleCommand2);
- hostRoleCommands1.add(hostRoleCommand3);
-
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
- stages.add(stage2);
- org.apache.ambari.server.actionmanager.Request requestMock0 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock0.getCommands()).andReturn(hostRoleCommands0).anyTimes();
+ RequestEntity requestMock0 = createNiceMock(RequestEntity.class);
expect(requestMock0.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock0.getRequestId()).andReturn(100L).anyTimes();
- org.apache.ambari.server.actionmanager.Request requestMock1 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock1.getCommands()).andReturn(hostRoleCommands1).anyTimes();
+ RequestEntity requestMock1 = createNiceMock(RequestEntity.class);
expect(requestMock1.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock1.getRequestId()).andReturn(101L).anyTimes();
- expect(requestMock0.getStages()).andReturn(stages).anyTimes();
- expect(requestMock1.getStages()).andReturn(stages).anyTimes();
-
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands0).anyTimes();
- expect(stage2.getOrderedHostRoleCommands()).andReturn(hostRoleCommands1).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock0));
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock1));
- expect(hostRoleCommand0.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand1.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand2.getRequestId()).andReturn(101L).anyTimes();
- expect(hostRoleCommand3.getRequestId()).andReturn(101L).anyTimes();
- expect(hostRoleCommand0.getStatus()).andReturn(HostRoleStatus.COMPLETED).anyTimes();
- expect(hostRoleCommand1.getStatus()).andReturn(HostRoleStatus.COMPLETED).anyTimes();
- expect(hostRoleCommand2.getStatus()).andReturn(HostRoleStatus.COMPLETED).anyTimes();
- expect(hostRoleCommand3.getStatus()).andReturn(HostRoleStatus.COMPLETED).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock0));
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock1));
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().completed(2));
+ }}).anyTimes();
// replay
- replay(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3,
- requestMock0, requestMock1, stage, stage2);
+ replay(managementController, actionManager, requestMock0, requestMock1, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -613,7 +543,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3, stage, stage2);
+ verify(managementController, actionManager, requestMock0, requestMock1, requestDAO, hrcDAO);
}
@Test
@@ -622,63 +552,34 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand0 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand1 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand2 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand3 = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
- Stage stage2 = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands0 = new LinkedList<HostRoleCommand>();
- hostRoleCommands0.add(hostRoleCommand0);
- hostRoleCommands0.add(hostRoleCommand1);
-
- List<HostRoleCommand> hostRoleCommands1 = new LinkedList<HostRoleCommand>();
- hostRoleCommands1.add(hostRoleCommand2);
- hostRoleCommands1.add(hostRoleCommand3);
-
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
- Collection<Stage> stages2 = new HashSet<Stage>();
- stages2.add(stage2);
-
- org.apache.ambari.server.actionmanager.Request requestMock0 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock0.getCommands()).andReturn(hostRoleCommands0).anyTimes();
+ RequestEntity requestMock0 = createNiceMock(RequestEntity.class);
expect(requestMock0.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock0.getRequestId()).andReturn(100L).anyTimes();
- org.apache.ambari.server.actionmanager.Request requestMock1 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock1.getCommands()).andReturn(hostRoleCommands1).anyTimes();
+ RequestEntity requestMock1 = createNiceMock(RequestEntity.class);
expect(requestMock1.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock1.getRequestId()).andReturn(101L).anyTimes();
- expect(requestMock0.getStages()).andReturn(stages).anyTimes();
- expect(requestMock1.getStages()).andReturn(stages2).anyTimes();
-
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands0).anyTimes();
- expect(stage2.getOrderedHostRoleCommands()).andReturn(hostRoleCommands1).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock0));
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock1));
- expect(hostRoleCommand0.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand1.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand2.getRequestId()).andReturn(101L).anyTimes();
- expect(hostRoleCommand3.getRequestId()).andReturn(101L).anyTimes();
- expect(hostRoleCommand0.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
- expect(hostRoleCommand1.getStatus()).andReturn(HostRoleStatus.PENDING).anyTimes();
- expect(hostRoleCommand2.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
- expect(hostRoleCommand3.getStatus()).andReturn(HostRoleStatus.QUEUED).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock0));
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock1));
+
+ // IN_PROGRESS and PENDING
+ expect(hrcDAO.findAggregateCounts(100L)).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1).pending(1));
+ }}).once();
+
+ // IN_PROGRESS and QUEUED
+ expect(hrcDAO.findAggregateCounts(101L)).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1).queued(1));
+ }}).once();
// replay
- replay(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3,
- requestMock0, requestMock1, stage, stage2);
+ replay(managementController, actionManager, requestMock0, requestMock1, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -722,7 +623,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3, stage, stage2);
+ verify(managementController, actionManager, requestMock0, requestMock1, requestDAO, hrcDAO);
}
@Test
@@ -731,63 +632,35 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand0 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand1 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand2 = createNiceMock(HostRoleCommand.class);
- HostRoleCommand hostRoleCommand3 = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
- Stage stage2 = createNiceMock(Stage.class);
-
- List<HostRoleCommand> hostRoleCommands0 = new LinkedList<HostRoleCommand>();
- hostRoleCommands0.add(hostRoleCommand0);
- hostRoleCommands0.add(hostRoleCommand1);
-
- List<HostRoleCommand> hostRoleCommands1 = new LinkedList<HostRoleCommand>();
- hostRoleCommands1.add(hostRoleCommand2);
- hostRoleCommands1.add(hostRoleCommand3);
-
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
-
- Collection<Stage> stages2 = new HashSet<Stage>();
- stages2.add(stage2);
- org.apache.ambari.server.actionmanager.Request requestMock0 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock0.getCommands()).andReturn(hostRoleCommands0).anyTimes();
+ RequestEntity requestMock0 = createNiceMock(RequestEntity.class);
expect(requestMock0.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock0.getRequestId()).andReturn(100L).anyTimes();
- org.apache.ambari.server.actionmanager.Request requestMock1 =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock1.getCommands()).andReturn(hostRoleCommands1).anyTimes();
+ RequestEntity requestMock1 = createNiceMock(RequestEntity.class);
expect(requestMock1.getRequestContext()).andReturn("this is a context").anyTimes();
expect(requestMock1.getRequestId()).andReturn(101L).anyTimes();
- expect(requestMock0.getStages()).andReturn(stages).anyTimes();
- expect(requestMock1.getStages()).andReturn(stages2).anyTimes();
-
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands0).anyTimes();
- expect(stage2.getOrderedHostRoleCommands()).andReturn(hostRoleCommands1).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock0));
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock1));
- expect(hostRoleCommand0.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand1.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand2.getRequestId()).andReturn(101L).anyTimes();
- expect(hostRoleCommand3.getRequestId()).andReturn(101L).anyTimes();
- expect(hostRoleCommand0.getStatus()).andReturn(HostRoleStatus.FAILED).anyTimes();
- expect(hostRoleCommand1.getStatus()).andReturn(HostRoleStatus.COMPLETED).anyTimes();
- expect(hostRoleCommand2.getStatus()).andReturn(HostRoleStatus.ABORTED).anyTimes();
- expect(hostRoleCommand3.getStatus()).andReturn(HostRoleStatus.TIMEDOUT).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock0));
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Arrays.asList(requestMock1));
+
+ // FAILED and COMPLETED
+ expect(hrcDAO.findAggregateCounts(100L)).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().failed(1).completed(1));
+ }}).once();
+
+ // ABORTED and TIMEDOUT
+ expect(hrcDAO.findAggregateCounts(101L)).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().aborted(1).timedout(1));
+ }}).once();
+
// replay
- replay(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3,
- requestMock0, requestMock1, stage, stage2);
+ replay(managementController, actionManager, requestMock0, requestMock1, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -832,7 +705,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3, stage, stage2);
+ verify(managementController, actionManager, requestMock0, requestMock1, requestDAO, hrcDAO);
}
@Test
@@ -1263,38 +1136,27 @@ public class RequestResourceProviderTest {
AmbariManagementController managementController = createMock(AmbariManagementController.class);
ActionManager actionManager = createNiceMock(ActionManager.class);
- HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
- Stage stage = createNiceMock(Stage.class);
- Clusters clusters = createNiceMock(Clusters.class);
-
- List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
- hostRoleCommands.add(hostRoleCommand);
- Collection<Stage> stages = new HashSet<Stage>();
- stages.add(stage);
+ Clusters clusters = createNiceMock(Clusters.class);
- org.apache.ambari.server.actionmanager.Request requestMock =
- createNiceMock(org.apache.ambari.server.actionmanager.Request.class);
- expect(requestMock.getCommands()).andReturn(hostRoleCommands).anyTimes();
- expect(requestMock.getStages()).andReturn(stages).anyTimes();
+ RequestEntity requestMock = createNiceMock(RequestEntity.class);
expect(requestMock.getRequestContext()).andReturn("this is a context").anyTimes();
- expect(requestMock.getClusterName()).andReturn(null).anyTimes();
expect(requestMock.getRequestId()).andReturn(100L).anyTimes();
- expect(stage.getOrderedHostRoleCommands()).andReturn(hostRoleCommands).anyTimes();
-
Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
// set expectations
expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
expect(managementController.getClusters()).andReturn(clusters).anyTimes();
expect(clusters.getCluster(anyObject(String.class))).andReturn(null).anyTimes();
- expect(actionManager.getRequests(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock));
- expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
- expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
+ expect(requestDAO.findByPks(capture(requestIdsCapture))).andReturn(Collections.singletonList(requestMock));
+ expect(hrcDAO.findAggregateCounts((Long) anyObject())).andReturn(new HashMap<Long, HostRoleCommandStatusSummaryDTO>(){{
+ put(1L, HostRoleCommandStatusSummaryDTO.create().inProgress(1));
+ }}).anyTimes();
+
// replay
- replay(managementController, actionManager, hostRoleCommand, clusters, requestMock, stage);
+ replay(managementController, actionManager, clusters, requestMock, requestDAO, hrcDAO);
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
type,
@@ -1321,7 +1183,7 @@ public class RequestResourceProviderTest {
}
// verify
- verify(managementController, actionManager, hostRoleCommand, clusters, stage);
+ verify(managementController, actionManager, clusters, requestMock, requestDAO, hrcDAO);
}
}