AHSWebServices extends WebServices { @GET @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) public AppsInfo get(@Context HttpServletRequest req, @Context HttpServletResponse res) { return getApps(req, res, null, Collections.<String> emptySet(), null, null, null, null, null, null, null, null, null, Collections.<String> emptySet()); } @Inject  AHSWebServices(ApplicationBaseProtocol appBaseProt,
      Configuration conf); @GET @Path("/about") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) TimelineAbout about(
      @Context HttpServletRequest req,
      @Context HttpServletResponse res); @GET @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) AppsInfo get(@Context HttpServletRequest req,
      @Context HttpServletResponse res); @GET @Path("/apps") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override AppsInfo getApps(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @QueryParam("state") String stateQuery,
      @QueryParam("states") Set<String> statesQuery,
      @QueryParam("finalStatus") String finalStatusQuery,
      @QueryParam("user") String userQuery,
      @QueryParam("queue") String queueQuery,
      @QueryParam("limit") String count,
      @QueryParam("startedTimeBegin") String startedBegin,
      @QueryParam("startedTimeEnd") String startedEnd,
      @QueryParam("finishedTimeBegin") String finishBegin,
      @QueryParam("finishedTimeEnd") String finishEnd,
      @QueryParam("name") String name,
      @QueryParam("applicationTypes") Set<String> applicationTypes); @GET @Path("/apps/{appid}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override AppInfo getApp(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @PathParam("appid") String appId); @GET @Path("/apps/{appid}/appattempts") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override AppAttemptsInfo getAppAttempts(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @PathParam("appid") String appId); @GET @Path("/apps/{appid}/appattempts/{appattemptid}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override AppAttemptInfo getAppAttempt(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @PathParam("appid") String appId,
      @PathParam("appattemptid") String appAttemptId); @GET @Path("/apps/{appid}/appattempts/{appattemptid}/containers") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override ContainersInfo getContainers(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @PathParam("appid") String appId,
      @PathParam("appattemptid") String appAttemptId); @GET @Path("/apps/{appid}/appattempts/{appattemptid}/containers/{containerid}") @Produces({ MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, MediaType.APPLICATION_XML + "; " + JettyUtils.UTF_8 }) @Override ContainerInfo getContainer(@Context HttpServletRequest req,
      @Context HttpServletResponse res, @PathParam("appid") String appId,
      @PathParam("appattemptid") String appAttemptId,
      @PathParam("containerid") String containerId); @GET @Path("/containers/{containerid}/logs") @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) Response getContainerLogsInfo(
      @Context HttpServletRequest req,
      @Context HttpServletResponse res,
      @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
      @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
      @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
      @DefaultValue("false") boolean redirectedFromNode,
      @QueryParam(YarnWebServiceParams.MANUAL_REDIRECTION)
      @DefaultValue("false") boolean manualRedirection); @GET @Path("/containers/{containerid}/logs/{filename}") @Produces({ MediaType.TEXT_PLAIN }) @Public @Unstable Response getContainerLogFile(@Context HttpServletRequest req,
      @Context HttpServletResponse res,
      @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
      @PathParam(YarnWebServiceParams.CONTAINER_LOG_FILE_NAME) String filename,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_FORMAT) String format,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_SIZE) String size,
      @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
      @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
      boolean redirectedFromNode,
      @QueryParam(YarnWebServiceParams.MANUAL_REDIRECTION)
      @DefaultValue("false") boolean manualRedirection); @GET @Path("/containerlogs/{containerid}/{filename}") @Produces({ MediaType.TEXT_PLAIN + "; " + JettyUtils.UTF_8 }) @Public @Unstable Response getLogs(@Context HttpServletRequest req,
      @Context HttpServletResponse res,
      @PathParam(YarnWebServiceParams.CONTAINER_ID) String containerIdStr,
      @PathParam(YarnWebServiceParams.CONTAINER_LOG_FILE_NAME) String filename,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_FORMAT) String format,
      @QueryParam(YarnWebServiceParams.RESPONSE_CONTENT_SIZE) String size,
      @QueryParam(YarnWebServiceParams.NM_ID) String nmId,
      @QueryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE)
      @DefaultValue("false") boolean redirectedFromNode,
      @QueryParam(YarnWebServiceParams.MANUAL_REDIRECTION)
      @DefaultValue("false") boolean manualRedirection);  }
@Test public void testInvalidApp() { ApplicationId appId = ApplicationId.newInstance(0, MAX_APPS + 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertResponseStatusCode("404 not found expected", Status.NOT_FOUND, response.getStatusInfo()); }
@Test public void testInvalidAttempt() { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, MAX_APPS + 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); if (round == 1) { assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); return; } assertResponseStatusCode("404 not found expected", Status.NOT_FOUND, response.getStatusInfo()); }
@Test public void testInvalidContainer() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ContainerId containerId = ContainerId.newContainerId(appAttemptId, MAX_APPS + 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()).path("containers") .path(containerId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); if (round == 1) { assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); return; } assertResponseStatusCode("404 not found expected", Status.NOT_FOUND, response.getStatusInfo()); }
@Test public void testInvalidUri() throws JSONException, Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.path("ws").path("v1").path("applicationhistory").path("bogus") .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo()); WebServicesTestUtils.checkStringMatch( "error string exists and shouldn't", "", responseStr); } }
@Test public void testInvalidUri2() throws JSONException, Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo()); WebServicesTestUtils.checkStringMatch( "error string exists and shouldn't", "", responseStr); } }
@Test public void testInvalidAccept() throws JSONException, Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.path("ws").path("v1").path("applicationhistory") .queryParam("user.name", USERS[round]) .accept(MediaType.TEXT_PLAIN).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertResponseStatusCode(Status.INTERNAL_SERVER_ERROR, response.getStatusInfo()); WebServicesTestUtils.checkStringMatch( "error string exists and shouldn't", "", responseStr); } }
@Test public void testAppsQuery() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .queryParam("state", YarnApplicationState.FINISHED.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); 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()); }
@Test public void testQueueQuery() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .queryParam("queue", "test queue") .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); 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 - 1, array.length()); }
@Test public void testSingleApp() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject app = json.getJSONObject("app"); assertEquals(appId.toString(), app.getString("appId")); assertEquals("test app", app.get("name")); assertEquals(round == 0 ? "test diagnostics info" : "", app.get("diagnosticsInfo")); assertEquals(Integer.MAX_VALUE + 1L, app.get("submittedTime")); assertEquals("test queue", app.get("queue")); assertEquals("user1", app.get("user")); assertEquals("test app type", app.get("type")); assertEquals(FinalApplicationStatus.UNDEFINED.toString(), app.get("finalAppStatus")); assertEquals(YarnApplicationState.FINISHED.toString(), app.get("appState")); assertNotNull("Aggregate resource allocation is null", app.get("aggregateResourceAllocation")); assertNotNull("Aggregate Preempted Resource Allocation is null", app.get("aggregatePreemptedResourceAllocation")); }
@Test public void testMultipleAttempts() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); if (round == 1) { assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); return; } assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject appAttempts = json.getJSONObject("appAttempts"); assertEquals("incorrect number of elements", 1, appAttempts.length()); JSONArray array = appAttempts.getJSONArray("appAttempt"); assertEquals("incorrect number of elements", MAX_APPS, array.length()); }
@Test public void testSingleAttempt() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); if (round == 1) { assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); return; } assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject appAttempt = json.getJSONObject("appAttempt"); assertEquals(appAttemptId.toString(), appAttempt.getString("appAttemptId")); assertEquals("test host", appAttempt.getString("host")); assertEquals("test diagnostics info", appAttempt.getString("diagnosticsInfo")); assertEquals("test tracking url", appAttempt.getString("trackingUrl")); assertEquals(YarnApplicationAttemptState.FINISHED.toString(), appAttempt.get("appAttemptState")); }
@Test public void testMultipleContainers() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()).path("containers") .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); if (round == 1) { assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); return; } assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject containers = json.getJSONObject("containers"); assertEquals("incorrect number of elements", 1, containers.length()); JSONArray array = containers.getJSONArray("container"); assertEquals("incorrect number of elements", MAX_APPS, array.length()); }
@Test public void testSingleContainer() throws Exception { ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ContainerId containerId = ContainerId.newContainerId(appAttemptId, 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()).path("appattempts") .path(appAttemptId.toString()).path("containers") .path(containerId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); if (round == 1) { assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); return; } assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, response.getType().toString()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject container = json.getJSONObject("container"); assertEquals(containerId.toString(), container.getString("containerId")); assertEquals("test diagnostics info", container.getString("diagnosticsInfo")); assertEquals("-1", container.getString("allocatedMB")); assertEquals("-1", container.getString("allocatedVCores")); assertEquals(NodeId.newInstance("test host", 100).toString(), container.getString("assignedNodeId")); assertEquals("-1", container.getString("priority")); Configuration conf = new YarnConfiguration(); assertEquals(WebAppUtils.getHttpSchemePrefix(conf) + WebAppUtils.getAHSWebAppURLWithoutScheme(conf) + "/applicationhistory/logs/test host:100/container_0_0001_01_000001/" + "container_0_0001_01_000001/user1", container.getString("logUrl")); assertEquals(ContainerState.COMPLETE.toString(), container.getString("containerState")); }
@Test(timeout = 10000) public void testContainerLogsForFinishedApps() throws Exception { String fileName = "syslog"; String user = "user1"; NodeId nodeId = NodeId.newInstance("test host", 100); NodeId nodeId2 = NodeId.newInstance("host2", 1234); ApplicationId appId = ApplicationId.newInstance(0, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance( appId, 1); ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 1); ContainerId containerId100 = ContainerId.newContainerId(appAttemptId, 100); TestContainerLogsUtils.createContainerLogFileInRemoteFS(conf, fs, rootLogDir, appId, Collections.singletonMap(containerId1, "Hello." + containerId1), nodeId, fileName, user, true); TestContainerLogsUtils.createContainerLogFileInRemoteFS(conf, fs, rootLogDir, appId, Collections.singletonMap(containerId100, "Hello." + containerId100), nodeId2, fileName, user, false); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1.toString()).path(fileName) .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); String responseText = response.getEntity(String.class); assertTrue(responseText.contains("Hello." + containerId1)); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containers") .path(containerId1.toString()).path("logs").path(fileName) .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertTrue(responseText.contains("Hello." + containerId1)); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId100.toString()).path(fileName) .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertTrue(responseText.contains("Hello." + containerId100)); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containers") .path(containerId100.toString()).path("logs").path(fileName) .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertTrue(responseText.contains("Hello." + containerId100)); ApplicationId appId100 = ApplicationId.newInstance(0, 100); ApplicationAttemptId appAttemptId100 = ApplicationAttemptId.newInstance( appId100, 1); ContainerId containerId1ForApp100 = ContainerId.newContainerId( appAttemptId100, 1); TestContainerLogsUtils.createContainerLogFileInRemoteFS(conf, fs, rootLogDir, appId100, Collections.singletonMap(containerId1ForApp100, "Hello." + containerId1ForApp100), nodeId, fileName, user, true); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1ForApp100.toString()).path(fileName) .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertTrue(responseText.contains("Hello." + containerId1ForApp100)); int fullTextSize = responseText.getBytes().length; String tailEndSeparator = StringUtils.repeat("*", "End of LogType:syslog".length() + 50) + "\n\n"; int tailTextSize = "\nEnd of LogType:syslog\n".getBytes().length + tailEndSeparator.getBytes().length; String logMessage = "Hello." + containerId1ForApp100; int fileContentSize = logMessage.getBytes().length; r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1ForApp100.toString()).path(fileName) .queryParam("user.name", user) .queryParam("size", "5") .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertEquals(responseText.getBytes().length, (fullTextSize - fileContentSize) + 5); assertTrue(fullTextSize >= responseText.getBytes().length); assertEquals(new String(responseText.getBytes(), (fullTextSize - fileContentSize - tailTextSize), 5), new String(logMessage.getBytes(), 0, 5)); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1ForApp100.toString()).path(fileName) .queryParam("user.name", user) .queryParam("size", "-5") .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertEquals(responseText.getBytes().length, (fullTextSize - fileContentSize) + 5); assertTrue(fullTextSize >= responseText.getBytes().length); assertEquals(new String(responseText.getBytes(), (fullTextSize - fileContentSize - tailTextSize), 5), new String(logMessage.getBytes(), fileContentSize - 5, 5)); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1ForApp100.toString()).path(fileName) .queryParam("user.name", user) .queryParam("size", "10000") .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertThat(responseText.getBytes()).hasSize(fullTextSize); r = resource(); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1ForApp100.toString()).path(fileName) .queryParam("user.name", user) .queryParam("size", "-10000") .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertThat(responseText.getBytes()).hasSize(fullTextSize); }
@Test(timeout = 10000) public void testContainerLogsForRunningApps() throws Exception { String fileName = "syslog"; String user = "user1"; ApplicationId appId = ApplicationId.newInstance( 1234, 1); ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1); ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 1); WebResource r = resource(); URI requestURI = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1.toString()).path(fileName) .queryParam("user.name", user).getURI(); String redirectURL = getRedirectURL(requestURI.toString()); assertTrue(redirectURL != null); assertTrue(redirectURL.contains("test:1234")); assertTrue(redirectURL.contains("ws/v1/node/containers")); assertTrue(redirectURL.contains(containerId1.toString())); assertTrue(redirectURL.contains("/logs/" + fileName)); assertTrue(redirectURL.contains("user.name=" + user)); requestURI = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1.toString()).path(fileName) .queryParam("user.name", user) .queryParam(YarnWebServiceParams.NM_ID, NM_ID) .getURI(); redirectURL = getRedirectURL(requestURI.toString()); assertTrue(redirectURL != null); assertTrue(redirectURL.contains(NM_WEBADDRESS)); assertTrue(redirectURL.contains("ws/v1/node/containers")); assertTrue(redirectURL.contains(containerId1.toString())); assertTrue(redirectURL.contains("/logs/" + fileName)); assertTrue(redirectURL.contains("user.name=" + user)); requestURI = r.path("ws").path("v1") .path("applicationhistory").path("containers") .path(containerId1.toString()).path("logs").path(fileName) .queryParam("user.name", user).getURI(); redirectURL = getRedirectURL(requestURI.toString()); assertTrue(redirectURL != null); assertTrue(redirectURL.contains("test:1234")); assertTrue(redirectURL.contains("ws/v1/node/containers")); assertTrue(redirectURL.contains(containerId1.toString())); assertTrue(redirectURL.contains("/logs/" + fileName)); assertTrue(redirectURL.contains("user.name=" + user)); requestURI = r.path("ws").path("v1") .path("applicationhistory").path("containers") .path(containerId1.toString()).path("logs").path(fileName) .queryParam("user.name", user) .queryParam(YarnWebServiceParams.NM_ID, NM_ID) .getURI(); redirectURL = getRedirectURL(requestURI.toString()); assertTrue(redirectURL != null); assertTrue(redirectURL.contains(NM_WEBADDRESS)); assertTrue(redirectURL.contains("ws/v1/node/containers")); assertTrue(redirectURL.contains(containerId1.toString())); assertTrue(redirectURL.contains("/logs/" + fileName)); assertTrue(redirectURL.contains("user.name=" + user)); ContainerId containerId1000 = ContainerId.newContainerId( appAttemptId, 1000); String content = "Hello." + containerId1000; NodeId nodeId = NodeId.newInstance("test host", 100); TestContainerLogsUtils.createContainerLogFileInRemoteFS(conf, fs, rootLogDir, appId, Collections.singletonMap(containerId1000, content), nodeId, fileName, user, true); r = resource(); ClientResponse response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1000.toString()).path(fileName) .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); String responseText = response.getEntity(String.class); assertTrue(responseText.contains(content)); assertTrue(responseText.contains("LogAggregationType: " + ContainerLogAggregationType.LOCAL)); assertTrue( responseText.contains(LogWebServiceUtils.getNoRedirectWarning())); response = r.path("ws").path("v1") .path("applicationhistory").path("containerlogs") .path(containerId1000.toString()).path(fileName) .queryParam(YarnWebServiceParams.NM_ID, "invalid-nm:1234") .queryParam("user.name", user) .accept(MediaType.TEXT_PLAIN) .get(ClientResponse.class); responseText = response.getEntity(String.class); assertTrue(responseText.contains(content)); assertTrue(responseText.contains("LogAggregationType: " + ContainerLogAggregationType.LOCAL)); assertTrue( responseText.contains(LogWebServiceUtils.getNoRedirectWarning())); String content1 = "Hello." + containerId1; NodeId nodeId1 = NodeId.fromString(NM_ID); TestContainerLogsUtils.createContainerLogFileInRemoteFS(conf, fs, rootLogDir, appId, Collections.singletonMap(containerId1, content1), nodeId1, fileName, user, true); response = r.path("ws").path("v1") .path("applicationhistory").path("containers") .path(containerId1.toString()).path("logs").path(fileName) .queryParam("user.name", user) .queryParam(YarnWebServiceParams.REDIRECTED_FROM_NODE, "true") .accept(MediaType.TEXT_PLAIN).get(ClientResponse.class); responseText = response.getEntity(String.class); assertTrue(responseText.contains(content1)); assertTrue(responseText.contains("LogAggregationType: " + ContainerLogAggregationType.AGGREGATED)); }