protected void unregister() { try { doUnregistration(); } catch(Exception are) { LOG.error("Exception while unregistering ", are); // if unregistration failed, isLastAMRetry needs to be recalculated // to see whether AM really has the chance to retry RunningAppContext raContext = (RunningAppContext) context; raContext.resetIsLastAMRetry(); } }
raContext.markSuccessfulUnregistration(); break;
private AppContext mockAppContext(Class<? extends AppContext> contextClass, ApplicationId appId, boolean isLastAMRetry) { JobId jobId = TypeConverter.toYarn(TypeConverter.fromYarn(appId)); AppContext mockContext = mock(contextClass); Job mockJob = mockJob(); when(mockContext.getJob(jobId)).thenReturn(mockJob); when(mockContext.getApplicationID()).thenReturn(appId); when(mockContext.isLastAMRetry()).thenReturn(isLastAMRetry); if (mockContext instanceof RunningAppContext) { when(((RunningAppContext)mockContext).getTimelineClient()). thenReturn(TimelineClient.createTimelineClient()); when(((RunningAppContext) mockContext).getTimelineV2Client()) .thenReturn(TimelineV2Client .createTimelineClient(ApplicationId.newInstance(0, 1))); } return mockContext; }
taskAttemptFinishingMonitor = createTaskAttemptFinishingMonitor(dispatcher.getEventHandler()); addIfService(taskAttemptFinishingMonitor); context = new RunningAppContext(conf, taskAttemptFinishingMonitor);
taskAttemptFinishingMonitor = createTaskAttemptFinishingMonitor(dispatcher.getEventHandler()); addIfService(taskAttemptFinishingMonitor); context = new RunningAppContext(conf, taskAttemptFinishingMonitor);
context = new RunningAppContext(conf);
if(timelineServiceV2Enabled) { timelineV2Client = ((MRAppMaster.RunningAppContext)context).getTimelineV2Client(); timelineV2Client.init(conf); } else { timelineClient = ((MRAppMaster.RunningAppContext) context).getTimelineClient(); timelineClient.init(conf);
if (appContext.getTimelineV2Client() != null) { appContext.getTimelineV2Client(). setTimelineCollectorInfo(response.getCollectorInfo());
TimelineV2Client client = spy(TimelineV2Client.createTimelineClient(appId)); client.init(conf); when(((RunningAppContext)allocator.getContext()).getTimelineV2Client()). thenReturn(client);
PreemptionMessage pM = getPreemptionMessage(false, false, container); policy.preempt(mPctxt, pM); verify(mActxt.getEventHandler(), times(0)).handle( any(TaskAttemptEvent.class)); verify(mActxt.getEventHandler(), times(0)).handle( any(JobCounterUpdateEvent.class)); pM = getPreemptionMessage(true, false, container); policy.preempt(mPctxt, pM); verify(mActxt.getEventHandler(), times(2)).handle( any(TaskAttemptEvent.class)); verify(mActxt.getEventHandler(), times(2)).handle( any(JobCounterUpdateEvent.class)); pM = getPreemptionMessage(false, true, container); policy.preempt(mPctxt, pM); verify(mActxt.getEventHandler(), times(2)).handle( any(TaskAttemptEvent.class)); verify(mActxt.getEventHandler(), times(2)).handle( any(JobCounterUpdateEvent.class)); pM = getPreemptionMessage(true, true, container); policy.preempt(mPctxt, pM); verify(mActxt.getEventHandler(), times(4)).handle( any(TaskAttemptEvent.class)); verify(mActxt.getEventHandler(), times(4)).handle( any(JobCounterUpdateEvent.class));
raContext.markSuccessfulUnregistration(); break;
raContext.markSuccessfulUnregistration(); break;
@SuppressWarnings("resource") private void testDeletionofStagingOnUnregistrationFailure( int maxAttempts, boolean shouldHaveDeleted) throws IOException { conf.set(MRJobConfig.MAPREDUCE_JOB_DIR, stagingJobDir); fs = mock(FileSystem.class); when(fs.delete(any(Path.class), anyBoolean())).thenReturn(true); //Staging Dir exists String user = UserGroupInformation.getCurrentUser().getShortUserName(); Path stagingDir = MRApps.getStagingAreaDir(conf, user); when(fs.exists(stagingDir)).thenReturn(true); ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1); JobId jobid = recordFactory.newRecordInstance(JobId.class); jobid.setAppId(appId); TestMRApp appMaster = new TestMRApp(attemptId, null, JobStateInternal.RUNNING, maxAttempts); appMaster.crushUnregistration = true; appMaster.init(conf); appMaster.start(); appMaster.shutDownJob(); ((RunningAppContext) appMaster.getContext()).resetIsLastAMRetry(); if (shouldHaveDeleted) { Assert.assertEquals(new Boolean(true), appMaster.isLastAMRetry()); verify(fs).delete(stagingJobPath, true); } else { Assert.assertEquals(new Boolean(false), appMaster.isLastAMRetry()); verify(fs, never()).delete(stagingJobPath, true); } }
@Before @SuppressWarnings("rawtypes") // mocked generics public void setup() { ApplicationId appId = ApplicationId.newInstance(200, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); jid = MRBuilderUtils.newJobId(appId, 1); mActxt = mock(RunningAppContext.class); @SuppressWarnings("unchecked") EventHandler<Event> ea = mock(EventHandler.class); when(mActxt.getEventHandler()).thenReturn(ea); for (int i = 0; i < 40; ++i) { ContainerId cId = ContainerId.newContainerId(appAttemptId, i); if (0 == i % 7) { preemptedContainers.add(cId); } TaskId tId = 0 == i % 2 ? MRBuilderUtils.newTaskId(jid, i / 2, TaskType.MAP) : MRBuilderUtils.newTaskId(jid, i / 2 + 1, TaskType.REDUCE); assignedContainers.put(cId, MRBuilderUtils.newTaskAttemptId(tId, 0)); contToResourceMap.put(cId, Resource.newInstance(2 * minAlloc, 2)); } for (Map.Entry<ContainerId,TaskAttemptId> ent : assignedContainers.entrySet()) { System.out.println("cont:" + ent.getKey().getContainerId() + " type:" + ent.getValue().getTaskId().getTaskType() + " res:" + contToResourceMap.get(ent.getKey()).getMemorySize() + "MB" ); } }
private RunningAppContext getRunningAppContext() { RunningAppContext mActxt = mock(RunningAppContext.class); @SuppressWarnings("unchecked") EventHandler<Event> eventHandler = mock(EventHandler.class); when(mActxt.getEventHandler()).thenReturn(eventHandler); return mActxt; }
protected void unregister() { try { doUnregistration(); } catch(Exception are) { LOG.error("Exception while unregistering ", are); // if unregistration failed, isLastAMRetry needs to be recalculated // to see whether AM really has the chance to retry RunningAppContext raContext = (RunningAppContext) context; raContext.resetIsLastAMRetry(); } }
protected void unregister() { try { doUnregistration(); } catch(Exception are) { LOG.error("Exception while unregistering ", are); // if unregistration failed, isLastAMRetry needs to be recalculated // to see whether AM really has the chance to retry RunningAppContext raContext = (RunningAppContext) context; raContext.resetIsLastAMRetry(); } }