diff options
author | Jim Hahn <jrh3@att.com> | 2018-02-19 16:56:06 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2018-02-20 09:59:15 -0500 |
commit | a45f8909871dc1ddb75845f067a602951afc8d11 (patch) | |
tree | fa72aff7ceede971d4e6922f62a503a8ee8924d5 /policy-endpoints/src | |
parent | 1708e9a45cb88571613c10b68d392811b2b3f0f4 (diff) |
Sonar fixes to drools-pdp
Fixed most of the instances of the following sonar issues:
Moved array designator
Used diamond operator
Changed System.out/err to use a logger
Changed several Thread.sleep() in test code to a single sleep()
Useless assignments
Replaced comparison with "" to string.isEmpty()
Merged if's
Replaced ArrayList with List in method returns
Reordered type modifiers
Reordered constructor methods
Defined constants for literals, or replaced them with method calls
Removed "throws Xxx" for subclasses of RuntimeException
Combined identical "catch" blocks
Re-interrupted the current thread after catching an InterruptedException
Removed tests against the literal "false"
Fix indentation of new makeTopicOperError() method.
Fix exception variable name in new methods, logNoUebEncoder()
and logNoDmaapEncoder().
Change-Id: Iddae5210553662f733b67333b372dec8c3fe2c94
Issue-ID: POLICY-336
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-endpoints/src')
9 files changed, 134 insertions, 155 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 fc7db6f7..5c04bb8f 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -43,6 +43,11 @@ import com.fasterxml.jackson.annotation.JsonIgnore; public interface TopicEndpoint extends Startable, Lockable { /** + * singleton for global access + */ + public static final TopicEndpoint manager = new ProxyTopicEndpointManager(); + + /** * Add Topic Sources to the communication infrastructure initialized per properties * * @param properties properties for Topic Source construction @@ -90,8 +95,7 @@ public interface TopicEndpoint extends Startable, Lockable { * @throws IllegalArgumentException if invalid parameters are present * @throws UnsupportedOperationException if the operation is not supported. */ - public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) - throws UnsupportedOperationException; + public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName); /** * get the UEB Topic Source for the given topic name @@ -138,8 +142,7 @@ public interface TopicEndpoint extends Startable, Lockable { * TopicWriters for a topic name and communication infrastructure * @throws IllegalArgumentException if invalid parameters are present */ - public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) - throws UnsupportedOperationException; + public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName); /** * get the Topic Sinks for the given topic name and all the underlying communication @@ -232,11 +235,6 @@ public interface TopicEndpoint extends Startable, Lockable { * @return the NOOP Topic Sinks List */ public List<NoopTopicSink> getNoopTopicSinks(); - - /** - * singleton for global access - */ - public static final TopicEndpoint manager = new ProxyTopicEndpointManager(); } @@ -552,17 +550,14 @@ class ProxyTopicEndpointManager implements TopicEndpoint { } @Override - public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) - throws UnsupportedOperationException { + public TopicSource getTopicSource(Topic.CommInfrastructure commType, String topicName) { if (commType == null) { - throw new IllegalArgumentException( - "Invalid parameter: a communication infrastructure required to fetch " + topicName); + throw parmException(topicName); } if (topicName == null) { - throw new IllegalArgumentException( - "Invalid parameter: a communication infrastructure required to fetch " + topicName); + throw parmException(topicName); } switch (commType) { @@ -575,17 +570,19 @@ class ProxyTopicEndpointManager implements TopicEndpoint { } } + private IllegalArgumentException parmException(String topicName) { + return new IllegalArgumentException( + "Invalid parameter: a communication infrastructure required to fetch " + topicName); + } + @Override - public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) - throws UnsupportedOperationException { + public TopicSink getTopicSink(Topic.CommInfrastructure commType, String topicName) { if (commType == null) { - throw new IllegalArgumentException( - "Invalid parameter: a communication infrastructure required to fetch " + topicName); + throw parmException(topicName); } if (topicName == null) { - throw new IllegalArgumentException( - "Invalid parameter: a communication infrastructure required to fetch " + topicName); + throw parmException(topicName); } switch (commType) { @@ -603,8 +600,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint { @Override public List<TopicSink> getTopicSinks(String topicName) { if (topicName == null) { - throw new IllegalArgumentException( - "Invalid parameter: a communication infrastructure required to fetch " + topicName); + throw parmException(topicName); } final List<TopicSink> sinks = new ArrayList<>(); @@ -612,24 +608,28 @@ class ProxyTopicEndpointManager implements TopicEndpoint { try { sinks.add(this.getUebTopicSink(topicName)); } catch (final Exception e) { - logger.debug("No sink for topic: {}", topicName, e); + logNoSink(topicName, e); } try { sinks.add(this.getDmaapTopicSink(topicName)); } catch (final Exception e) { - logger.debug("No sink for topic: {}", topicName, e); + logNoSink(topicName, e); } try { sinks.add(this.getNoopTopicSink(topicName)); } catch (final Exception e) { - logger.debug("No sink for topic: {}", topicName, e); + logNoSink(topicName, e); } return sinks; } +private void logNoSink(String topicName, Exception ex) { + logger.debug("No sink for topic: {}", topicName, ex); +} + @Override public UebTopicSource getUebTopicSource(String topicName) { return UebTopicSource.factory.get(topicName); diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java index b7937ec3..5ea849ee 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicSink.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -35,6 +35,6 @@ public interface TopicSink extends Topic { * @throws IllegalStateException the entity is in an state that prevents * it from sending messages, for example, locked or stopped. */ - public boolean send(String message) throws IllegalArgumentException, IllegalStateException; + public boolean send(String message); } 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 43854c2a..5ff5084e 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -167,6 +167,8 @@ public interface DmaapTopicSinkFactory { * Factory of DMAAP Reader Topics indexed by topic name */ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { + private static final String MISSING_TOPIC = "A topic must be provided"; + /** * Logger */ @@ -196,7 +198,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { boolean allowSelfSignedCerts) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized (this) { @@ -230,7 +232,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { boolean useHttps, boolean allowSelfSignedCerts) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized (this) { @@ -277,7 +279,8 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); List<String> serverList; - if (servers != null && !servers.isEmpty()) serverList = new ArrayList<>(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 + @@ -404,7 +407,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { public void destroy(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } DmaapTopicSink dmaapTopicWriter; @@ -435,7 +438,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { public DmaapTopicSink get(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -449,9 +452,7 @@ class IndexedDmaapTopicSinkFactory implements DmaapTopicSinkFactory { @Override public synchronized List<DmaapTopicSink> inventory() { - List<DmaapTopicSink> writers = - new ArrayList<>(this.dmaapTopicWriters.values()); - return writers; + return new ArrayList<>(this.dmaapTopicWriters.values()); } @Override diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java index d5894d5e..5a8e2a72 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/DmaapTopicSourceFactory.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -53,8 +53,7 @@ public interface DmaapTopicSourceFactory { * @return an DMAAP Topic Source * @throws IllegalArgumentException if invalid parameters are present */ - public List<DmaapTopicSource> build(Properties properties) - throws IllegalArgumentException; + public List<DmaapTopicSource> build(Properties properties); /** * Instantiates a new DMAAP Topic Source @@ -88,8 +87,7 @@ public interface DmaapTopicSourceFactory { int fetchLimit, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException; + boolean allowSelfSignedCerts); /** * Instantiates a new DMAAP Topic Source @@ -135,8 +133,7 @@ public interface DmaapTopicSourceFactory { Map<String,String> additionalProps, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException; + boolean allowSelfSignedCerts); /** * Instantiates a new DMAAP Topic Source @@ -152,8 +149,7 @@ public interface DmaapTopicSourceFactory { public DmaapTopicSource build(List<String> servers, String topic, String apiKey, - String apiSecret) - throws IllegalArgumentException; + String apiSecret); /** * Instantiates a new DMAAP Topic Source @@ -165,8 +161,7 @@ public interface DmaapTopicSourceFactory { * @throws IllegalArgumentException if invalid parameters are present */ public DmaapTopicSource build(List<String> servers, - String topic) - throws IllegalArgumentException; + String topic); /** * Destroys an DMAAP Topic Source based on a topic @@ -189,8 +184,7 @@ public interface DmaapTopicSourceFactory { * @throws IllegalStateException if the DMAAP Topic Source is * an incorrect state */ - public DmaapTopicSource get(String topic) - throws IllegalArgumentException, IllegalStateException; + public DmaapTopicSource get(String topic); /** * Provides a snapshot of the DMAAP Topic Sources @@ -207,6 +201,8 @@ public interface DmaapTopicSourceFactory { */ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { + private static final String MISSING_TOPIC = "A topic must be provided"; + /** * Logger */ @@ -240,11 +236,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { 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"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -282,15 +277,14 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { int fetchLimit, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException { + boolean allowSelfSignedCerts) { if (servers == null || servers.isEmpty()) { throw new IllegalArgumentException("DMaaP Server(s) must be provided"); } if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -315,8 +309,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { * {@inheritDoc} */ @Override - public List<DmaapTopicSource> build(Properties properties) - throws IllegalArgumentException { + public List<DmaapTopicSource> build(Properties properties) { String readTopics = properties.getProperty(PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS); if (readTopics == null || readTopics.isEmpty()) { @@ -325,11 +318,11 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { } List<String> readTopicList = new ArrayList<>(Arrays.asList(readTopics.split("\\s*,\\s*"))); - List<DmaapTopicSource> dmaapTopicSource_s = new ArrayList<>(); + List<DmaapTopicSource> dmaapTopicSourceLst = new ArrayList<>(); synchronized(this) { for (String topic: readTopicList) { if (this.dmaapTopicSources.containsKey(topic)) { - dmaapTopicSource_s.add(this.dmaapTopicSources.get(topic)); + dmaapTopicSourceLst.add(this.dmaapTopicSources.get(topic)); continue; } @@ -338,7 +331,8 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { PolicyProperties.PROPERTY_TOPIC_SERVERS_SUFFIX); List<String> serverList; - if (servers != null && !servers.isEmpty()) serverList = new ArrayList<>(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_SOURCE_TOPICS + @@ -490,10 +484,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { dme2Latitude, dme2Longitude, dme2AdditionalProps, managed, useHttps, allowSelfSignedCerts); - dmaapTopicSource_s.add(uebTopicSource); + dmaapTopicSourceLst.add(uebTopicSource); } } - return dmaapTopicSource_s; + return dmaapTopicSourceLst; } /** @@ -504,7 +498,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { public DmaapTopicSource build(List<String> servers, String topic, String apiKey, - String apiSecret) throws IllegalArgumentException { + String apiSecret) { return this.build(servers, topic, apiKey, apiSecret, null, null, null, null, @@ -520,7 +514,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { * @throws IllegalArgumentException */ @Override - public DmaapTopicSource build(List<String> servers, String topic) throws IllegalArgumentException { + public DmaapTopicSource build(List<String> servers, String topic) { return this.build(servers, topic, null, null); } @@ -528,11 +522,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { * {@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"); + throw new IllegalArgumentException(MISSING_TOPIC); } DmaapTopicSource uebTopicSource; @@ -552,11 +545,10 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { * {@inheritDoc} */ @Override - public DmaapTopicSource get(String topic) - throws IllegalArgumentException, IllegalStateException { + public DmaapTopicSource get(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -570,9 +562,7 @@ class IndexedDmaapTopicSourceFactory implements DmaapTopicSourceFactory { @Override public synchronized List<DmaapTopicSource> inventory() { - List<DmaapTopicSource> readers = - new ArrayList<>(this.dmaapTopicSources.values()); - return readers; + return new ArrayList<>(this.dmaapTopicSources.values()); } @Override 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 1958da06..8633d093 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -94,7 +94,9 @@ public interface NoopTopicSinkFactory { * Factory of noop sinks */ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { - /** + private static final String MISSING_TOPIC = "A topic must be provided"; + +/** * Logger */ private static Logger logger = LoggerFactory.getLogger(IndexedUebTopicSinkFactory.class); @@ -159,7 +161,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { } if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized (this) { @@ -179,7 +181,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { @Override public void destroy(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } NoopTopicSink noopSink; @@ -209,7 +211,7 @@ class IndexedNoopTopicSinkFactory implements NoopTopicSinkFactory { @Override public NoopTopicSink get(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized (this) { 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 fc4229c3..10468bef 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -116,6 +116,8 @@ public interface UebTopicSinkFactory { * Factory of UEB Reader Topics indexed by topic name */ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { + private static final String MISSING_TOPIC = "A topic must be provided"; + /** * Logger */ @@ -142,7 +144,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { } if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized (this) { @@ -245,7 +247,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { public void destroy(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } UebTopicSink uebTopicWriter; @@ -276,7 +278,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { public UebTopicSink get(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -290,9 +292,7 @@ class IndexedUebTopicSinkFactory implements UebTopicSinkFactory { @Override public synchronized List<UebTopicSink> inventory() { - List<UebTopicSink> writers = - new ArrayList<>(this.uebTopicSinks.values()); - return writers; + return new ArrayList<>(this.uebTopicSinks.values()); } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java index d614d100..d48be278 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/UebTopicSourceFactory.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,8 +44,7 @@ public interface UebTopicSourceFactory { * @return an UEB Topic Source * @throws IllegalArgumentException if invalid parameters are present */ - public List<UebTopicSource> build(Properties properties) - throws IllegalArgumentException; + public List<UebTopicSource> build(Properties properties); /** * Instantiates a new UEB Topic Source @@ -73,8 +72,7 @@ public interface UebTopicSourceFactory { int fetchLimit, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException; + boolean allowSelfSignedCerts); /** * Instantiates a new UEB Topic Source @@ -90,8 +88,7 @@ public interface UebTopicSourceFactory { public UebTopicSource build(List<String> servers, String topic, String apiKey, - String apiSecret) - throws IllegalArgumentException; + String apiSecret); /** * Instantiates a new UEB Topic Source @@ -103,8 +100,7 @@ public interface UebTopicSourceFactory { * @throws IllegalArgumentException if invalid parameters are present */ public UebTopicSource build(List<String> servers, - String topic) - throws IllegalArgumentException; + String topic); /** * Destroys an UEB Topic Source based on a topic @@ -127,8 +123,7 @@ public interface UebTopicSourceFactory { * @throws IllegalStateException if the UEB Topic Source is * an incorrect state */ - public UebTopicSource get(String topic) - throws IllegalArgumentException, IllegalStateException; + public UebTopicSource get(String topic); /** * Provides a snapshot of the UEB Topic Sources @@ -143,6 +138,8 @@ public interface UebTopicSourceFactory { * Factory of UEB Source Topics indexed by topic name */ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { + private static final String MISSING_TOPIC = "A topic must be provided"; + /** * Logger */ @@ -168,14 +165,13 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { int fetchLimit, boolean managed, boolean useHttps, - boolean allowSelfSignedCerts) - throws IllegalArgumentException { + boolean allowSelfSignedCerts) { if (servers == null || servers.isEmpty()) { throw new IllegalArgumentException("UEB Server(s) must be provided"); } if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -200,8 +196,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { * {@inheritDoc} */ @Override - public List<UebTopicSource> build(Properties properties) - throws IllegalArgumentException { + public List<UebTopicSource> build(Properties properties) { String readTopics = properties.getProperty(PolicyProperties.PROPERTY_UEB_SOURCE_TOPICS); if (readTopics == null || readTopics.isEmpty()) { @@ -334,11 +329,10 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { * {@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"); + throw new IllegalArgumentException(MISSING_TOPIC); } UebTopicSource uebTopicSource; @@ -358,11 +352,10 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { * {@inheritDoc} */ @Override - public UebTopicSource get(String topic) - throws IllegalArgumentException, IllegalStateException { + public UebTopicSource get(String topic) { if (topic == null || topic.isEmpty()) { - throw new IllegalArgumentException("A topic must be provided"); + throw new IllegalArgumentException(MISSING_TOPIC); } synchronized(this) { @@ -376,9 +369,7 @@ class IndexedUebTopicSourceFactory implements UebTopicSourceFactory { @Override public synchronized List<UebTopicSource> inventory() { - List<UebTopicSource> readers = - new ArrayList<>(this.uebTopicSources.values()); - return readers; + return new ArrayList<>(this.uebTopicSources.values()); } @Override 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 06503304..984baa79 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 @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -101,8 +101,7 @@ public interface BusConsumer { */ public CambriaConsumerWrapper(List<String> servers, String topic, String apiKey, String apiSecret, String consumerGroup, String consumerInstance, int fetchTimeout, - int fetchLimit, boolean useHttps, boolean useSelfSignedCerts) - throws IllegalArgumentException { + int fetchLimit, boolean useHttps, boolean useSelfSignedCerts) { this.fetchTimeout = fetchTimeout; @@ -368,27 +367,16 @@ public interface BusConsumer { additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY); if (environment == null || environment.isEmpty()) { - throw new IllegalArgumentException( - "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic - + PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX - + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX); } if (aftEnvironment == null || aftEnvironment.isEmpty()) { - throw new IllegalArgumentException( - "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic - + PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX - + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX); } if (latitude == null || latitude.isEmpty()) { - throw new IllegalArgumentException("Missing " - + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic - + PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX); } if (longitude == null || longitude.isEmpty()) { - throw new IllegalArgumentException( - "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic - + PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX - + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX); } if ((dme2Partner == null || dme2Partner.isEmpty()) @@ -459,6 +447,13 @@ public interface BusConsumer { logger.info("{}: CREATION", this); } + + private IllegalArgumentException parmException(String topic, String propnm) { + return new IllegalArgumentException( + "Missing " + PolicyProperties.PROPERTY_DMAAP_SOURCE_TOPICS + "." + topic + + propnm + " property for DME2 in DMaaP"); + + } } } diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java index f664cfa7..852c9c16 100644 --- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java +++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusPublisher.java @@ -1,8 +1,8 @@ -/*- +/* * ============LICENSE_START======================================================= * policy-endpoints * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -51,7 +51,7 @@ public interface BusPublisher { * @return true if success, false otherwise * @throws IllegalArgumentException if no message provided */ - public boolean send(String partitionId, String message) throws IllegalArgumentException; + public boolean send(String partitionId, String message); /** * closes the publisher @@ -73,7 +73,7 @@ public interface BusPublisher { public CambriaPublisherWrapper(List<String> servers, String topic, String apiKey, - String apiSecret, boolean useHttps) throws IllegalArgumentException { + String apiSecret, boolean useHttps) { PublisherBuilder builder = new CambriaClientBuilders.PublisherBuilder(); @@ -105,8 +105,7 @@ public interface BusPublisher { * {@inheritDoc} */ @Override - public boolean send(String partitionId, String message) - throws IllegalArgumentException { + public boolean send(String partitionId, String message) { if (message == null) throw new IllegalArgumentException("No message provided"); @@ -169,7 +168,7 @@ public interface BusPublisher { public DmaapPublisherWrapper(ProtocolTypeConstants protocol, List<String> servers, String topic, String username, - String password, boolean useHttps) throws IllegalArgumentException { + String password, boolean useHttps) { if (topic == null || topic.isEmpty()) @@ -260,8 +259,7 @@ public interface BusPublisher { * {@inheritDoc} */ @Override - public boolean send(String partitionId, String message) - throws IllegalArgumentException { + public boolean send(String partitionId, String message) { if (message == null) throw new IllegalArgumentException("No message provided"); @@ -322,17 +320,13 @@ public interface BusPublisher { String dme2RouteOffer = additionalProps.get(DmaapTopicSinkFactory.DME2_ROUTE_OFFER_PROPERTY); if (environment == null || environment.isEmpty()) { - throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_ENVIRONMENT_SUFFIX); } if (aftEnvironment == null || aftEnvironment.isEmpty()) { - throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_AFT_ENVIRONMENT_SUFFIX); } if (latitude == null || latitude.isEmpty()) { - throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LATITUDE_SUFFIX); } if (longitude == null || longitude.isEmpty()) { - throw new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + - "." + topic + PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX + " property for DME2 in DMaaP"); + throw parmException(topic, PolicyProperties.PROPERTY_DMAAP_DME2_LONGITUDE_SUFFIX); } if ((dme2Partner == null || dme2Partner.isEmpty()) && (dme2RouteOffer == null || dme2RouteOffer.isEmpty())) { @@ -381,5 +375,11 @@ public interface BusPublisher { this.publisher.setProps(props); } + + private IllegalArgumentException parmException(String topic, String propnm) { + return new IllegalArgumentException("Missing " + PolicyProperties.PROPERTY_DMAAP_SINK_TOPICS + + "." + topic + propnm + " property for DME2 in DMaaP"); + + } } } |