private static List<LocatedSegmentDescriptor> fetchLocatedSegmentDescriptors(String address, BaseQuery query) throws IOException { final String intervals = StringUtils.join(query.getIntervals(), ","); // Comma-separated intervals without brackets final String request = String.format("http://%s/druid/v2/datasources/%s/candidates?intervals=%s", address, query.getDataSource().getNames().get(0), URLEncoder.encode(intervals, "UTF-8")); LOG.debug("sending request {} to query for segments", request); final InputStream response; try { response = DruidStorageHandlerUtils.submitRequest(DruidStorageHandler.getHttpClient(), new Request(HttpMethod.GET, new URL(request))); } catch (Exception e) { throw new IOException(org.apache.hadoop.util.StringUtils.stringifyException(e)); } // Retrieve results final List<LocatedSegmentDescriptor> segmentDescriptors; try { segmentDescriptors = DruidStorageHandlerUtils.JSON_MAPPER.readValue(response, new TypeReference<List<LocatedSegmentDescriptor>>() { }); } catch (Exception e) { response.close(); throw new IOException(org.apache.hadoop.util.StringUtils.stringifyException(e)); } return segmentDescriptors; }
@Override public String getName() { return query.getDataSource().getName(); }
.setUser2(theQuery.getDataSource().getName()) .setUser4(theQuery.getType()) .setUser5(COMMA_JOIN.join(theQuery.getIntervals()))
private String getDataSourceName(DataSource dataSource) { return Iterables.getOnlyElement(dataSource.getNames()); }
List<Rule> rules = ruleManager.getRulesWithDefault((query.getDataSource()).getName());
public VersionedIntervalTimeline<String, SegmentLoadInfo> getTimeline(DataSource dataSource) { String table = Iterables.getOnlyElement(dataSource.getNames()); synchronized (lock) { return timelines.get(table); } }
@Nullable @Override public VersionedIntervalTimeline<String, ServerSelector> getTimeline(DataSource dataSource) { String table = Iterables.getOnlyElement(dataSource.getNames()); synchronized (lock) { return timelines.get(table); } }
public static String getMetricName(DataSource dataSource) { final List<String> names = dataSource.getNames(); return names.size() == 1 ? names.get(0) : names.toString(); } }
@Override public List<String> getNames() { return query.getDataSource().getNames(); }
@Override public <T> QueryRunner<T> getQueryRunnerForIntervals(final Query<T> query, Iterable<Interval> intervals) { final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query); final Map<Integer, FireChief> partitionChiefs = chiefs.get(Iterables.getOnlyElement(query.getDataSource() .getNames())); return partitionChiefs == null ? new NoopQueryRunner<T>() : factory.getToolchest().mergeResults( factory.mergeRunners( MoreExecutors.sameThreadExecutor(), // Chaining query runners which wait on submitted chain query runners can make executor pools deadlock Iterables.transform( partitionChiefs.values(), new Function<FireChief, QueryRunner<T>>() { @Override public QueryRunner<T> apply(FireChief fireChief) { return fireChief.getQueryRunner(query); } } ) ) ); }
@Override public void registerQuery(Query query, final ListenableFuture future) { final String id = query.getId(); final List<String> datasources = query.getDataSource().getNames(); queries.put(id, future); queryDatasources.putAll(id, datasources); future.addListener( new Runnable() { @Override public void run() { queries.remove(id, future); for (String datasource : datasources) { queryDatasources.remove(id, datasource); } } }, MoreExecutors.sameThreadExecutor() ); }
/** * Authorize the query. Will return an Access object denoting whether the query is authorized or not. * * @param authenticationResult authentication result indicating the identity of the requester * * @return authorization result */ public Access authorize(final AuthenticationResult authenticationResult) { transition(State.INITIALIZED, State.AUTHORIZING); return doAuthorize( authenticationResult, AuthorizationUtils.authorizeAllResourceActions( authenticationResult, Iterables.transform( queryPlus.getQuery().getDataSource().getNames(), AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR ), authorizerMapper ) ); }
@Override public <T> QueryRunner<T> getQueryRunnerForSegments(final Query<T> query, final Iterable<SegmentDescriptor> specs) { final QueryRunnerFactory<T, Query<T>> factory = conglomerate.findFactory(query); final Map<Integer, FireChief> partitionChiefs = chiefs.get(Iterables.getOnlyElement(query.getDataSource() .getNames())); return partitionChiefs == null ? new NoopQueryRunner<T>() : factory.getToolchest().mergeResults( factory.mergeRunners( MoreExecutors.sameThreadExecutor(), Iterables.transform( specs, new Function<SegmentDescriptor, QueryRunner<T>>() { @Override public QueryRunner<T> apply(SegmentDescriptor spec) { final FireChief retVal = partitionChiefs.get(spec.getPartitionNumber()); return retVal == null ? new NoopQueryRunner<T>() : retVal.getQueryRunner(query.withQuerySegmentSpec(new SpecificSegmentSpec(spec))); } } ) ) ); }
/** * Authorize the query. Will return an Access object denoting whether the query is authorized or not. * * @param req HTTP request object of the request. If provided, the auth-related fields in the HTTP request * will be automatically set. * * @return authorization result */ public Access authorize(HttpServletRequest req) { transition(State.INITIALIZED, State.AUTHORIZING); return doAuthorize( AuthorizationUtils.authenticationResultFromRequest(req), AuthorizationUtils.authorizeAllResourceActions( req, Iterables.transform( queryPlus.getQuery().getDataSource().getNames(), AuthorizationUtils.DATASOURCE_READ_RA_GENERATOR ), authorizerMapper ) ); }
final String dataSource = Iterables.getOnlyElement(query.getDataSource().getNames());
private <T> QueryRunner<T> getQueryRunnerImpl(Query<T> query) { QueryRunner<T> queryRunner = null; final String queryDataSource = Iterables.getOnlyElement(query.getDataSource().getNames()); for (final ThreadPoolTaskRunnerWorkItem taskRunnerWorkItem : ImmutableList.copyOf(runningItems)) { final Task task = taskRunnerWorkItem.getTask(); if (task.getDataSource().equals(queryDataSource)) { final QueryRunner<T> taskQueryRunner = task.getQueryRunner(query); if (taskQueryRunner != null) { if (queryRunner == null) { queryRunner = taskQueryRunner; } else { log.makeAlert("Found too many query runners for datasource") .addData("dataSource", queryDataSource) .emit(); } } } } return new SetAndVerifyContextQueryRunner( serverConfig, queryRunner == null ? new NoopQueryRunner<T>() : queryRunner ); }
.setName(StringUtils.format("%s[%s_%s_%s]", currThreadName, query.getType(), query.getDataSource().getNames(), queryId)); if (log.isDebugEnabled()) { log.debug("Got query [%s]", query);
List<Rule> rules = ruleManager.getRulesWithDefault(Iterables.getFirst(query.getDataSource().getNames(), null));
String dataSource = Iterables.getOnlyElement(query.getDataSource().getNames());