|
@@ -24,7 +24,6 @@ from resource_management.libraries.functions import conf_select
|
|
|
|
|
|
DEFAULT_COLLECTOR_SUFFIX = '.sink.timeline.collector.hosts'
|
|
|
DEFAULT_METRICS2_PROPERTIES_FILE_NAME = 'hadoop-metrics2.properties'
|
|
|
-DEFAULT_HADOOP_CONF_DIR_PATH = '/usr/hdp/current/hadoop-client/conf/'
|
|
|
|
|
|
def select_metric_collector_for_sink(sink_name):
|
|
|
# TODO check '*' sink_name
|
|
@@ -46,10 +45,18 @@ def get_metric_collectors_from_properties_file(sink_name):
|
|
|
try:
|
|
|
hadoop_conf_dir = conf_select.get_hadoop_conf_dir()
|
|
|
except Exception as e:
|
|
|
- print "Can't get hadoop conf directory from conf_select.get_hadoop_conf_dir() - " + str(e)
|
|
|
- hadoop_conf_dir = DEFAULT_HADOOP_CONF_DIR_PATH
|
|
|
- props = load_properties_from_file(os.path.join(hadoop_conf_dir, DEFAULT_METRICS2_PROPERTIES_FILE_NAME))
|
|
|
- return props.get(sink_name + DEFAULT_COLLECTOR_SUFFIX)
|
|
|
+ raise Exception("Couldn't define hadoop_conf_dir: {0}".format(e))
|
|
|
+ properties_filepath = os.path.join(hadoop_conf_dir, DEFAULT_METRICS2_PROPERTIES_FILE_NAME)
|
|
|
+
|
|
|
+ if not os.path.exists(properties_filepath):
|
|
|
+ raise Exception("Properties file doesn't exist : {0}. Can't define metric collector hosts".format(properties_filepath))
|
|
|
+ props = load_properties_from_file(properties_filepath)
|
|
|
+
|
|
|
+ property_key = sink_name + DEFAULT_COLLECTOR_SUFFIX
|
|
|
+ if property_key in props:
|
|
|
+ return props.get(property_key)
|
|
|
+ else:
|
|
|
+ raise Exception("Properties file doesn't contain {0}. Can't define metric collector hosts".format(property_key))
|
|
|
|
|
|
def load_properties_from_file(filepath, sep='=', comment_char='#'):
|
|
|
"""
|
|
@@ -64,4 +71,4 @@ def load_properties_from_file(filepath, sep='=', comment_char='#'):
|
|
|
key = key_value[0].strip()
|
|
|
value = sep.join(key_value[1:]).strip('" \t')
|
|
|
props[key] = value
|
|
|
- return props
|
|
|
+ return props
|