Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        private int VerifyApplicationState(ApplicationId appId)
        {
            YarnClient yarnClient = CreateYarnClient();

            try
            {
                ApplicationReport appReport = yarnClient.GetApplicationReport(appId);
                switch (appReport.GetYarnApplicationState())
                {
                case YarnApplicationState.New:
                case YarnApplicationState.NewSaving:
                case YarnApplicationState.Submitted:
                {
                    return(-1);
                }

                case YarnApplicationState.Accepted:
                case YarnApplicationState.Running:
                case YarnApplicationState.Failed:
                case YarnApplicationState.Finished:
                case YarnApplicationState.Killed:
                default:
                {
                    break;
                }
                }
            }
            finally
            {
                yarnClient.Close();
            }
            return(0);
        }
Beispiel #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestGetApplicationReportOnHA()
        {
            ApplicationReport report = client.GetApplicationReport(cluster.CreateFakeAppId());

            NUnit.Framework.Assert.IsTrue(report != null);
            NUnit.Framework.Assert.AreEqual(cluster.CreateFakeAppReport(), report);
        }
Beispiel #3
0
 /// <summary>Monitor the submitted application for completion.</summary>
 /// <remarks>
 /// Monitor the submitted application for completion.
 /// Kill application if time expires.
 /// </remarks>
 /// <param name="appId">Application Id of application to be monitored</param>
 /// <returns>true if application completed successfully</returns>
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 private bool MonitorApplication(ApplicationId appId)
 {
     while (true)
     {
         // Check app status every 1 second.
         try
         {
             Sharpen.Thread.Sleep(1000);
         }
         catch (Exception)
         {
             Log.Debug("Thread sleep in monitoring loop interrupted");
         }
         // Get application report for the appId we are interested in
         ApplicationReport report = yarnClient.GetApplicationReport(appId);
         Log.Info("Got application report from ASM for" + ", appId=" + appId.GetId() + ", clientToAMToken="
                  + report.GetClientToAMToken() + ", appDiagnostics=" + report.GetDiagnostics() +
                  ", appMasterHost=" + report.GetHost() + ", appQueue=" + report.GetQueue() + ", appMasterRpcPort="
                  + report.GetRpcPort() + ", appStartTime=" + report.GetStartTime() + ", yarnAppState="
                  + report.GetYarnApplicationState().ToString() + ", distributedFinalState=" + report
                  .GetFinalApplicationStatus().ToString() + ", appTrackingUrl=" + report.GetTrackingUrl
                      () + ", appUser="******"Application has completed successfully. Breaking monitoring loop");
                 return(true);
             }
             else
             {
                 Log.Info("Application did finished unsuccessfully." + " YarnState=" + state.ToString
                              () + ", DSFinalStatus=" + dsStatus.ToString() + ". Breaking monitoring loop");
                 return(false);
             }
         }
         else
         {
             if (YarnApplicationState.Killed == state || YarnApplicationState.Failed == state)
             {
                 Log.Info("Application did not finish." + " YarnState=" + state.ToString() + ", DSFinalStatus="
                          + dsStatus.ToString() + ". Breaking monitoring loop");
                 return(false);
             }
         }
         if (Runtime.CurrentTimeMillis() > (clientStartTime + clientTimeout))
         {
             Log.Info("Reached client specified timeout for application. Killing application");
             ForceKillApplication(appId);
             return(false);
         }
     }
 }
Beispiel #4
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private ApplicationAttemptReport MonitorCurrentAppAttempt(ApplicationId appId, YarnApplicationAttemptState
                                                                  attemptState)
        {
            long startTime = Runtime.CurrentTimeMillis();
            ApplicationAttemptId attemptId = null;

            while (true)
            {
                if (attemptId == null)
                {
                    attemptId = rmClient.GetApplicationReport(appId).GetCurrentApplicationAttemptId();
                }
                ApplicationAttemptReport attemptReport = null;
                if (attemptId != null)
                {
                    attemptReport = rmClient.GetApplicationAttemptReport(attemptId);
                    if (attemptState.Equals(attemptReport.GetYarnApplicationAttemptState()))
                    {
                        return(attemptReport);
                    }
                }
                Log.Info("Current attempt state of " + appId + " is " + (attemptReport == null ?
                                                                         " N/A " : attemptReport.GetYarnApplicationAttemptState()) + ", waiting for current attempt to reach "
                         + attemptState);
                try
                {
                    Sharpen.Thread.Sleep(1000);
                }
                catch (Exception)
                {
                    Log.Warn("Interrupted while waiting for current attempt of " + appId + " to reach "
                             + attemptState);
                }
                if (Runtime.CurrentTimeMillis() - startTime > AmStateWaitTimeoutMs)
                {
                    string errmsg = "Timeout for waiting current attempt of " + appId + " to reach "
                                    + attemptState;
                    Log.Error(errmsg);
                    throw new RuntimeException(errmsg);
                }
            }
        }
        public override bool IsApplicationActive(ApplicationId id)
        {
            ApplicationReport report = null;

            try
            {
                report = client.GetApplicationReport(id);
            }
            catch (ApplicationNotFoundException)
            {
                // the app does not exist
                return(false);
            }
            catch (IOException e)
            {
                throw new YarnException(e);
            }
            if (report == null)
            {
                // the app does not exist
                return(false);
            }
            return(ActiveStates.Contains(report.GetYarnApplicationState()));
        }
Beispiel #6
0
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 public override ApplicationReport GetApplicationReport(ApplicationId appId)
 {
     return(client.GetApplicationReport(appId));
 }