Search in sources :

Example 1 with InputStreamFullResponseHandler

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

the class SystemSchema method getThingsFromLeaderNode.

public static <T> JsonParserIterator<T> getThingsFromLeaderNode(String query, TypeReference<T> typeRef, DruidLeaderClient leaderClient, ObjectMapper jsonMapper) {
    Request request;
    InputStreamFullResponseHolder responseHolder;
    try {
        request = leaderClient.makeRequest(HttpMethod.GET, query);
        responseHolder = leaderClient.go(request, new InputStreamFullResponseHandler());
        if (responseHolder.getStatus().getCode() != HttpServletResponse.SC_OK) {
            throw new RE("Failed to talk to leader node at [%s]. Error code[%d], description[%s].", query, responseHolder.getStatus().getCode(), responseHolder.getStatus().getReasonPhrase());
        }
    } catch (IOException | InterruptedException e) {
        throw new RuntimeException(e);
    }
    final JavaType javaType = jsonMapper.getTypeFactory().constructType(typeRef);
    return new JsonParserIterator<>(javaType, Futures.immediateFuture(responseHolder.getContent()), request.getUrl().toString(), null, request.getUrl().getHost(), jsonMapper);
}
Also used : InputStreamFullResponseHandler(org.apache.druid.java.util.http.client.response.InputStreamFullResponseHandler) JavaType(com.fasterxml.jackson.databind.JavaType) InputStreamFullResponseHolder(org.apache.druid.java.util.http.client.response.InputStreamFullResponseHolder) RE(org.apache.druid.java.util.common.RE) JsonParserIterator(org.apache.druid.client.JsonParserIterator) Request(org.apache.druid.java.util.http.client.Request) IOException(java.io.IOException)

Aggregations

JavaType (com.fasterxml.jackson.databind.JavaType)1 IOException (java.io.IOException)1 JsonParserIterator (org.apache.druid.client.JsonParserIterator)1 RE (org.apache.druid.java.util.common.RE)1 Request (org.apache.druid.java.util.http.client.Request)1 InputStreamFullResponseHandler (org.apache.druid.java.util.http.client.response.InputStreamFullResponseHandler)1 InputStreamFullResponseHolder (org.apache.druid.java.util.http.client.response.InputStreamFullResponseHolder)1