use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class DirectDruidClient method cancelQuery.
private void cancelQuery(Query<T> query, String cancelUrl) {
Runnable cancelRunnable = () -> {
try {
Future<StatusResponseHolder> responseFuture = httpClient.go(new Request(HttpMethod.DELETE, new URL(cancelUrl)).setContent(objectMapper.writeValueAsBytes(query)).setHeader(HttpHeaders.Names.CONTENT_TYPE, isSmile ? SmileMediaTypes.APPLICATION_JACKSON_SMILE : MediaType.APPLICATION_JSON), StatusResponseHandler.getInstance(), Duration.standardSeconds(1));
Runnable checkRunnable = () -> {
try {
if (!responseFuture.isDone()) {
log.error("Error cancelling query[%s]", query);
}
StatusResponseHolder response = responseFuture.get();
if (response.getStatus().getCode() >= 500) {
log.error("Error cancelling query[%s]: queriable node returned status[%d] [%s].", query, response.getStatus().getCode(), response.getStatus().getReasonPhrase());
}
} catch (ExecutionException | InterruptedException e) {
log.error(e, "Error cancelling query[%s]", query);
}
};
queryCancellationExecutor.schedule(checkRunnable, 5, TimeUnit.SECONDS);
} catch (IOException e) {
log.error(e, "Error cancelling query[%s]", query);
}
};
queryCancellationExecutor.submit(cancelRunnable);
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class CommonCacheNotifier method start.
public void start() {
exec.submit(() -> {
while (!Thread.interrupted()) {
try {
LOG.debug(callerName + ":Waiting for cache update notification");
Pair<String, byte[]> update = updateQueue.take();
String authorizer = update.lhs;
byte[] serializedMap = update.rhs;
BasicAuthDBConfig authorizerConfig = itemConfigMap.get(update.lhs);
if (!authorizerConfig.isEnableCacheNotifications()) {
continue;
}
LOG.debug(callerName + ":Sending cache update notifications");
// Best effort, if a notification fails, the remote node will eventually poll to update its state
// We wait for responses however, to avoid flooding remote nodes with notifications.
List<ListenableFuture<StatusResponseHolder>> futures = sendUpdate(authorizer, serializedMap);
try {
List<StatusResponseHolder> responses = Futures.allAsList(futures).get(authorizerConfig.getCacheNotificationTimeout(), TimeUnit.MILLISECONDS);
for (StatusResponseHolder response : responses) {
LOG.debug(callerName + ":Got status: " + response.getStatus());
}
} catch (Exception e) {
LOG.makeAlert(e, callerName + ":Failed to get response for cache notification.").emit();
}
LOG.debug(callerName + ":Received responses for cache update notifications.");
} catch (InterruptedException e) {
LOG.noStackTrace().info(e, "%s: Interrupted while handling updates for cachedUserMaps.", callerName);
} catch (Throwable t) {
LOG.makeAlert(t, callerName + ":Error occured while handling updates for cachedUserMaps.").emit();
}
}
});
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class CommonCacheNotifier method sendUpdate.
private List<ListenableFuture<StatusResponseHolder>> sendUpdate(String updatedAuthenticatorPrefix, byte[] serializedEntity) {
List<ListenableFuture<StatusResponseHolder>> futures = new ArrayList<>();
for (NodeRole nodeRole : NODE_TYPES) {
DruidNodeDiscovery nodeDiscovery = discoveryProvider.getForNodeRole(nodeRole);
Collection<DiscoveryDruidNode> nodes = nodeDiscovery.getAllNodes();
for (DiscoveryDruidNode node : nodes) {
URL listenerURL = getListenerURL(node.getDruidNode(), StringUtils.format(baseUrl, StringUtils.urlEncode(updatedAuthenticatorPrefix)));
// best effort, if this fails, remote node will poll and pick up the update eventually
Request req = new Request(HttpMethod.POST, listenerURL);
req.setContent(MediaType.APPLICATION_JSON, serializedEntity);
BasicAuthDBConfig itemConfig = itemConfigMap.get(updatedAuthenticatorPrefix);
ListenableFuture<StatusResponseHolder> future = httpClient.go(req, new ResponseHandler(), Duration.millis(itemConfig.getCacheNotificationTimeout()));
futures.add(future);
}
}
return futures;
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class WorkerHolder method assignTask.
public boolean assignTask(Task task) {
if (disabled.get()) {
log.info("Received task[%s] assignment on worker[%s] when worker is disabled.", task.getId(), worker.getHost());
return false;
}
URL url = TaskRunnerUtils.makeWorkerURL(worker, "/druid-internal/v1/worker/assignTask");
int numTries = config.getAssignRequestMaxRetries();
try {
return RetryUtils.retry(() -> {
try {
final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, url).addHeader(HttpHeaders.Names.CONTENT_TYPE, SmileMediaTypes.APPLICATION_JACKSON_SMILE).setContent(smileMapper.writeValueAsBytes(task)), StatusResponseHandler.getInstance(), config.getAssignRequestHttpTimeout().toStandardDuration()).get();
if (response.getStatus().getCode() == 200) {
return true;
} else {
throw new RE("Failed to assign task[%s] to worker[%s]. Response Code[%s] and Message[%s]. Retrying...", task.getId(), worker.getHost(), response.getStatus().getCode(), response.getContent());
}
} catch (ExecutionException ex) {
throw new RE(ex, "Request to assign task[%s] to worker[%s] failed. Retrying...", task.getId(), worker.getHost());
}
}, e -> !(e instanceof InterruptedException), numTries);
} catch (Exception ex) {
log.info("Not sure whether task[%s] was successfully assigned to worker[%s].", task.getId(), worker.getHost());
return true;
}
}
Aggregations