Search in sources :

Example 21 with Workflow

use of org.apache.helix.task.Workflow in project helix by apache.

the class TestTaskRebalancerRetryLimit method test.

@Test
public void test() throws Exception {
    String jobResource = TestHelper.getTestMethodName();
    JobConfig.Builder jobBuilder = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG);
    jobBuilder.setJobCommandConfigMap(WorkflowGenerator.DEFAULT_COMMAND_CONFIG).setMaxAttemptsPerTask(2).setCommand(MockTask.TASK_COMMAND).setFailureThreshold(Integer.MAX_VALUE).setJobCommandConfigMap(ImmutableMap.of(MockTask.THROW_EXCEPTION, "true"));
    Workflow flow = WorkflowGenerator.generateSingleJobWorkflowBuilder(jobResource, jobBuilder).build();
    _driver.start(flow);
    // Wait until the job completes.
    _driver.pollForWorkflowState(jobResource, TaskState.COMPLETED);
    JobContext ctx = _driver.getJobContext(TaskUtil.getNamespacedJobName(jobResource));
    for (int i = 0; i < _numParitions; i++) {
        TaskPartitionState state = ctx.getPartitionState(i);
        if (state != null) {
            Assert.assertEquals(state, TaskPartitionState.TASK_ERROR);
            Assert.assertEquals(ctx.getPartitionNumAttempts(i), 2);
        }
    }
}
Also used : Workflow(org.apache.helix.task.Workflow) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 22 with Workflow

use of org.apache.helix.task.Workflow in project helix by apache.

the class TestTaskRebalancerStopResume method stopAndResume.

@Test
public void stopAndResume() throws Exception {
    Map<String, String> commandConfig = ImmutableMap.of(TIMEOUT_CONFIG, String.valueOf(100));
    JobConfig.Builder jobBuilder = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG);
    jobBuilder.setJobCommandConfigMap(commandConfig);
    Workflow flow = WorkflowGenerator.generateSingleJobWorkflowBuilder(JOB_RESOURCE, jobBuilder).build();
    LOG.info("Starting flow " + flow.getName());
    _driver.start(flow);
    _driver.pollForWorkflowState(JOB_RESOURCE, TaskState.IN_PROGRESS);
    LOG.info("Pausing job");
    _driver.stop(JOB_RESOURCE);
    _driver.pollForWorkflowState(JOB_RESOURCE, TaskState.STOPPED);
    LOG.info("Resuming job");
    _driver.resume(JOB_RESOURCE);
    _driver.pollForWorkflowState(JOB_RESOURCE, TaskState.COMPLETED);
}
Also used : Workflow(org.apache.helix.task.Workflow) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 23 with Workflow

use of org.apache.helix.task.Workflow in project helix by apache.

the class TestTaskRetryDelay method testTaskRetryWithDelay.

@Test
public void testTaskRetryWithDelay() throws Exception {
    String jobResource = TestHelper.getTestMethodName();
    JobConfig.Builder jobBuilder = JobConfig.Builder.fromMap(WorkflowGenerator.DEFAULT_JOB_CONFIG);
    jobBuilder.setJobCommandConfigMap(WorkflowGenerator.DEFAULT_COMMAND_CONFIG).setMaxAttemptsPerTask(2).setCommand(MockTask.TASK_COMMAND).setWorkflow(jobResource).setFailureThreshold(Integer.MAX_VALUE).setTaskRetryDelay(2000L).setJobCommandConfigMap(ImmutableMap.of(MockTask.FAILURE_COUNT_BEFORE_SUCCESS, "2"));
    Workflow flow = WorkflowGenerator.generateSingleJobWorkflowBuilder(jobResource, jobBuilder).build();
    _driver.start(flow);
    // Wait until the job completes.
    _driver.pollForWorkflowState(jobResource, TaskState.COMPLETED);
    long startTime = _driver.getWorkflowContext(jobResource).getStartTime();
    long finishedTime = _driver.getWorkflowContext(jobResource).getFinishTime();
    // It should finished at least 4 secs
    Assert.assertTrue(finishedTime - startTime >= 2000L);
}
Also used : Workflow(org.apache.helix.task.Workflow) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 24 with Workflow

use of org.apache.helix.task.Workflow in project helix by apache.

the class TestTaskWithInstanceDisabled method testTaskWithInstanceDisabled.

@Test
public void testTaskWithInstanceDisabled() throws InterruptedException {
    _setupTool.getClusterManagementTool().enableInstance(CLUSTER_NAME, PARTICIPANT_PREFIX + "_" + (_startPort + 0), false);
    String jobResource = TestHelper.getTestMethodName();
    JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand(MockTask.TASK_COMMAND).setTargetResource(WorkflowGenerator.DEFAULT_TGT_DB);
    Workflow flow = WorkflowGenerator.generateSingleJobWorkflowBuilder(jobResource, jobBuilder).build();
    _driver.start(flow);
    _driver.pollForWorkflowState(jobResource, TaskState.COMPLETED);
    JobContext ctx = _driver.getJobContext(TaskUtil.getNamespacedJobName(jobResource));
    Assert.assertEquals(ctx.getAssignedParticipant(0), PARTICIPANT_PREFIX + "_" + (_startPort + 1));
}
Also used : Workflow(org.apache.helix.task.Workflow) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 25 with Workflow

use of org.apache.helix.task.Workflow in project helix by apache.

the class TestIndependentTaskRebalancer method testOneTimeScheduled.

@Test
public void testOneTimeScheduled() throws Exception {
    String jobName = TestHelper.getTestMethodName();
    Workflow.Builder workflowBuilder = new Workflow.Builder(jobName);
    List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(1);
    Map<String, String> taskConfigMap = Maps.newHashMap();
    TaskConfig taskConfig1 = new TaskConfig("TaskOne", taskConfigMap);
    taskConfigs.add(taskConfig1);
    Map<String, String> jobCommandMap = Maps.newHashMap();
    jobCommandMap.put("Timeout", "1000");
    JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").addTaskConfigs(taskConfigs).setJobCommandConfigMap(jobCommandMap);
    workflowBuilder.addJob(jobName, jobBuilder);
    long inFiveSeconds = System.currentTimeMillis() + (5 * 1000);
    workflowBuilder.setScheduleConfig(ScheduleConfig.oneTimeDelayedStart(new Date(inFiveSeconds)));
    _driver.start(workflowBuilder.build());
    // Ensure the job completes
    _driver.pollForWorkflowState(jobName, TaskState.IN_PROGRESS);
    _driver.pollForWorkflowState(jobName, TaskState.COMPLETED);
    // Ensure that the class was invoked
    Assert.assertTrue(_invokedClasses.contains(TaskOne.class.getName()));
    // Check that the workflow only started after the start time (with a 1 second buffer)
    WorkflowContext workflowCtx = _driver.getWorkflowContext(jobName);
    long startTime = workflowCtx.getStartTime();
    Assert.assertTrue((startTime + 1000) >= inFiveSeconds);
}
Also used : WorkflowContext(org.apache.helix.task.WorkflowContext) Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) JobConfig(org.apache.helix.task.JobConfig) Date(java.util.Date) Test(org.testng.annotations.Test)

Aggregations

Workflow (org.apache.helix.task.Workflow)32 JobConfig (org.apache.helix.task.JobConfig)26 Test (org.testng.annotations.Test)25 JobContext (org.apache.helix.task.JobContext)13 TaskDriver (org.apache.helix.task.TaskDriver)6 WorkflowConfig (org.apache.helix.task.WorkflowConfig)6 WorkflowContext (org.apache.helix.task.WorkflowContext)6 ArrayList (java.util.ArrayList)5 TaskConfig (org.apache.helix.task.TaskConfig)5 HashMap (java.util.HashMap)4 HelixException (org.apache.helix.HelixException)4 TaskPartitionState (org.apache.helix.task.TaskPartitionState)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ZkClient (org.apache.helix.manager.zk.ZkClient)3 Form (org.restlet.data.Form)3 JobQueue (org.apache.helix.task.JobQueue)2 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)2 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)2 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)2