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

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

Introduction

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

Prototype

public String get(String name) 

Source Link

Document

Get the value of the name property, null if no such property exists.

Usage

From source file:com.avira.couchdoop.imp.ImportViewArgs.java

License:Apache License

protected static String[] parseViewKeys(Configuration hadoopConf) {
    return parseViewKeys(hadoopConf.get(ARG_VIEW_KEYS.getPropertyName()));
}

From source file:com.awcoleman.StandaloneJava.AvroCombinerByBlock.java

License:Apache License

public long getBlockSize() throws IOException {

    Configuration conf = new Configuration();

    /*      //from  ww w  .j a va  2  s.c  o  m
          //Block Size from XML conf files (is null if not explicitly defined)
          Configuration conf = new Configuration();
          conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));  //BigTop path, change to yours
          conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));
          System.out.println("Default block size from conf xml files: "+conf.get("dfs.blocksize"));  //Default blocksize
    */

    //FS blocksize
    FileSystem hdfs = FileSystem.get(conf);
    Configuration cconf = hdfs.getConf();
    String block = cconf.get("dfs.blocksize");
    long blocksize = Long.parseLong(block);
    //System.out.println("FS hdfs block size: "+block+" ( "+blocksize+" )");

    /*      
          //Block Size of file (not valid for directories - returns 0. Not sure how to get default directory block size if overridden from fs default)
          Path myFile = new Path("/myFile");
          FileStatus fileStatus = hdfs.getFileStatus(myFile);
          long fileBlockSize = fileStatus.getBlockSize();
          System.out.println("Input directory block size: "+fileBlockSize);   
    */
    return blocksize;
}

From source file:com.bah.culvert.accumulo.database.AccumuloDatabaseAdapter.java

License:Apache License

/**
 * Overloading the use of this method to actually create the connection
 */// w w  w. ja v  a 2s  .c  om
@Override
public boolean verify() {
    Configuration conf = this.getConf();
    try {
        this.inst = getInstance(conf);
        this.conn = inst.getConnector(conf.get(AccumuloConstants.USERNAME_KEY),
                conf.get(AccumuloConstants.PASSWORD_KEY));
    } catch (Exception e) {
        throw new RuntimeException("Could not verify/create connection to Accumulo", e);
    }
    return true;
}

From source file:com.bah.culvert.accumulo.database.AccumuloDatabaseAdapter.java

License:Apache License

private static Instance getInstance(Configuration conf) throws ClassNotFoundException {
    String instClass = conf.get(AccumuloConstants.INSTANCE_CLASS_KEY);
    Class<? extends Instance> clazz;

    // make sure that we have a valid instance
    if (instClass == null) {
        LOG.debug("No instance type specified for connecting to Accumulo, using default");
        clazz = AccumuloConstants.DEFAULT_INSTANCE_CLASS;
    } else/*from  w  ww  .ja  v a 2s . c  om*/
        clazz = Class.forName(instClass).asSubclass(Instance.class);

    // create the valid instance
    if (clazz.equals(ZooKeeperInstance.class))
        return new ZooKeeperInstance(conf.get(AccumuloConstants.INSTANCE_NAME_KEY),
                conf.get(AccumuloConstants.ZOOKEEPER_SERVERS_KEY));
    else if (clazz.equals(MockInstance.class))
        return new MockInstance(
                conf.get(AccumuloConstants.INSTANCE_NAME_KEY, AccumuloConstants.DEFAULT_INSTANCE_NAME));
    else
        throw new IllegalArgumentException(instClass + "is not a valid instance class");
}

From source file:com.bah.culvert.Client.java

License:Apache License

/**
 * Get the indices assigned to this client.
 * @return The indices for this table./*from w  w w.j  a va 2  s.  c om*/
 */
public Index[] getIndicesForTable(String tableName) {
    String[] indexNames = this.configuration.getStrings(INDEXES_CONF_KEY);
    List<Index> indices = new ArrayList<Index>();
    for (int i = 0; i < indexNames.length; i++) {
        String name = indexNames[i];
        Class<?> indexClass = configuration.getClass(indexClassConfKey(name), null);
        Configuration indexConf = ConfUtils.unpackConfigurationInPrefix(indexConfPrefix(name), configuration);
        String primaryTableName = indexConf.get(Index.PRIMARY_TABLE_CONF_KEY);
        if (tableName.equals(primaryTableName)) {
            Index index;
            try {
                index = Index.class.cast(indexClass.newInstance());
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
            index.setConf(indexConf);
            indices.add(index);
        }
    }
    return indices.toArray(new Index[indices.size()]);
}

From source file:com.bah.culvert.configuration.ConfigurationTest.java

License:Apache License

@Test
public void loadConfigurationTest() {
    Configuration conf = null;

    try {//from  w w w  .java  2s .c om
        conf = CConfiguration.getDefault();
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (conf != null) {
        Assert.assertEquals(conf.get("culvert.tableadapter"), "hbase");
    }
}

From source file:com.bah.culvert.configuration.ConfigurationTest.java

License:Apache License

@Test
public void incorporatesNewConfItems() {
    Configuration conf = new Configuration();
    String v1 = conf.iterator().next().getKey();
    conf.set(v1, "a special value");

    Configuration c2 = CConfiguration.create(conf);
    Assert.assertEquals("a special value", c2.get(v1));
}

From source file:com.bah.culvert.data.index.Index.java

License:Apache License

/**
 * Get the contents of a key that might be binary.
 * @param isBinarySettingKey Tells us weather or not the field is binary.
 * @param potentiallyBinaryEncodedSetting The actual field name that might
 *        contain binary data.// w  w  w  . j a  v  a 2  s .  co m
 * @param conf The configuration to retrieve from
 * @return The decoded value to return.
 */
private static byte[] getBinaryConfSetting(String isBinarySettingKey, String potentiallyBinaryEncodedSetting,
        Configuration conf) {
    String value = conf.get(potentiallyBinaryEncodedSetting);
    boolean isBase64 = conf.getBoolean(isBinarySettingKey, false);
    if (isBase64) {
        return Base64.decodeBase64(value.getBytes());
    } else {
        return value.getBytes();
    }
}

From source file:com.bah.culvert.data.index.Index.java

License:Apache License

/**
 * Gets a table adapter from a configuration.
 * @param conf//from  www  .  j a  v a 2  s  .com
 * @param adapterSetting
 * @return
 */
private static TableAdapter getTableAdapter(Configuration conf, String adapterSetting) {
    DatabaseAdapter db = getDatabaseAdapter(conf);
    String tableName = conf.get(adapterSetting);
    return db.getTableAdapter(tableName);
}

From source file:com.bah.culvert.hive.CulvertHiveUtils.java

License:Apache License

/**
 * Get the culvert mapping string. See/*from w w  w .  j av  a  2s  .c o m*/
 * {@link #getIndexMappings(Configuration)} for the format.
 * 
 * @param conf The configuration to get the mapping string from.
 * @return The unparsed mappings string.
 */
public static String getCulvertMapping(Configuration conf) {
    return conf.get(CULVERT_HIVE_MAPPING_CONF_KEY);
}