summaryrefslogtreecommitdiffstats
path: root/policyhandler/web_server.py
diff options
context:
space:
mode:
Diffstat (limited to 'policyhandler/web_server.py')
-rw-r--r--policyhandler/web_server.py33
1 files changed, 21 insertions, 12 deletions
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.