@Override public void unregisterApplicationMaster( FinalApplicationStatus appStatus, String appMessage, String appTrackingUrl) throws YarnException, IOException { Preconditions.checkArgument(appStatus != null, "AppStatus should not be null."); FinishApplicationMasterRequest request = FinishApplicationMasterRequest.newInstance(appStatus, appMessage, appTrackingUrl); try { while (true) { FinishApplicationMasterResponse response = rmClient.finishApplicationMaster(request); if (response.getIsUnregistered()) { break; } LOG.info("Waiting for application to be successfully unregistered."); Thread.sleep(100); } } catch (InterruptedException e) { LOG.info("Interrupted while waiting for application" + " to be removed from RMStateStore"); } catch (ApplicationMasterNotRegisteredException e) { LOG.warn("ApplicationMaster is out of sync with ResourceManager," + " hence resyncing."); // re register with RM registerApplicationMaster(); unregisterApplicationMaster(appStatus, appMessage, appTrackingUrl); } }
protected void unregister() { try { FinalApplicationStatus finishState = FinalApplicationStatus.UNDEFINED; JobImpl jobImpl = (JobImpl) job; if (jobImpl.getInternalState() == JobStateInternal.SUCCEEDED) { finishState = FinalApplicationStatus.SUCCEEDED; } else if (jobImpl.getInternalState() == JobStateInternal.KILLED || (jobImpl.getInternalState() == JobStateInternal.RUNNING && isSignalled)) { finishState = FinalApplicationStatus.KILLED; } else if (jobImpl.getInternalState() == JobStateInternal.FAILED || jobImpl.getInternalState() == JobStateInternal.ERROR) { finishState = FinalApplicationStatus.FAILED; } StringBuffer sb = new StringBuffer(); for (String s : job.getDiagnostics()) { sb.append(s).append("\n"); } LOG.info("Setting job diagnostics to " + sb.toString()); String historyUrl = JobHistoryUtils.getHistoryUrl(getConfig(), context.getApplicationID()); LOG.info("History url is " + historyUrl); FinishApplicationMasterRequest request = FinishApplicationMasterRequest.newInstance(finishState, sb.toString(), historyUrl); scheduler.finishApplicationMaster(request); } catch (Exception are) { LOG.error("Exception while unregistering ", are); } }
public void finishApplication(String diagnostics, FinalApplicationStatus finishState) throws YarnRemoteException { if (amResourceManager == null) throw new IllegalStateException( "Cannot finish an application without connecting to resource manager!"); FinishApplicationMasterRequest request = Records.newRecord(FinishApplicationMasterRequest.class); request.setAppAttemptId(appAttemptId); request.setDiagnostics(diagnostics); request.setFinishApplicationStatus(finishState); LOG.info( "Sending finish application notification " + ", state=" + request.getFinalApplicationStatus() + ", diagnostics=" + request.getDiagnostics()); amResourceManager.finishApplicationMaster(request); }