use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class WorkerTaskRunnerQueryAdpaterTest method testEnableWorker.
@Test
public void testEnableWorker() throws Exception {
final URL workerUrl = new URL("https://worker-host2/druid/worker/v1/enable");
final String workerResponse = "{\"worker-host2\":\"enabled\"}";
Capture<Request> capturedRequest = getHttpClientRequestCapture(HttpResponseStatus.OK, workerResponse);
EasyMock.replay(workerTaskRunner, taskMaster, httpClient);
workerTaskRunnerQueryAdapter.enableWorker("worker-host2");
Assert.assertEquals(HttpMethod.POST, capturedRequest.getValue().getMethod());
Assert.assertEquals(workerUrl, capturedRequest.getValue().getUrl());
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class AbstractQueryResourceTestClient method query.
public List<Map<String, Object>> query(String url, QueryType query) {
try {
String expectedResponseType = this.contentTypeHeader;
Request request = new Request(HttpMethod.POST, new URL(url));
request.setContent(this.contentTypeHeader, encoderDecoderMap.get(this.contentTypeHeader).encode(query));
if (this.acceptHeader != null) {
expectedResponseType = this.acceptHeader;
request.addHeader(HttpHeaders.Names.ACCEPT, this.acceptHeader);
}
BytesFullResponseHolder response = httpClient.go(request, new BytesFullResponseHandler()).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while querying[%s] status[%s] content[%s]", url, response.getStatus(), new String(response.getContent(), StandardCharsets.UTF_8));
}
String responseType = response.getResponse().headers().get(HttpHeaders.Names.CONTENT_TYPE);
if (!expectedResponseType.equals(responseType)) {
throw new ISE("Content-Type[%s] in HTTP response does not match the expected[%s]", responseType, expectedResponseType);
}
return this.encoderDecoderMap.get(responseType).decode(response.getContent());
} 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 AbstractQueryResourceTestClient method queryAsync.
public Future<StatusResponseHolder> queryAsync(String url, QueryType query) {
try {
Request request = new Request(HttpMethod.POST, new URL(url));
request.setContent(MediaType.APPLICATION_JSON, encoderDecoderMap.get(MediaType.APPLICATION_JSON).encode(query));
return httpClient.go(request, StatusResponseHandler.getInstance());
} 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 CompactionResourceTestClient method getDataSourceCompactionConfig.
public DataSourceCompactionConfig getDataSourceCompactionConfig(String dataSource) throws Exception {
String url = StringUtils.format("%sconfig/compaction/%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(url)), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while getting compaction config status[%s] content[%s]", response.getStatus(), response.getContent());
}
return jsonMapper.readValue(response.getContent(), new TypeReference<DataSourceCompactionConfig>() {
});
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class CompactionResourceTestClient method deleteCompactionConfig.
public void deleteCompactionConfig(final String dataSource) throws Exception {
String url = StringUtils.format("%sconfig/compaction/%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.DELETE, new URL(url)), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while deleting compaction config status[%s] content[%s]", response.getStatus(), response.getContent());
}
}
Aggregations