*/
package org.onap.vfc.nfvo.emsdriver.collector;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
import org.onap.vfc.nfvo.emsdriver.commons.model.CollectMsg;
import org.onap.vfc.nfvo.emsdriver.commons.utils.DriverThread;
+import org.onap.vfc.nfvo.emsdriver.configmgr.ConfigurationManager;
import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannel;
import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannelFactory;
public class CollectMsgReceiverThread extends DriverThread {
+ protected static final Log logger = LogFactory.getLog(CollectMsgReceiverThread.class);
private long timeStamp = System.currentTimeMillis();
try {
if (System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE) {
timeStamp = System.currentTimeMillis();
- log.debug("COLLECT_CHANNEL Msg size :"
+ logger.debug("COLLECT_CHANNEL Msg size :"
+ collectChannel.size());
}
Object obj = collectChannel.poll();
if (obj instanceof CollectMsg) {
CollectMsg collectMsg = (CollectMsg) obj;
taskService.add(collectMsg);
- log.debug("receive a CollectMsg id = " + collectMsg.getId());
+ logger.debug("receive a CollectMsg id = " + collectMsg.getId());
} else {
- log.error("receive Objcet not CollectMsg " + obj);
+ logger.error("receive Objcet not CollectMsg " + obj);
}
} catch (Exception e) {
- log.error("dispatch alarm exception", e);
+ logger.error("dispatch alarm exception", e);
}
}
int event = -1;
while (reader.hasNext()) {
try {
+ String fileHeaderConstant = "FileHeader";
event = reader.next();
switch (event) {
case XMLStreamConstants.START_ELEMENT:
localName = reader.getLocalName();
- if ("FileHeader".equalsIgnoreCase(localName)) {
+ if (fileHeaderConstant.equalsIgnoreCase(localName)) {
fileHeaderStart = true;
}
- if (fileHeaderStart&& !"FileHeader".equalsIgnoreCase(localName)) {
+ if (fileHeaderStart&& !fileHeaderConstant.equalsIgnoreCase(localName)) {
commonNameAndValue.put(localName, reader.getElementText().trim());
}
if ("Measurements".equalsIgnoreCase(localName)) {
}
if ("PmName".equalsIgnoreCase(localName)) {
pmNameFlag = true;
- pmNames = new LinkedHashMap<Integer, String>();
+ pmNames = new LinkedHashMap<>();
}
if (pmNameFlag && "N".equalsIgnoreCase(localName)) {
}
if ("PmData".equalsIgnoreCase(localName)) {
pmDataFlag = true;
- pmDatas = new LinkedHashMap<String, String>();
+ pmDatas = new LinkedHashMap<>();
}
if (pmDataFlag) {
measurementStart = false;
}
- if ("FileHeader".equalsIgnoreCase(endLocalName)) {
+ if (fileHeaderConstant.equalsIgnoreCase(endLocalName)) {
fileHeaderStart = false;
}
break;
}
private void ftpStore(String[] fileKeys, String ip, String port,
- String ftp_user, String ftp_password, String ftp_passive,
- String ftp_type, String remoteFile) {
+ String ftpUser, String ftpPassword, String ftpPassive,
+ String ftpType, String remoteFile) {
String zipFilePath = fileKeys[0];
FTPInterface ftpClient;
ftpClient = new FTPSrv();
// login
try {
- ftpClient.login(ip, Integer.parseInt(port), ftp_user, ftp_password,
- "GBK", Boolean.parseBoolean(ftp_passive), 5 * 60 * 1000);
+ ftpClient.login(ip, Integer.parseInt(port), ftpUser, ftpPassword,
+ "GBK", Boolean.parseBoolean(ftpPassive), 5 * 60 * 1000);
} catch (Exception e) {
log.error("login fail,ip=[" + ip + "] port=[" + port + "] user=["
- + ftp_user + /* "]pwd=[" + ftp_password + */"]"
+ + ftpUser + "]pwd=[" + ftpPassword + "]"
+ StringUtil.getStackTrace(e));
return;
}
public List<File> decompressed(String fileName) {
List<File> filelist = new ArrayList<>();
- if (fileName.indexOf(".gz") > 1) {
+ if (fileName.indexOf(".gz") > -1) {
try {
File decompressFile = deGz(fileName);
filelist.add(decompressFile);
} catch (IOException e) {
log.error("decompressed is fail " + StringUtil.getStackTrace(e));
}
- } else if (fileName.indexOf(".zip") > 1) {
+ } else if (fileName.indexOf(".zip") > -1) {
try {
File[] files = deZip(new File(fileName));
new File(fileName).delete();
*/
package org.onap.vfc.nfvo.emsdriver.collector.alarm;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.onap.vfc.nfvo.emsdriver.collector.CollectMsgReceiverThread;
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 java.util.List;
public class AlarmManager extends DriverThread {
-
+ protected static final Log logger = LogFactory.getLog(AlarmManager.class);
private ConfigurationInterface configurationInterface;
@Override
public void dispose() {
- log.debug("AlarmManager is start");
+ logger.debug("AlarmManager is start");
// get alarm CONFIG_PROPERTIES_LOCATION
List<EMSInfo> emsInfos = configurationInterface.getAllEMSInfo();
while (isRun() && emsInfos.isEmpty()) {
if (emsInfos.isEmpty()) {
try {
Thread.sleep(1000);
- log.debug("The configuration properties from "
+ logger.debug("The configuration properties from "
+ ConfigurationManager.CONFIG_PROPERTIES_LOCATION
+ " is not load");
} catch (Exception e) {
- log.error("Exception", e);
+ logger.error("Exception", e);
}
}
}
collectVo.setEmsName(emsInfo.getName());
collectVos.add(collectVo);
} else {
- log.error("emsInfo.getCollectVoByType(EMS_RESOUCE) result CollectVo = null emsInfo ="
+ logger.error("emsInfo.getCollectVoByType(EMS_RESOUCE) result CollectVo = null emsInfo ="
+ emsInfo);
}
}
AlarmTaskThread alarm = new AlarmTaskThread(collectVo);
alarm.setName(collectVo.getIP() + collectVo.getPort());
alarm.start();
- log.info("AlarmTaskThread is start");
+ logger.info("AlarmTaskThread is start");
}
}
public class MessageUtil {
public static final String MSG_BODY_ENCODE_CHARSET = "UTF-8";
public static final int MSG_BUF_SIZE = 8096;
-
+
+ private MessageUtil(){
+
+ }
public static Msg putLoginMsg(String user, String passwd) {
String body = String.format(Msg.REQ_LOGIN_ALARM, user, passwd, "msg");
return new Msg(body, MsgType.REQ_LOGIN_ALARM);
public static final String COLLECT_TYPE_ALARM = "EMS_ALARM";
public static final String ENCODING_UTF8 = "UTF-8";
public static final String ENCODING_GBK = "GBK";
+
+ private Constant(){
+
+ }
}
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class ConfigurationManager extends DriverThread {
public static final String CONFIG_PROPERTIES_LOCATION = Constant.SYS_CFG + "config.properties";
- protected static final Log log = LogFactory.getLog(ConfigurationManager.class);
+ protected static final Log logger = LogFactory.getLog(ConfigurationManager.class);
/**
* ESM Cache
*/
private static Map<String, CrontabVo> emsCrontab = new ConcurrentHashMap<>();
private static List<String> emsIdList = new ArrayList<>();
+ static{
+ File file = new File(CONFIG_PROPERTIES_LOCATION);
+ if (!file.exists() || !file.isFile()) {
+ logger.error("cacheFilePath " + CONFIG_PROPERTIES_LOCATION + " not exist or is not File");
+ }else{
+ try {
+ InputStream in = new FileInputStream(file);
+ properties = new Properties();
+ properties.load(in);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ logger.error("read [" + file.getAbsolutePath() + "]Exception :", e);
+ }
+
+ }
+ }
+
public static synchronized List<EMSInfo> getAllEMSInfos() {
List<EMSInfo> list = new ArrayList<>();
for (EMSInfo emsinfo : emsInfoCache.values()) {
@Override
public void dispose() {
-
- 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;
- }
- try(InputStream in = new FileInputStream(file)){
- properties = new Properties();
- properties.load(in);
- Map<String, CrontabVo> emsMap = readCorntab();
-
- emsCrontab.putAll(emsMap);
-
- new ReceiveSource().start();
- } catch (Exception e) {
- log.error("read [" + file.getAbsolutePath() + "]Exception :", e);
- }
+ Map<String, CrontabVo> emsMap = readCorntab();
+ emsCrontab.putAll(emsMap);
+ new ReceiveSource().start();
+
}
public Map<String, CrontabVo> readCorntab() {
String path = Constant.SYS_CFG + "crontab.xml";
File cfg = new File(path);
- log.debug("start loading " + path);
+ logger.debug("start loading " + path);
if (!cfg.exists() || !cfg.isFile()) {
- log.debug("not exists " + path);
+ logger.debug("not exists " + path);
return null;
}
Map<String, CrontabVo> tmpcache = new HashMap<>();
}
} catch (Exception e) {
- log.error("load crontab.xml is error " + StringUtil.getStackTrace(e));
+ logger.error("load crontab.xml is error " + StringUtil.getStackTrace(e));
}
return tmpcache;
}
try {
if (System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE) {
timeStamp = System.currentTimeMillis();
- log.debug("ReceiveSource run");
+ logger.debug("ReceiveSource run");
}
//get emsId list
List<String> emsIds = this.getEmsIdList();
- if (emsIds.size() > 0) {
+ if (!emsIds.isEmpty()) {
emsIdList.clear();
emsIdList.addAll(emsIds);
}
try {
Thread.sleep(60 * 1000L);
} catch (Exception e1) {
- log.error("InterruptedException :" + StringUtil.getStackTrace(e1));
+ logger.error("InterruptedException :" + StringUtil.getStackTrace(e1));
}
- log.error("ReceiveSource exception", e);
+ logger.error("ReceiveSource exception", e);
}
}
}
emstUrl = String.format(emstUrl, emsId);
String getemstUrl = "http://" + msbAddress + emstUrl;
String emsResult = HttpClientUtil.doGet(getemstUrl, Constant.ENCODING_UTF8);
- log.debug(getemstUrl + " result=" + emsResult);
+ logger.debug(getemstUrl + " result=" + emsResult);
JSONObject reagobj = JSONObject.parseObject(emsResult);
JSONObject esrSystemInfoList = reagobj.getJSONObject("esr-system-info-list");
EMSInfo emsInfo = new EMSInfo();
emsInfo.setName(emsId);
tmpcache.put(emsId, emsInfo);
+ String ipAddressConstant = "ip-address";
+ String userNameConstant = "user-name";
+ String passwordConstant = "password";
+ String portConstant = "port";
while (it.hasNext()) {
Object obj = it.next();
JSONObject collect = (JSONObject) obj;
if (crontabVo != null) {
collectVo.setType(systemType);
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.setIP(collect.getString(ipAddressConstant));
+ collectVo.setPort(collect.getString(portConstant));
+ collectVo.setUser(collect.getString(userNameConstant));
+ collectVo.setPassword(collect.getString(passwordConstant));
collectVo.setRemotepath(collect.getString("remote-path"));
collectVo.setMatch(crontabVo.getMatch());
collectVo.setPassive(collect.getString("passive"));
collectVo.setGranularity(crontabVo.getGranularity());
} else {
- log.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "] emsCrontabMap=" + emsCrontab);
+ logger.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "] emsCrontabMap=" + emsCrontab);
}
if (crontabVo != null) {
collectVo.setType(systemType);
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.setIP(collect.getString(ipAddressConstant));
+ collectVo.setPort(collect.getString(portConstant));
+ collectVo.setUser(collect.getString(userNameConstant));
+ collectVo.setPassword(collect.getString(passwordConstant));
collectVo.setRemotepath(collect.getString("remote-path"));
collectVo.setMatch(crontabVo.getMatch());
collectVo.setPassive(collect.getString("passive"));
collectVo.setGranularity(crontabVo.getGranularity());
} else {
- log.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "]");
+ logger.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "]");
}
} else if (Constant.COLLECT_TYPE_ALARM.equalsIgnoreCase(systemType)) {
CrontabVo crontabVo = emsCrontab.get(systemType);
if (crontabVo != null) {
collectVo.setIscollect(crontabVo.isIscollect());
collectVo.setType(systemType);
- collectVo.setIP(collect.getString("ip-address"));
- collectVo.setPort(collect.getString("port"));
- collectVo.setUser(collect.getString("user-name"));
- collectVo.setPassword(collect.getString("password"));
+ collectVo.setIP(collect.getString(ipAddressConstant));
+ collectVo.setPort(collect.getString(portConstant));
+ collectVo.setUser(collect.getString(userNameConstant));
+ collectVo.setPassword(collect.getString(passwordConstant));
collectVo.setReadTimeout(crontabVo.getReadTimeout());
} else {
- log.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "]");
+ logger.error("emsCrontab.get(systemType) result crontabVo is null systemType=[" + systemType + "]");
}
} else {
- log.error("ems system-type =" + systemType + " ");
+ logger.error("ems system-type =" + systemType + " ");
}
emsInfo.putCollectMap(systemType, collectVo);
String getemsListUrl = "http://" + msbAddress + url;
String result = HttpClientUtil.doGet(getemsListUrl, Constant.ENCODING_UTF8);
- log.debug(getemsListUrl + " result=" + result);
+ logger.debug(getemsListUrl + " result=" + result);
JSONObject reagobj = JSONObject.parseObject(result);
JSONArray esrEmsIds = reagobj.getJSONArray("esr-ems");
Iterator<Object> it = esrEmsIds.iterator();
import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES;
import evel_javalibrary.att.com.EvelHeader;
import evel_javalibrary.att.com.EvelScalingMeasurement;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
+import org.onap.vfc.nfvo.emsdriver.collector.alarm.AlarmManager;
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 java.util.Properties;
public class NorthMessageMgr extends DriverThread {
-
+ protected static final Log logger = LogFactory.getLog(NorthMessageMgr.class);
private MessageChannel alarmChannel = MessageChannelFactory.getMessageChannel(Constant.RESULT_CHANNEL_KEY);
private MessageChannel collectResultPMChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_PM_CHANNEL_KEY);
private MessageChannel collectResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_RESULT_CHANNEL_KEY);
@Override
public void dispose() {
- log.info("NorthMessageMgr Thread start threadStop=" + threadStop);
+ logger.info("NorthMessageMgr Thread start threadStop=" + threadStop);
try {
Properties properties = configurationInterface.getProperties();
String eventApiUrl = properties.getProperty("event_api_url");
//login north
eventApiUrl = "http://" + eventApiUrl;
- log.info("AgentMain.evel_initialize start event_api_url=[" + eventApiUrl + "]port=[" + port + "]path=[" + path + "]"
+ logger.info("AgentMain.evel_initialize start event_api_url=[" + eventApiUrl + "]port=[" + port + "]path=[" + path + "]"
+ "topic=[" + topic + "]username=[" + username + /*"]password=[" + password +*/ "]level=[" + level + "]");
try {
EVEL_ERR_CODES evecode = AgentMain.evel_initialize(eventApiUrl, Integer.parseInt(port),
username,
password,
level);
- log.info("AgentMain.evel_initialize sucess EVEL_ERR_CODES=" + evecode);
+ logger.info("AgentMain.evel_initialize sucess EVEL_ERR_CODES=" + evecode);
} catch (Exception e) {
- log.error("AgentMain.evel_initialize fail ", e);
+ logger.error("AgentMain.evel_initialize fail ", e);
}
} catch (Exception e2) {
- log.error("NorthMessageMgr start fail ", e2);
+ logger.error("NorthMessageMgr start fail ", e2);
}
new HeatBeatTread().start();
new CollectMessageRecv().start();
- log.info("NorthMessageMgr start sucess ");
+ logger.info("NorthMessageMgr start sucess ");
}
/**
header.evel_nfnamingcode_set("EMS-driver");
header.evel_nfcnamingcode_set("EMS-driver");
AgentMain.evel_post_event(header);
- log.info("HeatBeat send!");
+ logger.info("HeatBeat send!");
try {
Thread.sleep(60 * 1000L);//60 secs
} catch (Exception e) {
- log.error("Unable to sleep the HB thread ", e);
+ logger.error("Unable to sleep the HB thread ", e);
}
} catch (Exception e) {
- log.error("HeatBeatTread exception", e);
+ logger.error("HeatBeatTread exception", e);
}
}
}
if (System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE) {
timeStamp = System.currentTimeMillis();
- log.info("ALARM_CHANNEL Msg size :" + alarmChannel.size());
+ logger.info("ALARM_CHANNEL Msg size :" + alarmChannel.size());
}
Object obj = alarmChannel.poll();
EvelFault evelFault = this.resultEvelFault(reagobj);
//send
- log.info("AgentMain.evel_post_event alarm start");
+ logger.info("AgentMain.evel_post_event alarm start");
AgentMain.evel_post_event(evelFault);
- log.info("AgentMain.evel_post_event alarm sucess");
+ logger.info("AgentMain.evel_post_event alarm sucess");
} else {
- log.error("AlarmMessageRecv receive Object = " + obj);
+ logger.error("AlarmMessageRecv receive Object = " + obj);
}
} catch (Exception e) {
- log.error("AlarmMessageRecv exception", e);
+ logger.error("AlarmMessageRecv exception", e);
}
}
}
try {
eventTimeD = format.parse(eventTime);
} catch (ParseException e) {
- log.error("ParseException ", e);
+ logger.error("ParseException ", e);
}
flt.evel_start_epoch_set(eventTimeD.getTime());
flt.evel_last_epoch_set(eventTimeD.getTime());
if (System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE) {
timeStamp = System.currentTimeMillis();
- log.debug("COLLECT_RESULT_CHANNEL Msg size :" + collectResultChannel.size());
+ logger.debug("COLLECT_RESULT_CHANNEL Msg size :" + collectResultChannel.size());
}
Object obj = collectResultChannel.poll();
}
} catch (Exception e) {
- log.error("ResultMessageRecv exception", e);
+ logger.error("ResultMessageRecv exception", e);
}
}
}
@Override
public void run() {
- log.info("CollectMessageRecv Thread is start threadStop=" + threadStop);
+ logger.info("CollectMessageRecv Thread is start threadStop=" + threadStop);
while (!threadStop) {
try {
if (System.currentTimeMillis() - timeStamp > Constant.ONEMINUTE) {
timeStamp = System.currentTimeMillis();
- log.debug(Constant.COLLECT_RESULT_PM_CHANNEL_KEY + " Msg size :" + collectResultPMChannel.size());
+ logger.debug(Constant.COLLECT_RESULT_PM_CHANNEL_KEY + " Msg size :" + collectResultPMChannel.size());
}
Object obj = collectResultPMChannel.poll();
if (obj instanceof Map) {
@SuppressWarnings("unchecked")
Map<String, String> reMap = (Map<String, String>) obj;
- log.debug("reMap =" + reMap);
+ logger.debug("reMap =" + reMap);
EvelScalingMeasurement evelScalingMeasurement = this.resultEvelScalingMeasurement(reMap);
- log.debug("evelScalingMeasurement=" + evelScalingMeasurement);
+ logger.debug("evelScalingMeasurement=" + evelScalingMeasurement);
//send
- log.info("AgentMain.evel_post_event start");
+ logger.info("AgentMain.evel_post_event start");
AgentMain.evel_post_event(evelScalingMeasurement);
- log.info("AgentMain.evel_post_event sucess");
+ logger.info("AgentMain.evel_post_event sucess");
} else {
- log.error("CollectMessageRecv receive Object = " + obj);
+ logger.error("CollectMessageRecv receive Object = " + obj);
}
} catch (Exception e) {
- log.error("CollectMessageRecv exception", e);
+ logger.error("CollectMessageRecv exception", e);
}
}
}