[POLICY-114] fix some sonar criticals
Change-Id: Ic79b3d81ac814948ce3a956fe4c32b8a9b5c0009
Signed-off-by: Jorge Hernandez <jh1730@att.com>
diff --git a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
index 0e4ed79..5cbcf55 100644
--- a/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
+++ b/feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
@@ -172,9 +172,11 @@
try {
report.message = HttpClient.getBody(response, String.class);
} catch (Exception e) {
- logger.warn("{}: cannot get body from http-client {}", this, client, e);
+ logger.info("{}: cannot get body from http-client {}", this, client, e);
}
} catch (Exception e) {
+ logger.warn("{}: cannot contact http-client {}", this, client, e);
+
report.healthy = false;
reports.healthy = false;
}
@@ -202,6 +204,7 @@
}
}
} catch (Exception e) {
+ logger.warn("{}: cannot start {}", this, e);
return false;
}
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 c1eb1e0..84cc1de 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
@@ -564,7 +564,7 @@
if (uebSource != null)
sources.add(uebSource);
} catch (Exception e) {
- logger.info("No UEB source for topic: {}", topic);
+ logger.info("No UEB source for topic: {}", topic, e);
}
try {
@@ -572,7 +572,7 @@
if (dmaapSource != null)
sources.add(dmaapSource);
} catch (Exception e) {
- logger.info("No DMAAP source for topic: {}", topic);
+ logger.info("No DMAAP source for topic: {}", topic, e);
}
}
return sources;
@@ -596,7 +596,7 @@
if (uebSink != null)
sinks.add(uebSink);
} catch (Exception e) {
- logger.info("No UEB sink for topic: {}", topic);
+ logger.info("No UEB sink for topic: {}", topic, e);
}
try {
@@ -604,7 +604,7 @@
if (dmaapSink != null)
sinks.add(dmaapSink);
} catch (Exception e) {
- logger.info("No DMAAP sink for topic: {}", topic);
+ logger.info("No DMAAP sink for topic: {}", topic, e);
}
}
return sinks;
@@ -682,13 +682,13 @@
try {
sinks.add(this.getUebTopicSink(topicName));
} catch (Exception e) {
- ;
+ logger.debug("No sink for topic: {}", topicName, e);
}
try {
sinks.add(this.getDmaapTopicSink(topicName));
} catch (Exception e) {
- ;
+ logger.debug("No sink for topic: {}", topicName, e);
}
return sinks;
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 0555940..6122c5d 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
@@ -20,6 +20,7 @@
package org.onap.policy.drools.event.comm.bus.internal;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
@@ -52,7 +53,7 @@
* @return list of messages
* @throws Exception when error encountered by underlying libraries
*/
- public Iterable<String> fetch() throws Exception;
+ public Iterable<String> fetch() throws InterruptedException, IOException;
/**
* close underlying library consumer
@@ -136,7 +137,7 @@
/**
* {@inheritDoc}
*/
- public Iterable<String> fetch() throws Exception {
+ public Iterable<String> fetch() throws IOException {
return this.consumer.fetch();
}
@@ -208,7 +209,8 @@
/**
* {@inheritDoc}
*/
- public Iterable<String> fetch() throws Exception {
+ @Override
+ public Iterable<String> fetch() throws InterruptedException, IOException {
MRConsumerResponse response = this.consumer.fetchWithReturnConsumerResponse();
if (response == null) {
logger.warn("{}: DMaaP NULL response received", this);
@@ -245,6 +247,7 @@
/**
* {@inheritDoc}
*/
+ @Override
public void close() {
synchronized (closeCondition) {
closeCondition.notifyAll();
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
index c396049..5243838 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
@@ -20,6 +20,7 @@
package org.onap.policy.drools.event.comm.bus.internal;
+import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@@ -146,7 +147,7 @@
/**
* Initialize the Bus client
*/
- public abstract void init() throws Exception;
+ public abstract void init() throws MalformedURLException;
@Override
public void register(TopicListener topicListener)
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
index dc70e52..6c1bc8a 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
@@ -20,6 +20,7 @@
package org.onap.policy.drools.event.comm.bus.internal;
+import java.net.MalformedURLException;
import java.util.List;
import java.util.Map;
@@ -146,7 +147,7 @@
* Initialize the Cambria or MR Client
*/
@Override
- public void init() throws Exception {
+ public void init() throws MalformedURLException {
if (this.userName == null || this.userName.isEmpty() ||
this.password == null || this.password.isEmpty()) {
this.consumer =
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/HttpClientFactory.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/HttpClientFactory.java
index c434c64..aa0a8e6 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/HttpClientFactory.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/HttpClientFactory.java
@@ -19,6 +19,8 @@
*/
package org.onap.policy.drools.http.client;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -30,26 +32,52 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Http Client Factory
+ */
public interface HttpClientFactory {
+ /**
+ * build and http client with the following parameters
+ */
public HttpClient build(String name, boolean https,
boolean selfSignedCerts,
String hostname, int port,
String baseUrl, String userName,
String password, boolean managed)
- throws Exception;
+ throws KeyManagementException, NoSuchAlgorithmException;
- public ArrayList<HttpClient> build(Properties properties) throws Exception;
+ /**
+ * build http client from properties
+ */
+ public ArrayList<HttpClient> build(Properties properties)
+ throws KeyManagementException, NoSuchAlgorithmException;
+ /**
+ * get http client
+ * @param name the name
+ * @return the http client
+ */
public HttpClient get(String name);
+ /**
+ * list of http clients
+ * @return http clients
+ */
public List<HttpClient> inventory();
+ /**
+ * destroy by name
+ * @param name name
+ */
public void destroy(String name);
public void destroy();
}
+/**
+ * http client factory implementation indexed by name
+ */
class IndexedHttpClientFactory implements HttpClientFactory {
/**
@@ -64,7 +92,7 @@
String hostname, int port,
String baseUrl, String userName, String password,
boolean managed)
- throws Exception {
+ throws KeyManagementException, NoSuchAlgorithmException {
if (clients.containsKey(name))
return clients.get(name);
@@ -78,7 +106,8 @@
}
@Override
- public synchronized ArrayList<HttpClient> build(Properties properties) throws Exception {
+ public synchronized ArrayList<HttpClient> build(Properties properties)
+ throws KeyManagementException, NoSuchAlgorithmException {
ArrayList<HttpClient> clientList = new ArrayList<HttpClient>();
String clientNames = properties.getProperty(PolicyProperties.PROPERTY_HTTP_CLIENT_SERVICES);
diff --git a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
index fe36740..5dd9736 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
@@ -20,6 +20,8 @@
package org.onap.policy.drools.http.client.internal;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@@ -67,7 +69,7 @@
String hostname, int port,
String basePath, String userName,
String password)
- throws Exception {
+ throws KeyManagementException, NoSuchAlgorithmException {
super();
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
index c4c61a8..f531c44 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
@@ -164,7 +164,7 @@
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError, Exception;
+ throws IllegalArgumentException, LinkageError;
/**
* gets the classnames of facts as well as the current count
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 c7a63a0..8b73397 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
@@ -58,12 +58,11 @@
* @return the instantiated Drools Controller
* @throws IllegalArgumentException with invalid parameters
* @throws LinkageError Failure to link rules and models in Drools Libraries
- * @throws Exception Exception from Drools Libraries
*/
public DroolsController build(Properties properties,
List<? extends TopicSource> eventSources,
List<? extends TopicSink> eventSinks)
- throws IllegalArgumentException, LinkageError, Exception;
+ throws IllegalArgumentException, LinkageError;
/**
* Explicit construction of a Drools Controller
@@ -77,14 +76,13 @@
* @return the instantiated Drools Controller
* @throws IllegalArgumentException with invalid parameters
* @throws LinkageError Failure to link rules and models in Drools Libraries
- * @throws Exception Exception from Drools Libraries
*/
public DroolsController build(String groupId,
String artifactId,
String version,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError, Exception;
+ throws IllegalArgumentException, LinkageError;
/**
* Releases the Drools Controller from operation
@@ -177,7 +175,7 @@
public DroolsController build(Properties properties,
List<? extends TopicSource> eventSources,
List<? extends TopicSink> eventSinks)
- throws IllegalArgumentException, LinkageError, Exception {
+ throws IllegalArgumentException, LinkageError {
String groupId = properties.getProperty(PolicyProperties.RULES_GROUPID);
if (groupId == null || groupId.isEmpty())
@@ -380,7 +378,7 @@
String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError, Exception {
+ throws IllegalArgumentException, LinkageError {
if (newGroupId == null || newArtifactId == null || newVersion == null ||
newGroupId.isEmpty() || newArtifactId.isEmpty() || newVersion.isEmpty()) {
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 db62f78..79743b0 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
@@ -172,7 +172,7 @@
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError, Exception {
+ throws IllegalArgumentException, LinkageError {
if (logger.isInfoEnabled())
logger.info("UPDATE-TO-VERSION: " + this + " -> {" + newGroupId + ":" + newArtifactId + ":" + newVersion + "}");
@@ -722,7 +722,7 @@
List<PolicySession> sessions = this.getSessions();
for (PolicySession session : sessions) {
- if (sessionName.equals(session.getName()) || sessionName.equals(session.getName()))
+ if (sessionName.equals(session.getName()) || sessionName.equals(session.getFullName()))
return session;
}
@@ -752,8 +752,7 @@
else
classNames.put(className, 1);
} catch (Exception e) {
- if (logger.isInfoEnabled())
- logger.info("Object cannot be retrieved from fact: " + fact);
+ logger.warn("Object cannot be retrieved from fact {}", fact, e);
}
}
@@ -800,8 +799,7 @@
if (delete)
kieSession.delete(factHandle);
} catch (Exception e) {
- if (logger.isInfoEnabled())
- logger.info("Object cannot be retrieved from fact: " + factHandle);
+ logger.warn("Object cannot be retrieved from fact {}", factHandle, e);
}
}
@@ -846,8 +844,7 @@
if (delete)
kieSession.delete(row.getFactHandle(queriedEntity));
} catch (Exception e) {
- if (logger.isInfoEnabled())
- logger.info("Object cannot be retrieved from fact: " + row);
+ logger.warn("Object cannot be retrieved from row: {}", row, e);
}
}
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 3fef6fa..c4db6c7 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
@@ -221,7 +221,7 @@
public void updateToVersion(String newGroupId, String newArtifactId, String newVersion,
List<TopicCoderFilterConfiguration> decoderConfigurations,
List<TopicCoderFilterConfiguration> encoderConfigurations)
- throws IllegalArgumentException, LinkageError, Exception {
+ throws IllegalArgumentException, LinkageError {
throw new IllegalArgumentException(this.getClass().getCanonicalName() + " invoked");
}