Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 1c548e66d -> 56145c6c7


AMBARI-17180. Fix HA enabled logic in the alerts (Miklos Gergely via oleewere)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/56145c6c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/56145c6c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/56145c6c

Branch: refs/heads/branch-2.4
Commit: 56145c6c7106f597a02f59d078e83f8bed0f2722
Parents: 1c548e6
Author: Miklos Gergely <[email protected]>
Authored: Fri Jun 17 16:42:06 2016 +0200
Committer: oleewere <[email protected]>
Committed: Fri Jun 17 16:52:31 2016 +0200

----------------------------------------------------------------------
 .../python/ambari_agent/alerts/base_alert.py    | 33 ++++++++++++--------
 1 file changed, 20 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/56145c6c/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
----------------------------------------------------------------------
diff --git a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py 
b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
index 6c8ca5a..7f3b2a5 100644
--- a/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
+++ b/ambari-agent/src/main/python/ambari_agent/alerts/base_alert.py
@@ -395,22 +395,29 @@ class BaseAlert(object):
     ha_http_pattern = alert_uri_lookup_keys.ha_http_pattern
     ha_https_pattern = alert_uri_lookup_keys.ha_https_pattern
 
-    # at least one of these keys is needed
-    if ha_nameservice is None and ha_alias_key is None:
+    # if HA alias key is not defined then it's not HA environment
+    if ha_alias_key is None:
       return None
 
-    # convert dfs.ha.namenodes.{{ha-nameservice}} into
-    # dfs.ha.namenodes.c1ha
-    if ha_nameservice is not None:
+    if alert_uri_lookup_keys.ha_nameservice is not None:
+      # if there is a HA nameservice defined, but it can not be evaluated then 
it's not HA environment
+      if ha_nameservice is None:
+        return None
+      
+      # convert dfs.ha.namenodes.{{ha-nameservice}} into dfs.ha.namenodes.c1ha
       ha_alias_key = ha_alias_key.replace(self.HA_NAMESERVICE_PARAM, 
ha_nameservice)
-
-    # grab the alias value which should be like nn1, nn2
-    ha_nameservice_alias = self._get_configuration_value(ha_alias_key)
-    if ha_nameservice_alias is None:
-      logger.warning("[Alert][{0}] HA nameservice value is present but there 
are no aliases for {1}".format(
-        self.get_name(), ha_alias_key))
-
-      return None
+      ha_nameservice_alias = self._get_configuration_value(ha_alias_key)
+      
+      if ha_nameservice_alias is None:
+        logger.warning("[Alert][{0}] HA nameservice value is present but there 
are no aliases for {1}".format(
+          self.get_name(), ha_alias_key))
+        return None
+    else:
+      ha_nameservice_alias = self._get_configuration_value(ha_alias_key)
+      
+      # if HA nameservice is not defined then the fact that the HA alias_key 
could not be evaluated shows that it's not HA environment
+      if ha_nameservice_alias is None:
+        return None
 
     # determine which pattern to use (http or https)
     ha_pattern = ha_http_pattern

Reply via email to