use of org.apache.druid.java.util.http.client.response.BytesFullResponseHolder 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.response.BytesFullResponseHolder in project druid by druid-io.
the class CoordinatorPollingBasicAuthorizerCacheManager method tryFetchGroupMappingMapsFromCoordinator.
private GroupMappingAndRoleMap tryFetchGroupMappingMapsFromCoordinator(String prefix) throws Exception {
Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authorization/db/%s/cachedSerializedGroupMappingMap", prefix));
BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
// running 0.17.0+ tries to access this endpoint on an older coordinator.
if (responseHolder.getStatus().equals(HttpResponseStatus.NOT_FOUND)) {
LOG.warn("cachedSerializedGroupMappingMap is not available from the coordinator, skipping fetch of group mappings for now.");
return null;
}
byte[] groupRoleMapBytes = responseHolder.getContent();
GroupMappingAndRoleMap groupMappingAndRoleMap = objectMapper.readValue(groupRoleMapBytes, BasicAuthUtils.AUTHORIZER_GROUP_MAPPING_AND_ROLE_MAP_TYPE_REFERENCE);
if (groupMappingAndRoleMap != null && commonCacheConfig.getCacheDirectory() != null) {
writeGroupMappingMapToDisk(prefix, groupRoleMapBytes);
}
return groupMappingAndRoleMap;
}
use of org.apache.druid.java.util.http.client.response.BytesFullResponseHolder 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;
}
use of org.apache.druid.java.util.http.client.response.BytesFullResponseHolder in project druid by druid-io.
the class CoordinatorPollingBasicAuthenticatorCacheManager method tryFetchUserMapFromCoordinator.
private Map<String, BasicAuthenticatorUser> tryFetchUserMapFromCoordinator(String prefix) throws Exception {
Map<String, BasicAuthenticatorUser> userMap = null;
Request req = druidLeaderClient.makeRequest(HttpMethod.GET, StringUtils.format("/druid-ext/basic-security/authentication/db/%s/cachedSerializedUserMap", prefix));
BytesFullResponseHolder responseHolder = druidLeaderClient.go(req, new BytesFullResponseHandler());
byte[] userMapBytes = responseHolder.getContent();
if (ArrayUtils.isNotEmpty(userMapBytes)) {
userMap = objectMapper.readValue(userMapBytes, BasicAuthUtils.AUTHENTICATOR_USER_MAP_TYPE_REFERENCE);
if (userMap != null && commonCacheConfig.getCacheDirectory() != null) {
writeUserMapToDisk(prefix, userMapBytes);
}
} else {
LOG.info("Empty cached serialized user map retrieved, authenticator - %s", prefix);
}
return userMap;
}
Aggregations