use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class CompactionResourceTestClient method submitCompactionConfig.
public void submitCompactionConfig(final DataSourceCompactionConfig dataSourceCompactionConfig) throws Exception {
String url = StringUtils.format("%sconfig/compaction", getCoordinatorURL());
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(url)).setContent("application/json", jsonMapper.writeValueAsBytes(dataSourceCompactionConfig)), responseHandler).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while submiting compaction config status[%s] content[%s]", response.getStatus(), response.getContent());
}
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class CompactionResourceTestClient method getCompactionProgress.
public Map<String, String> getCompactionProgress(String dataSource) throws Exception {
String url = StringUtils.format("%scompaction/progress?dataSource=%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 progress status[%s] content[%s]", response.getStatus(), response.getContent());
}
return jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, String>>() {
});
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class CompactionResourceTestClient method getCompactionStatus.
public Map<String, String> getCompactionStatus(String dataSource) throws Exception {
String url = StringUtils.format("%scompaction/status?dataSource=%s", getCoordinatorURL(), StringUtils.urlEncode(dataSource));
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.GET, new URL(url)), responseHandler).get();
if (response.getStatus().equals(HttpResponseStatus.NOT_FOUND)) {
return null;
} else if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while getting compaction status status[%s] content[%s]", response.getStatus(), response.getContent());
}
Map<String, List<Map<String, String>>> latestSnapshots = jsonMapper.readValue(response.getContent(), new TypeReference<Map<String, List<Map<String, String>>>>() {
});
return latestSnapshots.get("latestStatus").get(0);
}
use of org.apache.druid.java.util.http.client.Request in project druid by druid-io.
the class EventReceiverFirehoseTestClient method postEvents.
/**
* post events from the collection and return the count of events accepted
*
* @param events Collection of events to be posted
*
* @return
*/
public int postEvents(Collection<Map<String, Object>> events, ObjectMapper objectMapper, String mediaType) throws InterruptedException {
int retryCount = 0;
while (true) {
try {
StatusResponseHolder response = httpClient.go(new Request(HttpMethod.POST, new URL(getURL())).setContent(mediaType, objectMapper.writeValueAsBytes(events)), StatusResponseHandler.getInstance()).get();
if (!response.getStatus().equals(HttpResponseStatus.OK)) {
throw new ISE("Error while posting events to url[%s] status[%s] content[%s]", getURL(), response.getStatus(), response.getContent());
}
Map<String, Integer> responseData = objectMapper.readValue(response.getContent(), new TypeReference<Map<String, Integer>>() {
});
return responseData.get("eventCount");
}// adding retries to flaky tests using channels
catch (ExecutionException e) {
if (retryCount > NUM_RETRIES) {
// giving up now
throw new RuntimeException(e);
} else {
LOG.info(e, "received exception, sleeping and retrying");
retryCount++;
Thread.sleep(DELAY_FOR_RETRIES_MS);
}
} 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 CoordinatorPollingBasicAuthorizerCacheManager method tryFetchUserMapsFromCoordinator.
private UserAndRoleMap tryFetchUserMapsFromCoordinator(String prefix) throws Exception {
Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authorization/db/%s/cachedSerializedUserMap", prefix));
BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
byte[] userRoleMapBytes = responseHolder.getContent();
UserAndRoleMap userAndRoleMap = objectMapper.readValue(userRoleMapBytes, BasicAuthUtils.AUTHORIZER_USER_AND_ROLE_MAP_TYPE_REFERENCE);
if (userAndRoleMap != null && commonCacheConfig.getCacheDirectory() != null) {
writeUserMapToDisk(prefix, userRoleMapBytes);
}
return userAndRoleMap;
}
Aggregations