Ejemplo n.º 1
0
        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();
            }
        }