Search in sources :

Example 21 with StatusResponseHolder

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();
    }
}
Also used : ServerDiscoverySelector(org.apache.druid.curator.discovery.ServerDiscoverySelector) EventReceiverFirehoseTestClient(org.apache.druid.testing.clients.EventReceiverFirehoseTestClient) Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) URL(java.net.URL)

Example 22 with StatusResponseHolder

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);
}
Also used : StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 23 with StatusResponseHolder

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

Example 24 with StatusResponseHolder

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);
    }
}
Also used : Request(org.apache.druid.java.util.http.client.Request) StatusResponseHolder(org.apache.druid.java.util.http.client.response.StatusResponseHolder) ISE(org.apache.druid.java.util.common.ISE) URL(java.net.URL) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException)

Example 25 with StatusResponseHolder

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

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