Skip to content

Commit 233d446

Browse files
committed
YARN-2621. Simplify the output when the user doesn't have the access for getDomain(s). Contributed by Zhijie Shen
1 parent 6f43491 commit 233d446

File tree

3 files changed

+28
-52
lines changed

3 files changed

+28
-52
lines changed

hadoop-yarn-project/CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ Release 2.6.0 - UNRELEASED
357357
YARN-2312. Deprecated old ContainerId#getId API and updated MapReduce to
358358
use ContainerId#getContainerId instead. (Tsuyoshi OZAWA via jianhe)
359359

360+
YARN-2621. Simplify the output when the user doesn't have the access for
361+
getDomain(s). (Zhijie Shen via jianhe)
362+
360363
OPTIMIZATIONS
361364

362365
BUG FIXES

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/main/java/org/apache/hadoop/yarn/server/timeline/TimelineDataManager.java

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -361,53 +361,37 @@ public void putDomain(TimelineDomain domain,
361361

362362
/**
363363
* Get a single domain of the particular ID. If callerUGI is not the owner
364-
* or the admin of the domain, we need to hide the details from him, and
365-
* only allow him to see the ID.
364+
* or the admin of the domain, null will be returned.
366365
*/
367366
public TimelineDomain getDomain(String domainId,
368367
UserGroupInformation callerUGI) throws YarnException, IOException {
369368
TimelineDomain domain = store.getDomain(domainId);
370369
if (domain != null) {
371370
if (timelineACLsManager.checkAccess(callerUGI, domain)) {
372371
return domain;
373-
} else {
374-
hideDomainDetails(domain);
375-
return domain;
376372
}
377373
}
378374
return null;
379375
}
380376

381377
/**
382378
* Get all the domains that belong to the given owner. If callerUGI is not
383-
* the owner or the admin of the domain, we need to hide the details from
384-
* him, and only allow him to see the ID.
379+
* the owner or the admin of the domain, empty list is going to be returned.
385380
*/
386381
public TimelineDomains getDomains(String owner,
387382
UserGroupInformation callerUGI) throws YarnException, IOException {
388383
TimelineDomains domains = store.getDomains(owner);
389384
boolean hasAccess = true;
390-
boolean isChecked = false;
391-
for (TimelineDomain domain : domains.getDomains()) {
392-
// The owner for each domain is the same, just need to check on
393-
if (!isChecked) {
394-
hasAccess = timelineACLsManager.checkAccess(callerUGI, domain);
395-
isChecked = true;
396-
}
397-
if (!hasAccess) {
398-
hideDomainDetails(domain);
399-
}
385+
if (domains.getDomains().size() > 0) {
386+
// The owner for each domain is the same, just need to check one
387+
hasAccess = timelineACLsManager.checkAccess(
388+
callerUGI, domains.getDomains().get(0));
389+
}
390+
if (hasAccess) {
391+
return domains;
392+
} else {
393+
return new TimelineDomains();
400394
}
401-
return domains;
402-
}
403-
404-
private static void hideDomainDetails(TimelineDomain domain) {
405-
domain.setDescription(null);
406-
domain.setOwner(null);
407-
domain.setReaders(null);
408-
domain.setWriters(null);
409-
domain.setCreatedTime(null);
410-
domain.setModifiedTime(null);
411395
}
412396

413397
private static boolean extendFields(EnumSet<Field> fieldEnums) {

hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-applicationhistoryservice/src/test/java/org/apache/hadoop/yarn/server/timeline/webapp/TestTimelineWebServices.java

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ public void testGetDomain() throws Exception {
807807
.get(ClientResponse.class);
808808
Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
809809
TimelineDomain domain = response.getEntity(TimelineDomain.class);
810-
verifyDomain(domain, "domain_id_1", true);
810+
verifyDomain(domain, "domain_id_1");
811811
}
812812

813813
@Test
@@ -823,16 +823,16 @@ public void testGetDomainYarnACLsEnabled() {
823823
.get(ClientResponse.class);
824824
Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
825825
TimelineDomain domain = response.getEntity(TimelineDomain.class);
826-
verifyDomain(domain, "domain_id_1", true);
826+
verifyDomain(domain, "domain_id_1");
827827

828828
response = r.path("ws").path("v1").path("timeline")
829829
.path("domain").path("domain_id_1")
830830
.queryParam("user.name", "tester")
831831
.accept(MediaType.APPLICATION_JSON)
832832
.get(ClientResponse.class);
833833
Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
834-
domain = response.getEntity(TimelineDomain.class);
835-
verifyDomain(domain, "domain_id_1", false);
834+
Assert.assertEquals(ClientResponse.Status.NOT_FOUND,
835+
response.getClientResponseStatus());
836836
} finally {
837837
timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
838838
}
@@ -851,7 +851,7 @@ public void testGetDomains() throws Exception {
851851
Assert.assertEquals(2, domains.getDomains().size());
852852
for (int i = 0; i < domains.getDomains().size(); ++i) {
853853
verifyDomain(domains.getDomains().get(i),
854-
i == 0 ? "domain_id_4" : "domain_id_1", true);
854+
i == 0 ? "domain_id_4" : "domain_id_1");
855855
}
856856
}
857857

@@ -871,7 +871,7 @@ public void testGetDomainsYarnACLsEnabled() throws Exception {
871871
Assert.assertEquals(2, domains.getDomains().size());
872872
for (int i = 0; i < domains.getDomains().size(); ++i) {
873873
verifyDomain(domains.getDomains().get(i),
874-
i == 0 ? "domain_id_4" : "domain_id_1", true);
874+
i == 0 ? "domain_id_4" : "domain_id_1");
875875
}
876876

877877
response = r.path("ws").path("v1").path("timeline")
@@ -882,11 +882,7 @@ public void testGetDomainsYarnACLsEnabled() throws Exception {
882882
.get(ClientResponse.class);
883883
Assert.assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
884884
domains = response.getEntity(TimelineDomains.class);
885-
Assert.assertEquals(2, domains.getDomains().size());
886-
for (int i = 0; i < domains.getDomains().size(); ++i) {
887-
verifyDomain(domains.getDomains().get(i),
888-
i == 0 ? "domain_id_4" : "domain_id_1", false);
889-
}
885+
Assert.assertEquals(0, domains.getDomains().size());
890886
} finally {
891887
timelineACLsManager.setAdminACLsManager(oldAdminACLsManager);
892888
}
@@ -978,22 +974,15 @@ public void testPutDomainYarnACLsEnabled() throws Exception {
978974
}
979975
}
980976

981-
private static void verifyDomain(TimelineDomain domain,
982-
String domainId, boolean hasAccess) {
977+
private static void verifyDomain(TimelineDomain domain, String domainId) {
983978
Assert.assertNotNull(domain);
984979
Assert.assertEquals(domainId, domain.getId());
985980
// The specific values have been verified in TestMemoryTimelineStore
986-
Assert.assertTrue(hasAccess && domain.getDescription() != null ||
987-
!hasAccess && domain.getDescription() == null);
988-
Assert.assertTrue(hasAccess && domain.getOwner() != null ||
989-
!hasAccess && domain.getOwner() == null);
990-
Assert.assertTrue(hasAccess && domain.getReaders() != null ||
991-
!hasAccess && domain.getReaders() == null);
992-
Assert.assertTrue(hasAccess && domain.getWriters() != null ||
993-
!hasAccess && domain.getWriters() == null);
994-
Assert.assertTrue(hasAccess && domain.getCreatedTime() != null ||
995-
!hasAccess && domain.getCreatedTime() == null);
996-
Assert.assertTrue(hasAccess && domain.getModifiedTime() != null ||
997-
!hasAccess && domain.getModifiedTime() == null);
981+
Assert.assertNotNull(domain.getDescription());
982+
Assert.assertNotNull(domain.getOwner());
983+
Assert.assertNotNull(domain.getReaders());
984+
Assert.assertNotNull(domain.getWriters());
985+
Assert.assertNotNull(domain.getCreatedTime());
986+
Assert.assertNotNull(domain.getModifiedTime());
998987
}
999988
}

0 commit comments

Comments
 (0)