Search in sources :

Example 16 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by axbaretto.

the class JdbcDataTest method testProjectPlan.

/**
 * Checks the logical plan.
 */
@Test
public void testProjectPlan() throws Exception {
    LogicalPlan plan = withModel(MODEL, "DONUTS").sql("select _MAP['ppu'] as ppu from donuts").logicalPlan();
    PlanProperties planProperties = plan.getProperties();
    Assert.assertEquals("optiq", planProperties.generator.type);
    Assert.assertEquals("na", planProperties.generator.info);
    Assert.assertEquals(1, planProperties.version);
    Assert.assertEquals(PlanProperties.PlanType.APACHE_DRILL_LOGICAL, planProperties.type);
    Map<String, StoragePluginConfig> seConfigs = plan.getStorageEngines();
    StoragePluginConfig config = seConfigs.get("donuts-json");
    // Assert.assertTrue(config != null && config instanceof ClasspathRSE.ClasspathRSEConfig);
    config = seConfigs.get("queue");
    // Assert.assertTrue(config != null && config instanceof QueueRSE.QueueRSEConfig);
    Scan scan = findOnlyOperator(plan, Scan.class);
    Assert.assertEquals("donuts-json", scan.getStorageEngine());
    Project project = findOnlyOperator(plan, Project.class);
    Assert.assertEquals(1, project.getSelections().size());
    Assert.assertEquals(Scan.class, project.getInput().getClass());
    Store store = findOnlyOperator(plan, Store.class);
    Assert.assertEquals("queue", store.getStorageEngine());
    Assert.assertEquals("output sink", store.getMemo());
    Assert.assertEquals(Project.class, store.getInput().getClass());
}
Also used : Project(org.apache.drill.common.logical.data.Project) PlanProperties(org.apache.drill.common.logical.PlanProperties) Store(org.apache.drill.common.logical.data.Store) LogicalPlan(org.apache.drill.common.logical.LogicalPlan) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) Scan(org.apache.drill.common.logical.data.Scan) Test(org.junit.Test) JdbcTest(org.apache.drill.categories.JdbcTest)

Example 17 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class TestPluginRegistry method testEnabledState.

/**
 * Tests the dedicated setEnabled() method to cleanly update the
 * enabled status of a plugin by name.
 */
@Test
public void testEnabledState() throws Exception {
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
    try (ClusterFixture cluster = builder.build()) {
        StoragePluginRegistry registry = cluster.storageRegistry();
        // Disable an enabled plugin
        StoragePluginConfig config = registry.getStoredConfig(CP_PLUGIN_NAME);
        assertTrue(config.isEnabled());
        // Enable/disable has traditionally been done by changing
        // the plugin outside of the registry, which leads to obvious
        // race conditions.
        // Tests synchronized version.
        registry.setEnabled(CP_PLUGIN_NAME, true);
        StoragePluginConfig savedConfig = registry.getStoredConfig(CP_PLUGIN_NAME);
        assertEquals(config, savedConfig);
        assertTrue(savedConfig.isEnabled());
        registry.setEnabled(CP_PLUGIN_NAME, false);
        savedConfig = registry.getStoredConfig(CP_PLUGIN_NAME);
        assertEquals(config, savedConfig);
        assertFalse(savedConfig.isEnabled());
        // OK to disable twice
        registry.setEnabled(CP_PLUGIN_NAME, false);
        savedConfig = registry.getStoredConfig(CP_PLUGIN_NAME);
        assertEquals(config, savedConfig);
        assertFalse(savedConfig.isEnabled());
        // Disabled plugins appear in the stored config map
        Map<String, StoragePluginConfig> configMap = registry.storedConfigs();
        assertTrue(configMap.containsKey(CP_PLUGIN_NAME));
        assertEquals(config, configMap.get(CP_PLUGIN_NAME));
        // Re-enable
        registry.setEnabled(CP_PLUGIN_NAME, true);
        savedConfig = registry.getStoredConfig(CP_PLUGIN_NAME);
        assertEquals(config, savedConfig);
        assertTrue(savedConfig.isEnabled());
        // Error if plugin does not exist
        try {
            registry.setEnabled("foo", true);
            fail();
        } catch (PluginException e) {
        // expected
        }
        try {
            registry.setEnabled("foo", false);
            fail();
        } catch (PluginException e) {
        // expected
        }
        // Error to mess with a system plugins
        try {
            registry.setEnabled(SYS_PLUGIN_NAME, true);
            fail();
        } catch (PluginException e) {
        // expected
        }
        try {
            registry.setEnabled(SYS_PLUGIN_NAME, false);
            fail();
        } catch (PluginException e) {
        // expected
        }
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 18 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class TestPluginRegistry method testEphemeralWithoutInstance.

@Test
public void testEphemeralWithoutInstance() throws Exception {
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
    try (ClusterFixture cluster = builder.build()) {
        StoragePluginRegistry registry = cluster.storageRegistry();
        // Create a plugin
        // Since we've created no plugin instance, the configs come from
        // the persistent store, there is no guarantee we get the same
        // instance on each retrieval.
        FileSystemConfig pConfig1 = myConfig1();
        registry.put(MY_PLUGIN_NAME, pConfig1);
        StoragePluginConfig savedConfig = registry.getStoredConfig(MY_PLUGIN_NAME);
        assertEquals(pConfig1, savedConfig);
        assertTrue(savedConfig.isEnabled());
        assertEquals(pConfig1, registry.getDefinedConfig(MY_PLUGIN_NAME));
        // Do not refer to the instance. As a result, no reason to
        // cache the plugin in ephemeral cache.
        // Change config
        FileSystemConfig pConfig1b = myConfig2();
        registry.put(MY_PLUGIN_NAME, pConfig1b);
        assertEquals(pConfig1b, registry.getDefinedConfig(MY_PLUGIN_NAME));
        // Put it back
        FileSystemConfig pConfig1c = myConfig1();
        registry.put(MY_PLUGIN_NAME, pConfig1c);
        assertEquals(pConfig1c, registry.getDefinedConfig(MY_PLUGIN_NAME));
        assertEquals(pConfig1c, registry.getPlugin(MY_PLUGIN_NAME).getConfig());
        // Odd case. Some thread refers to the config while not in
        // the store which forces an instance which later reappears.
        FileSystemConfig pConfig2a = myConfig1();
        registry.put("myplugin2", pConfig2a);
        // Didn't instantiate. Change
        FileSystemConfig pConfig2b = myConfig2();
        registry.put("myplugin2", pConfig2b);
        // Force a resync
        assertEquals(pConfig2b, registry.getDefinedConfig("myplugin2"));
        // Refer by original config. We didn't cache the original config
        // because there was no plugin instance. Must make up a new plugin
        // Which goes into the ephemeral cache.
        FileSystemConfig pConfig2c = myConfig1();
        StoragePlugin plugin2 = registry.getPluginByConfig(pConfig2c);
        assertEquals(pConfig2c, plugin2.getConfig());
        // Put the original config into the persistent store and local cache.
        // Should not dredge up the ephemeral version to reuse since that
        // version had an unknown name.
        // It is unfortunate that we have to instances with the same config,
        // but different names. But, since the name is immutable, and not
        // known above, the two-instance situation is the least bad option.
        FileSystemConfig pConfig2d = myConfig1();
        registry.put("myplugin2", pConfig2d);
        assertEquals(pConfig2d, registry.getPlugin("myplugin2").getConfig());
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 19 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class TestBootstrapLoader method testDuplicateBootstrapEntries.

@Test
public void testDuplicateBootstrapEntries() throws Exception {
    OperatorFixture.Builder builder = OperatorFixture.builder(dirTestWatcher);
    String bootstrapFile = RESOURCE_BASE + "dup-bootstrap.json";
    builder.configBuilder().put(ExecConstants.BOOTSTRAP_STORAGE_PLUGINS_FILE, bootstrapFile);
    try (OperatorFixture fixture = builder.build()) {
        PluginRegistryContextFixture context = new PluginRegistryContextFixture(fixture);
        PluginBootstrapLoaderImpl loader = new PluginBootstrapLoaderImpl(context);
        StoragePlugins plugins = loader.loadBootstrapPlugins(new HashMap<>());
        // Duplicates noted in log; last one wins.
        StoragePluginConfig pluginConfig = plugins.getConfig("cp");
        assertNotNull(pluginConfig);
        assertTrue(pluginConfig instanceof FileSystemConfig);
        FileSystemConfig cpConfig = (FileSystemConfig) pluginConfig;
        assertNotNull(cpConfig.getFormats().get("tsv"));
    }
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) OperatorFixture(org.apache.drill.test.OperatorFixture) Test(org.junit.Test)

Example 20 with StoragePluginConfig

use of org.apache.drill.common.logical.StoragePluginConfig in project drill by apache.

the class TestBootstrapLoader method testBootstrapLoaderWithFormats.

/**
 * Test a format bootstrap with a mock file. Can't use a real
 * file because those appear in modules not yet available when
 * this test runs.
 */
@Test
public void testBootstrapLoaderWithFormats() throws Exception {
    OperatorFixture.Builder builder = OperatorFixture.builder(dirTestWatcher);
    String bootstrapFile = RESOURCE_BASE + "mock-format-bootstrap.json";
    builder.configBuilder().put(ExecConstants.BOOTSTRAP_FORMAT_PLUGINS_FILE, bootstrapFile);
    try (OperatorFixture fixture = builder.build()) {
        PluginRegistryContextFixture context = new PluginRegistryContextFixture(fixture);
        PluginBootstrapLoader loader = new PluginBootstrapLoaderImpl(context);
        StoragePlugins plugins = loader.bootstrapPlugins();
        // bsv added to dfs
        StoragePluginConfig pluginConfig = plugins.getConfig("dfs");
        assertNotNull(pluginConfig);
        FileSystemConfig dfs = (FileSystemConfig) pluginConfig;
        assertNotNull(dfs.getFormats().get("bsv"));
    }
}
Also used : StoragePlugins(org.apache.drill.exec.planner.logical.StoragePlugins) StoragePluginConfig(org.apache.drill.common.logical.StoragePluginConfig) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig) OperatorFixture(org.apache.drill.test.OperatorFixture) Test(org.junit.Test)

Aggregations

StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)28 Test (org.junit.Test)15 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)12 StoragePlugins (org.apache.drill.exec.planner.logical.StoragePlugins)9 OperatorFixture (org.apache.drill.test.OperatorFixture)6 BaseTest (org.apache.drill.test.BaseTest)5 ClusterFixture (org.apache.drill.test.ClusterFixture)5 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)5 HashMap (java.util.HashMap)4 JdbcTest (org.apache.drill.categories.JdbcTest)4 LogicalPlan (org.apache.drill.common.logical.LogicalPlan)4 PlanProperties (org.apache.drill.common.logical.PlanProperties)4 Project (org.apache.drill.common.logical.data.Project)4 Scan (org.apache.drill.common.logical.data.Scan)4 Store (org.apache.drill.common.logical.data.Store)4 InfoSchemaStoragePlugin (org.apache.drill.exec.store.ischema.InfoSchemaStoragePlugin)4 IOException (java.io.IOException)3 Map (java.util.Map)3 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)3 PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)3