Search in sources :

Example 61 with Client

use of com.sun.jersey.api.client.Client in project hadoop by apache.

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowRunNotPresent.

@Test
public void testGetFlowRunNotPresent() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs/" + "1002345678929");
        verifyHttpResponse(client, uri, Status.NOT_FOUND);
    } finally {
        client.destroy();
    }
}
Also used : Client(com.sun.jersey.api.client.Client) URI(java.net.URI) Test(org.junit.Test)

Example 62 with Client

use of com.sun.jersey.api.client.Client in project hadoop by apache.

the class TestTimelineReaderWebServices method testQueryWithoutCluster.

@Test
public void testQueryWithoutCluster() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/apps/app1/entities/app/id_1");
        ClientResponse resp = getResponse(client, uri);
        TimelineEntity entity = resp.getEntity(TimelineEntity.class);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
        assertNotNull(entity);
        assertEquals("id_1", entity.getId());
        assertEquals("app", entity.getType());
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/apps/app1/entities/app");
        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(4, entities.size());
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Set(java.util.Set) Client(com.sun.jersey.api.client.Client) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) URI(java.net.URI) Test(org.junit.Test)

Example 63 with Client

use of com.sun.jersey.api.client.Client 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();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) GenericType(com.sun.jersey.api.client.GenericType) Set(java.util.Set) Client(com.sun.jersey.api.client.Client) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) URI(java.net.URI) Test(org.junit.Test)

Example 64 with Client

use of com.sun.jersey.api.client.Client in project hadoop by apache.

the class TestTimelineReaderWebServices method testGetEntitiesByMetricFilters.

@Test
public void testGetEntitiesByMetricFilters() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app?" + "metricfilters=metric3%20ge%200");
        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(2, entities.size());
        assertTrue("Entities with id_1 and id_2 should have been present" + " in response.", entities.contains(newEntity("app", "id_1")) && entities.contains(newEntity("app", "id_2")));
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Set(java.util.Set) Client(com.sun.jersey.api.client.Client) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) URI(java.net.URI) Test(org.junit.Test)

Example 65 with Client

use of com.sun.jersey.api.client.Client in project hadoop by apache.

the class TestTimelineReaderWebServices method testGetEntities.

@Test
public void testGetEntities() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app");
        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(4, entities.size());
        assertTrue("Entities id_1, id_2, id_3 and id_4 should have been" + " present in response", entities.contains(newEntity("app", "id_1")) && entities.contains(newEntity("app", "id_2")) && entities.contains(newEntity("app", "id_3")) && entities.contains(newEntity("app", "id_4")));
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Set(java.util.Set) Client(com.sun.jersey.api.client.Client) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Client (com.sun.jersey.api.client.Client)87 ClientResponse (com.sun.jersey.api.client.ClientResponse)61 Test (org.junit.Test)59 URI (java.net.URI)51 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)36 Set (java.util.Set)30 WebResource (com.sun.jersey.api.client.WebResource)19 HashSet (java.util.HashSet)19 GenericType (com.sun.jersey.api.client.GenericType)17 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)9 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)9 JSONObject (org.codehaus.jettison.json.JSONObject)7 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)6 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)4 ArrayList (java.util.ArrayList)4 FlowRunEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity)4 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)3 JSONException (org.codehaus.jettison.json.JSONException)3