33import xml .etree .ElementTree as ET
44import requests
55
6+ from .base import get_logger
7+
8+ log = get_logger (__name__ )
9+
610CONF_DIR = os .getenv ('HADOOP_CONF_DIR' , '/etc/hadoop/conf' )
711
812
@@ -14,7 +18,8 @@ def _get_rm_ids(hadoop_conf_path):
1418
1519
1620def _get_maximum_container_memory (hadoop_conf_path ):
17- container_memory = int (parse (os .path .join (hadoop_conf_path ,'yarn-site.xml' ), 'yarn.nodemanager.resource.memory-mb' ))
21+ container_memory = int (parse (os .path .join (hadoop_conf_path , 'yarn-site.xml' ),
22+ 'yarn.nodemanager.resource.memory-mb' ))
1823 return container_memory
1924
2025
@@ -29,7 +34,9 @@ def _is_https_only():
2934
3035def _get_resource_manager (hadoop_conf_path , rm_id = None ):
3136 # compose property name based on policy (and rm_id)
32- if _is_https_only ():
37+ is_https_only = _is_https_only ()
38+
39+ if is_https_only :
3340 prop_name = 'yarn.resourcemanager.webapp.https.address'
3441 else :
3542 prop_name = 'yarn.resourcemanager.webapp.address'
@@ -38,25 +45,27 @@ def _get_resource_manager(hadoop_conf_path, rm_id=None):
3845 if rm_id :
3946 prop_name = "{name}.{rm_id}" .format (name = prop_name , rm_id = rm_id )
4047
41- rm_webapp_address = parse (os .path .join (hadoop_conf_path , 'yarn-site.xml' ), prop_name )
48+ rm_address = parse (os .path .join (hadoop_conf_path , 'yarn-site.xml' ), prop_name )
4249
43- return rm_webapp_address or None
50+ return ( 'https://' if is_https_only else 'http://' ) + rm_address if rm_address else None
4451
4552
4653def check_is_active_rm (url , timeout = 30 , auth = None , verify = True ):
4754 try :
4855 response = requests .get (url + "/cluster" , timeout = timeout , auth = auth , verify = verify )
49- except :
56+ except requests .RequestException as e :
57+ log .warning ("Exception encountered accessing RM '{url}': '{err}', continuing..." .format (url = url , err = e ))
5058 return False
5159
5260 if response .status_code != 200 :
53- print ( "Error to access RM - HTTP Code {} " .format (response .status_code ))
61+ log . warning ( "Failed to access RM '{url}' - HTTP Code '{status}', continuing... " .format (url = url , status = response .status_code ))
5462 return False
5563 else :
5664 return True
5765
5866
5967def get_resource_manager_endpoint (timeout = 30 , auth = None , verify = True ):
68+ log .info ('Getting resource manager endpoint from config: {config_path}' .format (config_path = os .path .join (CONF_DIR , 'yarn-site.xml' )))
6069 hadoop_conf_path = CONF_DIR
6170 rm_ids = _get_rm_ids (hadoop_conf_path )
6271 if rm_ids :
@@ -72,18 +81,21 @@ def get_resource_manager_endpoint(timeout=30, auth=None, verify=True):
7281
7382def get_jobhistory_endpoint ():
7483 config_path = os .path .join (CONF_DIR , 'mapred-site.xml' )
84+ log .info ('Getting jobhistory endpoint from config: {config_path}' .format (config_path = config_path ))
7585 prop_name = 'mapreduce.jobhistory.webapp.address'
7686 return parse (config_path , prop_name )
7787
7888
7989def get_nodemanager_endpoint ():
8090 config_path = os .path .join (CONF_DIR , 'yarn-site.xml' )
91+ log .info ('Getting nodemanager endpoint from config: {config_path}' .format (config_path = config_path ))
8192 prop_name = 'yarn.nodemanager.webapp.address'
8293 return parse (config_path , prop_name )
8394
8495
8596def get_webproxy_endpoint (timeout = 30 , auth = None , verify = True ):
8697 config_path = os .path .join (CONF_DIR , 'yarn-site.xml' )
98+ log .info ('Getting webproxy endpoint from config: {config_path}' .format (config_path = config_path ))
8799 prop_name = 'yarn.web-proxy.address'
88100 value = parse (config_path , prop_name )
89101 return value or get_resource_manager_endpoint (timeout , auth , verify )
0 commit comments