use of org.apache.druid.java.util.common.RE 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());
}
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class OssDataSegmentPuller method getVersion.
/**
* Returns the "version" (aka last modified timestamp) of the URI
*
* @param uri The URI to check the last timestamp
* @return The time in ms of the last modification of the URI in String format
* @throws IOException
*/
@Override
public String getVersion(URI uri) throws IOException {
try {
final CloudObjectLocation coords = new CloudObjectLocation(OssUtils.checkURI(uri));
final OSSObjectSummary objectSummary = OssUtils.getSingleObjectSummary(client, coords.getBucket(), coords.getPath());
return StringUtils.format("%d", objectSummary.getLastModified().getTime());
} catch (OSSException e) {
if (OssUtils.isServiceExceptionRecoverable(e)) {
// The recoverable logic is always true for IOException, so we want to only pass IOException if it is recoverable
throw new IOE(e, "Could not fetch last modified timestamp from URI [%s]", uri);
} else {
throw new RE(e, "Error fetching last modified timestamp from URI [%s]", uri);
}
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class AzureCloudBlobIterator method fetchNextBatch.
private void fetchNextBatch() {
try {
log.debug("fetching up to %s resources in container '%s' with prefix '%s'", maxListingLength, currentContainer, currentPrefix);
result = AzureUtils.retryAzureOperation(() -> storage.listBlobsWithPrefixInContainerSegmented(currentContainer, currentPrefix, continuationToken, maxListingLength), config.getMaxTries());
continuationToken = result.getContinuationToken();
blobItemIterator = result.getResults().iterator();
} catch (Exception e) {
throw new RE(e, "Failed to get blob item from Azure container[%s], prefix[%s]. Error: %s", currentContainer, currentPrefix, e.getMessage());
}
}
use of org.apache.druid.java.util.common.RE in project druid by druid-io.
the class ProcCgroupDiscoverer method discover.
/**
* Gets the path in the virtual FS for the given cgroup (cpu, mem, etc.).
*
* The method first retrieves 2 paths:
* - The cgroup virtual FS mount point by calling /proc/mounts. This is usually like '/sys/fs/cgroup/cpu'.
* - The heirarchy path by calling /proc/[pid]/cgroup. In Docker this can look like '/docker/4b053f1267369a19dcdcb293e1b4d6b71fd0f26bf7711d589f19d48af92e6278'
*
* The method then tries to find the final virtual FS path by contenating the 2 paths first, and then falling back
* to the root virtual FS path. In this example, the method tries
* '/sys/fs/cgroup/cpu/docker/4b053f1267369a19dcdcb293e1b4d6b71fd0f26bf7711d589f19d48af92e6278' and then falls back
* to '/sys/fs/cgroup/cpu'.
*
* An exception is thrown if neither path exists.
* @param cgroup The cgroup.
* @return the virtual FS path.
*/
@Override
public Path discover(final String cgroup) {
Preconditions.checkNotNull(cgroup, "cgroup required");
final File procMounts = new File(procDir, "mounts");
final File pidCgroups = new File(procDir, "cgroup");
final PidCgroupEntry pidCgroupsEntry = getCgroupEntry(pidCgroups, cgroup);
final ProcMountsEntry procMountsEntry = getMountEntry(procMounts, cgroup);
final File cgroupDir = new File(procMountsEntry.path.toString(), pidCgroupsEntry.path.toString());
if (cgroupDir.exists() && cgroupDir.isDirectory()) {
return cgroupDir.toPath();
}
// Check the root /sys/fs directory if there isn't a cgroup path specific one
// This happens with certain OSes
final File fallbackCgroupDir = procMountsEntry.path.toFile();
if (fallbackCgroupDir.exists() && fallbackCgroupDir.isDirectory()) {
return fallbackCgroupDir.toPath();
}
throw new RE("No cgroup directory located at [%s] or [%s]", cgroupDir, fallbackCgroupDir);
}
use of org.apache.druid.java.util.common.RE in project hive by apache.
the class DruidQueryRecordReader method createQueryResultsIterator.
public JsonParserIterator<R> createQueryResultsIterator() {
JsonParserIterator<R> iterator = null;
String filterExprSerialized = conf.get(TableScanDesc.FILTER_EXPR_CONF_STR);
if (filterExprSerialized != null) {
ExprNodeGenericFuncDesc filterExpr = SerializationUtilities.deserializeExpression(filterExprSerialized);
query = DruidStorageHandlerUtils.addDynamicFilters(query, filterExpr, conf, true);
}
// Result type definition used to read the rows, this is query dependent.
JavaType resultsType = getResultTypeDef();
boolean initialized = false;
int currentLocationIndex = 0;
Exception ex = null;
while (!initialized && currentLocationIndex < locations.length) {
String address = locations[currentLocationIndex++];
if (Strings.isNullOrEmpty(address)) {
throw new RE("can not fetch results from empty or null host value");
}
// Execute query
LOG.debug("Retrieving data from druid location[{}] using query:[{}] ", address, query);
try {
Request request = DruidStorageHandlerUtils.createSmileRequest(address, query);
Future<InputStream> inputStreamFuture = httpClient.go(request, new InputStreamResponseHandler());
// noinspection unchecked
iterator = new JsonParserIterator(smileMapper, resultsType, inputStreamFuture, request.getUrl().toString(), query);
iterator.init();
initialized = true;
} catch (Exception e) {
if (iterator != null) {
// We got exception while querying results from this host.
CloseQuietly.close(iterator);
}
LOG.error("Failure getting results for query[{}] from host[{}] because of [{}]", query, address, e.getMessage());
if (ex == null) {
ex = e;
} else {
ex.addSuppressed(e);
}
}
}
if (!initialized) {
throw new RE(ex, "Failure getting results for query[%s] from locations[%s] because of [%s]", query, locations, Objects.requireNonNull(ex).getMessage());
}
return iterator;
}
Aggregations