/// <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);
        }
Esempio n. 2
0
        /// <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);
        }
Esempio n. 3
0
        /// <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);
        }
Esempio n. 4
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());
        }
Esempio n. 5
0
        /// <exception cref="Org.Apache.Hadoop.Yarn.Exceptions.YarnException"/>
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestHelper(bool isAHSEnabled)
        {
            conf.SetBoolean(YarnConfiguration.ApplicationHistoryEnabled, isAHSEnabled);
            appManager = Org.Mockito.Mockito.Mock <ApplicationClientProtocol>();
            Org.Mockito.Mockito.When(appManager.GetApplicationReport(Org.Mockito.Mockito.Any <
                                                                         GetApplicationReportRequest>())).ThenThrow(new ApplicationNotFoundException(appNotFoundExceptionMsg
                                                                                                                                                     ));
            fetcher = new TestAppReportFetcher.AppReportFetcherForTest(conf, appManager);
            ApplicationId appId = ApplicationId.NewInstance(0, 0);

            fetcher.GetApplicationReport(appId);
        }
Esempio n. 6
0
        /// <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);
        }
Esempio n. 7
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="Com.Google.Protobuf.ServiceException"/>
        public virtual YarnServiceProtos.GetApplicationReportResponseProto GetApplicationReport
            (RpcController arg0, YarnServiceProtos.GetApplicationReportRequestProto proto)
        {
            GetApplicationReportRequestPBImpl request = new GetApplicationReportRequestPBImpl
                                                            (proto);

            try
            {
                GetApplicationReportResponse response = real.GetApplicationReport(request);
                return(((GetApplicationReportResponsePBImpl)response).GetProto());
            }
            catch (YarnException e)
            {
                throw new ServiceException(e);
            }
            catch (IOException e)
            {
                throw new ServiceException(e);
            }
        }
Esempio n. 9
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);
            }
Esempio n. 11
0
        /// <exception cref="System.Exception"/>
        public virtual void TestResourceMgrDelegate()
        {
            /* we not want a mock of resource mgr delegate */
            ApplicationClientProtocol clientRMProtocol = Org.Mockito.Mockito.Mock <ApplicationClientProtocol
                                                                                   >();
            ResourceMgrDelegate delegate_ = new _ResourceMgrDelegate_256(clientRMProtocol, conf
                                                                         );

            /* make sure kill calls finish application master */
            Org.Mockito.Mockito.When(clientRMProtocol.ForceKillApplication(Matchers.Any <KillApplicationRequest
                                                                                         >())).ThenReturn(KillApplicationResponse.NewInstance(true));
            delegate_.KillApplication(appId);
            Org.Mockito.Mockito.Verify(clientRMProtocol).ForceKillApplication(Matchers.Any <KillApplicationRequest
                                                                                            >());
            /* make sure getalljobs calls get all applications */
            Org.Mockito.Mockito.When(clientRMProtocol.GetApplications(Matchers.Any <GetApplicationsRequest
                                                                                    >())).ThenReturn(recordFactory.NewRecordInstance <GetApplicationsResponse>());
            delegate_.GetAllJobs();
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetApplications(Matchers.Any <GetApplicationsRequest
                                                                                       >());
            /* make sure getapplication report is called */
            Org.Mockito.Mockito.When(clientRMProtocol.GetApplicationReport(Matchers.Any <GetApplicationReportRequest
                                                                                         >())).ThenReturn(recordFactory.NewRecordInstance <GetApplicationReportResponse>()
                                                                                                          );
            delegate_.GetApplicationReport(appId);
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetApplicationReport(Matchers.Any <GetApplicationReportRequest
                                                                                            >());
            /* make sure metrics is called */
            GetClusterMetricsResponse clusterMetricsResponse = recordFactory.NewRecordInstance
                                                               <GetClusterMetricsResponse>();

            clusterMetricsResponse.SetClusterMetrics(recordFactory.NewRecordInstance <YarnClusterMetrics
                                                                                      >());
            Org.Mockito.Mockito.When(clientRMProtocol.GetClusterMetrics(Matchers.Any <GetClusterMetricsRequest
                                                                                      >())).ThenReturn(clusterMetricsResponse);
            delegate_.GetClusterMetrics();
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetClusterMetrics(Matchers.Any <GetClusterMetricsRequest
                                                                                         >());
            Org.Mockito.Mockito.When(clientRMProtocol.GetClusterNodes(Matchers.Any <GetClusterNodesRequest
                                                                                    >())).ThenReturn(recordFactory.NewRecordInstance <GetClusterNodesResponse>());
            delegate_.GetActiveTrackers();
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetClusterNodes(Matchers.Any <GetClusterNodesRequest
                                                                                       >());
            GetNewApplicationResponse newAppResponse = recordFactory.NewRecordInstance <GetNewApplicationResponse
                                                                                        >();

            newAppResponse.SetApplicationId(appId);
            Org.Mockito.Mockito.When(clientRMProtocol.GetNewApplication(Matchers.Any <GetNewApplicationRequest
                                                                                      >())).ThenReturn(newAppResponse);
            delegate_.GetNewJobID();
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetNewApplication(Matchers.Any <GetNewApplicationRequest
                                                                                         >());
            GetQueueInfoResponse queueInfoResponse = recordFactory.NewRecordInstance <GetQueueInfoResponse
                                                                                      >();

            queueInfoResponse.SetQueueInfo(recordFactory.NewRecordInstance <QueueInfo>());
            Org.Mockito.Mockito.When(clientRMProtocol.GetQueueInfo(Matchers.Any <GetQueueInfoRequest
                                                                                 >())).ThenReturn(queueInfoResponse);
            delegate_.GetQueues();
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetQueueInfo(Matchers.Any <GetQueueInfoRequest
                                                                                    >());
            GetQueueUserAclsInfoResponse aclResponse = recordFactory.NewRecordInstance <GetQueueUserAclsInfoResponse
                                                                                        >();

            Org.Mockito.Mockito.When(clientRMProtocol.GetQueueUserAcls(Matchers.Any <GetQueueUserAclsInfoRequest
                                                                                     >())).ThenReturn(aclResponse);
            delegate_.GetQueueAclsForCurrentUser();
            Org.Mockito.Mockito.Verify(clientRMProtocol).GetQueueUserAcls(Matchers.Any <GetQueueUserAclsInfoRequest
                                                                                        >());
        }