Search in sources :

Example 1 with WorkflowContext

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;
        }
    }
}
Also used : WorkflowContext(org.apache.helix.task.WorkflowContext)

Example 2 with WorkflowContext

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);
}
Also used : ObjectNode(org.codehaus.jackson.node.ObjectNode) TaskDriver(org.apache.helix.task.TaskDriver) WorkflowContext(org.apache.helix.task.WorkflowContext) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 3 with WorkflowContext

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);
}
Also used : HashMap(java.util.HashMap) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) WorkflowContext(org.apache.helix.task.WorkflowContext) Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 4 with WorkflowContext

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)));
}
Also used : JobQueue(org.apache.helix.task.JobQueue) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) WorkflowContext(org.apache.helix.task.WorkflowContext) ArrayList(java.util.ArrayList) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 5 with WorkflowContext

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)));
}
Also used : ScheduleConfig(org.apache.helix.task.ScheduleConfig) WorkflowConfig(org.apache.helix.task.WorkflowConfig) JobQueue(org.apache.helix.task.JobQueue) WorkflowContext(org.apache.helix.task.WorkflowContext) Calendar(java.util.Calendar) Test(org.testng.annotations.Test)

Aggregations

WorkflowContext (org.apache.helix.task.WorkflowContext)31 Test (org.testng.annotations.Test)19 JobConfig (org.apache.helix.task.JobConfig)12 JobQueue (org.apache.helix.task.JobQueue)12 WorkflowConfig (org.apache.helix.task.WorkflowConfig)12 JobContext (org.apache.helix.task.JobContext)9 ArrayList (java.util.ArrayList)6 Workflow (org.apache.helix.task.Workflow)6 TaskDriver (org.apache.helix.task.TaskDriver)4 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)3 ZNRecord (org.apache.helix.ZNRecord)3 TaskConfig (org.apache.helix.task.TaskConfig)3 TaskState (org.apache.helix.task.TaskState)3 Calendar (java.util.Calendar)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 HelixException (org.apache.helix.HelixException)2 PropertyKey (org.apache.helix.PropertyKey)2