You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ao...@apache.org on 2018/03/16 13:14:18 UTC

[ambari] branch trunk updated: Revert "AMBARI-23258. Ambari-agent logs are messy/hard to read (aonishuk)"

This is an automated email from the ASF dual-hosted git repository.

aonishuk pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/ambari.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 82f1925  Revert "AMBARI-23258. Ambari-agent logs are messy/hard to read (aonishuk)"
82f1925 is described below

commit 82f192516fad8cc72dda2c5d2d92363ded8003ea
Author: aonishuk <ao...@hortonworks.com>
AuthorDate: Fri Mar 16 15:13:58 2018 +0200

    Revert "AMBARI-23258. Ambari-agent logs are messy/hard to read (aonishuk)"
    
    This reverts commit 668e397993bfe08314b731dcd5affcca5d398d7f.
---
 .../python/ambari_agent/AlertStatusReporter.py     | 17 +--------
 .../main/python/ambari_agent/CommandStatusDict.py  | 42 +++++++---------------
 .../ambari_agent/CustomServiceOrchestrator.py      |  4 +--
 .../main/python/ambari_agent/HeartbeatThread.py    | 16 +++------
 .../main/python/ambari_agent/alerts/ams_alert.py   |  2 +-
 .../python/ambari_agent/alerts/script_alert.py     |  2 +-
 .../listeners/AlertDefinitionsEventListener.py     | 15 --------
 .../listeners/CommandsEventListener.py             | 19 +---------
 .../listeners/ConfigurationEventListener.py        | 16 +--------
 .../listeners/ServerResponsesListener.py           |  8 -----
 .../listeners/TopologyEventListener.py             | 19 +---------
 .../main/python/ambari_agent/listeners/__init__.py |  4 +--
 ambari-agent/src/main/python/ambari_agent/main.py  |  4 ---
 .../src/main/python/ambari_agent/security.py       |  9 ++---
 .../src/main/python/ambari_stomp/transport.py      |  4 +--
 .../ambari/server/agent/ExecutionCommand.java      |  1 -
 .../ambari/server/orm/dao/AlertDefinitionDAO.java  |  2 +-
 .../server/orm/entities/AlertDefinitionEntity.java |  3 +-
 .../server/state/alert/AlertDefinitionHash.java    |  2 +-
 .../ambari/server/state/alert/AlertHelper.java     |  2 +-
 .../ambari/server/alerts/AlertHelperTest.java      |  2 ++
 21 files changed, 35 insertions(+), 158 deletions(-)

diff --git a/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py b/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py
index bfb0e4f..e588bd1 100644
--- a/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py
+++ b/ambari-agent/src/main/python/ambari_agent/AlertStatusReporter.py
@@ -59,7 +59,7 @@ class AlertStatusReporter(threading.Thread):
           changed_alerts = self.get_changed_alerts(alerts)
 
           if changed_alerts and self.initializer_module.is_registered:
-            self.initializer_module.connection.send(message=changed_alerts, destination=Constants.ALERTS_STATUS_REPORTS_ENDPOINT, log_message_function=AlertStatusReporter.log_sending)
+            self.initializer_module.connection.send(message=changed_alerts, destination=Constants.ALERTS_STATUS_REPORTS_ENDPOINT)
             self.save_results(changed_alerts)
       except ConnectionIsAlreadyClosed: # server and agent disconnected during sending data. Not an issue
         pass
@@ -93,18 +93,3 @@ class AlertStatusReporter(threading.Thread):
         changed_alerts.append(alert)
 
     return changed_alerts
-    
-  @staticmethod
-  def log_sending(message_dict):
-    """
-    Returned dictionary will be used while logging sent alert status.
-    Used because full dict is too big for logs and should be shortened
-    """
-    try:
-      for alert_status in message_dict:
-        if 'text' in alert_status:
-          alert_status['text'] = '...'
-    except KeyError:
-      pass
-      
-    return message_dict
diff --git a/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py b/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py
index 0ddc1d9..d036cbf 100644
--- a/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py
+++ b/ambari-agent/src/main/python/ambari_agent/CommandStatusDict.py
@@ -18,7 +18,6 @@ See the License for the specific language governing permissions and
 limitations under the License.
 '''
 
-import os
 import logging
 import threading
 import copy
@@ -77,7 +76,7 @@ class CommandStatusDict():
       return False
 
     try:
-      self.initializer_module.connection.send(message={'clusters':reports_dict}, destination=Constants.COMMANDS_STATUS_REPORTS_ENDPOINT, log_message_function=CommandStatusDict.log_sending)
+      self.initializer_module.connection.send(message={'clusters':reports_dict}, destination=Constants.COMMANDS_STATUS_REPORTS_ENDPOINT)
       return True
     except ConnectionIsAlreadyClosed:
       return False
@@ -132,18 +131,17 @@ class CommandStatusDict():
     and populates other fields of report.
     """
     from ActionQueue import ActionQueue
-    
-    files_to_read = [report['tmpout'], report['tmperr'], report['structuredOut']]
-    files_content = ['...', '...', '{}']
-
-    for i in xrange(len(files_to_read)):
-      filename = files_to_read[i]
-      if os.path.exists(filename):
-        with open(filename, 'r') as fp:
-          files_content[i] = fp.read()
-          
-    tmpout, tmperr, tmpstructuredout = files_content
-
+    try:
+      tmpout = open(report['tmpout'], 'r').read()
+      tmperr = open(report['tmperr'], 'r').read()
+    except Exception, err:
+      logger.warn(err)
+      tmpout = '...'
+      tmperr = '...'
+    try:
+      tmpstructuredout = open(report['structuredOut'], 'r').read()
+    except Exception:
+      tmpstructuredout = '{}'
     grep = Grep()
     output = grep.tail(tmpout, Grep.OUTPUT_LAST_LINES)
     inprogress = self.generate_report_template(command)
@@ -171,21 +169,5 @@ class CommandStatusDict():
       'roleCommand': command['roleCommand']
     }
     return stub
-    
-  @staticmethod
-  def log_sending(message_dict):
-    """
-    Returned dictionary will be used while logging sent component status.
-    Used because full dict is too big for logs and should be shortened
-    """
-    try:
-      for cluster_id in message_dict['clusters']:
-        for command_status in message_dict['clusters'][cluster_id]:
-          if 'stdout' in command_status:
-            command_status['stdout'] = '...'
-    except KeyError:
-      pass
-      
-    return message_dict
 
 
diff --git a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
index 9a57ae6..ad729ad 100644
--- a/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
+++ b/ambari-agent/src/main/python/ambari_agent/CustomServiceOrchestrator.py
@@ -241,7 +241,7 @@ class CustomServiceOrchestrator():
             config.pop(value_name, None)
     return configtype_credentials
 
-  def generateJceks(self, commandJson):
+  def qJceks(self, commandJson):
     """
     Generates the JCEKS file with passwords for the service specified in commandJson
 
@@ -363,7 +363,7 @@ class CustomServiceOrchestrator():
       # generate the JCEKS file for the configurations.
       credentialStoreEnabled = False
       if 'serviceLevelParams' in command and 'credentialStoreEnabled' in command['serviceLevelParams']:
-        credentialStoreEnabled = command['serviceLevelParams']['credentialStoreEnabled']
+        credentialStoreEnabled = (command['serviceLevelParams']['credentialStoreEnabled'] == "true")
 
       if credentialStoreEnabled == True:
         if 'commandBeingRetried' not in command['agentLevelParams'] or command['agentLevelParams']['commandBeingRetried'] != "true":
diff --git a/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py b/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py
index 5f91a77..2a4ae56 100644
--- a/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py
+++ b/ambari-agent/src/main/python/ambari_agent/HeartbeatThread.py
@@ -93,11 +93,7 @@ class HeartbeatThread(threading.Thread):
         logger.debug("Heartbeat response is {0}".format(response))
         self.handle_heartbeat_reponse(response)
       except Exception as ex:
-        if isinstance(ex, (ConnectionIsAlreadyClosed)):
-          logger.info("Connection was closed. Re-running the registration")
-        elif isinstance(ex, (socket_error)):
-          logger.info("Connection error \"{0}\". Re-running the registration".format(str(ex)))
-        else:
+        if not isinstance(ex, (socket_error, ConnectionIsAlreadyClosed)):
           logger.exception("Exception in HeartbeatThread. Re-running the registration")
 
         self.unregister()
@@ -129,7 +125,7 @@ class HeartbeatThread(threading.Thread):
 
     for endpoint, cache, listener in self.post_registration_requests:
       # should not hang forever on these requests
-      response = self.blocking_request({'hash': cache.hash}, endpoint, log_handler=listener.get_log_message)
+      response = self.blocking_request({'hash': cache.hash}, endpoint)
       try:
         listener.on_event({}, response)
       except:
@@ -231,16 +227,12 @@ class HeartbeatThread(threading.Thread):
     for topic_name in topics_list:
       self.connection.subscribe(destination=topic_name, id='sub', ack='client-individual')
 
-  def blocking_request(self, message, destination, log_handler=None, timeout=REQUEST_RESPONSE_TIMEOUT):
+  def blocking_request(self, message, destination, timeout=REQUEST_RESPONSE_TIMEOUT):
     """
     Send a request to server and waits for the response from it. The response it detected by the correspondence of correlation_id.
     """
-    def presend_hook(correlation_id):
-      if log_handler:
-        self.server_responses_listener.logging_handlers[str(correlation_id)] = log_handler 
-           
     try:
-      correlation_id = self.connection.send(message=message, destination=destination, presend_hook=presend_hook)
+      correlation_id = self.connection.send(message=message, destination=destination)
     except ConnectionIsAlreadyClosed:
       # this happens when trying to connect to broken connection. Happens if ambari-server is restarted.
       logger.warn("Connection failed while trying to connect to {0}".format(destination))
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
index 4f59143..cc2884e 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/ams_alert.py
@@ -31,7 +31,7 @@ import uuid
 from resource_management.libraries.functions.get_port_from_url import get_port_from_url
 from ambari_commons import inet_utils
 
-logger = logging.getLogger(__name__)
+logger = logging.getLogger()
 
 AMS_METRICS_GET_URL = "/ws/v1/timeline/metrics?%s"
 
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py b/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
index 073d6c0..b78d578 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/script_alert.py
@@ -115,7 +115,7 @@ class ScriptAlert(BaseAlert):
       matchObj = re.match( r'((.*)services(.*)package)', self.path_to_script)
       if matchObj:
         basedir = matchObj.group(1)
-        with Environment(basedir, tmp_dir=AGENT_TMP_DIR, logger=logging.getLogger('alerts')) as env:
+        with Environment(basedir, tmp_dir=AGENT_TMP_DIR, logger=logging.getLogger('ambari_alerts')) as env:
           result = cmd_module.execute(configurations, self.parameters, self.host_name)
       else:
         result = cmd_module.execute(configurations, self.parameters, self.host_name)
diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py b/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py
index 4ef9982..8f52be4 100644
--- a/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py
+++ b/ambari-agent/src/main/python/ambari_agent/listeners/AlertDefinitionsEventListener.py
@@ -60,18 +60,3 @@ class AlertDefinitionsEventListener(EventListener):
 
   def get_handled_path(self):
     return Constants.ALERTS_DEFINITIONS_TOPIC
-    
-  def get_log_message(self, headers, message_json):
-    """
-    This string will be used to log received messsage of this type.
-    Usually should be used if full dict is too big for logs and should shortened or made more readable
-    """
-    try:
-      for cluster_id in message_json['clusters']:
-        for alert_definition in message_json['clusters'][cluster_id]['alertDefinitions']:
-          if 'source' in alert_definition:
-            alert_definition['source'] = '...'
-    except KeyError:
-      pass
-      
-    return super(AlertDefinitionsEventListener, self).get_log_message(headers, message_json)
diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/CommandsEventListener.py b/ambari-agent/src/main/python/ambari_agent/listeners/CommandsEventListener.py
index 49ba20f..dc3bea9 100644
--- a/ambari-agent/src/main/python/ambari_agent/listeners/CommandsEventListener.py
+++ b/ambari-agent/src/main/python/ambari_agent/listeners/CommandsEventListener.py
@@ -59,21 +59,4 @@ class CommandsEventListener(EventListener):
       self.action_queue.put(commands)
 
   def get_handled_path(self):
-    return Constants.COMMANDS_TOPIC
-    
-  def get_log_message(self, headers, message_json):
-    """
-    This string will be used to log received messsage of this type.
-    Usually should be used if full dict is too big for logs and should shortened or made more readable
-    """
-    try:
-      for cluster_id in message_json['clusters']:
-        for command in message_json['clusters'][cluster_id]['commands']:
-          if 'repositoryFile' in command:
-            command['repositoryFile'] = '...'
-          if 'commandParams' in command:
-            command['commandParams'] = '...'
-    except KeyError:
-      pass
-      
-    return super(CommandsEventListener, self).get_log_message(headers, message_json)
\ No newline at end of file
+    return Constants.COMMANDS_TOPIC
\ No newline at end of file
diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/ConfigurationEventListener.py b/ambari-agent/src/main/python/ambari_agent/listeners/ConfigurationEventListener.py
index 880ffd3..1c083a6 100644
--- a/ambari-agent/src/main/python/ambari_agent/listeners/ConfigurationEventListener.py
+++ b/ambari-agent/src/main/python/ambari_agent/listeners/ConfigurationEventListener.py
@@ -49,18 +49,4 @@ class ConfigurationEventListener(EventListener):
     self.configuration_cache.rewrite_cache(message['clusters'], message['hash'])
 
   def get_handled_path(self):
-    return Constants.CONFIGURATIONS_TOPIC
-    
-  def get_log_message(self, headers, message_json):
-    """
-    This string will be used to log received messsage of this type.
-    Usually should be used if full dict is too big for logs and should shortened shortened or made more readable
-    """
-    try:
-      for cluster_id in message_json['clusters']:
-        for config_type in message_json['clusters'][cluster_id]['configurations']:
-          message_json['clusters'][cluster_id]['configurations'][config_type] = '...'
-    except KeyError:
-      pass
-      
-    return super(ConfigurationEventListener, self).get_log_message(headers, message_json)
\ No newline at end of file
+    return Constants.CONFIGURATIONS_TOPIC
\ No newline at end of file
diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/ServerResponsesListener.py b/ambari-agent/src/main/python/ambari_agent/listeners/ServerResponsesListener.py
index bb0a746..a4a48bc 100644
--- a/ambari-agent/src/main/python/ambari_agent/listeners/ServerResponsesListener.py
+++ b/ambari-agent/src/main/python/ambari_agent/listeners/ServerResponsesListener.py
@@ -33,7 +33,6 @@ class ServerResponsesListener(EventListener):
   """
   def __init__(self):
     self.listener_functions = {}
-    self.logging_handlers = {}
     self.reset_responses()
 
   def on_event(self, headers, message):
@@ -64,13 +63,6 @@ class ServerResponsesListener(EventListener):
     """
     if Constants.CORRELATION_ID_STRING in headers:
       correlation_id = headers[Constants.CORRELATION_ID_STRING]
-      
-      if correlation_id in self.logging_handlers:
-        message_json = self.logging_handlers[correlation_id](headers, message_json)
-        if message_json.startswith(" :"):
-          message_json = message_json[2:]
-        del self.logging_handlers[correlation_id]
-      
       return " (correlation_id={0}): {1}".format(correlation_id, message_json)
     return str(message_json)
 
diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/TopologyEventListener.py b/ambari-agent/src/main/python/ambari_agent/listeners/TopologyEventListener.py
index df4ea03..71aa161 100644
--- a/ambari-agent/src/main/python/ambari_agent/listeners/TopologyEventListener.py
+++ b/ambari-agent/src/main/python/ambari_agent/listeners/TopologyEventListener.py
@@ -56,21 +56,4 @@ class TopologyEventListener(EventListener):
       logger.error("Unknown event type '{0}' for topology event")
 
   def get_handled_path(self):
-    return Constants.TOPOLOGIES_TOPIC
-    
-  def get_log_message(self, headers, message_json):
-    """
-    This string will be used to log received messsage of this type.
-    Usually should be used if full dict is too big for logs and should shortened or made more readable
-    """
-    try:
-      for cluster_id in message_json['clusters']:
-        for component_info in message_json['clusters'][cluster_id]['components']:
-          if 'componentLevelParams' in component_info:
-            component_info['componentLevelParams'] = '...'
-          if 'commandParams' in component_info:
-            component_info['commandParams'] = '...'
-    except KeyError:
-      pass
-      
-    return super(TopologyEventListener, self).get_log_message(headers, message_json)
\ No newline at end of file
+    return Constants.TOPOLOGIES_TOPIC
\ No newline at end of file
diff --git a/ambari-agent/src/main/python/ambari_agent/listeners/__init__.py b/ambari-agent/src/main/python/ambari_agent/listeners/__init__.py
index 1134cb9..3dead4b 100644
--- a/ambari-agent/src/main/python/ambari_agent/listeners/__init__.py
+++ b/ambari-agent/src/main/python/ambari_agent/listeners/__init__.py
@@ -20,7 +20,6 @@ limitations under the License.
 import ambari_simplejson as json
 import ambari_stomp
 import logging
-import copy
 
 logger = logging.getLogger(__name__)
 
@@ -45,8 +44,7 @@ class EventListener(ambari_stomp.ConnectionListener):
       except ValueError:
         logger.exception("Received from server event is not a valid message json. Message is:\n{0}".format(message))
         return
-
-      logger.info("Event from server at {0}{1}".format(destination, self.get_log_message(headers, copy.deepcopy(message_json))))
+      logger.info("Event from server at {0}{1}".format(destination, self.get_log_message(headers, message_json)))
       try:
         self.on_event(headers, message_json)
       except:
diff --git a/ambari-agent/src/main/python/ambari_agent/main.py b/ambari-agent/src/main/python/ambari_agent/main.py
index bfe335f..1eb39bc 100644
--- a/ambari-agent/src/main/python/ambari_agent/main.py
+++ b/ambari-agent/src/main/python/ambari_agent/main.py
@@ -103,8 +103,6 @@ from ambari_commons.shell import shellRunner
 from HeartbeatHandlers import bind_signal_handlers
 from ambari_commons.constants import AMBARI_SUDO_BINARY
 from resource_management.core.logger import Logger
-#from resource_management.core.resources.system import File
-#from resource_management.core.environment import Environment
 
 from ambari_agent import HeartbeatThread
 from ambari_agent.InitializerModule import InitializerModule
@@ -418,8 +416,6 @@ def main(initializer_module, heartbeat_stop_callback=None):
   setup_logging(apscheduler_logger, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level)
   setup_logging(apscheduler_logger_global, AmbariConfig.AmbariConfig.getAlertsLogFile(), logging_level)
   Logger.initialize_logger('resource_management', logging_level=logging_level)
-  #with Environment() as env:
-  #  File("/abc")
 
   # init data, once loggers are setup to see exceptions/errors of initialization.
   initializer_module.init()
diff --git a/ambari-agent/src/main/python/ambari_agent/security.py b/ambari-agent/src/main/python/ambari_agent/security.py
index 563771a..215608e 100644
--- a/ambari-agent/src/main/python/ambari_agent/security.py
+++ b/ambari-agent/src/main/python/ambari_agent/security.py
@@ -20,7 +20,6 @@ import gzip
 import httplib
 import urllib2
 import socket
-import copy
 import ssl
 import os
 import logging
@@ -106,16 +105,12 @@ class AmbariStompConnection(WsConnection):
     self.correlation_id = -1
     WsConnection.__init__(self, *args, **kwargs)
 
-  def send(self, destination, message, content_type=None, headers=None, log_message_function=lambda x:x, presend_hook=None, **keyword_headers):
+  def send(self, destination, message, content_type=None, headers=None, **keyword_headers):
     with self.lock:
       self.correlation_id += 1
       correlation_id = self.correlation_id
-      
-    if presend_hook:
-      presend_hook(self.correlation_id)
 
-    logged_message = log_message_function(copy.deepcopy(message))
-    logger.info("Event to server at {0} (correlation_id={1}): {2}".format(destination, correlation_id, logged_message))
+    logger.info("Event to server at {0} (correlation_id={1}): {2}".format(destination, correlation_id, message))
 
     body = json.dumps(message)
     WsConnection.send(self, destination, body, content_type=content_type, headers=headers, correlationId=correlation_id, **keyword_headers)
diff --git a/ambari-common/src/main/python/ambari_stomp/transport.py b/ambari-common/src/main/python/ambari_stomp/transport.py
index 1fd18f0..32604fc 100644
--- a/ambari-common/src/main/python/ambari_stomp/transport.py
+++ b/ambari-common/src/main/python/ambari_stomp/transport.py
@@ -188,7 +188,7 @@ class BaseTransport(ambari_stomp.listener.Publisher):
             if log.isEnabledFor(logging.DEBUG):
                 log.debug("Received frame: %r, headers=%r, body=%r", f.cmd, f.headers, f.body)
             else:
-                log.debug("Received frame: %r, headers=%r, len(body)=%r", f.cmd, f.headers, utils.length(f.body))
+                log.info("Received frame: %r, headers=%r, len(body)=%r", f.cmd, f.headers, utils.length(f.body))
             self.notify(frame_type, f.headers, f.body)
         else:
             log.warning("Unknown response frame type: '%s' (frame length was %d)", frame_type, utils.length(frame_str))
@@ -268,7 +268,7 @@ class BaseTransport(ambari_stomp.listener.Publisher):
         if log.isEnabledFor(logging.DEBUG):
             log.debug("Sending frame: %s", lines)
         else:
-            log.debug("Sending frame: %r, headers=%r", frame.cmd or "heartbeat", frame.headers)
+            log.info("Sending frame: %r, headers=%r", frame.cmd or "heartbeat", frame.headers)
 
         self.send(encode(packed_frame))
 
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
index 17a81fb..b016b7c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/agent/ExecutionCommand.java
@@ -184,7 +184,6 @@ public class ExecutionCommand extends AgentCommand {
    * the deprecated use of {@link KeyNames#REPO_INFO}
    */
   @SerializedName("repositoryFile")
-  @JsonIgnore
   private CommandRepository commandRepository;
 
   @SerializedName("componentVersionMap")
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
index 229f2fe..c8508fc 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AlertDefinitionDAO.java
@@ -231,7 +231,7 @@ public class AlertDefinitionDAO {
 
   /**
    * Gets all alert definitions for the specified services that do not have a
-   * component and do not belong to AGGREGATE source type. These definitions are assumed to be run on the master hosts.
+   * component. These definitions are assumed to be run on the master hosts.
    *
    * @param clusterId
    *          the ID of the cluster.
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
index afa9684..2f4941b 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertDefinitionEntity.java
@@ -71,8 +71,7 @@ import org.apache.ambari.server.state.alert.SourceType;
     }),
   @NamedQuery(name = "AlertDefinitionEntity.findByService", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName = :serviceName AND ad.clusterId = :clusterId"),
   @NamedQuery(name = "AlertDefinitionEntity.findByServiceAndComponent", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName = :serviceName AND ad.componentName = :componentName AND ad.clusterId = :clusterId"),
-  @NamedQuery(name = "AlertDefinitionEntity.findByServiceMaster", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName IN :services AND ad.scope = :scope AND ad.clusterId = :clusterId AND ad.componentName IS NULL" +
-      " AND ad.sourceType <> org.apache.ambari.server.state.alert.SourceType.AGGREGATE"),
+  @NamedQuery(name = "AlertDefinitionEntity.findByServiceMaster", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.serviceName IN :services AND ad.scope = :scope AND ad.clusterId = :clusterId AND ad.componentName IS NULL"),
   @NamedQuery(name = "AlertDefinitionEntity.findByIds", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.definitionId IN :definitionIds"),
   @NamedQuery(name = "AlertDefinitionEntity.findBySourceType", query = "SELECT ad FROM AlertDefinitionEntity ad WHERE ad.clusterId = :clusterId AND ad.sourceType = :sourceType")})
 public class AlertDefinitionEntity {
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java
index 2f5fe29..771aa37 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertDefinitionHash.java
@@ -605,7 +605,7 @@ public class AlertDefinitionHash {
    * following types of alert definitions:
    * <ul>
    * <li>Service/Component alerts</li>
-   * <li>Service alerts where the host is a MASTER except AGGREGATE alerts</li>
+   * <li>Service alerts where the host is a MASTER</li>
    * <li>Host alerts that are not bound to a service</li>
    * </ul>
    *
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertHelper.java b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertHelper.java
index c7a9be4..81e9ac3 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertHelper.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/state/alert/AlertHelper.java
@@ -137,7 +137,7 @@ public class AlertHelper {
    * @param staleAlertsDefinitionId list of stale alerts
    */
   public void addStaleAlerts(Long hostId, List<StaleAlert> staleAlertsDefinitionId) {
-    staleAlerts.put(hostId, new ConcurrentHashMap<>());
+    staleAlerts.putIfAbsent(hostId, new ConcurrentHashMap<>());
     ConcurrentMap<Long, Long> hostStaleAlerts = staleAlerts.get(hostId);
     staleAlertsDefinitionId.forEach(s -> hostStaleAlerts.put(s.getId(), s.getTimestamp()));
   }
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/alerts/AlertHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/alerts/AlertHelperTest.java
index 6508302..aa4d90f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/alerts/AlertHelperTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/alerts/AlertHelperTest.java
@@ -47,6 +47,8 @@ public class AlertHelperTest {
     alertHelper.addStaleAlerts(1L, new ArrayList<StaleAlert>(){{
       add(new StaleAlert(1L, 111L));
       add(new StaleAlert(2L, 111L));
+    }});
+    alertHelper.addStaleAlerts(1L, new ArrayList<StaleAlert>(){{
       add(new StaleAlert(3L, 111L));
       add(new StaleAlert(4L, 111L));
     }});

-- 
To stop receiving notification emails like this one, please contact
aonishuk@apache.org.