From 45524ed05220b5d39fc1ba6f94234ece9273bd33 Mon Sep 17 00:00:00 2001 From: Prabhu Joseph Date: Sat, 30 Mar 2019 09:57:59 +0530 Subject: [PATCH] YARN-9408 --- .../AbstractTimelineReaderHBaseTestBase.java | 14 +++++ .../TestTimelineReaderWebServicesHBaseStorage.java | 28 ++++++++- .../reader/TimelineReaderWebServices.java | 73 ++++++++++++++++------ 3 files changed, 94 insertions(+), 21 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/AbstractTimelineReaderHBaseTestBase.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/AbstractTimelineReaderHBaseTestBase.java index 471fb6c..e1baa52 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/AbstractTimelineReaderHBaseTestBase.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/AbstractTimelineReaderHBaseTestBase.java @@ -142,6 +142,20 @@ protected void verifyHttpResponse(Client client, URI uri, Status status) { System.out.println("Response is: " + resp.getEntity(String.class)); } + protected void verifyHttpResponseMessage(Client client, URI uri, + Status expectedStatus, String message) { + ClientResponse resp = + client.resource(uri).accept(MediaType.APPLICATION_JSON) + .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); + assertNotNull(resp); + assertEquals(resp.getStatusInfo().getStatusCode(), + expectedStatus.getStatusCode()); + String remoteException = resp.getEntity(String.class); + assertTrue("Remote Exception doesn't contain expected message," + + " got: " + remoteException + " expected: " + message, + remoteException.contains(message)); + } + protected List verifyFlowEntites(Client client, URI uri, int noOfEntities) throws Exception { ClientResponse resp = getResponse(client, uri); diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesHBaseStorage.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesHBaseStorage.java index abd5362..3dd4fc7 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesHBaseStorage.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-timelineservice-hbase-tests/src/test/java/org/apache/hadoop/yarn/server/timelineservice/reader/TestTimelineReaderWebServicesHBaseStorage.java @@ -2228,9 +2228,35 @@ public void testGetFlowsNotPresent() throws Exception { public void testGetAppNotPresent() throws Exception { Client client = createClient(); try { + String appId = "application_1111111111_1378"; URI uri = URI.create("http://localhost:" + getServerPort() + "/ws/v2/" + - "timeline/clusters/cluster1/apps/application_1111111111_1378"); + "timeline/clusters/cluster1/apps/" + appId); verifyHttpResponse(client, uri, Status.NOT_FOUND); + + uri = URI.create("http://localhost:" + getServerPort() + "/ws/v2/" + + "timeline/clusters/cluster1/apps/" + appId + "/appattempts"); + verifyHttpResponseMessage(client, uri, Status.NOT_FOUND, + "Unable to find the application attempts for appid=" + appId); + + uri = URI.create("http://localhost:" + getServerPort() + "/ws/v2/" + + "timeline/apps/" + appId + "/appattempts/app-attempt-1/containers"); + verifyHttpResponseMessage(client, uri, Status.NOT_FOUND, "Unable to " + + "find the containers for appid=" + appId + + ", appattemptid=app-attempt-1"); + + uri = URI.create("http://localhost:" + getServerPort() + "/ws/v2/" + + "timeline/clusters/cluster1/apps/" + appId + + "/appattempts/app-attempt-1"); + verifyHttpResponseMessage(client, uri, Status.NOT_FOUND, "Unable to " + + "find the application attempt for appid=" + appId + + ", appattemptid=app-attempt-1"); + + uri = URI.create("http://localhost:" + getServerPort() + "/ws/v2/" + + "timeline/clusters/cluster1/apps/" + appId + + "/containers/container_2_2/"); + verifyHttpResponseMessage(client, uri, Status.NOT_FOUND, "Unable to " + + "find the container for appid=" + appId + + ", containerid=container_2_2"); } finally { client.destroy(); } 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 330e1f4..06c000d 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 @@ -2630,13 +2630,20 @@ public TimelineEntity getApp( @QueryParam("metricstimestart") String metricsTimeStart, @QueryParam("metricstimeend") String metricsTimeEnd, @QueryParam("fromid") String fromId) { - - 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, - metricsTimeStart, metricsTimeEnd, fromId); + try { + 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, metricsTimeStart, metricsTimeEnd, fromId); + } catch (Exception e) { + if (e instanceof NotFoundException) { + throw new NotFoundException("Unable to find the application attempts" + + " for appid=" + appId); + } + throw e; + } } /** @@ -2798,10 +2805,19 @@ public TimelineEntity getAppAttempt(@Context HttpServletRequest req, @QueryParam("metricstimestart") String metricsTimeStart, @QueryParam("metricstimeend") String metricsTimeEnd, @QueryParam("entityidprefix") String entityIdPrefix) { - return getEntity(req, res, clusterId, appId, - TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), appAttemptId, - userId, flowName, flowRunId, confsToRetrieve, metricsToRetrieve, fields, - metricsLimit, metricsTimeStart, metricsTimeEnd, entityIdPrefix); + try { + return getEntity(req, res, clusterId, appId, + TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), appAttemptId, + userId, flowName, flowRunId, confsToRetrieve, metricsToRetrieve, + fields, metricsLimit, metricsTimeStart, metricsTimeEnd, + entityIdPrefix); + } catch (Exception e) { + if (e instanceof NotFoundException) { + throw new NotFoundException("Unable to find the application attempt" + + " for appid=" + appId +", appattemptid=" + appAttemptId); + } + throw e; + } } /** @@ -3064,11 +3080,20 @@ public TimelineEntity getAppAttempt(@Context HttpServletRequest req, } 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, - metricsTimeStart, metricsTimeEnd, fromId); + + try { + return getEntities(req, res, clusterId, appId, entityType, userId, + flowName, flowRunId, limit, createdTimeStart, createdTimeEnd, + relatesTo, isRelatedTo, infofilter, conffilters, metricfilters, + eventfilters, confsToRetrieve, metricsToRetrieve, fields, + metricsLimit, metricsTimeStart, metricsTimeEnd, fromId); + } catch (Exception e) { + if (e instanceof NotFoundException) { + throw new NotFoundException("Unable to find the containers for appid=" + + appId + ", appattemptid=" + appattemptId); + } + throw e; + } } /** @@ -3229,10 +3254,18 @@ public TimelineEntity getContainer(@Context HttpServletRequest req, @QueryParam("metricstimestart") String metricsTimeStart, @QueryParam("metricstimeend") String metricsTimeEnd, @QueryParam("entityidprefix") String entityIdPrefix) { - return getEntity(req, res, clusterId, appId, - TimelineEntityType.YARN_CONTAINER.toString(), containerId, userId, - flowName, flowRunId, confsToRetrieve, metricsToRetrieve, fields, - metricsLimit, metricsTimeStart, metricsTimeEnd, entityIdPrefix); + try { + return getEntity(req, res, clusterId, appId, + TimelineEntityType.YARN_CONTAINER.toString(), containerId, userId, + flowName, flowRunId, confsToRetrieve, metricsToRetrieve, fields, + metricsLimit, metricsTimeStart, metricsTimeEnd, entityIdPrefix); + } catch (Exception e) { + if (e instanceof NotFoundException) { + throw new NotFoundException("Unable to find the container for appid=" + + appId + ", containerid=" + containerId); + } + throw e; + } } /** -- 2.7.4 (Apple Git-66)