[POLICY-114] fix some sonar criticals 83/6583/1
authorJorge Hernandez <jh1730@att.com>
Wed, 2 Aug 2017 23:16:28 +0000 (18:16 -0500)
committerJorge Hernandez <jh1730@att.com>
Wed, 2 Aug 2017 23:16:28 +0000 (18:16 -0500)
Change-Id: Ic79b3d81ac814948ce3a956fe4c32b8a9b5c0009
Signed-off-by: Jorge Hernandez <jh1730@att.com>
feature-healthcheck/src/main/java/org/onap/policy/drools/healthcheck/HealthCheck.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/TopicEndpoint.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/BusConsumer.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedBusTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/drools/event/comm/bus/internal/SingleThreadedDmaapTopicSource.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/client/HttpClientFactory.java
policy-endpoints/src/main/java/org/onap/policy/drools/http/client/internal/JerseyClient.java
policy-management/src/main/java/org/onap/policy/drools/controller/DroolsController.java
policy-management/src/main/java/org/onap/policy/drools/controller/DroolsControllerFactory.java
policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java
policy-management/src/main/java/org/onap/policy/drools/controller/internal/NullDroolsController.java

index 0e4ed79..5cbcf55 100644 (file)
@@ -172,9 +172,11 @@ class HealthCheckMonitor implements HealthCheck {
                                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 @@ class HealthCheckMonitor implements HealthCheck {
                                }
                        }
                } catch (Exception e) {
+                       logger.warn("{}: cannot start {}", this, e);            
                        return false;
                }
                
index c1eb1e0..84cc1de 100644 (file)
@@ -564,7 +564,7 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
                                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 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
                                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 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
                                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 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
                                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 @@ class ProxyTopicEndpointManager implements TopicEndpoint {
                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;
index 0555940..6122c5d 100644 (file)
@@ -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 @@ public interface BusConsumer {
         * @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 @@ public interface BusConsumer {
                /**
                 * {@inheritDoc}
                 */
-               public Iterable<String> fetch() throws Exception {
+               public Iterable<String> fetch() throws IOException {
                        return this.consumer.fetch();
                }
                
@@ -208,7 +209,8 @@ public interface BusConsumer {
                /**
                 * {@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 @@ public interface BusConsumer {
                /**
                 * {@inheritDoc}
                 */
+               @Override
                public void close() {
                        synchronized (closeCondition) {
                                closeCondition.notifyAll();
index c396049..5243838 100644 (file)
@@ -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 @@ public abstract class SingleThreadedBusTopicSource
        /**
         * Initialize the Bus client
         */
-       public abstract void init() throws Exception;
+       public abstract void init() throws MalformedURLException;
        
        @Override
        public void register(TopicListener topicListener) 
index dc70e52..6c1bc8a 100644 (file)
@@ -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 @@ public class SingleThreadedDmaapTopicSource extends SingleThreadedBusTopicSource
         * 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 =
index c434c64..aa0a8e6 100644 (file)
@@ -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.onap.policy.drools.properties.PolicyProperties;
 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 @@ class IndexedHttpClientFactory implements HttpClientFactory {
                                                     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 @@ class IndexedHttpClientFactory implements HttpClientFactory {
        }
 
        @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);
index fe36740..5dd9736 100644 (file)
@@ -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 @@ public class JerseyClient implements HttpClient {
                                    String hostname, int port, 
                                    String basePath, String userName,
                                    String password) 
-       throws Exception {
+       throws KeyManagementException, NoSuchAlgorithmException {
                
                super();
                
index c4c61a8..f531c44 100644 (file)
@@ -164,7 +164,7 @@ public interface DroolsController extends Startable, Lockable {
        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
index c7a63a0..8b73397 100644 (file)
@@ -58,12 +58,11 @@ public interface DroolsControllerFactory {
         * @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 @@ public interface DroolsControllerFactory {
         * @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 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
        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 @@ class IndexedDroolsControllerFactory implements DroolsControllerFactory {
                                              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()) {
index db62f78..79743b0 100644 (file)
@@ -172,7 +172,7 @@ public class MavenDroolsController implements DroolsController {
        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 @@ public class MavenDroolsController implements DroolsController {
                
                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 @@ public class MavenDroolsController implements DroolsController {
                                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 @@ public class MavenDroolsController implements DroolsController {
                                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 @@ public class MavenDroolsController implements DroolsController {
                                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);
                        }
                }
                
index 3fef6fa..c4db6c7 100644 (file)
@@ -221,7 +221,7 @@ public class NullDroolsController implements DroolsController {
        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");
        }