Search in sources :

Example 1 with StoragePlugins

use of org.apache.drill.exec.planner.logical.StoragePlugins in project drill by apache.

the class PluginBootstrapLoaderImpl method bootstrapPlugins.

@Override
public StoragePlugins bootstrapPlugins() throws IOException {
    Map<String, URL> pluginURLMap = new HashMap<>();
    StoragePlugins bootstrapPlugins = loadBootstrapPlugins(pluginURLMap);
    // Upgrade the bootstrap plugins with any updates. Seems odd,
    // but this is how Drill 1.17 works, so keeping the code.
    // Uses the enabled status from the updates if different than
    // the bootstrap version.
    StoragePlugins updatedPlugins = updatedPlugins();
    if (updatedPlugins != null) {
        bootstrapPlugins.putAll(updatedPlugins);
    }
    applyFormatPlugins(bootstrapPlugins, pluginURLMap);
    return bootstrapPlugins;
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) HashMap(java.util.HashMap) URL(java.net.URL)

Example 2 with StoragePlugins

use of org.apache.drill.exec.planner.logical.StoragePlugins in project drill by apache.

the class PluginBootstrapLoaderImpl method loadBootstrapPlugins.

@VisibleForTesting
protected StoragePlugins loadBootstrapPlugins(Map<String, URL> pluginURLMap) throws IOException {
    // bootstrap load the config since no plugins are stored.
    String storageBootstrapFileName = context.config().getString(ExecConstants.BOOTSTRAP_STORAGE_PLUGINS_FILE);
    Set<URL> storageUrls = ClassPathScanner.forResource(storageBootstrapFileName, false);
    if (storageUrls == null || storageUrls.isEmpty()) {
        throw new IOException("Cannot find storage plugin boostrap file: " + storageBootstrapFileName);
    }
    logger.info("Loading the storage plugin configs from URLs {}.", storageUrls);
    StoragePlugins bootstrapPlugins = new StoragePlugins();
    for (URL url : storageUrls) {
        try {
            loadStoragePlugins(url, bootstrapPlugins, pluginURLMap);
        } catch (IOException e) {
            throw new IOException("Failed to load bootstrap plugins from " + url.toString(), e);
        }
    }
    return bootstrapPlugins;
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) IOException(java.io.IOException) URL(java.net.URL) VisibleForTesting(org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting)

Example 3 with StoragePlugins

use of org.apache.drill.exec.planner.logical.StoragePlugins in project drill by apache.

the class PluginBootstrapLoaderImpl method loadFormatPlugins.

/**
 * Loads format plugins from the given URL and adds the formats to the
 * specified storage plugins
 *
 * @param url
 *          URL to the format plugins bootstrap file
 * @param bootstrapPlugins
 *          a collection with loaded storage plugins. New formats will be
 *          added to them
 * @param pluginURLMap
 *          a map to store correspondence between storage plugins and
 *          bootstrap files in which they are defined. Used for logging
 * @throws IOException
 *           if failed to retrieve a plugin from a bootstrap file
 */
private void loadFormatPlugins(URL url, StoragePlugins bootstrapPlugins, Map<String, URL> pluginURLMap) throws IOException {
    StoragePlugins plugins = getPluginsFromResource(url);
    for (Entry<String, StoragePluginConfig> sourceEntry : plugins) {
        String pluginName = sourceEntry.getKey();
        StoragePluginConfig sourcePlugin = sourceEntry.getValue();
        if (!(sourcePlugin instanceof FileSystemConfig)) {
            logger.warn("Formats are only supported by File System plugins. Source name '{}' is of type '{}'.", pluginName, sourcePlugin.getClass().getName());
            continue;
        }
        StoragePluginConfig targetPlugin = bootstrapPlugins.getConfig(pluginName);
        if (targetPlugin == null) {
            logger.warn("No boostrap storage plugin matches the name '{}'", pluginName);
            continue;
        }
        if (!(targetPlugin instanceof FileSystemConfig)) {
            logger.warn("Formats are only supported by File System plugins. Source name '{}' " + "is of type '{}' but the bootstrap plugin of that name is of type '{}.", pluginName, sourcePlugin.getClass().getName(), targetPlugin.getClass().getName());
            continue;
        }
        FileSystemConfig targetFsConfig = (FileSystemConfig) targetPlugin;
        FileSystemConfig sourceFsConfig = (FileSystemConfig) sourcePlugin;
        sourceFsConfig.getFormats().forEach((formatName, formatValue) -> {
            FormatPluginConfig oldPluginConfig = targetFsConfig.getFormats().putIfAbsent(formatName, formatValue);
            if (oldPluginConfig != null) {
                logger.warn("Duplicate format instance '{}' defined in '{}' and '{}', ignoring the later one.", formatName, pluginURLMap.get(pluginName), url);
            }
        });
    }
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) FormatPluginConfig(org.apache.drill.common.logical.FormatPluginConfig) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig)

Example 4 with StoragePlugins

use of org.apache.drill.exec.planner.logical.StoragePlugins in project drill by apache.

the class PluginBootstrapLoaderImpl method loadStoragePlugins.

/**
 * Loads storage plugins from the given URL
 *
 * @param url
 *          URL to the storage plugins bootstrap file
 * @param bootstrapPlugins
 *          a collection where the plugins should be loaded to
 * @param pluginURLMap
 *          a map to store correspondence between storage plugins and
 *          bootstrap files in which they are defined. Used for logging
 * @throws IOException
 *           if failed to retrieve a plugin from a bootstrap file
 */
private void loadStoragePlugins(URL url, StoragePlugins bootstrapPlugins, Map<String, URL> pluginURLMap) throws IOException {
    StoragePlugins plugins = getPluginsFromResource(url);
    plugins.forEach(plugin -> {
        StoragePluginConfig oldPluginConfig = bootstrapPlugins.putIfAbsent(plugin.getKey(), plugin.getValue());
        if (oldPluginConfig != null) {
            logger.warn("Duplicate plugin instance '[{}]' defined in [{}, {}], ignoring the later one.", plugin.getKey(), pluginURLMap.get(plugin.getKey()), url);
        } else {
            pluginURLMap.put(plugin.getKey(), url);
        }
    });
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig)

Example 5 with StoragePlugins

use of org.apache.drill.exec.planner.logical.StoragePlugins in project drill by apache.

the class TestClassicLocator method testBootstrap.

@Test
public void testBootstrap() throws Exception {
    try (OperatorFixture fixture = OperatorFixture.standardFixture(dirTestWatcher)) {
        PluginRegistryContextFixture context = new PluginRegistryContextFixture(fixture);
        ConnectorLocator locator = new ClassicConnectorLocator(context);
        locator.init();
        StoragePlugins plugins = locator.bootstrapPlugins();
        // Sanity test. Change this if the bootstrap file changes.
        // No need to test contents; here we assume serialization works.
        // See FormatPluginSerDeTest
        assertNotNull(plugins.getConfig("dfs"));
        assertNotNull(plugins.getConfig("s3"));
        assertNotNull(plugins.getConfig(StoragePluginTestUtils.CP_PLUGIN_NAME));
        // No-op
        locator.close();
    }
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) OperatorFixture(org.apache.drill.test.OperatorFixture) Test(org.junit.Test)

Aggregations

StoragePlugins (org.apache.drill.exec.planner.logical.StoragePlugins)15 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)9 OperatorFixture (org.apache.drill.test.OperatorFixture)7 Test (org.junit.Test)7 URL (java.net.URL)5 HashMap (java.util.HashMap)5 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)5 IOException (java.io.IOException)4 Map (java.util.Map)3 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)2 InfoSchemaConfig (org.apache.drill.exec.store.ischema.InfoSchemaConfig)2 InfoSchemaStoragePlugin (org.apache.drill.exec.store.ischema.InfoSchemaStoragePlugin)2 SystemTablePlugin (org.apache.drill.exec.store.sys.SystemTablePlugin)2 IdentityHashMap (java.util.IdentityHashMap)1 FormatPluginConfig (org.apache.drill.common.logical.FormatPluginConfig)1 VisibleForTesting (org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting)1