diff options
author | Sastry Isukapalli <sastry@research.att.com> | 2018-03-26 15:57:20 -0400 |
---|---|---|
committer | Sastry Isukapalli <sastry@research.att.com> | 2018-03-26 15:58:10 -0400 |
commit | 477092abdb41449158538dfd49d8cd25c5c8e42a (patch) | |
tree | 02933668add258d945a3c2ed76aa2fada2fc9827 | |
parent | 4de3bb8c9f62f15d6aeb965f9d4c47edb7efd2e9 (diff) |
Remove code smell from DMaaP adapter
Issue-ID: OPTFRA-195
Change-Id: I67f2f5c6f9190bb91f34b371c0bc3ea1aa2367b0
Signed-off-by: Sastry Isukapalli <sastry@research.att.com>
-rwxr-xr-x | osdf/adapters/dcae/message_router.py | 39 | ||||
-rw-r--r-- | test/adapters/test_message_router.py | 9 |
2 files changed, 19 insertions, 29 deletions
diff --git a/osdf/adapters/dcae/message_router.py b/osdf/adapters/dcae/message_router.py index e495331..caf04a4 100755 --- a/osdf/adapters/dcae/message_router.py +++ b/osdf/adapters/dcae/message_router.py @@ -23,39 +23,30 @@ from osdf.operation.exceptions import MessageBusConfigurationException class MessageRouterClient(object): def __init__(self, - dmaap_url=None, - mr_host_base_urls=None, - topic=None, - consumer_group=None, consumer_id=None, + dmaap_url='', + consumer_group_id=':', timeout_ms=15000, fetch_limit=1000, - userid=None, passwd=None): + userid_passwd=':'): """ - :param dmaap_url: protocol, host and port; mostly for UEB - (e.g. https://dcae-msrt-ftl.homer.att.com:3905/) - :param mr_host_base_urls: for DMaaP, we get a topic URL (base_url + events/topic_name) - (e.g. https://dcae-msrt-ftl.homer.att.com:3905/events/com.att.dcae.dmaap.FTL.SNIRO-CM-SCHEDULER-RESPONSE) - :param consumer_group: DMaaP/UEB consumer group (unique for each subscriber; required for GET) - :param consumer_id: DMaaP/UEB consumer ID (unique for each thread/process for a subscriber; required for GET) + :param dmaap_url: protocol, host and port; can also be a list of URLs + (e.g. https://dmaap-host.onapdemo.onap.org:3905/events/org.onap.dmaap.MULTICLOUD.URGENT), + can also be a list of such URLs + :param consumer_group_id: DMaaP consumer group and consumer id (':' separated) + consumer_group is unique for each subscriber; required for GET + consumer_id: DMaaP consumer ID (unique for each thread/process for a subscriber; required for GET) :param timeout_ms: (optional, default 15 seconds or 15,000 ms) server-side timeout for GET request :param fetch_limit: (optional, default 1000 messages per request for GET), ignored for "POST" - :param userid: (optional, userid for HTTP basic authentication) - :param passwd: (optional, password for HTTP basic authentication) + :param userid_passwd: (optional, userid:password for HTTP basic authentication) """ mr_error = MessageBusConfigurationException - if dmaap_url is None: # definitely not DMaaP, so use UEB mode - self.is_dmaap = False - if not (mr_host_base_urls and list_like(mr_host_base_urls)): - raise mr_error("Not a DMaaP or UEB configuration") - if not topic: - raise mr_error("Invalid topic: '{}'",format(topic)) - self.topic_urls = ["{}/events/{}".format(base_url, topic) for base_url in mr_host_base_urls] - else: - self.is_dmaap = True - self.topic_urls = [dmaap_url] - + if not dmaap_url: # definitely not DMaaP, so use UEB mode + raise mr_error("Not a valid DMaaP configuration") + self.topic_urls = [dmaap_url] if not list_like(dmaap_url) else dmaap_url self.timeout_ms = timeout_ms self.fetch_limit = fetch_limit + userid, passwd = userid_passwd.split(':') self.auth = (userid, passwd) if userid and passwd else None + consumer_group, consumer_id = consumer_group_id.split(':') self.consumer_group = consumer_group self.consumer_id = consumer_id diff --git a/test/adapters/test_message_router.py b/test/adapters/test_message_router.py index 60580d4..a9c4636 100644 --- a/test/adapters/test_message_router.py +++ b/test/adapters/test_message_router.py @@ -28,14 +28,13 @@ class TestMessageRouter(unittest.TestCase): mr = MR.MessageRouterClient(dmaap_url="https://MYHOST:3905") def test_valid_MR_with_base_urls(self): - base_urls = ["https://MYHOST1:3905/","https://MYHOST2:3905/"] - mr = MR.MessageRouterClient(mr_host_base_urls=base_urls, topic="MY-TOPIC") + base_urls = ["https://MYHOST1:3905/events/MY-TOPIC","https://MYHOST2:3905/events/MY-TOPIC"] + mr = MR.MessageRouterClient(dmaap_url=base_urls) def test_invalid_valid_MR_with_base_urls(self): - """Topic missing""" - base_urls = ["https://MYHOST1:3905/","https://MYHOST2:3905/"] + """No dmaap_url""" try: - mr = MR.MessageRouterClient(mr_host_base_urls=base_urls) + mr = MR.MessageRouterClient() except MessageBusConfigurationException: return |