Search in sources :

Example 11 with GenericType

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

the class TestTimelineReaderWebServices method testGetEntitiesByRelations.

@Test
public void testGetEntitiesByRelations() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app?relatesto=" + "flow:flow1");
        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(1, entities.size());
        assertTrue("Entity with id_1 should have been present in response.", entities.contains(newEntity("app", "id_1")));
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/app1/entities/app?isrelatedto=" + "type1:tid1_2,type2:tid2_1%60");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
        assertNotNull(entities);
        assertEquals(1, entities.size());
        assertTrue("Entity with id_1 should have been present in response.", entities.contains(newEntity("app", "id_1")));
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/app1/entities/app?isrelatedto=" + "type1:tid1_1:tid1_2,type2:tid2_1%60");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
        assertNotNull(entities);
        assertEquals(1, entities.size());
        assertTrue("Entity with id_1 should have been present in response.", entities.contains(newEntity("app", "id_1")));
    } 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 12 with GenericType

use of com.sun.jersey.api.client.GenericType 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 13 with GenericType

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetEntitiesDataToRetrieve.

/**
   * Tests if specific configs and metrics are retrieve for getEntities call.
   */
@Test
public void testGetEntitiesDataToRetrieve() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?confstoretrieve=cfg_");
        ClientResponse resp = getResponse(client, uri);
        Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        int cfgCnt = 0;
        for (TimelineEntity entity : entities) {
            cfgCnt += entity.getConfigs().size();
            for (String configKey : entity.getConfigs().keySet()) {
                assertTrue(configKey.startsWith("cfg_"));
            }
        }
        assertEquals(2, cfgCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?confstoretrieve=cfg_,config_");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        cfgCnt = 0;
        for (TimelineEntity entity : entities) {
            cfgCnt += entity.getConfigs().size();
            for (String configKey : entity.getConfigs().keySet()) {
                assertTrue(configKey.startsWith("cfg_") || configKey.startsWith("config_"));
            }
        }
        assertEquals(5, cfgCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?confstoretrieve=!(cfg_,config_)");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        cfgCnt = 0;
        for (TimelineEntity entity : entities) {
            cfgCnt += entity.getConfigs().size();
            for (String configKey : entity.getConfigs().keySet()) {
                assertTrue(configKey.startsWith("configuration_"));
            }
        }
        assertEquals(1, cfgCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricstoretrieve=MAP_");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        int metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            for (TimelineMetric metric : entity.getMetrics()) {
                assertTrue(metric.getId().startsWith("MAP_"));
            }
        }
        assertEquals(1, metricCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricstoretrieve=MAP1_,HDFS_");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            for (TimelineMetric metric : entity.getMetrics()) {
                assertTrue(metric.getId().startsWith("MAP1_") || metric.getId().startsWith("HDFS_"));
            }
        }
        assertEquals(3, metricCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?metricstoretrieve=!(MAP1_,HDFS_)");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(2, entities.size());
        metricCnt = 0;
        for (TimelineEntity entity : entities) {
            metricCnt += entity.getMetrics().size();
            for (TimelineMetric metric : entity.getMetrics()) {
                assertTrue(metric.getId().startsWith("MAP_") || metric.getId().startsWith("MAP11_"));
            }
        }
        assertEquals(2, metricCnt);
    } 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 GenericType

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetEntitiesConfigFilters.

@Test
public void testGetEntitiesConfigFilters() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?conffilters=config_param1%20eq%20value1%20OR%20" + "config_param1%20eq%20value3");
        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?conffilters=config_param1%20eq%20value1%20AND" + "%20configuration_param2%20eq%20value2");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(0, entities.size());
        // conffilters=(config_param1 eq value1 AND configuration_param2 eq
        // value2) OR (config_param1 eq value3 AND cfg_param3 eq value1)
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?conffilters=(config_param1%20eq%20value1%20AND" + "%20configuration_param2%20eq%20value2)%20OR%20(config_param1%20eq" + "%20value3%20AND%20cfg_param3%20eq%20value1)");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        int cfgCnt = 0;
        for (TimelineEntity entity : entities) {
            cfgCnt += entity.getConfigs().size();
            assertTrue(entity.getId().equals("entity2"));
        }
        assertEquals(0, cfgCnt);
        // conffilters=(config_param1 eq value1 AND configuration_param2 eq
        // value2) OR (config_param1 eq value3 AND cfg_param3 eq value1)
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?conffilters=(config_param1%20eq%20value1%20AND" + "%20configuration_param2%20eq%20value2)%20OR%20(config_param1%20eq" + "%20value3%20AND%20cfg_param3%20eq%20value1)&fields=CONFIGS");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        cfgCnt = 0;
        for (TimelineEntity entity : entities) {
            cfgCnt += entity.getConfigs().size();
            assertTrue(entity.getId().equals("entity2"));
        }
        assertEquals(3, cfgCnt);
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?conffilters=(config_param1%20eq%20value1%20AND" + "%20configuration_param2%20eq%20value2)%20OR%20(config_param1%20eq" + "%20value3%20AND%20cfg_param3%20eq%20value1)&confstoretrieve=cfg_," + "configuration_");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(1, entities.size());
        cfgCnt = 0;
        for (TimelineEntity entity : entities) {
            cfgCnt += entity.getConfigs().size();
            assertTrue(entity.getId().equals("entity2"));
            for (String configKey : entity.getConfigs().keySet()) {
                assertTrue(configKey.startsWith("cfg_") || configKey.startsWith("configuration_"));
            }
        }
        assertEquals(2, cfgCnt);
        // Test for behavior when compare op is ne(not equals) vs ene
        // (exists and not equals). configuration_param2 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.
        // conffilters=configuration_param2 ne value3
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?conffilters=configuration_param2%20ne%20value3");
        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"));
        }
        // conffilters=configuration_param2 ene value3
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/application_1111111111_1111/" + "entities/type1?conffilters=configuration_param2%20ene%20value3");
        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) 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 15 with GenericType

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

the class TestTimelineReaderWebServicesHBaseStorage method testGetFlowApps.

@Test
public void testGetFlowApps() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/apps?" + "fields=ALL");
        ClientResponse resp = getResponse(client, uri);
        Set<TimelineEntity> entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(3, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue("Unexpected app in result", (entity.getId().equals("application_1111111111_1111") && entity.getConfigs().size() == 1 && entity.getConfigs().equals(ImmutableMap.of("cfg2", "value1"))) || (entity.getId().equals("application_1111111111_2222") && entity.getConfigs().size() == 1 && entity.getConfigs().equals(ImmutableMap.of("cfg1", "value1"))) || (entity.getId().equals("application_1111111111_2224") && entity.getConfigs().size() == 0));
            for (TimelineMetric metric : entity.getMetrics()) {
                if (entity.getId().equals("application_1111111111_1111")) {
                    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);
                    assertTrue(verifyMetrics(metric, m1, m2, m3));
                } else if (entity.getId().equals("application_1111111111_2222")) {
                    TimelineMetric m1 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP_SLOT_MILLIS", ts - 80000, 101L);
                    assertTrue(verifyMetrics(metric, m1));
                } else if (entity.getId().equals("application_1111111111_2224")) {
                    TimelineMetric m1 = newMetric(TimelineMetric.Type.SINGLE_VALUE, "MAP_SLOT_MILLIS", ts - 80000, 101L);
                    assertTrue(verifyMetrics(metric, m1));
                }
            }
        }
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/users/user1/flows/flow_name/apps?" + "fields=ALL&metricslimit=6");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(3, entities.size());
        for (TimelineEntity entity : entities) {
            assertTrue("Unexpected app in result", (entity.getId().equals("application_1111111111_1111") && entity.getConfigs().size() == 1 && entity.getConfigs().equals(ImmutableMap.of("cfg2", "value1"))) || (entity.getId().equals("application_1111111111_2222") && entity.getConfigs().size() == 1 && entity.getConfigs().equals(ImmutableMap.of("cfg1", "value1"))) || (entity.getId().equals("application_1111111111_2224") && entity.getConfigs().size() == 0));
            for (TimelineMetric metric : entity.getMetrics()) {
                if (entity.getId().equals("application_1111111111_1111")) {
                    TimelineMetric m1 = newMetric(TimelineMetric.Type.TIME_SERIES, "HDFS_BYTES_READ", ts - 80000, 57L);
                    m1.addValue(ts - 100000, 31L);
                    TimelineMetric m2 = newMetric(TimelineMetric.Type.TIME_SERIES, "MAP_SLOT_MILLIS", ts - 80000, 40L);
                    m2.addValue(ts - 100000, 2L);
                    TimelineMetric m3 = newMetric(TimelineMetric.Type.TIME_SERIES, "MAP1_SLOT_MILLIS", ts - 80000, 40L);
                    m3.addValue(ts - 100000, 2L);
                    assertTrue(verifyMetrics(metric, m1, m2, m3));
                } else if (entity.getId().equals("application_1111111111_2222")) {
                    TimelineMetric m1 = newMetric(TimelineMetric.Type.TIME_SERIES, "MAP_SLOT_MILLIS", ts - 80000, 101L);
                    m1.addValue(ts - 100000, 5L);
                    assertTrue(verifyMetrics(metric, m1));
                } else if (entity.getId().equals("application_1111111111_2224")) {
                    TimelineMetric m1 = newMetric(TimelineMetric.Type.TIME_SERIES, "MAP_SLOT_MILLIS", ts - 80000, 101L);
                    m1.addValue(ts - 100000, 5L);
                    assertTrue(verifyMetrics(metric, m1));
                }
            }
        }
        // Query without specifying cluster ID.
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/users/user1/flows/flow_name/apps");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertNotNull(entities);
        assertEquals(3, entities.size());
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/users/user1/flows/flow_name/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)

Aggregations

ClientResponse (com.sun.jersey.api.client.ClientResponse)19 GenericType (com.sun.jersey.api.client.GenericType)19 URI (java.net.URI)19 Test (org.junit.Test)18 Client (com.sun.jersey.api.client.Client)17 Set (java.util.Set)17 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)14 HashSet (java.util.HashSet)12 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)5 WebResource (com.sun.jersey.api.client.WebResource)2 List (java.util.List)2 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 FlowRunEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity)2 PerContainerLogFileInfo (org.apache.hadoop.yarn.logaggregation.PerContainerLogFileInfo)2 ContainerLogsInfo (org.apache.hadoop.yarn.server.webapp.dao.ContainerLogsInfo)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 DateFormat (java.text.DateFormat)1 Configuration (org.apache.hadoop.conf.Configuration)1