aboutsummaryrefslogtreecommitdiffstats
path: root/policyhandler
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-09-20 15:15:45 -0400
committerAlex Shatov <alexs@att.com>2018-09-20 15:15:45 -0400
commit209f8239c17c437cd15518ae4c111af4147a6a64 (patch)
treeb347f981de960b3f1d2de7566a3223f72d2efd1e /policyhandler
parent2d0b15c1bfc707e37447d4b64686285c1e23c533 (diff)
4.4.0 policy-handler - configurable consul-url4.4.03.0.1-ONAP3.0.0-ONAPcasablanca
- made consul-url configurable thru env var or local config consul url is taken from env var $CONSUL_URL if not provided, then from consul_url in etc/config.json if not provided, then from hardcoded value of http://consul:8500 - per request from convergence team - needed to avoid the collision between two consuls provided by ONAP/OOM/DCAE and cloudify ver >= 4.x Change-Id: Ic702c872bda3d851842ec41085480a9df200cbde Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-822
Diffstat (limited to 'policyhandler')
-rw-r--r--policyhandler/config.py6
-rw-r--r--policyhandler/discovery.py20
2 files changed, 18 insertions, 8 deletions
diff --git a/policyhandler/config.py b/policyhandler/config.py
index a69954f..d94ed79 100644
--- a/policyhandler/config.py
+++ b/policyhandler/config.py
@@ -24,7 +24,6 @@ import logging
import logging.config
import os
-from .discovery import DiscoveryClient
from .onap.audit import Audit
from .policy_utils import Utils
@@ -134,6 +133,7 @@ class Config(object):
SERVICE_NAME_POLICY_HANDLER = "policy_handler"
FIELD_SYSTEM = "system"
+ FIELD_CONSUL_URL = "consul_url"
FIELD_WSERVICE_PORT = "wservice_port"
FIELD_TLS = "tls"
FIELD_POLICY_ENGINE = "policy_engine"
@@ -151,6 +151,7 @@ class Config(object):
system_name = SERVICE_NAME_POLICY_HANDLER
wservice_port = 25577
+ consul_url = "http://consul:8500"
tls_cacert_file = None
tls_server_cert_file = None
tls_private_key_file = None
@@ -236,6 +237,8 @@ class Config(object):
logging.config.dictConfig(logging_config)
Config.wservice_port = loaded_config.get(Config.FIELD_WSERVICE_PORT, Config.wservice_port)
+ Config.consul_url = os.environ.get(
+ "CONSUL_URL", loaded_config.get(Config.FIELD_CONSUL_URL, Config.consul_url)).rstrip("/")
local_config = loaded_config.get(Config.SERVICE_NAME_POLICY_HANDLER, {})
Config.system_name = local_config.get(Config.FIELD_SYSTEM, Config.system_name)
@@ -249,6 +252,7 @@ class Config(object):
def discover(audit):
"""bring and merge the config settings from the discovery service"""
discovery_key = Config.system_name
+ from .discovery import DiscoveryClient
new_config = DiscoveryClient.get_value(audit, discovery_key)
if not new_config or not isinstance(new_config, dict):
diff --git a/policyhandler/discovery.py b/policyhandler/discovery.py
index 4e6bc3d..5a35525 100644
--- a/policyhandler/discovery.py
+++ b/policyhandler/discovery.py
@@ -16,7 +16,7 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
-"""client to talk to consul at the standard port 8500"""
+"""client to talk to consul services and kv"""
import base64
import json
@@ -24,18 +24,24 @@ import logging
import requests
+from .config import Config
from .customize import CustomizerUser
from .onap.audit import AuditHttpCode, Metrics
class DiscoveryClient(object):
- """talking to consul at http://consul:8500
+ """talking to consul at Config.consul_url
+
+ Config.consul_url is populated
+ from env var $CONSUL_URL
+ if not provided, then from consul_url in etc/config.json
+ if not provided, then from hardcoded value of http://consul:8500
relies on proper --add-host "consul:<consul-agent ip>" in
docker run command that runs along the consul-agent:
docker run --name ${APPNAME} -d
- -e HOSTNAME
+ -e HOSTNAME -e CONSUL_URL
--add-host "consul:<consul-agent ip>"
-v ${BASEDIR}/logs:${TARGETDIR}/logs
-v ${BASEDIR}/etc:${TARGETDIR}/etc
@@ -43,8 +49,8 @@ class DiscoveryClient(object):
${APPNAME}:latest
"""
CONSUL_ENTITY = "consul"
- CONSUL_SERVICE_MASK = "http://consul:8500/v1/catalog/service/{0}"
- CONSUL_KV_MASK = "http://consul:8500/v1/kv/{0}"
+ CONSUL_SERVICE_MASK = "{}/v1/catalog/service/{}"
+ CONSUL_KV_MASK = "{}/v1/kv/{}"
_logger = logging.getLogger("policy_handler.discovery")
@staticmethod
@@ -63,7 +69,7 @@ class DiscoveryClient(object):
@staticmethod
def get_service_url(audit, service_name):
"""find the service record in consul"""
- service_path = DiscoveryClient.CONSUL_SERVICE_MASK.format(service_name)
+ service_path = DiscoveryClient.CONSUL_SERVICE_MASK.format(Config.consul_url, service_name)
metrics = Metrics(aud_parent=audit, targetEntity=DiscoveryClient.CONSUL_ENTITY,
targetServiceName=service_path)
@@ -116,7 +122,7 @@ class DiscoveryClient(object):
@staticmethod
def get_value(audit, key):
"""get the value for the key from consul-kv"""
- discovery_url = DiscoveryClient.CONSUL_KV_MASK.format(key)
+ discovery_url = DiscoveryClient.CONSUL_KV_MASK.format(Config.consul_url, key)
metrics = Metrics(aud_parent=audit, targetEntity=DiscoveryClient.CONSUL_ENTITY,
targetServiceName=discovery_url)