Search in sources :

Example 11 with StatusResponseHolder

use of com.metamx.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) {
    if (!started) {
        log.info("This TaskRunner is stopped. 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 = makeWorkerURL(zkWorker.getWorker(), String.format("/task/%s/shutdown", taskId));
            final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, url), RESPONSE_HANDLER, 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(io.druid.java.util.common.RE) Request(com.metamx.http.client.Request) StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) URL(java.net.URL) KeeperException(org.apache.zookeeper.KeeperException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 12 with StatusResponseHolder

use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.

the class CoordinatorResourceTestClient method getLoadStatus.

private Map<String, Integer> getLoadStatus() {
    Map<String, Integer> status = null;
    try {
        StatusResponseHolder response = makeRequest(HttpMethod.GET, getLoadStatusURL());
        status = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, Integer>>() {
        });
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return status;
}
Also used : StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 13 with StatusResponseHolder

use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.

the class CoordinatorResourceTestClient method getSegmentIntervals.

// return a list of the segment dates for the specified datasource
public ArrayList<String> getSegmentIntervals(final String dataSource) throws Exception {
    ArrayList<String> segments = null;
    try {
        StatusResponseHolder response = makeRequest(HttpMethod.GET, getIntervalsURL(dataSource));
        segments = jsonMapper.readValue(response.getContent(), new TypeReference<ArrayList<String>>() {
        });
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    return segments;
}
Also used : StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 14 with StatusResponseHolder

use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.

the class OverlordResourceTestClient method shutDownTask.

public Map<String, String> shutDownTask(String taskID) {
    try {
        StatusResponseHolder response = makeRequest(HttpMethod.POST, String.format("%stask/%s/shutdown", getIndexerURL(), URLEncoder.encode(taskID, "UTF-8")));
        LOG.info("Shutdown Task %s response %s", taskID, response.getContent());
        return jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, String>>() {
        });
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) Map(java.util.Map)

Example 15 with StatusResponseHolder

use of com.metamx.http.client.response.StatusResponseHolder in project druid by druid-io.

the class OverlordResourceTestClient method getTasks.

private List<TaskResponseObject> getTasks(String identifier) {
    try {
        StatusResponseHolder response = makeRequest(HttpMethod.GET, String.format("%s%s", getIndexerURL(), identifier));
        LOG.info("Tasks %s response %s", identifier, response.getContent());
        return jsonMapper.readValue(response.getContent(), new TypeReference<List<TaskResponseObject>>() {
        });
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : StatusResponseHolder(com.metamx.http.client.response.StatusResponseHolder) List(java.util.List)

Aggregations

StatusResponseHolder (com.metamx.http.client.response.StatusResponseHolder)15 Request (com.metamx.http.client.Request)10 URL (java.net.URL)6 StatusResponseHandler (com.metamx.http.client.response.StatusResponseHandler)5 IOException (java.io.IOException)5 Map (java.util.Map)5 Test (org.junit.Test)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 ISE (io.druid.java.util.common.ISE)3 HttpResponseHandler (com.metamx.http.client.response.HttpResponseHandler)2 RetryPolicyFactory (io.druid.indexing.common.RetryPolicyFactory)2 NoopTask (io.druid.indexing.common.task.NoopTask)2 Task (io.druid.indexing.common.task.Task)2 RE (io.druid.java.util.common.RE)2 QueryInterruptedException (io.druid.query.QueryInterruptedException)2 HashMap (java.util.HashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 EasyMock.anyObject (org.easymock.EasyMock.anyObject)2 JavaType (com.fasterxml.jackson.databind.JavaType)1 TypeFactory (com.fasterxml.jackson.databind.type.TypeFactory)1