aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java58
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java75
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/VolumeReport.java85
3 files changed, 111 insertions, 107 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java
index ba8f15a0..549511b7 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/LatencyReport.java
@@ -145,40 +145,38 @@ public class LatencyReport extends ReportBase {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
- PreparedStatement ps = conn.prepareStatement(SELECT_SQL);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)){
ps.setLong(1, from);
ps.setLong(2, to);
- ResultSet rs = ps.executeQuery();
- PrintWriter os = new PrintWriter(outfile);
- os.println("recordid,feedid,uri,size,min,max,avg,fanout");
- Counters c = null;
- while (rs.next()) {
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- String id = rs.getString("PUBLISH_ID");
- String fid = rs.getString("FEED_FILEID");
- int feed = rs.getInt("FEEDID");
- long clen = rs.getLong("CONTENT_LENGTH");
- if (c != null && !id.equals(c.id)) {
- String line = id + "," + c.toString();
- os.println(line);
- c = null;
+ try(ResultSet rs = ps.executeQuery()) {
+ try(PrintWriter os = new PrintWriter(outfile)) {
+ os.println("recordid,feedid,uri,size,min,max,avg,fanout");
+ Counters c = null;
+ while (rs.next()) {
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ String id = rs.getString("PUBLISH_ID");
+ String fid = rs.getString("FEED_FILEID");
+ int feed = rs.getInt("FEEDID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ if (c != null && !id.equals(c.id)) {
+ String line = id + "," + c.toString();
+ os.println(line);
+ c = null;
+ }
+ if (c == null) {
+ c = new Counters(id, feed, clen, fid);
+ }
+ if (feed != c.feedid)
+ System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);
+ if (clen != c.clen)
+ System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);
+ c.addEvent(type, etime);
+ }
}
- if (c == null) {
- c = new Counters(id, feed, clen, fid);
- }
- if (feed != c.feedid)
- System.err.println("Feed ID mismatch, " + feed + " <=> " + c.feedid);
- if (clen != c.clen)
- System.err.println("Cont Len mismatch, " + clen + " <=> " + c.clen);
-// if (fid != c.fileid)
-// System.err.println("File ID mismatch, "+fid+" <=> "+c.fileid);
- c.addEvent(type, etime);
+ db.release(conn);
+ }
}
- rs.close();
- ps.close();
- db.release(conn);
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
} catch (SQLException e) {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java
index e00c3944..51beac92 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/SubscriberReport.java
@@ -98,62 +98,61 @@ public class SubscriberReport extends ReportBase {
public void run() {
Map<String, Counters> map = new HashMap<String, Counters>();
long start = System.currentTimeMillis();
+
try {
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()) {
- String date = rs.getString("DATE");
- int sub = rs.getInt("DELIVERY_SUBID");
- int res = rs.getInt("RESULT");
- int count = rs.getInt("COUNT");
- String key = date + "," + sub;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, sub);
- map.put(key, c);
+ try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ ps.setLong(1, from);
+ ps.setLong(2, to);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ String date = rs.getString("DATE");
+ int sub = rs.getInt("DELIVERY_SUBID");
+ int res = rs.getInt("RESULT");
+ int count = rs.getInt("COUNT");
+ String key = date + "," + sub;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, sub);
+ map.put(key, c);
+ }
+ c.addCounts(res, count);
+ }
}
- c.addCounts(res, count);
}
- rs.close();
- ps.close();
- ps = conn.prepareStatement(SELECT_SQL2);
- ps.setLong(1, from);
- ps.setLong(2, to);
- rs = ps.executeQuery();
- while (rs.next()) {
- String date = rs.getString("DATE");
- int sub = rs.getInt("DELIVERY_SUBID");
- int count = rs.getInt("COUNT");
- String key = date + "," + sub;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, sub);
- map.put(key, c);
- }
- c.addDlxCount(count);
- }
- rs.close();
- ps.close();
+ try( PreparedStatement ps2 = conn.prepareStatement(SELECT_SQL2)) {
+ ps2.setLong(1, from);
+ ps2.setLong(2, to);
+ try(ResultSet rs2 = ps2.executeQuery()) {
+ while (rs2.next()) {
+ String date = rs2.getString("DATE");
+ int sub = rs2.getInt("DELIVERY_SUBID");
+ int count = rs2.getInt("COUNT");
+ String key = date + "," + sub;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, sub);
+ map.put(key, c);
+ }
+ c.addDlxCount(count);
+ }
+ }
+ }
db.release(conn);
} catch (SQLException e) {
e.printStackTrace();
}
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
- try {
- PrintWriter os = new PrintWriter(outfile);
+ try (PrintWriter os = new PrintWriter(outfile)){
os.println("date,subid,count100,count200,count300,count400,count500,countminus1,countdlx");
for (String key : new TreeSet<String>(map.keySet())) {
Counters c = map.get(key);
os.println(c.toString());
}
- os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
}
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 169db0d2..34e158a7 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
@@ -36,6 +36,7 @@ import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
+import org.apache.log4j.Logger;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
/**
@@ -57,7 +58,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
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 Logger loggerVolumeReport=Logger.getLogger("org.onap.dmaap.datarouter.reports");
private class Counters {
public int filespublished, filesdelivered, filesexpired;
public long bytespublished, bytesdelivered, bytesexpired;
@@ -83,58 +84,64 @@ public class VolumeReport extends ReportBase {
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;
+ try (PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ ps.setLong(1, from);
+ ps.setLong(2, to);
+ ps.setLong(3, i);
+ ps.setLong(4, stepsize);
+ try(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;
+ }
}
- } else if (type.equalsIgnoreCase("exp")) {
- c.filesexpired++;
- c.bytesexpired += clen;
}
+
+ }
+ catch (SQLException sqlException)
+ {
+ loggerVolumeReport.error("SqlException",sqlException);
}
- 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);
+ try (PrintWriter os = new PrintWriter(outfile)) {
os.println("date,feedid,filespublished,bytespublished,filesdelivered,bytesdelivered,filesexpired,bytesexpired");
- for (String key : new TreeSet<String>(map.keySet())) {
+ for(String key :new TreeSet<String>(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) {
+ }
+ catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
}
}