AMBARI-25126.fix ambari-metric exception printed in namenode (#16) master
authorasagjj <shenyinjie@cmss.chinamobile.com>
Mon, 1 Apr 2019 17:45:38 +0000 (01:45 +0800)
committeravijayanhwx <14299376+avijayanhwx@users.noreply.github.com>
Mon, 1 Apr 2019 17:45:38 +0000 (10:45 -0700)
* AMBARI-25126.fix ambari-metric exception printed in namenode

* Delete ambari-metrics.iml

ambari-metrics-common/src/main/java/org/apache/hadoop/metrics2/sink/timeline/availability/MetricSinkWriteShardHostnameHashingStrategy.java

index 25bff549d48c35817433422d550c90e10268b4ad..c79bbfb087e3154591b005afd0f222b639cbf060 100644 (file)
@@ -36,6 +36,10 @@ public class MetricSinkWriteShardHostnameHashingStrategy implements MetricSinkWr
 
   @Override
   public String findCollectorShard(List<String> collectorHosts) {
+    if(collectorHosts.size() ==0) {
+      LOG.warn("No metrics collectors alive, please check collector status!");
+      return "";
+    }
     long index = hostnameHash % collectorHosts.size();
     index = index < 0 ? index + collectorHosts.size() : index;
     String collectorHost = collectorHosts.get((int) index);