Browse Source

Revert "AMBARI-14538. Stale alerts missing host name(s) (dlysnichenko)"

This reverts commit fd1d96ff4465ed1128b96e768cd713d8b2f6bbc8.
Lisnichenko Dmitro 10 years ago
parent
commit
c17e206f83

+ 5 - 50
ambari-server/src/main/java/org/apache/ambari/server/alerts/StaleAlertRunnable.java

@@ -18,7 +18,6 @@
 package org.apache.ambari.server.alerts;
 
 import java.text.MessageFormat;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
@@ -76,10 +75,6 @@ public class StaleAlertRunnable implements Runnable {
    */
   private static final String STALE_ALERTS_MSG = "There are {0} stale alerts from {1} host(s): {2}";
 
-  private static final String TIMED_LABEL_MSG = "{0} ({1})";
-
-  private static final String HOST_LABEL_MSG = "{0}[{1}]";
-
   /**
    * Convert the minutes for the delay of an alert into milliseconds.
    */
@@ -135,7 +130,6 @@ public class StaleAlertRunnable implements Runnable {
 
         long now = System.currentTimeMillis();
         Set<String> staleAlerts = new HashSet<String>();
-        Map<String, Set<String>> staleHostAlerts = new HashMap<>();
         Set<String> hostsWithStaleAlerts = new HashSet<String>();
 
         // get the cluster's current alerts
@@ -174,28 +168,16 @@ public class StaleAlertRunnable implements Runnable {
           // if the last time it was run is >= 2x the interval, it's stale
           long timeDifference = now - current.getLatestTimestamp();
           if (timeDifference >= 2 * intervalInMillis) {
-            String label = definition.getLabel();
+            // keep track of the definition
+            staleAlerts.add(definition.getLabel());
+
+            // keek track of the host, if not null
             if (null != history.getHostName()) {
-              // keep track of the host, if not null
-              String hostName = history.getHostName();
-              hostsWithStaleAlerts.add(hostName);
-              if(!staleHostAlerts.containsKey(hostName)) {
-                staleHostAlerts.put(hostName, new HashSet<String>());
-              }
-
-              staleHostAlerts.get(hostName).add(MessageFormat.format(TIMED_LABEL_MSG, label,
-                  millisToHumanReadableStr(timeDifference)));
-            } else {
-              // non host alerts
-              staleAlerts.add(label);
+              hostsWithStaleAlerts.add( history.getHostName() );
             }
           }
         }
 
-        for(String host : staleHostAlerts.keySet()) {
-          staleAlerts.add(MessageFormat.format(HOST_LABEL_MSG, host, StringUtils.join(staleHostAlerts.get(host), ", ")));
-        }
-
         AlertState alertState = AlertState.OK;
         String alertText = ALL_ALERTS_CURRENT_MSG;
 
@@ -227,31 +209,4 @@ public class StaleAlertRunnable implements Runnable {
           exception);
     }
   }
-
-  private static final long MILLISECONDS_PER_MINUTE = 1000l * 60l;
-  private static final int MINUTES_PER_DAY = 24 * 60;
-  private static final int MINUTES_PER_HOUR = 60;
-
-  /**
-   * Converts given {@code milliseconds} to human-readable {@link String} like "1d 2h 3m" or "2h 4m".
-   * @param milliseconds milliseconds to convert
-   * @return human-readable string
-   */
-  private static String millisToHumanReadableStr(long milliseconds){
-    int min, hour, days;
-    min = (int)(milliseconds / MILLISECONDS_PER_MINUTE);
-    days = min / MINUTES_PER_DAY;
-    min = min % MINUTES_PER_DAY;
-    hour = min / MINUTES_PER_HOUR;
-    min = min % MINUTES_PER_HOUR;
-    String result = "";
-    if(days > 0)
-      result += days + "d ";
-    if(hour > 0)
-      result += hour + "h ";
-    if(min > 0)
-      result += min + "m ";
-    return result.trim();
-  }
 }
-