/// <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); } }
/// <exception cref="System.IO.IOException"/> public FinishApplicationMasterResponse FinishApplicationMaster(FinishApplicationMasterRequest request) { FinishApplicationMasterResponse response = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <FinishApplicationMasterResponse>(); return(response); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> public virtual void TestFinishApplicationMasterOnHA() { FinishApplicationMasterRequest request = FinishApplicationMasterRequest.NewInstance (FinalApplicationStatus.Succeeded, string.Empty, string.Empty); FinishApplicationMasterResponse response = amClient.FinishApplicationMaster(request ); NUnit.Framework.Assert.AreEqual(response, this.cluster.CreateFakeFinishApplicationMasterResponse ()); }
/// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/> /// <exception cref="System.IO.IOException"/> public virtual FinishApplicationMasterResponse FinishApplicationMaster(FinishApplicationMasterRequest request) { ApplicationAttemptId applicationAttemptId = AuthorizeRequest().GetApplicationAttemptId (); ApplicationId appId = applicationAttemptId.GetApplicationId(); RMApp rmApp = rmContext.GetRMApps()[applicationAttemptId.GetApplicationId()]; // checking whether the app exits in RMStateStore at first not to throw // ApplicationDoesNotExistInCacheException before and after // RM work-preserving restart. if (rmApp.IsAppFinalStateStored()) { Log.Info(rmApp.GetApplicationId() + " unregistered successfully. "); return(FinishApplicationMasterResponse.NewInstance(true)); } ApplicationMasterService.AllocateResponseLock Lock = responseMap[applicationAttemptId ]; if (Lock == null) { ThrowApplicationDoesNotExistInCacheException(applicationAttemptId); } // Allow only one thread in AM to do finishApp at a time. lock (Lock) { if (!HasApplicationMasterRegistered(applicationAttemptId)) { string message = "Application Master is trying to unregister before registering for: " + appId; Log.Error(message); RMAuditLogger.LogFailure(this.rmContext.GetRMApps()[appId].GetUser(), RMAuditLogger.AuditConstants .UnregisterAm, string.Empty, "ApplicationMasterService", message, appId, applicationAttemptId ); throw new ApplicationMasterNotRegisteredException(message); } this.amLivelinessMonitor.ReceivedPing(applicationAttemptId); rmContext.GetDispatcher().GetEventHandler().Handle(new RMAppAttemptUnregistrationEvent (applicationAttemptId, request.GetTrackingUrl(), request.GetFinalApplicationStatus (), request.GetDiagnostics())); // For UnmanagedAMs, return true so they don't retry return(FinishApplicationMasterResponse.NewInstance(rmApp.GetApplicationSubmissionContext ().GetUnmanagedAM())); } }
// 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); } }
/// <exception cref="Com.Google.Protobuf.ServiceException"/> public virtual YarnServiceProtos.FinishApplicationMasterResponseProto FinishApplicationMaster (RpcController arg0, YarnServiceProtos.FinishApplicationMasterRequestProto proto ) { FinishApplicationMasterRequestPBImpl request = new FinishApplicationMasterRequestPBImpl (proto); try { FinishApplicationMasterResponse response = real.FinishApplicationMaster(request); return(((FinishApplicationMasterResponsePBImpl)response).GetProto()); } catch (YarnException e) { throw new ServiceException(e); } catch (IOException e) { throw new ServiceException(e); } }
public virtual FinishApplicationMasterResponse CreateFakeFinishApplicationMasterResponse () { return(FinishApplicationMasterResponse.NewInstance(true)); }
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(); } }