use of alluxio.job.JobConfig in project alluxio by Alluxio.
the class TaskExecutorTest method runCompletion.
@Test
public void runCompletion() throws Exception {
long jobId = 1;
long taskId = 2;
JobConfig jobConfig = mock(JobConfig.class);
Serializable taskArgs = Lists.newArrayList(1);
RunTaskContext context = mock(RunTaskContext.class);
Integer taskResult = 1;
@SuppressWarnings("unchecked") PlanDefinition<JobConfig, Serializable, Serializable> planDefinition = mock(PlanDefinition.class);
when(mRegistry.getJobDefinition(any(JobConfig.class))).thenReturn(planDefinition);
when(planDefinition.runTask(any(JobConfig.class), eq(taskArgs), any(RunTaskContext.class))).thenReturn(taskResult);
RunTaskCommand command = RunTaskCommand.newBuilder().setJobConfig(ByteString.copyFrom(SerializationUtils.serialize(jobConfig))).setTaskArgs(ByteString.copyFrom(SerializationUtils.serialize(taskArgs))).build();
TaskExecutor executor = new TaskExecutor(jobId, taskId, command, context, mTaskExecutorManager);
executor.run();
verify(planDefinition).runTask(any(JobConfig.class), eq(taskArgs), eq(context));
verify(mTaskExecutorManager).notifyTaskCompletion(jobId, taskId, taskResult);
}
use of alluxio.job.JobConfig in project alluxio by Alluxio.
the class TaskExecutorTest method runFailure.
@Test
public void runFailure() throws Exception {
long jobId = 1;
long taskId = 2;
JobConfig jobConfig = new SleepJobConfig(10);
Serializable taskArgs = Lists.newArrayList(1);
RunTaskContext context = mock(RunTaskContext.class);
@SuppressWarnings("unchecked") PlanDefinition<JobConfig, Serializable, Serializable> planDefinition = mock(PlanDefinition.class);
when(mRegistry.getJobDefinition(eq(jobConfig))).thenReturn(planDefinition);
when(planDefinition.runTask(eq(jobConfig), any(Serializable.class), any(RunTaskContext.class))).thenThrow(new UnsupportedOperationException("failure"));
RunTaskCommand command = RunTaskCommand.newBuilder().setJobConfig(ByteString.copyFrom(SerializationUtils.serialize(jobConfig))).setTaskArgs(ByteString.copyFrom(SerializationUtils.serialize(taskArgs))).build();
TaskExecutor executor = new TaskExecutor(jobId, taskId, command, context, mTaskExecutorManager);
executor.run();
verify(mTaskExecutorManager).notifyTaskFailure(eq(jobId), eq(taskId), any());
}
use of alluxio.job.JobConfig in project alluxio by Alluxio.
the class BatchedJobDefinition method selectExecutors.
@Override
public Set<Pair<WorkerInfo, BatchedJobTask>> selectExecutors(BatchedJobConfig config, List<WorkerInfo> jobWorkerInfoList, SelectExecutorsContext context) throws Exception {
// get job type and config
String jobType = config.getJobType();
PlanDefinition plan = JobDefinitionFactory.create(jobType);
// convert map to config
final ObjectMapper mapper = new ObjectMapper();
Class<?> jobConfigClass = plan.getJobConfigClass();
Set<Pair<WorkerInfo, BatchedJobTask>> allTasks = Sets.newHashSet();
for (Map<String, String> configMap : config.getJobConfigs()) {
JobConfig jobConfig = (JobConfig) mapper.convertValue(configMap, jobConfigClass);
Set<Pair<WorkerInfo, Serializable>> tasks = plan.selectExecutors(jobConfig, jobWorkerInfoList, context);
for (Pair<WorkerInfo, Serializable> task : tasks) {
BatchedJobTask batchedTask = new BatchedJobTask(jobConfig, task.getSecond());
allTasks.add(new Pair<>(task.getFirst(), batchedTask));
}
}
return allTasks;
}
use of alluxio.job.JobConfig in project alluxio by Alluxio.
the class PlanInfoTest method compare.
@Test
public void compare() {
JobConfig jobConfig = new TestPlanConfig("unused");
PlanInfo a = new PlanInfo(0L, jobConfig, null);
CommonUtils.sleepMs(1);
PlanInfo b = new PlanInfo(0L, jobConfig, null);
Assert.assertEquals(-1, a.compareTo(b));
b.setStatus(Status.RUNNING);
CommonUtils.sleepMs(1);
a.setStatus(Status.RUNNING);
Assert.assertEquals(1, a.compareTo(b));
a.setStatus(Status.COMPLETED);
CommonUtils.sleepMs(1);
b.setStatus(Status.COMPLETED);
Assert.assertEquals(-1, a.compareTo(b));
}
use of alluxio.job.JobConfig in project alluxio by Alluxio.
the class PlanInfoTest method callback.
@Test
public void callback() {
final String result = "I was here!";
JobConfig jobConfig = new TestPlanConfig("unused");
PlanInfo a = new PlanInfo(0L, jobConfig, jobInfo -> jobInfo.setResult(result));
a.setStatus(Status.COMPLETED);
Assert.assertEquals(result, a.getResult());
}
Aggregations