Skip to content

Commit 14411ac

Browse files
committed
2.4.0 dns based discovery of deployment-handler
- policy-handler uses dns based discovery of deployment-handler - driven by config - new data structure for deploy_handler section of config -- changed from string "deployment_handler" in 2.3.1 to structure in 2.4.0 deploy_handler : # name of deployment-handler service # used by policy-handler for logging target_entity : "deployment_handler" # url of the deployment-handler service # for policy-handler to direct the policy-updates to # - expecting dns to resolve the name # deployment_handler to ip address url : "http://deployment_handler:8188" - logic is backwards compatible with 2.3.1 format - removed import pip from audit -- import pip broken in pip 9.0.2 (2018-03-19) -- import pip conflicts with requests -- pip API is not officially supported -- see links for more pypa/pip#5079 pypa/pip#5081 Change-Id: Ifcaba6cfd714f3099ab7a25fe979a3696a6460fc Signed-off-by: Alex Shatov <alexs@att.com> Issue-ID: DCAEGEN2-404
1 parent 7e220c8 commit 14411ac

File tree

7 files changed

+44
-24
lines changed

7 files changed

+44
-24
lines changed

etc_upload/config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
},
2424
"target_entity" : "policy_engine"
2525
},
26-
"deploy_handler" : "deployment_handler"
26+
"deploy_handler" : {
27+
"target_entity" : "deployment_handler",
28+
"url" : "http://deployment_handler:8188"
29+
}
2730
}
2831
}

policyhandler/deploy_handler.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import requests
2525

2626
from .config import Config
27+
from .customize import CustomizerUser
2728
from .discovery import DiscoveryClient
2829
from .onap.audit import REQUEST_X_ECOMP_REQUESTID, Audit, AuditHttpCode
29-
from .customize import CustomizerUser
3030

3131
POOL_SIZE = 1
3232

@@ -38,7 +38,7 @@ class DeployHandler(object):
3838
_requests_session = None
3939
_config = None
4040
_url = None
41-
_url_path = None
41+
_url_policy = None
4242
_target_entity = None
4343
_custom_kwargs = None
4444
_server_instance_uuid = None
@@ -66,10 +66,30 @@ def _lazy_init(audit):
6666
requests.adapters.HTTPAdapter(pool_connections=POOL_SIZE, pool_maxsize=POOL_SIZE)
6767
)
6868

69-
DeployHandler._target_entity = Config.config.get("deploy_handler", "deploy_handler")
70-
DeployHandler._url = DiscoveryClient.get_service_url(audit, DeployHandler._target_entity)
71-
DeployHandler._url_path = (DeployHandler._url or "") + '/policy'
72-
DeployHandler._logger.info("DeployHandler url(%s)", DeployHandler._url)
69+
config_dh = Config.config.get("deploy_handler")
70+
if config_dh and isinstance(config_dh, dict):
71+
# dns based routing to deployment-handler
72+
# config for policy-handler >= 2.4.0
73+
# "deploy_handler" : {
74+
# "target_entity" : "deployment_handler",
75+
# "url" : "http://deployment_handler:8188"
76+
# }
77+
DeployHandler._target_entity = config_dh.get("target_entity", "deployment_handler")
78+
DeployHandler._url = config_dh.get("url")
79+
DeployHandler._logger.info("dns based routing to %s: url(%s)",
80+
DeployHandler._target_entity, DeployHandler._url)
81+
82+
if not DeployHandler._url:
83+
# discover routing to deployment-handler at consul-services
84+
if not isinstance(config_dh, dict):
85+
# config for policy-handler <= 2.3.1
86+
# "deploy_handler" : "deployment_handler"
87+
DeployHandler._target_entity = str(config_dh or "deployment_handler")
88+
DeployHandler._url = DiscoveryClient.get_service_url(audit, DeployHandler._target_entity)
89+
90+
DeployHandler._url_policy = str(DeployHandler._url or "") + '/policy'
91+
DeployHandler._logger.info(
92+
"got %s policy url(%s)", DeployHandler._target_entity, DeployHandler._url_policy)
7393

7494
@staticmethod
7595
def policy_update(audit, message):
@@ -83,14 +103,14 @@ def policy_update(audit, message):
83103

84104
DeployHandler._lazy_init(audit)
85105
sub_aud = Audit(aud_parent=audit, targetEntity=DeployHandler._target_entity,
86-
targetServiceName=DeployHandler._url_path)
106+
targetServiceName=DeployHandler._url_policy)
87107
headers = {REQUEST_X_ECOMP_REQUESTID : sub_aud.request_id}
88108

89109
msg_str = json.dumps(message)
90110
headers_str = json.dumps(headers)
91111

92112
log_action = "post to {0} at {1}".format(
93-
DeployHandler._target_entity, DeployHandler._url_path)
113+
DeployHandler._target_entity, DeployHandler._url_policy)
94114
log_data = " msg={0} headers={1}".format(msg_str, headers_str)
95115
log_line = log_action + log_data
96116
DeployHandler._logger.info(log_line)
@@ -107,7 +127,7 @@ def policy_update(audit, message):
107127
res = None
108128
try:
109129
res = DeployHandler._requests_session.post(
110-
DeployHandler._url_path, json=message, headers=headers,
130+
DeployHandler._url_policy, json=message, headers=headers,
111131
**DeployHandler._custom_kwargs
112132
)
113133
except requests.exceptions.RequestException as ex:

policyhandler/onap/audit.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@
2525
audit = Audit(request_id=None, headers=None, msg=None)
2626
"""
2727

28+
import copy
29+
import json
2830
import os
2931
import sys
30-
import json
31-
import uuid
3232
import time
33-
import copy
33+
import uuid
3434
from datetime import datetime
35-
from threading import Lock
3635
from enum import Enum
37-
from pip import utils as pip_utils
36+
from threading import Lock
3837

3938
from .CommonLogger import CommonLogger
4039
from .health import Health
@@ -125,8 +124,6 @@ class Audit(object):
125124
_logger_audit = None
126125
_health = Health()
127126
_py_ver = sys.version.replace("\n", "")
128-
_packages = sorted([pckg.project_name + "==" + pckg.version
129-
for pckg in pip_utils.get_installed_distributions()])
130127

131128
@staticmethod
132129
def init(service_name, service_version, config_file_path):
@@ -154,8 +151,7 @@ def health():
154151
"started" : str(Audit._started),
155152
"now" : str(now),
156153
"uptime" : str(now - Audit._started),
157-
"stats" : Audit._health.dump(),
158-
"packages" : Audit._packages
154+
"stats" : Audit._health.dump()
159155
}
160156

161157
def __init__(self, request_id=None, req_message=None, aud_parent=None, **kwargs):

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property.
3030
<groupId>org.onap.dcaegen2.platform</groupId>
3131
<artifactId>policy-handler</artifactId>
3232
<name>dcaegen2-platform-policy-handler</name>
33-
<version>2.3.1-SNAPSHOT</version>
33+
<version>2.4.0-SNAPSHOT</version>
3434
<url>http://maven.apache.org</url>
3535
<properties>
3636
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
setup(
2424
name='policyhandler',
2525
description='DCAE-Controller policy-handler to communicate with policy-engine',
26-
version="2.3.1",
26+
version="2.4.0",
2727
author='Alex Shatov',
2828
packages=['policyhandler'],
2929
zip_safe=False,

tests/test_policyhandler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from datetime import datetime
2929

3030
import pytest
31+
3132
import cherrypy
3233
from cherrypy.test.helper import CPWebCase
3334

@@ -47,7 +48,7 @@
4748
from policyhandler.policy_utils import PolicyUtils, Utils
4849
from policyhandler.web_server import _PolicyWeb
4950

50-
POLICY_HANDLER_VERSION = "2.2.0"
51+
POLICY_HANDLER_VERSION = "2.4.0"
5152

5253
class MonkeyHttpResponse(object):
5354
"""Monkey http reposne"""

version.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
major=2
2-
minor=3
3-
patch=1
2+
minor=4
3+
patch=0
44
base_version=${major}.${minor}.${patch}
55
release_version=${base_version}
66
snapshot_version=${base_version}-SNAPSHOT

0 commit comments

Comments
 (0)