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 fcab78c..6b9280c 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 @@ -2120,4 +2120,210 @@ public TimelineEntity getApp( infofilters, conffilters, metricfilters, eventfilters, confsToRetrieve, metricsToRetrieve, fields, metricsLimit); } + + @GET + @Path("/apps/{appid}/appattempts") + @Produces(MediaType.APPLICATION_JSON) + public Set getAppAttempts(@Context HttpServletRequest req, + @Context HttpServletResponse res, @PathParam("appid") String appId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("limit") String limit, + @QueryParam("createdtimestart") String createdTimeStart, + @QueryParam("createdtimeend") String createdTimeEnd, + @QueryParam("relatesto") String relatesTo, + @QueryParam("isrelatedto") String isRelatedTo, + @QueryParam("infofilters") String infofilters, + @QueryParam("conffilters") String conffilters, + @QueryParam("metricfilters") String metricfilters, + @QueryParam("eventfilters") String eventfilters, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + + return getAppAttempts(req, res, null, appId, userId, flowName, flowRunId, + limit, createdTimeStart, createdTimeEnd, relatesTo, isRelatedTo, + infofilters, conffilters, metricfilters, eventfilters, confsToRetrieve, + metricsToRetrieve, fields, metricsLimit); + } + + @GET + @Path("/clusters/{clusterid}/apps/{appid}/appattempts") + @Produces(MediaType.APPLICATION_JSON) + public Set getAppAttempts(@Context HttpServletRequest req, + @Context HttpServletResponse res, + @PathParam("clusterid") String clusterId, + @PathParam("appid") String appId, @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("limit") String limit, + @QueryParam("createdtimestart") String createdTimeStart, + @QueryParam("createdtimeend") String createdTimeEnd, + @QueryParam("relatesto") String relatesTo, + @QueryParam("isrelatedto") String isRelatedTo, + @QueryParam("infofilters") String infofilters, + @QueryParam("conffilters") String conffilters, + @QueryParam("metricfilters") String metricfilters, + @QueryParam("eventfilters") String eventfilters, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + + return getEntities(req, res, clusterId, appId, + TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), userId, + flowName, flowRunId, limit, createdTimeStart, createdTimeEnd, relatesTo, + isRelatedTo, infofilters, conffilters, metricfilters, eventfilters, + confsToRetrieve, metricsToRetrieve, fields, metricsLimit); + } + + @GET + @Path("/apps/{appid}/appattempts/{appattemptid}") + @Produces(MediaType.APPLICATION_JSON) + public TimelineEntity getAppAttempt(@Context HttpServletRequest req, + @Context HttpServletResponse res, @PathParam("appid") String appId, + @PathParam("appattemptid") String appAttemptId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + return getAppAttempt(req, res, null, appId, appAttemptId, userId, flowName, + flowRunId, confsToRetrieve, metricsToRetrieve, fields, metricsLimit); + } + + @GET + @Path("/clusters/{clusterid}/apps/{appid}/appattempts/{appattemptid}") + @Produces(MediaType.APPLICATION_JSON) + public TimelineEntity getAppAttempt(@Context HttpServletRequest req, + @Context HttpServletResponse res, + @PathParam("clusterid") String clusterId, + @PathParam("appid") String appId, + @PathParam("appattemptid") String appAttemptId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + return getEntity(req, res, clusterId, appId, + TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), appAttemptId, + userId, flowName, flowRunId, confsToRetrieve, metricsToRetrieve, fields, + metricsLimit); + } + + @GET + @Path("/apps/{appid}/appattempts/{appattemptid}/containers") + @Produces(MediaType.APPLICATION_JSON) + public Set getContainers(@Context HttpServletRequest req, + @Context HttpServletResponse res, @PathParam("appid") String appId, + @PathParam("appattemptid") String appattemptId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("limit") String limit, + @QueryParam("createdtimestart") String createdTimeStart, + @QueryParam("createdtimeend") String createdTimeEnd, + @QueryParam("relatesto") String relatesTo, + @QueryParam("isrelatedto") String isRelatedTo, + @QueryParam("infofilters") String infofilters, + @QueryParam("conffilters") String conffilters, + @QueryParam("metricfilters") String metricfilters, + @QueryParam("eventfilters") String eventfilters, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + return getContainers(req, res, null, appId, appattemptId, userId, flowName, + flowRunId, limit, createdTimeStart, createdTimeEnd, relatesTo, + isRelatedTo, infofilters, conffilters, metricfilters, eventfilters, + confsToRetrieve, metricsToRetrieve, fields, metricsLimit); + } + + @GET + @Path("/clusters/{clusterid}/apps/{appid}/appattempts/{appattemptid}/containers") + @Produces(MediaType.APPLICATION_JSON) + public Set getContainers(@Context HttpServletRequest req, + @Context HttpServletResponse res, + @PathParam("clusterid") String clusterId, + @PathParam("appid") String appId, + @PathParam("appattemptid") String appattemptId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("limit") String limit, + @QueryParam("createdtimestart") String createdTimeStart, + @QueryParam("createdtimeend") String createdTimeEnd, + @QueryParam("relatesto") String relatesTo, + @QueryParam("isrelatedto") String isRelatedTo, + @QueryParam("infofilters") String infofilters, + @QueryParam("conffilters") String conffilters, + @QueryParam("metricfilters") String metricfilters, + @QueryParam("eventfilters") String eventfilters, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + + String entityType = TimelineEntityType.YARN_CONTAINER.toString(); + String parentEntityType = + TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(); + String jsonFormatString = "{\"type\":\"" + parentEntityType + "\",\"id\":\"" + + appattemptId + "\"}"; + String containerFilters = + "SYSTEM_INFO_PARENT_ENTITY eq " + jsonFormatString; + String infofilter; + if (infofilters != null) { + infofilter = containerFilters + " AND " + infofilters; + } else { + infofilter = containerFilters; + } + return getEntities(req, res, clusterId, appId, entityType, userId, flowName, + flowRunId, limit, createdTimeStart, createdTimeEnd, relatesTo, + isRelatedTo, infofilter, conffilters, metricfilters, eventfilters, + confsToRetrieve, metricsToRetrieve, fields, metricsLimit); + } + + @GET + @Path("/apps/{appid}/containers/{containerid}") + @Produces(MediaType.APPLICATION_JSON) + public TimelineEntity getContainer(@Context HttpServletRequest req, + @Context HttpServletResponse res, @PathParam("appid") String appId, + @PathParam("containerid") String containerId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + return getContainer(req, res, null, appId, containerId, userId, flowName, + flowRunId, confsToRetrieve, metricsToRetrieve, fields, metricsLimit); + } + + @GET + @Path("/clusters/{clusterid}/apps/{appid}/containers/{containerid}") + @Produces(MediaType.APPLICATION_JSON) + public TimelineEntity getContainer(@Context HttpServletRequest req, + @Context HttpServletResponse res, + @PathParam("clusterid") String clusterId, + @PathParam("appid") String appId, + @PathParam("containerid") String containerId, + @QueryParam("userid") String userId, + @QueryParam("flowname") String flowName, + @QueryParam("flowrunid") String flowRunId, + @QueryParam("confstoretrieve") String confsToRetrieve, + @QueryParam("metricstoretrieve") String metricsToRetrieve, + @QueryParam("fields") String fields, + @QueryParam("metricslimit") String metricsLimit) { + return getEntity(req, res, clusterId, appId, + TimelineEntityType.YARN_CONTAINER.toString(), containerId, userId, + flowName, flowRunId, confsToRetrieve, metricsToRetrieve, fields, + metricsLimit); + } } \ No newline at end of file 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 a5ef66c..cb592b5 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 @@ -37,6 +37,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.yarn.api.records.timeline.TimelineAbout; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.timelineservice.storage.FileSystemTimelineReaderImpl; import org.apache.hadoop.yarn.server.timelineservice.storage.TestFileSystemTimelineReaderImpl; @@ -567,4 +568,102 @@ public void testInvalidValuesHandling() throws Exception { client.destroy(); } } + + @Test + public void testGetContainers() throws Exception { + Client client = createClient(); + try { + // total 3 containers in a application. + URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/clusters/cluster1/apps/app1/entities/YARN_CONTAINER"); + ClientResponse resp = getResponse(client, uri); + Set entities = + resp.getEntity(new GenericType>() { + }); + assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType()); + assertNotNull(entities); + int totalEntities = entities.size(); + assertEquals(3, totalEntities); + assertTrue( + "Entity with container_1_1 should have been present in response.", + entities.contains(newEntity( + TimelineEntityType.YARN_CONTAINER.toString(), "container_1_1"))); + assertTrue( + "Entity with container_2_1 should have been present in response.", + entities.contains(newEntity( + TimelineEntityType.YARN_CONTAINER.toString(), "container_2_1"))); + assertTrue( + "Entity with container_2_2 should have been present in response.", + entities.contains(newEntity( + TimelineEntityType.YARN_CONTAINER.toString(), "container_2_2"))); + + // for app-attempt1 1 container has run + uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/clusters/cluster1/apps/app1/appattempts/app-attempt-1/containers"); + resp = getResponse(client, uri); + entities = resp.getEntity(new GenericType>() { + }); + assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType()); + assertNotNull(entities); + int retrievedEntity = entities.size(); + assertEquals(1, retrievedEntity); + assertTrue( + "Entity with container_1_1 should have been present in response.", + entities.contains(newEntity( + TimelineEntityType.YARN_CONTAINER.toString(), "container_1_1"))); + + // for app-attempt2 2 containers has run + uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/clusters/cluster1/apps/app1/appattempts/app-attempt-2/containers"); + resp = getResponse(client, uri); + entities = resp.getEntity(new GenericType>() { + }); + assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType()); + assertNotNull(entities); + retrievedEntity += entities.size(); + assertEquals(2, entities.size()); + assertTrue( + "Entity with container_2_1 should have been present in response.", + entities.contains(newEntity( + TimelineEntityType.YARN_CONTAINER.toString(), "container_2_1"))); + assertTrue( + "Entity with container_2_2 should have been present in response.", + entities.contains(newEntity( + TimelineEntityType.YARN_CONTAINER.toString(), "container_2_2"))); + + assertEquals(totalEntities, retrievedEntity); + + } finally { + client.destroy(); + } + } + + @Test + public void testGetContainer() throws Exception { + Client client = createClient(); + try { + URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/clusters/cluster1/apps/app1/entities/YARN_CONTAINER/container_2_2"); + ClientResponse resp = getResponse(client, uri); + TimelineEntity entities1 = + resp.getEntity(new GenericType() { + }); + assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType()); + assertNotNull(entities1); + + uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + + "timeline/clusters/cluster1/apps/app1/containers/container_2_2"); + resp = getResponse(client, uri); + TimelineEntity entities2 = + resp.getEntity(new GenericType() { + }); + assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType()); + assertNotNull(entities2); + + assertEquals(entities1, entities2); + + } finally { + client.destroy(); + } + } } \ No newline at end of file diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/TestFileSystemTimelineReaderImpl.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/TestFileSystemTimelineReaderImpl.java index 90f11a5..07ce016 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/TestFileSystemTimelineReaderImpl.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice/src/test/java/org/apache/hadoop/yarn/server/timelineservice/storage/TestFileSystemTimelineReaderImpl.java @@ -34,9 +34,12 @@ import org.apache.commons.csv.CSVPrinter; import org.apache.commons.io.FileUtils; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.yarn.api.records.timelineservice.ContainerEntity; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntityType; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEvent; import org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric; +import org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity.Identifier; import org.apache.hadoop.yarn.conf.YarnConfiguration; import org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve; import org.apache.hadoop.yarn.server.timelineservice.reader.TimelineEntityFilters; @@ -118,7 +121,8 @@ private static void writeEntityFile(TimelineEntity entity, File dir) } private static void loadEntityData(String rootDir) throws Exception { - File appDir = getAppDir(rootDir, "cluster1", "user1", "flow1", "1", "app1"); + File appDir = + getAppDir(rootDir, "cluster1", "user1", "flow1", "1", "app1", "app"); TimelineEntity entity11 = new TimelineEntity(); entity11.setId("id_1"); entity11.setType("app"); @@ -259,8 +263,41 @@ private static void loadEntityData(String rootDir) throws Exception { entity4.addEvent(event44); writeEntityFile(entity4, appDir); + File entityDir = getAppDir(rootDir, "cluster1", "user1", "flow1", "1", + "app1", TimelineEntityType.YARN_CONTAINER.toString()); + ContainerEntity containerEntity1 = new ContainerEntity(); + containerEntity1.setId("container_1_1"); + Identifier parentIdentifier1 = new Identifier(); + parentIdentifier1 + .setType(TimelineEntityType.YARN_APPLICATION_ATTEMPT.name()); + parentIdentifier1.setId("app-attempt-1"); + containerEntity1.setParent(parentIdentifier1); + containerEntity1.setCreatedTime(1425017502003L); + writeEntityFile(containerEntity1, entityDir); + + ContainerEntity containerEntity2 = new ContainerEntity(); + containerEntity2.setId("container_2_1"); + Identifier parentIdentifier2 = new Identifier(); + parentIdentifier2 + .setType(TimelineEntityType.YARN_APPLICATION_ATTEMPT.name()); + parentIdentifier2.setId("app-attempt-2"); + containerEntity2.setParent(parentIdentifier2); + containerEntity2.setCreatedTime(1425018502003L); + writeEntityFile(containerEntity2, entityDir); + + ContainerEntity containerEntity3 = new ContainerEntity(); + containerEntity3.setId("container_2_2"); + Identifier parentIdentifier3 = new Identifier(); + parentIdentifier3 + .setType(TimelineEntityType.YARN_APPLICATION_ATTEMPT.name()); + parentIdentifier3.setId("app-attempt-2"); + containerEntity3.setParent(parentIdentifier2); + containerEntity3.setCreatedTime(1425018502003L); + writeEntityFile(containerEntity3, entityDir); + File appDir2 = - getAppDir(rootDir, "cluster1", "user1", "flow1,flow", "1", "app2"); + getAppDir(rootDir, "cluster1", "user1", "flow1,flow", "1", "app2", + "app"); TimelineEntity entity5 = new TimelineEntity(); entity5.setId("id_5"); entity5.setType("app"); @@ -269,11 +306,11 @@ private static void loadEntityData(String rootDir) throws Exception { } private static File getAppDir(String rootDir, String cluster, String user, - String flowName, String flowRunId, String appId) { + String flowName, String flowRunId, String appId, String entityName) { return new File(rootDir + File.separator + "entities" + File.separator + cluster + File.separator + user + File.separator + flowName + File.separator + flowRunId + File.separator + appId + File.separator + - "app" + File.separator); + entityName + File.separator); } @Test