summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java2
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java41
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java23
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java9
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java39
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/messagemgr/MessageChannelFactory.java2
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgr.java6
7 files changed, 29 insertions, 93 deletions
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
index c7b87e9..55d8d72 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
@@ -106,7 +106,7 @@ public class TaskThread implements Runnable {
if (Constant.COLLECT_TYPE_CM.equalsIgnoreCase(collectVo.getType())) {
parseResult = processCMXml(tempfile, nename, "CM");
} else {
- if (unfileName.indexOf(".csv") > 0) {
+ if (unfileName.indexOf(".csv") > -1) {//changed to -1 for coding practice as having ".csv" must have some some legal name
parseResult = processPMCsv(tempfile);
} else {
parseResult = processPMXml(tempfile);
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java
index a2b04bc..3d470b5 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java
@@ -76,7 +76,6 @@ public class FTPSrv implements FTPInterface {
try {
this.ftpClient.setSoTimeout(timeout);
} catch (Exception e) {
- //e.printStackTrace();
log.error(" StackTrace :", e);
}
}
@@ -91,6 +90,7 @@ public class FTPSrv implements FTPInterface {
ftpClient.logout();
ftpClient.disconnect();
} catch (Exception e) {
+ log.error(" StackTrace :", e);
}
ftpClient = null;
}
@@ -116,9 +116,8 @@ public class FTPSrv implements FTPInterface {
public boolean downloadFile(String remoteFile, String localFile) {
boolean sucess = false;
- BufferedOutputStream toLfileOutput = null;
- try {
- toLfileOutput = new BufferedOutputStream(new FileOutputStream(localFile));
+ try (
+ BufferedOutputStream toLfileOutput = new BufferedOutputStream(new FileOutputStream(localFile))){
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
if (ftpClient.retrieveFile(remoteFile, toLfileOutput)) {
sucess = true;
@@ -128,13 +127,7 @@ public class FTPSrv implements FTPInterface {
} catch (Exception ioe) {
sucess = false;
log.error("downloadFile remoteFile =" + remoteFile + " is fail ", ioe);
- } finally {
- if (toLfileOutput != null)
- try {
- toLfileOutput.close();
- } catch (IOException e) {
- }
- }
+ }
return sucess;
}
@@ -167,31 +160,5 @@ public class FTPSrv implements FTPInterface {
return returnValue;
}
-// public boolean store(String localFile, String remoteFile) {
-//
-// boolean sucess = false;
-// FileInputStream lfileInput = null;
-// try {
-// lfileInput = new FileInputStream(localFile);
-// ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
-//
-// if (ftpClient.storeFile(remoteFile, lfileInput)){
-// sucess = true;
-// }else{
-// sucess = false;
-// }
-// } catch (Exception ioe) {
-// sucess = false;
-// log.error("store localFile = "+localFile+" is fail "+StringUtil.getStackTrace(ioe));
-// } finally {
-// if (lfileInput != null)
-// try {
-// lfileInput.close();
-// } catch (IOException e) {
-// }
-// }
-// return sucess;
-// }
-
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
index e10ab20..1b9606b 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/StringUtil.java
@@ -18,30 +18,25 @@ package org.onap.vfc.nfvo.emsdriver.commons.utils;
import java.io.File;
import java.io.PrintWriter;
import java.io.StringWriter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
public class StringUtil {
+ private static final Log log = LogFactory.getLog(StringUtil.class);
public static String getStackTrace(Throwable t) {
- StringWriter sw = null;
- PrintWriter pw = null;
- try {
- sw = new StringWriter();
- pw = new PrintWriter(sw);
+ try(
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw)){
t.printStackTrace(pw);
pw.flush();
sw.flush();
return sw.getBuffer().toString();
} catch (Exception e) {
-
- } finally {
- try {
- if (pw != null) pw.close();
- if (sw != null) sw.close();
- } catch (Exception e2) {
-
- }
- }
+ log.error("getStackTrace : ",e);
+ }
return null;
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
index 49e0894..bc70907 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/UnZip.java
@@ -52,8 +52,7 @@ public class UnZip {
*
*/
public void deCompress() throws IOException {
- ZipFile zipFile = new ZipFile(zipFilePath);
- try {
+ try(ZipFile zipFile = new ZipFile(zipFilePath)){
Enumeration<ZipEntry> e = zipFile.getEntries();
for (ZipEntry entry; e.hasMoreElements(); ) {
entry = e.nextElement();
@@ -66,10 +65,8 @@ public class UnZip {
}
} catch (IOException e) {
throw e;
- } finally {
- zipFile.close();
- }
- }
+ }
+ }
/**
*
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java
index d17ced5..ae2aa58 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java
@@ -71,16 +71,13 @@ public class ConfigurationManager extends DriverThread {
@Override
public void dispose() {
- //this.log.debug("start loading " + cacheFilePath);
File file = new File(CONFIG_PROPERTIES_LOCATION);
if (!file.exists() || !file.isFile()) {
log.error("cacheFilePath " + CONFIG_PROPERTIES_LOCATION + " not exist or is not File");
return;
}
- InputStream in = null;
- try {
+ try(InputStream in = new FileInputStream(file)){
properties = new Properties();
- in = new FileInputStream(file);
properties.load(in);
Map<String, CrontabVo> emsMap = readCorntab();
@@ -89,14 +86,7 @@ public class ConfigurationManager extends DriverThread {
new ReceiveSource().start();
} catch (Exception e) {
log.error("read [" + file.getAbsolutePath() + "]Exception :", e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (Exception e) {
- }
- }
- }
+ }
}
public Map<String, CrontabVo> readCorntab() {
@@ -107,11 +97,10 @@ public class ConfigurationManager extends DriverThread {
log.debug("not exists " + path);
return null;
}
- InputStream is = null;
Map<String, CrontabVo> tmpcache = new HashMap<String, CrontabVo>();
- try {
- is = new FileInputStream(cfg);
+ try (
+ InputStream is = new FileInputStream(cfg)){
Document doc = XmlUtil.getDocument(is);
Element root = doc.getRootElement();
@@ -151,16 +140,7 @@ public class ConfigurationManager extends DriverThread {
} catch (Exception e) {
log.error("load crontab.xml is error " + StringUtil.getStackTrace(e));
- } finally {
- try {
- if (is != null) {
- is.close();
- is = null;
- }
- } catch (Exception e2) {
- }
- cfg = null;
- }
+ }
return tmpcache;
}
@@ -189,15 +169,14 @@ public class ConfigurationManager extends DriverThread {
emsInfoCache.putAll(emsInfoMap);
}
if (emsInfoCache.size() > 0) {
- Thread.sleep(30 * 60 * 1000);
+ Thread.sleep(30 * 60 * 1000L);
} else {
- Thread.sleep(60 * 1000);
+ Thread.sleep(60 * 1000L);
}
} catch (Exception e) {
try {
- Thread.sleep(60 * 1000);
- } catch (InterruptedException e1) {
- //e1.printStackTrace();
+ Thread.sleep(60 * 1000L);
+ } catch (Exception e1) {
log.error("InterruptedException :" + StringUtil.getStackTrace(e1));
}
log.error("ReceiveSource exception", e);
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/messagemgr/MessageChannelFactory.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/messagemgr/MessageChannelFactory.java
index cca8058..494620d 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/messagemgr/MessageChannelFactory.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/messagemgr/MessageChannelFactory.java
@@ -20,7 +20,7 @@ import java.util.Map;
public class MessageChannelFactory {
- public static Map<String, MessageChannel> map = new HashMap<String, MessageChannel>();
+ private static Map<String, MessageChannel> map = new HashMap<String, MessageChannel>();
public synchronized static MessageChannel getMessageChannel(String key, Integer size) {
if (map.get(key) != null) {
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgr.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgr.java
index ca42866..179dcd5 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgr.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/northbound/client/NorthMessageMgr.java
@@ -124,7 +124,7 @@ public class NorthMessageMgr extends DriverThread {
AgentMain.evel_post_event(header);
log.info("HeatBeat send!");
try {
- Thread.sleep(60000);//60 secs
+ Thread.sleep(60 * 1000L);//60 secs
} catch (Exception e) {
// e.printStackTrace();
log.error("Unable to sleep the HB thread ", e);
@@ -224,8 +224,6 @@ public class NorthMessageMgr extends DriverThread {
try {
eventTimeD = format.parse(eventTime);
} catch (ParseException e) {
- // TODO Auto-generated catch block
- //e.printStackTrace();
log.error("ParseException ", e);
}
flt.evel_start_epoch_set(eventTimeD.getTime());
@@ -340,7 +338,7 @@ public class NorthMessageMgr extends DriverThread {
sm.evel_reporting_entity_id_set(rmUID.substring(0, 9));//
String Dn = reMap.get("Dn");
if (Dn != null)
- sm.evel_reporting_entity_name_set(Dn.substring(0, Dn != null && Dn.indexOf(";") > 0 ? Dn.indexOf(";") : Dn.length()));
+ sm.evel_reporting_entity_name_set(Dn.substring(0, Dn.indexOf(";") > -1 ? Dn.indexOf(";") : Dn.length()));//0 is valid index
else {
// decide the flow if Dn is null