From 073cc188efe9abb4c010cf674e34e2cf46ef1c52 Mon Sep 17 00:00:00 2001 From: Guo Ruijing Date: Mon, 31 Jul 2017 08:47:35 +0000 Subject: [POLICY-73] replace openecomp for policy-engine Change-Id: I54072f6bcd388c0e05562614ee89b4ae7ad67004 Signed-off-by: Guo Ruijing Signed-off-by: Pamela Dragosh --- .../java/org/onap/xacml/parser/LogEntryObject.java | 74 +++ .../main/java/org/onap/xacml/parser/ParseLog.java | 695 +++++++++++++++++++++ .../org/openecomp/xacml/parser/LogEntryObject.java | 74 --- .../java/org/openecomp/xacml/parser/ParseLog.java | 695 --------------------- .../java/org/onap/xacml/parser/ParseLogTest.java | 506 +++++++++++++++ .../org/openecomp/xacml/parser/ParseLogTest.java | 506 --------------- LogParser/src/test/resources/LineTest.txt | 20 +- LogParser/src/test/resources/LineTest2.txt | 10 +- 8 files changed, 1290 insertions(+), 1290 deletions(-) create mode 100644 LogParser/src/main/java/org/onap/xacml/parser/LogEntryObject.java create mode 100644 LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java delete mode 100644 LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java delete mode 100644 LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java create mode 100644 LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java delete mode 100644 LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java (limited to 'LogParser/src') diff --git a/LogParser/src/main/java/org/onap/xacml/parser/LogEntryObject.java b/LogParser/src/main/java/org/onap/xacml/parser/LogEntryObject.java new file mode 100644 index 000000000..1aeac1726 --- /dev/null +++ b/LogParser/src/main/java/org/onap/xacml/parser/LogEntryObject.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * LogParser + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.xacml.parser; + +import java.util.Date; + +public class LogEntryObject { + + private String system; + private String description; + private Date date; + private String remote; + private String systemType; + private LOGTYPE logType; + + public enum LOGTYPE { + INFO, DEBUG, ERROR, SEVERE, WARN; + } + + public String getSystem() { + return system; + } + public void setSystem(String system) { + this.system = system; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public Date getDate() { + return date; + } + public void setDate(Date date) { + this.date = date; + } + public String getRemote() { + return remote; + } + public void setRemote(String remote) { + this.remote = remote; + } + public String getSystemType() { + return systemType; + } + public void setSystemType(String systemType) { + this.systemType = systemType; + } + public LOGTYPE getLogType() { + return logType; + } + public void setLogType(LOGTYPE logType) { + this.logType = logType; + } +} \ No newline at end of file diff --git a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java new file mode 100644 index 000000000..31eceb09d --- /dev/null +++ b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java @@ -0,0 +1,695 @@ +/*- + * ============LICENSE_START======================================================= + * LogParser + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.xacml.parser; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.LineNumberReader; +import java.io.RandomAccessFile; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.text.Format; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Stream; + +import org.apache.log4j.Logger; +import org.onap.policy.common.im.AdministrativeStateException; +import org.onap.policy.common.im.IntegrityMonitor; +import org.onap.policy.common.im.StandbyStatusException; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.xacml.parser.LogEntryObject.LOGTYPE; + +/** + * Parse log files and store the information in a H2 database. + * + * + */ +public class ParseLog { + + // only logging last line of each log file processed to the log4j log file defined by property - PARSERLOGPATH + private static final Logger log4jlogger = Logger.getLogger(ParseLog.class.getName()); + + // processing logging + private static org.onap.policy.common.logging.flexlogger.Logger logger = FlexLogger.getLogger(ParseLog.class.getName()); + + private static String system; + private static int lastNumberRead = 0; + private static int debuglastNumberRead = 0; + private static int errorlastNumberRead = 0; + private static String type; + private static long startFileSize; + private static long debugStartFileSize; + private static long errorStartFileSize; + private static String systemLogFile; + private static String logFile; + private static String debuglogFile; + private static String errorlogFile; + private static String JDBC_URL; + private static String JDBC_USER; + private static String JDBC_PASSWORD; + private static String JDBC_DRIVER; + private static int maxLength = 255; //Max length that is allowed in the DB table + private static String resourceName; + private static long sleepTimer = 50000; + static IntegrityMonitor im; + private static boolean isMissingLogFile; + + private static RandomAccessFile randomAccessFile; + + public static void main(String[] args) throws Exception { + + Properties logProperties = getPropertiesValue("parserlog.properties"); + + if(logProperties == null || isMissingLogFile){ + // missing the path of log file in the properties file, so stop the process + logger.error("logProperties is null or LOGPATH is missing in parserlog.properties, so stop the process."); + return; + } + + File fileLog = new File(systemLogFile); + + im = IntegrityMonitor.getInstance(resourceName,logProperties ); + + startDebugLogParser(fileLog); + startErrorLogParser(fileLog); + startAPIRestLogParser(fileLog); + + } + + private static void startDebugLogParser(File fileLog){ + try{ + if(debuglogFile != null && !debuglogFile.isEmpty()){ + + // pull the last line number + String dataFileName = "debug.log"; + String filesRead = PullLastLineRead(fileLog, dataFileName); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); + debuglastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + debuglastNumberRead = 0; + } + + debugStartFileSize = countLines(debuglogFile); + if (debugStartFileSize < debuglastNumberRead ){ + logger.error("Filed Rolled: set Last debug number read to 0"); + debuglastNumberRead = 0; + } + + isMissingLogFile = false; + Path debugfilePath = Paths.get(debuglogFile); + File debugfile = new File(debuglogFile); + debugStartFileSize = debugfile.length(); + // start process debug.log file + + Runnable runnable = new Runnable (){ + boolean isStop = false; + + public void run(){ + while (!isStop){ + + if (debugfile.isFile()){ + // log4jlogger must use .info + Stream lines = null; + try { + lines = Files.lines(debugfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + debuglastNumberRead)).skip(debuglastNumberRead); + lines.forEachOrdered(line -> process(line, type, LOGTYPE.DEBUG)); + } catch (IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + }finally{ + if(lines != null){ + lines.close(); + } + } + } + try { + Thread.sleep(sleepTimer); + debugStartFileSize = countLines(debuglogFile); + } catch (InterruptedException | IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + + logger.debug("File Line Count of debug.log: " + debugStartFileSize + " value read in: " + debuglastNumberRead); + if (debugStartFileSize < debuglastNumberRead ){ + logger.debug("Failed Rolled: set Last number read to 0"); + debuglastNumberRead = 0; + } + } + } + }; + + Thread thread = new Thread(runnable); + thread.start(); + + } + }catch(Exception e){ + logger.error("Exception occured in DebugLogParser" +e); + } + } + + private static void startErrorLogParser(File fileLog){ + try{ + if(errorlogFile != null && !errorlogFile.isEmpty()){ + + // pull the last line number + String dataFileName = "error.log"; + String filesRead = PullLastLineRead(fileLog, dataFileName); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); + errorlastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + errorlastNumberRead = 0; + } + + errorStartFileSize = countLines(errorlogFile); + if (errorStartFileSize < errorlastNumberRead ){ + logger.error("Filed Rolled: set Last error number read to 0"); + errorlastNumberRead = 0; + } + + isMissingLogFile = false; + Path errorfilePath = Paths.get(errorlogFile); + File errorfile = new File(errorlogFile); + errorStartFileSize = errorfile.length(); + // start process error.log file + Runnable runnable = new Runnable (){ + boolean isStop = false; + public void run(){ + + while (!isStop){ + if (errorfile.isFile()){ + // log4jlogger must use .info + Stream lines = null; + try{ + lines = Files.lines(errorfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + errorlastNumberRead)).skip(errorlastNumberRead); + lines.forEachOrdered(line -> process(line, type, LOGTYPE.ERROR)); + } catch (IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + }finally{ + if(lines != null){ + lines.close(); + } + } + } + try { + Thread.sleep(sleepTimer); + errorStartFileSize = countLines(errorlogFile); + } catch (InterruptedException | IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + + logger.debug("File Line Count of error.log: " + errorStartFileSize + " value read in: " + errorlastNumberRead); + if (errorStartFileSize < errorlastNumberRead ){ + logger.debug("Failed Rolled: set Last error number read to 0"); + errorlastNumberRead = 0; + } + } + } + }; + + Thread thread = new Thread(runnable); + thread.start(); + } + }catch(Exception e){ + logger.error("Exception occured in startErrorLogParser" +e); + } + } + + private static void startAPIRestLogParser(File fileLog){ + try{ + if(logFile != null && !logFile.isEmpty()){ + + // pull the last line number + String dataFileName = type.toLowerCase()+"-rest.log"; + String filesRead = PullLastLineRead(fileLog, dataFileName); + if (filesRead!= null){ + filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); + lastNumberRead= Integer.parseInt(filesRead.trim()); + }else{ + lastNumberRead = 0; + } + startFileSize = countLines(logFile); + if (startFileSize < lastNumberRead ){ + logger.error("Filed Rolled: set Last number read to 0"); + lastNumberRead = 0; + } + + isMissingLogFile = false; + Path filePath = Paths.get(logFile); + File file = new File(logFile); + startFileSize = file.length(); + // start process pap/pdp-rest.log file + Runnable runnable = new Runnable () { + boolean isStop = false; + public void run(){ + while (!isStop){ + + if (file.isFile()){ + // log4jlogger must use .info + Stream lines = null;; + try { + lines = Files.lines(filePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + lastNumberRead)).skip(lastNumberRead); + lines.forEachOrdered(line -> process(line, type, LOGTYPE.INFO)); + } catch (IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + }finally{ + if(lines != null){ + lines.close(); + } + } + } + try { + Thread.sleep(sleepTimer); + startFileSize = countLines(logFile); + } catch (InterruptedException | IOException e) { + logger.error("Error processing line in " + dataFileName + ":" + e); + logger.error("break the loop."); + isStop = true; + } + + logger.debug("File Line Count of " + dataFileName+": " + startFileSize + " value read in: " + lastNumberRead); + if (startFileSize < lastNumberRead ){ + logger.debug("Failed Rolled: set Last number read to 0"); + lastNumberRead = 0; + } + } + } + }; + + Thread thread = new Thread(runnable); + thread.start(); + } + }catch(Exception e){ + logger.error("Exception occured in StartAPIRestLogParser" +e); + } + } + + public static int countLines(String filename) throws IOException { + LineNumberReader reader = new LineNumberReader(new FileReader(filename)); + int cnt = 0; + String line= null; + while ((line = reader.readLine()) != null) { + logger.info("Reading the Logs"+line); + } + cnt = reader.getLineNumber(); + reader.close(); + return cnt; + } + + public static String PullLastLineRead(File file, String dataFileName) throws IOException { + if(!file.exists()){ + file.createNewFile(); + return null; + } + randomAccessFile = new RandomAccessFile(file, "r"); + StringBuilder builder = new StringBuilder(); + long length = file.length(); + logger.debug("dataFileName: " +dataFileName); + if(length > 0){ + length--; + randomAccessFile.seek(length); + for(long seek = length; seek >= 0; --seek){ + randomAccessFile.seek(seek); + char c = (char)randomAccessFile.read(); + builder.append(c); + if(c == '\n'){ + builder = builder.reverse(); + logger.debug("builder.toString(): " +builder.toString()); + if (builder.toString().contains("Last-"+dataFileName+"-line-Read:")){ + String[] parseString = builder.toString().split("Last-"+dataFileName+"-line-Read:"); + String returnValue = parseString[1].replace("\r", ""); + return returnValue.trim(); + } + builder = null; + builder = new StringBuilder(); + } + } + } + + return null; + } + + public static LogEntryObject pullOutLogValues(String line, String type){ + Date date; + LogEntryObject logEntry = new LogEntryObject(); + String description = ""; + logEntry.setSystemType(type); + logEntry.setSystem(system); + logger.debug("In pullOutLogValues ..."); + //Values for PDP/PAP debug.log file contains "INFO:", error.log file contains ""ERROR:", others are in PDP/PAP rest log file + if(line.contains("||INFO||") || line.contains("||ERROR||") || line.contains("INFO:") || line.contains("ERROR:")){ + String[] splitString = null; + if(line.contains("||INFO||") || line.contains("||ERROR||")){ + splitString = line.split("[||]"); + }else if(line.contains("INFO:")){ + splitString = line.split("INFO:"); + }else{ + splitString = line.split("ERROR:"); + } + String dateString = splitString[0].substring(0, 19); + logEntry.setDescription(splitString[splitString.length-1]); + + //parse out date + date = parseDate(dateString.replace("T", " "), "yyyy-MM-dd HH:mm:ss", false); + logEntry.setDate(date); + + logEntry.setRemote(parseRemoteSystem(line)); + if (line.contains("INFO:") || line.contains("||INFO||")){ + logEntry.setLogType(LOGTYPE.INFO); + }else{ + logEntry.setLogType(LOGTYPE.ERROR); + } + // from PDP/PAP rest log file below + }else if (line.contains("INFO") && line.contains(")-")){ + //parse out description + logEntry.setDescription(line.substring(line.indexOf(")-")+3)); + + date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); + logEntry.setDate(date); + + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.INFO); + } else if (line.contains("INFO") && line.contains("--- [")){ + //parse out description + String temp = line.substring(line.indexOf("---")+1); + String[] split = temp.split(":"); + + logEntry.setDescription(split[1]); + + //parse out date + date = parseDate(line, "yyyy-MM-dd HH:mm:ss", false); + logEntry.setDate(date); + + //remote system + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.INFO); + }else if (line.contains("SEVERE") && line.contains("[main]")){ + String[] splitString = line.split(" "); + + for (int i = 5; i < splitString.length; i++){ + description = description + " " + splitString[i]; + } + + logEntry.setDescription(description); + //parse out date + date = parseDate(line, "dd-MMM-yyyy HH:mm:ss", false); + logEntry.setDate(date); + logEntry.setLogType(LOGTYPE.SEVERE); + } else if (line.contains("WARN") && line.contains(")-")){ + //parse out description + + logEntry.setDescription(line.substring(line.indexOf(")-")+3)); + + //parse out date + date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); + logEntry.setDate(date); + + //remote system + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.WARN); + }else if (line.contains("WARNING") && type =="PyPDP"){ + String[] splitString = line.split(" "); + for (int i = 5; i < splitString.length; i++){ + description = description + " " + splitString[i]; + } + + //parse out date + date = parseDate(line, "dd-MMM-yyyy HH:mm:ss", false); + logEntry.setDate(date); + logEntry.setLogType(LOGTYPE.WARN); + }else if (line.contains("ERROR") && line.contains(")-")){ + //parse out description + description = line.substring(line.indexOf(")-")+3); + + //parse out date + date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); + logEntry.setDate(date); + //remote system + logEntry.setRemote(parseRemoteSystem(line)); + logEntry.setLogType(LOGTYPE.ERROR); + }else { + return null; + } + + return logEntry; + } + + private static void DBClose(Connection conn) { + try { + conn.close(); + } catch (SQLException e) { + logger.error("Error closing DB Connection: " + e); + + } + } + + public static void process(String line, String type, LOGTYPE logFile) { + + logger.debug("In process: processing line : " + line); + LogEntryObject returnLogValue = null; + if (im!=null){ + try { + im.startTransaction(); + } catch (AdministrativeStateException e) { + logger.error("Error received" + e); + } catch (StandbyStatusException e) { + logger.error("Error received" + e); + } + } + returnLogValue = pullOutLogValues(line, type); + + if(logFile.equals(LOGTYPE.DEBUG)){ + debuglastNumberRead++; + }else if(logFile.equals(LOGTYPE.ERROR)){ + errorlastNumberRead++; + }else if(logFile.equals(LOGTYPE.INFO)){ + lastNumberRead++; + } + if (returnLogValue!=null){ + writeDB(returnLogValue); + } + if (im!=null){ + im.endTransaction(); + } + } + + private static void writeDB(LogEntryObject returnLogValue) { + + Connection conn = DBConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); + DBAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(), + returnLogValue.getDate(), returnLogValue.getRemote(), + returnLogValue.getSystemType(), returnLogValue.getLogType().toString()); + DBClose(conn); + } + + private static Connection DBConnection(String driver, String jdbc, String user, String pass){ + + try { + Class.forName(driver); + Connection conn = DriverManager.getConnection(jdbc, user, pass); + return conn; + } catch ( Exception e) { + logger.error("Error connecting to DB: " + e); + } + return null; + } + private static void DBAccesss(Connection conn, String system, String description, Date date, String remote, String type, String logType) { + + String sdate = null; + + if (date!=null){ + Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + sdate = formatter.format(date); + logger.debug("DBAccesss : sdate : " + sdate); + }else{ + logger.debug("DBAccesss : sdate is null"); + } + + //ensure the length of description is less than the maximumm db char length + if (description.length() > maxLength) { + description = description.substring(0, maxLength); + } + + try { + PreparedStatement prep = conn.prepareStatement("insert into SYSTEMLOGDB values (NULL, ?, ?, ?, ?, ?, ?);"); + prep.setString(1, system); + prep.setString(2, description); + prep.setString(3, remote); + prep.setString(4, type); + prep.setString(5, sdate); + prep.setString(6, logType); + + prep.executeUpdate(); + prep.close(); + + } catch (SQLException e1) { + logger.error("Error trying to excute SQL Statment: " + e1); + } + } + + public static Date parseDate(String dateline, String pattern, boolean singleSplit) { + + Date returnDate; + String[] splitString = dateline.split(" "); + SimpleDateFormat formatter = new SimpleDateFormat(pattern); + if (singleSplit){ + try { + returnDate = formatter.parse(splitString[0]); + } catch (ParseException e) { + logger.error("Unable to parse date for line: " + dateline); + returnDate = null; + } + }else{ + String tmpString = splitString[0] + " " + splitString[1]; + try { + returnDate = formatter.parse(tmpString); + } catch (ParseException e) { + logger.error("Unable to parse date for line: " + dateline); + returnDate = null; + } + } + + return returnDate; + } + + + public static String parseRemoteSystem(String line) { + + if (line.contains("http") && !(line.contains("www.w3.org"))){ + + Pattern pattern = Pattern.compile("://(.+?)/"); + Matcher remote = pattern.matcher(line); + if (remote.find()) + { + return remote.group(1); + } + } + return null; + } + + public static String[] getPaths(String logPath){ + + if(logPath != null && !logPath.isEmpty()){ + if(logPath.contains(";")){ + return logPath.split(";"); + }else{ + String[] oneFile = new String[1]; + oneFile[0] = logPath; + return oneFile; + } + } + + return null; + } + + public static Properties getPropertiesValue(String fileName) { + Properties config = new Properties(); + Path file = Paths.get(fileName); + if (Files.notExists(file)) { + logger.debug("File doesn't exist in the specified Path " + file.toString()); + }else{ + if (file.toString().endsWith(".properties")) { + InputStream in; + try { + in = new FileInputStream(file.toFile()); + config.load(in); + + resourceName = config.getProperty("RESOURCE_NAME"); + system = config.getProperty("SERVER"); + type = config.getProperty("LOGTYPE"); + systemLogFile = config.getProperty("PARSERLOGPATH"); + String logFiles = config.getProperty("LOGPATH"); + if(logFiles == null || logFiles.isEmpty()){ + isMissingLogFile = true; + return null; + } + + String[] splitString = getPaths(logFiles); + + if(splitString != null){ + for(int i=0; i < splitString.length; i++){ + + if(splitString[i].contains("debug")){ + // get path of debug.log file + debuglogFile = splitString[i]; + if(debuglogFile != null && !debuglogFile.isEmpty()){ + debuglogFile = debuglogFile.trim(); + } + }else if(splitString[i].contains("error")){ + // get path of error.log file + errorlogFile = splitString[i]; + if(errorlogFile != null && !errorlogFile.isEmpty()){ + errorlogFile = errorlogFile.trim(); + } + }else { + // get path of default file + logFile = splitString[i]; + if(logFile != null && !logFile.isEmpty()){ + logFile = logFile.trim(); + } + } + } + }else{ + + debuglogFile = null; + errorlogFile = null; + logFile = null; + } + + JDBC_URL = config.getProperty("JDBC_URL").replace("'", ""); + JDBC_USER = config.getProperty("JDBC_USER"); + JDBC_DRIVER = config.getProperty("JDBC_DRIVER"); + JDBC_PASSWORD = config.getProperty("JDBC_PASSWORD"); + return config; + + } catch (IOException e) { + logger.debug("Error porcessing Config file will be unable to create Health Check" + e); + } + + } + } + return null; + } +} \ No newline at end of file diff --git a/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java b/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java deleted file mode 100644 index 3b1ccffc5..000000000 --- a/LogParser/src/main/java/org/openecomp/xacml/parser/LogEntryObject.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * LogParser - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.xacml.parser; - -import java.util.Date; - -public class LogEntryObject { - - private String system; - private String description; - private Date date; - private String remote; - private String systemType; - private LOGTYPE logType; - - public enum LOGTYPE { - INFO, DEBUG, ERROR, SEVERE, WARN; - } - - public String getSystem() { - return system; - } - public void setSystem(String system) { - this.system = system; - } - public String getDescription() { - return description; - } - public void setDescription(String description) { - this.description = description; - } - public Date getDate() { - return date; - } - public void setDate(Date date) { - this.date = date; - } - public String getRemote() { - return remote; - } - public void setRemote(String remote) { - this.remote = remote; - } - public String getSystemType() { - return systemType; - } - public void setSystemType(String systemType) { - this.systemType = systemType; - } - public LOGTYPE getLogType() { - return logType; - } - public void setLogType(LOGTYPE logType) { - this.logType = logType; - } -} \ No newline at end of file diff --git a/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java deleted file mode 100644 index b0a5f677d..000000000 --- a/LogParser/src/main/java/org/openecomp/xacml/parser/ParseLog.java +++ /dev/null @@ -1,695 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * LogParser - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.xacml.parser; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.LineNumberReader; -import java.io.RandomAccessFile; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import java.text.Format; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.stream.Stream; - -import org.apache.log4j.Logger; -import org.openecomp.policy.common.im.AdministrativeStateException; -import org.openecomp.policy.common.im.IntegrityMonitor; -import org.openecomp.policy.common.im.StandbyStatusException; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; - -/** - * Parse log files and store the information in a H2 database. - * - * - */ -public class ParseLog { - - // only logging last line of each log file processed to the log4j log file defined by property - PARSERLOGPATH - private static final Logger log4jlogger = Logger.getLogger(ParseLog.class.getName()); - - // processing logging - private static org.openecomp.policy.common.logging.flexlogger.Logger logger = FlexLogger.getLogger(ParseLog.class.getName()); - - private static String system; - private static int lastNumberRead = 0; - private static int debuglastNumberRead = 0; - private static int errorlastNumberRead = 0; - private static String type; - private static long startFileSize; - private static long debugStartFileSize; - private static long errorStartFileSize; - private static String systemLogFile; - private static String logFile; - private static String debuglogFile; - private static String errorlogFile; - private static String JDBC_URL; - private static String JDBC_USER; - private static String JDBC_PASSWORD; - private static String JDBC_DRIVER; - private static int maxLength = 255; //Max length that is allowed in the DB table - private static String resourceName; - private static long sleepTimer = 50000; - static IntegrityMonitor im; - private static boolean isMissingLogFile; - - private static RandomAccessFile randomAccessFile; - - public static void main(String[] args) throws Exception { - - Properties logProperties = getPropertiesValue("parserlog.properties"); - - if(logProperties == null || isMissingLogFile){ - // missing the path of log file in the properties file, so stop the process - logger.error("logProperties is null or LOGPATH is missing in parserlog.properties, so stop the process."); - return; - } - - File fileLog = new File(systemLogFile); - - im = IntegrityMonitor.getInstance(resourceName,logProperties ); - - startDebugLogParser(fileLog); - startErrorLogParser(fileLog); - startAPIRestLogParser(fileLog); - - } - - private static void startDebugLogParser(File fileLog){ - try{ - if(debuglogFile != null && !debuglogFile.isEmpty()){ - - // pull the last line number - String dataFileName = "debug.log"; - String filesRead = PullLastLineRead(fileLog, dataFileName); - if (filesRead!= null){ - filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); - debuglastNumberRead= Integer.parseInt(filesRead.trim()); - }else{ - debuglastNumberRead = 0; - } - - debugStartFileSize = countLines(debuglogFile); - if (debugStartFileSize < debuglastNumberRead ){ - logger.error("Filed Rolled: set Last debug number read to 0"); - debuglastNumberRead = 0; - } - - isMissingLogFile = false; - Path debugfilePath = Paths.get(debuglogFile); - File debugfile = new File(debuglogFile); - debugStartFileSize = debugfile.length(); - // start process debug.log file - - Runnable runnable = new Runnable (){ - boolean isStop = false; - - public void run(){ - while (!isStop){ - - if (debugfile.isFile()){ - // log4jlogger must use .info - Stream lines = null; - try { - lines = Files.lines(debugfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + debuglastNumberRead)).skip(debuglastNumberRead); - lines.forEachOrdered(line -> process(line, type, LOGTYPE.DEBUG)); - } catch (IOException e) { - logger.error("Error processing line in " + dataFileName + ":" + e); - logger.error("break the loop."); - isStop = true; - }finally{ - if(lines != null){ - lines.close(); - } - } - } - try { - Thread.sleep(sleepTimer); - debugStartFileSize = countLines(debuglogFile); - } catch (InterruptedException | IOException e) { - logger.error("Error processing line in " + dataFileName + ":" + e); - logger.error("break the loop."); - isStop = true; - } - - logger.debug("File Line Count of debug.log: " + debugStartFileSize + " value read in: " + debuglastNumberRead); - if (debugStartFileSize < debuglastNumberRead ){ - logger.debug("Failed Rolled: set Last number read to 0"); - debuglastNumberRead = 0; - } - } - } - }; - - Thread thread = new Thread(runnable); - thread.start(); - - } - }catch(Exception e){ - logger.error("Exception occured in DebugLogParser" +e); - } - } - - private static void startErrorLogParser(File fileLog){ - try{ - if(errorlogFile != null && !errorlogFile.isEmpty()){ - - // pull the last line number - String dataFileName = "error.log"; - String filesRead = PullLastLineRead(fileLog, dataFileName); - if (filesRead!= null){ - filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); - errorlastNumberRead= Integer.parseInt(filesRead.trim()); - }else{ - errorlastNumberRead = 0; - } - - errorStartFileSize = countLines(errorlogFile); - if (errorStartFileSize < errorlastNumberRead ){ - logger.error("Filed Rolled: set Last error number read to 0"); - errorlastNumberRead = 0; - } - - isMissingLogFile = false; - Path errorfilePath = Paths.get(errorlogFile); - File errorfile = new File(errorlogFile); - errorStartFileSize = errorfile.length(); - // start process error.log file - Runnable runnable = new Runnable (){ - boolean isStop = false; - public void run(){ - - while (!isStop){ - if (errorfile.isFile()){ - // log4jlogger must use .info - Stream lines = null; - try{ - lines = Files.lines(errorfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + errorlastNumberRead)).skip(errorlastNumberRead); - lines.forEachOrdered(line -> process(line, type, LOGTYPE.ERROR)); - } catch (IOException e) { - logger.error("Error processing line in " + dataFileName + ":" + e); - logger.error("break the loop."); - isStop = true; - }finally{ - if(lines != null){ - lines.close(); - } - } - } - try { - Thread.sleep(sleepTimer); - errorStartFileSize = countLines(errorlogFile); - } catch (InterruptedException | IOException e) { - logger.error("Error processing line in " + dataFileName + ":" + e); - logger.error("break the loop."); - isStop = true; - } - - logger.debug("File Line Count of error.log: " + errorStartFileSize + " value read in: " + errorlastNumberRead); - if (errorStartFileSize < errorlastNumberRead ){ - logger.debug("Failed Rolled: set Last error number read to 0"); - errorlastNumberRead = 0; - } - } - } - }; - - Thread thread = new Thread(runnable); - thread.start(); - } - }catch(Exception e){ - logger.error("Exception occured in startErrorLogParser" +e); - } - } - - private static void startAPIRestLogParser(File fileLog){ - try{ - if(logFile != null && !logFile.isEmpty()){ - - // pull the last line number - String dataFileName = type.toLowerCase()+"-rest.log"; - String filesRead = PullLastLineRead(fileLog, dataFileName); - if (filesRead!= null){ - filesRead = filesRead.replaceAll("(\\r\\n|\\n)", "
"); - lastNumberRead= Integer.parseInt(filesRead.trim()); - }else{ - lastNumberRead = 0; - } - startFileSize = countLines(logFile); - if (startFileSize < lastNumberRead ){ - logger.error("Filed Rolled: set Last number read to 0"); - lastNumberRead = 0; - } - - isMissingLogFile = false; - Path filePath = Paths.get(logFile); - File file = new File(logFile); - startFileSize = file.length(); - // start process pap/pdp-rest.log file - Runnable runnable = new Runnable () { - boolean isStop = false; - public void run(){ - while (!isStop){ - - if (file.isFile()){ - // log4jlogger must use .info - Stream lines = null;; - try { - lines = Files.lines(filePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info("Last-"+dataFileName+"-line-Read:" + lastNumberRead)).skip(lastNumberRead); - lines.forEachOrdered(line -> process(line, type, LOGTYPE.INFO)); - } catch (IOException e) { - logger.error("Error processing line in " + dataFileName + ":" + e); - logger.error("break the loop."); - isStop = true; - }finally{ - if(lines != null){ - lines.close(); - } - } - } - try { - Thread.sleep(sleepTimer); - startFileSize = countLines(logFile); - } catch (InterruptedException | IOException e) { - logger.error("Error processing line in " + dataFileName + ":" + e); - logger.error("break the loop."); - isStop = true; - } - - logger.debug("File Line Count of " + dataFileName+": " + startFileSize + " value read in: " + lastNumberRead); - if (startFileSize < lastNumberRead ){ - logger.debug("Failed Rolled: set Last number read to 0"); - lastNumberRead = 0; - } - } - } - }; - - Thread thread = new Thread(runnable); - thread.start(); - } - }catch(Exception e){ - logger.error("Exception occured in StartAPIRestLogParser" +e); - } - } - - public static int countLines(String filename) throws IOException { - LineNumberReader reader = new LineNumberReader(new FileReader(filename)); - int cnt = 0; - String line= null; - while ((line = reader.readLine()) != null) { - logger.info("Reading the Logs"+line); - } - cnt = reader.getLineNumber(); - reader.close(); - return cnt; - } - - public static String PullLastLineRead(File file, String dataFileName) throws IOException { - if(!file.exists()){ - file.createNewFile(); - return null; - } - randomAccessFile = new RandomAccessFile(file, "r"); - StringBuilder builder = new StringBuilder(); - long length = file.length(); - logger.debug("dataFileName: " +dataFileName); - if(length > 0){ - length--; - randomAccessFile.seek(length); - for(long seek = length; seek >= 0; --seek){ - randomAccessFile.seek(seek); - char c = (char)randomAccessFile.read(); - builder.append(c); - if(c == '\n'){ - builder = builder.reverse(); - logger.debug("builder.toString(): " +builder.toString()); - if (builder.toString().contains("Last-"+dataFileName+"-line-Read:")){ - String[] parseString = builder.toString().split("Last-"+dataFileName+"-line-Read:"); - String returnValue = parseString[1].replace("\r", ""); - return returnValue.trim(); - } - builder = null; - builder = new StringBuilder(); - } - } - } - - return null; - } - - public static LogEntryObject pullOutLogValues(String line, String type){ - Date date; - LogEntryObject logEntry = new LogEntryObject(); - String description = ""; - logEntry.setSystemType(type); - logEntry.setSystem(system); - logger.debug("In pullOutLogValues ..."); - //Values for PDP/PAP debug.log file contains "INFO:", error.log file contains ""ERROR:", others are in PDP/PAP rest log file - if(line.contains("||INFO||") || line.contains("||ERROR||") || line.contains("INFO:") || line.contains("ERROR:")){ - String[] splitString = null; - if(line.contains("||INFO||") || line.contains("||ERROR||")){ - splitString = line.split("[||]"); - }else if(line.contains("INFO:")){ - splitString = line.split("INFO:"); - }else{ - splitString = line.split("ERROR:"); - } - String dateString = splitString[0].substring(0, 19); - logEntry.setDescription(splitString[splitString.length-1]); - - //parse out date - date = parseDate(dateString.replace("T", " "), "yyyy-MM-dd HH:mm:ss", false); - logEntry.setDate(date); - - logEntry.setRemote(parseRemoteSystem(line)); - if (line.contains("INFO:") || line.contains("||INFO||")){ - logEntry.setLogType(LOGTYPE.INFO); - }else{ - logEntry.setLogType(LOGTYPE.ERROR); - } - // from PDP/PAP rest log file below - }else if (line.contains("INFO") && line.contains(")-")){ - //parse out description - logEntry.setDescription(line.substring(line.indexOf(")-")+3)); - - date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); - logEntry.setDate(date); - - logEntry.setRemote(parseRemoteSystem(line)); - logEntry.setLogType(LOGTYPE.INFO); - } else if (line.contains("INFO") && line.contains("--- [")){ - //parse out description - String temp = line.substring(line.indexOf("---")+1); - String[] split = temp.split(":"); - - logEntry.setDescription(split[1]); - - //parse out date - date = parseDate(line, "yyyy-MM-dd HH:mm:ss", false); - logEntry.setDate(date); - - //remote system - logEntry.setRemote(parseRemoteSystem(line)); - logEntry.setLogType(LOGTYPE.INFO); - }else if (line.contains("SEVERE") && line.contains("[main]")){ - String[] splitString = line.split(" "); - - for (int i = 5; i < splitString.length; i++){ - description = description + " " + splitString[i]; - } - - logEntry.setDescription(description); - //parse out date - date = parseDate(line, "dd-MMM-yyyy HH:mm:ss", false); - logEntry.setDate(date); - logEntry.setLogType(LOGTYPE.SEVERE); - } else if (line.contains("WARN") && line.contains(")-")){ - //parse out description - - logEntry.setDescription(line.substring(line.indexOf(")-")+3)); - - //parse out date - date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); - logEntry.setDate(date); - - //remote system - logEntry.setRemote(parseRemoteSystem(line)); - logEntry.setLogType(LOGTYPE.WARN); - }else if (line.contains("WARNING") && type =="PyPDP"){ - String[] splitString = line.split(" "); - for (int i = 5; i < splitString.length; i++){ - description = description + " " + splitString[i]; - } - - //parse out date - date = parseDate(line, "dd-MMM-yyyy HH:mm:ss", false); - logEntry.setDate(date); - logEntry.setLogType(LOGTYPE.WARN); - }else if (line.contains("ERROR") && line.contains(")-")){ - //parse out description - description = line.substring(line.indexOf(")-")+3); - - //parse out date - date = parseDate(line, "yy_MM_dd_HH_mm_ss", true); - logEntry.setDate(date); - //remote system - logEntry.setRemote(parseRemoteSystem(line)); - logEntry.setLogType(LOGTYPE.ERROR); - }else { - return null; - } - - return logEntry; - } - - private static void DBClose(Connection conn) { - try { - conn.close(); - } catch (SQLException e) { - logger.error("Error closing DB Connection: " + e); - - } - } - - public static void process(String line, String type, LOGTYPE logFile) { - - logger.debug("In process: processing line : " + line); - LogEntryObject returnLogValue = null; - if (im!=null){ - try { - im.startTransaction(); - } catch (AdministrativeStateException e) { - logger.error("Error received" + e); - } catch (StandbyStatusException e) { - logger.error("Error received" + e); - } - } - returnLogValue = pullOutLogValues(line, type); - - if(logFile.equals(LOGTYPE.DEBUG)){ - debuglastNumberRead++; - }else if(logFile.equals(LOGTYPE.ERROR)){ - errorlastNumberRead++; - }else if(logFile.equals(LOGTYPE.INFO)){ - lastNumberRead++; - } - if (returnLogValue!=null){ - writeDB(returnLogValue); - } - if (im!=null){ - im.endTransaction(); - } - } - - private static void writeDB(LogEntryObject returnLogValue) { - - Connection conn = DBConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); - DBAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(), - returnLogValue.getDate(), returnLogValue.getRemote(), - returnLogValue.getSystemType(), returnLogValue.getLogType().toString()); - DBClose(conn); - } - - private static Connection DBConnection(String driver, String jdbc, String user, String pass){ - - try { - Class.forName(driver); - Connection conn = DriverManager.getConnection(jdbc, user, pass); - return conn; - } catch ( Exception e) { - logger.error("Error connecting to DB: " + e); - } - return null; - } - private static void DBAccesss(Connection conn, String system, String description, Date date, String remote, String type, String logType) { - - String sdate = null; - - if (date!=null){ - Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - sdate = formatter.format(date); - logger.debug("DBAccesss : sdate : " + sdate); - }else{ - logger.debug("DBAccesss : sdate is null"); - } - - //ensure the length of description is less than the maximumm db char length - if (description.length() > maxLength) { - description = description.substring(0, maxLength); - } - - try { - PreparedStatement prep = conn.prepareStatement("insert into SYSTEMLOGDB values (NULL, ?, ?, ?, ?, ?, ?);"); - prep.setString(1, system); - prep.setString(2, description); - prep.setString(3, remote); - prep.setString(4, type); - prep.setString(5, sdate); - prep.setString(6, logType); - - prep.executeUpdate(); - prep.close(); - - } catch (SQLException e1) { - logger.error("Error trying to excute SQL Statment: " + e1); - } - } - - public static Date parseDate(String dateline, String pattern, boolean singleSplit) { - - Date returnDate; - String[] splitString = dateline.split(" "); - SimpleDateFormat formatter = new SimpleDateFormat(pattern); - if (singleSplit){ - try { - returnDate = formatter.parse(splitString[0]); - } catch (ParseException e) { - logger.error("Unable to parse date for line: " + dateline); - returnDate = null; - } - }else{ - String tmpString = splitString[0] + " " + splitString[1]; - try { - returnDate = formatter.parse(tmpString); - } catch (ParseException e) { - logger.error("Unable to parse date for line: " + dateline); - returnDate = null; - } - } - - return returnDate; - } - - - public static String parseRemoteSystem(String line) { - - if (line.contains("http") && !(line.contains("www.w3.org"))){ - - Pattern pattern = Pattern.compile("://(.+?)/"); - Matcher remote = pattern.matcher(line); - if (remote.find()) - { - return remote.group(1); - } - } - return null; - } - - public static String[] getPaths(String logPath){ - - if(logPath != null && !logPath.isEmpty()){ - if(logPath.contains(";")){ - return logPath.split(";"); - }else{ - String[] oneFile = new String[1]; - oneFile[0] = logPath; - return oneFile; - } - } - - return null; - } - - public static Properties getPropertiesValue(String fileName) { - Properties config = new Properties(); - Path file = Paths.get(fileName); - if (Files.notExists(file)) { - logger.debug("File doesn't exist in the specified Path " + file.toString()); - }else{ - if (file.toString().endsWith(".properties")) { - InputStream in; - try { - in = new FileInputStream(file.toFile()); - config.load(in); - - resourceName = config.getProperty("RESOURCE_NAME"); - system = config.getProperty("SERVER"); - type = config.getProperty("LOGTYPE"); - systemLogFile = config.getProperty("PARSERLOGPATH"); - String logFiles = config.getProperty("LOGPATH"); - if(logFiles == null || logFiles.isEmpty()){ - isMissingLogFile = true; - return null; - } - - String[] splitString = getPaths(logFiles); - - if(splitString != null){ - for(int i=0; i < splitString.length; i++){ - - if(splitString[i].contains("debug")){ - // get path of debug.log file - debuglogFile = splitString[i]; - if(debuglogFile != null && !debuglogFile.isEmpty()){ - debuglogFile = debuglogFile.trim(); - } - }else if(splitString[i].contains("error")){ - // get path of error.log file - errorlogFile = splitString[i]; - if(errorlogFile != null && !errorlogFile.isEmpty()){ - errorlogFile = errorlogFile.trim(); - } - }else { - // get path of default file - logFile = splitString[i]; - if(logFile != null && !logFile.isEmpty()){ - logFile = logFile.trim(); - } - } - } - }else{ - - debuglogFile = null; - errorlogFile = null; - logFile = null; - } - - JDBC_URL = config.getProperty("JDBC_URL").replace("'", ""); - JDBC_USER = config.getProperty("JDBC_USER"); - JDBC_DRIVER = config.getProperty("JDBC_DRIVER"); - JDBC_PASSWORD = config.getProperty("JDBC_PASSWORD"); - return config; - - } catch (IOException e) { - logger.debug("Error porcessing Config file will be unable to create Health Check" + e); - } - - } - } - return null; - } -} \ No newline at end of file diff --git a/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java new file mode 100644 index 000000000..3cf3d188f --- /dev/null +++ b/LogParser/src/test/java/org/onap/xacml/parser/ParseLogTest.java @@ -0,0 +1,506 @@ +/*- + * ============LICENSE_START======================================================= + * LogParser + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.xacml.parser; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Date; +import java.util.Properties; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.policy.common.im.AdministrativeStateException; +import org.onap.policy.common.im.IntegrityMonitor; +import org.onap.policy.common.im.StandbyStatusException; +import org.onap.policy.common.logging.flexlogger.FlexLogger; +import org.onap.policy.common.logging.flexlogger.Logger; +import org.onap.xacml.parser.LogEntryObject.LOGTYPE; + + +public class ParseLogTest { + + private static Logger logger = FlexLogger.getLogger(ParseLogTest.class); + private Properties config = new Properties(); + private String configFile; + private String testFile1; + private String testFile2; + private IntegrityMonitor im; + + @Before + public void setUp() throws Exception { + System.setProperty("com.sun.management.jmxremote.port", "9998"); + im = Mockito.mock(IntegrityMonitor.class); + + try { + Mockito.doNothing().when(im).startTransaction(); + } catch (StandbyStatusException | AdministrativeStateException e) { + fail(); + } + Mockito.doNothing().when(im).endTransaction(); + ClassLoader classLoader = getClass().getClassLoader(); + configFile = classLoader.getResource("test_config.properties").getFile(); + if(configFile.startsWith("/C:/")){ + configFile = configFile.substring(1); + } + testFile1 = classLoader.getResource("LineTest.txt").getFile(); + testFile2 = classLoader.getResource("LineTest2.txt").getFile(); + + } + + @After + public void tearDown() { + + logger.debug("tearDown: enter"); + + File file = new File("nonExistFile.txt"); + file.delete(); + logger.debug("tearDown: exit"); + } + + @Test + public void testCountLines() throws IOException { + + logger.debug("testCountLines: enter"); + + int returnValue = ParseLog.countLines(testFile1); + logger.debug("testCountLines: returnValue: " + returnValue); + assertEquals(12, returnValue); + + logger.debug("testCountLines: exit"); + } + + @Test + public void testParseRemoteSystem() { + + logger.debug("testParseRemoteSystem: enter"); + + String line = "||org.onap.policy.pap.xacml.rest.XACMLPapServlet$Heartbeat.run(XACMLPapServlet.java:2801)||Heartbeat 'https://localhost:8081/pdp/' status='UP_TO_DATE'"; + String returnValue = ParseLog.parseRemoteSystem(line); + logger.debug("testParseRemoteSystem: returnValue: " + returnValue); + assertEquals("localhost:8081", returnValue); + + logger.debug("testParseRemoteSystem: exit"); + } + + @Test + public void testGetPropertiesValue() { + + logger.debug("testGetPropertiesValue: enter"); + + config = new Properties(); + config.put("RESOURCE_NAME", "logparser_pap01"); + config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); + config.put("JDBC_URL", "jdbc:mysql://localhost:3306/"); + config.put("JDBC_USER", "root"); + config.put("JDBC_PASSWORD", "password"); + config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); + config.put("SERVER", "password"); + config.put("JDBC_PASSWORD", "https://localhost:9091/pap/"); + config.put("LOGTYPE", "PAP"); + config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\pap-rest.log"); + config.put("PARSERLOGPATH", "IntegrityMonitor.log"); + + Properties returnConfig = ParseLog.getPropertiesValue(configFile); + logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig); + assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); + + logger.debug("testGetPropertiesValue: exit"); + } + + @Test + public void testGetPropertiesFail() { + + logger.debug("testGetPropertiesFail: enter"); + + Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); + logger.debug("testGetPropertiesFail: returnValue: " + returnValue); + assertEquals(null, returnValue); + + logger.debug("testGetPropertiesFail: exit"); + } + + @Test + public void testParseDate(){ + + logger.debug("testParseDate: enter"); + + String line = "2016-02-23 08:07:30"; + Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", false); + logger.debug("testParseDate: returnValue: " + returnValue); + line = returnValue.toString().substring(0, returnValue.toString().lastIndexOf(":30")+3); + assertEquals("Tue Feb 23 08:07:30", line); + + logger.debug("testParseDate: exit"); + } + + @Test + public void testParseDateFail(){ + + logger.debug("testParseDateFail: enter"); + + String line = "2016-02-23 08:07:30"; + Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", true); + logger.debug("testParseDateFail: returnValue: " + returnValue); + assertEquals(null, returnValue); + + logger.debug("testParseDateFail: exit"); + } + + @Test + public void testPullLastLineRead(){ + + logger.debug("testPullLastLineRead: enter"); + File file = new File(testFile1); + String returnValue = null; + try { + returnValue = ParseLog.PullLastLineRead(file, "pap-rest.log"); + logger.debug("testPullLastLineRead: returnValue for pap-rest.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("52", returnValue); + + try { + returnValue = ParseLog.PullLastLineRead(file, "debug.log"); + logger.debug("testPullLastLineRead: returnValue for debug.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("17", returnValue); + + try { + returnValue = ParseLog.PullLastLineRead(file, "error.log"); + logger.debug("testPullLastLineRead: returnValue for error.log: " + returnValue); + } catch (IOException e) { + fail(); + } + assertEquals("22", returnValue); + + logger.debug("testPullLastLineRead: exit"); + } + + @Test + public void testPullLastLineReadNoFile(){ + + logger.debug("testPullLastLineReadNoFile: enter"); + + File file = new File("nonExistFile.txt"); + try { + assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullLastLineReadNoFile: exit"); + } + + @Test + public void testPullLastLineReadFail(){ + + logger.debug("testPullLastLineReadFail: enter"); + + File file = new File(testFile2); + try { + assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullLastLineReadFail: exit"); + } + + @Test + public void testPullOutLogValues(){ + + logger.debug("testPullOutLogValues: enter"); + //ERROR_VALUE + // Open the file + FileInputStream fstream; + try { + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "ERROR"); + assertEquals("ERROR_VALUE", retrunObject.getDescription()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValues: exit"); + } + + @Test + public void testGetPaths(){ + + logger.debug("testGetPaths: enter"); + + try { + // valid test + String logPaths = "C:\\pap-log\\pap-rest.log;C:\\pap-log\\debug.log;C:\\pap-log\\error.log"; + String [] retrunObject = ParseLog.getPaths(logPaths); + assertEquals(3, retrunObject.length); + + // valid test + logPaths = "C:\\pap-log\\pap-rest.log"; + retrunObject = ParseLog.getPaths(logPaths); + assertEquals(1, retrunObject.length); + + // invalid test + logPaths = ""; + retrunObject = ParseLog.getPaths(logPaths); + assertTrue(retrunObject == null); + + } catch (Exception e) { + fail(); + } + + logger.debug("testGetPaths: exit"); + } + + @Test + public void testPullOutLogValuesSecond(){ + + logger.debug("testPullOutLogValuesSecond: enter"); + //ERROR_VALUE + // Open the file + FileInputStream fstream; + try { + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + strLine = br.readLine(); + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "INFO"); + assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesSecond: exit"); + } + + @Test + public void testPullOutLogValuesThird(){ + + logger.debug("testPullOutLogValuesThird: enter"); + //ERROR_VALUE + // Open the file + FileInputStream fstream; + try { + int number = 3; + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PAP"); + assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesThird: exit"); + } + + @Test + public void testPullOutLogValuesFourth(){ + + logger.debug("testPullOutLogValuesFourth: enter"); + // Open the file + FileInputStream fstream; + try { + int number = 4; + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PAP"); + assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesFourth: exit"); + } + + @Test + public void testPullOutLogValuesFith(){ + + logger.debug("testPullOutLogValuesFith: enter"); + // Open the file + FileInputStream fstream; + try { + int number = 5; + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PyPDP"); + assertEquals(LOGTYPE.WARN, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesFith: exit"); + } + + @Test + public void testPullOutLogValuesSixth(){ + + logger.debug("testPullOutLogValuesSixth: enter"); + // Open the file + FileInputStream fstream; + try { + int number = 6; + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PyPDP"); + assertEquals(LOGTYPE.SEVERE, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesSixth: exit"); + } + + @Test + public void testPullOutLogValuesSeven(){ + + logger.debug("testPullOutLogValuesSeven: enter"); + // Open the file + FileInputStream fstream; + try { + int number = 7; + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "Console"); + assertEquals(LOGTYPE.ERROR, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesSeven: exit"); + } + + @Test + public void testPullOutLogValuesEight(){ + + logger.debug("testPullOutLogValuesEight: enter"); + // Open the file + FileInputStream fstream; + try { + int number = 8; + fstream = new FileInputStream(testFile1); + BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); + String strLine = br.readLine(); + for (int i =0; i < number; i++){ + strLine = br.readLine(); + } + LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "pap"); + assertEquals(LOGTYPE.WARN, retrunObject.getLogType()); + br.close(); + } catch (IOException e) { + fail(); + } + + logger.debug("testPullOutLogValuesEight: exit"); + } + + @Test + public void testPullOutLogValuesNull(){ + + logger.debug("testPullOutLogValuesNull: enter"); + // Open the file + LogEntryObject retrunObject = ParseLog.pullOutLogValues("", "Console"); + assertEquals(null, retrunObject); + + logger.debug("testPullOutLogValuesNull: exit"); + } + + @Test + public void testLogEntryObject(){ + + logger.debug("testLogEntryObject: enter"); + + Date date = new Date(); + + // Open the file + LogEntryObject logObject = new LogEntryObject(); + logObject.setSystem("vm02"); + logObject.setSystemType("pap"); + logObject.setDate(date); + logObject.setRemote("remote"); + + assertEquals("vm02", logObject.getSystem()); + assertEquals("pap", logObject.getSystemType()); + assertEquals(date, logObject.getDate()); + assertEquals("remote", logObject.getRemote()); + + logger.debug("testLogEntryObject: exit"); + } + + @Test + public void testProcess(){ + + logger.debug("testProcess: enter"); + + String line = "2015-04-01 09:13:44.947 DEBUG 17482 --- [nio-8480-exec-7] c.a.l.onap.policy.std.StdPolicyConfig : config Retrieved "; + + im = Mockito.mock(IntegrityMonitor.class); + try { + Mockito.doNothing().when(im).startTransaction(); + } catch (StandbyStatusException | AdministrativeStateException e) { + fail(); + } + Mockito.doNothing().when(im).endTransaction(); + ParseLog.process(line, "pap", LOGTYPE.INFO); + + logger.debug("testProcess: exit"); + } +} \ No newline at end of file diff --git a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java b/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java deleted file mode 100644 index 2bd70f2be..000000000 --- a/LogParser/src/test/java/org/openecomp/xacml/parser/ParseLogTest.java +++ /dev/null @@ -1,506 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * LogParser - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.xacml.parser; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.Date; -import java.util.Properties; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.policy.common.im.AdministrativeStateException; -import org.openecomp.policy.common.im.IntegrityMonitor; -import org.openecomp.policy.common.im.StandbyStatusException; -import org.openecomp.policy.common.logging.flexlogger.FlexLogger; -import org.openecomp.policy.common.logging.flexlogger.Logger; -import org.openecomp.xacml.parser.LogEntryObject.LOGTYPE; - - -public class ParseLogTest { - - private static Logger logger = FlexLogger.getLogger(ParseLogTest.class); - private Properties config = new Properties(); - private String configFile; - private String testFile1; - private String testFile2; - private IntegrityMonitor im; - - @Before - public void setUp() throws Exception { - System.setProperty("com.sun.management.jmxremote.port", "9998"); - im = Mockito.mock(IntegrityMonitor.class); - - try { - Mockito.doNothing().when(im).startTransaction(); - } catch (StandbyStatusException | AdministrativeStateException e) { - fail(); - } - Mockito.doNothing().when(im).endTransaction(); - ClassLoader classLoader = getClass().getClassLoader(); - configFile = classLoader.getResource("test_config.properties").getFile(); - if(configFile.startsWith("/C:/")){ - configFile = configFile.substring(1); - } - testFile1 = classLoader.getResource("LineTest.txt").getFile(); - testFile2 = classLoader.getResource("LineTest2.txt").getFile(); - - } - - @After - public void tearDown() { - - logger.debug("tearDown: enter"); - - File file = new File("nonExistFile.txt"); - file.delete(); - logger.debug("tearDown: exit"); - } - - @Test - public void testCountLines() throws IOException { - - logger.debug("testCountLines: enter"); - - int returnValue = ParseLog.countLines(testFile1); - logger.debug("testCountLines: returnValue: " + returnValue); - assertEquals(12, returnValue); - - logger.debug("testCountLines: exit"); - } - - @Test - public void testParseRemoteSystem() { - - logger.debug("testParseRemoteSystem: enter"); - - String line = "||org.openecomp.policy.pap.xacml.rest.XACMLPapServlet$Heartbeat.run(XACMLPapServlet.java:2801)||Heartbeat 'https://localhost:8081/pdp/' status='UP_TO_DATE'"; - String returnValue = ParseLog.parseRemoteSystem(line); - logger.debug("testParseRemoteSystem: returnValue: " + returnValue); - assertEquals("localhost:8081", returnValue); - - logger.debug("testParseRemoteSystem: exit"); - } - - @Test - public void testGetPropertiesValue() { - - logger.debug("testGetPropertiesValue: enter"); - - config = new Properties(); - config.put("RESOURCE_NAME", "logparser_pap01"); - config.put("JDBC_DRIVER" ,"com.mysql.jdbc.Driver"); - config.put("JDBC_URL", "jdbc:mysql://localhost:3306/"); - config.put("JDBC_USER", "root"); - config.put("JDBC_PASSWORD", "password"); - config.put("JMX_URL", "service:jmx:rmi:///jndi/rmi://localhost:9998/jmxrmi"); - config.put("SERVER", "password"); - config.put("JDBC_PASSWORD", "https://localhost:9091/pap/"); - config.put("LOGTYPE", "PAP"); - config.put("LOGPATH", "C:\\Workspaces\\HealthCheck\\pap-rest.log"); - config.put("PARSERLOGPATH", "IntegrityMonitor.log"); - - Properties returnConfig = ParseLog.getPropertiesValue(configFile); - logger.debug("testGetPropertiesValue: returnConfig: " + returnConfig); - assertEquals(config.get("RESOURCE_NAME"), returnConfig.get("RESOURCE_NAME")); - - logger.debug("testGetPropertiesValue: exit"); - } - - @Test - public void testGetPropertiesFail() { - - logger.debug("testGetPropertiesFail: enter"); - - Properties returnValue = ParseLog.getPropertiesValue("nonExistFile"); - logger.debug("testGetPropertiesFail: returnValue: " + returnValue); - assertEquals(null, returnValue); - - logger.debug("testGetPropertiesFail: exit"); - } - - @Test - public void testParseDate(){ - - logger.debug("testParseDate: enter"); - - String line = "2016-02-23 08:07:30"; - Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", false); - logger.debug("testParseDate: returnValue: " + returnValue); - line = returnValue.toString().substring(0, returnValue.toString().lastIndexOf(":30")+3); - assertEquals("Tue Feb 23 08:07:30", line); - - logger.debug("testParseDate: exit"); - } - - @Test - public void testParseDateFail(){ - - logger.debug("testParseDateFail: enter"); - - String line = "2016-02-23 08:07:30"; - Date returnValue = ParseLog.parseDate(line, "yyyy-MM-dd HH:mm:ss", true); - logger.debug("testParseDateFail: returnValue: " + returnValue); - assertEquals(null, returnValue); - - logger.debug("testParseDateFail: exit"); - } - - @Test - public void testPullLastLineRead(){ - - logger.debug("testPullLastLineRead: enter"); - File file = new File(testFile1); - String returnValue = null; - try { - returnValue = ParseLog.PullLastLineRead(file, "pap-rest.log"); - logger.debug("testPullLastLineRead: returnValue for pap-rest.log: " + returnValue); - } catch (IOException e) { - fail(); - } - assertEquals("52", returnValue); - - try { - returnValue = ParseLog.PullLastLineRead(file, "debug.log"); - logger.debug("testPullLastLineRead: returnValue for debug.log: " + returnValue); - } catch (IOException e) { - fail(); - } - assertEquals("17", returnValue); - - try { - returnValue = ParseLog.PullLastLineRead(file, "error.log"); - logger.debug("testPullLastLineRead: returnValue for error.log: " + returnValue); - } catch (IOException e) { - fail(); - } - assertEquals("22", returnValue); - - logger.debug("testPullLastLineRead: exit"); - } - - @Test - public void testPullLastLineReadNoFile(){ - - logger.debug("testPullLastLineReadNoFile: enter"); - - File file = new File("nonExistFile.txt"); - try { - assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullLastLineReadNoFile: exit"); - } - - @Test - public void testPullLastLineReadFail(){ - - logger.debug("testPullLastLineReadFail: enter"); - - File file = new File(testFile2); - try { - assertEquals(null, ParseLog.PullLastLineRead(file, "pap-rest")); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullLastLineReadFail: exit"); - } - - @Test - public void testPullOutLogValues(){ - - logger.debug("testPullOutLogValues: enter"); - //ERROR_VALUE - // Open the file - FileInputStream fstream; - try { - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "ERROR"); - assertEquals("ERROR_VALUE", retrunObject.getDescription()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValues: exit"); - } - - @Test - public void testGetPaths(){ - - logger.debug("testGetPaths: enter"); - - try { - // valid test - String logPaths = "C:\\pap-log\\pap-rest.log;C:\\pap-log\\debug.log;C:\\pap-log\\error.log"; - String [] retrunObject = ParseLog.getPaths(logPaths); - assertEquals(3, retrunObject.length); - - // valid test - logPaths = "C:\\pap-log\\pap-rest.log"; - retrunObject = ParseLog.getPaths(logPaths); - assertEquals(1, retrunObject.length); - - // invalid test - logPaths = ""; - retrunObject = ParseLog.getPaths(logPaths); - assertTrue(retrunObject == null); - - } catch (Exception e) { - fail(); - } - - logger.debug("testGetPaths: exit"); - } - - @Test - public void testPullOutLogValuesSecond(){ - - logger.debug("testPullOutLogValuesSecond: enter"); - //ERROR_VALUE - // Open the file - FileInputStream fstream; - try { - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - strLine = br.readLine(); - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "INFO"); - assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesSecond: exit"); - } - - @Test - public void testPullOutLogValuesThird(){ - - logger.debug("testPullOutLogValuesThird: enter"); - //ERROR_VALUE - // Open the file - FileInputStream fstream; - try { - int number = 3; - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - for (int i =0; i < number; i++){ - strLine = br.readLine(); - } - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PAP"); - assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesThird: exit"); - } - - @Test - public void testPullOutLogValuesFourth(){ - - logger.debug("testPullOutLogValuesFourth: enter"); - // Open the file - FileInputStream fstream; - try { - int number = 4; - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - for (int i =0; i < number; i++){ - strLine = br.readLine(); - } - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PAP"); - assertEquals(LOGTYPE.INFO, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesFourth: exit"); - } - - @Test - public void testPullOutLogValuesFith(){ - - logger.debug("testPullOutLogValuesFith: enter"); - // Open the file - FileInputStream fstream; - try { - int number = 5; - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - for (int i =0; i < number; i++){ - strLine = br.readLine(); - } - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PyPDP"); - assertEquals(LOGTYPE.WARN, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesFith: exit"); - } - - @Test - public void testPullOutLogValuesSixth(){ - - logger.debug("testPullOutLogValuesSixth: enter"); - // Open the file - FileInputStream fstream; - try { - int number = 6; - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - for (int i =0; i < number; i++){ - strLine = br.readLine(); - } - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "PyPDP"); - assertEquals(LOGTYPE.SEVERE, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesSixth: exit"); - } - - @Test - public void testPullOutLogValuesSeven(){ - - logger.debug("testPullOutLogValuesSeven: enter"); - // Open the file - FileInputStream fstream; - try { - int number = 7; - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - for (int i =0; i < number; i++){ - strLine = br.readLine(); - } - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "Console"); - assertEquals(LOGTYPE.ERROR, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesSeven: exit"); - } - - @Test - public void testPullOutLogValuesEight(){ - - logger.debug("testPullOutLogValuesEight: enter"); - // Open the file - FileInputStream fstream; - try { - int number = 8; - fstream = new FileInputStream(testFile1); - BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); - String strLine = br.readLine(); - for (int i =0; i < number; i++){ - strLine = br.readLine(); - } - LogEntryObject retrunObject = ParseLog.pullOutLogValues(strLine, "pap"); - assertEquals(LOGTYPE.WARN, retrunObject.getLogType()); - br.close(); - } catch (IOException e) { - fail(); - } - - logger.debug("testPullOutLogValuesEight: exit"); - } - - @Test - public void testPullOutLogValuesNull(){ - - logger.debug("testPullOutLogValuesNull: enter"); - // Open the file - LogEntryObject retrunObject = ParseLog.pullOutLogValues("", "Console"); - assertEquals(null, retrunObject); - - logger.debug("testPullOutLogValuesNull: exit"); - } - - @Test - public void testLogEntryObject(){ - - logger.debug("testLogEntryObject: enter"); - - Date date = new Date(); - - // Open the file - LogEntryObject logObject = new LogEntryObject(); - logObject.setSystem("vm02"); - logObject.setSystemType("pap"); - logObject.setDate(date); - logObject.setRemote("remote"); - - assertEquals("vm02", logObject.getSystem()); - assertEquals("pap", logObject.getSystemType()); - assertEquals(date, logObject.getDate()); - assertEquals("remote", logObject.getRemote()); - - logger.debug("testLogEntryObject: exit"); - } - - @Test - public void testProcess(){ - - logger.debug("testProcess: enter"); - - String line = "2015-04-01 09:13:44.947 DEBUG 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved "; - - im = Mockito.mock(IntegrityMonitor.class); - try { - Mockito.doNothing().when(im).startTransaction(); - } catch (StandbyStatusException | AdministrativeStateException e) { - fail(); - } - Mockito.doNothing().when(im).endTransaction(); - ParseLog.process(line, "pap", LOGTYPE.INFO); - - logger.debug("testProcess: exit"); - } -} \ No newline at end of file diff --git a/LogParser/src/test/resources/LineTest.txt b/LogParser/src/test/resources/LineTest.txt index 32ec6cb0e..e80f631fc 100644 --- a/LogParser/src/test/resources/LineTest.txt +++ b/LogParser/src/test/resources/LineTest.txt @@ -1,12 +1,12 @@ -2016-04-26T00:00:00{GMT+0}+00:00|||Thread-5||||ERROR|||localhost.com||org.openecomp.policy.im.IntegrityMonitor.writeFpc(IntegrityMonitor.java:377)||ERROR_VALUE -2016-04-27T11:22:08{GMT+0}+00:00|||main||||INFO|||||org.openecomp.xacml.parser.ParseLog.main(ParseLog.java:86)||File Line Count: 18409 value read in: 0 -2016-04-27T11:22:48{GMT+0}+00:00|||Thread-0||||INFO|||||org.openecomp.xacml.parser.ParseLog$1.lambda$0(ParseLog.java:96)||Last line Read: 12 -2015_10_02_15_11_19_006 [http-nio-8081-exec-10] INFO corg.openecomp.research.xacml.rest.XACMLPdpServlet.doPutConfig(XACMLPdpServlet.java:409)- Success -2015-04-01 09:13:44.947 INFO 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved +2016-04-26T00:00:00{GMT+0}+00:00|||Thread-5||||ERROR|||localhost.com||org.onap.policy.im.IntegrityMonitor.writeFpc(IntegrityMonitor.java:377)||ERROR_VALUE +2016-04-27T11:22:08{GMT+0}+00:00|||main||||INFO|||||org.onap.xacml.parser.ParseLog.main(ParseLog.java:86)||File Line Count: 18409 value read in: 0 +2016-04-27T11:22:48{GMT+0}+00:00|||Thread-0||||INFO|||||org.onap.xacml.parser.ParseLog$1.lambda$0(ParseLog.java:96)||Last line Read: 12 +2015_10_02_15_11_19_006 [http-nio-8081-exec-10] INFO corg.onap.research.xacml.rest.XACMLPdpServlet.doPutConfig(XACMLPdpServlet.java:409)- Success +2015-04-01 09:13:44.947 INFO 17482 --- [nio-8480-exec-7] c.a.l.onap.policy.std.StdPolicyConfig : config Retrieved 08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. service Catalina08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. 06-Mar-2015 11:50:06.243 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["ajp-nio-8009"] java.net.BindException: Address already in use -2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.openecomp.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! -2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.openecomp.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore -2017-05-31T22:18:42{GMT+0}+00:00|||Thread-4||||INFO|||||org.openecomp.xacml.parser.ParseLog$1.lambda$0(ParseLog.java:136)||Last-debug.log-line-Read:17 -2017-05-31T22:18:42{GMT+0}+00:00|||Thread-5||||INFO|||||org.openecomp.xacml.parser.ParseLog$2.lambda$0(ParseLog.java:194)||Last-error.log-line-Read:22 -2017-05-31T22:18:42{GMT+0}+00:00|||Thread-6||||INFO|||||org.openecomp.xacml.parser.ParseLog$3.lambda$0(ParseLog.java:250)||Last-pap-rest.log-line-Read:52 \ No newline at end of file +2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.onap.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! +2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.onap.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore +2017-05-31T22:18:42{GMT+0}+00:00|||Thread-4||||INFO|||||org.onap.xacml.parser.ParseLog$1.lambda$0(ParseLog.java:136)||Last-debug.log-line-Read:17 +2017-05-31T22:18:42{GMT+0}+00:00|||Thread-5||||INFO|||||org.onap.xacml.parser.ParseLog$2.lambda$0(ParseLog.java:194)||Last-error.log-line-Read:22 +2017-05-31T22:18:42{GMT+0}+00:00|||Thread-6||||INFO|||||org.onap.xacml.parser.ParseLog$3.lambda$0(ParseLog.java:250)||Last-pap-rest.log-line-Read:52 \ No newline at end of file diff --git a/LogParser/src/test/resources/LineTest2.txt b/LogParser/src/test/resources/LineTest2.txt index 2243960df..da464412e 100644 --- a/LogParser/src/test/resources/LineTest2.txt +++ b/LogParser/src/test/resources/LineTest2.txt @@ -1,7 +1,7 @@ -2016-04-26T00:00:00{GMT+0}+00:00|||Thread-5||||ERROR|||localhost.com||org.openecomp.ecomp.policy.im.IntegrityMonitor.writeFpc(IntegrityMonitor.java:377)||ERROR_VALUE -2015_10_02_15_11_19_006 [http-nio-8081-exec-10] INFO org.openecomp.research.xacml.rest.XACMLPdpServlet.doPutConfig(XACMLPdpServlet.java:409)- Success -2015-04-01 09:13:44.947 INFO 17482 --- [nio-8480-exec-7] c.a.l.ecomp.policy.std.StdPolicyConfig : config Retrieved +2016-04-26T00:00:00{GMT+0}+00:00|||Thread-5||||ERROR|||localhost.com||org.onap.onap.policy.im.IntegrityMonitor.writeFpc(IntegrityMonitor.java:377)||ERROR_VALUE +2015_10_02_15_11_19_006 [http-nio-8081-exec-10] INFO org.onap.research.xacml.rest.XACMLPdpServlet.doPutConfig(XACMLPdpServlet.java:409)- Success +2015-04-01 09:13:44.947 INFO 17482 --- [nio-8480-exec-7] c.a.l.onap.policy.std.StdPolicyConfig : config Retrieved 08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. service Catalina08-Apr-2015 10:31:26.503 WARNING [localhost-startStop-2] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [PyPDPServer] appears to have started a thread named [Grizzly(1) SelectorRunner] but has failed to stop it. This is very likely to create a memory leak. 06-Mar-2015 11:50:06.243 SEVERE [main] org.apache.coyote.AbstractProtocol.init Failed to initialize end point associated with ProtocolHandler ["ajp-nio-8009"] java.net.BindException: Address already in use -2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.openecomp.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! -2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.openecomp.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore \ No newline at end of file +2015_09_30_10_39_31_675 [http-nio-8081-exec-1] ERROR org.onap.research.xacml.rest.XACMLPdpServlet.doPost(XACMLPdpServlet.java:644)- PE100 - Permissions Error: PEP not Authorized for making this Request!! +2015_03_17_15_01_08_348 [qtp1688376486-32] WARN org.onap.research.xacml.admin.components.PolicyManagement$1.accept(PolicyManagement.java:184)- Filtering out: C:\git\D2PE-take2\policy-engine-prototype\XACML-PAP-ADMIN\workspace\admin\repository\com\.svnignore \ No newline at end of file -- cgit 1.2.3-korg