Search in sources :

Example 71 with Client

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

the class TestTimelineReaderWebServices method testGetEntitiesNoMatch.

@Test
public void testGetEntitiesNoMatch() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app?" + "metricfilters=metric7%20ge%200&isrelatedto=type1:tid1_1:tid1_2," + "type2:tid2_1%60&relatesto=flow:flow1&eventfilters=event_2,event_4" + "&infofilters=info2%20eq%203.5&createdtimestart=1425016502030&" + "createdtimeend=1425016502060");
        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(0, entities.size());
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) 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 72 with Client

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

the class TestTimelineReaderWebServices method testGetEntitiesBasedOnCreatedTime.

@Test
public void testGetEntitiesBasedOnCreatedTime() throws Exception {
    Client client = createClient();
    try {
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app?" + "createdtimestart=1425016502030&createdtimeend=1425016502060");
        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_4 should have been present in response.", entities.contains(newEntity("app", "id_4")));
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/app1/entities/app?createdtimeend" + "=1425016502010");
        resp = getResponse(client, uri);
        entities = resp.getEntity(new GenericType<Set<TimelineEntity>>() {
        });
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
        assertNotNull(entities);
        assertEquals(3, entities.size());
        assertFalse("Entity with id_4 should not have been present in response.", entities.contains(newEntity("app", "id_4")));
        uri = URI.create("http://localhost:" + serverPort + "/ws/v2/timeline/" + "clusters/cluster1/apps/app1/entities/app?createdtimestart=" + "1425016502010");
        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_4 should have been present in response.", entities.contains(newEntity("app", "id_4")));
    } 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 73 with Client

use of com.sun.jersey.api.client.Client in project commons by twitter.

the class Main method getModules.

@Override
public Iterable<? extends Module> getModules() {
    return Arrays.asList(new HttpModule(), new LogModule(), new StatsModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(new TypeLiteral<Closure<String>>() {
            }).toInstance(new Closure<String>() {

                private final Client http = Client.create();

                @Override
                public void execute(String path) {
                    http.asyncResource("http://" + PING_TARGET.get() + path).get(String.class);
                }
            });
            install(new JerseyServletModule() {

                @Override
                protected void configureServlets() {
                    filter("/ping*").through(GuiceContainer.class, ImmutableMap.<String, String>of());
                    Registration.registerEndpoint(binder(), "/ping");
                    bind(PingHandler.class);
                }
            });
        }
    });
}
Also used : Closure(com.twitter.common.base.Closure) LogModule(com.twitter.common.application.modules.LogModule) HttpModule(com.twitter.common.application.modules.HttpModule) JerseyServletModule(com.sun.jersey.guice.JerseyServletModule) StatsModule(com.twitter.common.application.modules.StatsModule) Client(com.sun.jersey.api.client.Client) AbstractModule(com.google.inject.AbstractModule)

Example 74 with Client

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

the class EnterpriseServerIT method shouldRequireAuthorizationForHAStatusEndpoints.

@Test
public void shouldRequireAuthorizationForHAStatusEndpoints() throws Exception {
    // Given
    NeoServer server = EnterpriseServerBuilder.server().withProperty(GraphDatabaseSettings.auth_enabled.name(), "true").usingDataDir(folder.getRoot().getAbsolutePath()).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(initial_hosts.name(), ":5001").persistent().build();
    try {
        server.start();
        server.getDatabase();
        assertThat(server.getDatabase().getGraph(), is(instanceOf(HighlyAvailableGraphDatabase.class)));
        Client client = Client.create();
        ClientResponse r = client.resource("http://localhost:7474/db/manage/server/ha").accept(APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(401, r.getStatus());
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) ClientResponse(com.sun.jersey.api.client.ClientResponse) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 75 with Client

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

the class EnterpriseServerIT method shouldAllowDisablingAuthorizationOnHAStatusEndpoints.

@Test
public void shouldAllowDisablingAuthorizationOnHAStatusEndpoints() throws Exception {
    // Given
    NeoServer server = EnterpriseServerBuilder.server().withProperty(GraphDatabaseSettings.auth_enabled.name(), "true").withProperty(HaSettings.ha_status_auth_enabled.name(), "false").usingDataDir(folder.getRoot().getAbsolutePath()).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(initial_hosts.name(), ":5001").persistent().build();
    try {
        server.start();
        server.getDatabase();
        assertThat(server.getDatabase().getGraph(), is(instanceOf(HighlyAvailableGraphDatabase.class)));
        Client client = Client.create();
        ClientResponse r = client.resource("http://localhost:7474/db/manage/server/ha").accept(APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(200, r.getStatus());
        assertThat(r.getEntity(String.class), containsString("master"));
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) ClientResponse(com.sun.jersey.api.client.ClientResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(com.sun.jersey.api.client.Client) 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