diff options
Diffstat (limited to 'policy-endpoints/src/main/java/org/onap')
10 files changed, 207 insertions, 304 deletions
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java index 84cc1dee..cc3705ee 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java @@ -49,8 +49,7 @@ public interface TopicEndpoint extends Startable, Lockable { * @return a generic Topic Source * @throws IllegalArgumentException when invalid arguments are provided */ - public List<? extends TopicSource> addTopicSources(Properties properties) - throws IllegalArgumentException; + public List<TopicSource> addTopicSources(Properties properties); /** * Add Topic Sinks to the communication infrastructure initialized per @@ -60,14 +59,13 @@ public interface TopicEndpoint extends Startable, Lockable { * @return a generic Topic Sink * @throws IllegalArgumentException when invalid arguments are provided */ - public List<? extends TopicSink> addTopicSinks(Properties properties) - throws IllegalArgumentException; + public List<TopicSink> addTopicSinks(Properties properties); /** * gets all Topic Sources * @return the Topic Source List */ - List<? extends TopicSource> getTopicSources(); + List<TopicSource> getTopicSources(); /** * get the Topic Sources for the given topic name @@ -78,8 +76,7 @@ public interface TopicEndpoint extends Startable, Lockable { * @throws IllegalStateException if the entity is in an invalid state * @throws IllegalArgumentException if invalid parameters are present */ - public List<? extends TopicSource> getTopicSources(List<String> topicNames) - throws IllegalStateException, IllegalArgumentException; + public List<TopicSource> getTopicSources(List<String> topicNames); /** * gets the Topic Source for the given topic name and @@ -96,8 +93,7 @@ public interface TopicEndpoint extends Startable, Lockable { */ public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) - throws IllegalStateException, IllegalArgumentException, - UnsupportedOperationException; + throws UnsupportedOperationException; /** * get the UEB Topic Source for the given topic name @@ -109,8 +105,7 @@ public interface TopicEndpoint extends Startable, Lockable { * example multiple TopicReaders for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public UebTopicSource getUebTopicSource(String topicName) - throws IllegalStateException, IllegalArgumentException; + public UebTopicSource getUebTopicSource(String topicName); /** * get the DMAAP Topic Source for the given topic name @@ -122,8 +117,7 @@ public interface TopicEndpoint extends Startable, Lockable { * example multiple TopicReaders for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public DmaapTopicSource getDmaapTopicSource(String topicName) - throws IllegalStateException, IllegalArgumentException; + public DmaapTopicSource getDmaapTopicSource(String topicName); /** * get the Topic Sinks for the given topic name @@ -133,8 +127,7 @@ public interface TopicEndpoint extends Startable, Lockable { * @throws IllegalStateException * @throws IllegalArgumentException */ - public List<? extends TopicSink> getTopicSinks(List<String> topicNames) - throws IllegalStateException, IllegalArgumentException; + public List<TopicSink> getTopicSinks(List<String> topicNames); /** * get the Topic Sinks for the given topic name and @@ -150,8 +143,7 @@ public interface TopicEndpoint extends Startable, Lockable { */ public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) - throws IllegalStateException, IllegalArgumentException, - UnsupportedOperationException; + throws UnsupportedOperationException; /** * get the Topic Sinks for the given topic name and @@ -165,8 +157,7 @@ public interface TopicEndpoint extends Startable, Lockable { * example multiple TopicWriters for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public List<? extends TopicSink> getTopicSinks(String topicName) - throws IllegalStateException, IllegalArgumentException; + public List<TopicSink> getTopicSinks(String topicName); /** * get the UEB Topic Source for the given topic name @@ -178,8 +169,7 @@ public interface TopicEndpoint extends Startable, Lockable { * example multiple TopicReaders for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public UebTopicSink getUebTopicSink(String topicName) - throws IllegalStateException, IllegalArgumentException; + public UebTopicSink getUebTopicSink(String topicName); /** * get the no-op Topic Sink for the given topic name @@ -191,8 +181,7 @@ public interface TopicEndpoint extends Startable, Lockable { * example multiple TopicReaders for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public NoopTopicSink getNoopTopicSink(String topicName) - throws IllegalStateException, IllegalArgumentException; + public NoopTopicSink getNoopTopicSink(String topicName); /** * get the DMAAP Topic Source for the given topic name @@ -204,8 +193,7 @@ public interface TopicEndpoint extends Startable, Lockable { * example multiple TopicReaders for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public DmaapTopicSink getDmaapTopicSink(String topicName) - throws IllegalStateException, IllegalArgumentException; + public DmaapTopicSink getDmaapTopicSink(String topicName); /** * gets only the UEB Topic Sources @@ -223,7 +211,7 @@ public interface TopicEndpoint extends Startable, Lockable { * gets all Topic Sinks * @return the Topic Sink List */ - public List<? extends TopicSink> getTopicSinks(); + public List<TopicSink> getTopicSinks(); /** * gets only the UEB Topic Sinks @@ -272,16 +260,13 @@ class ProxyTopicEndpointManager implements TopicEndpoint { */ protected volatile boolean alive = false; - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSource> addTopicSources(Properties properties) throws IllegalArgumentException { + public List<TopicSource> addTopicSources(Properties properties) { // 1. Create UEB Sources // 2. Create DMAAP Sources - List<TopicSource> sources = new ArrayList<TopicSource>(); + List<TopicSource> sources = new ArrayList<>(); sources.addAll(UebTopicSource.factory.build(properties)); sources.addAll(DmaapTopicSource.factory.build(properties)); @@ -295,15 +280,12 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sources; } - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSink> addTopicSinks(Properties properties) throws IllegalArgumentException { + public List<TopicSink> addTopicSinks(Properties properties) { // 1. Create UEB Sinks // 2. Create DMAAP Sinks - List<TopicSink> sinks = new ArrayList<TopicSink>(); + List<TopicSink> sinks = new ArrayList<>(); sinks.addAll(UebTopicSink.factory.build(properties)); sinks.addAll(DmaapTopicSink.factory.build(properties)); @@ -318,13 +300,10 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sinks; } - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSource> getTopicSources() { + public List<TopicSource> getTopicSources() { - List<TopicSource> sources = new ArrayList<TopicSource>(); + List<TopicSource> sources = new ArrayList<>(); sources.addAll(UebTopicSource.factory.inventory()); sources.addAll(DmaapTopicSource.factory.inventory()); @@ -332,13 +311,10 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sources; } - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSink> getTopicSinks() { + public List<TopicSink> getTopicSinks() { - List<TopicSink> sinks = new ArrayList<TopicSink>(); + List<TopicSink> sinks = new ArrayList<>(); sinks.addAll(UebTopicSink.factory.inventory()); sinks.addAll(DmaapTopicSink.factory.inventory()); @@ -347,56 +323,38 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sinks; } - /** - * {@inheritDoc} - */ @JsonIgnore @Override public List<UebTopicSource> getUebTopicSources() { return UebTopicSource.factory.inventory(); } - /** - * {@inheritDoc} - */ @JsonIgnore @Override public List<DmaapTopicSource> getDmaapTopicSources() { return DmaapTopicSource.factory.inventory(); } - /** - * {@inheritDoc} - */ @JsonIgnore @Override public List<UebTopicSink> getUebTopicSinks() { return UebTopicSink.factory.inventory(); } - /** - * {@inheritDoc} - */ @JsonIgnore @Override public List<DmaapTopicSink> getDmaapTopicSinks() { return DmaapTopicSink.factory.inventory(); } - /** - * {@inheritDoc} - */ @JsonIgnore @Override public List<NoopTopicSink> getNoopTopicSinks() { return NoopTopicSink.factory.inventory(); } - /** - * {@inheritDoc} - */ @Override - public boolean start() throws IllegalStateException { + public boolean start() { synchronized (this) { if (this.locked) { @@ -426,11 +384,8 @@ class ProxyTopicEndpointManager implements TopicEndpoint { } - /** - * {@inheritDoc} - */ @Override - public boolean stop() throws IllegalStateException { + public boolean stop() { /* * stop regardless if it is locked, in other @@ -462,7 +417,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { */ @JsonIgnore protected List<Startable> getEndpoints() { - List<Startable> endpoints = new ArrayList<Startable>(); + List<Startable> endpoints = new ArrayList<>(); endpoints.addAll(this.getTopicSources()); endpoints.addAll(this.getTopicSinks()); @@ -470,12 +425,8 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return endpoints; } - - /** - * {@inheritDoc} - */ @Override - public void shutdown() throws IllegalStateException { + public void shutdown() { UebTopicSource.factory.destroy(); UebTopicSink.factory.destroy(); @@ -483,17 +434,11 @@ class ProxyTopicEndpointManager implements TopicEndpoint { DmaapTopicSink.factory.destroy(); } - /** - * {@inheritDoc} - */ @Override public boolean isAlive() { return this.alive; } - /** - * {@inheritDoc} - */ @Override public boolean lock() { @@ -515,9 +460,6 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return true; } - /** - * {@inheritDoc} - */ @Override public boolean unlock() { synchronized (this) { @@ -538,26 +480,19 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return true; } - /** - * {@inheritDoc} - */ @Override public boolean isLocked() { return this.locked; } - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSource> getTopicSources(List<String> topicNames) - throws IllegalStateException, IllegalArgumentException { + public List<TopicSource> getTopicSources(List<String> topicNames) { if (topicNames == null) { throw new IllegalArgumentException("must provide a list of topics"); } - List<TopicSource> sources = new ArrayList<TopicSource>(); + List<TopicSource> sources = new ArrayList<>(); for (String topic: topicNames) { try { TopicSource uebSource = this.getUebTopicSource(topic); @@ -578,18 +513,14 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sources; } - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSink> getTopicSinks(List<String> topicNames) - throws IllegalStateException, IllegalArgumentException { + public List<TopicSink> getTopicSinks(List<String> topicNames) { if (topicNames == null) { throw new IllegalArgumentException("must provide a list of topics"); } - List<TopicSink> sinks = new ArrayList<TopicSink>(); + List<TopicSink> sinks = new ArrayList<>(); for (String topic: topicNames) { try { TopicSink uebSink = this.getUebTopicSink(topic); @@ -610,12 +541,9 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sinks; } - /** - * {@inheritDoc} - */ @Override public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) - throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { + throws UnsupportedOperationException { if (commType == null) { throw new IllegalArgumentException @@ -638,12 +566,9 @@ class ProxyTopicEndpointManager implements TopicEndpoint { } } - /** - * {@inheritDoc} - */ @Override public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) - throws IllegalStateException, IllegalArgumentException, UnsupportedOperationException { + throws UnsupportedOperationException { if (commType == null) { throw new IllegalArgumentException ("Invalid parameter: a communication infrastructure required to fetch " + topicName); @@ -665,19 +590,15 @@ class ProxyTopicEndpointManager implements TopicEndpoint { } } - /** - * {@inheritDoc} - */ @Override - public List<? extends TopicSink> getTopicSinks(String topicName) - throws IllegalStateException, IllegalArgumentException { + public List<TopicSink> getTopicSinks(String topicName) { if (topicName == null) { throw new IllegalArgumentException ("Invalid parameter: a communication infrastructure required to fetch " + topicName); } - List<TopicSink> sinks = new ArrayList<TopicSink>(); + List<TopicSink> sinks = new ArrayList<>(); try { sinks.add(this.getUebTopicSink(topicName)); @@ -694,35 +615,28 @@ class ProxyTopicEndpointManager implements TopicEndpoint { return sinks; } - /** - * {@inheritDoc} - */ @Override - public UebTopicSource getUebTopicSource(String topicName) throws IllegalStateException, IllegalArgumentException { + public UebTopicSource getUebTopicSource(String topicName) { return UebTopicSource.factory.get(topicName); } - /** - * {@inheritDoc} - */ @Override - public UebTopicSink getUebTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException { + public UebTopicSink getUebTopicSink(String topicName) { return UebTopicSink.factory.get(topicName); } @Override - public DmaapTopicSource getDmaapTopicSource(String topicName) - throws IllegalStateException, IllegalArgumentException { + public DmaapTopicSource getDmaapTopicSource(String topicName) { return DmaapTopicSource.factory.get(topicName); } @Override - public DmaapTopicSink getDmaapTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException { + public DmaapTopicSink getDmaapTopicSink(String topicName) { return DmaapTopicSink.factory.get(topicName); } @Override - public NoopTopicSink getNoopTopicSink(String topicName) throws IllegalStateException, IllegalArgumentException { + public NoopTopicSink getNoopTopicSink(String topicName) { return NoopTopicSink.factory.get(topicName); } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicListener.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicListener.java index a7dedd27..4c8552b6 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicListener.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicListener.java @@ -23,6 +23,7 @@ package org.onap.policy.drools.event.comm; /** * Listener for event messages entering the Policy Engine */ +@FunctionalInterface public interface TopicListener { /** diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java index 759e97f7..43854c2a 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSinkFactory.java @@ -107,8 +107,7 @@ public interface DmaapTopicSinkFactory { String partitionKey, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException; + boolean allowSelfSignedCerts); /** * Creates an DMAAP Topic Sink based on properties files @@ -118,8 +117,7 @@ public interface DmaapTopicSinkFactory { * @return an DMAAP Topic Sink * @throws IllegalArgumentException if invalid parameters are present */ - public List<DmaapTopicSink> build(Properties properties) - throws IllegalArgumentException; + public List<DmaapTopicSink> build(Properties properties); /** * Instantiates a new DMAAP Topic Sink @@ -130,8 +128,7 @@ public interface DmaapTopicSinkFactory { * @return an DMAAP Topic Sink * @throws IllegalArgumentException if invalid parameters are present */ - public DmaapTopicSink build(List<String> servers, String topic) - throws IllegalArgumentException; + public DmaapTopicSink build(List<String> servers, String topic); /** * Destroys an DMAAP Topic Sink based on a topic @@ -150,8 +147,7 @@ public interface DmaapTopicSinkFactory { * @throws IllegalStateException if the DMAAP Topic Reader is * an incorrect state */ - public DmaapTopicSink get(String topic) - throws IllegalArgumentException, IllegalStateException; + public DmaapTopicSink get(String topic); /** * Provides a snapshot of the DMAAP Topic Sinks @@ -179,12 +175,8 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { /** * DMAAP Topic Name Index */ - protected HashMap<String, DmaapTopicSink> dmaapTopicWriters = - new HashMap<String, DmaapTopicSink>(); + protected HashMap<String, DmaapTopicSink> dmaapTopicWriters = new HashMap<>(); - /** - * {@inheritDoc} - */ @Override public DmaapTopicSink build(List<String> servers, String topic, @@ -201,8 +193,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { Map<String,String> additionalProps, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException { + boolean allowSelfSignedCerts) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); @@ -227,9 +218,6 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override public DmaapTopicSink build(List<String> servers, String topic, @@ -239,8 +227,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { String password, String partitionKey, boolean managed, - boolean useHttps, boolean allowSelfSignedCerts) - throws IllegalArgumentException { + boolean useHttps, boolean allowSelfSignedCerts) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); @@ -263,30 +250,22 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { } } - - /** - * {@inheritDoc} - */ @Override - public DmaapTopicSink build(List<String> servers, String topic) throws IllegalArgumentException { + public DmaapTopicSink build(List<String> servers, String topic) { return this.build(servers, topic, null, null, null, null, null, true, false, false); } - - /** - * {@inheritDoc} - */ @Override - public List<DmaapTopicSink> build(Properties properties) throws IllegalArgumentException { + public List<DmaapTopicSink> build(Properties properties) { String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS); if (writeTopics == null || writeTopics.isEmpty()) { logger.info("{}: no topic for DMaaP Sink", this); - return new ArrayList<DmaapTopicSink>(); + return new ArrayList<>(); } - List<String> writeTopicList = new ArrayList<String>(Arrays.asList(writeTopics.split("\\s*,\\s*"))); - List<DmaapTopicSink> newDmaapTopicSinks = new ArrayList<DmaapTopicSink>(); + List<String> writeTopicList = new ArrayList<>(Arrays.asList(writeTopics.split("\\s*,\\s*"))); + List<DmaapTopicSink> newDmaapTopicSinks = new ArrayList<>(); synchronized(this) { for (String topic: writeTopicList) { if (this.dmaapTopicWriters.containsKey(topic)) { @@ -298,7 +277,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); List<String> serverList; - if (servers != null && !servers.isEmpty()) serverList = new ArrayList<String>(Arrays.asList(servers.split("\\s*,\\s*"))); + if (servers != null && !servers.isEmpty()) serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*"))); else serverList = new ArrayList<>(); String apiKey = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + @@ -421,12 +400,8 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override - public void destroy(String topic) - throws IllegalArgumentException { + public void destroy(String topic) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); @@ -444,9 +419,6 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { dmaapTopicWriter.shutdown(); } - /** - * {@inheritDoc} - */ @Override public void destroy() { List<DmaapTopicSink> writers = this.inventory(); @@ -459,12 +431,8 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override - public DmaapTopicSink get(String topic) - throws IllegalArgumentException, IllegalStateException { + public DmaapTopicSink get(String topic) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); @@ -479,13 +447,10 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override public synchronized List<DmaapTopicSink> inventory() { List<DmaapTopicSink> writers = - new ArrayList<DmaapTopicSink>(this.dmaapTopicWriters.values()); + new ArrayList<>(this.dmaapTopicWriters.values()); return writers; } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSink.java index 4880525f..afc11229 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSink.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSink.java @@ -52,12 +52,12 @@ public class NoopTopicSink extends TopicBase implements TopicSink { * @param topic topic * @throws IllegalArgumentException if an invalid argument has been passed in */ - public NoopTopicSink(List<String> servers, String topic) throws IllegalArgumentException { + public NoopTopicSink(List<String> servers, String topic) { super(servers, topic); } @Override - public boolean send(String message) throws IllegalArgumentException, IllegalStateException { + public boolean send(String message) { if (message == null || message.isEmpty()) throw new IllegalArgumentException("Message to send is empty"); @@ -88,7 +88,7 @@ public class NoopTopicSink extends TopicBase implements TopicSink { } @Override - public boolean start() throws IllegalStateException { + public boolean start() { logger.info("{}: starting", this); synchronized(this) { @@ -106,7 +106,7 @@ public class NoopTopicSink extends TopicBase implements TopicSink { } @Override - public boolean stop() throws IllegalStateException { + public boolean stop() { synchronized(this) { this.alive = false; } @@ -114,7 +114,7 @@ public class NoopTopicSink extends TopicBase implements TopicSink { } @Override - public void shutdown() throws IllegalStateException { + public void shutdown() { this.stop(); } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java index 7a428dcd..946e48c0 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/NoopTopicSinkFactory.java @@ -42,8 +42,7 @@ public interface NoopTopicSinkFactory { * @return a noop topic sink * @throws IllegalArgumentException if invalid parameters are present */ - public List<NoopTopicSink> build(Properties properties) - throws IllegalArgumentException; + public List<NoopTopicSink> build(Properties properties); /** * builds a noop sink @@ -54,8 +53,7 @@ public interface NoopTopicSinkFactory { * @return a noop topic sink * @throws IllegalArgumentException if invalid parameters are present */ - public NoopTopicSink build(List<String> servers, String topic, boolean managed) - throws IllegalArgumentException; + public NoopTopicSink build(List<String> servers, String topic, boolean managed); /** * Destroys a sink based on the topic @@ -73,8 +71,7 @@ public interface NoopTopicSinkFactory { * @throws IllegalArgumentException if an invalid topic is provided * @throws IllegalStateException if the sink is in an incorrect state */ - public NoopTopicSink get(String topic) - throws IllegalArgumentException, IllegalStateException; + public NoopTopicSink get(String topic); /** * Provides a snapshot of the UEB Topic Writers @@ -102,18 +99,18 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { /** * noop topic sinks map */ - protected HashMap<String, NoopTopicSink> noopTopicSinks = new HashMap<String, NoopTopicSink>(); + protected HashMap<String, NoopTopicSink> noopTopicSinks = new HashMap<>(); @Override - public List<NoopTopicSink> build(Properties properties) throws IllegalArgumentException { + public List<NoopTopicSink> build(Properties properties) { String sinkTopics = properties.getProperty(PolicyProperties.PROPERTY_NOOP_SINK_TOPICS); if (sinkTopics == null || sinkTopics.isEmpty()) { logger.info("{}: no topic for noop sink", this); - return new ArrayList<NoopTopicSink>(); + return new ArrayList<>(); } - List<String> sinkTopicList = new ArrayList<String>(Arrays.asList(sinkTopics.split("\\s*,\\s*"))); + List<String> sinkTopicList = new ArrayList<>(Arrays.asList(sinkTopics.split("\\s*,\\s*"))); List<NoopTopicSink> newSinks = new ArrayList<NoopTopicSink>(); synchronized(this) { for (String topic: sinkTopicList) { @@ -129,7 +126,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { if (servers == null || servers.isEmpty()) servers = "noop"; - List<String> serverList = new ArrayList<String>(Arrays.asList(servers.split("\\s*,\\s*"))); + List<String> serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*"))); String managedString = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "." + topic + PolicyProperties.PROPERTY_MANAGED_SUFFIX); @@ -146,7 +143,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { } @Override - public NoopTopicSink build(List<String> servers, String topic, boolean managed) throws IllegalArgumentException { + public NoopTopicSink build(List<String> servers, String topic, boolean managed) { if (servers == null) { servers = new ArrayList<>(); } @@ -205,7 +202,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { } @Override - public NoopTopicSink get(String topic) throws IllegalArgumentException, IllegalStateException { + public NoopTopicSink get(String topic) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java index 50718097..10f56c4f 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSinkFactory.java @@ -56,8 +56,7 @@ public interface UebTopicSinkFactory { String partitionKey, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException; + boolean allowSelfSignedCerts); /** * Creates an UEB Topic Writer based on properties files @@ -67,8 +66,7 @@ public interface UebTopicSinkFactory { * @return an UEB Topic Writer * @throws IllegalArgumentException if invalid parameters are present */ - public List<UebTopicSink> build(Properties properties) - throws IllegalArgumentException; + public List<UebTopicSink> build(Properties properties); /** * Instantiates a new UEB Topic Writer @@ -79,8 +77,7 @@ public interface UebTopicSinkFactory { * @return an UEB Topic Writer * @throws IllegalArgumentException if invalid parameters are present */ - public UebTopicSink build(List<String> servers, String topic) - throws IllegalArgumentException; + public UebTopicSink build(List<String> servers, String topic); /** * Destroys an UEB Topic Writer based on a topic @@ -99,8 +96,7 @@ public interface UebTopicSinkFactory { * @throws IllegalStateException if the UEB Topic Reader is * an incorrect state */ - public UebTopicSink get(String topic) - throws IllegalArgumentException, IllegalStateException; + public UebTopicSink get(String topic); /** * Provides a snapshot of the UEB Topic Writers @@ -131,9 +127,6 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { protected HashMap<String, UebTopicSink> uebTopicSinks = new HashMap<String, UebTopicSink>(); - /** - * {@inheritDoc} - */ @Override public UebTopicSink build(List<String> servers, String topic, @@ -142,8 +135,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { String partitionKey, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException { + boolean allowSelfSignedCerts) { if (servers == null || servers.isEmpty()) { throw new IllegalArgumentException("UEB Server(s) must be provided"); @@ -170,29 +162,23 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { } - /** - * {@inheritDoc} - */ @Override - public UebTopicSink build(List<String> servers, String topic) throws IllegalArgumentException { + public UebTopicSink build(List<String> servers, String topic) { return this.build(servers, topic, null, null, null, true, false, false); } - /** - * {@inheritDoc} - */ @Override - public List<UebTopicSink> build(Properties properties) throws IllegalArgumentException { + public List<UebTopicSink> build(Properties properties) { String writeTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS); if (writeTopics == null || writeTopics.isEmpty()) { logger.info("{}: no topic for UEB Sink", this); - return new ArrayList<UebTopicSink>(); + return new ArrayList<>(); } - List<String> writeTopicList = new ArrayList<String>(Arrays.asList(writeTopics.split("\\s*,\\s*"))); - List<UebTopicSink> newUebTopicSinks = new ArrayList<UebTopicSink>(); + List<String> writeTopicList = new ArrayList<>(Arrays.asList(writeTopics.split("\\s*,\\s*"))); + List<UebTopicSink> newUebTopicSinks = new ArrayList<>(); synchronized(this) { for (String topic: writeTopicList) { if (this.uebTopicSinks.containsKey(topic)) { @@ -208,7 +194,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { continue; } - List<String> serverList = new ArrayList<String>(Arrays.asList(servers.split("\\s*,\\s*"))); + List<String> serverList = new ArrayList<>(Arrays.asList(servers.split("\\s*,\\s*"))); String apiKey = properties.getProperty(PolicyProperties.PROPERTY_UEB_SINK_TOPICS + "." + topic + @@ -255,12 +241,8 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override - public void destroy(String topic) - throws IllegalArgumentException { + public void destroy(String topic) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); @@ -278,9 +260,6 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { uebTopicWriter.shutdown(); } - /** - * {@inheritDoc} - */ @Override public void destroy() { List<UebTopicSink> writers = this.inventory(); @@ -293,12 +272,8 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override - public UebTopicSink get(String topic) - throws IllegalArgumentException, IllegalStateException { + public UebTopicSink get(String topic) { if (topic == null || topic.isEmpty()) { throw new IllegalArgumentException("A topic must be provided"); @@ -313,13 +288,10 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { } } - /** - * {@inheritDoc} - */ @Override public synchronized List<UebTopicSink> inventory() { List<UebTopicSink> writers = - new ArrayList<UebTopicSink>(this.uebTopicSinks.values()); + new ArrayList<>(this.uebTopicSinks.values()); return writers; } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java index 6122c5d0..edb03bba 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java @@ -134,16 +134,12 @@ public interface BusConsumer { } } - /** - * {@inheritDoc} - */ + @Override public Iterable<String> fetch() throws IOException { return this.consumer.fetch(); } - /** - * {@inheritDoc} - */ + @Override public void close() { this.consumer.close(); } @@ -159,9 +155,19 @@ public interface BusConsumer { */ public abstract class DmaapConsumerWrapper implements BusConsumer { + /** + * logger + */ private static Logger logger = LoggerFactory.getLogger(DmaapConsumerWrapper.class); + /** + * fetch timeout + */ protected int fetchTimeout; + + /** + * close condition + */ protected Object closeCondition = new Object(); /** @@ -206,9 +212,6 @@ public interface BusConsumer { this.consumer.setPassword(password); } - /** - * {@inheritDoc} - */ @Override public Iterable<String> fetch() throws InterruptedException, IOException { MRConsumerResponse response = this.consumer.fetchWithReturnConsumerResponse(); @@ -218,7 +221,7 @@ public interface BusConsumer { synchronized (closeCondition) { closeCondition.wait(fetchTimeout); } - return new ArrayList<String>(); + return new ArrayList<>(); } else { logger.debug("DMaaP consumer received {} : {}" + response.getResponseCode(), @@ -234,19 +237,17 @@ public interface BusConsumer { synchronized (closeCondition) { closeCondition.wait(fetchTimeout); } + /* fall through */ } } if (response.getActualMessages() == null) - return new ArrayList<String>(); + return new ArrayList<>(); else return response.getActualMessages(); } - /** - * {@inheritDoc} - */ @Override public void close() { synchronized (closeCondition) { @@ -308,7 +309,7 @@ public interface BusConsumer { // super constructor sets servers = {""} if empty to avoid errors when using DME2 if ((servers.size() == 1 && servers.get(0).equals("")) || - (servers == null) || (servers.size() == 0)) { + (servers == null) || (servers.isEmpty())) { throw new IllegalArgumentException("Must provide at least one host for HTTP AAF"); } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java index da515af9..a40bad91 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/HttpServletServer.java @@ -46,22 +46,22 @@ public interface HttpServletServer extends Startable { * * @param servletPath servlet path * @param restClass JAX-RS API Class + * * @throws IllegalArgumentException unable to process because of invalid input * @throws IllegalStateException unable to process because of invalid state */ - public void addServletClass(String servletPath, String restClass) - throws IllegalArgumentException, IllegalStateException; + public void addServletClass(String servletPath, String restClass); /** * adds a package containing JAX-RS classes to serve REST requests * * @param servletPath servlet path * @param restPackage JAX-RS package to scan + * * @throws IllegalArgumentException unable to process because of invalid input * @throws IllegalStateException unable to process because of invalid state */ - public void addServletPackage(String servletPath, String restPackage) - throws IllegalArgumentException, IllegalStateException; + public void addServletPackage(String servletPath, String restPackage); /** * blocking start of the http server @@ -70,8 +70,9 @@ public interface HttpServletServer extends Startable { * @return true if start was successful * * @throws IllegalArgumentException if arguments are invalid + * @throws InterruptedException if the blocking operation is interrupted */ - public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException; + public boolean waitedStart(long maxWaitTime) throws InterruptedException; /** diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java index 0c724fc8..8d66807d 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyJerseyServer.java @@ -24,6 +24,7 @@ import java.net.UnknownHostException; import java.util.HashMap; import org.eclipse.jetty.servlet.ServletHolder; +import org.onap.policy.drools.utils.NetworkUtil; import org.slf4j.LoggerFactory; import org.slf4j.Logger; @@ -33,21 +34,41 @@ import io.swagger.jersey.config.JerseyJaxrsConfig; * REST Jetty Server that uses Jersey Servlets to support JAX-RS Web Services */ public class JettyJerseyServer extends JettyServletServer { + + /** + * Swagger API Base Path + */ + protected static final String SWAGGER_API_BASEPATH = "swagger.api.basepath"; /** - * Jersey Packages Init Param Name + * Swagger Context ID */ - protected static final String JERSEY_INIT_PACKAGES_PARAM_NAME = "jersey.config.server.provider.packages"; + protected static final String SWAGGER_CONTEXT_ID = "swagger.context.id"; /** - * Jersey Packages Init Param Value + * Swagger Scanner ID */ - protected static final String JERSEY_INIT_PACKAGES_PARAM_VALUE = "com.fasterxml.jackson.jaxrs.json"; + protected static final String SWAGGER_SCANNER_ID = "swagger.scanner.id"; + + /** + * Swagger Pretty Print + */ + protected static final String SWAGGER_PRETTY_PRINT = "swagger.pretty.print"; /** * Swagger Packages */ protected static final String SWAGGER_INIT_PACKAGES_PARAM_VALUE = "io.swagger.jaxrs.listing"; + + /** + * Jersey Packages Init Param Name + */ + protected static final String JERSEY_INIT_PACKAGES_PARAM_NAME = "jersey.config.server.provider.packages"; + + /** + * Jersey Packages Init Param Value + */ + protected static final String JERSEY_INIT_PACKAGES_PARAM_VALUE = "com.fasterxml.jackson.jaxrs.json"; /** * Jersey Classes Init Param Name @@ -90,8 +111,7 @@ public class JettyJerseyServer extends JettyServletServer { * * @throws IllegalArgumentException in invalid arguments are provided */ - public JettyJerseyServer(String name, String host, int port, String contextPath, boolean swagger) - throws IllegalArgumentException { + public JettyJerseyServer(String name, String host, int port, String contextPath, boolean swagger) { super(name, host, port, contextPath); if (swagger) { @@ -108,20 +128,20 @@ public class JettyJerseyServer extends JettyServletServer { ServletHolder swaggerServlet = context.addServlet(JerseyJaxrsConfig.class, "/"); String hostname = this.connector.getHost(); - if (hostname == null || hostname.isEmpty() || hostname.equals("0.0.0.0")) { + if (hostname == null || hostname.isEmpty() || hostname.equals(NetworkUtil.IPv4_WILDCARD_ADDRESS)) { try { hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { - logger.warn("{}: can't resolve connector's hostname: ", this); + logger.warn("{}: can't resolve connector's hostname: {}", this, hostname, e); hostname = "localhost"; } } - swaggerServlet.setInitParameter("swagger.api.basepath", + swaggerServlet.setInitParameter(SWAGGER_API_BASEPATH, "http://" + hostname + ":" + this.connector.getPort() + "/"); - swaggerServlet.setInitParameter("swagger.context.id", swaggerId); - swaggerServlet.setInitParameter("swagger.scanner.id", swaggerId); - swaggerServlet.setInitParameter("swagger.pretty.print", "true"); + swaggerServlet.setInitParameter(SWAGGER_CONTEXT_ID, swaggerId); + swaggerServlet.setInitParameter(SWAGGER_SCANNER_ID, swaggerId); + swaggerServlet.setInitParameter(SWAGGER_PRETTY_PRINT, "true"); swaggerServlet.setInitOrder(2); if (logger.isDebugEnabled()) @@ -136,8 +156,7 @@ public class JettyJerseyServer extends JettyServletServer { * * @throws IllegalArgumentException if invalid arguments are provided */ - protected synchronized ServletHolder getServlet(String servletPath) - throws IllegalArgumentException { + protected synchronized ServletHolder getServlet(String servletPath) { ServletHolder jerseyServlet = servlets.get(servletPath); if (jerseyServlet == null) { @@ -151,8 +170,7 @@ public class JettyJerseyServer extends JettyServletServer { } @Override - public synchronized void addServletPackage(String servletPath, String restPackage) - throws IllegalArgumentException, IllegalStateException { + public synchronized void addServletPackage(String servletPath, String restPackage) { if (restPackage == null || restPackage.isEmpty()) throw new IllegalArgumentException("No discoverable REST package provided"); @@ -175,8 +193,8 @@ public class JettyJerseyServer extends JettyServletServer { SWAGGER_INIT_PACKAGES_PARAM_VALUE + "," + restPackage; - jerseyServlet.setInitParameter("swagger.context.id", swaggerId); - jerseyServlet.setInitParameter("swagger.scanner.id", swaggerId); + jerseyServlet.setInitParameter(SWAGGER_CONTEXT_ID, swaggerId); + jerseyServlet.setInitParameter(SWAGGER_SCANNER_ID, swaggerId); } else { initPackages = JERSEY_INIT_PACKAGES_PARAM_VALUE + "," + restPackage; @@ -192,8 +210,7 @@ public class JettyJerseyServer extends JettyServletServer { } @Override - public synchronized void addServletClass(String servletPath, String restClass) - throws IllegalArgumentException, IllegalStateException { + public synchronized void addServletClass(String servletPath, String restClass) { if (restClass == null || restClass.isEmpty()) throw new IllegalArgumentException("No discoverable REST class provided"); @@ -216,8 +233,8 @@ public class JettyJerseyServer extends JettyServletServer { SWAGGER_INIT_CLASSNAMES_PARAM_VALUE + "," + restClass; - jerseyServlet.setInitParameter("swagger.context.id", swaggerId); - jerseyServlet.setInitParameter("swagger.scanner.id", swaggerId); + jerseyServlet.setInitParameter(SWAGGER_CONTEXT_ID, swaggerId); + jerseyServlet.setInitParameter(SWAGGER_SCANNER_ID, swaggerId); } else { initClasses = JERSEY_JACKSON_INIT_CLASSNAMES_PARAM_VALUE + "," + restClass; } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java index d803fe0e..66261349 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/server/internal/JettyServletServer.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * policy-endpoints + * ONAP * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -39,28 +39,77 @@ import com.fasterxml.jackson.annotation.JsonIgnore; */ public abstract class JettyServletServer implements HttpServletServer, Runnable { + /** + * Logger + */ private static Logger logger = LoggerFactory.getLogger(JettyServletServer.class); + /** + * server name + */ protected final String name; + /** + * server host address + */ protected final String host; + + /** + * server port to bind + */ protected final int port; + /** + * server auth user name + */ protected String user; + + /** + * server auth password name + */ protected String password; + /** + * server base context path + */ protected final String contextPath; + /** + * embedded jetty server + */ protected final Server jettyServer; + + /** + * servlet context + */ protected final ServletContextHandler context; + + /** + * jetty connector + */ protected final ServerConnector connector; + /** + * jetty thread + */ protected volatile Thread jettyThread; + /** + * start condition + */ protected Object startCondition = new Object(); - public JettyServletServer(String name, String host, int port, String contextPath) - throws IllegalArgumentException { + /** + * constructor + * + * @param name server name + * @param host server host + * @param port server port + * @param contextPath context path + * + * @throws IllegalArgumentException if invalid parameters are passed in + */ + public JettyServletServer(String name, String host, int port, String contextPath) { if (name == null || name.isEmpty()) name = "http-" + port; @@ -96,9 +145,6 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable this.jettyServer.setHandler(context); } - /** - * {@inheritDoc} - */ @Override public void setBasicAuthentication(String user, String password, String servletPath) { if (user == null || user.isEmpty() || password == null || password.isEmpty()) @@ -135,7 +181,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable } /** - * Jetty Server Execution + * jetty server execution */ @Override public void run() { @@ -158,7 +204,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable } @Override - public boolean waitedStart(long maxWaitTime) throws IllegalArgumentException { + public boolean waitedStart(long maxWaitTime) throws InterruptedException { logger.info("{}: WAITED-START", this); if (maxWaitTime < 0) @@ -191,7 +237,7 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable } catch (InterruptedException e) { logger.warn("{}: waited-start has been interrupted", this); - return false; + throw e; } } @@ -199,11 +245,8 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable } } - /** - * {@inheritDoc} - */ @Override - public boolean start() throws IllegalStateException { + public boolean start() { logger.info("{}: STARTING", this); synchronized(this) { @@ -219,11 +262,8 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable return true; } - /** - * {@inheritDoc} - */ @Override - public boolean stop() throws IllegalStateException { + public boolean stop() { logger.info("{}: STOPPING", this); synchronized(this) { @@ -254,11 +294,8 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable return true; } - /** - * {@inheritDoc} - */ @Override - public void shutdown() throws IllegalStateException { + public void shutdown() { logger.info("{}: SHUTTING DOWN", this); this.stop(); @@ -270,16 +307,17 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable if (jettyThreadCopy.isAlive()) { try { - jettyThreadCopy.join(1000L); + jettyThreadCopy.join(2000L); } catch (InterruptedException e) { logger.warn("{}: error while shutting down management server", this); + Thread.currentThread().interrupt(); } if (!jettyThreadCopy.isInterrupted()) { try { jettyThreadCopy.interrupt(); } catch(Exception e) { // do nothing - logger.warn("{}: exception while shutting down (OK)", this); + logger.warn("{}: exception while shutting down (OK)", this, e); } } } @@ -287,9 +325,6 @@ public abstract class JettyServletServer implements HttpServletServer, Runnable this.jettyServer.destroy(); } - /** - * {@inheritDoc} - */ @Override public boolean isAlive() { if (this.jettyThread != null) |