use of org.apache.helix.task.WorkflowContext in project incubator-gobblin by apache.
the class GobblinHelixJobLauncher method helixTaskDriverWaitToStop.
/**
* Because fix https://github.com/apache/helix/commit/ae8e8e2ef37f48d782fc12f85ca97728cf2b70c4
* is not available in currently used version 0.6.9
*/
private void helixTaskDriverWaitToStop(String workflow, long timeoutInSeconds) throws InterruptedException {
this.helixTaskDriver.stop(workflow);
long endTime = System.currentTimeMillis() + timeoutInSeconds * 1000;
while (System.currentTimeMillis() <= endTime) {
WorkflowContext workflowContext = TaskDriver.getWorkflowContext(this.helixManager, this.helixQueueName);
if (workflowContext == null || workflowContext.getWorkflowState().equals(org.apache.helix.task.TaskState.IN_PROGRESS)) {
Thread.sleep(1000);
} else {
LOGGER.info("Successfully stopped the queue");
return;
}
}
}
use of org.apache.helix.task.WorkflowContext in project helix by apache.
the class WorkflowAccessor method getWorkflowContext.
@GET
@Path("{workflowId}/context")
public Response getWorkflowContext(@PathParam("clusterId") String clusterId, @PathParam("workflowId") String workflowId) {
TaskDriver taskDriver = getTaskDriver(clusterId);
WorkflowContext workflowContext = taskDriver.getWorkflowContext(workflowId);
ObjectNode workflowContextNode = JsonNodeFactory.instance.objectNode();
if (workflowContext != null) {
getWorkflowContextNode(workflowContextNode, workflowContext.getRecord());
}
return JSONRepresentation(workflowContextNode);
}
use of org.apache.helix.task.WorkflowContext in project helix by apache.
the class TestTaskRebalancerStopResume method testStopWorkflowInStoppingState.
@Test
public void testStopWorkflowInStoppingState() throws InterruptedException {
final String workflowName = TestHelper.getTestMethodName();
// Create a workflow
Workflow.Builder builder = new Workflow.Builder(workflowName);
// Add 2 jobs
Map<String, String> jobCommandConfigMap = new HashMap<String, String>();
jobCommandConfigMap.put(MockTask.TIMEOUT_CONFIG, "1000000");
jobCommandConfigMap.put(MockTask.NOT_ALLOW_TO_CANCEL, String.valueOf(true));
List<TaskConfig> taskConfigs = ImmutableList.of(new TaskConfig.Builder().setCommand(MockTask.TASK_COMMAND).setTaskId("testTask").build());
JobConfig.Builder job1 = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).addTaskConfigs(taskConfigs).setJobCommandConfigMap(jobCommandConfigMap);
String job1Name = "Job1";
JobConfig.Builder job2 = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).addTaskConfigs(taskConfigs);
String job2Name = "Job2";
builder.addJob(job1Name, job1);
builder.addJob(job2Name, job2);
_driver.start(builder.build());
Thread.sleep(2000);
_driver.stop(workflowName);
_driver.pollForWorkflowState(workflowName, TaskState.STOPPING);
// Expect job and workflow stuck in STOPPING state.
WorkflowContext workflowContext = _driver.getWorkflowContext(workflowName);
Assert.assertEquals(workflowContext.getJobState(TaskUtil.getNamespacedJobName(workflowName, job1Name)), TaskState.STOPPING);
}
use of org.apache.helix.task.WorkflowContext in project helix by apache.
the class TestTaskRebalancerStopResume method deleteJobFromRecurrentQueueNotStarted.
@Test
public void deleteJobFromRecurrentQueueNotStarted() throws Exception {
String queueName = TestHelper.getTestMethodName();
// Create a queue
LOG.info("Starting job-queue: " + queueName);
JobQueue.Builder queueBuilder = TaskTestUtil.buildRecurrentJobQueue(queueName);
List<JobConfig.Builder> jobs = new ArrayList<JobConfig.Builder>();
List<String> jobNames = new ArrayList<String>();
Map<String, String> commandConfig = ImmutableMap.of(TIMEOUT_CONFIG, String.valueOf(500));
int JOB_COUNTS = 3;
for (int i = 0; i < JOB_COUNTS; i++) {
String targetPartition = (i == 0) ? "MASTER" : "SLAVE";
String jobName = targetPartition.toLowerCase() + "Job" + i;
JobConfig.Builder job = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).setJobCommandConfigMap(commandConfig).setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB).setTargetPartitionStates(Sets.newHashSet(targetPartition));
jobs.add(job);
jobNames.add(jobName);
}
for (int i = 0; i < JOB_COUNTS - 1; i++) {
queueBuilder.enqueueJob(jobNames.get(i), jobs.get(i));
}
_driver.createQueue(queueBuilder.build());
String currentLastJob = jobNames.get(JOB_COUNTS - 2);
WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
String scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
// ensure all jobs are finished
String namedSpaceJob = String.format("%s_%s", scheduledQueue, currentLastJob);
_driver.pollForJobState(scheduledQueue, namedSpaceJob, TaskState.COMPLETED);
// enqueue the last job
LOG.info("Enqueuing job: " + jobNames.get(JOB_COUNTS - 1));
_driver.enqueueJob(queueName, jobNames.get(JOB_COUNTS - 1), jobs.get(JOB_COUNTS - 1));
// remove the last job
_driver.deleteJob(queueName, jobNames.get(JOB_COUNTS - 1));
// verify
verifyJobDeleted(queueName, String.format("%s_%s", scheduledQueue, jobNames.get(JOB_COUNTS - 1)));
}
use of org.apache.helix.task.WorkflowContext in project helix by apache.
the class TestUpdateWorkflow method testUpdateStoppedQueue.
@Test
public void testUpdateStoppedQueue() throws InterruptedException {
String queueName = TestHelper.getTestMethodName();
// Create a queue
LOG.info("Starting job-queue: " + queueName);
JobQueue queue = createDefaultRecurrentJobQueue(queueName, 2);
_driver.start(queue);
WorkflowContext wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
// ensure current schedule is started
String scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
_driver.pollForWorkflowState(scheduledQueue, TaskState.IN_PROGRESS);
_driver.stop(queueName);
WorkflowConfig workflowConfig = _driver.getWorkflowConfig(queueName);
Assert.assertEquals(workflowConfig.getTargetState(), TargetState.STOP);
WorkflowConfig.Builder configBuilder = new WorkflowConfig.Builder(workflowConfig);
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.SECOND, startTime.get(Calendar.SECOND) + 1);
ScheduleConfig scheduleConfig = ScheduleConfig.recurringFromDate(startTime.getTime(), TimeUnit.MINUTES, 2);
configBuilder.setScheduleConfig(scheduleConfig);
_driver.updateWorkflow(queueName, configBuilder.build());
workflowConfig = _driver.getWorkflowConfig(queueName);
Assert.assertEquals(workflowConfig.getTargetState(), TargetState.STOP);
_driver.resume(queueName);
// ensure current schedule is completed
_driver.pollForWorkflowState(scheduledQueue, TaskState.COMPLETED);
Thread.sleep(1000);
wCtx = TaskTestUtil.pollForWorkflowContext(_driver, queueName);
scheduledQueue = wCtx.getLastScheduledSingleWorkflow();
WorkflowConfig wCfg = _driver.getWorkflowConfig(scheduledQueue);
Calendar configStartTime = Calendar.getInstance();
configStartTime.setTime(wCfg.getStartTime());
Assert.assertTrue((startTime.get(Calendar.HOUR_OF_DAY) == configStartTime.get(Calendar.HOUR_OF_DAY) && startTime.get(Calendar.MINUTE) == configStartTime.get(Calendar.MINUTE) && startTime.get(Calendar.SECOND) == configStartTime.get(Calendar.SECOND)));
}
Aggregations