@Override public String apply(ClusterTask clusterTask) { return clusterTask.getTaskId(); } };
@Override public String apply(ClusterTask clusterTask) { return clusterTask.getTaskId(); } };
ClusterTask scheduleRetry(ClusterJob job, ClusterTask task) throws Exception { task.addAttempt(); List<ClusterTask> retryTasks = taskService.getRetryTask(task); if (retryTasks.size() == 1) { LOG.trace("Only one retry task for job {} for task {}", job, task); return retryTasks.get(0); } // store all retry tasks for (ClusterTask t : retryTasks) { clusterStore.writeClusterTask(t); } // Remove self from current stage job.getCurrentStage().remove(task.getTaskId()); // Add first retry task to current stage job.getCurrentStage().add(retryTasks.get(0).getTaskId()); // Add the rest of retry tasks after current stage. TODO: this needs to be revisited. job.insertTasksAfterCurrentStage(ImmutableList.copyOf(Iterables.transform(Iterables.skip(retryTasks, 1), CLUSTER_TASK_STRING_FUNCTION))); LOG.trace("Retry job {} for task {}", job, task); return retryTasks.get(0); }
@Override public void writeClusterTask(ClusterTask clusterTask) throws IOException { TaskId taskId = TaskId.fromString(clusterTask.getTaskId()); long clusterId = Long.parseLong(taskId.getClusterId()); try { Connection conn = dbConnectionPool.getConnection(); try { byte[] taskBytes = dbQueryExecutor.toBytes(clusterTask, ClusterTask.class); DBPut taskPut = new ClusterTaskDBPut(clusterTask, taskBytes, taskId, clusterId); taskPut.executePut(conn); } finally { conn.close(); } } catch (SQLException e) { throw new IOException(e); } }
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; }
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()); } } }
LOG.error("Exception while expanding macros for task {}", task.getTaskId(), e); taskService.failTask(task, -1); job.setStatusMessage("Exception while expanding macros: " + e.getMessage()); LOG.debug("Submitting task {}", task.getTaskId()); LOG.trace("Task {}", task); SchedulableTask schedulableTask = new SchedulableTask(task, taskConfig); queueName, new Element(task.getTaskId(), gson.toJson(schedulableTask))); job.setTaskStatus(task.getTaskId(), ClusterTask.Status.IN_PROGRESS); taskService.startTask(task);
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; }
for (String taskId : currentStage) { ClusterTask task = clusterStore.getClusterTask(TaskId.fromString(taskId)); job.setTaskStatus(task.getTaskId(), task.getStatus()); LOG.debug("Status of task {} is {}", taskId, task.getStatus()); if (task.getStatus() == ClusterTask.Status.COMPLETE) {
if (node == null) { LOG.error("Cannot find node {} for task {} to update the properties", clusterTask.getNodeId(), clusterTask.getTaskId()); } else {
@Test public void testTakeTask() throws Exception { String tenantId = USER1_ACCOUNT.getTenantId(); ClusterTask clusterTask = new ClusterTask( ProvisionerAction.CREATE, TaskId.fromString("1-1-1"), "node_id", "service", ClusterAction.CLUSTER_CREATE, "test", USER1_ACCOUNT); clusterStore.writeClusterTask(clusterTask); ClusterJob clusterJob = new ClusterJob(JobId.fromString("1-1"), ClusterAction.CLUSTER_CREATE); clusterStore.writeClusterJob(clusterJob); TaskConfig taskConfig = new TaskConfig( NodeProperties.builder().build(), Entities.ProviderExample.JOYENT, ImmutableMap.<String, NodeProperties>of(), new TaskServiceAction("svcA", new ServiceAction("shell", ImmutableMap.<String, String>of())), new JsonObject(), new JsonObject() ); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask))); TakeTaskRequest takeRequest = new TakeTaskRequest("worker1", PROVISIONER_ID, TENANT_ID); HttpResponse response = doPostInternalAPI("/tasks/take", gson.toJson(takeRequest)); assertResponseStatus(response, HttpResponseStatus.OK); JsonObject responseJson = getResponseJson(response); Assert.assertEquals(clusterTask.getTaskId(), responseJson.get("taskId").getAsString()); }
private TakeTaskRequest getRequest() throws IOException { String tenantId = USER1_ACCOUNT.getTenantId(); ClusterTask clusterTask = new ClusterTask( ProvisionerAction.CREATE, TaskId.fromString("1-1-1"), "node_id", "service", ClusterAction.CLUSTER_CREATE, "test", USER1_ACCOUNT); clusterStore.writeClusterTask(clusterTask); ClusterJob clusterJob = new ClusterJob(JobId.fromString("1-1"), ClusterAction.CLUSTER_CREATE); clusterStore.writeClusterJob(clusterJob); TaskConfig taskConfig = new TaskConfig( NodeProperties.builder().build(), Entities.ProviderExample.JOYENT, ImmutableMap.<String, NodeProperties>of(), new TaskServiceAction("svcA", new ServiceAction("shell", ImmutableMap.<String, String>of())), new JsonObject(), new JsonObject() ); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask))); return new TakeTaskRequest("worker1", PROVISIONER_ID, TENANT_ID); }
); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask))); Assert.assertEquals(clusterTask.getTaskId(), task.getTaskId()); new FinishTaskRequest("worker1", PROVISIONER_ID, tenantId, clusterTask.getTaskId(), "some stdout", "some stderr", 0, null, null, provisionerResult); TestHelper.finishTask(getBaseUrlInternalAPI(), finishRequest); ClusterTask actualTask = clusterStore.getClusterTask(TaskId.fromString(clusterTask.getTaskId())); Assert.assertEquals(ClusterTask.Status.COMPLETE, actualTask.getStatus());
taskQueues.recordProgress(consumerId, tenantId, clusterTask.getTaskId(), TrackingQueue.ConsumingStatus.FINISHED_SUCCESSFULLY, "Skipped due to job failure.");
nodeService.startAction(node1, task1.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node1.getActions().get(0).getStatus()); nodeService.startAction(node2, task2.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node2.getActions().get(0).getStatus()); nodeService.startAction(node3, task3.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node3.getActions().get(0).getStatus()); nodeService.startAction(node4, task4.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node4.getActions().get(0).getStatus()); Assert.assertEquals(0, Iterators.size(provisionerQueues.getBeingConsumed(queueName))); provisionerQueues.add(queueName, new Element(task1.getTaskId(), "")); provisionerQueues.add(queueName, new Element(task2.getTaskId(), "")); provisionerQueues.add(queueName, new Element(task3.getTaskId(), "")); provisionerQueues.add(queueName, new Element(task4.getTaskId(), "")); clusterStore.getClusterTask(TaskId.fromString(task1.getTaskId())).getStatus()); Assert.assertEquals(ClusterTask.Status.FAILED, clusterStore.getClusterTask(TaskId.fromString(task2.getTaskId())).getStatus()); Assert.assertEquals(ClusterTask.Status.IN_PROGRESS, clusterStore.getClusterTask(TaskId.fromString(task3.getTaskId())).getStatus()); Assert.assertEquals(ClusterTask.Status.IN_PROGRESS, clusterStore.getClusterTask(TaskId.fromString(task4.getTaskId())).getStatus());
@Test public void testQueuedTaskMissingFromStoreIsRemovedFromQueue() { ClusterCleanup clusterCleanup = new ClusterCleanup(clusterStore, clusterService, nodeService, taskService, jobQueues, provisionerQueues, -10, 1, 1); String queueName = account.getTenantId(); ClusterTask task = new ClusterTask(ProvisionerAction.CREATE, TaskId.fromString("3-1-1"), "node1", "service", ClusterAction.CLUSTER_CREATE, "test", account); task.setStatus(ClusterTask.Status.IN_PROGRESS); Cluster cluster = Entities.ClusterExample.createCluster(); TaskConfig taskConfig = TaskConfig.from(cluster, Entities.ClusterExample.NODE1, Entities.ServiceExample.NAMENODE, cluster.getConfig(), ProvisionerAction.START, null); SchedulableTask schedulableTask = new SchedulableTask(task, taskConfig); // add a task to the queue without storing it.x provisionerQueues.add(queueName, new Element(task.getTaskId(), gson.toJson(schedulableTask))); provisionerQueues.takeIterator("0").next(); clusterCleanup.run(); Assert.assertEquals(0, Iterators.size(provisionerQueues.getBeingConsumed(queueName))); }
); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask))); Assert.assertEquals(clusterTask.getTaskId(), task.getTaskId()); new FinishTaskRequest("worker1", PROVISIONER_ID, tenantId, clusterTask.getTaskId(), "some stdout", "some stderr", 1, null, null, null); TestHelper.finishTask(getBaseUrlInternalAPI(), finishRequest); ClusterTask actualTask = clusterStore.getClusterTask(TaskId.fromString(clusterTask.getTaskId())); Assert.assertEquals(ClusterTask.Status.FAILED, actualTask.getStatus());