Search in sources :

Example 21 with HttpClient

use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.

the class ITTLSTest method checkAccessWithWrongRoot.

@Test
public void checkAccessWithWrongRoot() {
    LOG.info("---------Testing TLS resource access when client certificate is signed by a non-trusted root CA---------");
    HttpClient wrongRootClient = makeCustomHttpClient("client_tls/client_another_root.jks", "druid_another_root");
    checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getCoordinatorTLSUrl());
    checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getOverlordTLSUrl());
    checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getBrokerTLSUrl());
    checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getHistoricalTLSUrl());
    checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getRouterTLSUrl());
    checkFailedAccessWrongRoot(wrongRootClient, HttpMethod.GET, config.getPermissiveRouterTLSUrl());
    makeRequest(wrongRootClient, HttpMethod.GET, config.getNoClientAuthRouterTLSUrl() + "/status", null);
}
Also used : HttpClient(org.apache.druid.java.util.http.client.HttpClient) CredentialedHttpClient(org.apache.druid.java.util.http.client.CredentialedHttpClient) Test(org.testng.annotations.Test)

Example 22 with HttpClient

use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.

the class ITTLSTest method testTLSNodeAccessWithIntermediate.

@Test
public void testTLSNodeAccessWithIntermediate() {
    LOG.info("---------Testing TLS resource access with 3-part cert chain---------");
    HttpClient intermediateCertClient = makeCustomHttpClient("client_tls/intermediate_ca_client.jks", "intermediate_ca_client");
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getCoordinatorTLSUrl() + "/status", null);
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getOverlordTLSUrl() + "/status", null);
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getBrokerTLSUrl() + "/status", null);
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getHistoricalTLSUrl() + "/status", null);
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getRouterTLSUrl() + "/status", null);
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getPermissiveRouterTLSUrl() + "/status", null);
    makeRequest(intermediateCertClient, HttpMethod.GET, config.getNoClientAuthRouterTLSUrl() + "/status", null);
}
Also used : HttpClient(org.apache.druid.java.util.http.client.HttpClient) CredentialedHttpClient(org.apache.druid.java.util.http.client.CredentialedHttpClient) Test(org.testng.annotations.Test)

Example 23 with HttpClient

use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.

the class IndexTaskClientTest method dontRetryIfNotFoundWithCorrectTaskId.

@Test
public void dontRetryIfNotFoundWithCorrectTaskId() {
    final String taskId = "taskId";
    final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
    final DefaultHttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
    response.headers().add(ChatHandlerResource.TASK_ID_HEADER, taskId);
    EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(response, StandardCharsets.UTF_8).addChunk("Error")))).times(1);
    EasyMock.replay(httpClient);
    try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
        final IOException e = Assert.assertThrows(IOException.class, () -> indexTaskClient.submitRequestWithEmptyContent(taskId, HttpMethod.GET, "test", null, false));
        Assert.assertEquals("Received server error with status [404 Not Found]; first 1KB of body: Error", e.getMessage());
    }
    EasyMock.verify(httpClient);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpClient(org.apache.druid.java.util.http.client.HttpClient) IOException(java.io.IOException) Test(org.junit.Test)

Example 24 with HttpClient

use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.

the class IndexTaskClientTest method retryOnServerError.

@Test
public void retryOnServerError() throws IOException {
    final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
    EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR), StandardCharsets.UTF_8).addChunk("Error")))).times(2);
    EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK), StandardCharsets.UTF_8)))).once();
    EasyMock.replay(httpClient);
    try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
        final StringFullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent("taskId", HttpMethod.GET, "test", null, true);
        Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
    }
    EasyMock.verify(httpClient);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpClient(org.apache.druid.java.util.http.client.HttpClient) Test(org.junit.Test)

Example 25 with HttpClient

use of org.apache.druid.java.util.http.client.HttpClient in project druid by druid-io.

the class IndexTaskClientTest method retryIfNotFoundWithIncorrectTaskId.

@Test
public void retryIfNotFoundWithIncorrectTaskId() throws IOException {
    final HttpClient httpClient = EasyMock.createMock(HttpClient.class);
    final String taskId = "taskId";
    final String incorrectTaskId = "incorrectTaskId";
    final DefaultHttpResponse incorrectResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.NOT_FOUND);
    incorrectResponse.headers().add(ChatHandlerResource.TASK_ID_HEADER, incorrectTaskId);
    final DefaultHttpResponse correctResponse = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
    correctResponse.headers().add(ChatHandlerResource.TASK_ID_HEADER, taskId);
    EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.error(new StringFullResponseHolder(incorrectResponse, StandardCharsets.UTF_8)))).times(2);
    EasyMock.expect(httpClient.go(EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(Futures.immediateFuture(Either.value(new StringFullResponseHolder(correctResponse, StandardCharsets.UTF_8)))).once();
    EasyMock.replay(httpClient);
    try (IndexTaskClient indexTaskClient = buildIndexTaskClient(httpClient, id -> TaskLocation.create(id, 8000, -1))) {
        final StringFullResponseHolder response = indexTaskClient.submitRequestWithEmptyContent(taskId, HttpMethod.GET, "test", null, true);
        Assert.assertEquals(HttpResponseStatus.OK, response.getStatus());
    }
    EasyMock.verify(httpClient);
}
Also used : StringFullResponseHolder(org.apache.druid.java.util.http.client.response.StringFullResponseHolder) DefaultHttpResponse(org.jboss.netty.handler.codec.http.DefaultHttpResponse) HttpClient(org.apache.druid.java.util.http.client.HttpClient) Test(org.junit.Test)

Aggregations

HttpClient (org.apache.druid.java.util.http.client.HttpClient)36 Test (org.junit.Test)16 CredentialedHttpClient (org.apache.druid.java.util.http.client.CredentialedHttpClient)15 ArrayList (java.util.ArrayList)10 Test (org.testng.annotations.Test)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)9 List (java.util.List)9 CuratorFramework (org.apache.curator.framework.CuratorFramework)9 ZkPathsConfig (org.apache.druid.server.initialization.ZkPathsConfig)9 ImmutableList (com.google.common.collect.ImmutableList)8 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)8 AtomicReference (java.util.concurrent.atomic.AtomicReference)8 DruidNodeDiscoveryProvider (org.apache.druid.discovery.DruidNodeDiscoveryProvider)8 TaskRunnerListener (org.apache.druid.indexing.overlord.TaskRunnerListener)8 TaskStorage (org.apache.druid.indexing.overlord.TaskStorage)8 HttpRemoteTaskRunnerConfig (org.apache.druid.indexing.overlord.config.HttpRemoteTaskRunnerConfig)8 Worker (org.apache.druid.indexing.worker.Worker)8 IndexerZkConfig (org.apache.druid.server.initialization.IndexerZkConfig)8 DiscoveryDruidNode (org.apache.druid.discovery.DiscoveryDruidNode)7 WorkerNodeService (org.apache.druid.discovery.WorkerNodeService)7