From d7f34d4b71ec4d86547628cda351d20bff4d017f Mon Sep 17 00:00:00 2001 From: Alex Shatov Date: Tue, 7 Aug 2018 12:11:35 -0400 Subject: 4.0.0 new dataflow on policy-update and catchup - changed API and functionality - new dataflow - new dataflow between policy-handler and deployment-handler on policy-update and catchup = GETting policy_ids+versions and policy-filters from deployment-handler = PUTting policy-update and catchup in the new message format = data segmenting the policy-update/catchup messages to deployment-handler to avoid 413 on deployment-handler side = matching policies from policy-engine to policies and policy-filters from deployment-handler = coarsening the policyName filter received from deployment-handler to reduce the number messages passed to policy-engine on catchup = consolidating sequential policy-updates into a single request when the policy-update is busy - removed policy scope-prefixes from config and logic - it is not needed anymore because = the policy matching happens directly to policies and policy-filters received from deployment-handler = on catchup - the policy scope-prefix equivalents are calculated based on the data received from deployment-handler - API - GET /policies_latest now returns the info on deployed policy_ids+versions and policy-filters, rather than policies of the scope-prefixes previously found in config (obsolete) - not sending an empty catch_up message to deployment-handler when nothing changed - send policy-removed to deployment-handler when getting 404-not found from PDP on removal of policy - config change: removed catch_up.max_skips - obsolete - brought the latest CommonLogger.py - minor refactoring - improved naming of variables Change-Id: I36b3412eefd439088cb693703a6e5f18f4238b00 Signed-off-by: Alex Shatov Issue-ID: DCAEGEN2-492 --- policyhandler/web_server.py | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'policyhandler/web_server.py') diff --git a/policyhandler/web_server.py b/policyhandler/web_server.py index c49536f..24db468 100644 --- a/policyhandler/web_server.py +++ b/policyhandler/web_server.py @@ -16,31 +16,39 @@ # # ECOMP is a trademark and service mark of AT&T Intellectual Property. -"""web-service for policy_handler""" +"""web-server for policy_handler""" -import logging import json +import logging from datetime import datetime + import cherrypy from .config import Config +from .deploy_handler import PolicyUpdateMessage from .onap.audit import Audit -from .policy_rest import PolicyRest +from .policy_matcher import PolicyMatcher from .policy_receiver import PolicyReceiver +from .policy_rest import PolicyRest + class PolicyWeb(object): - """run REST API of policy-handler""" - SERVER_HOST = "0.0.0.0" + """run http API of policy-handler on 0.0.0.0:wservice_port - any incoming address""" + HOST_INADDR_ANY = ".".join("0"*4) logger = logging.getLogger("policy_handler.policy_web") @staticmethod def run_forever(audit): """run the web-server of the policy-handler forever""" - PolicyWeb.logger.info("policy_handler web-service at port(%d)...", Config.wservice_port) - cherrypy.config.update({"server.socket_host": PolicyWeb.SERVER_HOST, - 'server.socket_port': Config.wservice_port}) + PolicyWeb.logger.info("policy_handler web-server on port(%d)...", Config.wservice_port) + cherrypy.config.update({"server.socket_host": PolicyWeb.HOST_INADDR_ANY, + "server.socket_port": Config.wservice_port}) cherrypy.tree.mount(_PolicyWeb(), '/') - audit.info("running policy_handler web-service at port({0})".format(Config.wservice_port)) + audit.info("running policy_handler web-server as {0}:{1}".format( + cherrypy.server.socket_host, cherrypy.server.socket_port)) + PolicyWeb.logger.info("running policy_handler web-server as %s:%d with config: %s", + cherrypy.server.socket_host, cherrypy.server.socket_port, + json.dumps(cherrypy.config)) cherrypy.engine.start() class _PolicyWeb(object): @@ -81,7 +89,9 @@ class _PolicyWeb(object): PolicyWeb.logger.info("%s", req_info) - result = PolicyRest.get_latest_policies(audit) + result, policy_update = PolicyMatcher.get_latest_policies(audit) + if policy_update and isinstance(policy_update, PolicyUpdateMessage): + result["policy_update"] = policy_update.get_message() PolicyWeb.logger.info("result %s: %s", req_info, json.dumps(result)) @@ -96,8 +106,7 @@ class _PolicyWeb(object): @cherrypy.tools.json_in() def policies_latest(self): """ - on :GET: retrieves all the latest policies from policy-engine that are - in the scope of the policy-handler. + on :GET: retrieves all the latest policies from policy-engine that are deployed on :POST: expects to receive the params that mimic the /getConfig of policy-engine and retrieves the matching policies from policy-engine and picks the latest on each policy. -- cgit 1.2.3-korg