diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerOnTimelineStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerOnTimelineStore.java index 0b57717c29..16fce2428f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerOnTimelineStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/applicationhistoryservice/ApplicationHistoryManagerOnTimelineStore.java @@ -127,9 +127,12 @@ public ApplicationReport getApplication(ApplicationId appId) ApplicationReportExt app = generateApplicationReport(entity, ApplicationReportField.ALL); apps.put(app.appReport.getApplicationId(), app.appReport); + } catch (AuthorizationException e){ + LOG.debug("Failed to authorize when generating application " + + "report for {}: {}", entity.getEntityId(), e.toString()); } catch (Exception e) { - LOG.error("Error on generating application report for " + - entity.getEntityId(), e); + LOG.error("Error on generating application report for {}: {}", + entity.getEntityId(), e.toString()); } } } @@ -681,17 +684,10 @@ private ApplicationReportExt generateApplicationReport(TimelineEntity entity, app.appReport.setTrackingUrl(appAttempt.getTrackingUrl()); app.appReport.setOriginalTrackingUrl(appAttempt.getOriginalTrackingUrl()); } - } catch (AuthorizationException | ApplicationAttemptNotFoundException e) { - // AuthorizationException is thrown because the user doesn't have access - if (e instanceof AuthorizationException) { - LOG.warn("Failed to authorize when generating application report for " - + app.appReport.getApplicationId() - + ". Use a placeholder for its latest attempt id. ", e); - } else { // Attempt not found - LOG.info("No application attempt found for " - + app.appReport.getApplicationId() - + ". Use a placeholder for its latest attempt id. ", e); - } + } catch (ApplicationAttemptNotFoundException e) { + LOG.info("No application attempt found for {}." + + " Use a placeholder for its latest attempt id. {}", + app.appReport.getApplicationId(), e.toString()); // It's possible that the app is finished before the first attempt is created. app.appReport.setDiagnostics(null); app.appReport.setCurrentApplicationAttemptId(null); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerOnTimelineStore.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerOnTimelineStore.java index ecaaf1e878..1a3c08857f 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerOnTimelineStore.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/TestApplicationHistoryManagerOnTimelineStore.java @@ -186,17 +186,36 @@ private static void prepareTimelineStore(TimelineStore store, int scale) public void testGetApplicationReport() throws Exception { for (int i = 1; i <= 3; ++i) { final ApplicationId appId = ApplicationId.newInstance(0, i); - ApplicationReport app; - if (callerUGI == null) { - app = historyManager.getApplication(appId); - } else { - app = - callerUGI.doAs(new PrivilegedExceptionAction () { - @Override - public ApplicationReport run() throws Exception { - return historyManager.getApplication(appId); - } - }); + ApplicationReport app = null; + try { + if(callerUGI == null) { + app = historyManager.getApplication(appId); + } else { + app = + callerUGI.doAs( + new PrivilegedExceptionAction() { + @Override + public ApplicationReport run() throws Exception { + return historyManager.getApplication(appId); + } + }); + } + } catch (AuthorizationException e){ + String userName = null; + if(callerUGI != null){ + userName = callerUGI.getShortUserName(); + } + // App 2 doesn't have the ACLs, + // such that the default ACLs " " will be used. + // Nobody except admin and owner has access to the details of the app. + if ((i != 2 && "user3".equals(userName)) || + (i == 2 && "user2".equals(userName) || + "user3".equals(userName))) { + return; + } else { + Assert.fail(userName + + " should success getApplication(" + appId + ")"); + } } Assert.assertNotNull(app); Assert.assertEquals(appId, app.getApplicationId()); @@ -220,33 +239,14 @@ public ApplicationReport run() throws Exception { Assert.assertEquals(2, app.getApplicationTags().size()); Assert.assertTrue(app.getApplicationTags().contains("Test_APP_TAGS_1")); Assert.assertTrue(app.getApplicationTags().contains("Test_APP_TAGS_2")); - // App 2 doesn't have the ACLs, such that the default ACLs " " will be used. - // Nobody except admin and owner has access to the details of the app. - if ((i != 2 && callerUGI != null && - callerUGI.getShortUserName().equals("user3")) || - (i == 2 && callerUGI != null && - (callerUGI.getShortUserName().equals("user2") || - callerUGI.getShortUserName().equals("user3")))) { - Assert.assertEquals(ApplicationAttemptId.newInstance(appId, -1), - app.getCurrentApplicationAttemptId()); - Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE, - app.getHost()); - Assert.assertEquals(-1, app.getRpcPort()); - Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE, - app.getTrackingUrl()); - Assert.assertEquals(ApplicationHistoryManagerOnTimelineStore.UNAVAILABLE, - app.getOriginalTrackingUrl()); - Assert.assertEquals("", app.getDiagnostics()); - } else { - Assert.assertEquals(ApplicationAttemptId.newInstance(appId, 1), - app.getCurrentApplicationAttemptId()); - Assert.assertEquals("test host", app.getHost()); - Assert.assertEquals(100, app.getRpcPort()); - Assert.assertEquals("test tracking url", app.getTrackingUrl()); - Assert.assertEquals("test original tracking url", - app.getOriginalTrackingUrl()); - Assert.assertEquals("test diagnostics info", app.getDiagnostics()); - } + Assert.assertEquals(ApplicationAttemptId.newInstance(appId, 1), + app.getCurrentApplicationAttemptId()); + Assert.assertEquals("test host", app.getHost()); + Assert.assertEquals(100, app.getRpcPort()); + Assert.assertEquals("test tracking url", app.getTrackingUrl()); + Assert.assertEquals("test original tracking url", + app.getOriginalTrackingUrl()); + Assert.assertEquals("test diagnostics info", app.getDiagnostics()); ApplicationResourceUsageReport applicationResourceUsageReport = app.getApplicationResourceUsageReport(); Assert.assertEquals(123, @@ -274,18 +274,37 @@ public ApplicationReport run() throws Exception { @Test public void testGetApplicationReportWithNotAttempt() throws Exception { final ApplicationId appId = ApplicationId.newInstance(0, SCALE + 1); - ApplicationReport app; - if (callerUGI == null) { - app = historyManager.getApplication(appId); - } else { - app = - callerUGI.doAs(new PrivilegedExceptionAction () { - @Override - public ApplicationReport run() throws Exception { - return historyManager.getApplication(appId); - } - }); + ApplicationReport app = null; + + try { + if(callerUGI == null) { + app = historyManager.getApplication(appId); + } else { + app = + callerUGI.doAs(new PrivilegedExceptionAction() { + @Override + public ApplicationReport run() throws Exception { + return historyManager.getApplication(appId); + } + }); + } + + } catch (AuthorizationException e){ + String userName = null; + if(callerUGI != null){ + userName = callerUGI.getShortUserName(); + } + // App 6 doesn't have the ACLs, + // such that the default ACLs " " will be used. + // Nobody except admin and owner has access to the details of the app. + if("user3".equals(userName) || "user2".equals(userName)){ + return; + } else { + Assert.fail(userName + + " should success getApplication(" + appId + ")"); + } } + Assert.assertNotNull(app); Assert.assertEquals(appId, app.getApplicationId()); Assert.assertEquals(ApplicationAttemptId.newInstance(appId, -1), diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java index 154c68a6a3..bf503a91a2 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/applicationhistoryservice/webapp/TestAHSWebServices.java @@ -362,9 +362,20 @@ public void testAppsQuery() throws Exception { JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject apps = json.getJSONObject("apps"); - assertEquals("incorrect number of elements", 1, apps.length()); - JSONArray array = apps.getJSONArray("app"); - assertEquals("incorrect number of elements", MAX_APPS, array.length()); + + //foo is yarn admin, bar is normal user. + //{"apps":{}} + int expectedAppsLength= 1; + if("bar".equals(USERS[round])){ + expectedAppsLength= 0; + } + + assertEquals("incorrect number of elements", expectedAppsLength, + apps.length()); + if(expectedAppsLength > 0) { + JSONArray array = apps.getJSONArray("app"); + assertEquals("incorrect number of elements", MAX_APPS, array.length()); + } } @Test @@ -380,11 +391,21 @@ public void testQueueQuery() throws Exception { response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); + + //foo is yarn admin, bar is normal user. + //{"apps":{}} + int expectedAppsLength= 1; + if("bar".equals(USERS[round])){ + expectedAppsLength= 0; + } JSONObject apps = json.getJSONObject("apps"); - assertEquals("incorrect number of elements", 1, apps.length()); - JSONArray array = apps.getJSONArray("app"); - assertEquals("incorrect number of elements", MAX_APPS - 1, - array.length()); + assertEquals("incorrect number of elements", expectedAppsLength, + apps.length()); + if(expectedAppsLength > 0) { + JSONArray array = apps.getJSONArray("app"); + assertEquals("incorrect number of elements", MAX_APPS - 1, + array.length()); + } } @Test @@ -400,6 +421,12 @@ public void testSingleApp() throws Exception { assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); + + if (round == 1) { + assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); + return; + } + assertEquals("incorrect number of elements", 1, json.length()); JSONObject app = json.getJSONObject("app"); assertEquals(appId.toString(), app.getString("appId"));