From 349bbf794dbc34a96755ae40e98b8ba83a074a02 Mon Sep 17 00:00:00 2001 From: krishnaa96 Date: Thu, 14 May 2020 18:22:46 +0530 Subject: Handle has exceptions for slice selection Issue-ID: OPTFRA-754 Signed-off-by: krishnaa96 Change-Id: I66904680a4b9a2bc69c144f05b95fb4f999d0e93 --- .../optimizers/conductor/remote_opt_processor.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'apps/slice_selection/optimizers') diff --git a/apps/slice_selection/optimizers/conductor/remote_opt_processor.py b/apps/slice_selection/optimizers/conductor/remote_opt_processor.py index b34c8b1..40638fc 100644 --- a/apps/slice_selection/optimizers/conductor/remote_opt_processor.py +++ b/apps/slice_selection/optimizers/conductor/remote_opt_processor.py @@ -66,10 +66,13 @@ def process_nsi_selection_opt(request_json, osdf_config): request_parameters = request_json.get('serviceProfile',{}) service_info = {} req_info['numSolutions'] = 'all' - resp = conductor.request(req_info, demands, request_parameters, service_info, False, - osdf_config, policies) - if resp["plans"][0].get("status") == "not found": - resp["recommendations"] = list() + try: + resp = conductor.request(req_info, demands, request_parameters, service_info, False, + osdf_config, policies) + except RequestException as e: + resp = e.response.json() + error = resp['plans'][0]['message'] + error_log.error('Error from conductor {}'.format(error)) debug_log.debug("Response from conductor {}".format(str(resp))) overall_recommendations[nst_name] = resp["plans"][0].get("recommendations") @@ -78,18 +81,12 @@ def process_nsi_selection_opt(request_json, osdf_config): solutions['newNSISolutions'] = new_nsi_solutions solutions['sharedNSISolutions'] = [] return get_nsi_selection_response(req_info, solutions) - else: + else: return conductor_response_processor(overall_recommendations, nst_info_map, req_info, request_json["serviceProfile"]) except Exception as ex: error_log.error("Error for {} {}".format(req_info.get('requestId'), traceback.format_exc())) - if isinstance(ex, RequestException): - try: - error_message = json.loads(ex.response)['plans'][0]['message'] - except Exception: - error_message = "Problem connecting to conductor" - else: - error_message = str(ex) + error_message = str(ex) return conductor_error_response_processor(req_info, error_message) -- cgit 1.2.3-korg