|
@@ -18,8 +18,6 @@
|
|
|
|
|
|
package org.apache.ambari.server.controller.internal;
|
|
package org.apache.ambari.server.controller.internal;
|
|
|
|
|
|
-import org.apache.ambari.server.api.util.TreeNode;
|
|
|
|
-import org.apache.ambari.server.api.util.TreeNodeImpl;
|
|
|
|
import org.apache.ambari.server.controller.spi.Resource;
|
|
import org.apache.ambari.server.controller.spi.Resource;
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
import org.apache.ambari.server.controller.utilities.PropertyHelper;
|
|
|
|
|
|
@@ -37,11 +35,9 @@ public class ResourceImpl implements Resource {
|
|
private final Type type;
|
|
private final Type type;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Tree of categories/properties.
|
|
|
|
- * Each category is a sub node and each node contains a map of properties(n/v pairs).
|
|
|
|
|
|
+ * The map of property maps keyed by property category.
|
|
*/
|
|
*/
|
|
- private final TreeNode<Map<String, Object>> m_treeProperties =
|
|
|
|
- new TreeNodeImpl<Map<String, Object>>(null, new HashMap<String, Object>(), null);
|
|
|
|
|
|
+ private final Map<String, Map<String, Object>> propertiesMap = new HashMap<String, Map<String, Object>>();
|
|
|
|
|
|
|
|
|
|
// ----- Constructors ------------------------------------------------------
|
|
// ----- Constructors ------------------------------------------------------
|
|
@@ -84,68 +80,37 @@ public class ResourceImpl implements Resource {
|
|
return type;
|
|
return type;
|
|
}
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
|
- public TreeNode<Map<String, Object>> getProperties() {
|
|
|
|
- return m_treeProperties;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
@Override
|
|
@Override
|
|
public Map<String, Map<String, Object>> getPropertiesMap() {
|
|
public Map<String, Map<String, Object>> getPropertiesMap() {
|
|
- Map<String, Map<String, Object>> mapProps = new HashMap<String, Map<String, Object>>();
|
|
|
|
- addNodeToMap(m_treeProperties, mapProps, null);
|
|
|
|
-
|
|
|
|
- return mapProps;
|
|
|
|
|
|
+ return propertiesMap;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void setProperty(String id, Object value) {
|
|
public void setProperty(String id, Object value) {
|
|
String category = PropertyHelper.getPropertyCategory(id);
|
|
String category = PropertyHelper.getPropertyCategory(id);
|
|
- TreeNode<Map<String, Object>> node;
|
|
|
|
- if (category == null) {
|
|
|
|
- node = m_treeProperties;
|
|
|
|
- } else {
|
|
|
|
- node = m_treeProperties.getChild(category);
|
|
|
|
- if (node == null) {
|
|
|
|
- String[] tokens = category.split("/");
|
|
|
|
- node = m_treeProperties;
|
|
|
|
- for (String t : tokens) {
|
|
|
|
- TreeNode<Map<String, Object>> child = node.getChild(t);
|
|
|
|
- if (child == null) {
|
|
|
|
- child = node.addChild(new HashMap<String, Object>(), t);
|
|
|
|
- }
|
|
|
|
- node = child;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ Map<String, Object> properties = propertiesMap.get(category);
|
|
|
|
+ if (properties == null) {
|
|
|
|
+ properties = new HashMap<String, Object>();
|
|
|
|
+ propertiesMap.put(category, properties);
|
|
}
|
|
}
|
|
- node.getObject().put(PropertyHelper.getPropertyName(id), value);
|
|
|
|
|
|
+ properties.put(PropertyHelper.getPropertyName(id), value);
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void addCategory(String id) {
|
|
public void addCategory(String id) {
|
|
- TreeNode<Map<String, Object>> node;
|
|
|
|
- if (id != null) {
|
|
|
|
- node = m_treeProperties.getChild(id);
|
|
|
|
- if (node == null) {
|
|
|
|
- String[] tokens = id.split("/");
|
|
|
|
- node = m_treeProperties;
|
|
|
|
- for (String t : tokens) {
|
|
|
|
- TreeNode<Map<String, Object>> child = node.getChild(t);
|
|
|
|
- if (child == null) {
|
|
|
|
- child = node.addChild(new HashMap<String, Object>(), t);
|
|
|
|
- }
|
|
|
|
- node = child;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ if (!propertiesMap.containsKey(id)) {
|
|
|
|
+ propertiesMap.put(id, new HashMap<String, Object>());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Object getPropertyValue(String id) {
|
|
public Object getPropertyValue(String id) {
|
|
- String category = PropertyHelper.getPropertyCategory(id);
|
|
|
|
- TreeNode<Map<String, Object>> node = (category == null) ? m_treeProperties :
|
|
|
|
- m_treeProperties.getChild(category);
|
|
|
|
|
|
+ Map<String, Object> properties =
|
|
|
|
+ propertiesMap.get(PropertyHelper.getPropertyCategory(id));
|
|
|
|
|
|
- return node == null ? null : node.getObject().get(PropertyHelper.getPropertyName(id));
|
|
|
|
|
|
+ return properties == null ?
|
|
|
|
+ null : properties.get(PropertyHelper.getPropertyName(id));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -157,52 +122,8 @@ public class ResourceImpl implements Resource {
|
|
|
|
|
|
sb.append("Resource : ").append(type).append("\n");
|
|
sb.append("Resource : ").append(type).append("\n");
|
|
sb.append("Properties:\n");
|
|
sb.append("Properties:\n");
|
|
-
|
|
|
|
- printPropertyNode(m_treeProperties, sb, null, " ");
|
|
|
|
|
|
+ sb.append(propertiesMap);
|
|
|
|
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- // ----- class private methods ---------------------------------------------
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Recursively prints the properties for a given node and it's children to a StringBuffer.
|
|
|
|
- *
|
|
|
|
- * @param node the node to print properties for
|
|
|
|
- * @param sb the SringBuffer to print to
|
|
|
|
- * @param category the absolute category name
|
|
|
|
- * @param indent the indent to be used
|
|
|
|
- */
|
|
|
|
- private void printPropertyNode(TreeNode<Map<String, Object>> node, StringBuilder sb, String category, String indent) {
|
|
|
|
- if (node.getParent() != null) {
|
|
|
|
- category = category == null ? node.getName() : category + '/' + node.getName();
|
|
|
|
- sb.append(indent).append("Category: ").append(category).append('\n');
|
|
|
|
- indent += " ";
|
|
|
|
- }
|
|
|
|
- for (Map.Entry<String, Object> entry : node.getObject().entrySet()) {
|
|
|
|
- sb.append(indent).append(entry.getKey()).append('=').append(entry.getValue()).append('\n');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- for (TreeNode<Map<String, Object>> n : node.getChildren()) {
|
|
|
|
- printPropertyNode(n, sb, category, indent);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * Add the node properties to the specified map.
|
|
|
|
- * Makes recursive calls for each child node.
|
|
|
|
- *
|
|
|
|
- * @param node the node whose properties are to be added
|
|
|
|
- * @param mapProps the map that the props are to be added to
|
|
|
|
- * @param path the current category hierarchy
|
|
|
|
- */
|
|
|
|
- private void addNodeToMap(TreeNode<Map<String, Object>> node, Map<String, Map<String, Object>> mapProps, String path) {
|
|
|
|
- path = path == null ? node.getName() : path + "/" + node.getName();
|
|
|
|
- mapProps.put(path, node.getObject());
|
|
|
|
-
|
|
|
|
- for (TreeNode<Map<String, Object>> child : node.getChildren()) {
|
|
|
|
- addNodeToMap(child, mapProps, path);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|