# =============================================================================
# Copyright (c) 2017-2020 AT&T Intellectual Property. All rights reserved.
# Copyright (c) 2020 Pantheon.tech. All rights reserved.
+# Modifications Copyright (c) 2021 Nordix Foundation.
# =============================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
def create_topic(**kwargs):
'''
Creates a message router topic.
- Allows 'topic_name', 'topic_description', 'txenable', 'replication_case', 'global_mr_url',
+ Allows 'topic_name', 'topic_description', 'tnxEnabled', 'replication_case', 'global_mr_url',
and 'useExisting' as optional node properties. If 'topic_name' is not set,
generates a random one.
Sets 'fqtn' in the instance runtime_properties.
- Note that 'txenable' is a Message Router flag indicating whether transactions
+ Note that 'tnxEnabled' is a Message Router flag indicating whether transactions
are enabled on the topic.
Note that 'useExisting' is a flag indicating whether DBCL will use existing topic if
the topic already exists.
topic_name = random_string(12)
# Make sure there's a topic description
- if "topic_description" in ctx.node.properties:
- topic_description = ctx.node.properties["topic_description"]
- else:
- topic_description = "No description provided"
+ topic_description = ctx.node.properties.get("topic_description", "No description provided")
# ..and the truly optional setting
- if "txenable" in ctx.node.properties:
- txenable = ctx.node.properties["txenable"]
- else:
- txenable= False
+ tnx_enabled = ctx.node.properties.get("tnxEnabled", False)
- if "replication_case" in ctx.node.properties:
- replication_case = ctx.node.properties["replication_case"]
- else:
- replication_case = None
+ replication_case = ctx.node.properties.get("replication_case")
- if "global_mr_url" in ctx.node.properties:
- global_mr_url = ctx.node.properties["global_mr_url"]
- else:
- global_mr_url = None
+ global_mr_url = ctx.node.properties.get("global_mr_url")
- if "useExisting" in ctx.node.properties:
- useExisting = ctx.node.properties["useExisting"]
- else:
- useExisting = False
+ use_existing = ctx.node.properties.get("useExisting", False)
# Make the request to the controller
dmc = DMaaPControllerHandle(DMAAP_API_URL, DMAAP_USER, DMAAP_PASS, ctx.logger)
ctx.logger.info("Attempting to create topic name {0}".format(topic_name))
- t = dmc.create_topic(topic_name, topic_description, txenable, DMAAP_OWNER, replication_case, global_mr_url, useExisting)
+ t = dmc.create_topic(topic_name, topic_description, tnx_enabled, DMAAP_OWNER, replication_case, global_mr_url, use_existing)
t.raise_for_status()
# Capture important properties from the result