Beispiel #1
0
 public AppInfo(ApplicationReport app)
 {
     // JAXB needs this
     appId = app.GetApplicationId().ToString();
     if (app.GetCurrentApplicationAttemptId() != null)
     {
         currentAppAttemptId = app.GetCurrentApplicationAttemptId().ToString();
     }
     user                = app.GetUser();
     queue               = app.GetQueue();
     name                = app.GetName();
     type                = app.GetApplicationType();
     host                = app.GetHost();
     rpcPort             = app.GetRpcPort();
     appState            = app.GetYarnApplicationState();
     diagnosticsInfo     = app.GetDiagnostics();
     trackingUrl         = app.GetTrackingUrl();
     originalTrackingUrl = app.GetOriginalTrackingUrl();
     submittedTime       = app.GetStartTime();
     startedTime         = app.GetStartTime();
     finishedTime        = app.GetFinishTime();
     elapsedTime         = Times.Elapsed(startedTime, finishedTime);
     finalAppStatus      = app.GetFinalApplicationStatus();
     progress            = app.GetProgress() * 100;
     // in percent
     if (app.GetApplicationTags() != null && !app.GetApplicationTags().IsEmpty())
     {
         this.applicationTags = StringHelper.CsvJoiner.Join(app.GetApplicationTags());
     }
 }
Beispiel #2
0
        /// <exception cref="System.Exception"/>
        public virtual void TestInvalidatedAMHostPortOnAMRestart()
        {
            MockRM rm1 = new MockRM(conf);

            rm1.Start();
            MockNM nm1 = new MockNM("127.0.0.1:1234", 15120, rm1.GetResourceTrackerService());

            nm1.RegisterNode();
            // a failed app
            RMApp  app2 = rm1.SubmitApp(200);
            MockAM am2  = MockRM.LaunchAndRegisterAM(app2, rm1, nm1);

            nm1.NodeHeartbeat(am2.GetApplicationAttemptId(), 1, ContainerState.Complete);
            am2.WaitForState(RMAppAttemptState.Failed);
            rm1.WaitForState(app2.GetApplicationId(), RMAppState.Accepted);
            // before new attempt is launched, the app report returns the invalid AM
            // host and port.
            GetApplicationReportRequest request1 = GetApplicationReportRequest.NewInstance(app2
                                                                                           .GetApplicationId());
            ApplicationReport report1 = rm1.GetClientRMService().GetApplicationReport(request1
                                                                                      ).GetApplicationReport();

            NUnit.Framework.Assert.AreEqual("N/A", report1.GetHost());
            NUnit.Framework.Assert.AreEqual(-1, report1.GetRpcPort());
        }
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
        /// <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 ApplicationReport MonitorApplication(ApplicationId appId, ICollection <YarnApplicationState
                                                                                       > finalState)
        {
            long          foundAMCompletedTime = 0;
            StringBuilder expectedFinalState   = new StringBuilder();
            bool          first = true;

            foreach (YarnApplicationState state in finalState)
            {
                if (first)
                {
                    first = false;
                    expectedFinalState.Append(state.ToString());
                }
                else
                {
                    expectedFinalState.Append("," + state.ToString());
                }
            }
            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 = rmClient.GetApplicationReport(appId);
                Log.Info("Got application report from ASM for" + ", appId=" + appId.GetId() + ", appAttemptId="
                         + report.GetCurrentApplicationAttemptId() + ", 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="******"Waited " + AmStateWaitTimeoutMs / 1000 + " seconds after process completed for AppReport"
                                     + " to reach desired final state. Not waiting anymore." + "CurrentState = " + state_1
                                     + ", ExpectedStates = " + expectedFinalState.ToString());
                            throw new RuntimeException("Failed to receive final expected state" + " in ApplicationReport"
                                                       + ", CurrentState=" + state_1 + ", ExpectedStates=" + expectedFinalState.ToString
                                                           ());
                        }
                    }
                }
            }
        }
        /// <exception cref="System.IO.IOException"/>
        private MRClientProtocol GetProxy()
        {
            if (realProxy != null)
            {
                return(realProxy);
            }
            // Possibly allow nulls through the PB tunnel, otherwise deal with an exception
            // and redirect to the history server.
            ApplicationReport application = null;

            try
            {
                application = rm.GetApplicationReport(appId);
            }
            catch (ApplicationNotFoundException)
            {
                application = null;
            }
            catch (YarnException e2)
            {
                throw new IOException(e2);
            }
            if (application != null)
            {
                trackingUrl = application.GetTrackingUrl();
            }
            IPEndPoint serviceAddr = null;

            while (application == null || YarnApplicationState.Running == application.GetYarnApplicationState
                       ())
            {
                if (application == null)
                {
                    Log.Info("Could not get Job info from RM for job " + jobId + ". Redirecting to job history server."
                             );
                    return(CheckAndGetHSProxy(null, JobState.New));
                }
                try
                {
                    if (application.GetHost() == null || string.Empty.Equals(application.GetHost()))
                    {
                        Log.Debug("AM not assigned to Job. Waiting to get the AM ...");
                        Sharpen.Thread.Sleep(2000);
                        Log.Debug("Application state is " + application.GetYarnApplicationState());
                        application = rm.GetApplicationReport(appId);
                        continue;
                    }
                    else
                    {
                        if (Unavailable.Equals(application.GetHost()))
                        {
                            if (!amAclDisabledStatusLogged)
                            {
                                Log.Info("Job " + jobId + " is running, but the host is unknown." + " Verify user has VIEW_JOB access."
                                         );
                                amAclDisabledStatusLogged = true;
                            }
                            return(GetNotRunningJob(application, JobState.Running));
                        }
                    }
                    if (!conf.GetBoolean(MRJobConfig.JobAmAccessDisabled, false))
                    {
                        UserGroupInformation newUgi = UserGroupInformation.CreateRemoteUser(UserGroupInformation
                                                                                            .GetCurrentUser().GetUserName());
                        serviceAddr = NetUtils.CreateSocketAddrForHost(application.GetHost(), application
                                                                       .GetRpcPort());
                        if (UserGroupInformation.IsSecurityEnabled())
                        {
                            Token clientToAMToken = application.GetClientToAMToken();
                            Org.Apache.Hadoop.Security.Token.Token <ClientToAMTokenIdentifier> token = ConverterUtils
                                                                                                       .ConvertFromYarn(clientToAMToken, serviceAddr);
                            newUgi.AddToken(token);
                        }
                        Log.Debug("Connecting to " + serviceAddr);
                        IPEndPoint finalServiceAddr = serviceAddr;
                        realProxy = newUgi.DoAs(new _PrivilegedExceptionAction_202(this, finalServiceAddr
                                                                                   ));
                    }
                    else
                    {
                        if (!amAclDisabledStatusLogged)
                        {
                            Log.Info("Network ACL closed to AM for job " + jobId + ". Not going to try to reach the AM."
                                     );
                            amAclDisabledStatusLogged = true;
                        }
                        return(GetNotRunningJob(null, JobState.Running));
                    }
                    return(realProxy);
                }
                catch (IOException)
                {
                    //possibly the AM has crashed
                    //there may be some time before AM is restarted
                    //keep retrying by getting the address from RM
                    Log.Info("Could not connect to " + serviceAddr + ". Waiting for getting the latest AM address..."
                             );
                    try
                    {
                        Sharpen.Thread.Sleep(2000);
                    }
                    catch (Exception e1)
                    {
                        Log.Warn("getProxy() call interruped", e1);
                        throw new YarnRuntimeException(e1);
                    }
                    try
                    {
                        application = rm.GetApplicationReport(appId);
                    }
                    catch (YarnException e1)
                    {
                        throw new IOException(e1);
                    }
                    if (application == null)
                    {
                        Log.Info("Could not get Job info from RM for job " + jobId + ". Redirecting to job history server."
                                 );
                        return(CheckAndGetHSProxy(null, JobState.Running));
                    }
                }
                catch (Exception e)
                {
                    Log.Warn("getProxy() call interruped", e);
                    throw new YarnRuntimeException(e);
                }
                catch (YarnException e)
                {
                    throw new IOException(e);
                }
            }
            string user = application.GetUser();

            if (user == null)
            {
                throw new IOException("User is not set in the application report");
            }
            if (application.GetYarnApplicationState() == YarnApplicationState.New || application
                .GetYarnApplicationState() == YarnApplicationState.NewSaving || application.GetYarnApplicationState
                    () == YarnApplicationState.Submitted || application.GetYarnApplicationState() ==
                YarnApplicationState.Accepted)
            {
                realProxy = null;
                return(GetNotRunningJob(application, JobState.New));
            }
            if (application.GetYarnApplicationState() == YarnApplicationState.Failed)
            {
                realProxy = null;
                return(GetNotRunningJob(application, JobState.Failed));
            }
            if (application.GetYarnApplicationState() == YarnApplicationState.Killed)
            {
                realProxy = null;
                return(GetNotRunningJob(application, JobState.Killed));
            }
            //History server can serve a job only if application
            //succeeded.
            if (application.GetYarnApplicationState() == YarnApplicationState.Finished)
            {
                Log.Info("Application state is completed. FinalApplicationStatus=" + application.
                         GetFinalApplicationStatus().ToString() + ". Redirecting to job history server");
                realProxy = CheckAndGetHSProxy(application, JobState.Succeeded);
            }
            return(realProxy);
        }
Beispiel #6
0
        /// <summary>Prints the application report for an application id.</summary>
        /// <param name="applicationId"/>
        /// <returns>exitCode</returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        private int PrintApplicationReport(string applicationId)
        {
            ApplicationReport appReport = null;

            try
            {
                appReport = client.GetApplicationReport(ConverterUtils.ToApplicationId(applicationId
                                                                                       ));
            }
            catch (ApplicationNotFoundException)
            {
                sysout.WriteLine("Application with id '" + applicationId + "' doesn't exist in RM or Timeline Server."
                                 );
                return(-1);
            }
            // Use PrintWriter.println, which uses correct platform line ending.
            ByteArrayOutputStream baos         = new ByteArrayOutputStream();
            PrintWriter           appReportStr = new PrintWriter(new OutputStreamWriter(baos, Sharpen.Extensions.GetEncoding
                                                                                            ("UTF-8")));

            if (appReport != null)
            {
                appReportStr.WriteLine("Application Report : ");
                appReportStr.Write("\tApplication-Id : ");
                appReportStr.WriteLine(appReport.GetApplicationId());
                appReportStr.Write("\tApplication-Name : ");
                appReportStr.WriteLine(appReport.GetName());
                appReportStr.Write("\tApplication-Type : ");
                appReportStr.WriteLine(appReport.GetApplicationType());
                appReportStr.Write("\tUser : "******"\tQueue : ");
                appReportStr.WriteLine(appReport.GetQueue());
                appReportStr.Write("\tStart-Time : ");
                appReportStr.WriteLine(appReport.GetStartTime());
                appReportStr.Write("\tFinish-Time : ");
                appReportStr.WriteLine(appReport.GetFinishTime());
                appReportStr.Write("\tProgress : ");
                DecimalFormat formatter = new DecimalFormat("###.##%");
                string        progress  = formatter.Format(appReport.GetProgress());
                appReportStr.WriteLine(progress);
                appReportStr.Write("\tState : ");
                appReportStr.WriteLine(appReport.GetYarnApplicationState());
                appReportStr.Write("\tFinal-State : ");
                appReportStr.WriteLine(appReport.GetFinalApplicationStatus());
                appReportStr.Write("\tTracking-URL : ");
                appReportStr.WriteLine(appReport.GetOriginalTrackingUrl());
                appReportStr.Write("\tRPC Port : ");
                appReportStr.WriteLine(appReport.GetRpcPort());
                appReportStr.Write("\tAM Host : ");
                appReportStr.WriteLine(appReport.GetHost());
                appReportStr.Write("\tAggregate Resource Allocation : ");
                ApplicationResourceUsageReport usageReport = appReport.GetApplicationResourceUsageReport
                                                                 ();
                if (usageReport != null)
                {
                    //completed app report in the timeline server doesn't have usage report
                    appReportStr.Write(usageReport.GetMemorySeconds() + " MB-seconds, ");
                    appReportStr.WriteLine(usageReport.GetVcoreSeconds() + " vcore-seconds");
                }
                else
                {
                    appReportStr.WriteLine("N/A");
                }
                appReportStr.Write("\tDiagnostics : ");
                appReportStr.Write(appReport.GetDiagnostics());
            }
            else
            {
                appReportStr.Write("Application with id '" + applicationId + "' doesn't exist in RM."
                                   );
                appReportStr.Close();
                sysout.WriteLine(baos.ToString("UTF-8"));
                return(-1);
            }
            appReportStr.Close();
            sysout.WriteLine(baos.ToString("UTF-8"));
            return(0);
        }
        private void VerifyEnemyAppReport(ApplicationReport appReport)
        {
            NUnit.Framework.Assert.AreEqual("Enemy should not see app host!", Unavailable, appReport
                                            .GetHost());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app rpc port!", -1, appReport
                                            .GetRpcPort());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app client token!", null, appReport
                                            .GetClientToAMToken());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app diagnostics!", Unavailable
                                            , appReport.GetDiagnostics());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app tracking url!", Unavailable
                                            , appReport.GetTrackingUrl());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app original tracking url!"
                                            , Unavailable, appReport.GetOriginalTrackingUrl());
            ApplicationResourceUsageReport usageReport = appReport.GetApplicationResourceUsageReport
                                                             ();

            NUnit.Framework.Assert.AreEqual("Enemy should not see app used containers", -1, usageReport
                                            .GetNumUsedContainers());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app reserved containers", -
                                            1, usageReport.GetNumReservedContainers());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app used resources", -1, usageReport
                                            .GetUsedResources().GetMemory());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app reserved resources", -1
                                            , usageReport.GetReservedResources().GetMemory());
            NUnit.Framework.Assert.AreEqual("Enemy should not see app needed resources", -1,
                                            usageReport.GetNeededResources().GetMemory());
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestDSShell(bool haveDomain)
        {
            string[] args = new string[] { "--jar", AppmasterJar, "--num_containers", "2", "--shell_command"
                                           , Shell.Windows ? "dir" : "ls", "--master_memory", "512", "--master_vcores", "2"
                                           , "--container_memory", "128", "--container_vcores", "1" };
            if (haveDomain)
            {
                string[] domainArgs = new string[] { "--domain", "TEST_DOMAIN", "--view_acls", "reader_user reader_group"
                                                     , "--modify_acls", "writer_user writer_group", "--create" };
                IList <string> argsList = new AList <string>(Arrays.AsList(args));
                Sharpen.Collections.AddAll(argsList, Arrays.AsList(domainArgs));
                args = Sharpen.Collections.ToArray(argsList, new string[argsList.Count]);
            }
            Log.Info("Initializing DS Client");
            Client client      = new Client(new Configuration(yarnCluster.GetConfig()));
            bool   initSuccess = client.Init(args);

            NUnit.Framework.Assert.IsTrue(initSuccess);
            Log.Info("Running DS Client");
            AtomicBoolean result = new AtomicBoolean(false);

            Sharpen.Thread t = new _Thread_194(result, client);
            t.Start();
            YarnClient yarnClient = YarnClient.CreateYarnClient();

            yarnClient.Init(new Configuration(yarnCluster.GetConfig()));
            yarnClient.Start();
            string hostName     = NetUtils.GetHostname();
            bool   verified     = false;
            string errorMessage = string.Empty;

            while (!verified)
            {
                IList <ApplicationReport> apps = yarnClient.GetApplications();
                if (apps.Count == 0)
                {
                    Sharpen.Thread.Sleep(10);
                    continue;
                }
                ApplicationReport appReport = apps[0];
                if (appReport.GetHost().Equals("N/A"))
                {
                    Sharpen.Thread.Sleep(10);
                    continue;
                }
                errorMessage = "Expected host name to start with '" + hostName + "', was '" + appReport
                               .GetHost() + "'. Expected rpc port to be '-1', was '" + appReport.GetRpcPort() +
                               "'.";
                if (CheckHostname(appReport.GetHost()) && appReport.GetRpcPort() == -1)
                {
                    verified = true;
                }
                if (appReport.GetYarnApplicationState() == YarnApplicationState.Finished)
                {
                    break;
                }
            }
            NUnit.Framework.Assert.IsTrue(errorMessage, verified);
            t.Join();
            Log.Info("Client run completed. Result=" + result);
            NUnit.Framework.Assert.IsTrue(result.Get());
            TimelineDomain domain = null;

            if (haveDomain)
            {
                domain = yarnCluster.GetApplicationHistoryServer().GetTimelineStore().GetDomain("TEST_DOMAIN"
                                                                                                );
                NUnit.Framework.Assert.IsNotNull(domain);
                NUnit.Framework.Assert.AreEqual("reader_user reader_group", domain.GetReaders());
                NUnit.Framework.Assert.AreEqual("writer_user writer_group", domain.GetWriters());
            }
            TimelineEntities entitiesAttempts = yarnCluster.GetApplicationHistoryServer().GetTimelineStore
                                                    ().GetEntities(ApplicationMaster.DSEntity.DsAppAttempt.ToString(), null, null, null
                                                                   , null, null, null, null, null, null);

            NUnit.Framework.Assert.IsNotNull(entitiesAttempts);
            NUnit.Framework.Assert.AreEqual(1, entitiesAttempts.GetEntities().Count);
            NUnit.Framework.Assert.AreEqual(2, entitiesAttempts.GetEntities()[0].GetEvents().
                                            Count);
            NUnit.Framework.Assert.AreEqual(entitiesAttempts.GetEntities()[0].GetEntityType()
                                            .ToString(), ApplicationMaster.DSEntity.DsAppAttempt.ToString());
            if (haveDomain)
            {
                NUnit.Framework.Assert.AreEqual(domain.GetId(), entitiesAttempts.GetEntities()[0]
                                                .GetDomainId());
            }
            else
            {
                NUnit.Framework.Assert.AreEqual("DEFAULT", entitiesAttempts.GetEntities()[0].GetDomainId
                                                    ());
            }
            TimelineEntities entities = yarnCluster.GetApplicationHistoryServer().GetTimelineStore
                                            ().GetEntities(ApplicationMaster.DSEntity.DsContainer.ToString(), null, null, null
                                                           , null, null, null, null, null, null);

            NUnit.Framework.Assert.IsNotNull(entities);
            NUnit.Framework.Assert.AreEqual(2, entities.GetEntities().Count);
            NUnit.Framework.Assert.AreEqual(entities.GetEntities()[0].GetEntityType().ToString
                                                (), ApplicationMaster.DSEntity.DsContainer.ToString());
            if (haveDomain)
            {
                NUnit.Framework.Assert.AreEqual(domain.GetId(), entities.GetEntities()[0].GetDomainId
                                                    ());
            }
            else
            {
                NUnit.Framework.Assert.AreEqual("DEFAULT", entities.GetEntities()[0].GetDomainId(
                                                    ));
            }
        }