Search in sources :

Example 41 with Request

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

the class DruidClusterAdminClient method postDynamicConfig.

private void postDynamicConfig(CoordinatorDynamicConfig coordinatorDynamicConfig) {
    ITRetryUtil.retryUntilTrue(() -> {
        try {
            String url = StringUtils.format("%s/druid/coordinator/v1/config", config.getCoordinatorUrl());
            StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)).setContent("application/json", jsonMapper.writeValueAsBytes(coordinatorDynamicConfig)), StatusResponseHandler.getInstance()).get();
            LOG.info("%s %s", response.getStatus(), response.getContent());
            // if coordinator is not leader then it will return 307 instead of 200
            return response.getStatus().equals(HttpResponseStatus.OK) || response.getStatus().equals(HttpResponseStatus.TEMPORARY_REDIRECT);
        } catch (Throwable e) {
            LOG.error(e, "Error while posting dynamic config");
            return false;
        }
    }, "Posting dynamic config after startup");
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL)

Example 42 with Request

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

the class HttpUtil method makeRequestWithExpectedStatus.

public static StatusResponseHolder makeRequestWithExpectedStatus(HttpClient httpClient, HttpMethod method, String url, @Nullable byte[] content, HttpResponseStatus expectedStatus) {
    try {
        Request request = new Request(method, new URL(url));
        if (content != null) {
            request.setContent(MediaType.APPLICATION_JSON, content);
        }
        int retryCount = 0;
        StatusResponseHolder response;
        while (true) {
            response = httpClient.go(request, RESPONSE_HANDLER).get();
            if (!response.getStatus().equals(expectedStatus)) {
                String errMsg = StringUtils.format("Error while making request to url[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
                // it can take time for the auth config to propagate, so we retry
                if (retryCount > NUM_RETRIES) {
                    throw new ISE(errMsg);
                } else {
                    LOG.error(errMsg);
                    LOG.error("retrying in 3000ms, retryCount: " + retryCount);
                    retryCount++;
                    Thread.sleep(DELAY_FOR_RETRIES_MS);
                }
            } else {
                break;
            }
        }
        return response;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL)

Example 43 with Request

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

the class ITUnionQueryTest method postEvents.

private void postEvents(int id) throws Exception {
    final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_PREFIX + id);
    eventReceiverSelector.start();
    try {
        ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
        // Access the docker VM mapped host and port instead of service announced in zookeeper
        String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
        LOG.info("Event Receiver Found at host [%s]", host);
        LOG.info("Checking worker /status/health for [%s]", host);
        ITRetryUtil.retryUntilTrue(() -> {
            try {
                StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://%s/status/health", host))), StatusResponseHandler.getInstance()).get();
                return response.getStatus().equals(HttpResponseStatus.OK);
            } catch (Throwable e) {
                LOG.error(e, "");
                return false;
            }
        }, StringUtils.format("Checking /status/health for worker [%s]", host));
        LOG.info("Finished checking worker /status/health for [%s], success", host);
        EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_PREFIX + id, jsonMapper, httpClient, smileMapper);
        client.postEventsFromFile(UNION_DATA_FILE);
    } finally {
        eventReceiverSelector.stop();
    }
}
Also used : ServerDiscoverySelector(org.apache.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(org.apache.druid.testing.clients.EventReceiverFirehoseTestClient) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL)

Example 44 with Request

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

the class ITTLSTest method makeRequest.

private StatusResponseHolder makeRequest(HttpClient httpClient, HttpMethod method, String url, byte[] content, int maxRetries) {
    try {
        Request request = new Request(method, new URL(url));
        if (content != null) {
            request.setContent(MediaType.APPLICATION_JSON, content);
        }
        int retryCount = 0;
        StatusResponseHolder response;
        while (true) {
            response = httpClient.go(request, StatusResponseHandler.getInstance()).get();
            if (!response.getStatus().equals(HttpResponseStatus.OK)) {
                String errMsg = StringUtils.format("Error while making request to url[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
                if (retryCount > maxRetries) {
                    throw new ISE(errMsg);
                } else {
                    LOG.error(errMsg);
                    LOG.error("retrying in 3000ms, retryCount: " + retryCount);
                    retryCount++;
                    Thread.sleep(3000);
                }
            } else {
                LOG.info("[%s] request to [%s] succeeded.", method, url);
                break;
            }
        }
        return response;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Example 45 with Request

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

the class ITHighAvailabilityTest method testSelfDiscovery.

private int testSelfDiscovery(Collection<DiscoveryDruidNode> nodes) throws MalformedURLException, ExecutionException, InterruptedException {
    int count = 0;
    for (DiscoveryDruidNode node : nodes) {
        final String location = StringUtils.format("http://%s:%s/status/selfDiscovered", config.isDocker() ? config.getDockerHost() : node.getDruidNode().getHost(), node.getDruidNode().getPlaintextPort());
        LOG.info("testing self discovery %s", location);
        StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(location)), StatusResponseHandler.getInstance()).get();
        LOG.info("%s responded with %s", location, response.getStatus().getCode());
        Assert.assertEquals(response.getStatus(), HttpResponseStatus.OK);
        count++;
    }
    return count;
}
Also used : DiscoveryDruidNode(org.apache.druid.discovery.DiscoveryDruidNode) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL)

Aggregations

Request (org.apache.druid.java.util.http.client.Request)148 URL (java.net.URL)129 Test (org.junit.Test)84 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)42 ISE (org.apache.druid.java.util.common.ISE)29 StringFullResponseHolder (org.apache.druid.java.util.http.client.response.StringFullResponseHolder)28 ObjectOrErrorResponseHandler (org.apache.druid.java.util.http.client.response.ObjectOrErrorResponseHandler)24 IOException (java.io.IOException)23 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)22 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)14 Map (java.util.Map)14 ExecutionException (java.util.concurrent.ExecutionException)14 InputStream (java.io.InputStream)12 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)11 RE (org.apache.druid.java.util.common.RE)10 InputStreamResponseHandler (org.apache.druid.java.util.http.client.response.InputStreamResponseHandler)10 BigEndianHeapChannelBuffer (org.jboss.netty.buffer.BigEndianHeapChannelBuffer)9 ImmutableMap (com.google.common.collect.ImmutableMap)8 HttpResponseHandler (org.apache.druid.java.util.http.client.response.HttpResponseHandler)8