Search in sources :

Example 56 with StatusResponseHolder

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

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

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

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

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

the class RemoteTaskRunner method shutdown.

/**
 * Finds the worker running the task and forwards the shutdown signal to the worker.
 *
 * @param taskId - task id to shutdown
 */
@Override
public void shutdown(final String taskId, String reason) {
    log.info("Shutdown [%s] because: [%s]", taskId, reason);
    if (!lifecycleLock.awaitStarted(1, TimeUnit.SECONDS)) {
        log.info("This TaskRunner is stopped or not yet started. Ignoring shutdown command for task: %s", taskId);
    } else if (pendingTasks.remove(taskId) != null) {
        pendingTaskPayloads.remove(taskId);
        log.info("Removed task from pending queue: %s", taskId);
    } else if (completeTasks.containsKey(taskId)) {
        cleanup(taskId);
    } else {
        final ZkWorker zkWorker = findWorkerRunningTask(taskId);
        if (zkWorker == null) {
            log.info("Can't shutdown! No worker running task %s", taskId);
            return;
        }
        URL url = null;
        try {
            url = TaskRunnerUtils.makeWorkerURL(zkWorker.getWorker(), "/druid/worker/v1/task/%s/shutdown", taskId);
            final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, url), StatusResponseHandler.getInstance(), shutdownTimeout).get();
            log.info("Sent shutdown message to worker: %s, status %s, response: %s", zkWorker.getWorker().getHost(), response.getStatus(), response.getContent());
            if (!HttpResponseStatus.OK.equals(response.getStatus())) {
                log.error("Shutdown failed for %s! Are you sure the task was running?", taskId);
            }
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RE(e, "Interrupted posting shutdown to [%s] for task [%s]", url, taskId);
        } catch (Exception e) {
            throw new RE(e, "Error in handling post to [%s] for task [%s]", zkWorker.getWorker().getHost(), taskId);
        }
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

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