use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class DruidClusterAdminClient method postDynamicConfig.
private void postDynamicConfig(CoordinatorDynamicConfig coordinatorDynamicConfig) {
ITRetryUtil.retryUntilTrue(() -> {
try {
String url = StringUtils.format("%s/druid/coordinator/v1/config", config.getCoordinatorUrl());
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)).setContent("application/json", jsonMapper.writeValueAsBytes(coordinatorDynamicConfig)), StatusResponseHandler.getInstance()).get();
LOG.info("%s %s", response.getStatus(), response.getContent());
// if coordinator is not leader then it will return 307 instead of 200
return response.getStatus().equals(HttpResponseStatus.OK) || response.getStatus().equals(HttpResponseStatus.TEMPORARY_REDIRECT);
} catch (Throwable e) {
LOG.error(e, "Error while posting dynamic config");
return false;
}
}, "Posting dynamic config after startup");
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class HttpUtil method makeRequestWithExpectedStatus.
public static StatusResponseHolder makeRequestWithExpectedStatus(HttpClient httpClient, HttpMethod method, String url, @Nullable byte[] content, HttpResponseStatus expectedStatus) {
try {
Request request = new Request(method, new URL(url));
if (content != null) {
request.setContent(MediaType.APPLICATION_JSON, content);
}
int retryCount = 0;
StatusResponseHolder response;
while (true) {
response = httpClient.go(request, RESPONSE_HANDLER).get();
if (!response.getStatus().equals(expectedStatus)) {
String errMsg = StringUtils.format("Error while making request to url[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
// it can take time for the auth config to propagate, so we retry
if (retryCount > NUM_RETRIES) {
throw new ISE(errMsg);
} else {
LOG.error(errMsg);
LOG.error("retrying in 3000ms, retryCount: " + retryCount);
retryCount++;
Thread.sleep(DELAY_FOR_RETRIES_MS);
}
} else {
break;
}
}
return response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class ITUnionQueryTest method postEvents.
private void postEvents(int id) throws Exception {
final ServerDiscoverySelector eventReceiverSelector = factory.createSelector(EVENT_RECEIVER_SERVICE_PREFIX + id);
eventReceiverSelector.start();
try {
ServerDiscoveryUtil.waitUntilInstanceReady(eventReceiverSelector, "Event Receiver");
// Access the docker VM mapped host and port instead of service announced in zookeeper
String host = config.getMiddleManagerHost() + ":" + eventReceiverSelector.pick().getPort();
LOG.info("Event Receiver Found at host [%s]", host);
LOG.info("Checking worker /status/health for [%s]", host);
ITRetryUtil.retryUntilTrue(() -> {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(StringUtils.format("https://%s/status/health", host))), StatusResponseHandler.getInstance()).get();
return response.getStatus().equals(HttpResponseStatus.OK);
} catch (Throwable e) {
LOG.error(e, "");
return false;
}
}, StringUtils.format("Checking /status/health for worker [%s]", host));
LOG.info("Finished checking worker /status/health for [%s], success", host);
EventReceiverFirehoseTestClient client = new EventReceiverFirehoseTestClient(host, EVENT_RECEIVER_SERVICE_PREFIX + id, jsonMapper, httpClient, smileMapper);
client.postEventsFromFile(UNION_DATA_FILE);
} finally {
eventReceiverSelector.stop();
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class ITTLSTest method makeRequest.
private StatusResponseHolder makeRequest(HttpClient httpClient, HttpMethod method, String url, byte[] content, int maxRetries) {
try {
Request request = new Request(method, new URL(url));
if (content != null) {
request.setContent(MediaType.APPLICATION_JSON, content);
}
int retryCount = 0;
StatusResponseHolder response;
while (true) {
response = httpClient.go(request, StatusResponseHandler.getInstance()).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
String errMsg = StringUtils.format("Error while making request to url[%s] status[%s] content[%s]", url, response.getStatus(), response.getContent());
if (retryCount > maxRetries) {
throw new ISE(errMsg);
} else {
LOG.error(errMsg);
LOG.error("retrying in 3000ms, retryCount: " + retryCount);
retryCount++;
Thread.sleep(3000);
}
} else {
LOG.info("[%s] request to [%s] succeeded.", method, url);
break;
}
}
return response;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class ITHighAvailabilityTest method testSelfDiscovery.
private int testSelfDiscovery(Collection<DiscoveryDruidNode> nodes) throws MalformedURLException, ExecutionException, InterruptedException {
int count = 0;
for (DiscoveryDruidNode node : nodes) {
final String location = StringUtils.format("http://%s:%s/status/selfDiscovered", config.isDocker() ? config.getDockerHost() : node.getDruidNode().getHost(), node.getDruidNode().getPlaintextPort());
LOG.info("testing self discovery %s", location);
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(location)), StatusResponseHandler.getInstance()).get();
LOG.info("%s responded with %s", location, response.getStatus().getCode());
Assert.assertEquals(response.getStatus(), HttpResponseStatus.OK);
count++;
}
return count;
}
Aggregations