/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> public override void UnregisterApplicationMaster(FinalApplicationStatus appStatus , string appMessage, string appTrackingUrl) { 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."); Sharpen.Thread.Sleep(100); } } catch (Exception) { Log.Info("Interrupted while waiting for application" + " to be removed from RMStateStore" ); } catch (ApplicationMasterNotRegisteredException) { Log.Warn("ApplicationMaster is out of sync with ResourceManager," + " hence resyncing." ); // re register with RM RegisterApplicationMaster(); UnregisterApplicationMaster(appStatus, appMessage, appTrackingUrl); } }
// Expected // provide main method so this class can act as AM /// <exception cref="System.Exception"/> public static void Main(string[] args) { if (args[0].Equals("success")) { ApplicationMasterProtocol client = ClientRMProxy.CreateRMProxy <ApplicationMasterProtocol >(conf); client.RegisterApplicationMaster(RegisterApplicationMasterRequest.NewInstance(NetUtils .GetHostname(), -1, string.Empty)); Sharpen.Thread.Sleep(1000); FinishApplicationMasterResponse resp = client.FinishApplicationMaster(FinishApplicationMasterRequest .NewInstance(FinalApplicationStatus.Succeeded, "success", null)); NUnit.Framework.Assert.IsTrue(resp.GetIsUnregistered()); System.Environment.Exit(0); } else { System.Environment.Exit(1); } }
protected internal virtual void DoUnregistration() { 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; } } } StringBuilder sb = new StringBuilder(); foreach (string s in job.GetDiagnostics()) { sb.Append(s).Append("\n"); } Log.Info("Setting job diagnostics to " + sb.ToString()); string historyUrl = MRWebAppUtil.GetApplicationWebURLOnJHSWithScheme(GetConfig(), context.GetApplicationID()); Log.Info("History url is " + historyUrl); FinishApplicationMasterRequest request = FinishApplicationMasterRequest.NewInstance (finishState, sb.ToString(), historyUrl); try { while (true) { FinishApplicationMasterResponse response = scheduler.FinishApplicationMaster(request ); if (response.GetIsUnregistered()) { // When excepting ClientService, other services are already stopped, // it is safe to let clients know the final states. ClientService // should wait for some time so clients have enough time to know the // final states. MRAppMaster.RunningAppContext raContext = (MRAppMaster.RunningAppContext)context; raContext.MarkSuccessfulUnregistration(); break; } Log.Info("Waiting for application to be successfully unregistered."); Sharpen.Thread.Sleep(rmPollInterval); } } catch (ApplicationMasterNotRegisteredException) { // RM might have restarted or failed over and so lost the fact that AM had // registered before. Register(); DoUnregistration(); } }