summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--etc_upload/config.json5
-rw-r--r--policyhandler/deploy_handler.py38
-rw-r--r--policyhandler/onap/audit.py14
-rw-r--r--pom.xml2
-rw-r--r--setup.py2
-rw-r--r--tests/test_policyhandler.py3
-rw-r--r--version.properties4
7 files changed, 44 insertions, 24 deletions
diff --git a/etc_upload/config.json b/etc_upload/config.json
index 920ef7c..1350b37 100644
--- a/etc_upload/config.json
+++ b/etc_upload/config.json
@@ -23,6 +23,9 @@
},
"target_entity" : "policy_engine"
},
- "deploy_handler" : "deployment_handler"
+ "deploy_handler" : {
+ "target_entity" : "deployment_handler",
+ "url" : "http://deployment_handler:8188"
+ }
}
}
diff --git a/policyhandler/deploy_handler.py b/policyhandler/deploy_handler.py
index f1a1294..139e660 100644
--- a/policyhandler/deploy_handler.py
+++ b/policyhandler/deploy_handler.py
@@ -24,9 +24,9 @@ import logging
import requests
from .config import Config
+from .customize import CustomizerUser
from .discovery import DiscoveryClient
from .onap.audit import REQUEST_X_ECOMP_REQUESTID, Audit, AuditHttpCode
-from .customize import CustomizerUser
POOL_SIZE = 1
@@ -38,7 +38,7 @@ class DeployHandler(object):
_requests_session = None
_config = None
_url = None
- _url_path = None
+ _url_policy = None
_target_entity = None
_custom_kwargs = None
_server_instance_uuid = None
@@ -66,10 +66,30 @@ class DeployHandler(object):
requests.adapters.HTTPAdapter(pool_connections=POOL_SIZE, pool_maxsize=POOL_SIZE)
)
- DeployHandler._target_entity = Config.config.get("deploy_handler", "deploy_handler")
- DeployHandler._url = DiscoveryClient.get_service_url(audit, DeployHandler._target_entity)
- DeployHandler._url_path = (DeployHandler._url or "") + '/policy'
- DeployHandler._logger.info("DeployHandler url(%s)", DeployHandler._url)
+ config_dh = Config.config.get("deploy_handler")
+ if config_dh and isinstance(config_dh, dict):
+ # dns based routing to deployment-handler
+ # config for policy-handler >= 2.4.0
+ # "deploy_handler" : {
+ # "target_entity" : "deployment_handler",
+ # "url" : "http://deployment_handler:8188"
+ # }
+ DeployHandler._target_entity = config_dh.get("target_entity", "deployment_handler")
+ DeployHandler._url = config_dh.get("url")
+ DeployHandler._logger.info("dns based routing to %s: url(%s)",
+ DeployHandler._target_entity, DeployHandler._url)
+
+ if not DeployHandler._url:
+ # discover routing to deployment-handler at consul-services
+ if not isinstance(config_dh, dict):
+ # config for policy-handler <= 2.3.1
+ # "deploy_handler" : "deployment_handler"
+ DeployHandler._target_entity = str(config_dh or "deployment_handler")
+ DeployHandler._url = DiscoveryClient.get_service_url(audit, DeployHandler._target_entity)
+
+ DeployHandler._url_policy = str(DeployHandler._url or "") + '/policy'
+ DeployHandler._logger.info(
+ "got %s policy url(%s)", DeployHandler._target_entity, DeployHandler._url_policy)
@staticmethod
def policy_update(audit, message):
@@ -83,14 +103,14 @@ class DeployHandler(object):
DeployHandler._lazy_init(audit)
sub_aud = Audit(aud_parent=audit, targetEntity=DeployHandler._target_entity,
- targetServiceName=DeployHandler._url_path)
+ targetServiceName=DeployHandler._url_policy)
headers = {REQUEST_X_ECOMP_REQUESTID : sub_aud.request_id}
msg_str = json.dumps(message)
headers_str = json.dumps(headers)
log_action = "post to {0} at {1}".format(
- DeployHandler._target_entity, DeployHandler._url_path)
+ DeployHandler._target_entity, DeployHandler._url_policy)
log_data = " msg={0} headers={1}".format(msg_str, headers_str)
log_line = log_action + log_data
DeployHandler._logger.info(log_line)
@@ -107,7 +127,7 @@ class DeployHandler(object):
res = None
try:
res = DeployHandler._requests_session.post(
- DeployHandler._url_path, json=message, headers=headers,
+ DeployHandler._url_policy, json=message, headers=headers,
**DeployHandler._custom_kwargs
)
except requests.exceptions.RequestException as ex:
diff --git a/policyhandler/onap/audit.py b/policyhandler/onap/audit.py
index 4e8378c..109e3ff 100644
--- a/policyhandler/onap/audit.py
+++ b/policyhandler/onap/audit.py
@@ -25,16 +25,15 @@
audit = Audit(request_id=None, headers=None, msg=None)
"""
+import copy
+import json
import os
import sys
-import json
-import uuid
import time
-import copy
+import uuid
from datetime import datetime
-from threading import Lock
from enum import Enum
-from pip import utils as pip_utils
+from threading import Lock
from .CommonLogger import CommonLogger
from .health import Health
@@ -125,8 +124,6 @@ class Audit(object):
_logger_audit = None
_health = Health()
_py_ver = sys.version.replace("\n", "")
- _packages = sorted([pckg.project_name + "==" + pckg.version
- for pckg in pip_utils.get_installed_distributions()])
@staticmethod
def init(service_name, service_version, config_file_path):
@@ -154,8 +151,7 @@ class Audit(object):
"started" : str(Audit._started),
"now" : str(now),
"uptime" : str(now - Audit._started),
- "stats" : Audit._health.dump(),
- "packages" : Audit._packages
+ "stats" : Audit._health.dump()
}
def __init__(self, request_id=None, req_message=None, aud_parent=None, **kwargs):
diff --git a/pom.xml b/pom.xml
index d49962f..f53ca45 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>2.3.1-SNAPSHOT</version>
+ <version>2.4.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
diff --git a/setup.py b/setup.py
index 0481a1e..3886070 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="2.3.1",
+ version="2.4.0",
author='Alex Shatov',
packages=['policyhandler'],
zip_safe=False,
diff --git a/tests/test_policyhandler.py b/tests/test_policyhandler.py
index b52e718..307a355 100644
--- a/tests/test_policyhandler.py
+++ b/tests/test_policyhandler.py
@@ -28,6 +28,7 @@ import uuid
from datetime import datetime
import pytest
+
import cherrypy
from cherrypy.test.helper import CPWebCase
@@ -47,7 +48,7 @@ from policyhandler.policy_rest import PolicyRest
from policyhandler.policy_utils import PolicyUtils, Utils
from policyhandler.web_server import _PolicyWeb
-POLICY_HANDLER_VERSION = "2.2.0"
+POLICY_HANDLER_VERSION = "2.4.0"
class MonkeyHttpResponse(object):
"""Monkey http reposne"""
diff --git a/version.properties b/version.properties
index 2416ac8..50463f0 100644
--- a/version.properties
+++ b/version.properties
@@ -1,6 +1,6 @@
major=2
-minor=3
-patch=1
+minor=4
+patch=0
base_version=${major}.${minor}.${patch}
release_version=${base_version}
snapshot_version=${base_version}-SNAPSHOT