summaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
authorRonan Keogh <ronan.keogh@ericsson.com>2018-09-25 11:44:55 +0100
committerRonan Keogh <ronan.keogh@ericsson.com>2018-09-25 11:44:59 +0100
commit05a33ba49e67befae4e4a680a72cf6340e995a52 (patch)
treed323b53d632d43228c8484a15b462d07e6a642b1 /datarouter-prov
parent61f221fd62846149f7ddd70306e4eb51810a3aa6 (diff)
Fix DailyLatencyReport vulnerabilities
Change-Id: Ib7f794e11fd4b3cf9d60134a57688bdd930829d9 Signed-off-by: Ronan Keogh <ronan.keogh@ericsson.com> Issue-ID: DMAAP-775
Diffstat (limited to 'datarouter-prov')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/reports/DailyLatencyReport.java70
1 files changed, 43 insertions, 27 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 f848733e..f1e0f7cc 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
@@ -37,7 +37,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
-
import org.onap.dmaap.datarouter.provisioning.utils.DB;
/**
@@ -65,42 +64,54 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
* @version $Id: DailyLatencyReport.java,v 1.2 2013/11/06 16:23:54 eby Exp $
*/
public class DailyLatencyReport extends ReportBase {
+
private static final String SELECT_SQL =
"select EVENT_TIME, TYPE, PUBLISH_ID, FEED_FILEID, FEEDID, CONTENT_LENGTH from LOG_RECORDS" +
- " where EVENT_TIME >= ? and EVENT_TIME <= ?";
+ " where EVENT_TIME >= ? and EVENT_TIME <= ?";
private class Job {
+
public long pubtime = 0;
public long clen = 0;
public List<Long> deltime = new ArrayList<Long>();
+
public long minLatency() {
long n = deltime.isEmpty() ? 0 : Long.MAX_VALUE;
- for (Long l : deltime)
- n = Math.min(n, l-pubtime);
+ for (Long l : deltime) {
+ n = Math.min(n, l - pubtime);
+ }
return n;
}
+
public long maxLatency() {
long n = 0;
- for (Long l : deltime)
- n = Math.max(n, l-pubtime);
+ for (Long l : deltime) {
+ n = Math.max(n, l - pubtime);
+ }
return n;
}
+
public long totalLatency() {
long n = 0;
- for (Long l : deltime)
- n += (l-pubtime);
+ for (Long l : deltime) {
+ n += (l - pubtime);
+ }
return n;
}
}
+
private class Counters {
+
public final String date;
public final int feedid;
public final Map<String, Job> jobs;
+
public Counters(String d, int fid) {
date = d;
feedid = fid;
- jobs = new HashMap<String, Job>();
+ jobs = new HashMap<>();
}
+
public void addEvent(long etime, String type, String id, String fid, long clen) {
Job j = jobs.get(id);
if (j == null) {
@@ -114,48 +125,52 @@ public class DailyLatencyReport extends ReportBase {
j.deltime.add(etime);
}
}
+
@Override
public String toString() {
long minsize = Long.MAX_VALUE, maxsize = 0, avgsize = 0;
- long minl = Long.MAX_VALUE, maxl = 0;
- long fanout = 0, totall = 0, totaln = 0;
+ long minl = Long.MAX_VALUE, maxl = 0;
+ long fanout = 0, totall = 0, totaln = 0;
for (Job j : jobs.values()) {
minsize = Math.min(minsize, j.clen);
maxsize = Math.max(maxsize, j.clen);
avgsize += j.clen;
- minl = Math.min(minl, j.minLatency());
- maxl = Math.max(maxl, j.maxLatency());
- totall += j.totalLatency();
- totaln += j.deltime.size();
- fanout += j.deltime.size();
+ minl = Math.min(minl, j.minLatency());
+ maxl = Math.max(maxl, j.maxLatency());
+ totall += j.totalLatency();
+ totaln += j.deltime.size();
+ fanout += j.deltime.size();
}
if (jobs.size() > 0) {
avgsize /= jobs.size();
- fanout /= jobs.size();
+ fanout /= jobs.size();
}
long avgl = (totaln > 0) ? (totall / totaln) : 0;
- return date + "," + feedid + "," + minsize + "," + maxsize + "," + avgsize + "," + minl + "," + maxl + "," + avgl + "," + fanout;
+ return date + "," + feedid + "," + minsize + "," + maxsize + "," + avgsize + "," + minl + "," + maxl + ","
+ + avgl + "," + fanout;
}
}
+
private long getPstart(String t) {
- if (t.indexOf('.') >= 0)
+ if (t.indexOf('.') >= 0) {
t = t.substring(0, t.indexOf('.'));
+ }
return Long.parseLong(t);
}
@Override
public void run() {
- Map<String, Counters> map = new HashMap<String, Counters>();
+ Map<String, Counters> 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();
- try(PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
+ try (PreparedStatement ps = conn.prepareStatement(SELECT_SQL)) {
ps.setLong(1, from);
ps.setLong(2, to);
- try(ResultSet rs = ps.executeQuery()) {
+ try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
String id = rs.getString("PUBLISH_ID");
int feed = rs.getInt("FEEDID");
@@ -177,17 +192,18 @@ public class DailyLatencyReport extends ReportBase {
db.release(conn);
}
} catch (SQLException e) {
- e.printStackTrace();
+ logger.error("SQLException: " + e.getMessage());
}
- logger.debug("Query time: " + (System.currentTimeMillis()-start) + " ms");
- try (PrintWriter os = new PrintWriter(outfile)){
+ logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
+ 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())) {
+ for (String key : new TreeSet<>(map.keySet())) {
Counters c = map.get(key);
os.println(c.toString());
}
} catch (FileNotFoundException e) {
- System.err.println("File cannot be written: "+outfile);
+ System.err.println("File cannot be written: " + outfile);
+ logger.error("FileNotFoundException: " + e.getMessage());
}
}
}