Ver código fonte

AMBARI-11434. After cluster installation accessing DATANODE host component results in NPE due to bad metrics JSON (dlysnichenko)

Lisnichenko Dmitro 10 anos atrás
pai
commit
1a6dd84d24

+ 7 - 5
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/StackDefinedPropertyProvider.java

@@ -248,11 +248,13 @@ public class StackDefinedPropertyProvider implements PropertyProvider {
 
     for (Entry<String, Metric> entry : def.getMetrics().entrySet()) {
       Metric metric = entry.getValue();
-      PropertyInfo propertyInfo = new PropertyInfo(metric.getName(),
-        metric.isTemporal(), metric.isPointInTime());
-      propertyInfo.setAmsHostMetric(metric.isAmsHostMetric());
-      propertyInfo.setUnit(metric.getUnit());
-      defs.put(entry.getKey(), propertyInfo);
+      if (metric.getName() != null) {
+        PropertyInfo propertyInfo = new PropertyInfo(metric.getName(),
+                metric.isTemporal(), metric.isPointInTime());
+        propertyInfo.setAmsHostMetric(metric.isAmsHostMetric());
+        propertyInfo.setUnit(metric.getUnit());
+        defs.put(entry.getKey(), propertyInfo);
+      }
     }
 
     return defs;

+ 2 - 0
ambari-server/src/test/java/org/apache/ambari/server/controller/metrics/RestMetricsPropertyProviderTest.java

@@ -82,6 +82,7 @@ public class RestMetricsPropertyProviderTest {
     componentMetrics.put("metrics/api/cluster/summary/slots.used", new Metric("/api/cluster/summary##slots.used", false, false, false, "unitless"));
     componentMetrics.put("metrics/api/cluster/summary/topologies", new Metric("/api/cluster/summary##topologies", false, false, false, "unitless"));
     componentMetrics.put("metrics/api/cluster/summary/nimbus.uptime", new Metric("/api/cluster/summary##nimbus.uptime", false, false, false, "unitless"));
+    componentMetrics.put("metrics/api/cluster/summary/wrong.metric", new Metric(null, false, false, false, "unitless"));
   }
 
 
@@ -132,6 +133,7 @@ public class RestMetricsPropertyProviderTest {
     Request request = PropertyHelper.getReadRequest(Collections.<String>emptySet());
 
     Assert.assertEquals(1, restMetricsPropertyProvider.populateResources(Collections.singleton(resource), request, null).size());
+    Assert.assertNull(resource.getPropertyValue(PropertyHelper.getPropertyId("metrics/api/cluster/summary", "wrong.metric")));
 
     //STORM_REST_API
     Assert.assertEquals(28.0, resource.getPropertyValue(PropertyHelper.getPropertyId("metrics/api/cluster/summary", "tasks.total")));