Search in sources :

Example 1 with TaskState

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

the class TestWorkflowAndJobPoll method testWorkflowPoll.

@Test
public void testWorkflowPoll() throws InterruptedException {
    String jobResource = TestHelper.getTestMethodName();
    Workflow.Builder builder = WorkflowGenerator.generateDefaultSingleJobWorkflowBuilder(jobResource);
    _driver.start(builder.build());
    TaskState polledState = _driver.pollForWorkflowState(jobResource, 4000L, TaskState.COMPLETED, TaskState.FAILED);
    Assert.assertEquals(TaskState.COMPLETED, polledState);
}
Also used : Workflow(org.apache.helix.task.Workflow) TaskState(org.apache.helix.task.TaskState) Test(org.testng.annotations.Test)

Example 2 with TaskState

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

the class TaskAdmin method list.

private static void list(TaskDriver taskDriver, String workflow) {
    WorkflowConfig wCfg = taskDriver.getWorkflowConfig(workflow);
    if (wCfg == null) {
        LOG.error("Workflow " + workflow + " does not exist!");
        return;
    }
    WorkflowContext wCtx = taskDriver.getWorkflowContext(workflow);
    LOG.info("Workflow " + workflow + " consists of the following tasks: " + wCfg.getJobDag().getAllNodes());
    String workflowState = (wCtx != null) ? wCtx.getWorkflowState().name() : TaskState.NOT_STARTED.name();
    LOG.info("Current state of workflow is " + workflowState);
    LOG.info("Job states are: ");
    LOG.info("-------");
    for (String job : wCfg.getJobDag().getAllNodes()) {
        TaskState jobState = (wCtx != null) ? wCtx.getJobState(job) : TaskState.NOT_STARTED;
        LOG.info("Job " + job + " is " + jobState);
        // fetch job information
        JobConfig jCfg = taskDriver.getJobConfig(job);
        JobContext jCtx = taskDriver.getJobContext(job);
        if (jCfg == null || jCtx == null) {
            LOG.info("-------");
            continue;
        }
        // calculate taskPartitions
        List<Integer> partitions = Lists.newArrayList(jCtx.getPartitionSet());
        Collections.sort(partitions);
        // report status
        for (Integer partition : partitions) {
            String taskId = jCtx.getTaskIdForPartition(partition);
            taskId = (taskId != null) ? taskId : jCtx.getTargetForPartition(partition);
            LOG.info("Task: " + taskId);
            TaskConfig taskConfig = jCfg.getTaskConfig(taskId);
            if (taskConfig != null) {
                LOG.info("Configuration: " + taskConfig.getConfigMap());
            }
            TaskPartitionState state = jCtx.getPartitionState(partition);
            state = (state != null) ? state : TaskPartitionState.INIT;
            LOG.info("State: " + state);
            String assignedParticipant = jCtx.getAssignedParticipant(partition);
            if (assignedParticipant != null) {
                LOG.info("Assigned participant: " + assignedParticipant);
            }
            LOG.info("-------");
        }
        LOG.info("-------");
    }
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) WorkflowContext(org.apache.helix.task.WorkflowContext) TaskConfig(org.apache.helix.task.TaskConfig) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) TaskState(org.apache.helix.task.TaskState) JobConfig(org.apache.helix.task.JobConfig)

Example 3 with TaskState

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

the class TestGenericTaskAssignmentCalculator method testAbortTaskForWorkflowFail.

@Test
public void testAbortTaskForWorkflowFail() throws InterruptedException {
    failTask = true;
    String workflowName = TestHelper.getTestMethodName();
    Workflow.Builder workflowBuilder = new Workflow.Builder(workflowName);
    List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(1);
    taskConfigs.add(_taskConfig);
    JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").addTaskConfigs(taskConfigs).setJobCommandConfigMap(_jobCommandMap);
    for (int i = 0; i < 5; i++) {
        workflowBuilder.addJob("JOB" + i, jobBuilder);
    }
    _driver.start(workflowBuilder.build());
    _driver.pollForWorkflowState(workflowName, TaskState.FAILED);
    int abortedTask = 0;
    for (TaskState jobState : _driver.getWorkflowContext(workflowName).getJobStates().values()) {
        if (jobState == TaskState.ABORTED) {
            abortedTask++;
        }
    }
    Assert.assertEquals(abortedTask, 4);
}
Also used : Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) TaskState(org.apache.helix.task.TaskState) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 4 with TaskState

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

the class TaskTestUtil method pollForWorkflowParallelState.

// 1. Different jobs in a same work flow is in RUNNING at the same time
// 2. When disallow overlap assignment, no two jobs in the same work flow is in RUNNING at the same instance
// Use this method with caution because it assumes workflow doesn't finish too quickly and number of parallel running
// tasks can be counted.
public static boolean pollForWorkflowParallelState(TaskDriver driver, String workflowName) throws InterruptedException {
    WorkflowConfig workflowConfig = driver.getWorkflowConfig(workflowName);
    Assert.assertNotNull(workflowConfig);
    WorkflowContext workflowContext = null;
    while (workflowContext == null) {
        workflowContext = driver.getWorkflowContext(workflowName);
        Thread.sleep(100);
    }
    int maxRunningCount = 0;
    boolean finished = false;
    while (!finished) {
        finished = true;
        int runningCount = 0;
        workflowContext = driver.getWorkflowContext(workflowName);
        for (String jobName : workflowConfig.getJobDag().getAllNodes()) {
            TaskState jobState = workflowContext.getJobState(jobName);
            if (jobState == TaskState.IN_PROGRESS) {
                ++runningCount;
                finished = false;
            }
        }
        if (runningCount > maxRunningCount) {
            maxRunningCount = runningCount;
        }
        List<JobContext> jobContextList = new ArrayList<JobContext>();
        for (String jobName : workflowConfig.getJobDag().getAllNodes()) {
            JobContext jobContext = driver.getJobContext(jobName);
            if (jobContext != null) {
                jobContextList.add(driver.getJobContext(jobName));
            }
        }
        if (!workflowConfig.isAllowOverlapJobAssignment()) {
            Set<String> instances = new HashSet<String>();
            for (JobContext jobContext : jobContextList) {
                for (int partition : jobContext.getPartitionSet()) {
                    String instance = jobContext.getAssignedParticipant(partition);
                    TaskPartitionState taskPartitionState = jobContext.getPartitionState(partition);
                    if (instance == null) {
                        continue;
                    }
                    if (taskPartitionState != TaskPartitionState.INIT && taskPartitionState != TaskPartitionState.RUNNING) {
                        continue;
                    }
                    if (instances.contains(instance)) {
                        return false;
                    }
                    TaskPartitionState state = jobContext.getPartitionState(partition);
                    if (state != TaskPartitionState.COMPLETED) {
                        instances.add(instance);
                    }
                }
            }
        }
        Thread.sleep(100);
    }
    return maxRunningCount > 1 && (workflowConfig.isJobQueue() ? maxRunningCount <= workflowConfig.getParallelJobs() : true);
}
Also used : WorkflowConfig(org.apache.helix.task.WorkflowConfig) WorkflowContext(org.apache.helix.task.WorkflowContext) ArrayList(java.util.ArrayList) TaskPartitionState(org.apache.helix.task.TaskPartitionState) JobContext(org.apache.helix.task.JobContext) TaskState(org.apache.helix.task.TaskState) HashSet(java.util.HashSet)

Example 5 with TaskState

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

the class TaskTestUtil method buildWorkflowContext.

public static WorkflowContext buildWorkflowContext(String workflowResource, TaskState workflowState, Long startTime, TaskState... jobStates) {
    WorkflowContext workflowContext = new WorkflowContext(new ZNRecord(TaskUtil.WORKFLOW_CONTEXT_KW));
    workflowContext.setName(workflowResource);
    workflowContext.setStartTime(startTime == null ? System.currentTimeMillis() : startTime);
    int jobId = 0;
    for (TaskState jobstate : jobStates) {
        workflowContext.setJobState(TaskUtil.getNamespacedJobName(workflowResource, JOB_KW) + jobId++, jobstate);
    }
    workflowContext.setWorkflowState(workflowState);
    return workflowContext;
}
Also used : WorkflowContext(org.apache.helix.task.WorkflowContext) TaskState(org.apache.helix.task.TaskState) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

TaskState (org.apache.helix.task.TaskState)6 Workflow (org.apache.helix.task.Workflow)3 WorkflowContext (org.apache.helix.task.WorkflowContext)3 Test (org.testng.annotations.Test)3 JobConfig (org.apache.helix.task.JobConfig)2 JobContext (org.apache.helix.task.JobContext)2 TaskConfig (org.apache.helix.task.TaskConfig)2 TaskPartitionState (org.apache.helix.task.TaskPartitionState)2 WorkflowConfig (org.apache.helix.task.WorkflowConfig)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ZNRecord (org.apache.helix.ZNRecord)1