|
@@ -18,6 +18,9 @@
|
|
|
|
|
|
package org.apache.ambari.server.controller.internal;
|
|
|
|
|
|
+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.controller.AmbariManagementController;
|
|
|
import org.apache.ambari.server.controller.RequestStatusResponse;
|
|
|
import org.apache.ambari.server.controller.spi.Predicate;
|
|
@@ -26,15 +29,21 @@ 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.easymock.Capture;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Test;
|
|
|
|
|
|
+import java.util.Collection;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.LinkedHashMap;
|
|
|
import java.util.LinkedHashSet;
|
|
|
+import java.util.LinkedList;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
|
|
|
+import static org.easymock.EasyMock.capture;
|
|
|
import static org.easymock.EasyMock.createMock;
|
|
|
import static org.easymock.EasyMock.createNiceMock;
|
|
|
import static org.easymock.EasyMock.expect;
|
|
@@ -90,16 +99,27 @@ public class RequestResourceProviderTest {
|
|
|
Resource.Type type = Resource.Type.Request;
|
|
|
|
|
|
AmbariManagementController managementController = createMock(AmbariManagementController.class);
|
|
|
+ ActionManager actionManager = createNiceMock(ActionManager.class);
|
|
|
+ HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
|
|
|
|
|
|
- Set<RequestStatusResponse> allResponse = new HashSet<RequestStatusResponse>();
|
|
|
- allResponse.add(new RequestStatusResponse(100L));
|
|
|
+ List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands.add(hostRoleCommand);
|
|
|
+
|
|
|
+ Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
|
|
|
+ Capture<List<Long>> requestIdListCapture = new Capture<List<Long>>();
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts = new HashMap<Long, String>();
|
|
|
+ requestContexts.put(100L, "this is a context");
|
|
|
|
|
|
// set expectations
|
|
|
- expect(managementController.getRequestStatus(AbstractResourceProviderTest.Matcher.getRequestRequest(100L))).
|
|
|
- andReturn(allResponse).once();
|
|
|
+ expect(managementController.getActionManager()).andReturn(actionManager);
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts);
|
|
|
+ expect(hostRoleCommand.getRequestId()).andReturn(100L).anyTimes();
|
|
|
+ expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS);
|
|
|
|
|
|
// replay
|
|
|
- replay(managementController);
|
|
|
+ replay(managementController, actionManager, hostRoleCommand);
|
|
|
|
|
|
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
|
|
|
type,
|
|
@@ -110,6 +130,7 @@ public class RequestResourceProviderTest {
|
|
|
Set<String> propertyIds = new HashSet<String>();
|
|
|
|
|
|
propertyIds.add(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID);
|
|
|
|
|
|
Predicate predicate = new PredicateBuilder().property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("100").
|
|
|
toPredicate();
|
|
@@ -118,12 +139,12 @@ public class RequestResourceProviderTest {
|
|
|
|
|
|
Assert.assertEquals(1, resources.size());
|
|
|
for (Resource resource : resources) {
|
|
|
- long userName = (Long) resource.getPropertyValue(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
- Assert.assertEquals(100L, userName);
|
|
|
+ Assert.assertEquals(100L, (long) (Long) resource.getPropertyValue(RequestResourceProvider.REQUEST_ID_PROPERTY_ID));
|
|
|
+ Assert.assertEquals("IN_PROGRESS", resource.getPropertyValue(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID));
|
|
|
}
|
|
|
|
|
|
// verify
|
|
|
- verify(managementController);
|
|
|
+ verify(managementController, actionManager, hostRoleCommand);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -131,21 +152,28 @@ public class RequestResourceProviderTest {
|
|
|
Resource.Type type = Resource.Type.Request;
|
|
|
|
|
|
AmbariManagementController managementController = createMock(AmbariManagementController.class);
|
|
|
+ ActionManager actionManager = createNiceMock(ActionManager.class);
|
|
|
+ HostRoleCommand hostRoleCommand = createNiceMock(HostRoleCommand.class);
|
|
|
|
|
|
- Set<RequestStatusResponse> response1 = new HashSet<RequestStatusResponse>();
|
|
|
- response1.add(new RequestStatusResponse(100L));
|
|
|
+ List<HostRoleCommand> hostRoleCommands = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands.add(hostRoleCommand);
|
|
|
|
|
|
- Set<RequestStatusResponse> response2 = new HashSet<RequestStatusResponse>();
|
|
|
- response2.add(new RequestStatusResponse(101L));
|
|
|
+ Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
|
|
|
+ Capture<List<Long>> requestIdListCapture = new Capture<List<Long>>();
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts = new HashMap<Long, String>();
|
|
|
+ requestContexts.put(100L, "this is a context");
|
|
|
|
|
|
// set expectations
|
|
|
- expect(managementController.getRequestStatus(AbstractResourceProviderTest.Matcher.getRequestRequest(100L))).
|
|
|
- andReturn(response1).once();
|
|
|
- expect(managementController.getRequestStatus(AbstractResourceProviderTest.Matcher.getRequestRequest(101L))).
|
|
|
- andReturn(response2).once();
|
|
|
+ expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands).anyTimes();
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts).anyTimes();
|
|
|
+ expect(hostRoleCommand.getRequestId()).andReturn(100L);
|
|
|
+ expect(hostRoleCommand.getRequestId()).andReturn(101L);
|
|
|
+ expect(hostRoleCommand.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
|
|
|
|
|
|
// replay
|
|
|
- replay(managementController);
|
|
|
+ replay(managementController, actionManager, hostRoleCommand);
|
|
|
|
|
|
ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
|
|
|
type,
|
|
@@ -170,7 +198,268 @@ public class RequestResourceProviderTest {
|
|
|
}
|
|
|
|
|
|
// verify
|
|
|
- verify(managementController);
|
|
|
+ verify(managementController, actionManager, hostRoleCommand);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetResourcesCompleted() throws Exception {
|
|
|
+ Resource.Type type = Resource.Type.Request;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ List<HostRoleCommand> hostRoleCommands0 = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands0.add(hostRoleCommand0);
|
|
|
+ hostRoleCommands0.add(hostRoleCommand1);
|
|
|
+
|
|
|
+ List<HostRoleCommand> hostRoleCommands1 = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands1.add(hostRoleCommand2);
|
|
|
+ hostRoleCommands1.add(hostRoleCommand3);
|
|
|
+
|
|
|
+ Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
|
|
|
+ Capture<List<Long>> requestIdListCapture = new Capture<List<Long>>();
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts0 = new HashMap<Long, String>();
|
|
|
+ requestContexts0.put(100L, "this is a context");
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts1 = new HashMap<Long, String>();
|
|
|
+ requestContexts1.put(101L, "this is a context");
|
|
|
+
|
|
|
+ // set expectations
|
|
|
+ expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands0);
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands1);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts0);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts1);
|
|
|
+ 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();
|
|
|
+
|
|
|
+ // replay
|
|
|
+ replay(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3);
|
|
|
+
|
|
|
+ ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
|
|
|
+ type,
|
|
|
+ PropertyHelper.getPropertyIds(type),
|
|
|
+ PropertyHelper.getKeyPropertyIds(type),
|
|
|
+ managementController);
|
|
|
+
|
|
|
+ Set<String> propertyIds = new HashSet<String>();
|
|
|
+
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID);
|
|
|
+
|
|
|
+ Predicate predicate = new PredicateBuilder().property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("100").or().
|
|
|
+ property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("101").toPredicate();
|
|
|
+ Request request = PropertyHelper.getReadRequest(propertyIds);
|
|
|
+ Set<Resource> resources = provider.getResources(request, predicate);
|
|
|
+
|
|
|
+ Assert.assertEquals(2, resources.size());
|
|
|
+ for (Resource resource : resources) {
|
|
|
+ long id = (Long) resource.getPropertyValue(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ Assert.assertTrue(id == 100L || id == 101L);
|
|
|
+ Assert.assertEquals("COMPLETED", resource.getPropertyValue(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID));
|
|
|
+ Assert.assertEquals(2, resource.getPropertyValue(RequestResourceProvider.REQUEST_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(0, resource.getPropertyValue(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(2, resource.getPropertyValue(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID));
|
|
|
+
|
|
|
+ Assert.assertEquals(100.0, resource.getPropertyValue(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID));
|
|
|
+ }
|
|
|
+
|
|
|
+ // verify
|
|
|
+ verify(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetResourcesInProgress() throws Exception {
|
|
|
+ Resource.Type type = Resource.Type.Request;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ List<HostRoleCommand> hostRoleCommands0 = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands0.add(hostRoleCommand0);
|
|
|
+ hostRoleCommands0.add(hostRoleCommand1);
|
|
|
+
|
|
|
+ List<HostRoleCommand> hostRoleCommands1 = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands1.add(hostRoleCommand2);
|
|
|
+ hostRoleCommands1.add(hostRoleCommand3);
|
|
|
+
|
|
|
+ Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
|
|
|
+ Capture<List<Long>> requestIdListCapture = new Capture<List<Long>>();
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts0 = new HashMap<Long, String>();
|
|
|
+ requestContexts0.put(100L, "this is a context");
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts1 = new HashMap<Long, String>();
|
|
|
+ requestContexts1.put(101L, "this is a context");
|
|
|
+
|
|
|
+ // set expectations
|
|
|
+ expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands0);
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands1);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts0);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts1);
|
|
|
+ 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.COMPLETED).anyTimes();
|
|
|
+ expect(hostRoleCommand2.getStatus()).andReturn(HostRoleStatus.IN_PROGRESS).anyTimes();
|
|
|
+ expect(hostRoleCommand3.getStatus()).andReturn(HostRoleStatus.QUEUED).anyTimes();
|
|
|
+
|
|
|
+ // replay
|
|
|
+ replay(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3);
|
|
|
+
|
|
|
+ ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
|
|
|
+ type,
|
|
|
+ PropertyHelper.getPropertyIds(type),
|
|
|
+ PropertyHelper.getKeyPropertyIds(type),
|
|
|
+ managementController);
|
|
|
+
|
|
|
+ Set<String> propertyIds = new HashSet<String>();
|
|
|
+
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID);
|
|
|
+
|
|
|
+ Predicate predicate = new PredicateBuilder().property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("100").or().
|
|
|
+ property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("101").toPredicate();
|
|
|
+ Request request = PropertyHelper.getReadRequest(propertyIds);
|
|
|
+ Set<Resource> resources = provider.getResources(request, predicate);
|
|
|
+
|
|
|
+ Assert.assertEquals(2, resources.size());
|
|
|
+ for (Resource resource : resources) {
|
|
|
+ long id = (Long) resource.getPropertyValue(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ Assert.assertTrue(id == 100L || id == 101L);
|
|
|
+ Assert.assertEquals("IN_PROGRESS", resource.getPropertyValue(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID));
|
|
|
+ Assert.assertEquals(2, resource.getPropertyValue(RequestResourceProvider.REQUEST_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(0, resource.getPropertyValue(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID));
|
|
|
+
|
|
|
+ if (id == 100L) {
|
|
|
+ Assert.assertEquals(1, resource.getPropertyValue(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(85.0, resource.getPropertyValue(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID));
|
|
|
+ } else {
|
|
|
+ Assert.assertEquals(0, resource.getPropertyValue(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(43.99999999999999, resource.getPropertyValue(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // verify
|
|
|
+ verify(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testGetResourcesFailed() throws Exception {
|
|
|
+ Resource.Type type = Resource.Type.Request;
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ List<HostRoleCommand> hostRoleCommands0 = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands0.add(hostRoleCommand0);
|
|
|
+ hostRoleCommands0.add(hostRoleCommand1);
|
|
|
+
|
|
|
+ List<HostRoleCommand> hostRoleCommands1 = new LinkedList<HostRoleCommand>();
|
|
|
+ hostRoleCommands1.add(hostRoleCommand2);
|
|
|
+ hostRoleCommands1.add(hostRoleCommand3);
|
|
|
+
|
|
|
+ Capture<Collection<Long>> requestIdsCapture = new Capture<Collection<Long>>();
|
|
|
+ Capture<List<Long>> requestIdListCapture = new Capture<List<Long>>();
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts0 = new HashMap<Long, String>();
|
|
|
+ requestContexts0.put(100L, "this is a context");
|
|
|
+
|
|
|
+ Map<Long, String> requestContexts1 = new HashMap<Long, String>();
|
|
|
+ requestContexts1.put(101L, "this is a context");
|
|
|
+
|
|
|
+ // set expectations
|
|
|
+ expect(managementController.getActionManager()).andReturn(actionManager).anyTimes();
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands0);
|
|
|
+ expect(actionManager.getAllTasksByRequestIds(capture(requestIdsCapture))).andReturn(hostRoleCommands1);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts0);
|
|
|
+ expect(actionManager.getRequestContext(capture(requestIdListCapture))).andReturn(requestContexts1);
|
|
|
+ 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();
|
|
|
+
|
|
|
+ // replay
|
|
|
+ replay(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3);
|
|
|
+
|
|
|
+ ResourceProvider provider = AbstractControllerResourceProvider.getResourceProvider(
|
|
|
+ type,
|
|
|
+ PropertyHelper.getPropertyIds(type),
|
|
|
+ PropertyHelper.getKeyPropertyIds(type),
|
|
|
+ managementController);
|
|
|
+
|
|
|
+ Set<String> propertyIds = new HashSet<String>();
|
|
|
+
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_ABORTED_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_TIMED_OUT_TASK_CNT_ID);
|
|
|
+ propertyIds.add(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID);
|
|
|
+
|
|
|
+ Predicate predicate = new PredicateBuilder().property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("100").or().
|
|
|
+ property(RequestResourceProvider.REQUEST_ID_PROPERTY_ID).equals("101").toPredicate();
|
|
|
+ Request request = PropertyHelper.getReadRequest(propertyIds);
|
|
|
+ Set<Resource> resources = provider.getResources(request, predicate);
|
|
|
+
|
|
|
+ Assert.assertEquals(2, resources.size());
|
|
|
+ for (Resource resource : resources) {
|
|
|
+ long id = (Long) resource.getPropertyValue(RequestResourceProvider.REQUEST_ID_PROPERTY_ID);
|
|
|
+ Assert.assertTrue(id == 100L || id == 101L);
|
|
|
+ Assert.assertEquals(2, resource.getPropertyValue(RequestResourceProvider.REQUEST_TASK_CNT_ID));
|
|
|
+ if (id == 100L) {
|
|
|
+ Assert.assertEquals("FAILED", resource.getPropertyValue(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID));
|
|
|
+ Assert.assertEquals(1, resource.getPropertyValue(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(0, resource.getPropertyValue(RequestResourceProvider.REQUEST_ABORTED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(0, resource.getPropertyValue(RequestResourceProvider.REQUEST_TIMED_OUT_TASK_CNT_ID));
|
|
|
+ } else {
|
|
|
+ Assert.assertEquals("ABORTED", resource.getPropertyValue(RequestResourceProvider.REQUEST_STATUS_PROPERTY_ID));
|
|
|
+ Assert.assertEquals(0, resource.getPropertyValue(RequestResourceProvider.REQUEST_FAILED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(1, resource.getPropertyValue(RequestResourceProvider.REQUEST_ABORTED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(1, resource.getPropertyValue(RequestResourceProvider.REQUEST_TIMED_OUT_TASK_CNT_ID));
|
|
|
+ }
|
|
|
+ Assert.assertEquals(2, resource.getPropertyValue(RequestResourceProvider.REQUEST_COMPLETED_TASK_CNT_ID));
|
|
|
+ Assert.assertEquals(100.0, resource.getPropertyValue(RequestResourceProvider.REQUEST_PROGRESS_PERCENT_ID));
|
|
|
+ }
|
|
|
+
|
|
|
+ // verify
|
|
|
+ verify(managementController, actionManager, hostRoleCommand0, hostRoleCommand1, hostRoleCommand2, hostRoleCommand3);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -236,4 +525,21 @@ public class RequestResourceProviderTest {
|
|
|
// verify
|
|
|
verify(managementController);
|
|
|
}
|
|
|
+
|
|
|
+// public static RequestResourceProvider getServiceProvider(AmbariManagementController managementController) {
|
|
|
+// Resource.Type type = Resource.Type.Request;
|
|
|
+//
|
|
|
+// return (RequestResourceProvider) AbstractControllerResourceProvider.getResourceProvider(
|
|
|
+// type,
|
|
|
+// PropertyHelper.getPropertyIds(type),
|
|
|
+// PropertyHelper.getKeyPropertyIds(type),
|
|
|
+// managementController);
|
|
|
+// }
|
|
|
+//
|
|
|
+// public static Set<RequestStatusResponse> getRequestStatus(
|
|
|
+// AmbariManagementController controller, RequestStatusRequest request)
|
|
|
+// throws AmbariException {
|
|
|
+// RequestResourceProvider provider = getServiceProvider(controller);
|
|
|
+// return provider.getRequestStatus(request);
|
|
|
+// }
|
|
|
}
|