diff options
21 files changed, 450 insertions, 700 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) diff --git a/policy-endpoints/src/test/java/org/onap/policy/drools/http/server/test/HttpClientTest.java b/policy-endpoints/src/test/java/org/onap/policy/drools/http/server/test/HttpClientTest.java index 0717a091..f7ef7bcf 100644 --- a/policy-endpoints/src/test/java/org/onap/policy/drools/http/server/test/HttpClientTest.java +++ b/policy-endpoints/src/test/java/org/onap/policy/drools/http/server/test/HttpClientTest.java @@ -41,7 +41,7 @@ public class HttpClientTest { private static Logger logger = LoggerFactory.getLogger(HttpClientTest.class); @BeforeClass - public static void setUp() { + public static void setUp() throws InterruptedException { logger.info("-- setup() --"); /* echo server */ diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java index 8b733970..31b7cec7 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java @@ -62,7 +62,7 @@ public interface DroolsControllerFactory { public DroolsController build(Properties properties, List<? extends TopicSource> eventSources, List<? extends TopicSink> eventSinks) - throws IllegalArgumentException, LinkageError; + throws LinkageError; /** * Explicit construction of a Drools Controller @@ -82,7 +82,7 @@ public interface DroolsControllerFactory { String version, List<TopicCoderFilterConfiguration> decoderConfigurations, List<TopicCoderFilterConfiguration> encoderConfigurations) - throws IllegalArgumentException, LinkageError; + throws LinkageError; /** * Releases the Drools Controller from operation @@ -121,8 +121,7 @@ public interface DroolsControllerFactory { */ public DroolsController get(String groupId, String artifactId, - String version) - throws IllegalArgumentException; + String version); /** * returns the current inventory of Drools Controllers @@ -147,8 +146,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { /** * Policy Controller Name Index */ - protected HashMap<String, DroolsController> droolsControllers = - new HashMap<String, DroolsController>(); + protected HashMap<String, DroolsController> droolsControllers = new HashMap<>(); /** * Null Drools Controller @@ -168,14 +166,11 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } } - /** - * {@inheritDoc} - */ @Override public DroolsController build(Properties properties, List<? extends TopicSource> eventSources, List<? extends TopicSink> eventSinks) - throws IllegalArgumentException, LinkageError { + throws LinkageError { String groupId = properties.getProperty(PolicyProperties.RULES_GROUPID); if (groupId == null || groupId.isEmpty()) @@ -210,14 +205,12 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { * @throws IllegalArgumentException invalid input data */ protected List<TopicCoderFilterConfiguration> codersAndFilters - (Properties properties, List<? extends Topic> topicEntities) - throws IllegalArgumentException { + (Properties properties, List<? extends Topic> topicEntities) { String PROPERTY_TOPIC_ENTITY_PREFIX; List<TopicCoderFilterConfiguration> - topics2DecodedClasses2Filters = - new ArrayList<TopicCoderFilterConfiguration>(); + topics2DecodedClasses2Filters = new ArrayList<>(); if (topicEntities.isEmpty()) return topics2DecodedClasses2Filters; @@ -225,7 +218,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { for (Topic topic: topicEntities) { /* source or sink ? ueb or dmaap? */ - boolean isSource = (topic instanceof TopicSource); + boolean isSource = topic instanceof TopicSource; CommInfrastructure commInfra = topic.getTopicCommInfrastructure(); if (commInfra == CommInfrastructure.UEB) { if (isSource) { @@ -295,10 +288,10 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { continue; } - List<PotentialCoderFilter> classes2Filters = new ArrayList<PotentialCoderFilter>(); + List<PotentialCoderFilter> classes2Filters = new ArrayList<>(); List<String> aTopicClasses = - new ArrayList<String>(Arrays.asList(eventClasses.split("\\s*,\\s*"))); + new ArrayList<>(Arrays.asList(eventClasses.split("\\s*,\\s*"))); for (String aClass: aTopicClasses) { @@ -312,7 +305,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { "." + aClass + PolicyProperties.PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX); - List<Pair<String,String>> filters = new ArrayList<Pair<String,String>>(); + List<Pair<String,String>> filters = new ArrayList<>(); if (filter == null || filter.isEmpty()) { // 4. topic -> class -> with no filters @@ -327,7 +320,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { // There are filters associated with the applicability of // this class for decoding. List<String> listOfFilters = - new ArrayList<String>(Arrays.asList(filter.split("\\s*,\\s*"))); + new ArrayList<>(Arrays.asList(filter.split("\\s*,\\s*"))); for (String nameValue: listOfFilters) { String fieldName; @@ -368,24 +361,22 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { return topics2DecodedClasses2Filters; } - /** - * {@inheritDoc} - * @param decoderConfiguration - */ @Override public DroolsController build(String newGroupId, String newArtifactId, String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations, List<TopicCoderFilterConfiguration> encoderConfigurations) - throws IllegalArgumentException, LinkageError { + throws LinkageError { - if (newGroupId == null || newArtifactId == null || newVersion == null || - newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) { - throw new IllegalArgumentException("Missing maven coordinates: " + - newGroupId + ":" + newArtifactId + ":" + - newVersion); - } + if (newGroupId == null || newGroupId.isEmpty()) + throw new IllegalArgumentException("Missing maven group-id coordinate"); + + if (newArtifactId == null || newArtifactId.isEmpty()) + throw new IllegalArgumentException("Missing maven artifact-id coordinate"); + + if (newVersion == null || newVersion.isEmpty()) + throw new IllegalArgumentException("Missing maven version coordinate"); String controllerId = newGroupId + ":" + newArtifactId; DroolsController controllerCopy = null; @@ -430,18 +421,12 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { return controller; } - /** - * {@inheritDoc} - */ @Override - public void destroy(DroolsController controller) throws IllegalArgumentException { + public void destroy(DroolsController controller) { unmanage(controller); controller.halt(); } - /** - * {@inheritDoc} - */ @Override public void destroy() { List<DroolsController> controllers = this.inventory(); @@ -461,7 +446,7 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { * @return * @throws IllegalArgumentException */ - protected void unmanage(DroolsController controller) throws IllegalArgumentException { + protected void unmanage(DroolsController controller) { if (controller == null) { throw new IllegalArgumentException("No controller provided"); } @@ -481,18 +466,12 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } } - /** - * {@inheritDoc} - */ @Override - public void shutdown(DroolsController controller) throws IllegalArgumentException { + public void shutdown(DroolsController controller) { this.unmanage(controller); controller.shutdown(); } - /** - * {@inheritDoc} - */ @Override public void shutdown() { List<DroolsController> controllers = this.inventory(); @@ -505,14 +484,10 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } } - /** - * {@inheritDoc} - */ @Override public DroolsController get(String groupId, String artifactId, - String version) - throws IllegalArgumentException, IllegalStateException { + String version) { if (groupId == null || artifactId == null || groupId.isEmpty() || artifactId.isEmpty()) { @@ -532,13 +507,10 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory { } } - /** - * {@inheritDoc} - */ @Override public List<DroolsController> inventory() { List<DroolsController> controllers = - new ArrayList<DroolsController>(this.droolsControllers.values()); + new ArrayList<>(this.droolsControllers.values()); return controllers; } diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index 79743b00..9689776c 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -127,25 +127,23 @@ public class MavenDroolsController implements DroolsController { String artifactId, String version, List<TopicCoderFilterConfiguration> decoderConfigurations, - List<TopicCoderFilterConfiguration> encoderConfigurations) - throws IllegalArgumentException { + List<TopicCoderFilterConfiguration> encoderConfigurations) { - if (logger.isInfoEnabled()) - logger.info("DROOLS CONTROLLER: instantiation " + this + - " -> {" + groupId + ":" + artifactId + ":" + version + "}"); - - if (groupId == null || artifactId == null || version == null || - groupId.isEmpty() || artifactId.isEmpty() || version.isEmpty()) { - throw new IllegalArgumentException("Missing maven coordinates: " + - groupId + ":" + artifactId + ":" + - version); - } + logger.info("drools-controller instantiation [{}:{}:{}]", groupId, artifactId, version); + + if (groupId == null || groupId.isEmpty()) + throw new IllegalArgumentException("Missing maven group-id coordinate"); + + if (artifactId == null || artifactId.isEmpty()) + throw new IllegalArgumentException("Missing maven artifact-id coordinate"); + + if (version == null || version.isEmpty()) + throw new IllegalArgumentException("Missing maven version coordinate"); this.policyContainer= new PolicyContainer(groupId, artifactId, version); this.init(decoderConfigurations, encoderConfigurations); - if (logger.isInfoEnabled()) - logger.info("DROOLS CONTROLLER: instantiation completed " + this); + logger.debug("{}: instantiation completed ", this); } /** @@ -165,24 +163,22 @@ public class MavenDroolsController implements DroolsController { this.modelClassLoaderHash = this.policyContainer.getClassLoader().hashCode(); } - /** - * {@inheritDoc} - */ @Override public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations, List<TopicCoderFilterConfiguration> encoderConfigurations) - throws IllegalArgumentException, LinkageError { + throws LinkageError { - if (logger.isInfoEnabled()) - logger.info("UPDATE-TO-VERSION: " + this + " -> {" + newGroupId + ":" + newArtifactId + ":" + newVersion + "}"); + logger.info("{}: updating version -> [{}:{}:{}]", newGroupId, newArtifactId, newVersion); - if (newGroupId == null || newArtifactId == null || newVersion == null || - newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) { - throw new IllegalArgumentException("Missing maven coordinates: " + - newGroupId + ":" + newArtifactId + ":" + - newVersion); - } + if (newGroupId == null || newGroupId.isEmpty()) + throw new IllegalArgumentException("Missing maven group-id coordinate"); + + if (newArtifactId == null || newArtifactId.isEmpty()) + throw new IllegalArgumentException("Missing maven artifact-id coordinate"); + + if (newVersion == null || newVersion.isEmpty()) + throw new IllegalArgumentException("Missing maven version coordinate"); if (newGroupId.equalsIgnoreCase(DroolsController.NO_GROUP_ID) || newArtifactId.equalsIgnoreCase(DroolsController.NO_ARTIFACT_ID) || @@ -234,8 +230,7 @@ public class MavenDroolsController implements DroolsController { * @param decoderConfiguration list of topic -> decoders -> filters mapping */ protected void initCoders(List<TopicCoderFilterConfiguration> coderConfigurations, - boolean decoder) - throws IllegalArgumentException { + boolean decoder) { if (logger.isInfoEnabled()) logger.info("INIT-CODERS: " + this); @@ -318,8 +313,7 @@ public class MavenDroolsController implements DroolsController { /** * remove decoders. */ - protected void removeDecoders() - throws IllegalArgumentException { + protected void removeDecoders(){ if (logger.isInfoEnabled()) logger.info("REMOVE-DECODERS: " + this); @@ -338,8 +332,7 @@ public class MavenDroolsController implements DroolsController { /** * remove decoders. */ - protected void removeEncoders() - throws IllegalArgumentException { + protected void removeEncoders() { if (logger.isInfoEnabled()) logger.info("REMOVE-ENCODERS: " + this); @@ -356,11 +349,8 @@ public class MavenDroolsController implements DroolsController { } - /** - * {@inheritDoc} - */ @Override - public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException { + public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) { if (!ReflectionUtil.isClass (this.policyContainer.getClassLoader(), coderClass.getCanonicalName())) { logger.error(this + coderClass.getCanonicalName() + " cannot be retrieved. "); @@ -382,9 +372,6 @@ public class MavenDroolsController implements DroolsController { } } - /** - * {@inheritDoc} - */ @Override public boolean start() { @@ -401,9 +388,6 @@ public class MavenDroolsController implements DroolsController { return this.policyContainer.start(); } - /** - * {@inheritDoc} - */ @Override public boolean stop() { @@ -419,12 +403,8 @@ public class MavenDroolsController implements DroolsController { return this.policyContainer.stop(); } - - /** - * {@inheritDoc} - */ @Override - public void shutdown() throws IllegalStateException { + public void shutdown() { logger.info("{}: SHUTDOWN", this); try { @@ -438,12 +418,8 @@ public class MavenDroolsController implements DroolsController { } - - /** - * {@inheritDoc} - */ @Override - public void halt() throws IllegalStateException { + public void halt() { logger.info("{}: HALT", this); try { @@ -475,17 +451,11 @@ public class MavenDroolsController implements DroolsController { } } - /** - * {@inheritDoc} - */ @Override public boolean isAlive() { return this.alive; } - /** - * {@inheritDoc} - */ @Override public boolean offer(String topic, String event) { logger.debug("{}: OFFER: {} <- {}", this, topic, event); @@ -498,7 +468,7 @@ public class MavenDroolsController implements DroolsController { // 0. Check if the policy container has any sessions - if (this.policyContainer.getPolicySessions().size() <= 0) { + if (this.policyContainer.getPolicySessions().isEmpty()) { // no sessions return true; } @@ -550,14 +520,9 @@ public class MavenDroolsController implements DroolsController { return true; } - /** - * {@inheritDoc} - */ @Override public boolean deliver(TopicSink sink, Object event) - throws IllegalArgumentException, - IllegalStateException, - UnsupportedOperationException { + throws UnsupportedOperationException { if (logger.isInfoEnabled()) logger.info(this + "DELIVER: " + event + " FROM " + this + " TO " + sink); @@ -589,25 +554,16 @@ public class MavenDroolsController implements DroolsController { } - /** - * {@inheritDoc} - */ @Override public String getVersion() { return this.policyContainer.getVersion(); } - /** - * {@inheritDoc} - */ @Override public String getArtifactId() { return this.policyContainer.getArtifactId(); } - /** - * {@inheritDoc} - */ @Override public String getGroupId() { return this.policyContainer.getGroupId(); @@ -620,9 +576,6 @@ public class MavenDroolsController implements DroolsController { return modelClassLoaderHash; } - /** - * {@inheritDoc} - */ @Override public synchronized boolean lock() { logger.info("LOCK: " + this); @@ -631,9 +584,6 @@ public class MavenDroolsController implements DroolsController { return true; } - /** - * {@inheritDoc} - */ @Override public synchronized boolean unlock() { logger.info("UNLOCK: " + this); @@ -642,34 +592,23 @@ public class MavenDroolsController implements DroolsController { return true; } - /** - * {@inheritDoc} - */ @Override public boolean isLocked() { return this.locked; } - /** - * {@inheritDoc} - */ @JsonIgnore + @Override public PolicyContainer getContainer() { return this.policyContainer; } - /** - * {@inheritDoc} - */ @JsonProperty("sessions") @Override public List<String> getSessionNames() { return getSessionNames(true); } - /** - * {@inheritDoc} - */ @JsonProperty("sessionCoordinates") @Override public List<String> getCanonicalSessionNames() { @@ -682,7 +621,7 @@ public class MavenDroolsController implements DroolsController { * @return session names */ protected List<String> getSessionNames(boolean abbreviated) { - List<String> sessionNames = new ArrayList<String>(); + List<String> sessionNames = new ArrayList<>(); try { for (PolicySession session: this.policyContainer.getPolicySessions()) { if (abbreviated) @@ -703,7 +642,7 @@ public class MavenDroolsController implements DroolsController { * @return the attached Policy Container */ protected List<PolicySession> getSessions() { - List<PolicySession> sessions = new ArrayList<PolicySession>(); + List<PolicySession> sessions = new ArrayList<>(); sessions.addAll(this.policyContainer.getPolicySessions()); return sessions; } @@ -729,15 +668,11 @@ public class MavenDroolsController implements DroolsController { throw new IllegalArgumentException("Invalid Session Name: " + sessionName); } - /** - * {@inheritDoc} - */ @Override - public Map<String,Integer> factClassNames(String sessionName) throws IllegalArgumentException { + public Map<String,Integer> factClassNames(String sessionName) { if (sessionName == null || sessionName.isEmpty()) throw new IllegalArgumentException("Invalid Session Name: " + sessionName); - - // List<String> classNames = new ArrayList<>(); + Map<String,Integer> classNames = new HashMap<>(); PolicySession session = getSession(sessionName); @@ -759,11 +694,8 @@ public class MavenDroolsController implements DroolsController { return classNames; } - /** - * {@inheritDoc} - */ @Override - public long factCount(String sessionName) throws IllegalArgumentException { + public long factCount(String sessionName) { if (sessionName == null || sessionName.isEmpty()) throw new IllegalArgumentException("Invalid Session Name: " + sessionName); @@ -771,9 +703,6 @@ public class MavenDroolsController implements DroolsController { return session.getKieSession().getFactCount(); } - /** - * {@inheritDoc} - */ @Override public List<Object> facts(String sessionName, String className, boolean delete) { if (sessionName == null || sessionName.isEmpty()) @@ -806,9 +735,6 @@ public class MavenDroolsController implements DroolsController { return factObjects; } - /** - * {@inheritDoc} - */ @Override public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) { if (sessionName == null || sessionName.isEmpty()) @@ -851,11 +777,8 @@ public class MavenDroolsController implements DroolsController { return factObjects; } - /** - * {@inheritDoc} - */ @Override - public Class<?> fetchModelClass(String className) throws IllegalStateException { + public Class<?> fetchModelClass(String className) { Class<?> modelClass = ReflectionUtil.fetchClass(this.policyContainer.getClassLoader(), className); return modelClass; @@ -883,10 +806,6 @@ public class MavenDroolsController implements DroolsController { } } - - /** - * {@inheritDoc} - */ @Override public boolean isBrained() { return true; diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java index c4db6c7e..2c4e40be 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java @@ -35,178 +35,111 @@ import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration; */ public class NullDroolsController implements DroolsController { - /** - * {@inheritDoc} - */ @Override - public boolean start() throws IllegalStateException { + public boolean start() { return false; } - /** - * {@inheritDoc} - */ @Override - public boolean stop() throws IllegalStateException { + public boolean stop() { return false; } - /** - * {@inheritDoc} - */ @Override - public void shutdown() throws IllegalStateException { + public void shutdown() { return; } - /** - * {@inheritDoc} - */ @Override - public void halt() throws IllegalStateException { + public void halt() { return; } - /** - * {@inheritDoc} - */ @Override public boolean isAlive() { return false; } - /** - * {@inheritDoc} - */ @Override public boolean lock() { return false; } - /** - * {@inheritDoc} - */ @Override public boolean unlock() { return false; } - /** - * {@inheritDoc} - */ @Override public boolean isLocked() { return false; } - /** - * {@inheritDoc} - */ @Override public String getGroupId() { return NO_GROUP_ID; } - /** - * {@inheritDoc} - */ @Override public String getArtifactId() { return NO_ARTIFACT_ID; } - /** - * {@inheritDoc} - */ @Override public String getVersion() { return NO_VERSION; } - /** - * {@inheritDoc} - */ @Override public List<String> getSessionNames() { - return new ArrayList<String>(); + return new ArrayList<>(); } - /** - * {@inheritDoc} - */ @Override public List<String> getCanonicalSessionNames() { - return new ArrayList<String>(); + return new ArrayList<>(); } - /** - * {@inheritDoc} - */ @Override public boolean offer(String topic, String event) { return false; } - /** - * {@inheritDoc} - */ @Override - public boolean deliver(TopicSink sink, Object event) - throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { + public boolean deliver(TopicSink sink, Object event) throws UnsupportedOperationException { throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked"); } - /** - * {@inheritDoc} - */ @Override public Object[] getRecentSourceEvents() { return new String[0]; } - /** - * {@inheritDoc} - */ @Override public PolicyContainer getContainer() { return null; } - /** - * {@inheritDoc} - */ @Override public String[] getRecentSinkEvents() { return new String[0]; } - /** - * {@inheritDoc} - */ @Override - public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) throws IllegalStateException { + public boolean ownsCoder(Class<? extends Object> coderClass, int modelHash) { throw new IllegalStateException(this.getClass().getCanonicalName() + " invoked"); } - /** - * {@inheritDoc} - */ @Override - public Class<?> fetchModelClass(String className) throws IllegalArgumentException { + public Class<?> fetchModelClass(String className) { throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); } - /** - * {@inheritDoc} - */ @Override public boolean isBrained() { return false; } - /** - * {@inheritDoc} - */ @Override public String toString() { StringBuilder builder = new StringBuilder(); @@ -214,9 +147,6 @@ public class NullDroolsController implements DroolsController { return builder.toString(); } - /** - * {@inheritDoc} - */ @Override public void updateToVersion(String newGroupId, String newArtifactId, String newVersion, List<TopicCoderFilterConfiguration> decoderConfigurations, @@ -225,38 +155,26 @@ public class NullDroolsController implements DroolsController { throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked"); } - /** - * {@inheritDoc} - */ @Override public Map<String, Integer> factClassNames(String sessionName) throws IllegalArgumentException { return new HashMap<String,Integer>(); } - /** - * {@inheritDoc} - */ @Override - public long factCount(String sessionName) throws IllegalArgumentException { + public long factCount(String sessionName) { return 0; } - /** - * {@inheritDoc} - */ @Override public List<Object> facts(String sessionName, String className, boolean delete) { - return new ArrayList<Object>(); + return new ArrayList<>(); } - /** - * {@inheritDoc} - */ @Override public List<Object> factQuery(String sessionName, String queryName, String queriedEntity, boolean delete, Object... queryParams) { - return new ArrayList<Object>(); + return new ArrayList<>(); } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java index 52aac744..bdda8e84 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java +++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java @@ -69,11 +69,11 @@ public interface SystemPersistence { * * @param controllerName the controller name * @param configuration object containing the configuration + * * @return true if storage is succesful, false otherwise * @throws IllegalArgumentException if the configuration cannot be handled by the persistence manager */ - public boolean storeController(String controllerName, Object configuration) - throws IllegalArgumentException; + public boolean storeController(String controllerName, Object configuration); /** * delete controller configuration @@ -88,19 +88,20 @@ public interface SystemPersistence { * * @param controllerName controller name * @return properties for this controller + * * @throws IllegalArgumentException if the controller name does not lead to a properties configuration */ - public Properties getControllerProperties(String controllerName) - throws IllegalArgumentException; + public Properties getControllerProperties(String controllerName); /** * get properties by name * * @param name * @return properties + * * @throws IllegalArgumentException if the name does not lead to a properties configuration */ - public Properties getProperties(String name) throws IllegalArgumentException; + public Properties getProperties(String name); /** * Persistence Manager. For now it is a file-based properties management, @@ -196,6 +197,7 @@ class SystemPropertiesPersistence implements SystemPersistence { /** * deletes properties-based controller configuration * @param controllerName the controller name + * * @return true if the properties has been deleted from disk, false otherwise */ @Override @@ -223,12 +225,12 @@ class SystemPropertiesPersistence implements SystemPersistence { } @Override - public Properties getControllerProperties(String controllerName) throws IllegalArgumentException { + public Properties getControllerProperties(String controllerName) { return this.getProperties(controllerName + CONTROLLER_SUFFIX_IDENTIFIER); } @Override - public Properties getProperties(String name) throws IllegalArgumentException { + public Properties getProperties(String name) { Path propertiesPath = Paths.get(CONFIG_DIR_NAME, name + ".properties"); @@ -242,7 +244,7 @@ class SystemPropertiesPersistence implements SystemPersistence { logger.warn("{}: can't read properties @ {}", name, propertiesPath); throw new IllegalArgumentException("can't read properties for " + name + " @ " + - propertiesPath); + propertiesPath, e); } } } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java index 8e7dec0b..1c8dafea 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java @@ -473,21 +473,20 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { /** * Logger */ - private static Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class); + private static final Logger logger = LoggerFactory.getLogger(GsonProtocolCoderToolset.class); /** * Formatter for JSON encoding/decoding */ @JsonIgnore - public static DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); @JsonIgnore - public static DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT; + public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT; /** * Adapter for ZonedDateTime */ - public static class GsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> { public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java index 4f5e33e7..d877f1e9 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java @@ -176,6 +176,7 @@ public class RestManager { return Response.status(Response.Status.OK). entity(PolicyEngine.manager.getFeatureProvider(featureName)).build(); } catch(IllegalArgumentException iae) { + logger.debug("feature unavailable: {}", featureName, iae); return Response.status(Response.Status.NOT_FOUND). entity(new Error(iae.getMessage())).build(); } @@ -478,6 +479,7 @@ public class RestManager { entity(PolicyController.factory.getFeatureProvider(featureName)). build(); } catch(IllegalArgumentException iae) { + logger.debug("{}: cannot feature {} because of {}", this, featureName, iae.getMessage(), iae); return Response.status(Response.Status.NOT_FOUND). entity(new Error(iae.getMessage())).build(); } @@ -504,10 +506,12 @@ public class RestManager { entity(PolicyController.factory.get(controllerName)). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")). build(); @@ -541,12 +545,12 @@ public class RestManager { entity(new Error(controllerName + " does not exist")). build(); } catch (IllegalArgumentException e) { - logger.info("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(new Error(controllerName + " not found: " + e.getMessage())). build(); } catch (IllegalStateException e) { - logger.info("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")).build(); } @@ -554,7 +558,7 @@ public class RestManager { try { PolicyEngine.manager.removePolicyController(controllerName); } catch (IllegalArgumentException | IllegalStateException e) { - logger.info("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e); + logger.debug("{}: cannot remove policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -585,10 +589,12 @@ public class RestManager { entity(controller.getProperties()). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")). build(); @@ -736,10 +742,12 @@ public class RestManager { entity(drools). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")). build(); @@ -770,10 +778,12 @@ public class RestManager { entity(sessionCounts). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")). build(); @@ -802,10 +812,12 @@ public class RestManager { entity(drools.factClassNames(sessionName)). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error("entity not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get drools-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + sessionName + " not acceptable")). build(); @@ -841,11 +853,13 @@ public class RestManager { else return Response.status(Response.Status.OK).entity(facts.size()).build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")). @@ -879,16 +893,22 @@ public class RestManager { List<Object> facts = drools.facts(sessionName, factType, true); return Response.status(Response.Status.OK).entity(facts).build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", + this, controllerName, sessionName, factType, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", + this, controllerName, sessionName, factType, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + sessionName + ":" + factType + " not acceptable")). build(); } catch (Exception e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, factType {}, because of {}", + this, controllerName, sessionName, factType, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -927,16 +947,22 @@ public class RestManager { else return Response.status(Response.Status.OK).entity(facts.size()).build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable")). build(); } catch (Exception e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -976,16 +1002,22 @@ public class RestManager { facts = drools.factQuery(sessionName, queryName, queriedEntity, false, queryParameters.toArray()); return Response.status(Response.Status.OK).entity(facts).build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable")). build(); } catch (Exception e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -1025,16 +1057,22 @@ public class RestManager { facts = drools.factQuery(sessionName, queryName, queriedEntity, true, queryParameters.toArray()); return Response.status(Response.Status.OK).entity(facts).build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + sessionName + ":" + queryName + queriedEntity + " not acceptable")). build(); } catch (Exception e) { + logger.debug("{}: cannot get: drools-controller {}, session {}, query {}, entity {}, params {} because of {}", + this, controllerName, sessionName, queryName, queriedEntity, queryParameters, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -1088,10 +1126,12 @@ public class RestManager { entity(decoders). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")). build(); @@ -1125,10 +1165,12 @@ public class RestManager { entity(filters). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoders for policy-controller {} because of {}", this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " not acceptable")). build(); @@ -1163,10 +1205,14 @@ public class RestManager { entity(decoder). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + " not acceptable")). build(); @@ -1207,10 +1253,14 @@ public class RestManager { entity(decoder.getCoders()). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + " not acceptable")). build(); @@ -1254,11 +1304,15 @@ public class RestManager { entity(filters). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", + this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", + this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")). @@ -1313,11 +1367,15 @@ public class RestManager { entity(filters). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}", + this, controllerName, topic, factClass, configFilters, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} filters {} because of {}", + this, controllerName, topic, factClass, configFilters, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")). @@ -1368,11 +1426,15 @@ public class RestManager { entity(filter.getRules()). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", + this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} because of {}", + this, controllerName, topic, factClass, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")). @@ -1425,11 +1487,15 @@ public class RestManager { entity(filter.getRules(ruleName)). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}", + this, controllerName, topic, factClass, ruleName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + factClass + ": " + ruleName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}", + this, controllerName, topic, factClass, ruleName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + factClass + ":" + ruleName + " not acceptable")). @@ -1499,11 +1565,15 @@ public class RestManager { entity(filter.getRules()). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}", + this, controllerName, topic, factClass, ruleName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + factClass + ": " + ruleName + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoder filters for policy-controller {} topic {} type {} rule {} because of {}", + this, controllerName, topic, factClass, ruleName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + factClass + ":" + ruleName + " not acceptable")). @@ -1566,11 +1636,15 @@ public class RestManager { entity(filter.getRules()). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}", + this, controllerName, topic, factClass, ruleName, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot access decoder filter rules for policy-controller {} topic {} type {} rule {} because of {}", + this, controllerName, topic, factClass, ruleName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + factClass + " not acceptable")). @@ -1603,11 +1677,15 @@ public class RestManager { try { policyController = PolicyController.factory.get(controllerName); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(controllerName + ":" + topic + ":" + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get decoders for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + ":" + topic + ":" + " not acceptable")). @@ -1628,6 +1706,8 @@ public class RestManager { json); result.decoding = true; } catch (Exception e) { + logger.debug("{}: cannot get policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(new Error(e.getMessage())). build(); @@ -1638,6 +1718,8 @@ public class RestManager { result.encoding = true; } catch (Exception e) { // continue so to propagate decoding results .. + logger.debug("{}: cannot encode for policy-controller {} topic {} because of {}", + this, controllerName, topic, e.getMessage(), e); } return Response.status(Response.Status.OK). @@ -1667,10 +1749,14 @@ public class RestManager { encoders = EventProtocolCoder.manager.getEncoderFilters (drools.getGroupId(), drools.getArtifactId()); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}", + this, controllerName, e.getMessage(), e); return Response.status(Response.Status.BAD_REQUEST). entity(new Error(controllerName + " not found: " + e.getMessage())). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot get encoder filters for policy-controller {} because of {}", + this, controllerName, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(controllerName + " is not accepting the request")).build(); } @@ -2100,14 +2186,20 @@ public class RestManager { entity(new Error("Failure to inject event over " + topic)). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", + this, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(topic + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", + this, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(topic + " not acceptable due to current state")). build(); } catch (Exception e) { + logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", + this, topic, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -2144,14 +2236,20 @@ public class RestManager { entity(new Error("Failure to inject event over " + topic)). build(); } catch (IllegalArgumentException e) { + logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", + this, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_FOUND). entity(new Error(topic + " not found")). build(); } catch (IllegalStateException e) { + logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", + this, topic, e.getMessage(), e); return Response.status(Response.Status.NOT_ACCEPTABLE). entity(new Error(topic + " not acceptable due to current state")). build(); } catch (Exception e) { + logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", + this, topic, e.getMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR). entity(new Error(e.getMessage())). build(); @@ -2262,7 +2360,7 @@ public class RestManager { * @return the underlying drools controller * @throws IllegalArgumentException if an invalid controller name has been passed in */ - protected DroolsController getDroolsController(String controllerName) throws IllegalArgumentException { + protected DroolsController getDroolsController(String controllerName) { PolicyController controller = PolicyController.factory.get(controllerName); if (controller == null) throw new IllegalArgumentException(controllerName + " does not exist"); diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java index 1ee12304..36821659 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java @@ -97,7 +97,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws IllegalArgumentException when invalid or insufficient * properties are provided */ - public void configure(Properties properties) throws IllegalArgumentException; + public void configure(Properties properties); /** * registers a new Policy Controller with the Policy Engine @@ -111,8 +111,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * this operation is not permitted. * @return the newly instantiated Policy Controller */ - public PolicyController createPolicyController(String name, Properties properties) - throws IllegalArgumentException, IllegalStateException; + public PolicyController createPolicyController(String name, Properties properties); /** * updates the Policy Engine with the given configuration @@ -122,8 +121,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws IllegalArgumentException if invalid argument provided * @throws IllegalStateException if the system is in an invalid state */ - public boolean configure(PdpdConfiguration configuration) - throws IllegalArgumentException, IllegalStateException; + public boolean configure(PdpdConfiguration configuration); /** * updates a set of Policy Controllers with configuration information @@ -133,8 +131,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws IllegalArgumentException * @throws IllegalStateException */ - public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration) - throws IllegalArgumentException, IllegalStateException; + public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configuration); /** * updates an already existing Policy Controller with configuration information @@ -146,8 +143,7 @@ public interface PolicyEngine extends Startable, Lockable, TopicListener { * @throws IllegalStateException if the controller is in a bad state * @throws Exception any other reason */ - public PolicyController updatePolicyController(ControllerConfiguration configuration) - throws Exception; + public PolicyController updatePolicyController(ControllerConfiguration configuration); /** * removes the Policy Controller identified by its name from the Policy Engine @@ -364,9 +360,6 @@ class PolicyEngineManager implements PolicyEngine { protected Gson decoder = new GsonBuilder().disableHtmlEscaping().create(); - /** - * {@inheritDoc} - */ @Override public synchronized void boot(String cliArgs[]) { @@ -397,11 +390,8 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override - public synchronized void configure(Properties properties) throws IllegalArgumentException { + public synchronized void configure(Properties properties) { if (properties == null) { logger.warn("No properties provided"); @@ -456,9 +446,6 @@ class PolicyEngineManager implements PolicyEngine { return; } - /** - * {@inheritDoc} - */ @Override public synchronized PolicyController createPolicyController(String name, Properties properties) throws IllegalArgumentException, IllegalStateException { @@ -507,11 +494,8 @@ class PolicyEngineManager implements PolicyEngine { } - /** - * {@inheritDoc} - */ @Override - public boolean configure(PdpdConfiguration config) throws IllegalArgumentException, IllegalStateException { + public boolean configure(PdpdConfiguration config) { if (config == null) throw new IllegalArgumentException("No configuration provided"); @@ -541,9 +525,6 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override public List<PolicyController> updatePolicyControllers(List<ControllerConfiguration> configControllers) throws IllegalArgumentException, IllegalStateException { @@ -567,12 +548,8 @@ class PolicyEngineManager implements PolicyEngine { return policyControllers; } - /** - * {@inheritDoc} - */ @Override - public PolicyController updatePolicyController(ControllerConfiguration configController) - throws Exception { + public PolicyController updatePolicyController(ControllerConfiguration configController) { if (configController == null) throw new IllegalArgumentException("No controller configuration has been provided"); @@ -595,7 +572,7 @@ class PolicyEngineManager implements PolicyEngine { policyController = PolicyController.factory.get(controllerName); } catch (IllegalArgumentException e) { // not found - logger.warn("Policy Controller " + controllerName + " not found"); + logger.warn("Policy Controller " + controllerName + " not found", e); } if (policyController == null) { @@ -669,11 +646,8 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override - public synchronized boolean start() throws IllegalStateException { + public synchronized boolean start() { /* policy-engine dispatch pre start hook */ for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { @@ -770,9 +744,6 @@ class PolicyEngineManager implements PolicyEngine { return success; } - /** - * {@inheritDoc} - */ @Override public synchronized boolean stop() { @@ -858,11 +829,8 @@ class PolicyEngineManager implements PolicyEngine { return success; } - /** - * {@inheritDoc} - */ @Override - public synchronized void shutdown() throws IllegalStateException { + public synchronized void shutdown() { /* policy-engine dispatch pre shutdown hook */ for (PolicyEngineFeatureAPI feature : PolicyEngineFeatureAPI.providers.getList()) { @@ -948,17 +916,11 @@ class PolicyEngineManager implements PolicyEngine { }).start(); } - /** - * {@inheritDoc} - */ @Override public synchronized boolean isAlive() { return this.alive; } - /** - * {@inheritDoc} - */ @Override public synchronized boolean lock() { @@ -1006,9 +968,6 @@ class PolicyEngineManager implements PolicyEngine { return success; } - /** - * {@inheritDoc} - */ @Override public synchronized boolean unlock() { @@ -1056,42 +1015,27 @@ class PolicyEngineManager implements PolicyEngine { return success; } - /** - * {@inheritDoc} - */ @Override public synchronized boolean isLocked() { return this.locked; } - /** - * {@inheritDoc} - */ @Override public void removePolicyController(String name) { PolicyController.factory.destroy(name); } - /** - * {@inheritDoc} - */ @Override public void removePolicyController(PolicyController controller) { PolicyController.factory.destroy(controller); } - /** - * {@inheritDoc} - */ @JsonIgnore @Override public List<PolicyController> getPolicyControllers() { return PolicyController.factory.inventory(); } - /** - * {@inheritDoc} - */ @JsonProperty("controllers") @Override public List<String> getPolicyControllerIds() { @@ -1102,9 +1046,6 @@ class PolicyEngineManager implements PolicyEngine { return controllerNames; } - /** - * {@inheritDoc} - */ @Override @JsonIgnore public Properties getProperties() { @@ -1112,36 +1053,23 @@ class PolicyEngineManager implements PolicyEngine { } - /** - * {@inheritDoc} - */ @SuppressWarnings("unchecked") @Override public List<TopicSource> getSources() { return (List<TopicSource>) this.sources; } - /** - * {@inheritDoc} - */ @SuppressWarnings("unchecked") @Override public List<TopicSink> getSinks() { return (List<TopicSink>) this.sinks; } - /** - * {@inheritDoc} - */ @Override public List<HttpServletServer> getHttpServers() { return this.httpServers; } - - /** - * {@inheritDoc} - */ @Override public List<String> getFeatures() { List<String> features = new ArrayList<String>(); @@ -1150,21 +1078,15 @@ class PolicyEngineManager implements PolicyEngine { } return features; } - - /** - * {@inheritDoc} - */ + @JsonIgnore @Override public List<PolicyEngineFeatureAPI> getFeatureProviders() { return PolicyEngineFeatureAPI.providers.getList(); } - /** - * {@inheritDoc} - */ @Override - public PolicyEngineFeatureAPI getFeatureProvider(String featureName) throws IllegalArgumentException { + public PolicyEngineFeatureAPI getFeatureProvider(String featureName) { if (featureName == null || featureName.isEmpty()) throw new IllegalArgumentException("A feature name must be provided"); @@ -1176,9 +1098,6 @@ class PolicyEngineManager implements PolicyEngine { throw new IllegalArgumentException("Invalid Feature Name: " + featureName); } - /** - * {@inheritDoc} - */ @Override public void onTopicEvent(CommInfrastructure commType, String topic, String event) { /* configuration request */ @@ -1191,9 +1110,6 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override public boolean deliver(String topic, Object event) throws IllegalArgumentException, IllegalStateException { @@ -1224,9 +1140,6 @@ class PolicyEngineManager implements PolicyEngine { topic, event); } - /** - * {@inheritDoc} - */ @Override public boolean deliver(String busType, String topic, Object event) throws IllegalArgumentException, IllegalStateException, @@ -1270,9 +1183,6 @@ class PolicyEngineManager implements PolicyEngine { topic, event); } - /** - * {@inheritDoc} - */ @Override public boolean deliver(Topic.CommInfrastructure busType, String topic, Object event) @@ -1323,9 +1233,6 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override public boolean deliver(Topic.CommInfrastructure busType, String topic, String event) @@ -1361,9 +1268,6 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override public synchronized void activate() { @@ -1406,9 +1310,6 @@ class PolicyEngineManager implements PolicyEngine { } } - /** - * {@inheritDoc} - */ @Override public synchronized void deactivate() { diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java index a9b916b1..1a771032 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/test/PolicyEngineTest.java @@ -93,6 +93,9 @@ public class PolicyEngineTest { PolicyController testController = PolicyController.factory.get("unnamed"); assertFalse(testController.getDrools().isAlive()); assertFalse(testController.getDrools().isLocked()); + + PolicyEngine.manager.removePolicyController("unnamed"); + assertTrue(PolicyController.factory.inventory().isEmpty()); } } diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java new file mode 100644 index 00000000..f6c837f5 --- /dev/null +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/NetworkUtil.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2017 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.drools.utils; + +/** + * Network Utilities + */ +public class NetworkUtil { + + /** + * IPv4 Wildcard IP address + */ + public static final String IPv4_WILDCARD_ADDRESS = "0.0.0.0"; + + /* Other methods will be added as needed */ + +} diff --git a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java index eeb7f1f6..ba00c57e 100644 --- a/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java +++ b/policy-utils/src/main/java/org/onap/policy/drools/utils/ReflectionUtil.java @@ -57,7 +57,7 @@ public class ReflectionUtil { classLoader); return aClass; } catch (Exception e) { - logger.error("FETCHED-CLASS {} IN {} does NOT EXIST", className, classLoader); + logger.error("class {} fetched in {} does not exist", className, classLoader, e); } return null; |