use of com.sun.jersey.api.client.GenericType in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetContainers.
@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<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
});
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
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<Set<TimelineEntity>>() {
});
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<Set<TimelineEntity>>() {
});
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();
}
}
use of com.sun.jersey.api.client.GenericType in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetAppAttempts.
@Test
public void testGetAppAttempts() throws Exception {
Client client = createClient();
try {
URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/" + "entities/YARN_APPLICATION_ATTEMPT");
ClientResponse resp = getResponse(client, uri);
Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
});
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
assertNotNull(entities);
int totalEntities = entities.size();
assertEquals(2, totalEntities);
assertTrue("Entity with app-attempt-2 should have been present in response.", entities.contains(newEntity(TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), "app-attempt-1")));
assertTrue("Entity with app-attempt-2 should have been present in response.", entities.contains(newEntity(TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), "app-attempt-2")));
uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/appattempts");
resp = getResponse(client, uri);
entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
});
assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getType());
assertNotNull(entities);
int retrievedEntity = entities.size();
assertEquals(2, retrievedEntity);
assertTrue("Entity with app-attempt-2 should have been present in response.", entities.contains(newEntity(TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), "app-attempt-1")));
assertTrue("Entity with app-attempt-2 should have been present in response.", entities.contains(newEntity(TimelineEntityType.YARN_APPLICATION_ATTEMPT.toString(), "app-attempt-2")));
assertEquals(totalEntities, retrievedEntity);
} finally {
client.destroy();
}
}
use of com.sun.jersey.api.client.GenericType in project hadoop by apache.
the class TestTimelineReaderWebServices method testGetEntitiesBasedOnCreatedTime.
@Test
public void testGetEntitiesBasedOnCreatedTime() throws Exception {
Client client = createClient();
try {
URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app?" + "createdtimestart=1425016502030&createdtimeend=1425016502060");
ClientResponse resp = getResponse(client, uri);
Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
});
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
assertNotNull(entities);
assertEquals(1, entities.size());
assertTrue("Entity with id_4 should have been present in response.", entities.contains(newEntity("app", "id_4")));
uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/app1/entities/app?createdtimeend" + "=1425016502010");
resp = getResponse(client, uri);
entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
});
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
assertNotNull(entities);
assertEquals(3, entities.size());
assertFalse("Entity with id_4 should not have been present in response.", entities.contains(newEntity("app", "id_4")));
uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/app1/entities/app?createdtimestart=" + "1425016502010");
resp = getResponse(client, uri);
entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
});
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
assertNotNull(entities);
assertEquals(1, entities.size());
assertTrue("Entity with id_4 should have been present in response.", entities.contains(newEntity("app", "id_4")));
} finally {
client.destroy();
}
}
use of com.sun.jersey.api.client.GenericType in project hadoop by apache.
the class TestAHSWebServices method testContainerLogsMetaForRunningApps.
@Test(timeout = 10000)
public void testContainerLogsMetaForRunningApps() throws Exception {
String user = "user1";
ApplicationId appId = ApplicationId.newInstance(1234, 1);
ApplicationAttemptId appAttemptId = ApplicationAttemptId.newInstance(appId, 1);
ContainerId containerId1 = ContainerId.newContainerId(appAttemptId, 1);
WebResource r = resource();
// If we specify the NMID, we re-direct the request by using
// the NM's web address
URI requestURI = r.path("ws").path("v1").path("applicationhistory").path("containers").path(containerId1.toString()).path("logs").queryParam("user.name", user).queryParam(YarnWebServiceParams.NM_ID, NM_ID).getURI();
String 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"));
// If we do not specify the NodeId but can get Container information
// from ATS, we re-direct the request to the node manager
// who runs the container.
requestURI = r.path("ws").path("v1").path("applicationhistory").path("containers").path(containerId1.toString()).path("logs").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"));
// If we can not container information from ATS,
// and not specify nodeId,
// we would try to get aggregated log meta from remote FileSystem.
ContainerId containerId1000 = ContainerId.newContainerId(appAttemptId, 1000);
String fileName = "syslog";
String content = "Hello." + containerId1000;
NodeId nodeId = NodeId.newInstance("test host", 100);
TestContainerLogsUtils.createContainerLogFileInRemoteFS(conf, fs, rootLogDir, containerId1000, nodeId, fileName, user, content, true);
ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("containers").path(containerId1000.toString()).path("logs").queryParam("user.name", user).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
List<ContainerLogsInfo> responseText = response.getEntity(new GenericType<List<ContainerLogsInfo>>() {
});
assertTrue(responseText.size() == 2);
for (ContainerLogsInfo logInfo : responseText) {
if (logInfo.getLogType().equals(ContainerLogAggregationType.AGGREGATED.toString())) {
List<PerContainerLogFileInfo> logMeta = logInfo.getContainerLogsInfo();
assertTrue(logMeta.size() == 1);
assertEquals(logMeta.get(0).getFileName(), fileName);
assertEquals(logMeta.get(0).getFileSize(), String.valueOf(content.length()));
} else {
assertEquals(logInfo.getLogType(), ContainerLogAggregationType.LOCAL.toString());
}
}
// If we can not container information from ATS,
// and we specify NM id, but can not find NM WebAddress for this nodeId,
// we would still try to get aggregated log meta from remote FileSystem.
response = r.path("ws").path("v1").path("applicationhistory").path("containers").path(containerId1000.toString()).path("logs").queryParam(YarnWebServiceParams.NM_ID, "invalid-nm:1234").queryParam("user.name", user).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
responseText = response.getEntity(new GenericType<List<ContainerLogsInfo>>() {
});
assertTrue(responseText.size() == 2);
for (ContainerLogsInfo logInfo : responseText) {
if (logInfo.getLogType().equals(ContainerLogAggregationType.AGGREGATED.toString())) {
List<PerContainerLogFileInfo> logMeta = logInfo.getContainerLogsInfo();
assertTrue(logMeta.size() == 1);
assertEquals(logMeta.get(0).getFileName(), fileName);
assertEquals(logMeta.get(0).getFileSize(), String.valueOf(content.length()));
} else {
assertEquals(logInfo.getLogType(), ContainerLogAggregationType.LOCAL.toString());
}
}
}
Aggregations