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

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

Introduction

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

Prototype

public void addResource(Configuration conf) 

Source Link

Document

Add a configuration resource.

Usage

From source file:org.apache.flink.tachyon.TachyonFileSystemWrapperTest.java

License:Apache License

@Test
public void testHadoopLoadability() {
    try {//from   w ww.j a v a2 s . c  o  m
        Path tPath = new Path(input);
        Configuration conf = new Configuration();
        conf.addResource(HADOOP_CONFIG_PATH);
        Assert.assertEquals("tachyon.hadoop.TFS", conf.get("fs.tachyon.impl", null));
        tPath.getFileSystem(conf);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Test failed with exception: " + e.getMessage());
    }
}

From source file:org.apache.gobblin.broker.SharedResourcesBrokerFactory.java

License:Apache License

private static Config addSystemConfigurationToConfig(Config config) {
    Map<String, String> confMap = Maps.newHashMap();
    addBrokerKeys(confMap, System.getenv().entrySet());
    addBrokerKeys(confMap, System.getProperties().entrySet());

    Config systemConfig = ConfigFactory.parseMap(confMap);

    Config tmpConfig = config.withFallback(systemConfig);
    String brokerConfPath = DEFAULT_BROKER_CONF_FILE;
    if (tmpConfig.hasPath(BROKER_CONF_FILE_KEY)) {
        brokerConfPath = tmpConfig.getString(BROKER_CONF_FILE_KEY);
    }//w w w. j ava 2 s  .c om

    Config resourceConfig = ConfigFactory.parseResources(SharedResourcesBrokerFactory.class, brokerConfPath);

    config = config.withFallback(resourceConfig).withFallback(systemConfig);

    if (ConfigUtils.getBoolean(config, LOAD_HADOOP_CONFIGURATION, true)) {
        Map<String, String> hadoopConfMap = Maps.newHashMap();
        Configuration hadoopConf = new Configuration();
        hadoopConf.addResource("gobblin-site.xml");
        addBrokerKeys(hadoopConfMap, hadoopConf);
        config = config.withFallback(ConfigFactory.parseMap(hadoopConfMap));
    }

    return config;
}

From source file:org.apache.hama.bsp.ApplicationMaster.java

License:Apache License

/**
 * Reads the configuration from the given path.
 *//* ww w . j  av a 2s  .  c  o m*/
private static Configuration getSubmitConfiguration(String path) throws IOException {
    Path jobSubmitPath = new Path(path);
    Configuration jobConf = new HamaConfiguration();

    FileSystem fs = FileSystem.get(URI.create(path), jobConf);

    InputStream in = fs.open(jobSubmitPath);
    jobConf.addResource(in);

    return jobConf;
}

From source file:org.apache.hama.HamaConfiguration.java

License:Apache License

/**
 * Adds Hama configuration files to a Configuration
 *//*from www.j  a  va 2  s  . co m*/
private static Configuration addHamaResources(Configuration conf) {
    conf.addResource("hama-default.xml");
    conf.addResource("hama-site.xml");
    return conf;

}

From source file:org.apache.hawq.pxf.service.utilities.SecureLogin.java

License:Apache License

public static void login() {
    try {//from  w w w  .  jav  a2  s .  c om
        Configuration config = new Configuration();
        config.addResource("pxf-site.xml");

        SecurityUtil.login(config, CONFIG_KEY_SERVICE_KEYTAB, CONFIG_KEY_SERVICE_PRINCIPAL);
    } catch (Exception e) {
        LOG.error("PXF service login failed");
        throw new RuntimeException(e);
    }
}

From source file:org.apache.hcatalog.hbase.snapshot.RevisionManagerConfiguration.java

License:Apache License

public static Configuration addResources(Configuration conf) {
    conf.addDefaultResource("revision-manager-default.xml");
    conf.addResource("revision-manager-site.xml");
    return conf;/*from ww w. jav  a2 s . c om*/
}

From source file:org.apache.hconf2prop.Main.java

License:Apache License

public static void convert(String arg) throws IOException {

    File input = new File(arg);
    if (!input.isFile() || !input.canRead()) {
        throw new IllegalArgumentException(arg);
    }/*ww w  .  j  a v a 2 s .  c o  m*/

    Configuration conf = new Configuration();
    conf.addResource(new Path(input.toURI()));

    TreeMap<String, String> map = new TreeMap<String, String>();

    Iterator<Map.Entry<String, String>> entries = conf.iterator();
    while (entries.hasNext()) {
        Map.Entry<String, String> entry = entries.next();
        map.put(entry.getKey(), entry.getValue());
    }

    String base = FilenameUtils.getBaseName(input.getName());
    File output = new File(input.getParentFile(), base + ".prop");
    FileOutputStream stream = new FileOutputStream(output);
    Writer writer = new OutputStreamWriter(stream);
    BufferedWriter buffer = new BufferedWriter(writer);
    Iterator<String> keys = map.navigableKeySet().iterator();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = map.get(key);
        String line = String.format("%s = %s", key, value);
        buffer.write(line);
        buffer.newLine();
    }
    buffer.close();

}

From source file:org.apache.hive.beeline.hs2connection.BeelineSiteParser.java

License:Apache License

@Override
public Properties getConnectionProperties() throws BeelineSiteParseException {
    Properties props = new Properties();
    String fileLocation = getFileLocation();
    if (fileLocation == null) {
        log.debug("Could not find Beeline configuration file: {}", DEFAULT_BEELINE_SITE_FILE_NAME);
        return props;
    }//  w  w w. ja  v a2  s .  c  o  m
    log.info("Beeline configuration file at: {}", fileLocation);
    // load the properties from config file
    Configuration conf = new Configuration(false);
    conf.addResource(new Path(new File(fileLocation).toURI()));
    try {
        for (Entry<String, String> kv : conf) {
            String key = kv.getKey();
            if (key.startsWith(BEELINE_CONNECTION_NAMED_JDBC_URL_PREFIX)) {
                props.setProperty(key.substring(BEELINE_CONNECTION_NAMED_JDBC_URL_PREFIX.length()),
                        kv.getValue());
            }
        }
    } catch (Exception e) {
        throw new BeelineSiteParseException(e.getMessage(), e);
    }
    return props;
}

From source file:org.apache.hive.beeline.hs2connection.BeelineSiteParser.java

License:Apache License

public Properties getConnectionProperties(String propertyValue) throws BeelineSiteParseException {
    Properties props = new Properties();
    String fileLocation = getFileLocation();
    if (fileLocation == null) {
        log.debug("Could not find Beeline configuration file: {}", DEFAULT_BEELINE_SITE_FILE_NAME);
        return props;
    }/*w w  w .j  a  va2s.  co  m*/
    log.info("Beeline configuration file at: {}", fileLocation);
    // load the properties from config file
    Configuration conf = new Configuration(false);
    conf.addResource(new Path(new File(fileLocation).toURI()));
    try {
        for (Entry<String, String> kv : conf) {
            String key = kv.getKey();
            if (key.startsWith(BEELINE_CONNECTION_NAMED_JDBC_URL_PREFIX)
                    && (propertyValue.equalsIgnoreCase(kv.getValue()))) {
                props.setProperty(key.substring(BEELINE_CONNECTION_NAMED_JDBC_URL_PREFIX.length()),
                        kv.getValue());
            }
        }
    } catch (Exception e) {
        throw new BeelineSiteParseException(e.getMessage(), e);
    }
    return props;
}

From source file:org.apache.hive.beeline.hs2connection.UserHS2ConnectionFileParser.java

License:Apache License

@Override
public Properties getConnectionProperties() throws BeelineHS2ConnectionFileParseException {
    Properties props = new Properties();
    String fileLocation = getFileLocation();
    if (fileLocation == null) {
        log.debug("User connection configuration file not found");
        return props;
    }/* w  w  w .  ja va 2s .  co m*/
    log.info("Using connection configuration file at " + fileLocation);
    props.setProperty(HS2ConnectionFileParser.URL_PREFIX_PROPERTY_KEY, "jdbc:hive2://");
    // load the properties from config file
    Configuration conf = new Configuration(false);
    conf.addResource(new Path(new File(fileLocation).toURI()));
    try {
        for (Entry<String, String> kv : conf) {
            String key = kv.getKey();
            if (key.startsWith(BEELINE_CONNECTION_PROPERTY_PREFIX)) {
                props.setProperty(key.substring(BEELINE_CONNECTION_PROPERTY_PREFIX.length()), kv.getValue());
            } else {
                log.warn("Ignoring " + key + " since it does not start with "
                        + BEELINE_CONNECTION_PROPERTY_PREFIX);
            }
        }
    } catch (Exception ex) {
        throw new BeelineHS2ConnectionFileParseException(ex.getMessage(), ex);
    }

    return props;
}