use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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.response.StatusResponseHolder in project druid by druid-io.
the class AbstractAuthConfigurationTest method verifySystemSchemaQueryBase.
protected void verifySystemSchemaQueryBase(HttpClient client, String query, List<Map<String, Object>> expectedResults, boolean isServerQuery) throws Exception {
StatusResponseHolder responseHolder = makeSQLQueryRequest(client, query, HttpResponseStatus.OK);
String content = responseHolder.getContent();
List<Map<String, Object>> responseMap = jsonMapper.readValue(content, SYS_SCHEMA_RESULTS_TYPE_REFERENCE);
if (isServerQuery) {
responseMap = getServersWithoutCurrentSize(responseMap);
}
Assert.assertEquals(responseMap, expectedResults);
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class AbstractAuthConfigurationTest method verifyMaliciousUser.
protected void verifyMaliciousUser() {
String maliciousUsername = "<script>alert('hello')</script>";
HttpClient maliciousClient = new CredentialedHttpClient(new BasicCredentials(maliciousUsername, "noPass"), httpClient);
StatusResponseHolder responseHolder = HttpUtil.makeRequestWithExpectedStatus(maliciousClient, HttpMethod.GET, config.getBrokerUrl() + "/status", null, HttpResponseStatus.UNAUTHORIZED);
String responseContent = responseHolder.getContent();
Assert.assertTrue(responseContent.contains("<tr><th>MESSAGE:</th><td>Unauthorized</td></tr>"));
Assert.assertFalse(responseContent.contains(maliciousUsername));
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder 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.response.StatusResponseHolder in project druid by druid-io.
the class ITSqlCancelTest method testCancelValidQuery.
@Test
public void testCancelValidQuery() throws Exception {
final String queryId = "sql-cancel-test";
final List<Future<StatusResponseHolder>> queryResponseFutures = new ArrayList<>();
for (int i = 0; i < NUM_QUERIES; i++) {
queryResponseFutures.add(sqlClient.queryAsync(sqlHelper.getQueryURL(config.getRouterUrl()), new SqlQuery(QUERY, null, false, false, false, ImmutableMap.of(BaseQuery.SQL_QUERY_ID, queryId), null)));
}
// Wait until the sqlLifecycle is authorized and registered
Thread.sleep(1000);
final HttpResponseStatus responseStatus = sqlClient.cancelQuery(sqlHelper.getCancelUrl(config.getRouterUrl(), queryId), 1000);
if (!responseStatus.equals(HttpResponseStatus.ACCEPTED)) {
throw new RE("Failed to cancel query [%s]. Response code was [%s]", queryId, responseStatus);
}
for (Future<StatusResponseHolder> queryResponseFuture : queryResponseFutures) {
final StatusResponseHolder queryResponse = queryResponseFuture.get(1, TimeUnit.SECONDS);
if (!queryResponse.getStatus().equals(HttpResponseStatus.INTERNAL_SERVER_ERROR)) {
throw new ISE("Query is not canceled after cancel request");
}
QueryException queryException = jsonMapper.readValue(queryResponse.getContent(), QueryException.class);
if (!QueryInterruptedException.QUERY_CANCELLED.equals(queryException.getErrorCode())) {
throw new ISE("Expected error code [%s], actual [%s]", QueryInterruptedException.QUERY_CANCELLED, queryException.getErrorCode());
}
}
}
Aggregations