Search in sources :

Example 16 with RE

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());
        }
    }
}
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)

Example 17 with RE

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);
        }
    }
}
Also used : OSSObjectSummary(com.aliyun.oss.model.OSSObjectSummary) RE(org.apache.druid.java.util.common.RE) CloudObjectLocation(org.apache.druid.data.input.impl.CloudObjectLocation) OSSException(com.aliyun.oss.OSSException) IOE(org.apache.druid.java.util.common.IOE)

Example 18 with RE

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());
    }
}
Also used : RE(org.apache.druid.java.util.common.RE) NoSuchElementException(java.util.NoSuchElementException)

Example 19 with RE

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);
}
Also used : RE(org.apache.druid.java.util.common.RE) File(java.io.File)

Example 20 with RE

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;
}
Also used : InputStream(java.io.InputStream) Request(org.apache.druid.java.util.http.client.Request) ExprNodeGenericFuncDesc(org.apache.hadoop.hive.ql.plan.ExprNodeGenericFuncDesc) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JavaType(com.fasterxml.jackson.databind.JavaType) RE(org.apache.druid.java.util.common.RE) InputStreamResponseHandler(org.apache.druid.java.util.http.client.response.InputStreamResponseHandler)

Aggregations

RE (org.apache.druid.java.util.common.RE)46 IOException (java.io.IOException)11 Request (org.apache.druid.java.util.http.client.Request)10 URL (java.net.URL)8 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 InputStream (java.io.InputStream)5 ExecutionException (java.util.concurrent.ExecutionException)5 ISE (org.apache.druid.java.util.common.ISE)5 Map (java.util.Map)4 StatusResponseHolder (org.apache.druid.java.util.http.client.response.StatusResponseHolder)4 JavaType (com.fasterxml.jackson.databind.JavaType)3 HashMap (java.util.HashMap)3 DataSegment (org.apache.druid.timeline.DataSegment)3 OSSException (com.aliyun.oss.OSSException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 NamedType (com.fasterxml.jackson.databind.jsontype.NamedType)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ApiException (io.kubernetes.client.openapi.ApiException)2 File (java.io.File)2