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

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

Introduction

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

Prototype

@InterfaceStability.Unstable
public synchronized String[] getPropertySources(String name) 

Source Link

Document

Gets information about why a property was set.

Usage

From source file:co.cask.cdap.gateway.handlers.ConfigService.java

License:Apache License

private List<ConfigEntry> toConfigEntries(Configuration configuration) {
    List<ConfigEntry> result = Lists.newArrayList();
    for (Map.Entry<String, String> entry : configuration) {
        String source = getFirstElement(configuration.getPropertySources(entry.getKey()));
        result.add(new ConfigEntry(entry.getKey(), entry.getValue(), source));
    }//from   w  w  w .  ja  v a  2 s . c o  m
    return result;
}

From source file:co.cask.cdap.internal.app.runtime.batch.MapReduceRuntimeService.java

License:Apache License

private boolean isProgrammaticConfig(Configuration conf, String name) {
    String[] sources = conf.getPropertySources(name);
    return sources != null && sources.length > 0
            && PROGRAMATIC_SOURCE_PATTERN.matcher(sources[sources.length - 1]).matches();
}

From source file:com.cloudera.recordservice.mr.PlanUtil.java

License:Apache License

/**
 * Return all configuration properties info (name, value, and source).
 * This is useful for debugging.//from   w w  w.  j ava 2s  .  co m
 * If `dumpAll` is false, only dump properties that start with 'recordservice'.
 * Otherwise, it dumps all properties in the `conf`.
 */
public static String dumpConfiguration(Configuration conf, boolean dumpAll) {
    // TODO: how do we handle SparkConf and SQLConf? Seems like they didn't offer
    // facility to track a property to its source.
    StringBuilder sb = new StringBuilder();
    sb.append('\n');
    sb.append("=============== Begin of Configuration Properties Info ===============");
    for (Map.Entry<String, String> e : conf) {
        if (!dumpAll && !e.getKey().startsWith("recordservice"))
            continue;
        String[] sources = conf.getPropertySources(e.getKey());
        String source;
        if (sources == null || sources.length == 0) {
            source = "Not Found";
        } else {
            // Only get the newest source that this property comes from.
            source = sources[sources.length - 1];
            URL url = conf.getResource(source);
            // If there's a URL with this resource, use that.
            if (url != null)
                source = url.toString();
        }
        sb.append('\n');
        sb.append(String.format("Property Name: %s\tValue: %s\tSource: %s", e.getKey(), e.getValue(), source));
    }
    sb.append('\n');
    sb.append("================ End of Configuration Properties Info ================");
    return sb.toString();
}

From source file:com.google.mr4c.hadoop.HadoopUtils.java

License:Open Source License

/**
  * Generates human readable string with property name, value, and source
*/// www .  jav a 2 s.c  o m
public static String describeConfProp(Configuration conf, String name) {
    String val = conf.get(name);
    String[] srcs = conf.getPropertySources(name);
    String source = srcs == null ? "unknown" : Arrays.toString(srcs);
    return String.format("%s=%s; source: %s", name, val, source);
}

From source file:org.apache.hoya.tools.ConfigHelper.java

License:Apache License

/**
 * Propagate a property from a source to a dest config, with a best-effort
 * attempt at propagating the origin./*from   w w w. ja  va 2  s . c  o m*/
 * If the 
 * @param dest destination
 * @param src source
 * @param key key to try to copy
 * @return true if the key was found and propagated
 */
public static boolean propagate(Configuration dest, Configuration src, String key) {
    String val = src.get(key);
    if (val != null) {
        String[] origin = src.getPropertySources(key);
        if (origin != null && origin.length > 0) {
            dest.set(key, val, origin[0]);
        } else {
            dest.set(key, val);
            return true;
        }
    }
    return false;
}

From source file:org.apache.twill.internal.appmaster.ApplicationMasterMain.java

License:Apache License

/**
 * Optionally sets the RM scheduler address based on the environment variable if it is not set in the cluster config.
 *//*from  ww w  . java  2 s  . c  o  m*/
private static void setRMSchedulerAddress(Configuration conf) {
    String schedulerAddress = System.getenv(EnvKeys.YARN_RM_SCHEDULER_ADDRESS);
    if (schedulerAddress == null) {
        return;
    }

    // If the RM scheduler address is not in the config or it's from yarn-default.xml,
    // replace it with the one from the env, which is the same as the one client connected to.
    String[] sources = conf.getPropertySources(YarnConfiguration.RM_SCHEDULER_ADDRESS);
    if (sources == null || sources.length == 0 || "yarn-default.xml".equals(sources[sources.length - 1])) {
        conf.set(YarnConfiguration.RM_SCHEDULER_ADDRESS, schedulerAddress);
    }
}