Search in sources :

Example 16 with StatusResponseHolder

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

the class OverlordResourceTestClient method resetSupervisor.

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

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

the class OverlordResourceTestClient method getSupervisorHistory.

public List<Object> getSupervisorHistory(String id) {
    try {
        StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("%ssupervisor/%s/history", getIndexerURL(), StringUtils.urlEncode(id)))), StatusResponseHandler.getInstance()).get();
        if (!response.getStatus().equals(HttpResponseStatus.OK)) {
            throw new ISE("Error while getting supervisor status, response [%s %s]", response.getStatus(), response.getContent());
        }
        List<Object> responseData = jsonMapper.readValue(response.getContent(), new TypeReference<List<Object>>() {
        });
        return responseData;
    } 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) ArrayList(java.util.ArrayList) List(java.util.List) URL(java.net.URL)

Example 18 with StatusResponseHolder

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

the class OverlordResourceTestClient method getLockedIntervals.

public Map<String, List<Interval>> getLockedIntervals(Map<String, Integer> minTaskPriority) {
    try {
        String jsonBody = jsonMapper.writeValueAsString(minTaskPriority);
        StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getIndexerURL() + "lockedIntervals")).setContent("application/json", StringUtils.toUtf8(jsonBody)), StatusResponseHandler.getInstance()).get();
        return jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, List<Interval>>>() {
        });
    } 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) Map(java.util.Map) URL(java.net.URL) Interval(org.joda.time.Interval)

Example 19 with StatusResponseHolder

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

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

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