diff options
Diffstat (limited to 'datarouter-node')
13 files changed, 445 insertions, 60 deletions
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/Delivery.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/Delivery.java index 150d2aa2..82a4e9f0 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/Delivery.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/Delivery.java @@ -126,14 +126,14 @@ public class Delivery { DelItem[] items = cv.toArray(new DelItem[cv.size()]); Arrays.sort(items); long stop = (long) (tspace * fdstop); - logger.info( + logger.warn( "NODE0501 Free disk space below red threshold. current=" + cur + " red=" + start + TOTAL + tspace); if (determineFreeDiskSpace(spoolfile, tspace, stop, cur, items)) { return; } cur = spoolfile.getUsableSpace(); if (cur >= stop) { - logger.info("NODE0503 Free disk space at or above yellow threshold. current=" + cur + YELLOW + stop + logger.warn("NODE0503 Free disk space at or above yellow threshold. current=" + cur + YELLOW + stop + TOTAL + tspace); return; } @@ -248,7 +248,7 @@ public class Delivery { private boolean determineFreeDiskSpace(File spoolfile, long tspace, long stop, long cur, DelItem[] items) { for (DelItem item : items) { long amount = dqs.get(item.getSpool()).cancelTask(item.getPublishId()); - logger.info("NODE0502 Attempting to discard " + item.getSpool() + "/" + item.getPublishId() + logger.debug("NODE0502 Attempting to discard " + item.getSpool() + "/" + item.getPublishId() + " to free up disk"); if (amount > 0) { cur += amount; @@ -256,7 +256,7 @@ public class Delivery { cur = spoolfile.getUsableSpace(); } if (cur >= stop) { - logger.info( + logger.warn( "NODE0503 Free disk space at or above yellow threshold. current=" + cur + YELLOW + stop + TOTAL + tspace); return true; diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java index 0ba9ecfd..a3df26ac 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java @@ -117,7 +117,7 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { */ private synchronized void markSuccess(DeliveryTask task) { working.remove(task.getPublishId()); - logger.debug(task.getPublishId() + " marked as success."); + logger.info(task.getPublishId() + " marked as success."); task.clean(); failed = false; failduration = 0; @@ -127,7 +127,7 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { * Mark that a delivery task has expired. */ private synchronized void markExpired(DeliveryTask task) { - logger.debug(task.getPublishId() + " marked as expired."); + logger.info(task.getPublishId() + " marked as expired."); task.clean(); } @@ -136,7 +136,7 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { */ private synchronized void markFailNoRetry(DeliveryTask task) { working.remove(task.getPublishId()); - logger.debug(task.getPublishId() + " marked as failed permanently"); + logger.info(task.getPublishId() + " marked as failed permanently"); task.clean(); failed = false; failduration = 0; @@ -166,7 +166,7 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { */ private synchronized void markRedirect(DeliveryTask task) { working.remove(task.getPublishId()); - logger.debug(task.getPublishId() + " marked as redirected."); + logger.info(task.getPublishId() + " marked as redirected."); retry.put(task.getPublishId(), task); } @@ -175,7 +175,7 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { */ private synchronized void markFailWithRetry(DeliveryTask task) { working.remove(task.getPublishId()); - logger.debug(task.getPublishId() + " marked as temporarily failed."); + logger.info(task.getPublishId() + " marked as temporarily failed."); retry.put(task.getPublishId(), task); fdupdate(); } @@ -334,7 +334,7 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper { long endtime = System.currentTimeMillis() + deliveryQueueHelper.getFairTimeLimit(); int filestogo = deliveryQueueHelper.getFairFileLimit(); while ((task = getNext()) != null) { - logger.debug("Processing file: " + task.getPublishId()); + logger.info("Processing file: " + task.getPublishId()); task.run(); if (--filestogo <= 0 || System.currentTimeMillis() > endtime) { break; diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java index 49852680..91622b3c 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java @@ -75,7 +75,7 @@ public class IsFrom { logger.error("IsFrom: UnknownHostEx: " + e.toString(), e); } ips = hostAddrArray.toArray(new String[0]); - logger.info("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips)); + logger.debug("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips)); } for (String ipAddr : ips) { if (ipAddr.equals(ip)) { 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 00922e0a..15672eee 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 @@ -114,7 +114,7 @@ public class NodeConfigManager implements DeliveryQueueHelper { Properties drNodeProperties = new Properties(); try { - eelfLogger.info("NODE0301 Loading local config file node.properties"); + eelfLogger.debug("NODE0301 Loading local config file node.properties"); drNodeProperties.load(new FileInputStream(System .getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties"))); } catch (Exception e) { @@ -146,7 +146,7 @@ public class NodeConfigManager implements DeliveryQueueHelper { eelfLogger.error(EelfMsgs.MESSAGE_BAD_PROV_URL, e, provurl); exit(1); } - eelfLogger.info("NODE0303 Provisioning server is " + provhost); + eelfLogger.debug("NODE0303 Provisioning server is " + provhost); eventlogurl = drNodeProperties.getProperty("LogUploadURL", "https://feeds-drtr.web.att.com/internal/logs"); provcheck = new IsFrom(provhost); gfport = Integer.parseInt(drNodeProperties.getProperty("IntHttpPort", "8080")); @@ -189,7 +189,7 @@ public class NodeConfigManager implements DeliveryQueueHelper { eelfLogger.error("NODE0309 Unable to fetch canonical name from keystore file " + ksfile); exit(1); } - eelfLogger.info("NODE0304 My certificate says my name is " + myname); + eelfLogger.debug("NODE0304 My certificate says my name is " + myname); pid = new PublishId(myname); long minrsinterval = Long.parseLong(drNodeProperties.getProperty("MinRedirSaveInterval", "10000")); long minpfinterval = Long.parseLong(drNodeProperties.getProperty("MinProvFetchInterval", "10000")); @@ -199,7 +199,7 @@ public class NodeConfigManager implements DeliveryQueueHelper { fetchconfig(); } }; - eelfLogger.info("NODE0305 Attempting to fetch configuration at " + provurl); + eelfLogger.debug("NODE0305 Attempting to fetch configuration at " + provurl); pfetcher.request(); } @@ -290,7 +290,7 @@ public class NodeConfigManager implements DeliveryQueueHelper { private void fetchconfig() { try { - eelfLogger.info("NodeConfigMan.fetchConfig: provurl:: " + provurl); + eelfLogger.debug("NodeConfigMan.fetchConfig: provurl:: " + provurl); Reader reader = new InputStreamReader((new URL(provurl)).openStream()); config = new NodeConfig(new ProvData(reader), myname, spooldir, port, nak); localconfig(); @@ -322,10 +322,10 @@ public class NodeConfigManager implements DeliveryQueueHelper { */ public synchronized void gofetch(String remoteAddr) { if (provcheck.isReachable(remoteAddr)) { - eelfLogger.info("NODE0307 Received configuration fetch request from provisioning server " + remoteAddr); + eelfLogger.debug("NODE0307 Received configuration fetch request from provisioning server " + remoteAddr); pfetcher.request(); } else { - eelfLogger.info("NODE0308 Received configuration fetch request from unexpected server " + remoteAddr); + eelfLogger.debug("NODE0308 Received configuration fetch request from unexpected server " + remoteAddr); } } @@ -602,15 +602,15 @@ public class NodeConfigManager implements DeliveryQueueHelper { if (provcheck.isFrom(remoteaddr)) { String sdir = config.getSpoolDir(subid); if (sdir != null) { - eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid + eelfLogger.debug("NODE0310 Received subscription reset request for subscription " + subid + " from provisioning server " + remoteaddr); } else { - eelfLogger.info("NODE0311 Received subscription reset request for unknown subscription " + subid + eelfLogger.debug("NODE0311 Received subscription reset request for unknown subscription " + subid + " from provisioning server " + remoteaddr); } return (sdir); } else { - eelfLogger.info("NODE0312 Received subscription reset request from unexpected server " + remoteaddr); + eelfLogger.debug("NODE0312 Received subscription reset request from unexpected server " + remoteaddr); return (null); } } 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 abec7393..6086168b 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 @@ -71,10 +71,10 @@ public class NodeMain { * system property. By default, it is "/opt/app/datartr/etc/node.properties". */ public static void main(String[] args) throws Exception { - nodeMainLogger.info("NODE0001 Data Router Node Starting"); + nodeMainLogger.debug("NODE0001 Data Router Node Starting"); IsFrom.setDNSCache(); nodeConfigManager = NodeConfigManager.getInstance(); - nodeMainLogger.info("NODE0002 I am " + nodeConfigManager.getMyName()); + nodeMainLogger.debug("NODE0002 I am " + nodeConfigManager.getMyName()); (new WaitForConfig(nodeConfigManager)).waitForConfig(); delivery = new Delivery(nodeConfigManager); new LogManager(nodeConfigManager); @@ -112,11 +112,11 @@ public class NodeMain { sslContextFactory.addExcludeProtocols("SSLv3"); sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols()); - nodeMainLogger.info("NODE00004 Unsupported protocols node server:-" + nodeMainLogger.debug("NODE00004 Unsupported protocols node server:-" + String.join(",", sslContextFactory.getExcludeProtocols())); - nodeMainLogger.info("NODE00004 Supported protocols node server:-" + nodeMainLogger.debug("NODE00004 Supported protocols node server:-" + String.join(",", sslContextFactory.getIncludeProtocols())); - nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-" + nodeMainLogger.debug("NODE00004 Unsupported ciphers node server:-" + String.join(",", sslContextFactory.getExcludeCipherSuites())); HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration); @@ -153,12 +153,12 @@ public class NodeMain { try { server.start(); - nodeMainLogger.info("NODE00006 Node Server started-" + server.getState()); + nodeMainLogger.debug("NODE00006 Node Server started-" + server.getState()); } catch (Exception e) { - nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e); + nodeMainLogger.error("NODE00006 Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e); } server.join(); - nodeMainLogger.info("NODE00007 Node Server joined - " + server.getState()); + nodeMainLogger.debug("NODE00007 Node Server joined - " + server.getState()); } private static void enableCadi(ServletContextHandler servletContextHandler) throws ServletException { @@ -172,7 +172,7 @@ public class NodeMain { .error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage(), e1); } cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL()); - nodeMainLogger.info("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url")); + nodeMainLogger.debug("NODE00005 aaf_url set to - " + cadiProperties.getProperty("aaf_url")); PropAccess access = new PropAccess(cadiProperties); servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet @@ -194,7 +194,7 @@ public class NodeMain { synchronized void waitForConfig() { localNodeConfigManager.registerConfigTask(this); while (!localNodeConfigManager.isConfigured()) { - nodeMainLogger.info("NODE0003 Waiting for Node Configuration"); + nodeMainLogger.debug("NODE0003 Waiting for Node Configuration"); try { wait(); } catch (Exception exception) { @@ -204,7 +204,7 @@ public class NodeMain { } } localNodeConfigManager.deregisterConfigTask(this); - nodeMainLogger.info("NODE0004 Node Configuration Data Received"); + nodeMainLogger.debug("NODE0004 Node Configuration Data Received"); } } 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 3b82484a..163b59ea 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 @@ -91,13 +91,13 @@ public class NodeServlet extends HttpServlet { @Override public void init() { config = NodeConfigManager.getInstance(); - eelfLogger.info("NODE0101 Node Servlet Configured"); + eelfLogger.debug("NODE0101 Node Servlet Configured"); } private boolean down(HttpServletResponse resp) { if (config.isShutdown() || !config.isConfigured()) { sendResponseError(resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE, eelfLogger); - eelfLogger.info("NODE0102 Rejecting request: Service is being quiesced"); + eelfLogger.error("NODE0102 Rejecting request: Service is being quiesced"); return true; } return false; @@ -112,7 +112,7 @@ public class NodeServlet extends HttpServlet { NodeUtils.setRequestIdAndInvocationId(req); eelfLogger.info(EelfMsgs.ENTRY); try { - eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF), + eelfLogger.debug(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF), getIdFromPath(req) + ""); if (down(resp)) { return; @@ -136,7 +136,7 @@ public class NodeServlet extends HttpServlet { } } - eelfLogger.info("NODE0103 Rejecting invalid GET of " + path + FROM + ip); + eelfLogger.debug("NODE0103 Rejecting invalid GET of " + path + FROM + ip); sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, eelfLogger); } finally { eelfLogger.info(EelfMsgs.EXIT); @@ -151,7 +151,7 @@ public class NodeServlet extends HttpServlet { NodeUtils.setIpAndFqdnForEelf("doPut"); NodeUtils.setRequestIdAndInvocationId(req); eelfLogger.info(EelfMsgs.ENTRY); - eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF), + eelfLogger.debug(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF), getIdFromPath(req) + ""); try { common(req, resp, true); @@ -169,7 +169,7 @@ public class NodeServlet extends HttpServlet { NodeUtils.setIpAndFqdnForEelf("doDelete"); NodeUtils.setRequestIdAndInvocationId(req); eelfLogger.info(EelfMsgs.ENTRY); - eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF), + eelfLogger.debug(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF), getIdFromPath(req) + ""); try { common(req, resp, false); @@ -228,7 +228,7 @@ public class NodeServlet extends HttpServlet { if (!("legacy".equalsIgnoreCase(aafInstance))) { isAAFFeed = true; String permission = config.getPermission(aafInstance); - eelfLogger.info("NodeServlet.common() permission string - " + permission); + eelfLogger.debug("NodeServlet.common() permission string - " + permission); //Check in CADI Framework API if user has AAF permission or not if (!req.isUserInRole(permission)) { String message = "AAF disallows access to permission string - " + permission; @@ -303,7 +303,7 @@ public class NodeServlet extends HttpServlet { .cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + FROM + PathUtil .cleanString(ip) + " reason Invalid AAF user- " + PathUtil.cleanString(reason)); String message = "Invalid AAF user- " + PathUtil.cleanString(reason); - eelfLogger.info("NODE0308 Rejecting unauthenticated PUT or DELETE of " + PathUtil + eelfLogger.debug("NODE0308 Rejecting unauthenticated PUT or DELETE of " + PathUtil .cleanString(req.getPathInfo()) + FROM + PathUtil.cleanString(req.getRemoteAddr())); resp.sendError(HttpServletResponse.SC_FORBIDDEN, message); return; @@ -326,7 +326,7 @@ public class NodeServlet extends HttpServlet { } String redirto = HTTPS + newnode + port + PUBLISH + feedid + "/" + fileid; eelfLogger - .info("NODE0108 Redirecting publish attempt for feed " + PathUtil.cleanString(feedid) + USER + .debug("NODE0108 Redirecting publish attempt for feed " + PathUtil.cleanString(feedid) + USER + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " to " + PathUtil .cleanString(redirto)); //Fortify scan fixes - log forging resp.sendRedirect(PathUtil.cleanString(redirto)); //Fortify scan fixes-open redirect - 2 issues @@ -517,7 +517,7 @@ public class NodeServlet extends HttpServlet { } boolean result = delivery.markTaskSuccess(config.getSpoolBase() + "/s/" + subIdDir + "/" + subId, pubid); if (result) { - eelfLogger.info("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + FROM_DR_MESSAGE + eelfLogger.debug("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + FROM_DR_MESSAGE + config.getMyName()); resp.setStatus(HttpServletResponse.SC_OK); eelfLogger.info(EelfMsgs.EXIT); diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/StatusLog.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/StatusLog.java index 53e53145..a9a48ade 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/StatusLog.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/StatusLog.java @@ -158,6 +158,8 @@ public class StatusLog { instance.log( "PUB|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + srcip + "|" + user + "|" + status); + eelfLogger.info("PUB|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + srcip + + "|" + user + "|" + status); } /** @@ -178,6 +180,8 @@ public class StatusLog { long rcvd, String srcip, String user, String error) { instance.log("PBF|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + rcvd + "|" + srcip + "|" + user + "|" + error); + eelfLogger.info("PBF|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + rcvd + + "|" + srcip + "|" + user + "|" + error); } /** @@ -202,6 +206,8 @@ public class StatusLog { instance.log( "DEL|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + user + "|" + status + "|" + xpubid); + eelfLogger.info("DEL|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + + "|" + user + "|" + status + "|" + xpubid); } /** @@ -225,6 +231,8 @@ public class StatusLog { instance.log( "EXP|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + reason + "|" + attempts); + eelfLogger.info("EXP|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + + "|" + reason + "|" + attempts); } /** @@ -242,6 +250,7 @@ public class StatusLog { return; } instance.log("DLX|" + pubid + "|" + feedid + "|" + subid + "|" + clen + "|" + sent); + eelfLogger.info("DLX|" + pubid + "|" + feedid + "|" + subid + "|" + clen + "|" + sent); } private synchronized void checkRoll(long now) throws IOException { diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/DebugFilter.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/DebugFilter.java new file mode 100644 index 00000000..58cd1706 --- /dev/null +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/DebugFilter.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.dmaap.datarouter.node.eelf; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.Filter; +import ch.qos.logback.core.spi.FilterReply; + + +public class DebugFilter extends Filter<ILoggingEvent> { + @Override + public FilterReply decide(ILoggingEvent event) { + if (event.getLevel().equals(Level.DEBUG) && !event.getMessage().contains("org.eclipse.jetty")) { + return FilterReply.ACCEPT; + } else { + return FilterReply.DENY; + } + } +} diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/ErrorFilter.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/ErrorFilter.java new file mode 100644 index 00000000..84f71cf5 --- /dev/null +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/ErrorFilter.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.dmaap.datarouter.node.eelf; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.filter.Filter; +import ch.qos.logback.core.spi.FilterReply; + + +public class ErrorFilter extends Filter<ILoggingEvent> { + @Override + public FilterReply decide(ILoggingEvent event) { + if ((event.getLevel().equals(Level.ERROR) || event.getLevel().equals(Level.WARN)) && !event.getMessage().contains("org.eclipse.jetty")) { + return FilterReply.ACCEPT; + } else { + return FilterReply.DENY; + } + } +} diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/JettyFilter.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/JettyFilter.java index 69f51d82..d5e520ea 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/JettyFilter.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/JettyFilter.java @@ -28,7 +28,7 @@ import ch.qos.logback.core.spi.FilterReply; public class JettyFilter extends Filter<ILoggingEvent> { @Override public FilterReply decide(ILoggingEvent event) { - if (event.getMessage().contains("org.eclipse.jetty")) { + if (event.getMessage().contains("org.eclipse.jetty") || event.getLoggerName().contains("org.eclipse.jetty")) { return FilterReply.ACCEPT; } else { return FilterReply.DENY; diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/MetricsFilter.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/MetricsFilter.java index 0fa57d4a..f3e27fee 100644 --- a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/MetricsFilter.java +++ b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/MetricsFilter.java @@ -29,7 +29,7 @@ import ch.qos.logback.core.spi.FilterReply; public class MetricsFilter extends Filter<ILoggingEvent> { @Override public FilterReply decide(ILoggingEvent event) { - if (event.getLevel().equals(Level.INFO) && !event.getMessage().contains("jetty")) { + if (event.getLevel().equals(Level.INFO) && !event.getMessage().contains("org.eclipse.jetty") && !event.getLoggerName().contains("org.eclipse.jetty")) { if (!event.getMessage().contains("DEL|") && !event.getMessage().contains("PUB|") && !event.getMessage().contains( "PBF|") && !event.getMessage().contains("EXP|") && !event.getMessage().contains("DLX|")) { return FilterReply.ACCEPT; diff --git a/datarouter-node/src/main/resources/logback.xml b/datarouter-node/src/main/resources/logback.xml index dc19cb6f..3c564f4a 100644 --- a/datarouter-node/src/main/resources/logback.xml +++ b/datarouter-node/src/main/resources/logback.xml @@ -110,10 +110,7 @@ <appender name="Debug" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDirectory}/${debugLog}.log</file> - <filter class="ch.qos.logback.classic.filter.LevelFilter"> - <level>DEBUG</level> - <onMatch>ACCEPT</onMatch> - <onMismatch>DENY</onMismatch> + <filter class="org.onap.dmaap.datarouter.node.eelf.DebugFilter"> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> @@ -141,10 +138,7 @@ <appender name="Error" class="ch.qos.logback.core.rolling.RollingFileAppender"> <file>${logDirectory}/${errorLog}.log</file> - <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> - <level>WARN</level> - <onMatch>ACCEPT</onMatch> - <onMismatch>DENY</onMismatch> + <filter class="org.onap.dmaap.datarouter.node.eelf.ErrorFilter"> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> @@ -204,21 +198,21 @@ <appender-ref ref="asyncAudit" /> </logger> - <logger name="com.att.eelf" level="info" additivity="false"> + <logger name="com.att.eelf" additivity="false"> <appender-ref ref="asyncMetrics" /> </logger> - <logger name="com.att.eelf" level="debug" additivity="false"> + <logger name="com.att.eelf" additivity="false"> <appender-ref ref="asyncDebug" /> </logger> - <logger name="com.att.eelf.error" level="error" additivity="false"> - <appender-ref ref="asyncError" /> - </logger> + <logger name="com.att.eelf.error" additivity="false"> + <appender-ref ref="asyncError" /> + </logger> - <logger name="log4j.logger.org.eclipse.jetty" additivity="false" level="info"> - <appender-ref ref="asyncJettyLog"/> - </logger> + <logger name="log4j.logger.org.eclipse.jetty" additivity="false"> + <appender-ref ref="asyncJettyLog"/> + </logger> diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java new file mode 100644 index 00000000..4a5d07ad --- /dev/null +++ b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogbackFilterTest.java @@ -0,0 +1,308 @@ +/******************************************************************************* + * ============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 static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; +import static org.onap.dmaap.datarouter.node.eelf.EelfMsgs.MESSAGE_WITH_BEHALF; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.spi.LoggingEvent; +import ch.qos.logback.core.spi.FilterReply; +import java.util.List; +import org.junit.Test; +import org.onap.dmaap.datarouter.node.eelf.AuditFilter; +import org.onap.dmaap.datarouter.node.eelf.DebugFilter; +import org.onap.dmaap.datarouter.node.eelf.ErrorFilter; +import org.onap.dmaap.datarouter.node.eelf.JettyFilter; +import org.onap.dmaap.datarouter.node.eelf.MetricsFilter; + +public class LogbackFilterTest { + + @Test + public void Given_Event_with_valid_status_then_audit_Filter_ACCEPT() { + final List<String> validStatus = asList("DEL|", "PUB|", "PBF|", "EXP|", "DLX|"); + final AuditFilter filter = new AuditFilter(); + filter.start(); + + for (final String status : validStatus) { + final LoggingEvent event = new LoggingEvent(); + event.setMessage("Test " + status); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + } + } + + @Test + public void Given_Event_with_invalid_status_then_audit_Filter_DENY() { + final AuditFilter filter = new AuditFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setMessage("Invalid status"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + + @Test + public void Given_Event_with_valid_jetty_string_and_invalid_logger_then_jetty_Filter_ACCEPT() { + final JettyFilter filter = new JettyFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setMessage("org.eclipse.jetty"); + event.setLoggerName("org.invalid.jetty"); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + } + + @Test + public void Given_Event_with_valid_jetty_string_and_valid_logger_then_jetty_Filter_ACCEPT() { + final JettyFilter filter = new JettyFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setMessage("org.eclipse.jetty"); + event.setLoggerName("org.eclipse.jetty"); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + } + + @Test + public void Given_Event_with_invalid_jetty_string_and_valid_logger_then_jetty_Filter_DENY() { + final JettyFilter filter = new JettyFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setMessage("org.invalid.jetty"); + event.setLoggerName("org.invalid.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + + @Test + public void Given_Event_with_level_info_and_valid_jetty_string_then_metrics_filter_DENY() { + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_not_info_and_valid_jetty_string_then_metrics_filter_DENY() { + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_not_info_and_invalid_jetty_string_and_valid_logger_then_metrics_filter_DENY() { + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMessage("org.invalid.jetty"); + event.setLoggerName("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + + @Test + public void Given_Event_with_level_not_info_and_invalid_jetty_string_and_invalid_logger_then_metrics_filter_DENY() { + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMessage("org.invalid.jetty"); + event.setLoggerName("org.eclipse.jetty"); + event.setLoggerName("org.invalid.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + + @Test + public void Given_Event_with_level_info_and_invalid_jetty_string_and_status_in_status_list_and_valid_logger_then_metrics_filter_DENY() { + final List<String> validStatus = asList("DEL|", "PUB|", "PBF|", "EXP|", "DLX|"); + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + + for (final String status : validStatus) { + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage(status); + event.setLoggerName("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + } + + @Test + public void Given_Event_with_level_info_and_invalid_jetty_string_and_status_in_status_list_and_invalid_logger_then_metrics_filter_DENY() { + final List<String> validStatus = asList("DEL|", "PUB|", "PBF|", "EXP|", "DLX|"); + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + + for (final String status : validStatus) { + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage(status); + event.setLoggerName("org.invalid.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + } + + @Test + public void Given_Event_with_level_info_and_invalid_jetty_string_and_status_not_in_status_list_and_valid_logger_then_metrics_filter_DENY() { + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("Invalid status"); + event.setLoggerName("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + } + + @Test + public void Given_Event_with_level_info_and_invalid_jetty_string_and_status_not_in_status_list_and_invalid_logger_then_metrics_filter_ACCEPT() { + final MetricsFilter filter = new MetricsFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("Invalid status"); + event.setLoggerName("org.invalid.jetty"); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + } + + @Test + public void Given_Event_with_level_debug_and_valid_jetty_string_then_debug_filter_DENY() { + final DebugFilter filter = new DebugFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_not_debug_and_valid_jetty_string_then_debug_filter_DENY() { + final DebugFilter filter = new DebugFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_not_debug_and_not_valid_jetty_string_then_debug_filter_DENY() { + final DebugFilter filter = new DebugFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("org.invalid.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_debug_and_not_valid_jetty_string_then_debug_filter_ACCEPT() { + final DebugFilter filter = new DebugFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.DEBUG); + event.setMessage("org.invalid.jetty"); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_error_and_valid_jetty_string_then_error_filter_DENY() { + final ErrorFilter filter = new ErrorFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_warn_and_valid_jetty_string_then_error_filter_DENY() { + final ErrorFilter filter = new ErrorFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_not_warn_or_error_and_valid_jetty_string_then_error_filter_DENY() { + final ErrorFilter filter = new ErrorFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("org.eclipse.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_not_warn_or_error_and_invalid_jetty_string_then_error_filter_DENY() { + final ErrorFilter filter = new ErrorFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.INFO); + event.setMessage("org.invalid.jetty"); + assertEquals(FilterReply.DENY, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_warn_and_invalid_jetty_string_then_error_filter_ACCEPT() { + final ErrorFilter filter = new ErrorFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.WARN); + event.setMessage("org.invalid.jetty"); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + + } + + @Test + public void Given_Event_with_level_error_and_invalid_jetty_string_then_error_filter_ACCEPT() { + final ErrorFilter filter = new ErrorFilter(); + filter.start(); + final LoggingEvent event = new LoggingEvent(); + event.setLevel(Level.ERROR); + event.setMessage("org.invalid.jetty"); + assertEquals(FilterReply.ACCEPT, filter.decide(event)); + + } + + + @Test + public void Given_call_to_EelfMsgs_return_the_correct_enum(){ + assertEquals(MESSAGE_WITH_BEHALF.toString(), "MESSAGE_WITH_BEHALF"); + } + +} |