incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From swa...@apache.org
Subject svn commit: r1466726 - in /incubator/ambari/trunk: ./ ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ ambari-server/src/main/java/org/apache/ambari/server/controller/ ambari-server/src/main/java/org/apache/ambari/server/orm/dao/ amb...
Date Wed, 10 Apr 2013 23:04:32 GMT
Author: swagle
Date: Wed Apr 10 23:04:32 2013
New Revision: 1466726

URL: http://svn.apache.org/r1466726
Log:
AMBARI-1867. Processing API requests takes too long. (swagle)

Modified:
    incubator/ambari/trunk/CHANGES.txt
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
    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/DaoUtils.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/HostRoleCommandDAO.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java
    incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java

Modified: incubator/ambari/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/CHANGES.txt?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/CHANGES.txt (original)
+++ incubator/ambari/trunk/CHANGES.txt Wed Apr 10 23:04:32 2013
@@ -679,6 +679,8 @@ Trunk (unreleased changes):
 
  BUG FIXES
 
+ AMBARI-1867. Processing API requests takes too long. (swagle)
+
  AMBARI-1856. Queries for metrics to populate the dashboard graphs don't work
  with updated Ganglia. (tbeerbower)
 

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessor.java
Wed Apr 10 23:04:32 2013
@@ -19,6 +19,7 @@ package org.apache.ambari.server.actionm
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.ambari.server.Role;
@@ -79,4 +80,8 @@ public interface ActionDBAccessor {
   public HostRoleCommand getTask(long taskId);
 
   public List<Long> getRequestsByStatus(RequestStatus status);
+
+  public Map<Long, String> getRequestContext(List<Long> requestIds);
+
+  public String getRequestContext(long requestId);
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBAccessorImpl.java
Wed Apr 10 23:04:32 2013
@@ -341,4 +341,14 @@ public class ActionDBAccessorImpl implem
     }
     return hostRoleCommandDAO.getRequestsByTaskStatus(statuses, match, checkAllTasks);
   }
+
+  @Override
+  public Map<Long, String> getRequestContext(List<Long> requestIds) {
+    return stageDAO.findRequestContext(requestIds);
+  }
+
+  @Override
+  public String getRequestContext(long requestId) {
+    return stageDAO.findRequestContext(requestId);
+  }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionDBInMemoryImpl.java
Wed Apr 10 23:04:32 2013
@@ -204,4 +204,22 @@ public class ActionDBInMemoryImpl implem
     // TODO
     throw new RuntimeException("Functionality not implemented");
   }
+
+  @Override
+  public Map<Long, String> getRequestContext(List<Long> requestIds) {
+    Map<Long, String> result = new HashMap<Long, String>();
+    for (Long requestId : requestIds) {
+      List<Stage> stages = getAllStages(requestId);
+      result.put(requestId, stages != null && !stages.isEmpty() ? stages.get
+        (0).getRequestContext() : "");
+    }
+    return result;
+  }
+
+  @Override
+  public String getRequestContext(long requestId) {
+    List<Stage> stages = getAllStages(requestId);
+    return stages != null && !stages.isEmpty() ? stages.get(0)
+      .getRequestContext() : "";
+  }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/actionmanager/ActionManager.java
Wed Apr 10 23:04:32 2013
@@ -31,6 +31,7 @@ import org.slf4j.LoggerFactory;
 
 import java.util.Collection;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -179,4 +180,11 @@ public class ActionManager {
     return db.getRequestsByStatus(status);
   }
 
+  public Map<Long, String> getRequestContext(List<Long> requestIds) {
+    return db.getRequestContext(requestIds);
+  }
+
+  public String getRequestContext(long requestId) {
+    return db.getRequestContext(requestId);
+  }
 }

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=1466726&r1=1466725&r2=1466726&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
Wed Apr 10 23:04:32 2013
@@ -31,6 +31,7 @@ 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;
@@ -3586,16 +3587,35 @@ 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>();
+
+    for (HostRoleCommand hostRoleCommand : hostRoleCommands) {
+      Long requestId = hostRoleCommand.getRequestId();
+      RequestStatusResponse response = responseMap.get(requestId);
+      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();
+  }
+
+
   private RequestStatusResponse getRequestStatusResponse(long requestId) {
     RequestStatusResponse response = new RequestStatusResponse(requestId);
     List<HostRoleCommand> hostRoleCommands =
         actionManager.getRequestTasks(requestId);
 
-    List<Stage> listStages = actionManager.getActions(requestId);
-    if (listStages != null && !listStages.isEmpty()) {
-      //todo: may not be necessary to check list size.
-      response.setRequestContext(listStages.get(0).getRequestContext());
-    }
+    response.setRequestContext(actionManager.getRequestContext(requestId));
     List<ShortTaskStatus> tasks = new ArrayList<ShortTaskStatus>();
 
     for (HostRoleCommand hostRoleCommand : hostRoleCommands) {
@@ -3621,9 +3641,8 @@ public class AmbariManagementControllerI
             + ", requestStatus=" + requestStatus);
       }
       List<Long> requestIds = actionManager.getRequestsByStatus(requestStatus);
-      for (Long requestId : requestIds) {
-        response.add(getRequestStatusResponse(requestId.longValue()));
-      }
+      response.addAll(getRequestStatusResponses(requestIds));
+
     } else {
       RequestStatusResponse requestStatusResponse = getRequestStatusResponse(
           request.getRequestId().longValue());

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/DaoUtils.java
Wed Apr 10 23:04:32 2013
@@ -47,6 +47,15 @@ class DaoUtils {
     }
   }
 
+  public <T> T selectOne(TypedQuery<T> query, Object... parameters) {
+    setParameters(query, parameters);
+    try {
+      return query.setMaxResults(1).getSingleResult();
+    } catch (NoResultException ignored) {
+      return null;
+    }
+  }
+
   public int executeUpdate(Query query, Object... parameters) {
     setParameters(query, parameters);
     return query.executeUpdate();

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=1466726&r1=1466725&r2=1466726&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
Wed Apr 10 23:04:32 2013
@@ -43,6 +43,8 @@ public class HostRoleCommandDAO {
   @Inject
   DaoUtils daoUtils;
   private static Logger LOG = LoggerFactory.getLogger(HostRoleCommandDAO.class);
+  private static final int REQUESTS_RESULT_LIMIT_WITH_FILTER =  20;
+  private static final int REQUESTS_RESULT_LIMIT = 200;
 
   @Transactional
   public HostRoleCommandEntity findByPK(long taskId) {
@@ -173,8 +175,11 @@ public class HostRoleCommandDAO {
         }
         queryStr.append("IN ?1 ");
       }
-      resultsLimit = 20;
+      resultsLimit = REQUESTS_RESULT_LIMIT_WITH_FILTER;
+    } else {
+      resultsLimit = REQUESTS_RESULT_LIMIT;
     }
+
     queryStr.append("ORDER BY command.requestId DESC");
     TypedQuery<Long> query = entityManagerProvider.get().createQuery(queryStr.toString(),
         Long.class);

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/StageDAO.java
Wed Apr 10 23:04:32 2013
@@ -25,11 +25,12 @@ import org.apache.ambari.server.actionma
 import org.apache.ambari.server.orm.entities.StageEntity;
 import org.apache.ambari.server.orm.entities.StageEntityPK;
 import org.apache.ambari.server.utils.StageUtils;
-
 import javax.persistence.EntityManager;
 import javax.persistence.TypedQuery;
-import java.util.Collection;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Collection;
+import java.util.Map;
 
 public class StageDAO {
 
@@ -105,4 +106,33 @@ public class StageDAO {
     remove(findByPK(stageEntityPK));
   }
 
+  @Transactional
+  public Map<Long, String> findRequestContext(List<Long> requestIds) {
+    Map<Long, String> resultMap = new HashMap<Long, String>();
+    if (requestIds != null && !requestIds.isEmpty()) {
+      TypedQuery<StageEntity> query = entityManagerProvider.get()
+        .createQuery("SELECT stage FROM StageEntity stage WHERE " +
+          "stage.requestId IN (SELECT DISTINCT s.requestId FROM StageEntity s " +
+          "WHERE s.requestId IN ?1)", StageEntity.class);
+      List<StageEntity> result = daoUtils.selectList(query, requestIds);
+      if (result != null && !result.isEmpty()) {
+        for (StageEntity entity : result) {
+          resultMap.put(entity.getRequestId(), entity.getRequestContext());
+        }
+      }
+    }
+    return resultMap;
+  }
+
+  @Transactional
+  public String findRequestContext(long requestId) {
+    TypedQuery<String> query = entityManagerProvider.get().createQuery(
+      "SELECT stage.requestContext " + "FROM StageEntity stage " +
+        "WHERE stage.requestId=?1", String.class);
+    String result =  daoUtils.selectOne(query, requestId);
+    if (result != null)
+      return result;
+    else
+      return ""; // Since it is defined as empty string in the StageEntity
+  }
 }

Modified: incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java?rev=1466726&r1=1466725&r2=1466726&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
(original)
+++ incubator/ambari/trunk/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/HostRoleCommandEntity.java
Wed Apr 10 23:04:32 2013
@@ -30,7 +30,6 @@ import static org.apache.commons.lang.St
 
 @Table(name = "host_role_command")
 @Entity
-@Cacheable(false)
 @TableGenerator(name = "host_role_command_id_generator",
     table = "ambari_sequences", pkColumnName = "sequence_name", valueColumnName = "value"
     , pkColumnValue = "host_role_command_id_seq"



Mime
View raw message