aboutsummaryrefslogtreecommitdiffstats
path: root/policyhandler/deploy_handler.py
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2019-04-01 11:32:06 -0400
committerAlex Shatov <alexs@att.com>2019-04-01 11:32:06 -0400
commit9a4d3c5b8dc9c7697275cab38ee45b014dff9e55 (patch)
treed4d55bcc8bc237ee3199d0e6a13f5e7cd95fadea /policyhandler/deploy_handler.py
parentebc1a062328e53e97e4d24ed111534cfc567a809 (diff)
5.0.0 policy-handler - new PDP API or old PDP API4.0.0-ONAPdublin
- in R4 Dublin the policy-engine introduced a totally new API - policy-handler now has a startup option to either use the new PDP API or the old PDP API that was created-updated before the end of 2018 - see README.md and README_pdp_api_v0.md for instructions on how to setup the policy-handler running either with the new PDP API or the old (pdp_api_v0) PDP API - this is a massive refactoring that changed almost all the source files, but kept the old logic when using the old (pdp_api_v0) PDP API - all the code related to PDP API version is split into two subfolders = pdp_api/ contains the new PDP API source code = pdp_api_v0/ contains the old (2018) PDP API source code = pdp_client.py imports from either pdp_api or pdp_api_v0 = the rest of the code is only affected when it needs to branch the logic - logging to policy_handler.log now shows the path of the source file to allow tracing which PDP API is actually used - when the new PDP API is used, the policy-update flow is disabled = passive mode of operation = no web-socket = no periodic catch_up = no policy-filters = reduced web-API - only a single /policy_latest endpoint is available /policies_latest returns 404 /catch_up request is accepted, but ignored - on new PDP API: http /policy_latest returns the new data from the new PDP API with the following fields added by the policy-handler to keep other policy related parts intact in R4 (see pdp_api/policy_utils.py) = "policyName" = policy_id + "." + "policyVersion" + ".xml" = "policyVersion" = str("metadata"."policy-version") = "config" - is the renamed "properties" from the new PDP API response - unit tests are split into two subfolders as well = main/ for the new PDP API testing = pdp_api_v0/ for the old (2018) PDP API - removed the following line from the license text of changed files ECOMP is a trademark and service mark of AT&T Intellectual Property. - the new PDP API is expected to be extended and redesigned in R5 El Alto - on retiring the old PDP API - the intention is to be able to remove the pdp_api_v0/ subfolder and minimal related cleanup of the code that imports that as well as the cleanup of the config.py, etc. Change-Id: Ief9a2ae4541300308caaf97377f4ed051535dbe4 Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-1128
Diffstat (limited to 'policyhandler/deploy_handler.py')
-rw-r--r--policyhandler/deploy_handler.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/policyhandler/deploy_handler.py b/policyhandler/deploy_handler.py
index 0ffacba..a127e54 100644
--- a/policyhandler/deploy_handler.py
+++ b/policyhandler/deploy_handler.py
@@ -1,5 +1,5 @@
# ================================================================================
-# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
+# Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -14,12 +14,10 @@
# limitations under the License.
# ============LICENSE_END=========================================================
#
-# ECOMP is a trademark and service mark of AT&T Intellectual Property.
"""send policy-update notification to deployment-handler"""
import json
-import logging
from copy import copy, deepcopy
from threading import Lock
@@ -32,7 +30,9 @@ from .onap.audit import (REQUEST_X_ECOMP_REQUESTID, AuditHttpCode,
from .policy_consts import (CATCH_UP, LATEST_POLICIES, POLICIES,
POLICY_FILTER_MATCHES, POLICY_FILTERS,
REMOVED_POLICIES, TARGET_ENTITY)
+from .utils import Utils
+_LOGGER = Utils.get_logger(__file__)
class PolicyUpdateMessage(object):
"""class for messages to deployment-handler on policy-update"""
@@ -143,7 +143,6 @@ class PolicyUpdateMessage(object):
class DeployHandler(object):
"""calling the deployment-handler web apis"""
- _logger = logging.getLogger("policy_handler.deploy_handler")
DEFAULT_TARGET_ENTITY = "deployment_handler"
DEFAULT_TIMEOUT_IN_SECS = 60
@@ -202,7 +201,7 @@ class DeployHandler(object):
tls_ca_mode = config_dh.get(Config.TLS_CA_MODE)
DeployHandler._custom_kwargs = Config.get_requests_kwargs(tls_ca_mode)
- DeployHandler._logger.info(
+ _LOGGER.info(
"dns based routing to %s: url(%s) tls_ca_mode(%s) custom_kwargs(%s)",
DeployHandler._target_entity, DeployHandler._url,
tls_ca_mode, json.dumps(DeployHandler._custom_kwargs))
@@ -221,8 +220,8 @@ class DeployHandler(object):
DeployHandler._target_entity)
DeployHandler._url_policy = str(DeployHandler._url or "") + '/policy'
- DeployHandler._logger.info("got %s policy url(%s): %s", DeployHandler._target_entity,
- DeployHandler._url_policy, DeployHandler._settings)
+ _LOGGER.info("got %s policy url(%s): %s", DeployHandler._target_entity,
+ DeployHandler._url_policy, DeployHandler._settings)
DeployHandler._settings.commit_change()
DeployHandler._lazy_inited = bool(DeployHandler._url)
@@ -310,12 +309,12 @@ class DeployHandler(object):
json.dumps(params), timeout_in_secs, json.dumps(custom_kwargs))
log_line = log_action + " " + log_data
- DeployHandler._logger.info(log_line)
+ _LOGGER.info(log_line)
metrics.metrics_start(log_line)
if not DeployHandler._url:
error_msg = "no url found to {0}".format(log_line)
- DeployHandler._logger.error(error_msg)
+ _LOGGER.error(error_msg)
metrics.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value)
audit.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value)
metrics.metrics(error_msg)
@@ -331,7 +330,7 @@ class DeployHandler(object):
else AuditHttpCode.SERVER_INTERNAL_ERROR.value)
error_msg = "failed to {} {}: {} {}".format(
log_action, type(ex).__name__, str(ex), log_data)
- DeployHandler._logger.exception(error_msg)
+ _LOGGER.exception(error_msg)
metrics.set_http_status_code(error_code)
audit.set_http_status_code(error_code)
metrics.metrics(error_msg)
@@ -345,10 +344,10 @@ class DeployHandler(object):
metrics.metrics(log_line)
if res.status_code != requests.codes.ok:
- DeployHandler._logger.error(log_line)
+ _LOGGER.error(log_line)
return
- DeployHandler._logger.info(log_line)
+ _LOGGER.info(log_line)
result = res.json() or {}
DeployHandler._server_instance_changed(result, metrics)
@@ -379,12 +378,12 @@ class DeployHandler(object):
json.dumps(headers), json.dumps(params), timeout_in_secs, json.dumps(custom_kwargs))
log_line = log_action + " " + log_data
- DeployHandler._logger.info(log_line)
+ _LOGGER.info(log_line)
metrics.metrics_start(log_line)
if not DeployHandler._url:
error_msg = "no url found to {}".format(log_line)
- DeployHandler._logger.error(error_msg)
+ _LOGGER.error(error_msg)
metrics.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value)
audit.set_http_status_code(AuditHttpCode.SERVICE_UNAVAILABLE_ERROR.value)
metrics.metrics(error_msg)
@@ -400,7 +399,7 @@ class DeployHandler(object):
else AuditHttpCode.SERVER_INTERNAL_ERROR.value)
error_msg = "failed to {} {}: {} {}".format(
log_action, type(ex).__name__, str(ex), log_data)
- DeployHandler._logger.exception(error_msg)
+ _LOGGER.exception(error_msg)
metrics.set_http_status_code(error_code)
audit.set_http_status_code(error_code)
metrics.metrics(error_msg)
@@ -414,7 +413,7 @@ class DeployHandler(object):
metrics.metrics(log_line)
if res.status_code != requests.codes.ok:
- DeployHandler._logger.error(log_line)
+ _LOGGER.error(log_line)
return None, None
result = res.json() or {}
@@ -424,12 +423,12 @@ class DeployHandler(object):
policy_filters = result.get(POLICY_FILTERS, {})
if not policies and not policy_filters:
audit.set_http_status_code(AuditHttpCode.DATA_NOT_FOUND_OK.value)
- DeployHandler._logger.warning(audit.warn(
+ _LOGGER.warning(audit.warn(
"found no deployed policies or policy-filters: {}".format(log_line),
error_code=AuditResponseCode.DATA_ERROR))
return policies, policy_filters
- DeployHandler._logger.info(log_line)
+ _LOGGER.info(log_line)
return policies, policy_filters
@staticmethod
@@ -442,6 +441,6 @@ class DeployHandler(object):
and prev_server_instance_uuid != DeployHandler._server_instance_uuid):
DeployHandler.server_instance_changed = True
- DeployHandler._logger.info(metrics.info(
+ _LOGGER.info(metrics.info(
"deployment_handler_changed: {1} != {0}"
.format(prev_server_instance_uuid, DeployHandler._server_instance_uuid)))