Fix critical sonar issues in messagerouter/mirroragent
[dmaap/messagerouter/mirroragent.git] / src / main / java / org / onap / dmaap / mr / dmaapMMAgent / MirrorMakerAgent.java
index 2252992..9af3809 100644 (file)
@@ -79,8 +79,7 @@ public class MirrorMakerAgent {
                        try {
                                agent.checkAgentProcess();
                        } catch (Exception e) {
-
-                               e.printStackTrace();
+                           logger.error("exception occured in checkAgentProcess ", e);
                        }
                        agent.readAgentTopic();
                } else {
@@ -92,11 +91,10 @@ public class MirrorMakerAgent {
        private boolean checkStartup() {
                FileInputStream input = null;
                try {
-                       //this.mmagenthome = System.getProperty("MMAGENTHOME");
                        input = new FileInputStream(mmagenthome + "/etc/mmagent.config");
                        logger.info("mmagenthome is set :" + mmagenthome + " loading properties at /etc/mmagent.config");
                } catch (IOException ex) {
-                       logger.error(mmagenthome + "/etc/mmagent.config not found.  Set -DMMAGENTHOME and check the config file");
+                       logger.error(mmagenthome + "/etc/mmagent.config not found.", ex);
                        return false;
                } finally {
                        if (input != null) {
@@ -111,9 +109,9 @@ public class MirrorMakerAgent {
                input = null;
                try {
                        input = new FileInputStream(kafkahome + "/bin/kafka-run-class.sh");
-                       logger.info("kakahome is set :" + kafkahome);
+                       logger.info("kafkahome is set :" + kafkahome);
                } catch (IOException ex) {
-                       logger.error(kafkahome + "/bin/kafka-run-class.sh not found.  Make sure kafka home is set correctly");
+                       logger.error(kafkahome + "/bin/kafka-run-class.sh not found.  Make sure kafka home is set correctly", ex);
                        return false;
                } finally {
                        if (input != null) {
@@ -131,7 +129,7 @@ public class MirrorMakerAgent {
                        return false;
                }
                logger.info("Published to Topic :" + this.topicname + " Successfully");
-               response = topicUtil.subscribeTopic(topicURL, topicname, "1", response, response);
+               response = topicUtil.subscribeTopic(topicURL, topicname, "1", mechid, password);
                if (response != null && response.startsWith("ERROR:")) {
                        logger.error("Problem subscribing to topic, please verify the config " + this.topicname + " MR URL is:"
                                        + this.topicURL + " Error is:  " + response);
@@ -175,7 +173,7 @@ public class MirrorMakerAgent {
                                try {
                                        input.close();
                                } catch (IOException e) {
-                                       e.printStackTrace();
+                                   logger.error("exception occured in checkPropertiesFile ", e);
                                }
                        }
                        if (out != null) {
@@ -270,7 +268,7 @@ public class MirrorMakerAgent {
 
                        }
                } catch (Exception e) {
-                       e.printStackTrace();
+                   logger.error("exception occured in readAgentTopic ", e);
                }
 
        }
@@ -308,13 +306,13 @@ public class MirrorMakerAgent {
                        out = new FileOutputStream(mmagenthome + "/etc/mmagent.config");
                        mirrorMakerProperties.store(out, "");
                } catch (IOException ex) {
-                       ex.printStackTrace();
+                   logger.error("exception occured in createMirrorMaker ", ex);
                } finally {
                        if (out != null) {
                                try {
                                        out.close();
                                } catch (IOException e) {
-                                       e.printStackTrace();
+                                   logger.error("exception occured in createMirrorMaker ", e);
                                }
                        }
                }
@@ -362,13 +360,13 @@ public class MirrorMakerAgent {
                                } catch (InterruptedException e) {
                                }
                        } catch (IOException ex) {
-                               ex.printStackTrace();
+                           logger.error("exception occured in updateMirrorMaker ", ex);
                        } finally {
                                if (out != null) {
                                        try {
                                                out.close();
                                        } catch (IOException e) {
-                                               e.printStackTrace();
+                                           logger.error("exception occured in updateMirrorMaker ", e);
                                        }
                                }
                        }
@@ -405,13 +403,13 @@ public class MirrorMakerAgent {
                                } catch (InterruptedException e) {
                                }
                        } catch (IOException ex) {
-                               ex.printStackTrace();
+                           logger.error("exception occured in updateWhiteList ", ex);
                        } finally {
                                if (out != null) {
                                        try {
                                                out.close();
                                        } catch (IOException e) {
-                                               e.printStackTrace();
+                                           logger.error("exception occured in updateWhiteList ", e);
                                        }
                                }
                        }
@@ -440,12 +438,14 @@ public class MirrorMakerAgent {
                                File file = new File(path);
                                file.delete();
                        } catch (Exception ex) {
+                           logger.error("exception occured in deleteMirrorMaker ", ex);
                        }
                        try {
                                String path = mmagenthome + "/etc/" + newMirrorMaker.name + "producer" + ".properties";
                                File file = new File(path);
                                file.delete();
                        } catch (Exception ex) {
+                           logger.error("exception occured in deleteMirrorMaker ", ex);
                        }
                        Gson g = new Gson();
                        mirrorMakerProperties.setProperty("mirrormakers", g.toJson(this.mirrorMakers));
@@ -455,13 +455,13 @@ public class MirrorMakerAgent {
                                mirrorMakerProperties.store(out, "");
                                MirrorMakerProcessHandler.stopMirrorMaker(newMirrorMaker.name);
                        } catch (IOException ex) {
-                               ex.printStackTrace();
+                           logger.error("exception occured in deleteMirrorMaker ", ex);
                        } finally {
                                if (out != null) {
                                        try {
                                                out.close();
                                        } catch (IOException e) {
-                                               e.printStackTrace();
+                                           logger.error("exception occured in deleteMirrorMaker ", e);
                                        }
                                }
                        }
@@ -480,7 +480,7 @@ public class MirrorMakerAgent {
                        if (mirrorMakerProperties.getProperty("mirrormakers") == null) {
                                this.mirrorMakers = new ListMirrorMaker();
                                ArrayList<MirrorMaker> list = this.mirrorMakers.getListMirrorMaker();
-                               list = new ArrayList<MirrorMaker>();
+                               list = new ArrayList<>();
                                this.mirrorMakers.setListMirrorMaker(list);
                        } else {
                                this.mirrorMakers = g.fromJson(mirrorMakerProperties.getProperty("mirrormakers"),
@@ -497,13 +497,13 @@ public class MirrorMakerAgent {
                        textEncryptor.setPassword(secret);
                        this.password = textEncryptor.decrypt(mirrorMakerProperties.getProperty("password"));
                } catch (Exception ex) {
-                       // ex.printStackTrace();
+                   logger.error("exception occured in loadProperties ", ex);
                } finally {
                        if (input != null) {
                                try {
                                        input.close();
                                } catch (IOException e) {
-                                       // e.printStackTrace();
+                                   logger.error("exception occured in loadProperties ", e);
                                }
                        }
                }