This is an automated email from the ASF dual-hosted git repository. sorabh pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/drill.git
commit c6df1d0e8654369fa8f4f98a371a08290510c95e Author: shuifeng lu <lushuif...@gmail.com> AuthorDate: Fri Sep 7 15:03:47 2018 +0800 DRILL-6732: Queries are runnable on disable plugins (#1460) --- .../org/apache/calcite/jdbc/DynamicRootSchema.java | 2 +- .../exec/store/StoragePluginRegistryImpl.java | 1 + .../drill/exec/store/store/TestDisabledPlugin.java | 80 ++++++++++++++++++++++ .../java/org/apache/drill/test/ClusterFixture.java | 1 + .../drill/test/ClusterMockStorageFixture.java | 1 + 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java b/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java index 5fecfdd..6bef3d5 100644 --- a/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java +++ b/exec/java-exec/src/main/java/org/apache/calcite/jdbc/DynamicRootSchema.java @@ -78,7 +78,7 @@ public class DynamicRootSchema extends DynamicSchema { try { SchemaPlus schemaPlus = this.plus(); StoragePlugin plugin = getSchemaFactories().getPlugin(schemaName); - if (plugin != null) { + if (plugin != null && plugin.getConfig().isEnabled()) { plugin.registerSchemas(schemaConfig, schemaPlus); return; } diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java index cf8ea50..c5554f8 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java @@ -373,6 +373,7 @@ public class StoragePluginRegistryImpl implements StoragePluginRegistry { logger.debug("Storage plugin name {} is not defined. Skipping plugin initialization.", annotatedClass.getClassName()); continue; } + storagePlugin.getConfig().setEnabled(true); plugins.put(name, storagePlugin); isPluginInitialized = true; diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/store/TestDisabledPlugin.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/store/TestDisabledPlugin.java new file mode 100644 index 0000000..0f31e57 --- /dev/null +++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/store/TestDisabledPlugin.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.drill.exec.store.store; + +import org.apache.drill.categories.SqlTest; +import org.apache.drill.common.exceptions.UserRemoteException; +import org.apache.drill.exec.proto.UserBitShared; +import org.apache.drill.exec.store.StoragePluginRegistry; +import org.apache.drill.exec.store.dfs.FileSystemConfig; +import org.apache.drill.test.ClusterFixture; +import org.apache.drill.test.ClusterTest; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import static org.apache.drill.exec.util.StoragePluginTestUtils.CP_PLUGIN_NAME; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +@Category(SqlTest.class) +public class TestDisabledPlugin extends ClusterTest { + private static StoragePluginRegistry pluginRegistry; + private static FileSystemConfig pluginConfig; + + @BeforeClass + public static void setup() throws Exception { + startCluster(ClusterFixture.builder(dirTestWatcher)); + pluginRegistry = cluster.drillbit().getContext().getStorage(); + pluginConfig = (FileSystemConfig) pluginRegistry.getPlugin(CP_PLUGIN_NAME).getConfig(); + pluginConfig.setEnabled(false); + pluginRegistry.createOrUpdate(CP_PLUGIN_NAME, pluginConfig, true); + } + + @AfterClass + public static void restore() throws Exception { + pluginConfig.setEnabled(true); + pluginRegistry.createOrUpdate(CP_PLUGIN_NAME, pluginConfig, true); + } + + @Test + public void testDisabledPluginQuery() throws Exception { + try { + run("SELECT * FROM cp.`employee.json` LIMIT 10"); + fail("Query should have failed!"); + } catch (UserRemoteException e) { + assertEquals(UserBitShared.DrillPBError.ErrorType.VALIDATION, e.getErrorType()); + assertTrue("Incorrect error message", + e.getMessage().contains("VALIDATION ERROR: Schema")); + } + } + + @Test + public void testUseStatement() throws Exception { + try { + run("use cp"); + fail("Query should have failed!"); + } catch (UserRemoteException e) { + assertEquals(UserBitShared.DrillPBError.ErrorType.VALIDATION, e.getErrorType()); + assertTrue("Incorrect error message", + e.getMessage().contains("VALIDATION ERROR: Schema")); + } + } +} diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java index 5f06b8f..8e045a2 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterFixture.java @@ -276,6 +276,7 @@ public class ClusterFixture extends BaseFixture implements AutoCloseable { MockStorageEngine plugin = new MockStorageEngine( MockStorageEngineConfig.INSTANCE, bit.getContext(), MockStorageEngineConfig.NAME); + config.setEnabled(true); ((StoragePluginRegistryImpl) pluginRegistry).addPluginToPersistentStoreIfAbsent(MockStorageEngineConfig.NAME, config, plugin); } diff --git a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterMockStorageFixture.java b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterMockStorageFixture.java index 03b0828..4a548b3 100644 --- a/exec/java-exec/src/test/java/org/apache/drill/test/ClusterMockStorageFixture.java +++ b/exec/java-exec/src/test/java/org/apache/drill/test/ClusterMockStorageFixture.java @@ -42,6 +42,7 @@ public class ClusterMockStorageFixture extends ClusterFixture { @SuppressWarnings("resource") MockBreakageStorage plugin = new MockBreakageStorage( MockStorageEngineConfig.INSTANCE, bit.getContext(), name); + config.setEnabled(true); ((StoragePluginRegistryImpl) pluginRegistry).addPluginToPersistentStoreIfAbsent(name, config, plugin); plugin.setBreakRegister(breakRegisterSchema);