diff options
author | Tej, Tarun <tt3868@att.com> | 2017-09-11 13:33:47 -0400 |
---|---|---|
committer | Tej, Tarun <tt3868@att.com> | 2017-09-11 14:04:48 -0400 |
commit | 663ed59389f1e1125a659f2e55dbe3c3a30d3ea9 (patch) | |
tree | fd6a3b2f0cbe89d6665d1fa0a8e33f37a30b2661 /LogParser | |
parent | 8f7700fa98a92cb8bf8bc4fb7af20c58080821ff (diff) |
Health check issue fixes
Fixes to PDP log parser failure issues and sonar fixes
Issue-Id: POLICY-211
Change-Id: I8086a6fc1dc24719c3ffd3785a12c086ab452ae7
Signed-off-by: Tej, Tarun <tt3868@att.com>
Diffstat (limited to 'LogParser')
-rw-r--r-- | LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java | 105 |
1 files changed, 55 insertions, 50 deletions
diff --git a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java index c3d631e1f..1dbe12523 100644 --- a/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java +++ b/LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java @@ -77,22 +77,21 @@ public class ParseLog { 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 String jdbcUrl; + private static String jdbcUser; + private static String jdbcPassword; + private static String jdbcDriver; 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; //Default:Timer initial delay and the delay between in milliseconds before task is to be execute - private static int TIMER_DELAY_TIME = 1000; + private static final int TIMER_DELAY_TIME = 1000; //Default:Timer scheduleAtFixedRate period - time in milliseconds between successive task executions - private static int CHECK_INTERVAL = 86400000; // run this clean up once a day - private static RandomAccessFile randomAccessFile; + private static int checkInterval = 86400000; // run this clean up once a day private static String loggingProcess = "Error processing line in "; - private static int TIME_FRAME = 5; + private static int defaultTimeFrame = 5; private static String message =" value read in: "; private static String lineFormat = "(\\r\\n|\\n)"; private static String lineRead = "-line-Read:"; @@ -344,30 +343,32 @@ public class ParseLog { 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+lineRead)){ - String[] parseString = builder.toString().split(last+dataFileName+lineRead); - String returnValue = parseString[1].replace("\r", ""); - return returnValue.trim(); - } - builder = new StringBuilder(); - } - } - } - + try(RandomAccessFile 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+lineRead)){ + String[] parseString = builder.toString().split(last+dataFileName+lineRead); + String returnValue = parseString[1].replace("\r", ""); + randomAccessFile.close(); + return returnValue.trim(); + } + builder = new StringBuilder(); + } + } + } + randomAccessFile.close(); + } return null; } @@ -602,7 +603,7 @@ public class ParseLog { private static void writeDB(LogEntryObject returnLogValue) { - Connection conn = dbConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); + Connection conn = dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword); dbAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(), returnLogValue.getDate(), returnLogValue.getRemote(), returnLogValue.getSystemType(), returnLogValue.getLogType().toString()); @@ -613,8 +614,7 @@ public class ParseLog { try { Class.forName(driver); - Connection conn = DriverManager.getConnection(jdbc, user, pass); - return conn; + return DriverManager.getConnection(jdbc, user, pass); } catch ( Exception e) { logger.error("Error connecting to DB: " + e); } @@ -713,19 +713,24 @@ public class ParseLog { if(cleanupInterval != null && !cleanupInterval.isEmpty()){ int intCheckInterval = Integer.parseInt(cleanupInterval); if(intCheckInterval > 300000) {//must be longer than 5 minutes - CHECK_INTERVAL = intCheckInterval; + checkInterval = intCheckInterval; } }else{ - logger.debug("No value defined for CHECK_INTERVAL in parserlog.properties, so use its default value:" + CHECK_INTERVAL + " milliseconds"); + logger.debug("No value defined for CHECK_INTERVAL in parserlog.properties, so use its default value:" + checkInterval + " milliseconds"); } - if(timeFrame != null && !timeFrame.isEmpty()){ - int intTimeFrame = Integer.parseInt(timeFrame); + if(timeFrame != null && !timeFrame.trim().isEmpty()){ + int intTimeFrame = defaultTimeFrame; + try{ + intTimeFrame = Integer.parseInt(timeFrame); + }catch(NumberFormatException e){ + logger.debug("Improper value defined for TIME_FRAME in parserlog.properties, so use its default value:" + defaultTimeFrame + " days"); + } if(intTimeFrame > 0){ - TIME_FRAME = intTimeFrame; + defaultTimeFrame = intTimeFrame; } }else{ - logger.debug("No value defined for TIME_FRAME in parserlog.properties, so use its default value:" + TIME_FRAME + " days"); + logger.debug("No value defined for TIME_FRAME in parserlog.properties, so use its default value:" + defaultTimeFrame + " days"); } } @@ -800,17 +805,17 @@ public class ParseLog { setLogFileProperties(splitString); - 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"); + jdbcUrl = config.getProperty("JDBC_URL").replace("'", ""); + jdbcUser = config.getProperty("JDBC_USER"); + jdbcDriver = config.getProperty("JDBC_DRIVER"); + jdbcPassword = config.getProperty("JDBC_PASSWORD"); return config; } catch (IOException e) { logger.error("Error porcessing Config file will be unable to create Health Check" + e); }catch(Exception e){ logger.error("Error getPropertiesValue on TIME_FRAME", e); - logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + TIME_FRAME + " days"); + logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + defaultTimeFrame + " days"); } } @@ -822,13 +827,13 @@ public class ParseLog { } public static Connection getDbConnection(){ - return dbConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); + return dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword); } private static void startCleanUp(){ - Connection conn = dbConnection(JDBC_DRIVER, JDBC_URL, JDBC_USER,JDBC_PASSWORD); - CleanUpSystemLogDB cleanUp = new CleanUpSystemLogDB(conn, TIME_FRAME); + Connection conn = dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword); + CleanUpSystemLogDB cleanUp = new CleanUpSystemLogDB(conn, defaultTimeFrame); Timer timer = new Timer(true); - timer.scheduleAtFixedRate(cleanUp, TIMER_DELAY_TIME, CHECK_INTERVAL); + timer.scheduleAtFixedRate(cleanUp, TIMER_DELAY_TIME, checkInterval); logger.info("startCleanUp begins! : " + new Date()); } }
\ No newline at end of file |