|
@@ -259,7 +259,18 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
*/
|
|
|
private static final WeakHashMap<Configuration,Object> REGISTRY =
|
|
|
new WeakHashMap<Configuration,Object>();
|
|
|
-
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Map to register all classes holding property tag enums.
|
|
|
+ */
|
|
|
+ private static final Map<String, Class>
|
|
|
+ REGISTERED_TAG_CLASS = new HashMap<>();
|
|
|
+ /**
|
|
|
+ * Map to hold properties by there tag groupings.
|
|
|
+ */
|
|
|
+ private final Map<PropertyTag, Properties> propertyTagsMap =
|
|
|
+ new ConcurrentHashMap<>();
|
|
|
+
|
|
|
/**
|
|
|
* List of default Resources. Resources are loaded in the order of the list
|
|
|
* entries
|
|
@@ -738,6 +749,12 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
public Configuration(boolean loadDefaults) {
|
|
|
this.loadDefaults = loadDefaults;
|
|
|
updatingResource = new ConcurrentHashMap<String, String[]>();
|
|
|
+
|
|
|
+ // Register all classes holding property tags with
|
|
|
+ REGISTERED_TAG_CLASS.put("core", CorePropertyTag.class);
|
|
|
+ REGISTERED_TAG_CLASS.put("hdfs", HDFSPropertyTag.class);
|
|
|
+ REGISTERED_TAG_CLASS.put("yarn", YarnPropertyTag.class);
|
|
|
+
|
|
|
synchronized(Configuration.class) {
|
|
|
REGISTRY.put(this, null);
|
|
|
}
|
|
@@ -765,6 +782,8 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
this.finalParameters = Collections.newSetFromMap(
|
|
|
new ConcurrentHashMap<String, Boolean>());
|
|
|
this.finalParameters.addAll(other.finalParameters);
|
|
|
+ this.REGISTERED_TAG_CLASS.putAll(other.REGISTERED_TAG_CLASS);
|
|
|
+ this.propertyTagsMap.putAll(other.propertyTagsMap);
|
|
|
}
|
|
|
|
|
|
synchronized(Configuration.class) {
|
|
@@ -2823,6 +2842,10 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
} else if ("source".equals(propertyAttr)) {
|
|
|
confSource.add(StringInterner.weakIntern(
|
|
|
reader.getAttributeValue(i)));
|
|
|
+ } else if ("tag".equals(propertyAttr)) {
|
|
|
+ //Read tags and put them in propertyTagsMap
|
|
|
+ readTagFromConfig(reader.getAttributeValue(i), confName,
|
|
|
+ confValue, confSource);
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
@@ -2830,6 +2853,7 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
case "value":
|
|
|
case "final":
|
|
|
case "source":
|
|
|
+ case "tag":
|
|
|
parseToken = true;
|
|
|
token.setLength(0);
|
|
|
break;
|
|
@@ -2911,6 +2935,13 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
case "source":
|
|
|
confSource.add(StringInterner.weakIntern(token.toString()));
|
|
|
break;
|
|
|
+ case "tag":
|
|
|
+ if (token.length() > 0) {
|
|
|
+ //Read tags and put them in propertyTagsMap
|
|
|
+ readTagFromConfig(token.toString(), confName,
|
|
|
+ confValue, confSource);
|
|
|
+ }
|
|
|
+ break;
|
|
|
case "include":
|
|
|
if (fallbackAllowed && !fallbackEntered) {
|
|
|
throw new IOException("Fetch fail on include for '"
|
|
@@ -2962,6 +2993,48 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void readTagFromConfig(String attributeValue, String confName, String
|
|
|
+ confValue, List<String> confSource) {
|
|
|
+ for (String tagStr : attributeValue.split(",")) {
|
|
|
+ tagStr = tagStr.trim();
|
|
|
+ try {
|
|
|
+ if (confSource.size() > 0) {
|
|
|
+ for (String source : confSource) {
|
|
|
+ PropertyTag tag1 = this.getPropertyTag(tagStr,
|
|
|
+ source.split("-")[0]);
|
|
|
+ if (propertyTagsMap.containsKey(tag1)) {
|
|
|
+ propertyTagsMap.get(tag1)
|
|
|
+ .setProperty(confName, confValue);
|
|
|
+ } else {
|
|
|
+ Properties props = new Properties();
|
|
|
+ props.setProperty(confName, confValue);
|
|
|
+ propertyTagsMap.put(tag1, props);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //If no source is set try to find tag in CorePropertyTag
|
|
|
+ if (propertyTagsMap
|
|
|
+ .containsKey(CorePropertyTag.valueOf(tagStr)
|
|
|
+ )) {
|
|
|
+ propertyTagsMap.get(CorePropertyTag.valueOf(tagStr))
|
|
|
+ .setProperty(confName, confValue);
|
|
|
+ } else {
|
|
|
+ Properties props = new Properties();
|
|
|
+ props.setProperty(confName, confValue);
|
|
|
+ propertyTagsMap.put(CorePropertyTag.valueOf(tagStr),
|
|
|
+ props);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IllegalArgumentException iae) {
|
|
|
+ //Log the invalid tag and continue to parse rest of the
|
|
|
+ // properties.
|
|
|
+ LOG.info("Invalid tag '" + tagStr + "' found for "
|
|
|
+ + "property:" + confName, iae);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void overlay(Properties to, Properties from) {
|
|
|
for (Entry<Object, Object> entry: from.entrySet()) {
|
|
|
to.put(entry.getKey(), entry.getValue());
|
|
@@ -3438,4 +3511,45 @@ public class Configuration implements Iterable<Map.Entry<String,String>>,
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get all properties belonging to tag.
|
|
|
+ * @return Properties with matching properties
|
|
|
+ */
|
|
|
+ public Properties getAllPropertiesByTag(final PropertyTag tag) {
|
|
|
+ Properties props = new Properties();
|
|
|
+ if (propertyTagsMap.containsKey(tag)) {
|
|
|
+ props.putAll(propertyTagsMap.get(tag));
|
|
|
+ }
|
|
|
+ return props;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get all properties belonging to list of input tags. Calls
|
|
|
+ * getAllPropertiesByTag internally.
|
|
|
+ *
|
|
|
+ * @return Properties with all matching properties
|
|
|
+ */
|
|
|
+ public Properties getAllPropertiesByTags(final List<PropertyTag> tagList) {
|
|
|
+ Properties prop = new Properties();
|
|
|
+ for (PropertyTag tag : tagList) {
|
|
|
+ prop.putAll(this.getAllPropertiesByTag(tag));
|
|
|
+ }
|
|
|
+ return prop;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get Property tag Enum corresponding to given source.
|
|
|
+ *
|
|
|
+ * @param tagStr String representation of Enum
|
|
|
+ * @param group Group to which enum belongs.Ex hdfs,yarn
|
|
|
+ * @return Properties with all matching properties
|
|
|
+ */
|
|
|
+ private PropertyTag getPropertyTag(String tagStr, String group) {
|
|
|
+ PropertyTag tag = null;
|
|
|
+ if (REGISTERED_TAG_CLASS.containsKey(group)) {
|
|
|
+ tag = (PropertyTag) Enum.valueOf(REGISTERED_TAG_CLASS.get(group), tagStr);
|
|
|
+ }
|
|
|
+ return tag;
|
|
|
+ }
|
|
|
}
|