/** * Makes sure that not more than one task per host is present in a stage. If task t1 and t2 for the same host are * present in stage i, then it create a new stage i.5 and adds either t1 or t2 to i.5. * Task i.5 will execute after i, but before i+1, so as to satisfy all dependencies. * @param tasks Initial task list, where there may be multiple tasks on same host in any stage. * @return the deduped task list. */ static List<Set<ClusterTask>> deDupNodePerStage(List<Set<ClusterTask>> tasks) { // Map contains nodeId and task. List<Map<String, ClusterTask>> deDupTasks = Lists.newArrayList(); for (Set<ClusterTask> stage : tasks) { List<Map<String, ClusterTask>> newStages = Lists.newArrayList(); for (ClusterTask task : stage) { if (!addToExistingStage(task, newStages)) { Map<String, ClusterTask> newStage = Maps.newHashMap(); newStage.put(task.getNodeId(), task); newStages.add(newStage); } } deDupTasks.addAll(newStages); } return Lists.newArrayList(Iterables.transform(deDupTasks, MAP_CLUSTER_TASK_FUNCTION)); }
private long getDeleteTaskTime(List<ClusterTask> deleteTasks, ClusterTask createTask) { ClusterTask result = null; for (ClusterTask deleteTask : deleteTasks) { if (createTask.getClusterId().equals(deleteTask.getClusterId()) && createTask.getNodeId().equals(deleteTask.getNodeId())) { if (result == null) { result = deleteTask; } else if (deleteTask.getStatusTime() < result.getStatusTime()) { result = deleteTask; } } } if (result == null) { return System.currentTimeMillis(); } return result.getStatusTime(); }
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()); } } }
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; }
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; }
ProvisionerAction action = taskOrder.get(i); TaskId retryTaskId = idService.getNewTaskId(JobId.fromString(task.getJobId())); ClusterTask retry = new ClusterTask(action, retryTaskId, task.getNodeId(), task.getService(), task.getClusterAction(), task.getClusterTemplateName(), task.getAccount()); retryTasks.add(retry);
Node node = clusterStore.getNode(task.getNodeId()); nodeService.failAction(node, "", statusMessage);
/** * 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; }
Node taskNode = nodeMap.get(task.getNodeId()); JsonObject clusterConfig = unexpandedClusterConfig;
Assert.assertEquals(ClusterTask.Status.COMPLETE, actualTask.getStatus()); Node actualNode = clusterStore.getNode(clusterTask.getNodeId()); Assert.assertNotNull(actualNode); Node.Action lastAction = actualNode.getActions().get(actualNode.getActions().size() - 1);
Assert.assertEquals(ClusterTask.Status.FAILED, actualTask.getStatus()); Node actualNode = clusterStore.getNode(clusterTask.getNodeId()); Assert.assertNotNull(actualNode); Node.Action lastAction = actualNode.getActions().get(actualNode.getActions().size() - 1);