use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class OverlordResourceTestClient method submitTask.
public String submitTask(final String task) {
try {
return RetryUtils.retry(() -> {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getIndexerURL() + "task")).setContent("application/json", StringUtils.toUtf8(task)), StatusResponseHandler.getInstance()).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while submitting task to indexer response [%s %s]", response.getStatus(), response.getContent());
}
Map<String, String> responseData = jsonMapper.readValue(response.getContent(), JacksonUtils.TYPE_REFERENCE_MAP_STRING_STRING);
String taskID = responseData.get("task");
LOG.debug("Submitted task with TaskID[%s]", taskID);
return taskID;
}, Predicates.alwaysTrue(), 5);
} 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 OverlordResourceTestClient method statsSupervisor.
public void statsSupervisor(String id) {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("%ssupervisor/%s/stats", getIndexerURL(), StringUtils.urlEncode(id)))), StatusResponseHandler.getInstance()).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while stats supervisor, response [%s %s]", response.getStatus(), response.getContent());
}
LOG.debug("stats supervisor with id[%s]", id);
} catch (ISE e) {
throw e;
} 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 DruidClusterAdminClient method waitUntilInstanceReady.
private void waitUntilInstanceReady(final String host) {
ITRetryUtil.retryUntilTrue(() -> {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("%s/status/health", host))), StatusResponseHandler.getInstance()).get();
LOG.info("%s %s", response.getStatus(), response.getContent());
return response.getStatus().equals(HttpResponseStatus.OK);
} catch (Throwable e) {
//
if (e.getCause() instanceof ChannelException) {
Throwable channelException = e.getCause();
if (channelException.getCause() instanceof ClosedChannelException) {
LOG.error("Channel Closed");
} else if ("Channel disconnected".equals(channelException.getMessage())) {
// log message only
LOG.error("Channel disconnected");
} else {
// log stack trace for unknown exception
LOG.error(e, "Error while waiting for [%s] to be ready", host);
}
} else {
// log stack trace for unknown exception
LOG.error(e, "Error while waiting for [%s] to be ready", host);
}
return false;
}
}, "Waiting for instance to be ready: [" + host + "]");
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class AbstractQueryResourceTestClient method cancelQuery.
public HttpResponseStatus cancelQuery(String url, long timeoutMs) {
try {
Request request = new Request(HttpMethod.DELETE, new URL(url));
Future<StatusResponseHolder> future = httpClient.go(request, StatusResponseHandler.getInstance());
StatusResponseHolder responseHolder = future.get(timeoutMs, TimeUnit.MILLISECONDS);
return responseHolder.getStatus();
} 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 CompactionResourceTestClient method updateCompactionTaskSlot.
public void updateCompactionTaskSlot(Double compactionTaskSlotRatio, Integer maxCompactionTaskSlots, Boolean useAutoScaleSlots) throws Exception {
String url;
if (useAutoScaleSlots == null) {
url = StringUtils.format("%sconfig/compaction/taskslots?ratio=%s&max=%s", getCoordinatorURL(), StringUtils.urlEncode(compactionTaskSlotRatio.toString()), StringUtils.urlEncode(maxCompactionTaskSlots.toString()));
} else {
url = StringUtils.format("%sconfig/compaction/taskslots?ratio=%s&max=%s&useAutoScaleSlots=%s", getCoordinatorURL(), StringUtils.urlEncode(compactionTaskSlotRatio.toString()), StringUtils.urlEncode(maxCompactionTaskSlots.toString()), StringUtils.urlEncode(useAutoScaleSlots.toString()));
}
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while updating compaction task slot status[%s] content[%s]", response.getStatus(), response.getContent());
}
}
Aggregations