X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=oti%2Fevent-handler%2Fotihandler%2Fweb_server.py;h=45c407f18c6562c1d56687129d9ea7d1924df842;hb=18512176d62ae211d97952027ca6a6dc59b50992;hp=f3eb0718463ab439a4a6677bc2e5151d3197f1a2;hpb=83f85998b01c7937b84549d81f5ec2a07958f96d;p=dcaegen2%2Fplatform.git diff --git a/oti/event-handler/otihandler/web_server.py b/oti/event-handler/otihandler/web_server.py index f3eb071..45c407f 100644 --- a/oti/event-handler/otihandler/web_server.py +++ b/oti/event-handler/otihandler/web_server.py @@ -180,6 +180,8 @@ class _DTIWeb(object): if cherrypy.request.method != "POST": raise cherrypy.HTTPError(404, "unexpected method {}".format(cherrypy.request.method)) + msg = "" + dti_event = cherrypy.request.json or {} str_dti_event = json.dumps(dti_event) @@ -192,38 +194,38 @@ class _DTIWeb(object): dcae_service_action = dti_event.get('dcae_service_action') if not dcae_service_action: msg = 'dcae_service_action is missing' - DTIWeb.logger.error(msg) - raise cherrypy.HTTPError(400, msg) elif dcae_service_action.lower() not in self.VALID_EVENT_TYPES: msg = 'dcae_service_action is invalid' - DTIWeb.logger.error(msg) - raise cherrypy.HTTPError(400,msg) dcae_target_name = dti_event.get('dcae_target_name') - if not dcae_target_name: + if not msg and not dcae_target_name: msg = 'dcae_target_name is missing' - DTIWeb.logger.error(msg) - raise cherrypy.HTTPError(400, msg) dcae_target_type = dti_event.get('dcae_target_type', '') - if not dcae_target_type: + if not msg and not dcae_target_type: msg = 'dcae_target_type is missing' - DTIWeb.logger.error(msg) - raise cherrypy.HTTPError(400, msg) - send_notification = True - if (isinstance(notify, bool) and not notify) or \ - (isinstance(notify, str) and notify.lower() in [ "f", "false", "n", "no" ]): - send_notification = False + if msg: + result = {"ERROR": msg} + + DTIWeb.logger.error("%s: dti_event=%s result=%s", \ + req_info, str_dti_event, json.dumps(result)) + else: + send_notification = True + if (isinstance(notify, bool) and not notify) or \ + (isinstance(notify, str) and notify.lower() in [ "f", "false", "n", "no" ]): + send_notification = False - prc = DTIProcessor(dti_event, send_notification=send_notification) - result = prc.get_result() + prc = DTIProcessor(dti_event, send_notification=send_notification) + result = prc.get_result() - DTIWeb.logger.info("%s: dti_event=%s result=%s", \ - req_info, str_dti_event, json.dumps(result)) + DTIWeb.logger.info("%s: dti_event=%s result=%s", \ + req_info, str_dti_event, json.dumps(result)) success, http_status_code, _ = audit.audit_done(result=json.dumps(result)) - if not success: + if msg: + cherrypy.response.status = "400 Bad Request" + elif not success: cherrypy.response.status = http_status_code return result @@ -537,7 +539,7 @@ class _DTIWeb(object): req_info, service_name, json.dumps(cherrypy.request.headers)) try: - result = CBSRest.get_dti(service_name=service_name, vnf_type=vnf_type, vnf_id=vnf_id, service_location=service_location) + result = CBSRest.get_oti(service_name=service_name, vnf_type=vnf_type, vnf_id=vnf_id, service_location=service_location) except Exception as e: result = {"ERROR": "exception {}: {!s}".format(type(e).__name__, e)} audit.set_http_status_code(404)