incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject svn commit: r1471108 - in /incubator/ambari/trunk/ambari-server/src: main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java
Date Tue, 23 Apr 2013 19:26:39 GMT
Author: tbeerbower
Date: Tue Apr 23 19:26:39 2013
New Revision: 1471108

URL: http://svn.apache.org/r1471108
Log:
AMBARI-1996 - Request resource provider handler unnecessarily queries host_role_command table.

Modified:
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/controller/AmbariManagementControllerImpl.java
    incubator/ambari/trunk/ambari-server/src/test/java/org/apache/ambari/server/controller/AmbariManagementControllerTest.java

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=1471108&r1=1471107&r2=1471108&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 Apr 23 19:26:39 2013
@@ -31,7 +31,6 @@ import java.util.Map.Entry;
 import java.util.Set;
 import java.util.TreeMap;
 
-import com.google.inject.persist.Transactional;
 import com.google.gson.Gson;
 import com.google.inject.Inject;
 import com.google.inject.Injector;
@@ -3618,11 +3617,15 @@ public class AmbariManagementControllerI
     return Collections.emptySet();
   }
 
-  @Transactional
-  Collection<RequestStatusResponse> getRequestStatusResponses(List<Long> requestIds)
{
-    List<HostRoleCommand> hostRoleCommands = actionManager.getAllTasksByRequestIds(requestIds);
-    Map<Long, String> requestContexts = actionManager.getRequestContext(requestIds);
-    Map<Long, RequestStatusResponse> responseMap = new HashMap<Long, RequestStatusResponse>();
+  /**
+   * Get a collection of request responses for the given list of request ids.  Note that
+   * this method populates request resources only and does NOT populate the set of task
+   * sub-resources in each request response.
+   */
+  private Collection<RequestStatusResponse> getRequestStatusResponsesWithoutTasks(List<Long>
requestIds) {
+    List<HostRoleCommand>            hostRoleCommands = actionManager.getAllTasksByRequestIds(requestIds);
+    Map<Long, String>                requestContexts  = actionManager.getRequestContext(requestIds);
+    Map<Long, RequestStatusResponse> responseMap      = new HashMap<Long, RequestStatusResponse>();
 
     for (HostRoleCommand hostRoleCommand : hostRoleCommands) {
       Long requestId = hostRoleCommand.getRequestId();
@@ -3630,17 +3633,17 @@ public class AmbariManagementControllerI
       if (response == null) {
         response = new RequestStatusResponse(requestId);
         response.setRequestContext(requestContexts.get(requestId));
-        response.setTasks(new ArrayList<ShortTaskStatus>());
         responseMap.put(requestId, response);
       }
-
-      response.getTasks().add(new ShortTaskStatus(hostRoleCommand));
     }
-
     return responseMap.values();
   }
 
-
+  /**
+   * Get a request response for the given request ids.  Note that this method
+   * fully populates a request resource including the set of task sub-resources
+   * in the request response.
+   */
   private RequestStatusResponse getRequestStatusResponse(long requestId) {
     RequestStatusResponse response = new RequestStatusResponse(requestId);
     List<HostRoleCommand> hostRoleCommands =
@@ -3660,8 +3663,10 @@ public class AmbariManagementControllerI
   @Override
   public Set<RequestStatusResponse> getRequestStatus(
       RequestStatusRequest request) throws AmbariException{
-    Set<RequestStatusResponse> response = new HashSet<RequestStatusResponse>();
-    if (request.getRequestId() == null) {
+    Set<RequestStatusResponse> response  = new HashSet<RequestStatusResponse>();
+    Long                       requestId = request.getRequestId();
+
+    if (requestId == null) {
       RequestStatus requestStatus = null;
       if (request.getRequestStatus() != null) {
         requestStatus = RequestStatus.valueOf(request.getRequestStatus());
@@ -3671,21 +3676,19 @@ public class AmbariManagementControllerI
             + ", requestId=null"
             + ", requestStatus=" + requestStatus);
       }
-      List<Long> requestIds = actionManager.getRequestsByStatus(requestStatus);
-      response.addAll(getRequestStatusResponses(requestIds));
-
+      response.addAll(getRequestStatusResponsesWithoutTasks(
+          actionManager.getRequestsByStatus(requestStatus)));
     } else {
-      RequestStatusResponse requestStatusResponse = getRequestStatusResponse(
-          request.getRequestId().longValue());
+      Collection<RequestStatusResponse> responses = getRequestStatusResponsesWithoutTasks(
+          Collections.singletonList(requestId.longValue()));
 
       //todo: correlate request with cluster
-      if (requestStatusResponse.getTasks().size() == 0) {
+      if (responses.isEmpty()) {
         //todo: should be thrown lower in stack but we only want to throw if id was specified
         //todo: and we currently iterate over all id's and invoke for each if id is not specified
         throw new ObjectNotFoundException("Request resource doesn't exist.");
-      } else {
-        response.add(requestStatusResponse);
       }
+      response.addAll(responses);
     }
     return response;
   }

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=1471108&r1=1471107&r2=1471108&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 Apr 23 19:26:39 2013
@@ -1498,7 +1498,6 @@ public class AmbariManagementControllerT
     Assert.assertNotNull(statusResponse);
     Assert.assertEquals(trackAction.getRequestId(),
         statusResponse.getRequestId());
-    Assert.assertEquals(5, statusResponse.getTasks().size());
 
     Set<TaskStatusRequest> taskRequests = new HashSet<TaskStatusRequest>();
     TaskStatusRequest t1, t2;
@@ -3384,18 +3383,10 @@ public class AmbariManagementControllerT
     RequestStatusResponse requestStatusResponse =
         requestStatusResponses.iterator().next();
     assertEquals(requestId, requestStatusResponse.getRequestId());
-    assertEquals(2, requestStatusResponse.getTasks().size());
     assertEquals(context, requestStatusResponse.getRequestContext());
 
-    ShortTaskStatus task1 = requestStatusResponse.getTasks().get(0);
-    ShortTaskStatus task2 = requestStatusResponse.getTasks().get(1);
-
-    assertEquals(RoleCommand.START.toString(), task1.getCommand());
-    assertEquals(Role.HBASE_MASTER.toString(), task1.getRole());
-
     Set<TaskStatusRequest> taskStatusRequests = new HashSet<TaskStatusRequest>();
-    taskStatusRequests.add(new TaskStatusRequest(requestId, task1.getTaskId()));
-    taskStatusRequests.add(new TaskStatusRequest(requestId, task2.getTaskId()));
+    taskStatusRequests.add(new TaskStatusRequest(requestId, null));
     Set<TaskStatusResponse> taskStatusResponses =
         controller.getTaskStatus(taskStatusRequests);
 



Mime
View raw message