Example usage for org.apache.hadoop.conf Configuration getBoolean

List of usage examples for org.apache.hadoop.conf Configuration getBoolean

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getBoolean.

Prototype

public boolean getBoolean(String name, boolean defaultValue) 

Source Link

Document

Get the value of the name property as a boolean.

Usage

From source file:com.cloudera.castagna.logparser.Utils.java

License:Apache License

public static void setReducers(Job job, Configuration configuration, Logger log) {
    boolean runLocal = configuration.getBoolean(Constants.OPTION_RUN_LOCAL, Constants.OPTION_RUN_LOCAL_DEFAULT);
    int num_reducers = configuration.getInt(Constants.OPTION_NUM_REDUCERS,
            Constants.OPTION_NUM_REDUCERS_DEFAULT);

    // TODO: should we comment this out and let Hadoop decide the number of reducers?
    if (runLocal) {
        if (log != null)
            log.debug("Setting number of reducers to {}", 1);
        job.setNumReduceTasks(1);// w w w. j av  a 2s  .com
    } else {
        job.setNumReduceTasks(num_reducers);
        if (log != null)
            log.debug("Setting number of reducers to {}", num_reducers);
    }
}

From source file:com.cloudera.hadoop.hdfs.nfs.nfs4.UserIDMapper.java

License:Apache License

public static synchronized UserIDMapper get(Configuration conf) {
    boolean cache = conf.getBoolean(USER_ID_MAPPER_CACHE, true);
    Class<?> clazz = conf.getClass(USER_ID_MAPPER_CLASS, UserIDMapperSystem.class, UserIDMapper.class);
    if (cache) {/*  w w w. j  a v  a2 s.c o m*/
        UserIDMapper mapper = classUserIdMapperMap.get(clazz);
        if (mapper == null) {
            mapper = (UserIDMapper) ReflectionUtils.newInstance(clazz, conf);
            classUserIdMapperMap.put(clazz, mapper);
        }
        return mapper;
    }
    return (UserIDMapper) ReflectionUtils.newInstance(clazz, conf);
}

From source file:com.cloudera.impala.service.JniFrontend.java

License:Apache License

/**
 * Return an empty string if short circuit read is properly enabled. If not, return an
 * error string describing the issues.//  w  w  w.j  a v a  2  s  .co  m
 */
private String checkShortCircuitRead(Configuration conf) {
    StringBuilder output = new StringBuilder();
    String errorMessage = "ERROR: short-circuit local reads is disabled because\n";
    String prefix = "  - ";
    StringBuilder errorCause = new StringBuilder();

    // dfs.domain.socket.path must be set properly
    String domainSocketPath = conf.getTrimmed(DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY,
            DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_DEFAULT);
    if (domainSocketPath.isEmpty()) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY);
        errorCause.append(" is not configured.\n");
    } else {
        // The socket path parent directory must be readable and executable.
        File socketFile = new File(domainSocketPath);
        File socketDir = socketFile.getParentFile();
        if (socketDir == null || !socketDir.canRead() || !socketDir.canExecute()) {
            errorCause.append(prefix);
            errorCause.append("Impala cannot read or execute the parent directory of ");
            errorCause.append(DFSConfigKeys.DFS_DOMAIN_SOCKET_PATH_KEY);
            errorCause.append("\n");
        }
    }

    // dfs.client.read.shortcircuit must be set to true.
    if (!conf.getBoolean(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_KEY,
            DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_DEFAULT)) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_KEY);
        errorCause.append(" is not enabled.\n");
    }

    // dfs.client.use.legacy.blockreader.local must be set to false
    if (conf.getBoolean(DFSConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL,
            DFSConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL_DEFAULT)) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL);
        errorCause.append(" should not be enabled.\n");
    }

    if (errorCause.length() > 0) {
        output.append(errorMessage);
        output.append(errorCause);
    }

    return output.toString();
}

From source file:com.cloudera.impala.service.JniFrontend.java

License:Apache License

/**
 * Check short circuit read for CDH 4.1.
 * Return an empty string if short circuit read is properly enabled. If not, return an
 * error string describing the issues./*  w  ww  .j a  va  2 s.  c  o  m*/
 */
private String checkShortCircuitReadCdh41(Configuration conf) {
    StringBuilder output = new StringBuilder();
    String errorMessage = "ERROR: short-circuit local reads is disabled because\n";
    String prefix = "  - ";
    StringBuilder errorCause = new StringBuilder();

    // Client side checks
    // dfs.client.read.shortcircuit must be set to true.
    if (!conf.getBoolean(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_KEY,
            DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_DEFAULT)) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_CLIENT_READ_SHORTCIRCUIT_KEY);
        errorCause.append(" is not enabled.\n");
    }

    // dfs.client.use.legacy.blockreader.local must be set to true
    if (!conf.getBoolean(DFSConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL,
            DFSConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL_DEFAULT)) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_CLIENT_USE_LEGACY_BLOCKREADERLOCAL);
        errorCause.append(" is not enabled.\n");
    }

    // Server side checks
    // Check data node server side configuration by reading the CONF from the data node
    // web UI
    // TODO: disabled for now
    //cdh41ShortCircuitReadDatanodeCheck(errorCause, prefix);

    if (errorCause.length() > 0) {
        output.append(errorMessage);
        output.append(errorCause);
    }

    return output.toString();
}

From source file:com.cloudera.impala.service.JniFrontend.java

License:Apache License

/**
 * Return an empty string if block location tracking is properly enabled. If not,
 * return an error string describing the issues.
 *///from   w  w  w  .  j a v a2 s.  c o  m
private String checkBlockLocationTracking(Configuration conf) {
    StringBuilder output = new StringBuilder();
    String errorMessage = "ERROR: block location tracking is not properly enabled " + "because\n";
    String prefix = "  - ";
    StringBuilder errorCause = new StringBuilder();
    if (!conf.getBoolean(DFSConfigKeys.DFS_HDFS_BLOCKS_METADATA_ENABLED,
            DFSConfigKeys.DFS_HDFS_BLOCKS_METADATA_ENABLED_DEFAULT)) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_HDFS_BLOCKS_METADATA_ENABLED);
        errorCause.append(" is not enabled.\n");
    }

    // dfs.client.file-block-storage-locations.timeout should be >= 500
    // TODO: OPSAPS-12765 - it should be >= 3000, but use 500 for now until CM refresh
    if (conf.getInt(DFSConfigKeys.DFS_CLIENT_FILE_BLOCK_STORAGE_LOCATIONS_TIMEOUT,
            DFSConfigKeys.DFS_CLIENT_FILE_BLOCK_STORAGE_LOCATIONS_TIMEOUT_DEFAULT) < 500) {
        errorCause.append(prefix);
        errorCause.append(DFSConfigKeys.DFS_CLIENT_FILE_BLOCK_STORAGE_LOCATIONS_TIMEOUT);
        errorCause.append(" is too low. It should be at least 3000.\n");
    }

    if (errorCause.length() > 0) {
        output.append(errorMessage);
        output.append(errorCause);
    }

    return output.toString();
}

From source file:com.cloudera.llama.am.api.LlamaAM.java

License:Apache License

/**
 * Creates a <code>LlamaAM</code> instance using the provided configuration.
 *
 * @param conf configuration for the LlamaAM instance. This configuration is
 * propagated to the underlying components (notably the {@link RMConnector}
 * instances)./*from   w w  w . j a va2  s .c om*/
 *
 * @return A new <code>LlamaAM</code> instance based on the provided
 * configuration.
 * @throws LlamaException thrown if the <code>LlamaAM</code> could not be
 * created.
 */
public static LlamaAM create(Configuration conf) throws LlamaException {
    conf = cloneConfiguration(conf);
    LlamaAM am = new MultiQueueLlamaAM(conf);
    if (conf.getBoolean(GANG_ANTI_DEADLOCK_ENABLED_KEY, GANG_ANTI_DEADLOCK_ENABLED_DEFAULT)) {
        am = new GangAntiDeadlockLlamaAM(conf, am);
    }
    am = new ExpansionReservationsLlamaAM(am);
    return new APIContractLlamaAM(am);
}

From source file:com.cloudera.llama.am.LlamaAdminClient.java

License:Apache License

public static int execute(String[] args) throws Exception {
    int exitCode = 1;
    CLIParser parser = createParser();/*www  .j  a v  a  2  s . c om*/
    try {
        CLIParser.Command command = parser.parse(args);
        CommandLine cl = command.getCommandLine();

        Configuration conf = new Configuration(false);
        conf.addResource(LLAMAADMIN_CONFIG);
        if (cl.hasOption(SECURE)) {
            conf.setBoolean(LLAMAADMIN_SERVER_SECURE_KEY, true);
        }
        if (cl.hasOption(LLAMA)) {
            conf.set(LLAMAADMIN_SERVER_ADDRESS_KEY, cl.getOptionValue(LLAMA));
        }
        String llama = conf.get(LLAMAADMIN_SERVER_ADDRESS_KEY, LLAMAADMIN_SERVER_ADDRESS_DEFAULT);
        boolean secure = conf.getBoolean(LLAMAADMIN_SERVER_SECURE_KEY, LLAMAADMIN_SERVER_SECURE_DEFAULT);

        if (command.getName().equals(HELP_CMD)) {
            parser.showHelp(command.getCommandLine());
            exitCode = 0;
        } else if (command.getName().equals(RELEASE_CMD)) {
            boolean doNotCache = cl.hasOption(DO_NOT_CACHE);
            List<UUID> handles = optToHandles(cl.getOptionValue(HANDLES));
            List<UUID> reservations = optToHandles(cl.getOptionValue(RESERVATIONS));
            List<String> queues = optToStrings(cl.getOptionValue(QUEUES));

            if (handles.isEmpty() && reservations.isEmpty() && queues.isEmpty()) {
                System.err.print("At least one of the -queues, -handles or "
                        + "-reservations options must be specified");
                exitCode = 1;
            } else {
                release(secure, getHost(llama), getPort(llama, LLAMAADMIN_SERVER_PORT_DEFAULT), handles,
                        reservations, queues, doNotCache);
                exitCode = 0;
            }
        } else if (command.getName().equals(EMPTY_CACHE_CMD)) {
            boolean allQueues = cl.hasOption(ALL_QUEUES);
            List<String> queues = optToStrings(cl.getOptionValue(QUEUES));
            if ((!allQueues && queues.isEmpty()) || (allQueues && !queues.isEmpty())) {
                System.err.print("Either the -allqueues or the -queues option must " + "be specified");
                exitCode = 1;
            } else {
                emptyCache(secure, getHost(llama), getPort(llama, LLAMAADMIN_SERVER_PORT_DEFAULT), queues,
                        allQueues);
                exitCode = 0;
            }
        } else if (command.getName().equals(ERROR_CODES_CMD)) {
            System.out.println();
            System.out.println("Error codes for Llama version: " + VersionInfo.getVersion());
            System.out.println();
            for (String description : ErrorCode.ERROR_CODE_DESCRIPTIONS) {
                System.out.println("  " + description);
            }
            System.out.println();
        } else if (command.getName().equals(VERSION_CMD)) {
            System.out.println(VersionInfo.getVersion());
        } else {
            System.err.println("Sub-command missing");
            System.err.println();
            System.err.println(parser.shortHelp());
            exitCode = 1;
        }
    } catch (ParseException ex) {
        System.err.println("Invalid sub-command: " + ex.getMessage());
        System.err.println();
        System.err.println(parser.shortHelp());
        exitCode = 1;
    } catch (Throwable ex) {
        System.err.println("Error: " + ex.getMessage());
        ex.printStackTrace(System.err);
        exitCode = 2;
    }
    return exitCode;
}

From source file:com.cloudera.llama.am.MiniLlama.java

License:Apache License

public MiniLlama(Configuration conf) {
    ParamChecker.notNull(conf, "conf");
    Class<? extends AbstractServer> klass = conf.getClass(MINI_SERVER_CLASS_KEY, LlamaAMServer.class,
            AbstractServer.class);
    server = ReflectionUtils.newInstance(klass, conf);
    this.conf = server.getConf();
    useExternalHadoop = conf.getBoolean(MINI_USE_EXTERNAL_HADOOP_KEY, false);
}

From source file:com.cloudera.llama.server.TestAbstractServer.java

License:Apache License

@Test
public void testStartStopStepsOK() throws Exception {
    MyServer server = new MyServer();
    Configuration conf = new Configuration(false);
    server.setConf(conf);//from   www. j a v a2s  . com
    server.start();
    for (String step : STEPS) {
        Assert.assertTrue(conf.getBoolean("start." + step + ".trace", false));
        Assert.assertFalse(conf.getBoolean("stop." + step + ".trace", false));
    }
    for (String step : STEPS) {
        conf.setBoolean("start." + step + ".trace", false);
    }
    server.stop();
    for (String step : STEPS) {
        Assert.assertFalse(conf.getBoolean("start." + step + ".trace", false));
        Assert.assertTrue(conf.getBoolean("stop." + step + ".trace", false));
    }
}

From source file:com.cloudera.llama.server.TestAbstractServer.java

License:Apache License

@Test
public void testStopStepsFailures() throws Exception {
    for (String step : STEPS) {
        MyServer server = new MyServer();
        Configuration conf = new Configuration(false);
        conf.setBoolean("stop." + step + ".fail", true);
        server.setConf(conf);/*ww  w.  j a  v a 2  s  .  co m*/
        server.start();
        server.stop();
        for (String step2 : STEPS) {
            Assert.assertTrue(conf.getBoolean("start." + step2 + ".trace", false));
            Assert.assertTrue(conf.getBoolean("stop." + step2 + ".trace", false));
        }
    }
}