Search in sources :

Example 31 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by axbaretto.

the class TestQueryMemoryAlloc method testCustomPercent.

@Test
public void testCustomPercent() throws Exception {
    OperatorFixture.Builder builder = OperatorFixture.builder();
    builder.systemOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.10);
    builder.systemOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB);
    try (OperatorFixture fixture = builder.build()) {
        final OptionManager optionManager = fixture.getOptionManager();
        optionManager.setLocalOption(ExecConstants.PERCENT_MEMORY_PER_QUERY_KEY, 0.10);
        optionManager.setLocalOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2 * ONE_GB);
        // Out-of-box memory, use query memory per node as floor.
        long mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 8 * ONE_GB);
        assertEquals(2 * ONE_GB, mem);
        // Up to 20 GB, query memory dominates.
        mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 20 * ONE_GB);
        assertEquals(2 * ONE_GB, mem);
        // After 20 GB, the percent dominates
        mem = MemoryAllocationUtilities.computeQueryMemory(fixture.config(), optionManager, 30 * ONE_GB);
        assertEquals(3 * ONE_GB, mem);
    }
}
Also used : OperatorFixture(org.apache.drill.test.OperatorFixture) OptionManager(org.apache.drill.exec.server.options.OptionManager) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 32 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by axbaretto.

the class TestOptionsAuthEnabled method testAdminUserOptions.

@Test
public void testAdminUserOptions() throws Exception {
    try (ClusterFixture cluster = ClusterFixture.standardCluster(dirTestWatcher);
        ClientFixture client = cluster.clientFixture()) {
        OptionManager optionManager = cluster.drillbit().getContext().getOptionManager();
        // Admin Users Tests
        // config file should have the 'fake' default admin user and it should be returned
        // by the option manager if the option has not been set by the user
        String configAdminUser = optionManager.getOption(ExecConstants.ADMIN_USERS_VALIDATOR);
        assertEquals(configAdminUser, ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
        // Option accessor should never return the 'fake' default from the config
        String adminUser1 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        assertNotEquals(adminUser1, ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
        // Change testAdminUser if necessary
        String testAdminUser = "ronswanson";
        if (adminUser1.equals(testAdminUser)) {
            testAdminUser += "thefirst";
        }
        // Check if the admin option accessor honors a user-supplied value
        client.alterSystem(ExecConstants.ADMIN_USERS_KEY, testAdminUser);
        String adminUser2 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        assertEquals(adminUser2, testAdminUser);
        // Ensure that the default admin users have admin privileges
        client.resetSystem(ExecConstants.ADMIN_USERS_KEY);
        client.resetSystem(ExecConstants.ADMIN_USER_GROUPS_KEY);
        String systemAdminUsersList0 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        String systemAdminUserGroupsList0 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        for (String user : systemAdminUsersList0.split(",")) {
            assertTrue(ImpersonationUtil.hasAdminPrivileges(user, systemAdminUsersList0, systemAdminUserGroupsList0));
        }
        // test if admin users, set by the user, have admin privileges
        // test if we can handle a user-supplied list that is not well formatted
        String crummyTestAdminUsersList = " alice, bob bob, charlie  ,, dave ";
        client.alterSystem(ExecConstants.ADMIN_USERS_KEY, crummyTestAdminUsersList);
        String[] sanitizedAdminUsers = { "alice", "bob bob", "charlie", "dave" };
        // also test the CSV sanitizer
        assertEquals(Joiner.on(",").join(sanitizedAdminUsers), DrillStringUtils.sanitizeCSV(crummyTestAdminUsersList));
        String systemAdminUsersList1 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        String systemAdminUserGroupsList1 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        for (String user : sanitizedAdminUsers) {
            assertTrue(ImpersonationUtil.hasAdminPrivileges(user, systemAdminUsersList1, systemAdminUserGroupsList1));
        }
        // Admin User Groups Tests
        // config file should have the 'fake' default admin user and it should be returned
        // by the option manager if the option has not been set by the user
        String configAdminUserGroups = optionManager.getOption(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR);
        assertEquals(configAdminUserGroups, ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
        // Option accessor should never return the 'fake' default from the config
        String adminUserGroups1 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        assertNotEquals(adminUserGroups1, ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
        // Change testAdminUserGroups if necessary
        String testAdminUserGroups = "yakshavers";
        if (adminUserGroups1.equals(testAdminUserGroups)) {
            testAdminUserGroups += ",wormracers";
        }
        // Check if the admin option accessor honors a user-supplied values
        client.alterSystem(ExecConstants.ADMIN_USER_GROUPS_KEY, testAdminUserGroups);
        String adminUserGroups2 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        assertEquals(adminUserGroups2, testAdminUserGroups);
        // Test if we can handle a user-supplied admin user groups list that is not well formatted
        String crummyTestAdminUserGroupsList = " g1, g 2, g4 ,, g5 ";
        client.alterSystem(ExecConstants.ADMIN_USER_GROUPS_KEY, crummyTestAdminUserGroupsList);
        String systemAdminUserGroupsList2 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        // for admin privileges
        for (String group : systemAdminUserGroupsList2.split(",")) {
            assertTrue(group.length() != 0);
            assertTrue(group.trim().equals(group));
        }
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) OptionManager(org.apache.drill.exec.server.options.OptionManager) Test(org.junit.Test)

Example 33 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class TestOptionsAuthEnabled method testAdminUserOptions.

@Test
public void testAdminUserOptions() throws Exception {
    try (ClusterFixture cluster = ClusterFixture.standardCluster(dirTestWatcher);
        ClientFixture client = cluster.clientFixture()) {
        OptionManager optionManager = cluster.drillbit().getContext().getOptionManager();
        // Admin Users Tests
        // config file should have the 'fake' default admin user and it should be returned
        // by the option manager if the option has not been set by the user
        String configAdminUser = optionManager.getOption(ExecConstants.ADMIN_USERS_VALIDATOR);
        assertEquals(configAdminUser, ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
        // Option accessor should never return the 'fake' default from the config
        String adminUser1 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        assertNotEquals(adminUser1, ExecConstants.ADMIN_USERS_VALIDATOR.DEFAULT_ADMIN_USERS);
        // Change testAdminUser if necessary
        String testAdminUser = "ronswanson";
        if (adminUser1.equals(testAdminUser)) {
            testAdminUser += "thefirst";
        }
        // Check if the admin option accessor honors a user-supplied value
        client.alterSystem(ExecConstants.ADMIN_USERS_KEY, testAdminUser);
        String adminUser2 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        assertEquals(adminUser2, testAdminUser);
        // Ensure that the default admin users have admin privileges
        client.resetSystem(ExecConstants.ADMIN_USERS_KEY);
        client.resetSystem(ExecConstants.ADMIN_USER_GROUPS_KEY);
        String systemAdminUsersList0 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        String systemAdminUserGroupsList0 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        for (String user : systemAdminUsersList0.split(",")) {
            assertTrue(ImpersonationUtil.hasAdminPrivileges(user, systemAdminUsersList0, systemAdminUserGroupsList0));
        }
        // test if admin users, set by the user, have admin privileges
        // test if we can handle a user-supplied list that is not well formatted
        String crummyTestAdminUsersList = " alice, bob bob, charlie  ,, dave ";
        client.alterSystem(ExecConstants.ADMIN_USERS_KEY, crummyTestAdminUsersList);
        String[] sanitizedAdminUsers = { "alice", "bob bob", "charlie", "dave" };
        // also test the CSV sanitizer
        assertEquals(Joiner.on(",").join(sanitizedAdminUsers), DrillStringUtils.sanitizeCSV(crummyTestAdminUsersList));
        String systemAdminUsersList1 = ExecConstants.ADMIN_USERS_VALIDATOR.getAdminUsers(optionManager);
        String systemAdminUserGroupsList1 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        for (String user : sanitizedAdminUsers) {
            assertTrue(ImpersonationUtil.hasAdminPrivileges(user, systemAdminUsersList1, systemAdminUserGroupsList1));
        }
        // Admin User Groups Tests
        // config file should have the 'fake' default admin user and it should be returned
        // by the option manager if the option has not been set by the user
        String configAdminUserGroups = optionManager.getOption(ExecConstants.ADMIN_USER_GROUPS_VALIDATOR);
        assertEquals(configAdminUserGroups, ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
        // Option accessor should never return the 'fake' default from the config
        String adminUserGroups1 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        assertNotEquals(adminUserGroups1, ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.DEFAULT_ADMIN_USER_GROUPS);
        // Change testAdminUserGroups if necessary
        String testAdminUserGroups = "yakshavers";
        if (adminUserGroups1.equals(testAdminUserGroups)) {
            testAdminUserGroups += ",wormracers";
        }
        // Check if the admin option accessor honors a user-supplied values
        client.alterSystem(ExecConstants.ADMIN_USER_GROUPS_KEY, testAdminUserGroups);
        String adminUserGroups2 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        assertEquals(adminUserGroups2, testAdminUserGroups);
        // Test if we can handle a user-supplied admin user groups list that is not well formatted
        String crummyTestAdminUserGroupsList = " g1, g 2, g4 ,, g5 ";
        client.alterSystem(ExecConstants.ADMIN_USER_GROUPS_KEY, crummyTestAdminUserGroupsList);
        String systemAdminUserGroupsList2 = ExecConstants.ADMIN_USER_GROUPS_VALIDATOR.getAdminUserGroups(optionManager);
        // for admin privileges
        for (String group : systemAdminUserGroupsList2.split(",")) {
            assertTrue(group.length() != 0);
            assertTrue(group.trim().equals(group));
        }
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) ClientFixture(org.apache.drill.test.ClientFixture) OptionManager(org.apache.drill.exec.server.options.OptionManager) Test(org.junit.Test)

Example 34 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class AbstractGroupScanWithMetadata method setFilterForRuntime.

/**
 *  Set the filter - thus enabling runtime rowgroup pruning
 *  The runtime pruning can be disabled with an option.
 * @param filterExpr The filter to be used at runtime to match with rowgroups' footers
 * @param optimizerContext The context for the options
 */
public void setFilterForRuntime(LogicalExpression filterExpr, OptimizerRulesContext optimizerContext) {
    OptionManager options = optimizerContext.getPlannerSettings().getOptions();
    // if option is set to disable runtime pruning
    boolean skipRuntimePruning = options.getBoolean(SKIP_RUNTIME_ROWGROUP_PRUNING_KEY);
    if (!skipRuntimePruning) {
        setFilter(filterExpr);
    }
}
Also used : OptionManager(org.apache.drill.exec.server.options.OptionManager)

Example 35 with OptionManager

use of org.apache.drill.exec.server.options.OptionManager in project drill by apache.

the class StatusResources method getSystemOptionsJSONHelper.

private List<OptionWrapper> getSystemOptionsJSONHelper(boolean internal) {
    List<OptionWrapper> options = new LinkedList<>();
    OptionManager optionManager = work.getContext().getOptionManager();
    OptionList optionList = internal ? optionManager.getInternalOptionList() : optionManager.getPublicOptionList();
    for (OptionValue option : optionList) {
        options.add(new OptionWrapper(option.name, option.getValue(), optionManager.getDefault(option.name).getValue().toString(), option.accessibleScopes, option.kind, option.scope));
    }
    Collections.sort(options, new Comparator<OptionWrapper>() {

        @Override
        public int compare(OptionWrapper o1, OptionWrapper o2) {
            return o1.name.compareTo(o2.name);
        }
    });
    return options;
}
Also used : OptionValue(org.apache.drill.exec.server.options.OptionValue) LinkedList(java.util.LinkedList) OptionManager(org.apache.drill.exec.server.options.OptionManager) SystemOptionManager(org.apache.drill.exec.server.options.SystemOptionManager) OptionList(org.apache.drill.exec.server.options.OptionList)

Aggregations

OptionManager (org.apache.drill.exec.server.options.OptionManager)39 Test (org.junit.Test)10 DrillTest (org.apache.drill.test.DrillTest)8 OperatorFixture (org.apache.drill.test.OperatorFixture)8 DrillbitContext (org.apache.drill.exec.server.DrillbitContext)7 OptionValue (org.apache.drill.exec.server.options.OptionValue)6 ExecutionSetupException (org.apache.drill.common.exceptions.ExecutionSetupException)5 SystemOptionManager (org.apache.drill.exec.server.options.SystemOptionManager)5 LinkedList (java.util.LinkedList)4 Callable (java.util.concurrent.Callable)4 ExecutionException (java.util.concurrent.ExecutionException)4 DrillConfig (org.apache.drill.common.config.DrillConfig)4 MajorType (org.apache.drill.common.types.TypeProtos.MajorType)4 SchemaChangeException (org.apache.drill.exec.exception.SchemaChangeException)4 MaterializedField (org.apache.drill.exec.record.MaterializedField)4 ArrayList (java.util.ArrayList)3 RelOptPlanner (org.apache.calcite.plan.RelOptPlanner)3 RelTraitSet (org.apache.calcite.plan.RelTraitSet)3 RelNode (org.apache.calcite.rel.RelNode)3 SqlSetOption (org.apache.calcite.sql.SqlSetOption)3