summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYan Yang <yangyanyj@chinamobile.com>2018-02-01 09:17:06 +0000
committerGerrit Code Review <gerrit@onap.org>2018-02-01 09:17:06 +0000
commit4de60fd69a84c6d6f744b2b2dd83190393df0053 (patch)
tree6cd3affbff1a20d847fb12570bbced761dce5c32
parentd512a452bda7cf0a7f63d4d52d38b7ff03d82aff (diff)
parent8074f04115c6f6f1d28b0d59ac0c5678ae7a5540 (diff)
Merge "remove test code from production code"
-rw-r--r--.gitignore3
-rw-r--r--ems/.gitignore3
-rw-r--r--ems/boco/.gitignore2
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java5
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManager.java132
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImpTest.java129
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java2
-rw-r--r--ems/microservice-standalone/.gitignore3
8 files changed, 148 insertions, 131 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..17aa10b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.idea
+target
+ems-driver.iml
diff --git a/ems/.gitignore b/ems/.gitignore
new file mode 100644
index 0000000..4c8558d
--- /dev/null
+++ b/ems/.gitignore
@@ -0,0 +1,3 @@
+.idea
+target
+ems-driver-boco-parent.iml
diff --git a/ems/boco/.gitignore b/ems/boco/.gitignore
new file mode 100644
index 0000000..3fcee50
--- /dev/null
+++ b/ems/boco/.gitignore
@@ -0,0 +1,2 @@
+target
+boco-driver.iml
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java
index 38ee12d..3535fa2 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmManager.java
@@ -22,6 +22,7 @@ import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
import org.onap.vfc.nfvo.emsdriver.commons.model.EMSInfo;
import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread;
import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface;
+import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationManager;
public class AlarmManager extends DriverThread{
@@ -30,14 +31,14 @@ public class AlarmManager extends DriverThread{
@Override
public void dispose() {
log.debug("AlarmManager is start");
- //get alarm config
+ //get alarm CONFIG_PROPERTIES_LOCATION
List<EMSInfo> emsInfos = configurationInterface.getAllEMSInfo();
while(isRun() && emsInfos.size() == 0){
emsInfos = configurationInterface.getAllEMSInfo();
if(emsInfos.size() == 0){
try {
Thread.sleep(1000);
- log.debug("config is not load");
+ log.debug("The configuration properties from " + ConfigurationManager.CONFIG_PROPERTIES_LOCATION + " is not load");
} catch (InterruptedException e) {
}
}
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 f82160b..7fb2078 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
@@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
+import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jdom.Document;
@@ -43,25 +44,26 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
-public class ConfigurationManager extends DriverThread{
+public class ConfigurationManager extends DriverThread {
protected static Log log = LogFactory.getLog(ConfigurationManager.class);
+ public final static String CONFIG_PROPERTIES_LOCATION = Constant.SYS_CFG + "config.properties";
/**
* ESM Cache
*/
- private static Map<String, EMSInfo> emsInfoCache = new ConcurrentHashMap<String, EMSInfo>();
+ @VisibleForTesting
+ static Map<String, EMSInfo> emsInfoCache = new ConcurrentHashMap<String, EMSInfo>();
private static Map<String, CrontabVo> emsCrontab= new ConcurrentHashMap<String, CrontabVo>();
private static List<String> emsIdList = new ArrayList<String>();
- private static Properties properties = null;
-
- private final static String config = Constant.SYS_CFG + "config.properties";
-
+ @VisibleForTesting
+ static Properties properties = null;
+
@Override
public void dispose() {
//this.log.debug("start loading " + cacheFilePath);
- File file = new File(config);
+ File file = new File(CONFIG_PROPERTIES_LOCATION);
if(!file.exists() || !file.isFile()){
- log.error("cacheFilePath " + config+" not exist or is not File");
+ log.error("cacheFilePath " + CONFIG_PROPERTIES_LOCATION +" not exist or is not File");
return;
}
InputStream in = null;
@@ -72,8 +74,7 @@ public class ConfigurationManager extends DriverThread{
Map<String, CrontabVo> emsMap = readCorntab();
emsCrontab.putAll(emsMap);
-
- //
+
new ReceiveSource().start();
}catch(Exception e) {
log.error("read ["+file.getAbsolutePath()+"]Exception :",e);
@@ -151,114 +152,6 @@ public class ConfigurationManager extends DriverThread{
}
return tmpcache;
}
-
-
- public void readcfg(){
- String path = Constant.SYS_CFG + "EMSInfo.xml";
- File cfg = new File(path);
- log.debug("start loading " + path);
- if(!cfg.exists() || !cfg.isFile()){
- log.debug("not exists " + path);
- return;
- }
-
-
- InputStream is = null;
- Map<String, EMSInfo> tmpcache = new HashMap<String, EMSInfo>();
-
- try {
- is = new FileInputStream(cfg);
- Document doc = XmlUtil.getDocument(is);
-
- Element root = doc.getRootElement();
-
- @SuppressWarnings("unchecked")
- List<Element> children = root.getChildren();
-
- for(Iterator<Element> it = children.iterator();it.hasNext();){
- EMSInfo emsInfo = new EMSInfo();
- Element child = it.next();
- String name = child.getAttributeValue("name");
- if(StringUtil.isBank(name)){
- continue;
- }
- emsInfo.setName(name);
-
-// tmpcache.put(name, emsInfo);
-
- @SuppressWarnings("unchecked")
- List<Element> collectList = child.getChildren();
- for(Element collect : collectList){
-
- CollectVo collectVo = new CollectVo();
-
- String type = collect.getAttributeValue("type");
- if("alarm".equalsIgnoreCase(type)){
- boolean iscollect = Boolean.parseBoolean(collect.getAttributeValue("iscollect"));
- if(iscollect){
- collectVo.setIscollect(iscollect);
- }else{
- continue;
- }
- collectVo.setType(type);
- collectVo.setIP(collect.getChildText("ip"));
- collectVo.setPort(collect.getChildText("port"));
- collectVo.setUser(collect.getChildText("user"));
- collectVo.setPassword(collect.getChildText("password"));
- collectVo.setRead_timeout(collect.getChildText("readtimeout"));
- }else{
- String crontab = collect.getAttributeValue("crontab");
- if(!StringUtil.isBank(type) && !StringUtil.isBank(crontab)){
- collectVo.setType(type);
- collectVo.setCrontab(crontab);
- }else{
- continue;
- }
- collectVo.setIP(collect.getChildText("ip"));
- collectVo.setPort(collect.getChildText("port"));
- collectVo.setUser(collect.getChildText("user"));
- collectVo.setPassword(collect.getChildText("password"));
- collectVo.setRemotepath(collect.getChildText("remotepath"));
- collectVo.setMatch(collect.getChildText("match"));
- collectVo.setPassive(collect.getChildText("passive"));
- collectVo.setFtptype(collect.getChildText("ftptype"));
- collectVo.setGranularity(collect.getChildText("granularity"));
- }
-
- emsInfo.putCollectMap(type, collectVo);
- }
- tmpcache.put(name, emsInfo);
- }
- emsInfoCache.putAll(tmpcache);
-
- File file = new File(config);
- if(!file.exists() || !file.isFile()){
- log.error("cacheFilePath " + config+" not exist or is not File");
- return;
- }
- InputStream in = null;
- try{
- properties = new Properties();
- in = new FileInputStream(file);
- properties.load(in);
- }catch (Exception e) {
- e.printStackTrace();
- }
- } catch (Exception e) {
- log.error("load EMSInfo.xml is error "+StringUtil.getStackTrace(e));
- }finally{
- tmpcache.clear();
- try {
- if(is != null){
- is.close();
- is = null;
- }
- } catch (Exception e2) {
- }
- cfg = null;
- }
- }
-
public static synchronized List<EMSInfo> getAllEMSInfos(){
List<EMSInfo> list = new ArrayList<EMSInfo>();
@@ -301,9 +194,6 @@ public class ConfigurationManager extends DriverThread{
emsInfoCache.putAll(emsInfoMap);
}
-
-
- //
if(emsInfoCache.size() > 0){
Thread.sleep(30*60*1000);
}else{
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImpTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImpTest.java
index 9037bde..0041fa6 100644
--- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImpTest.java
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationImpTest.java
@@ -18,27 +18,142 @@ package org.onap.vfc.nfvo.emsdriver.configmgr;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
+import java.io.InputStream;
+import java.util.*;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jdom.Document;
+import org.jdom.Element;
import org.junit.Before;
import org.junit.Test;
+import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
import org.onap.vfc.nfvo.emsdriver.commons.model.EMSInfo;
-import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationImp;
-import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationManager;
+import org.onap.vfc.nfvo.emsdriver.commons.utils.StringUtil;
+import org.onap.vfc.nfvo.emsdriver.commons.utils.XmlUtil;
public class ConfigurationImpTest {
-
-
+ //normally an unit test should not log
+ protected static Log log = LogFactory.getLog(ConfigurationImpTest.class);
private ConfigurationManager configurationManager;
private ConfigurationImp configurationImp;
+
+ public static void readcfg(){
+ String path = Constant.SYS_CFG + "EMSInfo.xml";
+ File cfg = new File(path);
+ log.debug("start loading " + path);
+ if(!cfg.exists() || !cfg.isFile()){
+ log.debug("not exists " + path);
+ return;
+ }
+
+
+ InputStream is = null;
+ Map<String, EMSInfo> tmpcache = new HashMap<String, EMSInfo>();
+
+ try {
+ is = new FileInputStream(cfg);
+ Document doc = XmlUtil.getDocument(is);
+
+ Element root = doc.getRootElement();
+
+ @SuppressWarnings("unchecked")
+ List<Element> children = root.getChildren();
+
+ for(Iterator<Element> it = children.iterator(); it.hasNext();){
+ EMSInfo emsInfo = new EMSInfo();
+ Element child = it.next();
+ String name = child.getAttributeValue("name");
+ if(StringUtil.isBank(name)){
+ continue;
+ }
+ emsInfo.setName(name);
+
+// tmpcache.put(name, emsInfo);
+
+ @SuppressWarnings("unchecked")
+ List<Element> collectList = child.getChildren();
+ for(Element collect : collectList){
+
+ CollectVo collectVo = new CollectVo();
+
+ String type = collect.getAttributeValue("type");
+ if("alarm".equalsIgnoreCase(type)){
+ boolean iscollect = Boolean.parseBoolean(collect.getAttributeValue("iscollect"));
+ if(iscollect){
+ collectVo.setIscollect(iscollect);
+ }else{
+ continue;
+ }
+ collectVo.setType(type);
+ collectVo.setIP(collect.getChildText("ip"));
+ collectVo.setPort(collect.getChildText("port"));
+ collectVo.setUser(collect.getChildText("user"));
+ collectVo.setPassword(collect.getChildText("password"));
+ collectVo.setRead_timeout(collect.getChildText("readtimeout"));
+ }else{
+ String crontab = collect.getAttributeValue("crontab");
+ if(!StringUtil.isBank(type) && !StringUtil.isBank(crontab)){
+ collectVo.setType(type);
+ collectVo.setCrontab(crontab);
+ }else{
+ continue;
+ }
+ collectVo.setIP(collect.getChildText("ip"));
+ collectVo.setPort(collect.getChildText("port"));
+ collectVo.setUser(collect.getChildText("user"));
+ collectVo.setPassword(collect.getChildText("password"));
+ collectVo.setRemotepath(collect.getChildText("remotepath"));
+ collectVo.setMatch(collect.getChildText("match"));
+ collectVo.setPassive(collect.getChildText("passive"));
+ collectVo.setFtptype(collect.getChildText("ftptype"));
+ collectVo.setGranularity(collect.getChildText("granularity"));
+ }
+
+ emsInfo.putCollectMap(type, collectVo);
+ }
+ tmpcache.put(name, emsInfo);
+ }
+ ConfigurationManager.emsInfoCache.putAll(tmpcache);
+
+ File file = new File(ConfigurationManager.CONFIG_PROPERTIES_LOCATION);
+ if(!file.exists() || !file.isFile()){
+ log.error("cacheFilePath " + ConfigurationManager.CONFIG_PROPERTIES_LOCATION +" not exist or is not File");
+ return;
+ }
+ InputStream in = null;
+ try{
+ ConfigurationManager.properties = new Properties();
+ in = new FileInputStream(file);
+ ConfigurationManager.properties.load(in);
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ } catch (Exception e) {
+ log.error("load EMSInfo.xml is error "+StringUtil.getStackTrace(e));
+ }finally{
+ tmpcache.clear();
+ try {
+ if(is != null){
+ is.close();
+ is = null;
+ }
+ } catch (Exception e2) {
+ }
+ cfg = null;
+ }
+ }
+
+
@Before
public void setUp() throws IOException {
configurationImp = new ConfigurationImp();
configurationManager = new ConfigurationManager();
- configurationManager.readcfg();
+ readcfg();
}
@Test
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java
index 575d3be..ef6ccfb 100644
--- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/configmgr/ConfigurationManagerTest.java
@@ -35,7 +35,7 @@ public class ConfigurationManagerTest {
@Before
public void setUp() throws IOException {
configurationManager = new ConfigurationManager();
- configurationManager.readcfg();
+ ConfigurationImpTest.readcfg();
}
@Test
diff --git a/ems/microservice-standalone/.gitignore b/ems/microservice-standalone/.gitignore
new file mode 100644
index 0000000..e52f0ed
--- /dev/null
+++ b/ems/microservice-standalone/.gitignore
@@ -0,0 +1,3 @@
+.idea
+target
+emsdriver-standalone.iml