Search in sources :

Example 11 with Workflow

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

the class TestJobTimeoutTaskNotStarted method testTaskNotStarted.

@Test
public void testTaskNotStarted() throws InterruptedException {
    final String BLOCK_WORKFLOW_NAME = "blockWorkflow";
    final String TIMEOUT_WORKFLOW_NAME = "timeoutWorkflow";
    final String DB_NAME = WorkflowGenerator.DEFAULT_TGT_DB;
    final String TIMEOUT_JOB_1 = "timeoutJob1";
    final String TIMEOUT_JOB_2 = "timeoutJob2";
    // 50 blocking tasks
    JobConfig.Builder blockJobBuilder = new JobConfig.Builder().setWorkflow(BLOCK_WORKFLOW_NAME).setTargetResource(DB_NAME).setTargetPartitionStates(Sets.newHashSet(MasterSlaveSMD.States.MASTER.name())).setCommand(MockTask.TASK_COMMAND).setNumConcurrentTasksPerInstance(_numParitions);
    Workflow.Builder blockWorkflowBuilder = new Workflow.Builder(BLOCK_WORKFLOW_NAME).addJob("blockJob", blockJobBuilder);
    _driver.start(blockWorkflowBuilder.build());
    Assert.assertTrue(TaskTestUtil.pollForAllTasksBlock(_manager.getHelixDataAccessor(), _participants[0].getInstanceName(), _numParitions, 10000));
    // Now, the HelixTask threadpool is full and blocked by blockJob.
    // New tasks assigned to the instance won't start at all.
    // 2 timeout jobs, first one timeout, but won't block the second one to run, the second one also timeout.
    JobConfig.Builder timeoutJobBuilder = new JobConfig.Builder().setWorkflow(TIMEOUT_WORKFLOW_NAME).setTargetResource(DB_NAME).setTargetPartitionStates(Sets.newHashSet(MasterSlaveSMD.States.MASTER.name())).setCommand(MockTask.TASK_COMMAND).setNumConcurrentTasksPerInstance(_numParitions).setTimeout(// Wait a bit so that tasks are already assigned to the job (and will be cancelled)
    3000);
    WorkflowConfig.Builder timeoutWorkflowConfigBuilder = new WorkflowConfig.Builder(TIMEOUT_WORKFLOW_NAME).setFailureThreshold(// workflow ignores first job's timeout and schedule second job and succeed.
    1);
    Workflow.Builder timeoutWorkflowBuilder = new Workflow.Builder(TIMEOUT_WORKFLOW_NAME).setWorkflowConfig(timeoutWorkflowConfigBuilder.build()).addJob(TIMEOUT_JOB_1, // job 1 timeout, but won't block job 2
    timeoutJobBuilder);
    // ignore first job's timeout
    timeoutJobBuilder.setIgnoreDependentJobFailure(true);
    // job 2 also timeout
    timeoutWorkflowBuilder.addJob(TIMEOUT_JOB_2, timeoutJobBuilder).addParentChildDependency(TIMEOUT_JOB_1, TIMEOUT_JOB_2);
    _driver.start(timeoutWorkflowBuilder.build());
    _driver.pollForJobState(TIMEOUT_WORKFLOW_NAME, TaskUtil.getNamespacedJobName(TIMEOUT_WORKFLOW_NAME, TIMEOUT_JOB_1), TaskState.TIMED_OUT);
    _driver.pollForJobState(TIMEOUT_WORKFLOW_NAME, TaskUtil.getNamespacedJobName(TIMEOUT_WORKFLOW_NAME, TIMEOUT_JOB_2), TaskState.TIMED_OUT);
    _driver.pollForWorkflowState(TIMEOUT_WORKFLOW_NAME, TaskState.FAILED);
    JobContext jobContext = _driver.getJobContext(TaskUtil.getNamespacedJobName(TIMEOUT_WORKFLOW_NAME, TIMEOUT_JOB_1));
    for (int pId : jobContext.getPartitionSet()) {
        // All tasks stuck at INIT->RUNNING, and state transition cancelled and marked TASK_ABORTED
        Assert.assertEquals(jobContext.getPartitionState(pId), TaskPartitionState.TASK_ABORTED);
    }
    jobContext = _driver.getJobContext(TaskUtil.getNamespacedJobName(TIMEOUT_WORKFLOW_NAME, TIMEOUT_JOB_2));
    for (int pId : jobContext.getPartitionSet()) {
        // All tasks stuck at INIT->RUNNING, and state transition cancelled and marked TASK_ABORTED
        Assert.assertEquals(jobContext.getPartitionState(pId), TaskPartitionState.TASK_ABORTED);
    }
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) Workflow(org.apache.helix.task.Workflow) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 12 with Workflow

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

the class TestRebalanceRunningTask method testFixedTargetTaskAndEnabledRebalanceAndNodeAdded.

/**
 * Task type: fixed target
 * Rebalance raunning task: enabled
 * Story: new node added
 */
@Test
public void testFixedTargetTaskAndEnabledRebalanceAndNodeAdded() throws InterruptedException {
    WORKFLOW = TestHelper.getTestMethodName();
    JobConfig.Builder jobBuilder = new JobConfig.Builder().setWorkflow(WORKFLOW).setTargetResource(DATABASE).setTargetPartitionStates(Sets.newHashSet(MasterSlaveSMD.States.MASTER.name())).setNumConcurrentTasksPerInstance(100).setRebalanceRunningTask(true).setCommand(MockTask.TASK_COMMAND).setJobCommandConfigMap(// task stuck
    ImmutableMap.of(MockTask.TIMEOUT_CONFIG, "99999999"));
    Workflow.Builder workflowBuilder = new Workflow.Builder(WORKFLOW).addJob(JOB, jobBuilder);
    _driver.start(workflowBuilder.build());
    // All tasks stuck on the same instance
    Assert.assertTrue(checkTasksOnSameInstances());
    // Add a new instance, partition is rebalanced
    startParticipant(_initialNumNodes);
    HelixClusterVerifier clusterVerifier = new BestPossibleExternalViewVerifier.Builder(CLUSTER_NAME).setZkClient(_gZkClient).setResources(Sets.newHashSet(DATABASE)).build();
    Assert.assertTrue(clusterVerifier.verify(10 * 1000));
    // Running tasks are also rebalanced
    Assert.assertTrue(checkTasksOnDifferentInstances());
}
Also used : HelixClusterVerifier(org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier) Workflow(org.apache.helix.task.Workflow) BestPossibleExternalViewVerifier(org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 13 with Workflow

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

the class TestRetrieveWorkflows method testGetAllWorkflows.

@Test
public void testGetAllWorkflows() throws Exception {
    List<Workflow> workflowList = new ArrayList<Workflow>();
    for (int i = 0; i < 2; i++) {
        Workflow workflow = WorkflowGenerator.generateDefaultRepeatedJobWorkflowBuilder(TestHelper.getTestMethodName() + i).build();
        _driver.start(workflow);
        workflowList.add(workflow);
    }
    for (Workflow workflow : workflowList) {
        _driver.pollForWorkflowState(workflow.getName(), TaskState.COMPLETED);
    }
    Map<String, WorkflowConfig> workflowConfigMap = _driver.getWorkflows();
    Assert.assertEquals(workflowConfigMap.size(), workflowList.size());
    for (Map.Entry<String, WorkflowConfig> workflow : workflowConfigMap.entrySet()) {
        WorkflowConfig workflowConfig = workflow.getValue();
        WorkflowContext workflowContext = _driver.getWorkflowContext(workflow.getKey());
        Assert.assertNotNull(workflowContext);
        for (String job : workflowConfig.getJobDag().getAllNodes()) {
            JobConfig jobConfig = _driver.getJobConfig(job);
            JobContext jobContext = _driver.getJobContext(job);
            Assert.assertNotNull(jobConfig);
            Assert.assertNotNull(jobContext);
        }
    }
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) WorkflowContext(org.apache.helix.task.WorkflowContext) ArrayList(java.util.ArrayList) Workflow(org.apache.helix.task.Workflow) JobContext(org.apache.helix.task.JobContext) Map(java.util.Map) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 14 with Workflow

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

the class TestTaskConditionalRetry method test.

@Test
public void test() throws Exception {
    int taskRetryCount = 5;
    int num_tasks = 5;
    String jobResource = TestHelper.getTestMethodName();
    JobConfig.Builder jobBuilder = new JobConfig.Builder();
    jobBuilder.setCommand(MockTask.TASK_COMMAND).setTimeoutPerTask(10000).setMaxAttemptsPerTask(taskRetryCount).setFailureThreshold(Integer.MAX_VALUE);
    // create each task configs.
    final int abortedTask = 1;
    final int failedTask = 2;
    final int exceptionTask = 3;
    List<TaskConfig> taskConfigs = new ArrayList<TaskConfig>();
    for (int j = 0; j < num_tasks; j++) {
        TaskConfig.Builder configBuilder = new TaskConfig.Builder().setTaskId("task_" + j);
        switch(j) {
            case abortedTask:
                configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FATAL_FAILED.name());
                break;
            case failedTask:
                configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FAILED.name());
                break;
            case exceptionTask:
                configBuilder.addConfig(MockTask.THROW_EXCEPTION, Boolean.TRUE.toString());
                break;
            default:
                break;
        }
        configBuilder.setTargetPartition(String.valueOf(j));
        taskConfigs.add(configBuilder.build());
    }
    jobBuilder.addTaskConfigs(taskConfigs);
    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 < num_tasks; i++) {
        TaskPartitionState state = ctx.getPartitionState(i);
        int retriedCount = ctx.getPartitionNumAttempts(i);
        String taskId = ctx.getTaskIdForPartition(i);
        if (taskId.equals("task_" + abortedTask)) {
            Assert.assertEquals(state, TaskPartitionState.TASK_ABORTED);
            Assert.assertEquals(retriedCount, 1);
        } else if (taskId.equals("task_" + failedTask) || taskId.equals("task_" + exceptionTask)) {
            Assert.assertEquals(state, TaskPartitionState.TASK_ERROR);
            Assert.assertEquals(retriedCount, taskRetryCount);
        } else {
            Assert.assertEquals(state, TaskPartitionState.COMPLETED);
            Assert.assertEquals(retriedCount, 1);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 15 with Workflow

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

the class TestTaskErrorReporting method test.

@Test
public void test() throws Exception {
    int taskRetryCount = 1;
    int num_tasks = 5;
    String jobResource = TestHelper.getTestMethodName();
    JobConfig.Builder jobBuilder = new JobConfig.Builder();
    jobBuilder.setCommand(MockTask.TASK_COMMAND).setTimeoutPerTask(10000).setMaxAttemptsPerTask(taskRetryCount).setFailureThreshold(Integer.MAX_VALUE);
    // create each task configs.
    final int abortedTask = 1;
    final int failedTask = 2;
    final int exceptionTask = 3;
    final String abortedMsg = "This task aborted, some terrible things must happened.";
    final String failedMsg = "This task failed, something may be wrong.";
    final String exceptionMsg = "This task throws exception.";
    final String successMsg = "Yes, we did it!";
    List<TaskConfig> taskConfigs = new ArrayList<TaskConfig>();
    for (int j = 0; j < num_tasks; j++) {
        TaskConfig.Builder configBuilder = new TaskConfig.Builder().setTaskId("task_" + j);
        switch(j) {
            case abortedTask:
                configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FATAL_FAILED.name()).addConfig(MockTask.ERROR_MESSAGE, abortedMsg);
                break;
            case failedTask:
                configBuilder.addConfig(MockTask.TASK_RESULT_STATUS, TaskResult.Status.FAILED.name()).addConfig(MockTask.ERROR_MESSAGE, failedMsg);
                break;
            case exceptionTask:
                configBuilder.addConfig(MockTask.THROW_EXCEPTION, Boolean.TRUE.toString()).addConfig(MockTask.ERROR_MESSAGE, exceptionMsg);
                break;
            default:
                configBuilder.addConfig(MockTask.ERROR_MESSAGE, successMsg);
                break;
        }
        configBuilder.setTargetPartition(String.valueOf(j));
        taskConfigs.add(configBuilder.build());
    }
    jobBuilder.addTaskConfigs(taskConfigs);
    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 < num_tasks; i++) {
        TaskPartitionState state = ctx.getPartitionState(i);
        String taskId = ctx.getTaskIdForPartition(i);
        String errMsg = ctx.getPartitionInfo(i);
        if (taskId.equals("task_" + abortedTask)) {
            Assert.assertEquals(state, TaskPartitionState.TASK_ABORTED);
            Assert.assertEquals(errMsg, abortedMsg);
        } else if (taskId.equals("task_" + failedTask)) {
            Assert.assertEquals(state, TaskPartitionState.TASK_ERROR);
            Assert.assertEquals(errMsg, failedMsg);
        } else if (taskId.equals("task_" + exceptionTask)) {
            Assert.assertEquals(state, TaskPartitionState.TASK_ERROR);
            Assert.assertTrue(errMsg.contains(exceptionMsg));
        } else {
            Assert.assertEquals(state, TaskPartitionState.COMPLETED);
            Assert.assertEquals(errMsg, successMsg);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) JobConfig(org.apache.helix.task.JobConfig) 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