/// <exception cref="System.Exception"/>
        public virtual void TestMoveTooLate()
        {
            // Submit application
            Application   application = new Application("user1", resourceManager);
            ApplicationId appId       = application.GetApplicationId();

            application.Submit();
            ClientRMService clientRMService = resourceManager.GetClientRMService();

            // Kill the application
            clientRMService.ForceKillApplication(KillApplicationRequest.NewInstance(appId));
            RMApp rmApp = resourceManager.GetRMContext().GetRMApps()[appId];

            // wait until it's dead
            while (rmApp.GetState() != RMAppState.Killed)
            {
                Sharpen.Thread.Sleep(100);
            }
            try
            {
                clientRMService.MoveApplicationAcrossQueues(MoveApplicationAcrossQueuesRequest.NewInstance
                                                                (appId, "newqueue"));
                NUnit.Framework.Assert.Fail("Should have hit exception");
            }
            catch (YarnException ex)
            {
                NUnit.Framework.Assert.AreEqual(typeof(YarnException), ex.GetType());
                NUnit.Framework.Assert.AreEqual("App in KILLED state cannot be moved.", ex.Message
                                                );
            }
        }
        /// <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);
        }
Exemple #3
0
        /// <exception cref="System.Exception"/>
        public virtual KillApplicationResponse KillApp(ApplicationId appId)
        {
            ApplicationClientProtocol client = GetClientRMService();
            KillApplicationRequest    req    = KillApplicationRequest.NewInstance(appId);

            return(client.ForceKillApplication(req));
        }
        /// <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);
        }
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 public override KillApplicationResponse ForceKillApplication(KillApplicationRequest
                                                              request)
 {
     this._enclosing.ResetStartFailoverFlag(true);
     // make sure failover has been triggered
     NUnit.Framework.Assert.IsTrue(this._enclosing.WaittingForFailOver());
     return(KillApplicationResponse.NewInstance(true));
 }
        /// <exception cref="System.Exception"/>
        private void VerifyKillAppSuccess(string submitter, string killer, string queueName
                                          , bool setupACLs)
        {
            ApplicationId applicationId = SubmitAppAndGetAppId(submitter, queueName, setupACLs
                                                               );
            KillApplicationRequest finishAppRequest = KillApplicationRequest.NewInstance(applicationId
                                                                                         );
            ApplicationClientProtocol ownerClient = GetRMClientForUser(killer);

            // Kill app as killer
            ownerClient.ForceKillApplication(finishAppRequest);
            resourceManager.WaitForState(applicationId, RMAppState.Killed);
        }
Exemple #7
0
            // don't do anything
            /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
            public override KillApplicationResponse ForceKillApplication(KillApplicationRequest
                                                                         request)
            {
                ApplicationId applicationId = request.GetApplicationId();
                RMApp         application   = this.rmContext.GetRMApps()[applicationId];

                if (application.IsAppFinalStateStored())
                {
                    return(KillApplicationResponse.NewInstance(true));
                }
                else
                {
                    return(KillApplicationResponse.NewInstance(false));
                }
            }
 /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
 /// <exception cref="System.IO.IOException"/>
 public virtual KillApplicationResponse ForceKillApplication(KillApplicationRequest
                                                             request)
 {
     YarnServiceProtos.KillApplicationRequestProto requestProto = ((KillApplicationRequestPBImpl
                                                                    )request).GetProto();
     try
     {
         return(new KillApplicationResponsePBImpl(proxy.ForceKillApplication(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);
        }
Exemple #10
0
        /// <summary>Validate killing an application when it is at accepted state.</summary>
        /// <exception cref="System.Exception">exception</exception>
        public virtual void TestApplicationKillAtAcceptedState()
        {
            Dispatcher dispatcher = new _AsyncDispatcher_573();
            MockRM     rm         = new _MockRM_596(dispatcher, conf);
            // test metrics
            QueueMetrics metrics       = rm.GetResourceScheduler().GetRootQueueMetrics();
            int          appsKilled    = metrics.GetAppsKilled();
            int          appsSubmitted = metrics.GetAppsSubmitted();

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

            nm1.RegisterNode();
            // a failed app
            RMApp  application = rm.SubmitApp(200);
            MockAM am          = MockRM.LaunchAM(application, rm, nm1);

            am.WaitForState(RMAppAttemptState.Launched);
            nm1.NodeHeartbeat(am.GetApplicationAttemptId(), 1, ContainerState.Running);
            rm.WaitForState(application.GetApplicationId(), RMAppState.Accepted);
            // Now kill the application before new attempt is launched, the app report
            // returns the invalid AM host and port.
            KillApplicationRequest request = KillApplicationRequest.NewInstance(application.GetApplicationId
                                                                                    ());

            rm.GetClientRMService().ForceKillApplication(request);
            // Specific test for YARN-1689 follows
            // Now let's say a race causes AM to register now. This should not crash RM.
            am.RegisterAppAttempt(false);
            // We explicitly intercepted the kill-event to RMAppAttempt, so app should
            // still be in KILLING state.
            rm.WaitForState(application.GetApplicationId(), RMAppState.Killing);
            // AM should now be in running
            rm.WaitForState(am.GetApplicationAttemptId(), RMAppAttemptState.Running);
            // Simulate that appAttempt is killed.
            rm.GetRMContext().GetDispatcher().GetEventHandler().Handle(new RMAppEvent(application
                                                                                      .GetApplicationId(), RMAppEventType.AttemptKilled));
            rm.WaitForState(application.GetApplicationId(), RMAppState.Killed);
            // test metrics
            metrics = rm.GetResourceScheduler().GetRootQueueMetrics();
            NUnit.Framework.Assert.AreEqual(appsKilled + 1, metrics.GetAppsKilled());
            NUnit.Framework.Assert.AreEqual(appsSubmitted + 1, metrics.GetAppsSubmitted());
        }
        /// <exception cref="System.Exception"/>
        private void VerifyKillAppFailure(string submitter, string killer, string queueName
                                          , bool setupACLs)
        {
            ApplicationId applicationId = SubmitAppAndGetAppId(submitter, queueName, setupACLs
                                                               );
            KillApplicationRequest finishAppRequest = KillApplicationRequest.NewInstance(applicationId
                                                                                         );
            ApplicationClientProtocol killerClient = GetRMClientForUser(killer);

            // Kill app as the killer
            try
            {
                killerClient.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 " + killer + " cannot perform operation MODIFY_APP on "
                                                                 + applicationId));
            }
            GetRMClientForUser(submitter).ForceKillApplication(finishAppRequest);
        }
Exemple #12
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public override void KillApplication(ApplicationId applicationId)
        {
            KillApplicationRequest request = Org.Apache.Hadoop.Yarn.Util.Records.NewRecord <KillApplicationRequest
                                                                                            >();

            request.SetApplicationId(applicationId);
            try
            {
                int  pollCount = 0;
                long startTime = Runtime.CurrentTimeMillis();
                while (true)
                {
                    KillApplicationResponse response = rmClient.ForceKillApplication(request);
                    if (response.GetIsKillCompleted())
                    {
                        Log.Info("Killed application " + applicationId);
                        break;
                    }
                    long elapsedMillis = Runtime.CurrentTimeMillis() - startTime;
                    if (EnforceAsyncAPITimeout() && elapsedMillis >= this.asyncApiPollTimeoutMillis)
                    {
                        throw new YarnException("Timed out while waiting for application " + applicationId
                                                + " to be killed.");
                    }
                    if (++pollCount % 10 == 0)
                    {
                        Log.Info("Waiting for application " + applicationId + " to be killed.");
                    }
                    Sharpen.Thread.Sleep(asyncApiPollIntervalMillis);
                }
            }
            catch (Exception)
            {
                Log.Error("Interrupted while waiting for application " + applicationId + " to be killed."
                          );
            }
        }
Exemple #13
0
 /// <exception cref="System.IO.IOException"/>
 public virtual KillApplicationResponse ForceKillApplication(KillApplicationRequest
                                                             request)
 {
     return(KillApplicationResponse.NewInstance(true));
 }