aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--etc/config.json1
-rw-r--r--policyhandler/config.py6
-rw-r--r--policyhandler/discovery.py20
-rw-r--r--pom.xml2
-rw-r--r--run_policy.sh5
-rw-r--r--setup.py2
-rw-r--r--version.properties4
7 files changed, 26 insertions, 14 deletions
diff --git a/etc/config.json b/etc/config.json
index aa24419..de7f6cc 100644
--- a/etc/config.json
+++ b/etc/config.json
@@ -1,5 +1,6 @@
{
"wservice_port" : 25577,
+ "consul_url" : "http://consul:8500",
"policy_handler" : {
"system" : "policy_handler",
"tls" : {
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)
diff --git a/pom.xml b/pom.xml
index 8a282b0..ed106ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -30,7 +30,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
<groupId>org.onap.dcaegen2.platform</groupId>
<artifactId>policy-handler</artifactId>
<name>dcaegen2-platform-policy-handler</name>
- <version>4.3.1-SNAPSHOT</version>
+ <version>4.4.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/run_policy.sh b/run_policy.sh
index 3b804ec..72069f7 100644
--- a/run_policy.sh
+++ b/run_policy.sh
@@ -25,8 +25,9 @@ echo "---------------------------------------------"
STARTED=$(date +%Y-%m-%d_%T.%N)
echo "${STARTED}: running ${BASH_SOURCE[0]}"
echo "APP_VER =" $(python setup.py --version)
-echo "HOSTNAME =" ${HOSTNAME}
-(uname -a; echo "/etc/hosts"; cat /etc/hosts; pwd; openssl version -a)
+echo "HOSTNAME =${HOSTNAME}"
+echo "CONSUL_URL =${CONSUL_URL}"
+(pwd; uname -a; echo "/etc/hosts"; cat /etc/hosts; openssl version -a)
python -m policyhandler &
PID=$!
diff --git a/setup.py b/setup.py
index c740a94..16d1885 100644
--- a/setup.py
+++ b/setup.py
@@ -23,7 +23,7 @@ from setuptools import setup
setup(
name='policyhandler',
description='DCAE-Controller policy-handler to communicate with policy-engine',
- version="4.3.1",
+ version="4.4.0",
author='Alex Shatov',
packages=['policyhandler'],
zip_safe=False,
diff --git a/version.properties b/version.properties
index af72773..c162183 100644
--- a/version.properties
+++ b/version.properties
@@ -1,6 +1,6 @@
major=4
-minor=3
-patch=1
+minor=4
+patch=0
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT