Browse Source

AMBARI-6299. JMXPropertyProvider makes call to endpoint without checking support for properties. (swagle via yusaku)

Yusaku Sako 11 years ago
parent
commit
e6a0d45d6c

+ 13 - 0
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AbstractPropertyProvider.java

@@ -297,4 +297,17 @@ public abstract class AbstractPropertyProvider extends BaseProvider implements P
 
     }
   }
+
+  /**
+   * Verify that the component metrics contains the property id.
+   * @param componentName Name of the component
+   * @param propertyId Property Id
+   * @return true/false
+   */
+  protected boolean isSupportedPropertyId(String componentName, String propertyId) {
+    Map<String, PropertyInfo> componentMetricMap = componentMetrics.get(componentName);
+
+    return componentMetricMap != null
+      && (componentMetricMap.containsKey(propertyId) || checkCategory(propertyId));
+  }
 }

+ 2 - 2
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/BaseProvider.java

@@ -170,10 +170,10 @@ public abstract class BaseProvider {
    * Check the categories to account for map properties where the entries will not be
    * in the provider property list ids but the map (category) might be.
    */
-  private boolean checkCategory(String unsupportedPropertyId) {
+  protected boolean checkCategory(String unsupportedPropertyId) {
     String category = PropertyHelper.getPropertyCategory(unsupportedPropertyId);
     while (category != null) {
-      if( this.propertyIds.contains(category)) {
+      if(this.categoryIds.contains(category)) {
         return true;
       }
       category = PropertyHelper.getPropertyCategory(category);

+ 12 - 10
ambari-server/src/main/java/org/apache/ambari/server/controller/jmx/JMXPropertyProvider.java

@@ -295,14 +295,23 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
       throws SystemException {
 
     Set<String> ids = getRequestPropertyIds(request, predicate);
-    Set<String> temporalIds = new HashSet<String>();
+    Set<String> unsupportedIds = new HashSet<String>();
+    String componentName = (String) resource.getPropertyValue(componentNamePropertyId);
+
+    if (getComponentMetrics().get(componentName) == null) {
+      // If there are no metrics defined for the given component then there is nothing to do.
+      return resource;
+    }
 
     for (String id : ids) {
       if (request.getTemporalInfo(id) != null) {
-        temporalIds.add(id);
+        unsupportedIds.add(id);
+      }
+      if (!isSupportedPropertyId(componentName, id)) {
+        unsupportedIds.add(id);
       }
     }
-    ids.removeAll(temporalIds);
+    ids.removeAll(unsupportedIds);
 
     if (ids.isEmpty()) {
       // no properties requested
@@ -317,13 +326,6 @@ public class JMXPropertyProvider extends AbstractPropertyProvider {
       }
     }
 
-    String componentName = (String) resource.getPropertyValue(componentNamePropertyId);
-
-    if (getComponentMetrics().get(componentName) == null) {
-      // If there are no metrics defined for the given component then there is nothing to do.
-      return resource;
-    }
-
     String clusterName = (String) resource.getPropertyValue(clusterNamePropertyId);
 
     String port = getPort(clusterName, componentName);