Search in sources :

Example 76 with Request

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

the class OverlordResourceTestClient method submitTask.

public String submitTask(final String task) {
    try {
        return RetryUtils.retry(() -> {
            StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getIndexerURL() + "task")).setContent("application/json", StringUtils.toUtf8(task)), StatusResponseHandler.getInstance()).get();
            if (!response.getStatus().equals(HttpResponseStatus.OK)) {
                throw new ISE("Error while submitting task to indexer response [%s %s]", response.getStatus(), response.getContent());
            }
            Map<String, String> responseData = jsonMapper.readValue(response.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_STRING);
            String taskID = responseData.get("task");
            LOG.debug("Submitted task with TaskID[%s]", taskID);
            return taskID;
        }, Predicates.alwaysTrue(), 5);
    } 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 77 with Request

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

the class OverlordResourceTestClient method statsSupervisor.

public void statsSupervisor(String id) {
    try {
        StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("%ssupervisor/%s/stats", getIndexerURL(), StringUtils.urlEncode(id)))), StatusResponseHandler.getInstance()).get();
        if (!response.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while stats supervisor, response [%s %s]", response.getStatus(), response.getContent());
        }
        LOG.debug("stats supervisor with id[%s]", id);
    } catch (ISE e) {
        throw e;
    } 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 78 with Request

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

the class DruidClusterAdminClient method waitUntilInstanceReady.

private void waitUntilInstanceReady(final String host) {
    ITRetryUtil.retryUntilTrue(() -> {
        try {
            StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("%s/status/health", host))), StatusResponseHandler.getInstance()).get();
            LOG.info("%s %s", response.getStatus(), response.getContent());
            return response.getStatus().equals(HttpResponseStatus.OK);
        } catch (Throwable e) {
            // 
            if (e.getCause() instanceof ChannelException) {
                Throwable channelException = e.getCause();
                if (channelException.getCause() instanceof ClosedChannelException) {
                    LOG.error("Channel Closed");
                } else if ("Channel disconnected".equals(channelException.getMessage())) {
                    // log message only
                    LOG.error("Channel disconnected");
                } else {
                    // log stack trace for unknown exception
                    LOG.error(e, "Error while waiting for [%s] to be ready", host);
                }
            } else {
                // log stack trace for unknown exception
                LOG.error(e, "Error while waiting for [%s] to be ready", host);
            }
            return false;
        }
    }, "Waiting for instance to be ready: [" + host + "]");
}
Also used : ClosedChannelException(java.nio.channels.ClosedChannelException) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL) ChannelException(org.jboss.netty.channel.ChannelException) ClosedChannelException(java.nio.channels.ClosedChannelException)

Example 79 with Request

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

the class AbstractQueryResourceTestClient method cancelQuery.

public HttpResponseStatus cancelQuery(String url, long timeoutMs) {
    try {
        Request request = new Request(HttpMethod.DELETE, new URL(url));
        Future<StatusResponseHolder> future = httpClient.go(request, StatusResponseHandler.getInstance());
        StatusResponseHolder responseHolder = future.get(timeoutMs, TimeUnit.MILLISECONDS);
        return responseHolder.getStatus();
    } 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) URL(java.net.URL) IOException(java.io.IOException)

Example 80 with Request

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

the class CompactionResourceTestClient method updateCompactionTaskSlot.

public void updateCompactionTaskSlot(Double compactionTaskSlotRatio, Integer maxCompactionTaskSlots, Boolean useAutoScaleSlots) throws Exception {
    String url;
    if (useAutoScaleSlots == null) {
        url = StringUtils.format("%sconfig/compaction/taskslots?ratio=%s&max=%s", getCoordinatorURL(), StringUtils.urlEncode(compactionTaskSlotRatio.toString()), StringUtils.urlEncode(maxCompactionTaskSlots.toString()));
    } else {
        url = StringUtils.format("%sconfig/compaction/taskslots?ratio=%s&max=%s&useAutoScaleSlots=%s", getCoordinatorURL(), StringUtils.urlEncode(compactionTaskSlotRatio.toString()), StringUtils.urlEncode(maxCompactionTaskSlots.toString()), StringUtils.urlEncode(useAutoScaleSlots.toString()));
    }
    StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)), responseHandler).get();
    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
        throw new ISE("Error while updating compaction task slot status[%s] content[%s]", response.getStatus(), response.getContent());
    }
}
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)

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