vdiravka commented on a change in pull request #1345: DRILL-6494: Drill Plugins Handler URL: https://github.com/apache/drill/pull/1345#discussion_r199310178
########## File path: exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistryImpl.java ########## @@ -121,69 +121,73 @@ public StoragePlugin load(StoragePluginConfig config) throws Exception { } @Override - public void init() throws DrillbitStartupException { + public void init() { availablePlugins = findAvailablePlugins(classpathScan); + try { + StoragePlugins bootstrapPlugins = pluginSystemTable.getAll().hasNext() ? null : loadBootstrapPlugins(); - // create registered plugins defined in "storage-plugins.json" - plugins.putAll(createPlugins()); + StoragePluginsHandler storagePluginsUpdaterService = new StoragePluginsHandlerService(context); + storagePluginsUpdaterService.loadPlugins(pluginSystemTable, bootstrapPlugins); + + // Defines enabled plugins + defineEnabledPlugins(); + } catch (IOException e) { + logger.error("Failure setting up storage enabledPlugins. Drillbit exiting.", e); + throw new IllegalStateException(e); + } } - @SuppressWarnings("resource") - private Map<String, StoragePlugin> createPlugins() throws DrillbitStartupException { - try { - /* - * Check if the storage plugins system table has any entries. If not, load the boostrap-storage-plugin file into - * the system table. - */ - if (!pluginSystemTable.getAll().hasNext()) { - // bootstrap load the config since no plugins are stored. - logger.info("No storage plugin instances configured in persistent store, loading bootstrap configuration."); - Collection<URL> urls = ClassPathScanner.forResource(ExecConstants.BOOTSTRAP_STORAGE_PLUGINS_FILE, false); - if (urls != null && !urls.isEmpty()) { - logger.info("Loading the storage plugin configs from URLs {}.", urls); - Map<String, URL> pluginURLMap = Maps.newHashMap(); - for (URL url : urls) { - String pluginsData = Resources.toString(url, Charsets.UTF_8); - StoragePlugins plugins = lpPersistence.getMapper().readValue(pluginsData, StoragePlugins.class); - for (Map.Entry<String, StoragePluginConfig> config : plugins) { - if (!definePluginConfig(config.getKey(), config.getValue())) { - logger.warn("Duplicate plugin instance '{}' defined in [{}, {}], ignoring the later one.", - config.getKey(), pluginURLMap.get(config.getKey()), url); - continue; - } - pluginURLMap.put(config.getKey(), url); - } - } - } else { - throw new IOException("Failure finding " + ExecConstants.BOOTSTRAP_STORAGE_PLUGINS_FILE); - } + /** + * Read bootstrap storage plugins {@link ExecConstants#BOOTSTRAP_STORAGE_PLUGINS_FILE} files for the first fresh + * instantiating of Drill + * + * @return bootstrap storage plugins + * @throws IOException if a read error occurs + */ + private StoragePlugins loadBootstrapPlugins() throws IOException { + // bootstrap load the config since no plugins are stored. + logger.info("No storage plugin instances configured in persistent store, loading bootstrap configuration."); + Set<URL> urls = ClassPathScanner.forResource(ExecConstants.BOOTSTRAP_STORAGE_PLUGINS_FILE, false); + if (urls != null && !urls.isEmpty()) { + logger.info("Loading the storage plugin configs from URLs {}.", urls); + StoragePlugins bootstrapPlugins = new StoragePlugins(new HashMap<>()); + for (URL url : urls) { + String pluginsData = Resources.toString(url, Charsets.UTF_8); + bootstrapPlugins.putAll(lpPersistence.getMapper().readValue(pluginsData, StoragePlugins.class)); Review comment: Agree. Simpler doesn't mean better. Returned the previous logic. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services