private List<ClusterTask> getTasksByName(List<ClusterTask> tasks, ProvisionerAction name) { List<ClusterTask> result = new ArrayList<ClusterTask>(); for (ClusterTask task : tasks) { if (task.getTaskName().equals(name)) { result.add(task); } } return result; }
@Override public int compare(ClusterTask task1, ClusterTask task2) { return task1.getTaskName().compareTo(task2.getTaskName()); } };
private JsonObject formatJobPlan(ClusterJob job) throws IOException { JsonObject jobJson = new JsonObject(); jobJson.addProperty("id", job.getJobId()); jobJson.addProperty("clusterId", job.getClusterId()); jobJson.addProperty("action", job.getClusterAction().name()); jobJson.addProperty("currentStage", job.getCurrentStageNumber()); JsonArray stagesJson = new JsonArray(); for (Set<String> stage : job.getStagedTasks()) { JsonArray stageJson = new JsonArray(); for (String taskId : stage) { ClusterTask task = clusterStore.getClusterTask(TaskId.fromString(taskId)); JsonObject taskJson = new JsonObject(); taskJson.addProperty("id", task.getTaskId()); taskJson.addProperty("taskName", task.getTaskName().name()); taskJson.addProperty("nodeId", task.getNodeId()); taskJson.addProperty("service", task.getService()); stageJson.add(taskJson); } stagesJson.add(stageJson); } jobJson.add("stages", stagesJson); return jobJson; }
@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; } }
@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; }
/** * Starts a task by setting the status of the task to {@link ClusterTask.Status#IN_PROGRESS} and the submit time * to the current timestamp. * * @param clusterTask Task to start. * @throws IOException */ public void startTask(ClusterTask clusterTask) throws IOException { clusterTask.setStatus(ClusterTask.Status.IN_PROGRESS); clusterTask.setSubmitTime(System.currentTimeMillis()); clusterStore.writeClusterTask(clusterTask); // Update stats serverStats.getProvisionerStats().incrementStat(clusterTask.getTaskName()); }
/** * Drop a task by setting the status of the task to {@link ClusterTask.Status#DROPPED} and the status time to the * current timestamp. Tasks can be dropped if there is no longer any point in executing them. For example, if another * task in the same stage has failed, the entire job cannot complete so there is no point in executing any * unexecuted task in the job. * * @param clusterTask Task to drop. * @throws IOException */ public void dropTask(ClusterTask clusterTask) throws IOException { clusterTask.setStatus(ClusterTask.Status.DROPPED); clusterTask.setStatusTime(System.currentTimeMillis()); clusterStore.writeClusterTask(clusterTask); // Update stats serverStats.getDroppedProvisionerStats().incrementStat(clusterTask.getTaskName()); }
ProvisionerAction retryAction = actions.getRetryAction().get(task.getTaskName()); int currentActionIndex = taskOrder.indexOf(task.getTaskName()); for (int i = retryActionIndex; i < currentActionIndex; ++i) { ProvisionerAction action = taskOrder.get(i);
/** * Fail a task by setting the status of the task to {@link ClusterTask.Status#FAILED} and the status time to the * current timestamp and the status code to the given code. * * @param clusterTask Task to fail. * @param status Status code of the failed task. * @throws IOException */ public void failTask(ClusterTask clusterTask, int status) throws IOException { clusterTask.setStatus(ClusterTask.Status.FAILED); clusterTask.setStatusCode(status); clusterTask.setStatusTime(System.currentTimeMillis()); clusterStore.writeClusterTask(clusterTask); // Update stats serverStats.getFailedProvisionerStats().incrementStat(clusterTask.getTaskName()); }
/** * Complete a task by setting the status of the task to {@link ClusterTask.Status#COMPLETE} and the status time to * the current timestamp and the status code to the given code. * * @param clusterTask Task to complete. * @param status Status code of the completed task. * @throws IOException */ public void completeTask(ClusterTask clusterTask, int status) throws IOException { clusterTask.setStatus(ClusterTask.Status.COMPLETE); clusterTask.setStatusCode(status); clusterTask.setStatusTime(System.currentTimeMillis()); clusterStore.writeClusterTask(clusterTask); // update stats serverStats.getSuccessfulProvisionerStats().incrementStat(clusterTask.getTaskName()); }
public SchedulableTask(ClusterTask clusterTask, TaskConfig config) { this.taskId = clusterTask.getTaskId(); this.jobId = clusterTask.getJobId(); this.clusterId = clusterTask.getClusterId(); this.taskName = clusterTask.getTaskName().name(); this.nodeId = clusterTask.getNodeId(); this.config = config; }
if (!task.getTaskName().isHardwareAction()) { try { task.getTaskName(), clusterNodes); LOG.debug("Submitting task {}", task.getTaskId()); LOG.trace("Task {}", task);
void startNodeAction(ClusterTask clusterTask) throws IOException { // Update node properties if task is associated with a nodeId. // There are cases when we don't associate a nodeId with a task so that the node properties don't get overridden // by the task output. // Eg. deleting a box during a rollback operation since we reuse nodeIds. if (clusterTask.getNodeId() != null) { Node node = clusterStore.getNode(clusterTask.getNodeId()); if (node == null) { LOG.error("Cannot find node {} for task {} to update the properties", clusterTask.getNodeId(), clusterTask.getTaskId()); } else { nodeService.startAction(node, clusterTask.getTaskId(), clusterTask.getService(), clusterTask.getTaskName().name()); } } }
/** * Get the rollback task that should run if the given task fails. * * @param task Task that needs to get rolled back. * @return Cluster task that will roll back the given failed task. */ private ClusterTask getRollbackTask(ClusterTask task) { ProvisionerAction rollback = actions.getRollbackActions().get(task.getTaskName()); if (rollback == null) { return null; } TaskId rollbackTaskId = idService.getNewTaskId(JobId.fromString(task.getJobId())); ClusterTask rollbackTask = new ClusterTask(rollback, rollbackTaskId, task.getNodeId(), task.getService(), task.getClusterAction(), task.getClusterTemplateName(), task.getAccount()); return rollbackTask; }
for (String taskId : job.getCurrentStage()) { ClusterTask task = clusterStore.getClusterTask(TaskId.fromString(taskId)); actionServices.add(new ActionService(task.getTaskName().name(), task.getService()));