use of org.apache.hadoop.yarn.api.records.ApplicationReport in project apex-core by apache.
the class InlineAM method monitorApplication.
/**
* Monitor the submitted application for completion. Kill application if time
* expires.
*
* @param appId
* Application Id of application to be monitored
* @return true if application completed successfully
* @throws YarnRemoteException
*/
private ApplicationReport monitorApplication(ApplicationId appId, Set<YarnApplicationState> finalState) throws YarnException, IOException {
while (true) {
// Check app status every 1 second.
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
LOG.debug("Thread sleep in monitoring loop interrupted");
}
// Get application report for the appId we are interested in
ApplicationReport report = rmClient.getApplicationReport(appId);
LOG.info("Got application report from ASM for" + ", appId=" + appId.getId() + ", appAttemptId=" + report.getCurrentApplicationAttemptId() + ", clientToken=" + report.getClientToAMToken() + ", appDiagnostics=" + report.getDiagnostics() + ", appMasterHost=" + report.getHost() + ", appQueue=" + report.getQueue() + ", appMasterRpcPort=" + report.getRpcPort() + ", appStartTime=" + report.getStartTime() + ", yarnAppState=" + report.getYarnApplicationState().toString() + ", distributedFinalState=" + report.getFinalApplicationStatus().toString() + ", appTrackingUrl=" + report.getTrackingUrl() + ", appUser=" + report.getUser());
YarnApplicationState state = report.getYarnApplicationState();
if (finalState.contains(state)) {
return report;
}
}
}
use of org.apache.hadoop.yarn.api.records.ApplicationReport in project apex-core by apache.
the class InlineAM method run.
public boolean run() throws Exception {
LOG.info("Starting Client");
// Connect to ResourceManager
rmClient.start();
try {
// Get a new application id
YarnClientApplication newApp = rmClient.createApplication();
ApplicationId appId = newApp.getNewApplicationResponse().getApplicationId();
// Create launch context for app master
LOG.info("Setting up application submission context for ASM");
ApplicationSubmissionContext appContext = Records.newRecord(ApplicationSubmissionContext.class);
// set the application id
appContext.setApplicationId(appId);
// set the application name
appContext.setApplicationName(appName);
// Set the priority for the application master
Priority pri = Records.newRecord(Priority.class);
pri.setPriority(amPriority);
appContext.setPriority(pri);
// Set the queue to which this application is to be submitted in the RM
appContext.setQueue(amQueue);
// Set up the container launch context for the application master
ContainerLaunchContext amContainer = Records.newRecord(ContainerLaunchContext.class);
appContext.setAMContainerSpec(amContainer);
// unmanaged AM
appContext.setUnmanagedAM(true);
LOG.info("Setting unmanaged AM");
// Submit the application to the applications manager
LOG.info("Submitting application to ASM");
rmClient.submitApplication(appContext);
// Monitor the application to wait for launch state
ApplicationReport appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.ACCEPTED));
ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
LOG.info("Launching application with id: " + attemptId);
// launch AM
runAM(attemptId);
// Monitor the application for end state
appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.KILLED, YarnApplicationState.FAILED, YarnApplicationState.FINISHED));
YarnApplicationState appState = appReport.getYarnApplicationState();
FinalApplicationStatus appStatus = appReport.getFinalApplicationStatus();
LOG.info("App ended with state: " + appReport.getYarnApplicationState() + " and status: " + appStatus);
boolean success;
if (YarnApplicationState.FINISHED == appState && FinalApplicationStatus.SUCCEEDED == appStatus) {
LOG.info("Application has completed successfully.");
success = true;
} else {
LOG.info("Application did finished unsuccessfully." + " YarnState=" + appState.toString() + ", FinalStatus=" + appStatus.toString());
success = false;
}
return success;
} finally {
rmClient.stop();
}
}
use of org.apache.hadoop.yarn.api.records.ApplicationReport in project apex-core by apache.
the class YarnAppLauncherImpl method shutdownApp.
protected void shutdownApp(YarnAppHandleImpl app, ShutdownMode shutdownMode) throws LauncherException {
if (shutdownMode == ShutdownMode.KILL) {
YarnClient yarnClient = YarnClient.createYarnClient();
try {
ApplicationId applicationId = app.appId;
ApplicationReport appReport = yarnClient.getApplicationReport(applicationId);
if (appReport == null) {
throw new LauncherException("Application " + app.getApplicationId() + " not found");
}
yarnClient.killApplication(applicationId);
} catch (YarnException | IOException e) {
throw Throwables.propagate(e);
} finally {
IOUtils.closeQuietly(yarnClient);
}
} else {
throw new UnsupportedOperationException("Orderly shutdown not supported, try kill instead");
}
}
use of org.apache.hadoop.yarn.api.records.ApplicationReport in project samza by apache.
the class TestYarnJobValidationTool method testValidateRunningAttemptId.
@Test
public void testValidateRunningAttemptId() throws Exception {
ApplicationReport appReport = mock(ApplicationReport.class);
when(client.getApplicationReport(appId)).thenReturn(appReport);
when(appReport.getCurrentApplicationAttemptId()).thenReturn(attemptId);
ApplicationAttemptReport attemptReport = mock(ApplicationAttemptReport.class);
when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.RUNNING);
when(attemptReport.getApplicationAttemptId()).thenReturn(attemptId);
when(client.getApplicationAttemptReport(attemptId)).thenReturn(attemptReport);
assertTrue(tool.validateRunningAttemptId(appId).equals(attemptId));
when(attemptReport.getYarnApplicationAttemptState()).thenReturn(YarnApplicationAttemptState.FAILED);
exception.expect(SamzaException.class);
tool.validateRunningAttemptId(appId);
}
use of org.apache.hadoop.yarn.api.records.ApplicationReport in project samza by apache.
the class TestYarnJobValidationTool method testValidateAppId.
@Test
public void testValidateAppId() throws Exception {
ApplicationReport appReport = mock(ApplicationReport.class);
when(appReport.getName()).thenReturn(jobName + "_" + jobId);
when(appReport.getApplicationId()).thenReturn(appId);
when(client.getApplications()).thenReturn(Collections.singletonList(appReport));
assertTrue(tool.validateAppId().equals(appId));
when(appReport.getName()).thenReturn("dummy");
exception.expect(SamzaException.class);
tool.validateAppId();
}
Aggregations