Search in sources :

Example 61 with StatusResponseHolder

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);
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) TimeoutException(io.netty.handler.timeout.TimeoutException)

Example 62 with StatusResponseHolder

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);
    }
}
Also used : StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) List(java.util.List) ISE(org.apache.druid.java.util.common.ISE) HashMap(java.util.HashMap) Map(java.util.Map) QueryWithResults(org.apache.druid.testing.utils.QueryWithResults)

Example 63 with StatusResponseHolder

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());
    }
}
Also used : SqlQuery(org.apache.druid.sql.http.SqlQuery) RE(org.apache.druid.java.util.common.RE) HttpResponseStatus(org.jboss.netty.handler.codec.http.HttpResponseStatus) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) Test(org.testng.annotations.Test)

Example 64 with StatusResponseHolder

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);
}
Also used : StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder)

Example 65 with StatusResponseHolder

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));
}
Also used : StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder)

Aggregations

StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)69 URL (java.net.URL)50 Request (org.apache.druid.java.util.http.client.Request)42 ISE (org.apache.druid.java.util.common.ISE)33 ExecutionException (java.util.concurrent.ExecutionException)13 Test (org.junit.Test)12 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)10 Map (java.util.Map)8 ArrayList (java.util.ArrayList)6 TypeReference (com.fasterxml.jackson.core.type.TypeReference)5 IOException (java.io.IOException)5 RE (org.apache.druid.java.util.common.RE)5 ChannelException (org.jboss.netty.channel.ChannelException)5 List (java.util.List)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3