AMBARI-25126.fix ambari-metric exception printed in namenode (#16)
[ambari-metrics.git] / 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) {
 
   @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);
     long index = hostnameHash % collectorHosts.size();
     index = index < 0 ? index + collectorHosts.size() : index;
     String collectorHost = collectorHosts.get((int) index);