import java.util.List;\r
import java.util.Map;\r
import java.util.TreeSet;\r
-import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
+import org.onap.dmaap.datarouter.provisioning.utils.ProvDbUtils;\r
\r
/**\r
* Generate a daily per feed latency report. The report is a .csv file containing the following columns:\r
*/\r
public class DailyLatencyReport extends ReportBase {\r
\r
- private static final String SELECT_SQL =\r
- "select EVENT_TIME, TYPE, PUBLISH_ID, FEED_FILEID, FEEDID, CONTENT_LENGTH from LOG_RECORDS" +\r
- " where EVENT_TIME >= ? and EVENT_TIME <= ?";\r
-\r
private class Job {\r
private long pubtime = 0;\r
private long clen = 0;\r
Map<String, Counters> map = new HashMap<>();\r
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");\r
long start = System.currentTimeMillis();\r
- try {\r
- DB db = new DB();\r
- @SuppressWarnings("resource")\r
- Connection conn = db.getConnection();\r
- try (PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {\r
- ps.setLong(1, from);\r
- ps.setLong(2, to);\r
- try (ResultSet rs = ps.executeQuery()) {\r
- while (rs.next()) {\r
- String id = rs.getString("PUBLISH_ID");\r
- int feed = rs.getInt("FEEDID");\r
- long etime = rs.getLong("EVENT_TIME");\r
- String type = rs.getString("TYPE");\r
- String fid = rs.getString("FEED_FILEID");\r
- long clen = rs.getLong("CONTENT_LENGTH");\r
- String date = sdf.format(new Date(getPstart(id)));\r
- String key = date + "," + feed;\r
- Counters c = map.get(key);\r
- if (c == null) {\r
- c = new Counters(date, feed);\r
- map.put(key, c);\r
- }\r
- c.addEvent(etime, type, id, fid, clen);\r
+ try (Connection conn = ProvDbUtils.getInstance().getConnection();\r
+ PreparedStatement ps = conn.prepareStatement(\r
+ "select EVENT_TIME, TYPE, PUBLISH_ID, FEED_FILEID, FEEDID, "\r
+ + "CONTENT_LENGTH from LOG_RECORDS where EVENT_TIME >= ? and EVENT_TIME <= ?")) {\r
+ ps.setLong(1, from);\r
+ ps.setLong(2, to);\r
+ try (ResultSet rs = ps.executeQuery()) {\r
+ while (rs.next()) {\r
+ String id = rs.getString("PUBLISH_ID");\r
+ int feed = rs.getInt("FEEDID");\r
+ long etime = rs.getLong("EVENT_TIME");\r
+ String type = rs.getString("TYPE");\r
+ String fid = rs.getString("FEED_FILEID");\r
+ long clen = rs.getLong("CONTENT_LENGTH");\r
+ String date = sdf.format(new Date(getPstart(id)));\r
+ String key = date + "," + feed;\r
+ Counters c = map.get(key);\r
+ if (c == null) {\r
+ c = new Counters(date, feed);\r
+ map.put(key, c);\r
}\r
+ c.addEvent(etime, type, id, fid, clen);\r
}\r
-\r
- db.release(conn);\r
}\r
} catch (SQLException e) {\r
logger.error("SQLException: " + e.getMessage());\r