summaryrefslogtreecommitdiffstats
path: root/policyhandler/discovery.py
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-03-08 13:12:23 -0500
committerAlex Shatov <alexs@att.com>2018-03-08 13:12:23 -0500
commitb9b955c0c2875effc1ce02d5576f0d2a59284c5d (patch)
treec073f6678be20cc4371bd1e91ca2796a6abf330d /policyhandler/discovery.py
parentdfd79f0cb9f8d418871b5fb7f3616554c3261800 (diff)
2.2.0 policy-handler - customization per company
- added etc_customize/ folder and customize.sh script = customize.sh script is expected to be overridden by company to customize Docker image build = the whole etc_customize/ folder is copied into docker image = it is up to the company what to put into that folder - any files - added customize/ folder with CustomizeBase and Customize classes = CustomizeBase defines the interface and the default=ONAP behavior = CustomizeBase is owned by ONAP and should not be changed by the company = Customize inherits CustomizeBase = policy-handler instantiates Customize to get the customized behavior = Customize is owned by the company and should be changed by the company = ONAP is not going to change Customize = the methods of Customize are expected to be overridden by the company to change the behavior of the policy-handler = sample Customize class can be found in README.md = Company is allowed to add more files to customize/ folder if that is required for better structuring of their code as soon as it is invoked by the methods of Customize Change-Id: I46f8170afaaa48e1005e4398a768a781db0a0e6c Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-379
Diffstat (limited to 'policyhandler/discovery.py')
-rw-r--r--policyhandler/discovery.py43
1 files changed, 31 insertions, 12 deletions
diff --git a/policyhandler/discovery.py b/policyhandler/discovery.py
index a7e3c56..ce24c3d 100644
--- a/policyhandler/discovery.py
+++ b/policyhandler/discovery.py
@@ -18,11 +18,14 @@
"""client to talk to consul at the standard port 8500"""
-import logging
-import json
import base64
+import json
+import logging
+
import requests
+from .customize import CustomizerUser
+
class DiscoveryClient(object):
"""talking to consul at http://consul:8500
@@ -39,27 +42,43 @@ class DiscoveryClient(object):
"""
CONSUL_SERVICE_MASK = "http://consul:8500/v1/catalog/service/{0}"
CONSUL_KV_MASK = "http://consul:8500/v1/kv/{0}"
- SERVICE_MASK = "http://{0}:{1}"
- SERVICE_ADDRESS = "ServiceAddress"
- SERVICE_PORT = "ServicePort"
_logger = logging.getLogger("policy_handler.discovery")
-
@staticmethod
- def get_service_url(service_name):
+ def get_service_url(audit, service_name):
"""find the service record in consul"""
service_path = DiscoveryClient.CONSUL_SERVICE_MASK.format(service_name)
- DiscoveryClient._logger.info("discover %s", service_path)
+ log_line = "discover {0}".format(service_path)
+ DiscoveryClient._logger.info(log_line)
+ audit.info(log_line)
response = requests.get(service_path)
+
+ log_line = "response {0} for {1}: {2}".format(
+ response.status_code, service_path, response.text)
+ DiscoveryClient._logger.info(log_line)
+ audit.info(log_line)
+
response.raise_for_status()
+
service = response.json()
if not service:
- DiscoveryClient._logger.error("failed discover %s", service_path)
+ log_line = "failed discover {0}".format(service_path)
+ DiscoveryClient._logger.error(log_line)
+ audit.error(log_line)
return
service = service[0]
- return DiscoveryClient.SERVICE_MASK.format(
- service[DiscoveryClient.SERVICE_ADDRESS], service[DiscoveryClient.SERVICE_PORT]
- )
+
+ service_url = CustomizerUser.get_customizer().get_service_url(audit, service_name, service)
+ if not service_url:
+ log_line = "failed to get service_url for {0}".format(service_name)
+ DiscoveryClient._logger.error(log_line)
+ audit.error(log_line)
+ return
+
+ log_line = "got service_url: {0} for {1}".format(service_url, service_name)
+ DiscoveryClient._logger.info(log_line)
+ audit.info(log_line)
+ return service_url
@staticmethod
def get_value(key):