private void recoverAppAttempts() { for (RMAppAttempt attempt : getAppAttempts().values()) { attempt.handle(new RMAppAttemptEvent(attempt.getAppAttemptId(), RMAppAttemptEventType.RECOVER)); } }
@Override public void handle(RMAppEvent event) { assertEquals(application.getApplicationId(), event.getApplicationId()); if (event instanceof RMAppFailedAttemptEvent) { transferStateFromPreviousAttempt = ((RMAppFailedAttemptEvent) event) .getTransferStateFromPreviousAttempt(); } try { application.handle(event); } catch (Throwable t) { LOG.error("Error in handling event type " + event.getType() + " for application " + application.getApplicationId(), t); } } }
@Override public boolean isAppInCompletedStates() { RMAppState appState = getState(); return appState == RMAppState.FINISHED || appState == RMAppState.FINISHING || appState == RMAppState.FAILED || appState == RMAppState.KILLED || appState == RMAppState.FINAL_SAVING || appState == RMAppState.KILLING; }
public void updateApplicationTimeout( Map<ApplicationTimeoutType, Long> updateTimeout) { this.writeLock.lock(); try { if (COMPLETED_APP_STATES.contains(getState())) { return; } // update monitoring service this.rmContext.getRMAppLifetimeMonitor() .updateApplicationTimeouts(getApplicationId(), updateTimeout); this.applicationTimeouts.putAll(updateTimeout); } finally { this.writeLock.unlock(); } }
@Override public void transition(RMAppImpl app, RMAppEvent event) { if(app.launchTime == 0) { LOG.info("update the launch time for applicationId: "+ app.getApplicationId()+", attemptId: "+ app.getCurrentAppAttempt().getAppAttemptId()+ "launchTime: "+event.getTimestamp()); app.launchTime = event.getTimestamp(); } } }
@Override public void transition(RMAppImpl app, RMAppEvent event) { app.stateBeforeKilling = app.getState(); // Forward app kill diagnostics in the event to kill app attempt. // These diagnostics will be returned back in ATTEMPT_KILLED event sent by // RMAppAttemptImpl. app.handler.handle( new RMAppAttemptEvent(app.currentAttempt.getAppAttemptId(), RMAppAttemptEventType.KILL, event.getDiagnosticMsg())); RMAppImpl.auditLogKillEvent(event); } }
appState.getApplicationSubmissionContext(); RMAppImpl application = new RMAppImpl( appState.getApplicationSubmissionContext().getApplicationId(), rmContext, conf, RMAppAttemptImpl.AM_CONTAINER_PRIORITY, ResourceRequest.ANY, submissionContext.getResource(), 1))); Assert.assertEquals(RMAppState.NEW, application.getState()); new RMAppRecoverEvent(application.getApplicationId(), rmState); application.handle(recoverEvent); RMAppImpl.isAppInFinalState(application)); application.getState()); verifyRMAppFieldsForFinalTransitions(application);
ApplicationResourceUsageReport appUsageReport = RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT; FinalApplicationStatus finishState = getFinalApplicationStatus(); String diags = UNAVAILABLE; float progress = 0.0f; appUsageReport = currentAttempt.getApplicationResourceUsageReport(); progress = currentAttempt.getProgress(); logAggregationStatus = this.getLogAggregationStatusForAppReport(); diags = getDiagnostics().toString(); if (getApplicationSubmissionContext().getUnmanagedAM() && clientUserName != null && getUser().equals(clientUserName)) { Token<AMRMTokenIdentifier> token = currentAttempt.getAMRMToken(); if (token != null) { RMAppMetrics rmAppMetrics = getRMAppMetrics(); appUsageReport .setResourceSecondsMap(rmAppMetrics.getResourceSecondsMap()); this.applicationId, currentApplicationAttemptId, this.user, this.queue, this.name, host, rpcPort, clientToAMToken, createApplicationState(), diags, trackingUrl, this.startTime, this.launchTime, this.finishTime, finishState, appUsageReport, origTrackingUrl, progress, this.applicationType, amrmToken, applicationTags, this.getApplicationPriority()); report.setLogAggregationStatus(logAggregationStatus); report.setUnmanagedApp(submissionContext.getUnmanagedAM());
ApplicationResourceUsageReport appUsageReport = RMServerUtils.DUMMY_APPLICATION_RESOURCE_USAGE_REPORT; FinalApplicationStatus finishState = getFinalApplicationStatus(); String diags = UNAVAILABLE; float progress = 0.0f; org.apache.hadoop.yarn.api.records.Token amrmToken = null; if (allowAccess) { trackingUrl = getDefaultProxyTrackingUrl(); if (this.currentAttempt != null) { currentApplicationAttemptId = this.currentAttempt.getAppAttemptId(); if (getApplicationSubmissionContext().getUnmanagedAM() && clientUserName != null && getUser().equals(clientUserName)) { Token<AMRMTokenIdentifier> token = currentAttempt.getAMRMToken(); if (token != null) { RMAppMetrics rmAppMetrics = getRMAppMetrics(); appUsageReport.setMemorySeconds(rmAppMetrics.getMemorySeconds()); appUsageReport.setVcoreSeconds(rmAppMetrics.getVcoreSeconds()); currentApplicationAttemptId, this.user, this.queue, this.name, host, rpcPort, clientToAMToken, createApplicationState(), diags, trackingUrl, this.startTime, this.finishTime, finishState, appUsageReport, origTrackingUrl, progress, this.applicationType,
rmApp.getLogAggregationStatusForAppReport()); rmApp.getLogAggregationStatusForAppReport()); rmApp.aggregateLogReport(nodeId1, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.NOT_START, "")); rmApp.aggregateLogReport(nodeId2, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.NOT_START, "")); rmApp.aggregateLogReport(nodeId3, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.NOT_START, "")); rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.NOT_START, "")); Assert.assertEquals(LogAggregationStatus.NOT_START, rmApp.getLogAggregationStatusForAppReport()); rmApp.aggregateLogReport(nodeId1, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.NOT_START, "")); rmApp.aggregateLogReport(nodeId2, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.RUNNING, "")); rmApp.aggregateLogReport(nodeId3, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, "")); rmApp.aggregateLogReport(nodeId4, LogAggregationReport.newInstance( rmApp.getApplicationId(), LogAggregationStatus.SUCCEEDED, "")); Assert.assertEquals(LogAggregationStatus.RUNNING, rmApp.getLogAggregationStatusForAppReport()); rmApp.handle(new RMAppEvent(rmApp.getApplicationId(), RMAppEventType.KILL)); Assert.assertTrue(RMAppImpl.isAppInFinalState(rmApp));
app1.setSystemClock(clock); MockAM am1 = MockRM.launchAndRegisterAM(app1, rm1, nm1); rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); Assert.assertEquals(2, app1.getAppAttempts().size()); RMAppAttempt attempt2 = app1.getCurrentAppAttempt(); Assert.assertTrue(((RMAppAttemptImpl) attempt2).mayBeLastAttempt()); MockAM am2 = MockRM.launchAndRegisterAM(app1, rm1, nm1); rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); Assert.assertEquals(3, app1.getAppAttempts().size()); RMAppAttempt attempt3 = app1.getCurrentAppAttempt(); clock.reset(); MockAM am3 = MockRM.launchAndRegisterAM(app1, rm1, nm1); rm2.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); rm2.waitForNewAMToLaunchAndRegister(app1.getApplicationId(), 4, nm1); rm2.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); rm2.waitForNewAMToLaunchAndRegister(app1.getApplicationId(), 5, nm1); clock.reset(); am5.waitForState(RMAppAttemptState.RUNNING); rm2.waitForState(app1.getApplicationId(), RMAppState.FAILED); rm1.stop(); rm2.stop();
/** * {@link RMAppAttemptState#FAILED} */ private void testAppAttemptFailedState(Container container, String diagnostics) { sendAttemptUpdateSavedEvent(applicationAttempt); assertEquals(RMAppAttemptState.FAILED, applicationAttempt.getAppAttemptState()); assertEquals(diagnostics, applicationAttempt.getDiagnostics()); assertEquals(0,applicationAttempt.getJustFinishedContainers().size()); assertEquals(container, applicationAttempt.getMasterContainer()); assertEquals(0.0, (double)applicationAttempt.getProgress(), 0.0001); assertEquals(0, application.getRanNodes().size()); // Check events verify(application, times(1)).handle(any(RMAppFailedAttemptEvent.class)); verifyTokenCount(applicationAttempt.getAppAttemptId(), 1); verifyAttemptFinalStateSaved(); verifyApplicationAttemptFinished(RMAppAttemptState.FAILED); }
/** * {@link RMAppAttemptState#SCHEDULED} */ @SuppressWarnings("unchecked") private void testAppAttemptScheduledState() { RMAppAttemptState expectedState; int expectedAllocateCount; if(unmanagedAM) { expectedState = RMAppAttemptState.LAUNCHED; expectedAllocateCount = 0; } else { expectedState = RMAppAttemptState.SCHEDULED; expectedAllocateCount = 1; } assertEquals(expectedState, applicationAttempt.getAppAttemptState()); verify(scheduler, times(expectedAllocateCount)).allocate( any(ApplicationAttemptId.class), any(List.class), eq(null), any(List.class), any(List.class), any(List.class), any(ContainerUpdates.class)); assertEquals(0,applicationAttempt.getJustFinishedContainers().size()); assertNull(applicationAttempt.getMasterContainer()); assertEquals(0.0, (double)applicationAttempt.getProgress(), 0.0001); assertEquals(0, application.getRanNodes().size()); assertNull(applicationAttempt.getFinalApplicationStatus()); }
private void createApplicationWithAMResourceInternal( ApplicationAttemptId attId, String queue, String user, Resource amResource, List<ResourceRequest> amReqs) { RMContext rmContext = resourceManager.getRMContext(); ApplicationId appId = attId.getApplicationId(); RMApp rmApp = new RMAppImpl(appId, rmContext, conf, null, user, null, ApplicationSubmissionContext.newInstance(appId, null, queue, null, mock(ContainerLaunchContext.class), false, false, 0, amResource, null), scheduler, null, 0, null, null, amReqs); rmContext.getRMApps().put(appId, rmApp); }
private void rememberTargetTransitionsAndStoreState(RMAppEvent event, Object transitionToDo, RMAppState targetFinalState, RMAppState stateToBeStored) { rememberTargetTransitions(event, transitionToDo, targetFinalState); this.stateBeforeFinalSaving = getState(); this.storedFinishTime = this.systemClock.getTime(); case ATTEMPT_FAILED: RMAppFailedAttemptEvent failedEvent = (RMAppFailedAttemptEvent) event; diags = getAppAttemptFailedDiagnostics(failedEvent); break; default:
&& !RMAppImpl.isAppInFinalState(rmApp)) { } else if (RMAppImpl.isAppInFinalState(rmApp)) { RMAppState appState = ((RMAppImpl) rmApp).getRecoveredFinalState(); LOG.warn(rmApp.getApplicationId() + " final state (" + appState + ") was recorded, but " + appAttempt.applicationAttemptId
rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); Assert.assertEquals(2, app1.getAppAttempts().size()); RMAppAttempt attempt2 = app1.getCurrentAppAttempt(); MockAM am2 = MockRM.launchAndRegisterAM(app1, rm1, nm1); rm1.waitForState(am2.getApplicationAttemptId(), RMAppAttemptState.RUNNING); rm1.waitForState(app1.getApplicationId(), RMAppState.ACCEPTED); Assert.assertEquals(3, app1.getAppAttempts().size()); MockAM am3 = rm1.launchAM(app1, rm1, nm1); RegisterApplicationMasterResponse registerResponse = rm1.waitForState(app1.getApplicationId(), RMAppState.RUNNING); rm1.stop();
app.getAMResourceRequests().get(0) .setNodeLabelExpression(amNodeLabelExpression); ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance( new HashMap<ApplicationAttemptId, RMAppAttempt>(); attempts.put(attemptId, rmAppAttemptImpl); when(app.getCurrentAppAttempt()).thenReturn(rmAppAttemptImpl); when(app.getAppAttempts()).thenReturn(attempts); when(app.getApplicationPriority()).thenReturn(Priority.newInstance(0)); when(rmAppAttemptImpl.getMasterContainer()).thenReturn(container); ResourceScheduler rs = mock(ResourceScheduler.class);
public void aggregateLogReport(NodeId nodeId, LogAggregationReport report) { try { this.writeLock.lock(); if (this.logAggregationEnabled && !isLogAggregationFinished()) { LogAggregationReport curReport = this.logAggregationStatus.get(nodeId); boolean stateChangedToFinal = false; if (curReport == null) { this.logAggregationStatus.put(nodeId, report); if (isLogAggregationFinishedForNM(report)) { stateChangedToFinal = true; if (isLogAggregationFinishedForNM(report)) { if (!isLogAggregationFinishedForNM(curReport)) { stateChangedToFinal = true; updateLogAggregationDiagnosticMessages(nodeId, report); if (isAppInFinalState(this) && stateChangedToFinal) { updateLogAggregationStatus(nodeId);
@Override public void recover(RMState state) { ApplicationStateData appState = state.getApplicationState().get(getApplicationId()); this.recoveredFinalState = appState.getState(); LOG.info("Recovering app: " + getApplicationId() + " with " + + appState.getAttemptCount() + " attempts and final state = " + this.recoveredFinalState ); this.diagnostics.append(appState.getDiagnostics()); this.storedFinishTime = appState.getFinishTime(); this.startTime = appState.getStartTime(); for(int i=0; i<appState.getAttemptCount(); ++i) { // create attempt createNewAttempt(); ((RMAppAttemptImpl)this.currentAttempt).recover(state); } }