From 40c3915a17dd9f47bb13250b2b4f06307171360e Mon Sep 17 00:00:00 2001 From: iPablo Date: Fri, 13 Nov 2015 10:24:22 +0100 Subject: [PATCH 1/3] Added new variable settings --- config-templates/development.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/config-templates/development.ini b/config-templates/development.ini index 841a4a37..65ea94ae 100644 --- a/config-templates/development.ini +++ b/config-templates/development.ini @@ -28,6 +28,7 @@ chef.url = https://localhost/chef/api/ chef.cookbook_name = gecos_ws_mgmt chef.seconds_sleep_is_busy = 5 chef.seconds_block_is_busy = 3600 +chef.heuristic_parameter = 3 ## Change this if you dont want to use mongo ## BROKER_URL = mongodb://localhost:27017/gecoscc ## CELERY_RESULT_BACKEND = mongodb From 20b5164782e9a3f537a186d4a3824fe009db2d6b Mon Sep 17 00:00:00 2001 From: iPablo Date: Fri, 13 Nov 2015 10:25:08 +0100 Subject: [PATCH 2/3] Temporary solution to the concurrency problem --- gecoscc/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gecoscc/utils.py b/gecoscc/utils.py index 2f3b33b6..89238533 100644 --- a/gecoscc/utils.py +++ b/gecoscc/utils.py @@ -252,10 +252,17 @@ def is_node_busy_and_reserve_it(node_id, api, controller_requestor='gcc', attemp def _is_node_busy_and_reserve_it(node_id, api, controller_requestor='gcc'): + ''' + Check if the node is busy, else try to get it and write in control and expiration date in the field USE_NODE. + ''' settings = get_current_registry().settings seconds_block_is_busy = int(settings.get('chef.seconds_block_is_busy')) time_to_exp = datetime.timedelta(seconds=seconds_block_is_busy) + + time_get = time.time() node = ChefNode(node_id, api) + time_get = time.time() - time_get + current_use_node = node.attributes.get(USE_NODE, {}) current_use_node_control = current_use_node.get('control', None) current_use_node_exp_date = current_use_node.get('exp_date', None) @@ -272,6 +279,11 @@ def _is_node_busy_and_reserve_it(node_id, api, controller_requestor='gcc'): node.attributes.set_dotted(USE_NODE, {'control': controller_requestor, 'exp_date': json.dumps(exp_date, default=json_util.default)}) node.save() + + heuristic_parameter = settings.get('chef.heuristic_parameter', 3) + seconds_sleep_is_busy = time_get * int(heuristic_parameter) + time.sleep(seconds_sleep_is_busy) + node2 = ChefNode(node.name, api) # second check current_use_node2 = node2.attributes.get(USE_NODE, {}) current_use_control2 = current_use_node2.get('control', None) From fc34630734a8737c399a98cdb252d96900648446 Mon Sep 17 00:00:00 2001 From: iPablo Date: Fri, 13 Nov 2015 12:48:39 +0100 Subject: [PATCH 3/3] Changed name parameter and added comments --- config-templates/development.ini | 5 ++++- gecoscc/utils.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config-templates/development.ini b/config-templates/development.ini index 65ea94ae..46a8e977 100644 --- a/config-templates/development.ini +++ b/config-templates/development.ini @@ -28,7 +28,10 @@ chef.url = https://localhost/chef/api/ chef.cookbook_name = gecos_ws_mgmt chef.seconds_sleep_is_busy = 5 chef.seconds_block_is_busy = 3600 -chef.heuristic_parameter = 3 +# smart_lock_sleep_factor is use to avoid concurrency problem +# We use this parameter to sleep the process between GET and POST request. +# It's a temporary solution +chef.smart_lock_sleep_factor = 3 ## Change this if you dont want to use mongo ## BROKER_URL = mongodb://localhost:27017/gecoscc ## CELERY_RESULT_BACKEND = mongodb diff --git a/gecoscc/utils.py b/gecoscc/utils.py index 89238533..a05055b1 100644 --- a/gecoscc/utils.py +++ b/gecoscc/utils.py @@ -280,8 +280,8 @@ def _is_node_busy_and_reserve_it(node_id, api, controller_requestor='gcc'): 'exp_date': json.dumps(exp_date, default=json_util.default)}) node.save() - heuristic_parameter = settings.get('chef.heuristic_parameter', 3) - seconds_sleep_is_busy = time_get * int(heuristic_parameter) + smart_lock_sleep_parameter = settings.get('chef.smart_lock_sleep_factor', 3) + seconds_sleep_is_busy = time_get * int(smart_lock_sleep_parameter) time.sleep(seconds_sleep_is_busy) node2 = ChefNode(node.name, api) # second check