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());
}
}
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>>() {
});
}
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);
}
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);
}
}
}
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);
}
}
}
Aggregations