X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Fprovisioning%2Futils%2FLogfileLoader.java;h=8223188434ab82437c98d303d95032c22db5273c;hb=refs%2Fchanges%2F51%2F78851%2F11;hp=8975f1612f4f96203f07cf6b490390e2b904951d;hpb=4a488856e1f47f46785586f8bf3dabbe067f11e7;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java index 8975f161..82231884 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java @@ -46,7 +46,8 @@ import java.util.Map; import java.util.TreeSet; import java.util.zip.GZIPInputStream; -import org.apache.log4j.Logger; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.onap.dmaap.datarouter.provisioning.BaseServlet; import org.onap.dmaap.datarouter.provisioning.beans.DeliveryExtraRecord; import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord; @@ -82,7 +83,7 @@ public class LogfileLoader extends Thread { /** * This is a singleton -- there is only one LogfileLoader object in the server */ - private static LogfileLoader p; + private static LogfileLoader logfileLoader; /** * Get the singleton LogfileLoader object, and start it if it is not running. @@ -90,23 +91,23 @@ public class LogfileLoader extends Thread { * @return the LogfileLoader */ public static synchronized LogfileLoader getLoader() { - if (p == null) - p = new LogfileLoader(); - if (!p.isAlive()) - p.start(); - return p; + if (logfileLoader == null) + logfileLoader = new LogfileLoader(); + if (!logfileLoader.isAlive()) + logfileLoader.start(); + return logfileLoader; } /** * The PreparedStatement which is loaded by a Loadable. */ - public static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; + public static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; /** * Each server can assign this many IDs */ private static final long SET_SIZE = (1L << 56); - private final Logger logger; + private final EELFLogger logger; private final DB db; private final String spooldir; private final long set_start; @@ -116,7 +117,7 @@ public class LogfileLoader extends Thread { private boolean idle; private LogfileLoader() { - this.logger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + this.logger = EELFManager.getInstance().getLogger("InternalLog"); this.db = new DB(); this.spooldir = db.getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir"); this.set_start = getIdRange(); @@ -188,6 +189,7 @@ public class LogfileLoader extends Thread { try { Thread.sleep(1000L); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); } idle = false; } else { @@ -213,12 +215,11 @@ public class LogfileLoader extends Thread { } } catch (Exception e) { logger.warn("PROV0020: Caught exception in LogfileLoader: " + e); - e.printStackTrace(); } } } - private boolean pruneRecords() { + boolean pruneRecords() { boolean did1 = false; long count = countRecords(); long threshold = DEFAULT_LOG_RETENTION; @@ -274,7 +275,7 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e.toString()); } finally { db.release(conn); } @@ -282,7 +283,7 @@ public class LogfileLoader extends Thread { return did1; } - private long countRecords() { + long countRecords() { long count = 0; Connection conn = null; try { @@ -296,14 +297,14 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e.toString()); } finally { db.release(conn); } return count; } - private Map getHistogram() { + Map getHistogram() { Map map = new HashMap(); Connection conn = null; try { @@ -321,7 +322,7 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e.toString()); } finally { db.release(conn); } @@ -332,26 +333,25 @@ public class LogfileLoader extends Thread { Connection conn = null; try { conn = db.getConnection(); - Statement stmt = conn.createStatement(); - // Build a bitset of all records in the LOG_RECORDS table - // We need to run this SELECT in stages, because otherwise we run out of memory! RLEBitSet nbs = new RLEBitSet(); - final long stepsize = 6000000L; - boolean go_again = true; - for (long i = 0; go_again; i += stepsize) { - String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize); - try(ResultSet rs = stmt.executeQuery(sql)) { - go_again = false; - while (rs.next()) { - long n = rs.getLong("RECORD_ID"); - nbs.set(n); - go_again = true; + try(Statement stmt = conn.createStatement()) { + // Build a bitset of all records in the LOG_RECORDS table + // We need to run this SELECT in stages, because otherwise we run out of memory! + final long stepsize = 6000000L; + boolean go_again = true; + for (long i = 0; go_again; i += stepsize) { + String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize); + try (ResultSet rs = stmt.executeQuery(sql)) { + go_again = false; + while (rs.next()) { + long n = rs.getLong("RECORD_ID"); + nbs.set(n); + go_again = true; + } } } } - stmt.close(); seq_set = nbs; - // Compare with the range for this server // Determine the next ID for this set of record IDs RLEBitSet tbs = (RLEBitSet) nbs.clone(); @@ -376,14 +376,14 @@ public class LogfileLoader extends Thread { logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextid, nextid)); } catch (SQLException e) { System.err.println(e); - e.printStackTrace(); + logger.error(e.toString()); } finally { db.release(conn); } } @SuppressWarnings("resource") - private int[] process(File f) { + int[] process(File f) { int ok = 0, total = 0; try { Connection conn = db.getConnection(); @@ -416,20 +416,16 @@ public class LogfileLoader extends Thread { } } catch (SQLException e) { logger.warn("PROV8003 Invalid value in record: " + line); - logger.debug(e); - e.printStackTrace(); + logger.debug(e.toString()); } catch (NumberFormatException e) { logger.warn("PROV8004 Invalid number in record: " + line); - logger.debug(e); - e.printStackTrace(); + logger.debug(e.toString()); } catch (ParseException e) { logger.warn("PROV8005 Invalid date in record: " + line); - logger.debug(e); - e.printStackTrace(); + logger.debug(e.toString()); } catch (Exception e) { logger.warn("PROV8006 Invalid pattern in record: " + line); - logger.debug(e); - e.printStackTrace(); + logger.debug(e.toString()); } total++; } @@ -447,7 +443,7 @@ public class LogfileLoader extends Thread { return new int[]{ok, total}; } - private Loadable[] buildRecords(String line) throws ParseException { + Loadable[] buildRecords(String line) throws ParseException { String[] pp = line.split("\\|"); if (pp != null && pp.length >= 7) { String rtype = pp[1].toUpperCase();