Search in sources :

Example 11 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowRuns.

@Test
public void testGetFlowRuns() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs");
        ClientResponse resp = getResponse(client, uri);
        Set<FlowRunEntity> entities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (FlowRunEntity entity : entities) {
            assertTrue("Id, run id or start time does not match.", ((entity.getId().equals("user1@flow_name/1002345678919")) && (entity.getRunId() == 1002345678919L) && (entity.getStartTime() == 1425016501000L)) || ((entity.getId().equals("user1@flow_name/1002345678920")) && (entity.getRunId() == 1002345678920L) && (entity.getStartTime() == 1425016501034L)));
            assertEquals(0, entity.getMetrics().size());
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/users/user1/flows/flow_name/runs?limit=1");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(1, entities.size());
        for (FlowRunEntity entity : entities) {
            assertTrue("Id, run id or start time does not match.", entity.getId().equals("user1@flow_name/1002345678920") && entity.getRunId() == 1002345678920L && entity.getStartTime() == 1425016501034L);
            assertEquals(0, entity.getMetrics().size());
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs?" + "createdtimestart=1425016501030");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(1, entities.size());
        for (FlowRunEntity entity : entities) {
            assertTrue("Id, run id or start time does not match.", entity.getId().equals("user1@flow_name/1002345678920") && entity.getRunId() == 1002345678920L && entity.getStartTime() == 1425016501034L);
            assertEquals(0, entity.getMetrics().size());
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs?" + "createdtimestart=1425016500999&createdtimeend=1425016501035");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (FlowRunEntity entity : entities) {
            assertTrue("Id, run id or start time does not match.", ((entity.getId().equals("user1@flow_name/1002345678919")) && (entity.getRunId() == 1002345678919L) && (entity.getStartTime() == 1425016501000L)) || ((entity.getId().equals("user1@flow_name/1002345678920")) && (entity.getRunId() == 1002345678920L) && (entity.getStartTime() == 1425016501034L)));
            assertEquals(0, entity.getMetrics().size());
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs?" + "createdtimeend=1425016501030");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(1, entities.size());
        for (FlowRunEntity entity : entities) {
            assertTrue("Id, run id or start time does not match.", entity.getId().equals("user1@flow_name/1002345678919") && entity.getRunId() == 1002345678919L && entity.getStartTime() == 1425016501000L);
            assertEquals(0, entity.getMetrics().size());
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs?" + "fields=metrics");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (FlowRunEntity entity : entities) {
            assertTrue("Id, run id or start time does not match.", ((entity.getId().equals("user1@flow_name/1002345678919")) && (entity.getRunId() == 1002345678919L) && (entity.getStartTime() == 1425016501000L) && (entity.getMetrics().size() == 3)) || ((entity.getId().equals("user1@flow_name/1002345678920")) && (entity.getRunId() == 1002345678920L) && (entity.getStartTime() == 1425016501034L) && (entity.getMetrics().size() == 1)));
        }
        // fields as CONFIGS will lead to a HTTP 400 as it makes no sense for
        // flow runs.
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs?" + "fields=CONFIGS");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) GenericType(com.sun.jersey.api.client.GenericType) Set(java.util.Set) HashSet(java.util.HashSet) FlowRunEntity(org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity) Client(com.sun.jersey.api.client.Client) URI(java.net.URI) Test(org.junit.Test)

Example 12 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetAppNotPresent.

@Test
public void testGetAppNotPresent() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1378");
        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 13 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowRunApps.

@Test
public void testGetFlowRunApps() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs/" + "1002345678919/apps?fields=ALL");
        ClientResponse resp = getResponse(client, uri);
        Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue("Unexpected app in result", (entity.getId().equals("application_1111111111_1111") && entity.getMetrics().size() == 3) || (entity.getId().equals("application_1111111111_2222") && entity.getMetrics().size() == 1));
            for (TimelineMetric metric : entity.getMetrics()) {
                assertEquals(TimelineMetric.Type.SINGLE_VALUE, metric.getType());
                assertEquals(1, metric.getValues().size());
            }
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/runs/" + "1002345678919/apps?fields=ALL&metricslimit=2");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue("Unexpected app in result", (entity.getId().equals("application_1111111111_1111") && entity.getMetrics().size() == 3) || (entity.getId().equals("application_1111111111_2222") && entity.getMetrics().size() == 1));
            for (TimelineMetric metric : entity.getMetrics()) {
                assertTrue(metric.getValues().size() <= 2);
                assertEquals(TimelineMetric.Type.TIME_SERIES, metric.getType());
            }
        }
        // Query without specifying cluster ID.
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/users/user1/flows/flow_name/runs/1002345678919/apps");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/users/user1/flows/flow_name/runs/1002345678919/" + "apps?limit=1");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) TimelineMetric(org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric) GenericType(com.sun.jersey.api.client.GenericType) Set(java.util.Set) HashSet(java.util.HashSet) 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 14 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetApp.

@Test
public void testGetApp() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111?" + "userid=user1&fields=ALL&flowname=flow_name&flowrunid=1002345678919");
        ClientResponse resp = getResponse(client, uri);
        TimelineEntity entity = resp.getEntity(TimelineEntity.class);
        assertNotNull(entity);
        assertEquals("application_1111111111_1111", entity.getId());
        assertEquals(3, entity.getMetrics().size());
        TimelineMetric m1 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "HDFS_BYTES_READ", ts - 80000, 57L);
        TimelineMetric m2 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP_SLOT_MILLIS", ts - 80000, 40L);
        TimelineMetric m3 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP1_SLOT_MILLIS", ts - 80000, 40L);
        for (TimelineMetric metric : entity.getMetrics()) {
            assertTrue(verifyMetrics(metric, m1, m2, m3));
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/apps/application_1111111111_2222?userid=user1" + "&fields=metrics&flowname=flow_name&flowrunid=1002345678919");
        resp = getResponse(client, uri);
        entity = resp.getEntity(TimelineEntity.class);
        assertNotNull(entity);
        assertEquals("application_1111111111_2222", entity.getId());
        assertEquals(1, entity.getMetrics().size());
        TimelineMetric m4 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP_SLOT_MILLIS", ts - 80000, 101L);
        for (TimelineMetric metric : entity.getMetrics()) {
            assertTrue(verifyMetrics(metric, m4));
        }
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) TimelineMetric(org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric) 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 15 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method createClient.

private static Client createClient() {
    ClientConfig cfg = new DefaultClientConfig();
    cfg.getClasses().add(YarnJacksonJaxbJsonProvider.class);
    return new Client(new URLConnectionClientHandler(new DummyURLConnectionFactory()), cfg);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client)

Aggregations

Client (com.sun.jersey.api.client.Client)85 ClientResponse (com.sun.jersey.api.client.ClientResponse)60 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 HashSet (java.util.HashSet)19 WebResource (com.sun.jersey.api.client.WebResource)18 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 FlowActivityEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity)3