@Override public Set<ClusterTask> getRunningTasks(long timestamp) throws IOException { try { Connection conn = dbConnectionPool.getConnection(); try { PreparedStatement statement = conn.prepareStatement("SELECT task FROM tasks WHERE status = ? AND submit_time < ?"); statement.setString(1, ClusterTask.Status.IN_PROGRESS.name()); statement.setTimestamp(2, DBHelper.getTimestamp(timestamp)); try { return dbQueryExecutor.getQuerySet(statement, ClusterTask.class); } finally { statement.close(); } } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
conn.prepareStatement(builder.toString()); try { int index = initializeFilter(statement, ClusterTask.Status.COMPLETE.name(), 1); index = initializeFilter(statement, ProvisionerAction.CREATE.name(), index); index = initializeFilter(statement, ProvisionerAction.DELETE.name(), index);
@Override public PreparedStatement createUpdateStatement(Connection conn) throws SQLException { PreparedStatement statement = conn.prepareStatement( "UPDATE tasks SET task=?, status=?, submit_time=?, status_time=?, type=?, " + "cluster_template_name=?, user_id=?, tenant_id=?" + " WHERE task_num=? AND job_num=? AND cluster_id=?"); statement.setBytes(1, dbQueryExecutor.toBytes(clusterTask, ClusterTask.class)); statement.setString(2, clusterTask.getStatus().name()); statement.setTimestamp(3, DBHelper.getTimestamp(clusterTask.getSubmitTime())); statement.setTimestamp(4, DBHelper.getTimestamp(clusterTask.getStatusTime())); statement.setString(5, clusterTask.getTaskName().name()); statement.setString(6, clusterTask.getClusterTemplateName()); statement.setString(7, clusterTask.getAccount().getUserId()); statement.setString(8, clusterTask.getAccount().getTenantId()); statement.setLong(9, taskId.getTaskNum()); statement.setLong(10, taskId.getJobNum()); statement.setLong(11, clusterId); return statement; }
@Override public PreparedStatement createInsertStatement(Connection conn) throws SQLException { PreparedStatement statement = conn.prepareStatement( "INSERT INTO tasks (task_num, job_num, cluster_id, status, submit_time, task, type, " + "cluster_template_name, user_id, tenant_id)" + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); statement.setLong(1, taskId.getTaskNum()); statement.setLong(2, taskId.getJobNum()); statement.setLong(3, clusterId); statement.setString(4, clusterTask.getStatus().name()); statement.setTimestamp(5, DBHelper.getTimestamp(clusterTask.getSubmitTime())); statement.setBytes(6, taskBytes); statement.setString(7, clusterTask.getTaskName().name()); statement.setString(8, clusterTask.getClusterTemplateName()); statement.setString(9, clusterTask.getAccount().getUserId()); statement.setString(10, clusterTask.getAccount().getTenantId()); return statement; } }
public ClusterStatusResponse(Cluster cluster, ClusterJob job) { this.clusterid = cluster.getId(); this.status = cluster.getStatus(); this.actionstatus = job.getJobStatus(); this.action = job.getClusterAction(); Map<String, ClusterTask.Status> taskStatus = job.getTaskStatus(); int completedTasks = 0; for (Map.Entry<String, ClusterTask.Status> entry : taskStatus.entrySet()) { if (entry.getValue().equals(ClusterTask.Status.COMPLETE)) { completedTasks++; } } this.stepscompleted = completedTasks; this.stepstotal = taskStatus.size(); }