Search in sources :

Example 51 with StatusResponseHolder

use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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 52 with StatusResponseHolder

use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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 53 with StatusResponseHolder

use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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 54 with StatusResponseHolder

use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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 55 with StatusResponseHolder

use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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

StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)69 URL (java.net.URL)50 Request (org.apache.druid.java.util.http.client.Request)42 ISE (org.apache.druid.java.util.common.ISE)33 ExecutionException (java.util.concurrent.ExecutionException)13 Test (org.junit.Test)12 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)10 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 IOException (java.io.IOException)5 RE (org.apache.druid.java.util.common.RE)5 ChannelException (org.jboss.netty.channel.ChannelException)5 List (java.util.List)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3