diff options
author | Alex Shatov <alexs@att.com> | 2018-03-08 13:12:23 -0500 |
---|---|---|
committer | Alex Shatov <alexs@att.com> | 2018-03-08 13:12:23 -0500 |
commit | b9b955c0c2875effc1ce02d5576f0d2a59284c5d (patch) | |
tree | c073f6678be20cc4371bd1e91ca2796a6abf330d /policyhandler/deploy_handler.py | |
parent | dfd79f0cb9f8d418871b5fb7f3616554c3261800 (diff) |
2.2.0 policy-handler - customization per company
- added etc_customize/ folder and customize.sh script
= customize.sh script is expected to be overridden by company
to customize Docker image build
= the whole etc_customize/ folder is copied into docker image
= it is up to the company what to put into that folder - any files
- added customize/ folder with CustomizeBase and Customize classes
= CustomizeBase defines the interface and the default=ONAP behavior
= CustomizeBase is owned by ONAP and should not be changed
by the company
= Customize inherits CustomizeBase
= policy-handler instantiates Customize
to get the customized behavior
= Customize is owned by the company and should be changed
by the company = ONAP is not going to change Customize
= the methods of Customize are expected to be overridden
by the company to change the behavior of the policy-handler
= sample Customize class can be found in README.md
= Company is allowed to add more files to customize/ folder
if that is required for better structuring of their code
as soon as it is invoked by the methods of Customize
Change-Id: I46f8170afaaa48e1005e4398a768a781db0a0e6c
Signed-off-by: Alex Shatov <alexs@att.com>
Issue-ID: DCAEGEN2-379
Diffstat (limited to 'policyhandler/deploy_handler.py')
-rw-r--r-- | policyhandler/deploy_handler.py | 39 |
1 files changed, 23 insertions, 16 deletions
diff --git a/policyhandler/deploy_handler.py b/policyhandler/deploy_handler.py index 5792631..0950dfd 100644 --- a/policyhandler/deploy_handler.py +++ b/policyhandler/deploy_handler.py @@ -18,13 +18,15 @@ """ send notification to deploy-handler""" -import logging import json +import logging + import requests from .config import Config from .discovery import DiscoveryClient from .onap.audit import REQUEST_X_ECOMP_REQUESTID, Audit, AuditHttpCode +from .customize import CustomizerUser POOL_SIZE = 1 @@ -38,14 +40,21 @@ class DeployHandler(object): _url = None _url_path = None _target_entity = None + _custom_kwargs = None @staticmethod - def _lazy_init(): + def _lazy_init(audit): """ set static properties """ if DeployHandler._lazy_inited: return DeployHandler._lazy_inited = True + DeployHandler._custom_kwargs = CustomizerUser.get_customizer() \ + .get_deploy_handler_kwargs(audit) + if not DeployHandler._custom_kwargs \ + or not isinstance(DeployHandler._custom_kwargs, dict): + DeployHandler._custom_kwargs = {} + DeployHandler._requests_session = requests.Session() DeployHandler._requests_session.mount( 'https://', @@ -56,8 +65,8 @@ class DeployHandler(object): requests.adapters.HTTPAdapter(pool_connections=POOL_SIZE, pool_maxsize=POOL_SIZE) ) - DeployHandler._target_entity = Config.config["deploy_handler"] - DeployHandler._url = DiscoveryClient.get_service_url(DeployHandler._target_entity) + DeployHandler._target_entity = Config.config.get("deploy_handler", "deploy_handler") + DeployHandler._url = DiscoveryClient.get_service_url(audit, DeployHandler._target_entity) DeployHandler._url_path = (DeployHandler._url or "") + '/policy' DeployHandler._logger.info("DeployHandler url(%s)", DeployHandler._url) @@ -67,7 +76,7 @@ class DeployHandler(object): if not message: return - DeployHandler._lazy_init() + DeployHandler._lazy_init(audit) sub_aud = Audit(aud_parent=audit, targetEntity=DeployHandler._target_entity, targetServiceName=DeployHandler._url_path) headers = {REQUEST_X_ECOMP_REQUESTID : sub_aud.request_id} @@ -75,10 +84,10 @@ class DeployHandler(object): msg_str = json.dumps(message) headers_str = json.dumps(headers) - DeployHandler._logger.info("message: %s", msg_str) - log_line = "post to deployment-handler {0} msg={1} headers={2}".format( - DeployHandler._url_path, msg_str, headers_str) - + log_action = "post to {0} at {1}".format( + DeployHandler._target_entity, DeployHandler._url_path) + log_data = " msg={0} headers={1}".format(msg_str, headers_str) + log_line = log_action + log_data DeployHandler._logger.info(log_line) sub_aud.metrics_start(log_line) @@ -93,11 +102,11 @@ class DeployHandler(object): res = None try: res = DeployHandler._requests_session.post( - DeployHandler._url_path, json=message, headers=headers + DeployHandler._url_path, json=message, headers=headers, + **DeployHandler._custom_kwargs ) except requests.exceptions.RequestException as ex: - error_msg = "failed to post to deployment-handler {0} {1} msg={2} headers={3}" \ - .format(DeployHandler._url_path, str(ex), msg_str, headers_str) + error_msg = "failed to {0}: {1}{2}".format(log_action, str(ex), log_data) DeployHandler._logger.exception(error_msg) sub_aud.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value) audit.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value) @@ -107,10 +116,8 @@ class DeployHandler(object): sub_aud.set_http_status_code(res.status_code) audit.set_http_status_code(res.status_code) - sub_aud.metrics( - "response from deployment-handler to post {0}: {1} msg={2} text={3} headers={4}" \ - .format(DeployHandler._url_path, res.status_code, msg_str, res.text, - res.request.headers)) + sub_aud.metrics("response {0} from {1}: text={2}{3}" \ + .format(res.status_code, log_action, res.text, log_data)) if res.status_code == requests.codes.ok: return res.json() |