summaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src/main/java')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java158
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java248
2 files changed, 202 insertions, 204 deletions
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 ff7893d5..8975f161 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
@@ -254,24 +254,24 @@ public class LogfileLoader extends Thread {
try {
// Limit to a million at a time to avoid typing up the DB for too long.
conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement("DELETE from LOG_RECORDS where EVENT_TIME < ? limit 1000000");
- ps.setLong(1, cutoff);
- while (count > 0) {
- if (!ps.execute()) {
- int dcount = ps.getUpdateCount();
- count -= dcount;
- logger.debug(" " + dcount + " rows deleted.");
- did1 |= (dcount != 0);
- if (dcount == 0)
- count = 0; // prevent inf. loops
- } else {
- count = 0; // shouldn't happen!
+ try(PreparedStatement ps = conn.prepareStatement("DELETE from LOG_RECORDS where EVENT_TIME < ? limit 1000000")) {
+ ps.setLong(1, cutoff);
+ while (count > 0) {
+ if (!ps.execute()) {
+ int dcount = ps.getUpdateCount();
+ count -= dcount;
+ logger.debug(" " + dcount + " rows deleted.");
+ did1 |= (dcount != 0);
+ if (dcount == 0)
+ count = 0; // prevent inf. loops
+ } else {
+ count = 0; // shouldn't happen!
+ }
}
}
- ps.close();
- Statement stmt = conn.createStatement();
- stmt.execute("OPTIMIZE TABLE LOG_RECORDS");
- stmt.close();
+ try(Statement stmt = conn.createStatement()) {
+ stmt.execute("OPTIMIZE TABLE LOG_RECORDS");
+ }
} catch (SQLException e) {
System.err.println(e);
e.printStackTrace();
@@ -287,14 +287,14 @@ public class LogfileLoader extends Thread {
Connection conn = null;
try {
conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS");
- if (rs.next()) {
- count = rs.getLong("COUNT");
- }
- rs.close();
- stmt.close();
- } catch (SQLException e) {
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS")) {
+ if (rs.next()) {
+ count = rs.getLong("COUNT");
+ }
+ }
+ }
+ } catch (SQLException e) {
System.err.println(e);
e.printStackTrace();
} finally {
@@ -309,17 +309,17 @@ public class LogfileLoader extends Thread {
try {
logger.debug(" LOG_RECORD table histogram...");
conn = db.getConnection();
- Statement stmt = conn.createStatement();
- ResultSet rs = stmt.executeQuery("SELECT FLOOR(EVENT_TIME/86400000) AS DAY, COUNT(*) AS COUNT FROM LOG_RECORDS GROUP BY DAY");
- while (rs.next()) {
- long day = rs.getLong("DAY");
- long cnt = rs.getLong("COUNT");
- map.put(day, cnt);
- logger.debug(" " + day + " " + cnt);
+ try(Statement stmt = conn.createStatement()) {
+ try(ResultSet rs = stmt.executeQuery("SELECT FLOOR(EVENT_TIME/86400000) AS DAY, COUNT(*) AS COUNT FROM LOG_RECORDS GROUP BY DAY")) {
+ while (rs.next()) {
+ long day = rs.getLong("DAY");
+ long cnt = rs.getLong("COUNT");
+ map.put(day, cnt);
+ logger.debug(" " + day + " " + cnt);
+ }
+ }
}
- rs.close();
- stmt.close();
- } catch (SQLException e) {
+ } catch (SQLException e) {
System.err.println(e);
e.printStackTrace();
} finally {
@@ -340,14 +340,14 @@ public class LogfileLoader extends Thread {
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);
- ResultSet rs = stmt.executeQuery(sql);
- go_again = false;
- while (rs.next()) {
- long n = rs.getLong("RECORD_ID");
- nbs.set(n);
- go_again = true;
+ try(ResultSet rs = stmt.executeQuery(sql)) {
+ go_again = false;
+ while (rs.next()) {
+ long n = rs.getLong("RECORD_ID");
+ nbs.set(n);
+ go_again = true;
+ }
}
- rs.close();
}
stmt.close();
seq_set = nbs;
@@ -391,49 +391,49 @@ public class LogfileLoader extends Thread {
Reader r = f.getPath().endsWith(".gz")
? new InputStreamReader(new GZIPInputStream(new FileInputStream(f)))
: new FileReader(f);
- LineNumberReader in = new LineNumberReader(r);
- String line;
- while ((line = in.readLine()) != null) {
- try {
- for (Loadable rec : buildRecords(line)) {
- rec.load(ps);
- if (rec instanceof LogRecord) {
- LogRecord lr = ((LogRecord) rec);
- if (!seq_set.get(lr.getRecordId())) {
+ try(LineNumberReader in = new LineNumberReader(r)) {
+ String line;
+ while ((line = in.readLine()) != null) {
+ try {
+ for (Loadable rec : buildRecords(line)) {
+ rec.load(ps);
+ if (rec instanceof LogRecord) {
+ LogRecord lr = ((LogRecord) rec);
+ if (!seq_set.get(lr.getRecordId())) {
+ ps.executeUpdate();
+ seq_set.set(lr.getRecordId());
+ } else
+ logger.debug("Duplicate record ignored: " + lr.getRecordId());
+ } else {
+ if (++nextid > set_end)
+ nextid = set_start;
+ ps.setLong(18, nextid);
ps.executeUpdate();
- seq_set.set(lr.getRecordId());
- } else
- logger.debug("Duplicate record ignored: " + lr.getRecordId());
- } else {
- if (++nextid > set_end)
- nextid = set_start;
- ps.setLong(18, nextid);
- ps.executeUpdate();
- seq_set.set(nextid);
+ seq_set.set(nextid);
+ }
+ ps.clearParameters();
+ ok++;
}
- ps.clearParameters();
- ok++;
+ } catch (SQLException e) {
+ logger.warn("PROV8003 Invalid value in record: " + line);
+ logger.debug(e);
+ e.printStackTrace();
+ } catch (NumberFormatException e) {
+ logger.warn("PROV8004 Invalid number in record: " + line);
+ logger.debug(e);
+ e.printStackTrace();
+ } catch (ParseException e) {
+ logger.warn("PROV8005 Invalid date in record: " + line);
+ logger.debug(e);
+ e.printStackTrace();
+ } catch (Exception e) {
+ logger.warn("PROV8006 Invalid pattern in record: " + line);
+ logger.debug(e);
+ e.printStackTrace();
}
- } catch (SQLException e) {
- logger.warn("PROV8003 Invalid value in record: " + line);
- logger.debug(e);
- e.printStackTrace();
- } catch (NumberFormatException e) {
- logger.warn("PROV8004 Invalid number in record: " + line);
- logger.debug(e);
- e.printStackTrace();
- } catch (ParseException e) {
- logger.warn("PROV8005 Invalid date in record: " + line);
- logger.debug(e);
- e.printStackTrace();
- } catch (Exception e) {
- logger.warn("PROV8006 Invalid pattern in record: " + line);
- logger.debug(e);
- e.printStackTrace();
+ total++;
}
- total++;
}
- in.close();
ps.close();
db.release(conn);
conn = null;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java
index d638aaa6..4346a0ec 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/FeedReport.java
@@ -69,45 +69,43 @@ public class FeedReport extends ReportBase {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
-// ps.setLong(1, from);
-// ps.setLong(2, to);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- if (alg1) {
- String date = rs.getString("date");
- String type = rs.getString("type");
- int feedid = rs.getInt("feedid");
- int subid = type.equals("del") ? rs.getInt("delivery_subid") : 0;
- int count = rs.getInt("count");
- sb.append(date + "," + type + "," + feedid + "," + subid + "," + count + "\n");
- } else {
- String date = rs.getString("date");
- JSONObject datemap = jo.optJSONObject(date);
- if (datemap == null) {
- datemap = new JSONObject();
- jo.put(date, datemap);
- }
- int feed = rs.getInt("FEEDID");
- JSONObject feedmap = datemap.optJSONObject("" + feed);
- if (feedmap == null) {
- feedmap = new JSONObject();
- feedmap.put("pubcount", 0);
- datemap.put("" + feed, feedmap);
- }
- String type = rs.getString("TYPE");
- int count = rs.getInt("count");
- if (type.equals("pub")) {
- feedmap.put("pubcount", count);
- } else if (type.equals("del")) {
- String subid = "" + rs.getInt("DELIVERY_SUBID");
- feedmap.put(subid, count);
- }
- }
- }
- rs.close();
- ps.close();
- db.release(conn);
+ try( PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ try (ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ if (alg1) {
+ String date = rs.getString("date");
+ String type = rs.getString("type");
+ int feedid = rs.getInt("feedid");
+ int subid = type.equals("del") ? rs.getInt("delivery_subid") : 0;
+ int count = rs.getInt("count");
+ sb.append(date + "," + type + "," + feedid + "," + subid + "," + count + "\n");
+ } else {
+ String date = rs.getString("date");
+ JSONObject datemap = jo.optJSONObject(date);
+ if (datemap == null) {
+ datemap = new JSONObject();
+ jo.put(date, datemap);
+ }
+ int feed = rs.getInt("FEEDID");
+ JSONObject feedmap = datemap.optJSONObject("" + feed);
+ if (feedmap == null) {
+ feedmap = new JSONObject();
+ feedmap.put("pubcount", 0);
+ datemap.put("" + feed, feedmap);
+ }
+ String type = rs.getString("TYPE");
+ int count = rs.getInt("count");
+ if (type.equals("pub")) {
+ feedmap.put("pubcount", count);
+ } else if (type.equals("del")) {
+ String subid = "" + rs.getInt("DELIVERY_SUBID");
+ feedmap.put(subid, count);
+ }
+ }
+ }
+ }
+ }
+ db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
}
@@ -134,47 +132,47 @@ public class FeedReport extends ReportBase {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL_OLD);
- ps.setLong(1, from);
- ps.setLong(2, to);
- ps.setFetchSize(100000);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- String id = rs.getString("PUBLISH_ID");
- String date = sdf.format(new Date(getPstart(id)));
- JSONObject datemap = jo.optJSONObject(date);
- if (datemap == null) {
- datemap = new JSONObject();
- jo.put(date, datemap);
- }
- int feed = rs.getInt("FEEDID");
- JSONObject feedmap = datemap.optJSONObject("" + feed);
- if (feedmap == null) {
- feedmap = new JSONObject();
- feedmap.put("pubcount", 0);
- datemap.put("" + feed, feedmap);
- }
- String type = rs.getString("TYPE");
- if (type.equals("pub")) {
- try {
- int n = feedmap.getInt("pubcount");
- feedmap.put("pubcount", n + 1);
- } catch (JSONException e) {
- feedmap.put("pubcount", 1);
- }
- } else if (type.equals("del")) {
- String subid = "" + rs.getInt("DELIVERY_SUBID");
- try {
- int n = feedmap.getInt(subid);
- feedmap.put(subid, n + 1);
- } catch (JSONException e) {
- feedmap.put(subid, 1);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL_OLD)) {
+ ps.setLong(1, from);
+ ps.setLong(2, to);
+ ps.setFetchSize(100000);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ String id = rs.getString("PUBLISH_ID");
+ String date = sdf.format(new Date(getPstart(id)));
+ JSONObject datemap = jo.optJSONObject(date);
+ if (datemap == null) {
+ datemap = new JSONObject();
+ jo.put(date, datemap);
+ }
+ int feed = rs.getInt("FEEDID");
+ JSONObject feedmap = datemap.optJSONObject("" + feed);
+ if (feedmap == null) {
+ feedmap = new JSONObject();
+ feedmap.put("pubcount", 0);
+ datemap.put("" + feed, feedmap);
+ }
+ String type = rs.getString("TYPE");
+ if (type.equals("pub")) {
+ try {
+ int n = feedmap.getInt("pubcount");
+ feedmap.put("pubcount", n + 1);
+ } catch (JSONException e) {
+ feedmap.put("pubcount", 1);
+ }
+ } else if (type.equals("del")) {
+ String subid = "" + rs.getInt("DELIVERY_SUBID");
+ try {
+ int n = feedmap.getInt(subid);
+ feedmap.put(subid, n + 1);
+ } catch (JSONException e) {
+ feedmap.put(subid, 1);
+ }
+ }
}
}
}
- rs.close();
- ps.close();
- db.release(conn);
+ db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
}
@@ -343,59 +341,59 @@ public class FeedReport extends ReportBase {
}
try {
JSONObject jo = new JSONObject();
- LineNumberReader lr = new LineNumberReader(new FileReader(infile));
- String line = lr.readLine();
- while (line != null) {
- String[] tt = line.split(",");
- if (tt[0].startsWith("2")) {
- String date = tt[0];
- switch (rtype) {
- case 1:
- String[] xx = date.split("-");
- Calendar cal = new GregorianCalendar(new Integer(xx[0]), new Integer(xx[1]) - 1, new Integer(xx[2]));
- date = xx[0] + "-W" + cal.get(Calendar.WEEK_OF_YEAR);
- break;
- case 2:
- date = date.substring(0, 7);
- break;
- case 3:
- date = date.substring(0, 4);
- break;
- }
- JSONObject datemap = jo.optJSONObject(date);
- if (datemap == null) {
- datemap = new JSONObject();
- jo.put(date, datemap);
- }
- int feed = Integer.parseInt(tt[2]);
- JSONObject feedmap = datemap.optJSONObject("" + feed);
- if (feedmap == null) {
- feedmap = new JSONObject();
- feedmap.put("pubcount", 0);
- datemap.put("" + feed, feedmap);
- }
- String type = tt[1];
- int count = Integer.parseInt(tt[4]);
- if (type.equals("pub")) {
- try {
- int n = feedmap.getInt("pubcount");
- feedmap.put("pubcount", n + count);
- } catch (JSONException e) {
- feedmap.put("pubcount", count);
+ try(LineNumberReader lr = new LineNumberReader(new FileReader(infile))) {
+ String line = lr.readLine();
+ while (line != null) {
+ String[] tt = line.split(",");
+ if (tt[0].startsWith("2")) {
+ String date = tt[0];
+ switch (rtype) {
+ case 1:
+ String[] xx = date.split("-");
+ Calendar cal = new GregorianCalendar(new Integer(xx[0]), new Integer(xx[1]) - 1, new Integer(xx[2]));
+ date = xx[0] + "-W" + cal.get(Calendar.WEEK_OF_YEAR);
+ break;
+ case 2:
+ date = date.substring(0, 7);
+ break;
+ case 3:
+ date = date.substring(0, 4);
+ break;
+ }
+ JSONObject datemap = jo.optJSONObject(date);
+ if (datemap == null) {
+ datemap = new JSONObject();
+ jo.put(date, datemap);
+ }
+ int feed = Integer.parseInt(tt[2]);
+ JSONObject feedmap = datemap.optJSONObject("" + feed);
+ if (feedmap == null) {
+ feedmap = new JSONObject();
+ feedmap.put("pubcount", 0);
+ datemap.put("" + feed, feedmap);
}
- } else if (type.equals("del")) {
- String subid = tt[3];
- try {
- int n = feedmap.getInt(subid);
- feedmap.put(subid, n + count);
- } catch (JSONException e) {
- feedmap.put(subid, count);
+ String type = tt[1];
+ int count = Integer.parseInt(tt[4]);
+ if (type.equals("pub")) {
+ try {
+ int n = feedmap.getInt("pubcount");
+ feedmap.put("pubcount", n + count);
+ } catch (JSONException e) {
+ feedmap.put("pubcount", count);
+ }
+ } else if (type.equals("del")) {
+ String subid = tt[3];
+ try {
+ int n = feedmap.getInt(subid);
+ feedmap.put(subid, n + count);
+ } catch (JSONException e) {
+ feedmap.put(subid, count);
+ }
}
}
+ line = lr.readLine();
}
- line = lr.readLine();
}
- lr.close();
String t = toHTML(jo);
switch (rtype) {
case 1: