From b85e3069bb0791005abecd02b5d4bfb4ce62b822 Mon Sep 17 00:00:00 2001 From: Telles Nobrega Date: Wed, 27 Feb 2019 17:15:17 -0300 Subject: [PATCH] Adding string to int conversion In python 2 this comparisson is possible but it fails on python3. Change-Id: I5a8f11b3cc7596e2974d2655278c48ab1fadb4e2 --- .../plugins/spark/config_helper.py | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/sahara_plugin_spark/plugins/spark/config_helper.py b/sahara_plugin_spark/plugins/spark/config_helper.py index 810b6cf..9bdfe50 100644 --- a/sahara_plugin_spark/plugins/spark/config_helper.py +++ b/sahara_plugin_spark/plugins/spark/config_helper.py @@ -441,7 +441,7 @@ def generate_hadoop_setup_script(storage_paths, env_configs): def generate_job_cleanup_config(cluster): - args = { + spark_config = { 'minimum_cleanup_megabytes': utils.get_config_value_or_default( "Spark", "Minimum cleanup megabytes", cluster), 'minimum_cleanup_seconds': utils.get_config_value_or_default( @@ -449,9 +449,15 @@ def generate_job_cleanup_config(cluster): 'maximum_cleanup_seconds': utils.get_config_value_or_default( "Spark", "Maximum cleanup seconds", cluster) } - job_conf = {'valid': (args['maximum_cleanup_seconds'] > 0 and - (args['minimum_cleanup_megabytes'] > 0 - and args['minimum_cleanup_seconds'] > 0))} + job_conf = { + 'valid': ( + _convert_config_to_int( + spark_config['maximum_cleanup_seconds']) > 0 and + _convert_config_to_int( + spark_config['minimum_cleanup_megabytes']) > 0 and + _convert_config_to_int( + spark_config['minimum_cleanup_seconds']) > 0) + } if job_conf['valid']: job_conf['cron'] = utils.get_file_text( 'plugins/spark/resources/spark-cleanup.cron', @@ -459,10 +465,17 @@ def generate_job_cleanup_config(cluster): job_cleanup_script = utils.get_file_text( 'plugins/spark/resources/tmp-cleanup.sh.template', 'sahara_plugin_spark') - job_conf['script'] = job_cleanup_script.format(**args) + job_conf['script'] = job_cleanup_script.format(**spark_config) return job_conf +def _convert_config_to_int(config_value): + try: + return int(config_value) + except ValueError: + return -1 + + def extract_name_values(configs): return {cfg['name']: cfg['value'] for cfg in configs}