aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
authorRam Koya <rk541m@att.com>2018-08-30 13:49:23 +0000
committerGerrit Code Review <gerrit@onap.org>2018-08-30 13:49:23 +0000
commit8e0bbba18fe05d447e05f2a8687e29eb7fca17bf (patch)
tree71847d7c6fa404f0932e1b87d3c2b3138a131abe /datarouter-prov
parent0422ec9144284e0ac5b4388d87e13d9631a52f52 (diff)
parentc2b240715d463f197c7b8fe482f512ac5feccbd1 (diff)
Merge "fix for sonar blocker in DailyLatencyReport.Java"
Diffstat (limited to 'datarouter-prov')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java47
1 files changed, 23 insertions, 24 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java
index a5281c06..28740c0f 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java
@@ -152,41 +152,40 @@ public class DailyLatencyReport 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()) {
- String id = rs.getString("PUBLISH_ID");
- int feed = rs.getInt("FEEDID");
- long etime = rs.getLong("EVENT_TIME");
- String type = rs.getString("TYPE");
- String fid = rs.getString("FEED_FILEID");
- long clen = rs.getLong("CONTENT_LENGTH");
- String date = sdf.format(new Date(getPstart(id)));
- String key = date + "," + feed;
- Counters c = map.get(key);
- if (c == null) {
- c = new Counters(date, feed);
- 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 id = rs.getString("PUBLISH_ID");
+ int feed = rs.getInt("FEEDID");
+ long etime = rs.getLong("EVENT_TIME");
+ String type = rs.getString("TYPE");
+ String fid = rs.getString("FEED_FILEID");
+ long clen = rs.getLong("CONTENT_LENGTH");
+ String date = sdf.format(new Date(getPstart(id)));
+ String key = date + "," + feed;
+ Counters c = map.get(key);
+ if (c == null) {
+ c = new Counters(date, feed);
+ map.put(key, c);
+ }
+ c.addEvent(etime, type, id, fid, clen);
+ }
}
- c.addEvent(etime, type, id, fid, clen);
+
+ db.release(conn);
}
- 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,minsize,maxsize,avgsize,minlat,maxlat,avglat,fanout");
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);
}