Java Code Examples for org.apache.hadoop.mapreduce.v2.api.records.TaskId#setJobId()

The following examples show how to use org.apache.hadoop.mapreduce.v2.api.records.TaskId#setJobId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestBlocks.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private Task getTask(long timestamp) {
  
  JobId jobId = new JobIdPBImpl();
  jobId.setId(0);
  jobId.setAppId(ApplicationIdPBImpl.newInstance(timestamp,1));

  TaskId taskId = new TaskIdPBImpl();
  taskId.setId(0);
  taskId.setTaskType(TaskType.REDUCE);
  taskId.setJobId(jobId);
  Task task = mock(Task.class);
  when(task.getID()).thenReturn(taskId);
  TaskReport report = mock(TaskReport.class);
  when(report.getProgress()).thenReturn(0.7f);
  when(report.getTaskState()).thenReturn(TaskState.SUCCEEDED);
  when(report.getStartTime()).thenReturn(100001L);
  when(report.getFinishTime()).thenReturn(100011L);

  when(task.getReport()).thenReturn(report);
  when(task.getType()).thenReturn(TaskType.REDUCE);
  return task;
}
 
Example 2
Source File: TestBlocks.java    From big-c with Apache License 2.0 6 votes vote down vote up
private Task getTask(long timestamp) {
  
  JobId jobId = new JobIdPBImpl();
  jobId.setId(0);
  jobId.setAppId(ApplicationIdPBImpl.newInstance(timestamp,1));

  TaskId taskId = new TaskIdPBImpl();
  taskId.setId(0);
  taskId.setTaskType(TaskType.REDUCE);
  taskId.setJobId(jobId);
  Task task = mock(Task.class);
  when(task.getID()).thenReturn(taskId);
  TaskReport report = mock(TaskReport.class);
  when(report.getProgress()).thenReturn(0.7f);
  when(report.getTaskState()).thenReturn(TaskState.SUCCEEDED);
  when(report.getStartTime()).thenReturn(100001L);
  when(report.getFinishTime()).thenReturn(100011L);

  when(task.getReport()).thenReturn(report);
  when(task.getType()).thenReturn(TaskType.REDUCE);
  return task;
}
 
Example 3
Source File: TestTaskImpl.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private TaskId getNewTaskID() {
  TaskId taskId = Records.newRecord(TaskId.class);
  taskId.setId(++taskCounter);
  taskId.setJobId(jobId);
  taskId.setTaskType(mockTask.getType());    
  return taskId;
}
 
Example 4
Source File: TypeConverter.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static TaskId toYarn(org.apache.hadoop.mapreduce.TaskID id) {
  TaskId taskId = recordFactory.newRecordInstance(TaskId.class);
  taskId.setId(id.getId());
  taskId.setTaskType(toYarn(id.getTaskType()));
  taskId.setJobId(toYarn(id.getJobID()));
  return taskId;
}
 
Example 5
Source File: MRBuilderUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public static TaskId newTaskId(JobId jobId, int id, TaskType taskType) {
  TaskId taskId = Records.newRecord(TaskId.class);
  taskId.setJobId(jobId);
  taskId.setId(id);
  taskId.setTaskType(taskType);
  return taskId;
}
 
Example 6
Source File: TestMRApps.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 120000)
public void testTaskIDtoString() {
  TaskId tid = RecordFactoryProvider.getRecordFactory(null).newRecordInstance(TaskId.class);
  tid.setJobId(RecordFactoryProvider.getRecordFactory(null).newRecordInstance(JobId.class));
  tid.getJobId().setAppId(ApplicationId.newInstance(0, 0));
  tid.setTaskType(TaskType.MAP);
  TaskType type = tid.getTaskType();
  System.err.println(type);
  type = TaskType.REDUCE;
  System.err.println(type);
  System.err.println(tid.getTaskType());
  assertEquals("task_0_0000_m_000000", MRApps.toString(tid));
  tid.setTaskType(TaskType.REDUCE);
  assertEquals("task_0_0000_r_000000", MRApps.toString(tid));
}
 
Example 7
Source File: TestTaskImpl.java    From big-c with Apache License 2.0 5 votes vote down vote up
private TaskId getNewTaskID() {
  TaskId taskId = Records.newRecord(TaskId.class);
  taskId.setId(++taskCounter);
  taskId.setJobId(jobId);
  taskId.setTaskType(mockTask.getType());    
  return taskId;
}
 
Example 8
Source File: TypeConverter.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static TaskId toYarn(org.apache.hadoop.mapreduce.TaskID id) {
  TaskId taskId = recordFactory.newRecordInstance(TaskId.class);
  taskId.setId(id.getId());
  taskId.setTaskType(toYarn(id.getTaskType()));
  taskId.setJobId(toYarn(id.getJobID()));
  return taskId;
}
 
Example 9
Source File: MRBuilderUtils.java    From big-c with Apache License 2.0 5 votes vote down vote up
public static TaskId newTaskId(JobId jobId, int id, TaskType taskType) {
  TaskId taskId = Records.newRecord(TaskId.class);
  taskId.setJobId(jobId);
  taskId.setId(id);
  taskId.setTaskType(taskType);
  return taskId;
}
 
Example 10
Source File: TestMRApps.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test (timeout = 120000)
public void testTaskIDtoString() {
  TaskId tid = RecordFactoryProvider.getRecordFactory(null).newRecordInstance(TaskId.class);
  tid.setJobId(RecordFactoryProvider.getRecordFactory(null).newRecordInstance(JobId.class));
  tid.getJobId().setAppId(ApplicationId.newInstance(0, 0));
  tid.setTaskType(TaskType.MAP);
  TaskType type = tid.getTaskType();
  System.err.println(type);
  type = TaskType.REDUCE;
  System.err.println(type);
  System.err.println(tid.getTaskType());
  assertEquals("task_0_0000_m_000000", MRApps.toString(tid));
  tid.setTaskType(TaskType.REDUCE);
  assertEquals("task_0_0000_r_000000", MRApps.toString(tid));
}
 
Example 11
Source File: TestBlocks.java    From hadoop with Apache License 2.0 4 votes vote down vote up
/**
 * Test rendering for TasksBlock
 */
@Test
public void testTasksBlock() throws Exception {

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 1);
  JobId jobId = new JobIdPBImpl();
  jobId.setId(0);
  jobId.setAppId(appId);

  TaskId taskId = new TaskIdPBImpl();
  taskId.setId(0);
  taskId.setTaskType(TaskType.MAP);
  taskId.setJobId(jobId);
  Task task = mock(Task.class);
  when(task.getID()).thenReturn(taskId);
  TaskReport report = mock(TaskReport.class);
  when(report.getProgress()).thenReturn(0.7f);
  when(report.getTaskState()).thenReturn(TaskState.SUCCEEDED);
  when(report.getStartTime()).thenReturn(100001L);
  when(report.getFinishTime()).thenReturn(100011L);
  when(report.getStatus()).thenReturn("Dummy Status \n*");


  when(task.getReport()).thenReturn(report);
  when(task.getType()).thenReturn(TaskType.MAP);


  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(taskId, task);
  AppContext ctx = mock(AppContext.class);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);


  App app = new App(ctx);
  app.setJob(job);
  TasksBlockForTest taskBlock = new TasksBlockForTest(app);
  taskBlock.addParameter(AMParams.TASK_TYPE, "m");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  taskBlock.render(html);
  pWriter.flush();
  assertTrue(data.toString().contains("task_0_0001_m_000000"));
  assertTrue(data.toString().contains("70.00"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertFalse(data.toString().contains("Dummy Status \n*"));
  assertTrue(data.toString().contains("Dummy Status \\n*"));


}
 
Example 12
Source File: MockJobs.java    From hadoop with Apache License 2.0 4 votes vote down vote up
public static Task newTask(JobId jid, int i, int m, final boolean hasFailedTasks) {
  final TaskId tid = Records.newRecord(TaskId.class);
  tid.setJobId(jid);
  tid.setId(i);
  tid.setTaskType(TASK_TYPES.next());
  final TaskReport report = newTaskReport(tid);
  final Map<TaskAttemptId, TaskAttempt> attempts = newTaskAttempts(tid, m);
  return new Task() {
    @Override
    public TaskId getID() {
      return tid;
    }

    @Override
    public TaskReport getReport() {
      return report;
    }

    @Override
    public Counters getCounters() {
      if (hasFailedTasks) {
        return null;
      }
      return new Counters(
        TypeConverter.fromYarn(report.getCounters()));
    }

    @Override
    public float getProgress() {
      return report.getProgress();
    }

    @Override
    public TaskType getType() {
      return tid.getTaskType();
    }

    @Override
    public Map<TaskAttemptId, TaskAttempt> getAttempts() {
      return attempts;
    }

    @Override
    public TaskAttempt getAttempt(TaskAttemptId attemptID) {
      return attempts.get(attemptID);
    }

    @Override
    public boolean isFinished() {
      switch (report.getTaskState()) {
      case SUCCEEDED:
      case KILLED:
      case FAILED:
        return true;
      }
      return false;
    }

    @Override
    public boolean canCommit(TaskAttemptId taskAttemptID) {
      return false;
    }

    @Override
    public TaskState getState() {
      return report.getTaskState();
    }
  };
}
 
Example 13
Source File: TestBlocks.java    From big-c with Apache License 2.0 4 votes vote down vote up
/**
 * Test rendering for TasksBlock
 */
@Test
public void testTasksBlock() throws Exception {

  ApplicationId appId = ApplicationIdPBImpl.newInstance(0, 1);
  JobId jobId = new JobIdPBImpl();
  jobId.setId(0);
  jobId.setAppId(appId);

  TaskId taskId = new TaskIdPBImpl();
  taskId.setId(0);
  taskId.setTaskType(TaskType.MAP);
  taskId.setJobId(jobId);
  Task task = mock(Task.class);
  when(task.getID()).thenReturn(taskId);
  TaskReport report = mock(TaskReport.class);
  when(report.getProgress()).thenReturn(0.7f);
  when(report.getTaskState()).thenReturn(TaskState.SUCCEEDED);
  when(report.getStartTime()).thenReturn(100001L);
  when(report.getFinishTime()).thenReturn(100011L);
  when(report.getStatus()).thenReturn("Dummy Status \n*");


  when(task.getReport()).thenReturn(report);
  when(task.getType()).thenReturn(TaskType.MAP);


  Map<TaskId, Task> tasks = new HashMap<TaskId, Task>();
  tasks.put(taskId, task);
  AppContext ctx = mock(AppContext.class);
  Job job = mock(Job.class);
  when(job.getTasks()).thenReturn(tasks);


  App app = new App(ctx);
  app.setJob(job);
  TasksBlockForTest taskBlock = new TasksBlockForTest(app);
  taskBlock.addParameter(AMParams.TASK_TYPE, "m");

  PrintWriter pWriter = new PrintWriter(data);
  Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false);

  taskBlock.render(html);
  pWriter.flush();
  assertTrue(data.toString().contains("task_0_0001_m_000000"));
  assertTrue(data.toString().contains("70.00"));
  assertTrue(data.toString().contains("SUCCEEDED"));
  assertTrue(data.toString().contains("100001"));
  assertTrue(data.toString().contains("100011"));
  assertFalse(data.toString().contains("Dummy Status \n*"));
  assertTrue(data.toString().contains("Dummy Status \\n*"));


}
 
Example 14
Source File: MockJobs.java    From big-c with Apache License 2.0 4 votes vote down vote up
public static Task newTask(JobId jid, int i, int m, final boolean hasFailedTasks) {
  final TaskId tid = Records.newRecord(TaskId.class);
  tid.setJobId(jid);
  tid.setId(i);
  tid.setTaskType(TASK_TYPES.next());
  final TaskReport report = newTaskReport(tid);
  final Map<TaskAttemptId, TaskAttempt> attempts = newTaskAttempts(tid, m);
  return new Task() {
    @Override
    public TaskId getID() {
      return tid;
    }

    @Override
    public TaskReport getReport() {
      return report;
    }

    @Override
    public Counters getCounters() {
      if (hasFailedTasks) {
        return null;
      }
      return new Counters(
        TypeConverter.fromYarn(report.getCounters()));
    }

    @Override
    public float getProgress() {
      return report.getProgress();
    }

    @Override
    public TaskType getType() {
      return tid.getTaskType();
    }

    @Override
    public Map<TaskAttemptId, TaskAttempt> getAttempts() {
      return attempts;
    }

    @Override
    public TaskAttempt getAttempt(TaskAttemptId attemptID) {
      return attempts.get(attemptID);
    }

    @Override
    public boolean isFinished() {
      switch (report.getTaskState()) {
      case SUCCEEDED:
      case KILLED:
      case FAILED:
        return true;
      }
      return false;
    }

    @Override
    public boolean canCommit(TaskAttemptId taskAttemptID) {
      return false;
    }

    @Override
    public TaskState getState() {
      return report.getTaskState();
    }
  };
}