summaryrefslogtreecommitdiffstats
path: root/datarouter-node
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-node')
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java20
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java2
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java98
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java28
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java2
-rw-r--r--datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EelfMsgs.java6
-rw-r--r--datarouter-node/src/main/resources/EelfMessages.properties148
-rw-r--r--datarouter-node/src/main/resources/logback.xml4
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java43
-rw-r--r--datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java48
10 files changed, 290 insertions, 109 deletions
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 7e10d5a0..4d570b55 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
@@ -28,7 +28,13 @@ import java.io.*;
import java.net.*;
import java.util.*;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import org.apache.log4j.Logger;
+import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
+import org.slf4j.MDC;
+
+import static com.att.eelf.configuration.Configuration.*;
/**
* A file to be delivered to a destination.
@@ -39,6 +45,8 @@ import org.apache.log4j.Logger;
*/
public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
private static Logger loggerDeliveryTask = Logger.getLogger("org.onap.dmaap.datarouter.node.DeliveryTask");
+ private static EELFLogger eelflogger = EELFManager.getInstance()
+ .getLogger(DeliveryTask.class);
private DeliveryTaskHelper dth;
private String pubid;
private DestInfo di;
@@ -55,6 +63,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
private String subid;
private int attempts;
private String[][] hdrs;
+ private String newInvocationId;
/**
@@ -84,6 +93,7 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
String s = br.readLine();
int i = s.indexOf('\t');
method = s.substring(0, i);
+ NodeUtils.setIpAndFqdnForEelf(method);
if (!"DELETE".equals(method) && !monly) {
length = datafile.length();
}
@@ -102,6 +112,14 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
if (h.equalsIgnoreCase("content-type")) {
ctype = v;
}
+ if (h.equalsIgnoreCase("x-onap-requestid")) {
+ MDC.put(MDC_KEY_REQUEST_ID, v);
+ }
+ if (h.equalsIgnoreCase("x-invocationid")) {
+ MDC.put("InvocationId", v);
+ v = UUID.randomUUID().toString();
+ newInvocationId = v;
+ }
hdrv.add(new String[]{h, v});
}
} catch (Exception e) {
@@ -252,6 +270,8 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
public void clean() {
datafile.delete();
metafile.delete();
+ eelflogger.info(EelfMsgs.INVOKE, newInvocationId);
+ eelflogger.info(EelfMsgs.EXIT);
hdrs = null;
}
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
index 17f902e5..50baef5c 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
@@ -50,7 +50,7 @@ import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
public class NodeConfigManager implements DeliveryQueueHelper {
private static EELFLogger eelflogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.node.NodeConfigManager");
+ .getLogger(NodeConfigManager.class);
private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeConfigManager");
private static NodeConfigManager base = new NodeConfigManager();
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 a223b98c..b1ab44fb 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
@@ -46,6 +46,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
+import org.slf4j.MDC;
/**
* Servlet for handling all http and https requests to the data router node
@@ -65,7 +66,7 @@ public class NodeServlet extends HttpServlet {
private static Pattern MetaDataPattern;
//Adding EELF Logger Rally:US664892
private static EELFLogger eelflogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.node.NodeServlet");
+ .getLogger(NodeServlet.class);
static {
final String ws = "\\s*";
@@ -101,37 +102,43 @@ public class NodeServlet extends HttpServlet {
*/
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
NodeUtils.setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"),
- getIdFromPath(req) + "");
+ NodeUtils.setRequestIdAndInvocationId(req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- if (down(resp)) {
- return;
- }
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"),
+ getIdFromPath(req) + "");
+ try {
+ if (down(resp)) {
+ return;
+ }
- } catch (IOException ioe) {
- logger.error("IOException" + ioe.getMessage());
- }
- String path = req.getPathInfo();
- String qs = req.getQueryString();
- String ip = req.getRemoteAddr();
- if (qs != null) {
- path = path + "?" + qs;
- }
- if ("/internal/fetchProv".equals(path)) {
- config.gofetch(ip);
- resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
- return;
- } else if (path.startsWith("/internal/resetSubscription/")) {
- String subid = path.substring(28);
- if (subid.length() != 0 && subid.indexOf('/') == -1) {
- NodeMain.resetQueue(subid, ip);
+ } catch (IOException ioe) {
+ logger.error("IOException" + ioe.getMessage());
+ }
+ String path = req.getPathInfo();
+ String qs = req.getQueryString();
+ String ip = req.getRemoteAddr();
+ if (qs != null) {
+ path = path + "?" + qs;
+ }
+ if ("/internal/fetchProv".equals(path)) {
+ config.gofetch(ip);
resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
return;
+ } else if (path.startsWith("/internal/resetSubscription/")) {
+ String subid = path.substring(28);
+ if (subid.length() != 0 && subid.indexOf('/') == -1) {
+ NodeMain.resetQueue(subid, ip);
+ resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ return;
+ }
}
- }
- logger.info("NODE0103 Rejecting invalid GET of " + path + " from " + ip);
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, logger);
+ logger.info("NODE0103 Rejecting invalid GET of " + path + " from " + ip);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, logger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
@@ -139,14 +146,18 @@ public class NodeServlet extends HttpServlet {
*/
protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
NodeUtils.setIpAndFqdnForEelf("doPut");
+ NodeUtils.setRequestIdAndInvocationId(req);
+ eelflogger.info(EelfMsgs.ENTRY);
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"),
- getIdFromPath(req) + "");
+ getIdFromPath(req) + "");
try {
common(req, resp, true);
} catch (IOException ioe) {
logger.error("IOException" + ioe.getMessage());
+ eelflogger.info(EelfMsgs.EXIT);
} catch (ServletException se) {
logger.error("ServletException" + se.getMessage());
+ eelflogger.info(EelfMsgs.EXIT);
}
}
@@ -155,20 +166,26 @@ public class NodeServlet extends HttpServlet {
*/
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
NodeUtils.setIpAndFqdnForEelf("doDelete");
+ NodeUtils.setRequestIdAndInvocationId(req);
+ eelflogger.info(EelfMsgs.ENTRY);
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-ATT-DR-ON-BEHALF-OF"),
getIdFromPath(req) + "");
try {
common(req, resp, false);
} catch (IOException ioe) {
logger.error("IOException" + ioe.getMessage());
+ eelflogger.info(EelfMsgs.EXIT);
} catch (ServletException se) {
logger.error("ServletException" + se.getMessage());
+ eelflogger.info(EelfMsgs.EXIT);
}
+
}
private void common(HttpServletRequest req, HttpServletResponse resp, boolean isput)
throws ServletException, IOException {
if (down(resp)) {
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
if (!req.isSecure()) {
@@ -176,6 +193,7 @@ public class NodeServlet extends HttpServlet {
"NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + " from " + req
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "https required on publish requests");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
String fileid = req.getPathInfo();
@@ -184,6 +202,7 @@ public class NodeServlet extends HttpServlet {
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
"Invalid request URI. Expecting <feed-publishing-url>/<fileid>.");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
String feedid = null;
@@ -193,6 +212,7 @@ public class NodeServlet extends HttpServlet {
logger.info("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization header required");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
String ip = req.getRemoteAddr();
@@ -209,6 +229,7 @@ public class NodeServlet extends HttpServlet {
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
"Invalid request URI. Expecting <feed-publishing-url>/<fileid>. Possible missing fileid.");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
feedid = fileid.substring(0, i);
@@ -220,6 +241,7 @@ public class NodeServlet extends HttpServlet {
if (!config.isAnotherNode(credentials, ip)) {
logger.info("NODE0107 Rejecting unauthorized node-to-node transfer attempt from " + ip);
resp.sendError(HttpServletResponse.SC_FORBIDDEN);
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
fileid = fileid.substring(18);
@@ -230,6 +252,7 @@ public class NodeServlet extends HttpServlet {
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
"Invalid request URI. Expecting <feed-publishing-url>/<fileid>.");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
if (fileid.indexOf('/') != -1) {
@@ -237,6 +260,7 @@ public class NodeServlet extends HttpServlet {
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
"Invalid request URI. Expecting <feed-publishing-url>/<fileid>.");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
String qs = req.getQueryString();
@@ -258,6 +282,7 @@ public class NodeServlet extends HttpServlet {
+ " from "
+ ip + " reason " + reason);
resp.sendError(HttpServletResponse.SC_FORBIDDEN, reason);
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
user = config.getAuthUser(feedid, credentials);
@@ -274,6 +299,7 @@ public class NodeServlet extends HttpServlet {
+ " to "
+ redirto);
resp.sendRedirect(redirto);
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
resp.setHeader("X-ATT-DR-PUBLISH-ID", pubid);
@@ -289,6 +315,8 @@ public class NodeServlet extends HttpServlet {
mx.append(req.getMethod()).append('\t').append(fileid).append('\n');
Enumeration hnames = req.getHeaderNames();
String ctype = null;
+ Boolean hasRequestIdHeader = false;
+ Boolean hasInvocationIdHeader = false;
while (hnames.hasMoreElements()) {
String hn = (String) hnames.nextElement();
String hnlc = hn.toLowerCase();
@@ -305,12 +333,19 @@ public class NodeServlet extends HttpServlet {
if ("content-type".equals(hnlc)) {
ctype = hv;
}
+ if ("x-onap-requestid".equals(hnlc)) {
+ hasRequestIdHeader = true;
+ }
+ if ("x-invocationid".equals(hnlc)) {
+ hasInvocationIdHeader = true;
+ }
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);
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Metadata too long");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
if (!MetaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) {
@@ -318,6 +353,7 @@ public class NodeServlet extends HttpServlet {
"NODE0109 Rejecting publish attempt with malformed metadata for feed " + feedid
+ " user " + user + " ip " + ip);
resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed metadata");
+ eelflogger.info(EelfMsgs.EXIT);
return;
}
}
@@ -325,6 +361,12 @@ public class NodeServlet extends HttpServlet {
}
}
}
+ if(!hasRequestIdHeader){
+ mx.append("X-ONAP-RequestID\t").append(MDC.get("RequestId")).append('\n');
+ }
+ if(!hasInvocationIdHeader){
+ mx.append("X-InvocationID\t").append(MDC.get("InvocationId")).append('\n');
+ }
mx.append("X-ATT-DR-RECEIVED\t").append(rcvd).append('\n');
String metadata = mx.toString();
byte[] buf = new byte[1024 * 1024];
@@ -347,6 +389,7 @@ public class NodeServlet extends HttpServlet {
}
StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user,
ioe.getMessage());
+ eelflogger.info(EelfMsgs.EXIT);
throw ioe;
}
Path dpath = Paths.get(fbase);
@@ -374,6 +417,7 @@ public class NodeServlet extends HttpServlet {
logger.info(
"NODE0110 IO Exception receiving publish attempt for feed " + feedid + " user " + user + " ip " + ip
+ " " + ioe.toString(), ioe);
+ eelflogger.info(EelfMsgs.EXIT);
throw ioe;
} finally {
if (is != null) {
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 63691957..2ba97163 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
@@ -24,10 +24,6 @@
package org.onap.dmaap.datarouter.node;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
-import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
-import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.FileInputStream;
@@ -40,19 +36,24 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.TimeZone;
+import java.util.UUID;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
import org.slf4j.MDC;
+import static com.att.eelf.configuration.Configuration.*;
+
/**
* Utility functions for the data router node
*/
public class NodeUtils {
private static EELFLogger eelfLogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
+ .getLogger(NodeUtils.class);
private static Logger nodeUtilsLogger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeUtils");
private NodeUtils() {
@@ -261,6 +262,23 @@ public class NodeUtils {
}
+ /* Method sets RequestIs and InvocationId for se in EELF logs
+ * @Method - setIpAndFqdnForEelf
+ * @Params - Req, Request used to get RequestId and InvocationId
+ */
+ public static void setRequestIdAndInvocationId(HttpServletRequest req) {
+ String reqId = req.getHeader("X-ONAP-RequestID");
+ if (StringUtils.isBlank(reqId)) {
+ reqId = UUID.randomUUID().toString();
+ }
+ MDC.put(MDC_KEY_REQUEST_ID, reqId);
+ String invId = req.getHeader("X-InvocationID");
+ if (StringUtils.isBlank(invId)) {
+ invId = UUID.randomUUID().toString();
+ }
+ MDC.put("InvocationId", invId);
+ }
+
public static void sendResponseError(HttpServletResponse response, int errorCode, Logger intlogger) {
try {
response.sendError(errorCode);
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
index ea3a50fc..f0b81747 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
@@ -41,7 +41,7 @@ import com.att.eelf.configuration.EELFManager;
* provisioning server to construct arrays of raw configuration entries.
*/
public class ProvData {
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.node.ProvData");
+ private static EELFLogger eelflogger = EELFManager.getInstance().getLogger(ProvData.class);
private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.ProvData");
private NodeConfig.ProvNode[] pn;
private NodeConfig.ProvParam[] pp;
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EelfMsgs.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EelfMsgs.java
index 7ebe4b53..756d01ad 100644
--- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EelfMsgs.java
+++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EelfMsgs.java
@@ -38,6 +38,12 @@ public enum EelfMsgs implements EELFResolvableErrorEnum {
MESSAGE_WITH_BEHALF_AND_FEEDID,
+ ENTRY,
+
+ EXIT,
+
+ INVOKE,
+
/**
* Application message prints keystore file error in EELF errors log
*/
diff --git a/datarouter-node/src/main/resources/EelfMessages.properties b/datarouter-node/src/main/resources/EelfMessages.properties
index 659748e9..27f83527 100644
--- a/datarouter-node/src/main/resources/EelfMessages.properties
+++ b/datarouter-node/src/main/resources/EelfMessages.properties
@@ -1,70 +1,78 @@
-#-------------------------------------------------------------------------------
-# ============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.
-# *
-#-------------------------------------------------------------------------------
-########################################################################
-#Resource key=Error Code|Message text|Resolution text |Description text
-#######
-#Newlines can be utilized to add some clarity ensuring continuing line
-#has atleast one leading space
-#ResourceKey=\
-# ERR0000E\
-# Sample error msg txt\
-# Sample resolution msg\
-# Sample description txt
-#
-######
-#Error code classification category
-#100 Permission errors
-#200 Availability errors/Timeouts
-#300 Data errors
-#400 Schema Interface type/validation errors
-#500 Business process errors
-#900 Unknown errors
-#
-########################################################################
-
-# Messages for Data Router EELF framework
-
-#Prints FeedID in the EELF apicalls log
-MESSAGE_WITH__FEEDID=EELF0001I| FeedID = {0}
-
-#Prints User in the EELF apicalls log
-MESSAGE_WITH_BEHALF=EELF0002I| User = {0}
-
-#Prints User and FeedID in the EELF apicalls log
-MESSAGE_WITH_BEHALF_AND_FEEDID=EELF0003I| User = {0} FeedID = {1}
-
-#Prints keystore file error in EELF errors log
-MESSAGE_KEYSTORE_LOAD_ERROR=EELF0001E| Error loading my keystore file {0} {1}
-
-MESSAGE_KEYSORE_NAME_ERROR=EELF0002E| Error extracting my name from my keystore file. {0}
-
-MESSAGE_PARSING_ERROR=EELF0003E| Error parsing configuration data from provisioning server. {0}
-
-MESSAGE_CONF_FAILED=EELF0004E| Configuration failed. {0} - try again later.
-
-MESSAGE_BAD_PROV_URL=EELF0005E| Bad provisioning server URL {0}
-
-MESSAGE_KEYSTORE_FETCH_ERROR=EELF0006E| Unable to fetch canonical name from keystore file {0}
-
-MESSAGE_PROPERTIES_LOAD_ERROR=EELF0007E| Unable to load local configuration file - etc/node.properties
-
+#-------------------------------------------------------------------------------
+# ============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.
+# *
+#-------------------------------------------------------------------------------
+########################################################################
+#Resource key=Error Code|Message text|Resolution text |Description text
+#######
+#Newlines can be utilized to add some clarity ensuring continuing line
+#has atleast one leading space
+#ResourceKey=\
+# ERR0000E\
+# Sample error msg txt\
+# Sample resolution msg\
+# Sample description txt
+#
+######
+#Error code classification category
+#100 Permission errors
+#200 Availability errors/Timeouts
+#300 Data errors
+#400 Schema Interface type/validation errors
+#500 Business process errors
+#900 Unknown errors
+#
+########################################################################
+
+# Messages for Data Router EELF framework
+
+#Prints FeedID in the EELF apicalls log
+MESSAGE_WITH__FEEDID=EELF0001I| FeedID = {0}
+
+#Prints User in the EELF apicalls log
+MESSAGE_WITH_BEHALF=EELF0002I| User = {0}
+
+#Prints User and FeedID in the EELF apicalls log
+MESSAGE_WITH_BEHALF_AND_FEEDID=EELF0003I| User = {0} FeedID = {1}
+
+#Prints InvocationId starting point for data router in the EELF apicalls log,
+ENTRY=EELF0004I| Entering data router node component with RequestId and InvocationId
+
+#Prints api exit point for data router in the EELF apicalls log,
+EXIT=EELF0005I| Exiting data router node component with RequestId and InvocationId
+
+INVOKE=EELF0006I| Invoking downstream call with InvocationId = {0}
+
+#Prints keystore file error in EELF errors log
+MESSAGE_KEYSTORE_LOAD_ERROR=EELF0001E| Error loading my keystore file {0} {1}
+
+MESSAGE_KEYSORE_NAME_ERROR=EELF0002E| Error extracting my name from my keystore file. {0}
+
+MESSAGE_PARSING_ERROR=EELF0003E| Error parsing configuration data from provisioning server. {0}
+
+MESSAGE_CONF_FAILED=EELF0004E| Configuration failed. {0} - try again later.
+
+MESSAGE_BAD_PROV_URL=EELF0005E| Bad provisioning server URL {0}
+
+MESSAGE_KEYSTORE_FETCH_ERROR=EELF0006E| Unable to fetch canonical name from keystore file {0}
+
+MESSAGE_PROPERTIES_LOAD_ERROR=EELF0007E| Unable to load local configuration file - etc/node.properties
+
diff --git a/datarouter-node/src/main/resources/logback.xml b/datarouter-node/src/main/resources/logback.xml
index b5528468..9bb1b732 100644
--- a/datarouter-node/src/main/resources/logback.xml
+++ b/datarouter-node/src/main/resources/logback.xml
@@ -45,10 +45,10 @@
<!-- name="auditLogName" value="audit" -->
<!-- name="debugLogName" value="debug" -->
<property name="jettyAndNodeLogName" value="node"></property>
- <property name="defaultPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|%msg%n" />
+ <property name="defaultPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%X{RequestId}|%X{InvocationId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|%msg%n" />
<property name="jettyAndNodeLoggerPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%thread|%.-5level|%msg%n" />
- <property name="debugLoggerPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|[%caller{3}]|%msg%n" />
+ <property name="debugLoggerPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{InvocationId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|[%caller{3}]|%msg%n" />
<property name="logDirectory" value="${logDir}" />
<!-- property name="debugLogDirectory" value="${debugDir}/${componentName}" /-->
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
index fbdd9230..4f31e922 100644
--- a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
+++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
@@ -22,22 +22,25 @@
******************************************************************************/
package org.onap.dmaap.datarouter.node;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
+import ch.qos.logback.classic.Logger;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.LoggerFactory;
-import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.*;
@@ -53,8 +56,11 @@ public class NodeServletTest {
@Mock
private HttpServletResponse response;
+ ListAppender<ILoggingEvent> listAppender;
+
@Before
public void setUp() throws Exception{
+ listAppender = setTestLogger();
nodeServlet = new NodeServlet();
setBehalfHeader("Stub_Value");
when(request.getPathInfo()).thenReturn("2");
@@ -70,6 +76,7 @@ public class NodeServletTest {
setNodeConfigManagerIsConfiguredToReturnFalse();
nodeServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_SERVICE_UNAVAILABLE));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -77,6 +84,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn("/internal/fetchProv");
nodeServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -84,6 +92,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn("/internal/resetSubscription/1");
nodeServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -91,6 +100,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn("/incorrect");
nodeServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -98,6 +108,7 @@ public class NodeServletTest {
setNodeConfigManagerIsConfiguredToReturnFalse();
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_SERVICE_UNAVAILABLE));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -105,6 +116,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn("/incorrect/");
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -112,6 +124,7 @@ public class NodeServletTest {
when(request.isSecure()).thenReturn(false);
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -119,6 +132,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn(null);
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -126,6 +140,7 @@ public class NodeServletTest {
when(request.getHeader("Authorization")).thenReturn(null);
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -133,6 +148,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn("/publish/");
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -141,6 +157,7 @@ public class NodeServletTest {
setNodeConfigManagerIsPublishPermittedToReturnAReason();
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -149,6 +166,7 @@ public class NodeServletTest {
setNodeConfigManagerIsPublishPermittedToReturnAReason();
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -156,6 +174,7 @@ public class NodeServletTest {
when(request.getPathInfo()).thenReturn("/internal/publish/1/");
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -164,6 +183,7 @@ public class NodeServletTest {
setNodeConfigManagerToAllowRedirectOnIngressNode();
nodeServlet.doPut(request, response);
verify(response).sendRedirect(anyString());
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -172,6 +192,7 @@ public class NodeServletTest {
setHeadersForValidRequest(true);
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -180,6 +201,7 @@ public class NodeServletTest {
setHeadersForValidRequest(false);
nodeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -188,6 +210,7 @@ public class NodeServletTest {
setHeadersForValidRequest(false);
nodeServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@@ -195,6 +218,20 @@ public class NodeServletTest {
when(request.getHeader("X-ATT-DR-ON-BEHALF-OF")).thenReturn(headerValue);
}
+ private ListAppender<ILoggingEvent> setTestLogger() {
+ Logger Logger = (Logger) LoggerFactory.getLogger(NodeServlet.class);
+ ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
+ listAppender.start();
+ Logger.addAppender(listAppender);
+ return listAppender;
+ }
+
+ private void verifyEnteringExitCalled(ListAppender<ILoggingEvent> listAppender) {
+ assertEquals("EELF0004I Entering data router node component with RequestId and InvocationId", listAppender.list.get(0).getMessage());
+ assertEquals("EELF0005I Exiting data router node component with RequestId and InvocationId", listAppender.list.get(2).getMessage());
+ assertEquals(3, listAppender.list.size());
+ }
+
private void setUpConfig() throws IllegalAccessException{
NodeConfigManager config = mock(NodeConfigManager.class);
PowerMockito.mockStatic(NodeConfigManager.class);
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
index 7dde043d..27fcd1c4 100644
--- 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
@@ -25,13 +25,31 @@ package org.onap.dmaap.datarouter.node;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.MDC;
+
+import javax.servlet.http.HttpServletRequest;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.util.UUID;
+
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
+import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeUtils")
+@PrepareForTest({ UUID.class, InetAddress.class })
public class NodeUtilsTest {
+ @Mock
+ private HttpServletRequest request;
+
@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";
@@ -58,4 +76,34 @@ public class NodeUtilsTest {
String s = NodeUtils.unloge("\\esearch\\ppub\\p12\\n");
Assert.assertEquals("\\search|pub|12\n", s);
}
+
+ @Test
+ public void Given_Request_Has_RequestId_And_InvocationId_Headers_Set_MDC_Values() {
+ when(request.getHeader("X-ONAP-RequestID")).thenReturn("123");
+ when(request.getHeader("X-InvocationID")).thenReturn("456");
+ NodeUtils.setRequestIdAndInvocationId(request);
+ Assert.assertEquals("123", MDC.get("RequestId"));
+ Assert.assertEquals("456", MDC.get("InvocationId"));
+ }
+
+ @Test
+ public void Given_setIpAndFqdnForEelf_Called_Set_MDC_Values() throws IOException {
+ mockStatic(InetAddress.class);
+ when(InetAddress.getLocalHost().getHostName()).thenReturn("testHostName");
+ when(InetAddress.getLocalHost().getHostAddress()).thenReturn("testHostAddress");
+ NodeUtils.setIpAndFqdnForEelf("doGet");
+ Assert.assertEquals("testHostName", MDC.get(MDC_SERVER_FQDN));
+ Assert.assertEquals("testHostAddress", MDC.get(MDC_SERVER_IP_ADDRESS));
+ }
+
+ @Test
+ public void Given_Request_Has_Empty_RequestId_And_InvocationId_Headers_Generate_MDC_Values() {
+ when(request.getHeader("X-ONAP-RequestID")).thenReturn("");
+ when(request.getHeader("X-InvocationID")).thenReturn("");
+ mockStatic(UUID.class);
+ when(UUID.randomUUID().toString()).thenReturn("123", "456");
+ NodeUtils.setRequestIdAndInvocationId(request);
+ Assert.assertEquals("123", MDC.get("RequestId"));
+ Assert.assertEquals("456", MDC.get("InvocationId"));
+ }
}