Example #1
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());
        }
        /// <exception cref="System.Exception"/>
        private static ApplicationClientProtocol CreateMockRMClient(IList <ApplicationId>
                                                                    finishedApplicaitons, IList <ApplicationId> runningApplications)
        {
            ApplicationClientProtocol mockProtocol = Org.Mockito.Mockito.Mock <ApplicationClientProtocol
                                                                               >();

            if (finishedApplicaitons != null && !finishedApplicaitons.IsEmpty())
            {
                foreach (ApplicationId appId in finishedApplicaitons)
                {
                    GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(appId
                                                                                                  );
                    GetApplicationReportResponse response = CreateApplicationReportWithFinishedApplication
                                                                ();
                    Org.Mockito.Mockito.When(mockProtocol.GetApplicationReport(request)).ThenReturn(response
                                                                                                    );
                }
            }
            if (runningApplications != null && !runningApplications.IsEmpty())
            {
                foreach (ApplicationId appId in runningApplications)
                {
                    GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(appId
                                                                                                  );
                    GetApplicationReportResponse response = CreateApplicationReportWithRunningApplication
                                                                ();
                    Org.Mockito.Mockito.When(mockProtocol.GetApplicationReport(request)).ThenReturn(response
                                                                                                    );
                }
            }
            return(mockProtocol);
        }
        /// <exception cref="System.Exception"/>
        private void VerifyAdministerQueueUserAccess()
        {
            isQueueUser = true;
            AccessControlList viewACL = new AccessControlList(string.Empty);

            viewACL.AddGroup(FriendlyGroup);
            AccessControlList modifyACL = new AccessControlList(string.Empty);

            modifyACL.AddUser(Friend);
            ApplicationId applicationId = SubmitAppAndGetAppId(viewACL, modifyACL);
            GetApplicationReportRequest appReportRequest = recordFactory.NewRecordInstance <GetApplicationReportRequest
                                                                                            >();

            appReportRequest.SetApplicationId(applicationId);
            KillApplicationRequest finishAppRequest = recordFactory.NewRecordInstance <KillApplicationRequest
                                                                                       >();

            finishAppRequest.SetApplicationId(applicationId);
            ApplicationClientProtocol administerQueueUserRmClient = GetRMClientForUser(QueueAdminUser
                                                                                       );

            // View as the administerQueueUserRmClient
            administerQueueUserRmClient.GetApplicationReport(appReportRequest);
            // List apps as administerQueueUserRmClient
            NUnit.Framework.Assert.AreEqual("App view by queue-admin-user should list the apps!!"
                                            , 5, administerQueueUserRmClient.GetApplications(recordFactory.NewRecordInstance
                                                                                             <GetApplicationsRequest>()).GetApplicationList().Count);
            // Kill app as the administerQueueUserRmClient
            administerQueueUserRmClient.ForceKillApplication(finishAppRequest);
            resourceManager.WaitForState(applicationId, RMAppState.Killed);
        }
Example #4
0
            /// <exception cref="System.Exception"/>
            public ApplicationReport Run()
            {
                GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(id);

                return(this._enclosing.appBaseProt.GetApplicationReport(request).GetApplicationReport
                           ());
            }
Example #5
0
        /// <summary>
        /// Get an application report for the specified application id from the RM and
        /// fall back to the Application History Server if not found in RM.
        /// </summary>
        /// <param name="appId">id of the application to get.</param>
        /// <returns>the ApplicationReport for the appId.</returns>
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException">on any error.</exception>
        /// <exception cref="System.IO.IOException"/>
        public virtual AppReportFetcher.FetchedAppReport GetApplicationReport(ApplicationId
                                                                              appId)
        {
            GetApplicationReportRequest request = recordFactory.NewRecordInstance <GetApplicationReportRequest
                                                                                   >();

            request.SetApplicationId(appId);
            ApplicationReport appReport;

            AppReportFetcher.FetchedAppReport fetchedAppReport;
            try
            {
                appReport = applicationsManager.GetApplicationReport(request).GetApplicationReport
                                ();
                fetchedAppReport = new AppReportFetcher.FetchedAppReport(appReport, AppReportFetcher.AppReportSource
                                                                         .Rm);
            }
            catch (ApplicationNotFoundException e)
            {
                if (!isAHSEnabled)
                {
                    // Just throw it as usual if historyService is not enabled.
                    throw;
                }
                //Fetch the application report from AHS
                appReport        = historyManager.GetApplicationReport(request).GetApplicationReport();
                fetchedAppReport = new AppReportFetcher.FetchedAppReport(appReport, AppReportFetcher.AppReportSource
                                                                         .Ahs);
            }
            return(fetchedAppReport);
        }
        /// <exception cref="System.Exception"/>
        private void VerifyOwnerAccess()
        {
            AccessControlList viewACL = new AccessControlList(string.Empty);

            viewACL.AddGroup(FriendlyGroup);
            AccessControlList modifyACL = new AccessControlList(string.Empty);

            modifyACL.AddUser(Friend);
            ApplicationId applicationId = SubmitAppAndGetAppId(viewACL, modifyACL);
            GetApplicationReportRequest appReportRequest = recordFactory.NewRecordInstance <GetApplicationReportRequest
                                                                                            >();

            appReportRequest.SetApplicationId(applicationId);
            KillApplicationRequest finishAppRequest = recordFactory.NewRecordInstance <KillApplicationRequest
                                                                                       >();

            finishAppRequest.SetApplicationId(applicationId);
            // View as owner
            rmClient.GetApplicationReport(appReportRequest);
            // List apps as owner
            NUnit.Framework.Assert.AreEqual("App view by owner should list the apps!!", 1, rmClient
                                            .GetApplications(recordFactory.NewRecordInstance <GetApplicationsRequest>()).GetApplicationList
                                                ().Count);
            // Kill app as owner
            rmClient.ForceKillApplication(finishAppRequest);
            resourceManager.WaitForState(applicationId, RMAppState.Killed);
        }
Example #7
0
        public virtual AppInfo GetApp(HttpServletRequest req, HttpServletResponse res, string
                                      appId)
        {
            UserGroupInformation callerUGI = GetUser(req);
            ApplicationId        id        = ParseApplicationId(appId);
            ApplicationReport    app       = null;

            try
            {
                if (callerUGI == null)
                {
                    GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(id);
                    app = appBaseProt.GetApplicationReport(request).GetApplicationReport();
                }
                else
                {
                    app = callerUGI.DoAs(new _PrivilegedExceptionAction_228(this, id));
                }
            }
            catch (Exception e)
            {
                RewrapAndThrowException(e);
            }
            if (app == null)
            {
                throw new NotFoundException("app with id: " + appId + " not found");
            }
            return(new AppInfo(app));
        }
Example #8
0
        public virtual void TestApplicationNotFound()
        {
            ApplicationId appId = null;

            appId = ApplicationId.NewInstance(0, MaxApps + 1);
            GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(appId
                                                                                          );

            try
            {
                GetApplicationReportResponse response = clientService.GetApplicationReport(request
                                                                                           );
                NUnit.Framework.Assert.Fail("Exception should have been thrown before we reach here."
                                            );
            }
            catch (ApplicationNotFoundException e)
            {
                //This exception is expected.
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("doesn't exist in the timeline store"
                                                                 ));
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.Fail("Undesired exception caught");
            }
        }
Example #9
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual ApplicationReport GetApplicationReport(ApplicationId appId)
        {
            ApplicationClientProtocol    client   = GetClientRMService();
            GetApplicationReportResponse response = client.GetApplicationReport(GetApplicationReportRequest
                                                                                .NewInstance(appId));

            return(response.GetApplicationReport());
        }
Example #10
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override ApplicationReport GetApplicationReport(ApplicationId appId)
        {
            GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(appId
                                                                                          );
            GetApplicationReportResponse response = ahsClient.GetApplicationReport(request);

            return(response.GetApplicationReport());
        }
Example #11
0
                /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
                public override GetApplicationReportResponse GetApplicationReport(GetApplicationReportRequest
                                                                                  request)
                {
                    this._enclosing.ResetStartFailoverFlag(true);
                    // make sure failover has been triggered
                    NUnit.Framework.Assert.IsTrue(this._enclosing.WaittingForFailOver());
                    // create a fake application report
                    ApplicationReport            report   = this._enclosing.CreateFakeAppReport();
                    GetApplicationReportResponse response = GetApplicationReportResponse.NewInstance(
                        report);

                    return(response);
                }
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 public virtual GetApplicationReportResponse GetApplicationReport(GetApplicationReportRequest
                                                                  request)
 {
     YarnServiceProtos.GetApplicationReportRequestProto requestProto = ((GetApplicationReportRequestPBImpl
                                                                         )request).GetProto();
     try
     {
         return(new GetApplicationReportResponsePBImpl(proxy.GetApplicationReport(null, requestProto
                                                                                  )));
     }
     catch (ServiceException e)
     {
         RPCUtil.UnwrapAndThrowException(e);
         return(null);
     }
 }
        /// <exception cref="System.Exception"/>
        private void VerifyEnemyAccess()
        {
            AccessControlList viewACL = new AccessControlList(string.Empty);

            viewACL.AddGroup(FriendlyGroup);
            AccessControlList modifyACL = new AccessControlList(string.Empty);

            modifyACL.AddUser(Friend);
            ApplicationId applicationId = SubmitAppAndGetAppId(viewACL, modifyACL);
            GetApplicationReportRequest appReportRequest = recordFactory.NewRecordInstance <GetApplicationReportRequest
                                                                                            >();

            appReportRequest.SetApplicationId(applicationId);
            KillApplicationRequest finishAppRequest = recordFactory.NewRecordInstance <KillApplicationRequest
                                                                                       >();

            finishAppRequest.SetApplicationId(applicationId);
            ApplicationClientProtocol enemyRmClient = GetRMClientForUser(Enemy);
            // View as the enemy
            ApplicationReport appReport = enemyRmClient.GetApplicationReport(appReportRequest
                                                                             ).GetApplicationReport();

            VerifyEnemyAppReport(appReport);
            // List apps as enemy
            IList <ApplicationReport> appReports = enemyRmClient.GetApplications(recordFactory
                                                                                 .NewRecordInstance <GetApplicationsRequest>()).GetApplicationList();

            NUnit.Framework.Assert.AreEqual("App view by enemy should list the apps!!", 4, appReports
                                            .Count);
            foreach (ApplicationReport report in appReports)
            {
                VerifyEnemyAppReport(report);
            }
            // Kill app as the enemy
            try
            {
                enemyRmClient.ForceKillApplication(finishAppRequest);
                NUnit.Framework.Assert.Fail("App killing by the enemy should fail!!");
            }
            catch (YarnException e)
            {
                Log.Info("Got exception while killing app as the enemy", e);
                NUnit.Framework.Assert.IsTrue(e.Message.Contains("User enemy cannot perform operation MODIFY_APP on "
                                                                 + applicationId));
            }
            rmClient.ForceKillApplication(finishAppRequest);
        }
Example #14
0
        /// <exception cref="System.Exception"/>
        private void VerifyGetClientAMToken(string submitter, string queueAdmin, string queueName
                                            , bool setupACLs)
        {
            ApplicationId applicationId = SubmitAppAndGetAppId(submitter, queueName, setupACLs
                                                               );
            GetApplicationReportRequest appReportRequest = GetApplicationReportRequest.NewInstance
                                                               (applicationId);
            ApplicationClientProtocol    submitterClient    = GetRMClientForUser(submitter);
            ApplicationClientProtocol    adMinUserClient    = GetRMClientForUser(queueAdmin);
            GetApplicationReportResponse submitterGetReport = submitterClient.GetApplicationReport
                                                                  (appReportRequest);
            GetApplicationReportResponse adMinUserGetReport = adMinUserClient.GetApplicationReport
                                                                  (appReportRequest);

            NUnit.Framework.Assert.AreEqual(submitterGetReport.GetApplicationReport().GetClientToAMToken
                                                (), adMinUserGetReport.GetApplicationReport().GetClientToAMToken());
        }
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual GetApplicationReportResponse GetApplicationReport(GetApplicationReportRequest
                                                                         request)
        {
            ApplicationId applicationId = request.GetApplicationId();

            try
            {
                GetApplicationReportResponse response = GetApplicationReportResponse.NewInstance(
                    history.GetApplication(applicationId));
                return(response);
            }
            catch (IOException e)
            {
                Log.Error(e.Message, e);
                throw;
            }
        }
Example #16
0
            /// <exception cref="System.IO.IOException"/>
            public virtual GetApplicationReportResponse GetApplicationReport(GetApplicationReportRequest
                                                                             request)
            {
                ApplicationId     applicationId = request.GetApplicationId();
                ApplicationReport application   = TestClientRedirect.recordFactory.NewRecordInstance
                                                  <ApplicationReport>();

                application.SetApplicationId(applicationId);
                application.SetFinalApplicationStatus(FinalApplicationStatus.Undefined);
                if (this._enclosing.amRunning)
                {
                    application.SetYarnApplicationState(YarnApplicationState.Running);
                }
                else
                {
                    if (this._enclosing.amRestarting)
                    {
                        application.SetYarnApplicationState(YarnApplicationState.Submitted);
                    }
                    else
                    {
                        application.SetYarnApplicationState(YarnApplicationState.Finished);
                        application.SetFinalApplicationStatus(FinalApplicationStatus.Succeeded);
                    }
                }
                string[] split = TestClientRedirect.Amhostaddress.Split(":");
                application.SetHost(split[0]);
                application.SetRpcPort(System.Convert.ToInt32(split[1]));
                application.SetUser("TestClientRedirect-user");
                application.SetName("N/A");
                application.SetQueue("N/A");
                application.SetStartTime(0);
                application.SetFinishTime(0);
                application.SetTrackingUrl("N/A");
                application.SetDiagnostics("N/A");
                GetApplicationReportResponse response = TestClientRedirect.recordFactory.NewRecordInstance
                                                        <GetApplicationReportResponse>();

                response.SetApplicationReport(application);
                return(response);
            }
Example #17
0
        public virtual void TestApplicationReport()
        {
            ApplicationId appId = null;

            appId = ApplicationId.NewInstance(0, 1);
            GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(appId
                                                                                          );
            GetApplicationReportResponse response = clientService.GetApplicationReport(request
                                                                                       );
            ApplicationReport appReport = response.GetApplicationReport();

            NUnit.Framework.Assert.IsNotNull(appReport);
            NUnit.Framework.Assert.AreEqual(123, appReport.GetApplicationResourceUsageReport(
                                                ).GetMemorySeconds());
            NUnit.Framework.Assert.AreEqual(345, appReport.GetApplicationResourceUsageReport(
                                                ).GetVcoreSeconds());
            NUnit.Framework.Assert.AreEqual("application_0_0001", appReport.GetApplicationId(
                                                ).ToString());
            NUnit.Framework.Assert.AreEqual("test app type", appReport.GetApplicationType().ToString
                                                ());
            NUnit.Framework.Assert.AreEqual("test queue", appReport.GetQueue().ToString());
        }
Example #18
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override ApplicationReport GetApplicationReport(ApplicationId appId)
        {
            GetApplicationReportResponse response = null;

            try
            {
                GetApplicationReportRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord
                                                      <GetApplicationReportRequest>();
                request.SetApplicationId(appId);
                response = rmClient.GetApplicationReport(request);
            }
            catch (ApplicationNotFoundException e)
            {
                if (!historyServiceEnabled)
                {
                    // Just throw it as usual if historyService is not enabled.
                    throw;
                }
                return(historyClient.GetApplicationReport(appId));
            }
            return(response.GetApplicationReport());
        }
            /// <exception cref="System.IO.IOException"/>
            private static bool IsApplicationTerminated(ApplicationId appId, ApplicationClientProtocol
                                                        rmClient)
            {
                ApplicationReport appReport = null;

                try
                {
                    appReport = rmClient.GetApplicationReport(GetApplicationReportRequest.NewInstance
                                                                  (appId)).GetApplicationReport();
                }
                catch (ApplicationNotFoundException)
                {
                    return(true);
                }
                catch (YarnException e)
                {
                    throw new IOException(e);
                }
                YarnApplicationState currentState = appReport.GetYarnApplicationState();

                return(currentState == YarnApplicationState.Failed || currentState == YarnApplicationState
                       .Killed || currentState == YarnApplicationState.Finished);
            }
Example #20
0
 public _PrivilegedExceptionAction_99(AppBlock _enclosing, GetApplicationReportRequest
                                      request)
 {
     this._enclosing = _enclosing;
     this.request    = request;
 }
        public virtual void TestClientToAMTokens()
        {
            conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "kerberos");
            UserGroupInformation.SetConfiguration(conf);
            ContainerManagementProtocol containerManager = Org.Mockito.Mockito.Mock <ContainerManagementProtocol
                                                                                     >();
            StartContainersResponse mockResponse = Org.Mockito.Mockito.Mock <StartContainersResponse
                                                                             >();

            Org.Mockito.Mockito.When(containerManager.StartContainers((StartContainersRequest
                                                                       )Matchers.Any())).ThenReturn(mockResponse);
            DrainDispatcher dispatcher = new DrainDispatcher();
            MockRM          rm         = new _MockRMWithCustomAMLauncher_192(dispatcher, conf, containerManager
                                                                             );

            rm.Start();
            // Submit an app
            RMApp app = rm.SubmitApp(1024);
            // Set up a node.
            MockNM nm1 = rm.RegisterNode("localhost:1234", 3072);

            nm1.NodeHeartbeat(true);
            dispatcher.Await();
            nm1.NodeHeartbeat(true);
            dispatcher.Await();
            ApplicationAttemptId appAttempt = app.GetCurrentAppAttempt().GetAppAttemptId();
            MockAM mockAM = new MockAM(rm.GetRMContext(), rm.GetApplicationMasterService(), app
                                       .GetCurrentAppAttempt().GetAppAttemptId());
            UserGroupInformation appUgi = UserGroupInformation.CreateRemoteUser(appAttempt.ToString
                                                                                    ());
            RegisterApplicationMasterResponse response = appUgi.DoAs(new _PrivilegedAction_229
                                                                         (mockAM));
            // Get the app-report.
            GetApplicationReportRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord
                                                  <GetApplicationReportRequest>();

            request.SetApplicationId(app.GetApplicationId());
            GetApplicationReportResponse reportResponse = rm.GetClientRMService().GetApplicationReport
                                                              (request);
            ApplicationReport appReport = reportResponse.GetApplicationReport();

            Org.Apache.Hadoop.Yarn.Api.Records.Token originalClientToAMToken = appReport.GetClientToAMToken
                                                                                   ();
            // ClientToAMToken master key should have been received on register
            // application master response.
            NUnit.Framework.Assert.IsNotNull(response.GetClientToAMTokenMasterKey());
            NUnit.Framework.Assert.IsTrue(((byte[])response.GetClientToAMTokenMasterKey().Array
                                               ()).Length > 0);
            // Start the AM with the correct shared-secret.
            ApplicationAttemptId appAttemptId = app.GetAppAttempts().Keys.GetEnumerator().Next
                                                    ();

            NUnit.Framework.Assert.IsNotNull(appAttemptId);
            TestClientToAMTokens.CustomAM am = new TestClientToAMTokens.CustomAM(appAttemptId
                                                                                 , ((byte[])response.GetClientToAMTokenMasterKey().Array()));
            am.Init(conf);
            am.Start();
            // Now the real test!
            // Set up clients to be able to pick up correct tokens.
            SecurityUtil.SetSecurityInfoProviders(new TestClientToAMTokens.CustomSecurityInfo
                                                      ());
            // Verify denial for unauthenticated user
            try
            {
                TestClientToAMTokens.CustomProtocol client = (TestClientToAMTokens.CustomProtocol
                                                              )RPC.GetProxy <TestClientToAMTokens.CustomProtocol>(1L, am.address, conf);
                client.Ping();
                NUnit.Framework.Assert.Fail("Access by unauthenticated user should fail!!");
            }
            catch (Exception)
            {
                NUnit.Framework.Assert.IsFalse(am.pinged);
            }
            Org.Apache.Hadoop.Security.Token.Token <ClientToAMTokenIdentifier> token = ConverterUtils
                                                                                       .ConvertFromYarn(originalClientToAMToken, am.address);
            // Verify denial for a malicious user with tampered ID
            VerifyTokenWithTamperedID(conf, am, token);
            // Verify denial for a malicious user with tampered user-name
            VerifyTokenWithTamperedUserName(conf, am, token);
            // Now for an authenticated user
            VerifyValidToken(conf, am, token);
            // Verify for a new version token
            VerifyNewVersionToken(conf, am, token, rm);
            am.Stop();
            rm.Stop();
        }
Example #22
0
        protected override void Render(HtmlBlock.Block html)
        {
            string webUiType = $(YarnWebParams.WebUiType);
            string aid       = $(YarnWebParams.ApplicationId);

            if (aid.IsEmpty())
            {
                Puts("Bad request: requires Application ID");
                return;
            }
            try
            {
                appID = Apps.ToAppID(aid);
            }
            catch (Exception)
            {
                Puts("Invalid Application ID: " + aid);
                return;
            }
            UserGroupInformation callerUGI = GetCallerUGI();
            ApplicationReport    appReport;

            try
            {
                GetApplicationReportRequest request = GetApplicationReportRequest.NewInstance(appID
                                                                                              );
                if (callerUGI == null)
                {
                    appReport = appBaseProt.GetApplicationReport(request).GetApplicationReport();
                }
                else
                {
                    appReport = callerUGI.DoAs(new _PrivilegedExceptionAction_99(this, request));
                }
            }
            catch (Exception e)
            {
                string message = "Failed to read the application " + appID + ".";
                Log.Error(message, e);
                html.P().(message).();
                return;
            }
            if (appReport == null)
            {
                Puts("Application not found: " + aid);
                return;
            }
            AppInfo app = new AppInfo(appReport);

            SetTitle(StringHelper.Join("Application ", aid));
            if (webUiType != null && webUiType.Equals(YarnWebParams.RmWebUi) && conf.GetBoolean
                    (YarnConfiguration.RmWebappUiActionsEnabled, YarnConfiguration.DefaultRmWebappUiActionsEnabled
                    ))
            {
                // Application Kill
                html.Div().Button().$onclick("confirmAction()").B("Kill Application").().();
                StringBuilder script = new StringBuilder();
                script.Append("function confirmAction() {").Append(" b = confirm(\"Are you sure?\");"
                                                                   ).Append(" if (b == true) {").Append(" $.ajax({").Append(" type: 'PUT',").Append
                    (" url: '/ws/v1/cluster/apps/").Append(aid).Append("/state',").Append(" contentType: 'application/json',"
                                                                                          ).Append(" data: '{\"state\":\"KILLED\"}',").Append(" dataType: 'json'").Append(
                    " }).done(function(data){").Append(" setTimeout(function(){").Append(" location.href = '/cluster/app/"
                                                                                         ).Append(aid).Append("';").Append(" }, 1000);").Append(" }).fail(function(data){"
                                                                                                                                                ).Append(" console.log(data);").Append(" });").Append(" }").Append("}");
                html.Script().$type("text/javascript").(script.ToString()).();
            }
            Info("Application Overview").("User:"******"Name:", app.GetName()).("Application Type:"
                                                                                            , app.GetType()).("Application Tags:", app.GetApplicationTags() == null ? string.Empty
                                 : app.GetApplicationTags()).("YarnApplicationState:", app.GetAppState() == null
                                 ? Unavailable : ClarifyAppState(app.GetAppState())).("FinalStatus Reported by AM:"
                                                                                      , ClairfyAppFinalStatus(app.GetFinalAppStatus())).("Started:", Times.Format(app.
                                                                                                                                                                  GetStartedTime())).("Elapsed:", StringUtils.FormatTime(Times.Elapsed(app.GetStartedTime
                                                                                                                                                                                                                                           (), app.GetFinishedTime()))).("Tracking URL:", app.GetTrackingUrl() == null || app
                                                                                                                                                                                                                                                                         .GetTrackingUrl().Equals(Unavailable) ? null : Root_url(app.GetTrackingUrl()), app
                                                                                                                                                                                                                                                                         .GetTrackingUrl() == null || app.GetTrackingUrl().Equals(Unavailable) ? "Unassigned"
                                 : app.GetAppState() == YarnApplicationState.Finished || app.GetAppState() == YarnApplicationState
                                                                                                                                                                                                                                                                         .Failed || app.GetAppState() == YarnApplicationState.Killed ? "History" : "ApplicationMaster"
                                                                                                                                                                                                                                                                         ).("Diagnostics:", app.GetDiagnosticsInfo() == null ? string.Empty : app.GetDiagnosticsInfo
                                                                                                                                                                                                                                                                                ());
            ICollection <ApplicationAttemptReport> attempts;

            try
            {
                GetApplicationAttemptsRequest request = GetApplicationAttemptsRequest.NewInstance
                                                            (appID);
                if (callerUGI == null)
                {
                    attempts = appBaseProt.GetApplicationAttempts(request).GetApplicationAttemptList(
                        );
                }
                else
                {
                    attempts = callerUGI.DoAs(new _PrivilegedExceptionAction_196(this, request));
                }
            }
            catch (Exception e)
            {
                string message = "Failed to read the attempts of the application " + appID + ".";
                Log.Error(message, e);
                html.P().(message).();
                return;
            }
            CreateApplicationMetricsTable(html);
            html.(typeof(InfoBlock));
            GenerateApplicationTable(html, callerUGI, attempts);
        }
        /// <exception cref="System.Exception"/>
        public virtual void TestClientTokenRace()
        {
            conf.Set(CommonConfigurationKeysPublic.HadoopSecurityAuthentication, "kerberos");
            UserGroupInformation.SetConfiguration(conf);
            ContainerManagementProtocol containerManager = Org.Mockito.Mockito.Mock <ContainerManagementProtocol
                                                                                     >();
            StartContainersResponse mockResponse = Org.Mockito.Mockito.Mock <StartContainersResponse
                                                                             >();

            Org.Mockito.Mockito.When(containerManager.StartContainers((StartContainersRequest
                                                                       )Matchers.Any())).ThenReturn(mockResponse);
            DrainDispatcher dispatcher = new DrainDispatcher();
            MockRM          rm         = new _MockRMWithCustomAMLauncher_433(dispatcher, conf, containerManager
                                                                             );

            rm.Start();
            // Submit an app
            RMApp app = rm.SubmitApp(1024);
            // Set up a node.
            MockNM nm1 = rm.RegisterNode("localhost:1234", 3072);

            nm1.NodeHeartbeat(true);
            dispatcher.Await();
            nm1.NodeHeartbeat(true);
            dispatcher.Await();
            ApplicationAttemptId appAttempt = app.GetCurrentAppAttempt().GetAppAttemptId();
            MockAM mockAM = new MockAM(rm.GetRMContext(), rm.GetApplicationMasterService(), app
                                       .GetCurrentAppAttempt().GetAppAttemptId());
            UserGroupInformation appUgi = UserGroupInformation.CreateRemoteUser(appAttempt.ToString
                                                                                    ());
            RegisterApplicationMasterResponse response = appUgi.DoAs(new _PrivilegedAction_469
                                                                         (mockAM));
            // Get the app-report.
            GetApplicationReportRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord
                                                  <GetApplicationReportRequest>();

            request.SetApplicationId(app.GetApplicationId());
            GetApplicationReportResponse reportResponse = rm.GetClientRMService().GetApplicationReport
                                                              (request);
            ApplicationReport appReport = reportResponse.GetApplicationReport();

            Org.Apache.Hadoop.Yarn.Api.Records.Token originalClientToAMToken = appReport.GetClientToAMToken
                                                                                   ();
            // ClientToAMToken master key should have been received on register
            // application master response.
            ByteBuffer clientMasterKey = response.GetClientToAMTokenMasterKey();

            NUnit.Framework.Assert.IsNotNull(clientMasterKey);
            NUnit.Framework.Assert.IsTrue(((byte[])clientMasterKey.Array()).Length > 0);
            // Start the AM with the correct shared-secret.
            ApplicationAttemptId appAttemptId = app.GetAppAttempts().Keys.GetEnumerator().Next
                                                    ();

            NUnit.Framework.Assert.IsNotNull(appAttemptId);
            TestClientToAMTokens.CustomAM am = new TestClientToAMTokens.CustomAM(appAttemptId
                                                                                 , null);
            am.Init(conf);
            am.Start();
            // Now the real test!
            // Set up clients to be able to pick up correct tokens.
            SecurityUtil.SetSecurityInfoProviders(new TestClientToAMTokens.CustomSecurityInfo
                                                      ());
            Org.Apache.Hadoop.Security.Token.Token <ClientToAMTokenIdentifier> token = ConverterUtils
                                                                                       .ConvertFromYarn(originalClientToAMToken, am.address);
            // Schedule the key to be set after a significant delay
            Timer     timer     = new Timer();
            TimerTask timerTask = new _TimerTask_516(am, clientMasterKey);

            timer.Schedule(timerTask, 250);
            // connect should pause waiting for the master key to arrive
            VerifyValidToken(conf, am, token);
            am.Stop();
            rm.Stop();
        }