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);
}
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));
}
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);
}
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;
}
Aggregations