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

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

Introduction

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

Prototype

public URL getResource(String name) 

Source Link

Document

Get the URL for the named resource.

Usage

From source file:org.apache.nutch.indexer.geoip.GeoIPIndexingFilter.java

License:Apache License

/**
 * @see org.apache.hadoop.conf.Configurable#setConf(org.apache.hadoop.conf.Configuration)
 *///w w w .  j  a  va2  s.c o m
@Override
public void setConf(Configuration conf) {
    this.conf = conf;
    usage = conf.get("index.geoip.usage", "insightsService");
    LOG.debug("GeoIP usage medium set to: {}", usage);
    if (usage.equalsIgnoreCase("insightsService")) {
        client = new WebServiceClient.Builder(conf.getInt("index.geoip.userid", 12345),
                conf.get("index.geoip.licensekey")).build();
    } else {
        String db = null;
        if (usage.equalsIgnoreCase("cityDatabase")) {
            db = "GeoIP2-City.mmdb";
        } else if (usage.equalsIgnoreCase("connectionTypeDatabase")) {
            db = "GeoIP2-Connection-Type.mmdb";
        } else if (usage.equalsIgnoreCase("domainDatabase")) {
            db = "GeoIP2-Domain.mmdb";
        } else if (usage.equalsIgnoreCase("ispDatabase")) {
            db = "GeoIP2-ISP.mmdb";
        }
        URL dbFileUrl = conf.getResource(db);
        if (dbFileUrl == null) {
            LOG.error("GeoDb file {} not found on classpath", db);
        } else {
            try {
                buildDb(new File(dbFileUrl.getFile()));
            } catch (Exception e) {
                LOG.error("Failed to read geoDb file {}: ", db, e);
            }
        }
    }
    if (!conf.getBoolean("store.ip.address", false)) {
        LOG.warn("Plugin index-geoip is active but IP address is not stored" + "(store.ip.address == false)");
    }
}

From source file:org.apache.pulsar.io.hdfs.AbstractHdfsConnector.java

License:Apache License

private static Configuration getConfig(final Configuration config, String res) throws IOException {
    boolean foundResources = false;
    if (null != res) {
        String[] resources = res.split(",");
        for (String resource : resources) {
            config.addResource(new Path(resource.trim()));
            foundResources = true;/*from   w  w  w.j a  va  2 s  .c  o m*/
        }
    }

    if (!foundResources) {
        // check that at least 1 non-default resource is available on the classpath
        String configStr = config.toString();
        for (String resource : configStr.substring(configStr.indexOf(":") + 1).split(",")) {
            if (!resource.contains("default") && config.getResource(resource.trim()) != null) {
                foundResources = true;
                break;
            }
        }
    }

    if (!foundResources) {
        throw new IOException("Could not find any of the " + res + " on the classpath");
    }
    return config;
}