You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jl...@apache.org on 2016/02/25 23:50:16 UTC

ambari git commit: AMBARI-15169: namenode_ha_utils.py returns sometimes Active NNs as emtpy set, and Stand-by NN as a set of 2 NNs in multi-homed environment (jluniya)

Repository: ambari
Updated Branches:
  refs/heads/trunk a4deda347 -> 4221872a6


AMBARI-15169: namenode_ha_utils.py returns sometimes Active NNs as emtpy set, and Stand-by NN as a set of 2 NNs in multi-homed environment (jluniya)


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

Branch: refs/heads/trunk
Commit: 4221872a6d9827ba3e026c767c3f3f7efe01bee0
Parents: a4deda3
Author: Jayush Luniya <jl...@hortonworks.com>
Authored: Thu Feb 25 14:50:11 2016 -0800
Committer: Jayush Luniya <jl...@hortonworks.com>
Committed: Thu Feb 25 14:50:11 2016 -0800

----------------------------------------------------------------------
 .../libraries/functions/namenode_ha_utils.py    | 29 ++++++++++++++++----
 .../package/alerts/alert_ha_namenode_health.py  | 14 ++++++++--
 2 files changed, 36 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/4221872a/ambari-common/src/main/python/resource_management/libraries/functions/namenode_ha_utils.py
----------------------------------------------------------------------
diff --git a/ambari-common/src/main/python/resource_management/libraries/functions/namenode_ha_utils.py b/ambari-common/src/main/python/resource_management/libraries/functions/namenode_ha_utils.py
index 0920e85..36a34c1 100644
--- a/ambari-common/src/main/python/resource_management/libraries/functions/namenode_ha_utils.py
+++ b/ambari-common/src/main/python/resource_management/libraries/functions/namenode_ha_utils.py
@@ -33,7 +33,10 @@ HDFS_NN_STATE_STANDBY = 'standby'
 
 NAMENODE_HTTP_FRAGMENT = 'dfs.namenode.http-address.{0}.{1}'
 NAMENODE_HTTPS_FRAGMENT = 'dfs.namenode.https-address.{0}.{1}'
+NAMENODE_RPC_FRAGMENT = 'dfs.namenode.rpc-address.{0}.{1}'
+NAMENODE_RPC_NON_HA = 'dfs.namenode.rpc-address'
 JMX_URI_FRAGMENT = "{0}://{1}/jmx?qry=Hadoop:service=NameNode,name=FSNamesystem"
+INADDR_ANY = '0.0.0.0'
 
 def get_namenode_states(hdfs_site, security_enabled, run_user, times=10, sleep_time=1, backoff_factor=2):
   """
@@ -73,7 +76,8 @@ def get_namenode_states_noretries(hdfs_site, security_enabled, run_user):
   nn_unique_ids = hdfs_site[nn_unique_ids_key].split(',')
   for nn_unique_id in nn_unique_ids:
     is_https_enabled = hdfs_site['dfs.https.enable'] if not is_empty(hdfs_site['dfs.https.enable']) else False
-    
+
+    rpc_key = NAMENODE_RPC_FRAGMENT.format(name_service,nn_unique_id)
     if not is_https_enabled:
       key = NAMENODE_HTTP_FRAGMENT.format(name_service,nn_unique_id)
       protocol = "http"
@@ -84,6 +88,11 @@ def get_namenode_states_noretries(hdfs_site, security_enabled, run_user):
     if key in hdfs_site:
       # use str() to ensure that unicode strings do not have the u' in them
       value = str(hdfs_site[key])
+      if INADDR_ANY in value and rpc_key in hdfs_site:
+        rpc_value = str(hdfs_site[rpc_key])
+        if INADDR_ANY not in rpc_value:
+          rpc_host = rpc_value.split(":")[0]
+          value = value.replace(INADDR_ANY, rpc_host)
 
       jmx_uri = JMX_URI_FRAGMENT.format(protocol, value)
       
@@ -139,6 +148,8 @@ def get_property_for_active_namenode(hdfs_site, property_name, security_enabled,
     - In non-ha mode it will return hdfs_site[dfs.namenode.rpc-address]
     - In ha-mode it will return hdfs_site[dfs.namenode.rpc-address.nnha.nn2], where nnha is the name of HA, and nn2 is id of active NN
   """
+  value = None
+  rpc_key = None
   if is_ha_enabled(hdfs_site):
     name_service = hdfs_site['dfs.nameservices']
     active_namenodes = get_namenode_states(hdfs_site, security_enabled, run_user)[0]
@@ -147,8 +158,16 @@ def get_property_for_active_namenode(hdfs_site, property_name, security_enabled,
       raise Fail("There is no active namenodes.")
     
     active_namenode_id = active_namenodes[0][0]
-    
-    return hdfs_site[format("{property_name}.{name_service}.{active_namenode_id}")]
+    value = hdfs_site[format("{property_name}.{name_service}.{active_namenode_id}")]
+    rpc_key = NAMENODE_RPC_FRAGMENT.format(name_service,active_namenode_id)
   else:
-    return hdfs_site[property_name]
-  
+    value = hdfs_site[property_name]
+    rpc_key = NAMENODE_RPC_NON_HA
+
+  if INADDR_ANY in value and rpc_key in hdfs_site:
+    rpc_value = str(hdfs_site[rpc_key])
+    if INADDR_ANY not in rpc_value:
+      rpc_host = rpc_value.split(":")[0]
+      value = value.replace(INADDR_ANY, rpc_host)
+
+  return value

http://git-wip-us.apache.org/repos/asf/ambari/blob/4221872a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py
index 7cd5591..a174cb4 100644
--- a/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py
+++ b/ambari-server/src/main/resources/common-services/HDFS/2.1.0.2.0/package/alerts/alert_ha_namenode_health.py
@@ -45,6 +45,10 @@ KERBEROS_PRINCIPAL = '{{hdfs-site/dfs.web.authentication.kerberos.principal}}'
 SECURITY_ENABLED_KEY = '{{cluster-env/security_enabled}}'
 SMOKEUSER_KEY = '{{cluster-env/smokeuser}}'
 EXECUTABLE_SEARCH_PATHS = '{{kerberos-env/executable_search_paths}}'
+INADDR_ANY = '0.0.0.0'
+NAMENODE_HTTP_FRAGMENT = 'dfs.namenode.http-address.{0}.{1}'
+NAMENODE_HTTPS_FRAGMENT = 'dfs.namenode.https-address.{0}.{1}'
+NAMENODE_RPC_FRAGMENT = 'dfs.namenode.rpc-address.{0}.{1}'
 
 CONNECTION_TIMEOUT_KEY = 'connection.timeout'
 CONNECTION_TIMEOUT_DEFAULT = 5.0
@@ -122,11 +126,11 @@ def execute(configurations={}, parameters={}, host_name=None):
   if not nn_unique_ids_key in hdfs_site:
     return (RESULT_STATE_UNKNOWN, ['Unable to find unique namenode alias key {0}'.format(nn_unique_ids_key)])
 
-  namenode_http_fragment = 'dfs.namenode.http-address.{0}.{1}'
+  namenode_http_fragment = NAMENODE_HTTP_FRAGMENT
   jmx_uri_fragment = "http://{0}/jmx?qry=Hadoop:service=NameNode,name=*"
 
   if is_ssl_enabled:
-    namenode_http_fragment = 'dfs.namenode.https-address.{0}.{1}'
+    namenode_http_fragment = NAMENODE_HTTPS_FRAGMENT
     jmx_uri_fragment = "https://{0}/jmx?qry=Hadoop:service=NameNode,name=*"
 
 
@@ -140,10 +144,16 @@ def execute(configurations={}, parameters={}, host_name=None):
   nn_unique_ids = hdfs_site[nn_unique_ids_key].split(',')
   for nn_unique_id in nn_unique_ids:
     key = namenode_http_fragment.format(name_service,nn_unique_id)
+    rpc_key = NAMENODE_RPC_FRAGMENT.format(name_service,nn_unique_id)
 
     if key in hdfs_site:
       # use str() to ensure that unicode strings do not have the u' in them
       value = str(hdfs_site[key])
+      if INADDR_ANY in value and rpc_key in hdfs_site:
+        rpc_value = str(hdfs_site[rpc_key])
+        if INADDR_ANY not in rpc_value:
+          rpc_host = rpc_value.split(":")[0]
+          value = value.replace(INADDR_ANY, rpc_host)
 
       try:
         jmx_uri = jmx_uri_fragment.format(value)