当前位置: 首页>>代码示例>>Java>>正文


Java MRBuilderUtils.newJobId方法代码示例

本文整理汇总了Java中org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils.newJobId方法的典型用法代码示例。如果您正苦于以下问题:Java MRBuilderUtils.newJobId方法的具体用法?Java MRBuilderUtils.newJobId怎么用?Java MRBuilderUtils.newJobId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils的用法示例。


在下文中一共展示了MRBuilderUtils.newJobId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createTce

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
private static TaskAttemptCompletionEvent createTce(int eventId,
    boolean isMap, TaskAttemptCompletionEventStatus status) {
  JobId jid = MRBuilderUtils.newJobId(12345, 1, 1);
  TaskId tid = MRBuilderUtils.newTaskId(jid, 0,
      isMap ? org.apache.hadoop.mapreduce.v2.api.records.TaskType.MAP
          : org.apache.hadoop.mapreduce.v2.api.records.TaskType.REDUCE);
  TaskAttemptId attemptId = MRBuilderUtils.newTaskAttemptId(tid, 0);
  RecordFactory recordFactory =
    RecordFactoryProvider.getRecordFactory(null);
  TaskAttemptCompletionEvent tce = recordFactory
      .newRecordInstance(TaskAttemptCompletionEvent.class);
  tce.setEventId(eventId);
  tce.setAttemptId(attemptId);
  tce.setStatus(status);
  return tce;
}
 
开发者ID:aliyun-beta,项目名称:aliyun-oss-hadoop-fs,代码行数:17,代码来源:TestTaskAttemptListenerImpl.java

示例2: testRenameMapOutputForReduce

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test
public void testRenameMapOutputForReduce() throws Exception {
  final JobConf conf = new JobConf();

  final MROutputFiles mrOutputFiles = new MROutputFiles();
  mrOutputFiles.setConf(conf);

  // make sure both dirs are distinct
  //
  conf.set(MRConfig.LOCAL_DIR, localDirs[0].toString());
  final Path mapOut = mrOutputFiles.getOutputFileForWrite(1);
  conf.set(MRConfig.LOCAL_DIR, localDirs[1].toString());
  final Path mapOutIdx = mrOutputFiles.getOutputIndexFileForWrite(1);
  Assert.assertNotEquals("Paths must be different!",
      mapOut.getParent(), mapOutIdx.getParent());

  // make both dirs part of LOCAL_DIR
  conf.setStrings(MRConfig.LOCAL_DIR, localDirs);

  final FileContext lfc = FileContext.getLocalFSFileContext(conf);
  lfc.create(mapOut, EnumSet.of(CREATE)).close();
  lfc.create(mapOutIdx, EnumSet.of(CREATE)).close();

  final JobId jobId = MRBuilderUtils.newJobId(12345L, 1, 2);
  final TaskId tid = MRBuilderUtils.newTaskId(jobId, 0, TaskType.MAP);
  final TaskAttemptId taid = MRBuilderUtils.newTaskAttemptId(tid, 0);

  LocalContainerLauncher.renameMapOutputForReduce(conf, taid, mrOutputFiles);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:30,代码来源:TestLocalContainerLauncher.java

示例3: getMockMapTask

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
private MapTaskImpl getMockMapTask(long clusterTimestamp, EventHandler eh) {

    ApplicationId appId = ApplicationId.newInstance(clusterTimestamp, 1);
    JobId jobId = MRBuilderUtils.newJobId(appId, 1);

    int partitions = 2;

    Path remoteJobConfFile = mock(Path.class);
    JobConf conf = new JobConf();
    TaskAttemptListener taskAttemptListener = mock(TaskAttemptListener.class);
    Token<JobTokenIdentifier> jobToken =
        (Token<JobTokenIdentifier>) mock(Token.class);
    Credentials credentials = null;
    Clock clock = new SystemClock();
    int appAttemptId = 3;
    MRAppMetrics metrics = mock(MRAppMetrics.class);
    Resource minContainerRequirements = mock(Resource.class);
    when(minContainerRequirements.getMemory()).thenReturn(1000);

    ClusterInfo clusterInfo = mock(ClusterInfo.class);
    AppContext appContext = mock(AppContext.class);
    when(appContext.getClusterInfo()).thenReturn(clusterInfo);

    TaskSplitMetaInfo taskSplitMetaInfo = mock(TaskSplitMetaInfo.class);
    MapTaskImpl mapTask = new MapTaskImpl(jobId, partitions,
        eh, remoteJobConfFile, conf,
        taskSplitMetaInfo, taskAttemptListener, jobToken, credentials, clock,
        appAttemptId, metrics, appContext);
    return mapTask;
  }
 
开发者ID:naver,项目名称:hadoop,代码行数:31,代码来源:TestRecovery.java

示例4: createMapTaskAttemptImplForTest

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
private TaskAttemptImpl createMapTaskAttemptImplForTest(
    EventHandler eventHandler, TaskSplitMetaInfo taskSplitMetaInfo, Clock clock) {
  ApplicationId appId = ApplicationId.newInstance(1, 1);
  JobId jobId = MRBuilderUtils.newJobId(appId, 1);
  TaskId taskId = MRBuilderUtils.newTaskId(jobId, 1, TaskType.MAP);
  TaskAttemptListener taListener = mock(TaskAttemptListener.class);
  Path jobFile = mock(Path.class);
  JobConf jobConf = new JobConf();
  TaskAttemptImpl taImpl =
      new MapTaskAttemptImpl(taskId, 1, eventHandler, jobFile, 1,
          taskSplitMetaInfo, jobConf, taListener, null,
          null, clock, null);
  return taImpl;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:15,代码来源:TestTaskAttempt.java

示例5: testWithSingleElement

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
/**
 * Trivial test case that verifies basic functionality of {@link
 * JobIdHistoryFileInfoMap}
 */
@Test(timeout = 2000)
public void testWithSingleElement() throws InterruptedException {
  JobIdHistoryFileInfoMap mapWithSize = new JobIdHistoryFileInfoMap();

  JobId jobId = MRBuilderUtils.newJobId(1, 1, 1);
  HistoryFileInfo fileInfo1 = Mockito.mock(HistoryFileInfo.class);
  Mockito.when(fileInfo1.getJobId()).thenReturn(jobId);

  // add it twice
  assertEquals("Incorrect return on putIfAbsent()",
      null, mapWithSize.putIfAbsent(jobId, fileInfo1));
  assertEquals("Incorrect return on putIfAbsent()",
      fileInfo1, mapWithSize.putIfAbsent(jobId, fileInfo1));

  // check get()
  assertEquals("Incorrect get()", fileInfo1, mapWithSize.get(jobId));
  assertTrue("Incorrect size()", checkSize(mapWithSize, 1));

  // check navigableKeySet()
  NavigableSet<JobId> set = mapWithSize.navigableKeySet();
  assertEquals("Incorrect navigableKeySet()", 1, set.size());
  assertTrue("Incorrect navigableKeySet()", set.contains(jobId));

  // check values()
  Collection<HistoryFileInfo> values = mapWithSize.values();
  assertEquals("Incorrect values()", 1, values.size());
  assertTrue("Incorrect values()", values.contains(fileInfo1));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:33,代码来源:TestJobIdHistoryFileInfoMap.java

示例6: testAddExisting

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test (timeout = 1000)
public void testAddExisting() {
  JobListCache cache = new JobListCache(2, 1000);

  JobId jobId = MRBuilderUtils.newJobId(1, 1, 1);
  HistoryFileInfo fileInfo = Mockito.mock(HistoryFileInfo.class);
  Mockito.when(fileInfo.getJobId()).thenReturn(jobId);

  cache.addIfAbsent(fileInfo);
  cache.addIfAbsent(fileInfo);
  assertEquals("Incorrect number of cache entries", 1,
      cache.values().size());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:TestJobListCache.java

示例7: testEviction

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test (timeout = 1000)
public void testEviction() throws InterruptedException {
  int maxSize = 2;
  JobListCache cache = new JobListCache(maxSize, 1000);

  JobId jobId1 = MRBuilderUtils.newJobId(1, 1, 1);
  HistoryFileInfo fileInfo1 = Mockito.mock(HistoryFileInfo.class);
  Mockito.when(fileInfo1.getJobId()).thenReturn(jobId1);

  JobId jobId2 = MRBuilderUtils.newJobId(2, 2, 2);
  HistoryFileInfo fileInfo2 = Mockito.mock(HistoryFileInfo.class);
  Mockito.when(fileInfo2.getJobId()).thenReturn(jobId2);

  JobId jobId3 = MRBuilderUtils.newJobId(3, 3, 3);
  HistoryFileInfo fileInfo3 = Mockito.mock(HistoryFileInfo.class);
  Mockito.when(fileInfo3.getJobId()).thenReturn(jobId3);

  cache.addIfAbsent(fileInfo1);
  cache.addIfAbsent(fileInfo2);
  cache.addIfAbsent(fileInfo3);

  Collection <HistoryFileInfo> values;
  for (int i = 0; i < 9; i++) {
    values = cache.values();
    if (values.size() > maxSize) {
      Thread.sleep(100);
    } else {
      assertFalse("fileInfo1 should have been evicted",
        values.contains(fileInfo1));
      return;
    }
  }
  fail("JobListCache didn't delete the extra entry");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:35,代码来源:TestJobListCache.java

示例8: testAverageMergeTime

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test(timeout = 10000)
public void testAverageMergeTime() throws IOException {
  String historyFileName =
      "job_1329348432655_0001-1329348443227-user-Sleep+job-1329348468601-10-1-SUCCEEDED-default.jhist";
  String confFileName =
      "job_1329348432655_0001_conf.xml";
  Configuration conf = new Configuration();
  JobACLsManager jobAclsMgr = new JobACLsManager(conf);
  Path fulleHistoryPath =
      new Path(TestJobHistoryEntities.class.getClassLoader()
          .getResource(historyFileName)
          .getFile());
  Path fullConfPath =
      new Path(TestJobHistoryEntities.class.getClassLoader()
          .getResource(confFileName)
          .getFile());

  HistoryFileInfo info = mock(HistoryFileInfo.class);
  when(info.getConfFile()).thenReturn(fullConfPath);

  JobId jobId = MRBuilderUtils.newJobId(1329348432655l, 1, 1);
  CompletedJob completedJob =
      new CompletedJob(conf, jobId, fulleHistoryPath, true, "user",
          info, jobAclsMgr);
  JobInfo jobInfo = new JobInfo(completedJob);
  // There are 2 tasks with merge time of 45 and 55 respectively. So average
  // merge time should be 50.
  Assert.assertEquals(50L, jobInfo.getAvgMergeTime().longValue());
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:30,代码来源:TestJobInfo.java

示例9: makeTaskAttemptId

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
public static TaskAttemptId makeTaskAttemptId(long ts, int appId, int taskId, 
    TaskType taskType, int id) {
  ApplicationId aID = ApplicationId.newInstance(ts, appId);
  JobId jID = MRBuilderUtils.newJobId(aID, id);
  TaskId tID = MRBuilderUtils.newTaskId(jID, taskId, taskType);
  return MRBuilderUtils.newTaskAttemptId(tID, id);
}
 
开发者ID:yncxcw,项目名称:big-c,代码行数:8,代码来源:TestContainerLauncherImpl.java

示例10: testPreemptReducers

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test(timeout = 30000)
public void testPreemptReducers() throws Exception {
  LOG.info("Running testPreemptReducers");

  Configuration conf = new Configuration();
  MyResourceManager rm = new MyResourceManager(conf);
  rm.start();
  DrainDispatcher dispatcher = (DrainDispatcher) rm.getRMContext()
      .getDispatcher();

  // Submit the application
  RMApp app = rm.submitApp(1024);
  dispatcher.await();

  MockNM amNodeManager = rm.registerNode("amNM:1234", 2048);
  amNodeManager.nodeHeartbeat(true);
  dispatcher.await();

  ApplicationAttemptId appAttemptId = app.getCurrentAppAttempt()
      .getAppAttemptId();
  rm.sendAMLaunched(appAttemptId);
  dispatcher.await();

  JobId jobId = MRBuilderUtils.newJobId(appAttemptId.getApplicationId(), 0);
  Job mockJob = mock(Job.class);
  when(mockJob.getReport()).thenReturn(
      MRBuilderUtils.newJobReport(jobId, "job", "user", JobState.RUNNING, 0,
          0, 0, 0, 0, 0, 0, "jobfile", null, false, ""));
  MyContainerAllocator allocator = new MyContainerAllocator(rm, conf,
      appAttemptId, mockJob, new SystemClock());
  allocator.setMapResourceRequest(BuilderUtils.newResource(1024, 1));
  allocator.setReduceResourceRequest(BuilderUtils.newResource(1024, 1));
  RMContainerAllocator.AssignedRequests assignedRequests =
      allocator.getAssignedRequests();
  RMContainerAllocator.ScheduledRequests scheduledRequests =
      allocator.getScheduledRequests();
  ContainerRequestEvent event1 =
      createReq(jobId, 1, 2048, new String[] { "h1" }, false, false);
  scheduledRequests.maps.put(mock(TaskAttemptId.class),
      new RMContainerRequestor.ContainerRequest(event1, null,null));
  assignedRequests.reduces.put(mock(TaskAttemptId.class),
      mock(Container.class));

  allocator.preemptReducesIfNeeded();
  Assert.assertEquals("The reducer is not preempted",
      1, assignedRequests.preemptionWaitingReduces.size());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:48,代码来源:TestRMContainerAllocator.java

示例11: testKillJob

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
@Test(timeout=10000)
public void testKillJob() throws Exception {
  JobConf conf = new JobConf();
  AppContext context = mock(AppContext.class);
  // a simple event handler solely to detect the container cleaned event
  final CountDownLatch isDone = new CountDownLatch(1);
  EventHandler handler = new EventHandler() {
    @Override
    public void handle(Event event) {
      LOG.info("handling event " + event.getClass() +
          " with type " + event.getType());
      if (event instanceof TaskAttemptEvent) {
        if (event.getType() == TaskAttemptEventType.TA_CONTAINER_CLEANED) {
          isDone.countDown();
        }
      }
    }
  };
  when(context.getEventHandler()).thenReturn(handler);

  // create and start the launcher
  LocalContainerLauncher launcher =
      new LocalContainerLauncher(context, mock(TaskUmbilicalProtocol.class));
  launcher.init(conf);
  launcher.start();

  // create mocked job, task, and task attempt
  // a single-mapper job
  JobId jobId = MRBuilderUtils.newJobId(System.currentTimeMillis(), 1, 1);
  TaskId taskId = MRBuilderUtils.newTaskId(jobId, 1, TaskType.MAP);
  TaskAttemptId taId = MRBuilderUtils.newTaskAttemptId(taskId, 0);

  Job job = mock(Job.class);
  when(job.getTotalMaps()).thenReturn(1);
  when(job.getTotalReduces()).thenReturn(0);
  Map<JobId,Job> jobs = new HashMap<JobId,Job>();
  jobs.put(jobId, job);
  // app context returns the one and only job
  when(context.getAllJobs()).thenReturn(jobs);

  org.apache.hadoop.mapreduce.v2.app.job.Task ytask =
      mock(org.apache.hadoop.mapreduce.v2.app.job.Task.class);
  when(ytask.getType()).thenReturn(TaskType.MAP);
  when(job.getTask(taskId)).thenReturn(ytask);

  // create a sleeping mapper that runs beyond the test timeout
  MapTask mapTask = mock(MapTask.class);
  when(mapTask.isMapOrReduce()).thenReturn(true);
  when(mapTask.isMapTask()).thenReturn(true);
  TaskAttemptID taskID = TypeConverter.fromYarn(taId);
  when(mapTask.getTaskID()).thenReturn(taskID);
  when(mapTask.getJobID()).thenReturn(taskID.getJobID());
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      // sleep for a long time
      LOG.info("sleeping for 5 minutes...");
      Thread.sleep(5*60*1000);
      return null;
    }
  }).when(mapTask).run(isA(JobConf.class), isA(TaskUmbilicalProtocol.class));

  // pump in a task attempt launch event
  ContainerLauncherEvent launchEvent =
      new ContainerRemoteLaunchEvent(taId, null, createMockContainer(), mapTask);
  launcher.handle(launchEvent);

  Thread.sleep(200);
  // now pump in a container clean-up event
  ContainerLauncherEvent cleanupEvent =
      new ContainerLauncherEvent(taId, null, null, null,
          ContainerLauncher.EventType.CONTAINER_REMOTE_CLEANUP);
  launcher.handle(cleanupEvent);

  // wait for the event to fire: this should be received promptly
  isDone.await();

  launcher.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:81,代码来源:TestLocalContainerLauncher.java

示例12: testLaunchFailedWhileKilling

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test
public void testLaunchFailedWhileKilling() throws Exception {
  ApplicationId appId = ApplicationId.newInstance(1, 2);
  ApplicationAttemptId appAttemptId =
    ApplicationAttemptId.newInstance(appId, 0);
  JobId jobId = MRBuilderUtils.newJobId(appId, 1);
  TaskId taskId = MRBuilderUtils.newTaskId(jobId, 1, TaskType.MAP);
  TaskAttemptId attemptId = MRBuilderUtils.newTaskAttemptId(taskId, 0);
  Path jobFile = mock(Path.class);

  MockEventHandler eventHandler = new MockEventHandler();
  TaskAttemptListener taListener = mock(TaskAttemptListener.class);
  when(taListener.getAddress()).thenReturn(new InetSocketAddress("localhost", 0));

  JobConf jobConf = new JobConf();
  jobConf.setClass("fs.file.impl", StubbedFS.class, FileSystem.class);
  jobConf.setBoolean("fs.file.impl.disable.cache", true);
  jobConf.set(JobConf.MAPRED_MAP_TASK_ENV, "");
  jobConf.set(MRJobConfig.APPLICATION_ATTEMPT_ID, "10");

  TaskSplitMetaInfo splits = mock(TaskSplitMetaInfo.class);
  when(splits.getLocations()).thenReturn(new String[] {"127.0.0.1"});

  TaskAttemptImpl taImpl =
    new MapTaskAttemptImpl(taskId, 1, eventHandler, jobFile, 1,
        splits, jobConf, taListener,
        new Token(), new Credentials(),
        new SystemClock(), null);

  NodeId nid = NodeId.newInstance("127.0.0.1", 0);
  ContainerId contId = ContainerId.newContainerId(appAttemptId, 3);
  Container container = mock(Container.class);
  when(container.getId()).thenReturn(contId);
  when(container.getNodeId()).thenReturn(nid);

  taImpl.handle(new TaskAttemptEvent(attemptId,
      TaskAttemptEventType.TA_SCHEDULE));
  taImpl.handle(new TaskAttemptContainerAssignedEvent(attemptId,
      container, mock(Map.class)));
  taImpl.handle(new TaskAttemptEvent(attemptId,
      TaskAttemptEventType.TA_KILL));
  taImpl.handle(new TaskAttemptEvent(attemptId,
      TaskAttemptEventType.TA_CONTAINER_CLEANED));
  taImpl.handle(new TaskAttemptEvent(attemptId,
      TaskAttemptEventType.TA_CONTAINER_LAUNCH_FAILED));
  assertFalse(eventHandler.internalError);
  assertEquals("Task attempt is not assigned on the local node", 
      Locality.NODE_LOCAL, taImpl.getLocality());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:TestTaskAttempt.java

示例13: testAverageReduceTime

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test
public void testAverageReduceTime() {
 
  Job job = mock(CompletedJob.class);
  final Task task1 = mock(Task.class);
  final Task task2 = mock(Task.class);

  JobId  jobId = MRBuilderUtils.newJobId(1L, 1, 1);

  final TaskId taskId1 = MRBuilderUtils.newTaskId(jobId, 1, TaskType.REDUCE);
  final TaskId taskId2 = MRBuilderUtils.newTaskId(jobId, 2, TaskType.REDUCE);

  final TaskAttemptId taskAttemptId1  = MRBuilderUtils.
  		newTaskAttemptId(taskId1, 1);
  final TaskAttemptId taskAttemptId2  = MRBuilderUtils.
  		newTaskAttemptId(taskId2, 2);

  final TaskAttempt taskAttempt1 = mock(TaskAttempt.class);
  final TaskAttempt taskAttempt2 = mock(TaskAttempt.class);

  JobReport jobReport = mock(JobReport.class);

  when(taskAttempt1.getState()).thenReturn(TaskAttemptState.SUCCEEDED);
  when(taskAttempt1.getLaunchTime()).thenReturn(0L);
  when(taskAttempt1.getShuffleFinishTime()).thenReturn(4L);
  when(taskAttempt1.getSortFinishTime()).thenReturn(6L);
  when(taskAttempt1.getFinishTime()).thenReturn(8L);

  when(taskAttempt2.getState()).thenReturn(TaskAttemptState.SUCCEEDED);
  when(taskAttempt2.getLaunchTime()).thenReturn(5L);
  when(taskAttempt2.getShuffleFinishTime()).thenReturn(10L);
  when(taskAttempt2.getSortFinishTime()).thenReturn(22L);
  when(taskAttempt2.getFinishTime()).thenReturn(42L);


  when(task1.getType()).thenReturn(TaskType.REDUCE);
  when(task2.getType()).thenReturn(TaskType.REDUCE);
  when(task1.getAttempts()).thenReturn
    (new HashMap<TaskAttemptId, TaskAttempt>() 
  		{{put(taskAttemptId1,taskAttempt1); }});
  when(task2.getAttempts()).thenReturn
    (new HashMap<TaskAttemptId, TaskAttempt>() 
  		  {{put(taskAttemptId2,taskAttempt2); }});

  when(job.getTasks()).thenReturn
    (new HashMap<TaskId, Task>() 
  		{{ put(taskId1,task1); put(taskId2, task2);  }});
  when(job.getID()).thenReturn(jobId);

  when(job.getReport()).thenReturn(jobReport);

  when(job.getName()).thenReturn("TestJobInfo");	  
  when(job.getState()).thenReturn(JobState.SUCCEEDED);	  

  JobInfo jobInfo = new JobInfo(job);

  Assert.assertEquals(11L, jobInfo.getAvgReduceTime().longValue());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:59,代码来源:TestJobInfo.java

示例14: testMapReduceAllocationWithNodeLabelExpression

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test
public void testMapReduceAllocationWithNodeLabelExpression() throws Exception {

  LOG.info("Running testMapReduceAllocationWithNodeLabelExpression");
  Configuration conf = new Configuration();
  /*
   * final int MAP_LIMIT = 3; final int REDUCE_LIMIT = 1;
   * conf.setInt(MRJobConfig.JOB_RUNNING_MAP_LIMIT, MAP_LIMIT);
   * conf.setInt(MRJobConfig.JOB_RUNNING_REDUCE_LIMIT, REDUCE_LIMIT);
   */
  conf.setFloat(MRJobConfig.COMPLETED_MAPS_FOR_REDUCE_SLOWSTART, 1.0f);
  conf.set(MRJobConfig.MAP_NODE_LABEL_EXP, "MapNodes");
  conf.set(MRJobConfig.REDUCE_NODE_LABEL_EXP, "ReduceNodes");
  ApplicationId appId = ApplicationId.newInstance(1, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, 1);
  JobId jobId = MRBuilderUtils.newJobId(appAttemptId.getApplicationId(), 0);
  Job mockJob = mock(Job.class);
  when(mockJob.getReport()).thenReturn(
      MRBuilderUtils.newJobReport(jobId, "job", "user", JobState.RUNNING, 0,
          0, 0, 0, 0, 0, 0, "jobfile", null, false, ""));
  final MockScheduler mockScheduler = new MockScheduler(appAttemptId);
  MyContainerAllocator allocator =
      new MyContainerAllocator(null, conf, appAttemptId, mockJob) {
        @Override
        protected void register() {
        }

        @Override
        protected ApplicationMasterProtocol createSchedulerProxy() {
          return mockScheduler;
        }
      };

  // create some map requests
  ContainerRequestEvent reqMapEvents;
  reqMapEvents = createReq(jobId, 0, 1024, new String[] { "map" });
  allocator.sendRequests(Arrays.asList(reqMapEvents));

  // create some reduce requests
  ContainerRequestEvent reqReduceEvents;
  reqReduceEvents =
      createReq(jobId, 0, 2048, new String[] { "reduce" }, false, true);
  allocator.sendRequests(Arrays.asList(reqReduceEvents));
  allocator.schedule();
  // verify all of the host-specific asks were sent plus one for the
  // default rack and one for the ANY request
  Assert.assertEquals(3, mockScheduler.lastAsk.size());
  // verify ResourceRequest sent for MAP have appropriate node
  // label expression as per the configuration
  validateLabelsRequests(mockScheduler.lastAsk.get(0), false);
  validateLabelsRequests(mockScheduler.lastAsk.get(1), false);
  validateLabelsRequests(mockScheduler.lastAsk.get(2), false);

  // assign a map task and verify we do not ask for any more maps
  ContainerId cid0 = mockScheduler.assignContainer("map", false);
  allocator.schedule();
  // default rack and one for the ANY request
  Assert.assertEquals(3, mockScheduler.lastAsk.size());
  validateLabelsRequests(mockScheduler.lastAsk.get(0), true);
  validateLabelsRequests(mockScheduler.lastAsk.get(1), true);
  validateLabelsRequests(mockScheduler.lastAsk.get(2), true);

  // complete the map task and verify that we ask for one more
  allocator.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:67,代码来源:TestRMContainerAllocator.java

示例15: testMapReduceScheduling

import org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils; //导入方法依赖的package包/类
@Test
public void testMapReduceScheduling() throws Exception {

  LOG.info("Running testMapReduceScheduling");

  Configuration conf = new Configuration();
  MyResourceManager rm = new MyResourceManager(conf);
  rm.start();
  DrainDispatcher dispatcher = (DrainDispatcher) rm.getRMContext()
      .getDispatcher();

  // Submit the application
  RMApp app = rm.submitApp(1024);
  dispatcher.await();

  MockNM amNodeManager = rm.registerNode("amNM:1234", 2048);
  amNodeManager.nodeHeartbeat(true);
  dispatcher.await();

  ApplicationAttemptId appAttemptId = app.getCurrentAppAttempt()
      .getAppAttemptId();
  rm.sendAMLaunched(appAttemptId);
  dispatcher.await();

  JobId jobId = MRBuilderUtils.newJobId(appAttemptId.getApplicationId(), 0);
  Job mockJob = mock(Job.class);
  when(mockJob.getReport()).thenReturn(
      MRBuilderUtils.newJobReport(jobId, "job", "user", JobState.RUNNING, 0,
          0, 0, 0, 0, 0, 0, "jobfile", null, false, ""));
  MyContainerAllocator allocator = new MyContainerAllocator(rm, conf,
      appAttemptId, mockJob);

  // add resources to scheduler
  MockNM nodeManager1 = rm.registerNode("h1:1234", 1024);
  MockNM nodeManager2 = rm.registerNode("h2:1234", 10240);
  MockNM nodeManager3 = rm.registerNode("h3:1234", 10240);
  dispatcher.await();

  // create the container request
  // send MAP request
  ContainerRequestEvent event1 = createReq(jobId, 1, 2048, new String[] {
      "h1", "h2" }, true, false);
  allocator.sendRequest(event1);

  // send REDUCE request
  ContainerRequestEvent event2 = createReq(jobId, 2, 3000,
      new String[] { "h1" }, false, true);
  allocator.sendRequest(event2);

  // send MAP request
  ContainerRequestEvent event3 = createReq(jobId, 3, 2048,
      new String[] { "h3" }, false, false);
  allocator.sendRequest(event3);

  // this tells the scheduler about the requests
  // as nodes are not added, no allocations
  List<TaskAttemptContainerAssignedEvent> assigned = allocator.schedule();
  dispatcher.await();
  Assert.assertEquals("No of assignments must be 0", 0, assigned.size());

  // update resources in scheduler
  nodeManager1.nodeHeartbeat(true); // Node heartbeat
  nodeManager2.nodeHeartbeat(true); // Node heartbeat
  nodeManager3.nodeHeartbeat(true); // Node heartbeat
  dispatcher.await();

  assigned = allocator.schedule();
  dispatcher.await();
  checkAssignments(new ContainerRequestEvent[] { event1, event3 },
      assigned, false);

  // validate that no container is assigned to h1 as it doesn't have 2048
  for (TaskAttemptContainerAssignedEvent assig : assigned) {
    Assert.assertFalse("Assigned count not correct", "h1".equals(assig
        .getContainer().getNodeId().getHost()));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:78,代码来源:TestRMContainerAllocator.java


注:本文中的org.apache.hadoop.mapreduce.v2.util.MRBuilderUtils.newJobId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。