Search in sources :

Example 51 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowAppsNotPresent.

@Test
public void testGetFlowAppsNotPresent() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster2/users/user1/flows/flow_name55/apps");
        ClientResponse resp = getResponse(client, uri);
        Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entities);
        assertEquals(0, entities.size());
    } 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 52 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowRun.

@Test
public void testGetFlowRun() 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");
        ClientResponse resp = getResponse(client, uri);
        FlowRunEntity entity = resp.getEntity(FlowRunEntity.class);
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; charset=utf-8", resp.getType().toString());
        assertNotNull(entity);
        assertEquals("user1@flow_name/1002345678919", 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, 141L);
        TimelineMetric m3 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP1_SLOT_MILLIS", ts - 80000, 40L);
        for (TimelineMetric metric : entity.getMetrics()) {
            assertTrue(verifyMetrics(metric, m1, m2, m3));
        }
        // Query without specifying cluster ID.
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/users/user1/flows/flow_name/runs/1002345678919");
        resp = getResponse(client, uri);
        entity = resp.getEntity(FlowRunEntity.class);
        assertNotNull(entity);
        assertEquals("user1@flow_name/1002345678919", entity.getId());
        assertEquals(3, entity.getMetrics().size());
        m1 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "HDFS_BYTES_READ", ts - 80000, 57L);
        m2 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP_SLOT_MILLIS", ts - 80000, 141L);
        m3 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP1_SLOT_MILLIS", 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) 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 53 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetEntitiesByUID.

@Test
public void testGetEntitiesByUID() throws Exception {
    Client client = createClient();
    try {
        // Query all flows.
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/flows");
        ClientResponse resp = getResponse(client, uri);
        Set<FlowActivityEntity> flowEntities = resp.getEntity(new GenericType<Set<FlowActivityEntity>>() {
        });
        assertNotNull(flowEntities);
        assertEquals(2, flowEntities.size());
        List<String> listFlowUIDs = new ArrayList<String>();
        for (FlowActivityEntity entity : flowEntities) {
            String flowUID = (String) entity.getInfo().get(TimelineReaderManager.UID_KEY);
            listFlowUIDs.add(flowUID);
            assertEquals(TimelineUIDConverter.FLOW_UID.encodeUID(new TimelineReaderContext(entity.getCluster(), entity.getUser(), entity.getFlowName(), null, null, null, null)), flowUID);
            assertTrue((entity.getId().endsWith("@flow_name") && entity.getFlowRuns().size() == 2) || (entity.getId().endsWith("@flow_name2") && entity.getFlowRuns().size() == 1));
        }
        // Query flowruns based on UID returned in query above.
        List<String> listFlowRunUIDs = new ArrayList<String>();
        for (String flowUID : listFlowUIDs) {
            uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/flow-uid/" + flowUID + "/runs");
            resp = getResponse(client, uri);
            Set<FlowRunEntity> frEntities = resp.getEntity(new GenericType<Set<FlowRunEntity>>() {
            });
            assertNotNull(frEntities);
            for (FlowRunEntity entity : frEntities) {
                String flowRunUID = (String) entity.getInfo().get(TimelineReaderManager.UID_KEY);
                listFlowRunUIDs.add(flowRunUID);
                assertEquals(TimelineUIDConverter.FLOWRUN_UID.encodeUID(new TimelineReaderContext("cluster1", entity.getUser(), entity.getName(), entity.getRunId(), null, null, null)), flowRunUID);
            }
        }
        assertEquals(3, listFlowRunUIDs.size());
        // Query single flowrun based on UIDs' returned in query to get flowruns.
        for (String flowRunUID : listFlowRunUIDs) {
            uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/run-uid/" + flowRunUID);
            resp = getResponse(client, uri);
            FlowRunEntity entity = resp.getEntity(FlowRunEntity.class);
            assertNotNull(entity);
        }
        // Query apps based on UIDs' returned in query to get flowruns.
        List<String> listAppUIDs = new ArrayList<String>();
        for (String flowRunUID : listFlowRunUIDs) {
            TimelineReaderContext context = TimelineUIDConverter.FLOWRUN_UID.decodeUID(flowRunUID);
            uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/run-uid/" + flowRunUID + "/apps");
            resp = getResponse(client, uri);
            Set<TimelineEntity> appEntities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
            });
            assertNotNull(appEntities);
            for (TimelineEntity entity : appEntities) {
                String appUID = (String) entity.getInfo().get(TimelineReaderManager.UID_KEY);
                listAppUIDs.add(appUID);
                assertEquals(TimelineUIDConverter.APPLICATION_UID.encodeUID(new TimelineReaderContext(context.getClusterId(), context.getUserId(), context.getFlowName(), context.getFlowRunId(), entity.getId(), null, null)), appUID);
            }
        }
        assertEquals(4, listAppUIDs.size());
        // Query single app based on UIDs' returned in query to get apps.
        for (String appUID : listAppUIDs) {
            uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/app-uid/" + appUID);
            resp = getResponse(client, uri);
            TimelineEntity entity = resp.getEntity(TimelineEntity.class);
            assertNotNull(entity);
        }
        // Query entities based on UIDs' returned in query to get apps and
        // a specific entity type(in this case type1).
        List<String> listEntityUIDs = new ArrayList<String>();
        for (String appUID : listAppUIDs) {
            TimelineReaderContext context = TimelineUIDConverter.APPLICATION_UID.decodeUID(appUID);
            uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/app-uid/" + appUID + "/entities/type1");
            resp = getResponse(client, uri);
            Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
            });
            assertNotNull(entities);
            for (TimelineEntity entity : entities) {
                String entityUID = (String) entity.getInfo().get(TimelineReaderManager.UID_KEY);
                listEntityUIDs.add(entityUID);
                assertEquals(TimelineUIDConverter.GENERIC_ENTITY_UID.encodeUID(new TimelineReaderContext(context.getClusterId(), context.getUserId(), context.getFlowName(), context.getFlowRunId(), context.getAppId(), "type1", entity.getId())), entityUID);
            }
        }
        assertEquals(2, listEntityUIDs.size());
        // Query single entity based on UIDs' returned in query to get entities.
        for (String entityUID : listEntityUIDs) {
            uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/entity-uid/" + entityUID);
            resp = getResponse(client, uri);
            TimelineEntity entity = resp.getEntity(TimelineEntity.class);
            assertNotNull(entity);
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/flow-uid/dummy:flow/runs");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/run-uid/dummy:flowrun");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
        // Run Id is not a numerical value.
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/run-uid/some:dummy:flow:123v456");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/run-uid/dummy:flowrun/apps");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/app-uid/dummy:app");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/app-uid/dummy:app/entities/type1");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/entity-uid/dummy:entity");
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) URI(java.net.URI) FlowRunEntity(org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity) FlowActivityEntity(org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 54 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowAppsFilters.

@Test
public void testGetFlowAppsFilters() throws Exception {
    Client client = createClient();
    try {
        String entityType = TimelineEntityType.YARN_APPLICATION.toString();
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/apps?" + "eventfilters=" + ApplicationMetricsConstants.FINISHED_EVENT_TYPE);
        ClientResponse resp = getResponse(client, uri);
        Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        assertTrue("Unexpected app in result", entities.contains(newEntity(entityType, "application_1111111111_1111")));
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/apps?" + "metricfilters=HDFS_BYTES_READ%20ge%200");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        assertTrue("Unexpected app in result", entities.contains(newEntity(entityType, "application_1111111111_1111")));
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/apps?" + "conffilters=cfg1%20eq%20value1");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        assertTrue("Unexpected app in result", entities.contains(newEntity(entityType, "application_1111111111_2222")));
    } 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)

Example 55 with Client

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

the class TestTimelineReaderWebServicesHBaseStorage method testUIDNotProperlyEscaped.

@Test
public void testUIDNotProperlyEscaped() throws Exception {
    Client client = createClient();
    try {
        String appUID = "cluster1!user*1!flow_name!1002345678919!application_1111111111_1111";
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/app-uid/" + appUID);
        verifyHttpResponse(client, uri, Status.BAD_REQUEST);
    } finally {
        client.destroy();
    }
}
Also used : Client(com.sun.jersey.api.client.Client) 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