sohami closed pull request #1460: DRILL-6732: Queries are runnable on disable 
plugins
URL: https://github.com/apache/drill/pull/1460
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 5fecfddb28b..6bef3d5aaa1 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 void loadSchemaFactory(String schemaName, boolean 
caseSensitive) {
     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 cf8ea500cf9..c5554f8fd29 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 @@ private StoragePlugins 
loadBootstrapPlugins(LogicalPlanPersistence lpPersistence
             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 00000000000..0f31e579c19
--- /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 5f06b8f4e12..8e045a27159 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 @@ private void configureStoragePlugins(Drillbit bit) throws 
Exception {
     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 03b0828d9f7..4a548b386ce 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 void insertMockStorage(String name, boolean 
breakRegisterSchema) {
       @SuppressWarnings("resource")
       MockBreakageStorage plugin = new MockBreakageStorage(
           MockStorageEngineConfig.INSTANCE, bit.getContext(), name);
+      config.setEnabled(true);
       ((StoragePluginRegistryImpl) 
pluginRegistry).addPluginToPersistentStoreIfAbsent(name, config, plugin);
 
       plugin.setBreakRegister(breakRegisterSchema);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to