public AppActivitiesInfo getAppActivitiesInfo(ApplicationId applicationId) { if (rmContext.getRMApps().get(applicationId).getFinalApplicationStatus() == FinalApplicationStatus.UNDEFINED) { List<AppAllocation> allocations = completedAppAllocations.get( applicationId); return new AppActivitiesInfo(allocations, applicationId); } else { return new AppActivitiesInfo( "fail to get application activities after finished", applicationId.toString()); } }
private static void assertFinalAppStatus(FinalApplicationStatus status, RMApp application) { Assert.assertEquals("Final application status should have been " + status, status, application.getFinalApplicationStatus()); }
private static void assertFinalAppStatus(FinalApplicationStatus status, RMApp application) { Assert.assertEquals("Final application status should have been " + status, status, application.getFinalApplicationStatus()); }
private static RMApp createRMApp(ApplicationId appId) { RMApp app = mock(RMApp.class); when(app.getApplicationId()).thenReturn(appId); when(app.getName()).thenReturn("test app"); when(app.getApplicationType()).thenReturn("test app type"); when(app.getUser()).thenReturn("test user"); when(app.getQueue()).thenReturn("test queue"); when(app.getSubmitTime()).thenReturn(0L); when(app.getStartTime()).thenReturn(1L); when(app.getFinishTime()).thenReturn(2L); when(app.getDiagnostics()).thenReturn( new StringBuilder("test diagnostics info")); when(app.getFinalApplicationStatus()).thenReturn( FinalApplicationStatus.UNDEFINED); return app; }
private static RMApp createRMApp(ApplicationId appId) { RMApp app = mock(RMApp.class); when(app.getApplicationId()).thenReturn(appId); when(app.getName()).thenReturn("test app"); when(app.getApplicationType()).thenReturn("test app type"); when(app.getUser()).thenReturn("test user"); when(app.getQueue()).thenReturn("test queue"); when(app.getSubmitTime()).thenReturn(0L); when(app.getStartTime()).thenReturn(1L); when(app.getFinishTime()).thenReturn(2L); when(app.getDiagnostics()).thenReturn( new StringBuilder("test diagnostics info")); when(app.getFinalApplicationStatus()).thenReturn( FinalApplicationStatus.UNDEFINED); return app; }
private static RMApp createRMApp(ApplicationId appId) { RMApp app = mock(RMApp.class); when(app.getApplicationId()).thenReturn(appId); when(app.getName()).thenReturn("test app"); when(app.getApplicationType()).thenReturn("test app type"); when(app.getUser()).thenReturn("test user"); when(app.getQueue()).thenReturn("test queue"); when(app.getSubmitTime()).thenReturn(Integer.MAX_VALUE + 1L); when(app.getStartTime()).thenReturn(Integer.MAX_VALUE + 2L); when(app.getFinishTime()).thenReturn(Integer.MAX_VALUE + 3L); when(app.getDiagnostics()).thenReturn( new StringBuilder("test diagnostics info")); RMAppAttempt appAttempt = mock(RMAppAttempt.class); when(appAttempt.getAppAttemptId()).thenReturn( ApplicationAttemptId.newInstance(appId, 1)); when(app.getCurrentAppAttempt()).thenReturn(appAttempt); when(app.getFinalApplicationStatus()).thenReturn( FinalApplicationStatus.UNDEFINED); when(app.getRMAppMetrics()).thenReturn( new RMAppMetrics(null, 0, 0, Integer.MAX_VALUE, Long.MAX_VALUE)); return app; }
@SuppressWarnings("unchecked") public void applicationFinished(RMApp app, RMAppState finalState) { if (historyServiceEnabled) { dispatcher.getEventHandler().handle( new WritingApplicationFinishEvent(app.getApplicationId(), ApplicationFinishData.newInstance(app.getApplicationId(), app.getFinishTime(), app.getDiagnostics().toString(), app.getFinalApplicationStatus(), RMServerUtils.createApplicationState(finalState)))); } }
@SuppressWarnings("unchecked") public void applicationFinished(RMApp app, RMAppState finalState) { if (historyServiceEnabled) { dispatcher.getEventHandler().handle( new WritingApplicationFinishEvent(app.getApplicationId(), ApplicationFinishData.newInstance(app.getApplicationId(), app.getFinishTime(), app.getDiagnostics().toString(), app.getFinalApplicationStatus(), RMServerUtils.createApplicationState(finalState)))); } }
@SuppressWarnings("unchecked") public void applicationFinished(RMApp app, RMAppState finalState) { if (historyServiceEnabled) { dispatcher.getEventHandler().handle( new WritingApplicationFinishEvent(app.getApplicationId(), ApplicationFinishData.newInstance(app.getApplicationId(), app.getFinishTime(), app.getDiagnostics().toString(), app.getFinalApplicationStatus(), RMServerUtils.createApplicationState(finalState)))); } }
@SuppressWarnings("unchecked") public void appFinished(RMApp app, RMAppState state, long finishedTime) { if (publishSystemMetrics) { dispatcher.getEventHandler().handle( new ApplicationFinishedEvent( app.getApplicationId(), app.getDiagnostics().toString(), app.getFinalApplicationStatus(), RMServerUtils.createApplicationState(state), app.getCurrentAppAttempt() == null ? null : app.getCurrentAppAttempt().getAppAttemptId(), finishedTime, app.getRMAppMetrics())); } }
@SuppressWarnings("unchecked") public void appFinished(RMApp app, RMAppState state, long finishedTime) { if (publishSystemMetrics) { dispatcher.getEventHandler().handle( new ApplicationFinishedEvent( app.getApplicationId(), app.getDiagnostics().toString(), app.getFinalApplicationStatus(), RMServerUtils.createApplicationState(state), app.getCurrentAppAttempt() == null ? null : app.getCurrentAppAttempt().getAppAttemptId(), finishedTime, app.getRMAppMetrics())); } }
@SuppressWarnings("unchecked") @Override public void appAttemptFinished(RMAppAttempt appAttempt, RMAppAttemptState appAttemtpState, RMApp app, long finishedTime) { TimelineEntity entity = createAppAttemptEntity(appAttempt.getAppAttemptId()); TimelineEvent tEvent = new TimelineEvent(); tEvent.setEventType(AppAttemptMetricsConstants.FINISHED_EVENT_TYPE); tEvent.setTimestamp(finishedTime); Map<String, Object> eventInfo = new HashMap<String, Object>(); eventInfo.put(AppAttemptMetricsConstants.TRACKING_URL_INFO, appAttempt.getTrackingUrl()); eventInfo.put(AppAttemptMetricsConstants.ORIGINAL_TRACKING_URL_INFO, appAttempt.getOriginalTrackingUrl()); eventInfo.put(AppAttemptMetricsConstants.DIAGNOSTICS_INFO, appAttempt.getDiagnostics()); eventInfo.put(AppAttemptMetricsConstants.FINAL_STATUS_INFO, app.getFinalApplicationStatus().toString()); eventInfo.put(AppAttemptMetricsConstants.STATE_INFO, RMServerUtils .createApplicationAttemptState(appAttemtpState).toString()); if (appAttempt.getMasterContainer() != null) { eventInfo.put(AppAttemptMetricsConstants.MASTER_CONTAINER_INFO, appAttempt.getMasterContainer().getId().toString()); } tEvent.setEventInfo(eventInfo); entity.addEvent(tEvent); getDispatcher().getEventHandler().handle( new TimelineV1PublishEvent(SystemMetricsEventType.PUBLISH_ENTITY, entity, appAttempt.getAppAttemptId().getApplicationId())); }
@Test(timeout = 10000) public void testPublishAppAttemptMetricsForUnmanagedAM() throws Exception { ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1); RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId,true); metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L); RMApp app = mock(RMApp.class); when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED); metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app, Integer.MAX_VALUE + 2L); TimelineEntity entity = null; do { entity = store.getEntity(appAttemptId.toString(), AppAttemptMetricsConstants.ENTITY_TYPE, EnumSet.allOf(Field.class)); // ensure two events are both published before leaving the loop } while (entity == null || entity.getEvents().size() < 2); }
@Test(timeout = 10000) public void testPublishAppAttemptMetricsForUnmanagedAM() throws Exception { ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(ApplicationId.newInstance(0, 1), 1); RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId,true); metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L); RMApp app = mock(RMApp.class); when(app.getFinalApplicationStatus()).thenReturn(FinalApplicationStatus.UNDEFINED); metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app, Integer.MAX_VALUE + 2L); TimelineEntity entity = null; do { entity = store.getEntity(appAttemptId.toString(), AppAttemptMetricsConstants.ENTITY_TYPE, EnumSet.allOf(Field.class)); // ensure two events are both published before leaving the loop } while (entity == null || entity.getEvents().size() < 2); }
public static ClientRMService mockClientRMService(RMContext rmContext) { ClientRMService clientRMService = mock(ClientRMService.class); List<ApplicationReport> appReports = new ArrayList<ApplicationReport>(); for (RMApp app : rmContext.getRMApps().values()) { ApplicationReport appReport = ApplicationReport.newInstance( app.getApplicationId(), (ApplicationAttemptId) null, app.getUser(), app.getQueue(), app.getName(), (String) null, 0, (Token) null, app.createApplicationState(), app.getDiagnostics().toString(), (String) null, app.getStartTime(), app.getFinishTime(), app.getFinalApplicationStatus(), (ApplicationResourceUsageReport) null, app.getTrackingUrl(), app.getProgress(), app.getApplicationType(), (Token) null); appReports.add(appReport); } GetApplicationsResponse response = mock(GetApplicationsResponse.class); when(response.getApplicationList()).thenReturn(appReports); try { when(clientRMService.getApplications(any(GetApplicationsRequest.class))) .thenReturn(response); } catch (YarnException e) { Assert.fail("Exception is not expteced."); } return clientRMService; }
public static ClientRMService mockClientRMService(RMContext rmContext) { ClientRMService clientRMService = mock(ClientRMService.class); List<ApplicationReport> appReports = new ArrayList<ApplicationReport>(); for (RMApp app : rmContext.getRMApps().values()) { ApplicationReport appReport = ApplicationReport.newInstance( app.getApplicationId(), (ApplicationAttemptId) null, app.getUser(), app.getQueue(), app.getName(), (String) null, 0, (Token) null, app.createApplicationState(), app.getDiagnostics().toString(), (String) null, app.getStartTime(), app.getLaunchTime(), app.getFinishTime(), app.getFinalApplicationStatus(), (ApplicationResourceUsageReport) null, app.getTrackingUrl(), app.getProgress(), app.getApplicationType(), (Token) null); appReports.add(appReport); } GetApplicationsResponse response = mock(GetApplicationsResponse.class); when(response.getApplicationList()).thenReturn(appReports); try { when(clientRMService.getApplications(any(GetApplicationsRequest.class))) .thenReturn(response); } catch (YarnException e) { Assert.fail("Exception is not expected."); } return clientRMService; }
@SuppressWarnings("unchecked") @Override public void appAttemptFinished(RMAppAttempt appAttempt, RMAppAttemptState appAttemtpState, RMApp app, long finishedTime) { ApplicationAttemptId attemptId = appAttempt.getAppAttemptId(); ApplicationAttemptEntity entity = createAppAttemptEntity(appAttempt.getAppAttemptId()); TimelineEvent tEvent = new TimelineEvent(); tEvent.setId(AppAttemptMetricsConstants.FINISHED_EVENT_TYPE); tEvent.setTimestamp(finishedTime); entity.addEvent(tEvent); Map<String, Object> entityInfo = new HashMap<String, Object>(); entityInfo.put(AppAttemptMetricsConstants.DIAGNOSTICS_INFO, appAttempt.getDiagnostics()); // app will get the final status from app attempt, or create one // based on app state if it doesn't exist entityInfo.put(AppAttemptMetricsConstants.FINAL_STATUS_INFO, app.getFinalApplicationStatus().toString()); entityInfo.put(AppAttemptMetricsConstants.STATE_INFO, RMServerUtils .createApplicationAttemptState(appAttemtpState).toString()); entity.setInfo(entityInfo); entity.setIdPrefix( TimelineServiceHelper.invertLong(attemptId.getAttemptId())); getDispatcher().getEventHandler().handle( new TimelineV2PublishEvent(SystemMetricsEventType.PUBLISH_ENTITY, entity, appAttempt.getAppAttemptId().getApplicationId())); }
@Test(timeout = 10000) public void testPublishAppAttemptMetrics() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); RMApp app = rmAppsMapInContext.get(appId); if (app == null) { app = createAppAndRegister(appId); } ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); RMAppAttempt appAttempt = createRMAppAttempt(appAttemptId); metricsPublisher.appAttemptRegistered(appAttempt, Integer.MAX_VALUE + 1L); when(app.getFinalApplicationStatus()).thenReturn( FinalApplicationStatus.UNDEFINED); metricsPublisher.appAttemptFinished(appAttempt, RMAppAttemptState.FINISHED, app, Integer.MAX_VALUE + 2L); dispatcher.await(); String outputDirApp = getTimelineEntityDir(app) + "/" + TimelineEntityType.YARN_APPLICATION_ATTEMPT + "/"; File entityFolder = new File(outputDirApp); Assert.assertTrue(entityFolder.isDirectory()); // file name is <entityId>.thist String timelineServiceFileName = appAttemptId.toString() + FileSystemTimelineWriterImpl.TIMELINE_SERVICE_STORAGE_EXTENSION; File appFile = new File(outputDirApp, timelineServiceFileName); Assert.assertTrue(appFile.exists()); verifyEntity(appFile, 2, AppAttemptMetricsConstants.REGISTERED_EVENT_TYPE, 0, TimelineServiceHelper.invertLong(appAttemptId.getAttemptId())); }
@SuppressWarnings("unchecked") public void appAttemptFinished(RMAppAttempt appAttempt, RMAppAttemptState appAttemtpState, RMApp app, long finishedTime) { if (publishSystemMetrics) { ContainerId container = (appAttempt.getMasterContainer() == null) ? null : appAttempt.getMasterContainer().getId(); dispatcher.getEventHandler().handle( new AppAttemptFinishedEvent( appAttempt.getAppAttemptId(), appAttempt.getTrackingUrl(), appAttempt.getOriginalTrackingUrl(), appAttempt.getDiagnostics(), // app will get the final status from app attempt, or create one // based on app state if it doesn't exist app.getFinalApplicationStatus(), RMServerUtils.createApplicationAttemptState(appAttemtpState), finishedTime, container)); } }
@SuppressWarnings("unchecked") public void appAttemptFinished(RMAppAttempt appAttempt, RMAppAttemptState appAttemtpState, RMApp app, long finishedTime) { if (publishSystemMetrics) { ContainerId container = (appAttempt.getMasterContainer() == null) ? null : appAttempt.getMasterContainer().getId(); dispatcher.getEventHandler().handle( new AppAttemptFinishedEvent( appAttempt.getAppAttemptId(), appAttempt.getTrackingUrl(), appAttempt.getOriginalTrackingUrl(), appAttempt.getDiagnostics(), // app will get the final status from app attempt, or create one // based on app state if it doesn't exist app.getFinalApplicationStatus(), RMServerUtils.createApplicationAttemptState(appAttemtpState), finishedTime, container)); } }