Search in sources :

Example 11 with FlowRunEntity

use of org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity 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 12 with FlowRunEntity

use of org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity 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)

Aggregations

FlowRunEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity)12 Test (org.junit.Test)9 FlowActivityEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowActivityEntity)6 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)5 TimelineReaderContext (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineReaderContext)5 Client (com.sun.jersey.api.client.Client)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 URI (java.net.URI)4 Configuration (org.apache.hadoop.conf.Configuration)4 TimelineEntities (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntities)4 TimelineDataToRetrieve (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineDataToRetrieve)4 HBaseTimelineReaderImpl (org.apache.hadoop.yarn.server.timelineservice.storage.HBaseTimelineReaderImpl)4 HBaseTimelineWriterImpl (org.apache.hadoop.yarn.server.timelineservice.storage.HBaseTimelineWriterImpl)4 HashSet (java.util.HashSet)3 Set (java.util.Set)3 TimelineEntityFilters (org.apache.hadoop.yarn.server.timelineservice.reader.TimelineEntityFilters)3 GenericType (com.sun.jersey.api.client.GenericType)2 Connection (org.apache.hadoop.hbase.client.Connection)2 Get (org.apache.hadoop.hbase.client.Get)2 Result (org.apache.hadoop.hbase.client.Result)2