Search in sources :

Example 81 with Request

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

the class CompactionResourceTestClient method submitCompactionConfig.

public void submitCompactionConfig(final DataSourceCompactionConfig dataSourceCompactionConfig) throws Exception {
    String url = StringUtils.format("%sconfig/compaction", getCoordinatorURL());
    StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)).setContent("application/json", jsonMapper.writeValueAsBytes(dataSourceCompactionConfig)), responseHandler).get();
    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
        throw new ISE("Error while submiting compaction config 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)

Example 82 with Request

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

the class CompactionResourceTestClient method getCompactionProgress.

public Map<String, String> getCompactionProgress(String dataSource) throws Exception {
    String url = StringUtils.format("%scompaction/progress?dataSource=%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
    StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(url)), responseHandler).get();
    if (!response.getStatus().equals(HttpResponseStatus.OK)) {
        throw new ISE("Error while getting compaction progress status[%s] content[%s]", response.getStatus(), response.getContent());
    }
    return jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, String>>() {
    });
}
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) Map(java.util.Map) URL(java.net.URL)

Example 83 with Request

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

the class CompactionResourceTestClient method getCompactionStatus.

public Map<String, String> getCompactionStatus(String dataSource) throws Exception {
    String url = StringUtils.format("%scompaction/status?dataSource=%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
    StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(url)), responseHandler).get();
    if (response.getStatus().equals(HttpResponseStatus.NOT_FOUND)) {
        return null;
    } else if (!response.getStatus().equals(HttpResponseStatus.OK)) {
        throw new ISE("Error while getting compaction status status[%s] content[%s]", response.getStatus(), response.getContent());
    }
    Map<String, List<Map<String, String>>> latestSnapshots = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, List<Map<String, String>>>>() {
    });
    return latestSnapshots.get("latestStatus").get(0);
}
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) List(java.util.List) Map(java.util.Map) URL(java.net.URL)

Example 84 with Request

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

the class EventReceiverFirehoseTestClient method postEvents.

/**
 * post events from the collection and return the count of events accepted
 *
 * @param events Collection of events to be posted
 *
 * @return
 */
public int postEvents(Collection<Map<String, Object>> events, ObjectMapper objectMapper, String mediaType) throws InterruptedException {
    int retryCount = 0;
    while (true) {
        try {
            StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getURL())).setContent(mediaType, objectMapper.writeValueAsBytes(events)), StatusResponseHandler.getInstance()).get();
            if (!response.getStatus().equals(HttpResponseStatus.OK)) {
                throw new ISE("Error while posting events to url[%s] status[%s] content[%s]", getURL(), response.getStatus(), response.getContent());
            }
            Map<String, Integer> responseData = objectMapper.readValue(response.getContent(), new TypeReference<Map<String, Integer>>() {
            });
            return responseData.get("eventCount");
        }// adding retries to flaky tests using channels
         catch (ExecutionException e) {
            if (retryCount > NUM_RETRIES) {
                // giving up now
                throw new RuntimeException(e);
            } else {
                LOG.info(e, "received exception, sleeping and retrying");
                retryCount++;
                Thread.sleep(DELAY_FOR_RETRIES_MS);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) URL(java.net.URL) ExecutionException(java.util.concurrent.ExecutionException) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map)

Example 85 with Request

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

the class CoordinatorPollingBasicAuthorizerCacheManager method tryFetchUserMapsFromCoordinator.

private UserAndRoleMap tryFetchUserMapsFromCoordinator(String prefix) throws Exception {
    Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authorization/db/%s/cachedSerializedUserMap", prefix));
    BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
    byte[] userRoleMapBytes = responseHolder.getContent();
    UserAndRoleMap userAndRoleMap = objectMapper.readValue(userRoleMapBytes, BasicAuthUtils.AUTHORIZER_USER_AND_ROLE_MAP_TYPE_REFERENCE);
    if (userAndRoleMap != null && commonCacheConfig.getCacheDirectory() != null) {
        writeUserMapToDisk(prefix, userRoleMapBytes);
    }
    return userAndRoleMap;
}
Also used : UserAndRoleMap(org.apache.druid.security.basic.authorization.entity.UserAndRoleMap) BytesFullResponseHolder(org.apache.druid.java.util.http.client.response.BytesFullResponseHolder) Request(org.apache.druid.java.util.http.client.Request) BytesFullResponseHandler(org.apache.druid.java.util.http.client.response.BytesFullResponseHandler)

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