use of org.apache.tez.dag.api.client.rpc.DAGClientAMProtocolRPC.ShutdownSessionRequestProto 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