Search in sources :

Example 16 with ClientResponse

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

the class TestTimelineReaderWebServicesHBaseStorage method testUIDQueryWithAndWithoutFlowContextInfo.

@Test
public void testUIDQueryWithAndWithoutFlowContextInfo() throws Exception {
    Client client = createClient();
    try {
        String appUIDWithFlowInfo = "cluster1!user1!flow_name!1002345678919!application_1111111111_1111";
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/app-uid/" + appUIDWithFlowInfo);
        ClientResponse resp = getResponse(client, uri);
        TimelineEntity appEntity1 = resp.getEntity(TimelineEntity.class);
        assertNotNull(appEntity1);
        assertEquals(TimelineEntityType.YARN_APPLICATION.toString(), appEntity1.getType());
        assertEquals("application_1111111111_1111", appEntity1.getId());
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "app-uid/" + appUIDWithFlowInfo + "/entities/type1");
        resp = getResponse(client, uri);
        Set<TimelineEntity> entities1 = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities1);
        assertEquals(2, entities1.size());
        for (TimelineEntity entity : entities1) {
            assertNotNull(entity.getInfo());
            assertEquals(1, entity.getInfo().size());
            String uid = (String) entity.getInfo().get(TimelineReaderManager.UID_KEY);
            assertNotNull(uid);
            assertTrue(uid.equals(appUIDWithFlowInfo + "!type1!entity1") || uid.equals(appUIDWithFlowInfo + "!type1!entity2"));
        }
        String appUIDWithoutFlowInfo = "cluster1!application_1111111111_1111";
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "app-uid/" + appUIDWithoutFlowInfo);
        resp = getResponse(client, uri);
        TimelineEntity appEntity2 = resp.getEntity(TimelineEntity.class);
        assertNotNull(appEntity2);
        assertEquals(TimelineEntityType.YARN_APPLICATION.toString(), appEntity2.getType());
        assertEquals("application_1111111111_1111", appEntity2.getId());
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "app-uid/" + appUIDWithoutFlowInfo + "/entities/type1");
        resp = getResponse(client, uri);
        Set<TimelineEntity> entities2 = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities2);
        assertEquals(2, entities2.size());
        for (TimelineEntity entity : entities2) {
            assertNotNull(entity.getInfo());
            assertEquals(1, entity.getInfo().size());
            String uid = (String) entity.getInfo().get(TimelineReaderManager.UID_KEY);
            assertNotNull(uid);
            assertTrue(uid.equals(appUIDWithoutFlowInfo + "!type1!entity1") || uid.equals(appUIDWithoutFlowInfo + "!type1!entity2"));
        }
        String entityUIDWithFlowInfo = appUIDWithFlowInfo + "!type1!entity1";
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "entity-uid/" + entityUIDWithFlowInfo);
        resp = getResponse(client, uri);
        TimelineEntity singleEntity1 = resp.getEntity(TimelineEntity.class);
        assertNotNull(singleEntity1);
        assertEquals("type1", singleEntity1.getType());
        assertEquals("entity1", singleEntity1.getId());
        String entityUIDWithoutFlowInfo = appUIDWithoutFlowInfo + "!type1!entity1";
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "entity-uid/" + entityUIDWithoutFlowInfo);
        resp = getResponse(client, uri);
        TimelineEntity singleEntity2 = resp.getEntity(TimelineEntity.class);
        assertNotNull(singleEntity2);
        assertEquals("type1", singleEntity2.getType());
        assertEquals("entity1", singleEntity2.getId());
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) 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 17 with ClientResponse

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetEntitiesMetricFilters.

@Test
public void testGetEntitiesMetricFilters() throws Exception {
    Client client = createClient();
    try {
        // metricfilters=HDFS_BYTES_READ lt 60 OR HDFS_BYTES_READ eq 157
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=HDFS_BYTES_READ%20lt%2060%20OR%20" + "HDFS_BYTES_READ%20eq%20157");
        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(entity.getId().equals("entity1") || entity.getId().equals("entity2"));
        }
        // metricfilters=HDFS_BYTES_READ lt 60 AND MAP_SLOT_MILLIS gt 40
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=HDFS_BYTES_READ%20lt%2060%20AND%20" + "MAP_SLOT_MILLIS%20gt%2040");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(0, entities.size());
        // metricfilters=(HDFS_BYTES_READ lt 60 AND MAP_SLOT_MILLIS gt 40) OR
        // (MAP1_SLOT_MILLIS ge 140 AND MAP11_SLOT_MILLIS le 122)
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=(HDFS_BYTES_READ%20lt%2060%20AND%20" + "MAP_SLOT_MILLIS%20gt%2040)%20OR%20(MAP1_SLOT_MILLIS%20ge" + "%20140%20AND%20MAP11_SLOT_MILLIS%20le%20122)");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        int metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            assertTrue(entity.getId().equals("entity2"));
        }
        assertEquals(0, metricCnt);
        // metricfilters=(HDFS_BYTES_READ lt 60 AND MAP_SLOT_MILLIS gt 40) OR
        // (MAP1_SLOT_MILLIS ge 140 AND MAP11_SLOT_MILLIS le 122)
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=(HDFS_BYTES_READ%20lt%2060%20AND%20" + "MAP_SLOT_MILLIS%20gt%2040)%20OR%20(MAP1_SLOT_MILLIS%20ge" + "%20140%20AND%20MAP11_SLOT_MILLIS%20le%20122)&fields=METRICS");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            assertTrue(entity.getId().equals("entity2"));
        }
        assertEquals(3, metricCnt);
        // metricfilters=(HDFS_BYTES_READ lt 60 AND MAP_SLOT_MILLIS gt 40) OR
        // (MAP1_SLOT_MILLIS ge 140 AND MAP11_SLOT_MILLIS le 122)
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=(HDFS_BYTES_READ%20lt%2060%20AND%20" + "MAP_SLOT_MILLIS%20gt%2040)%20OR%20(MAP1_SLOT_MILLIS%20ge" + "%20140%20AND%20MAP11_SLOT_MILLIS%20le%20122)&metricstoretrieve=" + "!(HDFS)");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            assertTrue(entity.getId().equals("entity2"));
            for (TimelineMetric metric : entity.getMetrics()) {
                assertTrue(metric.getId().startsWith("MAP1"));
                assertEquals(TimelineMetric.Type.SINGLE_VALUE, metric.getType());
            }
        }
        assertEquals(2, metricCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=(HDFS_BYTES_READ%20lt%2060%20AND%20" + "MAP_SLOT_MILLIS%20gt%2040)%20OR%20(MAP1_SLOT_MILLIS%20ge" + "%20140%20AND%20MAP11_SLOT_MILLIS%20le%20122)&metricstoretrieve=" + "!(HDFS)&metricslimit=10");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            assertTrue(entity.getId().equals("entity2"));
            for (TimelineMetric metric : entity.getMetrics()) {
                assertTrue(metric.getId().startsWith("MAP1"));
                if (metric.getId().equals("MAP1_SLOT_MILLIS")) {
                    assertEquals(2, metric.getValues().size());
                    assertEquals(TimelineMetric.Type.TIME_SERIES, metric.getType());
                } else if (metric.getId().equals("MAP11_SLOT_MILLIS")) {
                    assertEquals(TimelineMetric.Type.SINGLE_VALUE, metric.getType());
                } else {
                    fail("Unexpected metric id");
                }
            }
        }
        assertEquals(2, metricCnt);
        // Test for behavior when compare op is ne(not equals) vs ene
        // (exists and not equals). MAP11_SLOT_MILLIS does not exist for
        // entity1. For ne, both entity1 and entity2 will be returned. For ene,
        // only entity2 will be returned as we are checking for existence too.
        // metricfilters=MAP11_SLOT_MILLIS ne 100
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=MAP11_SLOT_MILLIS%20ne%20100");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue(entity.getId().equals("entity1") || entity.getId().equals("entity2"));
        }
        // metricfilters=MAP11_SLOT_MILLIS ene 100
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricfilters=MAP11_SLOT_MILLIS%20ene%20100");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue(entity.getId().equals("entity2"));
        }
    } 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 18 with ClientResponse

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetAppWithoutFlowInfo.

@Test
public void testGetAppWithoutFlowInfo() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111?" + "fields=ALL");
        ClientResponse resp = getResponse(client, uri);
        TimelineEntity entity = resp.getEntity(TimelineEntity.class);
        assertNotNull(entity);
        assertEquals("application_1111111111_1111", entity.getId());
        assertEquals(1, entity.getConfigs().size());
        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/clusters/cluster1/apps/application_1111111111_1111?" + "fields=ALL&metricslimit=10");
        resp = getResponse(client, uri);
        entity = resp.getEntity(TimelineEntity.class);
        assertNotNull(entity);
        assertEquals("application_1111111111_1111", entity.getId());
        assertEquals(1, entity.getConfigs().size());
        assertEquals(3, entity.getMetrics().size());
        m1 = newMetric(TimelineMetric.Type.TIME_SERIES, "HDFS_BYTES_READ", ts - 100000, 31L);
        m1.addValue(ts - 80000, 57L);
        m2 = newMetric(TimelineMetric.Type.TIME_SERIES, "MAP_SLOT_MILLIS", ts - 100000, 2L);
        m2.addValue(ts - 80000, 40L);
        m3 = newMetric(TimelineMetric.Type.TIME_SERIES, "MAP1_SLOT_MILLIS", ts - 100000, 2L);
        m3.addValue(ts - 80000, 40L);
        for (TimelineMetric metric : entity.getMetrics()) {
            assertTrue(verifyMetrics(metric, m1, m2, m3));
        }
    } 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 19 with ClientResponse

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

the class TestTimelineReaderWebServicesHBaseStorage method verifyHttpResponse.

private static void verifyHttpResponse(Client client, URI uri, Status status) {
    ClientResponse resp = client.resource(uri).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertNotNull(resp);
    assertTrue("Response from server should have been " + status, resp.getStatusInfo().getStatusCode() == status.getStatusCode());
    System.out.println("Response is: " + resp.getEntity(String.class));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse)

Example 20 with ClientResponse

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetEntitiesRelationFilters.

@Test
public void testGetEntitiesRelationFilters() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?isrelatedto=type3:entity31,type2:entity21:entity22");
        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(entity.getId().equals("entity1") || entity.getId().equals("entity2"));
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/application_1111111111_1111/entities/type1" + "?isrelatedto=!(type3:entity31,type2:entity21:entity22)");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(0, entities.size());
        // isrelatedto=!(type3:entity31,type2:entity21:entity22)OR type5:entity51,
        // type6:entity61:entity66
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/application_1111111111_1111/entities/type1" + "?isrelatedto=!(type3:entity31,type2:entity21:entity22)%20OR%20" + "type5:entity51,type6:entity61:entity66");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue(entity.getId().equals("entity2"));
        }
        // isrelatedto=(!(type3:entity31,type2:entity21:entity22)OR type5:
        // entity51,type6:entity61:entity66) OR (type1:entity14,type2:entity21:
        // entity22 AND (type3:entity32:entity35,type4:entity42))
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/application_1111111111_1111/entities/type1" + "?isrelatedto=(!(type3:entity31,type2:entity21:entity22)%20OR%20" + "type5:entity51,type6:entity61:entity66)%20OR%20(type1:entity14," + "type2:entity21:entity22%20AND%20(type3:entity32:entity35," + "type4:entity42))");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue(entity.getId().equals("entity1") || entity.getId().equals("entity2"));
        }
        // relatesto=!(type3:entity31,type2:entity21:entity22)OR type5:entity51,
        // type6:entity61:entity66
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/application_1111111111_1111/entities/type1" + "?relatesto=!%20(type3:entity31,type2:entity21:entity22%20)%20OR%20" + "type5:entity51,type6:entity61:entity66");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue(entity.getId().equals("entity2"));
        }
        // relatesto=(!(type3:entity31,type2:entity21:entity22)OR type5:entity51,
        // type6:entity61:entity66) OR (type1:entity14,type2:entity21:entity22 AND
        // (type3:entity32:entity35 , type4:entity42))
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/application_1111111111_1111/entities/type1" + "?relatesto=(!(%20type3:entity31,type2:entity21:entity22)%20OR%20" + "type5:entity51,type6:entity61:entity66%20)%20OR%20(type1:entity14," + "type2:entity21:entity22%20AND%20(type3:entity32:entity35%20,%20" + "type4:entity42))");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue(entity.getId().equals("entity1") || entity.getId().equals("entity2"));
        }
    } 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) 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

ClientResponse (com.sun.jersey.api.client.ClientResponse)2042 Test (org.junit.Test)1153 WebResource (com.sun.jersey.api.client.WebResource)699 JSONObject (org.codehaus.jettison.json.JSONObject)412 URI (java.net.URI)293 HashMap (java.util.HashMap)131 Client (com.sun.jersey.api.client.Client)123 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 ArrayList (java.util.ArrayList)100 IOException (java.io.IOException)91 JSONArray (org.codehaus.jettison.json.JSONArray)81 InputStream (java.io.InputStream)77 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)76 Gson (com.google.gson.Gson)59 JSONException (org.codehaus.jettison.json.JSONException)58 List (java.util.List)57 JavaResult (org.milyn.payload.JavaResult)52 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)48 Map (java.util.Map)47