Search in sources :

Example 6 with AuthConfig

use of org.apache.druid.server.security.AuthConfig in project druid by druid-io.

the class QueryResourceTest method testQueryTimeoutException.

@Test
public void testQueryTimeoutException() throws Exception {
    final QuerySegmentWalker timeoutSegmentWalker = new QuerySegmentWalker() {

        @Override
        public <T> QueryRunner<T> getQueryRunnerForIntervals(Query<T> query, Iterable<Interval> intervals) {
            throw new QueryTimeoutException();
        }

        @Override
        public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs) {
            return getQueryRunnerForIntervals(null, null);
        }
    };
    final QueryResource timeoutQueryResource = new QueryResource(new QueryLifecycleFactory(WAREHOUSE, timeoutSegmentWalker, new DefaultGenericQueryMetricsFactory(), new NoopServiceEmitter(), testRequestLogger, new AuthConfig(), AuthTestUtils.TEST_AUTHORIZER_MAPPER, Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))), jsonMapper, jsonMapper, queryScheduler, new AuthConfig(), null, ResponseContextConfig.newConfig(true), DRUID_NODE);
    expectPermissiveHappyPathAuth();
    Response response = timeoutQueryResource.doPost(new ByteArrayInputStream(SIMPLE_TIMESERIES_QUERY.getBytes(StandardCharsets.UTF_8)), null, /*pretty*/
    testServletRequest);
    Assert.assertNotNull(response);
    Assert.assertEquals(QueryTimeoutException.STATUS_CODE, response.getStatus());
    QueryTimeoutException ex;
    try {
        ex = jsonMapper.readValue((byte[]) response.getEntity(), QueryTimeoutException.class);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    Assert.assertEquals("Query Timed Out!", ex.getMessage());
    Assert.assertEquals(QueryTimeoutException.ERROR_CODE, ex.getErrorCode());
    Assert.assertEquals(1, timeoutQueryResource.getTimedOutQueryCount());
}
Also used : Query(org.apache.druid.query.Query) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) AuthConfig(org.apache.druid.server.security.AuthConfig) IOException(java.io.IOException) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) Response(javax.ws.rs.core.Response) QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) Test(org.junit.Test)

Example 7 with AuthConfig

use of org.apache.druid.server.security.AuthConfig in project druid by druid-io.

the class AbstractParallelIndexSupervisorTaskTest method prepareObjectMapper.

public void prepareObjectMapper(ObjectMapper objectMapper, IndexIO indexIO) {
    final TaskConfig taskConfig = new TaskConfig(null, null, null, null, null, false, null, null, null, false, false, TaskConfig.BATCH_PROCESSING_MODE_DEFAULT.name());
    objectMapper.setInjectableValues(new InjectableValues.Std().addValue(ExprMacroTable.class, LookupEnabledTestExprMacroTable.INSTANCE).addValue(IndexIO.class, indexIO).addValue(ObjectMapper.class, objectMapper).addValue(ChatHandlerProvider.class, new NoopChatHandlerProvider()).addValue(AuthConfig.class, new AuthConfig()).addValue(AuthorizerMapper.class, null).addValue(RowIngestionMetersFactory.class, new DropwizardRowIngestionMetersFactory()).addValue(DataSegment.PruneSpecsHolder.class, DataSegment.PruneSpecsHolder.DEFAULT).addValue(AuthorizerMapper.class, new AuthorizerMapper(ImmutableMap.of())).addValue(AppenderatorsManager.class, TestUtils.APPENDERATORS_MANAGER).addValue(LocalDataSegmentPuller.class, new LocalDataSegmentPuller()).addValue(CoordinatorClient.class, coordinatorClient).addValue(SegmentCacheManagerFactory.class, new SegmentCacheManagerFactory(objectMapper)).addValue(RetryPolicyFactory.class, new RetryPolicyFactory(new RetryPolicyConfig())).addValue(TaskConfig.class, taskConfig));
    objectMapper.registerSubtypes(new NamedType(ParallelIndexSupervisorTask.class, ParallelIndexSupervisorTask.TYPE), new NamedType(CompactionTask.CompactionTuningConfig.class, CompactionTask.CompactionTuningConfig.TYPE), new NamedType(SinglePhaseSubTask.class, SinglePhaseSubTask.TYPE), new NamedType(PartialHashSegmentGenerateTask.class, PartialHashSegmentGenerateTask.TYPE), new NamedType(PartialRangeSegmentGenerateTask.class, PartialRangeSegmentGenerateTask.TYPE), new NamedType(PartialGenericSegmentMergeTask.class, PartialGenericSegmentMergeTask.TYPE), new NamedType(PartialDimensionDistributionTask.class, PartialDimensionDistributionTask.TYPE), new NamedType(PartialDimensionCardinalityTask.class, PartialDimensionCardinalityTask.TYPE));
}
Also used : RetryPolicyConfig(org.apache.druid.indexing.common.RetryPolicyConfig) NoopChatHandlerProvider(org.apache.druid.segment.realtime.firehose.NoopChatHandlerProvider) NamedType(com.fasterxml.jackson.databind.jsontype.NamedType) SegmentCacheManagerFactory(org.apache.druid.indexing.common.SegmentCacheManagerFactory) TaskConfig(org.apache.druid.indexing.common.config.TaskConfig) AuthConfig(org.apache.druid.server.security.AuthConfig) DataSegment(org.apache.druid.timeline.DataSegment) RetryPolicyFactory(org.apache.druid.indexing.common.RetryPolicyFactory) LookupEnabledTestExprMacroTable(org.apache.druid.query.expression.LookupEnabledTestExprMacroTable) ExprMacroTable(org.apache.druid.math.expr.ExprMacroTable) DropwizardRowIngestionMetersFactory(org.apache.druid.indexing.common.stats.DropwizardRowIngestionMetersFactory) LocalDataSegmentPuller(org.apache.druid.segment.loading.LocalDataSegmentPuller) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RowIngestionMetersFactory(org.apache.druid.segment.incremental.RowIngestionMetersFactory) DropwizardRowIngestionMetersFactory(org.apache.druid.indexing.common.stats.DropwizardRowIngestionMetersFactory)

Example 8 with AuthConfig

use of org.apache.druid.server.security.AuthConfig in project druid by druid-io.

the class QueryResourceTest method testGoodQueryWithQueryConfigDoesNotOverrideQueryContext.

@Test
public void testGoodQueryWithQueryConfigDoesNotOverrideQueryContext() throws IOException {
    String overrideConfigKey = "priority";
    String overrideConfigValue = "678";
    DefaultQueryConfig overrideConfig = new DefaultQueryConfig(ImmutableMap.of(overrideConfigKey, overrideConfigValue));
    queryResource = new QueryResource(new QueryLifecycleFactory(WAREHOUSE, TEST_SEGMENT_WALKER, new DefaultGenericQueryMetricsFactory(), new NoopServiceEmitter(), testRequestLogger, new AuthConfig(), AuthTestUtils.TEST_AUTHORIZER_MAPPER, Suppliers.ofInstance(overrideConfig)), jsonMapper, smileMapper, queryScheduler, new AuthConfig(), null, ResponseContextConfig.newConfig(true), DRUID_NODE);
    expectPermissiveHappyPathAuth();
    Response response = queryResource.doPost(// SIMPLE_TIMESERIES_QUERY_LOW_PRIORITY context has overrideConfigKey with value of -1
    new ByteArrayInputStream(SIMPLE_TIMESERIES_QUERY_LOW_PRIORITY.getBytes(StandardCharsets.UTF_8)), null, /*pretty*/
    testServletRequest);
    Assert.assertNotNull(response);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ((StreamingOutput) response.getEntity()).write(baos);
    final List<Result<TimeBoundaryResultValue>> responses = jsonMapper.readValue(baos.toByteArray(), new TypeReference<List<Result<TimeBoundaryResultValue>>>() {
    });
    Assert.assertNotNull(response);
    Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Assert.assertEquals(0, responses.size());
    Assert.assertEquals(1, testRequestLogger.getNativeQuerylogs().size());
    Assert.assertNotNull(testRequestLogger.getNativeQuerylogs().get(0).getQuery());
    Assert.assertNotNull(testRequestLogger.getNativeQuerylogs().get(0).getQuery().getContext());
    Assert.assertTrue(testRequestLogger.getNativeQuerylogs().get(0).getQuery().getContext().containsKey(overrideConfigKey));
    Assert.assertEquals(-1, testRequestLogger.getNativeQuerylogs().get(0).getQuery().getContext().get(overrideConfigKey));
}
Also used : NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuthConfig(org.apache.druid.server.security.AuthConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) Result(org.apache.druid.query.Result) Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) TimeBoundaryResultValue(org.apache.druid.query.timeboundary.TimeBoundaryResultValue) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) Test(org.junit.Test)

Example 9 with AuthConfig

use of org.apache.druid.server.security.AuthConfig in project druid by druid-io.

the class QueryResourceTest method testGoodQueryWithQueryConfigOverrideDefault.

@Test
public void testGoodQueryWithQueryConfigOverrideDefault() throws IOException {
    String overrideConfigKey = "priority";
    String overrideConfigValue = "678";
    DefaultQueryConfig overrideConfig = new DefaultQueryConfig(ImmutableMap.of(overrideConfigKey, overrideConfigValue));
    queryResource = new QueryResource(new QueryLifecycleFactory(WAREHOUSE, TEST_SEGMENT_WALKER, new DefaultGenericQueryMetricsFactory(), new NoopServiceEmitter(), testRequestLogger, new AuthConfig(), AuthTestUtils.TEST_AUTHORIZER_MAPPER, Suppliers.ofInstance(overrideConfig)), jsonMapper, smileMapper, queryScheduler, new AuthConfig(), null, ResponseContextConfig.newConfig(true), DRUID_NODE);
    expectPermissiveHappyPathAuth();
    Response response = queryResource.doPost(new ByteArrayInputStream(SIMPLE_TIMESERIES_QUERY.getBytes(StandardCharsets.UTF_8)), null, /*pretty*/
    testServletRequest);
    Assert.assertNotNull(response);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ((StreamingOutput) response.getEntity()).write(baos);
    final List<Result<TimeBoundaryResultValue>> responses = jsonMapper.readValue(baos.toByteArray(), new TypeReference<List<Result<TimeBoundaryResultValue>>>() {
    });
    Assert.assertNotNull(response);
    Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
    Assert.assertEquals(0, responses.size());
    Assert.assertEquals(1, testRequestLogger.getNativeQuerylogs().size());
    Assert.assertNotNull(testRequestLogger.getNativeQuerylogs().get(0).getQuery());
    Assert.assertNotNull(testRequestLogger.getNativeQuerylogs().get(0).getQuery().getContext());
    Assert.assertTrue(testRequestLogger.getNativeQuerylogs().get(0).getQuery().getContext().containsKey(overrideConfigKey));
    Assert.assertEquals(overrideConfigValue, testRequestLogger.getNativeQuerylogs().get(0).getQuery().getContext().get(overrideConfigKey));
}
Also used : NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) StreamingOutput(javax.ws.rs.core.StreamingOutput) AuthConfig(org.apache.druid.server.security.AuthConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) Result(org.apache.druid.query.Result) Response(javax.ws.rs.core.Response) ByteArrayInputStream(java.io.ByteArrayInputStream) TimeBoundaryResultValue(org.apache.druid.query.timeboundary.TimeBoundaryResultValue) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) Test(org.junit.Test)

Example 10 with AuthConfig

use of org.apache.druid.server.security.AuthConfig in project druid by druid-io.

the class QueryResourceTest method createScheduledQueryResource.

private void createScheduledQueryResource(QueryScheduler scheduler, Collection<CountDownLatch> beforeScheduler, Collection<CountDownLatch> inScheduler) {
    QuerySegmentWalker texasRanger = new QuerySegmentWalker() {

        @Override
        public <T> QueryRunner<T> getQueryRunnerForIntervals(Query<T> query, Iterable<Interval> intervals) {
            return (queryPlus, responseContext) -> {
                beforeScheduler.forEach(CountDownLatch::countDown);
                return scheduler.run(scheduler.prioritizeAndLaneQuery(queryPlus, ImmutableSet.of()), new LazySequence<T>(() -> {
                    inScheduler.forEach(CountDownLatch::countDown);
                    try {
                        // pretend to be a query that is waiting on results
                        Thread.sleep(500);
                    } catch (InterruptedException ignored) {
                    }
                    // all that waiting for nothing :(
                    return Sequences.empty();
                }));
            };
        }

        @Override
        public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<SegmentDescriptor> specs) {
            return getQueryRunnerForIntervals(null, null);
        }
    };
    queryResource = new QueryResource(new QueryLifecycleFactory(WAREHOUSE, texasRanger, new DefaultGenericQueryMetricsFactory(), new NoopServiceEmitter(), testRequestLogger, new AuthConfig(), AuthTestUtils.TEST_AUTHORIZER_MAPPER, Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))), jsonMapper, smileMapper, scheduler, new AuthConfig(), null, ResponseContextConfig.newConfig(true), DRUID_NODE);
}
Also used : TimeBoundaryResultValue(org.apache.druid.query.timeboundary.TimeBoundaryResultValue) AuthorizerMapper(org.apache.druid.server.security.AuthorizerMapper) Key(com.google.inject.Key) Smile(org.apache.druid.guice.annotations.Smile) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) HttpStatus(org.apache.http.HttpStatus) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) BadJsonQueryException(org.apache.druid.query.BadJsonQueryException) After(org.junit.After) QueryRunner(org.apache.druid.query.QueryRunner) QueryToolChestWarehouse(org.apache.druid.query.QueryToolChestWarehouse) ForbiddenException(org.apache.druid.server.security.ForbiddenException) AuthConfig(org.apache.druid.server.security.AuthConfig) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ManualQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ManualQueryPrioritizationStrategy) HiLoQueryLaningStrategy(org.apache.druid.server.scheduling.HiLoQueryLaningStrategy) TestRequestLogger(org.apache.druid.server.log.TestRequestLogger) SmileMediaTypes(com.fasterxml.jackson.jaxrs.smile.SmileMediaTypes) LazySequence(org.apache.druid.java.util.common.guava.LazySequence) ImmutableSet(com.google.common.collect.ImmutableSet) Execs(org.apache.druid.java.util.common.concurrent.Execs) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) MapQueryToolChestWarehouse(org.apache.druid.query.MapQueryToolChestWarehouse) StreamingOutput(javax.ws.rs.core.StreamingOutput) Action(org.apache.druid.server.security.Action) GuiceInjectors(org.apache.druid.guice.GuiceInjectors) StandardCharsets(java.nio.charset.StandardCharsets) Executors(java.util.concurrent.Executors) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) QueryTimeoutException(org.apache.druid.query.QueryTimeoutException) Response(javax.ws.rs.core.Response) ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) Authorizer(org.apache.druid.server.security.Authorizer) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) QueryException(org.apache.druid.query.QueryException) BeforeClass(org.junit.BeforeClass) ByteArrayOutputStream(java.io.ByteArrayOutputStream) QueryCapacityExceededException(org.apache.druid.query.QueryCapacityExceededException) AuthenticationResult(org.apache.druid.server.security.AuthenticationResult) Interval(org.joda.time.Interval) HttpServletRequest(javax.servlet.http.HttpServletRequest) ImmutableList(com.google.common.collect.ImmutableList) Query(org.apache.druid.query.Query) Suppliers(com.google.common.base.Suppliers) AuthTestUtils(org.apache.druid.server.security.AuthTestUtils) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) Status(javax.ws.rs.core.Response.Status) Sequences(org.apache.druid.java.util.common.guava.Sequences) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) Before(org.junit.Before) Access(org.apache.druid.server.security.Access) EmittingLogger(org.apache.druid.java.util.emitter.EmittingLogger) ServerConfig(org.apache.druid.server.initialization.ServerConfig) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) IOException(java.io.IOException) EasyMock(org.easymock.EasyMock) DefaultObjectMapper(org.apache.druid.jackson.DefaultObjectMapper) Injector(com.google.inject.Injector) Consumer(java.util.function.Consumer) Result(org.apache.druid.query.Result) ThresholdBasedQueryPrioritizationStrategy(org.apache.druid.server.scheduling.ThresholdBasedQueryPrioritizationStrategy) TruncatedResponseContextException(org.apache.druid.query.TruncatedResponseContextException) Resource(org.apache.druid.server.security.Resource) ResourceLimitExceededException(org.apache.druid.query.ResourceLimitExceededException) NoQueryLaningStrategy(org.apache.druid.server.scheduling.NoQueryLaningStrategy) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) SegmentDescriptor(org.apache.druid.query.SegmentDescriptor) Assert(org.junit.Assert) Collections(java.util.Collections) QueryUnsupportedException(org.apache.druid.query.QueryUnsupportedException) Query(org.apache.druid.query.Query) NoopServiceEmitter(org.apache.druid.server.metrics.NoopServiceEmitter) AuthConfig(org.apache.druid.server.security.AuthConfig) CountDownLatch(java.util.concurrent.CountDownLatch) QueryInterruptedException(org.apache.druid.query.QueryInterruptedException) QuerySegmentWalker(org.apache.druid.query.QuerySegmentWalker) DefaultQueryConfig(org.apache.druid.query.DefaultQueryConfig) DefaultGenericQueryMetricsFactory(org.apache.druid.query.DefaultGenericQueryMetricsFactory) LazySequence(org.apache.druid.java.util.common.guava.LazySequence)

Aggregations

AuthConfig (org.apache.druid.server.security.AuthConfig)16 Response (javax.ws.rs.core.Response)11 AuthenticationResult (org.apache.druid.server.security.AuthenticationResult)11 Test (org.junit.Test)11 NoopServiceEmitter (org.apache.druid.server.metrics.NoopServiceEmitter)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 DefaultGenericQueryMetricsFactory (org.apache.druid.query.DefaultGenericQueryMetricsFactory)7 DefaultQueryConfig (org.apache.druid.query.DefaultQueryConfig)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 ImmutableList (com.google.common.collect.ImmutableList)6 AuthorizerMapper (org.apache.druid.server.security.AuthorizerMapper)6 IOException (java.io.IOException)5 List (java.util.List)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 StreamingOutput (javax.ws.rs.core.StreamingOutput)4 Result (org.apache.druid.query.Result)4 TimeBoundaryResultValue (org.apache.druid.query.timeboundary.TimeBoundaryResultValue)4 Access (org.apache.druid.server.security.Access)4