Author: smohanty
Date: Tue May 7 18:09:31 2013
New Revision: 1479997
URL: http://svn.apache.org/r1479997
Log:
AMBARI-2087. Tasks are not filtered by parent request id. (smohanty)
Modified:
incubator/ambari/trunk/CHANGES.txt
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Modified: incubator/ambari/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1479997&r1=1479996&r2=1479997&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Tue May 7 18:09:31 2013
@@ -830,6 +830,8 @@ Trunk (unreleased changes):
BUG FIXES
+ AMBARI-2087. Tasks are not filtered by parent request id. (smohanty)
+
AMBARI-2086. Agent on host with clients and DATANODE only seems to schedule
STATUS commands for several other services. (swagle)
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java?rev=1479997&r1=1479996&r2=1479997&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
Tue May 7 18:09:31 2013
@@ -3713,7 +3713,8 @@ public class AmbariManagementControllerI
for (TaskStatusRequest request : requests) {
if (request.getTaskId() != null) {
taskIds.add(request.getTaskId());
- } else {
+ }
+ if (request.getRequestId() != null) {
requestIds.add(request.getRequestId());
}
}
@@ -3723,6 +3724,10 @@ public class AmbariManagementControllerI
responses.add(new TaskStatusResponse(command));
}
+ if (responses.size() == 0) {
+ throw new ObjectNotFoundException("Task resource doesn't exist.");
+ }
+
return responses;
}
Modified:
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java?rev=1479997&r1=1479996&r2=1479997&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
Tue May 7 18:09:31 2013
@@ -73,7 +73,7 @@ public class HostRoleCommandDAO {
public List<HostRoleCommandEntity> findByRequestAndTaskIds(Collection<Long>
requestIds, Collection<Long> taskIds) {
TypedQuery<HostRoleCommandEntity> query =
entityManagerProvider.get().createQuery(
"SELECT DISTINCT task FROM HostRoleCommandEntity task " +
- "WHERE task.requestId IN ?1 OR task.taskId IN ?2 " +
+ "WHERE task.requestId IN ?1 AND task.taskId IN ?2 " +
"ORDER BY task.taskId", HostRoleCommandEntity.class
);
return daoUtils.selectList(query, requestIds, taskIds);
Modified:
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
URL:
http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java?rev=1479997&r1=1479996&r2=1479997&view=diff
==============================================================================
---
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
(original)
+++
incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Tue May 7 18:09:31 2013
@@ -36,6 +36,7 @@ import org.apache.ambari.server.AmbariEx
import org.apache.ambari.server.ClusterNotFoundException;
import org.apache.ambari.server.DuplicateResourceException;
import org.apache.ambari.server.ParentObjectNotFoundException;
+import org.apache.ambari.server.ObjectNotFoundException;
import org.apache.ambari.server.Role;
import org.apache.ambari.server.RoleCommand;
import org.apache.ambari.server.StackAccessException;
@@ -74,7 +75,9 @@ import org.apache.ambari.server.state.sv
import org.apache.ambari.server.utils.StageUtils;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.inject.Guice;
@@ -119,6 +122,9 @@ public class AmbariManagementControllerT
private Users users;
private EntityManager entityManager;
+ @Rule
+ public ExpectedException expectedException = ExpectedException.none();
+
@Before
public void setup() throws Exception {
injector = Guice.createInjector(new InMemoryDefaultTestModule());
@@ -6042,4 +6048,128 @@ public class AmbariManagementControllerT
}
}
+ @Test
+ public void testGetTasksByRequestId() throws AmbariException {
+ final long requestId1 = 1;
+ final long requestId2 = 2;
+ final String clusterName = "c1";
+ final String hostName1 = "h1";
+ final String context = "Test invocation";
+
+ clusters.addCluster(clusterName);
+ clusters.getCluster(clusterName).setDesiredStackVersion(new
StackId("HDP-0.1"));
+ clusters.addHost(hostName1);
+ clusters.getHost("h1").setOsType("centos5");
+ clusters.getHost(hostName1).persist();
+
+ clusters.mapHostsToCluster(new HashSet<String>(){
+ {add(hostName1);}}, clusterName);
+
+
+ List<Stage> stages = new ArrayList<Stage>();
+ stages.add(new Stage(requestId1, "/a1", clusterName, context));
+ stages.get(0).setStageId(1);
+ stages.get(0).addHostRoleExecutionCommand(hostName1, Role.HBASE_MASTER,
+ RoleCommand.START,
+ new ServiceComponentHostStartEvent(Role.HBASE_MASTER.toString(),
+ hostName1, System.currentTimeMillis(),
+ new HashMap<String, String>()),
+ clusterName, "HBASE");
+
+ stages.add(new Stage(requestId1, "/a2", clusterName, context));
+ stages.get(1).setStageId(2);
+ stages.get(1).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT,
+ RoleCommand.START,
+ new ServiceComponentHostStartEvent(Role.HBASE_CLIENT.toString(),
+ hostName1, System.currentTimeMillis(),
+ new HashMap<String, String>()), clusterName, "HBASE");
+
+ stages.add(new Stage(requestId1, "/a3", clusterName, context));
+ stages.get(2).setStageId(3);
+ stages.get(2).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT,
+ RoleCommand.START,
+ new ServiceComponentHostStartEvent(Role.HBASE_CLIENT.toString(),
+ hostName1, System.currentTimeMillis(),
+ new HashMap<String, String>()), clusterName, "HBASE");
+
+
+ stages.add(new Stage(requestId2, "/a4", clusterName, context));
+ stages.get(3).setStageId(4);
+ stages.get(3).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT,
+ RoleCommand.START,
+ new ServiceComponentHostStartEvent(Role.HBASE_CLIENT.toString(),
+ hostName1, System.currentTimeMillis(),
+ new HashMap<String, String>()), clusterName, "HBASE");
+
+ stages.add(new Stage(requestId2, "/a5", clusterName, context));
+ stages.get(4).setStageId(5);
+ stages.get(4).addHostRoleExecutionCommand(hostName1, Role.HBASE_CLIENT,
+ RoleCommand.START,
+ new ServiceComponentHostStartEvent(Role.HBASE_CLIENT.toString(),
+ hostName1, System.currentTimeMillis(),
+ new HashMap<String, String>()), clusterName, "HBASE");
+
+ actionDB.persistActions(stages);
+
+ Set<TaskStatusRequest> taskStatusRequests;
+ Set<TaskStatusResponse> taskStatusResponses;
+
+ //check count of tasks by requestId1
+ taskStatusRequests = new HashSet<TaskStatusRequest>(){
+ {
+ add(new TaskStatusRequest(requestId1, null));
+ }
+ };
+ taskStatusResponses = controller.getTaskStatus(taskStatusRequests);
+ assertEquals(3, taskStatusResponses.size());
+
+ //check a taskId that requested by requestId1 and task id
+ taskStatusRequests = new HashSet<TaskStatusRequest>(){
+ {
+ add(new TaskStatusRequest(requestId1, 2L));
+ }
+ };
+ taskStatusResponses = controller.getTaskStatus(taskStatusRequests);
+ assertEquals(1, taskStatusResponses.size());
+ assertEquals(2L, taskStatusResponses.iterator().next().getTaskId());
+
+ //check count of tasks by requestId2
+ taskStatusRequests = new HashSet<TaskStatusRequest>(){
+ {
+ add(new TaskStatusRequest(requestId2, null));
+ }
+ };
+ taskStatusResponses = controller.getTaskStatus(taskStatusRequests);
+ assertEquals(2, taskStatusResponses.size());
+
+ //check a taskId that requested by requestId2 and task id
+ taskStatusRequests = new HashSet<TaskStatusRequest>(){
+ {
+ add(new TaskStatusRequest(requestId2, 5L));
+ }
+ };
+ taskStatusResponses = controller.getTaskStatus(taskStatusRequests);
+ assertEquals(5L, taskStatusResponses.iterator().next().getTaskId());
+
+ //verify that task from second request (requestId2) does not present in
first request (requestId1)
+ taskStatusRequests = new HashSet<TaskStatusRequest>(){
+ {
+ add(new TaskStatusRequest(requestId1, 5L));
+ }
+ };
+ expectedException.expect(ObjectNotFoundException.class);
+ expectedException.expectMessage("Task resource doesn't exist.");
+ controller.getTaskStatus(taskStatusRequests);
+
+ //verify that task from first request (requestId1) does not present in
second request (requestId2)
+ taskStatusRequests = new HashSet<TaskStatusRequest>(){
+ {
+ add(new TaskStatusRequest(requestId2, 2L));
+ }
+ };
+ expectedException.expect(ObjectNotFoundException.class);
+ expectedException.expectMessage("Task resource doesn't exist.");
+ controller.getTaskStatus(taskStatusRequests);
+ }
+
}