use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class WorkerTaskRunnerQueryAdapter method sendRequestToWorker.
private void sendRequestToWorker(String workerHost, WorkerTaskRunner.ActionType action) {
WorkerTaskRunner workerTaskRunner = getWorkerTaskRunner();
if (workerTaskRunner == null) {
throw new RE("Task Runner does not support enable/disable worker actions");
}
Optional<ImmutableWorkerInfo> workerInfo = Iterables.tryFind(workerTaskRunner.getWorkers(), entry -> entry.getWorker().getHost().equals(workerHost));
if (!workerInfo.isPresent()) {
throw new RE("Worker on host %s does not exists", workerHost);
}
String actionName = WorkerTaskRunner.ActionType.ENABLE.equals(action) ? "enable" : "disable";
final URL workerUrl = TaskRunnerUtils.makeWorkerURL(workerInfo.get().getWorker(), "/druid/worker/v1/%s", actionName);
try {
final StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, workerUrl), StatusResponseHandler.getInstance()).get();
log.info("Sent %s action request to worker: %s, status: %s, response: %s", action, workerHost, response.getStatus(), response.getContent());
if (!HttpResponseStatus.OK.equals(response.getStatus())) {
throw new RE("Action [%s] failed for worker [%s] with status %s(%s)", action, workerHost, response.getStatus().getCode(), response.getStatus().getReasonPhrase());
}
} catch (ExecutionException | InterruptedException | TimeoutException e) {
Throwables.propagate(e);
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class ITQueryRetryTestOnMissingSegments method testQueries.
private void testQueries(List<QueryWithResults> queries, Expectation expectation) throws Exception {
int querySuccess = 0;
int queryFailure = 0;
int resultMatches = 0;
int resultMismatches = 0;
for (int i = 0; i < TIMES_TO_RUN; i++) {
for (QueryWithResults queryWithResult : queries) {
final StatusResponseHolder responseHolder = queryClient.queryAsync(queryHelper.getQueryURL(config.getBrokerUrl()), queryWithResult.getQuery()).get();
if (responseHolder.getStatus().getCode() == HttpResponseStatus.OK.getCode()) {
querySuccess++;
List<Map<String, Object>> result = jsonMapper.readValue(responseHolder.getContent(), new TypeReference<List<Map<String, Object>>>() {
});
if (!QueryResultVerifier.compareResults(result, queryWithResult.getExpectedResults(), queryWithResult.getFieldsToTest())) {
if (expectation != Expectation.INCORRECT_RESULT) {
throw new ISE("Incorrect query results for query %s \n expectedResults: %s \n actualResults : %s", queryWithResult.getQuery(), jsonMapper.writeValueAsString(queryWithResult.getExpectedResults()), jsonMapper.writeValueAsString(result));
} else {
resultMismatches++;
}
} else {
resultMatches++;
}
} else if (responseHolder.getStatus().getCode() == HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode() && expectation == Expectation.QUERY_FAILURE) {
final Map<String, Object> response = jsonMapper.readValue(responseHolder.getContent(), Map.class);
final String errorMessage = (String) response.get("errorMessage");
Assert.assertNotNull(errorMessage, "errorMessage");
Assert.assertTrue(errorMessage.contains("No results found for segments"));
queryFailure++;
} else {
throw new ISE("Unexpected failure, code: [%s], content: [%s]", responseHolder.getStatus(), responseHolder.getContent());
}
}
}
switch(expectation) {
case ALL_SUCCESS:
Assert.assertEquals(querySuccess, ITQueryRetryTestOnMissingSegments.TIMES_TO_RUN);
Assert.assertEquals(queryFailure, 0);
Assert.assertEquals(resultMatches, ITQueryRetryTestOnMissingSegments.TIMES_TO_RUN);
Assert.assertEquals(resultMismatches, 0);
break;
case QUERY_FAILURE:
Assert.assertTrue(querySuccess > 0, "At least one query is expected to succeed.");
Assert.assertTrue(queryFailure > 0, "At least one query is expected to fail.");
Assert.assertEquals(querySuccess, resultMatches);
Assert.assertEquals(resultMismatches, 0);
break;
case INCORRECT_RESULT:
Assert.assertEquals(querySuccess, ITQueryRetryTestOnMissingSegments.TIMES_TO_RUN);
Assert.assertEquals(queryFailure, 0);
Assert.assertTrue(resultMatches > 0, "At least one query is expected to return correct results.");
Assert.assertTrue(resultMismatches > 0, "At least one query is expected to return less results.");
break;
default:
throw new ISE("Unknown expectation[%s]", expectation);
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class ITSqlCancelTest method testCancelInvalidQuery.
@Test
public void testCancelInvalidQuery() throws Exception {
final Future<StatusResponseHolder> queryResponseFuture = sqlClient.queryAsync(sqlHelper.getQueryURL(config.getRouterUrl()), new SqlQuery(QUERY, null, false, false, false, ImmutableMap.of(BaseQuery.SQL_QUERY_ID, "validId"), null));
// Wait until the sqlLifecycle is authorized and registered
Thread.sleep(1000);
final HttpResponseStatus responseStatus = sqlClient.cancelQuery(sqlHelper.getCancelUrl(config.getRouterUrl(), "invalidId"), 1000);
if (!responseStatus.equals(HttpResponseStatus.NOT_FOUND)) {
throw new RE("Expected http response [%s], actual response [%s]", HttpResponseStatus.NOT_FOUND, responseStatus);
}
final StatusResponseHolder queryResponse = queryResponseFuture.get(30, TimeUnit.SECONDS);
if (!queryResponse.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Cancel request failed with status[%s] and content[%s]", queryResponse.getStatus(), queryResponse.getContent());
}
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class AbstractAuthConfigurationTest method verifySystemSchemaQueryFailure.
protected void verifySystemSchemaQueryFailure(HttpClient client, String query, HttpResponseStatus expectedErrorStatus, String expectedErrorMessage) throws Exception {
StatusResponseHolder responseHolder = makeSQLQueryRequest(client, query, expectedErrorStatus);
Assert.assertEquals(responseHolder.getStatus(), expectedErrorStatus);
Assert.assertEquals(responseHolder.getContent(), expectedErrorMessage);
}
use of org.apache.druid.java.util.http.client.response.StatusResponseHolder in project druid by druid-io.
the class AbstractAuthConfigurationTest method checkLoadStatusSingle.
protected void checkLoadStatusSingle(HttpClient httpClient, String baseUrl) throws Exception {
StatusResponseHolder holder = HttpUtil.makeRequest(httpClient, HttpMethod.GET, baseUrl + "/druid-ext/basic-security/authentication/loadStatus", null);
String content = holder.getContent();
Map<String, Boolean> loadStatus = jsonMapper.readValue(content, JacksonUtils.TYPE_REFERENCE_MAP_STRING_BOOLEAN);
String authenticatorName = getAuthenticatorName();
Assert.assertNotNull(loadStatus.get(authenticatorName));
Assert.assertTrue(loadStatus.get(authenticatorName));
holder = HttpUtil.makeRequest(httpClient, HttpMethod.GET, baseUrl + "/druid-ext/basic-security/authorization/loadStatus", null);
content = holder.getContent();
loadStatus = jsonMapper.readValue(content, JacksonUtils.TYPE_REFERENCE_MAP_STRING_BOOLEAN);
String authorizerName = getAuthorizerName();
Assert.assertNotNull(loadStatus.get(authorizerName));
Assert.assertTrue(loadStatus.get(authorizerName));
}
Aggregations