From 4c1c6891ed6cd4a9e5c2e0b3bacd0c2df89364a7 Mon Sep 17 00:00:00 2001 From: Jorge Hernandez Date: Tue, 19 Feb 2019 20:05:31 -0600 Subject: Support for lab contextual topic names. This work allows a drools application, with its drl template to refer to the topic name by its invariable canonical name, ie. POLICY-CL-MGT. Since the drl is a design time artifact, it is desired to know topics by its canonical non-changeable name. The actual per lab environment topic name may change on a per deployment basis, for example POLICY-CL-MGT-WINDRIVER or POLICY-CL-MGT-TLAB. The template can still use POLICY-CL-MGT without modification but the actual installation configuration would use the "effectiveTopic" property to point to the right topic on a per lab basis. This also helps with installation (long story) since the canonical topics will be known ahead of time. Change-Id: I8322bf7e427569c37a76eea5ce6d5b9547cb2ff3 Issue-ID: POLICY-1534 Signed-off-by: Jorge Hernandez --- .../event/comm/bus/internal/TopicBase.java | 45 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) (limited to 'policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBase.java') diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBase.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBase.java index 80664554..6f07df1b 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBase.java +++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/event/comm/bus/internal/TopicBase.java @@ -1,8 +1,8 @@ /* * ============LICENSE_START======================================================= - * policy-endpoints + * ONAP * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,12 @@ public abstract class TopicBase implements Topic { /** * Topic. */ - protected String topic; + protected final String topic; + + /** + * Topic Alias. + */ + protected final String effectiveTopic; /** * Event cache. @@ -78,6 +83,18 @@ public abstract class TopicBase implements Topic { * @throws IllegalArgumentException if invalid parameters are present */ public TopicBase(List servers, String topic) { + this(servers, topic, topic); + } + + /** + * Instantiates a new Topic Base. + * + * @param servers list of servers + * @param topic topic name + * + * @throws IllegalArgumentException if invalid parameters are present + */ + public TopicBase(List servers, String topic, String effectiveTopic) { if (servers == null || servers.isEmpty()) { throw new IllegalArgumentException("Server(s) must be provided"); @@ -87,8 +104,16 @@ public abstract class TopicBase implements Topic { throw new IllegalArgumentException("A Topic must be provided"); } + String effectiveTopicCopy; + if (effectiveTopic == null || effectiveTopic.isEmpty()) { + effectiveTopicCopy = topic; + } else { + effectiveTopicCopy = effectiveTopic; + } + this.servers = servers; this.topic = topic; + this.effectiveTopic = effectiveTopicCopy; } @Override @@ -203,6 +228,11 @@ public abstract class TopicBase implements Topic { return topic; } + @Override + public String getEffectiveTopic() { + return effectiveTopic; + } + @Override public boolean isAlive() { return this.alive; @@ -222,7 +252,12 @@ public abstract class TopicBase implements Topic { @Override public String toString() { - return "TopicBase [servers=" + servers + ", topic=" + topic + ", #recentEvents=" + recentEvents.size() - + ", locked=" + locked + ", #topicListeners=" + topicListeners.size() + "]"; + return "TopicBase [servers=" + servers + + ", topic=" + topic + + ", effectiveTopic=" + effectiveTopic + + ", #recentEvents=" + recentEvents.size() + + ", locked=" + locked + + ", #topicListeners=" + topicListeners.size() + + "]"; } } -- cgit 1.2.3-korg