use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.
the class TestYarnCLI method testMoveApplicationAcrossQueuesWithNewCommand.
@Test
public void testMoveApplicationAcrossQueuesWithNewCommand() throws Exception {
ApplicationCLI cli = createAndGetAppCLI();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
ApplicationReport newApplicationReport2 = ApplicationReport.newInstance(applicationId, ApplicationAttemptId.newInstance(applicationId, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.FINISHED, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(newApplicationReport2);
int result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-changeQueue", "targetqueue" });
assertEquals(0, result);
verify(client, times(0)).moveApplicationAcrossQueues(any(ApplicationId.class), any(String.class));
verify(sysOut).println("Application " + applicationId + " has already finished ");
ApplicationReport newApplicationReport = ApplicationReport.newInstance(applicationId, ApplicationAttemptId.newInstance(applicationId, 1), "user", "queue", "appname", "host", 124, null, YarnApplicationState.RUNNING, "diagnostics", "url", 0, 0, FinalApplicationStatus.SUCCEEDED, null, "N/A", 0.53789f, "YARN", null);
when(client.getApplicationReport(any(ApplicationId.class))).thenReturn(newApplicationReport);
result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-changeQueue", "targetqueue" });
assertEquals(0, result);
verify(client).moveApplicationAcrossQueues(any(ApplicationId.class), any(String.class));
verify(sysOut).println("Moving application application_1234_0005 to queue targetqueue");
verify(sysOut).println("Successfully completed move.");
doThrow(new ApplicationNotFoundException("Application with id '" + applicationId + "' doesn't exist in RM.")).when(client).moveApplicationAcrossQueues(applicationId, "targetqueue");
cli = createAndGetAppCLI();
try {
result = cli.run(new String[] { "application", "-appId", applicationId.toString(), "-changeQueue", "targetqueue" });
Assert.fail();
} catch (Exception ex) {
Assert.assertTrue(ex instanceof ApplicationNotFoundException);
Assert.assertEquals("Application with id '" + applicationId + "' doesn't exist in RM.", ex.getMessage());
}
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project hadoop by apache.
the class TestYarnCLI method testGetApplicationReportException.
@Test
public void testGetApplicationReportException() throws Exception {
ApplicationCLI cli = createAndGetAppCLI();
ApplicationId applicationId = ApplicationId.newInstance(1234, 5);
when(client.getApplicationReport(any(ApplicationId.class))).thenThrow(new ApplicationNotFoundException("History file for application" + applicationId + " is not found"));
int exitCode = cli.run(new String[] { "application", "-status", applicationId.toString() });
verify(sysOut).println("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server.");
Assert.assertNotSame("should return non-zero exit code.", 0, exitCode);
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project tez by apache.
the class TezClientUtils method getAMProxy.
static DAGClientAMProtocolBlockingPB getAMProxy(FrameworkClient yarnClient, Configuration conf, ApplicationId applicationId) throws TezException, IOException {
ApplicationReport appReport;
try {
appReport = yarnClient.getApplicationReport(applicationId);
if (appReport == null) {
throw new TezUncheckedException("Could not retrieve application report" + " from YARN, applicationId=" + applicationId);
}
YarnApplicationState appState = appReport.getYarnApplicationState();
if (appState != YarnApplicationState.RUNNING) {
if (appState == YarnApplicationState.FINISHED || appState == YarnApplicationState.KILLED || appState == YarnApplicationState.FAILED) {
String msg = "Application not running" + ", applicationId=" + applicationId + ", yarnApplicationState=" + appReport.getYarnApplicationState() + ", finalApplicationStatus=" + appReport.getFinalApplicationStatus() + ", trackingUrl=" + appReport.getTrackingUrl() + ", diagnostics=" + (appReport.getDiagnostics() != null ? appReport.getDiagnostics() : TezClient.NO_CLUSTER_DIAGNOSTICS_MSG);
LOG.info(msg);
throw new SessionNotRunning(msg);
}
return null;
}
} catch (ApplicationNotFoundException e) {
throw new SessionNotRunning(e);
} catch (YarnException e) {
throw new TezException(e);
}
return getAMProxy(conf, appReport.getHost(), appReport.getRpcPort(), appReport.getClientToAMToken());
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project tez by apache.
the class TezClient method getAppMasterStatus.
/**
* Get the status of the App Master executing the DAG
* In non-session mode it returns the status of the last submitted DAG App Master
* In session mode, it returns the status of the App Master hosting the session
*
* @return State of the session
* @throws TezException
* @throws IOException
*/
public synchronized TezAppMasterStatus getAppMasterStatus() throws TezException, IOException {
// Supporting per-DAG app master case since user may choose to run the same
// code in that mode and the code should continue to work. Its easy to provide
// the correct view for per-DAG app master too.
ApplicationId appId = null;
if (isSession) {
appId = sessionAppId;
} else {
appId = lastSubmittedAppId;
}
Preconditions.checkState(appId != null, "Cannot get status without starting an application");
try {
ApplicationReport appReport = frameworkClient.getApplicationReport(appId);
switch(appReport.getYarnApplicationState()) {
case NEW:
case NEW_SAVING:
case ACCEPTED:
case SUBMITTED:
return TezAppMasterStatus.INITIALIZING;
case FAILED:
case KILLED:
diagnostics = appReport.getDiagnostics();
LOG.info("App did not succeed. Diagnostics: " + (appReport.getDiagnostics() != null ? appReport.getDiagnostics() : NO_CLUSTER_DIAGNOSTICS_MSG));
return TezAppMasterStatus.SHUTDOWN;
case FINISHED:
return TezAppMasterStatus.SHUTDOWN;
case RUNNING:
try {
DAGClientAMProtocolBlockingPB proxy = getAMProxy(appId);
if (proxy == null) {
return TezAppMasterStatus.INITIALIZING;
}
GetAMStatusResponseProto response = proxy.getAMStatus(null, GetAMStatusRequestProto.newBuilder().build());
return DagTypeConverters.convertTezAppMasterStatusFromProto(response.getStatus());
} catch (TezException e) {
LOG.info("Failed to retrieve AM Status via proxy", e);
} catch (ServiceException e) {
LOG.info("Failed to retrieve AM Status via proxy", e);
}
}
} catch (ApplicationNotFoundException e) {
return TezAppMasterStatus.SHUTDOWN;
} catch (YarnException e) {
throw new TezException(e);
}
return TezAppMasterStatus.INITIALIZING;
}
use of org.apache.hadoop.yarn.exceptions.ApplicationNotFoundException in project tez by apache.
the class TezClient method stop.
/**
* Stop the client. This terminates the connection to the YARN cluster.
* In session mode, this shuts down the session DAG App Master
* @throws TezException
* @throws IOException
*/
public synchronized void stop() throws TezException, IOException {
try {
if (amKeepAliveService != null) {
amKeepAliveService.shutdownNow();
}
if (sessionStarted.get()) {
LOG.info("Shutting down Tez Session" + ", sessionName=" + clientName + ", applicationId=" + sessionAppId);
sessionStopped.set(true);
boolean sessionShutdownSuccessful = false;
try {
DAGClientAMProtocolBlockingPB proxy = getAMProxy(sessionAppId);
if (proxy != null) {
ShutdownSessionRequestProto request = ShutdownSessionRequestProto.newBuilder().build();
proxy.shutdownSession(null, request);
sessionShutdownSuccessful = true;
boolean asynchronousStop = amConfig.getTezConfiguration().getBoolean(TezConfiguration.TEZ_CLIENT_ASYNCHRONOUS_STOP, TezConfiguration.TEZ_CLIENT_ASYNCHRONOUS_STOP_DEFAULT);
if (!asynchronousStop) {
LOG.info("Waiting until application is in a final state");
long currentTimeMillis = System.currentTimeMillis();
long timeKillIssued = currentTimeMillis;
long killTimeOut = amConfig.getTezConfiguration().getLong(TezConfiguration.TEZ_CLIENT_HARD_KILL_TIMEOUT_MS, TezConfiguration.TEZ_CLIENT_HARD_KILL_TIMEOUT_MS_DEFAULT);
ApplicationReport appReport = frameworkClient.getApplicationReport(sessionAppId);
while ((currentTimeMillis < timeKillIssued + killTimeOut) && !isJobInTerminalState(appReport.getYarnApplicationState())) {
try {
Thread.sleep(1000L);
} catch (InterruptedException ie) {
/**
* interrupted, just break
*/
break;
}
currentTimeMillis = System.currentTimeMillis();
appReport = frameworkClient.getApplicationReport(sessionAppId);
}
if (!isJobInTerminalState(appReport.getYarnApplicationState())) {
frameworkClient.killApplication(sessionAppId);
}
}
}
} catch (TezException e) {
LOG.info("Failed to shutdown Tez Session via proxy", e);
} catch (ServiceException e) {
LOG.info("Failed to shutdown Tez Session via proxy", e);
} catch (ApplicationNotFoundException e) {
LOG.info("Failed to kill nonexistent application " + sessionAppId, e);
} catch (YarnException e) {
throw new TezException(e);
}
if (!sessionShutdownSuccessful) {
LOG.info("Could not connect to AM, killing session via YARN" + ", sessionName=" + clientName + ", applicationId=" + sessionAppId);
try {
frameworkClient.killApplication(sessionAppId);
} catch (ApplicationNotFoundException e) {
LOG.info("Failed to kill nonexistent application " + sessionAppId, e);
} catch (YarnException e) {
throw new TezException(e);
}
}
}
} finally {
if (frameworkClient != null) {
frameworkClient.close();
}
}
}
Aggregations