Search in sources :

Example 1 with TimeoutException

use of io.netty.handler.timeout.TimeoutException in project druid by druid-io.

the class WorkerTaskRunnerQueryAdapter method sendRequestToWorker.

private void sendRequestToWorker(String workerHost, WorkerTaskRunner.ActionType action) {
    WorkerTaskRunner workerTaskRunner = getWorkerTaskRunner();
    if (workerTaskRunner == null) {
        throw new RE("Task Runner does not support enable/disable worker actions");
    }
    Optional<ImmutableWorkerInfo> workerInfo = Iterables.tryFind(workerTaskRunner.getWorkers(), entry -> entry.getWorker().getHost().equals(workerHost));
    if (!workerInfo.isPresent()) {
        throw new RE("Worker on host %s does not exists", workerHost);
    }
    String actionName = WorkerTaskRunner.ActionType.ENABLE.equals(action) ? "enable" : "disable";
    final URL workerUrl = TaskRunnerUtils.makeWorkerURL(workerInfo.get().getWorker(), "/druid/worker/v1/%s", actionName);
    try {
        final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, workerUrl), StatusResponseHandler.getInstance()).get();
        log.info("Sent %s action request to worker: %s, status: %s, response: %s", action, workerHost, response.getStatus(), response.getContent());
        if (!HttpResponseStatus.OK.equals(response.getStatus())) {
            throw new RE("Action [%s] failed for worker [%s] with status %s(%s)", action, workerHost, response.getStatus().getCode(), response.getStatus().getReasonPhrase());
        }
    } catch (ExecutionException | InterruptedException | TimeoutException e) {
        Throwables.propagate(e);
    }
}
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) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) TimeoutException(io.netty.handler.timeout.TimeoutException)

Aggregations

TimeoutException (io.netty.handler.timeout.TimeoutException)1 URL (java.net.URL)1 ExecutionException (java.util.concurrent.ExecutionException)1 RE (org.apache.druid.java.util.common.RE)1 Request (org.apache.druid.java.util.http.client.Request)1 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)1