From: Ram Koya Date: Wed, 29 Aug 2018 13:52:08 +0000 (+0000) Subject: Merge "Add LOGJSONObject Unit Tests Issue-ID: DMAAP-101" X-Git-Tag: 1.0.1~52 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=f6ecbb70d6e625d716d91ccb00b36f887eb4323c;hp=15d7315f63755bf4d03b4527ddb5ae28d8850355;p=dmaap%2Fdatarouter.git Merge "Add LOGJSONObject Unit Tests Issue-ID: DMAAP-101" --- diff --git a/Subscriber/src/SSASubscriber.java b/Subscriber/src/SSASubscriber.java deleted file mode 100644 index 5ec099bd..00000000 --- a/Subscriber/src/SSASubscriber.java +++ /dev/null @@ -1,115 +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. - * * - ******************************************************************************/ - - -import org.eclipse.jetty.http.HttpVersion; -import org.eclipse.jetty.servlet.*; -import org.eclipse.jetty.util.ssl.*; -import org.eclipse.jetty.server.*; -import org.apache.log4j.Logger; - -/** - * Example stand alone subscriber - */ -public class SSASubscriber { - private static final int Port = 8447; - private static final String KeyStoreType = "jks"; - private static final String KeyStoreFile = "/root/sub/subscriber.jks"; - //private static final String KeyStoreFile = "c:/tmp/subscriber.jks"; - private static final String KeyStorePassword = "changeit"; - private static final String KeyPassword = "changeit"; - private static final String ContextPath = "/"; - private static final String URLPattern = "/*"; - - public static void main(String[] args) throws Exception { - //User story # US792630 -Jetty Upgrade to 9.3.11 - //SSASubscriber register Jetty server. - Server server = new Server(); - HttpConfiguration http_config = new HttpConfiguration(); - http_config.setSecureScheme("https"); - http_config.setSecurePort(Port); - http_config.setRequestHeaderSize(8192); - - // HTTP connector - ServerConnector http = new ServerConnector(server, - new HttpConnectionFactory(http_config)); - http.setPort(7070); - http.setIdleTimeout(30000); - - // SSL Context Factory - SslContextFactory sslContextFactory = new SslContextFactory(); - sslContextFactory.setKeyStoreType(KeyStoreType); - sslContextFactory.setKeyStorePath(KeyStoreFile); - sslContextFactory.setKeyStorePassword(KeyStorePassword); - sslContextFactory.setKeyManagerPassword(KeyPassword); - - // sslContextFactory.setTrustStorePath(ncm.getKSFile()); - // sslContextFactory.setTrustStorePassword("changeit"); - sslContextFactory.setExcludeCipherSuites("SSL_RSA_WITH_DES_CBC_SHA", - "SSL_DHE_RSA_WITH_DES_CBC_SHA", "SSL_DHE_DSS_WITH_DES_CBC_SHA", - "SSL_RSA_EXPORT_WITH_RC4_40_MD5", - "SSL_RSA_EXPORT_WITH_DES40_CBC_SHA", - "SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA", - "SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA"); - - // SSL HTTP Configuration - HttpConfiguration https_config = new HttpConfiguration(http_config); - https_config.addCustomizer(new SecureRequestCustomizer()); - - // SSL Connector - ServerConnector sslConnector = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory(https_config)); - sslConnector.setPort(Port); - server.addConnector(sslConnector); - - /**Skip SSLv3 Fixes*/ - sslContextFactory.addExcludeProtocols("SSLv3"); - System.out.println("Excluded protocols SSASubscriber-"+sslContextFactory.getExcludeProtocols().toString()); - /**End of SSLv3 Fixes*/ - - // HTTPS Configuration - ServerConnector https = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory,HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory(https_config)); - https.setPort(Port); - https.setIdleTimeout(30000); - //server.setConnectors(new Connector[] { http, https }); - server.setConnectors(new Connector[] { http }); - ServletContextHandler ctxt = new ServletContextHandler(0); - ctxt.setContextPath(ContextPath); - server.setHandler(ctxt); - - ctxt.addServlet(new ServletHolder(new SubscriberServlet()), "/*"); - - try { - server.start(); - } catch ( Exception e ) { - System.out.println("Jetty failed to start. Reporting will we unavailable-"+e); - }; - server.join(); - - System.out.println("Subscriber started-"+ server.getState()); - - } -} \ No newline at end of file diff --git a/Subscriber/src/log4j.properties b/Subscriber/src/log4j.properties deleted file mode 100644 index 8c12d5ca..00000000 --- a/Subscriber/src/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -log4j.debug=FALSE -log4j.rootLogger=INFO,Root - -log4j.appender.Root=org.apache.log4j.DailyRollingFileAppender -log4j.appender.Root.file=/opt/app/datartr/logs/subscriber.log -log4j.appender.Root.datePattern='.'yyyyMMdd -log4j.appender.Root.append=true -log4j.appender.Root.layout=org.apache.log4j.PatternLayout -log4j.appender.Root.layout.ConversionPattern=%d %p %t %m%n diff --git a/datarouter-node/pom.xml b/datarouter-node/pom.xml index 61e95400..c6bd3e94 100755 --- a/datarouter-node/pom.xml +++ b/datarouter-node/pom.xml @@ -43,7 +43,7 @@ junit junit - 3.8.1 + 4.10 test diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java index c28827a0..7e10d5a0 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java @@ -79,33 +79,31 @@ public class DeliveryTask implements Runnable, Comparable { boolean monly = di.isMetaDataOnly(); date = Long.parseLong(pubid.substring(0, pubid.indexOf('.'))); Vector hdrv = new Vector(); - try { - try(BufferedReader br = new BufferedReader(new FileReader(metafile))){ - String s = br.readLine(); - int i = s.indexOf('\t'); - method = s.substring(0, i); - if (!"DELETE".equals(method) && !monly) { - length = datafile.length(); + + try (BufferedReader br = new BufferedReader(new FileReader(metafile))) { + String s = br.readLine(); + int i = s.indexOf('\t'); + method = s.substring(0, i); + if (!"DELETE".equals(method) && !monly) { + length = datafile.length(); + } + fileid = s.substring(i + 1); + while ((s = br.readLine()) != null) { + i = s.indexOf('\t'); + String h = s.substring(0, i); + String v = s.substring(i + 1); + if ("x-att-dr-routing".equalsIgnoreCase(h)) { + subid = v.replaceAll("[^ ]*/", ""); + feedid = dth.getFeedId(subid.replaceAll(" .*", "")); } - fileid = s.substring(i + 1); - while ((s = br.readLine()) != null) { - i = s.indexOf('\t'); - String h = s.substring(0, i); - String v = s.substring(i + 1); - if ("x-att-dr-routing".equalsIgnoreCase(h)) { - subid = v.replaceAll("[^ ]*/", ""); - feedid = dth.getFeedId(subid.replaceAll(" .*", "")); - } - if (length == 0 && h.toLowerCase().startsWith("content-")) { - continue; - } - if (h.equalsIgnoreCase("content-type")) { - ctype = v; - } - hdrv.add(new String[]{h, v}); + if (length == 0 && h.toLowerCase().startsWith("content-")) { + continue; + } + if (h.equalsIgnoreCase("content-type")) { + ctype = v; } + hdrv.add(new String[]{h, v}); } - } catch (Exception e) { loggerDeliveryTask.error("Exception "+e.getStackTrace(),e); } @@ -191,29 +189,24 @@ public class DeliveryTask implements Runnable, Comparable { } if (os != null) { long sofar = 0; - try { + try (InputStream is = new FileInputStream(datafile)) { byte[] buf = new byte[1024 * 1024]; - try(InputStream is = new FileInputStream(datafile)){ - while (sofar < length) { - int i = buf.length; - if (sofar + i > length) { - i = (int) (length - sofar); - } - i = is.read(buf, 0, i); - if (i <= 0) { - throw new IOException("Unexpected problem reading data file " + datafile); - } - sofar += i; - os.write(buf, 0, i); + while (sofar < length) { + int i = buf.length; + if (sofar + i > length) { + i = (int) (length - sofar); } - is.close(); - os.close(); + i = is.read(buf, 0, i); + if (i <= 0) { + throw new IOException("Unexpected problem reading data file " + datafile); + } + sofar += i; + os.write(buf, 0, i); } - + os.close(); } catch (IOException ioe) { dth.reportDeliveryExtra(this, sofar); throw ioe; - } } } diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/LogManager.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/LogManager.java index ade47730..ee81a321 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/LogManager.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/LogManager.java @@ -22,22 +22,28 @@ ******************************************************************************/ package org.onap.dmaap.datarouter.node; -import java.util.*; -import java.util.regex.*; -import java.io.*; -import java.nio.file.*; -import java.text.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.TimerTask; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Cleanup of old log files. *

- * Periodically scan the log directory for log files that are older than - * the log file retention interval, and delete them. In a future release, - * This class will also be responsible for uploading events logs to the - * log server to support the log query APIs. + * Periodically scan the log directory for log files that are older than the log file retention interval, and delete + * them. In a future release, This class will also be responsible for uploading events logs to the log server to + * support the log query APIs. */ public class LogManager extends TimerTask { + private NodeConfigManager config; private Matcher isnodelog; private Matcher iseventlog; @@ -46,6 +52,7 @@ public class LogManager extends TimerTask { private String logdir; private class Uploader extends Thread implements DeliveryQueueHelper { + public long getInitFailureTimer() { return (10000L); } @@ -92,7 +99,9 @@ public class LogManager extends TimerTask { private DeliveryQueue dq; public Uploader() { - dq = new DeliveryQueue(this, new DestInfo("LogUpload", uploaddir, null, null, null, config.getMyName(), config.getMyAuth(), false, false)); + dq = new DeliveryQueue(this, + new DestInfo("LogUpload", uploaddir, null, null, null, config.getMyName(), config.getMyAuth(), false, + false)); setDaemon(true); setName("Log Uploader"); start(); @@ -154,11 +163,9 @@ public class LogManager extends TimerTask { f.delete(); } } - try { + try (Writer w = new FileWriter(uploaddir + "/.lastqueued")) { (new File(uploaddir + "/.meta")).delete(); - Writer w = new FileWriter(uploaddir + "/.lastqueued"); w.write(lastqueued + "\n"); - w.close(); } catch (Exception e) { } } @@ -167,10 +174,8 @@ public class LogManager extends TimerTask { /** * Construct a log manager *

- * The log manager will check for expired log files every 5 minutes - * at 20 seconds after the 5 minute boundary. (Actually, the - * interval is the event log rollover interval, which - * defaults to 5 minutes). + * The log manager will check for expired log files every 5 minutes at 20 seconds after the 5 minute boundary. + * (Actually, the interval is the event log rollover interval, which defaults to 5 minutes). */ public LogManager(NodeConfigManager config) { this.config = config; 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 c6b16822..b8c06f14 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 @@ -23,13 +23,19 @@ package org.onap.dmaap.datarouter.node; -import org.eclipse.jetty.http.HttpVersion; -import org.eclipse.jetty.servlet.*; -import org.eclipse.jetty.util.ssl.*; -import org.eclipse.jetty.server.*; -import org.apache.log4j.Logger; - import java.util.Arrays; +import org.apache.log4j.Logger; +import org.eclipse.jetty.http.HttpVersion; +import org.eclipse.jetty.server.Connector; +import org.eclipse.jetty.server.HttpConfiguration; +import org.eclipse.jetty.server.HttpConnectionFactory; +import org.eclipse.jetty.server.SecureRequestCustomizer; +import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.server.ServerConnector; +import org.eclipse.jetty.server.SslConnectionFactory; +import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.util.ssl.SslContextFactory; /** * The main starting point for the Data Router node @@ -60,7 +66,9 @@ public class NodeMain { try { wait(); } catch (Exception exception) { - nodeMainLogger.debug("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(), exception); + nodeMainLogger + .debug("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(), + exception); } } localNodeConfigManager.deregisterConfigTask(this); @@ -123,14 +131,15 @@ public class NodeMain { httpsConfiguration.addCustomizer(secureRequestCustomizer); // HTTPS connector - ServerConnector httpsServerConnector = new ServerConnector(server, + try (ServerConnector httpsServerConnector = new ServerConnector(server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory(httpsConfiguration)); - httpsServerConnector.setPort(nodeConfigManager.getHttpsPort()); - httpsServerConnector.setIdleTimeout(500000); - httpsServerConnector.setAcceptQueueSize(2); + new HttpConnectionFactory(httpsConfiguration))) { + httpsServerConnector.setPort(nodeConfigManager.getHttpsPort()); + httpsServerConnector.setIdleTimeout(500000); + httpsServerConnector.setAcceptQueueSize(2); - server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector}); + server.setConnectors(new Connector[]{httpServerConnector, httpsServerConnector}); + } } ctxt = new ServletContextHandler(0); ctxt.setContextPath("/"); diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java index 5d11206c..9ddbc25a 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java @@ -24,20 +24,28 @@ package org.onap.dmaap.datarouter.node; -import javax.servlet.*; -import javax.servlet.http.*; -import java.util.*; -import java.util.regex.*; -import java.io.*; -import java.nio.file.*; - -import org.apache.log4j.Logger; -import org.onap.dmaap.datarouter.node.eelf.EelfMsgs; - import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; - -import java.net.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Writer; +import java.net.Socket; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Enumeration; +import java.util.regex.Pattern; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.log4j.Logger; +import org.onap.dmaap.datarouter.node.eelf.EelfMsgs; /** * Servlet for handling all http and https requests to the data router node @@ -51,23 +59,25 @@ import java.net.*; * PUT/DELETE https://node/publish/feedid/fileid - publsh request */ public class NodeServlet extends HttpServlet { + private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeServlet"); private static NodeConfigManager config; private static Pattern MetaDataPattern; private static SubnetMatcher internalsubnet = new SubnetMatcher("135.207.136.128/25"); //Adding EELF Logger Rally:US664892 - private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.node.NodeServlet"); + private static EELFLogger eelflogger = EELFManager.getInstance() + .getLogger("org.onap.dmaap.datarouter.node.NodeServlet"); static { try { - String ws = "\\s*"; + final String ws = "\\s*"; // assume that \\ and \" have been replaced by X - String string = "\"[^\"]*\""; + final String string = "\"[^\"]*\""; //String string = "\"(?:[^\"\\\\]|\\\\.)*\""; - String number = "[+-]?(?:\\.\\d+|(?:0|[1-9]\\d*)(?:\\.\\d*)?)(?:[eE][+-]?\\d+)?"; - String value = "(?:" + string + "|" + number + "|null|true|false)"; - String item = string + ws + ":" + ws + value + ws; - String object = ws + "\\{" + ws + "(?:" + item + "(?:" + "," + ws + item + ")*)?\\}" + ws; + final String number = "[+-]?(?:\\.\\d+|(?:0|[1-9]\\d*)(?:\\.\\d*)?)(?:[eE][+-]?\\d+)?"; + final String value = "(?:" + string + "|" + number + "|null|true|false)"; + final String item = string + ws + ":" + ws + value + ws; + final String object = ws + "\\{" + ws + "(?:" + item + "(?:" + "," + ws + item + ")*)?\\}" + ws; MetaDataPattern = Pattern.compile(object, Pattern.DOTALL); } catch (Exception e) { } @@ -95,7 +105,8 @@ public class NodeServlet extends HttpServlet { */ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { NodeUtils.setIpAndFqdnForEelf("doGet"); - eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"), getIdFromPath(req) + ""); + eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"), + getIdFromPath(req) + ""); if (down(resp)) { return; } @@ -130,13 +141,13 @@ public class NodeServlet extends HttpServlet { resp.setContentType("text/plain"); resp.setContentLength((int) fn.length()); resp.setStatus(200); - InputStream is = new FileInputStream(fn); - OutputStream os = resp.getOutputStream(); - int i; - while ((i = is.read(buf)) > 0) { - os.write(buf, 0, i); + try (InputStream is = new FileInputStream(fn)) { + OutputStream os = resp.getOutputStream(); + int i; + while ((i = is.read(buf)) > 0) { + os.write(buf, 0, i); + } } - is.close(); return; } if (path.startsWith("/internal/rtt/")) { @@ -161,7 +172,6 @@ public class NodeServlet extends HttpServlet { } logger.info("NODE0103 Rejecting invalid GET of " + path + " from " + ip); resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return; } /** @@ -169,7 +179,8 @@ public class NodeServlet extends HttpServlet { */ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { NodeUtils.setIpAndFqdnForEelf("doPut"); - eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"), getIdFromPath(req) + ""); + eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"), + getIdFromPath(req) + ""); common(req, resp, true); } @@ -178,30 +189,36 @@ public class NodeServlet extends HttpServlet { */ protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { NodeUtils.setIpAndFqdnForEelf("doDelete"); - eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"), getIdFromPath(req) + ""); + eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"), + getIdFromPath(req) + ""); common(req, resp, false); } - private void common(HttpServletRequest req, HttpServletResponse resp, boolean isput) throws ServletException, IOException { + private void common(HttpServletRequest req, HttpServletResponse resp, boolean isput) + throws ServletException, IOException { if (down(resp)) { return; } if (!req.isSecure()) { - logger.info("NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); + logger.info( + "NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "https required on publish requests"); return; } String fileid = req.getPathInfo(); if (fileid == null) { - logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); - resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting /."); + logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req + .getRemoteAddr()); + resp.sendError(HttpServletResponse.SC_NOT_FOUND, + "Invalid request URI. Expecting /."); return; } String feedid = null; String user = null; String credentials = req.getHeader("Authorization"); if (credentials == null) { - logger.info("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); + logger.info("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req + .getRemoteAddr()); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization header required"); return; } @@ -215,8 +232,10 @@ public class NodeServlet extends HttpServlet { fileid = fileid.substring(9); int i = fileid.indexOf('/'); if (i == -1 || i == fileid.length() - 1) { - logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); - resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting /. Possible missing fileid."); + logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req + .getRemoteAddr()); + resp.sendError(HttpServletResponse.SC_NOT_FOUND, + "Invalid request URI. Expecting /. Possible missing fileid."); return; } feedid = fileid.substring(0, i); @@ -234,13 +253,17 @@ public class NodeServlet extends HttpServlet { pubid = req.getHeader("X-ATT-DR-PUBLISH-ID"); targets = config.parseRouting(req.getHeader("X-ATT-DR-ROUTING")); } else { - logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); - resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting /."); + logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req + .getRemoteAddr()); + resp.sendError(HttpServletResponse.SC_NOT_FOUND, + "Invalid request URI. Expecting /."); return; } if (fileid.indexOf('/') != -1) { - logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr()); - resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting /."); + logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req + .getRemoteAddr()); + resp.sendError(HttpServletResponse.SC_NOT_FOUND, + "Invalid request URI. Expecting /."); return; } String qs = req.getQueryString(); @@ -257,7 +280,9 @@ public class NodeServlet extends HttpServlet { logurl = "https://" + hp + "/publish/" + feedid + "/" + fileid; String reason = config.isPublishPermitted(feedid, credentials, ip); if (reason != null) { - logger.info("NODE0111 Rejecting unauthorized publish attempt to feed " + feedid + " fileid " + fileid + " from " + ip + " reason " + reason); + logger.info( + "NODE0111 Rejecting unauthorized publish attempt to feed " + feedid + " fileid " + fileid + " from " + + ip + " reason " + reason); resp.sendError(HttpServletResponse.SC_FORBIDDEN, reason); return; } @@ -270,7 +295,9 @@ public class NodeServlet extends HttpServlet { port = ":" + iport; } String redirto = "https://" + newnode + port + "/publish/" + feedid + "/" + fileid; - logger.info("NODE0108 Redirecting publish attempt for feed " + feedid + " user " + user + " ip " + ip + " to " + redirto); + logger.info( + "NODE0108 Redirecting publish attempt for feed " + feedid + " user " + user + " ip " + ip + " to " + + redirto); resp.sendRedirect(redirto); return; } @@ -291,12 +318,12 @@ public class NodeServlet extends HttpServlet { String hn = (String) hnames.nextElement(); String hnlc = hn.toLowerCase(); if ((isput && ("content-type".equals(hnlc) || - "content-language".equals(hnlc) || - "content-md5".equals(hnlc) || - "content-range".equals(hnlc))) || - "x-att-dr-meta".equals(hnlc) || - (feedid == null && "x-att-dr-received".equals(hnlc)) || - (hnlc.startsWith("x-") && !hnlc.startsWith("x-att-dr-"))) { + "content-language".equals(hnlc) || + "content-md5".equals(hnlc) || + "content-range".equals(hnlc))) || + "x-att-dr-meta".equals(hnlc) || + (feedid == null && "x-att-dr-received".equals(hnlc)) || + (hnlc.startsWith("x-") && !hnlc.startsWith("x-att-dr-"))) { Enumeration hvals = req.getHeaders(hn); while (hvals.hasMoreElements()) { String hv = (String) hvals.nextElement(); @@ -305,12 +332,16 @@ public class NodeServlet extends HttpServlet { } if ("x-att-dr-meta".equals(hnlc)) { if (hv.length() > 4096) { - logger.info("NODE0109 Rejecting publish attempt with metadata too long for feed " + feedid + " user " + user + " ip " + ip); + logger.info( + "NODE0109 Rejecting publish attempt with metadata too long for feed " + feedid + + " user " + user + " ip " + ip); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Metadata too long"); return; } if (!MetaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) { - logger.info("NODE0109 Rejecting publish attempt with malformed metadata for feed " + feedid + " user " + user + " ip " + ip); + logger.info( + "NODE0109 Rejecting publish attempt with malformed metadata for feed " + feedid + + " user " + user + " ip " + ip); resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed metadata"); return; } @@ -339,7 +370,8 @@ public class NodeServlet extends HttpServlet { exlen = Long.parseLong(req.getHeader("Content-Length")); } catch (Exception e) { } - StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, ioe.getMessage()); + StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, + ioe.getMessage()); throw ioe; } Path dpath = Paths.get(fbase); @@ -361,9 +393,12 @@ public class NodeServlet extends HttpServlet { } resp.setStatus(HttpServletResponse.SC_NO_CONTENT); resp.getOutputStream().close(); - StatusLog.logPub(pubid, feedid, logurl, req.getMethod(), ctype, data.length(), ip, user, HttpServletResponse.SC_NO_CONTENT); + StatusLog.logPub(pubid, feedid, logurl, req.getMethod(), ctype, data.length(), ip, user, + HttpServletResponse.SC_NO_CONTENT); } catch (IOException ioe) { - logger.info("NODE0110 IO Exception receiving publish attempt for feed " + feedid + " user " + user + " ip " + ip + " " + ioe.toString(), ioe); + logger.info( + "NODE0110 IO Exception receiving publish attempt for feed " + feedid + " user " + user + " ip " + ip + + " " + ioe.toString(), ioe); throw ioe; } finally { if (is != null) { @@ -397,8 +432,9 @@ public class NodeServlet extends HttpServlet { private 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) { diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java index 230afd4c..375a38e3 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java @@ -198,7 +198,7 @@ public class NodeUtils { if (i == -1) { return (null); } - return (new String[]{uriandparams.substring(i + 1, end - 1), uriandparams.substring(end + 1)}); + return (new String[]{uriandparams.substring(i + 1, end), uriandparams.substring(end + 1)}); } /** diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java index a557e7ad..7e4078f8 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java @@ -24,13 +24,18 @@ package org.onap.dmaap.datarouter.node; -import java.util.*; -import java.io.*; +import java.io.BufferedReader; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.OutputStream; +import java.util.Hashtable; +import java.util.Timer; /** * Track redirections of subscriptions */ public class RedirManager { + private Hashtable sid2primary = new Hashtable(); private Hashtable sid2secondary = new Hashtable(); private String redirfile; @@ -39,9 +44,10 @@ public class RedirManager { /** * Create a mechanism for maintaining subscription redirections. * - * @param redirfile The file to store the redirection information. - * @param mininterval The minimum number of milliseconds between writes to the redirection information file. - * @param timer The timer thread used to run delayed file writes. + * @param redirfile The file to store the redirection information. + * @param mininterval The minimum number of milliseconds between writes to the redirection + * information file. + * @param timer The timer thread used to run delayed file writes. */ public RedirManager(String redirfile, long mininterval, Timer timer) { this.redirfile = redirfile; @@ -50,38 +56,40 @@ public class RedirManager { try { StringBuffer sb = new StringBuffer(); for (String s : sid2primary.keySet()) { - sb.append(s).append(' ').append(sid2primary.get(s)).append(' ').append(sid2secondary.get(s)).append('\n'); + sb.append(s).append(' ').append(sid2primary.get(s)).append(' ') + .append(sid2secondary.get(s)).append('\n'); + } + try (OutputStream os = new FileOutputStream(RedirManager.this.redirfile)) { + os.write(sb.toString().getBytes()); } - OutputStream os = new FileOutputStream(RedirManager.this.redirfile); - os.write(sb.toString().getBytes()); - os.close(); } catch (Exception e) { } } }; try { String s; - BufferedReader br = new BufferedReader(new FileReader(redirfile)); - while ((s = br.readLine()) != null) { - s = s.trim(); - String[] sx = s.split(" "); - if (s.startsWith("#") || sx.length != 3) { - continue; + try (BufferedReader br = new BufferedReader(new FileReader(redirfile))) { + while ((s = br.readLine()) != null) { + s = s.trim(); + String[] sx = s.split(" "); + if (s.startsWith("#") || sx.length != 3) { + continue; + } + sid2primary.put(sx[0], sx[1]); + sid2secondary.put(sx[0], sx[2]); } - sid2primary.put(sx[0], sx[1]); - sid2secondary.put(sx[0], sx[2]); } - br.close(); } catch (Exception e) { // missing file is normal } } /** - * Set up redirection. If a request is to be sent to subscription ID sid, and that is configured to go to URL primary, instead, go to secondary. + * Set up redirection. If a request is to be sent to subscription ID sid, and that is + * configured to go to URL primary, instead, go to secondary. * - * @param sid The subscription ID to be redirected - * @param primary The URL associated with that subscription ID + * @param sid The subscription ID to be redirected + * @param primary The URL associated with that subscription ID * @param secondary The replacement URL to use instead */ public synchronized void redirect(String sid, String primary, String secondary) { @@ -91,9 +99,10 @@ public class RedirManager { } /** - * Cancel redirection. If a request is to be sent to subscription ID sid, send it to its primary URL. + * Cancel redirection. If a request is to be sent to subscription ID sid, send it to its + * primary URL. * - * @param sid The subscription ID to remove from the table. + * @param sid The subscription ID to remove from the table. */ public synchronized void forget(String sid) { sid2primary.remove(sid); @@ -102,10 +111,11 @@ public class RedirManager { } /** - * Look up where to send a subscription. If the primary has changed or there is no redirection, use the primary. Otherwise, redirect to the secondary URL. + * Look up where to send a subscription. If the primary has changed or there is no redirection, + * use the primary. Otherwise, redirect to the secondary URL. * - * @param sid The subscription ID to look up. - * @param primary The configured primary URL. + * @param sid The subscription ID to look up. + * @param primary The configured primary URL. * @return The destination URL to really use. */ public synchronized String lookup(String sid, String primary) { diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java new file mode 100644 index 00000000..97904a5e --- /dev/null +++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java @@ -0,0 +1,131 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ + +package org.onap.dmaap.datarouter.node; +import org.apache.commons.lang3.reflect.FieldUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.junit.Assert.*; +import java.io.File; + + + +import static org.mockito.Mockito.*; + +@RunWith(PowerMockRunner.class) +public class DeliveryQueueTest { + + private DeliveryQueue deliveryQueue; + @Mock + private DestInfo destInfo; + @Mock + DeliveryQueueHelper deliveryQueueHelper; + + private String dirPath = "/tmp/dir001/"; + private String FileName1 = "10000000000004.fileName.M"; + + @Before + public void setUp() { + when(destInfo.getSpool()).thenReturn("tmp"); + deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo); + } + + @Test + public void Given_New_DeliveryQueue_Directory_Is_Created_As_Defined_By_DestInfo() throws Exception { + when(destInfo.getSpool()).thenReturn("tmp"); + File file = new File("tmp"); + assertTrue(file.exists()); + deleteFile("tmp"); + } + + @Test + public void Given_Delivery_Task_Failed_And_Resume_Time_Not_Reached_Return_Null() throws Exception{ + FieldUtils.writeField(deliveryQueue,"failed",true,true); + FieldUtils.writeField(deliveryQueue,"resumetime",System.currentTimeMillis()*2,true); + assertNull(deliveryQueue.peekNext()); + } + + @Test + public void Given_Delivery_Task_Return_Next_Delivery_Task_Id() throws Exception{ + prepareFiles(); + when(destInfo.getSpool()).thenReturn(dirPath); + deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo); + DeliveryTask nt = deliveryQueue.getNext(); + assertEquals("10000000000004.fileName", nt.getPublishId()); + deleteFile(dirPath + FileName1); + deleteFile(dirPath); + } + + @Test + public void Given_Delivery_Task_Cancel_And_FileId_Is_Null_Return_Zero() throws Exception{ + long rc = deliveryQueue.cancelTask("123.node.datarouternew.com"); + assertEquals(0, rc); + } + + private void prepareFiles() throws Exception{ + createFolder(dirPath); + createFile(FileName1, dirPath); + String[] files = new String[2]; + files[0] = dirPath + FileName1; + } + + private void createFolder(String dirName) throws Exception{ + String dirPath = dirName; + + File newDirectory = new File(dirPath); + boolean isCreated = newDirectory.mkdirs(); + if (isCreated) { + System.out.println("1. Successfully created directories, path: " + newDirectory.getCanonicalPath()); + } else if (newDirectory.exists()) { + System.out.printf("1. Directory path already exist, path: " + newDirectory.getCanonicalPath()); + } else { + System.out.println("1. Unable to create directory"); + } + } + + private void createFile( String file, String dir) throws Exception{ + String FileName = file; + String dirPath = dir; + + File newFile = new File(dirPath + File.separator + FileName); + boolean isCreated = newFile.createNewFile(); + if (isCreated) { + System.out.println("\n2. Successfully created new file, path: " + newFile.getCanonicalPath()); + } else { //File may already exist + System.out.println("\n2. Unable to create new file: " + newFile.getCanonicalPath()); + } + } + + private void deleteFile(String fileName) { + File file = new File(fileName); + + if (file.exists()) { + file.delete(); + } + } + +} \ No newline at end of file diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java old mode 100755 new mode 100644 index 6350e640..18108172 --- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java +++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java @@ -28,6 +28,7 @@ import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; import org.powermock.modules.junit4.PowerMockRunner; import java.io.IOException; @@ -35,6 +36,7 @@ import java.io.Reader; import java.io.StringReader; @RunWith(PowerMockRunner.class) +@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData", "org.onap.dmaap.datarouter.node.NodeUtils"}) public class NodeConfigTest { private static NodeConfig nodeConfig; diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java new file mode 100644 index 00000000..7dde043d --- /dev/null +++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java @@ -0,0 +1,61 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.dmaap.datarouter.node; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +import org.powermock.modules.junit4.PowerMockRunner; + +@RunWith(PowerMockRunner.class) +@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeUtils") +public class NodeUtilsTest { + + @Test + public void Given_Uri_With_Params_Then_Get_Feed_And_File_Id_Returns_Correct_Values() { + String uri = "prov.datarouternew.com:8443/feed/12/fileName"; + String[] uriParams = NodeUtils.getFeedAndFileID(uri); + Assert.assertEquals("12", uriParams[0]); + Assert.assertEquals("fileName", uriParams[1]); + } + + @Test + public void Given_Uri_With_Illegal_Params_Then_Get_Feed_And_File_Id_Returns_Null() { + String uri = "prov.datarouternew.com:8443/feed"; + String[] uriParams = NodeUtils.getFeedAndFileID(uri); + Assert.assertNull(uriParams); + } + + @Test + public void Given_String_With_Escape_Fields_Then_Loge_Returns_Special_Chars() { + String s = NodeUtils.loge("\\search|pub|12\n"); + Assert.assertEquals("\\esearch\\ppub\\p12\\n", s); + } + + @Test + public void Given_String_With_Special_Chars_Then_Loge_Returns_String_With_Escape_Fields() { + String s = NodeUtils.unloge("\\esearch\\ppub\\p12\\n"); + Assert.assertEquals("\\search|pub|12\n", s); + } +} diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java new file mode 100644 index 00000000..e60f576c --- /dev/null +++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java @@ -0,0 +1,71 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.dmaap.datarouter.node; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +import org.powermock.modules.junit4.PowerMockRunner; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager") +@PrepareForTest(StatusLog.class) +public class StatusLogTest { + + @Before + public void setUp() { + PowerMockito.mockStatic(NodeConfigManager.class); + NodeConfigManager config = mock(NodeConfigManager.class); + when(config.getEventLogInterval()).thenReturn("5m"); + when(config.getEventLogPrefix()).thenReturn("logFile"); + when(config.getEventLogSuffix()).thenReturn(".log"); + PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config); + PowerMockito.mockStatic(System.class); + PowerMockito.when(System.currentTimeMillis()).thenReturn(1535367126000L); + } + + @Test + public void Given_Time_Interval_Parse_Interval_Returns_Correct_Value() { + long parsedTime = StatusLog.parseInterval("2h24m35s", 1); + Assert.assertEquals(8640000, parsedTime); + } + + @Test + public void Given_Time_Interval_In_Seconds_Parse_Interval_Returns_Correct_Value() { + long parsedTime = StatusLog.parseInterval("56784", 1); + Assert.assertEquals(43200000, parsedTime); + } + + @Test + public void Validate_Get_Cur_Log_File_Returns_Correct_File_Name() { + String logFile = StatusLog.getCurLogFile(); + Assert.assertTrue(logFile.matches("logFile-201808271[0-1]50.log")); + } +} diff --git a/datarouter-prov/pom.xml b/datarouter-prov/pom.xml index b3c28782..a970f715 100755 --- a/datarouter-prov/pom.xml +++ b/datarouter-prov/pom.xml @@ -277,7 +277,7 @@ src/main/resources true - **/proserver.properties + **/provserver.properties diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java index 28c3ec28..4c140490 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NodeClass.java @@ -3,7 +3,7 @@ * * 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 @@ -44,7 +44,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB; */ public abstract class NodeClass extends Syncable { private static Map map; - + private static Logger intLogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); public NodeClass() { // init on first use if (map == null) { @@ -68,11 +68,11 @@ public abstract class NodeClass extends Syncable { nextid = n + 1; } // take | separated list, add domain if needed. - Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + for (String node : nodes) { node = normalizeNodename(node); if (!map.containsKey(node)) { - intlogger.info("..adding " + node + " to NODES with index " + nextid); + intLogger.info("..adding " + node + " to NODES with index " + nextid); map.put(node, nextid); PreparedStatement ps = null; try { @@ -86,13 +86,14 @@ public abstract class NodeClass extends Syncable { ps.close(); db.release(conn); } catch (SQLException e) { - intlogger.warn("PROV0005 doInsert: " + e.getMessage()); - e.printStackTrace(); + intLogger.error("PROV0005 doInsert: " + e.getMessage(),e); } finally { try { - ps.close(); + if(ps!=null){ + ps.close(); + } } catch (SQLException e) { - e.printStackTrace(); + intLogger.error("Error in closing PreparedStatement: " + e.getMessage(),e); } } nextid++; @@ -119,25 +120,28 @@ public abstract class NodeClass extends Syncable { ps.close(); db.release(conn); } catch (SQLException e) { - e.printStackTrace(); + intLogger.error("PROV0005 doInsert: " + e.getMessage(),e); } finally { try { - ps.close(); + if(ps!=null){ + ps.close(); + } + } catch (SQLException e) { - e.printStackTrace(); + intLogger.error("PROV0005 doInsert: " + e.getMessage(),e); } } map = m; } - public static Integer lookupNodeName(final String name) throws IllegalArgumentException { + public static Integer lookupNodeName(final String name) { Integer n = map.get(name); if (n == null) throw new IllegalArgumentException("Invalid node name: " + name); return n; } - public static Collection lookupNodeNames(String patt) throws IllegalArgumentException { + public static Collection lookupNodeNames(String patt) { Collection coll = new TreeSet(); final Set keyset = map.keySet(); for (String s : patt.toLowerCase().split(",")) { @@ -173,7 +177,11 @@ public abstract class NodeClass extends Syncable { String domain = p.getValue(); s += "." + domain; } + return s.toLowerCase(); } - return s.toLowerCase(); + else{ + return s; + } + } } 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 a907a03b..bbcacb53 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 @@ -38,14 +38,12 @@ import java.util.*; */ public class DB { - /** - * The name of the properties file (in CLASSPATH) - */ + private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); + private static String DB_URL; private static String DB_LOGIN; private static String DB_PASSWORD; private static Properties props; - private static Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal"); private static final Queue queue = new LinkedList<>(); public static String HTTPS_PORT; diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java new file mode 100644 index 00000000..1e0c042b --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ + +package org.onap.dmaap.datarouter.provisioning.beans; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor; +import org.powermock.modules.junit4.PowerMockRunner; + + +@RunWith(PowerMockRunner.class) +@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Subscription"}) +public class SubscriptionTest { + + private Subscription subscription; + + @Test + public void validate_Subscription_Created_With_Default_Constructor() { + subscription = new Subscription(); + Assert.assertEquals(subscription.getSubid(), -1); + Assert.assertEquals(subscription.getGroupid(), -1); + Assert.assertEquals(subscription.getSubscriber(), ""); + } + + @Test + public void validate_Getters_And_Setters() { + String url = "1.2.3.4"; + String user = "myUser"; + String password = "myPass"; + String subscriber = "mySubscriber"; + SubDelivery subDelivery = new SubDelivery(url, user, password, false); + SubLinks subLinks = new SubLinks(); + subLinks.setFeed("feed"); + subLinks.setLog("log"); + subLinks.setSelf("self"); + + subscription = new Subscription(); + subscription.setGroupid(2); + subscription.setDelivery(subDelivery); + subscription.setMetadataOnly(false); + subscription.setSubscriber(subscriber); + subscription.setSuspended(false); + subscription.setLinks(subLinks); + + Assert.assertEquals(2, subscription.getGroupid()); + Assert.assertEquals(subDelivery, subscription.getDelivery()); + Assert.assertEquals(subLinks, subscription.getLinks()); + Assert.assertFalse(subscription.isMetadataOnly()); + Assert.assertFalse(subscription.isSuspended()); + } +} \ No newline at end of file diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java new file mode 100755 index 00000000..dc8d4c79 --- /dev/null +++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLITest.java @@ -0,0 +1,215 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ +package org.onap.dmaap.datarouter.provisioning.utils; + +import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.http.HttpEntity; +import org.apache.http.StatusLine; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.impl.client.AbstractHttpClient; +import org.json.JSONArray; +import org.json.JSONObject; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.powermock.modules.junit4.PowerMockRunner; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.doCallRealMethod; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +@RunWith(PowerMockRunner.class) +public class DRRouteCLITest { + + @Mock + private AbstractHttpClient httpClient; + + @Mock + private CloseableHttpResponse httpResponse; + + @Mock + private HttpEntity httpEntity; + + @Mock + private StatusLine statusLine; + + private DRRouteCLI drRouteCLI; + + @Before + public void setUp() throws IllegalAccessException{ + drRouteCLI = mock(DRRouteCLI.class); + doCallRealMethod().when(drRouteCLI).runCommand(anyObject()); + FieldUtils.writeField(drRouteCLI, "server", "prov.datarouternew.com", true); + } + + @Test + public void Given_Add_Egress_Then_RunCommand_Returns_True() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"add", "egress", "1", "node.datarouternew.com"})); + } + + @Test + public void Given_Add_Network_Then_RunCommand_Returns_True() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"add", "network", "prov.datarouternew.com", "node.datarouternew.com", "172.100.0.1"})); + } + + @Test + public void Given_Add_Egress_With_Incorrect_Args_Then_RunCommand_Returns_False() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertFalse(drRouteCLI.runCommand(new String[]{"add", "egress", "1", "user1", "172.100.0.0", "node.datarouternew.com"})); + } + + @Test + public void Given_Error_On_Post_Rest_Call_RunCommand_Returns_False() throws Exception{ + mockErrorResponseFromRestCall(); + Assert.assertFalse(drRouteCLI.runCommand(new String[]{"add", "network", "prov.datarouternew.com", "node.datarouternew.com"})); + } + + @Test + public void Given_Delete_Ingress_Then_RunCommand_Returns_True() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"del", "ingress", "1", "user1", "172.100.0.0"})); + } + + @Test + public void Given_Delete_Egress_Then_RunCommand_Returns_True() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"del", "egress", "1"})); + } + + @Test + public void Given_Delete_Network_Then_RunCommand_Returns_True() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"del", "network", "prov.datarouternew.com", "node.datarouternew.com"})); + } + + @Test + public void Given_Delete_Ingress_With_Incorrect_Args_Then_RunCommand_Returns_False() throws Exception{ + mockHttpClientForRestCall(); + Assert.assertFalse(drRouteCLI.runCommand(new String[]{"del", "ingress", "prov.datarouternew.com", "node.datarouternew.com"})); + } + + @Test + public void Given_Error_On_Delete_Rest_Call_RunCommand_Returns_False() throws Exception{ + mockErrorResponseFromRestCall(); + Assert.assertFalse(drRouteCLI.runCommand(new String[]{"del", "network", "prov.datarouternew.com", "node.datarouternew.com"})); + } + + @Test + public void Given_List_Args_Then_RunCommand_Returns_True() throws Exception{ + mockHttpClientForGetRequest(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"list"})); + } + + @Test + public void Given_Error_On_Get_Rest_Call_RunCommand_Returns_True() throws Exception{ + mockErrorResponseFromRestCall(); + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"list"})); + } + + @Test + public void Given_Width_Arg_Then_RunCommand_Returns_True() { + Assert.assertTrue(drRouteCLI.runCommand(new String[]{"width", "130"})); + } + + @Test + public void Given_Usage_Arg_Then_RunCommand_Returns_False() { + Assert.assertFalse(drRouteCLI.runCommand(new String[]{"usage"})); + } + + private void mockHttpClientForRestCall() throws Exception{ + when(httpResponse.getEntity()).thenReturn(httpEntity); + when(statusLine.getStatusCode()).thenReturn(200); + when(httpResponse.getStatusLine()).thenReturn(statusLine); + when(httpClient.execute(anyObject())).thenReturn(httpResponse); + FieldUtils.writeField(drRouteCLI, "httpclient", httpClient, true); + } + + private void mockHttpClientForGetRequest() throws Exception{ + mockResponseFromGet(); + when(httpResponse.getEntity()).thenReturn(httpEntity); + when(statusLine.getStatusCode()).thenReturn(200); + when(httpResponse.getStatusLine()).thenReturn(statusLine); + when(httpClient.execute(anyObject())).thenReturn(httpResponse); + FieldUtils.writeField(drRouteCLI, "httpclient", httpClient, true); + } + + private void mockResponseFromGet() throws IOException { + JSONObject response = new JSONObject(); + response.put("ingress", addIngressObject()); + response.put("egress", addEgressObject()); + response.put("routing", addRoutingObject()); + InputStream in = new ByteArrayInputStream(response.toString().getBytes()); + when(httpEntity.getContent()).thenReturn(in); + } + + private JSONArray addRoutingObject() { + JSONArray routing = new JSONArray(); + JSONObject route = new JSONObject(); + route.put("from", "prov.datarouternew.com"); + route.put("to", "node.datarouternew.com"); + route.put("via", "172.100.0.1"); + routing.put(route); + return routing; + } + + private JSONObject addEgressObject() { + JSONObject egress = new JSONObject(); + egress.put("1", "node.datarouternew.com"); + egress.put("2", "172.0.0.1"); + return egress; + } + + private JSONArray addIngressObject() { + JSONArray ingresses = new JSONArray(); + JSONObject ingress = new JSONObject(); + ingress.put("seq", 21); + ingress.put("feedid", 1); + ingress.put("user", "user1"); + ingress.put("subnet", "172.0.0.0"); + JSONArray nodes = new JSONArray(); + nodes.put("node.datarouternew.com"); + nodes.put("172.0.0.1"); + ingress.put("node", nodes); + ingresses.put(ingress); + return ingresses; + } + + private void mockErrorResponseFromRestCall() throws Exception{ + InputStream in = new ByteArrayInputStream("

 Server Not Found 
".getBytes()); + when(httpEntity.getContent()).thenReturn(in); + when(httpResponse.getEntity()).thenReturn(httpEntity); + when(statusLine.getStatusCode()).thenReturn(400); + when(httpResponse.getStatusLine()).thenReturn(statusLine); + when(httpClient.execute(anyObject())).thenReturn(httpResponse); + FieldUtils.writeField(drRouteCLI, "httpclient", httpClient, true); + } +} diff --git a/datarouter-subscriber/pom.xml b/datarouter-subscriber/pom.xml new file mode 100755 index 00000000..52cb25c7 --- /dev/null +++ b/datarouter-subscriber/pom.xml @@ -0,0 +1,393 @@ + + + 4.0.0 + + org.onap.dmaap.datarouter + parent + 1.0.1-SNAPSHOT + ../pom.xml + + datarouter-subscriber + jar + datarouter-subscriber + + java + false + true + /content/sites/site/${project.groupId}/${project.artifactId}/${project.version} + + ${basedir}/target/${artifactId} + onap/dmaap/datarouter-subscriber + + + + org.eclipse.jetty + jetty-server + ${jetty.version} + + + org.eclipse.jetty + jetty-continuation + ${jetty.version} + + + org.eclipse.jetty + jetty-util + ${jetty.version} + + + org.eclipse.jetty + jetty-deploy + ${jetty.version} + + + org.eclipse.jetty + jetty-servlet + ${jetty.version} + + + org.eclipse.jetty + jetty-servlets + ${jetty.version} + + + org.eclipse.jetty + jetty-http + ${jetty.version} + + + org.eclipse.jetty + jetty-security + ${jetty.version} + + + org.eclipse.jetty + jetty-websocket + ${jetty.websocket.version} + + + org.eclipse.jetty + jetty-io + ${jetty.version} + + + org.apache.httpcomponents + httpclient + 4.5.3 + + + org.sonatype.http-testing-harness + junit-runner + 0.11 + + + org.databene + contiperf + + + + + junit + junit + 4.10 + test + + + log4j + log4j + 1.2.17 + compile + + + + + docker + + false + false + true + + + + + com.spotify + docker-maven-plugin + 1.0.0 + + ${onap.nexus.dockerregistry.daily}/${datarouter.prov.image.name} + ${docker.location} + ${onap.nexus.dockerregistry.daily} + false + + ${project.version} + latest + + true + + + / + ${project.basedir} + + target/**/* + pom.xml + + + + + / + ${project.build.directory} + **/** + + + + + + + + + + datarouter-subscriber + + + src/main/resources + true + + **/*.properties + + + + src/main/resources + true + + **/subscriber.properties + + + + src/main/resources + true + + **/log4j.properties + + + + src/test/resources + true + + **/log4j.properties + + + + + + maven-assembly-plugin + 2.4 + + + jar-with-dependencies + + ${basedir}/target/opt/app/subscriber/lib + + + true + org.onap.dmaap.datarouter.subscriber.Subscriber + + + + + + make-assembly + + package + + + single + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + 3.6.0 + + + maven-resources-plugin + 2.7 + + + copy-docker-file + package + + copy-resources + + + ${docker.location} + true + + + ${basedir}/src/main/resources/docker + true + + **/* + + + + + + + copy-resources-1 + validate + + copy-resources + + + ${basedir}/target/opt/app/subscriber/lib + + + ${project.basedir}/src/main/resources + + **/*.jar + + + + + + + copy-resources-2 + validate + + copy-resources + + + ${basedir}/target/opt/app/subscriber/etc + + + ${basedir}/src/main/resources + + *.properties + + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/opt/app/subscriber/lib + false + false + true + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + + + **/gen/** + **/generated-sources/** + **/yang-gen/** + **/pax/** + + + + + pre-unit-test + + prepare-agent + + + ${project.build.directory}/code-coverage/jacoco-ut.exec + surefireArgLine + + + + post-unit-test + test + + report + + + ${project.build.directory}/code-coverage/jacoco-ut.exec + ${project.reporting.outputDirectory}/jacoco-ut + + + + pre-integration-test + pre-integration-test + + prepare-agent + + + ${project.build.directory}/code-coverage/jacoco-it.exec + failsafeArgLine + + + + post-integration-test + post-integration-test + + report + + + ${project.build.directory}/code-coverage/jacoco-it.exec + ${project.reporting.outputDirectory}/jacoco-it + + + + + + + diff --git a/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/Subscriber.java b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/Subscriber.java new file mode 100644 index 00000000..b6edb670 --- /dev/null +++ b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/Subscriber.java @@ -0,0 +1,120 @@ +/******************************************************************************* + * ============LICENSE_START================================================== + * * org.onap.dmaap + * * =========================================================================== + * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * * =========================================================================== + * * Licensed under the Apache License, Version 2.0 (the "License"); + * * you may not use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. + * * ============LICENSE_END==================================================== + * * + * * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * * + ******************************************************************************/ + +package org.onap.dmaap.datarouter.subscriber; + +import org.apache.log4j.Logger; +import org.eclipse.jetty.servlet.*; +import org.eclipse.jetty.util.ssl.*; +import org.eclipse.jetty.server.*; +import org.eclipse.jetty.http.HttpVersion; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Arrays; +import java.util.Properties; + +public class Subscriber { + + private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.Subscriber"); + + private static final String CONTEXT_PATH = "/"; + private static final String URL_PATTERN = "/*"; + + static Properties props; + + private static void loadProps() { + if (props == null) { + props = new Properties(); + try { + props.load(new FileInputStream(System.getProperty( + "org.onap.dmaap.datarouter.subscriber.properties", + "/opt/app/subscriber/etc/subscriber.properties"))); + } catch (IOException e) { + logger.fatal("SubServlet: Exception opening properties: " + e.getMessage()); + System.exit(1); + } + } + } + + public static void main(String[] args) throws Exception { + //Load the properties + loadProps(); + + int httpsPort = Integer.parseInt(props.getProperty("org.onap.dmaap.datarouter.subscriber.https.port", "8443")); + int httpPort = Integer.parseInt(props.getProperty("org.onap.dmaap.datarouter.subscriber.http.port", "8080")); + + Server server = new Server(); + HttpConfiguration httpConfig = new HttpConfiguration(); + httpConfig.setRequestHeaderSize(8192); + + // HTTP connector + ServletContextHandler ctxt; + try (ServerConnector httpServerConnector = new ServerConnector(server, + new HttpConnectionFactory(httpConfig))) { + httpServerConnector.setPort(httpPort); + httpServerConnector.setIdleTimeout(30000); + + // SSL Context Factory + SslContextFactory sslContextFactory = new SslContextFactory(); + + // SSL HTTP Configuration + HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig); + httpsConfig.addCustomizer(new SecureRequestCustomizer()); + + // SSL Connector + ServerConnector sslConnector = new ServerConnector(server, + new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), + new HttpConnectionFactory(httpsConfig)); + sslConnector.setPort(httpsPort); + server.addConnector(sslConnector); + + /*Skip SSLv3 Fixes*/ + sslContextFactory.addExcludeProtocols("SSLv3"); + logger.info("Excluded protocols for Subscriber:" + Arrays.toString(sslContextFactory.getExcludeProtocols())); + /*End of SSLv3 Fixes*/ + + // HTTPS Configuration + try (ServerConnector https = new ServerConnector(server, + new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), + new HttpConnectionFactory(httpsConfig))) { + https.setPort(httpsPort); + https.setIdleTimeout(30000); + } + server.setConnectors(new Connector[]{ httpServerConnector }); + } + ctxt = new ServletContextHandler(0); + ctxt.setContextPath(CONTEXT_PATH); + server.setHandler(ctxt); + + ctxt.addServlet(new ServletHolder(new SubscriberServlet()), URL_PATTERN); + try { + server.start(); + } catch ( Exception e ) { + logger.info("Jetty failed to start. Reporting will be unavailable-"+e); + } + server.join(); + logger.info("org.onap.dmaap.datarouter.subscriber.Subscriber started-"+ server.getState()); + + } +} \ No newline at end of file diff --git a/Subscriber/src/SubscriberServlet.java b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberServlet.java similarity index 50% rename from Subscriber/src/SubscriberServlet.java rename to datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberServlet.java index 1af62a63..72afcf06 100644 --- a/Subscriber/src/SubscriberServlet.java +++ b/datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberServlet.java @@ -7,9 +7,9 @@ * * 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. @@ -21,67 +21,88 @@ * * ******************************************************************************/ -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URLEncoder; +package org.onap.dmaap.datarouter.subscriber; + +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; import javax.servlet.ServletConfig; -import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.*; +import java.net.URLEncoder; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.nio.file.attribute.PosixFilePermissions; -import org.apache.commons.codec.binary.Base64; -import org.apache.log4j.Logger; +import static org.onap.dmaap.datarouter.subscriber.Subscriber.props; -/** - * Example stand alone subscriber servlet with Authorization header checking - */ -public class SubscriberServlet extends HttpServlet { - private static Logger logger = Logger.getLogger("com.att.datarouter.pubsub.ssasubscribe.SubscriberServlet"); - private String Login = "LOGIN"; - private String Password = "PASSWORD"; - private String OutputDirectory = "/root/sub/received"; +public class SubscriberServlet extends HttpServlet { - private String auth; + private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SubscriberServlet"); + private String outputDirectory; + private String basicAuth; - private static String gp(ServletConfig config, String param, String deflt) { - param = config.getInitParameter(param); - if (param == null || param.length() == 0) { - param = deflt; - } - return(param); - } /** * Configure this subscriberservlet. Configuration parameters from config.getInitParameter() are: *
    *
  • Login - The login expected in the Authorization header (default "LOGIN"). *
  • Password - The password expected in the Authorization header (default "PASSWORD"). - *
  • OutputDirectory - The directory where files are placed (default "received"). + *
  • outputDirectory - The directory where files are placed (default "tmp"). *
*/ - public void init(ServletConfig config) throws ServletException { - Login = gp(config, "Login", Login); - Password = gp(config, "Password", Password); - OutputDirectory = gp(config, "OutputDirectory", OutputDirectory); - (new File(OutputDirectory)).mkdirs(); - auth = "Basic " + Base64.encodeBase64String((Login + ":" + Password).getBytes()); + @Override + public void init(ServletConfig config) { + String login = props.getProperty("org.onap.dmaap.datarouter.subscriber.auth.user", "LOGIN"); + String password = props.getProperty("org.onap.dmaap.datarouter.subscriber.auth.password", "PASSWORD"); + outputDirectory = props.getProperty("org.onap.dmaap.datarouter.subscriber.delivery.dir", "/tmp"); + try { + Files.createDirectory(Paths.get(outputDirectory), PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx"))); + } catch (IOException e) { + logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage()); + e.printStackTrace(); + } + basicAuth = "Basic " + Base64.encodeBase64String((login + ":" + password).getBytes()); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { + File filesPath = new File(outputDirectory); + File[] filesArr = filesPath.listFiles(); + assert filesArr != null; + for (File file: filesArr) { + try (BufferedReader in = new BufferedReader(new FileReader(file))) { + String line = in.readLine(); + while (line != null) { + line = in.readLine(); + } + } + } } /** * Invoke common(req, resp, false). */ - protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - common(req, resp, false); - } + @Override + protected void doPut(HttpServletRequest req, HttpServletResponse resp) { + try { + common(req, resp, false); + } catch (IOException e) { + logger.info("SubServlet: Failed to doPut: " + req.getRemoteAddr() + " : " + req.getPathInfo(), e); + } + } /** * Invoke common(req, resp, true). */ - protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - common(req, resp, true); - } + @Override + protected void doDelete(HttpServletRequest req, HttpServletResponse resp) { + try { + common(req, resp, true); + } catch (IOException e) { + logger.info("SubServlet: Failed to doDelete: " + req.getRemoteAddr() + " : " + req.getPathInfo(), e); + } + } /** * Process a PUT or DELETE request. *
    @@ -90,59 +111,57 @@ public class SubscriberServlet extends HttpServlet { *
  1. Verify that the Authorization header matches the configured * Login and Password or else FORBIDDEN. *
  2. If the request is PUT, store the message body as a file - * in the configured OutputDirectory directory protecting against + * in the configured outputDirectory directory protecting against * evil characters in the received FileID. The file is created * initially with its name prefixed with a ".", and once it is complete, it is * renamed to remove the leading "." character. - *
  3. If the request is DELETE, instead delete the file (if it exists) from the configured OutputDirectory directory. + *
  4. If the request is DELETE, instead delete the file (if it exists) from the configured outputDirectory directory. *
  5. Respond with NO_CONTENT. *
*/ - protected void common(HttpServletRequest req, HttpServletResponse resp, boolean isdelete) throws ServletException, IOException { - String ah = req.getHeader("Authorization"); - if (ah == null) { + private void common(HttpServletRequest req, HttpServletResponse resp, boolean isdelete) throws IOException { + String authHeader = req.getHeader("Authorization"); + if (authHeader == null) { logger.info("Rejecting request with no Authorization header from " + req.getRemoteAddr() + ": " + req.getPathInfo()); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } - if (!auth.equals(ah)) { + if (!basicAuth.equals(authHeader)) { logger.info("Rejecting request with incorrect Authorization header from " + req.getRemoteAddr() + ": " + req.getPathInfo()); resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } String fileid = req.getPathInfo(); fileid = fileid.substring(fileid.lastIndexOf('/') + 1); - String qs = req.getQueryString(); - if (qs != null) { - fileid = fileid + "?" + qs; + String queryString = req.getQueryString(); + if (queryString != null) { + fileid = fileid + "?" + queryString; } String publishid = req.getHeader("X-ATT-DR-PUBLISH-ID"); String filename = URLEncoder.encode(fileid, "UTF-8").replaceAll("^\\.", "%2E").replaceAll("\\*", "%2A"); - String finalname = OutputDirectory + "/" + filename; - String tmpname = OutputDirectory + "/." + filename; + String fullPath = outputDirectory + "/" + filename; + String tmpPath = outputDirectory + "/." + filename; try { if (isdelete) { - (new File(finalname)).delete(); - logger.info("Received delete for file id " + fileid + " from " + req.getRemoteAddr() + " publish id " + publishid + " as " + finalname); + Files.deleteIfExists(Paths.get(fullPath)); + logger.info("Received delete for file id " + fileid + " from " + req.getRemoteAddr() + " publish id " + publishid + " as " + fullPath); } else { - InputStream is = req.getInputStream(); - OutputStream os = new FileOutputStream(tmpname); - byte[] buf = new byte[65536]; - int i; - while ((i = is.read(buf)) > 0) { - os.write(buf, 0, i); - } - is.close(); - os.close(); - (new File(tmpname)).renameTo(new File(finalname)); - logger.info("Received file id " + fileid + " from " + req.getRemoteAddr() + " publish id " + publishid + " as " + finalname); + new File(tmpPath).createNewFile(); + try (InputStream is = req.getInputStream(); OutputStream os = new FileOutputStream(tmpPath)) { + byte[] buf = new byte[65536]; + int i; + while ((i = is.read(buf)) > 0) { + os.write(buf, 0, i); + } + } + Files.move(Paths.get(tmpPath), Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING); + logger.info("Received file id " + fileid + " from " + req.getRemoteAddr() + " publish id " + publishid + " as " + fullPath); resp.setStatus(HttpServletResponse.SC_NO_CONTENT); - logger.info("Received file id " + fileid + " from " + req.getRemoteAddr() + " publish id " + publishid + " as " + finalname); } resp.setStatus(HttpServletResponse.SC_NO_CONTENT); } catch (IOException ioe) { - (new File(tmpname)).delete(); - logger.info("Failure to save file " + finalname + " from " + req.getRemoteAddr() + ": " + req.getPathInfo(), ioe); + Files.deleteIfExists(Paths.get(tmpPath)); + logger.info("Failed to process file " + fullPath + " from " + req.getRemoteAddr() + ": " + req.getPathInfo()); throw ioe; } } diff --git a/datarouter-subscriber/src/main/resources/docker/Dockerfile b/datarouter-subscriber/src/main/resources/docker/Dockerfile new file mode 100644 index 00000000..6cc74cc3 --- /dev/null +++ b/datarouter-subscriber/src/main/resources/docker/Dockerfile @@ -0,0 +1,6 @@ +FROM java:8 +ADD opt /opt/ +ADD startup.sh /startup.sh +RUN chmod 700 /startup.sh +ENTRYPOINT ./startup.sh start +EXPOSE 7070 \ No newline at end of file diff --git a/datarouter-subscriber/src/main/resources/docker/startup.sh b/datarouter-subscriber/src/main/resources/docker/startup.sh new file mode 100644 index 00000000..53b1053d --- /dev/null +++ b/datarouter-subscriber/src/main/resources/docker/startup.sh @@ -0,0 +1,12 @@ +#!/bin/bash +LIB=/opt/app/subscriber/lib +ETC=/opt/app/subscriber/etc +CLASSPATH=$ETC +for FILE in `find $LIB -name *.jar`; do + CLASSPATH=$CLASSPATH:$FILE +done +java -classpath $CLASSPATH org.onap.dmaap.datarouter.subscriber.Subscriber + +runner_file="$LIB/subscriber-jar-with-dependencies.jar" +echo "Starting using" $runner_file +java -Dorg.onap.dmaap.datarouter.subscriber.properties=/opt/app/subscriber/etc/subscriber.properties -jar $runner_file \ No newline at end of file diff --git a/datarouter-subscriber/src/main/resources/log4j.properties b/datarouter-subscriber/src/main/resources/log4j.properties new file mode 100644 index 00000000..bb66ef42 --- /dev/null +++ b/datarouter-subscriber/src/main/resources/log4j.properties @@ -0,0 +1,31 @@ +#------------------------------------------------------------------------------- +# ============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. +# * +#------------------------------------------------------------------------------- + +log4j.rootLogger=info,Root + +log4j.appender.Root=org.apache.log4j.DailyRollingFileAppender +log4j.appender.Root.file=/opt/app/subscriber/logs/subscriber.log +log4j.appender.Root.datePattern='.'yyyyMMdd +log4j.appender.Root.append=true +log4j.appender.Root.layout=org.apache.log4j.PatternLayout +log4j.appender.Root.layout.ConversionPattern=%d %p %t %m%n diff --git a/datarouter-subscriber/src/main/resources/subscriber.properties b/datarouter-subscriber/src/main/resources/subscriber.properties new file mode 100644 index 00000000..771fdd34 --- /dev/null +++ b/datarouter-subscriber/src/main/resources/subscriber.properties @@ -0,0 +1,40 @@ +#------------------------------------------------------------------------------- +# ============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. +# * +#------------------------------------------------------------------------------- + +#Subscriber properties +org.onap.dmaap.datarouter.subscriber.http.port = 7070 +org.onap.dmaap.datarouter.subscriber.https.port = 7443 +org.onap.dmaap.datarouter.subscriber.auth.user = LOGIN +org.onap.dmaap.datarouter.subscriber.auth.password = PASSWORD +org.onap.dmaap.datarouter.subscriber.delivery.dir = /opt/app/subscriber/delivery + +org.onap.dmaap.datarouter.subscriber.https.relaxation = true +org.onap.dmaap.datarouter.subscriber.keystore.type = jks +org.onap.dmaap.datarouter.subscriber.keymanager.password = changeit +org.onap.dmaap.datarouter.subscriber.keystore.path = /opt/app/datartr/self_signed/keystore.jks +org.onap.dmaap.datarouter.subscriber.keystore.password = changeit +org.onap.dmaap.datarouter.subscriber.truststore.path = /opt/app/datartr/self_signed/cacerts.jks +org.onap.dmaap.datarouter.subscriber.truststore.password = changeit + + + diff --git a/datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql b/docker-compose/database/sql_init_01.sql similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/database/sql_init_01.sql rename to docker-compose/database/sql_init_01.sql diff --git a/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml similarity index 89% rename from datarouter-prov/src/main/resources/docker-compose/docker-compose.yml rename to docker-compose/docker-compose.yml index 6aee4dbd..f8a4d843 100644 --- a/datarouter-prov/src/main/resources/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -1,96 +1,108 @@ -#------------------------------------------------------------------------------- -# ============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. -# * -#------------------------------------------------------------------------------- -version: '2.1' -services: - datarouter-prov: - image: nexus3.onap.org:10003/onap/dmaap/datarouter-prov - container_name: datarouter-prov - hostname: prov.datarouternew.com - ports: - - "8443:8443" - - "8080:8080" - volumes: - - ./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 - depends_on: - mariadb_container: - condition: service_healthy - healthcheck: - test: ["CMD", "curl", "-f", "http://prov.datarouternew.com:8080/internal/prov"] - interval: 10s - timeout: 10s - retries: 5 - extra_hosts: - - "node.datarouternew.com:172.100.0.4" - networks: - testing_net: - ipv4_address: 172.100.0.3 - - datarouter-node: - image: nexus3.onap.org:10003/onap/dmaap/datarouter-node - container_name: datarouter-node - hostname: node.datarouternew.com - ports: - - "9443:8443" - - "9090:8080" - volumes: - - ./node_data/node.properties:/opt/app/datartr/etc/node.properties - depends_on: - datarouter-prov: - condition: service_healthy - extra_hosts: - - "prov.datarouternew.com:172.100.0.3" - networks: - testing_net: - ipv4_address: 172.100.0.4 - - mariadb_container: - image: mariadb:10.2.14 - 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", "--silent"] - interval: 10s - timeout: 30s - retries: 5 - - networks: - testing_net: - ipv4_address: 172.100.0.2 - -networks: - testing_net: - driver: bridge - ipam: - driver: default - config: - - subnet: 172.100.0.0/16 +#------------------------------------------------------------------------------- +# ============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. +# * +#------------------------------------------------------------------------------- +version: '2.1' +services: + datarouter-prov: + image: nexus3.onap.org:10003/onap/dmaap/datarouter-prov + container_name: datarouter-prov + hostname: prov.datarouternew.com + ports: + - "8443:8443" + - "8080:8080" + volumes: + - ./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 + depends_on: + mariadb_container: + condition: service_healthy + healthcheck: + test: ["CMD", "curl", "-f", "http://prov.datarouternew.com:8080/internal/prov"] + interval: 10s + timeout: 10s + retries: 5 + extra_hosts: + - "node.datarouternew.com:172.100.0.4" + networks: + testing_net: + ipv4_address: 172.100.0.3 + + datarouter-node: + image: nexus3.onap.org:10003/onap/dmaap/datarouter-node + container_name: datarouter-node + hostname: node.datarouternew.com + ports: + - "9443:8443" + - "9090:8080" + volumes: + - ./node_data/node.properties:/opt/app/datartr/etc/node.properties + depends_on: + datarouter-prov: + condition: service_healthy + extra_hosts: + - "prov.datarouternew.com:172.100.0.3" + networks: + testing_net: + ipv4_address: 172.100.0.4 + + datarouter-subscriber: + image: nexus3.onap.org:10003/onap/dmaap/datarouter-subscriber + container_name: subscriber-node + hostname: subscriber.com + ports: + - "7070:7070" + volumes: + - ./subscriber_data/subscriber.properties:/opt/app/subscriber/etc/subscriber.properties + networks: + testing_net: + ipv4_address: 172.100.0.5 + + mariadb_container: + image: mariadb:10.2.14 + 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", "--silent"] + interval: 10s + timeout: 30s + retries: 5 + + networks: + testing_net: + ipv4_address: 172.100.0.2 + +networks: + testing_net: + driver: bridge + ipam: + driver: default + config: + - subnet: 172.100.0.0/16 diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/node.properties b/docker-compose/node_data/node.properties similarity index 94% rename from datarouter-prov/src/main/resources/docker-compose/node_data/node.properties rename to docker-compose/node_data/node.properties index 48485023..20c5af12 100644 --- a/datarouter-prov/src/main/resources/docker-compose/node_data/node.properties +++ b/docker-compose/node_data/node.properties @@ -1,112 +1,112 @@ -#------------------------------------------------------------------------------- -# ============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. -# * -#------------------------------------------------------------------------------- -# -# Configuration parameters fixed at startup for the DataRouter node -# -# URL to retrieve dynamic configuration -# -#ProvisioningURL: ${DRTR_PROV_INTURL:-https://feeds-drtr.web.att.com/internal/prov} -ProvisioningURL=https://prov.datarouternew.com:8443/internal/prov - -# -# URL to upload PUB/DEL/EXP logs -# -#LogUploadURL: ${DRTR_LOG_URL:-https://feeds-drtr.web.att.com/internal/logs} -LogUploadURL=https://prov.datarouternew.com:8443/internal/logs - -# -# The port number for http as seen within the server -# -#IntHttpPort: ${DRTR_NODE_INTHTTPPORT:-8080} -IntHttpPort=8080 -# -# The port number for https as seen within the server -# -IntHttpsPort=8443 -# -# The external port number for https taking port mapping into account -# -ExtHttpsPort=443 -# -# The minimum interval between fetches of the dynamic configuration -# from the provisioning server -# -MinProvFetchInterval=10000 -# -# The minimum interval between saves of the redirection data file -# -MinRedirSaveInterval=10000 -# -# The path to the directory where log files are stored -# -LogDir=/opt/app/datartr/logs -# -# The retention interval (in days) for log files -# -LogRetention=30 -# -# The path to the directories where data and meta data files are stored -# -SpoolDir=/opt/app/datartr/spool -# -# The path to the redirection data file -# -#RedirectionFile: etc/redirections.dat -# -# The type of keystore for https -# -KeyStoreType: jks -# -# The path to the keystore for https -# -KeyStoreFile:/opt/app/datartr/self_signed/keystore.jks -# -# The password for the https keystore -# -KeyStorePassword=changeit -# -# The password for the private key in the https keystore -# -KeyPassword=changeit -# -# The type of truststore for https -# -TrustStoreType=jks -# -# The path to the truststore for https -# -#TrustStoreFile=/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts -TrustStoreFile=/opt/app/datartr/self_signed/cacerts.jks -# -# The password for the https truststore -# -TrustStorePassword=changeit -# -# The path to the file used to trigger an orderly shutdown -# -QuiesceFile=etc/SHUTDOWN -# -# The key used to generate passwords for node to node transfers -# -NodeAuthKey=Node123! - +#------------------------------------------------------------------------------- +# ============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. +# * +#------------------------------------------------------------------------------- +# +# Configuration parameters fixed at startup for the DataRouter node +# +# URL to retrieve dynamic configuration +# +#ProvisioningURL: ${DRTR_PROV_INTURL:-https://feeds-drtr.web.att.com/internal/prov} +ProvisioningURL=https://prov.datarouternew.com:8443/internal/prov + +# +# URL to upload PUB/DEL/EXP logs +# +#LogUploadURL: ${DRTR_LOG_URL:-https://feeds-drtr.web.att.com/internal/logs} +LogUploadURL=https://prov.datarouternew.com:8443/internal/logs + +# +# The port number for http as seen within the server +# +#IntHttpPort: ${DRTR_NODE_INTHTTPPORT:-8080} +IntHttpPort=8080 +# +# The port number for https as seen within the server +# +IntHttpsPort=8443 +# +# The external port number for https taking port mapping into account +# +ExtHttpsPort=443 +# +# The minimum interval between fetches of the dynamic configuration +# from the provisioning server +# +MinProvFetchInterval=10000 +# +# The minimum interval between saves of the redirection data file +# +MinRedirSaveInterval=10000 +# +# The path to the directory where log files are stored +# +LogDir=/opt/app/datartr/logs +# +# The retention interval (in days) for log files +# +LogRetention=30 +# +# The path to the directories where data and meta data files are stored +# +SpoolDir=/opt/app/datartr/spool +# +# The path to the redirection data file +# +#RedirectionFile: etc/redirections.dat +# +# The type of keystore for https +# +KeyStoreType: jks +# +# The path to the keystore for https +# +KeyStoreFile:/opt/app/datartr/self_signed/keystore.jks +# +# The password for the https keystore +# +KeyStorePassword=changeit +# +# The password for the private key in the https keystore +# +KeyPassword=changeit +# +# The type of truststore for https +# +TrustStoreType=jks +# +# The path to the truststore for https +# +#TrustStoreFile=/usr/lib/jvm/java-8-oracle/jre/lib/security/cacerts +TrustStoreFile=/opt/app/datartr/self_signed/cacerts.jks +# +# The password for the https truststore +# +TrustStorePassword=changeit +# +# The path to the file used to trigger an orderly shutdown +# +QuiesceFile=etc/SHUTDOWN +# +# The key used to generate passwords for node to node transfers +# +NodeAuthKey=Node123! + diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/cacerts.jks b/docker-compose/node_data/self_signed/cacerts.jks similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/cacerts.jks rename to docker-compose/node_data/self_signed/cacerts.jks diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/keystore.jks b/docker-compose/node_data/self_signed/keystore.jks similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/keystore.jks rename to docker-compose/node_data/self_signed/keystore.jks diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/mykey.cer b/docker-compose/node_data/self_signed/mykey.cer similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/mykey.cer rename to docker-compose/node_data/self_signed/mykey.cer diff --git a/datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/nodekey.cer b/docker-compose/node_data/self_signed/nodekey.cer similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/node_data/self_signed/nodekey.cer rename to docker-compose/node_data/self_signed/nodekey.cer diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/addFeed3.txt b/docker-compose/prov_data/addFeed3.txt similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/prov_data/addFeed3.txt rename to docker-compose/prov_data/addFeed3.txt diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/addSubscriber.txt b/docker-compose/prov_data/addSubscriber.txt similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/prov_data/addSubscriber.txt rename to docker-compose/prov_data/addSubscriber.txt diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties b/docker-compose/prov_data/provserver.properties similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/prov_data/provserver.properties rename to docker-compose/prov_data/provserver.properties diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/cacerts.jks b/docker-compose/prov_data/self_signed/cacerts.jks similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/cacerts.jks rename to docker-compose/prov_data/self_signed/cacerts.jks diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/keystore.jks b/docker-compose/prov_data/self_signed/keystore.jks similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/keystore.jks rename to docker-compose/prov_data/self_signed/keystore.jks diff --git a/datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/mykey.cer b/docker-compose/prov_data/self_signed/mykey.cer similarity index 100% rename from datarouter-prov/src/main/resources/docker-compose/prov_data/self_signed/mykey.cer rename to docker-compose/prov_data/self_signed/mykey.cer diff --git a/docker-compose/subscriber_data/subscriber.properties b/docker-compose/subscriber_data/subscriber.properties new file mode 100644 index 00000000..771fdd34 --- /dev/null +++ b/docker-compose/subscriber_data/subscriber.properties @@ -0,0 +1,40 @@ +#------------------------------------------------------------------------------- +# ============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. +# * +#------------------------------------------------------------------------------- + +#Subscriber properties +org.onap.dmaap.datarouter.subscriber.http.port = 7070 +org.onap.dmaap.datarouter.subscriber.https.port = 7443 +org.onap.dmaap.datarouter.subscriber.auth.user = LOGIN +org.onap.dmaap.datarouter.subscriber.auth.password = PASSWORD +org.onap.dmaap.datarouter.subscriber.delivery.dir = /opt/app/subscriber/delivery + +org.onap.dmaap.datarouter.subscriber.https.relaxation = true +org.onap.dmaap.datarouter.subscriber.keystore.type = jks +org.onap.dmaap.datarouter.subscriber.keymanager.password = changeit +org.onap.dmaap.datarouter.subscriber.keystore.path = /opt/app/datartr/self_signed/keystore.jks +org.onap.dmaap.datarouter.subscriber.keystore.password = changeit +org.onap.dmaap.datarouter.subscriber.truststore.path = /opt/app/datartr/self_signed/cacerts.jks +org.onap.dmaap.datarouter.subscriber.truststore.password = changeit + + + diff --git a/pom.xml b/pom.xml index d3327ba9..43aeca21 100755 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,7 @@ datarouter-prov datarouter-node + datarouter-subscriber