|
@@ -23,6 +23,7 @@ import com.google.inject.Provider;
|
|
|
import com.google.inject.Singleton;
|
|
|
import com.google.inject.persist.Transactional;
|
|
|
import org.apache.ambari.server.actionmanager.HostRoleStatus;
|
|
|
+import org.apache.ambari.server.orm.RequiresSession;
|
|
|
import org.apache.ambari.server.orm.entities.HostEntity;
|
|
|
import org.apache.ambari.server.orm.entities.HostRoleCommandEntity;
|
|
|
import org.apache.ambari.server.orm.entities.StageEntity;
|
|
@@ -48,12 +49,12 @@ public class HostRoleCommandDAO {
|
|
|
private static Logger LOG = LoggerFactory.getLogger(HostRoleCommandDAO.class);
|
|
|
private static final int REQUESTS_RESULT_LIMIT = 10;
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public HostRoleCommandEntity findByPK(long taskId) {
|
|
|
return entityManagerProvider.get().find(HostRoleCommandEntity.class, taskId);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<HostRoleCommandEntity> findByPKs(Collection<Long> taskIds) {
|
|
|
if (taskIds == null || taskIds.isEmpty()) {
|
|
|
return Collections.emptyList();
|
|
@@ -65,7 +66,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, taskIds);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<HostRoleCommandEntity> findByRequestIds(Collection<Long> requestIds) {
|
|
|
TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
|
|
|
"SELECT task FROM HostRoleCommandEntity task " +
|
|
@@ -74,7 +75,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, requestIds);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<Long> findTaskIdsByRequestIds(Collection<Long> requestIds) {
|
|
|
TypedQuery<Long> query = entityManagerProvider.get().createQuery(
|
|
|
"SELECT task.taskId FROM HostRoleCommandEntity task " +
|
|
@@ -83,7 +84,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, requestIds);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<HostRoleCommandEntity> findByRequestAndTaskIds(Collection<Long> requestIds, Collection<Long> taskIds) {
|
|
|
TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery(
|
|
|
"SELECT DISTINCT task FROM HostRoleCommandEntity task " +
|
|
@@ -93,7 +94,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, requestIds, taskIds);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<Long> findTaskIdsByRequestAndTaskIds(Collection<Long> requestIds, Collection<Long> taskIds) {
|
|
|
TypedQuery<Long> query = entityManagerProvider.get().createQuery(
|
|
|
"SELECT DISTINCT task.taskId FROM HostRoleCommandEntity task " +
|
|
@@ -103,7 +104,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, requestIds, taskIds);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<HostRoleCommandEntity> findSortedCommandsByStageAndHost(StageEntity stageEntity, HostEntity hostEntity) {
|
|
|
TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand " +
|
|
|
"FROM HostRoleCommandEntity hostRoleCommand " +
|
|
@@ -112,7 +113,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, stageEntity, hostEntity);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public Map<String, List<HostRoleCommandEntity>> findSortedCommandsByStage(StageEntity stageEntity) {
|
|
|
TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand " +
|
|
|
"FROM HostRoleCommandEntity hostRoleCommand " +
|
|
@@ -133,7 +134,7 @@ public class HostRoleCommandDAO {
|
|
|
return hostCommands;
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<Long> findTaskIdsByStage(long requestId, long stageId) {
|
|
|
TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT hostRoleCommand.taskId " +
|
|
|
"FROM HostRoleCommandEntity hostRoleCommand " +
|
|
@@ -144,7 +145,7 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, requestId, stageId);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
public List<HostRoleCommandEntity> findByHostRole(String hostName, long requestId, long stageId, String role) {
|
|
|
TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
|
|
|
"FROM HostRoleCommandEntity command " +
|
|
@@ -155,7 +156,28 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query, hostName, requestId, stageId, role);
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
+ @RequiresSession
|
|
|
+ public List<HostRoleCommandEntity> findByRequest(long requestId) {
|
|
|
+ TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
|
|
|
+ "FROM HostRoleCommandEntity command " +
|
|
|
+ "WHERE command.requestId=?1 ORDER BY command.taskId", HostRoleCommandEntity.class);
|
|
|
+ return daoUtils.selectList(query, requestId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresSession
|
|
|
+ public List<Long> findTaskIdsByRequest(long requestId) {
|
|
|
+ TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT command.taskId " +
|
|
|
+ "FROM HostRoleCommandEntity command " +
|
|
|
+ "WHERE command.requestId=?1 ORDER BY command.taskId", Long.class);
|
|
|
+ return daoUtils.selectList(query, requestId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresSession
|
|
|
+ public List<HostRoleCommandEntity> findAll() {
|
|
|
+ return daoUtils.selectAll(entityManagerProvider.get(), HostRoleCommandEntity.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequiresSession
|
|
|
public List<Long> getRequests() {
|
|
|
String queryStr = "SELECT DISTINCT command.requestId " +
|
|
|
"FROM HostRoleCommandEntity command ORDER BY command.requestId DESC";
|
|
@@ -165,6 +187,48 @@ public class HostRoleCommandDAO {
|
|
|
return daoUtils.selectList(query);
|
|
|
}
|
|
|
|
|
|
+ @RequiresSession
|
|
|
+ public List<Long> getRequestsByTaskStatus(
|
|
|
+ Collection<HostRoleStatus> statuses, boolean match, boolean checkAllTasks) {
|
|
|
+ List<Long> results = null;
|
|
|
+ StringBuilder queryStr = new StringBuilder();
|
|
|
+
|
|
|
+ queryStr.append("SELECT DISTINCT command.requestId ").append(
|
|
|
+ "FROM HostRoleCommandEntity command ");
|
|
|
+ if (statuses != null && !statuses.isEmpty()) {
|
|
|
+ queryStr.append("WHERE ");
|
|
|
+
|
|
|
+ if (checkAllTasks) {
|
|
|
+ queryStr.append("command.requestId ");
|
|
|
+ if (!match) {
|
|
|
+ queryStr.append("NOT ");
|
|
|
+ }
|
|
|
+ queryStr.append("IN (").append("SELECT c.requestId ")
|
|
|
+ .append("FROM HostRoleCommandEntity c ")
|
|
|
+ .append("WHERE c.requestId = command.requestId ")
|
|
|
+ .append("AND c.status IN ?1) ");
|
|
|
+ } else {
|
|
|
+ queryStr.append("command.status ");
|
|
|
+ if (!match) {
|
|
|
+ queryStr.append("NOT ");
|
|
|
+ }
|
|
|
+ queryStr.append("IN ?1 ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ queryStr.append("ORDER BY command.requestId DESC");
|
|
|
+ TypedQuery<Long> query = entityManagerProvider.get().createQuery(queryStr.toString(),
|
|
|
+ Long.class);
|
|
|
+ query.setMaxResults(REQUESTS_RESULT_LIMIT);
|
|
|
+
|
|
|
+ if (statuses != null && !statuses.isEmpty()) {
|
|
|
+ results = daoUtils.selectList(query, statuses);
|
|
|
+ } else {
|
|
|
+ results = daoUtils.selectList(query);
|
|
|
+ }
|
|
|
+ return results;
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
/**
|
|
|
* NB: You cannot rely on return value if batch write is enabled
|
|
@@ -184,27 +248,6 @@ public class HostRoleCommandDAO {
|
|
|
return commandEntities.size();
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
- public List<HostRoleCommandEntity> findByRequest(long requestId) {
|
|
|
- TypedQuery<HostRoleCommandEntity> query = entityManagerProvider.get().createQuery("SELECT command " +
|
|
|
- "FROM HostRoleCommandEntity command " +
|
|
|
- "WHERE command.requestId=?1 ORDER BY command.taskId", HostRoleCommandEntity.class);
|
|
|
- return daoUtils.selectList(query, requestId);
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- public List<Long> findTaskIdsByRequest(long requestId) {
|
|
|
- TypedQuery<Long> query = entityManagerProvider.get().createQuery("SELECT command.taskId " +
|
|
|
- "FROM HostRoleCommandEntity command " +
|
|
|
- "WHERE command.requestId=?1 ORDER BY command.taskId", Long.class);
|
|
|
- return daoUtils.selectList(query, requestId);
|
|
|
- }
|
|
|
-
|
|
|
- @Transactional
|
|
|
- public List<HostRoleCommandEntity> findAll() {
|
|
|
- return daoUtils.selectAll(entityManagerProvider.get(), HostRoleCommandEntity.class);
|
|
|
- }
|
|
|
-
|
|
|
@Transactional
|
|
|
public void create(HostRoleCommandEntity stageEntity) {
|
|
|
entityManagerProvider.get().persist(stageEntity);
|
|
@@ -235,46 +278,4 @@ public class HostRoleCommandDAO {
|
|
|
remove(findByPK(taskId));
|
|
|
}
|
|
|
|
|
|
- @Transactional
|
|
|
- public List<Long> getRequestsByTaskStatus(
|
|
|
- Collection<HostRoleStatus> statuses, boolean match, boolean checkAllTasks) {
|
|
|
- List<Long> results = null;
|
|
|
- StringBuilder queryStr = new StringBuilder();
|
|
|
-
|
|
|
- queryStr.append("SELECT DISTINCT command.requestId ").append(
|
|
|
- "FROM HostRoleCommandEntity command ");
|
|
|
- if (statuses != null && !statuses.isEmpty()) {
|
|
|
- queryStr.append("WHERE ");
|
|
|
-
|
|
|
- if (checkAllTasks) {
|
|
|
- queryStr.append("command.requestId ");
|
|
|
- if (!match) {
|
|
|
- queryStr.append("NOT ");
|
|
|
- }
|
|
|
- queryStr.append("IN (").append("SELECT c.requestId ")
|
|
|
- .append("FROM HostRoleCommandEntity c ")
|
|
|
- .append("WHERE c.requestId = command.requestId ")
|
|
|
- .append("AND c.status IN ?1) ");
|
|
|
- } else {
|
|
|
- queryStr.append("command.status ");
|
|
|
- if (!match) {
|
|
|
- queryStr.append("NOT ");
|
|
|
- }
|
|
|
- queryStr.append("IN ?1 ");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- queryStr.append("ORDER BY command.requestId DESC");
|
|
|
- TypedQuery<Long> query = entityManagerProvider.get().createQuery(queryStr.toString(),
|
|
|
- Long.class);
|
|
|
- query.setMaxResults(REQUESTS_RESULT_LIMIT);
|
|
|
-
|
|
|
- if (statuses != null && !statuses.isEmpty()) {
|
|
|
- results = daoUtils.selectList(query, statuses);
|
|
|
- } else {
|
|
|
- results = daoUtils.selectList(query);
|
|
|
- }
|
|
|
- return results;
|
|
|
- }
|
|
|
-
|
|
|
}
|