From 86c99f91b87af95eb4300c9c32bd6ea76a4fa6ad Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Tue, 12 Mar 2019 23:00:56 +0530 Subject: [PATCH] YARN-7982 --- .../reader/TimelineReaderManager.java | 2 +- .../reader/TimelineReaderWebServices.java | 9 +++--- .../storage/FileSystemTimelineReaderImpl.java | 1 + .../reader/TestTimelineReaderWebServices.java | 37 ++++++++++++++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderManager.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderManager.java index 8c7c974..b26e224 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderManager.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderManager.java @@ -205,7 +205,7 @@ public TimelineEntity getEntity(TimelineReaderContext context, public Set getEntityTypes(TimelineReaderContext context) throws IOException{ context.setClusterId(getClusterID(context.getClusterId(), getConfig())); - return reader.getEntityTypes(new TimelineReaderContext(context)); + return reader.getEntityTypes(context); } /** diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderWebServices.java index 279cfdc..ffa4fde 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/reader/TimelineReaderWebServices.java @@ -3325,10 +3325,11 @@ public TimelineEntity getContainer(@Context HttpServletRequest req, TimelineReaderManager timelineReaderManager = getTimelineReaderManager(); Set results = null; try { - results = timelineReaderManager.getEntityTypes( - TimelineReaderWebServicesUtils.createTimelineReaderContext( - clusterId, userId, flowName, flowRunId, appId, - null, null, null)); + TimelineReaderContext context = TimelineReaderWebServicesUtils. + createTimelineReaderContext(clusterId, userId, flowName, flowRunId, + appId, null, null, null); + results = timelineReaderManager.getEntityTypes(context); + checkAccess(getTimelineReaderManager(), callerUGI, context.getUserId()); succeeded = true; } catch (Exception e) { handleException(e, url, startTime, "flowrunid"); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/FileSystemTimelineReaderImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/FileSystemTimelineReaderImpl.java index ef08a9d..5dc15c7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/FileSystemTimelineReaderImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/main/java/org/apache/hadoop/yarn/server/timelineservice/storage/FileSystemTimelineReaderImpl.java @@ -431,6 +431,7 @@ public TimelineEntity getEntity(TimelineReaderContext context, String flowRunPathStr = getFlowRunPath(context.getUserId(), context.getClusterId(), context.getFlowName(), context.getFlowRunId(), context.getAppId()); + context.setUserId(flowRunPathStr.split(File.separator)[0]); Path clusterIdPath = new Path(entitiesPath, context.getClusterId()); Path flowRunPath = new Path(clusterIdPath, flowRunPathStr); Path appIdPath = new Path(flowRunPath, context.getAppId()); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServices.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServices.java index 03939ad..9304826 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServices.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServices.java @@ -32,6 +32,7 @@ import java.util.Set; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; @@ -67,6 +68,7 @@ private int serverPort; private TimelineReaderServer server; + private static final String ADMIN = "yarn"; @BeforeClass public static void setup() throws Exception { @@ -91,6 +93,9 @@ public void init() throws Exception { FileSystemTimelineReaderImpl.class, TimelineReader.class); config.set(FileSystemTimelineReaderImpl.TIMELINE_SERVICE_STORAGE_DIR_ROOT, ROOT_DIR); + config.setBoolean(YarnConfiguration.FILTER_ENTITY_LIST_BY_USER, true); + config.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true); + config.set(YarnConfiguration.YARN_ADMIN_ACL, ADMIN); server = new TimelineReaderServer(); server.init(config); server.start(); @@ -178,6 +183,38 @@ public void testAbout() throws Exception { } @Test + public void testGetEntityTypes() throws Exception { + Client client = createClient(); + try { + String unAuthorizedUser ="user2"; + URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/apps/app1/entity-types?user.name="+unAuthorizedUser); + ClientResponse resp = + client.resource(uri).accept(MediaType.APPLICATION_JSON) + .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); + String msg = "User " + unAuthorizedUser + + " is not allowed to read TimelineService V2 data."; + assertEquals(Status.FORBIDDEN.getStatusCode(), resp.getStatus()); + assertTrue(resp.getEntity(String.class).contains(msg)); + + String authorizedUser ="user1"; + uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/apps/app1/entity-types?user.name="+authorizedUser); + resp = client.resource(uri).accept(MediaType.APPLICATION_JSON) + .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); + assertEquals(Status.OK.getStatusCode(), resp.getStatus()); + + uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/apps/app1/entity-types?user.name="+ADMIN); + resp = client.resource(uri).accept(MediaType.APPLICATION_JSON) + .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); + assertEquals(Status.OK.getStatusCode(), resp.getStatus()); + } finally { + client.destroy(); + } + } + + @Test public void testGetEntityDefaultView() throws Exception { Client client = createClient(); try { -- 2.7.4 (Apple Git-66)