You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/07/01 21:21:22 UTC

[GitHub] vdiravka commented on a change in pull request #1345: DRILL-6494: Drill Plugins Handler

vdiravka commented on a change in pull request #1345: DRILL-6494: Drill Plugins Handler
URL: https://github.com/apache/drill/pull/1345#discussion_r199359888
 
 

 ##########
 File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginsHandlerService.java
 ##########
 @@ -0,0 +1,130 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import com.jasonclawson.jackson.dataformat.hocon.HoconFactory;
+import org.apache.drill.common.config.CommonConstants;
+import org.apache.drill.common.config.LogicalPlanPersistence;
+import org.apache.drill.common.exceptions.DrillRuntimeException;
+import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.common.scanner.ClassPathScanner;
+import org.apache.drill.exec.planner.logical.StoragePlugins;
+import org.apache.drill.exec.server.DrillbitContext;
+import org.apache.drill.exec.store.sys.PersistentStore;
+
+import javax.annotation.Nullable;
+import javax.validation.constraints.NotNull;
+import java.io.IOException;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Drill plugins handler, which allows to update storage plugins configs from the
+ * {@link CommonConstants#STORAGE_PLUGINS_OVERRIDE_CONF} conf file
+ *
+ * TODO: DRILL-6564: It can be improved with configs versioning and service of creating
+ * {@link CommonConstants#STORAGE_PLUGINS_OVERRIDE_CONF}
+ */
+public class StoragePluginsHandlerService implements StoragePluginsHandler {
+  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(StoragePluginsHandlerService.class);
+
+  private final LogicalPlanPersistence hoconLogicalPlanPersistence;
+
+  public StoragePluginsHandlerService(DrillbitContext context) {
+    hoconLogicalPlanPersistence = new LogicalPlanPersistence(context.getConfig(), context.getClasspathScan(),
+        new ObjectMapper(new HoconFactory()));
+  }
+
+  @Override
+  public void loadPlugins(@NotNull PersistentStore<StoragePluginConfig> persistentStore,
+                          @Nullable StoragePlugins bootstrapPlugins) {
+    // if bootstrapPlugins is not null -- fresh Drill set up
+    StoragePlugins pluginsToBeWrittenToPersistentStore;
+
+    StoragePlugins newPlugins = getNewStoragePlugins();
+
+    if (newPlugins != null) {
+      pluginsToBeWrittenToPersistentStore = new StoragePlugins(new HashMap<>());
+      Optional.ofNullable(bootstrapPlugins)
+          .ifPresent(pluginsToBeWrittenToPersistentStore::putAll);
+
+      for (Map.Entry<String, StoragePluginConfig> newPlugin : newPlugins) {
+        String pluginName = newPlugin.getKey();
+        StoragePluginConfig oldPluginConfig = Optional.ofNullable(bootstrapPlugins)
+            .map(plugins -> plugins.getConfig(pluginName))
+            .orElse(persistentStore.get(pluginName));
+        StoragePluginConfig updatedStatusPluginConfig = updatePluginStatus(oldPluginConfig, newPlugin.getValue());
+        pluginsToBeWrittenToPersistentStore.put(pluginName, updatedStatusPluginConfig);
+      }
+    } else {
+      pluginsToBeWrittenToPersistentStore = bootstrapPlugins;
+    }
+
+    // load pluginsToBeWrittenToPersistentStore to Persistent Store
+    Optional.ofNullable(pluginsToBeWrittenToPersistentStore)
+        .ifPresent(plugins -> plugins.forEach(plugin -> persistentStore.put(plugin.getKey(), plugin.getValue())));
+  }
+
+  /**
+   * Helper method to identify the enabled status for new storage plugins config. If this status is absent in the updater
+   * file, the status is kept from the configs, which are going to be updated
+   *
+   * @param oldPluginConfig current storage plugin config from Persistent Store or bootstrap config file
+   * @param newPluginConfig new storage plugin config
+   * @return new storage plugin config with updated enabled status
+   */
+  private StoragePluginConfig updatePluginStatus(@Nullable StoragePluginConfig oldPluginConfig,
+                                                 @NotNull StoragePluginConfig newPluginConfig) {
+    if (!newPluginConfig.isEnabledStatusPresent()) {
 
 Review comment:
   It was decided to consider incremental update as a future enhancement. I have added it to [DRILL-6564](https://issues.apache.org/jira/browse/DRILL-6564)

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services