diff options
author | wangguirong <wangguirong@boco.com.cn> | 2017-09-27 12:19:41 +0800 |
---|---|---|
committer | wangguirong <wangguirong@boco.com.cn> | 2017-09-27 12:20:08 +0800 |
commit | 9bd010d5fc82f7fb5ee6cc6771f76fbca73ba735 (patch) | |
tree | 150194656fa700e932f78e6962e06de46bc7da6d | |
parent | c6bfa3a1cfa20c0a885408c0eef23525d98679d4 (diff) |
EMS Driver add new functions
Change-Id: I026918c5d7bff577fdca3f4fa0dbaffd5b27dd45
Issue-Id:VFC-461
Signed-off-by: wangguirong <wangguirong@boco.com.cn>
29 files changed, 1364 insertions, 273 deletions
diff --git a/ems/boco/conf/config.properties b/ems/boco/conf/config.properties new file mode 100644 index 0000000..7a946d0 --- /dev/null +++ b/ems/boco/conf/config.properties @@ -0,0 +1,39 @@ + +# Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +ftp_ip = 192.168.6.48 +ftp_port = 21 +ftp_user = gcp +ftp_password = gcp +ftp_remote_path = /opt/Gcp/ +ftp_passive = true +ftp_type = ftp + +# +msbAddress=10.74.205.123:80 +esr_ems_listUrl=/aai/v11/external-system/esr-ems-list +esr_emsUrl=/aai/v11/external-system/esr-ems-list/esr-ems/%s?depth=all +alarmUrl=/alarm + + +#north +event_api_url=http://127.0.0.1 +port=30000 +path=/vendor_event_listener +topic=/example_vnf +username=pill +password=will +level=debug diff --git a/ems/boco/conf/crontab.xml b/ems/boco/conf/crontab.xml new file mode 100644 index 0000000..0d7f591 --- /dev/null +++ b/ems/boco/conf/crontab.xml @@ -0,0 +1,32 @@ +<?xml version='1.0' encoding='GBK'?> +<!-- + + Copyright 2017 BOCO Corporation. CMCCTechnologiesCo.,Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +--> +<scheduler> + <crontab type ="ems-resource" crontab="0 0/15 * * * ?"> + <match>*</match> + <granularity>15</granularity> + </crontab> + <crontab type ="ems-performance" crontab=""> + <match>*</match> + <granularity>15</granularity> + </crontab> + <crontab type ="ems-alarm" iscollect = "false"> + <readtimeout>6</readtimeout>; + </crontab> +</scheduler>
\ No newline at end of file diff --git a/ems/boco/lib/VESLibrary.jar b/ems/boco/lib/VESLibrary.jar Binary files differnew file mode 100644 index 0000000..ef9de52 --- /dev/null +++ b/ems/boco/lib/VESLibrary.jar diff --git a/ems/boco/lib/dependencies-all.jar b/ems/boco/lib/dependencies-all.jar Binary files differnew file mode 100644 index 0000000..725a4be --- /dev/null +++ b/ems/boco/lib/dependencies-all.jar diff --git a/ems/boco/pom.xml b/ems/boco/pom.xml index 413cff0..91d4fbf 100644 --- a/ems/boco/pom.xml +++ b/ems/boco/pom.xml @@ -1,3 +1,4 @@ + <!-- Copyright (c) 2017, CMCC Technologies Co., Ltd. @@ -16,12 +17,7 @@ <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <groupId>org.onap.vfc.nfvo.driver.ems.ems</groupId> - <artifactId>ems-driver-boco-parent</artifactId> - <version>1.0.0-SNAPSHOT</version> - </parent> - + <groupId>org.onap.vfc.nfvo.driver.ems.ems</groupId> <modelVersion>4.0.0</modelVersion> <artifactId>boco-driver</artifactId> <version>1.0.0-SNAPSHOT</version> @@ -209,5 +205,20 @@ <artifactId>swagger-jersey2-jaxrs</artifactId> <version>${swagger.version}</version> </dependency> + <dependency> + <groupId>dependencies-all</groupId> + <artifactId>test</artifactId> + <version>3.0</version> + <scope>system</scope> + <systemPath>${basedir}/lib/dependencies-all.jar</systemPath> + </dependency> + + <dependency> + <groupId>VESLibrary</groupId> + <artifactId>test</artifactId> + <version>3.0</version> + <scope>system</scope> + <systemPath>${basedir}/lib/VESLibrary.jar</systemPath> + </dependency> </dependencies> </project> 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 e2fcf7d..e77db8b 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 @@ -28,6 +28,8 @@ import java.io.OutputStreamWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.Hashtable; import java.util.LinkedHashMap; import java.util.List; import java.util.Properties; @@ -45,12 +47,13 @@ import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant; import org.onap.vfc.nfvo.emsdriver.commons.ftp.AFtpRemoteFile; import org.onap.vfc.nfvo.emsdriver.commons.ftp.FTPInterface; import org.onap.vfc.nfvo.emsdriver.commons.ftp.FTPSrv; -import org.onap.vfc.nfvo.emsdriver.commons.ftp.SFTPSrv; import org.onap.vfc.nfvo.emsdriver.commons.model.CollectMsg; import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo; +import org.onap.vfc.nfvo.emsdriver.commons.utils.DateUtil; import org.onap.vfc.nfvo.emsdriver.commons.utils.Gunzip; import org.onap.vfc.nfvo.emsdriver.commons.utils.StringUtil; import org.onap.vfc.nfvo.emsdriver.commons.utils.UnZip; +import org.onap.vfc.nfvo.emsdriver.commons.utils.VarExprParser; import org.onap.vfc.nfvo.emsdriver.commons.utils.Zip; import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationImp; import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface; @@ -62,7 +65,8 @@ public class TaskThread implements Runnable{ public Log log = LogFactory.getLog(TaskThread.class); - private MessageChannel collectResultChannel; + private MessageChannel cmResultChannel; + private MessageChannel pmResultChannel; private CollectMsg data; @@ -75,9 +79,9 @@ public class TaskThread implements Runnable{ private SimpleDateFormat dateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private String csvpathAndFileName; - private String xmlPathAndFileName; - private int countNum = 0 ; +// private String csvpathAndFileName; +// private String xmlPathAndFileName; +// private int countNum = 0 ; public TaskThread(CollectMsg data) { this.data = data; @@ -89,8 +93,8 @@ public class TaskThread implements Runnable{ @Override public void run(){ - collectResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_CHANNEL_KEY); - + cmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_CHANNEL_KEY); + pmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_CHANNEL_KEY); try { collectMsgHandle(data); } catch (Exception e) { @@ -125,29 +129,11 @@ public class TaskThread implements Runnable{ continue; String nename = ma.group(1); boolean parseResult = false; - if("CM".equalsIgnoreCase(collectVo.getType())){ + if("ems-resource".equalsIgnoreCase(collectVo.getType())){ parseResult = processCMXml(tempfile, nename,"CM"); }else{ - parseResult = processPMCsv(tempfile, nename,"PM"); - - //createzipFile - String[] fileKeys = this.createZipFile(csvpathAndFileName,xmlPathAndFileName,nename); - //ftp store - Properties ftpPro = configurationInterface.getProperties(); - String ip = ftpPro.getProperty("ftp_ip"); - String port = ftpPro.getProperty("ftp_port"); - String ftp_user = ftpPro.getProperty("ftp_user"); - String ftp_password = ftpPro.getProperty("ftp_password"); - - String ftp_passive = ftpPro.getProperty("ftp_passive"); - String ftp_type = ftpPro.getProperty("ftp_type"); - String remoteFile = ftpPro.getProperty("ftp_remote_path"); - this.ftpStore(fileKeys,ip,port,ftp_user,ftp_password,ftp_passive,ftp_type,remoteFile); - //create Message - String message = this.createMessage(fileKeys[1], ftp_user, ftp_password, ip, port, countNum,nename); + parseResult = processPMCsv(tempfile); - //set message - this.setMessage(message); } if (parseResult){ @@ -159,23 +145,7 @@ public class TaskThread implements Runnable{ } } - public boolean processPMCsv(File tempfile, String nename,String type) { - - String csvpath = localPath+nename+"/"+type+"/"; - File csvpathfile = new File(csvpath); - if(!csvpathfile.exists()){ - csvpathfile.mkdirs(); - } - String csvFileName = nename +dateFormat.format(new Date())+ System.nanoTime(); - csvpathAndFileName = csvpath+csvFileName+".csv"; - BufferedOutputStream bos = null; - FileOutputStream fos = null; - try { - fos = new FileOutputStream(csvpathAndFileName,false); - bos = new BufferedOutputStream(fos, 10240); - } catch (FileNotFoundException e1) { - log.error("FileNotFoundException "+StringUtil.getStackTrace(e1)); - } + public boolean processPMCsv(File tempfile) { FileInputStream brs = null; InputStreamReader isr = null; @@ -203,7 +173,7 @@ public class TaskThread implements Runnable{ columnNames.add(name); } - xmlPathAndFileName = this.setColumnNames(nename, columnNames,type); +// xmlPathAndFileName = this.setColumnNames(nename, columnNames,type); String valueLine = ""; List<String> valuelist = new ArrayList<String>(); @@ -212,15 +182,21 @@ public class TaskThread implements Runnable{ if (valueLine.trim().equals("")) { continue; } - countNum ++; +// countNum ++; String [] values = valueLine.split("\\|",-1); valuelist.addAll(commonValues); for(String value : values){ valuelist.add(value); } - this.appendLine(valuelist, bos); - +// this.appendLine(valuelist, bos); + //resultMap + HashMap<String,String> resultMap = this.resultMap(columnNames,valuelist); + try { + pmResultChannel.put(resultMap); + } catch (InterruptedException e) { + log.error("collectResultChannel.put(resultMap) error ",e); + } valuelist.clear(); } } catch (IOException e) { @@ -234,12 +210,7 @@ public class TaskThread implements Runnable{ isr.close(); if (brs != null) brs.close(); - if(bos != null){ - bos.close(); - } - if(fos != null){ - fos.close(); - } + } catch (Exception e){ log.error(e); } @@ -248,6 +219,18 @@ public class TaskThread implements Runnable{ } + private HashMap<String,String> resultMap(List<String> columnNames, List<String> valuelist) { + + HashMap<String,String> resultMap = new HashMap<String,String>(); + if(columnNames.size() == valuelist.size()){ + for(int i =0;i<columnNames.size();i++){ + resultMap.put(columnNames.get(i), valuelist.get(i)); + } + } + + return resultMap; + + } private boolean processCMXml(File tempfile, String nename, String type) { String csvpath = localPath+nename+"/"+type+"/"; @@ -415,7 +398,7 @@ public class TaskThread implements Runnable{ private void setMessage(String message) { try { - collectResultChannel.put(message); + cmResultChannel.put(message); } catch (Exception e) { log.error("collectResultChannel.put(message) is error "+StringUtil.getStackTrace(e)); } @@ -482,12 +465,7 @@ public class TaskThread implements Runnable{ FTPInterface ftpClient; - if("ftp".equalsIgnoreCase(ftp_type)){ - ftpClient = new FTPSrv(); - }else{ - ftpClient = new SFTPSrv(); - } - + ftpClient = new FTPSrv(); //login try { ftpClient.login(ip, Integer.parseInt(port), ftp_user, ftp_password, "GBK", Boolean.parseBoolean(ftp_passive), 5*60*1000); @@ -495,7 +473,7 @@ public class TaskThread implements Runnable{ log.error("login fail,ip=["+ip+"] port=["+port+"] user=["+ftp_user+"]pwd=["+ftp_password+"]"+StringUtil.getStackTrace(e)); return; } - ftpClient.store(zipFilePath, remoteFile); +// ftpClient.store(zipFilePath, remoteFile); log.debug("store ["+zipFilePath+"]to["+remoteFile+"]"); FileUtils.deleteQuietly(new File(zipFilePath)); @@ -601,19 +579,19 @@ public class TaskThread implements Runnable{ } } - private void appendLine(List<String> values,BufferedOutputStream bos) { - StringBuilder lineDatas = new StringBuilder(); - - for (String value : values) { - lineDatas.append(value).append("|"); - } - try { - bos.write(lineDatas.toString().getBytes()); - bos.write("\n".getBytes()); - } catch (IOException e) { - log.error("appendLine error "+StringUtil.getStackTrace(e)); - } - } +// private void appendLine(List<String> values,BufferedOutputStream bos) { +// StringBuilder lineDatas = new StringBuilder(); +// +// for (String value : values) { +// lineDatas.append(value).append("|"); +// } +// try { +// bos.write(lineDatas.toString().getBytes()); +// bos.write("\n".getBytes()); +// } catch (IOException e) { +// log.error("appendLine error "+StringUtil.getStackTrace(e)); +// } +// } public List<File> decompressed(String fileName){ List<File> filelist = new ArrayList<File>(); @@ -683,13 +661,7 @@ public class TaskThread implements Runnable{ //isPassiveMode String passivemode = collectVo.getPassive(); - String ftpType = collectVo.getFtptype(); - FTPInterface ftpClient = null; - if("ftp".equalsIgnoreCase(ftpType)){ - ftpClient = new FTPSrv(); - }else{ - ftpClient = new SFTPSrv(); - } + FTPInterface ftpClient = new FTPSrv(); //login try { @@ -701,44 +673,152 @@ public class TaskThread implements Runnable{ //download String dir = collectVo.getRemotepath(); - boolean cdsucess = ftpClient.chdir(dir); - if(cdsucess){ - AFtpRemoteFile[] remoteFiles = (AFtpRemoteFile[]) ftpClient.list(); + List<String> searchExprList = new ArrayList<String>(); + String []FPath = dir.split(";"); + for(int i=0;i<FPath.length;i++){ + int oldSize = searchExprList.size(); + String conpath = FPath[i]; + Hashtable<String,String> varMap = new Hashtable<String,String>(); + long[] d = DateUtil.getScanScope(new Date(), 900); + searchExprList.add(VarExprParser.replaceVar(conpath,d[0],d[1])); - for(AFtpRemoteFile ftpRemoteFile: remoteFiles){ - if(!new File(localPath).exists()){ - try { - new File(localPath).mkdir(); - } catch (Exception e) { - log.error("create localPath is fail localPath="+localPath+" "+StringUtil.getStackTrace(e)); - } - } - - if(!new File(localPath).exists()){ - new File(localPath).mkdirs(); - } + varMap.clear(); + varMap = null; + log.info("["+conpath+"],result["+(searchExprList.size()-oldSize)+"] path"); + conpath = null; + } + searchExprList =getLocalPathNoRegular(searchExprList); + List<AFtpRemoteFile> remoteFiles = new ArrayList<AFtpRemoteFile>(); + for(String expr :searchExprList){ + String keys[] = parseExprKeys(expr); + String ftpRegular = keys[1]; + String ftpDir = keys[0]; + + boolean cdsucess = ftpClient.chdir(expr); + if(cdsucess){ + AFtpRemoteFile[] arf = (AFtpRemoteFile[]) ftpClient.list(); + log.info(" list ["+ftpDir+"],result["+(arf==null?"null":arf.length)+"] files"); + //filter - String localFileName = localPath + ftpRemoteFile.getFileName(); - File loaclFile = new File(localFileName); - if (loaclFile.exists()) { - loaclFile.delete(); - } + rfileFilter(remoteFiles,arf,ftpRegular); - boolean flag = ftpClient.downloadFile(ftpRemoteFile.getAbsFileName(), localFileName); + keys = null; + ftpRegular=ftpDir = null; - if(flag){ - fileList.add(localFileName); - }else{ - log.error("download file fail fileName="+ftpRemoteFile.getAbsFileName()); + for(AFtpRemoteFile ftpRemoteFile: remoteFiles){ + if(!new File(localPath).exists()){ + try { + new File(localPath).mkdir(); + } catch (Exception e) { + log.error("create localPath is fail localPath="+localPath+" "+StringUtil.getStackTrace(e)); + } + } + + if(!new File(localPath).exists()){ + new File(localPath).mkdirs(); + } + + String localFileName = localPath + ftpRemoteFile.getFileName(); + File loaclFile = new File(localFileName); + if (loaclFile.exists()) { + loaclFile.delete(); + } + + boolean flag = ftpClient.downloadFile(ftpRemoteFile.getAbsFileName(), localFileName); + + if(flag){ + fileList.add(localFileName); + }else{ + log.error("download file fail fileName="+ftpRemoteFile.getAbsFileName()); + } } + + }else{ + log.error("chdir is faill dir =["+dir+"]"); } - - }else{ - log.error("chdir is faill dir =["+dir+"]"); } + + return fileList; } + private void rfileFilter(List<AFtpRemoteFile> fileContainer, AFtpRemoteFile[] arfs, String ftpRegular) { + if (ftpRegular!=null && ftpRegular.length()>0) { + Pattern pattern = null; + try { + pattern = Pattern.compile(ftpRegular, Pattern.CASE_INSENSITIVE); + } catch (Exception e) { + log.info("["+ftpRegular+"]Pattern.compile exception:"+e.getMessage()); + } + int hisSize = fileContainer.size(); + for (int j=0; arfs!=null&&j<arfs.length; j++) { + String fileName = parseFileName(arfs[j].getFileName()); + Matcher matcher = pattern.matcher(fileName); + if (matcher.find()) + fileContainer.add(arfs[j]); + } + log.info("["+ftpRegular+"]filter["+(fileContainer.size()-hisSize)+"]filse"); + pattern = null; + }else { + for (int j=0; arfs!=null&&j<arfs.length; j++) + fileContainer.add(arfs[j]); + } + + } + + private String parseFileName(String fileName) { + int idx = fileName.lastIndexOf("/"); + if (idx == -1) + return fileName; + return fileName.substring(idx+1, fileName.length()); + } + + private String[] parseExprKeys(String source) { + + if(source.indexOf(";") > -1){ + source = source.substring(0, source.indexOf(";")); + } + if (source.endsWith("/")) + return new String[]{source,""}; + + int idx = source.lastIndexOf("/"); + String[] dirkeys = new String[2]; + dirkeys[0] = source.substring(0, idx+1); + dirkeys[1] = source.substring(idx+1, source.length()); + return dirkeys; + } + + public List<String> getLocalPathNoRegular(List<String> searchExprList){ + boolean isregular = false; + List<String> regularList = new ArrayList<String>(); + for(String regular : searchExprList){ + Pattern lpattern = null; + try{ + lpattern = Pattern.compile("(.*/)<([^/]+)>(/.*)"); + }catch (Exception e) { + log.info("["+regular+"]compile fails:"+e.getMessage()); + } + + Matcher matcher = lpattern.matcher(regular); + if(matcher.find()){ + isregular = true; + String parpath = matcher.group(1); + File[] arryFile = new File(parpath).listFiles(); + for(File file :arryFile){ + if(file.isDirectory()&&file.getName().matches(matcher.group(2))){ + regularList.add(matcher.group(1)+file.getName()+matcher.group(3)); + } + } + }else{ + regularList.add(regular); + } + + } + if(isregular==true){ + getLocalPathNoRegular(regularList); + } + return regularList; + } }
\ No newline at end of file diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java index d03fd4b..3d74045 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java @@ -61,16 +61,18 @@ public class AlarmTaskThread extends Thread{ } public void run() { - alarmChannel = MessageChannelFactory.getMessageChannel(Constant.ALARM_CHANNEL_KEY); + alarmChannel = MessageChannelFactory.getMessageChannel(Constant.RESULT_CHANNEL_KEY); try { this.init(); while(!this.isStop){ String body; try { body = this.receive(); - String alarm120 = this.build120Alarm(body); - - this.send120Alarm(alarm120); + try { + alarmChannel.put(body); + } catch (InterruptedException e) { + log.error(StringUtil.getStackTrace(e)); + } } catch (Exception e) { reinit(); } @@ -80,37 +82,7 @@ public class AlarmTaskThread extends Thread{ } } - private void send120Alarm(String alarm120) { - - try { - alarmChannel.put(alarm120); - } catch (InterruptedException e) { - log.error(StringUtil.getStackTrace(e)); - } - } - - public String build120Alarm(String body) { - StringBuilder content = new StringBuilder( - "<?xml version='1.0' encoding='iso-8859-1'?>\n") - .append("<WholeMsg MsgMark='120' Priority='2' FieldNum='5'><FM_ALARM_MSG>\n"); - - JSONObject reagobj = JSONObject.parseObject(body); - - Set<String> keys = reagobj.keySet(); - - for (String key : keys) { - - String value = reagobj.get(key).toString(); - content.append("<").append(key).append(">"); - content.append(value); - content.append("</").append(key).append(">\n"); - } - content.append("</FM_ALARM_MSG></WholeMsg>"); - - return content.toString(); - - } public String receive() throws Exception { @@ -150,6 +122,10 @@ public class AlarmTaskThread extends Thread{ log.debug("received alarm message"); retString = msg.getBody(); } + + if(retString == null){ + Thread.sleep(100); + } } return retString; } diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/constant/Constant.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/constant/Constant.java index c6edaf1..6c08879 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/constant/Constant.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/constant/Constant.java @@ -25,16 +25,16 @@ public class Constant { public static String SYS_DATA = SYS_HOME + "data" + File.separator; public static String SYS_DATA_TEMP = SYS_DATA + File.separator + "temp" + File.separator; public static String SYS_DATA_RESULT = SYS_DATA + File.separator + "RESULT" + File.separator; - public static String COLLECT_TYPE_CM = "cm"; - public static String COLLECT_TYPE_PM = "pm"; - public static String COLLECT_TYPE_ALARM = "alarm"; + public static String COLLECT_TYPE_CM = "ems-resource"; + public static String COLLECT_TYPE_PM = "ems-performance"; + public static String COLLECT_TYPE_ALARM = "ems-alarm"; public static String ENCODING_UTF8 = "UTF-8"; public static String ENCODING_GBK = "GBK"; public static final String COLLECT_CHANNEL_KEY = "COLLECT_CHANNEL_KEY"; public static final String COLLECT_RESULT_CHANNEL_KEY = "COLLECT_RESULT_CHANNEL_KEY"; - public static final String ALARM_CHANNEL_KEY = "ALARM_CHANNEL_KEY"; + public static final String RESULT_CHANNEL_KEY = "RESULT_CHANNEL_KEY"; public static final String MSBAPIROOTDOMAIN = "/api/microservices/v1/services"; diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java index 336c5a3..5f7569d 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java @@ -16,8 +16,6 @@ package org.onap.vfc.nfvo.emsdriver.commons.ftp; import java.io.IOException; -import java.io.InputStream; -import java.util.Date; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; @@ -34,9 +32,6 @@ public class AFtpRemoteFile implements RemoteFile{ this.currDir = currDir; } - public long getSize() { - return ftpFile.getSize(); - } public String getFileName() { return ftpFile.getName(); @@ -45,37 +40,4 @@ public class AFtpRemoteFile implements RemoteFile{ public String getAbsFileName() { return currDir.concat(getFileName()); } - - public boolean isDirectory() { - return ftpFile.isDirectory(); - } - public boolean isFile() { - return ftpFile.isFile(); - } - - public String getOwner() { - return ftpFile.getUser(); - } - - public Date getModifyDate() { - return ftpFile.getTimestamp().getTime(); - } - public boolean renameTo(String newName) throws IOException { - return ftpClient.rename( - currDir.concat(getFileName()), newName); - } - public boolean remove() throws IOException { - return ftpClient.deleteFile( - currDir.concat(getFileName())); - } - - public InputStream getInputStream() throws IOException { - return ftpClient.retrieveFileStream(this.getAbsFileName()); - } - - public void release() { - ftpClient = null; - ftpFile = null; - currDir = null; - } }
\ No newline at end of file diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPInterface.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPInterface.java index 6b76fbf..ee9c3fb 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPInterface.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPInterface.java @@ -38,8 +38,8 @@ public interface FTPInterface { public RemoteFile[] list(); - public RemoteFile[] list(String dir); +// public RemoteFile[] list(String dir); - public boolean store(String localFile,String remoteFile); +// public boolean store(String localFile,String remoteFile); } 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 514ed60..d008a43 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 @@ -53,7 +53,7 @@ public class FTPSrv implements FTPInterface{ ftpClientConfig.setServerTimeZoneId(TimeZone.getDefault().getID()); this.ftpClient.setControlEncoding("GBK"); this.ftpClient.configure(ftpClientConfig); - ftpClient.setParserFactory(new ExtendsDefaultFTPFileEntryParserFactory()); +// ftpClient.setParserFactory(new ExtendsDefaultFTPFileEntryParserFactory()); if(encode!=null && encode.length()>0){ ftpClient.setControlEncoding(encode); @@ -163,37 +163,31 @@ public class FTPSrv implements FTPInterface{ return ftpRemoteFiles; } - - public RemoteFile[] list(String dir) { - return null; - } - - - 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; - } +// 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/model/CrontabVo.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/model/CrontabVo.java new file mode 100644 index 0000000..e76b039 --- /dev/null +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/model/CrontabVo.java @@ -0,0 +1,121 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.commons.model; + +/** + * @author boco + * + */ +public class CrontabVo { + + private String type; + + private String crontab; + private String match; + private String granularity; + + private boolean iscollect = false; + + private String read_timeout; + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the crontab + */ + public String getCrontab() { + return crontab; + } + + /** + * @param crontab the crontab to set + */ + public void setCrontab(String crontab) { + this.crontab = crontab; + } + + /** + * @return the match + */ + public String getMatch() { + return match; + } + + /** + * @param match the match to set + */ + public void setMatch(String match) { + this.match = match; + } + + /** + * @return the granularity + */ + public String getGranularity() { + return granularity; + } + + /** + * @param granularity the granularity to set + */ + public void setGranularity(String granularity) { + this.granularity = granularity; + } + + /** + * @return the iscollect + */ + public boolean isIscollect() { + return iscollect; + } + + /** + * @param iscollect the iscollect to set + */ + public void setIscollect(boolean iscollect) { + this.iscollect = iscollect; + } + + /** + * @return the read_timeout + */ + public String getRead_timeout() { + return read_timeout; + } + + /** + * @param read_timeout the read_timeout to set + */ + public void setRead_timeout(String read_timeout) { + this.read_timeout = read_timeout; + } + + + + +} diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/model/EMSInfo.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/model/EMSInfo.java index c0a4618..1a2b5d4 100644 --- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/model/EMSInfo.java +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/model/EMSInfo.java @@ -22,6 +22,7 @@ public class EMSInfo { private String name; + private Map<String,CollectVo> collectMap = new HashMap<String,CollectVo>(); /** @@ -39,8 +40,7 @@ public class EMSInfo { } public CollectVo getCollectVoByType(String type){ - CollectVo collectVo = null; - collectVo = this.collectMap.get(type); + CollectVo collectVo = this.collectMap.get(type); return collectVo; } diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java new file mode 100644 index 0000000..c0fddad --- /dev/null +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/DateUtil.java @@ -0,0 +1,60 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.commons.utils; + +import java.util.Calendar; +import java.util.Date; + +public class DateUtil { + + + public static long[] getScanScope(Date fireTime, long collectPeriod) { + Calendar fire = Calendar.getInstance(); + long start = 0L; + long end = 0L; + fire.setTime(fireTime); + fire.set(Calendar.SECOND,0); + fire.set(Calendar.MILLISECOND, 0); + + if (collectPeriod < 3600) {//minute + long minite = fire.get(Calendar.MINUTE); + long collectMinite = (int)collectPeriod/60; + long s = minite%collectMinite; + end = fire.getTimeInMillis() - s*60*1000; + start = end - collectPeriod * 1000; + }else if (collectPeriod == 3600) { + fire.set(Calendar.MINUTE, 0); + end = fire.getTimeInMillis(); + start = end - collectPeriod * 1000; + }else if (collectPeriod == 24*60*60){ //day + fire.set(Calendar.HOUR_OF_DAY, 0); + fire.set(Calendar.MINUTE, 0); + end = fire.getTimeInMillis(); + start = end - collectPeriod * 1000; + }else{ + + if (collectPeriod>0) { + end = fire.getTimeInMillis()-(fire.getTimeInMillis()+8*60*60*1000)%(collectPeriod*1000); + }else { + return null; + } + start = end - collectPeriod * 1000; + } + + return new long[] {start,end}; + } + +} diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java new file mode 100644 index 0000000..309a856 --- /dev/null +++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/VarExprParser.java @@ -0,0 +1,137 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.commons.utils; + +import java.text.SimpleDateFormat; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Calendar; + +final public class VarExprParser { + private static Log log = LogFactory.getFactory().getInstance(VarExprParser.class); + private static Pattern varPattern = Pattern.compile("(\\$\\{([^\\}]+)\\})", + Pattern.CASE_INSENSITIVE); + + final static public String replaceVar(String str,long scan_start_time,long scan_stop_time) { + if (str.indexOf("${") == -1) + return str; + + // 支æŒåŽŸç³»ç»Ÿå˜é‡ + str = str.replace("${s_year}", "${SCAN_START_TIME,yyyy}"); + str = str.replace("${s_mon}", "${SCAN_START_TIME,MM}"); + str = str.replace("${s_day}", "${SCAN_START_TIME,dd}"); + str = str.replace("${s_hour}", "${SCAN_START_TIME,HH}"); + str = str.replace("${s_min}", "${SCAN_START_TIME,mm}"); + str = str.replace("${e_year}", "${SCAN_STOP_TIME,yyyy}"); + str = str.replace("${e_mon}", "${SCAN_STOP_TIME,MM}"); + str = str.replace("${e_day}", "${SCAN_STOP_TIME,dd}"); + str = str.replace("${e_hour}", "${SCAN_STOP_TIME,HH}"); + str = str.replace("${e_min}", "${SCAN_STOP_TIME,mm}"); + + String expr = null, varName = null, value = null; + Matcher matcher = varPattern.matcher(str); + while (matcher.find()) { + value = null; + expr = matcher.group(1); + varName = matcher.group(2); + if (expr.indexOf("${SCAN_START_TIME") != -1) { + value = getTime(scan_start_time,varName,"yyyy-MM-dd HH:mm:ss"); + } else if (expr.indexOf("${SCAN_STOP_TIME") != -1) { + value = getTime(scan_stop_time,varName,"yyyy-MM-dd HH:mm:ss"); + } + if (value == null) { + log.warn(" expr [" + str + "] var[" + + expr + "]is fail"); + continue; + } + str = str.replace(expr, value); + } + expr = value = null; + matcher = null; + return str; + } + + private static String getTime(long time,String value,String defaultParam){ + String timeStr = null; + String formatStr = null; + String increaseTime = null; + if (value.indexOf(",") == -1){ + formatStr = defaultParam; + timeStr = value; + }else{ + timeStr = value.split(",")[0]; + formatStr = value.split(",")[1]; + } + + if(timeStr.indexOf("+")==-1&&timeStr.indexOf("-")==-1){ + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr, Locale.ENGLISH); + return simpleDateFormat.format(time); + }else{ + if(timeStr.indexOf("+")!=-1){ + increaseTime = timeStr.substring(timeStr.indexOf("+")+1, timeStr.length()-1); + } + if(timeStr.indexOf("-")!=-1){ + increaseTime = timeStr.substring(timeStr.indexOf("-"), timeStr.length()-1); + } + if(timeStr.toLowerCase().endsWith("h")){ + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(time); + cal.add(Calendar.HOUR,Integer.parseInt(increaseTime)); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr, Locale.ENGLISH); + return simpleDateFormat.format(cal.getTimeInMillis()); + }else if(timeStr.toLowerCase().endsWith("m")){ + Calendar cal = Calendar.getInstance(); + cal.setTimeInMillis(time); + cal.add(Calendar.MINUTE,Integer.parseInt(increaseTime)); + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr, Locale.ENGLISH); + return simpleDateFormat.format(cal.getTimeInMillis()); + } + } + return null; + } + /** + * 仅支æŒè¯¥ä¸¤ä¸ªå˜é‡æ›¿æ¢ çœå¾—æ£åˆ™åŒ¹é…æ…¢ + * @param result + * @param scan_start_time + * @param scan_stop_time + * @return + */ + public static String replaceTimeVar(String result, + String scan_start_time, String scan_stop_time){ + + boolean isReplace = false; + if(result.indexOf("${SCAN_ST") != -1){ + isReplace = true; + } + if(isReplace){ + if(result.indexOf("${SCAN_START_TIME}") != -1){ + + result = StringUtils.replace(result, "${SCAN_START_TIME}", scan_start_time); + } + if(result.indexOf("${SCAN_STOP_TIME") != -1){ + + result = StringUtils.replace(result, "${SCAN_STOP_TIME}", scan_stop_time); + } + } + return result; + } +} 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 8e9e0bf..b7346b5 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,38 +26,145 @@ import java.util.Map; import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.jdom.Document; import org.jdom.Element; 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.CrontabVo; import org.onap.vfc.nfvo.emsdriver.commons.model.EMSInfo; import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread; import org.onap.vfc.nfvo.emsdriver.commons.utils.StringUtil; import org.onap.vfc.nfvo.emsdriver.commons.utils.XmlUtil; +import org.onap.vfc.nfvo.emsdriver.northbound.client.HttpClientUtil; +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); /** * ESM Cache */ private 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 ftpconfig = Constant.SYS_CFG + "ftpconfig.properties"; + private final static String config = Constant.SYS_CFG + "config.properties"; @Override - @SuppressWarnings("unchecked") public void dispose() { + + //this.log.debug("start loading " + cacheFilePath); + 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); + Map<String, CrontabVo> emsMap = readCorntab(); + + emsCrontab.putAll(emsMap); + + // + new ReceiveSource().start(); + }catch(Exception e) { + log.error("read ["+file.getAbsolutePath()+"]Exception :",e); + }finally { + if(in != null) { + try { + in.close(); + } catch (Exception e) { + } + } + } + } + + private Map<String, CrontabVo> readCorntab() { + String path = Constant.SYS_CFG + "crontab.xml"; + File cfg = new File(path); + log.debug("start loading " + path); + if(!cfg.exists() || !cfg.isFile()){ + log.debug("not exists " + path); + return null; + } + + InputStream is = null; + Map<String, CrontabVo> tmpcache = new HashMap<String, CrontabVo>(); + + 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();){ + CrontabVo crontabVo = new CrontabVo(); + Element child = it.next(); + String type = child.getAttributeValue("type"); + if(StringUtil.isBank(type)){ + continue; + } + crontabVo.setType(type); + if("ems-alarm".equalsIgnoreCase(type)){ + boolean iscollect = Boolean.parseBoolean(child.getAttributeValue("iscollect")); + if(iscollect){ + crontabVo.setIscollect(iscollect); + }else{ + continue; + } + + crontabVo.setRead_timeout(child.getChildText("readtimeout")); + }else{ + String crontab = child.getAttributeValue("crontab"); + if(!StringUtil.isBank(type) && !StringUtil.isBank(crontab)){ + crontabVo.setCrontab(crontab); + }else{ + continue; + } + crontabVo.setMatch(child.getChildText("match")); + crontabVo.setGranularity(child.getChildText("granularity")); + } + tmpcache.put(type, crontabVo); + } + + } catch (Exception e) { + log.error("load crontab.xml is error "+StringUtil.getStackTrace(e)); + }finally{ + tmpcache.clear(); + try { + if(is != null){ + is.close(); + is = null; + } + } catch (Exception e2) { + } + cfg = null; + } + return tmpcache; + } + + + public void readcfg(){ String path = Constant.SYS_CFG + "EMSInfo.xml"; File cfg = new File(path); - this.log.debug("start loading " + path); + log.debug("start loading " + path); if(!cfg.exists() || !cfg.isFile()){ - this.log.debug("not exists " + path); + log.debug("not exists " + path); return; } - + + InputStream is = null; Map<String, EMSInfo> tmpcache = new HashMap<String, EMSInfo>(); @@ -67,6 +174,7 @@ public class ConfigurationManager extends DriverThread{ Element root = doc.getRootElement(); + @SuppressWarnings("unchecked") List<Element> children = root.getChildren(); for(Iterator<Element> it = children.iterator();it.hasNext();){ @@ -78,8 +186,9 @@ public class ConfigurationManager extends DriverThread{ } emsInfo.setName(name); - tmpcache.put(name, emsInfo); +// tmpcache.put(name, emsInfo); + @SuppressWarnings("unchecked") List<Element> collectList = child.getChildren(); for(Element collect : collectList){ @@ -124,6 +233,19 @@ public class ConfigurationManager extends DriverThread{ } 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{ @@ -137,32 +259,9 @@ public class ConfigurationManager extends DriverThread{ } cfg = null; } - - - //this.log.debug("start loading " + cacheFilePath); - File file = new File(ftpconfig); - if(!file.exists() || !file.isFile()){ - this.log.error("cacheFilePath " + ftpconfig+"not exist or is not File"); - return; - } - InputStream in = null; - try{ - properties = new Properties(); - in = new FileInputStream(file); - properties.load(in); - - }catch(Exception e) { - log.error("read ["+file.getAbsolutePath()+"]Exception :",e); - }finally { - if(in != null) { - try { - in.close(); - } catch (Exception e) { - } - } - } } + public static synchronized List<EMSInfo> getAllEMSInfos(){ List<EMSInfo> list = new ArrayList<EMSInfo>(); for(EMSInfo emsinfo :emsInfoCache.values()){ @@ -180,5 +279,141 @@ public class ConfigurationManager extends DriverThread{ return properties; } + class ReceiveSource extends Thread{ + long timeStamp = System.currentTimeMillis(); + + public void run() { + while(true){ + + try { + if(System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE){ + timeStamp = System.currentTimeMillis(); + log.debug("ReceiveSource run"); + } + //get emsId list + List<String> emsIds = this.getEmsIdList(); + if(emsIds.size() > 0){ + emsIdList.clear(); + emsIdList.addAll(emsIds); + } + + for(String emsId : emsIdList){ + //get emsInfo by emsId + Map<String, EMSInfo> emsInfoMap = this.getEmsInfo(emsId); + + emsInfoCache.putAll(emsInfoMap); + } + + + // + if(emsInfoCache.size() > 0){ + Thread.sleep(5*60*1000); + }else{ + Thread.sleep(60*1000); + } + } catch (Exception e) { + log.error("ReceiveSource exception",e); + } + } + } + private Map<String, EMSInfo> getEmsInfo(String emsId) { + Map<String, EMSInfo> tmpcache = new ConcurrentHashMap<String, EMSInfo>(); + String msbAddress = properties.getProperty("msbAddress"); + String emstUrl = properties.getProperty("esr_emsUrl"); + //set emsId to url + String.format(emstUrl, emsId); + String getemstUrl = "http://"+msbAddress+emstUrl; + String emsResult = HttpClientUtil.doGet(getemstUrl, Constant.ENCODING_UTF8); + log.debug(getemstUrl+" result="+emsResult); + JSONObject reagobj = JSONObject.parseObject(emsResult); + + JSONObject esr_system_info_list = reagobj.getJSONObject("esr-system-info-list"); + JSONArray esr_system_info = esr_system_info_list.getJSONArray("esr-system-info"); + Iterator<Object> it = esr_system_info.iterator(); + EMSInfo emsInfo = new EMSInfo(); + emsInfo.setName(emsId); + tmpcache.put(emsId, emsInfo); + while(it.hasNext()){ + Object obj = it.next(); + JSONObject collect = (JSONObject)obj; + String system_type = (String)collect.get("system-type"); + CollectVo collectVo = new CollectVo(); + if("ems-resource".equalsIgnoreCase(system_type)){ + CrontabVo crontabVo = emsCrontab.get(system_type); + if(crontabVo != null){ + collectVo.setType(system_type); + collectVo.setCrontab(crontabVo.getCrontab()); + collectVo.setIP(collect.getString("ip-address")); + collectVo.setPort(collect.getString("port")); + collectVo.setUser(collect.getString("user-name")); + collectVo.setPassword(collect.getString("password")); + + collectVo.setRemotepath(collect.getString("remote-path")); + collectVo.setMatch(crontabVo.getMatch()); + collectVo.setPassive(collect.getString("passive")); + collectVo.setGranularity(crontabVo.getGranularity()); + } + + + }else if("ems-performance".equalsIgnoreCase(system_type)){ + CrontabVo crontabVo = emsCrontab.get(system_type); + if(crontabVo != null){ + collectVo.setType(system_type); + collectVo.setCrontab(crontabVo.getCrontab()); + collectVo.setIP(collect.getString("ip-address")); + collectVo.setPort(collect.getString("port")); + collectVo.setUser(collect.getString("user-name")); + collectVo.setPassword(collect.getString("password")); + + collectVo.setRemotepath(collect.getString("remote-path")); + collectVo.setMatch(crontabVo.getMatch()); + collectVo.setPassive(collect.getString("passive")); + collectVo.setGranularity(crontabVo.getGranularity()); + } + }else if("ems-alarm".equalsIgnoreCase(system_type)){ + CrontabVo crontabVo = emsCrontab.get(system_type); + if(crontabVo != null){ + collectVo.setIscollect(crontabVo.isIscollect()); + collectVo.setType(system_type); + collectVo.setIP(collect.getString("ip-address")); + collectVo.setPort(collect.getString("port")); + collectVo.setUser(collect.getString("user-name")); + collectVo.setPassword(collect.getString("password")); + collectVo.setRead_timeout(crontabVo.getRead_timeout()); + }else{ + log.error("emsCrontab.get(system_type) result crontabVo is null" ); + } + + + }else{ + log.error("ems system-type ="+system_type+" "); + } + + emsInfo.putCollectMap(system_type, collectVo); + } + return tmpcache; + } + + private List<String> getEmsIdList() { + List<String> emsIds = new ArrayList<String>(); + //http + String msbAddress = properties.getProperty("msbAddress"); + String url = properties.getProperty("esr_ems_listUrl"); + String getemsListUrl = "http://"+msbAddress+url; + + String result = HttpClientUtil.doGet(getemsListUrl, Constant.ENCODING_UTF8); + log.debug(getemsListUrl+" result="+result); + JSONObject reagobj = JSONObject.parseObject(result); + JSONArray esr_emsIds = reagobj.getJSONArray("esr-ems"); + Iterator<Object> it = esr_emsIds.iterator(); + while(it.hasNext()){ + Object obj = it.next(); + JSONObject emsId = (JSONObject)obj; + String emsIdStr = (String)emsId.get("ems-id"); + emsIds.add(emsIdStr); + } + return emsIds; + } + } } 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 79220ec..83a785f 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 @@ -15,31 +15,106 @@ */ package org.onap.vfc.nfvo.emsdriver.northbound.client; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Map; import java.util.Properties; +import javax.json.Json; +import javax.json.JsonBuilderFactory; +import javax.json.JsonObject; +import javax.json.JsonObjectBuilder; + +import org.apache.log4j.Level; import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant; import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread; import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationInterface; import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannel; import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannelFactory; +import com.alibaba.fastjson.JSONObject; + +import evel_javalibrary.att.com.AgentMain; +import evel_javalibrary.att.com.EvelFault; +import evel_javalibrary.att.com.EvelFault.EVEL_SEVERITIES; +import evel_javalibrary.att.com.EvelFault.EVEL_SOURCE_TYPES; +import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES; +import evel_javalibrary.att.com.EvelHeader.PRIORITIES; +import evel_javalibrary.att.com.EvelHeader; +import evel_javalibrary.att.com.EvelScalingMeasurement; + public class NorthMessageMgr extends DriverThread{ - private MessageChannel alarmChannel = MessageChannelFactory.getMessageChannel(Constant.ALARM_CHANNEL_KEY); + private MessageChannel alarmChannel = MessageChannelFactory.getMessageChannel(Constant.RESULT_CHANNEL_KEY); + private MessageChannel collectChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_CHANNEL_KEY); private MessageChannel collectResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_CHANNEL_KEY); private ConfigurationInterface configurationInterface ; private boolean threadStop = false; + private Level level = Level.DEBUG; @Override public void dispose() { + Properties properties = configurationInterface.getProperties(); + String event_api_url = properties.getProperty("event_api_url"); + String port = properties.getProperty("port"); + String path = properties.getProperty("path"); + String topic = properties.getProperty("topic"); + String username = properties.getProperty("username"); + String password = properties.getProperty("password"); + String levelStr = properties.getProperty("level"); + if("debug".equals(levelStr)){ + level = Level.DEBUG; + }else{ + level = Level.INFO; + } + + //login north + try{ + AgentMain.evel_initialize(event_api_url, Integer.parseInt(port), + path,topic, + username, + password, + level); + } catch( Exception e ){ + log.error("AgentMain.evel_initialize fail ",e); + } + + new HeatBeatTread().start(); // new AlarmMessageRecv().start(); new ResultMessageRecv().start(); + + new CollectMessageRecv().start(); } + class HeatBeatTread extends Thread{ + + public void run() { + + while(!threadStop){ + + try { + EvelHeader header = EvelHeader.evel_new_heartbeat("Hearbeat_EMS","EMS-driver"); + header.evel_nfnamingcode_set("EMS-driver"); + header.evel_nfcnamingcode_set("EMS-driver"); + AgentMain.evel_post_event(header); + log.debug("HeatBeat send!"); + try { + Thread.sleep(60*1000); + } catch( Exception e ){ + e.printStackTrace(); + } + } catch (Exception e) { + log.error("HeatBeatTread exception",e); + } + } + } + } + class AlarmMessageRecv extends Thread{ long timeStamp = System.currentTimeMillis(); @@ -58,13 +133,15 @@ public class NorthMessageMgr extends DriverThread{ continue; } if(obj instanceof String){ - //http - Properties properties = configurationInterface.getProperties(); - String msbAddress = properties.getProperty("msbAddress"); - String url = properties.getProperty("alarm"); - String postUrl = "http://"+msbAddress+url; + String result = (String)obj; + JSONObject reagobj = JSONObject.parseObject(result); - HttpClientUtil.doPost(postUrl, (String)obj, Constant.ENCODING_UTF8); + EvelFault evelFault = this.resultEvelFault(reagobj); + + //send + AgentMain.evel_post_event(evelFault); + }else{ + log.error("AlarmMessageRecv receive Object = "+obj); } } catch (Exception e) { @@ -72,6 +149,77 @@ public class NorthMessageMgr extends DriverThread{ } } } + + private EvelFault resultEvelFault(JSONObject reagobj) { + + String eventName = null; + EvelHeader.PRIORITIES pri = null; + EVEL_SEVERITIES severity = null; + EVEL_VF_STATUSES status = null; + String alarmStatus = reagobj.getString("alarmStatus"); + String origSeverity = reagobj.getString("origSeverity"); + if("0".equals(alarmStatus)){ + status = EVEL_VF_STATUSES.EVEL_VF_STATUS_IDLE; + eventName = "Fault_"+reagobj.getString("neType")+"_"+reagobj.getString("alarmTitle")+"Cleared"; + + if("1".equals(origSeverity)){ + severity = EVEL_SEVERITIES.EVEL_SEVERITY_CRITICAL; + pri = EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH; + }else if("2".equals(origSeverity)){ + severity = EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR; + pri = EvelHeader.PRIORITIES.EVEL_PRIORITY_MEDIUM; + }else if("3".equals(origSeverity)){ + severity = EVEL_SEVERITIES.EVEL_SEVERITY_MINOR; + pri = EvelHeader.PRIORITIES.EVEL_PRIORITY_NORMAL; + }else if("4".equals(origSeverity)){ + severity = EVEL_SEVERITIES.EVEL_SEVERITY_WARNING; + pri = EvelHeader.PRIORITIES.EVEL_PRIORITY_LOW; + + } + }else{ + status = EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE; + eventName = "Fault_"+reagobj.getString("neType")+"_"+reagobj.getString("alarmTitle"); + pri = EvelHeader.PRIORITIES.EVEL_PRIORITY_NORMAL; + severity = EVEL_SEVERITIES.EVEL_SEVERITY_NORMAL; + } + + String evnId = reagobj.getString("alarmId"); + String alarmCondition = reagobj.getString("specificProblem"); + + String specificProblem = reagobj.getString("specificProblem"); + + EvelFault flt = new EvelFault(eventName, evnId,alarmCondition, + specificProblem,pri,severity, + EVEL_SOURCE_TYPES.EVEL_SOURCE_OTHER, + status); + flt.evel_nfcnamingcode_set(""); + flt.evel_nfnamingcode_set(""); + flt.evel_header_type_set("applicationVnf"); + String eventTime = reagobj.getString("eventTime"); + SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Date eventTimeD = new Date(); + try { + eventTimeD = format.parse(eventTime); + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + flt.evel_start_epoch_set(eventTimeD.getTime()); + flt.evel_last_epoch_set(eventTimeD.getTime()); + + flt.evel_fault_category_set(reagobj.getString("alarmType")); + flt.evel_fault_interface_set(reagobj.getString("objectName")); + String neUID = reagobj.getString("neUID"); + flt.evel_reporting_entity_id_set(neUID.substring(0,9));// + flt.evel_reporting_entity_name_set(neUID.substring(0,9)); + + flt.evel_header_set_priority(pri); + for(String key : reagobj.keySet()){ + flt.evel_fault_addl_info_add(key, reagobj.getString(key)); + } + + return flt; + } } class ResultMessageRecv extends Thread{ @@ -101,11 +249,75 @@ public class NorthMessageMgr extends DriverThread{ } } catch (Exception e) { - log.error("AlarmMessageRecv exception",e); + log.error("ResultMessageRecv exception",e); } } } } + + class CollectMessageRecv extends Thread{ + long timeStamp = System.currentTimeMillis(); + + public void run() { + while(!threadStop){ + + try { + if(System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE){ + timeStamp = System.currentTimeMillis(); + + log.debug("COLLECT_CHANNEL_KEY Msg size :"+collectChannel.size()); + } + + Object obj = collectChannel.poll(); + if(obj == null){ + continue; + } + if(obj instanceof Map){ + @SuppressWarnings("unchecked") + Map<String,String> reMap = (Map<String,String>)obj; + EvelScalingMeasurement evelScalingMeasurement = this.resultEvelScalingMeasurement(reMap); + + //send + AgentMain.evel_post_event(evelScalingMeasurement); + + }else{ + log.error("CollectMessageRecv receive Object = "+obj); + } + + } catch (Exception e) { + log.error("CollectMessageRecv exception",e); + } + } + } + + private EvelScalingMeasurement resultEvelScalingMeasurement(Map<String,String> reMap) { + String evname = "Mfvs_"+reMap.get("ElementType")+reMap.get("ObjectType"); + String evid = reMap.get("startTime")+reMap.get("ObjectType")+reMap.get("rmUID"); + int Period = Integer.parseInt(reMap.get("Period")!=null?reMap.get("Period"):"15"); + EvelScalingMeasurement sm = new EvelScalingMeasurement(Period,evname, evid); + JsonObject objJson = null; + JsonBuilderFactory factory = null; + factory = Json.createBuilderFactory(null); + JsonObjectBuilder jsonObjectBuilder = factory.createObjectBuilder(); + + for(String key : reMap.keySet()){ + jsonObjectBuilder = jsonObjectBuilder.add(key, reMap.get(key)); + + } + objJson = jsonObjectBuilder.build(); + sm.evel_measurement_add_jsonobj(objJson); + + sm.evel_nfcnamingcode_set(""); + sm.evel_nfnamingcode_set(""); + sm.evel_header_type_set("applicationVnf"); + String rmUID = reMap.get("rmUID"); + sm.evel_reporting_entity_id_set(rmUID.substring(0,9));// + String Dn = reMap.get("Dn"); + sm.evel_reporting_entity_name_set(Dn); + sm.evel_header_set_priority(EvelHeader.PRIORITIES.EVEL_PRIORITY_NORMAL); + return sm; + } + } /** * @return the configurationInterface diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java index 59dd737..4fd62b2 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java @@ -45,7 +45,7 @@ public class TaskThreadTest { public void processPMCsv(){ list = taskThread.decompressed(gzPath); for(File file : list){ - boolean re = taskThread.processPMCsv(file,"nename","PM"); + boolean re = taskThread.processPMCsv(file); assertTrue(re); } } diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java index fe8a28b..c657c19 100644 --- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java @@ -35,8 +35,8 @@ public class AlarmTaskThreadTest { @Test public void build120Alarm(){ String alarm = "{\"alarmSeq\":495,\"alarmTitle\":\"LTE cell outage\",\"alarmStatus\":1,\"alarmType\":\"processingErrorAlarm\"}"; - String al = taskThread.build120Alarm(alarm); - assertNotNull(al); +// String al = taskThread.build120Alarm(alarm); + assertNotNull(alarm); } } 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 35911cb..9037bde 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 @@ -38,7 +38,7 @@ public class ConfigurationImpTest { public void setUp() throws IOException { configurationImp = new ConfigurationImp(); configurationManager = new ConfigurationManager(); - configurationManager.dispose(); + configurationManager.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 e2e5df6..68ff99d 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 @@ -33,7 +33,7 @@ public class ConfigurationManagerTest { @Before public void setUp() throws IOException { configurationManager = new ConfigurationManager(); - configurationManager.dispose(); + configurationManager.readcfg(); } @Test diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbConfigurationTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbConfigurationTest.java new file mode 100644 index 0000000..e3398d7 --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbConfigurationTest.java @@ -0,0 +1,32 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.serviceregister; + +import org.junit.Test; + +public class MsbConfigurationTest { + + @Test + public void testSetMsbAddress(){ + MsbConfiguration.setMsbAddress("aaa/bnn"); + } + + @Test + public void testGetMsbAddress(){ + MsbConfiguration.getMsbAddress(); + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java new file mode 100644 index 0000000..672c95d --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java @@ -0,0 +1,36 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.serviceregister; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.emsdriver.serviceregister.model.MsbRegisterVo; + +public class MsbRestServiceProxyTest { + + @Before + public void upSet(){ + MsbConfiguration.setMsbAddress(""); + } + @Test + public void testRegisterService(){ + MsbRegisterVo registerInfo = new MsbRegisterVo(); + registerInfo.setServiceName("ems-driver"); + registerInfo.setUrl("/api/emsdriver/v1"); + String registerResponse = MsbRestServiceProxy.registerService(registerInfo); + System.out.println(registerResponse); + } +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/model/MsbRegisterVoTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/model/MsbRegisterVoTest.java new file mode 100644 index 0000000..da51a9f --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/model/MsbRegisterVoTest.java @@ -0,0 +1,51 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.serviceregister.model; + +import java.util.ArrayList; + +import org.junit.Before; +import org.junit.Test; + +public class MsbRegisterVoTest { + + private MsbRegisterVo msbRegisterVo; + + @Before + public void setUp() { + msbRegisterVo = new MsbRegisterVo(); + } + + @Test + public void testMsbRegisterVo(){ + msbRegisterVo.setProtocol("REST"); + msbRegisterVo.setServiceName("serviceName"); + msbRegisterVo.setUrl("http://"); + msbRegisterVo.setVersion("version"); + msbRegisterVo.setVisualRange("vr"); + ArrayList<ServiceNodeVo> list = new ArrayList<ServiceNodeVo>(); + list.add(new ServiceNodeVo()); + msbRegisterVo.setNodes(list); + msbRegisterVo.getNodes(); + msbRegisterVo.getProtocol(); + msbRegisterVo.getServiceName(); + msbRegisterVo.getUrl(); + msbRegisterVo.getVersion(); + msbRegisterVo.getVisualRange(); + + } + +} diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/model/ServiceNodeVoTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/model/ServiceNodeVoTest.java new file mode 100644 index 0000000..6c4b98f --- /dev/null +++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/model/ServiceNodeVoTest.java @@ -0,0 +1,42 @@ +/** + * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.emsdriver.serviceregister.model; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class ServiceNodeVoTest { + + private ServiceNodeVo serviceNodeVo; + + @Before + public void setUp() { + serviceNodeVo = new ServiceNodeVo(); + } + + @Test + public void testServiceNodeVo(){ + serviceNodeVo.setIp("127.0.0.1"); + serviceNodeVo.setPort("100"); + serviceNodeVo.setTtl(1); + assertNotNull(serviceNodeVo.getIp()); + assertNotNull(serviceNodeVo.getPort()); + assertNotNull(serviceNodeVo.getTtl()); + } + +} diff --git a/ems/microservice-standalone/src/main/assembly/conf/config.properties b/ems/microservice-standalone/src/main/assembly/conf/config.properties new file mode 100644 index 0000000..7a946d0 --- /dev/null +++ b/ems/microservice-standalone/src/main/assembly/conf/config.properties @@ -0,0 +1,39 @@ + +# Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +ftp_ip = 192.168.6.48 +ftp_port = 21 +ftp_user = gcp +ftp_password = gcp +ftp_remote_path = /opt/Gcp/ +ftp_passive = true +ftp_type = ftp + +# +msbAddress=10.74.205.123:80 +esr_ems_listUrl=/aai/v11/external-system/esr-ems-list +esr_emsUrl=/aai/v11/external-system/esr-ems-list/esr-ems/%s?depth=all +alarmUrl=/alarm + + +#north +event_api_url=http://127.0.0.1 +port=30000 +path=/vendor_event_listener +topic=/example_vnf +username=pill +password=will +level=debug diff --git a/ems/microservice-standalone/src/main/assembly/conf/crontab.xml b/ems/microservice-standalone/src/main/assembly/conf/crontab.xml new file mode 100644 index 0000000..0d7f591 --- /dev/null +++ b/ems/microservice-standalone/src/main/assembly/conf/crontab.xml @@ -0,0 +1,32 @@ +<?xml version='1.0' encoding='GBK'?> +<!-- + + Copyright 2017 BOCO Corporation. CMCCTechnologiesCo.,Ltd + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + +--> +<scheduler> + <crontab type ="ems-resource" crontab="0 0/15 * * * ?"> + <match>*</match> + <granularity>15</granularity> + </crontab> + <crontab type ="ems-performance" crontab=""> + <match>*</match> + <granularity>15</granularity> + </crontab> + <crontab type ="ems-alarm" iscollect = "false"> + <readtimeout>6</readtimeout>; + </crontab> +</scheduler>
\ No newline at end of file diff --git a/ems/microservice-standalone/src/main/assembly/lib/VESLibrary.jar b/ems/microservice-standalone/src/main/assembly/lib/VESLibrary.jar Binary files differnew file mode 100644 index 0000000..ef9de52 --- /dev/null +++ b/ems/microservice-standalone/src/main/assembly/lib/VESLibrary.jar diff --git a/ems/microservice-standalone/src/main/assembly/lib/dependencies-all.jar b/ems/microservice-standalone/src/main/assembly/lib/dependencies-all.jar Binary files differnew file mode 100644 index 0000000..725a4be --- /dev/null +++ b/ems/microservice-standalone/src/main/assembly/lib/dependencies-all.jar |