本文整理匯總了Java中org.apache.hadoop.conf.Configuration.getValByRegex方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.getValByRegex方法的具體用法?Java Configuration.getValByRegex怎麽用?Java Configuration.getValByRegex使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.hadoop.conf.Configuration
的用法示例。
在下文中一共展示了Configuration.getValByRegex方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: expandEnv
import org.apache.hadoop.conf.Configuration; //導入方法依賴的package包/類
private static void expandEnv(Configuration conf) {
Map<String, String> kvs = conf.getValByRegex("angel.*");
Pattern pattern = Pattern.compile("\\$\\{[\\p{Alnum}\\p{Punct}]+?\\}");
for (Map.Entry<String, String> kv : kvs.entrySet()) {
String value = kv.getValue();
Matcher matcher = pattern.matcher(value);
List<String> keys = new ArrayList<String>();
while (matcher.find()) {
String matchedStr = matcher.group();
keys.add(matchedStr.substring(2, matchedStr.length() - 1));
}
int size = keys.size();
for (int i = 0; i < size; i++) {
String envValue = System.getenv(keys.get(i));
if (envValue == null) {
LOG.warn("env " + keys.get(i) + " is null, please check.");
continue;
}
value = value.replaceAll("\\$\\{" + keys.get(i) + "\\}", envValue);
}
conf.set(kv.getKey(), value);
}
// Add default fs(local fs) for lib jars.
String libJars = conf.get(AngelConf.ANGEL_JOB_LIBJARS);
if (libJars != null) {
StringBuilder sb = new StringBuilder();
String[] jars = libJars.split(",");
for (int i = 0; i < jars.length; i++) {
if (new Path(jars[i]).isAbsoluteAndSchemeAuthorityNull()) {
sb.append("file://").append(jars[i]);
if (i != jars.length - 1) {
sb.append(",");
}
} else {
sb.append(jars[i]);
if (i != jars.length - 1) {
sb.append(",");
}
}
}
conf.set(AngelConf.ANGEL_JOB_LIBJARS, sb.toString());
LOG.info("jars loaded: " + sb.toString());
}
}