aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java64
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java106
-rw-r--r--datarouter-node/src/main/resources/docker/startup.sh2
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java617
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java49
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedLogServlet.java5
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java2
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java149
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java212
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java166
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java54
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java75
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java258
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java79
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java16
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql145
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/docker-compose.yml11
-rw-r--r--datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties14
-rw-r--r--datarouter-prov/src/main/resources/docker/startup.sh3
-rw-r--r--datarouter-prov/src/main/resources/misc/provcmd15
-rw-r--r--datarouter-prov/src/main/resources/misc/sql_init_01.sql13
-rw-r--r--datarouter-prov/src/main/resources/provserver.properties16
-rw-r--r--datarouter-prov/src/test/java/datarouter/provisioning/AllTests.java29
-rw-r--r--datarouter-prov/src/test/java/datarouter/provisioning/DbTestData.java109
-rw-r--r--datarouter-prov/src/test/java/datarouter/provisioning/FillDB.java148
-rw-r--r--datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java35
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java21
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java81
29 files changed, 1453 insertions, 1043 deletions
diff --git a/.gitignore b/.gitignore
index bf068300..a311f8d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
*.iml
.idea
**/target/
-*.log
+*.log*
*.classpath
*.project
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
index a0d5f618..4af4bd0b 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
@@ -38,15 +38,17 @@ import com.att.eelf.configuration.EELFManager;
/**
* Maintain the configuration of a Data Router node
* <p>
- * The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention subsystems to access configuration information. (Log4J has its own configuration mechanism).
+ * The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
+ * subsystems to access configuration information. (Log4J has its own configuration mechanism).
* <p>
- * There are two basic sets of configuration data. The
- * static local configuration data, stored in a local configuration file (created
- * as part of installation by SWM), and the dynamic global
- * configuration data fetched from the data router provisioning server.
+ * There are two basic sets of configuration data. The static local configuration data, stored in a local configuration
+ * file (created as part of installation by SWM), and the dynamic global configuration data fetched from the data router
+ * provisioning server.
*/
public class NodeConfigManager implements DeliveryQueueHelper {
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.node.NodeConfigManager");
+
+ private static EELFLogger eelflogger = EELFManager.getInstance()
+ .getLogger("org.onap.dmaap.datarouter.node.NodeConfigManager");
private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeConfigManager");
private static NodeConfigManager base = new NodeConfigManager();
@@ -105,12 +107,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
private NodeConfigManager() {
Properties p = new Properties();
try {
- p.load(new FileInputStream(System.getProperty("org.onap.dmaap.datarouter.node.ConfigFile", "/opt/app/datartr/etc/node.properties")));
+ p.load(new FileInputStream(System
+ .getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties")));
} catch (Exception e) {
NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
eelflogger.error(EelfMsgs.MESSAGE_PROPERTIES_LOAD_ERROR);
- logger.error("NODE0301 Unable to load local configuration file " + System.getProperty("org.onap.dmaap.datarouter.node.ConfigFile", "/opt/app/datartr/etc/node.properties"), e);
+ logger.error("NODE0301 Unable to load local configuration file " + System
+ .getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties"), e);
}
provurl = p.getProperty("ProvisioningURL", "https://feeds-drtr.web.att.com/internal/prov");
try {
@@ -262,10 +266,9 @@ public class NodeConfigManager implements DeliveryQueueHelper {
}
/**
- * Process a gofetch request from a particular IP address. If the
- * IP address is not an IP address we would go to to fetch the
- * provisioning data, ignore the request. If the data has been
- * fetched very recently (default 10 seconds), wait a while before fetching again.
+ * Process a gofetch request from a particular IP address. If the IP address is not an IP address we would go to to
+ * fetch the provisioning data, ignore the request. If the data has been fetched very recently (default 10
+ * seconds), wait a while before fetching again.
*/
public synchronized void gofetch(String remoteaddr) {
if (provcheck.isFrom(remoteaddr)) {
@@ -304,7 +307,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
* Given a set of credentials and an IP address, is this request from another node?
*
* @param credentials Credentials offered by the supposed node
- * @param ip IP address the request came from
+ * @param ip IP address the request came from
* @return If the credentials and IP address are recognized, true, otherwise false.
*/
public boolean isAnotherNode(String credentials, String ip) {
@@ -314,9 +317,9 @@ public class NodeConfigManager implements DeliveryQueueHelper {
/**
* Check whether publication is allowed.
*
- * @param feedid The ID of the feed being requested
+ * @param feedid The ID of the feed being requested
* @param credentials The offered credentials
- * @param ip The requesting IP address
+ * @param ip The requesting IP address
* @return True if the IP and credentials are valid for the specified feed.
*/
public String isPublishPermitted(String feedid, String credentials, String ip) {
@@ -326,7 +329,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
/**
* Check who the user is given the feed ID and the offered credentials.
*
- * @param feedid The ID of the feed specified
+ * @param feedid The ID of the feed specified
* @param credentials The offered credentials
* @return Null if the credentials are invalid or the user if they are valid.
*/
@@ -338,8 +341,8 @@ public class NodeConfigManager implements DeliveryQueueHelper {
* Check if the publish request should be sent to another node based on the feedid, user, and source IP address.
*
* @param feedid The ID of the feed specified
- * @param user The publishing user
- * @param ip The IP address of the publish endpoint
+ * @param user The publishing user
+ * @param ip The IP address of the publish endpoint
* @return Null if the request should be accepted or the correct hostname if it should be sent to another node.
*/
public String getIngressNode(String feedid, String user, String ip) {
@@ -359,7 +362,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
/**
* Get a provisioned configuration parameter (from the provisioning server configuration)
*
- * @param name The name of the parameter
+ * @param name The name of the parameter
* @param deflt The value to use if the parameter is not defined
* @return The value of the parameter or deflt if it is not defined.
*/
@@ -379,8 +382,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
}
/**
- * Get all the outbound spooling destinations.
- * This will include both subscriptions and nodes.
+ * Get all the outbound spooling destinations. This will include both subscriptions and nodes.
*/
public DestInfo[] getAllDests() {
return (config.getAllDests());
@@ -404,7 +406,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
* Get the URL to deliver a message to.
*
* @param destinfo The destination information
- * @param fileid The file ID
+ * @param fileid The file ID
* @return The URL to deliver to
*/
public String getDestURL(DestInfo destinfo, String fileid) {
@@ -479,16 +481,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
}
/**
- * Get the maximum number of file delivery attempts before checking
- * if another queue has work to be performed.
+ * Get the maximum number of file delivery attempts before checking if another queue has work to be performed.
*/
public int getFairFileLimit() {
return (fairfilelimit);
}
/**
- * Get the maximum amount of time spent delivering files before
- * checking if another queue has work to be performed.
+ * Get the maximum amount of time spent delivering files before checking if another queue has work to be performed.
*/
public long getFairTimeLimit() {
return (fairtimelimit);
@@ -657,14 +657,16 @@ public class NodeConfigManager implements DeliveryQueueHelper {
}
/**
- * Get the fraction of free spool disk space where we start throwing away undelivered files. This is FREE_DISK_RED_PERCENT / 100.0. Default is 0.05. Limited by 0.01 <= FreeDiskStart <= 0.5.
+ * Get the fraction of free spool disk space where we start throwing away undelivered files. This is
+ * FREE_DISK_RED_PERCENT / 100.0. Default is 0.05. Limited by 0.01 <= FreeDiskStart <= 0.5.
*/
public double getFreeDiskStart() {
return (fdpstart);
}
/**
- * Get the fraction of free spool disk space where we stop throwing away undelivered files. This is FREE_DISK_YELLOW_PERCENT / 100.0. Default is 0.2. Limited by FreeDiskStart <= FreeDiskStop <= 0.5.
+ * Get the fraction of free spool disk space where we stop throwing away undelivered files. This is
+ * FREE_DISK_YELLOW_PERCENT / 100.0. Default is 0.2. Limited by FreeDiskStart <= FreeDiskStop <= 0.5.
*/
public double getFreeDiskStop() {
return (fdpstop);
@@ -677,9 +679,11 @@ public class NodeConfigManager implements DeliveryQueueHelper {
if (provcheck.isFrom(remoteaddr)) {
String sdir = config.getSpoolDir(subid);
if (sdir != null) {
- logger.info("NODE0310 Received subscription reset request for subscription " + subid + " from provisioning server " + remoteaddr);
+ logger.info("NODE0310 Received subscription reset request for subscription " + subid
+ + " from provisioning server " + remoteaddr);
} else {
- logger.info("NODE0311 Received subscription reset request for unknown subscription " + subid + " from provisioning server " + remoteaddr);
+ logger.info("NODE0311 Received subscription reset request for unknown subscription " + subid
+ + " from provisioning server " + remoteaddr);
}
return (sdir);
} else {
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java
index f9d82a77..07e10b2b 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java
@@ -29,66 +29,69 @@ import org.eclipse.jetty.util.ssl.*;
import org.eclipse.jetty.server.*;
import org.apache.log4j.Logger;
+import java.util.Arrays;
+
/**
* The main starting point for the Data Router node
*/
public class NodeMain {
+
private NodeMain() {
}
private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeMain");
- private static class wfconfig implements Runnable {
- private NodeConfigManager ncm;
+ private static class WaitForConfig implements Runnable {
- wfconfig(NodeConfigManager ncm) {
- this.ncm = ncm;
+ private NodeConfigManager localNodeConfigManager;
+
+ WaitForConfig(NodeConfigManager ncm) {
+ this.localNodeConfigManager = ncm;
}
public synchronized void run() {
notify();
}
- synchronized void waitforconfig() {
- ncm.registerConfigTask(this);
- while (!ncm.isConfigured()) {
+ synchronized void waitForConfig() {
+ localNodeConfigManager.registerConfigTask(this);
+ while (!localNodeConfigManager.isConfigured()) {
logger.info("NODE0003 Waiting for Node Configuration");
try {
wait();
} catch (Exception e) {
- logger.debug("NodeMain: waitforconfig exception");
+ logger.debug("NodeMain: waitForConfig exception");
}
}
- ncm.deregisterConfigTask(this);
+ localNodeConfigManager.deregisterConfigTask(this);
logger.info("NODE0004 Node Configuration Data Received");
}
}
- private static Delivery d;
- private static NodeConfigManager ncm;
+ private static Delivery delivery;
+ private static NodeConfigManager nodeConfigManager;
/**
* Reset the retry timer for a subscription
*/
static void resetQueue(String subid, String ip) {
- d.resetQueue(ncm.getSpoolDir(subid, ip));
+ delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
}
/**
* Start the data router.
* <p>
- * The location of the node configuration file can be set using the
- * org.onap.dmaap.datarouter.node.ConfigFile system property. By
- * default, it is "etc/node.properties".
+ * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.ConfigFile system
+ * property. By default, it is "etc/node.properties".
*/
public static void main(String[] args) throws Exception {
logger.info("NODE0001 Data Router Node Starting");
IsFrom.setDNSCache();
- ncm = NodeConfigManager.getInstance();
- logger.info("NODE0002 I am " + ncm.getMyName());
- (new wfconfig(ncm)).waitforconfig();
- d = new Delivery(ncm);
- LogManager lm = new LogManager(ncm);
+ nodeConfigManager = NodeConfigManager.getInstance();
+ logger.info("NODE0002 I am " + nodeConfigManager.getMyName());
+ (new WaitForConfig(nodeConfigManager)).waitForConfig();
+ delivery = new Delivery(nodeConfigManager);
+ LogManager lm = new LogManager(nodeConfigManager);
Server server = new Server();
// HTTP configuration
@@ -97,38 +100,41 @@ public class NodeMain {
httpConfiguration.setRequestHeaderSize(2048);
// HTTP connector
- ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
- httpServerConnector.setPort(ncm.getHttpPort());
-
- // HTTPS configuration
- SslContextFactory sslContextFactory = new SslContextFactory();
- sslContextFactory.setKeyStoreType(ncm.getKSType());
- sslContextFactory.setKeyStorePath(ncm.getKSFile());
- sslContextFactory.setKeyStorePassword(ncm.getKSPass());
- sslContextFactory.setKeyManagerPassword(ncm.getKPass());
- /* Skip SSLv3 Fixes */
- sslContextFactory.addExcludeProtocols("SSLv3");
- logger.info("Excluded protocols node-" + sslContextFactory.getExcludeProtocols());
- /* End of SSLv3 Fixes */
-
- HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
- httpsConfiguration.setRequestHeaderSize(8192);
-
- SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
- secureRequestCustomizer.setStsMaxAge(2000);
- secureRequestCustomizer.setStsIncludeSubDomains(true);
- httpsConfiguration.addCustomizer(secureRequestCustomizer);
-
- // HTTPS connector
- ServerConnector httpsServerConnector = new ServerConnector(server,
- new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
+ ServletContextHandler ctxt;
+ try (ServerConnector httpServerConnector = new ServerConnector(server,
+ new HttpConnectionFactory(httpConfiguration))) {
+ httpServerConnector.setPort(nodeConfigManager.getHttpPort());
+
+ // HTTPS configuration
+ SslContextFactory sslContextFactory = new SslContextFactory();
+ sslContextFactory.setKeyStoreType(nodeConfigManager.getKSType());
+ sslContextFactory.setKeyStorePath(nodeConfigManager.getKSFile());
+ sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
+ sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
+ /* Skip SSLv3 Fixes */
+ sslContextFactory.addExcludeProtocols("SSLv3");
+ logger.info("Excluded protocols node-" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
+ /* End of SSLv3 Fixes */
+
+ HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
+ httpsConfiguration.setRequestHeaderSize(8192);
+
+ SecureRequestCustomizer secureRequestCustomizer = new SecureRequestCustomizer();
+ secureRequestCustomizer.setStsMaxAge(2000);
+ secureRequestCustomizer.setStsIncludeSubDomains(true);
+ httpsConfiguration.addCustomizer(secureRequestCustomizer);
+
+ // HTTPS connector
+ ServerConnector httpsServerConnector = new ServerConnector(server,
+ new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(httpsConfiguration));
- httpsServerConnector.setPort(ncm.getHttpsPort());
- httpsServerConnector.setIdleTimeout(500000);
- httpsServerConnector.setAcceptQueueSize(2);
+ httpsServerConnector.setPort(nodeConfigManager.getHttpsPort());
+ httpsServerConnector.setIdleTimeout(500000);
+ httpsServerConnector.setAcceptQueueSize(2);
- server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
- ServletContextHandler ctxt = new ServletContextHandler(0);
+ server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector});
+ }
+ ctxt = new ServletContextHandler(0);
ctxt.setContextPath("/");
server.setHandler(ctxt);
ctxt.addServlet(new ServletHolder(new NodeServlet()), "/*");
diff --git a/datarouter-node/src/main/resources/docker/startup.sh b/datarouter-node/src/main/resources/docker/startup.sh
index 2384d6df..c4a655fb 100644
--- a/datarouter-node/src/main/resources/docker/startup.sh
+++ b/datarouter-node/src/main/resources/docker/startup.sh
@@ -16,4 +16,4 @@ java -classpath $CLASSPATH org.onap.dmaap.datarouter.node.NodeMain
runner_file="$LIB/datarouter-node-jar-with-dependencies.jar"
echo "Starting using" $runner_file
-java -Dcom.att.eelf.logging.file==/opt/app/datartr/etc/logback.xml -Dcom.att.eelf.logging.path=/ -Dorg.onap.dmaap.datarouter.node.ConfigFile==/opt/app/datartr/etc/node.properties -jar $runner_file \ No newline at end of file
+java -Dcom.att.eelf.logging.file=/opt/app/datartr/etc/logback.xml -Dcom.att.eelf.logging.path=/root -Dorg.onap.dmaap.datarouter.node.properties=/opt/app/datartr/etc/node.properties -jar $runner_file \ No newline at end of file
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 92e52fce..6ed5d8b6 100644
--- 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
@@ -79,132 +79,194 @@ import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
+
/**
- * This is the base class for all Servlets in the provisioning code.
- * It provides standard constants and some common methods.
+ * This is the base class for all Servlets in the provisioning code. It provides standard constants and some common
+ * methods.
*
* @author Robert Eby
* @version $Id: BaseServlet.java,v 1.16 2014/03/12 19:45:40 eby Exp $
*/
@SuppressWarnings("serial")
public class BaseServlet extends HttpServlet implements ProvDataProvider {
- public static final String BEHALF_HEADER = "X-ATT-DR-ON-BEHALF-OF";
- public static final String FEED_BASECONTENT_TYPE = "application/vnd.att-dr.feed";
- public static final String FEED_CONTENT_TYPE = "application/vnd.att-dr.feed; version=2.0";
+
+ public static final String BEHALF_HEADER = "X-ATT-DR-ON-BEHALF-OF";
+ static final String FEED_BASECONTENT_TYPE = "application/vnd.att-dr.feed";
+ public static final String FEED_CONTENT_TYPE = "application/vnd.att-dr.feed; version=2.0";
public static final String FEEDFULL_CONTENT_TYPE = "application/vnd.att-dr.feed-full; version=2.0";
public static final String FEEDLIST_CONTENT_TYPE = "application/vnd.att-dr.feed-list; version=1.0";
- public static final String SUB_BASECONTENT_TYPE = "application/vnd.att-dr.subscription";
- public static final String SUB_CONTENT_TYPE = "application/vnd.att-dr.subscription; version=2.0";
- public static final String SUBFULL_CONTENT_TYPE = "application/vnd.att-dr.subscription-full; version=2.0";
- public static final String SUBLIST_CONTENT_TYPE = "application/vnd.att-dr.subscription-list; version=1.0";
+ static final String SUB_BASECONTENT_TYPE = "application/vnd.att-dr.subscription";
+ public static final String SUB_CONTENT_TYPE = "application/vnd.att-dr.subscription; version=2.0";
+ public static final String SUBFULL_CONTENT_TYPE = "application/vnd.att-dr.subscription-full; version=2.0";
+ static final String SUBLIST_CONTENT_TYPE = "application/vnd.att-dr.subscription-list; version=1.0";
//Adding groups functionality, ...1610
- public static final String GROUP_BASECONTENT_TYPE = "application/vnd.att-dr.group";
- public static final String GROUP_CONTENT_TYPE = "application/vnd.att-dr.group; version=2.0";
- public static final String GROUPFULL_CONTENT_TYPE = "application/vnd.att-dr.group-full; version=2.0";
+ static final String GROUP_BASECONTENT_TYPE = "application/vnd.att-dr.group";
+ public static final String GROUP_CONTENT_TYPE = "application/vnd.att-dr.group; version=2.0";
+ static final String GROUPFULL_CONTENT_TYPE = "application/vnd.att-dr.group-full; version=2.0";
public static final String GROUPLIST_CONTENT_TYPE = "application/vnd.att-dr.fegrouped-list; version=1.0";
- public static final String LOGLIST_CONTENT_TYPE = "application/vnd.att-dr.log-list; version=1.0";
+ public static final String LOGLIST_CONTENT_TYPE = "application/vnd.att-dr.log-list; version=1.0";
public static final String PROVFULL_CONTENT_TYPE1 = "application/vnd.att-dr.provfeed-full; version=1.0";
public static final String PROVFULL_CONTENT_TYPE2 = "application/vnd.att-dr.provfeed-full; version=2.0";
- public static final String CERT_ATTRIBUTE = "javax.servlet.request.X509Certificate";
-
- public static final String DB_PROBLEM_MSG = "There has been a problem with the DB. It is suggested you try the operation again.";
-
- public static final int DEFAULT_MAX_FEEDS = 10000;
- public static final int DEFAULT_MAX_SUBS = 100000;
- public static final int DEFAULT_POKETIMER1 = 5;
- public static final int DEFAULT_POKETIMER2 = 30;
- public static final String DEFAULT_DOMAIN = "web.att.com";
- public static final String DEFAULT_PROVSRVR_NAME = "feeds-drtr.web.att.com";
- public static final String RESEARCH_SUBNET = "135.207.136.128/25";
- public static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610
-
- /** A boolean to trigger one time "provisioning changed" event on startup */
- private static boolean startmsg_flag = true;
- /** This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE) */
- private static boolean require_secure = true;
- /** This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT) */
- private static boolean require_cert = true;
- /** The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES) */
+ public static final String CERT_ATTRIBUTE = "javax.servlet.request.X509Certificate";
+
+ static final String DB_PROBLEM_MSG = "There has been a problem with the DB. It is suggested you try the operation again.";
+
+ private static final int DEFAULT_MAX_FEEDS = 10000;
+ private static final int DEFAULT_MAX_SUBS = 100000;
+ private static final int DEFAULT_POKETIMER1 = 5;
+ private static final int DEFAULT_POKETIMER2 = 30;
+ private static final String DEFAULT_DOMAIN = "onap";
+ private static final String DEFAULT_PROVSRVR_NAME = "dmaap-dr-prov";
+ private static final String RESEARCH_SUBNET = "10.42.0.0/16";
+ private static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610
+
+ /**
+ * A boolean to trigger one time "provisioning changed" event on startup
+ */
+ private static boolean startmsgFlag = true;
+ /**
+ * This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE)
+ */
+ private static boolean requireSecure = true;
+ /**
+ * This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT)
+ */
+ private static boolean requireCert = true;
+ /**
+ * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES)
+ */
private static Set<String> authorizedAddressesAndNetworks = new HashSet<String>();
- /** The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS) */
+ /**
+ * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS)
+ */
private static Set<String> authorizedNames = new HashSet<String>();
- /** The FQDN of the initially "active" provisioning server in this Data Router ecosystem */
- private static String initial_active_pod;
- /** The FQDN of the initially "standby" provisioning server in this Data Router ecosystem */
- private static String initial_standby_pod;
- /** The FQDN of this provisioning server in this Data Router ecosystem */
- private static String this_pod;
- /** "Timer 1" - used to determine when to notify nodes of provisioning changes */
- private static long poke_timer1;
- /** "Timer 2" - used to determine when to notify nodes of provisioning changes */
- private static long poke_timer2;
- /** Array of nodes names and/or FQDNs */
+ /**
+ * The FQDN of the initially "active" provisioning server in this Data Router ecosystem
+ */
+ private static String initialActivePod;
+ /**
+ * The FQDN of the initially "standby" provisioning server in this Data Router ecosystem
+ */
+ private static String initialStandbyPod;
+ /**
+ * The FQDN of this provisioning server in this Data Router ecosystem
+ */
+ private static String thisPod;
+ /**
+ * "Timer 1" - used to determine when to notify nodes of provisioning changes
+ */
+ private static long pokeTimer1;
+ /**
+ * "Timer 2" - used to determine when to notify nodes of provisioning changes
+ */
+ private static long pokeTimer2;
+ /**
+ * Array of nodes names and/or FQDNs
+ */
private static String[] nodes = new String[0];
- /** Array of node IP addresses */
+ /**
+ * Array of node IP addresses
+ */
private static InetAddress[] nodeAddresses = new InetAddress[0];
- /** Array of POD IP addresses */
+ /**
+ * Array of POD IP addresses
+ */
private static InetAddress[] podAddresses = new InetAddress[0];
- /** The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT) */
- protected static int max_feeds = 0;
- /** The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT) */
- protected static int max_subs = 0;
- /** The current number of feeds in the system */
- protected static int active_feeds = 0;
- /** The current number of subscriptions in the system */
- protected static int active_subs = 0;
- /** The domain used to generate a FQDN from the "bare" node names */
- public static String prov_domain = "web.att.com";
- /** The standard FQDN of the provisioning server in this Data Router ecosystem */
- public static String prov_name = "feeds-drtr.web.att.com";
- /** The standard FQDN of the ACTIVE provisioning server in this Data Router ecosystem */
- public static String active_prov_name = "feeds-drtr.web.att.com";
- /** Special subnet that is allowed access to /internal */
- protected static String special_subnet = RESEARCH_SUBNET;
-
- /** Special subnet that is allowed access to /internal to Lab Machine */
- protected static String special_subnet_secondary = RESEARCH_SUBNET;
- protected static String static_routing_nodes = STATIC_ROUTING_NODES; //Adding new param for static Routing - Rally:US664862-1610
-
- /** This logger is used to log provisioning events */
+ /**
+ * The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT)
+ */
+ static int maxFeeds = 0;
+ /**
+ * The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT)
+ */
+ static int maxSubs = 0;
+ /**
+ * The current number of feeds in the system
+ */
+ static int activeFeeds = 0;
+ /**
+ * The current number of subscriptions in the system
+ */
+ static int activeSubs = 0;
+ /**
+ * The domain used to generate a FQDN from the "bare" node names
+ */
+ private static String provDomain = "web.att.com";
+ /**
+ * The standard FQDN of the provisioning server in this Data Router ecosystem
+ */
+ public static String provName = "feeds-drtr.web.att.com";
+ /**
+ * The standard FQDN of the ACTIVE provisioning server in this Data Router ecosystem
+ */
+ public static String activeProvName = "feeds-drtr.web.att.com";
+ /**
+ * Special subnet that is allowed access to /internal
+ */
+ private static String researchSubnet = RESEARCH_SUBNET;
+ /**
+ * Special subnet that is allowed access to /internal to Lab Machine
+ */
+ private static String researchSubnet1 = RESEARCH_SUBNET;
+ private static String staticRoutingNodes = STATIC_ROUTING_NODES; //Adding new param for static Routing - Rally:US664862-1610
+
+ /**
+ * This logger is used to log provisioning events
+ */
protected static Logger eventlogger;
- /** This logger is used to log internal events (errors, etc.) */
+ /**
+ * This logger is used to log internal events (errors, etc.)
+ */
protected static Logger intlogger;
- /** Authorizer - interface to the Policy Engine */
+ /**
+ * Authorizer - interface to the Policy Engine
+ */
protected static Authorizer authz;
- /** The Synchronizer used to sync active DB to standby one */
- protected static SynchronizerTask synctask = null;
+ /**
+ * The Synchronizer used to sync active DB to standby one
+ */
+ private static SynchronizerTask synctask = null;
//Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
private InetAddress thishost;
private InetAddress loopback;
private static Boolean mailSendFlag = false;
- public static final String MAILCONFIG_FILE = "mail.properties";
+ private static final String MAILCONFIG_FILE = "mail.properties";
private static Properties mailprops;
+
+ //DMAAP-597 (Tech Dept) REST request source IP auth relaxation to accommodate OOM kubernetes deploy
+ private static String isAddressAuthEnabled = (new DB()).getProperties()
+ .getProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false");
+
/**
* Initialize data common to all the provisioning server servlets.
*/
protected BaseServlet() {
- if (eventlogger == null)
+ if (eventlogger == null) {
eventlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.events");
- if (intlogger == null)
- intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
- if (authz == null)
+ }
+ if (intlogger == null) {
+ intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
+ }
+ if (authz == null) {
authz = new ProvAuthorizer(this);
- if (startmsg_flag) {
- startmsg_flag = false;
+ }
+ if (startmsgFlag) {
+ startmsgFlag = false;
provisioningParametersChanged();
}
if (synctask == null) {
synctask = SynchronizerTask.getSynchronizer();
}
String name = this.getClass().getName();
- intlogger.info("PROV0002 Servlet "+name+" started.");
+ intlogger.info("PROV0002 Servlet " + name + " started.");
}
+
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
@@ -216,43 +278,52 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
// ignore
}
}
- protected int getIdFromPath(HttpServletRequest req) {
+
+ int getIdFromPath(HttpServletRequest req) {
String path = req.getPathInfo();
- if (path == null || path.length() < 2)
+ if (path == null || path.length() < 2) {
return -1;
+ }
try {
return Integer.parseInt(path.substring(1));
} catch (NumberFormatException e) {
return -1;
}
}
+
/**
* Read the request's input stream and return a JSONObject from it
+ *
* @param req the HTTP request
* @return the JSONObject, or null if the stream cannot be parsed
*/
- protected JSONObject getJSONfromInput(HttpServletRequest req) {
+ JSONObject getJSONfromInput(HttpServletRequest req) {
JSONObject jo = null;
try {
jo = new JSONObject(new JSONTokener(req.getInputStream()));
- if (intlogger.isDebugEnabled())
- intlogger.debug("JSON: "+jo.toString());
+ if (intlogger.isDebugEnabled()) {
+ intlogger.debug("JSON: " + jo.toString());
+ }
} catch (Exception e) {
- intlogger.info("Error reading JSON: "+e);
+ intlogger.info("Error reading JSON: " + e);
}
return jo;
}
+
/**
- * Check if the remote host is authorized to perform provisioning.
- * Is the request secure?
- * Is it coming from an authorized IP address or network (configured via PROV_AUTH_ADDRESSES)?
- * Does it have a valid client certificate (configured via PROV_AUTH_SUBJECTS)?
+ * Check if the remote host is authorized to perform provisioning. Is the request secure? Is it coming from an
+ * authorized IP address or network (configured via PROV_AUTH_ADDRESSES)? Does it have a valid client certificate
+ * (configured via PROV_AUTH_SUBJECTS)?
+ *
* @param request the request
* @return an error string, or null if all is OK
*/
- protected String isAuthorizedForProvisioning(HttpServletRequest request) {
+ String isAuthorizedForProvisioning(HttpServletRequest request) {
+ if (Boolean.parseBoolean(isAddressAuthEnabled)) {
+ return null;
+ }
// Is the request https?
- if (require_secure && !request.isSecure()) {
+ if (requireSecure && !request.isSecure()) {
return "Request must be made over an HTTPS connection.";
}
@@ -265,14 +336,14 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
found |= addressMatchesNetwork(ip, addrnet);
}
if (!found) {
- return "Unauthorized address: "+remote;
+ return "Unauthorized address: " + remote;
}
} catch (UnknownHostException e) {
- return "Unauthorized address: "+remote;
+ return "Unauthorized address: " + remote;
}
// Does remote have a valid certificate?
- if (require_cert) {
+ if (requireCert) {
X509Certificate certs[] = (X509Certificate[]) request.getAttribute(CERT_ATTRIBUTE);
if (certs == null || certs.length == 0) {
return "Client certificate is missing.";
@@ -288,139 +359,159 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
// No problems!
return null;
}
+
/**
* Check if the remote IP address is authorized to see the /internal URL tree.
+ *
* @param request the HTTP request
* @return true iff authorized
*/
- protected boolean isAuthorizedForInternal(HttpServletRequest request) {
+ boolean isAuthorizedForInternal(HttpServletRequest request) {
+
try {
+ if (Boolean.parseBoolean(isAddressAuthEnabled)) {
+ return true;
+ }
InetAddress ip = InetAddress.getByName(request.getRemoteAddr());
for (InetAddress node : getNodeAddresses()) {
- if (node != null && ip.equals(node))
+ if (node != null && ip.equals(node)) {
return true;
+ }
}
for (InetAddress pod : getPodAddresses()) {
- if (pod != null && ip.equals(pod))
+ if (pod != null && ip.equals(pod)) {
return true;
+ }
}
- if (thishost != null && ip.equals(thishost))
+ if (thishost != null && ip.equals(thishost)) {
return true;
- if (loopback != null && ip.equals(loopback))
+ }
+ if (loopback != null && ip.equals(loopback)) {
return true;
+ }
// Also allow the "special subnet" access
- if (addressMatchesNetwork(ip, special_subnet_secondary))
+ if (addressMatchesNetwork(ip, researchSubnet1)) {
return true;
- if (addressMatchesNetwork(ip, special_subnet))
+ }
+ if (addressMatchesNetwork(ip, researchSubnet)) {
return true;
+ }
} catch (UnknownHostException e) {
// ignore
}
return false;
}
+
/**
* Check if an IP address matches a network address.
+ *
* @param ip the IP address
* @param s the network address; a bare IP address may be matched also
* @return true if they intersect
*/
- protected static boolean addressMatchesNetwork(InetAddress ip, String s) {
+ private static boolean addressMatchesNetwork(InetAddress ip, String s) {
int mlen = -1;
int n = s.indexOf("/");
if (n >= 0) {
- mlen = Integer.parseInt(s.substring(n+1));
+ mlen = Integer.parseInt(s.substring(n + 1));
s = s.substring(0, n);
}
try {
InetAddress i2 = InetAddress.getByName(s);
byte[] b1 = ip.getAddress();
byte[] b2 = i2.getAddress();
- if (b1.length != b2.length)
+ if (b1.length != b2.length) {
return false;
+ }
if (mlen > 0) {
byte[] masks = {
- (byte)0x00, (byte)0x80, (byte)0xC0, (byte)0xE0,
- (byte)0xF0, (byte)0xF8, (byte)0xFC, (byte)0xFE
+ (byte) 0x00, (byte) 0x80, (byte) 0xC0, (byte) 0xE0,
+ (byte) 0xF0, (byte) 0xF8, (byte) 0xFC, (byte) 0xFE
};
- byte mask = masks[mlen%8];
- for (n = mlen/8; n < b1.length; n++) {
+ byte mask = masks[mlen % 8];
+ for (n = mlen / 8; n < b1.length; n++) {
b1[n] &= mask;
b2[n] &= mask;
mask = 0;
}
}
- for (n = 0; n < b1.length; n++)
- if (b1[n] != b2[n])
+ for (n = 0; n < b1.length; n++) {
+ if (b1[n] != b2[n]) {
return false;
+ }
+ }
} catch (UnknownHostException e) {
return false;
}
return true;
}
+
/**
- * Something has changed in the provisioning data.
- * Start the timers that will cause the pre-packaged JSON string to be regenerated,
- * and cause nodes and the other provisioning server to be notified.
+ * Something has changed in the provisioning data. Start the timers that will cause the pre-packaged JSON string to
+ * be regenerated, and cause nodes and the other provisioning server to be notified.
*/
public static void provisioningDataChanged() {
long now = System.currentTimeMillis();
Poker p = Poker.getPoker();
- p.setTimers(now + (poke_timer1 * 1000L), now + (poke_timer2 * 1000L));
+ p.setTimers(now + (pokeTimer1 * 1000L), now + (pokeTimer2 * 1000L));
}
+
/**
* Something in the parameters has changed, reload all parameters from the DB.
*/
public static void provisioningParametersChanged() {
- Map<String,String> map = Parameters.getParameters();
- require_secure = getBoolean(map, Parameters.PROV_REQUIRE_SECURE);
- require_cert = getBoolean(map, Parameters.PROV_REQUIRE_CERT);
+ Map<String, String> map = Parameters.getParameters();
+ requireSecure = getBoolean(map, Parameters.PROV_REQUIRE_SECURE);
+ requireCert = getBoolean(map, Parameters.PROV_REQUIRE_CERT);
authorizedAddressesAndNetworks = getSet(map, Parameters.PROV_AUTH_ADDRESSES);
- authorizedNames = getSet (map, Parameters.PROV_AUTH_SUBJECTS);
- nodes = getSet (map, Parameters.NODES).toArray(new String[0]);
- max_feeds = getInt (map, Parameters.PROV_MAXFEED_COUNT, DEFAULT_MAX_FEEDS);
- max_subs = getInt (map, Parameters.PROV_MAXSUB_COUNT, DEFAULT_MAX_SUBS);
- poke_timer1 = getInt (map, Parameters.PROV_POKETIMER1, DEFAULT_POKETIMER1);
- poke_timer2 = getInt (map, Parameters.PROV_POKETIMER2, DEFAULT_POKETIMER2);
- prov_domain = getString (map, Parameters.PROV_DOMAIN, DEFAULT_DOMAIN);
- prov_name = getString (map, Parameters.PROV_NAME, DEFAULT_PROVSRVR_NAME);
- active_prov_name = getString (map, Parameters.PROV_ACTIVE_NAME, prov_name);
- special_subnet = getString (map, Parameters.PROV_SPECIAL_SUBNET, RESEARCH_SUBNET);
- static_routing_nodes = getString (map, Parameters.STATIC_ROUTING_NODES, ""); //Adding new param for static Routing - Rally:US664862-1610
- initial_active_pod = getString (map, Parameters.ACTIVE_POD, "");
- initial_standby_pod = getString (map, Parameters.STANDBY_POD, "");
- static_routing_nodes = getString (map, Parameters.STATIC_ROUTING_NODES, ""); //Adding new param for static Routing - Rally:US664862-1610
- active_feeds = Feed.countActiveFeeds();
- active_subs = Subscription.countActiveSubscriptions();
+ authorizedNames = getSet(map, Parameters.PROV_AUTH_SUBJECTS);
+ nodes = getSet(map, Parameters.NODES).toArray(new String[0]);
+ maxFeeds = getInt(map, Parameters.PROV_MAXFEED_COUNT, DEFAULT_MAX_FEEDS);
+ maxSubs = getInt(map, Parameters.PROV_MAXSUB_COUNT, DEFAULT_MAX_SUBS);
+ pokeTimer1 = getInt(map, Parameters.PROV_POKETIMER1, DEFAULT_POKETIMER1);
+ pokeTimer2 = getInt(map, Parameters.PROV_POKETIMER2, DEFAULT_POKETIMER2);
+ provDomain = getString(map, Parameters.PROV_DOMAIN, DEFAULT_DOMAIN);
+ provName = getString(map, Parameters.PROV_NAME, DEFAULT_PROVSRVR_NAME);
+ activeProvName = getString(map, Parameters.PROV_ACTIVE_NAME, provName);
+ researchSubnet = getString(map, Parameters.PROV_SPECIAL_SUBNET, RESEARCH_SUBNET);
+ staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
+ ""); //Adding new param for static Routing - Rally:US664862-1610
+ initialActivePod = getString(map, Parameters.ACTIVE_POD, "");
+ initialStandbyPod = getString(map, Parameters.STANDBY_POD, "");
+ staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
+ ""); //Adding new param for static Routing - Rally:US664862-1610
+ activeFeeds = Feed.countActiveFeeds();
+ activeSubs = Subscription.countActiveSubscriptions();
try {
- this_pod = InetAddress.getLocalHost().getHostName();
+ thisPod = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
- this_pod = "";
+ thisPod = "";
intlogger.warn("PROV0014 Cannot determine the name of this provisioning server.");
}
// Normalize the nodes, and fill in nodeAddresses
InetAddress[] na = new InetAddress[nodes.length];
for (int i = 0; i < nodes.length; i++) {
- if (nodes[i].indexOf('.') < 0)
- nodes[i] += "." + prov_domain;
+ if (nodes[i].indexOf('.') < 0) {
+ nodes[i] += "." + provDomain;
+ }
try {
na[i] = InetAddress.getByName(nodes[i]);
- intlogger.debug("PROV0003 DNS lookup: "+nodes[i]+" => "+na[i].toString());
+ intlogger.debug("PROV0003 DNS lookup: " + nodes[i] + " => " + na[i].toString());
} catch (UnknownHostException e) {
na[i] = null;
- intlogger.warn("PROV0004 Cannot lookup "+nodes[i]+": "+e);
+ intlogger.warn("PROV0004 Cannot lookup " + nodes[i] + ": " + e);
}
}
//Reset Nodes arr after - removing static routing Nodes, Rally Userstory - US664862 .
List<String> filterNodes = new ArrayList<>();
- for (int i = 0; i < nodes.length; i++) {
- if(!static_routing_nodes.contains(nodes[i])){
- filterNodes.add(nodes[i]);
+ for (String node : nodes) {
+ if (!staticRoutingNodes.contains(node)) {
+ filterNodes.add(node);
}
}
- String [] filteredNodes = filterNodes.toArray(new String[filterNodes.size()]);
- nodes = filteredNodes;
+ nodes = filterNodes.toArray(new String[filterNodes.size()]);
nodeAddresses = na;
NodeClass.setNodes(nodes); // update NODES table
@@ -429,14 +520,15 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
String[] pods = getPods();
na = new InetAddress[pods.length];
for (int i = 0; i < pods.length; i++) {
- if (pods[i].indexOf('.') < 0)
- pods[i] += "." + prov_domain;
+ if (pods[i].indexOf('.') < 0) {
+ pods[i] += "." + provDomain;
+ }
try {
na[i] = InetAddress.getByName(pods[i]);
- intlogger.debug("PROV0003 DNS lookup: "+pods[i]+" => "+na[i].toString());
+ intlogger.debug("PROV0003 DNS lookup: " + pods[i] + " => " + na[i].toString());
} catch (UnknownHostException e) {
na[i] = null;
- intlogger.warn("PROV0004 Cannot lookup "+pods[i]+": "+e);
+ intlogger.warn("PROV0004 Cannot lookup " + pods[i] + ": " + e);
}
}
podAddresses = na;
@@ -445,16 +537,17 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
ThrottleFilter.configure();
// Check if we are active or standby POD
- if (!isInitialActivePOD() && !isInitialStandbyPOD())
+ if (!isInitialActivePOD() && !isInitialStandbyPOD()) {
intlogger.warn("PROV0015 This machine is neither the active nor the standby POD.");
+ }
}
- /**Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
- * Load mail properties.
- * @author vs215k
+ /**
+ * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Load mail properties.
*
- **/
+ * @author vs215k
+ **/
private void loadMailProperties() {
if (mailprops == null) {
mailprops = new Properties();
@@ -462,46 +555,45 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
try {
mailprops.load(inStream);
} catch (IOException e) {
- intlogger.fatal("PROV9003 Opening properties: "+e.getMessage());
+ intlogger.fatal("PROV9003 Opening properties: " + e.getMessage());
e.printStackTrace();
System.exit(1);
- }
- finally {
+ } finally {
try {
inStream.close();
- }
- catch (IOException e) {
+ } catch (IOException e) {
}
}
}
}
- /**Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
- * Check if HTTPS Relexaction is enabled
- * @author vs215k
+ /**
+ * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Check if HTTPS Relexaction is enabled
*
- **/
+ * @author vs215k
+ **/
private void checkHttpsRelaxation() {
- if(mailSendFlag == false) {
+ if (!mailSendFlag) {
Properties p = (new DB()).getProperties();
- intlogger.info("HTTPS relaxatio: "+p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
+ intlogger.info("HTTPS relaxatio: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
- if(p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) {
+ if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) {
try {
- notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
- }
- catch (Exception e) {
+ notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
+ } catch (Exception e) {
e.printStackTrace();
}
- }
+ }
mailSendFlag = true;
}
}
- /**Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
- * @author vs215k
+ /**
+ * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
+ *
* @param email - list of email ids to notify if HTTP relexcation is enabled.
- **/
+ * @author vs215k
+ **/
private void notifyPSTeam(String email) throws Exception {
loadMailProperties(); //Load HTTPS Relex mail properties.
String[] emails = email.split(Pattern.quote("|"));
@@ -516,88 +608,101 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
try {
- Message msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress(mailprops.get("com.att.dmaap.datarouter.mail.from").toString()));
+ Message msg = new MimeMessage(session);
+ msg.setFrom(new InternetAddress(mailprops.get("com.att.dmaap.datarouter.mail.from").toString()));
- InternetAddress[] addressTo = new InternetAddress[emails.length];
- for ( int x =0 ; x < emails.length; x++) {
- addressTo[x] = new InternetAddress(emails[x]);
- }
+ InternetAddress[] addressTo = new InternetAddress[emails.length];
+ for (int x = 0; x < emails.length; x++) {
+ addressTo[x] = new InternetAddress(emails[x]);
+ }
- msg.addRecipients(Message.RecipientType.TO, addressTo);
- msg.setSubject(mailprops.get("com.att.dmaap.datarouter.mail.subject").toString());
- htmlPart.setContent(mailprops.get("com.att.dmaap.datarouter.mail.body").toString().replace("[SERVER]", InetAddress.getLocalHost().getHostName()), "text/html");
- mp.addBodyPart(htmlPart);
- msg.setContent(mp);
+ msg.addRecipients(Message.RecipientType.TO, addressTo);
+ msg.setSubject(mailprops.get("com.att.dmaap.datarouter.mail.subject").toString());
+ htmlPart.setContent(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
+ .replace("[SERVER]", InetAddress.getLocalHost().getHostName()), "text/html");
+ mp.addBodyPart(htmlPart);
+ msg.setContent(mp);
- System.out.println(mailprops.get("com.att.dmaap.datarouter.mail.body").toString().replace("[SERVER]", InetAddress.getLocalHost().getHostName()));
+ System.out.println(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
+ .replace("[SERVER]", InetAddress.getLocalHost().getHostName()));
- Transport.send(msg);
- intlogger.info("HTTPS relaxation mail is sent to - : "+email);
+ Transport.send(msg);
+ intlogger.info("HTTPS relaxation mail is sent to - : " + email);
} catch (AddressException e) {
- intlogger.error("Invalid email address, unable to send https relaxation mail to - : "+email);
+ intlogger.error("Invalid email address, unable to send https relaxation mail to - : " + email);
} catch (MessagingException e) {
- intlogger.error("Invalid email address, unable to send https relaxation mail to - : "+email);
+ intlogger.error("Invalid email address, unable to send https relaxation mail to - : " + email);
}
}
/**
* Get an array of all node names in the DR network.
+ *
* @return an array of Strings
*/
public static String[] getNodes() {
return nodes;
}
+
/**
* Get an array of all node InetAddresses in the DR network.
+ *
* @return an array of InetAddresses
*/
public static InetAddress[] getNodeAddresses() {
return nodeAddresses;
}
+
/**
* Get an array of all POD names in the DR network.
+ *
* @return an array of Strings
*/
public static String[] getPods() {
- return new String[] { initial_active_pod, initial_standby_pod };
+ return new String[]{initialActivePod, initialStandbyPod};
}
+
/**
* Get an array of all POD InetAddresses in the DR network.
+ *
* @return an array of InetAddresses
*/
- public static InetAddress[] getPodAddresses() {
+ private static InetAddress[] getPodAddresses() {
return podAddresses;
}
+
/**
- * Gets the FQDN of the initially ACTIVE provisioning server (POD).
- * Note: this used to be called isActivePOD(), however, that is a misnomer, as the active status
- * could shift to the standby POD without these parameters changing. Hence, the function names
- * have been changed to more accurately reflect their purpose.
+ * Gets the FQDN of the initially ACTIVE provisioning server (POD). Note: this used to be called isActivePOD(),
+ * however, that is a misnomer, as the active status could shift to the standby POD without these parameters
+ * changing. Hence, the function names have been changed to more accurately reflect their purpose.
+ *
* @return the FQDN
*/
public static boolean isInitialActivePOD() {
- return this_pod.equals(initial_active_pod);
+ return thisPod.equals(initialActivePod);
}
+
/**
- * Gets the FQDN of the initially STANDBY provisioning server (POD).
- * Note: this used to be called isStandbyPOD(), however, that is a misnomer, as the standby status
- * could shift to the active POD without these parameters changing. Hence, the function names
- * have been changed to more accurately reflect their purpose.
+ * Gets the FQDN of the initially STANDBY provisioning server (POD). Note: this used to be called isStandbyPOD(),
+ * however, that is a misnomer, as the standby status could shift to the active POD without these parameters
+ * changing. Hence, the function names have been changed to more accurately reflect their purpose.
+ *
* @return the FQDN
*/
public static boolean isInitialStandbyPOD() {
- return this_pod.equals(initial_standby_pod);
+ return thisPod.equals(initialStandbyPod);
}
+
/**
* INSERT an {@link Insertable} bean into the database.
+ *
* @param bean the bean representing a row to insert
* @return true if the INSERT was successful
*/
protected boolean doInsert(Insertable bean) {
- boolean rv = false;
+ boolean rv;
DB db = new DB();
Connection conn = null;
try {
@@ -605,21 +710,24 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
rv = bean.doInsert(conn);
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0005 doInsert: "+e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage());
e.printStackTrace();
} finally {
- if (conn != null)
+ if (conn != null) {
db.release(conn);
+ }
}
return rv;
}
+
/**
* UPDATE an {@link Updateable} bean in the database.
+ *
* @param bean the bean representing a row to update
* @return true if the UPDATE was successful
*/
protected boolean doUpdate(Updateable bean) {
- boolean rv = false;
+ boolean rv;
DB db = new DB();
Connection conn = null;
try {
@@ -627,21 +735,24 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
rv = bean.doUpdate(conn);
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: "+e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
e.printStackTrace();
} finally {
- if (conn != null)
+ if (conn != null) {
db.release(conn);
+ }
}
return rv;
}
+
/**
* DELETE an {@link Deleteable} bean from the database.
+ *
* @param bean the bean representing a row to delete
* @return true if the DELETE was successful
*/
protected boolean doDelete(Deleteable bean) {
- boolean rv = false;
+ boolean rv;
DB db = new DB();
Connection conn = null;
try {
@@ -649,23 +760,27 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
rv = bean.doDelete(conn);
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: "+e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage());
e.printStackTrace();
} finally {
- if (conn != null)
+ if (conn != null) {
db.release(conn);
+ }
}
return rv;
}
- private static boolean getBoolean(Map<String,String> map, String name) {
+
+ private static boolean getBoolean(Map<String, String> map, String name) {
String s = map.get(name);
return (s != null) && s.equalsIgnoreCase("true");
}
- private static String getString(Map<String,String> map, String name, String dflt) {
+
+ private static String getString(Map<String, String> map, String name, String dflt) {
String s = map.get(name);
return (s != null) ? s : dflt;
}
- private static int getInt(Map<String,String> map, String name, int dflt) {
+
+ private static int getInt(Map<String, String> map, String name, int dflt) {
try {
String s = map.get(name);
return Integer.parseInt(s);
@@ -673,7 +788,8 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
return dflt;
}
}
- private static Set<String> getSet(Map<String,String> map, String name) {
+
+ private static Set<String> getSet(Map<String, String> map, String name) {
Set<String> set = new HashSet<String>();
String s = map.get(name);
if (s != null) {
@@ -681,8 +797,9 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
if (pp != null) {
for (String t : pp) {
String t2 = t.trim();
- if (t2.length() > 0)
+ if (t2.length() > 0) {
set.add(t2);
+ }
}
}
}
@@ -690,36 +807,43 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/**
- * A class used to encapsulate a Content-type header, separating out the "version" attribute
- * (which defaults to "1.0" if missing).
+ * A class used to encapsulate a Content-type header, separating out the "version" attribute (which defaults to
+ * "1.0" if missing).
*/
public class ContentHeader {
+
private String type = "";
private Map<String, String> map = new HashMap<String, String>();
- public ContentHeader() {
+
+ ContentHeader() {
this("", "1.0");
}
- public ContentHeader(String t, String v) {
+
+ ContentHeader(String t, String v) {
type = t.trim();
map.put("version", v);
}
+
public String getType() {
return type;
}
+
public String getAttribute(String key) {
String s = map.get(key);
- if (s == null)
+ if (s == null) {
s = "";
+ }
return s;
}
}
/**
* Get the ContentHeader from an HTTP request.
+ *
* @param req the request
* @return the header, encapsulated in a ContentHeader object
*/
- public ContentHeader getContentHeader(HttpServletRequest req) {
+ ContentHeader getContentHeader(HttpServletRequest req) {
ContentHeader ch = new ContentHeader();
String s = req.getHeader("Content-Type");
if (s != null) {
@@ -729,8 +853,8 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
int ix = pp[i].indexOf('=');
if (ix > 0) {
String k = pp[i].substring(0, ix).trim();
- String v = pp[i].substring(ix+1).trim();
- ch.map.put(k, v);
+ String v = pp[i].substring(ix + 1).trim();
+ ch.map.put(k, v);
} else {
ch.map.put(pp[i].trim(), "");
}
@@ -738,38 +862,44 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
return ch;
}
+
// Methods for the Policy Engine classes - ProvDataProvider interface
@Override
public String getFeedOwner(String feedId) {
try {
int n = Integer.parseInt(feedId);
Feed f = Feed.getFeedById(n);
- if (f != null)
+ if (f != null) {
return f.getPublisher();
+ }
} catch (NumberFormatException e) {
// ignore
}
return null;
}
+
@Override
public String getFeedClassification(String feedId) {
try {
int n = Integer.parseInt(feedId);
Feed f = Feed.getFeedById(n);
- if (f != null)
+ if (f != null) {
return f.getAuthorization().getClassification();
+ }
} catch (NumberFormatException e) {
// ignore
}
return null;
}
+
@Override
public String getSubscriptionOwner(String subId) {
try {
int n = Integer.parseInt(subId);
Subscription s = Subscription.getSubscriptionById(n);
- if (s != null)
+ if (s != null) {
return s.getSubscriber();
+ }
} catch (NumberFormatException e) {
// ignore
}
@@ -783,18 +913,19 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
*/
private boolean isUserMemberOfGroup(Group group, String user) {
- String groupdetails = group.getMembers().replace("]", "").replace("[", "");
- String s[] = groupdetails.split("},");
+ String groupDetails = group.getMembers().replace("]", "").replace("[", "");
+ String[] s = groupDetails.split("},");
- for(int i=0; i < s.length; i++) {
- JSONObject jsonObj = null;
- try {
- jsonObj = new JSONObject(s[i]+"}");
- if(jsonObj.get("id").equals(user))
- return true;
- } catch (JSONException e) {
- e.printStackTrace();
+ for (String value : s) {
+ JSONObject jsonObj;
+ try {
+ jsonObj = new JSONObject(value + "}");
+ if (jsonObj.get("id").equals(user)) {
+ return true;
}
+ } catch (JSONException e) {
+ e.printStackTrace();
+ }
}
return false;
@@ -812,9 +943,10 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
Feed f = Feed.getFeedById(n);
if (f != null) {
int groupid = f.getGroupid();
- if(groupid > 0) {
+ if (groupid > 0) {
Group group = Group.getGroupById(groupid);
- if(isUserMemberOfGroup(group, owner)) {
+ assert group != null;
+ if (isUserMemberOfGroup(group, owner)) {
return group.getAuthid();
}
}
@@ -837,9 +969,10 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
Subscription s = Subscription.getSubscriptionById(n);
if (s != null) {
int groupid = s.getGroupid();
- if(groupid > 0) {
+ if (groupid > 0) {
Group group = Group.getGroupById(groupid);
- if(isUserMemberOfGroup(group, owner)) {
+ assert group != null;
+ if (isUserMemberOfGroup(group, owner)) {
return group.getAuthid();
}
}
@@ -854,7 +987,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
* @Method - setIpAndFqdnForEelf - Rally:US664892
* @Params - method, prints method name in EELF log.
*/
- protected void setIpAndFqdnForEelf(String method) {
+ void setIpAndFqdnForEelf(String method) {
MDC.clear();
MDC.put(MDC_SERVICE_NAME, method);
try {
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 dc9ec3ad..47156d28 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
@@ -42,17 +42,18 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
/**
- * This servlet handles provisioning for the &lt;drFeedsURL&gt; which is the URL on the
- * provisioning server used to create new feeds. It supports POST to create new feeds,
- * and GET to support the Feeds Collection Query function.
+ * This servlet handles provisioning for the &lt;drFeedsURL&gt; which is the URL on the provisioning server used to
+ * create new feeds. It supports POST to create new feeds, and GET to support the Feeds Collection Query function.
*
* @author Robert Eby
* @version $Id$
*/
@SuppressWarnings("serial")
public class DRFeedsServlet extends ProxyServlet {
+
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.DRFeedsServlet");
+ private static EELFLogger eelflogger = EELFManager.getInstance()
+ .getLogger("org.onap.dmaap.datarouter.provisioning.DRFeedsServlet");
/**
* DELETE on the &lt;drFeedsURL&gt; -- not supported.
@@ -60,7 +61,7 @@ public class DRFeedsServlet extends ProxyServlet {
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
String message = "DELETE not allowed for the drFeedsURL.";
EventLogRecord elr = new EventLogRecord(req);
elr.setMessage(message);
@@ -68,15 +69,15 @@ public class DRFeedsServlet extends ProxyServlet {
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
}
+
/**
- * GET on the &lt;drFeedsURL&gt; -- query the list of feeds already existing in the DB.
- * See the <i>Feeds Collection Queries</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * GET on the &lt;drFeedsURL&gt; -- query the list of feeds already existing in the DB. See the <i>Feeds Collection
+ * Queries</i> section in the <b>Provisioning API</b> document for details on how this method should be invoked.
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
String message = isAuthorizedForProvisioning(req);
if (message != null) {
@@ -92,14 +93,15 @@ public class DRFeedsServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return;
}
- String path = req.getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
+ String path = req
+ .getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
if (path != null && !path.equals("/")) {
message = "Bad URL.";
elr.setMessage(message);
@@ -110,7 +112,7 @@ public class DRFeedsServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -161,13 +163,14 @@ public class DRFeedsServlet extends ProxyServlet {
resp.getOutputStream().print(t);
}
}
+
/**
* PUT on the &lt;drFeedsURL&gt; -- not supported.
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
String message = "PUT not allowed for the drFeedsURL.";
EventLogRecord elr = new EventLogRecord(req);
elr.setMessage(message);
@@ -175,10 +178,10 @@ public class DRFeedsServlet extends ProxyServlet {
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
}
+
/**
- * POST on the &lt;drFeedsURL&gt; -- create a new feed.
- * See the <i>Creating a Feed</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * POST on the &lt;drFeedsURL&gt; -- create a new feed. See the <i>Creating a Feed</i> 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 {
@@ -199,14 +202,15 @@ public class DRFeedsServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return;
}
- String path = req.getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
+ String path = req
+ .getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
if (path != null && !path.equals("/")) {
message = "Bad URL.";
elr.setMessage(message);
@@ -228,7 +232,7 @@ public class DRFeedsServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -245,10 +249,11 @@ public class DRFeedsServlet extends ProxyServlet {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return;
}
- if (intlogger.isDebugEnabled())
+ if (intlogger.isDebugEnabled()) {
intlogger.debug(jo.toString());
- if (++active_feeds > max_feeds) {
- active_feeds--;
+ }
+ if (++activeFeeds > maxFeeds) {
+ activeFeeds--;
message = "Cannot create feed; the maximum number of feeds has been configured.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_CONFLICT);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedLogServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedLogServlet.java
index 7ac4bbee..2a1a8424 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedLogServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedLogServlet.java
@@ -24,14 +24,15 @@
package org.onap.dmaap.datarouter.provisioning;
/**
- * This servlet handles requests to the &lt;feedLogURL&gt;
- * which are generated by the provisioning server to handle the log query API.
+ * This servlet handles requests to the &lt;feedLogURL&gt; which are generated by the provisioning server to handle the
+ * log query API.
*
* @author Robert Eby
* @version $Id: FeedLogServlet.java,v 1.1 2013/04/26 21:00:24 eby Exp $
*/
@SuppressWarnings("serial")
public class FeedLogServlet extends LogServlet {
+
public FeedLogServlet() {
super(true);
}
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 d0f529c9..3f8929e7 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
@@ -116,7 +116,7 @@ public class FeedServlet extends ProxyServlet {
// Delete FEED table entry (set DELETED flag)
feed.setDeleted(true);
if (doUpdate(feed)) {
- active_feeds--;
+ activeFeeds--;
// send response
elr.setResult(HttpServletResponse.SC_NO_CONTENT);
eventlogger.info(elr);
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 27192089..61845cef 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
@@ -53,81 +53,86 @@ import com.att.eelf.configuration.EELFManager;
/**
* <p>
- * This servlet handles requests to URLs under /internal on the provisioning server.
- * These include:
+ * This servlet handles requests to URLs under /internal on the provisioning server. These include:
* </p>
* <div class="contentContainer">
* <table class="packageSummary" border="0" cellpadding="3" cellspacing="0">
* <caption><span>URL Path Summary</span><span class="tabEnd">&nbsp;</span></caption>
* <tr>
- * <th class="colFirst" width="15%">URL Path</th>
- * <th class="colOne">Method</th>
- * <th class="colLast">Purpose</th>
+ * <th class="colFirst" width="15%">URL Path</th>
+ * <th class="colOne">Method</th>
+ * <th class="colLast">Purpose</th>
* </tr>
* <tr class="altColor">
- * <td class="colFirst">/internal/prov</td>
- * <td class="colOne">GET</td>
- * <td class="colLast">used to GET a full JSON copy of the provisioning data.</td>
+ * <td class="colFirst">/internal/prov</td>
+ * <td class="colOne">GET</td>
+ * <td class="colLast">used to GET a full JSON copy of the provisioning data.</td>
* </tr>
* <tr class="rowColor">
- * <td class="colFirst">/internal/fetchProv</td>
- * <td class="colOne">GET</td>
- * <td class="colLast">used to signal to a standby POD that the provisioning data should be fetched from the active POD.</td>
+ * <td class="colFirst">/internal/fetchProv</td>
+ * <td class="colOne">GET</td>
+ * <td class="colLast">used to signal to a standby POD that the provisioning data should be fetched from the active
+ * POD.</td>
* </tr>
* <tr class="altColor">
- * <td class="colFirst" rowspan="2">/internal/logs</td>
- * <td class="colOne">GET</td>
- * <td class="colLast">used to GET an index of log files and individual logs for this provisioning server.</td>
+ * <td class="colFirst" rowspan="2">/internal/logs</td>
+ * <td class="colOne">GET</td>
+ * <td class="colLast">used to GET an index of log files and individual logs for this provisioning server.</td>
* </tr>
* <tr class="altColor">
- * <td class="colOne">POST</td>
- * <td class="colLast">used to POST log files from the individual nodes to this provisioning server.</td>
+ * <td class="colOne">POST</td>
+ * <td class="colLast">used to POST log files from the individual nodes to this provisioning server.</td>
* </tr>
* <tr class="rowColor">
- * <td class="colFirst" rowspan="4">/internal/api</td>
- * <td class="colOne">GET</td>
- * <td class="colLast">used to GET an individual parameter value. The parameter name is specified by the path after /api/.</td>
+ * <td class="colFirst" rowspan="4">/internal/api</td>
+ * <td class="colOne">GET</td>
+ * <td class="colLast">used to GET an individual parameter value. The parameter name is specified by the path after
+ * /api/.</td>
* </tr>
* <tr class="rowColor">
- * <td class="colOne">PUT</td>
- * <td class="colLast">used to set an individual parameter value. The parameter name is specified by the path after /api/.</td>
+ * <td class="colOne">PUT</td>
+ * <td class="colLast">used to set an individual parameter value. The parameter name is specified by the path after
+ * /api/.</td>
* </tr>
* <tr class="rowColor">
- * <td class="colOne">DELETE</td>
- * <td class="colLast">used to remove an individual parameter value. The parameter name is specified by the path after /api/.</td>
+ * <td class="colOne">DELETE</td>
+ * <td class="colLast">used to remove an individual parameter value. The parameter name is specified by the path after
+ * /api/.</td>
* </tr>
* <tr class="rowColor">
- * <td class="colOne">POST</td>
- * <td class="colLast">used to create a new individual parameter value. The parameter name is specified by the path after /api/.</td>
+ * <td class="colOne">POST</td>
+ * <td class="colLast">used to create a new individual parameter value. The parameter name is specified by the path
+ * after /api/.</td>
* </tr>
* <tr class="altColor">
- * <td class="colFirst">/internal/halt</td>
- * <td class="colOne">GET</td>
- * <td class="colLast">used to halt the server (must be accessed from 127.0.0.1).</td>
+ * <td class="colFirst">/internal/halt</td>
+ * <td class="colOne">GET</td>
+ * <td class="colLast">used to halt the server (must be accessed from 127.0.0.1).</td>
* </tr>
* <tr class="rowColor">
- * <td class="colFirst" rowspan="2">/internal/drlogs</td>
- * <td class="colOne">GET</td>
- * <td class="colLast">used to get a list of DR log entries available for retrieval.
- * Note: these are the actual data router log entries sent to the provisioning server
- * by the nodes, not the provisioning server's internal logs (access via /internal/logs above).
- * The range is returned as a list of record sequence numbers.</td>
+ * <td class="colFirst" rowspan="2">/internal/drlogs</td>
+ * <td class="colOne">GET</td>
+ * <td class="colLast">used to get a list of DR log entries available for retrieval.
+ * Note: these are the actual data router log entries sent to the provisioning server by the nodes, not the provisioning
+ * server's internal logs (access via /internal/logs above). The range is returned as a list of record sequence
+ * numbers.</td>
* </tr>
* <tr class="rowColor">
- * <td class="colOne">POST</td>
- * <td class="colLast">used to retrieve specific log entries.
- * The sequence numbers of the records to fetch are POST-ed; the records matching the sequence numbers are returned.</td>
+ * <td class="colOne">POST</td>
+ * <td class="colLast">used to retrieve specific log entries.
+ * The sequence numbers of the records to fetch are POST-ed; the records matching the sequence numbers are
+ * returned.</td>
* </tr>
* <tr class="altColor">
- * <td class="colFirst">/internal/route/*</td>
- * <td class="colOne">*</td>
- * <td class="colLast">URLs under this path are handled via the {@link org.onap.dmaap.datarouter.provisioning.RouteServlet}</td>
+ * <td class="colFirst">/internal/route/*</td>
+ * <td class="colOne">*</td>
+ * <td class="colLast">URLs under this path are handled via the {@link org.onap.dmaap.datarouter.provisioning.RouteServlet}</td>
* </tr>
* </table>
* </div>
* <p>
- * Authorization to use these URLs is a little different than for other URLs on the provisioning server.
- * For the most part, the IP address that the request comes from should be either:
+ * Authorization to use these URLs is a little different than for other URLs on the provisioning server. For the most
+ * part, the IP address that the request comes from should be either:
* </p>
* <ol>
* <li>an IP address of a provisioning server, or</li>
@@ -139,8 +144,8 @@ import com.att.eelf.configuration.EELFManager;
* In addition, requests to /internal/halt can ONLY come from localhost (127.0.0.1) on the HTTP port.
* </p>
* <p>
- * All DELETE/GET/PUT/POST requests made to /internal/api on this servlet on the standby server are
- * proxied to the active server (using the {@link ProxyServlet}) if it is up and reachable.
+ * All DELETE/GET/PUT/POST requests made to /internal/api on this servlet on the standby server are proxied to the
+ * active server (using the {@link ProxyServlet}) if it is up and reachable.
* </p>
*
* @author Robert Eby
@@ -148,18 +153,20 @@ import com.att.eelf.configuration.EELFManager;
*/
@SuppressWarnings("serial")
public class InternalServlet extends ProxyServlet {
- private static Integer logseq = new Integer(0); // another piece of info to make log spool file names unique
+
+ private static Integer logseq = 0; // another piece of info to make log spool file names unique
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.InternalServlet");
+ private static EELFLogger eelflogger = EELFManager.getInstance()
+ .getLogger("org.onap.dmaap.datarouter.provisioning.InternalServlet");
/**
- * Delete a parameter at the address /internal/api/&lt;parameter&gt;.
- * See the <b>Internal API</b> document for details on how this method should be invoked.
+ * Delete a parameter at the address /internal/api/&lt;parameter&gt;. See the <b>Internal API</b> document for
+ * details on how this method should be invoked.
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
elr.setMessage("Unauthorized.");
@@ -197,14 +204,15 @@ public class InternalServlet extends ProxyServlet {
}
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Bad URL.");
}
+
/**
- * Get some information (such as a parameter) underneath the /internal/ namespace.
- * See the <b>Internal API</b> document for details on how this method should be invoked.
+ * Get some information (such as a parameter) underneath the /internal/ namespace. See the <b>Internal API</b>
+ * document for details on how this method should be invoked.
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
String path = req.getPathInfo();
if (path.equals("/halt") && !req.isSecure()) {
// request to halt the server - can ONLY come from localhost
@@ -214,7 +222,7 @@ public class InternalServlet extends ProxyServlet {
resp.setStatus(HttpServletResponse.SC_OK);
Main.shutdown();
} else {
- intlogger.info("PROV0010 Disallowed request to HALT received from "+remote);
+ intlogger.info("PROV0010 Disallowed request to HALT received from " + remote);
resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
return;
@@ -237,8 +245,9 @@ public class InternalServlet extends ProxyServlet {
}
if (path.equals("/prov")) {
if (isProxyOK(req) && isProxyServer()) {
- if (super.doGetWithFallback(req, resp))
+ 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.");
}
@@ -297,14 +306,15 @@ public class InternalServlet extends ProxyServlet {
}
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Bad URL.");
}
+
/**
- * Modify a parameter at the address /internal/api/&lt;parameter&gt;.
- * See the <b>Internal API</b> document for details on how this method should be invoked.
+ * Modify a parameter at the address /internal/api/&lt;parameter&gt;. See the <b>Internal API</b> document for
+ * details on how this method should be invoked.
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
elr.setMessage("Unauthorized.");
@@ -343,9 +353,10 @@ public class InternalServlet extends ProxyServlet {
}
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Bad URL.");
}
+
/**
- * Create some new information (such as a parameter or log entries) underneath the /internal/ namespace.
- * See the <b>Internal API</b> document for details on how this method should be invoked.
+ * Create some new information (such as a parameter or log entries) underneath the /internal/ namespace. See the
+ * <b>Internal API</b> document for details on how this method should be invoked.
*/
@SuppressWarnings("resource")
@Override
@@ -394,7 +405,7 @@ public class InternalServlet extends ProxyServlet {
String ctype = req.getHeader("Content-Type");
if (ctype == null || !ctype.equals("text/plain")) {
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- elr.setMessage("Bad media type: "+ctype);
+ elr.setMessage("Bad media type: " + ctype);
resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
eventlogger.info(elr);
return;
@@ -421,11 +432,14 @@ public class InternalServlet extends ProxyServlet {
FileSystem fs = (Paths.get(spooldir)).getFileSystem();
long total = 0;
long avail = 0;
- for (FileStore store: fs.getFileStores()) {
+ for (FileStore store : fs.getFileStores()) {
total += store.getTotalSpace();
avail += store.getUsableSpace();
}
- try { fs.close(); } catch (Exception e) { }
+ try {
+ fs.close();
+ } catch (Exception e) {
+ }
if (((avail * 100) / total) < 5) {
elr.setResult(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
@@ -433,7 +447,7 @@ public class InternalServlet extends ProxyServlet {
return;
}
Path tmppath = Paths.get(spooldir, spoolname);
- Path donepath = Paths.get(spooldir, "IN."+spoolname);
+ Path donepath = Paths.get(spooldir, "IN." + spoolname);
Files.copy(req.getInputStream(), Paths.get(spooldir, spoolname), StandardCopyOption.REPLACE_EXISTING);
Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
elr.setResult(HttpServletResponse.SC_CREATED);
@@ -448,7 +462,7 @@ public class InternalServlet extends ProxyServlet {
String ctype = req.getHeader("Content-Type");
if (ctype == null || !ctype.equals("text/plain")) {
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- elr.setMessage("Bad media type: "+ctype);
+ elr.setMessage("Bad media type: " + ctype);
resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
eventlogger.info(elr);
return;
@@ -456,8 +470,9 @@ public class InternalServlet extends ProxyServlet {
InputStream is = req.getInputStream();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int ch = 0;
- while ((ch = is.read()) >= 0)
+ while ((ch = is.read()) >= 0) {
bos.write(ch);
+ }
RLEBitSet bs = new RLEBitSet(bos.toString()); // The set of records to retrieve
elr.setResult(HttpServletResponse.SC_OK);
resp.setStatus(HttpServletResponse.SC_OK);
@@ -484,6 +499,7 @@ public class InternalServlet extends ProxyServlet {
}
return sb.toString();
}
+
private JSONArray generateLogfileList() {
JSONArray ja = new JSONArray();
Properties p = (new DB()).getProperties();
@@ -495,8 +511,9 @@ public class InternalServlet extends ProxyServlet {
String[] list = f.list();
if (list != null) {
for (String s2 : list) {
- if (!s2.startsWith("."))
+ if (!s2.startsWith(".")) {
ja.put(s2);
+ }
}
}
}
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 3e3f45fe..3afce990 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
@@ -55,14 +55,14 @@ import javax.servlet.DispatcherType;
/**
* <p>
- * A main class which may be used to start the provisioning server with an "embedded" Jetty server.
- * Configuration is done via the properties file <i>provserver.properties</i>, which should be in the CLASSPATH.
- * The provisioning server may also be packaged with a web.xml and started as a traditional webapp.
+ * A main class which may be used to start the provisioning server with an "embedded" Jetty server. Configuration is
+ * done via the properties file <i>provserver.properties</i>, which should be in the CLASSPATH. The provisioning server
+ * may also be packaged with a web.xml and started as a traditional webapp.
* </p>
* <p>
- * Most of the work of the provisioning server is carried out within the eight servlets (configured below)
- * that are used to handle each of the eight types of requests the server may receive.
- * In addition, there are background threads started to perform other tasks:
+ * Most of the work of the provisioning server is carried out within the eight servlets (configured below) that are used
+ * to handle each of the eight types of requests the server may receive. In addition, there are background threads
+ * started to perform other tasks:
* </p>
* <ul>
* <li>One background Thread runs the {@link LogfileLoader} in order to process incoming logfiles.
@@ -75,14 +75,15 @@ import javax.servlet.DispatcherType;
* /opt/app/datartr/logs directory.</li>
* </ul>
* <p>
- * The provisioning server is stopped by issuing a GET to the URL http://127.0.0.1/internal/halt
- * using <i>curl</i> or some other such tool.
+ * The provisioning server is stopped by issuing a GET to the URL http://127.0.0.1/internal/halt using <i>curl</i> or
+ * some other such tool.
* </p>
*
* @author Robert Eby
* @version $Id: Main.java,v 1.12 2014/03/12 19:45:41 eby Exp $
*/
public class Main {
+
/**
* The truststore to use if none is specified
*/
@@ -109,8 +110,9 @@ public class Main {
Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
// Check DB is accessible and contains the expected tables
- if (!checkDatabase(logger))
+ if (!checkDatabase(logger)) {
System.exit(1);
+ }
logger.info("PROV0000 **** AT&T Data Router Provisioning Server starting....");
@@ -139,101 +141,109 @@ public class Main {
server = new Server(queuedThreadPool);
// HTTP connector
- ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
- httpServerConnector.setPort(httpPort);
- httpServerConnector.setAcceptQueueSize(2);
-
- // HTTPS configuration
- HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
- httpsConfiguration.setRequestHeaderSize(8192);
-
- // HTTPS connector
- SslContextFactory sslContextFactory = new SslContextFactory();
- 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"));
- // SSL stuff
- /* Skip SSLv3 Fixes */
- sslContextFactory.addExcludeProtocols("SSLv3");
- logger.info("Excluded protocols prov-" + sslContextFactory.getExcludeProtocols());
- /* End of SSLv3 Fixes */
-
- ServerConnector httpsServerConnector = new ServerConnector(server,
- new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
+ HandlerCollection hc;
+ try (ServerConnector httpServerConnector = new ServerConnector(server,
+ new HttpConnectionFactory(httpConfiguration))) {
+ httpServerConnector.setPort(httpPort);
+ httpServerConnector.setAcceptQueueSize(2);
+
+ // HTTPS configuration
+ HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
+ httpsConfiguration.setRequestHeaderSize(8192);
+
+ // HTTPS connector
+ SslContextFactory sslContextFactory = new SslContextFactory();
+ 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"));
+ // 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);
+ 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.setTrustStorePath("/opt/app/datartr/self_signed/cacerts.jks");
sslContextFactory.setTrustStorePassword("changeit");
- }
- sslContextFactory.setTrustStorePath("/opt/app/datartr/self_signed/cacerts.jks");
- 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
- HandlerCollection 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();
-
- ServerConnector serverConnector = new ServerConnector(server,
- new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()),
- new HttpConnectionFactory(httpsConfiguration));
- serverConnector.setPort(httpsPort);
- serverConnector.setIdleTimeout(500000);
+ 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);
server.setStopTimeout(5000);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
index 4250624b..f2c511c1 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
@@ -23,9 +23,7 @@
package org.onap.dmaap.datarouter.provisioning;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.MalformedURLException;
@@ -34,14 +32,11 @@ import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
-import java.util.Properties;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.TreeSet;
-import javax.servlet.ServletException;
-
import org.apache.log4j.Logger;
import org.json.JSONException;
import org.json.JSONObject;
@@ -56,84 +51,92 @@ import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.onap.dmaap.datarouter.provisioning.utils.*;
/**
- * This class handles the two timers (described in R1 Design Notes), and takes care of issuing
- * the GET to each node of the URL to "poke".
+ * This class handles the two timers (described in R1 Design Notes), and takes care of issuing the GET to each node of
+ * the URL to "poke".
*
* @author Robert Eby
* @version $Id: Poker.java,v 1.11 2014/01/08 16:13:47 eby Exp $
*/
public class Poker extends TimerTask {
- /** Template used to generate the URL to issue the GET against */
- public static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";
-
-
+ /**
+ * Template used to generate the URL to issue the GET against
+ */
+ private static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";
- /** This is a singleton -- there is only one Poker object in the server */
- private static Poker p;
+ /**
+ * This is a singleton -- there is only one Poker object in the server
+ */
+ private static Poker poker;
/**
* Get the singleton Poker object.
+ *
* @return the Poker
*/
public static synchronized Poker getPoker() {
- if (p == null)
- p = new Poker();
- return p;
+ if (poker == null) {
+ poker = new Poker();
+ }
+ return poker;
}
private long timer1;
private long timer2;
- private Timer rolex;
- private String this_pod; // DNS name of this machine
+ private String thisPod; // DNS name of this machine
private Logger logger;
- private String provstring;
+ private String provString;
private Poker() {
timer1 = timer2 = 0;
- rolex = new Timer();
+ Timer rolex = new Timer();
logger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
try {
- this_pod = InetAddress.getLocalHost().getHostName();
+ thisPod = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
- this_pod = "*UNKNOWN*"; // not a major problem
+ thisPod = "*UNKNOWN*"; // not a major problem
}
- provstring = buildProvisioningString();
+ provString = buildProvisioningString();
rolex.scheduleAtFixedRate(this, 0L, 1000L); // Run once a second to check the timers
}
/**
* This method sets the two timers described in the design notes.
- * @param t1 the first timer controls how long to wait after a provisioning request before poking each node
- * This timer can be reset if it has not "gone off".
+ *
+ * @param t1 the first timer controls how long to wait after a provisioning request before poking each node This
+ * timer can be reset if it has not "gone off".
* @param t2 the second timer set the outer bound on how long to wait. It cannot be reset.
*/
public void setTimers(long t1, long t2) {
- synchronized (this_pod) {
- if (timer1 == 0 || t1 > timer1)
+ synchronized (thisPod) {
+ if (timer1 == 0 || t1 > timer1) {
timer1 = t1;
- if (timer2 == 0)
+ }
+ if (timer2 == 0) {
timer2 = t2;
+ }
}
- if (logger.isDebugEnabled())
+ if (logger.isDebugEnabled()) {
logger.debug("Poker timers set to " + timer1 + " and " + timer2);
+ }
}
/**
* Return the last provisioning string built.
+ *
* @return the last provisioning string built.
*/
public String getProvisioningString() {
- return provstring;
+ return provString;
}
/**
- * The method to run at the predefined interval (once per second). This method checks
- * to see if either of the two timers has expired, and if so, will rebuild the provisioning
- * string, and poke all the nodes and other PODs. The timers are then reset to 0.
+ * The method to run at the predefined interval (once per second). This method checks to see if either of the two
+ * timers has expired, and if so, will rebuild the provisioning string, and poke all the nodes and other PODs. The
+ * timers are then reset to 0.
*/
@Override
public void run() {
@@ -141,62 +144,61 @@ public class Poker extends TimerTask {
if (timer1 > 0) {
long now = System.currentTimeMillis();
boolean fire = false;
- synchronized (this_pod) {
+ synchronized (thisPod) {
if (now > timer1 || now > timer2) {
timer1 = timer2 = 0;
fire = true;
}
}
if (fire) {
- // Rebuild the prov string
- provstring = buildProvisioningString();
-
- // Only the active POD should poke nodes, etc.
- boolean active = SynchronizerTask.getSynchronizer().isActive();
- if (active) {
- // Poke all the DR nodes
- for (String n : BaseServlet.getNodes()) {
- pokeNode(n);
- }
- // Poke the pod that is not us
- for (String n : BaseServlet.getPods()) {
- if (n.length() > 0 && !n.equals(this_pod))
- pokeNode(n);
- }
- }
+ pokeNodes();
}
}
} catch (Exception e) {
- logger.warn("PROV0020: Caught exception in Poker: "+e);
+ logger.warn("PROV0020: Caught exception in Poker: " + e);
e.printStackTrace();
}
}
- private void pokeNode(final String nodename) {
- logger.debug("PROV0012 Poking node " + nodename + " ...");
- Runnable r = new Runnable() {
- @Override
- public void run() {
- try {
- String u = String.format(POKE_URL_TEMPLATE, nodename+":"+DB.HTTP_PORT);
- URL url = new URL(u);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setConnectTimeout(60000); //Fixes for Itrack DATARTR-3, poke timeout
- conn.connect();
- conn.getContentLength(); // Force the GET through
- conn.disconnect();
- } catch (MalformedURLException e) {
- logger.warn("PROV0013 MalformedURLException Error poking node "+nodename+": " + e.getMessage());
- } catch (IOException e) {
- logger.warn("PROV0013 IOException Error poking node "+nodename+": " + e.getMessage());
+ private void pokeNodes() {
+ // Rebuild the prov string
+ provString = buildProvisioningString();
+ // Only the active POD should poke nodes, etc.
+ boolean active = SynchronizerTask.getSynchronizer().isActive();
+ if (active) {
+ // Poke all the DR nodes
+ for (String n : BaseServlet.getNodes()) {
+ pokeNode(n);
+ }
+ // Poke the pod that is not us
+ for (String n : BaseServlet.getPods()) {
+ if (n.length() > 0 && !n.equals(thisPod)) {
+ pokeNode(n);
}
}
+ }
+ }
+
+ private void pokeNode(final String nodename) {
+ logger.debug("PROV0012 Poking node " + nodename + " ...");
+ String nodeUrl = String.format(POKE_URL_TEMPLATE, nodename + ":" + DB.HTTP_PORT);
+ Runnable r = () -> {
+ try {
+ URL url = new URL(nodeUrl);
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setConnectTimeout(60000); //Fixes for Itrack DATARTR-3, poke timeout
+ conn.connect();
+ conn.getContentLength(); // Force the GET through
+ conn.disconnect();
+ } catch (MalformedURLException e) {
+ logger.warn("PROV0013 MalformedURLException Error poking node at " + nodeUrl + " : " + e.getMessage());
+ } catch (IOException e) {
+ logger.warn("PROV0013 IOException Error poking node at " + nodeUrl + " : " + e.getMessage());
+ }
};
-// Thread t = new Thread(r);
-// t.start();
r.run();
}
- @SuppressWarnings("unused")
+
private String buildProvisioningString() {
StringBuilder sb = new StringBuilder("{\n");
@@ -220,14 +222,14 @@ public class Poker extends TimerTask {
}
sb.append("\n],\n");
-
// Append Subscriptions to the string
pfx = "\n";
sb.append("\"subscriptions\": [");
for (Subscription s : Subscription.getAllSubscriptions()) {
sb.append(pfx);
- if(s!=null)
- sb.append(s.asJSONObject().toString());
+ if (s != null) {
+ sb.append(s.asJSONObject().toString());
+ }
pfx = ",\n";
}
sb.append("\n],\n");
@@ -235,11 +237,12 @@ public class Poker extends TimerTask {
// Append Parameters to the string
pfx = "\n";
sb.append("\"parameters\": {");
- Map<String,String> props = Parameters.getParameters();
+ Map<String, String> props = Parameters.getParameters();
Set<String> ivals = new HashSet<String>();
String intv = props.get("_INT_VALUES");
- if (intv != null)
+ if (intv != null) {
ivals.addAll(Arrays.asList(intv.split("\\|")));
+ }
for (String key : new TreeSet<String>(props.keySet())) {
String v = props.get(key);
sb.append(pfx);
@@ -279,7 +282,7 @@ public class Poker extends TimerTask {
for (EgressRoute eg : EgressRoute.getAllEgressRoutes()) {
sb.append(pfx);
String t = eg.asJSONObject().toString();
- t = t.substring(1, t.length()-1);
+ t = t.substring(1, t.length() - 1);
sb.append(t);
pfx = ",\n";
}
@@ -296,14 +299,15 @@ public class Poker extends TimerTask {
sb.append("\n}");
// Convert to string and verify it is valid JSON
- String provstring = sb.toString();
+ String tempProvString = sb.toString();
try {
- new JSONObject(new JSONTokener(provstring));
+ new JSONObject(new JSONTokener(tempProvString));
} catch (JSONException e) {
- logger.warn("PROV0016: Possible invalid prov string: "+e);
+ logger.warn("PROV0016: Possible invalid prov string: " + e);
}
- return provstring;
+ return tempProvString;
}
+
private String quote(String s) {
StringBuilder sb = new StringBuilder();
for (char ch : s.toCharArray()) {
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 3ad22427..21d391e5 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
@@ -43,8 +43,8 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
/**
- * This servlet handles provisioning for the &lt;subscribeURL&gt; which is generated by the provisioning
- * server to handle the creation and inspection of subscriptions to a specific feed.
+ * This servlet handles provisioning for the &lt;subscribeURL&gt; which is generated by the provisioning server to
+ * handle the creation and inspection of subscriptions to a specific feed.
*
* @author Robert Eby
* @version $Id$
@@ -53,7 +53,8 @@ import com.att.eelf.configuration.EELFManager;
public class SubscribeServlet extends ProxyServlet {
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.SubscribeServlet");
+ private static EELFLogger eelflogger = EELFManager.getInstance()
+ .getLogger("org.onap.dmaap.datarouter.provisioning.SubscribeServlet");
/**
* DELETE on the &lt;subscribeUrl&gt; -- not supported.
@@ -61,7 +62,7 @@ public class SubscribeServlet extends ProxyServlet {
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
String message = "DELETE not allowed for the subscribeURL.";
EventLogRecord elr = new EventLogRecord(req);
elr.setMessage(message);
@@ -69,15 +70,15 @@ public class SubscribeServlet extends ProxyServlet {
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
}
+
/**
- * GET on the &lt;subscribeUrl&gt; -- get the list of subscriptions to a feed.
- * See the <i>Subscription Collection Query</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * GET on the &lt;subscribeUrl&gt; -- get the list of subscriptions to a feed. See the <i>Subscription Collection
+ * Query</i> section in the <b>Provisioning API</b> document for details on how this method should be invoked.
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
String message = isAuthorizedForProvisioning(req);
if (message != null) {
@@ -93,7 +94,7 @@ public class SubscribeServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
@@ -120,7 +121,7 @@ public class SubscribeServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -140,13 +141,14 @@ public class SubscribeServlet extends ProxyServlet {
resp.setContentType(SUBLIST_CONTENT_TYPE);
resp.getOutputStream().print(t);
}
+
/**
* PUT on the &lt;subscribeUrl&gt; -- not supported.
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
String message = "PUT not allowed for the subscribeURL.";
EventLogRecord elr = new EventLogRecord(req);
elr.setMessage(message);
@@ -154,10 +156,10 @@ public class SubscribeServlet extends ProxyServlet {
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
}
+
/**
- * POST on the &lt;subscribeUrl&gt; -- create a new subscription to a feed.
- * See the <i>Creating a Subscription</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * POST on the &lt;subscribeUrl&gt; -- create a new subscription to a feed. See the <i>Creating a Subscription</i>
+ * 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 {
@@ -178,7 +180,7 @@ public class SubscribeServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
@@ -205,7 +207,7 @@ public class SubscribeServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -218,7 +220,7 @@ public class SubscribeServlet extends ProxyServlet {
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
- intlogger.debug("Content-type is: "+req.getHeader("Content-Type"));
+ intlogger.debug("Content-type is: " + req.getHeader("Content-Type"));
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -235,10 +237,11 @@ public class SubscribeServlet extends ProxyServlet {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return;
}
- if (intlogger.isDebugEnabled())
+ if (intlogger.isDebugEnabled()) {
intlogger.debug(jo.toString());
- if (++active_subs > max_subs) {
- active_subs--;
+ }
+ if (++activeSubs > maxSubs) {
+ activeSubs--;
message = "Cannot create subscription; the maximum number of subscriptions has been configured.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_CONFLICT);
@@ -250,7 +253,7 @@ public class SubscribeServlet extends ProxyServlet {
try {
sub = new Subscription(jo);
} catch (InvalidObjectException e) {
- active_subs--;
+ activeSubs--;
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
@@ -263,8 +266,11 @@ public class SubscribeServlet extends ProxyServlet {
// Check if this subscription already exists; not an error (yet), just warn
Subscription sub2 = Subscription.getSubscriptionMatching(sub);
- if (sub2 != null)
- intlogger.warn("PROV0011 Creating a duplicate subscription: new subid="+sub.getSubid()+", old subid="+sub2.getSubid());
+ if (sub2 != null) {
+ intlogger.warn(
+ "PROV0011 Creating a duplicate subscription: new subid=" + sub.getSubid() + ", old subid=" + sub2
+ .getSubid());
+ }
// Create SUBSCRIPTIONS table entries
if (doInsert(sub)) {
@@ -279,7 +285,7 @@ public class SubscribeServlet extends ProxyServlet {
provisioningDataChanged();
} else {
// Something went wrong with the INSERT
- active_subs--;
+ activeSubs--;
elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
eventlogger.info(elr);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG);
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 8e49e304..3294580b 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
@@ -45,30 +45,30 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
/**
- * This servlet handles provisioning for the &lt;subscriptionURL&gt; which is generated by the provisioning
- * server to handle the inspection, modification, and deletion of a particular subscription to a feed.
- * It supports DELETE to delete a subscription, GET to retrieve information about the subscription,
- * and PUT to modify the subscription. In DR 3.0, POST is also supported in order to reset the subscription
- * timers for individual subscriptions.
+ * This servlet handles provisioning for the &lt;subscriptionURL&gt; which is generated by the provisioning server to
+ * handle the inspection, modification, and deletion of a particular subscription to a feed. It supports DELETE to
+ * delete a subscription, GET to retrieve information about the subscription, and PUT to modify the subscription. In DR
+ * 3.0, POST is also supported in order to reset the subscription timers for individual subscriptions.
*
* @author Robert Eby
* @version $Id$
*/
@SuppressWarnings("serial")
public class SubscriptionServlet extends ProxyServlet {
+
public static final String SUBCNTRL_CONTENT_TYPE = "application/vnd.att-dr.subscription-control";
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.SubscriptionServlet");
+ private static EELFLogger eelflogger = EELFManager.getInstance()
+ .getLogger("org.onap.dmaap.datarouter.provisioning.SubscriptionServlet");
/**
- * DELETE on the &lt;subscriptionUrl&gt; -- delete a subscription.
- * See the <i>Deleting a Subscription</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * DELETE on the &lt;subscriptionUrl&gt; -- delete a subscription. See the <i>Deleting a Subscription</i> section in
+ * the <b>Provisioning API</b> document for details on how this method should be invoked.
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
String message = isAuthorizedForProvisioning(req);
if (message != null) {
@@ -84,7 +84,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
@@ -111,7 +111,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -122,7 +122,7 @@ public class SubscriptionServlet extends ProxyServlet {
// Delete Subscription
if (doDelete(sub)) {
- active_subs--;
+ activeSubs--;
// send response
elr.setResult(HttpServletResponse.SC_NO_CONTENT);
eventlogger.info(elr);
@@ -135,15 +135,16 @@ public class SubscriptionServlet extends ProxyServlet {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG);
}
}
+
/**
- * GET on the &lt;subscriptionUrl&gt; -- get information about a subscription.
- * See the <i>Retreiving Information about a Subscription</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * GET on the &lt;subscriptionUrl&gt; -- get information about a subscription. See the <i>Retreiving Information
+ * about a Subscription</i> section in the <b>Provisioning API</b> document for details on how this method should be
+ * invoked.
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
String message = isAuthorizedForProvisioning(req);
if (message != null) {
@@ -159,7 +160,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
@@ -186,7 +187,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -202,15 +203,15 @@ public class SubscriptionServlet extends ProxyServlet {
resp.setContentType(SUBFULL_CONTENT_TYPE);
resp.getOutputStream().print(sub.asJSONObject(true).toString());
}
+
/**
- * PUT on the &lt;subscriptionUrl&gt; -- modify a subscription.
- * See the <i>Modifying a Subscription</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * PUT on the &lt;subscriptionUrl&gt; -- modify a subscription. See the <i>Modifying a Subscription</i> section in
+ * the <b>Provisioning API</b> document for details on how this method should be invoked.
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
String message = isAuthorizedForProvisioning(req);
if (message != null) {
@@ -226,7 +227,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
@@ -253,7 +254,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -281,8 +282,9 @@ public class SubscriptionServlet extends ProxyServlet {
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
return;
}
- if (intlogger.isDebugEnabled())
+ if (intlogger.isDebugEnabled()) {
intlogger.debug(jo.toString());
+ }
Subscription sub = null;
try {
sub = new Subscription(jo);
@@ -335,10 +337,10 @@ public class SubscriptionServlet extends ProxyServlet {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG);
}
}
+
/**
- * POST on the &lt;subscriptionUrl&gt; -- control a subscription.
- * See the <i>Resetting a Subscription's Retry Schedule</i> section in the <b>Provisioning API</b>
- * document for details on how this method should be invoked.
+ * POST on the &lt;subscriptionUrl&gt; -- control a subscription. See the <i>Resetting a Subscription's Retry
+ * Schedule</i> 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 {
@@ -367,7 +369,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
@@ -396,7 +398,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
+ if (!aresp.isAuthorized()) {
message = "Policy Engine disallows access.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -437,22 +439,25 @@ public class SubscriptionServlet extends ProxyServlet {
}
/**
- * A Thread class used to serially send reset notifications to all nodes in the DR network,
- * when a POST is received for a subscription.
+ * A Thread class used to serially send reset notifications to all nodes in the DR network, when a POST is received
+ * for a subscription.
*/
public class SubscriberNotifyThread extends Thread {
+
public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";
private List<String> urls = new Vector<String>();
public SubscriberNotifyThread() {
setName("SubscriberNotifyThread");
}
+
public void resetSubscription(int subid) {
for (String nodename : BaseServlet.getNodes()) {
String u = String.format(URL_TEMPLATE, nodename, subid);
urls.add(u);
}
}
+
public void run() {
try {
while (!urls.isEmpty()) {
@@ -464,11 +469,11 @@ public class SubscriptionServlet extends ProxyServlet {
conn.getContentLength(); // Force the GET through
conn.disconnect();
} catch (IOException e) {
- intlogger.info("IOException Error accessing URL: "+u+": " + e.getMessage());
+ intlogger.info("IOException Error accessing URL: " + u + ": " + e.getMessage());
}
}
} catch (Exception e) {
- intlogger.warn("Caught exception in SubscriberNotifyThread: "+e);
+ intlogger.warn("Caught exception in SubscriberNotifyThread: " + e);
e.printStackTrace();
}
}
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 898a3f05..9eeac236 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
@@ -89,23 +89,32 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
* </ol>
* <p>For this to work correctly, the following code needs to be placed at the beginning of main().</p>
* <code>
- * Security.setProperty("networkaddress.cache.ttl", "10");
+ * Security.setProperty("networkaddress.cache.ttl", "10");
* </code>
*
* @author Robert Eby
* @version $Id: SynchronizerTask.java,v 1.10 2014/03/21 13:50:10 eby Exp $
*/
public class SynchronizerTask extends TimerTask {
- /** This is a singleton -- there is only one SynchronizerTask object in the server */
+
+ /**
+ * This is a singleton -- there is only one SynchronizerTask object in the server
+ */
private static SynchronizerTask synctask;
- /** This POD is unknown -- not on the list of PODs */
+ /**
+ * This POD is unknown -- not on the list of PODs
+ */
public static final int UNKNOWN = 0;
- /** This POD is active -- on the list of PODs, and the DNS CNAME points to us */
+ /**
+ * This POD is active -- on the list of PODs, and the DNS CNAME points to us
+ */
public static final int ACTIVE = 1;
- /** This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us */
+ /**
+ * This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us
+ */
public static final int STANDBY = 2;
- private static final String[] stnames = { "UNKNOWN", "ACTIVE", "STANDBY" };
+ private static final String[] stnames = {"UNKNOWN", "ACTIVE", "STANDBY"};
private static final long ONE_HOUR = 60 * 60 * 1000L;
private final Logger logger;
@@ -118,11 +127,13 @@ public class SynchronizerTask extends TimerTask {
/**
* Get the singleton SynchronizerTask object.
+ *
* @return the SynchronizerTask
*/
public static synchronized SynchronizerTask getSynchronizer() {
- if (synctask == null)
+ if (synctask == null) {
synctask = new SynchronizerTask();
+ }
return synctask;
}
@@ -138,16 +149,16 @@ public class SynchronizerTask extends TimerTask {
logger.info("PROV5000: Sync task starting, server state is UNKNOWN");
try {
Properties props = (new DB()).getProperties();
- String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
+ 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_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);
+ pass = props.getProperty(Main.TRUSTSTORE_PASSWORD_PROPERTY);
KeyStore trustStore = null;
if (store != null && store.length() > 0) {
trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
@@ -158,12 +169,13 @@ public class SynchronizerTask extends TimerTask {
// 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
+ 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);
+ ? 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);
@@ -179,12 +191,13 @@ public class SynchronizerTask extends TimerTask {
}
rolex.scheduleAtFixedRate(this, 0L, interval);
} catch (Exception e) {
- logger.warn("PROV5005: Problem starting the synchronizer: "+e);
+ logger.warn("PROV5005: Problem starting the synchronizer: " + e);
}
}
/**
* What is the state of this POD?
+ *
* @return one of ACTIVE, STANDBY, UNKNOWN
*/
public int getState() {
@@ -193,6 +206,7 @@ public class SynchronizerTask extends TimerTask {
/**
* Is this the active POD?
+ *
* @return true if we are active (the master), false otherwise
*/
public boolean isActive() {
@@ -200,8 +214,8 @@ public class SynchronizerTask extends TimerTask {
}
/**
- * This method is used to signal that another POD (the active POD) has sent us a /fetchProv request,
- * and that we should re-synchronize with the master.
+ * This method is used to signal that another POD (the active POD) has sent us a /fetchProv request, and that we
+ * should re-synchronize with the master.
*/
public void doFetch() {
doFetch = true;
@@ -226,20 +240,23 @@ public class SynchronizerTask extends TimerTask {
JSONObject jo = readProvisioningJSON();
if (jo != null) {
doFetch = false;
- syncFeeds( jo.getJSONArray("feeds"));
- syncSubs( jo.getJSONArray("subscriptions"));
- syncGroups( jo.getJSONArray("groups")); //Rally:US708115 - 1610
+ syncFeeds(jo.getJSONArray("feeds"));
+ syncSubs(jo.getJSONArray("subscriptions"));
+ syncGroups(jo.getJSONArray("groups")); //Rally:US708115 - 1610
syncParams(jo.getJSONObject("parameters"));
// The following will not be present in a version=1.0 provfeed
JSONArray ja = jo.optJSONArray("ingress");
- if (ja != null)
+ if (ja != null) {
syncIngressRoutes(ja);
+ }
JSONObject j2 = jo.optJSONObject("egress");
- if (j2 != null)
- syncEgressRoutes( j2);
+ if (j2 != null) {
+ syncEgressRoutes(j2);
+ }
ja = jo.optJSONArray("routing");
- if (ja != null)
+ if (ja != null) {
syncNetworkRoutes(ja);
+ }
}
logger.info("PROV5013: Sync completed.");
nextsynctime = System.currentTimeMillis() + ONE_HOUR;
@@ -254,53 +271,61 @@ public class SynchronizerTask extends TimerTask {
if (lfl.isIdle()) {
// Only fetch new logs if the loader is waiting for them.
logger.trace("Checking for logs to replicate...");
- RLEBitSet local = lfl.getBitSet();
+ RLEBitSet local = lfl.getBitSet();
RLEBitSet remote = readRemoteLoglist();
remote.andNot(local);
if (!remote.isEmpty()) {
- logger.debug(" Replicating logs: "+remote);
+ logger.debug(" Replicating logs: " + remote);
replicateDRLogs(remote);
}
}
} catch (Exception e) {
- logger.warn("PROV0020: Caught exception in SynchronizerTask: "+e);
+ logger.warn("PROV0020: Caught exception in SynchronizerTask: " + e);
e.printStackTrace();
}
}
/**
- * This method is used to lookup the CNAME that points to the active server.
- * It returns 0 (UNKNOWN), 1(ACTIVE), or 2 (STANDBY) to indicate the state of this server.
+ * This method is used to lookup the CNAME that points to the active server. It returns 0 (UNKNOWN), 1(ACTIVE), or 2
+ * (STANDBY) to indicate the state of this server.
+ *
* @return the current state
*/
private int lookupState() {
int newstate = UNKNOWN;
try {
InetAddress myaddr = InetAddress.getLocalHost();
- if (logger.isTraceEnabled())
- logger.trace("My address: "+myaddr);
- String this_pod = myaddr.getHostName();
- Set<String> pods = new TreeSet<String>(Arrays.asList(BaseServlet.getPods()));
- if (pods.contains(this_pod)) {
- InetAddress pserver = InetAddress.getByName(BaseServlet.active_prov_name);
+ if (logger.isTraceEnabled()) {
+ logger.trace("My address: " + myaddr);
+ }
+ String thisPod = myaddr.getHostName();
+ Set<String> pods = new TreeSet<>(Arrays.asList(BaseServlet.getPods()));
+ if (pods.contains(thisPod)) {
+ InetAddress pserver = InetAddress.getByName(BaseServlet.activeProvName);
newstate = myaddr.equals(pserver) ? ACTIVE : STANDBY;
- if (logger.isDebugEnabled() && System.currentTimeMillis() >= next_msg) {
- logger.debug("Active POD = "+pserver+", Current state is "+stnames[newstate]);
- next_msg = System.currentTimeMillis() + (5 * 60 * 1000L);
+ if (logger.isDebugEnabled() && System.currentTimeMillis() >= nextMsg) {
+ logger.debug("Active POD = " + pserver + ", Current state is " + stnames[newstate]);
+ nextMsg = System.currentTimeMillis() + (5 * 60 * 1000L);
}
} else {
- logger.warn("PROV5003: My name ("+this_pod+") is missing from the list of provisioning servers.");
+ logger.warn("PROV5003: My name (" + thisPod + ") is missing from the list of provisioning servers.");
}
} catch (UnknownHostException e) {
logger.warn("PROV5002: Cannot determine the name of this provisioning server.");
}
- if (newstate != state)
- logger.info(String.format("PROV5001: Server state changed from %s to %s", stnames[state], stnames[newstate]));
+ if (newstate != state) {
+ logger
+ .info(String.format("PROV5001: Server state changed from %s to %s", stnames[state], stnames[newstate]));
+ }
return newstate;
}
- private static long next_msg = 0; // only display the "Current state" msg every 5 mins.
- /** Synchronize the Feeds in the JSONArray, with the Feeds in the DB. */
+
+ private static long nextMsg = 0; // only display the "Current state" msg every 5 mins.
+
+ /**
+ * Synchronize the Feeds in the JSONArray, with the Feeds in the DB.
+ */
private void syncFeeds(JSONArray ja) {
Collection<Syncable> coll = new ArrayList<Syncable>();
for (int n = 0; n < ja.length(); n++) {
@@ -308,13 +333,17 @@ public class SynchronizerTask extends TimerTask {
Feed f = new Feed(ja.getJSONObject(n));
coll.add(f);
} catch (Exception e) {
- logger.warn("PROV5004: Invalid object in feed: "+ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n));
}
}
- if (sync(coll, Feed.getAllFeeds()))
+ if (sync(coll, Feed.getAllFeeds())) {
BaseServlet.provisioningDataChanged();
+ }
}
- /** Synchronize the Subscriptions in the JSONArray, with the Subscriptions in the DB. */
+
+ /**
+ * Synchronize the Subscriptions in the JSONArray, with the Subscriptions in the DB.
+ */
private void syncSubs(JSONArray ja) {
Collection<Syncable> coll = new ArrayList<Syncable>();
for (int n = 0; n < ja.length(); n++) {
@@ -325,14 +354,17 @@ public class SynchronizerTask extends TimerTask {
Subscription s = new Subscription(j);
coll.add(s);
} catch (Exception e) {
- logger.warn("PROV5004: Invalid object in subscription: "+ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n));
}
}
- if (sync(coll, Subscription.getAllSubscriptions()))
+ if (sync(coll, Subscription.getAllSubscriptions())) {
BaseServlet.provisioningDataChanged();
+ }
}
- /** Rally:US708115 - Synchronize the Groups in the JSONArray, with the Groups in the DB. */
+ /**
+ * 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>();
for (int n = 0; n < ja.length(); n++) {
@@ -340,15 +372,18 @@ public class SynchronizerTask extends TimerTask {
Group g = new Group(ja.getJSONObject(n));
coll.add(g);
} catch (Exception e) {
- logger.warn("PROV5004: Invalid object in subscription: "+ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n));
}
}
- if (sync(coll, Group.getAllgroups()))
+ if (sync(coll, Group.getAllgroups())) {
BaseServlet.provisioningDataChanged();
+ }
}
- /** Synchronize the Parameters in the JSONObject, with the Parameters in the DB. */
+ /**
+ * Synchronize the Parameters in the JSONObject, with the Parameters in the DB.
+ */
private void syncParams(JSONObject jo) {
Collection<Syncable> coll = new ArrayList<Syncable>();
for (String k : jo.keySet()) {
@@ -357,12 +392,13 @@ public class SynchronizerTask extends TimerTask {
v = jo.getString(k);
} catch (JSONException e) {
try {
- v = ""+jo.getInt(k);
+ v = "" + jo.getInt(k);
} catch (JSONException e1) {
JSONArray ja = jo.getJSONArray(k);
for (int i = 0; i < ja.length(); i++) {
- if (i > 0)
+ if (i > 0) {
v += "|";
+ }
v += ja.getString(i);
}
}
@@ -374,6 +410,7 @@ public class SynchronizerTask extends TimerTask {
BaseServlet.provisioningParametersChanged();
}
}
+
private void syncIngressRoutes(JSONArray ja) {
Collection<Syncable> coll = new ArrayList<Syncable>();
for (int n = 0; n < ja.length(); n++) {
@@ -381,12 +418,14 @@ public class SynchronizerTask extends TimerTask {
IngressRoute in = new IngressRoute(ja.getJSONObject(n));
coll.add(in);
} catch (NumberFormatException e) {
- logger.warn("PROV5004: Invalid object in ingress routes: "+ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in ingress routes: " + ja.optJSONObject(n));
}
}
- if (sync(coll, IngressRoute.getAllIngressRoutes()))
+ if (sync(coll, IngressRoute.getAllIngressRoutes())) {
BaseServlet.provisioningDataChanged();
+ }
}
+
private void syncEgressRoutes(JSONObject jo) {
Collection<Syncable> coll = new ArrayList<Syncable>();
for (String key : jo.keySet()) {
@@ -396,14 +435,16 @@ public class SynchronizerTask extends TimerTask {
EgressRoute er = new EgressRoute(sub, node);
coll.add(er);
} catch (NumberFormatException e) {
- logger.warn("PROV5004: Invalid subid in egress routes: "+key);
+ logger.warn("PROV5004: Invalid subid in egress routes: " + key);
} catch (IllegalArgumentException e) {
- logger.warn("PROV5004: Invalid node name in egress routes: "+key);
+ logger.warn("PROV5004: Invalid node name in egress routes: " + key);
}
}
- if (sync(coll, EgressRoute.getAllEgressRoutes()))
+ if (sync(coll, EgressRoute.getAllEgressRoutes())) {
BaseServlet.provisioningDataChanged();
+ }
}
+
private void syncNetworkRoutes(JSONArray ja) {
Collection<Syncable> coll = new ArrayList<Syncable>();
for (int n = 0; n < ja.length(); n++) {
@@ -411,12 +452,14 @@ public class SynchronizerTask extends TimerTask {
NetworkRoute nr = new NetworkRoute(ja.getJSONObject(n));
coll.add(nr);
} catch (JSONException e) {
- logger.warn("PROV5004: Invalid object in network routes: "+ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in network routes: " + ja.optJSONObject(n));
}
}
- if (sync(coll, NetworkRoute.getAllNetworkRoutes()))
+ if (sync(coll, NetworkRoute.getAllNetworkRoutes())) {
BaseServlet.provisioningDataChanged();
+ }
}
+
private boolean sync(Collection<? extends Syncable> newc, Collection<? extends Syncable> oldc) {
boolean changes = false;
try {
@@ -431,18 +474,21 @@ public class SynchronizerTask extends TimerTask {
Syncable newobj = newmap.get(n);
Syncable oldobj = oldmap.get(n);
if (oldobj == null) {
- if (logger.isDebugEnabled())
- logger.debug(" Inserting record: "+newobj);
+ if (logger.isDebugEnabled()) {
+ logger.debug(" Inserting record: " + newobj);
+ }
newobj.doInsert(conn);
changes = true;
} else if (newobj == null) {
- if (logger.isDebugEnabled())
- logger.debug(" Deleting record: "+oldobj);
+ if (logger.isDebugEnabled()) {
+ logger.debug(" Deleting record: " + oldobj);
+ }
oldobj.doDelete(conn);
changes = true;
} else if (!newobj.equals(oldobj)) {
- if (logger.isDebugEnabled())
- logger.debug(" Updating record: "+newobj);
+ if (logger.isDebugEnabled()) {
+ logger.debug(" Updating record: " + newobj);
+ }
newobj.doUpdate(conn);
/**Rally US708115
@@ -455,11 +501,12 @@ public class SynchronizerTask extends TimerTask {
}
db.release(conn);
} catch (SQLException e) {
- logger.warn("PROV5009: problem during sync, exception: "+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>();
for (Syncable v : c) {
@@ -468,29 +515,28 @@ public class SynchronizerTask extends TimerTask {
return map;
}
-
/**Change owner of FEED/SUBSCRIPTION*/
- /**Rally US708115
- * Change Ownership of FEED - 1610
- *
- * */
+ /**
+ * Rally US708115 Change Ownership of FEED - 1610
+ */
private void checkChnageOwner(Syncable newobj, Syncable oldobj) {
- if(newobj instanceof Feed) {
+ if (newobj instanceof Feed) {
Feed oldfeed = (Feed) oldobj;
Feed newfeed = (Feed) newobj;
- if(!oldfeed.getPublisher().equals(newfeed.getPublisher())){
- logger.info("PROV5013 - Previous publisher: "+oldfeed.getPublisher() +": New publisher-"+newfeed.getPublisher());
+ if (!oldfeed.getPublisher().equals(newfeed.getPublisher())) {
+ logger.info("PROV5013 - Previous publisher: " + oldfeed.getPublisher() + ": New publisher-" + newfeed
+ .getPublisher());
oldfeed.setPublisher(newfeed.getPublisher());
oldfeed.changeOwnerShip();
}
- }
- else if(newobj instanceof Subscription) {
+ } else if (newobj instanceof Subscription) {
Subscription oldsub = (Subscription) oldobj;
Subscription newsub = (Subscription) newobj;
- if(!oldsub.getSubscriber().equals(newsub.getSubscriber())){
- logger.info("PROV5013 - Previous subscriber: "+oldsub.getSubscriber() +": New subscriber-"+newsub.getSubscriber());
+ if (!oldsub.getSubscriber().equals(newsub.getSubscriber())) {
+ logger.info("PROV5013 - Previous subscriber: " + oldsub.getSubscriber() + ": New subscriber-" + newsub
+ .getSubscriber());
oldsub.setSubscriber(newsub.getSubscriber());
oldsub.changeOwnerShip();
}
@@ -500,43 +546,47 @@ public class SynchronizerTask extends TimerTask {
/**
* Issue a GET on the peer POD's /internal/prov/ URL to get a copy of its provisioning data.
+ *
* @return the provisioning data (as a JONObject)
*/
private synchronized JSONObject readProvisioningJSON() {
- String url = URLUtilities.generatePeerProvURL();
+ String url = URLUtilities.generatePeerProvURL();
HttpGet get = new HttpGet(url);
try {
HttpResponse response = httpclient.execute(get);
int code = response.getStatusLine().getStatusCode();
if (code != HttpServletResponse.SC_OK) {
- logger.warn("PROV5010: readProvisioningJSON failed, bad error code: "+code);
+ logger.warn("PROV5010: readProvisioningJSON failed, bad error code: " + code);
return null;
}
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
- if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1) && !ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
- logger.warn("PROV5011: readProvisioningJSON failed, bad content type: "+ctype);
+ if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1) && !ctype
+ .equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
+ logger.warn("PROV5011: readProvisioningJSON failed, bad content type: " + ctype);
return null;
}
return new JSONObject(new JSONTokener(entity.getContent()));
} catch (Exception e) {
- logger.warn("PROV5012: readProvisioningJSON failed, exception: "+e);
+ logger.warn("PROV5012: readProvisioningJSON failed, exception: " + e);
return null;
} finally {
get.releaseConnection();
}
}
+
/**
- * Issue a GET on the peer POD's /internal/drlogs/ URL to get an RELBitSet representing the
- * log records available in the remote database.
+ * Issue a GET on the peer POD's /internal/drlogs/ URL to get an RELBitSet representing the log records available in
+ * the remote database.
+ *
* @return the bitset
*/
private RLEBitSet readRemoteLoglist() {
RLEBitSet bs = new RLEBitSet();
- String url = URLUtilities.generatePeerLogsURL();
+ String url = URLUtilities.generatePeerLogsURL();
//Fixing if only one Prov is configured, not to give exception to fill logs, return empty bitset.
- if(url.equals("")) {
+ if (url.equals("")) {
return bs;
}
//End of fix.
@@ -546,66 +596,70 @@ public class SynchronizerTask extends TimerTask {
HttpResponse response = httpclient.execute(get);
int code = response.getStatusLine().getStatusCode();
if (code != HttpServletResponse.SC_OK) {
- logger.warn("PROV5010: readRemoteLoglist failed, bad error code: "+code);
+ logger.warn("PROV5010: readRemoteLoglist failed, bad error code: " + code);
return bs;
}
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
if (!ctype.equals("text/plain")) {
- logger.warn("PROV5011: readRemoteLoglist failed, bad content type: "+ctype);
+ logger.warn("PROV5011: readRemoteLoglist failed, bad content type: " + ctype);
return bs;
}
InputStream is = entity.getContent();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int ch = 0;
- while ((ch = is.read()) >= 0)
+ while ((ch = is.read()) >= 0) {
bos.write(ch);
+ }
bs.set(bos.toString());
is.close();
} catch (Exception e) {
- logger.warn("PROV5012: readRemoteLoglist failed, exception: "+e);
+ logger.warn("PROV5012: readRemoteLoglist failed, exception: " + e);
return bs;
} finally {
get.releaseConnection();
}
return bs;
}
+
/**
- * Issue a POST on the peer POD's /internal/drlogs/ URL to fetch log records available
- * in the remote database that we wish to copy to the local database.
+ * Issue a POST on the peer POD's /internal/drlogs/ URL to fetch log records available in the remote database that
+ * we wish to copy to the local database.
+ *
* @param bs the bitset (an RELBitSet) of log records to fetch
*/
private void replicateDRLogs(RLEBitSet bs) {
- String url = URLUtilities.generatePeerLogsURL();
+ String url = URLUtilities.generatePeerLogsURL();
HttpPost post = new HttpPost(url);
try {
String t = bs.toString();
HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create("text/plain"));
post.setEntity(body);
- if (logger.isDebugEnabled())
- logger.debug("Requesting records: "+t);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Requesting records: " + t);
+ }
HttpResponse response = httpclient.execute(post);
int code = response.getStatusLine().getStatusCode();
if (code != HttpServletResponse.SC_OK) {
- logger.warn("PROV5010: replicateDRLogs failed, bad error code: "+code);
+ logger.warn("PROV5010: replicateDRLogs failed, bad error code: " + code);
return;
}
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
if (!ctype.equals("text/plain")) {
- logger.warn("PROV5011: replicateDRLogs failed, bad content type: "+ctype);
+ logger.warn("PROV5011: replicateDRLogs failed, bad content type: " + ctype);
return;
}
String spoolname = "" + System.currentTimeMillis();
Path tmppath = Paths.get(spooldir, spoolname);
- Path donepath = Paths.get(spooldir, "IN."+spoolname);
+ Path donepath = Paths.get(spooldir, "IN." + spoolname);
Files.copy(entity.getContent(), Paths.get(spooldir, spoolname), StandardCopyOption.REPLACE_EXISTING);
Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
- logger.info("Approximately "+bs.cardinality()+" records replicated.");
+ logger.info("Approximately " + bs.cardinality() + " records replicated.");
} catch (Exception e) {
- logger.warn("PROV5012: replicateDRLogs failed, exception: "+e);
+ logger.warn("PROV5012: replicateDRLogs failed, exception: " + e);
} finally {
post.releaseConnection();
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
index c65ee267..a907a03b 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
@@ -37,11 +37,10 @@ import java.util.*;
* @version $Id$
*/
public class DB {
+
/**
* The name of the properties file (in CLASSPATH)
*/
- private static final String CONFIG_FILE = "provserver.properties";
-
private static String DB_URL;
private static String DB_LOGIN;
private static String DB_PASSWORD;
@@ -53,15 +52,17 @@ public class DB {
public static String HTTP_PORT;
/**
- * Construct a DB object. If this is the very first creation of this object, it will load a copy
- * of the properties for the server, and attempt to load the JDBC driver for the database. If a fatal
- * error occurs (e.g. either the properties file or the DB driver is missing), the JVM will exit.
+ * Construct a DB object. If this is the very first creation of this object, it will load a copy of the properties
+ * for the server, and attempt to load the JDBC driver for the database. If a fatal error occurs (e.g. either the
+ * properties file or the DB driver is missing), the JVM will exit.
*/
public DB() {
if (props == null) {
props = new Properties();
- try (InputStream inStream = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)) {
- props.load(inStream);
+ try {
+ props.load(new FileInputStream(System.getProperty(
+ "org.onap.dmaap.datarouter.provserver.properties",
+ "/opt/app/datartr/etc/provserver.properties")));
String DB_DRIVER = (String) props.get("org.onap.dmaap.datarouter.db.driver");
DB_URL = (String) props.get("org.onap.dmaap.datarouter.db.url");
DB_LOGIN = (String) props.get("org.onap.dmaap.datarouter.db.login");
@@ -94,7 +95,6 @@ public class DB {
* Get a JDBC connection to the DB from the pool. Creates a new one if none are available.
*
* @return the Connection
- * @throws SQLException
*/
@SuppressWarnings("resource")
public Connection getConnection() throws SQLException {
@@ -110,8 +110,9 @@ public class DB {
try {
connection = DriverManager.getConnection(DB_URL, DB_LOGIN, DB_PASSWORD);
} catch (SQLException sqlEx) {
- if (++n >= 3)
+ if (++n >= 3) {
throw sqlEx;
+ }
}
} while (connection == null);
}
@@ -132,15 +133,16 @@ public class DB {
public void release(Connection connection) {
if (connection != null) {
synchronized (queue) {
- if (!queue.contains(connection))
+ if (!queue.contains(connection)) {
queue.add(connection);
+ }
}
}
}
/**
- * Run all necessary retrofits required to bring the database up to the level required for this version
- * of the provisioning server. This should be run before the server itself is started.
+ * Run all necessary retrofits required to bring the database up to the level required for this version of the
+ * provisioning server. This should be run before the server itself is started.
*
* @return true if all retrofits worked, false otherwise
*/
@@ -149,16 +151,15 @@ public class DB {
}
/**
- * Retrofit 1 - Make sure the expected tables are in DB and are initialized.
- * Uses sql_init_01.sql to setup the DB.
+ * Retrofit 1 - Make sure the expected tables are in DB and are initialized. Uses sql_init_01.sql to setup the DB.
*
* @return true if the retrofit worked, false otherwise
*/
private boolean retroFit1() {
final String[] expectedTables = {
- "FEEDS", "FEED_ENDPOINT_ADDRS", "FEED_ENDPOINT_IDS", "PARAMETERS",
- "SUBSCRIPTIONS", "LOG_RECORDS", "INGRESS_ROUTES", "EGRESS_ROUTES",
- "NETWORK_ROUTES", "NODESETS", "NODES", "GROUPS"
+ "FEEDS", "FEED_ENDPOINT_ADDRS", "FEED_ENDPOINT_IDS", "PARAMETERS",
+ "SUBSCRIPTIONS", "LOG_RECORDS", "INGRESS_ROUTES", "EGRESS_ROUTES",
+ "NETWORK_ROUTES", "NODESETS", "NODES", "GROUPS"
};
Connection connection = null;
try {
@@ -166,7 +167,7 @@ public class DB {
Set<String> actualTables = getTableSet(connection);
boolean initialize = false;
for (String table : expectedTables) {
- initialize |= !actualTables.contains(table);
+ initialize |= !actualTables.contains(table.toLowerCase());
}
if (initialize) {
intlogger.info("PROV9001: First time startup; The database is being initialized.");
@@ -176,8 +177,9 @@ public class DB {
intlogger.fatal("PROV9000: The database credentials are not working: " + e.getMessage());
return false;
} finally {
- if (connection != null)
+ if (connection != null) {
release(connection);
+ }
}
return true;
}
@@ -192,7 +194,7 @@ public class DB {
Set<String> tables = new HashSet<String>();
try {
DatabaseMetaData md = connection.getMetaData();
- ResultSet rs = md.getTables("datarouter", "", "", null);
+ ResultSet rs = md.getTables(null, null, "%", null);
if (rs != null) {
while (rs.next()) {
tables.add(rs.getString("TABLE_NAME"));
@@ -200,44 +202,45 @@ public class DB {
rs.close();
}
} catch (SQLException e) {
+ intlogger.fatal("PROV9010: Failed to get TABLE data from DB: " + e.getMessage());
}
return tables;
}
/**
- * Initialize the tables by running the initialization scripts located in the directory specified
- * by the property <i>org.onap.dmaap.datarouter.provserver.dbscripts</i>. Scripts have names of
- * the form sql_init_NN.sql
+ * Initialize the tables by running the initialization scripts located in the directory specified by the property
+ * <i>org.onap.dmaap.datarouter.provserver.dbscripts</i>. Scripts have names of the form sql_init_NN.sql
*
* @param connection a DB connection
- * @param scriptId the number of the sql_init_NN.sql script to run
+ * @param scriptId the number of the sql_init_NN.sql script to run
*/
private void runInitScript(Connection connection, int scriptId) {
String scriptDir = (String) props.get("org.onap.dmaap.datarouter.provserver.dbscripts");
- StringBuilder sb = new StringBuilder();
+ StringBuilder strBuilder = new StringBuilder();
try {
String scriptFile = String.format("%s/sql_init_%02d.sql", scriptDir, scriptId);
- if (!(new File(scriptFile)).exists())
- return;
-
- LineNumberReader in = new LineNumberReader(new FileReader(scriptFile));
+ if (!(new File(scriptFile)).exists()) {
+ intlogger.fatal("PROV9005 Failed to load sql script from : " + scriptFile);
+ System.exit(1);
+ }
+ LineNumberReader lineReader = new LineNumberReader(new FileReader(scriptFile));
String line;
- while ((line = in.readLine()) != null) {
+ while ((line = lineReader.readLine()) != null) {
if (!line.startsWith("--")) {
line = line.trim();
- sb.append(line);
+ strBuilder.append(line);
if (line.endsWith(";")) {
// Execute one DDL statement
- String sql = sb.toString();
- sb.setLength(0);
- Statement s = connection.createStatement();
- s.execute(sql);
- s.close();
+ String sql = strBuilder.toString();
+ strBuilder.setLength(0);
+ Statement statement = connection.createStatement();
+ statement.execute(sql);
+ statement.close();
}
}
}
- in.close();
- sb.setLength(0);
+ lineReader.close();
+ strBuilder.setLength(0);
} catch (Exception e) {
intlogger.fatal("PROV9002 Error when initializing table: " + e.getMessage());
System.exit(1);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
index c3661ba0..b58ab5a0 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
@@ -37,6 +37,7 @@ import org.onap.dmaap.datarouter.provisioning.BaseServlet;
* @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $
*/
public class URLUtilities {
+
/**
* Generate the URL used to access a feed.
*
@@ -44,7 +45,7 @@ public class URLUtilities {
* @return the URL
*/
public static String generateFeedURL(int feedid) {
- return "https://" + BaseServlet.prov_name + "/feed/" + feedid;
+ return "https://" + BaseServlet.provName + "/feed/" + feedid;
}
/**
@@ -54,7 +55,7 @@ public class URLUtilities {
* @return the URL
*/
public static String generatePublishURL(int feedid) {
- return "https://" + BaseServlet.prov_name + "/publish/" + feedid;
+ return "https://" + BaseServlet.provName + "/publish/" + feedid;
}
/**
@@ -64,7 +65,7 @@ public class URLUtilities {
* @return the URL
*/
public static String generateSubscribeURL(int feedid) {
- return "https://" + BaseServlet.prov_name + "/subscribe/" + feedid;
+ return "https://" + BaseServlet.provName + "/subscribe/" + feedid;
}
/**
@@ -74,7 +75,7 @@ public class URLUtilities {
* @return the URL
*/
public static String generateFeedLogURL(int feedid) {
- return "https://" + BaseServlet.prov_name + "/feedlog/" + feedid;
+ return "https://" + BaseServlet.provName + "/feedlog/" + feedid;
}
/**
@@ -84,7 +85,7 @@ public class URLUtilities {
* @return the URL
*/
public static String generateSubscriptionURL(int subid) {
- return "https://" + BaseServlet.prov_name + "/subs/" + subid;
+ return "https://" + BaseServlet.provName + "/subs/" + subid;
}
/**
@@ -94,7 +95,7 @@ public class URLUtilities {
* @return the URL
*/
public static String generateSubLogURL(int subid) {
- return "https://" + BaseServlet.prov_name + "/sublog/" + subid;
+ return "https://" + BaseServlet.provName + "/sublog/" + subid;
}
/**
@@ -137,8 +138,9 @@ public class URLUtilities {
}
System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));
for (String pod : BaseServlet.getPods()) {
- if (!pod.equals(this_pod))
+ if (!pod.equals(this_pod)) {
other_pod = pod;
+ }
}
}
return other_pod;
diff --git a/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql b/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql
new file mode 100644
index 00000000..e01ce3b0
--- /dev/null
+++ b/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql
@@ -0,0 +1,145 @@
+use datarouter;
+
+CREATE TABLE FEEDS (
+ FEEDID INT UNSIGNED NOT NULL PRIMARY KEY,
+ GROUPID INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ NAME VARCHAR(255) NOT NULL,
+ VERSION VARCHAR(20) NOT NULL,
+ DESCRIPTION VARCHAR(1000),
+ BUSINESS_DESCRIPTION VARCHAR(1000) DEFAULT NULL,
+ AUTH_CLASS VARCHAR(32) NOT NULL,
+ PUBLISHER VARCHAR(8) NOT NULL,
+ SELF_LINK VARCHAR(256),
+ PUBLISH_LINK VARCHAR(256),
+ SUBSCRIBE_LINK VARCHAR(256),
+ LOG_LINK VARCHAR(256),
+ DELETED BOOLEAN DEFAULT FALSE,
+ LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ SUSPENDED BOOLEAN DEFAULT FALSE,
+ CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
+
+CREATE TABLE FEED_ENDPOINT_IDS (
+ FEEDID INT UNSIGNED NOT NULL,
+ USERID VARCHAR(20) NOT NULL,
+ PASSWORD VARCHAR(32) NOT NULL
+);
+
+CREATE TABLE FEED_ENDPOINT_ADDRS (
+ FEEDID INT UNSIGNED NOT NULL,
+ ADDR VARCHAR(44) NOT NULL
+);
+
+CREATE TABLE SUBSCRIPTIONS (
+ SUBID INT UNSIGNED NOT NULL PRIMARY KEY,
+ FEEDID INT UNSIGNED NOT NULL,
+ GROUPID INT(10) UNSIGNED NOT NULL DEFAULT 0,
+ DELIVERY_URL VARCHAR(256),
+ DELIVERY_USER VARCHAR(20),
+ DELIVERY_PASSWORD VARCHAR(32),
+ DELIVERY_USE100 BOOLEAN DEFAULT FALSE,
+ METADATA_ONLY BOOLEAN DEFAULT FALSE,
+ SUBSCRIBER VARCHAR(8) NOT NULL,
+ SELF_LINK VARCHAR(256),
+ LOG_LINK VARCHAR(256),
+ LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+ SUSPENDED BOOLEAN DEFAULT FALSE,
+ CREATED_DATE TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+
+);
+
+CREATE TABLE PARAMETERS (
+ KEYNAME VARCHAR(32) NOT NULL PRIMARY KEY,
+ VALUE VARCHAR(4096) NOT NULL
+);
+
+CREATE TABLE LOG_RECORDS (
+ TYPE ENUM('pub', 'del', 'exp', 'pbf', 'dlx') NOT NULL,
+ EVENT_TIME BIGINT NOT NULL, /* time of the publish request */
+ PUBLISH_ID VARCHAR(64) NOT NULL, /* unique ID assigned to this publish attempt */
+ FEEDID INT UNSIGNED NOT NULL, /* pointer to feed in FEEDS */
+ REQURI VARCHAR(256) NOT NULL, /* request URI */
+ METHOD ENUM('DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'TRACE') NOT NULL, /* HTTP method */
+ CONTENT_TYPE VARCHAR(256) NOT NULL, /* content type of published file */
+ CONTENT_LENGTH BIGINT NOT NULL, /* content length of published file */
+
+ FEED_FILEID VARCHAR(256), /* file ID of published file */
+ REMOTE_ADDR VARCHAR(40), /* IP address of publishing endpoint */
+ USER VARCHAR(50), /* user name of publishing endpoint */
+ STATUS SMALLINT, /* status code returned to delivering agent */
+
+ DELIVERY_SUBID INT UNSIGNED, /* pointer to subscription in SUBSCRIPTIONS */
+ DELIVERY_FILEID VARCHAR(256), /* file ID of file being delivered */
+ RESULT SMALLINT, /* result received from subscribing agent */
+
+ ATTEMPTS INT, /* deliveries attempted */
+ REASON ENUM('notRetryable', 'retriesExhausted', 'diskFull', 'other'),
+
+ RECORD_ID BIGINT UNSIGNED NOT NULL PRIMARY KEY, /* unique ID for this record */
+ CONTENT_LENGTH_2 BIGINT,
+
+ INDEX (FEEDID) USING BTREE,
+ INDEX (DELIVERY_SUBID) USING BTREE,
+ INDEX (RECORD_ID) USING BTREE
+) ENGINE = MyISAM;
+
+CREATE TABLE INGRESS_ROUTES (
+ SEQUENCE INT UNSIGNED NOT NULL,
+ FEEDID INT UNSIGNED NOT NULL,
+ USERID VARCHAR(20),
+ SUBNET VARCHAR(44),
+ NODESET INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE EGRESS_ROUTES (
+ SUBID INT UNSIGNED NOT NULL PRIMARY KEY,
+ NODEID INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NETWORK_ROUTES (
+ FROMNODE INT UNSIGNED NOT NULL,
+ TONODE INT UNSIGNED NOT NULL,
+ VIANODE INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NODESETS (
+ SETID INT UNSIGNED NOT NULL,
+ NODEID INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NODES (
+ NODEID INT UNSIGNED NOT NULL PRIMARY KEY,
+ NAME VARCHAR(255) NOT NULL,
+ ACTIVE BOOLEAN DEFAULT TRUE
+);
+
+CREATE TABLE GROUPS (
+ GROUPID INT UNSIGNED NOT NULL PRIMARY KEY,
+ AUTHID VARCHAR(100) NOT NULL,
+ NAME VARCHAR(50) NOT NULL,
+ DESCRIPTION VARCHAR(255),
+ CLASSIFICATION VARCHAR(20) NOT NULL,
+ MEMBERS TINYTEXT,
+ LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
+
+INSERT INTO PARAMETERS VALUES
+ ('ACTIVE_POD', 'prov.datarouternew.com'),
+ ('PROV_ACTIVE_NAME', 'prov.datarouternew.com'),
+ ('STANDBY_POD', ''),
+ ('PROV_NAME', 'prov.datarouternew.com'),
+ ('NODES', '172.100.0.1|node.datarouternew.com'),
+ ('PROV_DOMAIN', 'datarouternew.com'),
+ ('DELIVERY_INIT_RETRY_INTERVAL', '10'),
+ ('DELIVERY_MAX_AGE', '86400'),
+ ('DELIVERY_MAX_RETRY_INTERVAL', '3600'),
+ ('DELIVERY_RETRY_RATIO', '2'),
+ ('LOGROLL_INTERVAL', '300'),
+ ('PROV_AUTH_ADDRESSES', '172.100.0.1|prov.datarouternew.com|node.datarouternew.com'),
+ ('PROV_AUTH_SUBJECTS', ''),
+ ('PROV_MAXFEED_COUNT', '10000'),
+ ('PROV_MAXSUB_COUNT', '100000'),
+ ('PROV_REQUIRE_CERT', 'false'),
+ ('PROV_REQUIRE_SECURE', 'false'),
+ ('_INT_VALUES', 'LOGROLL_INTERVAL|PROV_MAXFEED_COUNT|PROV_MAXSUB_COUNT|DELIVERY_INIT_RETRY_INTERVAL|DELIVERY_MAX_RETRY_INTERVAL|DELIVERY_RETRY_RATIO|DELIVERY_MAX_AGE')
+ ;
diff --git a/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml b/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml
index eece1554..6aee4dbd 100644
--- a/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml
+++ b/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml
@@ -30,11 +30,9 @@ services:
- "8443:8443"
- "8080:8080"
volumes:
- - ./prov_data/proserver.properties:/opt/app/datartr/etc/proserver.properties
-# - ./prov_data/datarouter-prov-jar-with-dependencies.jar:/opt/app/datartr/lib/datarouter-prov-jar-with-dependencies.jar
+ - ./prov_data/provserver.properties:/opt/app/datartr/etc/provserver.properties
- ./prov_data/addSubscriber.txt:/opt/app/datartr/addSubscriber.txt
- ./prov_data/addFeed3.txt:/opt/app/datartr/addFeed3.txt
- entrypoint: ["bash", "-c", "./startup.sh"]
depends_on:
mariadb_container:
condition: service_healthy
@@ -58,7 +56,6 @@ services:
- "9090:8080"
volumes:
- ./node_data/node.properties:/opt/app/datartr/etc/node.properties
- entrypoint: ["bash", "-c", "./startup.sh"]
depends_on:
datarouter-prov:
condition: service_healthy
@@ -73,15 +70,17 @@ services:
container_name: mariadb
ports:
- "3306:3306"
+# volumes:
+# - ./database/sql_init_01.sql:/docker-entrypoint-initdb.d/sql_init_01.sql
environment:
MYSQL_ROOT_PASSWORD: datarouter
MYSQL_DATABASE: datarouter
MYSQL_USER: datarouter
MYSQL_PASSWORD: datarouter
healthcheck:
- test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
+ test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost", "--silent"]
interval: 10s
- timeout: 10s
+ timeout: 30s
retries: 5
networks:
diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties b/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties
index d733cc2a..10bb5eba 100644
--- a/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties
+++ b/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties
@@ -24,22 +24,24 @@
#Jetty Server properties
org.onap.dmaap.datarouter.provserver.http.port = 8080
org.onap.dmaap.datarouter.provserver.https.port = 8443
-org.onap.dmaap.datarouter.provserver.https.relaxation = false
-org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
+org.onap.dmaap.datarouter.provserver.https.relaxation = false
+
org.onap.dmaap.datarouter.provserver.keystore.type = jks
+org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
org.onap.dmaap.datarouter.provserver.keystore.path = /opt/app/datartr/self_signed/keystore.jks
-
org.onap.dmaap.datarouter.provserver.keystore.password = changeit
-#org.onap.dmaap.datarouter.provserver.truststore.path = /home/eby/dr2/misc/cacerts+1
-#org.onap.dmaap.datarouter.provserver.truststore.path = /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts
org.onap.dmaap.datarouter.provserver.truststore.path = /opt/app/datartr/self_signed/cacerts.jks
-
org.onap.dmaap.datarouter.provserver.truststore.password = changeit
+
org.onap.dmaap.datarouter.provserver.accesslog.dir = /opt/app/datartr/logs
org.onap.dmaap.datarouter.provserver.spooldir = /opt/app/datartr/spool
org.onap.dmaap.datarouter.provserver.dbscripts = /opt/app/datartr/etc/misc
org.onap.dmaap.datarouter.provserver.logretention = 30
+#DMAAP-597 (Tech Dept) REST request source IP auth
+# relaxation to accommodate OOM kubernetes deploy
+org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true
+
# Database access
org.onap.dmaap.datarouter.db.driver = org.mariadb.jdbc.Driver
org.onap.dmaap.datarouter.db.url = jdbc:mariadb://172.100.0.2:3306/datarouter
diff --git a/datarouter-prov/src/main/resources/docker/startup.sh b/datarouter-prov/src/main/resources/docker/startup.sh
index e964f66e..ba0f7351 100644
--- a/datarouter-prov/src/main/resources/docker/startup.sh
+++ b/datarouter-prov/src/main/resources/docker/startup.sh
@@ -13,5 +13,4 @@ java -classpath $CLASSPATH org.onap.dmaap.datarouter.provisioning.Main
runner_file="$LIB/datarouter-prov-jar-with-dependencies.jar"
echo "Starting using" $runner_file
-java -Dcom.att.eelf.logging.file==/opt/app/datartr/etc/logback.xml -Dcom.att.eelf.logging.path=/root -jar $runner_file
-
+java -Dorg.onap.dmaap.datarouter.provserver.properties=/opt/app/datartr/etc/provserver.properties -Dcom.att.eelf.logging.file=/opt/app/datartr/etc/logback.xml -Dcom.att.eelf.logging.path=/root -jar $runner_file \ No newline at end of file
diff --git a/datarouter-prov/src/main/resources/misc/provcmd b/datarouter-prov/src/main/resources/misc/provcmd
index 75d0bffa..e3654eb9 100644
--- a/datarouter-prov/src/main/resources/misc/provcmd
+++ b/datarouter-prov/src/main/resources/misc/provcmd
@@ -19,6 +19,21 @@
#
# ECOMP is a trademark and service mark of AT&T Intellectual Property.
+urlencode() {
+ local data
+ if [[ $# != 1 ]]; then
+ echo "Usage: $0 string-to-urlencode"
+ return 1
+ fi
+ data="$(curl -s -o /dev/null -w %url_effective --get --data-urlencode "$1" "")"
+ if [[ $? != 3 ]]; then
+ echo "Unexpected error" 1>&2
+ return 2
+ fi
+ echo "${data##/?}"
+ return 0
+}
+export urlencode
PATH=/opt/app/datartr/bin:/bin:/usr/bin:$PATH
PROVCMD="$0"
diff --git a/datarouter-prov/src/main/resources/misc/sql_init_01.sql b/datarouter-prov/src/main/resources/misc/sql_init_01.sql
index e1dfd0c8..e01ce3b0 100644
--- a/datarouter-prov/src/main/resources/misc/sql_init_01.sql
+++ b/datarouter-prov/src/main/resources/misc/sql_init_01.sql
@@ -114,12 +114,12 @@ CREATE TABLE NODES (
);
CREATE TABLE GROUPS (
- GROUPID INT UNSIGNED NOT NULL PRIMARY KEY,
- AUTHID VARCHAR(100) NOT NULL,
- NAME VARCHAR(50) NOT NULL,
+ GROUPID INT UNSIGNED NOT NULL PRIMARY KEY,
+ AUTHID VARCHAR(100) NOT NULL,
+ NAME VARCHAR(50) NOT NULL,
DESCRIPTION VARCHAR(255),
- CLASSIFICATION VARCHAR(20) NOT NULL,
- MEMBERS TINYTEXT,
+ CLASSIFICATION VARCHAR(20) NOT NULL,
+ MEMBERS TINYTEXT,
LAST_MOD TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
@@ -143,6 +143,3 @@ INSERT INTO PARAMETERS VALUES
('PROV_REQUIRE_SECURE', 'false'),
('_INT_VALUES', 'LOGROLL_INTERVAL|PROV_MAXFEED_COUNT|PROV_MAXSUB_COUNT|DELIVERY_INIT_RETRY_INTERVAL|DELIVERY_MAX_RETRY_INTERVAL|DELIVERY_RETRY_RATIO|DELIVERY_MAX_AGE')
;
-
-INSERT INTO FEED_ENDPOINT_ADDRS VALUES
- (1, '172.100.0.1'); \ No newline at end of file
diff --git a/datarouter-prov/src/main/resources/provserver.properties b/datarouter-prov/src/main/resources/provserver.properties
index 28ffb981..10bb5eba 100644
--- a/datarouter-prov/src/main/resources/provserver.properties
+++ b/datarouter-prov/src/main/resources/provserver.properties
@@ -24,22 +24,24 @@
#Jetty Server properties
org.onap.dmaap.datarouter.provserver.http.port = 8080
org.onap.dmaap.datarouter.provserver.https.port = 8443
-org.onap.dmaap.datarouter.provserver.https.relaxation = false
-org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
+org.onap.dmaap.datarouter.provserver.https.relaxation = false
+
org.onap.dmaap.datarouter.provserver.keystore.type = jks
+org.onap.dmaap.datarouter.provserver.keymanager.password = changeit
org.onap.dmaap.datarouter.provserver.keystore.path = /opt/app/datartr/self_signed/keystore.jks
-
org.onap.dmaap.datarouter.provserver.keystore.password = changeit
-#org.onap.dmaap.datarouter.provserver.truststore.path = /home/eby/dr2/misc/cacerts+1
-#org.onap.dmaap.datarouter.provserver.truststore.path = /usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts
org.onap.dmaap.datarouter.provserver.truststore.path = /opt/app/datartr/self_signed/cacerts.jks
-
org.onap.dmaap.datarouter.provserver.truststore.password = changeit
+
org.onap.dmaap.datarouter.provserver.accesslog.dir = /opt/app/datartr/logs
org.onap.dmaap.datarouter.provserver.spooldir = /opt/app/datartr/spool
-org.onap.dmaap.datarouter.provserver.dbscripts = /opt/app/datartr/etc/misc
+org.onap.dmaap.datarouter.provserver.dbscripts = /opt/app/datartr/etc/misc
org.onap.dmaap.datarouter.provserver.logretention = 30
+#DMAAP-597 (Tech Dept) REST request source IP auth
+# relaxation to accommodate OOM kubernetes deploy
+org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true
+
# Database access
org.onap.dmaap.datarouter.db.driver = org.mariadb.jdbc.Driver
org.onap.dmaap.datarouter.db.url = jdbc:mariadb://172.100.0.2:3306/datarouter
diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/AllTests.java b/datarouter-prov/src/test/java/datarouter/provisioning/AllTests.java
index 34fb144f..33a34c07 100644
--- a/datarouter-prov/src/test/java/datarouter/provisioning/AllTests.java
+++ b/datarouter-prov/src/test/java/datarouter/provisioning/AllTests.java
@@ -30,20 +30,21 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({
- IntegrationTestDrFeedsPost.class,
- IntegrationTestDrFeedsGet.class,
- IntegrationTestDrFeedsPut.class,
- IntegrationTestDrFeedsDelete.class,
- IntegrationTestFeedPut.class,
- IntegrationTestSubscribePost.class,
- IntegrationTestInternalGet.class,
- IntegrationTestInternalMisc.class,
- IntegrationTestPublish.class,
- IntegrationTestLogGet.class,
- IntegrationTestFeedDelete.class,
- IntegrationTestCleanup.class,
- IntegrationTestRleBitSet.class
- })
+ IntegrationTestDrFeedsPost.class,
+ IntegrationTestDrFeedsPut.class,
+ IntegrationTestDrFeedsDelete.class,
+ IntegrationTestFeedPut.class,
+ IntegrationTestDrFeedsGet.class,
+ IntegrationTestInternalGet.class,
+ IntegrationTestInternalMisc.class,
+ IntegrationTestPublish.class,
+ IntegrationTestSubscribePost.class,
+ IntegrationTestLogGet.class,
+ IntegrationTestFeedDelete.class,
+ IntegrationTestCleanup.class,
+ IntegrationTestRleBitSet.class
+})
public class AllTests {
+
}
diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/DbTestData.java b/datarouter-prov/src/test/java/datarouter/provisioning/DbTestData.java
new file mode 100644
index 00000000..36a2eb01
--- /dev/null
+++ b/datarouter-prov/src/test/java/datarouter/provisioning/DbTestData.java
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * ============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 datarouter.provisioning;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.onap.dmaap.datarouter.provisioning.FeedServlet;
+
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * The DbTestData class
+ *
+ * @version 1.0.1
+ */
+public class DbTestData {
+
+ private static boolean dbReady = false;
+
+ public static void populateDb(AbstractHttpClient httpclient, Properties props) {
+ if (!dbReady) {
+ JSONObject jo = buildFeedRequest();
+ for (int i = 0; i < 10; i++) {
+ jo.put("version", "" + System.currentTimeMillis());
+ int statusCode = -1;
+ String url = props.getProperty("test.host");
+ HttpPost httpPost = new HttpPost(url);
+ try {
+ httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
+ String feedRequestString = jo.toString();
+ HttpEntity body = new ByteArrayEntity(feedRequestString.getBytes(),
+ ContentType.create(FeedServlet.FEED_CONTENT_TYPE));
+ httpPost.setEntity(body);
+ HttpResponse response = httpclient.execute(httpPost);
+ statusCode = response.getStatusLine().getStatusCode();
+ HttpEntity entity = response.getEntity();
+ EntityUtils.consume(entity);
+ } catch (IOException e) {
+ System.err.println(e);
+ } finally {
+ httpPost.releaseConnection();
+ }
+ System.out.println(i + " " + statusCode);
+ }
+ dbReady = true;
+ }
+ }
+
+ private static JSONObject buildFeedRequest() {
+ JSONObject jo = new JSONObject();
+ jo.put("name", "feed");
+ jo.put("version", "" + System.currentTimeMillis());
+ jo.put("description", "Sample feed used by JUnit to test");
+
+ JSONObject jo2 = new JSONObject();
+ jo2.put("classification", "unrestricted");
+
+ JSONObject jo3 = new JSONObject();
+ jo3.put("id", "id001");
+ jo3.put("password", "re1kwelj");
+
+ JSONObject jo4 = new JSONObject();
+ jo4.put("id", "id002");
+ jo4.put("password", "o9eqlmbd");
+
+ JSONArray ja = new JSONArray();
+ ja.put(jo3);
+ ja.put(jo4);
+ jo2.put("endpoint_ids", ja);
+
+ ja = new JSONArray();
+ ja.put("10.0.0.1");
+ ja.put("192.168.0.1");
+ ja.put("135.207.136.128/25");
+ jo2.put("endpoint_addrs", ja);
+
+ jo.put("authorization", jo2);
+ return jo;
+ }
+}
diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/FillDB.java b/datarouter-prov/src/test/java/datarouter/provisioning/FillDB.java
deleted file mode 100644
index fd682bb3..00000000
--- a/datarouter-prov/src/test/java/datarouter/provisioning/FillDB.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*******************************************************************************
- * ============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 datarouter.provisioning;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.ssl.SSLSocketFactory;
-import org.apache.http.entity.ByteArrayEntity;
-import org.apache.http.entity.ContentType;
-import org.apache.http.impl.client.AbstractHttpClient;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.util.EntityUtils;
-import org.json.JSONArray;
-import org.json.JSONObject;
-import org.onap.dmaap.datarouter.provisioning.FeedServlet;
-
-/**
- * The FillDB class
- *
- * @version 1.0.1
- */
-public class FillDB {
- /**
- * This is the main method of the FillDB class.
- *
- * @throws KeyStoreException KeyStore exception
- * @throws FileNotFoundException Exeception thrown when error locating file
- * @throws KeyManagementException KeyManagement exception
- * @throws UnrecoverableKeyException Exception thrown when Key cannot be recovered
- * @throws NoSuchAlgorithmException Exception thrown when algorithm does not exist
- */
- public static void main(String[] args)
- throws KeyStoreException, FileNotFoundException, KeyManagementException, UnrecoverableKeyException,
- NoSuchAlgorithmException {
- AbstractHttpClient httpclient = new DefaultHttpClient();
-
- String keystore = "/home/eby/dr2/misc/client.keystore";
- String kspass = "changeit";
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- FileInputStream instream = new FileInputStream(new File(keystore));
- try {
- trustStore.load(instream, kspass.toCharArray());
- } catch (Exception x) {
- System.err.println("READING KEYSTORE: " + x);
- } finally {
- try {
- instream.close();
- } catch (Exception ignore) {
- // Ignore exception
- }
- }
-
- SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore, "changeit", trustStore);
- Scheme sch = new Scheme("https", 443, socketFactory);
- httpclient.getConnectionManager().getSchemeRegistry().register(sch);
-
- JSONObject jo = buildFeedRequest();
- for (int i = 0; i < 10000; i++) {
- jo.put("version", "" + System.currentTimeMillis());
- int rv = -1;
- String url = "https://conwy.proto.research.att.com:6443/";
- HttpPost httpPost = new HttpPost(url);
- try {
- httpPost.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
- String feedRequestString = jo.toString();
- HttpEntity body = new ByteArrayEntity(feedRequestString.getBytes(),
- ContentType.create(FeedServlet.FEED_CONTENT_TYPE));
- httpPost.setEntity(body);
-
- HttpResponse response = httpclient.execute(httpPost);
- rv = response.getStatusLine().getStatusCode();
- HttpEntity entity = response.getEntity();
- EntityUtils.consume(entity);
- } catch (IOException e) {
- System.err.println(e);
- } finally {
- httpPost.releaseConnection();
- }
- System.out.println(i + " " + rv);
- }
- }
-
- private static JSONObject buildFeedRequest() {
- JSONObject jo = new JSONObject();
- jo.put("name", "feed");
- jo.put("version", "" + System.currentTimeMillis());
- jo.put("description", "Sample feed used by JUnit to test");
-
- JSONObject jo2 = new JSONObject();
- jo2.put("classification", "unrestricted");
-
-
- JSONObject jo3 = new JSONObject();
- jo3.put("id", "id001");
- jo3.put("password", "re1kwelj");
-
- JSONObject jo4 = new JSONObject();
- jo4.put("id", "id002");
- jo4.put("password", "o9eqlmbd");
-
- JSONArray ja = new JSONArray();
- ja.put(jo3);
- ja.put(jo4);
- jo2.put("endpoint_ids", ja);
-
- ja = new JSONArray();
- ja.put("10.0.0.1");
- ja.put("192.168.0.1");
- ja.put("135.207.136.128/25");
- jo2.put("endpoint_addrs", ja);
-
- jo.put("authorization", jo2);
- return jo;
- }
-}
diff --git a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java
index 52e80a8f..71446219 100644
--- a/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java
+++ b/datarouter-prov/src/test/java/datarouter/provisioning/IntegrationTestBase.java
@@ -49,14 +49,17 @@ import org.junit.Before;
import org.onap.dmaap.datarouter.provisioning.FeedServlet;
public class IntegrationTestBase {
- /** The properties file to read the DB properties from. */
- public static final String CONFIG_FILE = "integration_test.properties";
+
+ /**
+ * The properties file to read the DB properties from.
+ */
+ private static final String CONFIG_FILE = "integration_test.properties";
public Properties props;
protected AbstractHttpClient httpclient;
- protected String s33;
- protected String s257;
- protected static JSONObject db_state;
+ String s33;
+ String s257;
+ static JSONObject db_state;
/**
* This is the setUp method.
@@ -65,13 +68,10 @@ public class IntegrationTestBase {
public void setUp() throws Exception {
if (props == null) {
props = new Properties();
- InputStream inStream = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE);
- try {
+ try (InputStream inStream = getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)) {
props.load(inStream);
} catch (Exception e) {
e.printStackTrace();
- } finally {
- inStream.close();
}
}
@@ -83,8 +83,8 @@ public class IntegrationTestBase {
// keystore
String store = props.getProperty("test.keystore");
- String pass = props.getProperty("test.kspassword");
- KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ String pass = props.getProperty("test.kspassword");
+ KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream instream = new FileInputStream(new File(store));
try {
keyStore.load(instream, pass.toCharArray());
@@ -99,8 +99,8 @@ public class IntegrationTestBase {
}
store = props.getProperty("test.truststore");
- pass = props.getProperty("test.tspassword");
- KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ pass = props.getProperty("test.tspassword");
+ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
instream = new FileInputStream(new File(store));
try {
trustStore.load(instream, pass.toCharArray());
@@ -117,15 +117,17 @@ public class IntegrationTestBase {
SSLSocketFactory socketFactory = new SSLSocketFactory(keyStore, "changeit", trustStore);
Scheme sch = new Scheme("https", 443, socketFactory);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
+
+ //DbTestData.populateDb(httpclient, props);
}
/**
* This is the getDBstate method.
*/
- public JSONObject getDBstate() {
+ void getDBstate() {
// set db_state!
if (db_state == null) {
- String url = props.getProperty("test.host") + "/internal/prov";
+ String url = props.getProperty("test.host") + "/internal/prov";
HttpGet httpGet = new HttpGet(url);
try {
httpGet.addHeader(FeedServlet.BEHALF_HEADER, "JUnit");
@@ -133,7 +135,7 @@ public class IntegrationTestBase {
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
// save the response body as db_state
- boolean ok = ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE1);
+ boolean ok = ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE1);
ok |= ctype.equals(FeedServlet.PROVFULL_CONTENT_TYPE2);
if (ok) {
db_state = null;
@@ -151,7 +153,6 @@ public class IntegrationTestBase {
httpGet.releaseConnection();
}
}
- return db_state;
}
/**
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
index 5966b775..99142ac9 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
@@ -29,11 +29,14 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
+import java.util.Properties;
import java.util.Set;
import static org.hamcrest.Matchers.is;
@@ -44,6 +47,7 @@ import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class BaseServletTest {
+
private BaseServlet baseServlet;
@Mock
@@ -51,20 +55,25 @@ public class BaseServletTest {
@Before
public void setUp() throws Exception {
- FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsg_flag", false, true);
+ Properties props = new Properties();
+ props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false");
+ FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true);
+ FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true);
SynchronizerTask synchronizerTask = mock(SynchronizerTask.class);
+ when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true);
baseServlet = new BaseServlet();
}
@Test
- public void Given_Request_Path_Info_Is_Valid_Then_Id_Is_Extracted_Correctly() throws Exception {
+ public void Given_Request_Path_Info_Is_Valid_Then_Id_Is_Extracted_Correctly() {
when(request.getPathInfo()).thenReturn("/123");
assertThat(baseServlet.getIdFromPath(request), is(123));
}
+
@Test
- public void Given_Request_Path_Info_Is_Not_Valid_Then_Minus_One_Is_Returned() throws Exception {
+ public void Given_Request_Path_Info_Is_Not_Valid_Then_Minus_One_Is_Returned() {
when(request.getPathInfo()).thenReturn("/abc");
assertThat(baseServlet.getIdFromPath(request), is(-1));
when(request.getPathInfo()).thenReturn("/");
@@ -76,8 +85,10 @@ public class BaseServletTest {
when(request.isSecure()).thenReturn(true);
Set<String> authAddressesAndNetworks = new HashSet<String>();
authAddressesAndNetworks.add(("127.0.0.1"));
- FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true);
- FieldUtils.writeDeclaredStaticField(BaseServlet.class, "require_cert", false, true);
+ FieldUtils
+ .writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks,
+ true);
+ FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", false, true);
assertThat(baseServlet.isAuthorizedForProvisioning(request), is(nullValue()));
}
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
index 0e717b35..858a71c2 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
@@ -23,7 +23,6 @@
package org.onap.dmaap.datarouter.provisioning;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
@@ -33,6 +32,7 @@ import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
import org.onap.dmaap.datarouter.authz.Authorizer;
import org.onap.dmaap.datarouter.provisioning.beans.Feed;
import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
@@ -41,8 +41,8 @@ import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import java.io.OutputStream;
import java.util.HashSet;
+import java.util.Properties;
import java.util.Set;
import static org.hamcrest.Matchers.notNullValue;
@@ -53,6 +53,7 @@ import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Feed")
public class FeedServletTest {
+
private static FeedServlet feedServlet;
@Mock
@@ -71,7 +72,8 @@ public class FeedServletTest {
}
@Test
- public void Given_Request_Is_HTTP_DELETE_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated()
+ throws Exception {
when(request.isSecure()).thenReturn(false);
feedServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
@@ -79,7 +81,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_DELETE_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
setBehalfHeader(null);
feedServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
@@ -87,7 +90,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_DELETE_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
when(request.getPathInfo()).thenReturn(null);
feedServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
@@ -95,7 +99,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_DELETE_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
+ throws Exception {
setFeedToReturnInvalidFeedIdSupplied();
feedServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
@@ -103,7 +108,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_DELETE_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated()
+ throws Exception {
setAuthoriserToReturnRequestNotAuthorized();
feedServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
@@ -111,19 +117,22 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Fails_An_Internal_Server_Error_Is_Reported() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Fails_An_Internal_Server_Error_Is_Reported()
+ throws Exception {
FeedServlet feedServlet = new FeedServlet() {
protected boolean doUpdate(Updateable bean) {
return false;
}
};
feedServlet.doDelete(request, response);
- verify(response).sendError(eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), argThat(notNullValue(String.class)));
+ verify(response)
+ .sendError(eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), argThat(notNullValue(String.class)));
}
@Test
- public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Succeeds_A_NO_CONTENT_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Succeeds_A_NO_CONTENT_Response_Is_Generated()
+ throws Exception {
FeedServlet feedServlet = new FeedServlet() {
protected boolean doUpdate(Updateable bean) {
return true;
@@ -134,14 +143,16 @@ public class FeedServletTest {
}
@Test
- public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_GET_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated()
+ throws Exception {
when(request.isSecure()).thenReturn(false);
feedServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
}
@Test
- public void Given_Request_Is_HTTP_GET_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_GET_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
setBehalfHeader(null);
feedServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
@@ -149,7 +160,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_GET_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_GET_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
when(request.getPathInfo()).thenReturn(null);
feedServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
@@ -157,7 +169,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_GET_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_GET_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
+ throws Exception {
setFeedToReturnInvalidFeedIdSupplied();
feedServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
@@ -165,7 +178,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_GET_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_GET_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated()
+ throws Exception {
setAuthoriserToReturnRequestNotAuthorized();
feedServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
@@ -182,14 +196,16 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated()
+ throws Exception {
when(request.isSecure()).thenReturn(false);
feedServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
}
@Test
- public void Given_Request_Is_HTTP_PUT_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_PUT_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
setBehalfHeader(null);
feedServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
@@ -197,7 +213,8 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_PUT_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_PUT_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
when(request.getPathInfo()).thenReturn(null);
feedServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
@@ -205,21 +222,25 @@ public class FeedServletTest {
@Test
- public void Given_Request_Is_HTTP_PUT_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_PUT_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
+ throws Exception {
setFeedToReturnInvalidFeedIdSupplied();
feedServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
}
@Test
- public void Given_Request_Is_HTTP_PUT_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_PUT_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
+ throws Exception {
when(request.getContentType()).thenReturn("stub_contentType");
feedServlet.doPut(request, response);
- verify(response).sendError(eq(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), argThat(notNullValue(String.class)));
+ verify(response)
+ .sendError(eq(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE), argThat(notNullValue(String.class)));
}
@Test
- public void Given_Request_Is_HTTP_PUT_And_Request_Contains_Badly_Formed_JSON_Then_Bad_Request_Response_Is_Generated() throws Exception {
+ public void Given_Request_Is_HTTP_PUT_And_Request_Contains_Badly_Formed_JSON_Then_Bad_Request_Response_Is_Generated()
+ throws Exception {
when(request.getHeader("Content-Type")).thenReturn("application/vnd.att-dr.feed; version=1.0");
ServletInputStream inStream = mock(ServletInputStream.class);
when(request.getInputStream()).thenReturn(inStream);
@@ -228,8 +249,12 @@ public class FeedServletTest {
}
- private void initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase() throws IllegalAccessException {
- FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsg_flag", false, true);
+ private void initialiseBaseServletToBypassRetreiviingInitialisationParametersFromDatabase()
+ throws IllegalAccessException {
+ Properties props = new Properties();
+ props.setProperty("org.onap.dmaap.datarouter.provserver.isaddressauthenabled", "false");
+ FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true);
+ FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true);
SynchronizerTask synchronizerTask = mock(SynchronizerTask.class);
when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN);
FieldUtils.writeDeclaredStaticField(SynchronizerTask.class, "synctask", synchronizerTask, true);
@@ -239,8 +264,10 @@ public class FeedServletTest {
when(request.isSecure()).thenReturn(true);
Set<String> authAddressesAndNetworks = new HashSet<String>();
authAddressesAndNetworks.add(("127.0.0.1"));
- FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true);
- FieldUtils.writeDeclaredStaticField(BaseServlet.class, "require_cert", false, true);
+ FieldUtils
+ .writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks,
+ true);
+ FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", false, true);
}
private void setBehalfHeader(String headerValue) {
@@ -282,7 +309,7 @@ public class FeedServletTest {
private void setPokerToNotCreateTimersWhenDeleteFeedIsCalled() throws Exception {
Poker poker = mock(Poker.class);
- FieldUtils.writeDeclaredStaticField(Poker.class, "p", poker, true);
+ FieldUtils.writeDeclaredStaticField(Poker.class, "poker", poker, true);
}
private void setupValidAuthorisedRequest() throws Exception {