aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src/main')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java157
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java43
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java30
-rwxr-xr-xdatarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java18
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java2
-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
7 files changed, 326 insertions, 330 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
index 800bd9af..5d799eee 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
@@ -156,91 +156,92 @@ public class Main {
sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
sslContextFactory
- .setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
+ .setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
// SSL stuff
/* Skip SSLv3 Fixes */
sslContextFactory.addExcludeProtocols("SSLv3");
logger.info("Excluded protocols prov-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
/* End of SSLv3 Fixes */
- ServerConnector httpsServerConnector = new ServerConnector(server,
- new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
- new HttpConnectionFactory(httpsConfiguration));
- httpsServerConnector.setPort(httpsPort);
- httpsServerConnector.setIdleTimeout(30000);
- httpsServerConnector.setAcceptQueueSize(2);
-
- sslContextFactory.setKeyStoreType(p.getProperty(KEYSTORE_TYPE_PROPERTY, "jks"));
- sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
- sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
- sslContextFactory
- .setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
-
- String ts = p.getProperty(TRUSTSTORE_PATH_PROPERTY);
- if (ts != null && ts.length() > 0) {
- System.out.println("@@ TS -> " + ts);
- sslContextFactory.setTrustStorePath(ts);
- sslContextFactory.setTrustStorePassword(p.getProperty(TRUSTSTORE_PASSWORD_PROPERTY));
- } else {
- sslContextFactory.setTrustStorePath(DEFAULT_TRUSTSTORE);
- sslContextFactory.setTrustStorePassword("changeit");
- }
- sslContextFactory.setWantClientAuth(true);
-
- // Servlet and Filter configuration
- ServletContextHandler ctxt = new ServletContextHandler(0);
- ctxt.setContextPath("/");
- ctxt.addServlet(new ServletHolder(new FeedServlet()), "/feed/*");
- ctxt.addServlet(new ServletHolder(new FeedLogServlet()), "/feedlog/*");
- ctxt.addServlet(new ServletHolder(new PublishServlet()), "/publish/*");
- ctxt.addServlet(new ServletHolder(new SubscribeServlet()), "/subscribe/*");
- ctxt.addServlet(new ServletHolder(new StatisticsServlet()), "/statistics/*");
- ctxt.addServlet(new ServletHolder(new SubLogServlet()), "/sublog/*");
- ctxt.addServlet(new ServletHolder(new GroupServlet()),
- "/group/*"); //Provision groups - Rally US708115 -1610
- ctxt.addServlet(new ServletHolder(new SubscriptionServlet()), "/subs/*");
- ctxt.addServlet(new ServletHolder(new InternalServlet()), "/internal/*");
- ctxt.addServlet(new ServletHolder(new RouteServlet()), "/internal/route/*");
- ctxt.addServlet(new ServletHolder(new DRFeedsServlet()), "/");
- ctxt.addFilter(new FilterHolder(new ThrottleFilter()), "/publish/*", EnumSet.of(DispatcherType.REQUEST));
-
- ContextHandlerCollection contexts = new ContextHandlerCollection();
- contexts.addHandler(ctxt);
-
- // Request log configuration
- NCSARequestLog nrl = new NCSARequestLog();
- nrl.setFilename(
- p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir") + "/request.log.yyyy_mm_dd");
- nrl.setFilenameDateFormat("yyyyMMdd");
- nrl.setRetainDays(90);
- nrl.setAppend(true);
- nrl.setExtended(false);
- nrl.setLogCookies(false);
- nrl.setLogTimeZone("GMT");
-
- RequestLogHandler reqlog = new RequestLogHandler();
- reqlog.setRequestLog(nrl);
-
- // Server's Handler collection
- hc = new HandlerCollection();
- hc.setHandlers(new Handler[]{contexts, new DefaultHandler()});
- hc.addHandler(reqlog);
-
- // Daemon to clean up the log directory on a daily basis
- Timer rolex = new Timer();
- rolex.scheduleAtFixedRate(new PurgeLogDirTask(), 0, 86400000L); // run once per day
-
- // Start LogfileLoader
- LogfileLoader.getLoader();
-
- try (ServerConnector serverConnector = new ServerConnector(server,
- new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
- new HttpConnectionFactory(httpsConfiguration))) {
- serverConnector.setPort(httpsPort);
- serverConnector.setIdleTimeout(500000);
+ try (ServerConnector httpsServerConnector = new ServerConnector(server,
+ new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
+ new HttpConnectionFactory(httpsConfiguration))) {
+ httpsServerConnector.setPort(httpsPort);
+ httpsServerConnector.setIdleTimeout(30000);
+ httpsServerConnector.setAcceptQueueSize(2);
+
+ sslContextFactory.setKeyStoreType(p.getProperty(KEYSTORE_TYPE_PROPERTY, "jks"));
+ sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
+ sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
+ sslContextFactory
+ .setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
+
+ String ts = p.getProperty(TRUSTSTORE_PATH_PROPERTY);
+ if (ts != null && ts.length() > 0) {
+ System.out.println("@@ TS -> " + ts);
+ sslContextFactory.setTrustStorePath(ts);
+ sslContextFactory.setTrustStorePassword(p.getProperty(TRUSTSTORE_PASSWORD_PROPERTY));
+ } else {
+ sslContextFactory.setTrustStorePath(DEFAULT_TRUSTSTORE);
+ sslContextFactory.setTrustStorePassword("changeit");
+ }
+ sslContextFactory.setWantClientAuth(true);
+
+ // Servlet and Filter configuration
+ ServletContextHandler ctxt = new ServletContextHandler(0);
+ ctxt.setContextPath("/");
+ ctxt.addServlet(new ServletHolder(new FeedServlet()), "/feed/*");
+ ctxt.addServlet(new ServletHolder(new FeedLogServlet()), "/feedlog/*");
+ ctxt.addServlet(new ServletHolder(new PublishServlet()), "/publish/*");
+ ctxt.addServlet(new ServletHolder(new SubscribeServlet()), "/subscribe/*");
+ ctxt.addServlet(new ServletHolder(new StatisticsServlet()), "/statistics/*");
+ ctxt.addServlet(new ServletHolder(new SubLogServlet()), "/sublog/*");
+ ctxt.addServlet(new ServletHolder(new GroupServlet()),
+ "/group/*"); //Provision groups - Rally US708115 -1610
+ ctxt.addServlet(new ServletHolder(new SubscriptionServlet()), "/subs/*");
+ ctxt.addServlet(new ServletHolder(new InternalServlet()), "/internal/*");
+ ctxt.addServlet(new ServletHolder(new RouteServlet()), "/internal/route/*");
+ ctxt.addServlet(new ServletHolder(new DRFeedsServlet()), "/");
+ ctxt.addFilter(new FilterHolder(new ThrottleFilter()), "/publish/*", EnumSet.of(DispatcherType.REQUEST));
+
+ ContextHandlerCollection contexts = new ContextHandlerCollection();
+ contexts.addHandler(ctxt);
+
+ // Request log configuration
+ NCSARequestLog nrl = new NCSARequestLog();
+ nrl.setFilename(
+ p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir") + "/request.log.yyyy_mm_dd");
+ nrl.setFilenameDateFormat("yyyyMMdd");
+ nrl.setRetainDays(90);
+ nrl.setAppend(true);
+ nrl.setExtended(false);
+ nrl.setLogCookies(false);
+ nrl.setLogTimeZone("GMT");
+
+ RequestLogHandler reqlog = new RequestLogHandler();
+ reqlog.setRequestLog(nrl);
+
+ // Server's Handler collection
+ hc = new HandlerCollection();
+ hc.setHandlers(new Handler[]{contexts, new DefaultHandler()});
+ hc.addHandler(reqlog);
+
+ // Daemon to clean up the log directory on a daily basis
+ Timer rolex = new Timer();
+ rolex.scheduleAtFixedRate(new PurgeLogDirTask(), 0, 86400000L); // run once per day
+
+ // Start LogfileLoader
+ LogfileLoader.getLoader();
+
+ try (ServerConnector serverConnector = new ServerConnector(server,
+ new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
+ new HttpConnectionFactory(httpsConfiguration))) {
+ serverConnector.setPort(httpsPort);
+ serverConnector.setIdleTimeout(500000);
+ }
+
+ server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
}
-
- server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
}
server.setHandler(hc);
server.setStopAtShutdown(true);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
index 9eeac236..e1eeb786 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
@@ -153,34 +153,35 @@ public class SynchronizerTask extends TimerTask {
String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
String pass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY);
KeyStore keyStore = KeyStore.getInstance(type);
- FileInputStream instream = new FileInputStream(new File(store));
- keyStore.load(instream, pass.toCharArray());
- instream.close();
-
- store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
- pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY);
- KeyStore trustStore = null;
- if (store != null && store.length() > 0) {
- trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- instream = new FileInputStream(new File(store));
- trustStore.load(instream, pass.toCharArray());
- instream.close();
+ try(FileInputStream instream = new FileInputStream(new File(store))) {
+ keyStore.load(instream, pass.toCharArray());
+
}
+ store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
+ pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY);
+ KeyStore trustStore = null;
+ if (store != null && store.length() > 0) {
+ trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ try(FileInputStream instream = new FileInputStream(new File(store))){
+ trustStore.load(instream, pass.toCharArray());
+
+ }
+ }
// We are connecting with the node name, but the certificate will have the CNAME
// So we need to accept a non-matching certificate name
String keystorepass = props.getProperty(
Main.KEYSTORE_PASSWORD_PROPERTY); //itrack.web.att.com/browse/DATARTR-6 for changing hard coded passphase ref
- AbstractHttpClient hc = new DefaultHttpClient();
- SSLSocketFactory socketFactory =
- (trustStore == null)
- ? new SSLSocketFactory(keyStore, keystorepass)
- : new SSLSocketFactory(keyStore, keystorepass, trustStore);
- socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
- Scheme sch = new Scheme("https", 443, socketFactory);
- hc.getConnectionManager().getSchemeRegistry().register(sch);
+ try(AbstractHttpClient hc = new DefaultHttpClient()) {
+ SSLSocketFactory socketFactory =
+ (trustStore == null)
+ ? new SSLSocketFactory(keyStore, keystorepass)
+ : new SSLSocketFactory(keyStore, keystorepass, trustStore);
+ socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ Scheme sch = new Scheme("https", 443, socketFactory);
+ hc.getConnectionManager().getSchemeRegistry().register(sch);
httpclient = hc;
-
+ }
// Run once every 5 seconds to check DNS, etc.
long interval = 0;
try {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
index 1853ee30..70b8e6a0 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
@@ -59,23 +59,23 @@ public class LogRecord extends BaseLogRecord {
Connection conn = null;
try {
conn = db.getConnection();
- Statement stmt = conn.createStatement();
- Iterator<Long[]> iter = bs.getRangeIterator();
- PreparedStatement ps = conn.prepareStatement(sql);
- while (iter.hasNext()) {
- Long[] n = iter.next();
- ps.setLong(1, n[0]);
- ps.setLong(2, n[1]);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- LogRecord lr = new LogRecord(rs);
- os.write(lr.toString().getBytes());
+ try(Statement stmt = conn.createStatement()) {
+ Iterator<Long[]> iter = bs.getRangeIterator();
+ try(PreparedStatement ps = conn.prepareStatement(sql)) {
+ while (iter.hasNext()) {
+ Long[] n = iter.next();
+ ps.setLong(1, n[0]);
+ ps.setLong(2, n[1]);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ LogRecord lr = new LogRecord(rs);
+ os.write(lr.toString().getBytes());
+ }
+ ps.clearParameters();
+ }
+ }
}
- rs.close();
- ps.clearParameters();
}
- ps.close();
- stmt.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java
index 1b368517..9d43bd0a 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java
@@ -105,20 +105,20 @@ public abstract class NodeClass extends Syncable {
public static void reload() {
Map<String, Integer> m = new HashMap<String, Integer>();
PreparedStatement ps = null;
- ResultSet rs=null;
+
try {
DB db = new DB();
@SuppressWarnings("resource")
Connection conn = db.getConnection();
String sql = "select NODEID, NAME from NODES";
ps = conn.prepareStatement(sql);
- rs = ps.executeQuery();
- while (rs.next()) {
- int id = rs.getInt("NODEID");
- String name = rs.getString("NAME");
- m.put(name, id);
+ try(ResultSet rs = ps.executeQuery()) {
+ while (rs.next()) {
+ int id = rs.getInt("NODEID");
+ String name = rs.getString("NAME");
+ m.put(name, id);
+ }
}
- rs.close();
ps.close();
db.release(conn);
} catch (SQLException e) {
@@ -128,10 +128,6 @@ public abstract class NodeClass extends Syncable {
if(ps!=null){
ps.close();
}
- if(rs!=null){
- rs.close();
- }
-
} catch (SQLException e) {
intLogger.error("PROV0005 doInsert: " + e.getMessage(),e);
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
index 595a86db..8e9d5bfd 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
@@ -122,7 +122,7 @@ public class Parameters extends Syncable {
@SuppressWarnings("resource")
Connection conn = db.getConnection();
Statement stmt = conn.createStatement();
- String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = \"" + k + "\"";
+ String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = '" + k + "'";
ResultSet rs = stmt.executeQuery(sql);
if (rs.next()) {
v = new Parameters(rs);
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: