Search in sources :

Example 16 with TaskConfig

use of org.apache.helix.task.TaskConfig 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)

Example 17 with TaskConfig

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

the class TestIndependentTaskRebalancer method testReassignment.

@Test
public void testReassignment() throws Exception {
    final int NUM_INSTANCES = 5;
    String jobName = TestHelper.getTestMethodName();
    Workflow.Builder workflowBuilder = new Workflow.Builder(jobName);
    List<TaskConfig> taskConfigs = Lists.newArrayListWithCapacity(2);
    Map<String, String> taskConfigMap = Maps.newHashMap(ImmutableMap.of("fail", "" + true, "failInstance", PARTICIPANT_PREFIX + '_' + (_startPort + 1)));
    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);
    _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()));
    // Ensure that this was tried on two different instances, the first of which exhausted the
    // attempts number, and the other passes on the first try
    Assert.assertEquals(_runCounts.size(), 2);
    Assert.assertTrue(_runCounts.values().contains(JobConfig.DEFAULT_MAX_ATTEMPTS_PER_TASK / NUM_INSTANCES));
    Assert.assertTrue(_runCounts.values().contains(1));
}
Also used : Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 18 with TaskConfig

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

the class TestUserContentStore method testWorkflowAndJobTaskUserContentStore.

@Test
public void testWorkflowAndJobTaskUserContentStore() throws InterruptedException {
    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("ContentStoreTask", taskConfigMap);
    taskConfigs.add(taskConfig1);
    Map<String, String> jobCommandMap = Maps.newHashMap();
    jobCommandMap.put("Timeout", "1000");
    JobConfig.Builder jobBuilder = new JobConfig.Builder().setCommand("DummyCommand").addTaskConfigs(taskConfigs).setWorkflow(jobName).setJobCommandConfigMap(jobCommandMap);
    workflowBuilder.addJob(jobName, jobBuilder);
    _driver.start(workflowBuilder.build());
    _driver.pollForWorkflowState(jobName, TaskState.COMPLETED);
    Assert.assertEquals(_driver.getWorkflowContext(jobName).getWorkflowState(), TaskState.COMPLETED);
}
Also used : Workflow(org.apache.helix.task.Workflow) TaskConfig(org.apache.helix.task.TaskConfig) JobConfig(org.apache.helix.task.JobConfig) Test(org.testng.annotations.Test)

Example 19 with TaskConfig

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

the class JobAccessor method getTaskConfigMap.

private static Map<String, TaskConfig> getTaskConfigMap(Map<String, Map<String, String>> taskConfigs) {
    Map<String, TaskConfig> taskConfigsMap = new HashMap<>();
    if (taskConfigs == null || taskConfigs.isEmpty()) {
        return Collections.emptyMap();
    }
    for (Map<String, String> taskConfigMap : taskConfigs.values()) {
        if (!taskConfigMap.containsKey(JobProperties.TASK_COMMAND.name())) {
            continue;
        }
        TaskConfig taskConfig = new TaskConfig(taskConfigMap.get(JobProperties.TASK_COMMAND.name()), taskConfigMap);
        taskConfigsMap.put(taskConfig.getId(), taskConfig);
    }
    return taskConfigsMap;
}
Also used : HashMap(java.util.HashMap) TaskConfig(org.apache.helix.task.TaskConfig)

Aggregations

TaskConfig (org.apache.helix.task.TaskConfig)19 JobConfig (org.apache.helix.task.JobConfig)16 Test (org.testng.annotations.Test)14 Workflow (org.apache.helix.task.Workflow)12 ArrayList (java.util.ArrayList)4 JobContext (org.apache.helix.task.JobContext)4 HashMap (java.util.HashMap)3 TaskPartitionState (org.apache.helix.task.TaskPartitionState)3 WorkflowContext (org.apache.helix.task.WorkflowContext)3 WorkUnit (org.apache.gobblin.source.workunit.WorkUnit)2 Path (org.apache.hadoop.fs.Path)2 JobQueue (org.apache.helix.task.JobQueue)2 TaskCallbackContext (org.apache.helix.task.TaskCallbackContext)2 TaskDriver (org.apache.helix.task.TaskDriver)2 TaskState (org.apache.helix.task.TaskState)2 WorkflowConfig (org.apache.helix.task.WorkflowConfig)2 File (java.io.File)1 Date (java.util.Date)1 OptionParser (joptsimple.OptionParser)1 OptionSet (joptsimple.OptionSet)1