diff options
author | Alex Shatov <alexs@att.com> | 2019-04-01 11:32:06 -0400 |
---|---|---|
committer | Alex Shatov <alexs@att.com> | 2019-04-01 11:32:06 -0400 |
commit | 9a4d3c5b8dc9c7697275cab38ee45b014dff9e55 (patch) | |
tree | d4d55bcc8bc237ee3199d0e6a13f5e7cd95fadea /policyhandler/service_activator.py | |
parent | ebc1a062328e53e97e4d24ed111534cfc567a809 (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/service_activator.py')
-rw-r--r-- | policyhandler/service_activator.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/policyhandler/service_activator.py b/policyhandler/service_activator.py index d51d11c..9c8a1b2 100644 --- a/policyhandler/service_activator.py +++ b/policyhandler/service_activator.py @@ -14,7 +14,6 @@ # limitations under the License. # ============LICENSE_END========================================================= # -# ECOMP is a trademark and service mark of AT&T Intellectual Property. """ ask service_activator for the mode_of_operation @@ -30,23 +29,25 @@ """ import json -import logging from copy import deepcopy from urllib.parse import urljoin import requests from .config import Config, Settings -from .onap.audit import REQUEST_X_ECOMP_REQUESTID, AuditHttpCode, Metrics +from .onap.audit import (REQUEST_X_ECOMP_REQUESTID, Audit, AuditHttpCode, + Metrics) from .policy_consts import TARGET_ENTITY +from .utils import Utils +_LOGGER = Utils.get_logger(__file__) class ServiceActivator(object): """calling the service_activator web api to determine the mode_of_operation""" - _logger = logging.getLogger("policy_handler.service_activator") DEFAULT_TARGET_ENTITY = "service_activator" DEFAULT_TIMEOUT_IN_SECS = 10 MODE_OF_OPERATION_ACTIVE = "active" + SERVICE_MODE = "service_mode" _lazy_inited = False _settings = Settings(Config.MODE_OF_OPERATION, Config.SERVICE_ACTIVATOR) @@ -81,6 +82,7 @@ class ServiceActivator(object): """ ServiceActivator._custom_kwargs = {} ServiceActivator._url = ServiceActivator._url_register = "" + Audit.register_item_health(ServiceActivator.SERVICE_MODE, ServiceActivator._get_service_mode) try: _, ServiceActivator._mode_of_operation = ServiceActivator._settings.get_by_key( @@ -98,7 +100,7 @@ class ServiceActivator(object): tls_ca_mode = config_sa.get(Config.TLS_CA_MODE) ServiceActivator._custom_kwargs = Config.get_requests_kwargs(tls_ca_mode) - ServiceActivator._logger.info(audit.info( + _LOGGER.info(audit.info( "dns based routing to %s: url(%s) tls_ca_mode(%s) custom_kwargs(%s)", ServiceActivator._target_entity, ServiceActivator._url_register, tls_ca_mode, json.dumps(ServiceActivator._custom_kwargs))) @@ -134,17 +136,31 @@ class ServiceActivator(object): ServiceActivator._init(audit) @staticmethod - def is_active_mode_of_operation(audit): + def _get_service_mode(): + """returns the service_mode as json to be reported by the healthcheck""" + return { + "is_active_mode_of_operation": ServiceActivator.is_active_mode_of_operation(), + "is_pdp_api_default": Config.is_pdp_api_default(log_status=False) + } + + @staticmethod + def is_active_mode_of_operation(audit=None): """ mode_of_operation - whether the service is active == True or passive == False based on the current value of the mode_of_operation + + temporary for R4 Dublin - passive for new PDP API """ active = (ServiceActivator._mode_of_operation is None or ServiceActivator._mode_of_operation == ServiceActivator.MODE_OF_OPERATION_ACTIVE) - ServiceActivator._logger.info(audit.info( - "mode_of_operation = {} active = {}".format( + + if active and Config.is_pdp_api_default(): + active = False + + if audit: + _LOGGER.info(audit.info("mode_of_operation = {} active = {}".format( ServiceActivator._mode_of_operation, active))) return active @@ -157,8 +173,7 @@ class ServiceActivator(object): target_entity = ServiceActivator._target_entity if not ServiceActivator._url: - ServiceActivator._logger.info(audit.info( - "no url found for {}".format(target_entity))) + _LOGGER.info(audit.info("no url found for {}".format(target_entity))) return ServiceActivator.is_active_mode_of_operation(audit) url = ServiceActivator._url_register @@ -177,7 +192,7 @@ class ServiceActivator(object): json.dumps(custom_kwargs)) log_line = log_action + " " + log_data - ServiceActivator._logger.info(log_line) + _LOGGER.info(log_line) metrics.metrics_start(log_line) res = None @@ -190,7 +205,7 @@ class ServiceActivator(object): else AuditHttpCode.SERVER_INTERNAL_ERROR.value) error_msg = "failed to {} {}: {} {}".format( log_action, type(ex).__name__, str(ex), log_data) - ServiceActivator._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) @@ -204,7 +219,7 @@ class ServiceActivator(object): metrics.metrics(log_line) if res.status_code != requests.codes.ok: - ServiceActivator._logger.error(log_line) + _LOGGER.error(log_line) return ServiceActivator.is_active_mode_of_operation(audit) result = res.json() or {} |