Search in sources :

Example 16 with JobConfig

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);
}
Also used : RunTaskCommand(alluxio.grpc.RunTaskCommand) Serializable(java.io.Serializable) RunTaskContext(alluxio.job.RunTaskContext) JobConfig(alluxio.job.JobConfig) SleepJobConfig(alluxio.job.SleepJobConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with JobConfig

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());
}
Also used : RunTaskCommand(alluxio.grpc.RunTaskCommand) Serializable(java.io.Serializable) RunTaskContext(alluxio.job.RunTaskContext) SleepJobConfig(alluxio.job.SleepJobConfig) JobConfig(alluxio.job.JobConfig) SleepJobConfig(alluxio.job.SleepJobConfig) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with JobConfig

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;
}
Also used : Serializable(java.io.Serializable) WorkerInfo(alluxio.wire.WorkerInfo) BatchedJobConfig(alluxio.job.plan.BatchedJobConfig) JobConfig(alluxio.job.JobConfig) AbstractVoidPlanDefinition(alluxio.job.plan.AbstractVoidPlanDefinition) PlanDefinition(alluxio.job.plan.PlanDefinition) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pair(alluxio.collections.Pair)

Example 19 with JobConfig

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));
}
Also used : TestPlanConfig(alluxio.job.TestPlanConfig) PlanInfo(alluxio.job.plan.meta.PlanInfo) JobConfig(alluxio.job.JobConfig) Test(org.junit.Test)

Example 20 with JobConfig

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());
}
Also used : TestPlanConfig(alluxio.job.TestPlanConfig) PlanInfo(alluxio.job.plan.meta.PlanInfo) JobConfig(alluxio.job.JobConfig) Test(org.junit.Test)

Aggregations

JobConfig (alluxio.job.JobConfig)26 Test (org.junit.Test)17 SleepJobConfig (alluxio.job.SleepJobConfig)10 TestPlanConfig (alluxio.job.TestPlanConfig)9 Serializable (java.io.Serializable)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 JobServerContext (alluxio.job.JobServerContext)5 CompositeConfig (alluxio.job.workflow.composite.CompositeConfig)5 CommandManager (alluxio.master.job.command.CommandManager)5 WorkerInfo (alluxio.wire.WorkerInfo)5 ArrayList (java.util.ArrayList)5 JobDoesNotExistException (alluxio.exception.JobDoesNotExistException)4 BatchedJobConfig (alluxio.job.plan.BatchedJobConfig)4 PlanInfo (alluxio.job.plan.meta.PlanInfo)4 ResourceExhaustedException (alluxio.exception.status.ResourceExhaustedException)3 RunTaskCommand (alluxio.grpc.RunTaskCommand)3 RunTaskContext (alluxio.job.RunTaskContext)3 CompactConfig (alluxio.job.plan.transform.CompactConfig)3 WorkflowInfo (alluxio.job.wire.WorkflowInfo)3 PlanCoordinator (alluxio.master.job.plan.PlanCoordinator)3