diff options
author | Alex Shatov <alexs@att.com> | 2018-01-10 11:00:50 -0500 |
---|---|---|
committer | Alex Shatov <alexs@att.com> | 2018-01-10 11:07:30 -0500 |
commit | 1369bea8b3c24ef063799acefbfc01659878f034 (patch) | |
tree | 95fa3e5580f62be9c1e1d630ed0c6496b9fb03a2 /policyhandler/deploy_handler.py | |
parent | dc5da5bf63ae4a4ac11b4b5c46407e58da16fbfe (diff) |
variable collection of policies per component
* new feature variable collection of policies per component in DCAE
* massive refactoring
* dissolved the external PolicyEngine.py into policy_receiver.py
- kept only the web-socket communication to PolicyEngine
* new /healthcheck - shows some stats of service running
* Unit Test coverage 75%
Change-Id: I816b7d5713ae0dd88fa73d3656f272b4f3e7946e
Issue-ID: DCAEGEN2-249
Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'policyhandler/deploy_handler.py')
-rw-r--r-- | policyhandler/deploy_handler.py | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/policyhandler/deploy_handler.py b/policyhandler/deploy_handler.py index 1d50fc3..a641a95 100644 --- a/policyhandler/deploy_handler.py +++ b/policyhandler/deploy_handler.py @@ -59,14 +59,27 @@ class DeployHandler(object): DeployHandler._target_entity = Config.config["deploy_handler"] DeployHandler._url = DiscoveryClient.get_service_url(DeployHandler._target_entity) - DeployHandler._url_path = DeployHandler._url + '/policy' + DeployHandler._url_path = (DeployHandler._url or "") + '/policy' DeployHandler._logger.info("DeployHandler url(%s)", DeployHandler._url) @staticmethod - def policy_update(audit, latest_policies): - """ post policy_updated message to deploy-handler """ + def policy_update(audit, latest_policies, removed_policies=None, + errored_policies=None, catch_up=False): + """post policy_updated message to deploy-handler""" + if not latest_policies and not removed_policies and not catch_up: + return + + latest_policies = latest_policies or {} + removed_policies = removed_policies or {} + errored_policies = errored_policies or {} + DeployHandler._lazy_init() - msg = {"latest_policies":latest_policies} + msg = { + "catch_up" : catch_up, + "latest_policies" : latest_policies, + "removed_policies" : removed_policies, + "errored_policies" : errored_policies + } sub_aud = Audit(aud_parent=audit, targetEntity=DeployHandler._target_entity, targetServiceName=DeployHandler._url_path) headers = {REQUEST_X_ECOMP_REQUESTID : sub_aud.request_id} @@ -74,10 +87,22 @@ class DeployHandler(object): msg_str = json.dumps(msg) headers_str = json.dumps(headers) + DeployHandler._logger.info( + "catch_up(%s) latest_policies[%s], removed_policies[%s], errored_policies[%s]", + catch_up, len(latest_policies), len(removed_policies), len(errored_policies)) log_line = "post to deployment-handler {0} msg={1} headers={2}".format( DeployHandler._url_path, msg_str, headers_str) - sub_aud.metrics_start(log_line) + DeployHandler._logger.info(log_line) + sub_aud.metrics_start(log_line) + + if not DeployHandler._url: + error_msg = "no url found to {0}".format(log_line) + DeployHandler._logger.error(error_msg) + sub_aud.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value) + audit.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value) + sub_aud.metrics(error_msg) + return res = None try: |