X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Freports%2FVolumeReport.java;fp=datarouter-prov%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fdmaap%2Fdatarouter%2Freports%2FVolumeReport.java;h=169db0d2ab0b6fbadac1c73fe09ba532ea40c0f8;hb=4261823d84c2b911b68cdf4cb4dc3be429ebe285;hp=b210ef9fd76155b1cf86ab6b1d09a1c5ac39aee1;hpb=13639e1b05d8c8b5b1e9efd543573834501aefaa;p=dmaap%2Fdatarouter.git diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java index b210ef9f..169db0d2 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java @@ -7,9 +7,9 @@ * * 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. @@ -55,86 +55,87 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; * @version $Id: VolumeReport.java,v 1.3 2014/02/28 15:11:13 eby Exp $ */ public class VolumeReport extends ReportBase { - private static final String SELECT_SQL = "select EVENT_TIME, TYPE, FEEDID, CONTENT_LENGTH, RESULT" + - " from LOG_RECORDS where EVENT_TIME >= ? and EVENT_TIME <= ? LIMIT ?, ?"; + private static final String SELECT_SQL = "select EVENT_TIME, TYPE, FEEDID, CONTENT_LENGTH, RESULT" + + " from LOG_RECORDS where EVENT_TIME >= ? and EVENT_TIME <= ? LIMIT ?, ?"; + + private class Counters { + public int filespublished, filesdelivered, filesexpired; + public long bytespublished, bytesdelivered, bytesexpired; - private class Counters { - public int filespublished, filesdelivered, filesexpired; - public long bytespublished, bytesdelivered, bytesexpired; - @Override - public String toString() { - return String.format("%d,%d,%d,%d,%d,%d", - filespublished, bytespublished, filesdelivered, - bytesdelivered, filesexpired, bytesexpired); - } - } + @Override + public String toString() { + return String.format("%d,%d,%d,%d,%d,%d", + filespublished, bytespublished, filesdelivered, + bytesdelivered, filesexpired, bytesexpired); + } + } - @Override - public void run() { - Map map = new HashMap(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - long start = System.currentTimeMillis(); - try { - DB db = new DB(); - @SuppressWarnings("resource") - Connection conn = db.getConnection(); - // 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) { - PreparedStatement ps = conn.prepareStatement(SELECT_SQL); - ps.setLong(1, from); - ps.setLong(2, to); - ps.setLong(3, i); - ps.setLong(4, stepsize); - ResultSet rs = ps.executeQuery(); - go_again = false; - while (rs.next()) { - go_again = true; - long etime = rs.getLong("EVENT_TIME"); - String type = rs.getString("TYPE"); - int feed = rs.getInt("FEEDID"); - long clen = rs.getLong("CONTENT_LENGTH"); - String key = sdf.format(new Date(etime)) + ":" + feed; - Counters c = map.get(key); - if (c == null) { - c = new Counters(); - map.put(key, c); - } - if (type.equalsIgnoreCase("pub")) { - c.filespublished++; - c.bytespublished += clen; - } else if (type.equalsIgnoreCase("del")) { - // Only count successful deliveries - int statusCode = rs.getInt("RESULT"); - if (statusCode >= 200 && statusCode < 300) { - c.filesdelivered++; - c.bytesdelivered += clen; - } - } else if (type.equalsIgnoreCase("exp")) { - c.filesexpired++; - c.bytesexpired += clen; - } - } - rs.close(); - ps.close(); - } - db.release(conn); - } catch (SQLException e) { - e.printStackTrace(); - } - logger.debug("Query time: " + (System.currentTimeMillis()-start) + " ms"); - try { - PrintWriter os = new PrintWriter(outfile); - os.println("date,feedid,filespublished,bytespublished,filesdelivered,bytesdelivered,filesexpired,bytesexpired"); - for (String key : new TreeSet(map.keySet())) { - Counters c = map.get(key); - String[] p = key.split(":"); - os.println(String.format("%s,%s,%s", p[0], p[1], c.toString())); - } - os.close(); - } catch (FileNotFoundException e) { - System.err.println("File cannot be written: "+outfile); - } - } + @Override + public void run() { + Map map = new HashMap(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + long start = System.currentTimeMillis(); + try { + DB db = new DB(); + @SuppressWarnings("resource") + Connection conn = db.getConnection(); + // 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) { + PreparedStatement ps = conn.prepareStatement(SELECT_SQL); + ps.setLong(1, from); + ps.setLong(2, to); + ps.setLong(3, i); + ps.setLong(4, stepsize); + ResultSet rs = ps.executeQuery(); + go_again = false; + while (rs.next()) { + go_again = true; + long etime = rs.getLong("EVENT_TIME"); + String type = rs.getString("TYPE"); + int feed = rs.getInt("FEEDID"); + long clen = rs.getLong("CONTENT_LENGTH"); + String key = sdf.format(new Date(etime)) + ":" + feed; + Counters c = map.get(key); + if (c == null) { + c = new Counters(); + map.put(key, c); + } + if (type.equalsIgnoreCase("pub")) { + c.filespublished++; + c.bytespublished += clen; + } else if (type.equalsIgnoreCase("del")) { + // Only count successful deliveries + int statusCode = rs.getInt("RESULT"); + if (statusCode >= 200 && statusCode < 300) { + c.filesdelivered++; + c.bytesdelivered += clen; + } + } else if (type.equalsIgnoreCase("exp")) { + c.filesexpired++; + c.bytesexpired += clen; + } + } + rs.close(); + ps.close(); + } + db.release(conn); + } catch (SQLException e) { + e.printStackTrace(); + } + logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms"); + try { + PrintWriter os = new PrintWriter(outfile); + os.println("date,feedid,filespublished,bytespublished,filesdelivered,bytesdelivered,filesexpired,bytesexpired"); + for (String key : new TreeSet(map.keySet())) { + Counters c = map.get(key); + String[] p = key.split(":"); + os.println(String.format("%s,%s,%s", p[0], p[1], c.toString())); + } + os.close(); + } catch (FileNotFoundException e) { + System.err.println("File cannot be written: " + outfile); + } + } }