Merge "Fix LogServlet Vulnerabilities"
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
index b54068b..51e5992 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
@@ -137,15 +137,16 @@
/**
* Handle all PUT requests
*/
- protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
+ protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
NodeUtils.setIpAndFqdnForEelf("doPut");
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"),
getIdFromPath(req) + "");
try {
common(req, resp, true);
- }
- catch(IOException ioe){
+ } catch(IOException ioe){
logger.error("IOException" + ioe.getMessage());
+ } catch(ServletException se){
+ logger.error("ServletException" + se.getMessage());
}
}
@@ -158,9 +159,10 @@
getIdFromPath(req) + "");
try {
common(req, resp, false);
- }
- catch(IOException ioe){
+ } catch(IOException ioe){
logger.error("IOException" + ioe.getMessage());
+ } catch(ServletException se){
+ logger.error("ServletException" + se.getMessage());
}
}
@@ -277,9 +279,8 @@
File data = new File(fbase);
File meta = new File(fbase + ".M");
OutputStream dos = null;
- Writer mw = null;
InputStream is = null;
- try {
+ try (Writer mw = new FileWriter(meta)){
StringBuffer mx = new StringBuffer();
mx.append(req.getMethod()).append('\t').append(fileid).append('\n');
Enumeration hnames = req.getHeaderNames();
@@ -353,12 +354,10 @@
}
String dbase = di.getSpool() + "/" + pubid;
Files.createLink(Paths.get(dbase), dpath);
- mw = new FileWriter(meta);
mw.write(metadata);
if (di.getSubId() == null) {
mw.write("X-ATT-DR-ROUTING\t" + t.getRouting() + "\n");
}
- mw.close();
meta.renameTo(new File(dbase + ".M"));
}
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
@@ -383,12 +382,6 @@
} catch (Exception e) {
}
}
- if (mw != null) {
- try {
- mw.close();
- } catch (Exception e) {
- }
- }
try {
data.delete();
} catch (Exception e) {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
index 3838cad..be87e13 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
@@ -535,7 +535,6 @@
mailprops.load(inStream);
} catch (IOException e) {
intlogger.fatal("PROV9003 Opening properties: " + e.getMessage());
- e.printStackTrace();
System.exit(1);
} finally {
try {
@@ -560,7 +559,7 @@
try {
notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
} catch (Exception e) {
- e.printStackTrace();
+ intlogger.warn("Exception: " + e.getMessage());
}
}
mailSendFlag = true;
@@ -697,7 +696,6 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
} finally {
if (conn != null) {
db.release(conn);
@@ -722,7 +720,6 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
} finally {
if (conn != null) {
db.release(conn);
@@ -747,7 +744,6 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
} finally {
if (conn != null) {
db.release(conn);
@@ -910,7 +906,7 @@
return true;
}
} catch (JSONException e) {
- e.printStackTrace();
+ intlogger.error("JSONException: " + e.getMessage());
}
}
return false;
@@ -980,7 +976,7 @@
MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
} catch (Exception e) {
- e.printStackTrace();
+ intlogger.error("Exception: " + e.getMessage());
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
index d7da4dc..68c81d8 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
@@ -90,11 +90,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -211,11 +207,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPost(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPost(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
index d2452e7..827f009 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
@@ -75,11 +75,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doDelete(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doDelete(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -155,11 +151,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -230,11 +222,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPut(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPut(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
index 96a9924..17a1d75 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
@@ -75,11 +75,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -165,11 +161,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPut(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPut(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -288,11 +280,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPost(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPost(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
index 685d552..0d8ed66 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
@@ -182,11 +182,7 @@
String path = req.getPathInfo();
if (path.startsWith("/api/")) {
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doDelete(req, resp);
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
+ super.doDelete(req, resp);
return;
}
String key = path.substring(5);
@@ -253,12 +249,8 @@
}
if (path.equals("/prov")) {
if (isProxyOK(req) && isProxyServer()) {
- try {
- if (super.doGetWithFallback(req, resp)) {
- return;
- }
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ if (super.doGetWithFallback(req, resp)) {
+ return;
}
// fall back to returning the local data if the remote is unreachable
intlogger.info("Active server unavailable; falling back to local copy.");
@@ -305,11 +297,7 @@
}
if (path.startsWith("/api/")) {
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
String key = path.substring(5);
@@ -361,11 +349,7 @@
String path = req.getPathInfo();
if (path.startsWith("/api/")) {
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doPut(req, resp);
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPut(req, resp);
return;
}
String key = path.substring(5);
@@ -414,11 +398,7 @@
String path = req.getPathInfo();
if (path.startsWith("/api/")) {
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doPost(req, resp);
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPost(req, resp);
return;
}
String key = path.substring(5);
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 5d799ee..651d731 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
@@ -90,9 +90,9 @@
public static final String DEFAULT_TRUSTSTORE = "/opt/java/jdk/jdk180/jre/lib/security/cacerts";
public static final String KEYSTORE_TYPE_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.type";
public static final String KEYSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.path";
- public static final String KEYSTORE_PASSWORD_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.password";
+ public static final String KEYSTORE_PASS_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.password";
public static final String TRUSTSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.path";
- public static final String TRUSTSTORE_PASSWORD_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.password";
+ public static final String TRUSTSTORE_PASS_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.password";
/**
* The one and only {@link Server} instance in this JVM
@@ -110,7 +110,7 @@
Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
// Check DB is accessible and contains the expected tables
- if (!checkDatabase(logger)) {
+ if (!checkDatabase()) {
System.exit(1);
}
@@ -154,7 +154,7 @@
// HTTPS connector
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
- sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
+ sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASS_PROPERTY));
sslContextFactory
.setKeyManagerPassword(p.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
// SSL stuff
@@ -172,15 +172,15 @@
sslContextFactory.setKeyStoreType(p.getProperty(KEYSTORE_TYPE_PROPERTY, "jks"));
sslContextFactory.setKeyStorePath(p.getProperty(KEYSTORE_PATH_PROPERTY));
- sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASSWORD_PROPERTY));
+ sslContextFactory.setKeyStorePassword(p.getProperty(KEYSTORE_PASS_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);
+ logger.info("@@ TS -> " + ts);
sslContextFactory.setTrustStorePath(ts);
- sslContextFactory.setTrustStorePassword(p.getProperty(TRUSTSTORE_PASSWORD_PROPERTY));
+ sslContextFactory.setTrustStorePassword(p.getProperty(TRUSTSTORE_PASS_PROPERTY));
} else {
sslContextFactory.setTrustStorePath(DEFAULT_TRUSTSTORE);
sslContextFactory.setTrustStorePassword("changeit");
@@ -255,7 +255,7 @@
logger.info("PROV0001 **** AT&T Data Router Provisioning Server halted.");
}
- private static boolean checkDatabase(Logger logger) {
+ private static boolean checkDatabase() {
DB db = new DB();
return db.runRetroFits();
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
index 66a9d42..ca63f46 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
@@ -54,6 +54,8 @@
import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
+import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError;
+
/**
* This class is the base class for those servlets that need to proxy their requests from the standby to active server.
* Its methods perform the proxy function to the active server. If the active server is not reachable, a 503
@@ -80,11 +82,11 @@
Properties props = (new DB()).getProperties();
String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
- String pass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY);
+ String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
KeyStore keyStore = readStore(store, pass, type);
store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
- pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY);
+ pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
if (store == null || store.length() == 0) {
store = Main.DEFAULT_TRUSTSTORE;
pass = "changeit";
@@ -94,12 +96,12 @@
// We are connecting with the node name, but the certificate will have the CNAME
// So we need to accept a non-matching certificate name
SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore,
- props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY), trustStore);
+ props.getProperty(Main.KEYSTORE_PASS_PROPERTY), trustStore);
socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
sch = new Scheme("https", 443, socketFactory);
inited = true;
} catch (Exception e) {
- e.printStackTrace();
+ intlogger.error("ProxyServlet: " + e.getMessage());
}
intlogger.info("ProxyServlet: inited = " + inited);
}
@@ -111,7 +113,7 @@
} catch (FileNotFoundException fileNotFoundException) {
intlogger.error("ProxyServlet: " + fileNotFoundException.getMessage());
} catch (Exception x) {
- System.err.println("READING TRUSTSTORE: " + x);
+ intlogger.error("READING TRUSTSTORE: " + x);
}
return ks;
}
@@ -151,7 +153,7 @@
* Issue a proxy DELETE to the active provisioning server.
*/
@Override
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
doProxy(req, resp, "DELETE");
}
@@ -159,7 +161,7 @@
* Issue a proxy GET to the active provisioning server.
*/
@Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) {
doProxy(req, resp, "GET");
}
@@ -167,7 +169,7 @@
* Issue a proxy PUT to the active provisioning server.
*/
@Override
- public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) {
doProxy(req, resp, "PUT");
}
@@ -175,7 +177,7 @@
* Issue a proxy POST to the active provisioning server.
*/
@Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) {
doProxy(req, resp, "POST");
}
@@ -185,7 +187,7 @@
*
* @return true if the proxy succeeded
*/
- public boolean doGetWithFallback(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ public boolean doGetWithFallback(HttpServletRequest req, HttpServletResponse resp) {
boolean rv = false;
if (inited) {
String url = buildUrl(req);
@@ -199,24 +201,17 @@
copyRequestHeaders(req, proxy);
// Execute the request
- HttpResponse pxy_response = httpclient.execute(proxy);
+ HttpResponse pxyResponse = httpclient.execute(proxy);
// Get response headers and body
- int code = pxy_response.getStatusLine().getStatusCode();
+ int code = pxyResponse.getStatusLine().getStatusCode();
resp.setStatus(code);
- copyResponseHeaders(pxy_response, resp);
-
- HttpEntity entity = pxy_response.getEntity();
- if (entity != null) {
- InputStream in = entity.getContent();
- IOUtils.copy(in, resp.getOutputStream());
- in.close();
- }
+ copyResponseHeaders(pxyResponse, resp);
+ copyEntityContent(pxyResponse, resp);
rv = true;
} catch (IOException e) {
- System.err.println("ProxyServlet: " + e);
- e.printStackTrace();
+ intlogger.error("ProxyServlet: " + e.getMessage());
} finally {
proxy.releaseConnection();
httpclient.getConnectionManager().shutdown();
@@ -228,7 +223,7 @@
return rv;
}
- private void doProxy(HttpServletRequest req, HttpServletResponse resp, final String method) throws IOException {
+ private void doProxy(HttpServletRequest req, HttpServletResponse resp, final String method) {
if (inited && isProxyServer()) {
String url = buildUrl(req);
intlogger.info("ProxyServlet: proxying " + method + " " + url);
@@ -247,23 +242,16 @@
}
// Execute the request
- HttpResponse pxy_response = httpclient.execute(proxy);
+ HttpResponse pxyResponse = httpclient.execute(proxy);
// Get response headers and body
- int code = pxy_response.getStatusLine().getStatusCode();
+ int code = pxyResponse.getStatusLine().getStatusCode();
resp.setStatus(code);
- copyResponseHeaders(pxy_response, resp);
-
- HttpEntity entity = pxy_response.getEntity();
- if (entity != null) {
- InputStream in = entity.getContent();
- IOUtils.copy(in, resp.getOutputStream());
- in.close();
- }
+ copyResponseHeaders(pxyResponse, resp);
+ copyEntityContent(pxyResponse, resp);
} catch (IOException e) {
intlogger.warn("ProxyServlet: " + e);
- resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- e.printStackTrace();
+ sendResponseError(resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE, "", intlogger);
} finally {
proxy.releaseConnection();
httpclient.getConnectionManager().shutdown();
@@ -271,7 +259,7 @@
}
} else {
intlogger.warn("ProxyServlet: proxy disabled");
- resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, intlogger);
}
}
@@ -306,6 +294,17 @@
}
}
+ private void copyEntityContent(HttpResponse pxyResponse, HttpServletResponse resp) {
+ HttpEntity entity = pxyResponse.getEntity();
+ if (entity != null) {
+ try (InputStream in = entity.getContent()) {
+ IOUtils.copy(in, resp.getOutputStream());
+ } catch (Exception e) {
+ intlogger.error("Exception: " + e.getMessage());
+ }
+ }
+ }
+
public class ProxyHttpRequest extends HttpEntityEnclosingRequestBase {
private final String method;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
index 0550276..4cefdf1 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
@@ -25,11 +25,9 @@
package org.onap.dmaap.datarouter.provisioning;
import java.io.IOException;
-import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
-import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
@@ -98,41 +96,47 @@
setIpAndFqdnForEelf("doPost");
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
redirect(req, resp);
+
}
- private void redirect(HttpServletRequest req, HttpServletResponse resp) throws IOException {
- String[] nodes = getNodes();
- if (nodes == null || nodes.length == 0) {
- resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "There are no nodes defined in the DR network.");
- } else {
- EventLogRecord elr = new EventLogRecord(req);
- int feedid = checkPath(req);
- if (feedid < 0) {
- String message = (feedid == -1)
- ? "Invalid request - Missing or bad feed number."
- : "Invalid request - Missing file ID.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
-
- resp.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+ private void redirect(HttpServletRequest req, HttpServletResponse resp) {
+ try {
+ String[] nodes = getNodes();
+ if (nodes == null || nodes.length == 0) {
+ resp.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "There are no nodes defined in the DR network.");
} else {
- // Generate new URL
- String nextnode = getRedirectNode(feedid, req);
- nextnode = nextnode+":"+DB.HTTPS_PORT;
- String newurl = "https://" + nextnode + "/publish" + req.getPathInfo();
- String qs = req.getQueryString();
- if (qs != null)
- newurl += "?" + qs;
+ EventLogRecord elr = new EventLogRecord(req);
+ int feedid = checkPath(req);
+ if (feedid < 0) {
+ String message = (feedid == -1)
+ ? "Invalid request - Missing or bad feed number."
+ : "Invalid request - Missing file ID.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
- // Log redirect in event log
- String message = "Redirected to: "+newurl;
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_MOVED_PERMANENTLY);
- eventlogger.info(elr);
+ resp.sendError(HttpServletResponse.SC_NOT_FOUND, message);
+ } else {
+ // Generate new URL
+ String nextnode = getRedirectNode(feedid, req);
+ nextnode = nextnode + ":" + DB.HTTPS_PORT;
+ String newurl = "https://" + nextnode + "/publish" + req.getPathInfo();
+ String qs = req.getQueryString();
+ if (qs != null)
+ newurl += "?" + qs;
- resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
- resp.setHeader("Location", newurl);
+ // Log redirect in event log
+ String message = "Redirected to: " + newurl;
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ eventlogger.info(elr);
+
+ resp.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
+ resp.setHeader("Location", newurl);
+ }
}
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+
}
}
private String getRedirectNode(int feedid, HttpServletRequest req) {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
index a9b22ec..12699a4 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
@@ -143,11 +143,7 @@
return;
}
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doDelete(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doDelete(req, resp);
return;
}
@@ -255,11 +251,7 @@
return;
}
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
@@ -355,11 +347,7 @@
return;
}
if (isProxyOK(req) && isProxyServer()) {
- try {
- super.doPost(req, resp);
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
+ super.doPost(req, resp);
return;
}
String path = req.getPathInfo();
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
index e8828f1..1ab45a9 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
@@ -91,11 +91,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -172,7 +168,7 @@
* section in the <b>Provisioning API</b> document for details on how this method should be invoked.
*/
@Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) {
setIpAndFqdnForEelf("doPost");
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
EventLogRecord elr = new EventLogRecord(req);
@@ -185,11 +181,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPost(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
- }
+ super.doPost(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
index 3bfa750..5fa370d 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
@@ -81,11 +81,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doDelete(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
- }
+ super.doDelete(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -161,11 +157,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doGet(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
- }
+ super.doGet(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -236,11 +228,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPut(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
- }
+ super.doPut(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
@@ -390,11 +378,7 @@
return;
}
if (isProxyServer()) {
- try {
- super.doPost(req, resp);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
- }
+ super.doPost(req, resp);
return;
}
String bhdr = req.getHeader(BEHALF_HEADER);
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 f9d0867..9eece14 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
@@ -151,14 +151,14 @@
Properties props = (new DB()).getProperties();
String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
- String pass = props.getProperty(Main.KEYSTORE_PASSWORD_PROPERTY);
+ String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
KeyStore keyStore = KeyStore.getInstance(type);
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);
+ pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
KeyStore trustStore = null;
if (store != null && store.length() > 0) {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -171,7 +171,7 @@
// 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
+ Main.KEYSTORE_PASS_PROPERTY); //itrack.web.att.com/browse/DATARTR-6 for changing hard coded passphase ref
try(AbstractHttpClient hc = new DefaultHttpClient()) {
SSLSocketFactory socketFactory =
(trustStore == null)
@@ -282,7 +282,6 @@
}
} catch (Exception e) {
logger.warn("PROV0020: Caught exception in SynchronizerTask: " + e);
- e.printStackTrace();
}
}
@@ -328,7 +327,7 @@
* Synchronize the Feeds in the JSONArray, with the Feeds in the DB.
*/
private void syncFeeds(JSONArray ja) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
Feed f = new Feed(ja.getJSONObject(n));
@@ -346,7 +345,7 @@
* Synchronize the Subscriptions in the JSONArray, with the Subscriptions in the DB.
*/
private void syncSubs(JSONArray ja) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
//Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
@@ -367,7 +366,7 @@
* Rally:US708115 - Synchronize the Groups in the JSONArray, with the Groups in the DB.
*/
private void syncGroups(JSONArray ja) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
Group g = new Group(ja.getJSONObject(n));
@@ -386,7 +385,7 @@
* Synchronize the Parameters in the JSONObject, with the Parameters in the DB.
*/
private void syncParams(JSONObject jo) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (String k : jo.keySet()) {
String v = "";
try {
@@ -413,7 +412,7 @@
}
private void syncIngressRoutes(JSONArray ja) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
IngressRoute in = new IngressRoute(ja.getJSONObject(n));
@@ -428,7 +427,7 @@
}
private void syncEgressRoutes(JSONObject jo) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (String key : jo.keySet()) {
try {
int sub = Integer.parseInt(key);
@@ -447,7 +446,7 @@
}
private void syncNetworkRoutes(JSONArray ja) {
- Collection<Syncable> coll = new ArrayList<Syncable>();
+ Collection<Syncable> coll = new ArrayList<>();
for (int n = 0; n < ja.length(); n++) {
try {
NetworkRoute nr = new NetworkRoute(ja.getJSONObject(n));
@@ -466,7 +465,7 @@
try {
Map<String, Syncable> newmap = getMap(newc);
Map<String, Syncable> oldmap = getMap(oldc);
- Set<String> union = new TreeSet<String>(newmap.keySet());
+ Set<String> union = new TreeSet<>(newmap.keySet());
union.addAll(oldmap.keySet());
DB db = new DB();
@SuppressWarnings("resource")
@@ -503,13 +502,12 @@
db.release(conn);
} catch (SQLException e) {
logger.warn("PROV5009: problem during sync, exception: " + e);
- e.printStackTrace();
}
return changes;
}
private Map<String, Syncable> getMap(Collection<? extends Syncable> c) {
- Map<String, Syncable> map = new HashMap<String, Syncable>();
+ Map<String, Syncable> map = new HashMap<>();
for (Syncable v : c) {
map.put(v.getKey(), v);
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
index c6788e0..242c105 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
@@ -72,7 +72,7 @@
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return set;
}
@@ -102,14 +102,14 @@
ps.close();
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return v;
@@ -140,14 +140,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -168,14 +168,14 @@
rv = true;
} catch (SQLException e) {
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -194,14 +194,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
index 9c060d5..334863d 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
@@ -82,7 +82,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return count != 0;
}
@@ -133,7 +133,7 @@
db.release(conn);
} catch (SQLException e) {
intlogger.info("countActiveFeeds: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return count;
}
@@ -154,7 +154,7 @@
db.release(conn);
} catch (SQLException e) {
intlogger.info("getMaxFeedID: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return max;
}
@@ -200,7 +200,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return map.values();
}
@@ -234,7 +234,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return list;
}
@@ -271,7 +271,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return feed;
}
@@ -534,14 +534,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -602,7 +602,7 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return rv;
}
@@ -683,13 +683,13 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if (ps != null)
ps.close();
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -716,14 +716,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
index 91d6c1b..3536309 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
@@ -106,7 +106,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return list;
}
@@ -127,7 +127,7 @@
db.release(conn);
} catch (SQLException e) {
intlogger.info("getMaxSubID: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return max;
}
@@ -150,7 +150,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return list;
}
@@ -176,7 +176,7 @@
db.release(conn);
} catch (SQLException e) {
intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return count;
}
@@ -346,14 +346,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -376,14 +376,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -401,14 +401,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
index a4ed60a..6b390c4 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
@@ -99,7 +99,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return set;
}
@@ -137,7 +137,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return rv;
}
@@ -172,14 +172,14 @@
ps.close();
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return v;
@@ -212,7 +212,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return rv;
}
@@ -397,7 +397,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return set;
}
@@ -425,14 +425,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -468,14 +468,14 @@
rv = true;
} catch (SQLException e) {
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
index 00eb6a2..bad6f53 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
@@ -73,7 +73,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
return set;
}
@@ -127,14 +127,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
@@ -157,14 +157,14 @@
rv = true;
} catch (SQLException e) {
intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
}
@@ -185,14 +185,14 @@
} catch (SQLException e) {
rv = false;
intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- e.printStackTrace();
+ intlogger.error("SQLException " + e.getMessage());
}
}
return rv;
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 110c63d..b6ad8e4 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
@@ -214,7 +214,6 @@
}
} catch (Exception e) {
logger.warn("PROV0020: Caught exception in LogfileLoader: " + e);
- e.printStackTrace();
}
}
}
@@ -275,7 +274,7 @@
}
} catch (SQLException e) {
System.err.println(e);
- e.printStackTrace();
+ logger.error(e);
} finally {
db.release(conn);
}
@@ -297,7 +296,7 @@
}
} catch (SQLException e) {
System.err.println(e);
- e.printStackTrace();
+ logger.error(e);
} finally {
db.release(conn);
}
@@ -322,7 +321,7 @@
}
} catch (SQLException e) {
System.err.println(e);
- e.printStackTrace();
+ logger.error(e);
} finally {
db.release(conn);
}
@@ -376,7 +375,7 @@
logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextid, nextid));
} catch (SQLException e) {
System.err.println(e);
- e.printStackTrace();
+ logger.error(e);
} finally {
db.release(conn);
}
@@ -417,19 +416,15 @@
} 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++;
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
index 7b0e0e6..14d1519 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
@@ -27,24 +27,30 @@
import java.io.File;
import java.util.Properties;
import java.util.TimerTask;
+import org.apache.log4j.Logger;
/**
- * This class provides a {@link TimerTask} that purges old logfiles
- * (older than the number of days specified by the org.onap.dmaap.datarouter.provserver.logretention property).
+ * This class provides a {@link TimerTask} that purges old logfiles (older than the number of days specified by the
+ * org.onap.dmaap.datarouter.provserver.logretention property).
*
* @author Robert Eby
* @version $Id: PurgeLogDirTask.java,v 1.2 2013/07/05 13:48:05 eby Exp $
*/
public class PurgeLogDirTask extends TimerTask {
+
private static final long ONEDAY = 86400000L;
private final String logdir;
private final long interval;
+ private Logger utilsLogger;
public PurgeLogDirTask() {
Properties p = (new DB()).getProperties();
logdir = p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");
String s = p.getProperty("org.onap.dmaap.datarouter.provserver.logretention", "30");
+
+ this.utilsLogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.utils");
+
long n = 30;
try {
n = Long.parseLong(s);
@@ -61,12 +67,13 @@
if (dir.exists()) {
long exptime = System.currentTimeMillis() - interval;
for (File logfile : dir.listFiles()) {
- if (logfile.lastModified() < exptime)
+ if (logfile.lastModified() < exptime) {
logfile.delete();
+ }
}
}
} catch (Exception e) {
- e.printStackTrace();
+ utilsLogger.error("Exception: " + e.getMessage());
}
}
}
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 28740c0..f1e0f7c 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.List;
import java.util.Map;
import java.util.TreeSet;
-
import org.onap.dmaap.datarouter.provisioning.utils.DB;
/**
@@ -65,42 +64,54 @@
* @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 @@
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 @@
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());
}
}
}
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 fe9c460..3f67efe 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
@@ -83,7 +83,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ logger.error(e);
}
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
try (PrintWriter os = new PrintWriter(outfile)) {
@@ -91,6 +91,7 @@
os.print(sb.toString());
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
+ logger.error(e);
}
}
@@ -129,6 +130,7 @@
feedmap.put("pubcount", n + 1);
} catch (JSONException e) {
feedmap.put("pubcount", 1);
+ logger.error(e);
}
} else if (type.equals("del")) {
String subid = "" + rs.getInt("DELIVERY_SUBID");
@@ -137,6 +139,7 @@
feedmap.put(subid, n + 1);
} catch (JSONException e) {
feedmap.put(subid, 1);
+ logger.error(e);
}
}
}
@@ -144,7 +147,7 @@
}
db.release(conn);
} catch (SQLException e) {
- e.printStackTrace();
+ logger.error(e);
}
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
try {
@@ -153,6 +156,7 @@
os.close();
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
+ logger.error(e);
}
}
@@ -279,7 +283,7 @@
*
* @param args
*/
- public static void main(String[] args) {
+ public void main(String[] args) {
int rtype = 0; // 0 -> day, 1 -> week, 2 -> month, 3 -> year
String infile = null;
String outfile = null;
@@ -350,6 +354,7 @@
feedmap.put("pubcount", n + count);
} catch (JSONException e) {
feedmap.put("pubcount", count);
+ logger.error(e);
}
} else if (type.equals("del")) {
String subid = tt[3];
@@ -358,6 +363,7 @@
feedmap.put(subid, n + count);
} catch (JSONException e) {
feedmap.put(subid, count);
+ logger.error(e);
}
}
}
@@ -379,7 +385,7 @@
System.out.println(t);
} catch (Exception e) {
System.err.println(e);
- e.printStackTrace();
+ logger.error(e);
}
}
}
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 549511b..f500140 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
@@ -180,7 +180,7 @@
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
} catch (SQLException e) {
- e.printStackTrace();
+ logger.error("SQLException: " + e.getMessage());
}
logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
}
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 51beac9..b580af7 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
@@ -144,7 +144,7 @@
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)){
@@ -155,6 +155,7 @@
}
} catch (FileNotFoundException e) {
System.err.println("File cannot be written: " + outfile);
+ logger.error("FileNotFoundException: " + e.getMessage());
}
}
}
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 34e158a..8d5731f 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
@@ -1,148 +1,147 @@
-/*******************************************************************************
- * ============LICENSE_START==================================================
- * * org.onap.dmaap
- * * ===========================================================================
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- * * http://www.apache.org/licenses/LICENSE-2.0
- * *
- * * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-
-
-package org.onap.dmaap.datarouter.reports;
-
-import java.io.FileNotFoundException;
-import java.io.PrintWriter;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-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;
-
-/**
- * Generate a traffic volume report. The report is a .csv file containing the following columns:
- * <table>
- * <tr><td>date</td><td>the date for this record</td></tr>
- * <tr><td>feedid</td><td>the Feed ID for this record</td></tr>
- * <tr><td>filespublished</td><td>the number of files published on this feed and date</td></tr>
- * <tr><td>bytespublished</td><td>the number of bytes published on this feed and date</td></tr>
- * <tr><td>filesdelivered</td><td>the number of files delivered on this feed and date</td></tr>
- * <tr><td>bytesdelivered</td><td>the number of bytes delivered on this feed and date</td></tr>
- * <tr><td>filesexpired</td><td>the number of files expired on this feed and date</td></tr>
- * <tr><td>bytesexpired</td><td>the number of bytes expired on this feed and date</td></tr>
- * </table>
- *
- * @author Robert P. Eby
- * @version $Id: VolumeReport.java,v 1.3 2014/02/28 15:11:13 eby Exp $
- */
-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;
-
- @Override
- public String toString() {
- return String.format("%d,%d,%d,%d,%d,%d",
- filespublished, bytespublished, filesdelivered,
- bytesdelivered, filesexpired, bytesexpired);
- }
- }
-
- @Override
- public void run() {
- Map<String, Counters> map = new HashMap<String, Counters>();
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
- long start = System.currentTimeMillis();
- try {
- DB db = new DB();
- @SuppressWarnings("resource")
- Connection conn = db.getConnection();
- // We need to run this SELECT in stages, because otherwise we run out of memory!
- final long stepsize = 6000000L;
- boolean go_again = true;
- for (long i = 0; go_again; i += stepsize) {
- 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;
- }
- }
- }
-
- }
- catch (SQLException sqlException)
- {
- loggerVolumeReport.error("SqlException",sqlException);
- }
- }
-
- db.release(conn);
- } catch (SQLException e) {
- e.printStackTrace();
- }
- logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
- try (PrintWriter os = new PrintWriter(outfile)) {
- os.println("date,feedid,filespublished,bytespublished,filesdelivered,bytesdelivered,filesexpired,bytesexpired");
- 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()));
- }
- }
- catch (FileNotFoundException e) {
- System.err.println("File cannot be written: " + outfile);
- }
- }
-}
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+
+
+package org.onap.dmaap.datarouter.reports;
+
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+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;
+
+/**
+ * Generate a traffic volume report. The report is a .csv file containing the following columns:
+ * <table>
+ * <tr><td>date</td><td>the date for this record</td></tr>
+ * <tr><td>feedid</td><td>the Feed ID for this record</td></tr>
+ * <tr><td>filespublished</td><td>the number of files published on this feed and date</td></tr>
+ * <tr><td>bytespublished</td><td>the number of bytes published on this feed and date</td></tr>
+ * <tr><td>filesdelivered</td><td>the number of files delivered on this feed and date</td></tr>
+ * <tr><td>bytesdelivered</td><td>the number of bytes delivered on this feed and date</td></tr>
+ * <tr><td>filesexpired</td><td>the number of files expired on this feed and date</td></tr>
+ * <tr><td>bytesexpired</td><td>the number of bytes expired on this feed and date</td></tr>
+ * </table>
+ *
+ * @author Robert P. Eby
+ * @version $Id: VolumeReport.java,v 1.3 2014/02/28 15:11:13 eby Exp $
+ */
+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 {
+ int filespublished, filesdelivered, filesexpired;
+ long bytespublished, bytesdelivered, bytesexpired;
+
+ @Override
+ public String toString() {
+ return String.format("%d,%d,%d,%d,%d,%d",
+ filespublished, bytespublished, filesdelivered,
+ bytesdelivered, filesexpired, bytesexpired);
+ }
+ }
+
+ @Override
+ public void run() {
+ Map<String, Counters> map = new HashMap<String, Counters>();
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+ long start = System.currentTimeMillis();
+ try {
+ DB db = new DB();
+ @SuppressWarnings("resource")
+ Connection conn = db.getConnection();
+ // We need to run this SELECT in stages, because otherwise we run out of memory!
+ final long stepsize = 6000000L;
+ boolean go_again = true;
+ for (long i = 0; go_again; i += stepsize) {
+ 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;
+ }
+ }
+ }
+ }
+ catch (SQLException sqlException)
+ {
+ loggerVolumeReport.error("SqlException",sqlException);
+ }
+ }
+
+ db.release(conn);
+ } catch (SQLException e) {
+ loggerVolumeReport.error("SQLException: " + e.getMessage());
+ }
+ logger.debug("Query time: " + (System.currentTimeMillis() - start) + " ms");
+ try (PrintWriter os = new PrintWriter(outfile)) {
+ os.println("date,feedid,filespublished,bytespublished,filesdelivered,bytesdelivered,filesexpired,bytesexpired");
+ 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()));
+ }
+ }
+ catch (FileNotFoundException e) {
+ System.err.println("File cannot be written: " + outfile);
+ }
+ }
+}