Merge changes Id40d25d3,I12263a65
authorFiachra Corcoran <fiachra.corcoran@est.tech>
Tue, 23 Jul 2019 15:00:28 +0000 (15:00 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 23 Jul 2019 15:00:28 +0000 (15:00 +0000)
* changes:
  Document OJSI-158 vulnerability
  Improve security release notes

114 files changed:
INFO.yaml
ci_scripts/onap-style-java.xml [new file with mode: 0644]
ci_scripts/pre-commit.sh [new file with mode: 0755]
ci_scripts/suppressedFilesForStyleCheck.xml [new file with mode: 0644]
datarouter-node/pom.xml
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilter.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/Delivery.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTask.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryTaskHelper.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DestInfo.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DestInfoBuilder.java [new file with mode: 0644]
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/IsFrom.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/LogManager.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfig.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeServlet.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeUtils.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathFinder.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PathUtil.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/PublishId.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RateLimitedOperation.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/RedirManager.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/StatusLog.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/SubnetMatcher.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/Target.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/TaskList.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/AuditFilter.java [new file with mode: 0644]
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EELFFilter.java [deleted file]
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/JettyFilter.java [new file with mode: 0644]
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/MetricsFilter.java [new file with mode: 0644]
datarouter-node/src/main/resources/docker/Dockerfile
datarouter-node/src/main/resources/logback.xml
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DRNodeCadiFilterTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryQueueTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java [new file with mode: 0644]
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java [new file with mode: 0644]
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java [new file with mode: 0644]
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeConfigTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeServletTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/NodeUtilsTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java [new file with mode: 0644]
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/ProvDataTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java [new file with mode: 0644]
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/StatusLogTest.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java [new file with mode: 0644]
datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node [new file with mode: 0644]
datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M [new file with mode: 0644]
datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz [new file with mode: 0644]
datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M [new file with mode: 0644]
datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks [new file with mode: 0644]
datarouter-node/src/test/resources/redir_file [new file with mode: 0644]
datarouter-prov/pom.xml
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespImpl.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthzResource.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryExtraRecord.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedEndpointID.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecord.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubDelivery.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java [new file with mode: 0644]
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java [new file with mode: 0755]
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
datarouter-prov/src/test/resources/create.sql
datarouter-prov/src/test/resources/h2Database.properties
datarouter-prov/src/test/resources/prov_data.json [new file with mode: 0644]
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java
docs/release-notes.rst
pom.xml

index 419d763..3b16c12 100644 (file)
--- a/INFO.yaml
+++ b/INFO.yaml
@@ -3,9 +3,9 @@ project: 'dmaap-datarouter'
 project_creation_date: '2017-06-30'
 lifecycle_state: 'Incubation'
 project_lead: &onap_releng_ptl
-    name: 'Ram Koya'
-    email: 'rk541m@att.com'
-    id: 'rampi_k'
+    name: 'Mandar Sawant'
+    email: 'ms5838@att.com'
+    id: 'sawantmandar'
     company: 'ATT'
     timezone: 'America/Dallas'
 primary_contact: *onap_releng_ptl
@@ -45,11 +45,6 @@ committers:
       company: 'ATT'
       id: 'sawantmandar'
       timezone: 'America/Dallas'
-    - name: 'Varun Gudisena'
-      email: 'vg411h@att.com'
-      company: 'ATT'
-      id: 'vg411h'
-      timezone: 'America/Dallas'
     - name: 'Bhanu Ramesh'
       email: 'bg6954@att.com'
       company: 'ATT'
@@ -69,7 +64,13 @@ committers:
       email: 'conor.ward@ericsson.com'
       company: 'ericsson'
       id: 'econwar'
-      timezone: 'America/Dallas'
+      timezone: 'Europe/Dublin'
+    - name: 'Fiachra Corcoran'
+      email: 'fiachra.corcoran@est.tech'
+      company: 'ericsson'
+      id: 'efiacor'
+      timezone: 'Europe/Dublin'
+      
 tsc:
     approval: 'https://lists.onap.org/pipermail/onap-tsc'
     changes:
@@ -78,3 +79,4 @@ tsc:
           name: 'Xinhui Li'
           name: 'Jing Wang'
           name: 'Ramdas Sawant'
+          name: 'Varun Gudisena'
diff --git a/ci_scripts/onap-style-java.xml b/ci_scripts/onap-style-java.xml
new file mode 100644 (file)
index 0000000..502ea7a
--- /dev/null
@@ -0,0 +1,225 @@
+<?xml version="1.0"?>
+<!--
+  ============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=========================================================
+-->
+<!DOCTYPE module PUBLIC
+  "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+  "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
+
+<!--
+
+    Checkstyle configuration that checks the Google coding conventions from:
+
+    -  Google Java Style
+       https://google-styleguide.googlecode.com/svn-history/r130/trunk/javaguide.html
+
+    Checkstyle is very configurable. Be sure to read the documentation at
+    http://checkstyle.sf.net (or in your downloaded distribution).
+
+    Most Checks are configurable, be sure to consult the documentation.
+
+    To completely disable a check, just comment it out or delete it from the file.
+
+    Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
+
+ -->
+
+<module name = "Checker">
+    <property name="charset" value="UTF-8"/>
+
+    <property name="severity" value="warning"/>
+
+    <property name="fileExtensions" value="java, properties, xml"/>
+    <!-- Checks for whitespace                               -->
+    <!-- See http://checkstyle.sf.net/config_whitespace.html -->
+    <module name="FileTabCharacter">
+        <property name="eachLine" value="true"/>
+    </module>
+    <module name="SuppressionFilter">
+        <property name="file" value="ci_scripts/suppressedFilesForStyleCheck.xml" />
+    </module>
+    <module name="TreeWalker">
+        <module name="OuterTypeFilename"/>
+        <module name="IllegalTokenText">
+            <property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
+            <property name="format" value="\\u00(08|09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
+            <property name="message" value="Avoid using corresponding octal or Unicode escape."/>
+        </module>
+        <module name="AvoidEscapedUnicodeCharacters">
+            <property name="allowEscapesForControlCharacters" value="true"/>
+            <property name="allowByTailComment" value="true"/>
+            <property name="allowNonPrintableEscapes" value="true"/>
+        </module>
+        <module name="LineLength">
+            <property name="max" value="120"/>
+            <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
+        </module>
+        <module name="AvoidStarImport"/>
+        <module name="OneTopLevelClass"/>
+        <module name="NoLineWrap"/>
+        <module name="EmptyBlock">
+            <property name="option" value="TEXT"/>
+            <property name="tokens" value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
+        </module>
+        <module name="NeedBraces"/>
+        <module name="LeftCurly">
+        </module>
+        <module name="RightCurly">
+            <property name="option" value="alone"/>
+            <property name="tokens" value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO, STATIC_INIT, INSTANCE_INIT"/>
+        </module>
+        <module name="WhitespaceAround">
+            <property name="allowEmptyConstructors" value="true"/>
+            <property name="allowEmptyMethods" value="true"/>
+            <property name="allowEmptyTypes" value="true"/>
+            <property name="allowEmptyLoops" value="true"/>
+            <message key="ws.notFollowed"
+              value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
+            <message key="ws.notPreceded"
+              value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
+        </module>
+        <module name="OneStatementPerLine"/>
+        <module name="MultipleVariableDeclarations"/>
+        <module name="ArrayTypeStyle"/>
+        <module name="MissingSwitchDefault"/>
+        <module name="FallThrough"/>
+        <module name="UpperEll"/>
+        <module name="ModifierOrder"/>
+        <module name="EmptyLineSeparator">
+            <property name="allowNoEmptyLineBetweenFields" value="true"/>
+        </module>
+        <module name="SeparatorWrap">
+            <property name="tokens" value="DOT"/>
+            <property name="option" value="nl"/>
+        </module>
+        <module name="SeparatorWrap">
+            <property name="tokens" value="COMMA"/>
+            <property name="option" value="EOL"/>
+        </module>
+        <module name="PackageName">
+            <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
+            <message key="name.invalidPattern"
+              value="Package name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="TypeName">
+            <message key="name.invalidPattern"
+              value="Type name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="MemberName">
+            <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
+            <message key="name.invalidPattern"
+              value="Member name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="ParameterName">
+            <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
+            <message key="name.invalidPattern"
+              value="Parameter name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="LocalVariableName">
+            <property name="tokens" value="VARIABLE_DEF"/>
+            <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
+            <property name="allowOneCharVarInForLoop" value="true"/>
+            <message key="name.invalidPattern"
+              value="Local variable name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="ClassTypeParameterName">
+            <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
+            <message key="name.invalidPattern"
+              value="Class type name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="MethodTypeParameterName">
+            <property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
+            <message key="name.invalidPattern"
+              value="Method type name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="NoFinalizer"/>
+        <module name="GenericWhitespace">
+            <message key="ws.followed"
+              value="GenericWhitespace ''{0}'' is followed by whitespace."/>
+            <message key="ws.preceded"
+              value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
+            <message key="ws.illegalFollow"
+              value="GenericWhitespace ''{0}'' should followed by whitespace."/>
+            <message key="ws.notPreceded"
+              value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
+        </module>
+        <module name="Indentation">
+            <property name="basicOffset" value="4"/>
+            <property name="braceAdjustment" value="0"/>
+            <property name="caseIndent" value="4"/>
+            <property name="throwsIndent" value="4"/>
+            <property name="lineWrappingIndentation" value="4"/>
+            <property name="arrayInitIndent" value="4"/>
+        </module>
+        <module name="AbbreviationAsWordInName">
+            <property name="ignoreFinal" value="false"/>
+            <property name="allowedAbbreviationLength" value="20"/>
+        </module>
+        <module name="OverloadMethodsDeclarationOrder"/>
+        <module name="VariableDeclarationUsageDistance"/>
+        <module name="CustomImportOrder">
+            <property name="sortImportsInGroupAlphabetically" value="true"/>
+            <property name="separateLineBetweenGroups" value="true"/>
+            <property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
+        </module>
+        <module name="MethodParamPad"/>
+        <module name="OperatorWrap">
+            <property name="option" value="NL"/>
+            <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
+        </module>
+        <module name="AnnotationLocation">
+            <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
+        </module>
+        <module name="AnnotationLocation">
+            <property name="tokens" value="VARIABLE_DEF"/>
+            <property name="allowSamelineMultipleAnnotations" value="true"/>
+        </module>
+        <module name="NonEmptyAtclauseDescription"/>
+        <module name="JavadocTagContinuationIndentation"/>
+        <module name="SummaryJavadocCheck">
+            <property name="forbiddenSummaryFragments" value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
+        </module>
+        <module name="JavadocParagraph"/>
+        <module name="AtclauseOrder">
+            <property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
+            <property name="target" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
+        </module>
+        <module name="JavadocMethod">
+            <property name="scope" value="public"/>
+            <property name="allowMissingParamTags" value="true"/>
+            <property name="allowMissingThrowsTags" value="true"/>
+            <property name="allowMissingReturnTag" value="true"/>
+            <property name="minLineCount" value="2"/>
+            <property name="allowedAnnotations" value="Override, Test"/>
+            <property name="allowThrowsTagsForSubclasses" value="true"/>
+        </module>
+        <module name="MethodName">
+            <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
+            <message key="name.invalidPattern"
+              value="Method name ''{0}'' must match pattern ''{1}''."/>
+        </module>
+        <module name="SingleLineJavadoc">
+            <property name="ignoreInlineTags" value="false"/>
+        </module>
+        <module name="EmptyCatchBlock">
+            <property name="exceptionVariableName" value="expected"/>
+        </module>
+        <module name="CommentsIndentation"/>
+    </module>
+</module>
diff --git a/ci_scripts/pre-commit.sh b/ci_scripts/pre-commit.sh
new file mode 100755 (executable)
index 0000000..636f8ff
--- /dev/null
@@ -0,0 +1,56 @@
+#!/usr/bin/env bash
+#
+# ============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=========================================================
+#
+# Pre-commit hook for running checkstyle on changed Java sources
+#
+# To use this you need:
+# 1. Checkstyle's jar file downloaded *version is important checkstyle-8.13-all.jar
+# 2. To configure git:
+#   * git config --add checkstyle.jar <location_of_jar>
+# 3. Copy this file to your .git/hooks directory as pre-commit
+#
+# Now, when you commit, you will be disallowed from doing so
+# until you pass your checkstyle checks.
+
+changed_files=" "
+for file in $(git diff --cached --name-status | grep -E '\.(java)$' | grep -vE '^D' | awk '{print $2}')
+do
+  changed_files+="$file "
+done
+
+printf "Using checkstyle sheet "
+checkstlye_jar_command='git config --get checkstyle.jar'
+
+if ! ($checkstlye_jar_command)
+then
+  printf "You must configure checkstyle in your git config"
+  exit 1
+fi
+
+checkstyle_warnings=$(java -jar $($checkstlye_jar_command) -c ci_scripts/onap-style-java.xml $changed_files | grep WARN)
+if [ $? == 0 ]
+then
+  printf "\nWarnings found\n\n"
+  echo "$checkstyle_warnings"
+  printf "\n###############################################################\n\nFix warnings before committing\n\n"
+  exit 1
+else
+  printf "\nCode checkstyle passed.\n"
+fi
diff --git a/ci_scripts/suppressedFilesForStyleCheck.xml b/ci_scripts/suppressedFilesForStyleCheck.xml
new file mode 100644 (file)
index 0000000..ed56442
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<!--
+  ============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=========================================================
+-->
+<!DOCTYPE suppressions PUBLIC
+  "-//Puppy Crawl//DTD Suppressions 1.1//EN"
+  "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
+
+<suppressions>
+  <suppress files=".*Test\.java" checks="[a-zA-Z0-9]*"/>
+</suppressions>
\ No newline at end of file
index 06aa3fc..42c1c9a 100755 (executable)
             <groupId>commons-codec</groupId>
             <artifactId>commons-codec</artifactId>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.awaitility</groupId>
+            <artifactId>awaitility</artifactId>
+            <version>3.1.6</version>
+        </dependency>
     </dependencies>
     <profiles>
         <profile>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>cobertura-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.sonatype.plugins</groupId>
-                <artifactId>nexus-staging-maven-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
index 30ad161..245dbcc 100644 (file)
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.dmaap.datarouter.node;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.onap.aaf.cadi.PropAccess;
-import org.onap.aaf.cadi.filter.CadiFilter;
-
+import java.io.IOException;
 import javax.servlet.FilterChain;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+import org.onap.aaf.cadi.PropAccess;
+import org.onap.aaf.cadi.filter.CadiFilter;
 
 
 public class DRNodeCadiFilter extends CadiFilter {
+
     private static EELFLogger logger = EELFManager.getInstance().getLogger(NodeServlet.class);
 
     DRNodeCadiFilter(boolean init, PropAccess access) throws ServletException {
@@ -41,23 +42,16 @@ public class DRNodeCadiFilter extends CadiFilter {
     }
 
     @Override
-    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+            throws IOException, ServletException {
         HttpServletRequest httpRequest = (HttpServletRequest) request;
         String path = httpRequest.getPathInfo();
         if (!(path.startsWith("/internal"))) {
-            if (!(httpRequest.getMethod().equalsIgnoreCase("POST"))) {
-                if (httpRequest.getMethod().equalsIgnoreCase("DELETE") && path.startsWith("/delete")) {
+            if (!("POST".equalsIgnoreCase(httpRequest.getMethod()))) {
+                if ("DELETE".equalsIgnoreCase(httpRequest.getMethod()) && path.startsWith("/delete")) {
                     chain.doFilter(request, response);
                 } else {
-                    String feedId = getFeedId(request, response);
-                    String aafDbInstance = NodeConfigManager.getInstance().getAafInstance(feedId);
-                    if (aafDbInstance != null && !aafDbInstance.equals("") && !aafDbInstance.equalsIgnoreCase("legacy")) {
-                        logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "AAF Instance -" + aafDbInstance);
-                        super.doFilter(request, response, chain);
-                    } else {
-                        logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "Legacy Feed");
-                        chain.doFilter(request, response);
-                    }
+                    doFilterWithFeedId(request, response, chain);
                 }
             }
         } else {
@@ -72,9 +66,10 @@ public class DRNodeCadiFilter extends CadiFilter {
         if (fileid == null) {
             logger.error("NODE0105 Rejecting bad URI for PUT " + req.getPathInfo() + " from " + req.getRemoteAddr());
             try {
-                resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                resp.sendError(HttpServletResponse.SC_NOT_FOUND,
+                        "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
             } catch (IOException e) {
-                logger.error("NODE0541 DRNodeCadiFilter.getFeedId: ", e.getMessage());
+                logger.error("NODE0541 DRNodeCadiFilter.getFeedId: ", e);
             }
             return null;
         }
@@ -82,19 +77,34 @@ public class DRNodeCadiFilter extends CadiFilter {
 
         if (fileid.startsWith("/publish/")) {
             fileid = fileid.substring(9);
-            int i = fileid.indexOf('/');
-            if (i == -1 || i == fileid.length() - 1) {
-                logger.error("NODE0105 Rejecting bad URI for PUT (publish) of " + req.getPathInfo() + " from " + req.getRemoteAddr());
+            int index = fileid.indexOf('/');
+            if (index == -1 || index == fileid.length() - 1) {
+                logger.error("NODE0105 Rejecting bad URI for PUT (publish) of " + req.getPathInfo() + " from " + req
+                        .getRemoteAddr());
                 try {
-                    resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");
+                    resp.sendError(HttpServletResponse.SC_NOT_FOUND,
+                            "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  "
+                                    + "Possible missing fileid.");
                 } catch (IOException e) {
-                    logger.error("NODE0542 DRNodeCadiFilter.getFeedId: ", e.getMessage());
+                    logger.error("NODE0542 DRNodeCadiFilter.getFeedId: ", e);
                 }
                 return null;
             }
-            feedid = fileid.substring(0, i);
+            feedid = fileid.substring(0, index);
         }
         return feedid;
     }
 
+    private void doFilterWithFeedId(ServletRequest request, ServletResponse response, FilterChain chain)
+            throws IOException, ServletException {
+        String feedId = getFeedId(request, response);
+        String aafDbInstance = NodeConfigManager.getInstance().getAafInstance(feedId);
+        if (aafDbInstance != null && !"".equals(aafDbInstance) && !"legacy".equalsIgnoreCase(aafDbInstance)) {
+            logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "AAF Instance -" + aafDbInstance);
+            super.doFilter(request, response, chain);
+        } else {
+            logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "Legacy Feed");
+            chain.doFilter(request, response);
+        }
+    }
 }
index 501e489..150d2aa 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-import java.util.*;
-import java.io.*;
-
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Objects;
 
 /**
  * Main control point for delivering files to destinations.
- * <p>
- * The Delivery class manages assignment of delivery threads to delivery
- * queues and creation and destruction of delivery queues as
- * configuration changes.  DeliveryQueues are assigned threads based on a
- * modified round-robin approach giving priority to queues with more work
- * as measured by both bytes to deliver and files to deliver and lower
- * priority to queues that already have delivery threads working.
- * A delivery thread continues to work for a delivery queue as long as
- * that queue has more files to deliver.
+ *
+ * <p>The Delivery class manages assignment of delivery threads to delivery queues and creation and destruction of
+ * delivery queues as configuration changes. DeliveryQueues are assigned threads based on a modified round-robin
+ * approach giving priority to queues with more work as measured by both bytes to deliver and files to deliver and lower
+ * priority to queues that already have delivery threads working. A delivery thread continues to work for a delivery
+ * queue as long as that queue has more files to deliver.
  */
 public class Delivery {
-    private static EELFLogger logger = EELFManager.getInstance().getLogger(Delivery.class);
-
-    private static class DelItem implements Comparable<DelItem> {
-        private String pubid;
-        private String spool;
-
-        public int compareTo(DelItem x) {
-            int i = pubid.compareTo(x.pubid);
-            if (i == 0) {
-                i = spool.compareTo(x.spool);
-            }
-            return (i);
-        }
-
-        public String getPublishId() {
-            return (pubid);
-        }
-
-        public String getSpool() {
-            return (spool);
-        }
-
-        public DelItem(String pubid, String spool) {
-            this.pubid = pubid;
-            this.spool = spool;
-        }
-    }
 
+    private static final String TOTAL = " total=";
+    private static final String YELLOW = " yellow=";
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(Delivery.class);
     private double fdstart;
     private double fdstop;
     private int threads;
     private int curthreads;
     private NodeConfigManager config;
-    private Hashtable<String, DeliveryQueue> dqs = new Hashtable<String, DeliveryQueue>();
+    private HashMap<String, DeliveryQueue> dqs = new HashMap<>();
     private DeliveryQueue[] queues = new DeliveryQueue[0];
     private int qpos = 0;
     private long nextcheck;
-    private Runnable cmon = new Runnable() {
-        public void run() {
-            checkconfig();
-        }
-    };
 
     /**
      * Constructs a new Delivery system using the specified configuration manager.
@@ -92,10 +62,37 @@ public class Delivery {
      */
     public Delivery(NodeConfigManager config) {
         this.config = config;
+        Runnable cmon = this::checkconfig;
         config.registerConfigTask(cmon);
         checkconfig();
     }
 
+    /**
+     * Reset the retry timer for a delivery queue.
+     */
+    public synchronized void resetQueue(String spool) {
+        if (spool != null) {
+            DeliveryQueue dq = dqs.get(spool);
+            if (dq != null) {
+                dq.resetQueue();
+            }
+        }
+    }
+
+    /**
+     * Mark the task in spool a success.
+     */
+    public synchronized boolean markTaskSuccess(String spool, String pubId) {
+        boolean succeeded = false;
+        if (spool != null) {
+            DeliveryQueue dq = dqs.get(spool);
+            if (dq != null) {
+                succeeded = dq.markTaskSuccess(pubId);
+            }
+        }
+        return succeeded;
+    }
+
     private void cleardir(String dir) {
         if (dqs.get(dir) != null) {
             return;
@@ -113,12 +110,11 @@ public class Delivery {
         File spoolfile = new File(config.getSpoolBase());
         long tspace = spoolfile.getTotalSpace();
         long start = (long) (tspace * fdstart);
-        long stop = (long) (tspace * fdstop);
         long cur = spoolfile.getUsableSpace();
         if (cur >= start) {
             return;
         }
-        Vector<DelItem> cv = new Vector<DelItem>();
+        ArrayList<DelItem> cv = new ArrayList<>();
         for (String sdir : dqs.keySet()) {
             for (String meta : (new File(sdir)).list()) {
                 if (!meta.endsWith(".M") || meta.charAt(0) == '.') {
@@ -129,27 +125,21 @@ public class Delivery {
         }
         DelItem[] items = cv.toArray(new DelItem[cv.size()]);
         Arrays.sort(items);
-        logger.info("NODE0501 Free disk space below red threshold.  current=" + cur + " red=" + start + " total=" + tspace);
-        for (DelItem item : items) {
-            long amount = dqs.get(item.getSpool()).cancelTask(item.getPublishId());
-            logger.info("NODE0502 Attempting to discard " + item.getSpool() + "/" + item.getPublishId() + " to free up disk");
-            if (amount > 0) {
-                cur += amount;
-                if (cur >= stop) {
-                    cur = spoolfile.getUsableSpace();
-                }
-                if (cur >= stop) {
-                    logger.info("NODE0503 Free disk space at or above yellow threshold.  current=" + cur + " yellow=" + stop + " total=" + tspace);
-                    return;
-                }
-            }
+        long stop = (long) (tspace * fdstop);
+        logger.info(
+                "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 + " total=" + tspace);
+            logger.info("NODE0503 Free disk space at or above yellow threshold.  current=" + cur + YELLOW + stop
+                                + TOTAL + tspace);
             return;
         }
-        logger.warn("NODE0504 Unable to recover sufficient disk space to reach green status.  current=" + cur + " yellow=" + stop + " total=" + tspace);
+        logger.warn(
+                "NODE0504 Unable to recover sufficient disk space to reach green status.  current=" + cur + YELLOW
+                        + stop + TOTAL + tspace);
     }
 
     private void cleardirs() {
@@ -188,7 +178,7 @@ public class Delivery {
         DestInfo[] alldis = config.getAllDests();
         DeliveryQueue[] nqs = new DeliveryQueue[alldis.length];
         qpos = 0;
-        Hashtable<String, DeliveryQueue> ndqs = new Hashtable<String, DeliveryQueue>();
+        HashMap<String, DeliveryQueue> ndqs = new HashMap<>();
         for (DestInfo di : alldis) {
             String spl = di.getSpool();
             DeliveryQueue dq = dqs.get(spl);
@@ -205,11 +195,8 @@ public class Delivery {
         cleardirs();
         while (curthreads < threads) {
             curthreads++;
-            (new Thread() {
-                {
-                    setName("Delivery Thread");
-                }
-
+            (new Thread("del-thread-" + curthreads) {
+                @Override
                 public void run() {
                     dodelivery();
                 }
@@ -246,6 +233,7 @@ public class Delivery {
                 try {
                     wait(nextcheck + 500 - now);
                 } catch (Exception e) {
+                    logger.error("InterruptedException", e);
                 }
                 now = System.currentTimeMillis();
             }
@@ -257,29 +245,69 @@ public class Delivery {
         }
     }
 
-    /**
-     * Reset the retry timer for a delivery queue
-     */
-    public synchronized void resetQueue(String spool) {
-        if (spool != null) {
-            DeliveryQueue dq = dqs.get(spool);
-            if (dq != null) {
-                dq.resetQueue();
+    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()
+                                + " to free up disk");
+            if (amount > 0) {
+                cur += amount;
+                if (cur >= stop) {
+                    cur = spoolfile.getUsableSpace();
+                }
+                if (cur >= stop) {
+                    logger.info(
+                            "NODE0503 Free disk space at or above yellow threshold.  current=" + cur + YELLOW + stop
+                                    + TOTAL + tspace);
+                    return true;
+                }
             }
         }
+        return false;
     }
 
-    /**
-     * Mark the task in spool a success
-     */
-    public synchronized boolean markTaskSuccess(String spool, String pubId) {
-        boolean succeeded = false;
-        if (spool != null) {
-            DeliveryQueue dq = dqs.get(spool);
-            if (dq != null) {
-                succeeded = dq.markTaskSuccess(pubId);
+    static class DelItem implements Comparable<DelItem> {
+
+        private String pubid;
+        private String spool;
+
+        public DelItem(String pubid, String spool) {
+            this.pubid = pubid;
+            this.spool = spool;
+        }
+
+        public int compareTo(DelItem other) {
+            int diff = pubid.compareTo(other.pubid);
+            if (diff == 0) {
+                diff = spool.compareTo(other.spool);
             }
+            return (diff);
+        }
+
+        public String getPublishId() {
+            return (pubid);
+        }
+
+        public String getSpool() {
+            return (spool);
+        }
+
+        @Override
+        public boolean equals(Object object) {
+            if (this == object) {
+                return true;
+            }
+            if (object == null || getClass() != object.getClass()) {
+                return false;
+            }
+            DelItem delItem = (DelItem) object;
+            return Objects.equals(pubid, delItem.pubid)
+                           && Objects.equals(getSpool(), delItem.getSpool());
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(pubid, getSpool());
         }
-        return succeeded;
     }
 }
index bef8dab..0ba9ecf 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import java.io.*;
 import java.util.*;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Mechanism for monitoring and controlling delivery of files to a destination.
@@ -64,6 +67,7 @@ import java.util.*;
  * failure timer is active or if no files are found in a directory scan.
  */
 public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(DeliveryQueue.class);
     private DeliveryQueueHelper deliveryQueueHelper;
     private DestInfo destinationInfo;
     private Hashtable<String, DeliveryTask> working = new Hashtable<>();
@@ -113,6 +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.");
         task.clean();
         failed = false;
         failduration = 0;
@@ -122,6 +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.");
         task.clean();
     }
 
@@ -130,6 +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");
         task.clean();
         failed = false;
         failduration = 0;
@@ -159,6 +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.");
         retry.put(task.getPublishId(), task);
     }
 
@@ -167,6 +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.");
         retry.put(task.getPublishId(), task);
         fdupdate();
     }
@@ -202,53 +211,15 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
                 todo = new Vector<>();
                 String[] files = dir.list();
                 Arrays.sort(files);
-                for (String fname : files) {
-                    if (!fname.endsWith(".M")) {
-                        continue;
-                    }
-                    String fname2 = fname.substring(0, fname.length() - 2);
-                    long pidtime = 0;
-                    int dot = fname2.indexOf('.');
-                    if (dot < 1) {
-                        continue;
-                    }
-                    try {
-                        pidtime = Long.parseLong(fname2.substring(0, dot));
-                    } catch (Exception e) {
-                    }
-                    if (pidtime < 1000000000000L) {
-                        continue;
-                    }
-                    if (working.get(fname2) != null) {
-                        continue;
-                    }
-                    DeliveryTask dt = retry.get(fname2);
-                    if (dt == null) {
-                        dt = new DeliveryTask(this, fname2);
-                    }
-                    todo.add(dt);
-                }
+                scanForNextTask(files);
                 retry = new Hashtable<>();
             }
-            if (todoindex < todo.size()) {
-                DeliveryTask dt = todo.get(todoindex);
-                if (dt.isCleaned()) {
-                    todoindex++;
-                    continue;
-                }
-                if (destinationInfo.isPrivilegedSubscriber() && dt.getResumeTime() > System.currentTimeMillis()) {
-                    retry.put(dt.getPublishId(), dt);
-                    todoindex++;
-                    continue;
-                }
-                if (dt.getDate() >= mindate) {
-                    return (dt);
-                }
-                todoindex++;
-                reportExpiry(dt);
-                continue;
+            DeliveryTask dt = getDeliveryTask(mindate);
+            if (dt != null) {
+                return dt;
             }
-            return (null);
+            return null;
+
         }
     }
 
@@ -359,11 +330,12 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
      * files to deliver
      */
     public void run() {
-        DeliveryTask t;
+        DeliveryTask task;
         long endtime = System.currentTimeMillis() + deliveryQueueHelper.getFairTimeLimit();
         int filestogo = deliveryQueueHelper.getFairFileLimit();
-        while ((t = getNext()) != null) {
-            t.run();
+        while ((task = getNext()) != null) {
+            logger.debug("Processing file: " + task.getPublishId());
+            task.run();
             if (--filestogo <= 0 || System.currentTimeMillis() > endtime) {
                 break;
             }
@@ -403,4 +375,62 @@ public class DeliveryQueue implements Runnable, DeliveryTaskHelper {
         }
         return false;
     }
+    private void scanForNextTask(String[] files) {
+        for (String fname : files) {
+            String pubId = getPubId(fname);
+            if (pubId == null) {
+                continue;
+            }
+            DeliveryTask dt = retry.get(pubId);
+            if (dt == null) {
+                dt = new DeliveryTask(this, pubId);
+            }
+            todo.add(dt);
+        }
+    }
+
+    @Nullable
+    private DeliveryTask getDeliveryTask(long mindate) {
+        if (todoindex < todo.size()) {
+            DeliveryTask dt = todo.get(todoindex);
+            if (dt.isCleaned()) {
+                todoindex++;
+            }
+            if (destinationInfo.isPrivilegedSubscriber() && dt.getResumeTime() > System.currentTimeMillis()) {
+                retry.put(dt.getPublishId(), dt);
+                todoindex++;
+            }
+            if (dt.getDate() >= mindate) {
+                return (dt);
+            }
+            todoindex++;
+            reportExpiry(dt);
+        }
+        return null;
+    }
+
+    @Nullable
+    private String getPubId(String fname) {
+        if (!fname.endsWith(".M")) {
+            return null;
+        }
+        String fname2 = fname.substring(0, fname.length() - 2);
+        long pidtime = 0;
+        int dot = fname2.indexOf('.');
+        if (dot < 1) {
+            return null;
+        }
+        try {
+            pidtime = Long.parseLong(fname2.substring(0, dot));
+        } catch (Exception e) {
+            logger.error("Exception", e);
+        }
+        if (pidtime < 1000000000000L) {
+            return null;
+        }
+        if (working.get(fname2) != null) {
+            return null;
+        }
+        return fname2;
+    }
 }
index cca6170..7ed3592 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-import java.io.*;
-import java.net.*;
-import java.util.*;
-import java.util.zip.GZIPInputStream;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+import static org.onap.dmaap.datarouter.node.NodeUtils.isFiletypeGzip;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.ProtocolException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.UUID;
+import java.util.zip.GZIPInputStream;
+import org.jetbrains.annotations.Nullable;
 import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
 import org.slf4j.MDC;
 
-import static com.att.eelf.configuration.Configuration.*;
-import static org.onap.dmaap.datarouter.node.NodeUtils.isFiletypeGzip;
-
 /**
  * A file to be delivered to a destination.
- * <p>
- * A Delivery task represents a work item for the data router - a file that
- * needs to be delivered and provides mechanisms to get information about
- * the file and its delivery data as well as to attempt delivery.
+ *
+ * <p>A Delivery task represents a work item for the data router - a file that needs to be delivered and provides
+ * mechanisms to get information about the file and its delivery data as well as to attempt delivery.
  */
 public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
-    private static EELFLogger eelfLogger = EELFManager.getInstance()
-            .getLogger(DeliveryTask.class);
+
+    private static final String DECOMPRESSION_STATUS = "Decompression_Status";
+    private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(DeliveryTask.class);
     private DeliveryTaskHelper deliveryTaskHelper;
     private String pubid;
     private DestInfo destInfo;
@@ -69,12 +80,11 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
 
 
     /**
-     * Create a delivery task for a given delivery queue and pub ID
+     * Create a delivery task for a given delivery queue and pub ID.
      *
      * @param deliveryTaskHelper The delivery task helper for the queue this task is in.
-     * @param pubid              The publish ID for this file.  This is used as
-     *                           the base for the file name in the spool directory and is of
-     *                           the form <milliseconds since 1970>.<fqdn of initial data router node>
+     * @param pubid The publish ID for this file.  This is used as the base for the file name in the spool directory and
+     *      is of the form (milliseconds since 1970).(fqdn of initial data router node)
      */
     DeliveryTask(DeliveryTaskHelper deliveryTaskHelper, String pubid) {
         this.deliveryTaskHelper = deliveryTaskHelper;
@@ -84,70 +94,70 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
         this.followRedirects = destInfo.isFollowRedirects();
         feedid = destInfo.getLogData();
         spool = destInfo.getSpool();
-        String dfn = spool + "/" + pubid;
+        String dfn = spool + File.separator + pubid;
         String mfn = dfn + ".M";
-        datafile = new File(spool + "/" + pubid);
+        datafile = new File(spool + File.separator + pubid);
         metafile = new File(mfn);
         boolean monly = destInfo.isMetaDataOnly();
         date = Long.parseLong(pubid.substring(0, pubid.indexOf('.')));
         resumeTime = System.currentTimeMillis();
-        Vector<String[]> hdrv = new Vector<>();
+        ArrayList<String[]> hdrv = new ArrayList<>();
 
         try (BufferedReader br = new BufferedReader(new FileReader(metafile))) {
-            String s = br.readLine();
-            int i = s.indexOf('\t');
-            method = s.substring(0, i);
+            String line = br.readLine();
+            int index = line.indexOf('\t');
+            method = line.substring(0, index);
             NodeUtils.setIpAndFqdnForEelf(method);
             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-dmaap-dr-routing".equalsIgnoreCase(h)) {
-                    subid = v.replaceAll("[^ ]*/", "");
+            fileid = line.substring(index + 1);
+            while ((line = br.readLine()) != null) {
+                index = line.indexOf('\t');
+                String header = line.substring(0, index);
+                String headerValue = line.substring(index + 1);
+                if ("x-dmaap-dr-routing".equalsIgnoreCase(header)) {
+                    subid = headerValue.replaceAll("[^ ]*/", "");
                     feedid = deliveryTaskHelper.getFeedId(subid.replaceAll(" .*", ""));
                 }
-                if (length == 0 && h.toLowerCase().startsWith("content-")) {
+                if (length == 0 && header.toLowerCase().startsWith("content-")) {
                     continue;
                 }
-                if (h.equalsIgnoreCase("content-type")) {
-                    ctype = v;
+                if ("content-type".equalsIgnoreCase(header)) {
+                    ctype = headerValue;
                 }
-                if (h.equalsIgnoreCase("x-onap-requestid")) {
-                    MDC.put(MDC_KEY_REQUEST_ID, v);
+                if ("x-onap-requestid".equalsIgnoreCase(header)) {
+                    MDC.put(MDC_KEY_REQUEST_ID, headerValue);
                 }
-                if (h.equalsIgnoreCase("x-invocationid")) {
-                    MDC.put("InvocationId", v);
-                    v = UUID.randomUUID().toString();
-                    newInvocationId = v;
+                if ("x-invocationid".equalsIgnoreCase(header)) {
+                    MDC.put("InvocationId", headerValue);
+                    headerValue = UUID.randomUUID().toString();
+                    newInvocationId = headerValue;
                 }
-                hdrv.add(new String[]{h, v});
+                hdrv.add(new String[]{header, headerValue});
             }
         } catch (Exception e) {
-            eelfLogger.error("Exception "+ Arrays.toString(e.getStackTrace()), e.getMessage());
+            eelfLogger.error("Exception", e);
         }
         hdrs = hdrv.toArray(new String[hdrv.size()][]);
         url = deliveryTaskHelper.getDestURL(fileid);
     }
 
     /**
-     * Is the object a DeliveryTask with the same publication ID?
+     * Is the object a DeliveryTask with the same publication ID.
      */
-    public boolean equals(Object o) {
-        if (!(o instanceof DeliveryTask)) {
+    public boolean equals(Object object) {
+        if (!(object instanceof DeliveryTask)) {
             return (false);
         }
-        return (pubid.equals(((DeliveryTask) o).pubid));
+        return (pubid.equals(((DeliveryTask) object).pubid));
     }
 
     /**
      * Compare the publication IDs.
      */
-    public int compareTo(DeliveryTask o) {
-        return (pubid.compareTo(o.pubid));
+    public int compareTo(DeliveryTask other) {
+        return (pubid.compareTo(other.pubid));
     }
 
     /**
@@ -165,79 +175,49 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
     }
 
     /**
-     * Get the publish ID
+     * Get the publish ID.
      */
     String getPublishId() {
         return (pubid);
     }
 
     /**
-     * Attempt delivery
+     * Attempt delivery.
      */
     public void run() {
         attempts++;
         try {
             destInfo = deliveryTaskHelper.getDestinationInfo();
-            boolean expect100 = destInfo.isUsing100();
             boolean monly = destInfo.isMetaDataOnly();
             length = 0;
             if (!"DELETE".equals(method) && !monly) {
                 length = datafile.length();
             }
-            if (destInfo.isDecompress() && isFiletypeGzip(datafile) && fileid.endsWith(".gz")){
-                    fileid = fileid.replace(".gz", "");
-            }
+            stripSuffixIfIsDecompress();
             url = deliveryTaskHelper.getDestURL(fileid);
-            URL u = new URL(url);
-            HttpURLConnection uc = (HttpURLConnection) u.openConnection();
-            uc.setConnectTimeout(60000);
-            uc.setReadTimeout(60000);
-            uc.setInstanceFollowRedirects(false);
-            uc.setRequestMethod(method);
-            uc.setRequestProperty("Content-Length", Long.toString(length));
-            uc.setRequestProperty("Authorization", destInfo.getAuth());
-            uc.setRequestProperty("X-DMAAP-DR-PUBLISH-ID", pubid);
-            for (String[] nv : hdrs) {
-                uc.addRequestProperty(nv[0], nv[1]);
-            }
-            if (length > 0) {
-                if (expect100) {
-                    uc.setRequestProperty("Expect", "100-continue");
-                }
-                uc.setDoOutput(true);
-                if (destInfo.isDecompress()) {
-                    if (isFiletypeGzip(datafile)) {
-                        sendDecompressedFile(uc);
-                    } else {
-                        uc.setRequestProperty("Decompression_Status", "UNSUPPORTED_FORMAT");
-                        sendFile(uc);
-                    }
-                } else {
-                    sendFile(uc);
-                }
-            }
-            int rc = uc.getResponseCode();
-            String rmsg = uc.getResponseMessage();
-            if (rmsg == null) {
-                String h0 = uc.getHeaderField(0);
-                if (h0 != null) {
-                    int i = h0.indexOf(' ');
-                    int j = h0.indexOf(' ', i + 1);
-                    if (i != -1 && j != -1) {
-                        rmsg = h0.substring(j + 1);
-                    }
-                }
-            }
+            URL urlObj = new URL(url);
+            HttpURLConnection urlConnection = (HttpURLConnection) urlObj.openConnection();
+            urlConnection.setConnectTimeout(60000);
+            urlConnection.setReadTimeout(60000);
+            urlConnection.setInstanceFollowRedirects(false);
+            urlConnection.setRequestMethod(method);
+            urlConnection.setRequestProperty("Content-Length", Long.toString(length));
+            urlConnection.setRequestProperty("Authorization", destInfo.getAuth());
+            urlConnection.setRequestProperty("X-DMAAP-DR-PUBLISH-ID", pubid);
+            boolean expect100 = destInfo.isUsing100();
+            int rc = deliverFileToSubscriber(expect100, urlConnection);
+            String rmsg = urlConnection.getResponseMessage();
+            rmsg = getResponseMessage(urlConnection, rmsg);
             String xpubid = null;
             InputStream is;
             if (rc >= 200 && rc <= 299) {
-                is = uc.getInputStream();
-                xpubid = uc.getHeaderField("X-DMAAP-DR-PUBLISH-ID");
+                is = urlConnection.getInputStream();
+                xpubid = urlConnection.getHeaderField("X-DMAAP-DR-PUBLISH-ID");
             } else {
                 if (rc >= 300 && rc <= 399) {
-                    rmsg = uc.getHeaderField("Location");
+                    rmsg = urlConnection.getHeaderField("Location");
                 }
-                is = uc.getErrorStream();
+                is = urlConnection.getErrorStream();
             }
             byte[] buf = new byte[4096];
             if (is != null) {
@@ -247,23 +227,22 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
             }
             deliveryTaskHelper.reportStatus(this, rc, xpubid, rmsg);
         } catch (Exception e) {
-            eelfLogger.error("Exception "+ Arrays.toString(e.getStackTrace()),e);
+            eelfLogger.error("Exception " + Arrays.toString(e.getStackTrace()), e);
             deliveryTaskHelper.reportException(this, e);
         }
     }
 
     /**
-     * To send decompressed gzip to the subscribers
+     * To send decompressed gzip to the subscribers.
      *
      * @param httpURLConnection connection used to make request
-     * @throws IOException
      */
     private void sendDecompressedFile(HttpURLConnection httpURLConnection) throws IOException {
         byte[] buffer = new byte[8164];
-        httpURLConnection.setRequestProperty("Decompression_Status", "SUCCESS");
+        httpURLConnection.setRequestProperty(DECOMPRESSION_STATUS, "SUCCESS");
         OutputStream outputStream = getOutputStream(httpURLConnection);
         if (outputStream != null) {
-            int bytesRead = 0;
+            int bytesRead;
             try (InputStream gzipInputStream = new GZIPInputStream(new FileInputStream(datafile))) {
                 int bufferLength = buffer.length;
                 while ((bytesRead = gzipInputStream.read(buffer, 0, bufferLength)) > 0) {
@@ -271,8 +250,8 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
                 }
                 outputStream.close();
             } catch (IOException e) {
-                httpURLConnection.setRequestProperty("Decompression_Status", "FAILURE");
-                eelfLogger.info("Could not decompress file");
+                httpURLConnection.setRequestProperty(DECOMPRESSION_STATUS, "FAILURE");
+                eelfLogger.info("Could not decompress file", e);
                 sendFile(httpURLConnection);
             }
 
@@ -283,44 +262,42 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
      * To send any file to the subscriber.
      *
      * @param httpURLConnection connection used to make request
-     * @throws IOException
      */
     private void sendFile(HttpURLConnection httpURLConnection) throws IOException {
         OutputStream os = getOutputStream(httpURLConnection);
-        if (os != null) {
-            long sofar = 0;
-            try (InputStream is = new FileInputStream(datafile)) {
-                byte[] buf = new byte[1024 * 1024];
-                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);
+        if (os == null) {
+            return;
+        }
+        long sofar = 0;
+        try (InputStream is = new FileInputStream(datafile)) {
+            byte[] buf = new byte[1024 * 1024];
+            while (sofar < length) {
+                int len = buf.length;
+                if (sofar + len > length) {
+                    len = (int) (length - sofar);
                 }
-                os.close();
-            } catch (IOException ioe) {
-                deliveryTaskHelper.reportDeliveryExtra(this, sofar);
-                throw ioe;
+                len = is.read(buf, 0, len);
+                if (len <= 0) {
+                    throw new IOException("Unexpected problem reading data file " + datafile);
+                }
+                sofar += len;
+                os.write(buf, 0, len);
             }
+            os.close();
+        } catch (IOException ioe) {
+            deliveryTaskHelper.reportDeliveryExtra(this, sofar);
+            throw ioe;
         }
     }
 
     /**
-     * Get the outputstream that will be used to send data
+     * Get the outputstream that will be used to send data.
      *
      * @param httpURLConnection connection used to make request
      * @return AN Outpustream that can be used to send your data.
-     * @throws IOException
      */
     private OutputStream getOutputStream(HttpURLConnection httpURLConnection) throws IOException {
         OutputStream outputStream = null;
-
         try {
             outputStream = httpURLConnection.getOutputStream();
         } catch (ProtocolException pe) {
@@ -331,22 +308,74 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
         return outputStream;
     }
 
+    private void stripSuffixIfIsDecompress() {
+        if (destInfo.isDecompress() && isFiletypeGzip(datafile) && fileid.endsWith(".gz")) {
+            fileid = fileid.replace(".gz", "");
+        }
+    }
+
+    private int deliverFileToSubscriber(boolean expect100, HttpURLConnection uc) throws IOException {
+        for (String[] nv : hdrs) {
+            uc.addRequestProperty(nv[0], nv[1]);
+        }
+        if (length > 0) {
+            if (expect100) {
+                uc.setRequestProperty("Expect", "100-continue");
+            }
+            uc.setDoOutput(true);
+            if (destInfo.isDecompress()) {
+                if (isFiletypeGzip(datafile)) {
+                    sendDecompressedFile(uc);
+                } else {
+                    uc.setRequestProperty(DECOMPRESSION_STATUS, "UNSUPPORTED_FORMAT");
+                    sendFile(uc);
+                }
+            } else {
+                sendFile(uc);
+            }
+        }
+        return uc.getResponseCode();
+    }
+
+    @Nullable
+    private String getResponseMessage(HttpURLConnection uc, String rmsg) {
+        if (rmsg == null) {
+            String h0 = uc.getHeaderField(0);
+            if (h0 != null) {
+                int indexOfSpace1 = h0.indexOf(' ');
+                int indexOfSpace2 = h0.indexOf(' ', indexOfSpace1 + 1);
+                if (indexOfSpace1 != -1 && indexOfSpace2 != -1) {
+                    rmsg = h0.substring(indexOfSpace2 + 1);
+                }
+            }
+        }
+        return rmsg;
+    }
+
     /**
-     * Remove meta and data files
+     * Remove meta and data files.
      */
     void clean() {
-        datafile.delete();
-        metafile.delete();
+        deleteWithRetry(datafile);
+        deleteWithRetry(metafile);
         eelfLogger.info(EelfMsgs.INVOKE, newInvocationId);
         eelfLogger.info(EelfMsgs.EXIT);
         hdrs = null;
     }
 
-    /**
-     * Set the resume time for a delivery task.
-     */
-    void setResumeTime(long resumeTime) {
-        this.resumeTime = resumeTime;
+    private void deleteWithRetry(File file) {
+        int maxTries = 3;
+        int tryCount = 1;
+        while (tryCount <= maxTries) {
+            try {
+                Files.deleteIfExists(file.toPath());
+                break;
+            } catch (IOException e) {
+                eelfLogger.error("IOException : Failed to delete file :"
+                                         + file.getName() + " on attempt " + tryCount, e);
+            }
+            tryCount++;
+        }
     }
 
     /**
@@ -357,14 +386,21 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
     }
 
     /**
-     * Has this delivery task been cleaned?
+     * Set the resume time for a delivery task.
+     */
+    void setResumeTime(long resumeTime) {
+        this.resumeTime = resumeTime;
+    }
+
+    /**
+     * Has this delivery task been cleaned.
      */
     boolean isCleaned() {
         return (hdrs == null);
     }
 
     /**
-     * Get length of body
+     * Get length of body.
      */
     public long getLength() {
         return (length);
@@ -378,58 +414,58 @@ public class DeliveryTask implements Runnable, Comparable<DeliveryTask> {
     }
 
     /**
-     * Get the most recent delivery attempt URL
+     * Get the most recent delivery attempt URL.
      */
     public String getURL() {
         return (url);
     }
 
     /**
-     * Get the content type
+     * Get the content type.
      */
     String getCType() {
         return (ctype);
     }
 
     /**
-     * Get the method
+     * Get the method.
      */
     String getMethod() {
         return (method);
     }
 
     /**
-     * Get the file ID
+     * Get the file ID.
      */
     String getFileId() {
         return (fileid);
     }
 
     /**
-     * Get the number of delivery attempts
+     * Get the number of delivery attempts.
      */
     int getAttempts() {
         return (attempts);
     }
 
     /**
-     * Get the (space delimited list of) subscription ID for this delivery task
+     * Get the (space delimited list of) subscription ID for this delivery task.
      */
     String getSubId() {
         return (subid);
     }
 
     /**
-     * Get the feed ID for this delivery task
+     * Get the feed ID for this delivery task.
      */
     String getFeedId() {
         return (feedid);
     }
 
     /**
-     * Get the followRedirects for this delivery task
+     * Get the followRedirects for this delivery task.
      */
-    public boolean getFollowRedirects() {
-        return(followRedirects);
+    boolean getFollowRedirects() {
+        return (followRedirects);
     }
 }
index d4ac8bd..b9068f2 100644 (file)
@@ -26,32 +26,33 @@ package org.onap.dmaap.datarouter.node;
 
 /**
  * Interface to allow independent testing of the DeliveryTask code.
- * <p>
- * This interface represents all the configuraiton information and
- * feedback mechanisms that a delivery task needs.
+ *
+ * <p>This interface represents all the configuraiton information and feedback mechanisms that a delivery task needs.
  */
 
 public interface DeliveryTaskHelper {
+
     /**
-     * Report that a delivery attempt failed due to an exception (like can't connect to remote host)
+     * Report that a delivery attempt failed due to an exception (like can't connect to remote host).
      *
-     * @param task      The task that failed
+     * @param task The task that failed
      * @param exception The exception that occurred
      */
     void reportException(DeliveryTask task, Exception exception);
 
     /**
-     * Report that a delivery attempt completed (successfully or unsuccessfully)
+     * Report that a delivery attempt completed (successfully or unsuccessfully).
      *
-     * @param task     The task that failed
-     * @param status   The HTTP status
-     * @param xpubid   The publish ID from the far end (if any)
+     * @param task The task that failed
+     * @param status The HTTP status
+     * @param xpubid The publish ID from the far end (if any)
      * @param location The redirection location for a 3XX response
      */
     void reportStatus(DeliveryTask task, int status, String xpubid, String location);
 
     /**
-     * Report that a delivery attempt either failed while sending data or that an error was returned instead of a 100 Continue.
+     * Report that a delivery attempt either failed while sending data or that an error was returned instead of a 100
+     * Continue.
      *
      * @param task The task that failed
      * @param sent The number of bytes sent or -1 if an error was returned instead of 100 Continue.
@@ -59,14 +60,14 @@ public interface DeliveryTaskHelper {
     void reportDeliveryExtra(DeliveryTask task, long sent);
 
     /**
-     * Get the destination information for the delivery queue
+     * Get the destination information for the delivery queue.
      *
      * @return The destination information
      */
     DestInfo getDestinationInfo();
 
     /**
-     * Given a file ID, get the URL to deliver to
+     * Given a file ID, get the URL to deliver to.
      *
      * @param fileid The file id
      * @return The URL to deliver to
@@ -74,7 +75,7 @@ public interface DeliveryTaskHelper {
     String getDestURL(String fileid);
 
     /**
-     * Get the feed ID for a subscription
+     * Get the feed ID for a subscription.
      *
      * @param subid The subscription ID
      * @return The feed iD
index 8890fe9..f5fa6e9 100644 (file)
 package org.onap.dmaap.datarouter.node;
 
 /**
- * Information for a delivery destination that doesn't change from message to message
+ * Information for a delivery destination that doesn't change from message to message.
  */
 public class DestInfo {
+
     private String name;
     private String spool;
     private String subid;
@@ -40,114 +41,33 @@ public class DestInfo {
     private boolean privilegedSubscriber;
     private boolean decompress;
     private boolean followRedirects;
-    private String aafInstance;
-
-    public static class DestInfoBuilder {
-        private String name;
-        private String spool;
-        private String subid;
-        private String logdata;
-        private String url;
-        private String authuser;
-        private String authentication;
-        private boolean metaonly;
-        private boolean use100;
-        private boolean privilegedSubscriber;
-        private boolean followRedirects;
-        private boolean decompress;
-        private NodeConfig.ProvSubscription subscription;
-
-        public DestInfoBuilder setName(String name) {
-            this.name = name;
-            return this;
-        }
-
-        public DestInfoBuilder setSpool(String spool) {
-            this.spool = spool;
-            return this;
-        }
-
-        public DestInfoBuilder setSubid(String subid) {
-            this.subid = subid;
-            return this;
-        }
-
-        public DestInfoBuilder setLogdata(String logdata) {
-            this.logdata = logdata;
-            return this;
-        }
-
-        public DestInfoBuilder setUrl(String url) {
-            this.url = url;
-            return this;
-        }
-
-        public DestInfoBuilder setAuthuser(String authuser) {
-            this.authuser = authuser;
-            return this;
-        }
-
-        public DestInfoBuilder setAuthentication(String authentication) {
-            this.authentication = authentication;
-            return this;
-        }
-
-        public DestInfoBuilder setMetaonly(boolean metaonly) {
-            this.metaonly = metaonly;
-            return this;
-        }
-
-        public DestInfoBuilder setUse100(boolean use100) {
-            this.use100 = use100;
-            return this;
-        }
-
-        public DestInfoBuilder setPrivilegedSubscriber(boolean privilegedSubscriber) {
-            this.privilegedSubscriber = privilegedSubscriber;
-            return this;
-        }
-
-        public DestInfoBuilder setFollowRedirects(boolean followRedirects) {
-            this.followRedirects = followRedirects;
-            return this;
-        }
-
-        public DestInfoBuilder setDecompress(boolean decompress) {
-            this.decompress = decompress;
-            return this;
-        }
-
-        public DestInfoBuilder setSubscription(NodeConfig.ProvSubscription subscription) {
-            this.subscription = subscription;
-            return this;
-        }
-
-        public DestInfo createDestInfo() {
-            return new DestInfo(this);
-        }
-    }
 
+    /**
+     * Create a destination information object.
+     *
+     * @param destInfoBuilder DestInfo Object Builder
+     */
     public DestInfo(DestInfoBuilder destInfoBuilder) {
-        this.name = destInfoBuilder.name;
-        this.spool = destInfoBuilder.spool;
-        this.subid = destInfoBuilder.subid;
-        this.logdata = destInfoBuilder.logdata;
-        this.url = destInfoBuilder.url;
-        this.authuser = destInfoBuilder.authuser;
-        this.authentication = destInfoBuilder.authentication;
-        this.metaonly = destInfoBuilder.metaonly;
-        this.use100 = destInfoBuilder.use100;
-        this.privilegedSubscriber = destInfoBuilder.privilegedSubscriber;
-        this.followRedirects = destInfoBuilder.followRedirects;
-        this.decompress = destInfoBuilder.decompress;
+        this.name = destInfoBuilder.getName();
+        this.spool = destInfoBuilder.getSpool();
+        this.subid = destInfoBuilder.getSubid();
+        this.logdata = destInfoBuilder.getLogdata();
+        this.url = destInfoBuilder.getUrl();
+        this.authuser = destInfoBuilder.getAuthuser();
+        this.authentication = destInfoBuilder.getAuthentication();
+        this.metaonly = destInfoBuilder.isMetaonly();
+        this.use100 = destInfoBuilder.isUse100();
+        this.privilegedSubscriber = destInfoBuilder.isPrivilegedSubscriber();
+        this.followRedirects = destInfoBuilder.isFollowRedirects();
+        this.decompress = destInfoBuilder.isDecompress();
     }
 
     /**
      * Create a destination information object.
      *
-     * @param    name    n:fqdn or s:subid
-     * @param    spool    The directory where files are spooled.
-     * @param    subscription    The subscription.
+     * @param name n:fqdn or s:subid
+     * @param spool The directory where files are spooled.
+     * @param subscription The subscription.
      */
     public DestInfo(String name, String spool, NodeConfig.ProvSubscription subscription) {
         this.name = name;
@@ -164,8 +84,8 @@ public class DestInfo {
         this.decompress = subscription.isDecompress();
     }
 
-    public boolean equals(Object o) {
-        return ((o instanceof DestInfo) && ((DestInfo) o).spool.equals(spool));
+    public boolean equals(Object object) {
+        return ((object instanceof DestInfo) && ((DestInfo) object).spool.equals(spool));
     }
 
     public int hashCode() {
@@ -173,7 +93,7 @@ public class DestInfo {
     }
 
     /**
-     * Get the name of this destination
+     * Get the name of this destination.
      */
     public String getName() {
         return (name);
@@ -217,7 +137,7 @@ public class DestInfo {
     }
 
     /**
-     * Get the user for authentication
+     * Get the user for authentication.
      *
      * @return The name of the user for logging
      */
@@ -226,7 +146,7 @@ public class DestInfo {
     }
 
     /**
-     * Get the authentication header
+     * Get the authentication header.
      *
      * @return The string to use to authenticate to the recipient.
      */
@@ -235,7 +155,7 @@ public class DestInfo {
     }
 
     /**
-     * Is this a metadata only delivery?
+     * Is this a metadata only delivery.
      *
      * @return True if this is a metadata only delivery
      */
@@ -244,7 +164,7 @@ public class DestInfo {
     }
 
     /**
-     * Should I send expect 100-continue header?
+     * Should I send expect 100-continue header.
      *
      * @return True if I should.
      */
@@ -253,23 +173,23 @@ public class DestInfo {
     }
 
     /**
-     * Should we wait to receive a file processed acknowledgement before deleting file
+     * Should we wait to receive a file processed acknowledgement before deleting file.
      */
     public boolean isPrivilegedSubscriber() {
         return (privilegedSubscriber);
     }
 
     /**
-    * Should I follow redirects?
-    *
-    * @return True if I should.
-    */
+     * Should I follow redirects.
+     *
+     * @return True if I should.
+     */
     public boolean isFollowRedirects() {
         return (followRedirects);
     }
 
     /**
-     * Should i decompress the file before sending it on
+     * Should i decompress the file before sending it on.
      *
      * @return True if I should.
      */
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DestInfoBuilder.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DestInfoBuilder.java
new file mode 100644 (file)
index 0000000..00c5cd8
--- /dev/null
@@ -0,0 +1,149 @@
+/*-
+ * ============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;
+
+public class DestInfoBuilder {
+
+    private String destInfoName;
+    private String destInfoSpool;
+    private String destInfoSubId;
+    private String destInfoLogData;
+    private String destInfoUrl;
+    private String destInfoAuthUser;
+    private String destInfoAuthentication;
+    private boolean destInfoMetaOnly;
+    private boolean destInfoUse100;
+    private boolean destInfoPrivilegedSubscriber;
+    private boolean destInfoFollowRedirects;
+    private boolean destInfoDecompress;
+
+    public String getName() {
+        return destInfoName;
+    }
+
+    public DestInfoBuilder setName(String name) {
+        this.destInfoName = name;
+        return this;
+    }
+
+    public String getSpool() {
+        return destInfoSpool;
+    }
+
+    public DestInfoBuilder setSpool(String spool) {
+        this.destInfoSpool = spool;
+        return this;
+    }
+
+    public String getSubid() {
+        return destInfoSubId;
+    }
+
+    public DestInfoBuilder setSubid(String subid) {
+        this.destInfoSubId = subid;
+        return this;
+    }
+
+    String getLogdata() {
+        return destInfoLogData;
+    }
+
+    DestInfoBuilder setLogdata(String logdata) {
+        this.destInfoLogData = logdata;
+        return this;
+    }
+
+    public String getUrl() {
+        return destInfoUrl;
+    }
+
+    public DestInfoBuilder setUrl(String url) {
+        this.destInfoUrl = url;
+        return this;
+    }
+
+    String getAuthuser() {
+        return destInfoAuthUser;
+    }
+
+    DestInfoBuilder setAuthuser(String authuser) {
+        this.destInfoAuthUser = authuser;
+        return this;
+    }
+
+    String getAuthentication() {
+        return destInfoAuthentication;
+    }
+
+    DestInfoBuilder setAuthentication(String authentication) {
+        this.destInfoAuthentication = authentication;
+        return this;
+    }
+
+    boolean isMetaonly() {
+        return destInfoMetaOnly;
+    }
+
+    DestInfoBuilder setMetaonly(boolean metaonly) {
+        this.destInfoMetaOnly = metaonly;
+        return this;
+    }
+
+    boolean isUse100() {
+        return destInfoUse100;
+    }
+
+    DestInfoBuilder setUse100(boolean use100) {
+        this.destInfoUse100 = use100;
+        return this;
+    }
+
+    boolean isPrivilegedSubscriber() {
+        return destInfoPrivilegedSubscriber;
+    }
+
+    DestInfoBuilder setPrivilegedSubscriber(boolean privilegedSubscriber) {
+        this.destInfoPrivilegedSubscriber = privilegedSubscriber;
+        return this;
+    }
+
+    boolean isFollowRedirects() {
+        return destInfoFollowRedirects;
+    }
+
+    DestInfoBuilder setFollowRedirects(boolean followRedirects) {
+        this.destInfoFollowRedirects = followRedirects;
+        return this;
+    }
+
+    boolean isDecompress() {
+        return destInfoDecompress;
+    }
+
+    DestInfoBuilder setDecompress(boolean decompress) {
+        this.destInfoDecompress = decompress;
+        return this;
+    }
+
+    DestInfo createDestInfo() {
+        return new DestInfo(this);
+    }
+}
\ No newline at end of file
index f7cedd2..4985268 100644 (file)
@@ -26,39 +26,40 @@ package org.onap.dmaap.datarouter.node;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-
 import java.io.IOException;
-import java.util.*;
-import java.net.*;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
 
 /**
- * Determine if an IP address is from a machine
+ * Determine if an IP address is from a machine.
  */
 public class IsFrom {
+
+    private static EELFLogger logger = EELFManager.getInstance().getLogger(IsFrom.class);
     private long nextcheck;
     private String[] ips;
     private String fqdn;
-    private static EELFLogger logger = EELFManager.getInstance().getLogger(IsFrom.class);
 
     /**
-     * Configure the JVM DNS cache to have a 10 second TTL.  This needs to be called very very early or it won't have any effect.
+     * Create an IsFrom for the specified fully qualified domain name.
      */
-    public static void setDNSCache() {
-        java.security.Security.setProperty("networkaddress.cache.ttl", "10");
+    public IsFrom(String fqdn) {
+        this.fqdn = fqdn;
     }
 
     /**
-     * Create an IsFrom for the specified fully qualified domain name.
+     * Configure the JVM DNS cache to have a 10 second TTL.  This needs to be called very very early or it won't have
+     * any effect.
      */
-    public IsFrom(String fqdn) {
-        this.fqdn = fqdn;
+    public static void setDNSCache() {
+        java.security.Security.setProperty("networkaddress.cache.ttl", "10");
     }
 
     /**
-     * Check if an IP address matches.  If it has been more than
-     * 10 seconds since DNS was last checked for changes to the
-     * IP address(es) of this FQDN, check again.  Then check
-     * if the specified IP address belongs to the FQDN.
+     * Check if an IP address matches.  If it has been more than 10 seconds since DNS was last checked for changes to
+     * the IP address(es) of this FQDN, check again.  Then check if the specified IP address belongs to the FQDN.
      */
     public synchronized boolean isFrom(String ip) {
         long now = System.currentTimeMillis();
@@ -71,7 +72,7 @@ public class IsFrom {
                     hostAddrArray.add(addr.getHostAddress());
                 }
             } catch (UnknownHostException e) {
-                logger.error("IsFrom: UnknownHostEx: " + e.toString(), e.getMessage());
+                logger.error("IsFrom: UnknownHostEx: " + e.toString(), e);
             }
             ips = hostAddrArray.toArray(new String[0]);
             logger.info("IsFrom: DNS ENTRIES FOR FQDN " + fqdn + " : " + Arrays.toString(ips));
@@ -90,15 +91,15 @@ public class IsFrom {
                 return true;
             }
         } catch (UnknownHostException e) {
-            logger.error("IsFrom: UnknownHostEx: " + e.toString(), e.getMessage());
+            logger.error("IsFrom: UnknownHostEx: " + e.toString(), e);
         } catch (IOException e) {
-            logger.error("IsFrom: Failed to parse IP : " + ip + " : " + e.toString(), e.getMessage());
+            logger.error("IsFrom: Failed to parse IP : " + ip + " : " + e.toString(), e);
         }
         return false;
     }
 
     /**
-     * Return the fully qualified domain name
+     * Return the fully qualified domain name.
      */
     public String toString() {
         return (fqdn);
index 78a195b..cf3b29a 100644 (file)
  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * *
  ******************************************************************************/
+
 package org.onap.dmaap.datarouter.node;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
@@ -33,17 +36,20 @@ import java.util.Arrays;
 import java.util.TimerTask;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
+import org.jetbrains.annotations.NotNull;
 
 /**
  * Cleanup of old log files.
- * <p>
- * Periodically scan the log directory for log files that are older than the log file retention interval, and delete
+ *
+ * <p>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 static final String EXCEPTION = "Exception";
+    private EELFLogger logger = EELFManager.getInstance().getLogger(LogManager.class);
     private NodeConfigManager config;
     private Matcher isnodelog;
     private Matcher iseventlog;
@@ -51,7 +57,58 @@ public class LogManager extends TimerTask {
     private String uploaddir;
     private String logdir;
 
-    private class Uploader extends Thread implements DeliveryQueueHelper {
+    /**
+     * Construct a log manager
+     *
+     * <p>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;
+        try {
+            isnodelog = Pattern.compile("node\\.log\\.\\d{8}").matcher("");
+            iseventlog = Pattern.compile("events-\\d{12}\\.log").matcher("");
+        } catch (Exception e) {
+            logger.error(EXCEPTION, e);
+        }
+        logdir = config.getLogDir();
+        uploaddir = logdir + "/.spool";
+        (new File(uploaddir)).mkdirs();
+        long now = System.currentTimeMillis();
+        long intvl = StatusLog.parseInterval(config.getEventLogInterval(), 30000);
+        long when = now - now % intvl + intvl + 20000L;
+        config.getTimer().scheduleAtFixedRate(this, when - now, intvl);
+        worker = new Uploader();
+    }
+
+    /**
+     * Trigger check for expired log files and log files to upload.
+     */
+    public void run() {
+        worker.poke();
+    }
+
+    public Uploader getWorker() {
+        return worker;
+    }
+
+    class Uploader extends Thread implements DeliveryQueueHelper {
+
+        private static final String META = "/.meta";
+        private EELFLogger logger = EELFManager.getInstance().getLogger(Uploader.class);
+        private DeliveryQueue dq;
+
+        Uploader() {
+            dq = new DeliveryQueue(this,
+                    new DestInfoBuilder().setName("LogUpload").setSpool(uploaddir).setSubid(null).setLogdata(null)
+                            .setUrl(null).setAuthuser(config.getMyName()).setAuthentication(config.getMyAuth())
+                            .setMetaonly(false).setUse100(false).setPrivilegedSubscriber(false)
+                            .setFollowRedirects(false)
+                            .setDecompress(false).createDestInfo());
+            setDaemon(true);
+            setName("Log Uploader");
+            start();
+        }
 
         public long getInitFailureTimer() {
             return (10000L);
@@ -86,6 +143,7 @@ public class LogManager extends TimerTask {
         }
 
         public void handleUnreachable(DestInfo destinationInfo) {
+            throw new UnsupportedOperationException();
         }
 
         public boolean handleRedirection(DestInfo destinationInfo, String location, String fileid) {
@@ -100,23 +158,11 @@ public class LogManager extends TimerTask {
             return (null);
         }
 
-        private DeliveryQueue dq;
-
-        public Uploader() {
-            dq = new DeliveryQueue(this,
-                new DestInfo.DestInfoBuilder().setName("LogUpload").setSpool(uploaddir).setSubid(null).setLogdata(null)
-                    .setUrl(null).setAuthuser(config.getMyName()).setAuthentication(config.getMyAuth())
-                    .setMetaonly(false).setUse100(false).setPrivilegedSubscriber(false).setFollowRedirects(false)
-                    .setDecompress(false).createDestInfo());
-            setDaemon(true);
-            setName("Log Uploader");
-            start();
-        }
-
         private synchronized void snooze() {
             try {
                 wait(10000);
             } catch (Exception e) {
+                logger.error(EXCEPTION, e);
             }
         }
 
@@ -124,6 +170,7 @@ public class LogManager extends TimerTask {
             notify();
         }
 
+        @Override
         public void run() {
             while (true) {
                 scan();
@@ -141,69 +188,48 @@ public class LogManager extends TimerTask {
             String curlog = StatusLog.getCurLogFile();
             curlog = curlog.substring(curlog.lastIndexOf('/') + 1);
             try {
-                Writer w = new FileWriter(uploaddir + "/.meta");
-                w.write("POST\tlogdata\nContent-Type\ttext/plain\n");
-                w.close();
+                Writer writer = new FileWriter(uploaddir + META);
+                writer.write("POST\tlogdata\nContent-Type\ttext/plain\n");
+                writer.close();
                 BufferedReader br = new BufferedReader(new FileReader(uploaddir + "/.lastqueued"));
                 lastqueued = br.readLine();
                 br.close();
             } catch (Exception e) {
+                logger.error(EXCEPTION, e);
             }
             for (String fn : fns) {
                 if (!isnodelog.reset(fn).matches()) {
                     if (!iseventlog.reset(fn).matches()) {
                         continue;
                     }
-                    if (lastqueued.compareTo(fn) < 0 && curlog.compareTo(fn) > 0) {
-                        lastqueued = fn;
-                        try {
-                            String pid = config.getPublishId();
-                            Files.createLink(Paths.get(uploaddir + "/" + pid), Paths.get(logdir + "/" + fn));
-                            Files.createLink(Paths.get(uploaddir + "/" + pid + ".M"), Paths.get(uploaddir + "/.meta"));
-                        } catch (Exception e) {
-                        }
-                    }
+                    lastqueued = setLastQueued(lastqueued, curlog, fn);
                 }
-                File f = new File(dir, fn);
-                if (f.lastModified() < threshold) {
-                    f.delete();
+                File file = new File(dir, fn);
+                if (file.lastModified() < threshold) {
+                    file.delete();
                 }
             }
             try (Writer w = new FileWriter(uploaddir + "/.lastqueued")) {
-                (new File(uploaddir + "/.meta")).delete();
+                (new File(uploaddir + META)).delete();
                 w.write(lastqueued + "\n");
             } catch (Exception e) {
+                logger.error(EXCEPTION, e);
             }
         }
-    }
 
-    /**
-     * Construct a log manager
-     * <p>
-     * 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;
-        try {
-            isnodelog = Pattern.compile("node\\.log\\.\\d{8}").matcher("");
-            iseventlog = Pattern.compile("events-\\d{12}\\.log").matcher("");
-        } catch (Exception e) {
+        @NotNull
+        private String setLastQueued(String lastqueued, String curlog, String fn) {
+            if (lastqueued.compareTo(fn) < 0 && curlog.compareTo(fn) > 0) {
+                lastqueued = fn;
+                try {
+                    String pid = config.getPublishId();
+                    Files.createLink(Paths.get(uploaddir + "/" + pid), Paths.get(logdir + "/" + fn));
+                    Files.createLink(Paths.get(uploaddir + "/" + pid + ".M"), Paths.get(uploaddir + META));
+                } catch (Exception e) {
+                    logger.error(EXCEPTION, e);
+                }
+            }
+            return lastqueued;
         }
-        logdir = config.getLogDir();
-        uploaddir = logdir + "/.spool";
-        (new File(uploaddir)).mkdirs();
-        long now = System.currentTimeMillis();
-        long intvl = StatusLog.parseInterval(config.getEventLogInterval(), 30000);
-        long when = now - now % intvl + intvl + 20000L;
-        config.getTimer().scheduleAtFixedRate(this, when - now, intvl);
-        worker = new Uploader();
-    }
-
-    /**
-     * Trigger check for expired log files and log files to upload
-     */
-    public void run() {
-        worker.poke();
     }
 }
index d455f2d..127668f 100644 (file)
@@ -26,924 +26,985 @@ package org.onap.dmaap.datarouter.node;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Vector;
+import org.jetbrains.annotations.NotNull;
 
 /**
  * Processed configuration for this node.
- * <p>
- * The NodeConfig represents a processed configuration from the Data Router provisioning server.  Each time
+ *
+ * <p>The NodeConfig represents a processed configuration from the Data Router provisioning server.  Each time
  * configuration data is received from the provisioning server, a new NodeConfig is created and the previous one
  * discarded.
  */
 public class NodeConfig {
+
+    private static final String PUBLISHER_NOT_PERMITTED = "Publisher not permitted for this feed";
     private static EELFLogger logger = EELFManager.getInstance().getLogger(NodeConfig.class);
+    private HashMap<String, String> params = new HashMap<>();
+    private HashMap<String, Feed> feeds = new HashMap<>();
+    private HashMap<String, DestInfo> nodeinfo = new HashMap<>();
+    private HashMap<String, DestInfo> subinfo = new HashMap<>();
+    private HashMap<String, IsFrom> nodes = new HashMap<>();
+    private HashMap<String, ProvSubscription> provSubscriptions = new HashMap<>();
+    private String myname;
+    private String myauth;
+    private DestInfo[] alldests;
+    private int rrcntr;
+
     /**
-     * Raw configuration entry for a data router node
+     * Process the raw provisioning data to configure this node.
+     *
+     * @param pd The parsed provisioning data
+     * @param myname My name as seen by external systems
+     * @param spooldir The directory where temporary files live
+     * @param port The port number for URLs
+     * @param nodeauthkey The keying string used to generate node authentication credentials
      */
-    public static class ProvNode {
-
-        private String cname;
-
-        /**
-         * Construct a node configuration entry.
-         *
-         * @param cname The cname of the node.
-         */
-        public ProvNode(String cname) {
-            this.cname = cname;
+    public NodeConfig(ProvData pd, String myname, String spooldir, int port, String nodeauthkey) {
+        this.myname = myname;
+        for (ProvParam p : pd.getParams()) {
+            params.put(p.getName(), p.getValue());
         }
+        ArrayList<DestInfo> destInfos = addDestInfoToNodeConfig(pd, myname, spooldir, port, nodeauthkey);
+        PathFinder pf = new PathFinder(myname, nodeinfo.keySet().toArray(new String[0]), pd.getHops());
+        HashMap<String, ArrayList<Redirection>> rdtab = addSubRedirInfoToNodeConfig(pd);
+        HashMap<String, HashMap<String, String>> pfutab = addFeedUsersToNodeConfig(pd);
+        HashMap<String, String> egrtab = addEgressRoutesToNodeConfig(pd, myname);
+        HashMap<String, ArrayList<SubnetMatcher>> pfstab = addFeedSubnetToNodeConfig(pd);
+        HashSet<String> allfeeds = addFeedsToNodeConfig(pd);
+        HashMap<String, StringBuilder> feedTargets = addSubsToNodeConfig(pd, spooldir, destInfos, pf, egrtab, allfeeds);
+        alldests = destInfos.toArray(new DestInfo[0]);
+        addFeedTargetsToNodeConfig(pd, rdtab, pfutab, pfstab, feedTargets);
+    }
 
-        /**
-         * Get the cname of the node
-         */
-        public String getCName() {
-            return (cname);
+    @NotNull
+    private ArrayList<DestInfo> addDestInfoToNodeConfig(ProvData pd, String myname, String spooldir, int port,
+            String nodeauthkey) {
+        ArrayList<DestInfo> destInfos = new ArrayList<>();
+        myauth = NodeUtils.getNodeAuthHdr(myname, nodeauthkey);
+        for (ProvNode pn : pd.getNodes()) {
+            String commonName = pn.getCName();
+            if (nodeinfo.get(commonName) != null) {
+                continue;
+            }
+            DestInfo di = new DestInfoBuilder().setName("n:" + commonName).setSpool(spooldir + "/n/" + commonName)
+                    .setSubid(null)
+                    .setLogdata("n2n-" + commonName).setUrl("https://" + commonName + ":" + port + "/internal/publish")
+                    .setAuthuser(commonName).setAuthentication(myauth).setMetaonly(false).setUse100(true)
+                    .setPrivilegedSubscriber(false).setFollowRedirects(false).setDecompress(false).createDestInfo();
+            (new File(di.getSpool())).mkdirs();
+            String auth = NodeUtils.getNodeAuthHdr(commonName, nodeauthkey);
+            destInfos.add(di);
+            nodeinfo.put(commonName, di);
+            nodes.put(auth, new IsFrom(commonName));
         }
+        return destInfos;
     }
 
-    /**
-     * Raw configuration entry for a provisioning parameter
-     */
-    public static class ProvParam {
-
-        private String name;
-        private String value;
-
-        /**
-         * Construct a provisioning parameter configuration entry.
-         *
-         * @param name The name of the parameter.
-         * @param value The value of the parameter.
-         */
-        public ProvParam(String name, String value) {
-            this.name = name;
-            this.value = value;
+    @NotNull
+    private HashMap<String, ArrayList<Redirection>> addSubRedirInfoToNodeConfig(ProvData pd) {
+        HashMap<String, ArrayList<Redirection>> rdtab = new HashMap<>();
+        for (ProvForceIngress pfi : pd.getForceIngress()) {
+            ArrayList<Redirection> redirections = rdtab.get(pfi.getFeedId());
+            if (redirections == null) {
+                redirections = new ArrayList<>();
+                rdtab.put(pfi.getFeedId(), redirections);
+            }
+            Redirection redirection = new Redirection();
+            if (pfi.getSubnet() != null) {
+                redirection.snm = new SubnetMatcher(pfi.getSubnet());
+            }
+            redirection.user = pfi.getUser();
+            redirection.nodes = pfi.getNodes();
+            redirections.add(redirection);
         }
+        return rdtab;
+    }
 
-        /**
-         * Get the name of the parameter.
-         */
-        public String getName() {
-            return (name);
+    @NotNull
+    private HashMap<String, HashMap<String, String>> addFeedUsersToNodeConfig(ProvData pd) {
+        HashMap<String, HashMap<String, String>> pfutab = new HashMap<>();
+        for (ProvFeedUser pfu : pd.getFeedUsers()) {
+            HashMap<String, String> userInfo = pfutab.get(pfu.getFeedId());
+            if (userInfo == null) {
+                userInfo = new HashMap<>();
+                pfutab.put(pfu.getFeedId(), userInfo);
+            }
+            userInfo.put(pfu.getCredentials(), pfu.getUser());
         }
+        return pfutab;
+    }
 
-        /**
-         * Get the value of the parameter.
-         */
-        public String getValue() {
-            return (value);
+    @NotNull
+    private HashMap<String, String> addEgressRoutesToNodeConfig(ProvData pd, String myname) {
+        HashMap<String, String> egrtab = new HashMap<>();
+        for (ProvForceEgress pfe : pd.getForceEgress()) {
+            if (pfe.getNode().equals(myname) || nodeinfo.get(pfe.getNode()) == null) {
+                continue;
+            }
+            egrtab.put(pfe.getSubId(), pfe.getNode());
         }
+        return egrtab;
     }
 
-    /**
-     * Raw configuration entry for a data feed.
-     */
-    public static class ProvFeed {
-
-        private String id;
-        private String logdata;
-        private String status;
-        private String createdDate;
-        /*
-         * AAF changes: TDP EPIC US# 307413
-         * Passing aafInstance from to identify legacy/AAF feeds
-         */
-        private String aafInstance;
-
-        /**
-         * Construct a feed configuration entry.
-         *
-         * @param id The feed ID of the entry.
-         * @param logdata String for log entries about the entry.
-         * @param status The reason why this feed cannot be used (Feed has been deleted, Feed has been suspended) or
-         * null if it is valid.
-         */
-        public ProvFeed(String id, String logdata, String status, String createdDate, String aafInstance) {
-            this.id = id;
-            this.logdata = logdata;
-            this.status = status;
-            this.createdDate = createdDate;
-            this.aafInstance = aafInstance;
+    @NotNull
+    private HashMap<String, ArrayList<SubnetMatcher>> addFeedSubnetToNodeConfig(ProvData pd) {
+        HashMap<String, ArrayList<SubnetMatcher>> pfstab = new HashMap<>();
+        for (ProvFeedSubnet pfs : pd.getFeedSubnets()) {
+            ArrayList<SubnetMatcher> subnetMatchers = pfstab.get(pfs.getFeedId());
+            if (subnetMatchers == null) {
+                subnetMatchers = new ArrayList<>();
+                pfstab.put(pfs.getFeedId(), subnetMatchers);
+            }
+            subnetMatchers.add(new SubnetMatcher(pfs.getCidr()));
         }
+        return pfstab;
+    }
 
-        /**
-         * Get the created date of the data feed.
-         */
-        public String getCreatedDate()
-        {
-            return(createdDate);
+    @NotNull
+    private HashSet<String> addFeedsToNodeConfig(ProvData pd) {
+        HashSet<String> allfeeds = new HashSet<>();
+        for (ProvFeed pfx : pd.getFeeds()) {
+            if (pfx.getStatus() == null) {
+                allfeeds.add(pfx.getId());
+            }
         }
+        return allfeeds;
+    }
 
-        /**
-         * Get the aafInstance of the data feed.
-         */
-        public String getAafInstance() {
-            return aafInstance;
+    @NotNull
+    private HashMap<String, StringBuilder> addSubsToNodeConfig(ProvData pd, String spooldir,
+            ArrayList<DestInfo> destInfos, PathFinder pf, HashMap<String, String> egrtab, HashSet<String> allfeeds) {
+        HashMap<String, StringBuilder> feedTargets = new HashMap<>();
+        for (ProvSubscription provSubscription : pd.getSubscriptions()) {
+            String subId = provSubscription.getSubId();
+            String feedId = provSubscription.getFeedId();
+            if (isFeedOrSubKnown(allfeeds, subId, feedId)) {
+                continue;
+            }
+            int sididx = 999;
+            try {
+                sididx = Integer.parseInt(subId);
+                sididx -= sididx % 100;
+            } catch (Exception e) {
+                logger.error("NODE0517 Exception NodeConfig: " + e);
+            }
+            String subscriptionDirectory = sididx + "/" + subId;
+            DestInfo destinationInfo = new DestInfo("s:" + subId,
+                    spooldir + "/s/" + subscriptionDirectory, provSubscription);
+            (new File(destinationInfo.getSpool())).mkdirs();
+            destInfos.add(destinationInfo);
+            provSubscriptions.put(subId, provSubscription);
+            subinfo.put(subId, destinationInfo);
+            String egr = egrtab.get(subId);
+            if (egr != null) {
+                subId = pf.getPath(egr) + subId;
+            }
+            StringBuilder sb = feedTargets.get(feedId);
+            if (sb == null) {
+                sb = new StringBuilder();
+                feedTargets.put(feedId, sb);
+            }
+            sb.append(' ').append(subId);
         }
+        return feedTargets;
+    }
 
-        /**
-         * Get the feed id of the data feed.
-         */
-        public String getId() {
-            return (id);
+    private void addFeedTargetsToNodeConfig(ProvData pd, HashMap<String, ArrayList<Redirection>> rdtab,
+            HashMap<String, HashMap<String, String>> pfutab, HashMap<String, ArrayList<SubnetMatcher>> pfstab,
+            HashMap<String, StringBuilder> feedTargets) {
+        for (ProvFeed pfx : pd.getFeeds()) {
+            String fid = pfx.getId();
+            Feed feed = feeds.get(fid);
+            if (feed != null) {
+                continue;
+            }
+            feed = new Feed();
+            feeds.put(fid, feed);
+            feed.createdDate = pfx.getCreatedDate();
+            feed.loginfo = pfx.getLogData();
+            feed.status = pfx.getStatus();
+            /*
+             * AAF changes: TDP EPIC US# 307413
+             * Passing aafInstance from ProvFeed to identify legacy/AAF feeds
+             */
+            feed.aafInstance = pfx.getAafInstance();
+            ArrayList<SubnetMatcher> v1 = pfstab.get(fid);
+            if (v1 == null) {
+                feed.subnets = new SubnetMatcher[0];
+            } else {
+                feed.subnets = v1.toArray(new SubnetMatcher[0]);
+            }
+            HashMap<String, String> h1 = pfutab.get(fid);
+            if (h1 == null) {
+                h1 = new HashMap();
+            }
+            feed.authusers = h1;
+            ArrayList<Redirection> v2 = rdtab.get(fid);
+            if (v2 == null) {
+                feed.redirections = new Redirection[0];
+            } else {
+                feed.redirections = v2.toArray(new Redirection[0]);
+            }
+            StringBuilder sb = feedTargets.get(fid);
+            if (sb == null) {
+                feed.targets = new Target[0];
+            } else {
+                feed.targets = parseRouting(sb.toString());
+            }
         }
+    }
 
-        /**
-         * Get the log data of the data feed.
-         */
-        public String getLogData() {
-            return (logdata);
+    /**
+     * Parse a target string into an array of targets.
+     *
+     * @param routing Target string
+     * @return Array of targets.
+     */
+    public Target[] parseRouting(String routing) {
+        routing = routing.trim();
+        if ("".equals(routing)) {
+            return (new Target[0]);
         }
-
-        /**
-         * Get the status of the data feed.
-         */
-        public String getStatus() {
-            return (status);
+        String[] routingTable = routing.split("\\s+");
+        HashMap<String, Target> tmap = new HashMap<>();
+        HashSet<String> subset = new HashSet<>();
+        ArrayList<Target> targets = new ArrayList<>();
+        for (int i = 0; i < routingTable.length; i++) {
+            String target = routingTable[i];
+            int index = target.indexOf('/');
+            if (index == -1) {
+                addTarget(subset, targets, target);
+            } else {
+                addTargetWithRouting(tmap, targets, target, index);
+            }
         }
+        return (targets.toArray(new Target[0]));
     }
 
     /**
-     * Raw configuration entry for a feed user.
+     * Check whether this is a valid node-to-node transfer.
+     *
+     * @param credentials Credentials offered by the supposed node
+     * @param ip IP address the request came from
      */
-    public static class ProvFeedUser {
-
-        private String feedid;
-        private String user;
-        private String credentials;
+    public boolean isAnotherNode(String credentials, String ip) {
+        IsFrom node = nodes.get(credentials);
+        return (node != null && node.isFrom(ip));
+    }
 
-        /**
-         * Construct a feed user configuration entry
-         *
-         * @param feedid The feed id.
-         * @param user The user that will publish to the feed.
-         * @param credentials The Authorization header the user will use to publish.
-         */
-        public ProvFeedUser(String feedid, String user, String credentials) {
-            this.feedid = feedid;
-            this.user = user;
-            this.credentials = credentials;
+    /**
+     * Check whether publication is allowed.
+     *
+     * @param feedid The ID of the feed being requested.
+     * @param credentials The offered credentials
+     * @param ip The requesting IP address
+     */
+    public String isPublishPermitted(String feedid, String credentials, String ip) {
+        Feed feed = feeds.get(feedid);
+        String nf = "Feed does not exist";
+        if (feed != null) {
+            nf = feed.status;
         }
-
-        /**
-         * Get the feed id of the feed user.
-         */
-        public String getFeedId() {
-            return (feedid);
+        if (nf != null) {
+            return (nf);
         }
-
-        /**
-         * Get the user for the feed user.
-         */
-        public String getUser() {
-            return (user);
+        String user = feed.authusers.get(credentials);
+        if (user == null) {
+            return (PUBLISHER_NOT_PERMITTED);
         }
-
-        /**
-         * Get the credentials for the feed user.
-         */
-        public String getCredentials() {
-            return (credentials);
+        if (feed.subnets.length == 0) {
+            return (null);
+        }
+        byte[] addr = NodeUtils.getInetAddress(ip);
+        for (SubnetMatcher snm : feed.subnets) {
+            if (snm.matches(addr)) {
+                return (null);
+            }
         }
+        return (PUBLISHER_NOT_PERMITTED);
     }
 
     /**
-     * Raw configuration entry for a feed subnet
+     * Check whether publication is allowed for AAF Feed.
+     *
+     * @param feedid The ID of the feed being requested.
+     * @param ip The requesting IP address
      */
-    public static class ProvFeedSubnet {
+    public String isPublishPermitted(String feedid, String ip) {
+        Feed feed = feeds.get(feedid);
+        String nf = "Feed does not exist";
+        if (feed != null) {
+            nf = feed.status;
+        }
+        if (nf != null) {
+            return nf;
+        }
+        if (feed.subnets.length == 0) {
+            return null;
+        }
+        byte[] addr = NodeUtils.getInetAddress(ip);
+        for (SubnetMatcher snm : feed.subnets) {
+            if (snm.matches(addr)) {
+                return null;
+            }
+        }
+        return PUBLISHER_NOT_PERMITTED;
+    }
 
-        private String feedid;
-        private String cidr;
+    /**
+     * Check whether delete file is allowed.
+     *
+     * @param subId The ID of the subscription being requested.
+     */
+    public boolean isDeletePermitted(String subId) {
+        ProvSubscription provSubscription = provSubscriptions.get(subId);
+        return provSubscription.isPrivilegedSubscriber();
+    }
 
-        /**
-         * Construct a feed subnet configuration entry
-         *
-         * @param feedid The feed ID
-         * @param cidr The CIDR allowed to publish to the feed.
-         */
-        public ProvFeedSubnet(String feedid, String cidr) {
-            this.feedid = feedid;
-            this.cidr = cidr;
-        }
+    /**
+     * Get authenticated user.
+     */
+    public String getAuthUser(String feedid, String credentials) {
+        return (feeds.get(feedid).authusers.get(credentials));
+    }
 
-        /**
-         * Get the feed id of the feed subnet.
-         */
-        public String getFeedId() {
-            return (feedid);
-        }
+    /**
+     * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID.
+     *
+     * @param feedid The ID of the feed specified
+     */
+    public String getAafInstance(String feedid) {
+        Feed feed = feeds.get(feedid);
+        return feed.aafInstance;
+    }
 
-        /**
-         * Get the CIDR of the feed subnet.
-         */
-        public String getCidr() {
-            return (cidr);
+    /**
+     * Check if the request should be redirected to a different ingress node.
+     */
+    public String getIngressNode(String feedid, String user, String ip) {
+        Feed feed = feeds.get(feedid);
+        if (feed.redirections.length == 0) {
+            return (null);
+        }
+        byte[] addr = NodeUtils.getInetAddress(ip);
+        for (Redirection r : feed.redirections) {
+            if ((r.user != null && !user.equals(r.user)) || (r.snm != null && !r.snm.matches(addr))) {
+                continue;
+            }
+            for (String n : r.nodes) {
+                if (myname.equals(n)) {
+                    return (null);
+                }
+            }
+            if (r.nodes.length == 0) {
+                return (null);
+            }
+            return (r.nodes[rrcntr++ % r.nodes.length]);
         }
+        return (null);
     }
 
     /**
-     * Raw configuration entry for a subscription
+     * Get a provisioned configuration parameter.
      */
-    public static class ProvSubscription {
+    public String getProvParam(String name) {
+        return (params.get(name));
+    }
 
-        private String subid;
-        private String feedid;
-        private String url;
-        private String authuser;
-        private String credentials;
-        private boolean metaonly;
-        private boolean use100;
-        private boolean privilegedSubscriber;
-        private boolean followRedirect;
-        private boolean decompress;
+    /**
+     * Get all the DestInfos.
+     */
+    public DestInfo[] getAllDests() {
+        return (alldests);
+    }
 
-        /**
-         * Construct a subscription configuration entry
-         *
-         * @param subid The subscription ID
-         * @param feedid The feed ID
-         * @param url The base delivery URL (not including the fileid)
-         * @param authuser The user in the credentials used to deliver
-         * @param credentials The credentials used to authenticate to the delivery URL exactly as they go in the
-         * Authorization header.
-         * @param metaonly Is this a meta data only subscription?
-         * @param use100 Should we send Expect: 100-continue?
-         * @param privilegedSubscriber Can we wait to receive a delete file call before deleting file
-         * @param followRedirect Is follow redirect of destination enabled?
-         * @param decompress To see if they want their information compressed or decompressed
-         */
-        public ProvSubscription(String subid, String feedid, String url, String authuser, String credentials, boolean metaonly, boolean use100, boolean privilegedSubscriber, boolean followRedirect, boolean decompress) {
-            this.subid = subid;
-            this.feedid = feedid;
-            this.url = url;
-            this.authuser = authuser;
-            this.credentials = credentials;
-            this.metaonly = metaonly;
-            this.use100 = use100;
-            this.privilegedSubscriber = privilegedSubscriber;
-            this.followRedirect = followRedirect;
-            this.decompress = decompress;
+    /**
+     * Get the targets for a feed.
+     *
+     * @param feedid The feed ID
+     * @return The targets this feed should be delivered to
+     */
+    public Target[] getTargets(String feedid) {
+        if (feedid == null) {
+            return (new Target[0]);
         }
-
-        /**
-         * Get the subscription ID
-         */
-        public String getSubId() {
-            return (subid);
+        Feed feed = feeds.get(feedid);
+        if (feed == null) {
+            return (new Target[0]);
         }
+        return (feed.targets);
+    }
 
-        /**
-         * Get the feed ID
-         */
-        public String getFeedId() {
-            return (feedid);
-        }
+    /**
+     * Get the creation date for a feed.
+     *
+     * @param feedid The feed ID
+     * @return the timestamp of creation date of feed id passed
+     */
+    public String getCreatedDate(String feedid) {
+        Feed feed = feeds.get(feedid);
+        return (feed.createdDate);
+    }
 
-        /**
-         * Get the delivery URL
-         */
-        public String getURL() {
-            return (url);
+    /**
+     * Get the feed ID for a subscription.
+     *
+     * @param subid The subscription ID
+     * @return The feed ID
+     */
+    public String getFeedId(String subid) {
+        DestInfo di = subinfo.get(subid);
+        if (di == null) {
+            return (null);
         }
+        return (di.getLogData());
+    }
 
-        /**
-         * Get the user
-         */
-        public String getAuthUser() {
-            return (authuser);
+    /**
+     * Get the spool directory for a subscription.
+     *
+     * @param subid The subscription ID
+     * @return The spool directory
+     */
+    public String getSpoolDir(String subid) {
+        DestInfo di = subinfo.get(subid);
+        if (di == null) {
+            return (null);
         }
+        return (di.getSpool());
+    }
 
-        /**
-         * Get the delivery credentials
-         */
-        public String getCredentials() {
-            return (credentials);
-        }
+    /**
+     * Get the Authorization value this node uses.
+     *
+     * @return The Authorization header value for this node
+     */
+    public String getMyAuth() {
+        return (myauth);
+    }
 
-        /**
-         * Is this a meta data only subscription?
-         */
-        public boolean isMetaDataOnly() {
-            return (metaonly);
-        }
+    private boolean isFeedOrSubKnown(HashSet<String> allfeeds, String subId, String feedId) {
+        return !allfeeds.contains(feedId) || subinfo.get(subId) != null;
+    }
 
-        /**
-         * Should we send Expect: 100-continue?
-         */
-        public boolean isUsing100() {
-            return (use100);
+    private void addTargetWithRouting(HashMap<String, Target> tmap, ArrayList<Target> targets, String target,
+            int index) {
+        String node = target.substring(0, index);
+        String rtg = target.substring(index + 1);
+        DestInfo di = nodeinfo.get(node);
+        if (di == null) {
+            targets.add(new Target(null, target));
+        } else {
+            Target tt = tmap.get(node);
+            if (tt == null) {
+                tt = new Target(di, rtg);
+                tmap.put(node, tt);
+                targets.add(tt);
+            } else {
+                tt.addRouting(rtg);
+            }
         }
+    }
 
-        /**
-         * Can we wait to receive a delete file call before deleting file
-         */
-        public boolean isPrivilegedSubscriber() {
-            return (privilegedSubscriber);
+    private void addTarget(HashSet<String> subset, ArrayList<Target> targets, String target) {
+        DestInfo destInfo = subinfo.get(target);
+        if (destInfo == null) {
+            targets.add(new Target(null, target));
+        } else {
+            if (!subset.contains(target)) {
+                subset.add(target);
+                targets.add(new Target(destInfo, null));
+            }
         }
+    }
+
+    /**
+     * Raw configuration entry for a data router node.
+     */
+    public static class ProvNode {
+
+        private String cname;
 
         /**
-         * Should i decompress the file before sending it on
-        */
-        public boolean isDecompress() {
-            return (decompress);
+         * Construct a node configuration entry.
+         *
+         * @param cname The cname of the node.
+         */
+        public ProvNode(String cname) {
+            this.cname = cname;
         }
 
         /**
-         *  New field is added - FOLLOW_REDIRECTS feature iTrack:DATARTR-17 - 1706
-         *     Get the followRedirect of this destination
+         * Get the cname of the node.
          */
-        boolean getFollowRedirect() {
-            return(followRedirect);
+        public String getCName() {
+            return (cname);
         }
     }
 
     /**
-     * Raw configuration entry for controlled ingress to the data router node
+     * Raw configuration entry for a provisioning parameter.
      */
-    public static class ProvForceIngress {
+    public static class ProvParam {
 
-        private String feedid;
-        private String subnet;
-        private String user;
-        private String[] nodes;
+        private String name;
+        private String value;
 
         /**
-         * Construct a forced ingress configuration entry
+         * Construct a provisioning parameter configuration entry.
          *
-         * @param feedid The feed ID that this entry applies to
-         * @param subnet The CIDR for which publisher IP addresses this entry applies to or "" if it applies to all
-         * publisher IP addresses
-         * @param user The publishing user this entry applies to or "" if it applies to all publishing users.
-         * @param nodes The array of FQDNs of the data router nodes to redirect publication attempts to.
+         * @param name The name of the parameter.
+         * @param value The value of the parameter.
          */
-        public ProvForceIngress(String feedid, String subnet, String user, String[] nodes) {
-            this.feedid = feedid;
-            this.subnet = subnet;
-            this.user = user;
-            //Sonar fix
-            if(nodes == null) {
-                this.nodes = new String[0];
-            } else {
-                this.nodes = Arrays.copyOf(nodes, nodes.length);
-            }
+        public ProvParam(String name, String value) {
+            this.name = name;
+            this.value = value;
         }
 
         /**
-         * Get the feed ID
+         * Get the name of the parameter.
          */
-        public String getFeedId() {
-            return (feedid);
+        public String getName() {
+            return (name);
         }
 
         /**
-         * Get the subnet
+         * Get the value of the parameter.
          */
-        public String getSubnet() {
-            return (subnet);
+        public String getValue() {
+            return (value);
+        }
+    }
+
+    /**
+     * Raw configuration entry for a data feed.
+     */
+    public static class ProvFeed {
+
+        private String id;
+        private String logdata;
+        private String status;
+        private String createdDate;
+        /*
+         * AAF changes: TDP EPIC US# 307413
+         * Passing aafInstance from to identify legacy/AAF feeds
+         */
+        private String aafInstance;
+
+        /**
+         * Construct a feed configuration entry.
+         *
+         * @param id The feed ID of the entry.
+         * @param logdata String for log entries about the entry.
+         * @param status The reason why this feed cannot be used (Feed has been deleted, Feed has been suspended) or
+         *      null if it is valid.
+         */
+        public ProvFeed(String id, String logdata, String status, String createdDate, String aafInstance) {
+            this.id = id;
+            this.logdata = logdata;
+            this.status = status;
+            this.createdDate = createdDate;
+            this.aafInstance = aafInstance;
+        }
+
+        /**
+         * Get the created date of the data feed.
+         */
+        public String getCreatedDate() {
+            return (createdDate);
+        }
+
+        /**
+         * Get the aafInstance of the data feed.
+         */
+        public String getAafInstance() {
+            return aafInstance;
+        }
+
+        /**
+         * Get the feed id of the data feed.
+         */
+        public String getId() {
+            return (id);
+        }
+
+        /**
+         * Get the log data of the data feed.
+         */
+        public String getLogData() {
+            return (logdata);
+        }
+
+        /**
+         * Get the status of the data feed.
+         */
+        public String getStatus() {
+            return (status);
+        }
+    }
+
+    /**
+     * Raw configuration entry for a feed user.
+     */
+    public static class ProvFeedUser {
+
+        private String feedid;
+        private String user;
+        private String credentials;
+
+        /**
+         * Construct a feed user configuration entry.
+         *
+         * @param feedid The feed id.
+         * @param user The user that will publish to the feed.
+         * @param credentials The Authorization header the user will use to publish.
+         */
+        public ProvFeedUser(String feedid, String user, String credentials) {
+            this.feedid = feedid;
+            this.user = user;
+            this.credentials = credentials;
+        }
+
+        /**
+         * Get the feed id of the feed user.
+         */
+        public String getFeedId() {
+            return (feedid);
         }
 
         /**
-         * Get the user
+         * Get the user for the feed user.
          */
         public String getUser() {
             return (user);
         }
 
         /**
-         * Get the node
+         * Get the credentials for the feed user.
          */
-        public String[] getNodes() {
-            return (nodes);
+        public String getCredentials() {
+            return (credentials);
         }
     }
 
     /**
-     * Raw configuration entry for controlled egress from the data router
+     * Raw configuration entry for a feed subnet.
      */
-    public static class ProvForceEgress {
+    public static class ProvFeedSubnet {
 
-        private String subid;
-        private String node;
+        private String feedid;
+        private String cidr;
 
         /**
-         * Construct a forced egress configuration entry
+         * Construct a feed subnet configuration entry.
          *
-         * @param subid The subscription ID the subscription with forced egress
-         * @param node The node handling deliveries for this subscription
+         * @param feedid The feed ID
+         * @param cidr The CIDR allowed to publish to the feed.
          */
-        public ProvForceEgress(String subid, String node) {
-            this.subid = subid;
-            this.node = node;
+        public ProvFeedSubnet(String feedid, String cidr) {
+            this.feedid = feedid;
+            this.cidr = cidr;
         }
 
         /**
-         * Get the subscription ID
+         * Get the feed id of the feed subnet.
          */
-        public String getSubId() {
-            return (subid);
+        public String getFeedId() {
+            return (feedid);
         }
 
         /**
-         * Get the node
+         * Get the CIDR of the feed subnet.
          */
-        public String getNode() {
-            return (node);
+        public String getCidr() {
+            return (cidr);
         }
     }
 
     /**
-     * Raw configuration entry for routing within the data router network
+     * Raw configuration entry for a subscription.
      */
-    public static class ProvHop {
+    public static class ProvSubscription {
 
-        private String from;
-        private String to;
-        private String via;
+        private String subid;
+        private String feedid;
+        private String url;
+        private String authuser;
+        private String credentials;
+        private boolean metaonly;
+        private boolean use100;
+        private boolean privilegedSubscriber;
+        private boolean followRedirect;
+        private boolean decompress;
 
         /**
-         * A human readable description of this entry
+         * Construct a subscription configuration entry.
+         *
+         * @param subid The subscription ID
+         * @param feedid The feed ID
+         * @param url The base delivery URL (not including the fileid)
+         * @param authuser The user in the credentials used to deliver
+         * @param credentials The credentials used to authenticate to the delivery URL exactly as they go in the
+         *      Authorization header.
+         * @param metaonly Is this a meta data only subscription?
+         * @param use100 Should we send Expect: 100-continue?
+         * @param privilegedSubscriber Can we wait to receive a delete file call before deleting file
+         * @param followRedirect Is follow redirect of destination enabled?
+         * @param decompress To see if they want their information compressed or decompressed
          */
-        public String toString() {
-            return ("Hop " + from + "->" + to + " via " + via);
+        public ProvSubscription(String subid, String feedid, String url, String authuser, String credentials,
+                boolean metaonly, boolean use100, boolean privilegedSubscriber, boolean followRedirect,
+                boolean decompress) {
+            this.subid = subid;
+            this.feedid = feedid;
+            this.url = url;
+            this.authuser = authuser;
+            this.credentials = credentials;
+            this.metaonly = metaonly;
+            this.use100 = use100;
+            this.privilegedSubscriber = privilegedSubscriber;
+            this.followRedirect = followRedirect;
+            this.decompress = decompress;
         }
 
         /**
-         * Construct a hop entry
-         *
-         * @param from The FQDN of the node with the data to be delivered
-         * @param to The FQDN of the node that will deliver to the subscriber
-         * @param via The FQDN of the node where the from node should send the data
+         * Get the subscription ID.
          */
-        public ProvHop(String from, String to, String via) {
-            this.from = from;
-            this.to = to;
-            this.via = via;
+        public String getSubId() {
+            return (subid);
         }
 
         /**
-         * Get the from node
+         * Get the feed ID.
          */
-        public String getFrom() {
-            return (from);
+        public String getFeedId() {
+            return (feedid);
         }
 
         /**
-         * Get the to node
+         * Get the delivery URL.
          */
-        public String getTo() {
-            return (to);
+        public String getURL() {
+            return (url);
         }
 
         /**
-         * Get the next intermediate node
+         * Get the user.
          */
-        public String getVia() {
-            return (via);
+        public String getAuthUser() {
+            return (authuser);
         }
-    }
 
-    private static class Redirection {
+        /**
+         * Get the delivery credentials.
+         */
+        public String getCredentials() {
+            return (credentials);
+        }
 
-        SubnetMatcher snm;
-        String user;
-        String[] nodes;
-    }
+        /**
+         * Is this a meta data only subscription.
+         */
+        public boolean isMetaDataOnly() {
+            return (metaonly);
+        }
 
-    private static class Feed {
+        /**
+         * Should we send Expect: 100-continue.
+         */
+        public boolean isUsing100() {
+            return (use100);
+        }
 
-        String loginfo;
-        String status;
-        SubnetMatcher[] subnets;
-        Hashtable<String, String> authusers = new Hashtable<String, String>();
-        Redirection[] redirections;
-        Target[] targets;
-        String createdDate;
-        String aafInstance;
-    }
+        /**
+         * Can we wait to receive a delete file call before deleting file.
+         */
+        public boolean isPrivilegedSubscriber() {
+            return (privilegedSubscriber);
+        }
 
-    private Hashtable<String, String> params = new Hashtable<>();
-    private Hashtable<String, Feed> feeds = new Hashtable<>();
-    private Hashtable<String, DestInfo> nodeinfo = new Hashtable<>();
-    private Hashtable<String, DestInfo> subinfo = new Hashtable<>();
-    private Hashtable<String, IsFrom> nodes = new Hashtable<>();
-    private Hashtable<String, ProvSubscription> provSubscriptions = new Hashtable<>();
-    private String myname;
-    private String myauth;
-    private DestInfo[] alldests;
-    private int rrcntr;
+        /**
+         * Should I decompress the file before sending it on.
+         */
+        public boolean isDecompress() {
+            return (decompress);
+        }
+
+        /**
+         * New field is added - FOLLOW_REDIRECTS feature iTrack:DATARTR-17 - 1706 Get the followRedirect of this
+         * destination.
+         */
+        boolean getFollowRedirect() {
+            return (followRedirect);
+        }
+    }
 
     /**
-     * Process the raw provisioning data to configure this node
-     *
-     * @param pd The parsed provisioning data
-     * @param myname My name as seen by external systems
-     * @param spooldir The directory where temporary files live
-     * @param port The port number for URLs
-     * @param nodeauthkey The keying string used to generate node authentication credentials
+     * Raw configuration entry for controlled ingress to the data router node.
      */
-    public NodeConfig(ProvData pd, String myname, String spooldir, int port, String nodeauthkey) {
-        this.myname = myname;
-        for (ProvParam p : pd.getParams()) {
-            params.put(p.getName(), p.getValue());
-        }
-        Vector<DestInfo> destInfos = new Vector<>();
-        myauth = NodeUtils.getNodeAuthHdr(myname, nodeauthkey);
-        for (ProvNode pn : pd.getNodes()) {
-            String cName = pn.getCName();
-            if (nodeinfo.get(cName) != null) {
-                continue;
-            }
-            String auth = NodeUtils.getNodeAuthHdr(cName, nodeauthkey);
-            DestInfo di = new DestInfo.DestInfoBuilder().setName("n:" + cName).setSpool(spooldir + "/n/" + cName).setSubid(null)
-                .setLogdata("n2n-" + cName).setUrl("https://" + cName + ":" + port + "/internal/publish")
-                .setAuthuser(cName).setAuthentication(myauth).setMetaonly(false).setUse100(true)
-                .setPrivilegedSubscriber(false).setFollowRedirects(false).setDecompress(false).createDestInfo();
-            (new File(di.getSpool())).mkdirs();
-            destInfos.add(di);
-            nodeinfo.put(cName, di);
-            nodes.put(auth, new IsFrom(cName));
-        }
-        PathFinder pf = new PathFinder(myname, nodeinfo.keySet().toArray(new String[0]), pd.getHops());
-        Hashtable<String, Vector<Redirection>> rdtab = new Hashtable<>();
-        for (ProvForceIngress pfi : pd.getForceIngress()) {
-            Vector<Redirection> v = rdtab.get(pfi.getFeedId());
-            if (v == null) {
-                v = new Vector<>();
-                rdtab.put(pfi.getFeedId(), v);
-            }
-            Redirection r = new Redirection();
-            if (pfi.getSubnet() != null) {
-                r.snm = new SubnetMatcher(pfi.getSubnet());
-            }
-            r.user = pfi.getUser();
-            r.nodes = pfi.getNodes();
-            v.add(r);
-        }
-        Hashtable<String, Hashtable<String, String>> pfutab = new Hashtable<>();
-        for (ProvFeedUser pfu : pd.getFeedUsers()) {
-            Hashtable<String, String> t = pfutab.get(pfu.getFeedId());
-            if (t == null) {
-                t = new Hashtable<>();
-                pfutab.put(pfu.getFeedId(), t);
-            }
-            t.put(pfu.getCredentials(), pfu.getUser());
-        }
-        Hashtable<String, String> egrtab = new Hashtable<>();
-        for (ProvForceEgress pfe : pd.getForceEgress()) {
-            if (pfe.getNode().equals(myname) || nodeinfo.get(pfe.getNode()) == null) {
-                continue;
-            }
-            egrtab.put(pfe.getSubId(), pfe.getNode());
-        }
-        Hashtable<String, Vector<SubnetMatcher>> pfstab = new Hashtable<>();
-        for (ProvFeedSubnet pfs : pd.getFeedSubnets()) {
-            Vector<SubnetMatcher> v = pfstab.get(pfs.getFeedId());
-            if (v == null) {
-                v = new Vector<>();
-                pfstab.put(pfs.getFeedId(), v);
-            }
-            v.add(new SubnetMatcher(pfs.getCidr()));
-        }
-        Hashtable<String, StringBuffer> feedTargets = new Hashtable<>();
-        HashSet<String> allfeeds = new HashSet<>();
-        for (ProvFeed pfx : pd.getFeeds()) {
-            if (pfx.getStatus() == null) {
-                allfeeds.add(pfx.getId());
-            }
-        }
-        for (ProvSubscription provSubscription : pd.getSubscriptions()) {
-            String subId = provSubscription.getSubId();
-            String feedId = provSubscription.getFeedId();
-            if (!allfeeds.contains(feedId)) {
-                continue;
-            }
-            if (subinfo.get(subId) != null) {
-                continue;
-            }
-            int sididx = 999;
-            try {
-                sididx = Integer.parseInt(subId);
-                sididx -= sididx % 100;
-            } catch (Exception e) {
-                logger.error("NODE0517 Exception NodeConfig: "+e);
-            }
-            String subscriptionDirectory = sididx + "/" + subId;
-            DestInfo destinationInfo = new DestInfo("s:" + subId,
-                    spooldir + "/s/" + subscriptionDirectory, provSubscription);
-            (new File(destinationInfo.getSpool())).mkdirs();
-            destInfos.add(destinationInfo);
-            provSubscriptions.put(subId, provSubscription);
-            subinfo.put(subId, destinationInfo);
-            String egr = egrtab.get(subId);
-            if (egr != null) {
-                subId = pf.getPath(egr) + subId;
-            }
-            StringBuffer sb = feedTargets.get(feedId);
-            if (sb == null) {
-                sb = new StringBuffer();
-                feedTargets.put(feedId, sb);
-            }
-            sb.append(' ').append(subId);
-        }
-        alldests = destInfos.toArray(new DestInfo[0]);
-        for (ProvFeed pfx : pd.getFeeds()) {
-            String fid = pfx.getId();
-            Feed f = feeds.get(fid);
-            if (f != null) {
-                continue;
-            }
-            f = new Feed();
-            feeds.put(fid, f);
-            f.createdDate = pfx.getCreatedDate();
-            f.loginfo = pfx.getLogData();
-            f.status = pfx.getStatus();
-            /*
-             * AAF changes: TDP EPIC US# 307413
-             * Passing aafInstance from ProvFeed to identify legacy/AAF feeds
-             */
-            f.aafInstance = pfx.getAafInstance();
-            Vector<SubnetMatcher> v1 = pfstab.get(fid);
-            if (v1 == null) {
-                f.subnets = new SubnetMatcher[0];
-            } else {
-                f.subnets = v1.toArray(new SubnetMatcher[0]);
-            }
-            Hashtable<String, String> h1 = pfutab.get(fid);
-            if (h1 == null) {
-                h1 = new Hashtable<String, String>();
-            }
-            f.authusers = h1;
-            Vector<Redirection> v2 = rdtab.get(fid);
-            if (v2 == null) {
-                f.redirections = new Redirection[0];
-            } else {
-                f.redirections = v2.toArray(new Redirection[0]);
-            }
-            StringBuffer sb = feedTargets.get(fid);
-            if (sb == null) {
-                f.targets = new Target[0];
-            } else {
-                f.targets = parseRouting(sb.toString());
-            }
-        }
-    }
+    public static class ProvForceIngress {
 
-    /**
-     * Parse a target string into an array of targets
-     *
-     * @param routing Target string
-     * @return Array of targets.
-     */
-    public Target[] parseRouting(String routing) {
-        routing = routing.trim();
-        if ("".equals(routing)) {
-            return (new Target[0]);
-        }
-        String[] xx = routing.split("\\s+");
-        Hashtable<String, Target> tmap = new Hashtable<String, Target>();
-        HashSet<String> subset = new HashSet<String>();
-        Vector<Target> tv = new Vector<Target>();
-        Target[] ret = new Target[xx.length];
-        for (int i = 0; i < xx.length; i++) {
-            String t = xx[i];
-            int j = t.indexOf('/');
-            if (j == -1) {
-                DestInfo di = subinfo.get(t);
-                if (di == null) {
-                    tv.add(new Target(null, t));
-                } else {
-                    if (!subset.contains(t)) {
-                        subset.add(t);
-                        tv.add(new Target(di, null));
-                    }
-                }
+        private String feedid;
+        private String subnet;
+        private String user;
+        private String[] nodes;
+
+        /**
+         * Construct a forced ingress configuration entry.
+         *
+         * @param feedid The feed ID that this entry applies to
+         * @param subnet The CIDR for which publisher IP addresses this entry applies to or "" if it applies to all
+         *      publisher IP addresses
+         * @param user The publishing user this entry applies to or "" if it applies to all publishing users.
+         * @param nodes The array of FQDNs of the data router nodes to redirect publication attempts to.
+         */
+        public ProvForceIngress(String feedid, String subnet, String user, String[] nodes) {
+            this.feedid = feedid;
+            this.subnet = subnet;
+            this.user = user;
+            //Sonar fix
+            if (nodes == null) {
+                this.nodes = new String[0];
             } else {
-                String node = t.substring(0, j);
-                String rtg = t.substring(j + 1);
-                DestInfo di = nodeinfo.get(node);
-                if (di == null) {
-                    tv.add(new Target(null, t));
-                } else {
-                    Target tt = tmap.get(node);
-                    if (tt == null) {
-                        tt = new Target(di, rtg);
-                        tmap.put(node, tt);
-                        tv.add(tt);
-                    } else {
-                        tt.addRouting(rtg);
-                    }
-                }
+                this.nodes = Arrays.copyOf(nodes, nodes.length);
             }
         }
-        return (tv.toArray(new Target[0]));
-    }
-
-    /**
-     * Check whether this is a valid node-to-node transfer
-     *
-     * @param credentials Credentials offered by the supposed node
-     * @param ip IP address the request came from
-     */
-    public boolean isAnotherNode(String credentials, String ip) {
-        IsFrom n = nodes.get(credentials);
-        return (n != null && n.isFrom(ip));
-    }
 
-    /**
-     * Check whether publication is allowed.
-     *
-     * @param feedid The ID of the feed being requested.
-     * @param credentials The offered credentials
-     * @param ip The requesting IP address
-     */
-    public String isPublishPermitted(String feedid, String credentials, String ip) {
-        Feed f = feeds.get(feedid);
-        String nf = "Feed does not exist";
-        if (f != null) {
-            nf = f.status;
-        }
-        if (nf != null) {
-            return (nf);
+        /**
+         * Get the feed ID.
+         */
+        public String getFeedId() {
+            return (feedid);
         }
-        String user = f.authusers.get(credentials);
-        if (user == null) {
-            return ("Publisher not permitted for this feed");
+
+        /**
+         * Get the subnet.
+         */
+        public String getSubnet() {
+            return (subnet);
         }
-        if (f.subnets.length == 0) {
-            return (null);
+
+        /**
+         * Get the user.
+         */
+        public String getUser() {
+            return (user);
         }
-        byte[] addr = NodeUtils.getInetAddress(ip);
-        for (SubnetMatcher snm : f.subnets) {
-            if (snm.matches(addr)) {
-                return (null);
-            }
+
+        /**
+         * Get the node.
+         */
+        public String[] getNodes() {
+            return (nodes);
         }
-        return ("Publisher not permitted for this feed");
     }
 
     /**
-     * Check whether delete file is allowed.
-     *
-     * @param subId The ID of the subscription being requested.
+     * Raw configuration entry for controlled egress from the data router.
      */
-    public boolean isDeletePermitted(String subId) {
-        ProvSubscription provSubscription = provSubscriptions.get(subId);
-        return provSubscription.isPrivilegedSubscriber();
-    }
+    public static class ProvForceEgress {
 
-    /**
-     * Check whether publication is allowed for AAF Feed.
-     * @param feedid The ID of the feed being requested.
-     * @param ip The requesting IP address
-     */
-    public String isPublishPermitted(String feedid, String ip) {
-        Feed f = feeds.get(feedid);
-        String nf = "Feed does not exist";
-        if (f != null) {
-            nf = f.status;
-        }
-        if (nf != null) {
-            return(nf);
+        private String subid;
+        private String node;
+
+        /**
+         * Construct a forced egress configuration entry.
+         *
+         * @param subid The subscription ID the subscription with forced egress
+         * @param node The node handling deliveries for this subscription
+         */
+        public ProvForceEgress(String subid, String node) {
+            this.subid = subid;
+            this.node = node;
         }
-        if (f.subnets.length == 0) {
-            return(null);
+
+        /**
+         * Get the subscription ID.
+         */
+        public String getSubId() {
+            return (subid);
         }
-        byte[] addr = NodeUtils.getInetAddress(ip);
-        for (SubnetMatcher snm: f.subnets) {
-            if (snm.matches(addr)) {
-                return(null);
-            }
+
+        /**
+         * Get the node.
+         */
+        public String getNode() {
+            return (node);
         }
-        return("Publisher not permitted for this feed");
     }
 
     /**
-     * Get authenticated user
+     * Raw configuration entry for routing within the data router network.
      */
-    public String getAuthUser(String feedid, String credentials) {
-        return (feeds.get(feedid).authusers.get(credentials));
-    }
+    public static class ProvHop {
 
-    /**
-     * AAF changes: TDP EPIC US# 307413
-     * Check AAF_instance for feed ID
-     * @param feedid   The ID of the feed specified
-     */
-    public String getAafInstance(String feedid) {
-        Feed f = feeds.get(feedid);
-        return f.aafInstance;
-    }
+        private String from;
+        private String to;
+        private String via;
 
-    /**
-     * Check if the request should be redirected to a different ingress node
-     */
-    public String getIngressNode(String feedid, String user, String ip) {
-        Feed f = feeds.get(feedid);
-        if (f.redirections.length == 0) {
-            return (null);
-        }
-        byte[] addr = NodeUtils.getInetAddress(ip);
-        for (Redirection r : f.redirections) {
-            if (r.user != null && !user.equals(r.user)) {
-                continue;
-            }
-            if (r.snm != null && !r.snm.matches(addr)) {
-                continue;
-            }
-            for (String n : r.nodes) {
-                if (myname.equals(n)) {
-                    return (null);
-                }
-            }
-            if (r.nodes.length == 0) {
-                return (null);
-            }
-            return (r.nodes[rrcntr++ % r.nodes.length]);
+        /**
+         * Construct a hop entry.
+         *
+         * @param from The FQDN of the node with the data to be delivered
+         * @param to The FQDN of the node that will deliver to the subscriber
+         * @param via The FQDN of the node where the from node should send the data
+         */
+        public ProvHop(String from, String to, String via) {
+            this.from = from;
+            this.to = to;
+            this.via = via;
         }
-        return (null);
-    }
 
-    /**
-     * Get a provisioned configuration parameter
-     */
-    public String getProvParam(String name) {
-        return (params.get(name));
-    }
+        /**
+         * A human readable description of this entry.
+         */
+        public String toString() {
+            return ("Hop " + from + "->" + to + " via " + via);
+        }
 
-    /**
-     * Get all the DestInfos
-     */
-    public DestInfo[] getAllDests() {
-        return (alldests);
-    }
+        /**
+         * Get the from node.
+         */
+        public String getFrom() {
+            return (from);
+        }
 
-    /**
-     * Get the targets for a feed
-     *
-     * @param feedid The feed ID
-     * @return The targets this feed should be delivered to
-     */
-    public Target[] getTargets(String feedid) {
-        if (feedid == null) {
-            return (new Target[0]);
+        /**
+         * Get the to node.
+         */
+        public String getTo() {
+            return (to);
         }
-        Feed f = feeds.get(feedid);
-        if (f == null) {
-            return (new Target[0]);
+
+        /**
+         * Get the next intermediate node.
+         */
+        public String getVia() {
+            return (via);
         }
-        return (f.targets);
     }
 
-    /**
-     * Get the creation date for a feed
-     * @param feedid The feed ID
-     * @return the timestamp of creation date of feed id passed
-     */
-    public String getCreatedDate(String feedid) {
-        Feed f = feeds.get(feedid);
-        return(f.createdDate);
-    }
+    private static class Redirection {
 
-    /**
-     * Get the feed ID for a subscription
-     *
-     * @param subid The subscription ID
-     * @return The feed ID
-     */
-    public String getFeedId(String subid) {
-        DestInfo di = subinfo.get(subid);
-        if (di == null) {
-            return (null);
-        }
-        return (di.getLogData());
+        SubnetMatcher snm;
+        String user;
+        String[] nodes;
     }
 
-    /**
-     * Get the spool directory for a subscription
-     *
-     * @param subid The subscription ID
-     * @return The spool directory
-     */
-    public String getSpoolDir(String subid) {
-        DestInfo di = subinfo.get(subid);
-        if (di == null) {
-            return (null);
-        }
-        return (di.getSpool());
-    }
+    private static class Feed {
 
-    /**
-     * Get the Authorization value this node uses
-     *
-     * @return The Authorization header value for this node
-     */
-    public String getMyAuth() {
-        return (myauth);
+        String loginfo;
+        String status;
+        SubnetMatcher[] subnets;
+        HashMap<String, String> authusers = new HashMap<>();
+        Redirection[] redirections;
+        Target[] targets;
+        String createdDate;
+        String aafInstance;
     }
-
 }
index 16099e6..786befc 100644 (file)
@@ -26,8 +26,6 @@ package org.onap.dmaap.datarouter.node;
 
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
-
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.InputStreamReader;
@@ -35,22 +33,24 @@ import java.io.Reader;
 import java.net.URL;
 import java.util.Properties;
 import java.util.Timer;
+import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
 
 
 /**
  * Maintain the configuration of a Data Router node
- * <p>
- * The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
+ *
+ * <p>The NodeConfigManager is the single point of contact for servlet, delivery, event logging, and log retention
  * subsystems to access configuration information.
- * <p>
- * There are two basic sets of configuration data.  The static local configuration data, stored in a local configuration
- * file (created as part of installation by SWM), and the dynamic global configuration data fetched from the data router
- * provisioning server.
+ *
+ * <p>There are two basic sets of configuration data.  The static local configuration data, stored in a local
+ * configuration file (created as part of installation by SWM), and the dynamic global configuration data fetched from
+ * the data router provisioning server.
  */
 public class NodeConfigManager implements DeliveryQueueHelper {
 
-    private static EELFLogger eelfLogger = EELFManager.getInstance()
-            .getLogger(NodeConfigManager.class);
+    private static final String CHANGE_ME = "changeme";
+    private static final String NODE_CONFIG_MANAGER = "NodeConfigManager";
+    private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(NodeConfigManager.class);
     private static NodeConfigManager base = new NodeConfigManager();
 
     private Timer timer = new Timer("Node Configuration Timer", true);
@@ -94,7 +94,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     private String eventlogsuffix;
     private String eventloginterval;
     private boolean followredirects;
-    private String [] enabledprotocols;
+    private String[] enabledprotocols;
     private String aafType;
     private String aafInstance;
     private String aafAction;
@@ -103,14 +103,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
 
 
     /**
-     * Get the default node configuration manager
-     */
-    public static NodeConfigManager getInstance() {
-        return base;
-    }
-
-    /**
-     * Initialize the configuration of a Data Router node
+     * Initialize the configuration of a Data Router node.
      */
     private NodeConfigManager() {
 
@@ -120,8 +113,10 @@ public class NodeConfigManager implements DeliveryQueueHelper {
             drNodeProperties.load(new FileInputStream(System
                     .getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties")));
         } catch (Exception e) {
-            NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
-            eelfLogger.error(EelfMsgs.MESSAGE_PROPERTIES_LOAD_ERROR, System.getProperty("org.onap.dmaap.datarouter.node.properties", "/opt/app/datartr/etc/node.properties"));
+            NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
+            eelfLogger.error(EelfMsgs.MESSAGE_PROPERTIES_LOAD_ERROR, e,
+                    System.getProperty("org.onap.dmaap.datarouter.node.properties",
+                            "/opt/app/datartr/etc/node.properties"));
         }
         provurl = drNodeProperties.getProperty("ProvisioningURL", "https://dmaap-dr-prov:8443/internal/prov");
         /*
@@ -143,8 +138,8 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         try {
             provhost = (new URL(provurl)).getHost();
         } catch (Exception e) {
-            NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
-            eelfLogger.error(EelfMsgs.MESSAGE_BAD_PROV_URL, provurl);
+            NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
+            eelfLogger.error(EelfMsgs.MESSAGE_BAD_PROV_URL, e, provurl);
             System.exit(1);
         }
         eelfLogger.info("NODE0303 Provisioning server is " + provhost);
@@ -153,8 +148,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         gfport = Integer.parseInt(drNodeProperties.getProperty("IntHttpPort", "8080"));
         svcport = Integer.parseInt(drNodeProperties.getProperty("IntHttpsPort", "8443"));
         port = Integer.parseInt(drNodeProperties.getProperty("ExtHttpsPort", "443"));
-        long minpfinterval = Long.parseLong(drNodeProperties.getProperty("MinProvFetchInterval", "10000"));
-        long minrsinterval = Long.parseLong(drNodeProperties.getProperty("MinRedirSaveInterval", "10000"));
         spooldir = drNodeProperties.getProperty("SpoolDir", "spool");
         File fdir = new File(spooldir + "/f");
         fdir.mkdirs();
@@ -168,14 +161,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         logretention = Long.parseLong(drNodeProperties.getProperty("LogRetention", "30")) * 86400000L;
         eventlogprefix = logdir + "/events";
         eventlogsuffix = ".log";
-        String redirfile = drNodeProperties.getProperty("RedirectionFile", "etc/redirections.dat");
+        redirfile = drNodeProperties.getProperty("RedirectionFile", "etc/redirections.dat");
         kstype = drNodeProperties.getProperty("KeyStoreType", "jks");
         ksfile = drNodeProperties.getProperty("KeyStoreFile", "etc/keystore");
-        kspass = drNodeProperties.getProperty("KeyStorePassword", "changeme");
-        kpass = drNodeProperties.getProperty("KeyPassword", "changeme");
+        kspass = drNodeProperties.getProperty("KeyStorePassword", CHANGE_ME);
+        kpass = drNodeProperties.getProperty("KeyPassword", CHANGE_ME);
         tstype = drNodeProperties.getProperty("TrustStoreType", "jks");
         tsfile = drNodeProperties.getProperty("TrustStoreFile");
-        tspass = drNodeProperties.getProperty("TrustStorePassword", "changeme");
+        tspass = drNodeProperties.getProperty("TrustStorePassword", CHANGE_ME);
         if (tsfile != null && tsfile.length() > 0) {
             System.setProperty("javax.net.ssl.trustStoreType", tstype);
             System.setProperty("javax.net.ssl.trustStore", tsfile);
@@ -185,13 +178,15 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         quiesce = new File(drNodeProperties.getProperty("QuiesceFile", "etc/SHUTDOWN"));
         myname = NodeUtils.getCanonicalName(kstype, ksfile, kspass);
         if (myname == null) {
-            NodeUtils.setIpAndFqdnForEelf("NodeConfigManager");
+            NodeUtils.setIpAndFqdnForEelf(NODE_CONFIG_MANAGER);
             eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_FETCH_ERROR, ksfile);
             eelfLogger.error("NODE0309 Unable to fetch canonical name from keystore file " + ksfile);
             System.exit(1);
         }
         eelfLogger.info("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"));
         rdmgr = new RedirManager(redirfile, minrsinterval, timer);
         pfetcher = new RateLimitedOperation(minpfinterval, timer) {
             public void run() {
@@ -202,6 +197,13 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         pfetcher.request();
     }
 
+    /**
+     * Get the default node configuration manager.
+     */
+    public static NodeConfigManager getInstance() {
+        return base;
+    }
+
     private void localconfig() {
         followredirects = Boolean.parseBoolean(getProvParam("FOLLOW_REDIRECTS", "false"));
         eventloginterval = getProvParam("LOGROLL_INTERVAL", "30s");
@@ -218,42 +220,53 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         try {
             initfailuretimer = (long) (Double.parseDouble(getProvParam("DELIVERY_INIT_RETRY_INTERVAL")) * 1000);
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing DELIVERY_INIT_RETRY_INTERVAL", e);
         }
         try {
-            waitForFileProcessFailureTimer = (long) (Double.parseDouble(getProvParam("DELIVERY_FILE_PROCESS_INTERVAL")) * 1000);
+            waitForFileProcessFailureTimer = (long) (Double.parseDouble(getProvParam("DELIVERY_FILE_PROCESS_INTERVAL"))
+                    * 1000);
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing DELIVERY_FILE_PROCESS_INTERVAL", e);
         }
         try {
             maxfailuretimer = (long) (Double.parseDouble(getProvParam("DELIVERY_MAX_RETRY_INTERVAL")) * 1000);
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing DELIVERY_MAX_RETRY_INTERVAL", e);
         }
         try {
             expirationtimer = (long) (Double.parseDouble(getProvParam("DELIVERY_MAX_AGE")) * 1000);
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing DELIVERY_MAX_AGE", e);
         }
         try {
             failurebackoff = Double.parseDouble(getProvParam("DELIVERY_RETRY_RATIO"));
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing DELIVERY_RETRY_RATIO", e);
         }
         try {
             deliverythreads = Integer.parseInt(getProvParam("DELIVERY_THREADS"));
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing DELIVERY_THREADS", e);
         }
         try {
             fairfilelimit = Integer.parseInt(getProvParam("FAIR_FILE_LIMIT"));
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing FAIR_FILE_LIMIT", e);
         }
         try {
             fairtimelimit = (long) (Double.parseDouble(getProvParam("FAIR_TIME_LIMIT")) * 1000);
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing FAIR_TIME_LIMIT", e);
         }
         try {
             fdpstart = Double.parseDouble(getProvParam("FREE_DISK_RED_PERCENT")) / 100.0;
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing FREE_DISK_RED_PERCENT", e);
         }
         try {
             fdpstop = Double.parseDouble(getProvParam("FREE_DISK_YELLOW_PERCENT")) / 100.0;
         } catch (Exception e) {
+            eelfLogger.trace("Error parsing FREE_DISK_YELLOW_PERCENT", e);
         }
         if (fdpstart < 0.01) {
             fdpstart = 0.01;
@@ -272,26 +285,30 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     private void fetchconfig() {
         try {
             eelfLogger.info("NodeConfigMan.fetchConfig: provurl:: " + provurl);
-            Reader r = new InputStreamReader((new URL(provurl)).openStream());
-            config = new NodeConfig(new ProvData(r), myname, spooldir, port, nak);
+            Reader reader = new InputStreamReader((new URL(provurl)).openStream());
+            config = new NodeConfig(new ProvData(reader), myname, spooldir, port, nak);
             localconfig();
             configtasks.startRun();
-            Runnable rr;
-            while ((rr = configtasks.next()) != null) {
-                try {
-                    rr.run();
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0518 Exception fetchconfig: " + e);
-                }
-            }
+            runTasks();
         } catch (Exception e) {
             NodeUtils.setIpAndFqdnForEelf("fetchconfigs");
             eelfLogger.error(EelfMsgs.MESSAGE_CONF_FAILED, e.toString());
-            eelfLogger.error("NODE0306 Configuration failed " + e.toString() + " - try again later", e.getMessage());
+            eelfLogger.error("NODE0306 Configuration failed " + e.toString() + " - try again later", e);
             pfetcher.request();
         }
     }
 
+    private void runTasks() {
+        Runnable rr;
+        while ((rr = configtasks.next()) != null) {
+            try {
+                rr.run();
+            } catch (Exception e) {
+                eelfLogger.error("NODE0518 Exception fetchconfig: " + e);
+            }
+        }
+    }
+
     /**
      * Process a gofetch request from a particular IP address.  If the IP address is not an IP address we would go to to
      * fetch the provisioning data, ignore the request.  If the data has been fetched very recently (default 10
@@ -307,14 +324,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Am I configured?
+     * Am I configured.
      */
     public boolean isConfigured() {
         return (config != null);
     }
 
     /**
-     * Am I shut down?
+     * Am I shut down.
      */
     public boolean isShutdown() {
         return (quiesce.exists());
@@ -331,7 +348,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Given a set of credentials and an IP address, is this request from another node?
+     * Given a set of credentials and an IP address, is this request from another node.
      *
      * @param credentials Credentials offered by the supposed node
      * @param ip IP address the request came from
@@ -353,16 +370,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (config.isPublishPermitted(feedid, credentials, ip));
     }
 
-    /**
-     * Check whether delete file is allowed.
-     *
-     * @param subId The ID of the subscription being requested
-     * @return True if the delete file is permitted for the subscriber.
-     */
-    public boolean isDeletePermitted(String subId) {
-        return (config.isDeletePermitted(subId));
-    }
-
     /**
      * Check whether publication is allowed for AAF Feed.
      *
@@ -371,7 +378,17 @@ public class NodeConfigManager implements DeliveryQueueHelper {
      * @return True if the IP and credentials are valid for the specified feed.
      */
     public String isPublishPermitted(String feedid, String ip) {
-        return(config.isPublishPermitted(feedid, ip));
+        return (config.isPublishPermitted(feedid, ip));
+    }
+
+    /**
+     * Check whether delete file is allowed.
+     *
+     * @param subId The ID of the subscription being requested
+     * @return True if the delete file is permitted for the subscriber.
+     */
+    public boolean isDeletePermitted(String subId) {
+        return (config.isDeletePermitted(subId));
     }
 
     /**
@@ -386,12 +403,16 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * AAF changes: TDP EPIC US# 307413
-     * Check AAF_instance for feed ID in NodeConfig
+     * AAF changes: TDP EPIC US# 307413 Check AAF_instance for feed ID in NodeConfig.
+     *
      * @param feedid The ID of the feed specified
      */
     public String getAafInstance(String feedid) {
-        return(config.getAafInstance(feedid));
+        return (config.getAafInstance(feedid));
+    }
+
+    public String getAafInstance() {
+        return aafInstance;
     }
 
     /**
@@ -407,7 +428,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Get a provisioned configuration parameter (from the provisioning server configuration)
+     * Get a provisioned configuration parameter (from the provisioning server configuration).
      *
      * @param name The name of the parameter
      * @return The value of the parameter or null if it is not defined.
@@ -417,7 +438,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Get a provisioned configuration parameter (from the provisioning server configuration)
+     * Get a provisioned configuration parameter (from the provisioning server configuration).
      *
      * @param name The name of the parameter
      * @param defaultValue The value to use if the parameter is not defined
@@ -432,7 +453,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Generate a publish ID
+     * Generate a publish ID.
      */
     public String getPublishId() {
         return (pid.next());
@@ -446,14 +467,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Register a task to run whenever the configuration changes
+     * Register a task to run whenever the configuration changes.
      */
     public void registerConfigTask(Runnable task) {
         configtasks.addTask(task);
     }
 
     /**
-     * Deregister a task to run whenever the configuration changes
+     * Deregister a task to run whenever the configuration changes.
      */
     public void deregisterConfigTask(Runnable task) {
         configtasks.removeTask(task);
@@ -476,14 +497,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Is a destination redirected?
-     */
-    public boolean isDestRedirected(DestInfo destinfo) {
-        return (followredirects && rdmgr.isRedirected(destinfo.getSubId()));
-    }
-
-    /**
-     * Set up redirection on receipt of a 3XX from a target URL
+     * Set up redirection on receipt of a 3XX from a target URL.
      */
     public boolean handleRedirection(DestInfo destinationInfo, String redirto, String fileid) {
         fileid = "/" + fileid;
@@ -500,24 +514,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Set up redirection on receipt of a 3XX from a target URL
-     */
-    public boolean handleRedirectionSubLevel(DeliveryTask task, DestInfo destinfo, String redirto, String fileid) {
-        fileid = "/" + fileid;
-        String subid = destinfo.getSubId();
-        String purl = destinfo.getURL();
-        if (task.getFollowRedirects() && subid != null && redirto.endsWith(fileid)) {
-            redirto = redirto.substring(0, redirto.length() - fileid.length());
-            if (!redirto.equals(purl)) {
-                rdmgr.redirect(subid, purl, redirto);
-                return true;
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Handle unreachable target URL
+     * Handle unreachable target URL.
      */
     public void handleUnreachable(DestInfo destinationInfo) {
         String subid = destinationInfo.getSubId();
@@ -527,35 +524,35 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Get the timeout before retrying after an initial delivery failure
+     * Get the timeout before retrying after an initial delivery failure.
      */
     public long getInitFailureTimer() {
         return (initfailuretimer);
     }
 
     /**
-     * Get the timeout before retrying after delivery and wait for file processing
+     * Get the timeout before retrying after delivery and wait for file processing.
      */
     public long getWaitForFileProcessFailureTimer() {
         return (waitForFileProcessFailureTimer);
     }
 
     /**
-     * Get the maximum timeout between delivery attempts
+     * Get the maximum timeout between delivery attempts.
      */
     public long getMaxFailureTimer() {
         return (maxfailuretimer);
     }
 
     /**
-     * Get the ratio between consecutive delivery attempts
+     * Get the ratio between consecutive delivery attempts.
      */
     public double getFailureBackoff() {
         return (failurebackoff);
     }
 
     /**
-     * Get the expiration timer for deliveries
+     * Get the expiration timer for deliveries.
      */
     public long getExpirationTimer() {
         return (expirationtimer);
@@ -576,7 +573,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Get the targets for a feed
+     * Get the targets for a feed.
      *
      * @param feedid The feed ID
      * @return The targets this feed should be delivered to
@@ -586,149 +583,160 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Get the creation date for a feed
-     * @param feedid The feed ID
-     * @return the timestamp of creation date of feed id passed
+     * Get the spool directory for temporary files.
      */
-    public String getCreatedDate(String feedid) {
-        return(config.getCreatedDate(feedid));
+    public String getSpoolDir() {
+        return (spooldir + "/f");
     }
 
     /**
-     * Get the spool directory for temporary files
+     * Get the spool directory for a subscription.
      */
-    public String getSpoolDir() {
-        return (spooldir + "/f");
+    public String getSpoolDir(String subid, String remoteaddr) {
+        if (provcheck.isFrom(remoteaddr)) {
+            String sdir = config.getSpoolDir(subid);
+            if (sdir != null) {
+                eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid
+                        + " from provisioning server " + remoteaddr);
+            } else {
+                eelfLogger.info("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);
+            return (null);
+        }
     }
 
     /**
-     * Get the base directory for spool directories
+     * Get the base directory for spool directories.
      */
     public String getSpoolBase() {
         return (spooldir);
     }
 
     /**
-     * Get the key store type
+     * Get the key store type.
      */
     public String getKSType() {
         return (kstype);
     }
 
     /**
-     * Get the key store file
+     * Get the key store file.
      */
     public String getKSFile() {
         return (ksfile);
     }
 
     /**
-     * Get the key store password
+     * Get the key store password.
      */
     public String getKSPass() {
         return (kspass);
     }
 
     /**
-     * Get the key password
+     * Get the key password.
      */
     public String getKPass() {
         return (kpass);
     }
 
     /**
-     * Get the http port
+     * Get the http port.
      */
     public int getHttpPort() {
         return (gfport);
     }
 
     /**
-     * Get the https port
+     * Get the https port.
      */
     public int getHttpsPort() {
         return (svcport);
     }
 
     /**
-     * Get the externally visible https port
+     * Get the externally visible https port.
      */
     public int getExtHttpsPort() {
         return (port);
     }
 
     /**
-     * Get the external name of this machine
+     * Get the external name of this machine.
      */
     public String getMyName() {
         return (myname);
     }
 
     /**
-     * Get the number of threads to use for delivery
+     * Get the number of threads to use for delivery.
      */
     public int getDeliveryThreads() {
         return (deliverythreads);
     }
 
     /**
-     * Get the URL for uploading the event log data
+     * Get the URL for uploading the event log data.
      */
     public String getEventLogUrl() {
         return (eventlogurl);
     }
 
     /**
-     * Get the prefix for the names of event log files
+     * Get the prefix for the names of event log files.
      */
     public String getEventLogPrefix() {
         return (eventlogprefix);
     }
 
     /**
-     * Get the suffix for the names of the event log files
+     * Get the suffix for the names of the event log files.
      */
     public String getEventLogSuffix() {
         return (eventlogsuffix);
     }
 
     /**
-     * Get the interval between event log file rollovers
+     * Get the interval between event log file rollovers.
      */
     public String getEventLogInterval() {
         return (eventloginterval);
     }
 
     /**
-     * Should I follow redirects from subscribers?
+     * Should I follow redirects from subscribers.
      */
     public boolean isFollowRedirects() {
         return (followredirects);
     }
 
     /**
-     * Get the directory where the event and node log files live
+     * Get the directory where the event and node log files live.
      */
     public String getLogDir() {
         return (logdir);
     }
 
     /**
-     * How long do I keep log files (in milliseconds)
+     * How long do I keep log files (in milliseconds).
      */
     public long getLogRetention() {
         return (logretention);
     }
 
     /**
-     * Get the timer
+     * Get the timer.
      */
     public Timer getTimer() {
         return (timer);
     }
 
     /**
-     * Get the feed ID for a subscription
+     * Get the feed ID for a subscription.
      *
      * @param subid The subscription ID
      * @return The feed ID
@@ -738,7 +746,7 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Get the authorization string this node uses
+     * Get the authorization string this node uses.
      *
      * @return The Authorization string for this node
      */
@@ -763,72 +771,33 @@ public class NodeConfigManager implements DeliveryQueueHelper {
     }
 
     /**
-     * Disable and enable protocols
-     * */
+     * Disable and enable protocols.
+     */
     public String[] getEnabledprotocols() {
         return enabledprotocols;
     }
-    public void setEnabledprotocols(String[] enabledprotocols) {
-        this.enabledprotocols = enabledprotocols.clone();
-    }
-
-    /**
-     * Get the spool directory for a subscription
-     */
-    public String getSpoolDir(String subid, String remoteaddr) {
-        if (provcheck.isFrom(remoteaddr)) {
-            String sdir = config.getSpoolDir(subid);
-            if (sdir != null) {
-                eelfLogger.info("NODE0310 Received subscription reset request for subscription " + subid
-                        + " from provisioning server " + remoteaddr);
-            } else {
-                eelfLogger.info("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);
-            return (null);
-        }
-    }
 
     public String getAafType() {
         return aafType;
     }
-    public void setAafType(String aafType) {
-        this.aafType = aafType;
-    }
-    public String getAafInstance() {
-        return aafInstance;
-    }
-    public void setAafInstance(String aafInstance) {
-        this.aafInstance = aafInstance;
-    }
+
     public String getAafAction() {
         return aafAction;
     }
-    public void setAafAction(String aafAction) {
-        this.aafAction = aafAction;
-    }
+
     /*
      * Get aafURL from SWM variable
      * */
     public String getAafURL() {
         return aafURL;
     }
-    public void setAafURL(String aafURL) {
-        this.aafURL = aafURL;
-    }
 
-    public boolean getCadiEnabeld() {
+    public boolean getCadiEnabled() {
         return cadiEnabled;
     }
-    public void setCadiEnabled(boolean cadiEnabled) {
-        this.cadiEnabled = cadiEnabled;
-    }
 
     /**
-     * Builds the permissions string to be verified
+     * Builds the permissions string to be verified.
      *
      * @param aafInstance The aaf instance
      * @return The permissions
@@ -837,12 +806,12 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         try {
             String type = getAafType();
             String action = getAafAction();
-            if (aafInstance == null || aafInstance.equals("")) {
+            if ("".equals(aafInstance)) {
                 aafInstance = getAafInstance();
             }
             return type + "|" + aafInstance + "|" + action;
         } catch (Exception e) {
-            eelfLogger.error("NODE0543 NodeConfigManager.getPermission: ", e.getMessage());
+            eelfLogger.error("NODE0543 NodeConfigManager.getPermission: ", e);
         }
         return null;
     }
index 058295d..abec739 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.EnumSet;
+import java.util.Properties;
+import javax.servlet.DispatcherType;
+import javax.servlet.ServletException;
 import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.server.*;
+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.FilterHolder;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.onap.aaf.cadi.PropAccess;
 
-import javax.servlet.DispatcherType;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.EnumSet;
-import java.util.Properties;
-
 /**
- * The main starting point for the Data Router node
+ * The main starting point for the Data Router node.
  */
 public class NodeMain {
 
-    private NodeMain() {
-    }
-
     private static EELFLogger nodeMainLogger = EELFManager.getInstance().getLogger(NodeMain.class);
-
-    class Inner {
-        InputStream getCadiProps() {
-            InputStream in = null;
-            try {
-                in = getClass().getClassLoader().getResourceAsStream("drNodeCadi.properties");
-            } catch (Exception e) {
-                nodeMainLogger.error("Exception in Inner.getCadiProps() method " + e.getMessage());
-            }
-            return in;
-        }
-    }
-
-    private static class WaitForConfig implements Runnable {
-
-        private NodeConfigManager localNodeConfigManager;
-
-        WaitForConfig(NodeConfigManager ncm) {
-            this.localNodeConfigManager = ncm;
-        }
-
-        public synchronized void run() {
-            notify();
-        }
-
-        synchronized void waitForConfig() {
-            localNodeConfigManager.registerConfigTask(this);
-            while (!localNodeConfigManager.isConfigured()) {
-                nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
-                try {
-                    wait();
-                } catch (Exception exception) {
-                    nodeMainLogger
-                            .error("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
-                                    exception);
-                }
-            }
-            localNodeConfigManager.deregisterConfigTask(this);
-            nodeMainLogger.info("NODE0004 Node Configuration Data Received");
-        }
-    }
-
     private static Delivery delivery;
     private static NodeConfigManager nodeConfigManager;
 
+    private NodeMain() {
+    }
+
     /**
-     * Reset the retry timer for a subscription
+     * Reset the retry timer for a subscription.
      */
     static void resetQueue(String subid, String ip) {
         delivery.resetQueue(nodeConfigManager.getSpoolDir(subid, ip));
@@ -103,9 +66,9 @@ public class NodeMain {
 
     /**
      * Start the data router.
-     * <p>
-     * The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties system
-     * property.  By default, it is "/opt/app/datartr/etc/node.properties".
+     *
+     * <p>The location of the node configuration file can be set using the org.onap.dmaap.datarouter.node.properties
+     * 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");
@@ -123,7 +86,8 @@ public class NodeMain {
         httpConfiguration.setRequestHeaderSize(2048);
 
         // HTTP connector
-        try (ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration))) {
+        try (ServerConnector httpServerConnector = new ServerConnector(server,
+                new HttpConnectionFactory(httpConfiguration))) {
             httpServerConnector.setPort(nodeConfigManager.getHttpPort());
             httpServerConnector.setIdleTimeout(2000);
 
@@ -134,7 +98,8 @@ public class NodeMain {
             sslContextFactory.setKeyStorePassword(nodeConfigManager.getKSPass());
             sslContextFactory.setKeyManagerPassword(nodeConfigManager.getKPass());
 
-            //SP-6 : Fixes for SDV scan to exclude/remove DES/3DES ciphers are taken care by upgrading jdk in descriptor.xml
+            //SP-6: Fixes for SDV scan to exclude/remove DES/3DES
+            // ciphers are taken care by upgrading jdk in descriptor.xml
             sslContextFactory.setExcludeCipherSuites(
                     "SSL_RSA_WITH_DES_CBC_SHA",
                     "SSL_DHE_RSA_WITH_DES_CBC_SHA",
@@ -147,9 +112,12 @@ public class NodeMain {
 
             sslContextFactory.addExcludeProtocols("SSLv3");
             sslContextFactory.setIncludeProtocols(nodeConfigManager.getEnabledprotocols());
-            nodeMainLogger.info("NODE00004 Unsupported protocols node server:-" + String.join(",", sslContextFactory.getExcludeProtocols()));
-            nodeMainLogger.info("NODE00004 Supported protocols node server:-" + String.join(",", sslContextFactory.getIncludeProtocols()));
-            nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-" + String.join(",", sslContextFactory.getExcludeCipherSuites()));
+            nodeMainLogger.info("NODE00004 Unsupported protocols node server:-"
+                    + String.join(",", sslContextFactory.getExcludeProtocols()));
+            nodeMainLogger.info("NODE00004 Supported protocols node server:-"
+                    + String.join(",", sslContextFactory.getIncludeProtocols()));
+            nodeMainLogger.info("NODE00004 Unsupported ciphers node server:-"
+                    + String.join(",", sslContextFactory.getExcludeCipherSuites()));
 
             HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
             httpsConfiguration.setRequestHeaderSize(8192);
@@ -174,20 +142,8 @@ public class NodeMain {
                 servletContextHandler.addServlet(new ServletHolder(new NodeServlet(delivery)), "/*");
 
                 //CADI Filter activation check
-                if (nodeConfigManager.getCadiEnabeld()) {
-                    Properties cadiProperties = new Properties();
-                    try {
-                        Inner obj = new NodeMain().new Inner();
-                        InputStream in = obj.getCadiProps();
-                        cadiProperties.load(in);
-                    } catch (IOException e1) {
-                        nodeMainLogger.error("NODE00005 Exception in NodeMain.Main() loading CADI properties " + e1.getMessage());
-                    }
-                    cadiProperties.setProperty("aaf_locate_url", nodeConfigManager.getAafURL());
-                    nodeMainLogger.info("NODE00005  aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
-
-                    PropAccess access = new PropAccess(cadiProperties);
-                    servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet.of(DispatcherType.REQUEST));
+                if (nodeConfigManager.getCadiEnabled()) {
+                    enableCadi(servletContextHandler);
                 }
 
                 server.setHandler(servletContextHandler);
@@ -199,9 +155,69 @@ public class NodeMain {
             server.start();
             nodeMainLogger.info("NODE00006 Node Server started-" + server.getState());
         } catch (Exception e) {
-            nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable", e.getMessage());
+            nodeMainLogger.info("NODE00006 Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e);
         }
         server.join();
         nodeMainLogger.info("NODE00007 Node Server joined - " + server.getState());
     }
+
+    private static void enableCadi(ServletContextHandler servletContextHandler) throws ServletException {
+        Properties cadiProperties = new Properties();
+        try {
+            Inner obj = new NodeMain().new Inner();
+            InputStream in = obj.getCadiProps();
+            cadiProperties.load(in);
+        } catch (IOException e1) {
+            nodeMainLogger
+                    .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"));
+
+        PropAccess access = new PropAccess(cadiProperties);
+        servletContextHandler.addFilter(new FilterHolder(new DRNodeCadiFilter(true, access)), "/*", EnumSet
+                .of(DispatcherType.REQUEST));
+    }
+
+    private static class WaitForConfig implements Runnable {
+
+        private NodeConfigManager localNodeConfigManager;
+
+        WaitForConfig(NodeConfigManager ncm) {
+            this.localNodeConfigManager = ncm;
+        }
+
+        public synchronized void run() {
+            notify();
+        }
+
+        synchronized void waitForConfig() {
+            localNodeConfigManager.registerConfigTask(this);
+            while (!localNodeConfigManager.isConfigured()) {
+                nodeMainLogger.info("NODE0003 Waiting for Node Configuration");
+                try {
+                    wait();
+                } catch (Exception exception) {
+                    nodeMainLogger
+                            .error("NodeMain: waitForConfig exception. Exception Message:- " + exception.toString(),
+                                    exception);
+                }
+            }
+            localNodeConfigManager.deregisterConfigTask(this);
+            nodeMainLogger.info("NODE0004 Node Configuration Data Received");
+        }
+    }
+
+    class Inner {
+
+        InputStream getCadiProps() {
+            InputStream in = null;
+            try {
+                in = getClass().getClassLoader().getResourceAsStream("drNodeCadi.properties");
+            } catch (Exception e) {
+                nodeMainLogger.error("Exception in Inner.getCadiProps() method ", e);
+            }
+            return in;
+        }
+    }
 }
index a984211..3b82484 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
+
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.jetbrains.annotations.Nullable;
-import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
-import org.slf4j.MDC;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
@@ -45,13 +40,17 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.regex.Pattern;
-
-import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.jetbrains.annotations.Nullable;
+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
- * <p>
- * Handled requests are:
+ * Servlet for handling all http and https requests to the data router node.
+ *
+ * <p>Handled requests are:
  * <br>
  * GET http://<i>node</i>/internal/fetchProv - fetch the provisioning data
  * <br>
@@ -61,29 +60,33 @@ import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
  */
 public class NodeServlet extends HttpServlet {
 
+    private static final String FROM = " from ";
+    private static final String INVALID_REQUEST_URI = "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.";
+    private static final String IO_EXCEPTION = "IOException";
+    private static final String ON_BEHALF_OF = "X-DMAAP-DR-ON-BEHALF-OF";
     private static NodeConfigManager config;
-    private static Pattern MetaDataPattern;
+    private static Pattern metaDataPattern;
     private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(NodeServlet.class);
-    private final Delivery delivery;
 
     static {
         final String ws = "\\s*";
         // assume that \\ and \" have been replaced by X
         final String string = "\"[^\"]*\"";
-        //String string = "\"(?:[^\"\\\\]|\\\\.)*\"";
         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);
+        metaDataPattern = Pattern.compile(object, Pattern.DOTALL);
     }
 
+    private final Delivery delivery;
+
     NodeServlet(Delivery delivery) {
         this.delivery = delivery;
     }
 
     /**
-     * Get the NodeConfigurationManager
+     * Get the NodeConfigurationManager.
      */
     @Override
     public void init() {
@@ -91,7 +94,7 @@ public class NodeServlet extends HttpServlet {
         eelfLogger.info("NODE0101 Node Servlet Configured");
     }
 
-    private boolean down(HttpServletResponse resp) throws IOException {
+    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");
@@ -101,7 +104,7 @@ public class NodeServlet extends HttpServlet {
     }
 
     /**
-     * Handle a GET for /internal/fetchProv
+     * Handle a GET for /internal/fetchProv.
      */
     @Override
     protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
@@ -109,15 +112,10 @@ public class NodeServlet extends HttpServlet {
         NodeUtils.setRequestIdAndInvocationId(req);
         eelfLogger.info(EelfMsgs.ENTRY);
         try {
-            eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
+            eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
                     getIdFromPath(req) + "");
-            try {
-                if (down(resp)) {
-                    return;
-                }
-
-            } catch (IOException ioe) {
-                eelfLogger.error("IOException" + ioe.getMessage());
+            if (down(resp)) {
+                return;
             }
             String path = req.getPathInfo();
             String qs = req.getQueryString();
@@ -138,7 +136,7 @@ public class NodeServlet extends HttpServlet {
                 }
             }
 
-            eelfLogger.info("NODE0103 Rejecting invalid GET of " + path + " from " + ip);
+            eelfLogger.info("NODE0103 Rejecting invalid GET of " + path + FROM + ip);
             sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, eelfLogger);
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
@@ -146,50 +144,55 @@ public class NodeServlet extends HttpServlet {
     }
 
     /**
-     * Handle all PUT requests
+     * Handle all PUT requests.
      */
     @Override
     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-DMAAP-DR-ON-BEHALF-OF"),
+        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
                 getIdFromPath(req) + "");
         try {
             common(req, resp, true);
         } catch (IOException ioe) {
-            eelfLogger.error("IOException" + ioe.getMessage());
+            eelfLogger.error(IO_EXCEPTION, ioe);
             eelfLogger.info(EelfMsgs.EXIT);
         }
     }
 
     /**
-     * Handle all DELETE requests
+     * Handle all DELETE requests.
      */
     @Override
     protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
         NodeUtils.setIpAndFqdnForEelf("doDelete");
         NodeUtils.setRequestIdAndInvocationId(req);
         eelfLogger.info(EelfMsgs.ENTRY);
-        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
+        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
                 getIdFromPath(req) + "");
         try {
             common(req, resp, false);
         } catch (IOException ioe) {
-            eelfLogger.error("IOException " + ioe.getMessage());
+            eelfLogger.error(IO_EXCEPTION, ioe);
             eelfLogger.info(EelfMsgs.EXIT);
         }
     }
 
     private void common(HttpServletRequest req, HttpServletResponse resp, boolean isput) throws IOException {
+        final String PUBLISH = "/publish/";
+        final String INTERNAL_PUBLISH = "/internal/publish/";
+        final String HTTPS = "https://";
+        final String USER = " user ";
         String fileid = getFileId(req, resp);
-        if (fileid == null) return;
+        if (fileid == null) {
+            return;
+        }
         String feedid = null;
         String user = null;
         String ip = req.getRemoteAddr();
         String lip = req.getLocalAddr();
         String pubid = null;
-        String xpubid = null;
         String rcvd = NodeUtils.logts(System.currentTimeMillis()) + ";from=" + ip + ";by=" + lip;
         Target[] targets = null;
         boolean isAAFFeed = false;
@@ -199,37 +202,38 @@ public class NodeServlet extends HttpServlet {
         }
         String credentials = req.getHeader("Authorization");
         if (credentials == null) {
-            eelfLogger.error("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0306 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization header required");
             eelfLogger.info(EelfMsgs.EXIT);
             return;
         }
-        if (fileid.startsWith("/publish/")) {
+        if (fileid.startsWith(PUBLISH)) {
             fileid = fileid.substring(9);
-            int i = fileid.indexOf('/');
-            if (i == -1 || i == fileid.length() - 1) {
-                eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            int index = fileid.indexOf('/');
+            if (index == -1 || index == fileid.length() - 1) {
+                eelfLogger.error("NODE0205 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                         .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);
+            feedid = fileid.substring(0, index);
 
-            if (config.getCadiEnabeld()) {
+            if (config.getCadiEnabled()) {
                 String path = req.getPathInfo();
                 if (!path.startsWith("/internal") && feedid != null) {
                     String aafInstance = config.getAafInstance(feedid);
-                    if (!(aafInstance.equalsIgnoreCase("legacy"))) {
+                    if (!("legacy".equalsIgnoreCase(aafInstance))) {
                         isAAFFeed = true;
                         String permission = config.getPermission(aafInstance);
                         eelfLogger.info("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;
-                            eelfLogger.error("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr());
+                            eelfLogger.error("NODE0307 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo()
+                                    + FROM + req.getRemoteAddr());
                             resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
                             eelfLogger.info(EelfMsgs.EXIT);
                             return;
@@ -238,11 +242,10 @@ public class NodeServlet extends HttpServlet {
                 }
             }
 
-            fileid = fileid.substring(i + 1);
+            fileid = fileid.substring(index + 1);
             pubid = config.getPublishId();
-            xpubid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
             targets = config.getTargets(feedid);
-        } else if (fileid.startsWith("/internal/publish/")) {
+        } else if (fileid.startsWith(INTERNAL_PUBLISH)) {
             if (!config.isAnotherNode(credentials, ip)) {
                 eelfLogger.error("NODE0107 Rejecting unauthorized node-to-node transfer attempt from " + ip);
                 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
@@ -254,18 +257,18 @@ public class NodeServlet extends HttpServlet {
             user = "datartr";   // SP6 : Added usr as datartr to avoid null entries for internal routing
             targets = config.parseRouting(req.getHeader("X-DMAAP-DR-ROUTING"));
         } else {
-            eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0204 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
-                    "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                    INVALID_REQUEST_URI);
             eelfLogger.info(EelfMsgs.EXIT);
             return;
         }
         if (fileid.indexOf('/') != -1) {
-            eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0202 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
-                    "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                    INVALID_REQUEST_URI);
             eelfLogger.info(EelfMsgs.EXIT);
             return;
         }
@@ -278,14 +281,16 @@ public class NodeServlet extends HttpServlet {
         if (xp != 443) {
             hp = hp + ":" + xp;
         }
-        String logurl = "https://" + hp + "/internal/publish/" + fileid;
+        String logurl = HTTPS + hp + INTERNAL_PUBLISH + fileid;
         if (feedid != null) {
-            logurl = "https://" + hp + "/publish/" + feedid + "/" + fileid;
+            logurl = HTTPS + hp + PUBLISH + feedid + "/" + fileid;
             //Cadi code starts
             if (!isAAFFeed) {
                 String reason = config.isPublishPermitted(feedid, credentials, ip);
                 if (reason != null) {
-                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil.cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + " from " + PathUtil.cleanString(ip) + " reason " + PathUtil.cleanString(reason));
+                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil
+                            .cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + FROM + PathUtil
+                            .cleanString(ip) + " reason " + PathUtil.cleanString(reason));
                     resp.sendError(HttpServletResponse.SC_FORBIDDEN, reason);
                     eelfLogger.info(EelfMsgs.EXIT);
                     return;
@@ -294,9 +299,12 @@ public class NodeServlet extends HttpServlet {
             } else {
                 String reason = config.isPublishPermitted(feedid, ip);
                 if (reason != null) {
-                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil.cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + " from " + PathUtil.cleanString(ip) + " reason   Invalid AAF user- " + PathUtil.cleanString(reason));
+                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil
+                            .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("NODE0106 Rejecting unauthenticated PUT or DELETE of " + PathUtil.cleanString(req.getPathInfo()) + " from " + PathUtil.cleanString(req.getRemoteAddr()));
+                    eelfLogger.info("NODE0308 Rejecting unauthenticated PUT or DELETE of " + PathUtil
+                            .cleanString(req.getPathInfo()) + FROM + PathUtil.cleanString(req.getRemoteAddr()));
                     resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
                     return;
                 }
@@ -316,25 +324,26 @@ public class NodeServlet extends HttpServlet {
                 if (iport != 443) {
                     port = ":" + iport;
                 }
-                String redirto = "https://" + newnode + port + "/publish/" + feedid + "/" + fileid;
-                eelfLogger.info("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
+                String redirto = HTTPS + newnode + port + PUBLISH + feedid + "/" + fileid;
+                eelfLogger
+                        .info("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
                 eelfLogger.info(EelfMsgs.EXIT);
                 return;
             }
             resp.setHeader("X-DMAAP-DR-PUBLISH-ID", pubid);
         }
-        if (req.getPathInfo().startsWith("/internal/publish/")) {
+        if (req.getPathInfo().startsWith(INTERNAL_PUBLISH)) {
             feedid = req.getHeader("X-DMAAP-DR-FEED-ID");
         }
         String fbase = PathUtil.cleanString(config.getSpoolDir() + "/" + pubid);  //Fortify scan fixes-Path manipulation
         File data = new File(fbase);
         File meta = new File(fbase + ".M");
-        OutputStream dos = null;
         Writer mw = null;
-        InputStream is = null;
         try {
-            StringBuffer mx = new StringBuffer();
+            StringBuilder mx = new StringBuilder();
             mx.append(req.getMethod()).append('\t').append(fileid).append('\n');
             Enumeration hnames = req.getHeaderNames();
             String ctype = null;
@@ -343,13 +352,13 @@ public class NodeServlet extends HttpServlet {
             while (hnames.hasMoreElements()) {
                 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-dmaap-dr-meta".equals(hnlc) ||
-                        (feedid == null && "x-dmaap-dr-received".equals(hnlc)) ||
-                        (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
+                if ((isput && ("content-type".equals(hnlc)
+                        || "content-language".equals(hnlc)
+                        || "content-md5".equals(hnlc)
+                        || "content-range".equals(hnlc)))
+                        || "x-dmaap-dr-meta".equals(hnlc)
+                        || (feedid == null && "x-dmaap-dr-received".equals(hnlc))
+                        || (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
                     Enumeration hvals = req.getHeaders(hn);
                     while (hvals.hasMoreElements()) {
                         String hv = (String) hvals.nextElement();
@@ -364,13 +373,17 @@ public class NodeServlet extends HttpServlet {
                         }
                         if ("x-dmaap-dr-meta".equals(hnlc)) {
                             if (hv.length() > 4096) {
-                                eelfLogger.error("NODE0109 Rejecting publish attempt with metadata too long for feed " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
+                                eelfLogger.error("NODE0109 Rejecting publish attempt with metadata too long for feed "
+                                        + PathUtil.cleanString(feedid) + USER + PathUtil.cleanString(user) + " ip "
+                                        + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
                                 resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Metadata too long");
                                 eelfLogger.info(EelfMsgs.EXIT);
                                 return;
                             }
-                            if (!MetaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) {
-                                eelfLogger.error("NODE0109 Rejecting publish attempt with malformed metadata for feed " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
+                            if (!metaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) {
+                                eelfLogger.error("NODE0109 Rejecting publish attempt with malformed metadata for feed "
+                                        + PathUtil.cleanString(feedid) + USER + PathUtil.cleanString(user) + " ip "
+                                        + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
                                 resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed metadata");
                                 eelfLogger.info(EelfMsgs.EXIT);
                                 return;
@@ -388,28 +401,12 @@ public class NodeServlet extends HttpServlet {
             }
             mx.append("X-DMAAP-DR-RECEIVED\t").append(rcvd).append('\n');
             String metadata = mx.toString();
-            byte[] buf = new byte[1024 * 1024];
-            int i;
-            try {
-                is = req.getInputStream();
-                dos = new FileOutputStream(data);
-                while ((i = is.read(buf)) > 0) {
-                    dos.write(buf, 0, i);
-                }
-                is.close();
-                is = null;
-                dos.close();
-                dos = null;
-            } catch (IOException ioe) {
-                long exlen = -1;
-                try {
-                    exlen = Long.parseLong(req.getHeader("Content-Length"));
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0529 Exception common: " + e);
-                }
-                StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, ioe.getMessage());
-                eelfLogger.info(EelfMsgs.EXIT);
-                throw ioe;
+            long exlen = getExlen(req);
+            String message = writeInputStreamToFile(req, data);
+            if (message != null) {
+                StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user,
+                        message);
+                throw new IOException(message);
             }
             Path dpath = Paths.get(fbase);
             for (Target t : targets) {
@@ -418,7 +415,8 @@ public class NodeServlet extends HttpServlet {
                     // TODO: unknown destination
                     continue;
                 }
-                String dbase = PathUtil.cleanString(di.getSpool() + "/" + pubid);  //Fortify scan fixes-Path Manipulation
+                String dbase = PathUtil
+                        .cleanString(di.getSpool() + "/" + pubid);  //Fortify scan fixes-Path Manipulation
                 Files.createLink(Paths.get(dbase), dpath);
                 mw = new FileWriter(meta);
                 mw.write(metadata);
@@ -427,45 +425,28 @@ public class NodeServlet extends HttpServlet {
                 }
                 mw.close();
                 meta.renameTo(new File(dbase + ".M"));
-
             }
             resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
             try {
                 resp.getOutputStream().close();
             } catch (IOException ioe) {
-                long exlen = -1;
-                try {
-                    exlen = Long.parseLong(req.getHeader("Content-Length"));
-                } catch (Exception e) {
-                    eelfLogger.error("NODE00000 Exception common: " + e.getMessage());
-                }
-                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());
                 //Fortify scan fixes - log forging
-                eelfLogger.error("NODE0110 IO Exception while closing IO stream " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " " + ioe.toString(), ioe);
-
+                eelfLogger.error("NODE0110 IO Exception while closing IO stream " + PathUtil.cleanString(feedid)
+                        + USER + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " " + ioe
+                        .toString(), ioe);
                 throw ioe;
             }
 
-            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) {
-            eelfLogger.error("NODE0110 IO Exception receiving publish attempt for feed " + feedid + " user " + user + " ip " + ip + " " + ioe.toString(), ioe);
+            eelfLogger.error("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) {
-                try {
-                    is.close();
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0530 Exception common: " + e);
-                }
-            }
-            if (dos != null) {
-                try {
-                    dos.close();
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0531 Exception common: " + e);
-                }
-            }
             if (mw != null) {
                 try {
                     mw.close();
@@ -486,22 +467,49 @@ public class NodeServlet extends HttpServlet {
         }
     }
 
+    private String writeInputStreamToFile(HttpServletRequest req, File data) {
+        byte[] buf = new byte[1024 * 1024];
+        int bytesRead;
+        try (OutputStream dos = new FileOutputStream(data);
+                InputStream is = req.getInputStream()) {
+            while ((bytesRead = is.read(buf)) > 0) {
+                dos.write(buf, 0, bytesRead);
+            }
+        } catch (IOException ioe) {
+            eelfLogger.error("NODE0530 Exception common: " + ioe, ioe);
+            eelfLogger.info(EelfMsgs.EXIT);
+            return ioe.getMessage();
+        }
+        return null;
+    }
+
+    private long getExlen(HttpServletRequest req) {
+        long exlen = -1;
+        try {
+            exlen = Long.parseLong(req.getHeader("Content-Length"));
+        } catch (Exception e) {
+            eelfLogger.error("NODE0529 Exception common: " + e);
+        }
+        return exlen;
+    }
+
     private void deleteFile(HttpServletRequest req, HttpServletResponse resp, String fileid, String pubid) {
+        final String FROM_DR_MESSAGE = ".M) from DR Node: ";
         try {
             fileid = fileid.substring(8);
-            int i = fileid.indexOf('/');
-            if (i == -1 || i == fileid.length() - 1) {
-                eelfLogger.error("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + " from " + req
+            int index = fileid.indexOf('/');
+            if (index == -1 || index == fileid.length() - 1) {
+                eelfLogger.error("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + FROM + req
                         .getRemoteAddr());
                 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
                         "Invalid request URI. Expecting <subId>/<pubId>.");
                 eelfLogger.info(EelfMsgs.EXIT);
                 return;
             }
-            String subscriptionId = fileid.substring(0, i);
+            String subscriptionId = fileid.substring(0, index);
             int subId = Integer.parseInt(subscriptionId);
-            pubid = fileid.substring(i + 1);
-            String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + ".M) from DR Node: "
+            pubid = fileid.substring(index + 1);
+            String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
                     + config.getMyName() + ".";
             int subIdDir = subId - (subId % 100);
             if (!isAuthorizedToDelete(resp, subscriptionId, errorMessage)) {
@@ -509,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 + ".M) from DR Node: "
+                eelfLogger.info("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
                         + config.getMyName());
                 resp.setStatus(HttpServletResponse.SC_OK);
                 eelfLogger.info(EelfMsgs.EXIT);
@@ -519,8 +527,8 @@ public class NodeServlet extends HttpServlet {
                 eelfLogger.info(EelfMsgs.EXIT);
             }
         } catch (IOException ioe) {
-            eelfLogger.error("NODE0117 Unable to delete files (" + pubid + ", " + pubid + ".M) from DR Node: "
-                    + config.getMyName() + ". Error: " + ioe.getMessage());
+            eelfLogger.error("NODE0117 Unable to delete files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
+                    + config.getMyName(), ioe);
             eelfLogger.info(EelfMsgs.EXIT);
         }
     }
@@ -533,7 +541,7 @@ public class NodeServlet extends HttpServlet {
         }
         if (!req.isSecure()) {
             eelfLogger.error(
-                    "NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + " from " + req
+                    "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);
@@ -541,17 +549,18 @@ public class NodeServlet extends HttpServlet {
         }
         String fileid = req.getPathInfo();
         if (fileid == null) {
-            eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0201 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
-                    "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                    INVALID_REQUEST_URI);
             eelfLogger.info(EelfMsgs.EXIT);
             return null;
         }
         return fileid;
     }
 
-    private boolean isAuthorizedToDelete(HttpServletResponse resp, String subscriptionId, String errorMessage) throws IOException {
+    private boolean isAuthorizedToDelete(HttpServletResponse resp, String subscriptionId, String errorMessage)
+            throws IOException {
         try {
             boolean deletePermitted = config.isDeletePermitted(subscriptionId);
             if (!deletePermitted) {
@@ -562,7 +571,8 @@ public class NodeServlet extends HttpServlet {
                 return false;
             }
         } catch (NullPointerException npe) {
-            eelfLogger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId + " does not exist");
+            eelfLogger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId
+                    + " does not exist", npe);
             resp.sendError(HttpServletResponse.SC_NOT_FOUND);
             eelfLogger.info(EelfMsgs.EXIT);
             return false;
index 4601f99..d4fc7db 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+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.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.InetAddress;
 import java.security.KeyStore;
+import java.security.KeyStoreException;
 import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -47,10 +54,8 @@ import org.apache.commons.lang3.StringUtils;
 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
+ * Utility functions for the data router node.
  */
 public class NodeUtils {
 
@@ -61,9 +66,9 @@ public class NodeUtils {
     }
 
     /**
-     * Base64 encode a byte array
+     * Base64 encode a byte array.
      *
-     * @param  raw The bytes to be encoded
+     * @param raw The bytes to be encoded
      * @return The encoded string
      */
     public static String base64Encode(byte[] raw) {
@@ -71,7 +76,7 @@ public class NodeUtils {
     }
 
     /**
-     * Given a user and password, generate the credentials
+     * Given a user and password, generate the credentials.
      *
      * @param user User name
      * @param password User password
@@ -85,7 +90,7 @@ public class NodeUtils {
     }
 
     /**
-     * Given a node name, generate the credentials
+     * Given a node name, generate the credentials.
      *
      * @param node Node name
      */
@@ -117,16 +122,12 @@ public class NodeUtils {
         KeyStore ks;
         try {
             ks = KeyStore.getInstance(kstype);
-            try (FileInputStream fileInputStream = new FileInputStream(ksfile)) {
-                ks.load(fileInputStream, kspass.toCharArray());
-            } catch (IOException ioException) {
-                eelfLogger.error("IOException occurred while opening FileInputStream: " + ioException.getMessage(),
-                        ioException);
+            if (loadKeyStore(ksfile, kspass, ks)) {
                 return (null);
             }
         } catch (Exception e) {
             setIpAndFqdnForEelf("getCanonicalName");
-            eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_LOAD_ERROR, ksfile, e.toString());
+            eelfLogger.error(EelfMsgs.MESSAGE_KEYSTORE_LOAD_ERROR, e, ksfile);
             return (null);
         }
         return (getCanonicalName(ks));
@@ -142,32 +143,19 @@ public class NodeUtils {
         try {
             Enumeration<String> aliases = ks.aliases();
             while (aliases.hasMoreElements()) {
-                String s = aliases.nextElement();
-                if (ks.entryInstanceOf(s, KeyStore.PrivateKeyEntry.class)) {
-                    X509Certificate c = (X509Certificate) ks.getCertificate(s);
-                    if (c != null) {
-                        String subject = c.getSubjectX500Principal().getName();
-                        String[] parts = subject.split(",");
-                        if (parts.length < 1) {
-                            return (null);
-                        }
-                        subject = parts[5].trim();
-                        if (!subject.startsWith("CN=")) {
-                            return (null);
-
-                        }
-                        return (subject.substring(3));
-                    }
+                String name = getNameFromSubject(ks, aliases);
+                if (name != null) {
+                    return name;
                 }
             }
         } catch (Exception e) {
-            eelfLogger.error("NODE0402 Error extracting my name from my keystore file " + e.toString(), e.getMessage());
+            eelfLogger.error("NODE0402 Error extracting my name from my keystore file " + e.toString(), e);
         }
         return (null);
     }
 
     /**
-     * Given a string representation of an IP address, get the corresponding byte array
+     * Given a string representation of an IP address, get the corresponding byte array.
      *
      * @param ip The IP address as a string
      * @return The IP address as a byte array or null if the address is invalid
@@ -184,48 +172,48 @@ public class NodeUtils {
     }
 
     /**
-     * Given a uri with parameters, split out the feed ID and file ID
+     * Given a uri with parameters, split out the feed ID and file ID.
      */
     public static String[] getFeedAndFileID(String uriandparams) {
         int end = uriandparams.length();
-        int i = uriandparams.indexOf('#');
-        if (i != -1 && i < end) {
-            end = i;
+        int index = uriandparams.indexOf('#');
+        if (index != -1 && index < end) {
+            end = index;
         }
-        i = uriandparams.indexOf('?');
-        if (i != -1 && i < end) {
-            end = i;
+        index = uriandparams.indexOf('?');
+        if (index != -1 && index < end) {
+            end = index;
         }
         end = uriandparams.lastIndexOf('/', end);
         if (end < 2) {
             return (null);
         }
-        i = uriandparams.lastIndexOf('/', end - 1);
-        if (i == -1) {
+        index = uriandparams.lastIndexOf('/', end - 1);
+        if (index == -1) {
             return (null);
         }
-        return (new String[]{uriandparams.substring(i + 1, end), uriandparams.substring(end + 1)});
+        return (new String[]{uriandparams.substring(index + 1, end), uriandparams.substring(end + 1)});
     }
 
     /**
      * Escape fields that might contain vertical bar, backslash, or newline by replacing them with backslash p,
      * backslash e and backslash n.
      */
-    public static String loge(String s) {
-        if (s == null) {
-            return (s);
+    public static String loge(String string) {
+        if (string == null) {
+            return (string);
         }
-        return (s.replaceAll("\\\\", "\\\\e").replaceAll("\\|", "\\\\p").replaceAll("\n", "\\\\n"));
+        return (string.replaceAll("\\\\", "\\\\e").replaceAll("\\|", "\\\\p").replaceAll("\n", "\\\\n"));
     }
 
     /**
      * Undo what loge does.
      */
-    public static String unloge(String s) {
-        if (s == null) {
-            return (s);
+    public static String unloge(String string) {
+        if (string == null) {
+            return (string);
         }
-        return (s.replaceAll("\\\\p", "\\|").replaceAll("\\\\n", "\n").replaceAll("\\\\e", "\\\\"));
+        return (string.replaceAll("\\\\p", "\\|").replaceAll("\\\\n", "\n").replaceAll("\\\\e", "\\\\"));
     }
 
     /**
@@ -244,9 +232,9 @@ public class NodeUtils {
         return (logDate.format(when));
     }
 
-    /* Method prints method name, server FQDN and IP Address of the machine in EELF logs
-     * @Method - setIpAndFqdnForEelf - Rally:US664892
-     * @Params - method, prints method name in EELF log.
+    /** Method prints method name, server FQDN and IP Address of the machine in EELF logs.
+     *
+     * @param method Prints method name in EELF log.
      */
     public static void setIpAndFqdnForEelf(String method) {
         MDC.clear();
@@ -262,9 +250,9 @@ public class NodeUtils {
 
     }
 
-    /* Method sets RequestIs and InvocationId for se in EELF logs
-     * @Method - setIpAndFqdnForEelf
-     * @Params - Req, Request used to get RequestId and InvocationId
+    /** Method sets RequestIs and InvocationId for se in EELF logs.
+     *
+     * @param req Request used to get RequestId and InvocationId.
      */
     public static void setRequestIdAndInvocationId(HttpServletRequest req) {
         String reqId = req.getHeader("X-ONAP-RequestID");
@@ -279,30 +267,65 @@ public class NodeUtils {
         MDC.put("InvocationId", invId);
     }
 
+    /**
+     * Sends error as response with error code input.
+     */
     public static void sendResponseError(HttpServletResponse response, int errorCode, EELFLogger intlogger) {
         try {
             response.sendError(errorCode);
         } catch (IOException ioe) {
-            intlogger.error("IOException" + ioe.getMessage());
+            intlogger.error("IOException", ioe);
         }
     }
 
     /**
-     * Method to check to see if file is of type gzip
+     * Method to check to see if file is of type gzip.
      *
-     * @param   file The name of the file to be checked
-     * @return  True if the file is of type gzip
+     * @param file The name of the file to be checked
+     * @return True if the file is of type gzip
      */
-    public static boolean isFiletypeGzip(File file){
-        try(FileInputStream fileInputStream = new FileInputStream(file);
-            GZIPInputStream gzip = new GZIPInputStream(fileInputStream)) {
+    public static boolean isFiletypeGzip(File file) {
+        try (FileInputStream fileInputStream = new FileInputStream(file);
+                GZIPInputStream gzip = new GZIPInputStream(fileInputStream)) {
 
             return true;
-        }catch (IOException e){
+        } catch (IOException e) {
             eelfLogger.error("NODE0403 " + file.toString() + " Not in gzip(gz) format: " + e.toString() + e);
             return false;
         }
     }
 
 
+    private static boolean loadKeyStore(String ksfile, String kspass, KeyStore ks)
+            throws NoSuchAlgorithmException, CertificateException {
+        try (FileInputStream fileInputStream = new FileInputStream(ksfile)) {
+            ks.load(fileInputStream, kspass.toCharArray());
+        } catch (IOException ioException) {
+            eelfLogger.error("IOException occurred while opening FileInputStream: " + ioException.getMessage(),
+                    ioException);
+            return true;
+        }
+        return false;
+    }
+
+
+    private static String getNameFromSubject(KeyStore ks, Enumeration<String> aliases) throws KeyStoreException {
+        String alias = aliases.nextElement();
+        if (ks.entryInstanceOf(alias, KeyStore.PrivateKeyEntry.class)) {
+            X509Certificate cert = (X509Certificate) ks.getCertificate(alias);
+            if (cert != null) {
+                String subject = cert.getSubjectX500Principal().getName();
+                String[] parts = subject.split(",");
+                if (parts.length < 1) {
+                    return null;
+                }
+                subject = parts[5].trim();
+                if (!subject.startsWith("CN=")) {
+                    return null;
+                }
+                return subject.substring(3);
+            }
+        }
+        return null;
+    }
 }
index fec2ca3..fe3fdb6 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Vector;
+import org.jetbrains.annotations.Nullable;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvHop;
 
 /**
  * Given a set of node names and next hops, identify and ignore any cycles and figure out the sequence of next hops to
- * get from this node to any other node
+ * get from this node to any other node.
  */
 
-public class PathFinder {
+class PathFinder {
 
-    private static class Hop {
+    private ArrayList<String> errors = new ArrayList<>();
+    private HashMap<String, String> routes = new HashMap<>();
 
-        boolean mark;
-        boolean bad;
-        NodeConfig.ProvHop basis;
+    /**
+     * Find routes from a specified origin to all of the nodes given a set of specified next hops.
+     *
+     * @param origin where we start
+     * @param nodes where we can go
+     * @param hops detours along the way
+     */
+    PathFinder(String origin, String[] nodes, NodeConfig.ProvHop[] hops) {
+        HashSet<String> known = new HashSet<>();
+        HashMap<String, HashMap<String, Hop>> ht = new HashMap<>();
+        for (String n : nodes) {
+            known.add(n);
+            ht.put(n, new HashMap<>());
+        }
+        for (NodeConfig.ProvHop ph : hops) {
+            Hop hop = getHop(known, ht, ph);
+            if (hop == null) {
+                continue;
+            }
+            if (ph.getVia().equals(ph.getTo())) {
+                errors.add(ph + " gives destination as via");
+                hop.bad = true;
+            }
+        }
+        for (String n : known) {
+            if (n.equals(origin)) {
+                routes.put(n, "");
+            }
+            routes.put(n, plot(origin, n, ht.get(n)) + "/");
+        }
     }
 
-    private Vector<String> errors = new Vector<String>();
-    private Hashtable<String, String> routes = new Hashtable<String, String>();
-
     /**
-     * Get list of errors encountered while finding paths
+     * Get list of errors encountered while finding paths.
      *
      * @return array of error descriptions
      */
-    public String[] getErrors() {
-        return (errors.toArray(new String[errors.size()]));
+    String[] getErrors() {
+        return (errors.toArray(new String[0]));
     }
 
     /**
-     * Get the route from this node to the specified node
+     * Get the route from this node to the specified node.
      *
      * @param destination node
      * @return list of node names separated by and ending with "/"
      */
-    public String getPath(String destination) {
+    String getPath(String destination) {
         String ret = routes.get(destination);
         if (ret == null) {
             return ("");
@@ -68,13 +95,12 @@ public class PathFinder {
         return (ret);
     }
 
-    private String plot(String from, String to, Hashtable<String, Hop> info) {
+    private String plot(String from, String to, HashMap<String, Hop> info) {
         Hop nh = info.get(from);
         if (nh == null || nh.bad) {
             return (to);
         }
         if (nh.mark) {
-            // loop detected;
             while (!nh.bad) {
                 nh.bad = true;
                 errors.add(nh.basis + " is part of a cycle");
@@ -83,63 +109,46 @@ public class PathFinder {
             return (to);
         }
         nh.mark = true;
-        String x = plot(nh.basis.getVia(), to, info);
+        String route = plot(nh.basis.getVia(), to, info);
         nh.mark = false;
         if (nh.bad) {
             return (to);
         }
-        return (nh.basis.getVia() + "/" + x);
+        return (nh.basis.getVia() + "/" + route);
     }
 
-    /**
-     * Find routes from a specified origin to all of the nodes given a set of specified next hops.
-     *
-     * @param origin where we start
-     * @param nodes where we can go
-     * @param hops detours along the way
-     */
-    public PathFinder(String origin, String[] nodes, NodeConfig.ProvHop[] hops) {
-        HashSet<String> known = new HashSet<String>();
-        Hashtable<String, Hashtable<String, Hop>> ht = new Hashtable<String, Hashtable<String, Hop>>();
-        for (String n : nodes) {
-            known.add(n);
-            ht.put(n, new Hashtable<String, Hop>());
+    @Nullable
+    private Hop getHop(HashSet<String> known, HashMap<String, HashMap<String, Hop>> ht, ProvHop ph) {
+        if (!known.contains(ph.getFrom())) {
+            errors.add(ph + " references unknown from node");
+            return null;
         }
-        for (NodeConfig.ProvHop ph : hops) {
-            if (!known.contains(ph.getFrom())) {
-                errors.add(ph + " references unknown from node");
-                continue;
-            }
-            if (!known.contains(ph.getTo())) {
-                errors.add(ph + " references unknown destination node");
-                continue;
-            }
-            Hashtable<String, Hop> ht2 = ht.get(ph.getTo());
-            Hop h = ht2.get(ph.getFrom());
-            if (h != null) {
-                h.bad = true;
-                errors.add(ph + " gives duplicate next hop - previous via was " + h.basis.getVia());
-                continue;
-            }
-            h = new Hop();
-            h.basis = ph;
-            ht2.put(ph.getFrom(), h);
-            if (!known.contains(ph.getVia())) {
-                errors.add(ph + " references unknown via node");
-                h.bad = true;
-                continue;
-            }
-            if (ph.getVia().equals(ph.getTo())) {
-                errors.add(ph + " gives destination as via");
-                h.bad = true;
-                continue;
-            }
+        if (!known.contains(ph.getTo())) {
+            errors.add(ph + " references unknown destination node");
+            return null;
         }
-        for (String n : known) {
-            if (n.equals(origin)) {
-                routes.put(n, "");
-            }
-            routes.put(n, plot(origin, n, ht.get(n)) + "/");
+        HashMap<String, Hop> ht2 = ht.get(ph.getTo());
+        Hop hop = ht2.get(ph.getFrom());
+        if (hop != null) {
+            hop.bad = true;
+            errors.add(ph + " gives duplicate next hop - previous via was " + hop.basis.getVia());
+            return null;
+        }
+        hop = new Hop();
+        hop.basis = ph;
+        ht2.put(ph.getFrom(), hop);
+        if (!known.contains(ph.getVia())) {
+            errors.add(ph + " references unknown via node");
+            hop.bad = true;
+            return null;
         }
+        return hop;
+    }
+
+    private static class Hop {
+
+        boolean mark;
+        boolean bad;
+        NodeConfig.ProvHop basis;
     }
 }
index a403441..d67c909 100644 (file)
@@ -1,67 +1,84 @@
-/**\r
- * -\r
+/*-\r
  * ============LICENSE_START=======================================================\r
- * Copyright (C) 2019 Nordix Foundation.\r
+ *  Copyright (C) 2019 Nordix Foundation.\r
  * ================================================================================\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * <p>\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * <p>\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
  * Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * <p>\r
+ *\r
  * SPDX-License-Identifier: Apache-2.0\r
  * ============LICENSE_END=========================================================\r
  */\r
+\r
 package org.onap.dmaap.datarouter.node;\r
 \r
 /**\r
- * FORTIFY SCAN FIXES\r
+ * FORTIFY SCAN FIXES.\r
  * <p>This Utility is used for Fortify fixes. It Validates the path url formed from\r
- *  the string passed in the request parameters.</p>\r
- *\r
+ * the string passed in the request parameters.</p>\r
  */\r
 class PathUtil {\r
 \r
+    private PathUtil() {\r
+        throw new IllegalStateException("Utility Class");\r
+    }\r
+\r
     /**\r
      * This method takes String as the parameter and return the filtered path string.\r
-     * @param aString String to clean\r
+     *\r
+     * @param string String to clean\r
      * @return A cleaned String\r
      */\r
-    static String cleanString(String aString) {\r
-        if (aString == null) return null;\r
-        String cleanString = "";\r
-        for (int i = 0; i < aString.length(); ++i) {\r
-            cleanString += cleanChar(aString.charAt(i));\r
+    static String cleanString(String string) {\r
+        if (string == null) {\r
+            return null;\r
+        }\r
+        StringBuilder cleanString = new StringBuilder();\r
+        for (int i = 0; i < string.length(); ++i) {\r
+            cleanString.append(cleanChar(string.charAt(i)));\r
         }\r
-        return cleanString;\r
+        return cleanString.toString();\r
     }\r
 \r
     /**\r
      * This method filters the valid special characters in path string.\r
-     * @param aChar The char to be cleaned\r
+     *\r
+     * @param character The char to be cleaned\r
      * @return The cleaned char\r
      */\r
-    private static char cleanChar(char aChar) {\r
+    private static char cleanChar(char character) {\r
         // 0 - 9\r
         for (int i = 48; i < 58; ++i) {\r
-            if (aChar == i) return (char) i;\r
+            if (character == i) {\r
+                return (char) i;\r
+            }\r
         }\r
         // 'A' - 'Z'\r
         for (int i = 65; i < 91; ++i) {\r
-            if (aChar == i) return (char) i;\r
+            if (character == i) {\r
+                return (char) i;\r
+            }\r
         }\r
         // 'a' - 'z'\r
         for (int i = 97; i < 123; ++i) {\r
-            if (aChar == i) return (char) i;\r
+            if (character == i) {\r
+                return (char) i;\r
+            }\r
         }\r
+        return getValidCharacter(character);\r
+    }\r
+\r
+    private static char getValidCharacter(char character) {\r
         // other valid characters\r
-        switch (aChar) {\r
+        switch (character) {\r
             case '/':\r
                 return '/';\r
             case '.':\r
@@ -82,7 +99,8 @@ class PathUtil {
                 return '_';\r
             case ' ':\r
                 return ' ';\r
+            default:\r
+                return '%';\r
         }\r
-        return '%';\r
     }\r
 }\r
index 1af7dda..03e952c 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-import java.io.*;
-import java.util.*;
-
-import org.json.*;
-import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
-
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import org.jetbrains.annotations.Nullable;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvFeed;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvFeedSubnet;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvFeedUser;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvForceEgress;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvForceIngress;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvHop;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvNode;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvParam;
+import org.onap.dmaap.datarouter.node.NodeConfig.ProvSubscription;
+import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
 
 /**
  * Parser for provisioning data from the provisioning server.
- * <p>
- * The ProvData class uses a Reader for the text configuration from the
- * provisioning server to construct arrays of raw configuration entries.
+ *
+ * <p>The ProvData class uses a Reader for the text configuration from the provisioning server to construct arrays of
+ * raw configuration entries.
  */
 public class ProvData {
+
+    private static final String FEED_ID = "feedid";
     private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(ProvData.class);
     private NodeConfig.ProvNode[] pn;
     private NodeConfig.ProvParam[] pp;
@@ -51,208 +65,39 @@ public class ProvData {
     private NodeConfig.ProvForceEgress[] pfe;
     private NodeConfig.ProvHop[] ph;
 
-    private static String[] gvasa(JSONArray a, int index) {
-        return (gvasa(a.get(index)));
-    }
-
-    private static String[] gvasa(JSONObject o, String key) {
-        return (gvasa(o.opt(key)));
-    }
-
-    private static String[] gvasa(Object o) {
-        if (o instanceof JSONArray) {
-            JSONArray a = (JSONArray) o;
-            Vector<String> v = new Vector<String>();
-            for (int i = 0; i < a.length(); i++) {
-                String s = gvas(a, i);
-                if (s != null) {
-                    v.add(s);
-                }
-            }
-            return (v.toArray(new String[v.size()]));
-        } else {
-            String s = gvas(o);
-            if (s == null) {
-                return (new String[0]);
-            } else {
-                return (new String[]{s});
-            }
-        }
-    }
-
-    private static String gvas(JSONArray a, int index) {
-        return (gvas(a.get(index)));
-    }
-
-    private static String gvas(JSONObject o, String key) {
-        return (gvas(o.opt(key)));
-    }
-
-    private static String gvas(Object o) {
-        if (o instanceof Boolean || o instanceof Number || o instanceof String) {
-            return (o.toString());
-        }
-        return (null);
-    }
-
     /**
-     * Construct raw provisioing data entries from the text (JSON)
-     * provisioning document received from the provisioning server
+     * Construct raw provisioing data entries from the text (JSON) provisioning document received from the provisioning
+     * server.
      *
-     * @param r The reader for the JSON text.
+     * @param reader The reader for the JSON text.
      */
-    public ProvData(Reader r) throws IOException {
-        Vector<NodeConfig.ProvNode> pnv = new Vector<NodeConfig.ProvNode>();
-        Vector<NodeConfig.ProvParam> ppv = new Vector<NodeConfig.ProvParam>();
-        Vector<NodeConfig.ProvFeed> pfv = new Vector<NodeConfig.ProvFeed>();
-        Vector<NodeConfig.ProvFeedUser> pfuv = new Vector<NodeConfig.ProvFeedUser>();
-        Vector<NodeConfig.ProvFeedSubnet> pfsnv = new Vector<NodeConfig.ProvFeedSubnet>();
-        Vector<NodeConfig.ProvSubscription> psv = new Vector<NodeConfig.ProvSubscription>();
-        Vector<NodeConfig.ProvForceIngress> pfiv = new Vector<NodeConfig.ProvForceIngress>();
-        Vector<NodeConfig.ProvForceEgress> pfev = new Vector<NodeConfig.ProvForceEgress>();
-        Vector<NodeConfig.ProvHop> phv = new Vector<NodeConfig.ProvHop>();
+    public ProvData(Reader reader) throws IOException {
+        ArrayList<ProvNode> pnv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvParam> ppv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvFeed> pfv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvFeedUser> pfuv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvFeedSubnet> pfsnv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvSubscription> psv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvForceIngress> pfiv = new ArrayList<>();
+        ArrayList<NodeConfig.ProvForceEgress> pfev = new ArrayList<>();
+        ArrayList<NodeConfig.ProvHop> phv = new ArrayList<>();
         try {
-            JSONTokener jtx = new JSONTokener(r);
+            JSONTokener jtx = new JSONTokener(reader);
             JSONObject jcfg = new JSONObject(jtx);
             char c = jtx.nextClean();
             if (c != '\0') {
                 throw new JSONException("Spurious characters following configuration");
             }
-            r.close();
-            JSONArray jfeeds = jcfg.optJSONArray("feeds");
-            if (jfeeds != null) {
-                for (int fx = 0; fx < jfeeds.length(); fx++) {
-                    JSONObject jfeed = jfeeds.getJSONObject(fx);
-                    String stat = null;
-                    if (jfeed.optBoolean("suspend", false)) {
-                        stat = "Feed is suspended";
-                    }
-                    if (jfeed.optBoolean("deleted", false)) {
-                        stat = "Feed is deleted";
-                    }
-                    String fid = gvas(jfeed, "feedid");
-                    String fname = gvas(jfeed, "name");
-                    String fver = gvas(jfeed, "version");
-                    String createdDate = gvas(jfeed, "created_date");
-                    /*
-                     * START - AAF changes
-                     * TDP EPIC US# 307413
-                     * Passing aafInstance to ProvFeed from feeds json passed by prov to identify legacy/AAF feeds
-                     */
-                    String aafInstance = gvas(jfeed, "aaf_instance");
-                    pfv.add(new NodeConfig.ProvFeed(fid, fname + "//" + fver, stat,createdDate, aafInstance));
-                    /*
-                     * END - AAF changes
-                     */
-                    JSONObject jauth = jfeed.optJSONObject("authorization");
-                    if (jauth == null) {
-                        continue;
-                    }
-                    JSONArray jeids = jauth.optJSONArray("endpoint_ids");
-                    if (jeids != null) {
-                        for (int ux = 0; ux < jeids.length(); ux++) {
-                            JSONObject ju = jeids.getJSONObject(ux);
-                            String login = gvas(ju, "id");
-                            String password = gvas(ju, "password");
-                            pfuv.add(new NodeConfig.ProvFeedUser(fid, login, NodeUtils.getAuthHdr(login, password)));
-                        }
-                    }
-                    JSONArray jeips = jauth.optJSONArray("endpoint_addrs");
-                    if (jeips != null) {
-                        for (int ix = 0; ix < jeips.length(); ix++) {
-                            String sn = gvas(jeips, ix);
-                            pfsnv.add(new NodeConfig.ProvFeedSubnet(fid, sn));
-                        }
-                    }
-                }
-            }
-            JSONArray jsubs = jcfg.optJSONArray("subscriptions");
-            if (jsubs != null) {
-                for (int sx = 0; sx < jsubs.length(); sx++) {
-                    JSONObject jsub = jsubs.getJSONObject(sx);
-                    if (jsub.optBoolean("suspend", false)) {
-                        continue;
-                    }
-                    String sid = gvas(jsub, "subid");
-                    String fid = gvas(jsub, "feedid");
-                    JSONObject jdel = jsub.getJSONObject("delivery");
-                    String delurl = gvas(jdel, "url");
-                    String id = gvas(jdel, "user");
-                    String password = gvas(jdel, "password");
-                    boolean monly = jsub.getBoolean("metadataOnly");
-                    boolean use100 = jdel.getBoolean("use100");
-                    boolean privilegedSubscriber = jsub.getBoolean("privilegedSubscriber");
-                    boolean decompress = jsub.getBoolean("decompress");
-                    boolean followRedirect = jsub.getBoolean("follow_redirect");
-                    psv.add(new NodeConfig.ProvSubscription(sid, fid, delurl, id, NodeUtils.getAuthHdr(id, password), monly, use100, privilegedSubscriber, followRedirect, decompress));
-                }
-            }
-            JSONObject jparams = jcfg.optJSONObject("parameters");
-            if (jparams != null) {
-                for (String pname : JSONObject.getNames(jparams)) {
-                    String pvalue = gvas(jparams, pname);
-                    if (pvalue != null) {
-                        ppv.add(new NodeConfig.ProvParam(pname, pvalue));
-                    }
-                }
-                String sfx = gvas(jparams, "PROV_DOMAIN");
-                JSONArray jnodes = jparams.optJSONArray("NODES");
-                if (jnodes != null) {
-                    for (int nx = 0; nx < jnodes.length(); nx++) {
-                        String nn = gvas(jnodes, nx);
-                        if (nn.indexOf('.') == -1) {
-                            nn = nn + "." + sfx;
-                        }
-                        pnv.add(new NodeConfig.ProvNode(nn));
-                    }
-                }
-            }
-            JSONArray jingresses = jcfg.optJSONArray("ingress");
-            if (jingresses != null) {
-                for (int fx = 0; fx < jingresses.length(); fx++) {
-                    JSONObject jingress = jingresses.getJSONObject(fx);
-                    String fid = gvas(jingress, "feedid");
-                    String subnet = gvas(jingress, "subnet");
-                    String user = gvas(jingress, "user");
-                    String[] nodes = gvasa(jingress, "node");
-                    if (fid == null || "".equals(fid)) {
-                        continue;
-                    }
-                    if ("".equals(subnet)) {
-                        subnet = null;
-                    }
-                    if ("".equals(user)) {
-                        user = null;
-                    }
-                    pfiv.add(new NodeConfig.ProvForceIngress(fid, subnet, user, nodes));
-                }
-            }
-            JSONObject jegresses = jcfg.optJSONObject("egress");
-            if (jegresses != null && JSONObject.getNames(jegresses) != null) {
-                for (String esid : JSONObject.getNames(jegresses)) {
-                    String enode = gvas(jegresses, esid);
-                    if (esid != null && enode != null && !"".equals(esid) && !"".equals(enode)) {
-                        pfev.add(new NodeConfig.ProvForceEgress(esid, enode));
-                    }
-                }
-            }
-            JSONArray jhops = jcfg.optJSONArray("routing");
-            if (jhops != null) {
-                for (int fx = 0; fx < jhops.length(); fx++) {
-                    JSONObject jhop = jhops.getJSONObject(fx);
-                    String from = gvas(jhop, "from");
-                    String to = gvas(jhop, "to");
-                    String via = gvas(jhop, "via");
-                    if (from == null || to == null || via == null || "".equals(from) || "".equals(to) || "".equals(via)) {
-                        continue;
-                    }
-                    phv.add(new NodeConfig.ProvHop(from, to, via));
-                }
-            }
+            reader.close();
+            addJSONFeeds(pfv, pfuv, pfsnv, jcfg);
+            addJSONSubs(psv, jcfg);
+            addJSONParams(pnv, ppv, jcfg);
+            addJSONRoutingInformation(pfiv, pfev, phv, jcfg);
         } catch (JSONException jse) {
             NodeUtils.setIpAndFqdnForEelf("ProvData");
             eelfLogger.error(EelfMsgs.MESSAGE_PARSING_ERROR, jse.toString());
-            eelfLogger.error("NODE0201 Error parsing configuration data from provisioning server " + jse.toString(), jse);
+            eelfLogger
+                    .error("NODE0201 Error parsing configuration data from provisioning server " + jse.toString(), jse);
             throw new IOException(jse.toString(), jse);
         }
         pn = pnv.toArray(new NodeConfig.ProvNode[pnv.size()]);
@@ -266,66 +111,294 @@ public class ProvData {
         ph = phv.toArray(new NodeConfig.ProvHop[phv.size()]);
     }
 
+    private static String[] gvasa(JSONObject object, String key) {
+        return (gvasa(object.opt(key)));
+    }
+
+    private static String[] gvasa(Object object) {
+        if (object instanceof JSONArray) {
+            JSONArray jsonArray = (JSONArray) object;
+            ArrayList<String> array = new ArrayList<>();
+            for (int i = 0; i < jsonArray.length(); i++) {
+                String string = gvas(jsonArray, i);
+                if (string != null) {
+                    array.add(string);
+                }
+            }
+            return (array.toArray(new String[array.size()]));
+        } else {
+            String string = gvas(object);
+            if (string == null) {
+                return (new String[0]);
+            } else {
+                return (new String[]{string});
+            }
+        }
+    }
+
+    private static String gvas(JSONArray array, int index) {
+        return (gvas(array.get(index)));
+    }
+
+    private static String gvas(JSONObject object, String key) {
+        return (gvas(object.opt(key)));
+    }
+
+    private static String gvas(Object object) {
+        if (object instanceof Boolean || object instanceof Number || object instanceof String) {
+            return (object.toString());
+        }
+        return (null);
+    }
+
     /**
-     * Get the raw node configuration entries
+     * Get the raw node configuration entries.
      */
     public NodeConfig.ProvNode[] getNodes() {
         return (pn);
     }
 
     /**
-     * Get the raw parameter configuration entries
+     * Get the raw parameter configuration entries.
      */
     public NodeConfig.ProvParam[] getParams() {
         return (pp);
     }
 
     /**
-     * Ge the raw feed configuration entries
+     * Ge the raw feed configuration entries.
      */
     public NodeConfig.ProvFeed[] getFeeds() {
         return (pf);
     }
 
     /**
-     * Get the raw feed user configuration entries
+     * Get the raw feed user configuration entries.
      */
     public NodeConfig.ProvFeedUser[] getFeedUsers() {
         return (pfu);
     }
 
     /**
-     * Get the raw feed subnet configuration entries
+     * Get the raw feed subnet configuration entries.
      */
     public NodeConfig.ProvFeedSubnet[] getFeedSubnets() {
         return (pfsn);
     }
 
     /**
-     * Get the raw subscription entries
+     * Get the raw subscription entries.
      */
     public NodeConfig.ProvSubscription[] getSubscriptions() {
         return (ps);
     }
 
     /**
-     * Get the raw forced ingress entries
+     * Get the raw forced ingress entries.
      */
     public NodeConfig.ProvForceIngress[] getForceIngress() {
         return (pfi);
     }
 
     /**
-     * Get the raw forced egress entries
+     * Get the raw forced egress entries.
      */
     public NodeConfig.ProvForceEgress[] getForceEgress() {
         return (pfe);
     }
 
     /**
-     * Get the raw next hop entries
+     * Get the raw next hop entries.
      */
     public NodeConfig.ProvHop[] getHops() {
         return (ph);
     }
+
+    @Nullable
+    private String getFeedStatus(JSONObject jfeed) {
+        String stat = null;
+        if (jfeed.optBoolean("suspend", false)) {
+            stat = "Feed is suspended";
+        }
+        if (jfeed.optBoolean("deleted", false)) {
+            stat = "Feed is deleted";
+        }
+        return stat;
+    }
+
+    private void addJSONFeeds(ArrayList<ProvFeed> pfv, ArrayList<ProvFeedUser> pfuv, ArrayList<ProvFeedSubnet> pfsnv,
+            JSONObject jcfg) {
+        JSONArray jfeeds = jcfg.optJSONArray("feeds");
+        if (jfeeds != null) {
+            for (int fx = 0; fx < jfeeds.length(); fx++) {
+                addJSONFeed(pfv, pfuv, pfsnv, jfeeds, fx);
+            }
+        }
+    }
+
+    private void addJSONFeed(ArrayList<ProvFeed> pfv, ArrayList<ProvFeedUser> pfuv, ArrayList<ProvFeedSubnet> pfsnv,
+            JSONArray jfeeds, int fx) {
+        JSONObject jfeed = jfeeds.getJSONObject(fx);
+        String stat = getFeedStatus(jfeed);
+        String fid = gvas(jfeed, FEED_ID);
+        String fname = gvas(jfeed, "name");
+        String fver = gvas(jfeed, "version");
+        String createdDate = gvas(jfeed, "created_date");
+        /*
+         * START - AAF changes
+         * TDP EPIC US# 307413
+         * Passing aafInstance to ProvFeed from feeds json passed by prov to identify legacy/AAF feeds
+         */
+        String aafInstance = gvas(jfeed, "aaf_instance");
+        pfv.add(new ProvFeed(fid, fname + "//" + fver, stat, createdDate, aafInstance));
+        /*
+         * END - AAF changes
+         */
+        addJSONFeedAuthArrays(pfuv, pfsnv, jfeed, fid);
+    }
+
+    private void addJSONFeedAuthArrays(ArrayList<ProvFeedUser> pfuv, ArrayList<ProvFeedSubnet> pfsnv, JSONObject jfeed,
+            String fid) {
+        JSONObject jauth = jfeed.optJSONObject("authorization");
+        if (jauth == null) {
+            return;
+        }
+        JSONArray jeids = jauth.optJSONArray("endpoint_ids");
+        if (jeids != null) {
+            for (int ux = 0; ux < jeids.length(); ux++) {
+                JSONObject ju = jeids.getJSONObject(ux);
+                String login = gvas(ju, "id");
+                String password = gvas(ju, "password");
+                pfuv.add(new ProvFeedUser(fid, login, NodeUtils.getAuthHdr(login, password)));
+            }
+        }
+        JSONArray jeips = jauth.optJSONArray("endpoint_addrs");
+        if (jeips != null) {
+            for (int ix = 0; ix < jeips.length(); ix++) {
+                String sn = gvas(jeips, ix);
+                pfsnv.add(new ProvFeedSubnet(fid, sn));
+            }
+        }
+    }
+
+    private void addJSONSubs(ArrayList<ProvSubscription> psv, JSONObject jcfg) {
+        JSONArray jsubs = jcfg.optJSONArray("subscriptions");
+        if (jsubs != null) {
+            for (int sx = 0; sx < jsubs.length(); sx++) {
+                addJSONSub(psv, jsubs, sx);
+            }
+        }
+    }
+
+    private void addJSONSub(ArrayList<ProvSubscription> psv, JSONArray jsubs, int sx) {
+        JSONObject jsub = jsubs.getJSONObject(sx);
+        if (jsub.optBoolean("suspend", false)) {
+            return;
+        }
+        String sid = gvas(jsub, "subid");
+        String fid = gvas(jsub, FEED_ID);
+        JSONObject jdel = jsub.getJSONObject("delivery");
+        String delurl = gvas(jdel, "url");
+        String id = gvas(jdel, "user");
+        String password = gvas(jdel, "password");
+        boolean monly = jsub.getBoolean("metadataOnly");
+        boolean use100 = jdel.getBoolean("use100");
+        boolean privilegedSubscriber = jsub.getBoolean("privilegedSubscriber");
+        boolean decompress = jsub.getBoolean("decompress");
+        boolean followRedirect = jsub.getBoolean("follow_redirect");
+        psv.add(new ProvSubscription(sid, fid, delurl, id, NodeUtils.getAuthHdr(id, password), monly, use100,
+                privilegedSubscriber, followRedirect, decompress));
+    }
+
+    private void addJSONParams(ArrayList<ProvNode> pnv, ArrayList<ProvParam> ppv, JSONObject jcfg) {
+        JSONObject jparams = jcfg.optJSONObject("parameters");
+        if (jparams != null) {
+            for (String pname : JSONObject.getNames(jparams)) {
+                addJSONParam(ppv, jparams, pname);
+            }
+            addJSONNodesToParams(pnv, jparams);
+        }
+    }
+
+    private void addJSONParam(ArrayList<ProvParam> ppv, JSONObject jparams, String pname) {
+        String pvalue = gvas(jparams, pname);
+        if (pvalue != null) {
+            ppv.add(new ProvParam(pname, pvalue));
+        }
+    }
+
+    private void addJSONNodesToParams(ArrayList<ProvNode> pnv, JSONObject jparams) {
+        String sfx = gvas(jparams, "PROV_DOMAIN");
+        JSONArray jnodes = jparams.optJSONArray("NODES");
+        if (jnodes != null) {
+            for (int nx = 0; nx < jnodes.length(); nx++) {
+                String nn = gvas(jnodes, nx);
+                if (nn == null) {
+                    continue;
+                }
+                if (nn.indexOf('.') == -1) {
+                    nn = nn + "." + sfx;
+                }
+                pnv.add(new ProvNode(nn));
+            }
+        }
+    }
+
+    private void addJSONRoutingInformation(ArrayList<ProvForceIngress> pfiv, ArrayList<ProvForceEgress> pfev,
+            ArrayList<ProvHop> phv, JSONObject jcfg) {
+        JSONArray jingresses = jcfg.optJSONArray("ingress");
+        if (jingresses != null) {
+            for (int fx = 0; fx < jingresses.length(); fx++) {
+                addJSONIngressRoute(pfiv, jingresses, fx);
+            }
+        }
+        JSONObject jegresses = jcfg.optJSONObject("egress");
+        if (jegresses != null && JSONObject.getNames(jegresses) != null) {
+            for (String esid : JSONObject.getNames(jegresses)) {
+                addJSONEgressRoute(pfev, jegresses, esid);
+            }
+        }
+        JSONArray jhops = jcfg.optJSONArray("routing");
+        if (jhops != null) {
+            for (int fx = 0; fx < jhops.length(); fx++) {
+                addJSONRoutes(phv, jhops, fx);
+            }
+        }
+    }
+
+    private void addJSONIngressRoute(ArrayList<ProvForceIngress> pfiv, JSONArray jingresses, int fx) {
+        JSONObject jingress = jingresses.getJSONObject(fx);
+        String fid = gvas(jingress, FEED_ID);
+        String subnet = gvas(jingress, "subnet");
+        String user = gvas(jingress, "user");
+        if (fid == null || "".equals(fid)) {
+            return;
+        }
+        if ("".equals(subnet)) {
+            subnet = null;
+        }
+        if ("".equals(user)) {
+            user = null;
+        }
+        String[] nodes = gvasa(jingress, "node");
+        pfiv.add(new ProvForceIngress(fid, subnet, user, nodes));
+    }
+
+    private void addJSONEgressRoute(ArrayList<ProvForceEgress> pfev, JSONObject jegresses, String esid) {
+        String enode = gvas(jegresses, esid);
+        if (esid != null && enode != null && !"".equals(esid) && !"".equals(enode)) {
+            pfev.add(new ProvForceEgress(esid, enode));
+        }
+    }
+
+    private void addJSONRoutes(ArrayList<ProvHop> phv, JSONArray jhops, int fx) {
+        JSONObject jhop = jhops.getJSONObject(fx);
+        String from = gvas(jhop, "from");
+        String to = gvas(jhop, "to");
+        String via = gvas(jhop, "via");
+        if (from == null || to == null || via == null || "".equals(from) || "".equals(to) || "".equals(via)) {
+            return;
+        }
+        phv.add(new ProvHop(from, to, via));
+    }
 }
index 3d4908e..d1d2abb 100644 (file)
 package org.onap.dmaap.datarouter.node;
 
 /**
- * Generate publish IDs
+ * Generate publish IDs.
  */
 public class PublishId {
+
     private long nextuid;
     private String myname;
 
     /**
-     * Generate publish IDs for the specified name
+     * Generate publish IDs for the specified name.
      *
      * @param myname Unique identifier for this publish ID generator (usually fqdn of server)
      */
@@ -41,7 +42,8 @@ public class PublishId {
     }
 
     /**
-     * Generate a Data Router Publish ID that uniquely identifies the particular invocation of the Publish API for log correlation purposes.
+     * Generate a Data Router Publish ID that uniquely identifies the particular invocation of the Publish API for log
+     * correlation purposes.
      */
     public synchronized String next() {
         long now = System.currentTimeMillis();
index 42af8ca..0270455 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-import java.util.*;
+import java.util.Timer;
+import java.util.TimerTask;
 
 /**
- * Execute an operation no more frequently than a specified interval
+ * Execute an operation no more frequently than a specified interval.
  */
 
 public abstract class RateLimitedOperation implements Runnable {
+
     private boolean marked;    // a timer task exists
     private boolean executing;    // the operation is currently in progress
     private boolean remark;    // a request was made while the operation was in progress
@@ -39,33 +41,19 @@ public abstract class RateLimitedOperation implements Runnable {
     private long mininterval;
 
     /**
-     * Create a rate limited operation
+     * Create a rate limited operation.
      *
-     * @param mininterval The minimum number of milliseconds after the last execution starts before a new execution can begin
-     * @param timer       The timer used to perform deferred executions
+     * @param mininterval The minimum number of milliseconds after the last execution starts before a new execution can
+     *      begin
+     * @param timer The timer used to perform deferred executions
      */
     public RateLimitedOperation(long mininterval, Timer timer) {
         this.timer = timer;
         this.mininterval = mininterval;
     }
 
-    private class deferred extends TimerTask {
-        public void run() {
-            execute();
-        }
-    }
-
-    private synchronized void unmark() {
-        marked = false;
-    }
-
-    private void execute() {
-        unmark();
-        request();
-    }
-
     /**
-     * Request that the operation be performed by this thread or at a later time by the timer
+     * Request that the operation be performed by this thread or at a later time by the timer.
      */
     public void request() {
         if (premark()) {
@@ -73,7 +61,8 @@ public abstract class RateLimitedOperation implements Runnable {
         }
         do {
             run();
-        } while (demark());
+        }
+        while (demark());
     }
 
     private synchronized boolean premark() {
@@ -90,7 +79,7 @@ public abstract class RateLimitedOperation implements Runnable {
         if (last + mininterval > now) {
             // too soon - schedule a timer
             marked = true;
-            timer.schedule(new deferred(), last + mininterval - now);
+            timer.schedule(new Deferred(), last + mininterval - now);
             return (true);
         }
         last = now;
@@ -107,4 +96,20 @@ public abstract class RateLimitedOperation implements Runnable {
         }
         return (false);
     }
+
+    private class Deferred extends TimerTask {
+
+        public void run() {
+            execute();
+        }
+
+        private void execute() {
+            unmark();
+            request();
+        }
+
+        private synchronized void unmark() {
+            marked = false;
+        }
+    }
 }
index 7e4078f..b4a3f0a 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import java.io.BufferedReader;
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.OutputStream;
-import java.util.Hashtable;
+import java.util.HashMap;
+import java.util.Map;
 import java.util.Timer;
 
 /**
- * Track redirections of subscriptions
+ * Track redirections of subscriptions.
  */
-public class RedirManager {
+class RedirManager {
 
-    private Hashtable<String, String> sid2primary = new Hashtable<String, String>();
-    private Hashtable<String, String> sid2secondary = new Hashtable<String, String>();
+    private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(RedirManager.class);
+    private RateLimitedOperation op;
+    private HashMap<String, String> sid2primary = new HashMap<>();
+    private HashMap<String, String> sid2secondary = new HashMap<>();
     private String redirfile;
-    RateLimitedOperation op;
 
     /**
      * 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 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) {
+    RedirManager(String redirfile, long mininterval, Timer timer) {
         this.redirfile = redirfile;
         op = new RateLimitedOperation(mininterval, timer) {
             public void run() {
                 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');
+                    StringBuilder sb = new StringBuilder();
+                    for (Map.Entry<String, String> entry : sid2primary.entrySet()) {
+                        String key = entry.getKey();
+                        String value = entry.getValue();
+                        sb.append(key).append(' ').append(value).append(' ')
+                                .append(sid2secondary.get(key)).append('\n');
                     }
                     try (OutputStream os = new FileOutputStream(RedirManager.this.redirfile)) {
                         os.write(sb.toString().getBytes());
                     }
                 } catch (Exception e) {
+                    eelfLogger.error("Exception", e);
                 }
             }
         };
         try {
-            String s;
+            String line;
             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]);
+                while ((line = br.readLine()) != null) {
+                    addSubRedirInfo(line);
                 }
             }
         } catch (Exception e) {
-            // missing file is normal
+            eelfLogger.debug("Missing file is normal", e);
         }
     }
 
     /**
-     * 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 secondary The replacement URL to use instead
      */
-    public synchronized void redirect(String sid, String primary, String secondary) {
+    synchronized void redirect(String sid, String primary, String secondary) {
         sid2primary.put(sid, primary);
         sid2secondary.put(sid, secondary);
         op.request();
     }
 
     /**
-     * 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.
      */
-    public synchronized void forget(String sid) {
+    synchronized void forget(String sid) {
         sid2primary.remove(sid);
         sid2secondary.remove(sid);
         op.request();
     }
 
     /**
-     * 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.
      * @return The destination URL to really use.
      */
-    public synchronized String lookup(String sid, String primary) {
+    synchronized String lookup(String sid, String primary) {
         String oprim = sid2primary.get(sid);
         if (primary.equals(oprim)) {
             return (sid2secondary.get(sid));
@@ -129,9 +128,19 @@ public class RedirManager {
     }
 
     /**
-     * Is a subscription redirected?
+     * Is a subscription redirected.
      */
-    public synchronized boolean isRedirected(String sid) {
+    synchronized boolean isRedirected(String sid) {
         return (sid != null && sid2secondary.get(sid) != null);
     }
+
+    private void addSubRedirInfo(String subRedirInfo) {
+        subRedirInfo = subRedirInfo.trim();
+        String[] sx = subRedirInfo.split(" ");
+        if (subRedirInfo.startsWith("#") || sx.length != 3) {
+            return;
+        }
+        sid2primary.put(sx[0], sx[1]);
+        sid2secondary.put(sx[0], sx[2]);
+    }
 }
index c8a7bd0..53e5314 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-import java.util.regex.*;
-import java.util.*;
-import java.io.*;
-import java.nio.file.*;
-import java.text.*;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
- * Logging for data router delivery events (PUB/DEL/EXP)
+ * Logging for data router delivery events (PUB/DEL/EXP).
  */
 public class StatusLog {
+
+    private static final String EXCEPTION = "Exception";
+    private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(StatusLog.class);
     private static StatusLog instance = new StatusLog();
-    private HashSet<String> toship = new HashSet<String>();
-    private SimpleDateFormat filedate;
+    private SimpleDateFormat filedate = new SimpleDateFormat("-yyyyMMddHHmm");
+
     private String prefix = "logs/events";
     private String suffix = ".log";
     private String plainfile;
@@ -43,89 +53,81 @@ public class StatusLog {
     private long nexttime;
     private OutputStream os;
     private long intvl;
-    private NodeConfigManager config = NodeConfigManager.getInstance();
+    private static NodeConfigManager config = NodeConfigManager.getInstance();
 
-    {
-        try {
-            filedate = new SimpleDateFormat("-yyyyMMddHHmm");
-        } catch (Exception e) {
-        }
+    private StatusLog() {
     }
 
     /**
-     * Parse an interval of the form xxhyymzzs and round it to the nearest whole fraction of 24 hours.If no units are specified, assume seconds.
+     * Parse an interval of the form xxhyymzzs and round it to the nearest whole fraction of 24 hours.If no units are
+     * specified, assume seconds.
      */
     public static long parseInterval(String interval, int def) {
         try {
-            Matcher m = Pattern.compile("(?:(\\d+)[Hh])?(?:(\\d+)[Mm])?(?:(\\d+)[Ss]?)?").matcher(interval);
-            if (m.matches()) {
-                int dur = 0;
-                String x = m.group(1);
-                if (x != null) {
-                    dur += 3600 * Integer.parseInt(x);
-                }
-                x = m.group(2);
-                if (x != null) {
-                    dur += 60 * Integer.parseInt(x);
-                }
-                x = m.group(3);
-                if (x != null) {
-                    dur += Integer.parseInt(x);
-                }
-                if (dur < 60) {
-                    dur = 60;
-                }
+            Matcher matcher = Pattern.compile("(?:(\\d+)[Hh])?(?:(\\d+)[Mm])?(?:(\\d+)[Ss]?)?").matcher(interval);
+            if (matcher.matches()) {
+                int dur = getDur(matcher);
                 int best = 86400;
                 int dist = best - dur;
                 if (dur > best) {
                     dist = dur - best;
                 }
-                int base = 1;
-                for (int i = 0; i < 8; i++) {
-                    int base2 = base;
-                    base *= 2;
-                    for (int j = 0; j < 4; j++) {
-                        int base3 = base2;
-                        base2 *= 3;
-                        for (int k = 0; k < 3; k++) {
-                            int cur = base3;
-                            base3 *= 5;
-                            int ndist = cur - dur;
-                            if (dur > cur) {
-                                ndist = dur - cur;
-                            }
-                            if (ndist < dist) {
-                                best = cur;
-                                dist = ndist;
-                            }
-                        }
-                    }
-                }
+                best = getBest(dur, best, dist);
                 def = best * 1000;
             }
         } catch (Exception e) {
+            eelfLogger.error(EXCEPTION, e);
         }
         return (def);
     }
 
-    private synchronized void checkRoll(long now) throws IOException {
-        if (now >= nexttime) {
-            if (os != null) {
-                os.close();
-                os = null;
+    private static int getBest(int dur, int best, int dist) {
+        int base = 1;
+        for (int i = 0; i < 8; i++) {
+            int base2 = base;
+            base *= 2;
+            for (int j = 0; j < 4; j++) {
+                int base3 = base2;
+                base2 *= 3;
+                for (int k = 0; k < 3; k++) {
+                    int cur = base3;
+                    base3 *= 5;
+                    int ndist = cur - dur;
+                    if (dur > cur) {
+                        ndist = dur - cur;
+                    }
+                    if (ndist < dist) {
+                        best = cur;
+                        dist = ndist;
+                    }
+                }
             }
-            intvl = parseInterval(config.getEventLogInterval(), 300000);
-            prefix = config.getEventLogPrefix();
-            suffix = config.getEventLogSuffix();
-            nexttime = now - now % intvl + intvl;
-            curfile = prefix + filedate.format(new Date(nexttime - intvl)) + suffix;
-            plainfile = prefix + suffix;
-            notify();
         }
+        return best;
+    }
+
+    private static int getDur(Matcher matcher) {
+        int dur = 0;
+        String match = matcher.group(1);
+        if (match != null) {
+            dur += 3600 * Integer.parseInt(match);
+        }
+        match = matcher.group(2);
+        if (match != null) {
+            dur += 60 * Integer.parseInt(match);
+        }
+        match = matcher.group(3);
+        if (match != null) {
+            dur += Integer.parseInt(match);
+        }
+        if (dur < 60) {
+            dur = 60;
+        }
+        return dur;
     }
 
     /**
-     * Get the name of the current log file
+     * Get the name of the current log file.
      *
      * @return The full path name of the current event log file
      */
@@ -133,109 +135,107 @@ public class StatusLog {
         try {
             instance.checkRoll(System.currentTimeMillis());
         } catch (Exception e) {
+            eelfLogger.error(EXCEPTION, e);
         }
         return (instance.curfile);
     }
 
-    private synchronized void log(String s) {
-        try {
-            long now = System.currentTimeMillis();
-            checkRoll(now);
-            if (os == null) {
-                os = new FileOutputStream(curfile, true);
-                (new File(plainfile)).delete();
-                Files.createLink(Paths.get(plainfile), Paths.get(curfile));
-            }
-            os.write((NodeUtils.logts(new Date(now)) + '|' + s + '\n').getBytes());
-            os.flush();
-        } catch (IOException ioe) {
-        }
-    }
-
     /**
      * Log a received publication attempt.
      *
-     * @param pubid  The publish ID assigned by the node
+     * @param pubid The publish ID assigned by the node
      * @param feedid The feed id given by the publisher
      * @param requrl The URL of the received request
      * @param method The method (DELETE or PUT) in the received request
-     * @param ctype  The content type (if method is PUT and clen > 0)
-     * @param clen   The content length (if method is PUT)
-     * @param srcip  The IP address of the publisher
-     * @param user   The identity of the publisher
+     * @param ctype The content type (if method is PUT and clen > 0)
+     * @param clen The content length (if method is PUT)
+     * @param srcip The IP address of the publisher
+     * @param user The identity of the publisher
      * @param status The status returned to the publisher
      */
-    public static void logPub(String pubid, String feedid, String requrl, String method, String ctype, long clen, String srcip, String user, int status) {
-        instance.log("PUB|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + srcip + "|" + user + "|" + status);
+    public static void logPub(String pubid, String feedid, String requrl, String method, String ctype, long clen,
+            String srcip, String user, int status) {
+        instance.log(
+                "PUB|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + srcip
+                        + "|" + user + "|" + status);
     }
 
     /**
-     * Log a data transfer error receiving a publication attempt
+     * Log a data transfer error receiving a publication attempt.
      *
-     * @param pubid  The publish ID assigned by the node
+     * @param pubid The publish ID assigned by the node
      * @param feedid The feed id given by the publisher
      * @param requrl The URL of the received request
      * @param method The method (DELETE or PUT) in the received request
-     * @param ctype  The content type (if method is PUT and clen > 0)
-     * @param clen   The expected content length (if method is PUT)
-     * @param rcvd   The content length received
-     * @param srcip  The IP address of the publisher
-     * @param user   The identity of the publisher
-     * @param error  The error message from the IO exception
+     * @param ctype The content type (if method is PUT and clen > 0)
+     * @param clen The expected content length (if method is PUT)
+     * @param rcvd The content length received
+     * @param srcip The IP address of the publisher
+     * @param user The identity of the publisher
+     * @param error The error message from the IO exception
      */
-    public static void logPubFail(String pubid, String feedid, String requrl, String method, String ctype, long clen, long rcvd, String srcip, String user, String error) {
-        instance.log("PBF|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + rcvd + "|" + srcip + "|" + user + "|" + error);
+    public static void logPubFail(String pubid, String feedid, String requrl, String method, String ctype, long clen,
+            long rcvd, String srcip, String user, String error) {
+        instance.log("PBF|" + pubid + "|" + feedid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + rcvd
+                + "|" + srcip + "|" + user + "|" + error);
     }
 
     /**
      * Log a delivery attempt.
      *
-     * @param pubid  The publish ID assigned by the node
+     * @param pubid The publish ID assigned by the node
      * @param feedid The feed ID
-     * @param subid  The (space delimited list of) subscription ID
+     * @param subid The (space delimited list of) subscription ID
      * @param requrl The URL used in the attempt
      * @param method The method (DELETE or PUT) in the attempt
-     * @param ctype  The content type (if method is PUT, not metaonly, and clen > 0)
-     * @param clen   The content length (if PUT and not metaonly)
-     * @param user   The identity given to the subscriber
+     * @param ctype The content type (if method is PUT, not metaonly, and clen > 0)
+     * @param clen The content length (if PUT and not metaonly)
+     * @param user The identity given to the subscriber
      * @param status The status returned by the subscriber or -1 if an exeception occured trying to connect
      * @param xpubid The publish ID returned by the subscriber
      */
-    public static void logDel(String pubid, String feedid, String subid, String requrl, String method, String ctype, long clen, String user, int status, String xpubid) {
+    public static void logDel(String pubid, String feedid, String subid, String requrl, String method, String ctype,
+            long clen, String user, int status, String xpubid) {
         if (feedid == null) {
             return;
         }
-        instance.log("DEL|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + user + "|" + status + "|" + xpubid);
+        instance.log(
+                "DEL|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen
+                        + "|" + user + "|" + status + "|" + xpubid);
     }
 
     /**
-     * Log delivery attempts expired
+     * Log delivery attempts expired.
      *
-     * @param pubid    The publish ID assigned by the node
-     * @param feedid   The feed ID
-     * @param subid    The (space delimited list of) subscription ID
-     * @param requrl   The URL that would be delivered to
-     * @param method   The method (DELETE or PUT) in the request
-     * @param ctype    The content type (if method is PUT, not metaonly, and clen > 0)
-     * @param clen     The content length (if PUT and not metaonly)
-     * @param reason   The reason the attempts were discontinued
+     * @param pubid The publish ID assigned by the node
+     * @param feedid The feed ID
+     * @param subid The (space delimited list of) subscription ID
+     * @param requrl The URL that would be delivered to
+     * @param method The method (DELETE or PUT) in the request
+     * @param ctype The content type (if method is PUT, not metaonly, and clen > 0)
+     * @param clen The content length (if PUT and not metaonly)
+     * @param reason The reason the attempts were discontinued
      * @param attempts The number of attempts made
      */
-    public static void logExp(String pubid, String feedid, String subid, String requrl, String method, String ctype, long clen, String reason, int attempts) {
+    public static void logExp(String pubid, String feedid, String subid, String requrl, String method, String ctype,
+            long clen, String reason, int attempts) {
         if (feedid == null) {
             return;
         }
-        instance.log("EXP|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen + "|" + reason + "|" + attempts);
+        instance.log(
+                "EXP|" + pubid + "|" + feedid + "|" + subid + "|" + requrl + "|" + method + "|" + ctype + "|" + clen
+                        + "|" + reason + "|" + attempts);
     }
 
     /**
      * Log extra statistics about unsuccessful delivery attempts.
      *
-     * @param pubid  The publish ID assigned by the node
+     * @param pubid The publish ID assigned by the node
      * @param feedid The feed ID
-     * @param subid  The (space delimited list of) subscription ID
-     * @param clen   The content length
-     * @param sent   The # of bytes sent or -1 if subscriber returned an error instead of 100 Continue, otherwise, the number of bytes sent before an error occurred.
+     * @param subid The (space delimited list of) subscription ID
+     * @param clen The content length
+     * @param sent The # of bytes sent or -1 if subscriber returned an error instead of 100 Continue, otherwise, the
+     *      number of bytes sent before an error occurred.
      */
     public static void logDelExtra(String pubid, String feedid, String subid, long clen, long sent) {
         if (feedid == null) {
@@ -244,6 +244,35 @@ public class StatusLog {
         instance.log("DLX|" + pubid + "|" + feedid + "|" + subid + "|" + clen + "|" + sent);
     }
 
-    private StatusLog() {
+    private synchronized void checkRoll(long now) throws IOException {
+        if (now >= nexttime) {
+            if (os != null) {
+                os.close();
+                os = null;
+            }
+            intvl = parseInterval(config.getEventLogInterval(), 300000);
+            prefix = config.getEventLogPrefix();
+            suffix = config.getEventLogSuffix();
+            nexttime = now - now % intvl + intvl;
+            curfile = prefix + filedate.format(new Date(nexttime - intvl)) + suffix;
+            plainfile = prefix + suffix;
+            notify();
+        }
+    }
+
+    private synchronized void log(String string) {
+        try {
+            long now = System.currentTimeMillis();
+            checkRoll(now);
+            if (os == null) {
+                os = new FileOutputStream(curfile, true);
+                (new File(plainfile)).delete();
+                Files.createLink(Paths.get(plainfile), Paths.get(curfile));
+            }
+            os.write((NodeUtils.logts(new Date(now)) + '|' + string + '\n').getBytes());
+            os.flush();
+        } catch (IOException ioe) {
+            eelfLogger.error("IOException", ioe);
+        }
     }
 }
index 6f74df4..2f51012 100644 (file)
 package org.onap.dmaap.datarouter.node;
 
 /**
- * Compare IP addresses as byte arrays to a subnet specified as a CIDR
+ * Compare IP addresses as byte arrays to a subnet specified as a CIDR.
  */
 public class SubnetMatcher {
+
     private byte[] sn;
     private int len;
     private int mask;
 
     /**
-     * Construct a subnet matcher given a CIDR
+     * Construct a subnet matcher given a CIDR.
      *
      * @param subnet The CIDR to match
      */
     public SubnetMatcher(String subnet) {
-        int i = subnet.lastIndexOf('/');
-        if (i == -1) {
+        int index = subnet.lastIndexOf('/');
+        if (index == -1) {
             sn = NodeUtils.getInetAddress(subnet);
             len = sn.length;
         } else {
-            len = Integer.parseInt(subnet.substring(i + 1));
-            sn = NodeUtils.getInetAddress(subnet.substring(0, i));
+            len = Integer.parseInt(subnet.substring(index + 1));
+            sn = NodeUtils.getInetAddress(subnet.substring(0, index));
             mask = ((0xff00) >> (len % 8)) & 0xff;
             len /= 8;
         }
     }
 
     /**
-     * Is the IP address in the CIDR?
+     * Is the IP address in the CIDR.
      *
      * @param addr the IP address as bytes in network byte order
      * @return true if the IP address matches.
index eb10876..475c876 100644 (file)
 package org.onap.dmaap.datarouter.node;
 
 /**
- * A destination to deliver a message
+ * A destination to deliver a message.
  */
 public class Target {
+
     private DestInfo destinfo;
     private String routing;
 
     /**
-     * A destination to deliver a message
+     * A destination to deliver a message.
      *
      * @param destinfo Either info for a subscription ID or info for a node-to-node transfer
-     * @param routing  For a node-to-node transfer, what to do when it gets there.
+     * @param routing For a node-to-node transfer, what to do when it gets there.
      */
     public Target(DestInfo destinfo, String routing) {
         this.destinfo = destinfo;
@@ -43,21 +44,21 @@ public class Target {
     }
 
     /**
-     * Add additional routing
+     * Add additional routing.
      */
     public void addRouting(String routing) {
         this.routing = this.routing + " " + routing;
     }
 
     /**
-     * Get the destination information for this target
+     * Get the destination information for this target.
      */
     public DestInfo getDestInfo() {
         return (destinfo);
     }
 
     /**
-     * Get the next hop information for this target
+     * Get the next hop information for this target.
      */
     public String getRouting() {
         return (routing);
index 33e4f80..a77277f 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
-import java.util.*;
+import java.util.HashSet;
+import java.util.Iterator;
 
 /**
- * Manage a list of tasks to be executed when an event occurs.
- * This makes the following guarantees:
+ * Manage a list of tasks to be executed when an event occurs. This makes the following guarantees:
  * <ul>
  * <li>Tasks can be safely added and removed in the middle of a run.</li>
  * <li>No task will be returned more than once during a run.</li>
  * <li>No task will be returned when it is not, at that moment, in the list of tasks.</li>
  * <li>At the moment when next() returns null, all tasks on the list have been returned during the run.</li>
- * <li>Initially and once next() returns null during a run, next() will continue to return null until startRun() is called.
+ * <li>Initially and once next() returns null during a run, next() will continue to return null until startRun() is
+ * called.
  * </ul>
  */
-public class TaskList {
+class TaskList {
+
     private Iterator<Runnable> runlist;
-    private HashSet<Runnable> tasks = new HashSet<Runnable>();
+    private HashSet<Runnable> tasks = new HashSet<>();
     private HashSet<Runnable> togo;
     private HashSet<Runnable> sofar;
     private HashSet<Runnable> added;
     private HashSet<Runnable> removed;
 
-    /**
-     * Construct a new TaskList
-     */
-    public TaskList() {
-    }
-
     /**
      * Start executing the sequence of tasks.
      */
-    public synchronized void startRun() {
-        sofar = new HashSet<Runnable>();
-        added = new HashSet<Runnable>();
-        removed = new HashSet<Runnable>();
-        togo = new HashSet<Runnable>(tasks);
+    synchronized void startRun() {
+        sofar = new HashSet<>();
+        added = new HashSet<>();
+        removed = new HashSet<>();
+        togo = new HashSet<>(tasks);
         runlist = togo.iterator();
     }
 
     /**
-     * Get the next task to execute
+     * Get the next task to execute.
      */
-    public synchronized Runnable next() {
+    synchronized Runnable next() {
         while (runlist != null) {
             if (runlist.hasNext()) {
                 Runnable task = runlist.next();
-                if (removed.contains(task)) {
-                    continue;
+                if (addTaskToSoFar(task)) {
+                    return task;
                 }
-                if (sofar.contains(task)) {
-                    continue;
-                }
-                sofar.add(task);
-                return (task);
             }
-            if (added.size() != 0) {
+            if (!added.isEmpty()) {
                 togo = added;
-                added = new HashSet<Runnable>();
+                added = new HashSet<>();
                 removed.clear();
                 runlist = togo.iterator();
                 continue;
@@ -97,7 +88,7 @@ public class TaskList {
     /**
      * Add a task to the list of tasks to run whenever the event occurs.
      */
-    public synchronized void addTask(Runnable task) {
+    synchronized void addTask(Runnable task) {
         if (runlist != null) {
             added.add(task);
             removed.remove(task);
@@ -108,11 +99,22 @@ public class TaskList {
     /**
      * Remove a task from the list of tasks to run whenever the event occurs.
      */
-    public synchronized void removeTask(Runnable task) {
+    synchronized void removeTask(Runnable task) {
         if (runlist != null) {
             removed.add(task);
             added.remove(task);
         }
         tasks.remove(task);
     }
+
+    private boolean addTaskToSoFar(Runnable task) {
+        if (removed.contains(task)) {
+            return false;
+        }
+        if (sofar.contains(task)) {
+            return false;
+        }
+        sofar.add(task);
+        return true;
+    }
 }
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/AuditFilter.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/AuditFilter.java
new file mode 100644 (file)
index 0000000..a278c2e
--- /dev/null
@@ -0,0 +1,38 @@
+/*-
+ * ============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.spi.ILoggingEvent;
+import ch.qos.logback.core.filter.Filter;
+import ch.qos.logback.core.spi.FilterReply;
+
+
+public class AuditFilter extends Filter<ILoggingEvent> {
+    @Override
+    public FilterReply decide(ILoggingEvent event) {
+        if (event.getMessage().contains("DEL|") || event.getMessage().contains("PUB|") || event.getMessage().contains("PBF|")
+                                                        || event.getMessage().contains("EXP|") || event.getMessage().contains("DLX|")) {
+            return FilterReply.ACCEPT;
+        } else {
+            return FilterReply.DENY;
+        }
+    }
+}
diff --git a/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EELFFilter.java b/datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/EELFFilter.java
deleted file mode 100644 (file)
index b733e7e..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*******************************************************************************
- * ============LICENSE_START==================================================
- * * org.onap.dmaap
- * * ===========================================================================
- * * Copyright Â© 2017 AT&T Intellectual Property. All rights reserved.
- * * ===========================================================================
- * * Licensed under the Apache License, Version 2.0 (the "License");
- * * you may not use this file except in compliance with the License.
- * * You may obtain a copy of the License at
- * *
- *  *      http://www.apache.org/licenses/LICENSE-2.0
- * *
- *  * Unless required by applicable law or agreed to in writing, software
- * * distributed under the License is distributed on an "AS IS" BASIS,
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * * See the License for the specific language governing permissions and
- * * limitations under the License.
- * * ============LICENSE_END====================================================
- * *
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * *
- ******************************************************************************/
-package org.onap.dmaap.datarouter.node.eelf;
-
-import ch.qos.logback.classic.spi.ILoggingEvent;
-import ch.qos.logback.core.filter.Filter;
-import ch.qos.logback.core.spi.FilterReply;
-
-/*
- * When EELF functionality added it default started logging Jetty logs as well which in turn stopped existing functionality of logging jetty statements in node.log
- * added code in logback.xml to add jetty statements in node.log.
- * This class removes extran EELF statements from node.log since they are being logged in apicalls.log
- */
-public class EELFFilter extends Filter<ILoggingEvent> {
-    @Override
-    public FilterReply decide(ILoggingEvent event) {
-        if (event.getMessage().contains("EELF")) {
-            return FilterReply.DENY;
-        } else {
-            return FilterReply.ACCEPT;
-        }
-    }
-}
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
new file mode 100644 (file)
index 0000000..69f51d8
--- /dev/null
@@ -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.spi.ILoggingEvent;
+import ch.qos.logback.core.filter.Filter;
+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")) {
+            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
new file mode 100644 (file)
index 0000000..0fa57d4
--- /dev/null
@@ -0,0 +1,42 @@
+/*-
+ * ============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 MetricsFilter extends Filter<ILoggingEvent> {
+    @Override
+    public FilterReply decide(ILoggingEvent event) {
+        if (event.getLevel().equals(Level.INFO) && !event.getMessage().contains("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;
+            }
+        } else {
+            return FilterReply.DENY;
+        }
+        return FilterReply.DENY;
+    }
+}
index b07b3ef..01880bb 100644 (file)
@@ -35,6 +35,6 @@ ENTRYPOINT ["sh", "startup.sh"]
 
 RUN addgroup -S -g 1001 onap \
     && adduser -S -u 1000 datarouter -G onap \
-    && chown -R datarouter:onap /opt/
+    && chown -R datarouter:onap /opt/ /var/
 
 USER datarouter
\ No newline at end of file
index 2ce2050..dc19cb6 100644 (file)
@@ -8,9 +8,9 @@
   * 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
+  *      http://www.apache.org/licenses/LICENSE-2.0
   *
-   * Unless required by applicable law or agreed to in writing, software
+  * 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
   * ECOMP is a trademark and service mark of AT&T Intellectual Property.
   *
 -->
-<configuration scan="true" scanPeriod="3 seconds" debug="true">
-  <!--<jmxConfigurator /> -->
-  <!-- directory path for all other type logs -->
-  <!-- property name="logDir" value="/home/eby/dr2/logs" / -->
-  <property name="logDir" value="/opt/app/datartr/logs" />
+<configuration scan="true" scanPeriod="3 seconds" debug="false">
 
-  <!-- directory path for debugging type logs -->
-  <!-- property name="debugDir" value="/home/eby/dr2/debug-logs" /-->
-
-  <!--  specify the component name
-    <ECOMP-component-name>::= "MSO" | "DCAE" | "ASDC " | "AAI" |"Policy" | "SDNC" | "AC"  -->
-  <!-- This creates the MSO directory in in the LogDir which is not needed, mentioned last directory of the path-->
-  <!-- property name="componentName" value="logs"></property -->
+  <property name="logDir" value="/var/log/onap/datarouter" />
+  <!--  log file names -->
+  <property name="auditLog" value="audit" />
+  <property name="errorLog" value="error" />
+  <property name="debugLog" value="debug" />
+  <property name="metricsLog" value="metrics" />
+  <property name="jettyLog" value="jetty" />
 
   <!--  log file names -->
-  <property name="generalLogName" value="apicalls" />
-  <!-- name="securityLogName" value="security" -->
-  <!-- name="performanceLogName" value="performance" -->
-  <!-- name="serverLogName" value="server" -->
-  <!-- name="policyLogName" value="policy"-->
-  <property name="errorLogName" value="errors" />
-  <!-- name="metricsLogName" value="metrics" -->
-  <property name="jettyAndNodeLogName" value="node"></property>
-  <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="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}%n|%msg%n" />
   <property name="logDirectory" value="${logDir}" />
-  <!-- property name="debugLogDirectory" value="${debugDir}/${componentName}" /-->
 
 
   <!-- Example evaluator filter applied against console appender -->
     log -->
 
 
-  <appender name="EELF"
+  <appender name="Audit"
     class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${generalLogName}.log</file>
-     <filter class="ch.qos.logback.classic.filter.LevelFilter">
-        <level>INFO</level>
-        <onMatch>ACCEPT</onMatch>
-        <onMismatch>DENY</onMismatch>
+    <file>${logDirectory}/${auditLog}.log</file>
+     <filter class="org.onap.dmaap.datarouter.node.eelf.AuditFilter">
     </filter>
     <rollingPolicy
       class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${generalLogName}.%i.log.zip
+      <fileNamePattern>${logDirectory}/${auditLog}.%i.log.zip
       </fileNamePattern>
       <minIndex>1</minIndex>
       <maxIndex>9</maxIndex>
     </rollingPolicy>
     <triggeringPolicy
       class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
+      <maxFileSize>50MB</maxFileSize>
     </triggeringPolicy>
     <encoder>
       <pattern>${defaultPattern}</pattern>
     </encoder>
   </appender>
 
-  <appender name="asyncEELF" class="ch.qos.logback.classic.AsyncAppender">
+  <appender name="asyncAudit" class="ch.qos.logback.classic.AsyncAppender">
     <queueSize>256</queueSize>
-    <appender-ref ref="EELF" />
-  </appender>
-
-  <!-- EELF Security Appender. This appender is used to record security events
-    to the security log file. Security events are separate from other loggers
-    in EELF so that security log records can be captured and managed in a secure
-    way separate from the other logs. This appender is set to never discard any
-    events. -->
-  <!--appender name="EELFSecurity"
-    class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${securityLogName}.log</file>
-    <rollingPolicy
-      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${securityLogName}.%i.log.zip
-      </fileNamePattern>
-      <minIndex>1</minIndex>
-      <maxIndex>9</maxIndex>
-    </rollingPolicy>
-    <triggeringPolicy
-      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
-    </triggeringPolicy>
-    <encoder>
-      <pattern>${defaultPattern}</pattern>
-    </encoder>
+    <appender-ref ref="Audit" />
   </appender>
 
-  <appender name="asyncEELFSecurity" class="ch.qos.logback.classic.AsyncAppender">
-    <queueSize>256</queueSize>
-    <discardingThreshold>0</discardingThreshold>
-    <appender-ref ref="EELFSecurity" />
-  </appender-->
+    <!-- ============================================================================ -->
 
-  <!-- EELF Performance Appender. This appender is used to record performance
-    records. -->
-  <!--appender name="EELFPerformance"
-    class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${performanceLogName}.log</file>
+  <appender name="Metrics"
+            class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <file>${logDirectory}/${metricsLog}.log</file>
+    <filter class="org.onap.dmaap.datarouter.node.eelf.MetricsFilter">
+    </filter>
     <rollingPolicy
-      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${performanceLogName}.%i.log.zip
+            class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+      <fileNamePattern>${logDirectory}/${metricsLog}.%i.log.zip
       </fileNamePattern>
       <minIndex>1</minIndex>
       <maxIndex>9</maxIndex>
     </rollingPolicy>
     <triggeringPolicy
-      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
+            class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+      <maxFileSize>50MB</maxFileSize>
     </triggeringPolicy>
     <encoder>
-      <outputPatternAsHeader>true</outputPatternAsHeader>
       <pattern>${defaultPattern}</pattern>
     </encoder>
   </appender>
-  <appender name="asyncEELFPerformance" class="ch.qos.logback.classic.AsyncAppender">
-    <queueSize>256</queueSize>
-    <appender-ref ref="EELFPerformance" />
-  </appender-->
-
-  <!-- EELF Server Appender. This appender is used to record Server related
-    logging events. The Server logger and appender are specializations of the
-    EELF application root logger and appender. This can be used to segregate Server
-    events from other components, or it can be eliminated to record these events
-    as part of the application root log. -->
-  <!--appender name="EELFServer"
-    class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${serverLogName}.log</file>
-    <rollingPolicy
-      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${serverLogName}.%i.log.zip
-      </fileNamePattern>
-      <minIndex>1</minIndex>
-      <maxIndex>9</maxIndex>
-    </rollingPolicy>
-    <triggeringPolicy
-      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
-    </triggeringPolicy>
-    <encoder>
-        <pattern>${defaultPattern}</pattern>
-    </encoder>
-  </appender>
-  <appender name="asyncEELFServer" class="ch.qos.logback.classic.AsyncAppender">
-    <queueSize>256</queueSize>
-    <appender-ref ref="EELFServer" />
-  </appender-->
 
-
-  <!-- EELF Policy Appender. This appender is used to record Policy engine
-    related logging events. The Policy logger and appender are specializations
-    of the EELF application root logger and appender. This can be used to segregate
-    Policy engine events from other components, or it can be eliminated to record
-    these events as part of the application root log. -->
-  <!--appender name="EELFPolicy"
-    class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${policyLogName}.log</file>
-    <rollingPolicy
-      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${policyLogName}.%i.log.zip
-      </fileNamePattern>
-      <minIndex>1</minIndex>
-      <maxIndex>9</maxIndex>
-    </rollingPolicy>
-    <triggeringPolicy
-      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
-    </triggeringPolicy>
-    <encoder>
-        <pattern>${defaultPattern}</pattern>
-    </encoder>
-  </appender>
-  <appender name="asyncEELFPolicy" class="ch.qos.logback.classic.AsyncAppender">
+  <appender name="asyncMetrics" class="ch.qos.logback.classic.AsyncAppender">
     <queueSize>256</queueSize>
-    <appender-ref ref="EELFPolicy" >
-  </appender-->
+    <appender-ref ref="Metrics" />
+  </appender>
 
+  <!-- ============================================================================ -->
 
-  <!-- EELF Audit Appender. This appender is used to record audit engine
-    related logging events. The audit logger and appender are specializations
-    of the EELF application root logger and appender. This can be used to segregate
-    Policy engine events from other components, or it can be eliminated to record
-    these events as part of the application root log. -->
 
-  <!--appender name="EELFAudit"
-    class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${auditLogName}.log</file>
+  <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>
     <rollingPolicy
-      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${auditLogName}.%i.log.zip
+            class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+      <fileNamePattern>${logDirectory}/${debugLog}.%i.log.zip
       </fileNamePattern>
       <minIndex>1</minIndex>
       <maxIndex>9</maxIndex>
     </rollingPolicy>
     <triggeringPolicy
-      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
+            class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+      <maxFileSize>50MB</maxFileSize>
     </triggeringPolicy>
     <encoder>
-         <pattern>${defaultPattern}</pattern>
+      <pattern>${defaultPattern}</pattern>
     </encoder>
   </appender>
-  <appender name="asyncEELFAudit" class="ch.qos.logback.classic.AsyncAppender">
-    <queueSize>256</queueSize>
-    <appender-ref ref="EELFAudit" />
-  </appender-->
 
-<!--appender name="EELFMetrics"
-    class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${metricsLogName}.log</file>
-    <rollingPolicy
-      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${metricsLogName}.%i.log.zip
-      </fileNamePattern>
-      <minIndex>1</minIndex>
-      <maxIndex>9</maxIndex>
-    </rollingPolicy>
-    <triggeringPolicy
-      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
-    </triggeringPolicy>
-    <encoder-->
-      <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} -
-        %msg%n"</pattern> -->
-      <!--pattern>${defaultPattern}</pattern>
-    </encoder>
+  <appender name="asyncDebug" class="ch.qos.logback.classic.AsyncAppender">
+    <queueSize>256</queueSize>
+    <appender-ref ref="Debug" />
   </appender>
 
+  <!-- ============================================================================ -->
 
-  <appender name="asyncEELFMetrics" class="ch.qos.logback.classic.AsyncAppender">
-    <queueSize>256</queueSize>
-    <appender-ref ref="EELFMetrics"/>
-  </appender-->
-
-  <appender name="EELFError"
+  <appender name="Error"
     class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${errorLogName}.log</file>
-    <filter class="ch.qos.logback.classic.filter.LevelFilter">
-        <level>ERROR</level>
+    <file>${logDirectory}/${errorLog}.log</file>
+    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+        <level>WARN</level>
         <onMatch>ACCEPT</onMatch>
         <onMismatch>DENY</onMismatch>
     </filter>
     <rollingPolicy
       class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip
+      <fileNamePattern>${logDirectory}/${errorLog}.%i.log.zip
       </fileNamePattern>
       <minIndex>1</minIndex>
       <maxIndex>9</maxIndex>
     </rollingPolicy>
     <triggeringPolicy
       class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
+      <maxFileSize>50MB</maxFileSize>
     </triggeringPolicy>
     <encoder>
       <pattern>${defaultPattern}</pattern>
     </encoder>
   </appender>
 
-  <appender name="asyncEELFError" class="ch.qos.logback.classic.AsyncAppender">
+  <appender name="asyncError" class="ch.qos.logback.classic.AsyncAppender">
     <queueSize>256</queueSize>
-    <appender-ref ref="EELFError"/>
+    <appender-ref ref="Error"/>
   </appender>
 
   <!-- ============================================================================ -->
-   <appender name="jettyAndNodelog"
+   <appender name="Jetty"
     class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${logDirectory}/${jettyAndNodeLogName}.log</file>
-     <filter class="org.onap.dmaap.datarouter.node.eelf.EELFFilter" />
+    <file>${logDirectory}/${jettyLog}.log</file>
+     <filter class="org.onap.dmaap.datarouter.node.eelf.JettyFilter" />
     <rollingPolicy
       class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
-      <fileNamePattern>${logDirectory}/${jettyAndNodeLogName}.%i.log.zip
+      <fileNamePattern>${logDirectory}/${jettyLog}.%i.log.zip
       </fileNamePattern>
       <minIndex>1</minIndex>
       <maxIndex>9</maxIndex>
     </rollingPolicy>
     <triggeringPolicy
       class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
-      <maxFileSize>5MB</maxFileSize>
+      <maxFileSize>50MB</maxFileSize>
     </triggeringPolicy>
     <encoder>
-      <pattern>${jettyAndNodeLoggerPattern}</pattern>
+      <pattern>${defaultPattern}</pattern>
     </encoder>
   </appender>
 
-  <appender name="asyncEELFjettyAndNodelog" class="ch.qos.logback.classic.AsyncAppender">
+  <appender name="asyncJettyLog" class="ch.qos.logback.classic.AsyncAppender">
     <queueSize>256</queueSize>
-    <appender-ref ref="jettyAndNodelog" />
+    <appender-ref ref="Jetty" />
     <includeCallerData>true</includeCallerData>
   </appender>
 
   <!--  EELF loggers -->
   <!-- ============================================================================ -->
   <logger name="com.att.eelf" level="info" additivity="false">
-    <appender-ref ref="asyncEELF" />
+    <appender-ref ref="asyncAudit" />
   </logger>
 
-     <logger name="com.att.eelf.error" level="error" additivity="false">
-          <appender-ref ref="asyncEELFError" />
-      </logger>
-
-     <logger name="log4j.logger.org.eclipse.jetty" additivity="false" level="info">
-        <appender-ref ref="asyncEELFjettyAndNodelog"/>
-    </logger>
-
-  <!-- logger name="com.att.eelf.security" level="info" additivity="false">
-    <appender-ref ref="asyncEELFSecurity" />
-  </logger>
-  <logger name="com.att.eelf.perf" level="info" additivity="false">
-    <appender-ref ref="asyncEELFPerformance" />
-  </logger>
-  <logger name="com.att.eelf.server" level="info" additivity="false">
-    <appender-ref ref="asyncEELFServer" />
-  </logger>
-  <logger name="com.att.eelf.policy" level="info" additivity="false">
-    <appender-ref ref="asyncEELFPolicy" />
+  <logger name="com.att.eelf" level="info" additivity="false">
+    <appender-ref ref="asyncMetrics" />
   </logger>
 
-  <logger name="com.att.eelf.audit" level="info" additivity="false">
-    <appender-ref ref="asyncEELFAudit" />
+  <logger name="com.att.eelf" level="debug" additivity="false">
+    <appender-ref ref="asyncDebug" />
   </logger>
 
-  <logger name="com.att.eelf.metrics" level="info" additivity="false">
-        <appender-ref ref="asyncEELFMetrics" />
-  </logger>
+     <logger name="com.att.eelf.error" level="error" additivity="false">
+          <appender-ref ref="asyncError" />
+      </logger>
 
-   <logger name="com.att.eelf.debug" level="debug" additivity="false">
-        <appender-ref ref="asyncEELFDebug" />
-  </logger-->
+     <logger name="log4j.logger.org.eclipse.jetty" additivity="false" level="info">
+        <appender-ref ref="asyncJettyLog"/>
+    </logger>
 
 
 
 
-  <root level="TRACE">
-    <appender-ref ref="asyncEELF" />
-    <appender-ref ref="asyncEELFError" />
-    <appender-ref ref="asyncEELFjettyAndNodelog" />
+  <root level="INFO">
+    <appender-ref ref="asyncAudit" />
+    <appender-ref ref="asyncMetrics" />
+    <appender-ref ref="asyncDebug" />
+    <appender-ref ref="asyncError" />
+    <appender-ref ref="asyncJettyLog" />
   </root>
 
 </configuration>
index f6737b1..bb36718 100644 (file)
@@ -1,4 +1,4 @@
-/**-\r
+/*\r
  * ============LICENSE_START=======================================================\r
  *  Copyright (C) 2019 Nordix Foundation.\r
  * ================================================================================\r
 \r
 package org.onap.dmaap.datarouter.node;\r
 \r
+import static org.mockito.Mockito.doThrow;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.IOException;\r
+import javax.servlet.FilterChain;\r
+import javax.servlet.ServletException;\r
+import javax.servlet.http.HttpServletRequest;\r
+import javax.servlet.http.HttpServletResponse;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
 import org.junit.runner.RunWith;\r
@@ -32,19 +43,10 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;\r
 import org.powermock.modules.junit4.PowerMockRunner;\r
 \r
-import javax.servlet.FilterChain;\r
-import javax.servlet.ServletException;\r
-import javax.servlet.http.HttpServletRequest;\r
-import javax.servlet.http.HttpServletResponse;\r
-import java.io.IOException;\r
-\r
-import static org.mockito.Mockito.*;\r
-\r
 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")\r
 @PrepareForTest({CadiFilter.class})\r
 @RunWith(PowerMockRunner.class)\r
-public class DRNodeCadiFilterTest\r
-{\r
+public class DRNodeCadiFilterTest {\r
 \r
     @Mock\r
     private PropAccess access;\r
@@ -67,7 +69,8 @@ public class DRNodeCadiFilterTest
     }\r
 \r
     @Test\r
-    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called() throws Exception {\r
+    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Instance_Is_NULL_Then_Chain_doFilter_Called()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
@@ -75,12 +78,13 @@ public class DRNodeCadiFilterTest
         PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");\r
         when(request.getPathInfo()).thenReturn("/publish/5");\r
         when(request.getMethod()).thenReturn("GET");\r
-        cadiFilter.doFilter(request,response,chain);\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(1)).doFilter(request, response);\r
     }\r
 \r
     @Test\r
-    public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called() throws Exception {\r
+    public void Given_doFilter_Called_And_Method_Is_GET_And_Path_Includes_Internal_Then_Chain_doFilter_Called()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
@@ -88,12 +92,13 @@ public class DRNodeCadiFilterTest
         PowerMockito.when(config.getAafInstance("/other/5")).thenReturn("legacy");\r
         when(request.getPathInfo()).thenReturn("/internal/5");\r
         when(request.getMethod()).thenReturn("GET");\r
-        cadiFilter.doFilter(request,response,chain);\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(1)).doFilter(request, response);\r
     }\r
 \r
     @Test\r
-    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called() throws Exception {\r
+    public void Given_doFilter_Called_And_Method_Is_GET_And_AAF_DB_Is_Not_Null_Then_Super_doFilter_Called()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
@@ -102,20 +107,22 @@ public class DRNodeCadiFilterTest
         when(request.getPathInfo()).thenReturn("/publish/5/fileId");\r
         when(request.getMethod()).thenReturn("GET");\r
         PowerMockito.suppress(MemberMatcher.methodsDeclaredIn(CadiFilter.class));\r
-        cadiFilter.doFilter(request,response,chain);\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(0)).doFilter(request, response);\r
     }\r
 \r
     @Test\r
-    public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter() throws Exception {\r
+    public void Given_getFileid_Called_And_SendError_Fails_Then_Throw_IOException_And_Call_chain_doFilter()\r
+            throws Exception {\r
         PowerMockito.mockStatic(NodeConfigManager.class);\r
         NodeConfigManager config = mock(NodeConfigManager.class);\r
 \r
         PowerMockito.when(NodeConfigManager.getInstance()).thenReturn(config);\r
         when(request.getPathInfo()).thenReturn("/publish/5");\r
         when(request.getMethod()).thenReturn("DELETE");\r
-        doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");\r
-        cadiFilter.doFilter(request,response,chain);\r
+        doThrow(new IOException()).when(response).sendError(HttpServletResponse.SC_NOT_FOUND,\r
+                "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");\r
+        cadiFilter.doFilter(request, response, chain);\r
         verify(chain, times(1)).doFilter(request, response);\r
     }\r
 }\r
index 6dc334f..6a5f219 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.util.Hashtable;
+import java.util.Vector;
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.jetbrains.annotations.NotNull;
 import org.junit.Before;
 import org.junit.Test;
 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 java.io.File;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.when;
-
 @RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
 public class DeliveryQueueTest {
 
+    @Mock
+    DeliveryQueueHelper deliveryQueueHelper;
     private DeliveryQueue deliveryQueue;
     @Mock
     private DestInfo destInfo;
-    @Mock
-    DeliveryQueueHelper deliveryQueueHelper;
-
     private String dirPath = "/tmp/dir001/";
-    private String FileName1 = "10000000000004.fileName.M";
+    private String fileName = "10000000000004.fileName.M";
 
     @Before
-    public void setUp() {
-        when(destInfo.getSpool()).thenReturn("tmp");
+    public void setUp() throws IllegalAccessException {
+        when(destInfo.getSpool()).thenReturn(dirPath);
+        when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
         deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+        NodeConfigManager configManager = mockNodeConfigManager();
+        FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", configManager, true);
     }
 
     @Test
     public void Given_New_DeliveryQueue_Directory_Is_Created_As_Defined_By_DestInfo() {
-        when(destInfo.getSpool()).thenReturn("tmp");
-        File file = new File("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);
+        FieldUtils.writeField(deliveryQueue, "failed", true, true);
+        FieldUtils.writeField(deliveryQueue, "resumetime", System.currentTimeMillis() * 2, true);
         assertNull(deliveryQueue.peekNext());
     }
 
@@ -75,21 +87,155 @@ public class DeliveryQueueTest {
         deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
         DeliveryTask nt = deliveryQueue.getNext();
         assertEquals("10000000000004.fileName", nt.getPublishId());
-        deleteFile(dirPath + FileName1);
+        deleteFile(dirPath + fileName);
         deleteFile(dirPath);
     }
 
+    @Test
+    public void Given_Task_In_Todo_Is_Already_Cleaned_GetNext_Returns_Null() throws Exception {
+        when(deliveryQueueHelper.getExpirationTimer()).thenReturn(10000L);
+        deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+        Vector<DeliveryTask> tasks = new Vector<>();
+        DeliveryTask task = new DeliveryTask(deliveryQueue, "123.node.datarouternew.com");
+        task.clean();
+        tasks.add(task);
+        FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+        DeliveryTask nt = deliveryQueue.getNext();
+        assertNull(nt);
+    }
+
+    @Test
+    public void Given_Task_In_Todo_Has_Resume_Time_In_Future_GetNext_Returns_Null() throws Exception {
+        when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
+        when(deliveryQueueHelper.getExpirationTimer()).thenReturn(10000L);
+        deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+        Vector<DeliveryTask> tasks = new Vector<>();
+        DeliveryTask task = new DeliveryTask(deliveryQueue, "123.node.datarouternew.com");
+        long timeInFuture = 2558366240223L;
+        task.setResumeTime(timeInFuture);
+        tasks.add(task);
+        FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+        DeliveryTask nt = deliveryQueue.getNext();
+        assertNull(nt);
+    }
+
+    @Test
+    public void Given_Task_In_Todo_Is_Expired_GetNext_Returns_Null() throws Exception {
+        when(destInfo.isPrivilegedSubscriber()).thenReturn(true);
+        when(deliveryQueueHelper.getExpirationTimer()).thenReturn(10000L);
+        deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+        Vector<DeliveryTask> tasks = new Vector<>();
+        DeliveryTask task = new DeliveryTask(deliveryQueue, "123.node.datarouternew.com");
+        long timeInPast = 1058366240223L;
+        task.setResumeTime(timeInPast);
+        tasks.add(task);
+        FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+        DeliveryTask nt = deliveryQueue.getNext();
+        assertNull(nt);
+    }
+
     @Test
     public void Given_Delivery_Task_Cancel_And_FileId_Is_Null_Return_Zero() {
         long rc = deliveryQueue.cancelTask("123.node.datarouternew.com");
         assertEquals(0, rc);
     }
 
+    @Test
+    public void Given_Delivery_Task_Is_Working_Cancel_Task_Returns_Zero() throws IllegalAccessException {
+        Hashtable<String, DeliveryTask> tasks = new Hashtable<>();
+        tasks.put("123.node.datarouternew.com", new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+        FieldUtils.writeField(deliveryQueue, "working", tasks, true);
+        long rc = deliveryQueue.cancelTask("123.node.datarouternew.com");
+        assertEquals(0, rc);
+    }
+
+    @Test
+    public void Given_Delivery_Task_In_Todo_Cancel_Task_Returns_Zero() throws IllegalAccessException {
+        Vector<DeliveryTask> tasks = new Vector<>();
+        tasks.add(new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+        FieldUtils.writeField(deliveryQueue, "todo", tasks, true);
+        long rc = deliveryQueue.cancelTask("123.node.datarouternew.com");
+        assertEquals(0, rc);
+    }
+
+    @Test
+    public void Given_Ok_Status_And_Privileged_Subscriber_Then_Set_Resume_Time_Is_Called_On_DeliveryTask() {
+        DeliveryTask deliveryTask = mockDeliveryTask();
+        deliveryQueue.reportStatus(deliveryTask, 200, "123456789.dmaap-dr-node", "delivery");
+        verify(deliveryTask, times(1)).setResumeTime(anyLong());
+        cleanUpLogging();
+    }
+
+    @Test
+    public void Given_Ok_Status_And_Not_Privileged_Subscriber_Then_Clean_Is_Called_On_DeliveryTask() {
+        DeliveryTask deliveryTask = mockDeliveryTask();
+        when(destInfo.isPrivilegedSubscriber()).thenReturn(false);
+        deliveryQueue = new DeliveryQueue(deliveryQueueHelper, destInfo);
+        deliveryQueue.reportStatus(deliveryTask, 200, "123456789.dmaap-dr-node", "delivery");
+        verify(deliveryTask, times(1)).clean();
+        cleanUpLogging();
+    }
+
+    @Test
+    public void Given_Not_Ok_Status_Then_Clean_Is_Called_On_DeliveryTask() {
+        DeliveryTask deliveryTask = mockDeliveryTask();
+        deliveryQueue.reportStatus(deliveryTask, 400, "123456789.dmaap-dr-node", "delivery");
+        verify(deliveryTask, times(1)).clean();
+        cleanUpLogging();
+    }
+
+    @Test
+    public void Given_Task_In_Working_MarkTaskSuccess_Returns_True() throws IllegalAccessException {
+        Hashtable<String, DeliveryTask> tasks = new Hashtable<>();
+        tasks.put("123.node.datarouternew.com", new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+        FieldUtils.writeField(deliveryQueue, "working", tasks, true);
+        assertTrue(deliveryQueue.markTaskSuccess("123.node.datarouternew.com"));
+    }
+
+    @Test
+    public void Given_Task_In_Retry_MarkTaskSuccess_Returns_True() throws IllegalAccessException {
+        Hashtable<String, DeliveryTask> tasks = new Hashtable<>();
+        tasks.put("123.node.datarouternew.com", new DeliveryTask(deliveryQueue, "123.node.datarouternew.com"));
+        FieldUtils.writeField(deliveryQueue, "retry", tasks, true);
+        assertTrue(deliveryQueue.markTaskSuccess("123.node.datarouternew.com"));
+    }
+
+    @Test
+    public void Given_Task_Does_Not_Exist_MarkTaskSuccess_Returns_False() {
+        assertFalse(deliveryQueue.markTaskSuccess("false.pubId.com"));
+    }
+
+    private void cleanUpLogging() {
+        final File currentDir = new File(System.getProperty("user.dir"));
+        final File[] files = currentDir.listFiles((file, name) -> name.matches("null.*"));
+        if (files != null) {
+            for (final File file : files) {
+                file.delete();
+            }
+        }
+    }
+
+    @NotNull
+    private DeliveryTask mockDeliveryTask() {
+        DeliveryTask deliveryTask = mock(DeliveryTask.class);
+        when(deliveryTask.getPublishId()).thenReturn("123456789.dmaap-dr-node");
+        when(deliveryTask.getFeedId()).thenReturn("1");
+        when(deliveryTask.getSubId()).thenReturn("1");
+        when(deliveryTask.getURL()).thenReturn("http://subcriber.com:7070/delivery");
+        when(deliveryTask.getCType()).thenReturn("application/json");
+        when(deliveryTask.getLength()).thenReturn(486L);
+        return deliveryTask;
+    }
+
+    private NodeConfigManager mockNodeConfigManager() {
+        NodeConfigManager config = mock(NodeConfigManager.class);
+        PowerMockito.when(config.getEventLogInterval()).thenReturn("30000");
+        return config;
+    }
+
     private void prepareFiles() throws Exception {
         createFolder(dirPath);
-        createFile(FileName1, dirPath);
-        String[] files = new String[2];
-        files[0] = dirPath + FileName1;
+        createFile(fileName, dirPath);
     }
 
     private void createFolder(String dirName) {
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DeliveryTaskTest.java
new file mode 100644 (file)
index 0000000..a0f0577
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * ============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;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DeliveryTask.class})
+public class DeliveryTaskTest {
+
+    @Mock
+    private DeliveryQueue deliveryQueue;
+
+    private ExecutorService executorService;
+
+    @Before
+    public void setUp() throws Exception {
+        DestInfo destInfo = getPrivDestInfo();
+        deliveryQueue = mockDelvieryQueue(destInfo);
+
+        URL url = PowerMockito.mock(URL.class);
+        HttpURLConnection urlConnection = PowerMockito.mock(HttpURLConnection.class);
+        OutputStream outputStream = PowerMockito.mock(OutputStream.class);
+
+        PowerMockito.whenNew(URL.class).withParameterTypes(String.class).withArguments(Mockito.anyString())
+                .thenReturn(url);
+        PowerMockito.when(urlConnection.getOutputStream()).thenReturn(outputStream);
+        PowerMockito.when(url.openConnection()).thenReturn(urlConnection);
+        PowerMockito.when(urlConnection.getHeaderField(0)).thenReturn("PUT");
+        PowerMockito.when(urlConnection.getResponseCode()).thenReturn(200);
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+
+    @Test
+    public void Validate_Delivery_Task_Equals() {
+        DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
+        DeliveryTask task2 = new DeliveryTask(deliveryQueue, "123456789.test-dr-datafile");
+        Assert.assertEquals(task, task2);
+        Assert.assertEquals(task.hashCode(), task2.hashCode());
+        Assert.assertEquals(task.toString(), task2.toString());
+        Assert.assertEquals(task.getPublishId(), task2.getPublishId());
+        Assert.assertEquals(task.getSubId(), task2.getSubId());
+        Assert.assertEquals(task.getFeedId(), task2.getFeedId());
+        Assert.assertEquals(task.getLength(), task2.getLength());
+        Assert.assertEquals(task.isCleaned(), task2.isCleaned());
+        Assert.assertEquals(task.getDate(), task2.getDate());
+        Assert.assertEquals(task.getURL(), task2.getURL());
+        Assert.assertEquals(task.getCType(), task2.getCType());
+        Assert.assertEquals(task.getMethod(), task2.getMethod());
+        Assert.assertEquals(task.getFileId(), task2.getFileId());
+        Assert.assertEquals(task.getAttempts(), task2.getAttempts());
+        Assert.assertEquals(task.getFollowRedirects(), task2.getFollowRedirects());
+
+        Assert.assertEquals(0, task.compareTo(task2));
+    }
+
+    @Test
+    public void Validate_Delivery_Tasks_Success_For_Standard_File() throws InterruptedException {
+        DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node");
+        executorService = Executors.newSingleThreadExecutor();
+        executorService.execute(task);
+
+        executorService.shutdown();
+        executorService.awaitTermination(2, TimeUnit.SECONDS);
+    }
+
+    @Test
+    public void Validate_Delivery_Tasks_Success_For_Compressed_File() throws InterruptedException {
+
+        DeliveryTask task = new DeliveryTask(deliveryQueue, "123456789.test-dr-node.gz");
+        executorService = Executors.newSingleThreadExecutor();
+        executorService.execute(task);
+
+        executorService.shutdown();
+        executorService.awaitTermination(2, TimeUnit.SECONDS);
+    }
+
+    private DestInfo getPrivDestInfo() {
+        return new DestInfoBuilder().setName("n:" + "dmaap-dr-node")
+                       .setSpool(System.getProperty("user.dir") + "/src/test/resources/delivery_files")
+                       .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
+                       .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
+                       .setPrivilegedSubscriber(true).setFollowRedirects(false).setDecompress(true).createDestInfo();
+    }
+
+    private DeliveryQueue mockDelvieryQueue(DestInfo destInfo) {
+        DeliveryQueue mockedDeliveryQueue = mock(DeliveryQueue.class);
+        when(mockedDeliveryQueue.getDestinationInfo()).thenReturn(destInfo);
+        return mockedDeliveryQueue;
+    }
+
+}
index 0812007..18d9d56 100644 (file)
  ******************************************************************************/
 package org.onap.dmaap.datarouter.node;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Hashtable;
 import org.apache.commons.lang3.reflect.FieldUtils;
 import org.junit.After;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
+import org.onap.dmaap.datarouter.node.Delivery.DelItem;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Hashtable;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
 @RunWith(PowerMockRunner.class)
 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.node.NodeConfigManager")
 public class DeliveryTest {
 
-  @Mock
-  private DeliveryQueue deliveryQueue;
+    @Mock
+    private DeliveryQueue deliveryQueue;
+    @Mock
+    private NodeConfigManager config;
+    private File nDir = new File("tmp/n");
+    private File newNDir = new File("tmp/n/0");
+    private File newNFile = new File("tmp/n/0/testN.txt");
+    private File sDir = new File("tmp/s");
+    private File newSDir = new File("tmp/s/0/1");
+    private File newSpoolFile = new File("tmp/s/0/1/123456789.dmaap-dr-node");
+    private File spoolFileMeta = new File("tmp/s/0/1/123456789.dmaap-dr-node.M");
+
+    @Before
+    public void setUp() throws IOException {
+        nDir.mkdirs();
+        sDir.mkdirs();
+        newNDir.mkdirs();
+        newNFile.createNewFile();
+        newSDir.mkdirs();
+        newSpoolFile.createNewFile();
+        spoolFileMeta.createNewFile();
+        config = mockNodeConfigManager();
+    }
+
+    @Test
+    public void Validate_Reset_Queue_Calls_Reset_Queue_On_Delivery_Queue_Object() throws IllegalAccessException {
+        Delivery delivery = new Delivery(config);
+        HashMap<String, DeliveryQueue> dqs = new HashMap<>();
+        dqs.put("tmp/s/0/1", deliveryQueue);
+        FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
+        delivery.resetQueue("tmp/s/0/1");
+        verify(deliveryQueue, times(1)).resetQueue();
+    }
 
-  private File nDir = new File("tmp/n");
-  private File sDir = new File("tmp/s");
+    @Test
+    public void Validate_Mark_Success_Calls_Mark_Success_On_Delivery_Queue_Object() throws IllegalAccessException {
+        Delivery delivery = new Delivery(config);
+        HashMap<String, DeliveryQueue> dqs = new HashMap<>();
+        dqs.put("tmp/s/0/1", deliveryQueue);
+        FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
+        delivery.markTaskSuccess("tmp/s/0/1", "123456789.dmaap-dr-node");
+        verify(deliveryQueue, times(1)).markTaskSuccess("123456789.dmaap-dr-node");
+    }
 
-  @Before
-  public void setUp() throws IOException {
-    nDir.mkdirs();
-    sDir.mkdirs();
-    File newNDir = new File("tmp/n/0");
-    newNDir.mkdirs();
-    File newNFile = new File("tmp/n/0/testN.txt");
-    newNFile.createNewFile();
-    File newSDir = new File("tmp/s/0/1");
-    newSDir.mkdirs();
-    File newSpoolFile = new File("tmp/s/0/1/testSpool.txt");
-    newSpoolFile.createNewFile();
-  }
+    @Test
+    public void Validate_DelItem_With_Equal_Spool_And_PubId_Are_Equal() {
+        DelItem delItem1 = new DelItem("123456789.dmaap-dr-node", "tmp/s/0/1");
+        DelItem delItem2 = new DelItem("123456789.dmaap-dr-node", "tmp/s/0/1");
+        Assert.assertEquals(delItem1, delItem2);
+        Assert.assertEquals(0, delItem1.compareTo(delItem2));
+    }
 
-  @Test
-  public void Validate_Reset_Queue_Calls_Reset_Queue_On_Delivery_Queue_Object() throws IllegalAccessException {
-    NodeConfigManager config = mockNodeConfigManager();
-    Delivery delivery = new Delivery(config);
-    Hashtable<String, DeliveryQueue> dqs = new Hashtable<>();
-    dqs.put("spool/s/0/1", deliveryQueue);
-    FieldUtils.writeDeclaredField(delivery, "dqs", dqs, true);
-    delivery.resetQueue("spool/s/0/1");
-    verify(deliveryQueue, times(1)).resetQueue();
-  }
+    @Test
+    public void Validate_DelItem_With_Unequal_Spool_And_PubId_Are_Not_Equal() {
+        DelItem delItem1 = new DelItem("123456789.dmaap-dr-node", "tmp/s/0/1");
+        DelItem delItem2 = new DelItem("000000000.dmaap-dr-node", "tmp/s/0/2");
+        Assert.assertNotEquals(delItem1, delItem2);
+        Assert.assertNotEquals(0, delItem1.compareTo(delItem2));
+    }
 
-  @After
-  public void tearDown() {
-    nDir.delete();
-    sDir.delete();
-    File tmpDir = new File("tmp");
-    tmpDir.delete();
-  }
+    @After
+    public void tearDown() {
+        newSpoolFile.delete();
+        spoolFileMeta.delete();
+        newNFile.delete();
+        newNDir.delete();
+        newSDir.delete();
+        new File("tmp/s/0").delete();
+        nDir.delete();
+        sDir.delete();
+        File tmpDir = new File("tmp");
+        tmpDir.delete();
+    }
 
-  private NodeConfigManager mockNodeConfigManager() {
-    PowerMockito.mockStatic(NodeConfigManager.class);
-    NodeConfigManager config = mock(NodeConfigManager.class);
-    PowerMockito.when(config.isConfigured()).thenReturn(true);
-    PowerMockito.when(config.getAllDests()).thenReturn(createDestInfoObjects());
-    PowerMockito.when(config.getFreeDiskStart()).thenReturn(0.49);
-    PowerMockito.when(config.getFreeDiskStop()).thenReturn(0.5);
-    PowerMockito.when(config.getDeliveryThreads()).thenReturn(0);
-    PowerMockito.when(config.getSpoolBase()).thenReturn("tmp");
-    return config;
-  }
+    private NodeConfigManager mockNodeConfigManager() {
+        NodeConfigManager config = mock(NodeConfigManager.class);
+        PowerMockito.when(config.isConfigured()).thenReturn(true);
+        PowerMockito.when(config.getAllDests()).thenReturn(createDestInfoObjects());
+        PowerMockito.when(config.getFreeDiskStart()).thenReturn(0.9);
+        PowerMockito.when(config.getFreeDiskStop()).thenReturn(0.2);
+        PowerMockito.when(config.getDeliveryThreads()).thenReturn(0);
+        PowerMockito.when(config.getSpoolBase()).thenReturn("tmp");
+        return config;
+    }
 
-  private DestInfo[] createDestInfoObjects() {
-    DestInfo[] destInfos = new DestInfo[1];
-    DestInfo destInfo = new DestInfo.DestInfoBuilder().setName("node.datarouternew.com").setSpool("spool/s/0/1").setSubid("1")
-        .setLogdata("logs/").setUrl("/subs/1").setAuthuser("user1").setAuthentication("Basic dXNlcjE6cGFzc3dvcmQx")
-        .setMetaonly(false).setUse100(true).setPrivilegedSubscriber(false).setFollowRedirects(false)
-        .setDecompress(false).createDestInfo();
-    destInfos[0] = destInfo;
-    return destInfos;
-  }
+    private DestInfo[] createDestInfoObjects() {
+        DestInfo[] destInfos = new DestInfo[1];
+        DestInfo destInfo = new DestInfoBuilder().setName("node.datarouternew.com").setSpool("tmp/s/0/1")
+                .setSubid("1")
+                .setLogdata("logs/").setUrl("/subs/1").setAuthuser("user1")
+                .setAuthentication("Basic dXNlcjE6cGFzc3dvcmQx")
+                .setMetaonly(false).setUse100(true).setPrivilegedSubscriber(false).setFollowRedirects(false)
+                .setDecompress(false).createDestInfo();
+        destInfos[0] = destInfo;
+        return destInfos;
+    }
 }
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/DestInfoTest.java
new file mode 100644 (file)
index 0000000..ed629bf
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * ============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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class DestInfoTest {
+
+    private DestInfo destInfo;
+
+    @Before
+    public void setUp() {
+        destInfo = getDestInfo("/src/test/resources");
+    }
+
+    @Test
+    public void Validate_Getters_And_Setters() {
+        assertEquals("n:dmaap-dr-node", destInfo.getName());
+        assertEquals("/src/test/resources", destInfo.getSpool());
+        assertEquals("1", destInfo.getSubId());
+        assertEquals("n2n-dmaap-dr-node", destInfo.getLogData());
+        assertEquals("https://dmaap-dr-node:8443/internal/publish", destInfo.getURL());
+        assertEquals("dmaap-dr-node", destInfo.getAuthUser());
+        assertEquals("Auth", destInfo.getAuth());
+        assertFalse(destInfo.isMetaDataOnly());
+        assertTrue(destInfo.isUsing100());
+        assertFalse(destInfo.isPrivilegedSubscriber());
+        assertFalse(destInfo.isFollowRedirects());
+        assertFalse(destInfo.isDecompress());
+    }
+
+    @Test
+    public void Validate_DestInfo_Objects_Are_Equal() {
+        DestInfo destInfo2 = getDestInfo("/src/test/resources");
+        assertEquals(destInfo, destInfo2);
+        assertEquals(destInfo.hashCode(), destInfo2.hashCode());
+    }
+
+    @Test
+    public void Validate_DestInfo_Objects_Are_Not_Equal() {
+        DestInfo destInfo2 = getDestInfo("notEqual");
+        assertNotEquals(destInfo, destInfo2);
+        assertNotEquals(destInfo.hashCode(), destInfo2.hashCode());
+    }
+
+    private DestInfo getDestInfo(String spool) {
+        return new DestInfoBuilder().setName("n:" + "dmaap-dr-node").setSpool(spool)
+                .setSubid("1").setLogdata("n2n-dmaap-dr-node").setUrl("https://dmaap-dr-node:8443/internal/publish")
+                .setAuthuser("dmaap-dr-node").setAuthentication("Auth").setMetaonly(false).setUse100(true)
+                .setPrivilegedSubscriber(false).setFollowRedirects(false).setDecompress(false).createDestInfo();
+    }
+
+}
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/LogManagerTest.java
new file mode 100644 (file)
index 0000000..da69020
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * ============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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Timer;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.onap.dmaap.datarouter.node.LogManager.Uploader;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.NodeConfigManager"})
+public class LogManagerTest {
+
+    @Mock
+    private NodeConfigManager config;
+
+    private LogManager logManager;
+
+    @Before
+    public void setUp() throws IllegalAccessException {
+        mockNodeConfigManager();
+        FieldUtils.writeDeclaredStaticField(StatusLog.class, "config", config, true);
+        logManager = new LogManager(config);
+    }
+
+    @AfterClass
+    public static void tearDown() throws IOException {
+        File spoolDir = new File(System.getProperty("user.dir") + "/src/test/resources/.spool");
+        FileUtils.deleteDirectory(spoolDir);
+    }
+
+    @Test
+    public void Verify_LogManager_Attempts_To_Deliver_Log_Files_To_Prov() {
+        logManager.run();
+        try {
+            Thread.sleep(1000);
+        } catch (Exception e) {
+            System.out.println("Exception caught: " + e.getMessage());
+        }
+        File file = new File(System.getProperty("user.dir") + "/src/test/resources/.spool/.lastqueued");
+        assertTrue(file.isFile());
+    }
+
+    @Test
+    public void Validate_Uploader_Getters() {
+        Uploader worker = logManager.getWorker();
+        assertEquals(10000L, worker.getInitFailureTimer());
+        assertEquals(600000L, worker.getWaitForFileProcessFailureTimer());
+        assertEquals(2.0, worker.getFailureBackoff(), 0.0);
+        assertEquals(150000L, worker.getMaxFailureTimer());
+        assertEquals(604800000L, worker.getExpirationTimer());
+        assertEquals(10000, worker.getFairFileLimit());
+        assertEquals(86400000, worker.getFairTimeLimit());
+        assertEquals("https://dmaap-dr-prov:8443/internal/logs",
+                worker.getDestURL(new DestInfoBuilder().createDestInfo(), "String"));
+        assertFalse(worker.handleRedirection(new DestInfoBuilder().createDestInfo(), "", ""));
+        assertFalse(worker.isFollowRedirects());
+        assertNull(worker.getFeedId(""));
+    }
+
+    private void mockNodeConfigManager() {
+        PowerMockito.when(config.getLogDir()).thenReturn(System.getProperty("user.dir") + "/src/test/resources");
+        PowerMockito.when(config.getTimer()).thenReturn(new Timer("Node Configuration Timer", true));
+        PowerMockito.when(config.getEventLogPrefix())
+                .thenReturn(System.getProperty("user.dir") + "/src/test/resources/events");
+        PowerMockito.when(config.getEventLogSuffix()).thenReturn(".log");
+        PowerMockito.when(config.getLogRetention()).thenReturn(94608000000L);
+        PowerMockito.when(config.getEventLogInterval()).thenReturn("30s");
+        PowerMockito.when(config.getPublishId()).thenReturn("123456789.dmaap-dr-node");
+        PowerMockito.when(config.getEventLogUrl()).thenReturn("https://dmaap-dr-prov:8443/internal/logs");
+    }
+
+}
index 5e35737..b03407b 100644 (file)
@@ -22,6 +22,9 @@
  ******************************************************************************/
 package org.onap.dmaap.datarouter.node;
 
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.junit.Assert;
@@ -31,23 +34,114 @@ import org.junit.runner.RunWith;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-
 @RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData",
-        "org.onap.dmaap.datarouter.node.NodeUtils"})
+@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.node.ProvData"})
 public class NodeConfigTest {
 
     private static NodeConfig nodeConfig;
 
     @BeforeClass
-    public static void setUp() throws IOException{
+    public static void setUp() throws IOException {
         ProvData provData = setUpProvData();
         nodeConfig = new NodeConfig(provData, "Name", "spool/dir", 80, "Key");
     }
 
+    private static ProvData setUpProvData() throws IOException {
+        JSONObject provData = new JSONObject();
+        createValidFeed(provData);
+        createValidSubscription(provData);
+        createValidParameters(provData);
+        createValidIngressValues(provData);
+        createValidEgressValues(provData);
+        createValidRoutingValues(provData);
+        Reader reader = new StringReader(provData.toString());
+        return new ProvData(reader);
+    }
+
+    private static void createValidFeed(JSONObject provData) {
+        JSONArray feeds = new JSONArray();
+        JSONObject feed = new JSONObject();
+        JSONObject auth = new JSONObject();
+        JSONArray endpointIds = new JSONArray();
+        JSONArray endpointAddrs = new JSONArray();
+        JSONObject endpointId = new JSONObject();
+        feed.put("feedid", "1");
+        feed.put("name", "Feed1");
+        feed.put("version", "m1.0");
+        feed.put("suspend", false);
+        feed.put("deleted", false);
+        endpointId.put("id", "user1");
+        endpointId.put("password", "password1");
+        endpointIds.put(endpointId);
+        auth.put("endpoint_ids", endpointIds);
+        endpointAddrs.put("172.0.0.1");
+        auth.put("endpoint_addrs", endpointAddrs);
+        feed.put("authorization", auth);
+        feed.put("aaf_instance", "legacy");
+        feeds.put(feed);
+        provData.put("feeds", feeds);
+    }
+
+    private static void createValidSubscription(JSONObject provData) {
+        JSONArray subscriptions = new JSONArray();
+        JSONObject subscription = new JSONObject();
+        JSONObject delivery = new JSONObject();
+        subscription.put("subid", "1");
+        subscription.put("feedid", "1");
+        subscription.put("suspend", false);
+        subscription.put("metadataOnly", false);
+        delivery.put("url", "https://172.0.0.2");
+        delivery.put("user", "user1");
+        delivery.put("password", "password1");
+        delivery.put("use100", true);
+        subscription.put("delivery", delivery);
+        subscription.put("privilegedSubscriber", false);
+        subscription.put("follow_redirect", false);
+        subscription.put("decompress", false);
+        subscriptions.put(subscription);
+        provData.put("subscriptions", subscriptions);
+    }
+
+    private static void createValidParameters(JSONObject provData) {
+        JSONObject parameters = new JSONObject();
+        JSONArray nodes = new JSONArray();
+        parameters.put("PROV_NAME", "prov.datarouternew.com");
+        parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
+        parameters.put("DELIVERY_MAX_AGE", "86400");
+        parameters.put("PROV_DOMAIN", "");
+        nodes.put("172.0.0.4");
+        parameters.put("NODES", nodes);
+        provData.put("parameters", parameters);
+    }
+
+    private static void createValidIngressValues(JSONObject provData) {
+        JSONArray ingresses = new JSONArray();
+        JSONObject ingress = new JSONObject();
+        ingress.put("feedid", "1");
+        ingress.put("subnet", "");
+        ingress.put("user", "");
+        ingress.put("node", "172.0.0.4");
+        ingresses.put(ingress);
+        provData.put("ingress", ingresses);
+    }
+
+    private static void createValidEgressValues(JSONObject provData) {
+        JSONObject egress = new JSONObject();
+        egress.put("subid", "1");
+        egress.put("nodeid", "172.0.0.4");
+        provData.put("egress", egress);
+    }
+
+    private static void createValidRoutingValues(JSONObject provData) {
+        JSONArray routings = new JSONArray();
+        JSONObject routing = new JSONObject();
+        routing.put("from", "prov.datarouternew.com");
+        routing.put("to", "172.0.0.4");
+        routing.put("via", "172.100.0.1");
+        routings.put(routing);
+        provData.put("routing", routings);
+    }
+
     @Test
     public void Given_Feed_Does_Not_Exist_Then_Is_Publish_Permitted_Returns_Not_Null() {
         String permitted = nodeConfig.isPublishPermitted("2", "user", "0.0.0.0");
@@ -73,7 +167,7 @@ public class NodeConfigTest {
     }
 
     @Test
-    public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id(){
+    public void Given_SubId_Then_Get_Feed_Id_Returns_Correct_Id() {
         String feedId = nodeConfig.getFeedId("1");
         Assert.assertEquals("1", feedId);
     }
@@ -164,100 +258,4 @@ public class NodeConfigTest {
         String auth = nodeConfig.getMyAuth();
         Assert.assertEquals("Basic TmFtZTp6Z04wMFkyS3gybFppbXltNy94ZDhuMkdEYjA9", auth);
     }
-
-    private static ProvData setUpProvData() throws IOException {
-        JSONObject provData = new JSONObject();
-        createValidFeed(provData);
-        createValidSubscription(provData);
-        createValidParameters(provData);
-        createValidIngressValues(provData);
-        createValidEgressValues(provData);
-        createValidRoutingValues(provData);
-        Reader reader = new StringReader(provData.toString());
-        return new ProvData(reader);
-    }
-
-    private static void createValidFeed(JSONObject provData) {
-        JSONArray feeds = new JSONArray();
-        JSONObject feed = new JSONObject();
-        JSONObject auth = new JSONObject();
-        JSONArray endpointIds = new JSONArray();
-        JSONArray endpointAddrs = new JSONArray();
-        JSONObject endpointId = new JSONObject();
-        feed.put("feedid", "1");
-        feed.put("name", "Feed1");
-        feed.put("version", "m1.0");
-        feed.put("suspend", false);
-        feed.put("deleted", false);
-        endpointId.put("id", "user1");
-        endpointId.put("password", "password1");
-        endpointIds.put(endpointId);
-        auth.put("endpoint_ids", endpointIds);
-        endpointAddrs.put("172.0.0.1");
-        auth.put("endpoint_addrs", endpointAddrs);
-        feed.put("authorization", auth);
-        feed.put("aaf_instance", "legacy");
-        feeds.put(feed);
-        provData.put("feeds", feeds);
-    }
-
-    private static void createValidSubscription(JSONObject provData) {
-        JSONArray subscriptions = new JSONArray();
-        JSONObject subscription = new JSONObject();
-        JSONObject delivery = new JSONObject();
-        subscription.put("subid", "1");
-        subscription.put("feedid", "1");
-        subscription.put("suspend", false);
-        subscription.put("metadataOnly", false);
-        delivery.put("url", "https://172.0.0.2");
-        delivery.put("user", "user1");
-        delivery.put("password", "password1");
-        delivery.put("use100", true);
-        subscription.put("delivery", delivery);
-        subscription.put("privilegedSubscriber", false);
-        subscription.put("follow_redirect", false);
-        subscription.put("decompress", false);
-        subscriptions.put(subscription);
-        provData.put("subscriptions", subscriptions);
-    }
-
-    private static void createValidParameters(JSONObject provData) {
-        JSONObject parameters = new JSONObject();
-        JSONArray nodes = new JSONArray();
-        parameters.put("PROV_NAME", "prov.datarouternew.com");
-        parameters.put("DELIVERY_INIT_RETRY_INTERVAL", "10");
-        parameters.put("DELIVERY_MAX_AGE", "86400");
-        parameters.put("PROV_DOMAIN", "");
-        nodes.put("172.0.0.4");
-        parameters.put("NODES", nodes);
-        provData.put("parameters", parameters);
-    }
-
-    private static void createValidIngressValues(JSONObject provData) {
-        JSONArray ingresses = new JSONArray();
-        JSONObject ingress = new JSONObject();
-        ingress.put("feedid", "1");
-        ingress.put("subnet", "");
-        ingress.put("user", "");
-        ingress.put("node", "172.0.0.4");
-        ingresses.put(ingress);
-        provData.put("ingress", ingresses);
-    }
-
-    private static void createValidEgressValues(JSONObject provData) {
-        JSONObject egress = new JSONObject();
-        egress.put("subid", "1");
-        egress.put("nodeid", "172.0.0.4");
-        provData.put("egress", egress);
-    }
-
-    private static void createValidRoutingValues(JSONObject provData) {
-        JSONArray routings = new JSONArray();
-        JSONObject routing = new JSONObject();
-        routing.put("from", "prov.datarouternew.com");
-        routing.put("to", "172.0.0.4");
-        routing.put("via", "172.100.0.1");
-        routings.put(routing);
-        provData.put("routing", routings);
-    }
 }
index db71cea..a375f02 100644 (file)
@@ -219,7 +219,7 @@ public class NodeServletTest {
 
     @Test
     public void Given_Request_Is_HTTP_PUT_On_Publish_On_AAF_Feed_And_Cadi_Enabled_And_No_Permissions_Then_Forbidden_Response_Is_Generated() throws Exception {
-        when(config.getCadiEnabeld()).thenReturn(true);
+        when(config.getCadiEnabled()).thenReturn(true);
         when(config.getAafInstance("1")).thenReturn("*");
         when(request.getPathInfo()).thenReturn("/publish/1/fileName");
         setHeadersForValidRequest(true);
index 27fcd1c..2d87b8b 100644 (file)
  ******************************************************************************/
 package org.onap.dmaap.datarouter.node;
 
+import static org.mockito.Mockito.when;
+
+import javax.servlet.http.HttpServletRequest;
 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.core.classloader.annotations.PowerMockIgnore;
 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 })
+@PowerMockIgnore({"java.net.ssl", "javax.security.auth.x500.X500Principal"})
 public class NodeUtilsTest {
 
     @Mock
@@ -54,6 +44,7 @@ public class NodeUtilsTest {
     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 uriParams != null;
         Assert.assertEquals("12", uriParams[0]);
         Assert.assertEquals("fileName", uriParams[1]);
     }
@@ -87,23 +78,8 @@ public class NodeUtilsTest {
     }
 
     @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"));
+    public void Given_Get_CanonicalName_Called_Valid_CN_Returned() {
+        String canonicalName = NodeUtils.getCanonicalName("jks", "src/test/resources/org.onap.dmaap-dr-test-cert.jks", "WGxd2P6MDo*Bi4+UdzWs{?$8");
+        Assert.assertEquals("dmaap-dr-node", canonicalName);
     }
 }
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/PathFinderTest.java
new file mode 100644 (file)
index 0000000..25edd0c
--- /dev/null
@@ -0,0 +1,75 @@
+/*-
+ * ============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;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class PathFinderTest {
+
+    @Test
+    public void Given_Unknown_From_Node_Returns_Null() {
+        new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+                new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-4", "dr-node-3", "dr-node-2")});
+    }
+
+    @Test
+    public void Given_Unknown_Destination_Node_Returns_Null() {
+        new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+                new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-5", "dr-node-2")});
+    }
+
+    @Test
+    public void Given_Duplicate_Next_Hop_Returns_Null() {
+        PathFinder p = new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+                new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2"),
+                        new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2")});
+        assertThat(p.getErrors().length, is(1));
+        assertNotNull(p.getPath("dr-node-3"));
+        assertThat(p.getPath("dr-node-5").length(), is(0));
+    }
+
+    @Test
+    public void Given_Unknown_Via_Node_Returns_Null() {
+        new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+                new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-4")});
+    }
+
+    @Test
+    public void Given_Dest_Equals_Via_Bad_Hop_Defined() {
+        new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+                new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-2", "dr-node-2")});
+    }
+
+    @Test
+    public void Given_Valid_Path_Defined_Success() {
+        new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
+                new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3+", "dr-node-2")});
+    }
+
+
+}
index 662f2cc..1fd79d9 100644 (file)
 package org.onap.dmaap.datarouter.node;
 
 
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.modules.junit4.PowerMockRunner;
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.StandardCharsets;
-
-import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertNull;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
 
 @RunWith(PowerMockRunner.class)
 public class ProvDataTest {
@@ -40,77 +39,77 @@ public class ProvDataTest {
     public void Validate_Values_Are_Set_Correctly_Through_ProvData_Constuctor() throws Exception {
         String InternalProvData =
                 "{" +
-                "\"ingress\":[{" +
-                  "\"feedid\":1," +
-                  "\"subnet\":\"\"," +
-                  "\"user\":\"\"," +
-                  "\"node\":\"node\"" +
-                "}]," +
-                "\"routing\":[{" +
-                  "\"from\":\"172.10.10.10\"," +
-                  "\"to\":\"172.10.10.12\"," +
-                  "\"via\":\"172.10.10.11\"" +
-                "}]," +
-                "\"subscriptions\":[{" +
-                  "\"subid\":1," +
-                  "\"suspend\":false," +
-                  "\"delivery\":{" +
-                    "\"use100\":true," +
-                    "\"password\":\"PASSWORD\"," +
-                    "\"user\":\"LOGIN\"," +
-                    "\"url\":\"http://172.18.0.2:7070\"" +
-                  "}," +
-                  "\"last_mod\":1553608460000," +
-                  "\"subscriber\":\"PMMAPER\"," +
-                  "\"feedid\":1," +
-                  "\"decompress\":false," +
-                  "\"groupid\":1," +
-                  "\"metadataOnly\":false," +
-                  "\"follow_redirect\":false," +
-                  "\"links\":{" +
-                    "\"feed\":\"https://dmaap-dr-prov/feed/1\"" +
-                    ",\"log\":\"https://dmaap-dr-prov/sublog/1\"" +
-                    ",\"self\":\"https://dmaap-dr-prov/subs/1\"" +
-                  "}," +
-                  "\"created_date\":1553608460000," +
-                  "\"privilegedSubscriber\":false" +
-                "}]," +
-                "\"feeds\":[{" +
-                  "\"suspend\":false," +
-                  "\"groupid\":0," +
-                  "\"description\":\"Default feed\"," +
-                  "\"version\":\"m1.0\"," +
-                  "\"authorization\":{" +
-                    "\"endpoint_addrs\":[\"172.10.10.20\"]," +
-                    "\"classification\":\"unclassified\"," +
-                    "\"endpoint_ids\":[{" +
-                      "\"password\":\"password\"," +
-                      "\"id\":\"user\"" +
-                    "}]" +
-                  "}," +
-                  "\"last_mod\":1553608454000," +
-                  "\"deleted\":false," +
-                  "\"feedid\":1," +
-                  "\"name\":\"CSIT_Test2\"" +
-                  ",\"business_description\":\"Default Feed\"" +
-                  ",\"publisher\":\"dradmin\"" +
-                  ",\"links\":{" +
-                    "\"subscribe\":\"https://dmaap-dr-prov/subscribe/1\"," +
-                    "\"log\":\"https://dmaap-dr-prov/feedlog/1\"," +
-                    "\"publish\":\"https://dmaap-dr-prov/publish/1\"," +
-                    "\"self\":\"https://dmaap-dr-prov/feed/1\"" +
-                  "}," +
-                  "\"created_date\":1553608454000" +
-                "}]," +
-                "\"groups\":[]," +
-                "\"parameters\":{" +
-                  "\"NODES\":[\"dmaap-dr-node\"]," +
-                  "\"PROV_DOMAIN\":\"\"" +
-                "}," +
-                "\"egress\":{" +
-                "\"1\":1" +
-                "}" +
-                "}" ;
+                        "\"ingress\":[{" +
+                        "\"feedid\":1," +
+                        "\"subnet\":\"\"," +
+                        "\"user\":\"\"," +
+                        "\"node\":\"node\"" +
+                        "}]," +
+                        "\"routing\":[{" +
+                        "\"from\":\"172.10.10.10\"," +
+                        "\"to\":\"172.10.10.12\"," +
+                        "\"via\":\"172.10.10.11\"" +
+                        "}]," +
+                        "\"subscriptions\":[{" +
+                        "\"subid\":1," +
+                        "\"suspend\":false," +
+                        "\"delivery\":{" +
+                        "\"use100\":true," +
+                        "\"password\":\"PASSWORD\"," +
+                        "\"user\":\"LOGIN\"," +
+                        "\"url\":\"http://172.18.0.2:7070\"" +
+                        "}," +
+                        "\"last_mod\":1553608460000," +
+                        "\"subscriber\":\"PMMAPER\"," +
+                        "\"feedid\":1," +
+                        "\"decompress\":false," +
+                        "\"groupid\":1," +
+                        "\"metadataOnly\":false," +
+                        "\"follow_redirect\":false," +
+                        "\"links\":{" +
+                        "\"feed\":\"https://dmaap-dr-prov/feed/1\"" +
+                        ",\"log\":\"https://dmaap-dr-prov/sublog/1\"" +
+                        ",\"self\":\"https://dmaap-dr-prov/subs/1\"" +
+                        "}," +
+                        "\"created_date\":1553608460000," +
+                        "\"privilegedSubscriber\":false" +
+                        "}]," +
+                        "\"feeds\":[{" +
+                        "\"suspend\":false," +
+                        "\"groupid\":0," +
+                        "\"description\":\"Default feed\"," +
+                        "\"version\":\"m1.0\"," +
+                        "\"authorization\":{" +
+                        "\"endpoint_addrs\":[\"172.10.10.20\"]," +
+                        "\"classification\":\"unclassified\"," +
+                        "\"endpoint_ids\":[{" +
+                        "\"password\":\"password\"," +
+                        "\"id\":\"user\"" +
+                        "}]" +
+                        "}," +
+                        "\"last_mod\":1553608454000," +
+                        "\"deleted\":false," +
+                        "\"feedid\":1," +
+                        "\"name\":\"CSIT_Test2\"" +
+                        ",\"business_description\":\"Default Feed\"" +
+                        ",\"publisher\":\"dradmin\"" +
+                        ",\"links\":{" +
+                        "\"subscribe\":\"https://dmaap-dr-prov/subscribe/1\"," +
+                        "\"log\":\"https://dmaap-dr-prov/feedlog/1\"," +
+                        "\"publish\":\"https://dmaap-dr-prov/publish/1\"," +
+                        "\"self\":\"https://dmaap-dr-prov/feed/1\"" +
+                        "}," +
+                        "\"created_date\":1553608454000" +
+                        "}]," +
+                        "\"groups\":[]," +
+                        "\"parameters\":{" +
+                        "\"NODES\":[\"dmaap-dr-node\"]," +
+                        "\"PROV_DOMAIN\":\"\"" +
+                        "}," +
+                        "\"egress\":{" +
+                        "\"1\":1" +
+                        "}" +
+                        "}";
         Reader r = new InputStreamReader(new ByteArrayInputStream(InternalProvData.getBytes(StandardCharsets.UTF_8)));
         ProvData pd = new ProvData(r);
 
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/RedirManagerTest.java
new file mode 100644 (file)
index 0000000..2c8a0e5
--- /dev/null
@@ -0,0 +1,73 @@
+/*-
+ * ============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;
+
+import static org.junit.Assert.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.Timer;
+import org.hamcrest.core.Is;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class RedirManagerTest {
+
+    private RedirManager redirManager;
+    private String redirFilePath = System.getProperty("user.dir") + "/src/test/resources/redir_file";
+
+    @Before
+    public void setUp() {
+        Timer timer = new Timer("Node Configuration Timer", true);
+        redirManager = new RedirManager(redirFilePath, 10000L, timer);
+    }
+
+    @Test
+    public void Given_Lookup_On_Valid_Redirect_Returns_Target_URL() {
+        assertThat(redirManager.lookup("1", "http://destination:8443/path/to"), Is.is("http://redirect:8443/path/to"));
+    }
+
+    @Test
+    public void Given_IsRedirected_Called_On_Valid_Sub_Id_Then_Returns_True() {
+        assertThat(redirManager.isRedirected("1"), Is.is(true));
+    }
+
+    @Test
+    public void Given_Redirect_Called_On_Valid_Redirect_New_Redirect_Added() throws IOException {
+        long origFileLenght = new File(redirFilePath).length();
+        redirManager.redirect("3", "http://destination3:8443/path/to", "http://redirect3:8443/path/to");
+        assertThat(redirManager.lookup("3", "http://destination3:8443/path/to"), Is.is("http://redirect3:8443/path/to"));
+        new RandomAccessFile(redirFilePath, "rw").setLength(origFileLenght);
+    }
+
+    @Test
+    public void Given_Lookup_On_Invalid_Redirect_Returns_Primary_Target_URL_And_Is_Forgotten() throws IOException {
+        assertThat(redirManager.lookup("2", "http://invalid:8443/path/to"), Is.is("http://invalid:8443/path/to"));
+        Files.write(Paths.get(redirFilePath), "2 http://destination2:8443/path/to http://redirect2:8443/path/to".getBytes(), StandardOpenOption.APPEND);
+    }
+}
index e60f576..d379306 100644 (file)
@@ -22,6 +22,9 @@
  ******************************************************************************/
 package org.onap.dmaap.datarouter.node;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
@@ -31,9 +34,6 @@ 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)
diff --git a/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java b/datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java
new file mode 100644 (file)
index 0000000..311165c
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ============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;
+
+import org.junit.Test;
+
+public class TaskListTest {
+
+    @Test
+    public void Given_New_Task_List_Verify_Add_And_Run() {
+        TaskList taskList = new TaskList();
+        taskList.startRun();
+        taskList.addTask(() -> {
+        });
+        taskList.next();
+        taskList.removeTask(() -> {
+        });
+    }
+
+    @Test
+    public void Given_Empty_Task_List_Verify_Next() {
+        TaskList taskList = new TaskList();
+        taskList.startRun();
+        taskList.next();
+    }
+}
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node
new file mode 100644 (file)
index 0000000..1677aaf
--- /dev/null
@@ -0,0 +1 @@
+Hello World!!!!!!
\ No newline at end of file
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.M
new file mode 100644 (file)
index 0000000..b317b67
--- /dev/null
@@ -0,0 +1,8 @@
+PUT    A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-RequestID    A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-InvocationID ea407097-2de5-452e-9f21-569e6d867deb
+X-TransactionID        A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-ONAP-RequestID       A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-DMAAP-DR-META        {"productName":"RnNode","vendorName":"Ericsson","lastEpochMicrosec":"1561550151179","sourceName":"","startEpochMicrosec":"1561550151179","timeZoneOffset":"UTC+00:00","location":"ftps://onap:pano@10.209.63.42:2036/A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz","compression":"gzip","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10"}
+Content-Type   application/octet-stream
+X-DMAAP-DR-RECEIVED    2019-06-26T11:56:38.216Z;from=10.42.54.206;by=10.42.70.78
\ No newline at end of file
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz
new file mode 100644 (file)
index 0000000..d38bae1
Binary files /dev/null and b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz differ
diff --git a/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M b/datarouter-node/src/test/resources/delivery_files/123456789.test-dr-node.gz.M
new file mode 100644 (file)
index 0000000..b317b67
--- /dev/null
@@ -0,0 +1,8 @@
+PUT    A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-RequestID    A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-InvocationID ea407097-2de5-452e-9f21-569e6d867deb
+X-TransactionID        A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-ONAP-RequestID       A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz
+X-DMAAP-DR-META        {"productName":"RnNode","vendorName":"Ericsson","lastEpochMicrosec":"1561550151179","sourceName":"","startEpochMicrosec":"1561550151179","timeZoneOffset":"UTC+00:00","location":"ftps://onap:pano@10.209.63.42:2036/A20190626.1106+0000-1120+0000_excl-eeiwbue-perf-large3-pnf-sim-lw-17.xml.gz","compression":"gzip","fileFormatType":"org.3GPP.32.435#measCollec","fileFormatVersion":"V10"}
+Content-Type   application/octet-stream
+X-DMAAP-DR-RECEIVED    2019-06-26T11:56:38.216Z;from=10.42.54.206;by=10.42.70.78
\ No newline at end of file
diff --git a/datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks b/datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks
new file mode 100644 (file)
index 0000000..2320dc9
Binary files /dev/null and b/datarouter-node/src/test/resources/org.onap.dmaap-dr-test-cert.jks differ
diff --git a/datarouter-node/src/test/resources/redir_file b/datarouter-node/src/test/resources/redir_file
new file mode 100644 (file)
index 0000000..0c72ebe
--- /dev/null
@@ -0,0 +1,2 @@
+1 http://destination:8443/path/to http://redirect:8443/path/to
+2 http://destination2:8443/path/to http://redirect2:8443/path/to
\ No newline at end of file
index 56a4b13..cbcfc71 100755 (executable)
@@ -36,7 +36,8 @@
         <sitePath>/content/sites/site/${project.groupId}/${project.artifactId}/${project.version}</sitePath>
         <docker.location>${basedir}/target/${project.artifactId}</docker.location>
         <datarouter.prov.image.name>${docker.image.root}${project.artifactId}</datarouter.prov.image.name>
-        <sonar.exclusions>**/src/main/java/org/onap/dmaap/datarouter/reports/**</sonar.exclusions>
+        <sonar.exclusions>**/src/main/java/org/onap/dmaap/datarouter/reports/**,
+            **/src/main/java/org/onap/dmaap/authz/impl/AuthRespSupplementImpl.java</sonar.exclusions>
         <sonar.language>java</sonar.language>
         <sonar.skip>false</sonar.skip>
     </properties>
                 <groupId>org.codehaus.mojo</groupId>
                 <artifactId>cobertura-maven-plugin</artifactId>
             </plugin>
-            <plugin>
-                <groupId>org.sonatype.plugins</groupId>
-                <artifactId>nexus-staging-maven-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
                 <configuration>
                     <excludes>
                         <exclude>**/src/main/java/org/onap/dmaap/datarouter/reports/**</exclude>
+                        <exclude>**/src/main/java/org/onap/dmaap/authz/impl/AuthRespSupplementImpl.java</exclude>
                     </excludes>
                 </configuration>
             </plugin>
index f327833..c7d7199 100644 (file)
@@ -44,21 +44,23 @@ public class AuthRespImpl implements AuthorizationResponse {
     /** Constructor.  This version will not be used in Data Router R1 since we will not have advice and obligations.\r
      *\r
      * @param authorized flag indicating whether the response carried a permit response (<code>true</code>)\r
-     * or something else (<code>false</code>).\r
+     *                   or something else (<code>false</code>).\r
      * @param advice list of advice elements returned in the response.\r
      * @param obligations list of obligation elements returned in the response.\r
      */\r
-    public AuthRespImpl(boolean authorized, List<AuthorizationResponseSupplement> advice, List<AuthorizationResponseSupplement> obligations) {\r
+    private AuthRespImpl(boolean authorized, List<AuthorizationResponseSupplement> advice,\r
+            List<AuthorizationResponseSupplement> obligations) {\r
         this.authorized = authorized;\r
-        this.advice = (advice == null ? null : new ArrayList<AuthorizationResponseSupplement> (advice));\r
-        this.obligations = (obligations == null ? null : new ArrayList<AuthorizationResponseSupplement> (obligations));\r
+        this.advice = (advice == null ? null : new ArrayList<>(advice));\r
+        this.obligations = (obligations == null ? null : new ArrayList<>(obligations));\r
     }\r
 \r
     /** Constructor.  Simple version for authorization responses that have no advice and no obligations.\r
      *\r
-     * @param authorized flag indicating whether the response carried a permit (<code>true</code>) or something else (<code>false</code>).\r
+     * @param authorized flag indicating whether the response carried a permit (<code>true</code>)\r
+     *                   or something else (<code>false</code>).\r
      */\r
-    public AuthRespImpl(boolean authorized) {\r
+    AuthRespImpl(boolean authorized) {\r
         this(authorized, null, null);\r
     }\r
 \r
@@ -69,25 +71,25 @@ public class AuthRespImpl implements AuthorizationResponse {
      */\r
     @Override\r
     public boolean isAuthorized() {\r
-            return authorized;\r
+        return authorized;\r
     }\r
 \r
     /**\r
      * Returns any advice elements that were included in the authorization response.\r
      *\r
-     * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface, with each object representing an\r
-     * advice element from the authorization response.\r
+     * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface,\r
+     * with each object representing an advice element from the authorization response.\r
      */\r
     @Override\r
     public List<AuthorizationResponseSupplement> getAdvice() {\r
-            return advice;\r
+        return advice;\r
     }\r
 \r
     /**\r
      * Returns any obligation elements that were included in the authorization response.\r
      *\r
-     * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface, with each object representing an\r
-     * obligation element from the authorization response.\r
+     * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface,\r
+     * with each object representing an obligation element from the authorization response.\r
      */\r
     @Override\r
     public List<AuthorizationResponseSupplement> getObligations() {\r
index d995270..b61c00e 100644 (file)
@@ -36,17 +36,17 @@ import org.onap.dmaap.datarouter.authz.AuthorizationResponseSupplement;
  */\r
 public class AuthRespSupplementImpl implements AuthorizationResponseSupplement {\r
 \r
-    private String id = null;\r
-    private Map<String, String> attributes = null;\r
+    private String id;\r
+    private Map<String, String> attributes;\r
 \r
     /** Constructor, available within the package.\r
      *\r
      * @param id  The identifier for the advice or obligation element\r
      * @param attributes The attributes (name-value pairs) for the advice or obligation element.\r
      */\r
-    AuthRespSupplementImpl (String id, Map<String, String> attributes) {\r
+    AuthRespSupplementImpl(String id, Map<String, String> attributes) {\r
         this.id = id;\r
-        this.attributes = new HashMap<String,String>(attributes);\r
+        this.attributes = new HashMap<>(attributes);\r
     }\r
 \r
     /** Return the identifier for the supplementary information element.\r
index 0357fa7..c248468 100644 (file)
@@ -30,7 +30,6 @@ import java.util.regex.Pattern;
 /** Internal representation of an authorization resource (the entity to which access is being requested).  Consists\r
  * of a type and an identifier.   The constructor takes the request URI from an HTTP request and checks it against\r
  * patterns for the the different resource types.  In DR R1, there are four resource types:\r
- * <ul>\r
  * <li>the feeds collection resource, the target of POST requests to create a new feed and GET requests to list\r
  * the existing feeds.  This is the root resource for the DR provisioning system, and it has no explicit id.\r
  * </li>\r
@@ -53,10 +52,10 @@ public class AuthzResource {
     private String id = "";\r
 \r
     /* Construct an AuthzResource by matching a request URI against the various patterns */\r
-    public AuthzResource(String rURI) {\r
-        if (rURI != null) {\r
+    AuthzResource(String requestUri) {\r
+        if (requestUri != null) {\r
             for (ResourceType t : ResourceType.values()) {\r
-                Matcher m = t.getPattern().matcher(rURI);\r
+                Matcher m = t.getPattern().matcher(requestUri);\r
                 if (m.find(0)) {\r
                     this.type = t;\r
                     if (m.group("id") != null) {\r
@@ -83,13 +82,13 @@ public class AuthzResource {
      */\r
     public enum ResourceType {\r
         FEEDS_COLLECTION("((://[^/]+/)|(^/))(?<id>)$"),\r
-        SUBS_COLLECTION ("((://[^/]+/)|(^/{0,1}))subscribe/(?<id>[^/]+)$"),\r
+        SUBS_COLLECTION("((://[^/]+/)|(^/{0,1}))subscribe/(?<id>[^/]+)$"),\r
         FEED("((://[^/]+/)|(^/{0,1}))feed/(?<id>[^/]+)$"),\r
         SUB("((://[^/]+/)|(^/{0,1}))subs/(?<id>[^/]+)$");\r
 \r
         private Pattern uriPattern;\r
 \r
-        private ResourceType(String patternString) {\r
+        ResourceType(String patternString) {\r
             this.uriPattern = Pattern.compile(patternString);\r
         }\r
 \r
index 745e339..595b626 100644 (file)
 
 package org.onap.dmaap.datarouter.authz.impl;
 
-import java.util.Map;
-
-import javax.servlet.http.HttpServletRequest;
-
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
 import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
 import org.onap.dmaap.datarouter.authz.Authorizer;
 import org.onap.dmaap.datarouter.authz.impl.AuthzResource.ResourceType;
 
-/** Authorizer for the provisioning API for Data Router R1
+/** Authorizer for the provisioning API for Data Router R1.
  *
  * @author J. F. Lucas
  *
@@ -45,6 +43,7 @@ public class ProvAuthorizer implements Authorizer {
 
     private static final String SUBJECT_HEADER = "X-DMAAP-DR-ON-BEHALF-OF";  // HTTP header carrying requester identity
     private static final String SUBJECT_HEADER_GROUP = "X-DMAAP-DR-ON-BEHALF-OF-GROUP";  // HTTP header carrying requester identity  by group Rally : US708115
+
     /** Constructor. For the moment, do nothing special.  Make it a singleton?
      *
      */
@@ -63,7 +62,7 @@ public class ProvAuthorizer implements Authorizer {
      */
     @Override
     public AuthorizationResponse decide(HttpServletRequest request) {
-            return this.decide(request, null);
+        return this.decide(request, null);
     }
 
     /**
@@ -79,80 +78,66 @@ public class ProvAuthorizer implements Authorizer {
     @Override
     public AuthorizationResponse decide(HttpServletRequest request,
             Map<String, String> additionalAttrs) {
-        log.trace ("Entering decide()");
-
+        log.trace("Entering decide()");
         boolean decision = false;
-
         // Extract interesting parts of the HTTP request
         String method = request.getMethod();
         AuthzResource resource = new AuthzResource(request.getRequestURI());
-        String subject = (request.getHeader(SUBJECT_HEADER));         // identity of the requester
-        String subjectgroup = (request.getHeader(SUBJECT_HEADER_GROUP)); // identity of the requester by group Rally : US708115
-
-        log.trace("Method: " + method + " -- Type: " + resource.getType() + " -- Id: " + resource.getId() +
-                " -- Subject: " + subject);
+        String subject = (request.getHeader(SUBJECT_HEADER));
+        String subjectgroup = (request.getHeader(SUBJECT_HEADER_GROUP));
 
+        log.trace("Method: " + method + " -- Type: " + resource.getType() + " -- Id: " + resource.getId()
+                          + " -- Subject: " + subject);
         // Choose authorization method based on the resource type
         ResourceType resourceType = resource.getType();
         if (resourceType != null) {
-
             switch (resourceType) {
-
-            case FEEDS_COLLECTION:
-                decision = allowFeedsCollectionAccess(resource, method, subject, subjectgroup);
-                break;
-
-            case SUBS_COLLECTION:
-                decision = allowSubsCollectionAccess(resource, method, subject, subjectgroup);
-                break;
-
-            case FEED:
-                decision = allowFeedAccess(resource, method, subject, subjectgroup);
-                break;
-
-            case SUB:
-                decision = allowSubAccess(resource, method, subject, subjectgroup);
-                break;
-
-            default:
-                decision = false;
-                break;
+                case FEEDS_COLLECTION:
+                    decision = allowFeedsCollectionAccess(method);
+                    break;
+                case SUBS_COLLECTION:
+                    decision = allowSubsCollectionAccess(method);
+                    break;
+                case FEED:
+                    decision = allowFeedAccess(resource, method, subject, subjectgroup);
+                    break;
+                case SUB:
+                    decision = allowSubAccess(resource, method, subject, subjectgroup);
+                    break;
+                default:
+                    decision = false;
+                    break;
             }
         }
-        log.debug("Exit decide(): "  + method + "|" + resourceType + "|" + resource.getId() + "|" + subject + " ==> " + decision);
+        log.debug("Exit decide(): "  + method + "|" + resourceType + "|" + resource.getId() + "|"
+                          + subject + " ==> " + decision);
 
         return new AuthRespImpl(decision);
     }
 
-    private boolean allowFeedsCollectionAccess(AuthzResource resource,    String method, String subject, String subjectgroup) {
-
+    private boolean allowFeedsCollectionAccess(String method) {
         // Allow GET or POST unconditionally
         return method != null && ("GET".equalsIgnoreCase(method) || "POST".equalsIgnoreCase(method));
     }
 
-    private boolean allowSubsCollectionAccess(AuthzResource resource, String method, String subject, String subjectgroup) {
-
+    private boolean allowSubsCollectionAccess(String method) {
         // Allow GET or POST unconditionally
         return method != null && ("GET".equalsIgnoreCase(method) || "POST".equalsIgnoreCase(method));
     }
 
-    private boolean allowFeedAccess(AuthzResource resource, String method,    String subject, String subjectgroup) {
+    private boolean allowFeedAccess(AuthzResource resource, String method, String subject, String subjectgroup) {
         boolean decision = false;
-
         // Allow GET, PUT, or DELETE if requester (subject) is the owner (publisher) of the feed
-        if ( method != null && ("GET".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) ||
-                       "DELETE".equalsIgnoreCase(method))) {
+        if ( method != null && ("GET".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) || "DELETE".equalsIgnoreCase(method))) {
 
             String owner = provData.getFeedOwner(resource.getId());
             decision = (owner != null) && owner.equals(subject);
-
             //Verifying by group Rally : US708115
-            if(subjectgroup != null) {
-                String feedowner = provData.getGroupByFeedGroupId(subject, resource.getId());
-                decision = (feedowner != null) && feedowner.equals(subjectgroup);
+            if (subjectgroup != null) {
+                String feedOwner = provData.getGroupByFeedGroupId(subject, resource.getId());
+                decision = (feedOwner != null) && feedOwner.equals(subjectgroup);
             }
         }
-
         return decision;
     }
 
@@ -160,14 +145,13 @@ public class ProvAuthorizer implements Authorizer {
         boolean decision = false;
 
         // Allow GET, PUT, or DELETE if requester (subject) is the owner of the subscription (subscriber)
-        if (method != null && ("GET".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) ||
-                       "DELETE".equalsIgnoreCase(method) || "POST".equalsIgnoreCase(method))) {
+        if (method != null && ("GET".equalsIgnoreCase(method) || "PUT".equalsIgnoreCase(method) || "DELETE".equalsIgnoreCase(method) || "POST".equalsIgnoreCase(method))) {
 
             String owner = provData.getSubscriptionOwner(resource.getId());
             decision = (owner != null) && owner.equals(subject);
 
             //Verifying by group Rally : US708115
-            if(subjectgroup != null) {
+            if (subjectgroup != null) {
                 String feedowner = provData.getGroupBySubGroupId(subject, resource.getId());
                 decision = (feedowner != null) && feedowner.equals(subjectgroup);
             }
index deb78b1..c6b1cde 100755 (executable)
 
 package org.onap.dmaap.datarouter.provisioning;
 
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
 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 static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
 
-
-
-import java.io.IOException;
-import java.io.InputStream;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
 import java.security.cert.X509Certificate;
 import java.sql.Connection;
 import java.sql.SQLException;
-
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletException;
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
 import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.Nullable;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
@@ -55,21 +58,19 @@ import org.json.JSONTokener;
 import org.onap.dmaap.datarouter.authz.Authorizer;
 import org.onap.dmaap.datarouter.authz.impl.ProvAuthorizer;
 import org.onap.dmaap.datarouter.authz.impl.ProvDataProvider;
-import org.onap.dmaap.datarouter.provisioning.beans.*;
+import org.onap.dmaap.datarouter.provisioning.beans.Deleteable;
+import org.onap.dmaap.datarouter.provisioning.beans.Feed;
+import org.onap.dmaap.datarouter.provisioning.beans.Group;
+import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
+import org.onap.dmaap.datarouter.provisioning.beans.NodeClass;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
+import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
+import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
 import org.onap.dmaap.datarouter.provisioning.utils.DB;
 import org.onap.dmaap.datarouter.provisioning.utils.PasswordProcessor;
 import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
 import org.slf4j.MDC;
 
-import javax.mail.*;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import java.security.GeneralSecurityException;
-import java.util.*;
-import java.util.regex.Pattern;
-
 
 /**
  * This is the base class for all Servlets in the provisioning code. It provides standard constants and some common
@@ -94,10 +95,10 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     static final String CREATE_PERMISSION = "create";
     static final String EDIT_PERMISSION = "edit";
     static final String DELETE_PERMISSION = "delete";
-    static final String PUBLISH_PERMISSION = "publish";
-    static final String SUSPEND_PERMISSION = "suspend";
-    static final String RESTORE_PERMISSION = "restore";
-    static final String SUBSCRIBE_PERMISSION = "subscribe";
+    private static final String PUBLISH_PERMISSION = "publish";
+    private static final String SUSPEND_PERMISSION = "suspend";
+    private static final String RESTORE_PERMISSION = "restore";
+    private static final String SUBSCRIBE_PERMISSION = "subscribe";
     static final String APPROVE_SUB_PERMISSION = "approveSub";
 
     static final String FEED_BASECONTENT_TYPE = "application/vnd.dmaap-dr.feed";
@@ -113,7 +114,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     //Adding groups functionality, ...1610
     static final String GROUP_BASECONTENT_TYPE = "application/vnd.dmaap-dr.group";
     static final String GROUP_CONTENT_TYPE = "application/vnd.dmaap-dr.group; version=2.0";
-    public static final String GROUPFULL_CONTENT_TYPE = "application/vnd.dmaap-dr.group-full; version=2.0";
+    static final String GROUPFULL_CONTENT_TYPE = "application/vnd.dmaap-dr.group-full; version=2.0";
     public static final String GROUPLIST_CONTENT_TYPE = "application/vnd.dmaap-dr.fegrouped-list; version=1.0";
 
 
@@ -130,101 +131,123 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     private static final int DEFAULT_POKETIMER2 = 30;
     private static final String DEFAULT_DOMAIN = "onap";
     private static final String DEFAULT_PROVSRVR_NAME = "dmaap-dr-prov";
-    private static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610
+
+    //Common Errors
+    static final String MISSING_ON_BEHALF = "Missing X-DMAAP-DR-ON-BEHALF-OF header.";
+    static final String MISSING_FEED = "Missing or bad feed number.";
+    static final String POLICY_ENGINE = "Policy Engine disallows access.";
+    static final String UNAUTHORIZED = "Unauthorized.";
+    static final String BAD_SUB = "Missing or bad subscription number.";
+    static final String BAD_JSON = "Badly formed JSON";
+    static final String BAD_URL = "Bad URL.";
+
+    public static final String API = "/api/";
+    static final String LOGS = "/logs/";
+    static final String TEXT_CT = "text/plain";
+    static final String INGRESS = "/ingress/";
+    static final String EGRESS = "/egress/";
+    static final String NETWORK = "/network/";
+    static final String GROUPID = "groupid";
+    public static final String FEEDID = "feedid";
+    static final String FEEDIDS = "feedids";
+    static final String SUBID = "subid";
+    static final String EVENT_TYPE = "eventType";
+    static final String OUTPUT_TYPE = "output_type";
+    static final String START_TIME = "start_time";
+    static final String END_TIME = "end_time";
+    static final String REASON_SQL = "reasonSQL";
+
 
     /**
-     * A boolean to trigger one time "provisioning changed" event on startup
+     * A boolean to trigger one time "provisioning changed" event on startup.
      */
     private static boolean startmsgFlag = true;
     /**
-     * This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE)
+     * This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE).
      */
     private static boolean requireSecure = true;
     /**
-     * This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT)
+     * This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT).
      */
     private static boolean requireCert = true;
     /**
-     * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES)
+     * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES).
      */
     private static Set<String> authorizedAddressesAndNetworks = new HashSet<>();
     /**
-     * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS)
+     * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS).
      */
     private static Set<String> authorizedNames = new HashSet<>();
     /**
-     * The FQDN of the initially "active" provisioning server in this Data Router ecosystem
+     * The FQDN of the initially "active" provisioning server in this Data Router ecosystem.
      */
     private static String initialActivePod;
     /**
-     * The FQDN of the initially "standby" provisioning server in this Data Router ecosystem
+     * The FQDN of the initially "standby" provisioning server in this Data Router ecosystem.
      */
     private static String initialStandbyPod;
     /**
-     * The FQDN of this provisioning server in this Data Router ecosystem
+     * The FQDN of this provisioning server in this Data Router ecosystem.
      */
     private static String thisPod;
     /**
-     * "Timer 1" - used to determine when to notify nodes of provisioning changes
+     * "Timer 1" - used to determine when to notify nodes of provisioning changes.
      */
     private static long pokeTimer1;
     /**
-     * "Timer 2" - used to determine when to notify nodes of provisioning changes
+     * "Timer 2" - used to determine when to notify nodes of provisioning changes.
      */
     private static long pokeTimer2;
     /**
-     * Array of nodes names and/or FQDNs
+     * Array of nodes names and/or FQDNs.
      */
     private static String[] nodes = new String[0];
     /**
-     * [DATARTR-27] Poke all the DR nodes : Array of nodes names and/or FQDNs
+     * [DATARTR-27] Poke all the DR nodes : Array of nodes names and/or FQDNs.
      */
     private static String[] drnodes = new String[0];
     /**
-     * Array of node IP addresses
+     * Array of node IP addresses.
      */
     private static InetAddress[] nodeAddresses = new InetAddress[0];
     /**
-     * Array of POD IP addresses
+     * Array of POD IP addresses.
      */
     private static InetAddress[] podAddresses = new InetAddress[0];
     /**
-     * The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT)
+     * The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT).
      */
     static int maxFeeds = 0;
     /**
-     * The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT)
+     * The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT).
      */
     static int maxSubs = 0;
     /**
-     * The current number of feeds in the system
+     * The current number of feeds in the system.
      */
     static int activeFeeds = 0;
     /**
-     * The current number of subscriptions in the system
+     * The current number of subscriptions in the system.
      */
     static int activeSubs = 0;
 
     /**
-     * The domain used to generate a FQDN from the "bare" node names
+     * The domain used to generate a FQDN from the "bare" node names.
      */
     private static String provDomain = "web.att.com";
 
     /**
-     * The standard FQDN of the provisioning server in this Data Router ecosystem
+     * The standard FQDN of the provisioning server in this Data Router ecosystem.
      */
     private static String provName = "feeds-drtr.web.att.com";
 
     /**
-     * The standard FQDN of the ACTIVE provisioning server in this Data Router ecosystem
+     * The standard FQDN of the ACTIVE_POD provisioning server in this Data Router ecosystem.
      */
     private static String activeProvName = "feeds-drtr.web.att.com";
 
-    //Adding new param for static Routing - Rally:US664862-1610
-    private static String staticRoutingNodes = STATIC_ROUTING_NODES;
-
     /**
-     * This logger is used to log provisioning events
+     * This logger is used to log provisioning events.
      */
     protected static EELFLogger eventlogger;
     /**
@@ -232,21 +255,17 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
      */
     protected static EELFLogger intlogger;
     /**
-     * Authorizer - interface to the Policy Engine
+     * Authorizer - interface to the Policy Engine.
      */
     protected static Authorizer authz;
     /**
-     * The Synchronizer used to sync active DB to standby one
+     * The Synchronizer used to sync active DB to standby one.
      */
     private static SynchronizerTask synctask = null;
 
     //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
     private InetAddress thishost;
     private InetAddress loopback;
-    private static Boolean mailSendFlag = false;
-
-    private static final String MAILCONFIG_FILE = "mail.properties";
-    private static Properties mailprops;
 
     //DMAAP-597 (Tech Dept) REST request source IP auth relaxation to accommodate OOM kubernetes deploy
     private static String isAddressAuthEnabled = (new DB()).getProperties()
@@ -259,10 +278,10 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
      * Initialize data common to all the provisioning server servlets.
      */
     protected BaseServlet() {
-        if(eventlogger == null) {
-            this.eventlogger = EELFManager.getInstance().getLogger("EventLog");
+        if (eventlogger == null) {
+            eventlogger = EELFManager.getInstance().getLogger("EventLog");
         }
-        if(intlogger == null) {
+        if (intlogger == null) {
             this.intlogger = EELFManager.getInstance().getLogger("InternalLog");
         }
         if (authz == null) {
@@ -285,9 +304,8 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         try {
             thishost = InetAddress.getLocalHost();
             loopback = InetAddress.getLoopbackAddress();
-            //checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
         } catch (UnknownHostException e) {
-            // ignore
+            intlogger.info("BaseServlet.init: " + e.getMessage(), e);
         }
     }
 
@@ -304,7 +322,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     }
 
     /**
-     * Read the request's input stream and return a JSONObject from it
+     * Read the request's input stream and return a JSONObject from it.
      *
      * @param req the HTTP request
      * @return the JSONObject, or null if the stream cannot be parsed
@@ -323,35 +341,40 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     }
 
     /**
-     * This method encrypt/decrypt the key in the JSON passed by user request inside the authorisation header object in request before logging the JSON.
+     * This method encrypt/decrypt the key in the JSON passed by user request inside the authorisation
+     * header object in request before logging the JSON.
      *
-     * @param jo-      the JSON passed in http request.
-     * @param maskKey- the key to be masked in the JSON passed.
-     * @param action-  whether to mask the key or unmask it in a JSON passed.
+     * @param jo      the JSON passed in http request.
+     * @param maskKey the key to be masked in the JSON passed.
+     * @param action  whether to mask the key or unmask it in a JSON passed.
      * @return the JSONObject, or null if the stream cannot be parsed.
      */
-    public static JSONObject maskJSON(JSONObject jo, String maskKey, boolean action) {
+    static JSONObject maskJSON(JSONObject jo, String maskKey, boolean action) {
         if (!jo.isNull("authorization")) {
-            JSONObject j2 = jo.getJSONObject("authorization");
-            JSONArray ja = j2.getJSONArray("endpoint_ids");
-            for (int i = 0; i < ja.length(); i++) {
-                if ((!ja.getJSONObject(i).isNull(maskKey))) {
-                    String password = ja.getJSONObject(i).get(maskKey).toString();
-                    try {
-                        if (action) {
-                            ja.getJSONObject(i).put(maskKey, PasswordProcessor.encrypt(password));
-                        } else {
-                            ja.getJSONObject(i).put(maskKey, PasswordProcessor.decrypt(password));
-                        }
-                    } catch (JSONException | GeneralSecurityException e) {
-                        intlogger.info("Error reading JSON while masking: " + e);
-                    }
+            JSONArray endpointIds = jo.getJSONObject("authorization").getJSONArray("endpoint_ids");
+            for (int index = 0; index < endpointIds.length(); index++) {
+                if ((!endpointIds.getJSONObject(index).isNull(maskKey))) {
+                    String password = endpointIds.getJSONObject(index).get(maskKey).toString();
+                    processPassword(maskKey, action, endpointIds, index, password);
                 }
             }
         }
         return jo;
     }
 
+    private static void processPassword(String maskKey, boolean action, JSONArray endpointIds, int index,
+            String password) {
+        try {
+            if (action) {
+                endpointIds.getJSONObject(index).put(maskKey, PasswordProcessor.encrypt(password));
+            } else {
+                endpointIds.getJSONObject(index).put(maskKey, PasswordProcessor.decrypt(password));
+            }
+        } catch (JSONException | GeneralSecurityException e) {
+            intlogger.info("Error reading JSON while masking: " + e);
+        }
+    }
+
     /**
      * Check if the remote host is authorized to perform provisioning. Is the request secure? Is it coming from an
      * authorized IP address or network (configured via PROV_AUTH_ADDRESSES)? Does it have a valid client certificate
@@ -368,20 +391,9 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         if (requireSecure && !request.isSecure()) {
             return "Request must be made over an HTTPS connection.";
         }
-        // Is remote IP authorized?
-        String remote = request.getRemoteAddr();
-        try {
-            boolean found = false;
-            InetAddress ip = InetAddress.getByName(remote);
-            for (String addrnet : authorizedAddressesAndNetworks) {
-                found |= addressMatchesNetwork(ip, addrnet);
-            }
-            if (!found) {
-                return "Unauthorized address: " + remote;
-            }
-        } catch (UnknownHostException e) {
-            intlogger.error("PROV0051 BaseServlet.isAuthorizedForProvisioning: ", e.getMessage());
-            return "Unauthorized address: " + remote;
+        String remoteHostCheck = checkRemoteHostAuthorization(request);
+        if (remoteHostCheck != null) {
+            return remoteHostCheck;
         }
         // Does remote have a valid certificate?
         if (requireCert) {
@@ -400,6 +412,26 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         return null;
     }
 
+    @Nullable
+    private String checkRemoteHostAuthorization(HttpServletRequest request) {
+        // Is remote IP authorized?
+        String remote = request.getRemoteAddr();
+        try {
+            boolean found = false;
+            InetAddress ip = InetAddress.getByName(remote);
+            for (String addrnet : authorizedAddressesAndNetworks) {
+                found |= addressMatchesNetwork(ip, addrnet);
+            }
+            if (!found) {
+                return "Unauthorized address: " + remote;
+            }
+        } catch (UnknownHostException e) {
+            intlogger.error("PROV0051 BaseServlet.isAuthorizedForProvisioning: " + e.getMessage(), e);
+            return "Unauthorized address: " + remote;
+        }
+        return null;
+    }
+
     /**
      * Check if the remote IP address is authorized to see the /internal URL tree.
      *
@@ -413,23 +445,23 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             }
             InetAddress ip = InetAddress.getByName(request.getRemoteAddr());
             for (InetAddress node : getNodeAddresses()) {
-                if (node != null && ip.equals(node)) {
+                if (ip.equals(node)) {
                     return true;
                 }
             }
             for (InetAddress pod : getPodAddresses()) {
-                if (pod != null && ip.equals(pod)) {
+                if (ip.equals(pod)) {
                     return true;
                 }
             }
-            if (thishost != null && ip.equals(thishost)) {
+            if (ip.equals(thishost)) {
                 return true;
             }
-            if (loopback != null && ip.equals(loopback)) {
+            if (ip.equals(loopback)) {
                 return true;
             }
         } catch (UnknownHostException e) {
-            intlogger.error("PROV0052 BaseServlet.isAuthorizedForInternal: ", e.getMessage());
+            intlogger.error("PROV0052 BaseServlet.isAuthorizedForInternal: " + e.getMessage(), e);
         }
         return false;
     }
@@ -443,7 +475,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
      */
     private static boolean addressMatchesNetwork(InetAddress ip, String s) {
         int mlen = -1;
-        int n = s.indexOf("/");
+        int n = s.indexOf('/');
         if (n >= 0) {
             mlen = Integer.parseInt(s.substring(n + 1));
             s = s.substring(0, n);
@@ -473,7 +505,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                 }
             }
         } catch (UnknownHostException e) {
-            intlogger.error("PROV0053 BaseServlet.addressMatchesNetwork: ", e.getMessage());
+            intlogger.error("PROV0053 BaseServlet.addressMatchesNetwork: " + e.getMessage(), e);
             return false;
         }
         return true;
@@ -503,23 +535,23 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         maxSubs = getInt(map, Parameters.PROV_MAXSUB_COUNT, DEFAULT_MAX_SUBS);
         pokeTimer1 = getInt(map, Parameters.PROV_POKETIMER1, DEFAULT_POKETIMER1);
         pokeTimer2 = getInt(map, Parameters.PROV_POKETIMER2, DEFAULT_POKETIMER2);
-        /**
-         * The domain used to generate a FQDN from the "bare" node names
-         */
+
+        // The domain used to generate a FQDN from the "bare" node names
         provDomain = getString(map, Parameters.PROV_DOMAIN, DEFAULT_DOMAIN);
         provName = getString(map, Parameters.PROV_NAME, DEFAULT_PROVSRVR_NAME);
         activeProvName = getString(map, Parameters.PROV_ACTIVE_NAME, provName);
         initialActivePod = getString(map, Parameters.ACTIVE_POD, "");
         initialStandbyPod = getString(map, Parameters.STANDBY_POD, "");
-        staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
-                ""); //Adding new param for static Routing - Rally:US664862-1610
+
+        //Adding new param for static Routing - Rally:US664862-1610
+        String staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES, "");
         activeFeeds = Feed.countActiveFeeds();
         activeSubs = Subscription.countActiveSubscriptions();
         try {
             thisPod = InetAddress.getLocalHost().getHostName();
         } catch (UnknownHostException e) {
             thisPod = "";
-            intlogger.warn("PROV0014 Cannot determine the name of this provisioning server.");
+            intlogger.warn("PROV0014 Cannot determine the name of this provisioning server.", e);
         }
 
         // Normalize the nodes, and fill in nodeAddresses
@@ -530,7 +562,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                 intlogger.debug("PROV0003 DNS lookup: " + nodes[i] + " => " + na[i].toString());
             } catch (UnknownHostException e) {
                 na[i] = null;
-                intlogger.warn("PROV0004 Cannot lookup " + nodes[i] + ": " + e.getMessage());
+                intlogger.warn("PROV0004 Cannot lookup " + nodes[i] + ": " + e.getMessage(), e);
             }
         }
 
@@ -558,7 +590,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                 intlogger.debug("PROV0003 DNS lookup: " + pods[i] + " => " + na[i].toString());
             } catch (UnknownHostException e) {
                 na[i] = null;
-                intlogger.warn("PROV0004 Cannot lookup " + pods[i] + ": " + e.getMessage());
+                intlogger.warn("PROV0004 Cannot lookup " + pods[i] + ": " + e.getMessage(), e);
             }
         }
         podAddresses = na;
@@ -572,96 +604,11 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         }
     }
 
-
-    /**
-     * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Load mail properties.
-     *
-     * @author vs215k
-     **/
-    private void loadMailProperties() {
-        if (mailprops == null) {
-            mailprops = new Properties();
-            try (InputStream inStream = getClass().getClassLoader().getResourceAsStream(MAILCONFIG_FILE)) {
-                mailprops.load(inStream);
-            } catch (IOException e) {
-                intlogger.error("PROV9003 Opening properties: " + e.getMessage());
-                System.exit(1);
-            }
-        }
-    }
-
-    /**
-     * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Check if HTTPS Relexaction is enabled
-     *
-     * @author vs215k
-     **/
-    private void checkHttpsRelaxation() {
-        if (!mailSendFlag) {
-            Properties p = (new DB()).getProperties();
-            intlogger.info("HTTPS relaxation: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
-
-            if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) {
-                try {
-                    notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
-                } catch (Exception e) {
-                    intlogger.warn("Exception: " + e.getMessage());
-                }
-            }
-            mailSendFlag = true;
-        }
-    }
-
-    /**
-     * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
-     *
-     * @param email - list of email ids to notify if HTTP relexcation is enabled.
-     * @author vs215k
-     **/
-    private void notifyPSTeam(String email) throws Exception {
-        loadMailProperties(); //Load HTTPS Relex mail properties.
-        String[] emails = email.split(Pattern.quote("|"));
-
-        Properties mailproperties = new Properties();
-        mailproperties.put("mail.smtp.host", mailprops.get("com.att.dmaap.datarouter.mail.server"));
-        mailproperties.put("mail.transport.protocol", mailprops.get("com.att.dmaap.datarouter.mail.protocol"));
-
-        Session session = Session.getDefaultInstance(mailproperties, null);
-        Multipart mp = new MimeMultipart();
-        MimeBodyPart htmlPart = new MimeBodyPart();
-
-        try {
-
-            Message msg = new MimeMessage(session);
-            msg.setFrom(new InternetAddress(mailprops.get("com.att.dmaap.datarouter.mail.from").toString()));
-
-            InternetAddress[] addressTo = new InternetAddress[emails.length];
-            for (int x = 0; x < emails.length; x++) {
-                addressTo[x] = new InternetAddress(emails[x]);
-            }
-
-            msg.addRecipients(Message.RecipientType.TO, addressTo);
-            msg.setSubject(mailprops.get("com.att.dmaap.datarouter.mail.subject").toString());
-            htmlPart.setContent(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
-                    .replace("[SERVER]", InetAddress.getLocalHost().getHostName()), "text/html");
-            mp.addBodyPart(htmlPart);
-            msg.setContent(mp);
-
-            System.out.println(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
-                    .replace("[SERVER]", InetAddress.getLocalHost().getHostName()));
-
-            Transport.send(msg);
-            intlogger.info("HTTPS relaxation mail is sent to - : " + email);
-
-        } catch (MessagingException e) {
-            intlogger.error("Invalid email address, unable to send https relaxation mail to - : " + email);
-        }
-    }
-
     public static String getProvName() {
         return provName;
     }
 
-    public static String getActiveProvName() {
+    static String getActiveProvName() {
         return activeProvName;
     }
 
@@ -674,22 +621,12 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
         return nodes;
     }
 
-    /**
-     * [DATARTR-27] Poke all the DR nodes
-     * Get an array of all node names in the DR network.
-     *
-     * @return an array of Strings
-     */
-    public static String[] getDRNodes() {
-        return drnodes;
-    }
-
     /**
      * Get an array of all node InetAddresses in the DR network.
      *
      * @return an array of InetAddresses
      */
-    public static InetAddress[] getNodeAddresses() {
+    private static InetAddress[] getNodeAddresses() {
         return nodeAddresses;
     }
 
@@ -712,7 +649,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     }
 
     /**
-     * Gets the FQDN of the initially ACTIVE provisioning server (POD). Note: this used to be called isActivePOD(),
+     * Gets the FQDN of the initially ACTIVE_POD provisioning server (POD). Note: this used to be called isActivePOD(),
      * however, that is a misnomer, as the active status could shift to the standby POD without these parameters
      * changing.  Hence, the function names have been changed to more accurately reflect their purpose.
      *
@@ -723,7 +660,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     }
 
     /**
-     * Gets the FQDN of the initially STANDBY provisioning server (POD). Note: this used to be called isStandbyPOD(),
+     * Gets the FQDN of the initially STANDBY_POD provisioning server (POD). Note: this used to be called isStandbyPOD(),
      * however, that is a misnomer, as the standby status could shift to the active POD without these parameters
      * changing.  Hence, the function names have been changed to more accurately reflect their purpose.
      *
@@ -748,7 +685,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             rv = bean.doInsert(conn);
         } catch (SQLException e) {
             rv = false;
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+            intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
         } finally {
             if (conn != null) {
                 db.release(conn);
@@ -772,7 +709,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             rv = bean.doUpdate(conn);
         } catch (SQLException e) {
             rv = false;
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
         } finally {
             if (conn != null) {
                 db.release(conn);
@@ -796,7 +733,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             rv = bean.doDelete(conn);
         } catch (SQLException e) {
             rv = false;
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+            intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
         } finally {
             if (conn != null) {
                 db.release(conn);
@@ -807,7 +744,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
 
     private static boolean getBoolean(Map<String, String> map, String name) {
         String s = map.get(name);
-        return (s != null) && s.equalsIgnoreCase("true");
+        return "true".equalsIgnoreCase(s);
     }
 
     private static String getString(Map<String, String> map, String name, String dflt) {
@@ -847,7 +784,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
      */
     public class ContentHeader {
 
-        private String type = "";
+        private String type;
         private Map<String, String> map = new HashMap<>();
 
         ContentHeader() {
@@ -863,7 +800,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             return type;
         }
 
-        public String getAttribute(String key) {
+        String getAttribute(String key) {
             String s = map.get(key);
             if (s == null) {
                 s = "";
@@ -959,7 +896,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                     return true;
                 }
             } catch (JSONException e) {
-                intlogger.error("JSONException: " + e.getMessage());
+                intlogger.error("JSONException: " + e.getMessage(), e);
             }
         }
         return false;
@@ -969,19 +906,17 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     /*
      * @Method - getGroupByFeedGroupId- Rally:US708115
      * @Params - User to check in group and feedid which is assigned the group.
-     * @return - string value grupid/null
+     * @return - string value groupid/null
      */
     @Override
     public String getGroupByFeedGroupId(String owner, String feedId) {
         try {
-            int n = Integer.parseInt(feedId);
-            Feed f = Feed.getFeedById(n);
+            Feed f = Feed.getFeedById(Integer.parseInt(feedId));
             if (f != null) {
                 int groupid = f.getGroupid();
                 if (groupid > 0) {
                     Group group = Group.getGroupById(groupid);
-                    assert group != null;
-                    if (isUserMemberOfGroup(group, owner)) {
+                    if (group != null && isUserMemberOfGroup(group, owner)) {
                         return group.getAuthid();
                     }
                 }
@@ -995,7 +930,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
     /*
      * @Method - getGroupBySubGroupId - Rally:US708115
      * @Params - User to check in group and subid which is assigned the group.
-     * @return - string value grupid/null
+     * @return - string value groupid/null
      */
     @Override
     public String getGroupBySubGroupId(String owner, String subId) {
@@ -1006,8 +941,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                 int groupid = s.getGroupid();
                 if (groupid > 0) {
                     Group group = Group.getGroupById(groupid);
-                    assert group != null;
-                    if (isUserMemberOfGroup(group, owner)) {
+                    if (group != null && isUserMemberOfGroup(group, owner)) {
                         return group.getAuthid();
                     }
                 }
@@ -1048,7 +982,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
             MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
         } catch (Exception e) {
-            intlogger.error("Exception: " + e.getMessage());
+            intlogger.error("Exception: " + e.getMessage(), e);
         }
 
     }
@@ -1086,12 +1020,12 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                 default:
                     action = "*";
             }
-            if (aafInstance == null || aafInstance.equals("")) {
+            if (aafInstance == null || "".equals(aafInstance)) {
                 aafInstance = props.getProperty(AAF_INSTANCE, "org.onap.dmaap-dr.NoInstanceDefined");
             }
             return type + "|" + aafInstance + "|" + action;
         } catch (Exception e) {
-            intlogger.error("PROV7005 BaseServlet.getFeedPermission: ", e.getMessage());
+            intlogger.error("PROV7005 BaseServlet.getFeedPermission: " + e.getMessage(), e);
         }
         return null;
     }
@@ -1134,12 +1068,12 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
                 default:
                     action = "*";
             }
-            if (aafInstance == null || aafInstance.equals("")) {
+            if (aafInstance == null || "".equals(aafInstance)) {
                 aafInstance = props.getProperty(AAF_INSTANCE, "org.onap.dmaap-dr.NoInstanceDefined");
             }
             return type + "|" + aafInstance + "|" + action;
         } catch (Exception e) {
-            intlogger.error("PROV7005 BaseServlet.getSubscriberPermission: ", e.getMessage());
+            intlogger.error("PROV7005 BaseServlet.getSubscriberPermission: " + e.getMessage(), e);
         }
         return null;
     }
index 86e0268..960d509 100644 (file)
@@ -109,8 +109,8 @@ public class DRFeedsServlet extends ProxyServlet {
             }
             // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
             String path = req.getRequestURI();
-            if (path != null && !path.equals("/")) {
-                message = "Bad URL.";
+            if (path != null && !"/".equals(path)) {
+                message = BAD_URL;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -120,7 +120,7 @@ public class DRFeedsServlet extends ProxyServlet {
             // Check with the Authorizer
             AuthorizationResponse aresp = authz.decide(req);
             if (!aresp.isAuthorized()) {
-                message = "Policy Engine disallows access.";
+                message = POLICY_ENGINE;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                 eventlogger.error(elr.toString());
@@ -150,7 +150,7 @@ public class DRFeedsServlet extends ProxyServlet {
                     try {
                         resp.getOutputStream().print(feed.asJSONObject(true).toString());
                     } catch (IOException ioe) {
-                        eventlogger.error("IOException" + ioe.getMessage());
+                        eventlogger.error("PROV0111 DRFeedServlet.doGet " + ioe.getMessage(), ioe);
                     }
                 }
             } else {
@@ -174,7 +174,7 @@ public class DRFeedsServlet extends ProxyServlet {
                 try {
                     resp.getOutputStream().print(t);
                 } catch (IOException ioe) {
-                    eventlogger.error("IOException" + ioe.getMessage());
+                    eventlogger.error("PROV0112 DRFeedServlet.doGet " + ioe.getMessage(), ioe);
                 }
             }
         } finally {
@@ -236,8 +236,8 @@ public class DRFeedsServlet extends ProxyServlet {
             }
             // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
             String path = req.getRequestURI();
-            if (path != null && !path.equals("/")) {
-                message = "Bad URL.";
+            if (path != null && !"/".equals(path)) {
+                message = BAD_URL;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -247,7 +247,7 @@ public class DRFeedsServlet extends ProxyServlet {
             // check content type is FEED_CONTENT_TYPE, version 1.0
             ContentHeader ch = getContentHeader(req);
             String ver = ch.getAttribute("version");
-            if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+            if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
                 message = "Incorrect content-type";
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -257,7 +257,7 @@ public class DRFeedsServlet extends ProxyServlet {
             }
             JSONObject jo = getJSONfromInput(req);
             if (jo == null) {
-                message = "Badly formed JSON";
+                message = BAD_JSON;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -283,7 +283,7 @@ public class DRFeedsServlet extends ProxyServlet {
                 message = e.getMessage();
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
-                eventlogger.error(elr.toString());
+                eventlogger.error(elr.toString(), e);
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
                 return;
             }
@@ -295,11 +295,11 @@ public class DRFeedsServlet extends ProxyServlet {
              */
             String aafInstance = feed.getAafInstance();
             if (Boolean.parseBoolean(isCadiEnabled)) {
-                if ((aafInstance == null || aafInstance.equals("") || (aafInstance.equalsIgnoreCase("legacy")) && req.getHeader(EXCLUDE_AAF_HEADER).equalsIgnoreCase("true"))) {
+                if ((aafInstance == null || "".equals(aafInstance) || ("legacy".equalsIgnoreCase(aafInstance)) && "true".equalsIgnoreCase(req.getHeader(EXCLUDE_AAF_HEADER)))) {
                     // Check with the Authorizer
                     AuthorizationResponse aresp = authz.decide(req);
                     if (!aresp.isAuthorized()) {
-                        message = "Policy Engine disallows access.";
+                        message = POLICY_ENGINE;
                         elr.setMessage(message);
                         elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                         eventlogger.error(elr.toString());
@@ -307,7 +307,7 @@ public class DRFeedsServlet extends ProxyServlet {
                         return;
                     }
                 } else {
-                    if (req.getHeader(EXCLUDE_AAF_HEADER).equalsIgnoreCase("true")) {
+                    if ("true".equalsIgnoreCase(req.getHeader(EXCLUDE_AAF_HEADER))) {
                         message = "DRFeedsServlet.doPost() -Invalid request exclude_AAF should not be true if passing AAF_Instance value= " + aafInstance;
                         elr.setMessage(message);
                         elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -329,7 +329,7 @@ public class DRFeedsServlet extends ProxyServlet {
             } else {
                 AuthorizationResponse aresp = authz.decide(req);
                 if (!aresp.isAuthorized()) {
-                    message = "Policy Engine disallows access.";
+                    message = POLICY_ENGINE;
                     elr.setMessage(message);
                     elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                     eventlogger.error(elr.toString());
@@ -365,7 +365,7 @@ public class DRFeedsServlet extends ProxyServlet {
                 try {
                     resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
                 } catch (IOException ioe) {
-                    eventlogger.error("IOException" + ioe.getMessage());
+                    eventlogger.error("PROV0113 DRFeedServlet.doPost " + ioe.getMessage(), ioe);
                 }
                 provisioningDataChanged();
             } else {
index 3cbaac3..e1938cd 100644 (file)
@@ -82,7 +82,7 @@ public class FeedServlet extends ProxyServlet {
             }
             String bhdr = req.getHeader(BEHALF_HEADER);
             if (bhdr == null) {
-                message = "Missing "+BEHALF_HEADER+" header.";
+                message = MISSING_ON_BEHALF;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -91,7 +91,7 @@ public class FeedServlet extends ProxyServlet {
             }
             int feedid = getIdFromPath(req);
             if (feedid < 0) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -100,7 +100,7 @@ public class FeedServlet extends ProxyServlet {
             }
             Feed feed = Feed.getFeedById(feedid);
             if (feed == null || feed.isDeleted()) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -113,10 +113,10 @@ public class FeedServlet extends ProxyServlet {
              * CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove feed
              */
             String aafInstance = feed.getAafInstance();
-            if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+            if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
                 AuthorizationResponse aresp = authz.decide(req);
                 if (! aresp.isAuthorized()) {
-                    message = "Policy Engine disallows access.";
+                    message = POLICY_ENGINE;
                     elr.setMessage(message);
                     elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                     eventlogger.error(elr.toString());
@@ -183,7 +183,7 @@ public class FeedServlet extends ProxyServlet {
             }
             String bhdr = req.getHeader(BEHALF_HEADER);
             if (bhdr == null) {
-                message = "Missing "+BEHALF_HEADER+" header.";
+                message = MISSING_ON_BEHALF;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -192,7 +192,7 @@ public class FeedServlet extends ProxyServlet {
             }
             int feedid = getIdFromPath(req);
             if (feedid < 0) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -201,7 +201,7 @@ public class FeedServlet extends ProxyServlet {
             }
             Feed feed = Feed.getFeedById(feedid);
             if (feed == null || feed.isDeleted()) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -211,7 +211,7 @@ public class FeedServlet extends ProxyServlet {
             // Check with the Authorizer
             AuthorizationResponse aresp = authz.decide(req);
             if (! aresp.isAuthorized()) {
-                message = "Policy Engine disallows access.";
+                message = POLICY_ENGINE;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                 eventlogger.error(elr.toString());
@@ -227,7 +227,7 @@ public class FeedServlet extends ProxyServlet {
             try {
                 resp.getOutputStream().print(feed.asJSONObject(true).toString());
             } catch (IOException ioe) {
-                eventlogger.error("IOException" + ioe.getMessage());
+                eventlogger.error("PROV0101 FeedServlet.doGet: " + ioe.getMessage(), ioe);
             }
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
@@ -259,7 +259,7 @@ public class FeedServlet extends ProxyServlet {
             }
             String bhdr = req.getHeader(BEHALF_HEADER);
             if (bhdr == null) {
-                message = "Missing "+BEHALF_HEADER+" header.";
+                message = MISSING_ON_BEHALF;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -268,7 +268,7 @@ public class FeedServlet extends ProxyServlet {
             }
             int feedid = getIdFromPath(req);
             if (feedid < 0) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -277,7 +277,7 @@ public class FeedServlet extends ProxyServlet {
             }
             Feed oldFeed = Feed.getFeedById(feedid);
             if (oldFeed == null || oldFeed.isDeleted()) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -287,7 +287,7 @@ public class FeedServlet extends ProxyServlet {
             // check content type is FEED_CONTENT_TYPE, version 1.0
             ContentHeader ch = getContentHeader(req);
             String ver = ch.getAttribute("version");
-            if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+            if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
                 message = "Incorrect content-type";
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -297,7 +297,7 @@ public class FeedServlet extends ProxyServlet {
             }
             JSONObject jo = getJSONfromInput(req);
             if (jo == null) {
-                message = "Badly formed JSON";
+                message = BAD_JSON;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -313,7 +313,7 @@ public class FeedServlet extends ProxyServlet {
                 message = e.getMessage();
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
-                eventlogger.error(elr.toString());
+                eventlogger.error(elr.toString(), e);
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
                 return;
             }
@@ -355,11 +355,11 @@ public class FeedServlet extends ProxyServlet {
              * CADI code - check on permissions based on Legacy/AAF users to allow feed edit/update/modify
              */
             String aafInstance = feed.getAafInstance();
-            if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+            if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
                 // Check with the Authorizer
                 AuthorizationResponse aresp = authz.decide(req);
                 if (!aresp.isAuthorized()) {
-                    message = "Policy Engine disallows access.";
+                    message = POLICY_ENGINE;
                     elr.setMessage(message);
                     elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                     eventlogger.error(elr.toString());
@@ -392,7 +392,7 @@ public class FeedServlet extends ProxyServlet {
                 try {
                     resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
                 } catch (IOException ioe) {
-                    eventlogger.error("IOException" + ioe.getMessage());
+                    eventlogger.error("PROV0102 FeedServlet.doPut: " + ioe.getMessage(), ioe);
                 }
 
 
@@ -405,7 +405,7 @@ public class FeedServlet extends ProxyServlet {
                             feed.changeOwnerShip();
                         }
                     } catch (JSONException je) {
-                        eventlogger.error("JSONException" + je.getMessage());
+                        eventlogger.error("PROV0103 FeedServlet.doPut: " + je.getMessage(), je);
                     }
                 }
                 /***End of change ownership*/
index 188dce6..4432913 100644 (file)
@@ -88,31 +88,6 @@ public class GroupServlet extends ProxyServlet {
             return;
         }
 
-        // Check with the Authorizer
-        /*AuthorizationResponse aresp = authz.decide(req);
-        if (! aresp.isAuthorized()) {
-            message = "Policy Engine disallows access.";
-            elr.setMessage(message);
-            elr.setResult(HttpServletResponse.SC_FORBIDDEN);
-            eventlogger.error(elr.toString());
-            resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
-            return;
-        }*/
-
-
-        /*ContentHeader ch = getContentHeader(req);
-        String ver = ch.getAttribute("version");
-        if (!ch.getType().equals(GROUPLIST_CONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
-            intlogger.debug("Content-type is: "+req.getHeader("Content-Type"));
-            message = "Incorrect content-type";
-            elr.setMessage(message);
-            elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
-            eventlogger.error(elr.toString());
-            resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message);
-            return;
-        }*/
-
-
         int groupid = getIdFromPath(req);
         if (groupid < 0) {
             message = "Missing or bad group number.";
@@ -132,19 +107,9 @@ public class GroupServlet extends ProxyServlet {
         try {
             resp.getOutputStream().print(gup.asJSONObject().toString());
         } catch (IOException ioe) {
-            eventlogger.error("IOException" + ioe.getMessage());
+            eventlogger.error("PROV0121 GroupServlet.doGet: " + ioe.getMessage(), ioe);
         }
 
-        // Display a list of Groups
-        /*Collection<Group> list = Group.getGroupById(groupid);
-        String t = JSONUtilities.createJSONArray(list);
-
-        // send response
-        elr.setResult(HttpServletResponse.SC_OK);
-        eventlogger.info(elr.toString());
-        resp.setStatus(HttpServletResponse.SC_OK);
-        resp.setContentType(GROUPLIST_CONTENT_TYPE);
-        resp.getOutputStream().print(t);*/
     }
     /**
      * PUT on the &lt;GROUPS&gt; -- not supported.
@@ -191,20 +156,11 @@ public class GroupServlet extends ProxyServlet {
             sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
             return;
         }
-        // Check with the Authorizer
-        /*AuthorizationResponse aresp = authz.decide(req);
-        if (! aresp.isAuthorized()) {
-            message = "Policy Engine disallows access.";
-            elr.setMessage(message);
-            elr.setResult(HttpServletResponse.SC_FORBIDDEN);
-            eventlogger.error(elr.toString());
-            resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
-            return;
-        }*/
+
         // check content type is SUB_CONTENT_TYPE, version 1.0
         ContentHeader ch = getContentHeader(req);
         String ver = ch.getAttribute("version");
-        if (!ch.getType().equals(GROUP_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+        if (!ch.getType().equals(GROUP_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
             message = "Incorrect content-type";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -214,7 +170,7 @@ public class GroupServlet extends ProxyServlet {
         }
         JSONObject jo = getJSONfromInput(req);
         if (jo == null) {
-            message = "Badly formed JSON";
+            message = BAD_JSON;
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
             eventlogger.error(elr.toString());
@@ -230,7 +186,7 @@ public class GroupServlet extends ProxyServlet {
             message = e.getMessage();
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
-            eventlogger.error(elr.toString());
+            eventlogger.error(elr.toString(), e);
             sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
             return;
         }
@@ -253,7 +209,7 @@ public class GroupServlet extends ProxyServlet {
             try {
                 resp.getOutputStream().print(gup.asJSONObject().toString());
             } catch (IOException ioe) {
-                eventlogger.error("IOException" + ioe.getMessage());
+                eventlogger.error("PROV0122 GroupServlet.doPut: " + ioe.getMessage(), ioe);
             }
             provisioningDataChanged();
         } else {
@@ -292,34 +248,6 @@ public class GroupServlet extends ProxyServlet {
             sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
             return;
         }
-        /*int feedid = getIdFromPath(req);
-        if (feedid < 0) {
-            message = "Missing or bad feed number.";
-            elr.setMessage(message);
-            elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
-            eventlogger.info(elr.toString());
-            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
-            return;
-        }
-        Feed feed = Feed.getFeedById(feedid);
-        if (feed == null || feed.isDeleted()) {
-            message = "Missing or bad feed number.";
-            elr.setMessage(message);
-            elr.setResult(HttpServletResponse.SC_NOT_FOUND);
-            eventlogger.info(elr.toString());
-            resp.sendError(HttpServletResponse.SC_NOT_FOUND, message);
-            return;
-        }*/
-        // Check with the Authorizer
-        /*AuthorizationResponse aresp = authz.decide(req);
-        if (! aresp.isAuthorized()) {
-            message = "Policy Engine disallows access.";
-            elr.setMessage(message);
-            elr.setResult(HttpServletResponse.SC_FORBIDDEN);
-            eventlogger.info(elr.toString());
-            resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
-            return;
-        }*/
 
         // check content type is SUB_CONTENT_TYPE, version 1.0
         ContentHeader ch = getContentHeader(req);
@@ -335,7 +263,7 @@ public class GroupServlet extends ProxyServlet {
         }
         JSONObject jo = getJSONfromInput(req);
         if (jo == null) {
-            message = "Badly formed JSON";
+            message = BAD_JSON;
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
             eventlogger.error(elr.toString());
@@ -352,7 +280,7 @@ public class GroupServlet extends ProxyServlet {
             message = e.getMessage();
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
-            eventlogger.error(elr.toString());
+            eventlogger.error(elr.toString(), e);
             sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
             return;
         }
@@ -379,7 +307,7 @@ public class GroupServlet extends ProxyServlet {
             try {
                 resp.getOutputStream().print(gup.asJSONObject().toString());
             } catch (IOException ioe) {
-                eventlogger.error("IOException" + ioe.getMessage());
+                eventlogger.error("PROV0122 GroupServlet.doPost: " + ioe.getMessage(), ioe);
             }
             provisioningDataChanged();
         } else {
index 56b40e0..8ae9fa2 100644 (file)
@@ -156,6 +156,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
 @SuppressWarnings("serial")
 public class InternalServlet extends ProxyServlet {
 
+
     private static final Object lock = new Object();
     private static Integer logseq = 0; // another piece of info to make log spool file names unique
     //Adding EELF Logger Rally:US664892
@@ -174,15 +175,15 @@ public class InternalServlet extends ProxyServlet {
             eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
             EventLogRecord elr = new EventLogRecord(req);
             if (!isAuthorizedForInternal(req)) {
-                elr.setMessage("Unauthorized.");
+                elr.setMessage(UNAUTHORIZED);
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                 eventlogger.error(elr.toString());
-                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
                 return;
             }
 
             String path = req.getPathInfo();
-            if (path.startsWith("/api/")) {
+            if (path.startsWith(API)) {
                 if (isProxyOK(req) && isProxyServer()) {
                     super.doDelete(req, resp);
                     return;
@@ -207,7 +208,7 @@ public class InternalServlet extends ProxyServlet {
                     }
                 }
             }
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
         }
@@ -225,7 +226,7 @@ public class InternalServlet extends ProxyServlet {
             eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
             String path = req.getPathInfo();
             Properties props = (new DB()).getProperties();
-            if (path.equals("/halt") && !req.isSecure()) {
+            if ("/halt".equals(path) && !req.isSecure()) {
                 // request to halt the server - can ONLY come from localhost
                 String remote = req.getRemoteAddr();
                 if (remote.equals(props.getProperty("org.onap.dmaap.datarouter.provserver.localhost"))) {
@@ -241,20 +242,20 @@ public class InternalServlet extends ProxyServlet {
 
             EventLogRecord elr = new EventLogRecord(req);
             if (!isAuthorizedForInternal(req)) {
-                elr.setMessage("Unauthorized.");
+                elr.setMessage(UNAUTHORIZED);
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                 eventlogger.error(elr.toString());
-                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
                 return;
             }
-            if (path.equals("/fetchProv") && !req.isSecure()) {
+            if ("/fetchProv".equals(path) && !req.isSecure()) {
                 // if request came from active_pod or standby_pod and it is not us, reload prov data
                 SynchronizerTask s = SynchronizerTask.getSynchronizer();
                 s.doFetch();
                 resp.setStatus(HttpServletResponse.SC_OK);
                 return;
             }
-            if (path.equals("/prov")) {
+            if ("/prov".equals(path)) {
                 if (isProxyOK(req) && isProxyServer()) {
                     if (super.doGetWithFallback(req, resp)) {
                         return;
@@ -268,33 +269,33 @@ public class InternalServlet extends ProxyServlet {
                 try {
                     resp.getOutputStream().print(p.getProvisioningString());
                 } catch (IOException ioe) {
-                    intlogger.error("IOException" + ioe.getMessage());
+                    intlogger.error("PROV0131 InternalServlet.doGet: " + ioe.getMessage(), ioe);
                 }
                 return;
             }
-            if (path.equals("/logs") || path.equals("/logs/")) {
+            if ("/logs".equals(path) || LOGS.equals(path)) {
                 resp.setStatus(HttpServletResponse.SC_OK);
                 resp.setContentType("application/json");
                 try {
                     resp.getOutputStream().print(generateLogfileList().toString());
                 } catch (IOException ioe) {
-                    intlogger.error("IOException" + ioe.getMessage());
+                    intlogger.error("PROV0132 InternalServlet.doGet: " + ioe.getMessage(), ioe);
                 }
                 return;
             }
-            if (path.startsWith("/logs/")) {
+            if (path.startsWith(LOGS)) {
                 String logdir = props.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");
                 String logfile = path.substring(6);
                 if (logdir != null && logfile != null && logfile.indexOf('/') < 0) {
                     File log = new File(logdir + "/" + logfile);
                     if (log.exists() && log.isFile()) {
                         resp.setStatus(HttpServletResponse.SC_OK);
-                        resp.setContentType("text/plain");
+                        resp.setContentType(TEXT_CT);
                         Path logpath = Paths.get(log.getAbsolutePath());
                         try {
                             Files.copy(logpath, resp.getOutputStream());
                         } catch (IOException ioe) {
-                            intlogger.error("IOException" + ioe.getMessage());
+                            intlogger.error("PROV0133 InternalServlet.doGet: " + ioe.getMessage(), ioe);
                         }
                         return;
                     }
@@ -302,7 +303,7 @@ public class InternalServlet extends ProxyServlet {
                 sendResponseError(resp, HttpServletResponse.SC_NO_CONTENT, "No file.", eventlogger);
                 return;
             }
-            if (path.startsWith("/api/")) {
+            if (path.startsWith(API)) {
                 if (isProxyOK(req) && isProxyServer()) {
                     super.doGet(req, resp);
                     return;
@@ -312,29 +313,29 @@ public class InternalServlet extends ProxyServlet {
                     Parameters param = Parameters.getParameter(key);
                     if (param != null) {
                         resp.setStatus(HttpServletResponse.SC_OK);
-                        resp.setContentType("text/plain");
+                        resp.setContentType(TEXT_CT);
                         try {
                             resp.getOutputStream().print(param.getValue() + "\n");
                         } catch (IOException ioe) {
-                            intlogger.error("IOException" + ioe.getMessage());
+                            intlogger.error("PROV0134 InternalServlet.doGet: " + ioe.getMessage(), ioe);
                         }
                         return;
                     }
                 }
             }
-            if (path.equals("/drlogs") || path.equals("/drlogs/")) {
+            if ("/drlogs".equals(path) || "/drlogs/".equals(path)) {
                 // Special POD <=> POD API to determine what log file records are loaded here
                 LogfileLoader lfl = LogfileLoader.getLoader();
                 resp.setStatus(HttpServletResponse.SC_OK);
-                resp.setContentType("text/plain");
+                resp.setContentType(TEXT_CT);
                 try {
                     resp.getOutputStream().print(lfl.getBitSet().toString());
                 } catch (IOException ioe) {
-                    intlogger.error("IOException" + ioe.getMessage());
+                    intlogger.error("PROV0135 InternalServlet.doGet: " + ioe.getMessage(), ioe);
                 }
                 return;
             }
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
         }
@@ -352,14 +353,14 @@ public class InternalServlet extends ProxyServlet {
             eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
             EventLogRecord elr = new EventLogRecord(req);
             if (!isAuthorizedForInternal(req)) {
-                elr.setMessage("Unauthorized.");
+                elr.setMessage(UNAUTHORIZED);
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                 eventlogger.error(elr.toString());
-                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
                 return;
             }
             String path = req.getPathInfo();
-            if (path.startsWith("/api/")) {
+            if (path.startsWith(API)) {
                 if (isProxyOK(req) && isProxyServer()) {
                     super.doPut(req, resp);
                     return;
@@ -386,7 +387,7 @@ public class InternalServlet extends ProxyServlet {
                     }
                 }
             }
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
         }
@@ -405,15 +406,15 @@ public class InternalServlet extends ProxyServlet {
             eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
             EventLogRecord elr = new EventLogRecord(req);
             if (!isAuthorizedForInternal(req)) {
-                elr.setMessage("Unauthorized.");
+                elr.setMessage(UNAUTHORIZED);
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                 eventlogger.error(elr.toString());
-                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+                sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
                 return;
             }
 
             String path = req.getPathInfo();
-            if (path.startsWith("/api/")) {
+            if (path.startsWith(API)) {
                 if (isProxyOK(req) && isProxyServer()) {
                     super.doPost(req, resp);
                     return;
@@ -441,9 +442,9 @@ public class InternalServlet extends ProxyServlet {
                 }
             }
 
-            if (path.equals("/logs") || path.equals("/logs/")) {
+            if ("/logs".equals(path) || LOGS.equals(path)) {
                 String ctype = req.getHeader("Content-Type");
-                if (ctype == null || !ctype.equals("text/plain")) {
+                if (ctype == null || !TEXT_CT.equals(ctype)) {
                     elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
                     elr.setMessage("Bad media type: " + ctype);
                     resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -459,7 +460,7 @@ public class InternalServlet extends ProxyServlet {
                 }
                 String encoding = req.getHeader("Content-Encoding");
                 if (encoding != null) {
-                    if (encoding.trim().equals("gzip")) {
+                    if ("gzip".equals(encoding.trim())) {
                         spoolname += ".gz";
                     } else {
                         elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -477,12 +478,13 @@ public class InternalServlet extends ProxyServlet {
                         total += store.getTotalSpace();
                         avail += store.getUsableSpace();
                     } catch (IOException ioe) {
-                        intlogger.error("IOException" + ioe.getMessage());
+                        intlogger.error("PROV0136 InternalServlet.doPost: " + ioe.getMessage(), ioe);
                     }
                 }
                 try {
                     fs.close();
                 } catch (Exception e) {
+                    intlogger.error("PROV0137 InternalServlet.doPost: " + e.getMessage(), e);
                 }
                 if (((avail * 100) / total) < 5) {
                     elr.setResult(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
@@ -500,15 +502,15 @@ public class InternalServlet extends ProxyServlet {
                     eventlogger.info(elr.toString());
                     LogfileLoader.getLoader();    // This starts the logfile loader "task"
                 } catch (IOException ioe) {
-                    intlogger.error("IOException" + ioe.getMessage());
+                    intlogger.error("PROV0138 InternalServlet.doPost: " + ioe.getMessage(), ioe);
                 }
                 return;
             }
 
-            if (path.equals("/drlogs") || path.equals("/drlogs/")) {
+            if ("/drlogs".equals(path) || "/drlogs/".equals(path)) {
                 // Receive post request and generate log entries
                 String ctype = req.getHeader("Content-Type");
-                if (ctype == null || !ctype.equals("text/plain")) {
+                if (ctype == null || !TEXT_CT.equals(ctype)) {
                     elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
                     elr.setMessage("Bad media type: " + ctype);
                     resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -525,17 +527,17 @@ public class InternalServlet extends ProxyServlet {
                     RLEBitSet bs = new RLEBitSet(bos.toString());    // The set of records to retrieve
                     elr.setResult(HttpServletResponse.SC_OK);
                     resp.setStatus(HttpServletResponse.SC_OK);
-                    resp.setContentType("text/plain");
+                    resp.setContentType(TEXT_CT);
                     LogRecord.printLogRecords(resp.getOutputStream(), bs);
                     eventlogger.info(elr.toString());
                 } catch (IOException ioe) {
-                    intlogger.error("IOException" + ioe.getMessage());
+                    intlogger.error("PROV0139 InternalServlet.doPost: " + ioe.getMessage(), ioe);
                 }
                 return;
             }
 
             elr.setResult(HttpServletResponse.SC_NOT_FOUND);
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
             eventlogger.error(elr.toString());
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
index 77bcbdd..762ab4e 100644 (file)
@@ -68,6 +68,12 @@ public class LogServlet extends BaseServlet {
     private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);\r
     private static final String FMT_1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
     private static final String FMT_2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
+    private static final String PUBLISHSQL = "publishSQL";\r
+    private static final String STATUSSQL = "statusSQL";\r
+    private static final String RESULTSQL = "resultSQL";\r
+    private static final String FILENAMESQL = "filenameSQL";\r
+    private static final String TIMESQL = "timeSQL";\r
+    private static final String LOG_RECORDSSQL = "select * from LOG_RECORDS where FEEDID = ";\r
 \r
     private final boolean isfeedlog;\r
 \r
@@ -226,7 +232,7 @@ public class LogServlet extends BaseServlet {
                 }\r
                 out.print("]");\r
             } catch (IOException ioe) {\r
-                eventlogger.error("IOException: " + ioe.getMessage());\r
+                eventlogger.error("PROV0141 LogServlet.doGet: " + ioe.getMessage(), ioe);\r
             }\r
         } finally {\r
             eelfLogger.info(EelfMsgs.EXIT);\r
@@ -275,7 +281,7 @@ public class LogServlet extends BaseServlet {
         Map<String, String> map = new HashMap<>();\r
         String s = req.getParameter("type");\r
         if (s != null) {\r
-            if (s.equals("pub") || s.equals("del") || s.equals("exp")) {\r
+            if ("pub".equals(s) || "del".equals(s) || "exp".equals(s)) {\r
                 map.put("type", s);\r
             } else {\r
                 map.put("err", "bad type");\r
@@ -284,11 +290,11 @@ public class LogServlet extends BaseServlet {
         } else {\r
             map.put("type", "all");\r
         }\r
-        map.put("publishSQL", "");\r
-        map.put("statusSQL", "");\r
-        map.put("resultSQL", "");\r
-        map.put("reasonSQL", "");\r
-        map.put("filenameSQL", "");\r
+        map.put(PUBLISHSQL, "");\r
+        map.put(STATUSSQL, "");\r
+        map.put(RESULTSQL, "");\r
+        map.put(REASON_SQL, "");\r
+        map.put(FILENAMESQL, "");\r
 \r
         s = req.getParameter("publishId");\r
         if (s != null) {\r
@@ -296,22 +302,22 @@ public class LogServlet extends BaseServlet {
                 map.put("err", "bad publishId");\r
                 return map;\r
             }\r
-            map.put("publishSQL", " AND PUBLISH_ID = '"+s+"'");\r
+            map.put(PUBLISHSQL, " AND PUBLISH_ID = '"+s+"'");\r
         }\r
 \r
         s = req.getParameter("filename");\r
         if (s != null) {\r
-            map.put("filenameSQL", " AND FILENAME = '"+s+"'");\r
+            map.put(FILENAMESQL, " AND FILENAME = '"+s+"'");\r
         }\r
 \r
         s = req.getParameter("statusCode");\r
         if (s != null) {\r
             String sql = null;\r
-            if (s.equals("success")) {\r
+            if ("success".equals(s)) {\r
                 sql = " AND STATUS >= 200 AND STATUS < 300";\r
-            } else if (s.equals("redirect")) {\r
+            } else if ("redirect".equals(s)) {\r
                 sql = " AND STATUS >= 300 AND STATUS < 400";\r
-            } else if (s.equals("failure")) {\r
+            } else if ("failure".equals(s)) {\r
                 sql = " AND STATUS >= 400";\r
             } else {\r
                 try {\r
@@ -325,21 +331,21 @@ public class LogServlet extends BaseServlet {
                 map.put("err", "bad statusCode");\r
                 return map;\r
             }\r
-            map.put("statusSQL", sql);\r
-            map.put("resultSQL", sql.replaceAll("STATUS", "RESULT"));\r
+            map.put(STATUSSQL, sql);\r
+            map.put(RESULTSQL, sql.replaceAll("STATUS", "RESULT"));\r
         }\r
 \r
         s = req.getParameter("expiryReason");\r
         if (s != null) {\r
             map.put("type", "exp");\r
-            if (s.equals("notRetryable")) {\r
-                map.put("reasonSQL", " AND REASON = 'notRetryable'");\r
-            } else if (s.equals("retriesExhausted")) {\r
-                map.put("reasonSQL", " AND REASON = 'retriesExhausted'");\r
-            } else if (s.equals("diskFull")) {\r
-                map.put("reasonSQL", " AND REASON = 'diskFull'");\r
-            } else if (s.equals("other")) {\r
-                map.put("reasonSQL", " AND REASON = 'other'");\r
+            if ("notRetryable".equals(s)) {\r
+                map.put(REASON_SQL, " AND REASON = 'notRetryable'");\r
+            } else if ("retriesExhausted".equals(s)) {\r
+                map.put(REASON_SQL, " AND REASON = 'retriesExhausted'");\r
+            } else if ("diskFull".equals(s)) {\r
+                map.put(REASON_SQL, " AND REASON = 'diskFull'");\r
+            } else if ("other".equals(s)) {\r
+                map.put(REASON_SQL, " AND REASON = 'other'");\r
             } else {\r
                 map.put("err", "bad expiryReason");\r
                 return map;\r
@@ -364,7 +370,7 @@ public class LogServlet extends BaseServlet {
         } else if (etime == 0) {\r
             etime = stime + TWENTYFOUR_HOURS;\r
         }\r
-        map.put("timeSQL", String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));\r
+        map.put(TIMESQL, String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));\r
         return map;\r
     }\r
     private long getTimeFromParam(final String s) {\r
@@ -381,8 +387,7 @@ public class LogServlet extends BaseServlet {
         }\r
         try {\r
             // Also allow a long (in ms); useful for testing\r
-            long n = Long.parseLong(s);\r
-            return n;\r
+            return Long.parseLong(s);\r
         } catch (NumberFormatException numberFormatException) {\r
             intlogger.error("Exception in getting Time :- "+numberFormatException.getMessage(),numberFormatException);\r
         }\r
@@ -392,51 +397,51 @@ public class LogServlet extends BaseServlet {
 \r
     private void getPublishRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
         String type = map.get("type");\r
-        if (type.equals("all") || type.equals("pub")) {\r
-            String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
+        if ("all".equals(type) || "pub".equals(type)) {\r
+            String sql = LOG_RECORDSSQL+feedid\r
                 + " AND TYPE = 'pub'"\r
-                + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL") + map.get("filenameSQL");\r
+                + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(STATUSSQL) + map.get(FILENAMESQL);\r
             getRecordsForSQL(sql, rh);\r
         }\r
     }\r
     private void getDeliveryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
         String type = map.get("type");\r
-        if (type.equals("all") || type.equals("del")) {\r
-            String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
+        if ("all".equals(type) || "del".equals(type)) {\r
+            String sql = LOG_RECORDSSQL+feedid\r
                 + " AND TYPE = 'del'"\r
-                + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");\r
+                + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(RESULTSQL);\r
             getRecordsForSQL(sql, rh);\r
         }\r
     }\r
     private void getDeliveryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {\r
         String type = map.get("type");\r
-        if (type.equals("all") || type.equals("del")) {\r
+        if ("all".equals(type) || "del".equals(type)) {\r
             String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid\r
                 + " AND TYPE = 'del'"\r
-                + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");\r
+                + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(RESULTSQL);\r
             getRecordsForSQL(sql, rh);\r
         }\r
     }\r
     private void getExpiryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {\r
         String type = map.get("type");\r
-        if (type.equals("all") || type.equals("exp")) {\r
-            String st = map.get("statusSQL");\r
+        if ("all".equals(type) || "exp".equals(type)) {\r
+            String st = map.get(STATUSSQL);\r
             if (st == null || st.length() == 0) {\r
-                String sql = "select * from LOG_RECORDS where FEEDID = "+feedid\r
+                String sql = LOG_RECORDSSQL+feedid\r
                     + " AND TYPE = 'exp'"\r
-                    + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");\r
+                    + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(REASON_SQL);\r
                 getRecordsForSQL(sql, rh);\r
             }\r
         }\r
     }\r
     private void getExpiryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {\r
         String type = map.get("type");\r
-        if (type.equals("all") || type.equals("exp")) {\r
-            String st = map.get("statusSQL");\r
+        if ("all".equals(type) || "exp".equals(type)) {\r
+            String st = map.get(STATUSSQL);\r
             if (st == null || st.length() == 0) {\r
                 String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid\r
                     + " AND TYPE = 'exp'"\r
-                    + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");\r
+                    + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(REASON_SQL);\r
                 getRecordsForSQL(sql, rh);\r
             }\r
         }\r
index a0d8664..7c693bd 100644 (file)
@@ -102,7 +102,7 @@ public class Main {
             try {
                 in = getClass().getClassLoader().getResourceAsStream("drProvCadi.properties");
             } catch (Exception e) {
-                intlogger.error("Exception in Main.getCadiProps() method ", e.getMessage());
+                intlogger.error("Exception in Main.getCadiProps(): " + e.getMessage(), e);
             }
             return in;
         }
@@ -247,8 +247,8 @@ public class Main {
                         Inner obj = new Main().new Inner();
                         InputStream in = obj.getCadiProps();
                         cadiProperties.load(in);
-                    } catch (IOException e1) {
-                        intlogger.error("PROV0001 Exception loading CADI properties", e1.getMessage());
+                    } catch (IOException ioe) {
+                        intlogger.error("PROV0001 Exception loading CADI properties: " + ioe.getMessage(), ioe);
                     }
                     cadiProperties.setProperty("aaf_locate_url", provProperties.getProperty("org.onap.dmaap.datarouter.provserver.cadi.aaf.url", "https://aaf-onap-test.osaaf.org:8095"));
                     intlogger.info("PROV0001  aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
@@ -281,7 +281,7 @@ public class Main {
             server.start();
             intlogger.info("Prov Server started-" + server.getState());
         } catch (Exception e) {
-            intlogger.info("Jetty failed to start. Reporting will we unavailable", e.getMessage());
+            intlogger.info("Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e);
         }
         server.join();
         intlogger.info("PROV0001 **** AT&T Data Router Provisioning Server halted.");
@@ -302,7 +302,7 @@ public class Main {
                 Thread.sleep(5000L);
                 System.exit(0);
             } catch (Exception e) {
-                intlogger.error("Exception in Main.shutdown() method " + e.getMessage());
+                intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e);
             }
         });
     }
index b9d5e7a..6cb8520 100644 (file)
@@ -66,6 +66,7 @@ public class Poker extends TimerTask {
     private static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";\r
 \r
     private static final Object lock = new Object();\r
+    private static final String CARRIAGE_RETURN = "\n],\n";\r
 \r
     /**\r
      * This is a singleton -- there is only one Poker object in the server\r
@@ -77,6 +78,7 @@ public class Poker extends TimerTask {
     private EELFLogger logger;\r
     private String provString;\r
 \r
+\r
     private Poker() {\r
         timer1 = timer2 = 0;\r
         Timer rolex = new Timer();\r
@@ -84,8 +86,8 @@ public class Poker extends TimerTask {
         try {\r
             thisPod = InetAddress.getLocalHost().getHostName();\r
         } catch (UnknownHostException e) {\r
-            thisPod = "*UNKNOWN*"; // not a major problem\r
-            logger.info("UnknownHostException: Setting thisPod to \"*UNKNOWN*\"");\r
+            thisPod = "*UNKNOWN_POD*"; // not a major problem\r
+            logger.info("UnknownHostException: Setting thisPod to \"*UNKNOWN_POD*\"", e);\r
         }\r
         provString = buildProvisioningString();\r
 \r
@@ -195,10 +197,10 @@ public class Poker extends TimerTask {
             } catch (MalformedURLException e) {\r
                 logger.warn(\r
                         "PROV0013 MalformedURLException Error poking node at " + nodeUrl + " : " + e\r
-                                .getMessage());\r
+                                .getMessage(), e);\r
             } catch (IOException e) {\r
                 logger.warn("PROV0013 IOException Error poking node at " + nodeUrl + " : " + e\r
-                        .getMessage());\r
+                        .getMessage(), e);\r
             }\r
         };\r
         r.run();\r
@@ -215,7 +217,7 @@ public class Poker extends TimerTask {
             sb.append(f.asJSONObject().toString());\r
             pfx = ",\n";\r
         }\r
-        sb.append("\n],\n");\r
+        sb.append(CARRIAGE_RETURN);\r
 \r
         //Append groups to the string - Rally:US708115  - 1610\r
         pfx = "\n";\r
@@ -225,7 +227,7 @@ public class Poker extends TimerTask {
             sb.append(s.asJSONObject().toString());\r
             pfx = ",\n";\r
         }\r
-        sb.append("\n],\n");\r
+        sb.append(CARRIAGE_RETURN);\r
 \r
         // Append Subscriptions to the string\r
         pfx = "\n";\r
@@ -237,13 +239,13 @@ public class Poker extends TimerTask {
             }\r
             pfx = ",\n";\r
         }\r
-        sb.append("\n],\n");\r
+        sb.append(CARRIAGE_RETURN);\r
 \r
         // Append Parameters to the string\r
         pfx = "\n";\r
         sb.append("\"parameters\": {");\r
         Map<String, String> props = Parameters.getParameters();\r
-        Set<String> ivals = new HashSet<String>();\r
+        Set<String> ivals = new HashSet<>();\r
         String intv = props.get("_INT_VALUES");\r
         if (intv != null) {\r
             ivals.addAll(Arrays.asList(intv.split("\\|")));\r
@@ -280,7 +282,7 @@ public class Poker extends TimerTask {
             sb.append(in.asJSONObject().toString());\r
             pfx = ",\n";\r
         }\r
-        sb.append("\n],\n");\r
+        sb.append(CARRIAGE_RETURN);\r
 \r
         pfx = "\n";\r
         sb.append("\"egress\": {");\r
index 67a74de..7542360 100755 (executable)
@@ -101,7 +101,7 @@ public class ProxyServlet extends BaseServlet {
             sch = new Scheme("https", 443, socketFactory);
             inited = true;
         } catch (Exception e) {
-            intlogger.error("ProxyServlet: " + e.getMessage());
+            intlogger.error("ProxyServlet.init: " + e.getMessage(), e);
         }
         intlogger.info("ProxyServlet: inited = " + inited);
     }
@@ -111,7 +111,7 @@ public class ProxyServlet extends BaseServlet {
         try (FileInputStream instream = new FileInputStream(new File(store))) {
             ks.load(instream, pass.toCharArray());
         } catch (FileNotFoundException fileNotFoundException) {
-            intlogger.error("ProxyServlet: " + fileNotFoundException.getMessage());
+            intlogger.error("ProxyServlet.readStore: " + fileNotFoundException.getMessage(), fileNotFoundException);
         } catch (Exception x) {
             intlogger.error("READING TRUSTSTORE: " + x);
         }
@@ -130,7 +130,7 @@ public class ProxyServlet extends BaseServlet {
         if (t != null) {
             t = t.replaceAll("&amp;", "&");
             for (String s : t.split("&")) {
-                if (s.equals("noproxy") || s.startsWith("noproxy=")) {
+                if ("noproxy".equals(s) || s.startsWith("noproxy=")) {
                     return false;
                 }
             }
@@ -146,7 +146,7 @@ public class ProxyServlet extends BaseServlet {
      */
     public boolean isProxyServer() {
         SynchronizerTask st = SynchronizerTask.getSynchronizer();
-        return st.getState() == SynchronizerTask.STANDBY;
+        return st.getPodState() == SynchronizerTask.STANDBY_POD;
     }
 
     /**
@@ -211,7 +211,7 @@ public class ProxyServlet extends BaseServlet {
                     rv = true;
 
                 } catch (IOException e) {
-                    intlogger.error("ProxyServlet: " + e.getMessage());
+                    intlogger.error("ProxyServlet.doGetWithFallback: " + e.getMessage(), e);
                 } finally {
                     proxy.releaseConnection();
                     httpclient.getConnectionManager().shutdown();
@@ -234,7 +234,7 @@ public class ProxyServlet extends BaseServlet {
 
                     // Copy request headers and request body
                     copyRequestHeaders(req, proxy);
-                    if (method.equals("POST") || method.equals("PUT")) {
+                    if ("POST".equals(method) || "PUT".equals(method)) {
                         BasicHttpEntity body = new BasicHttpEntity();
                         body.setContent(req.getInputStream());
                         body.setContentLength(-1);    // -1 = unknown
@@ -250,7 +250,7 @@ public class ProxyServlet extends BaseServlet {
                     copyResponseHeaders(pxyResponse, resp);
                     copyEntityContent(pxyResponse, resp);
                 } catch (IOException e) {
-                    intlogger.warn("ProxyServlet: " + e.getMessage());
+                    intlogger.warn("ProxyServlet.doProxy: " + e.getMessage(), e);
                     sendResponseError(resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE, "", intlogger);
                 } finally {
                     proxy.releaseConnection();
@@ -279,7 +279,7 @@ public class ProxyServlet extends BaseServlet {
         List<String> list = Collections.list(from.getHeaderNames());
         for (String name : list) {
             // Proxy code will add this one
-            if (!name.equalsIgnoreCase("Content-Length")) {
+            if (!"Content-Length".equalsIgnoreCase(name)) {
                 to.addHeader(name, from.getHeader(name));
             }
         }
@@ -288,7 +288,7 @@ public class ProxyServlet extends BaseServlet {
     private void copyResponseHeaders(HttpResponse from, HttpServletResponse to) {
         for (Header hdr : from.getAllHeaders()) {
             // Don't copy Date: our Jetty will add another Date header
-            if (!hdr.getName().equals("Date")) {
+            if (!"Date".equals(hdr.getName())) {
                 to.addHeader(hdr.getName(), hdr.getValue());
             }
         }
@@ -300,7 +300,7 @@ public class ProxyServlet extends BaseServlet {
             try (InputStream in = entity.getContent()) {
                 IOUtils.copy(in, resp.getOutputStream());
             } catch (Exception e) {
-                intlogger.error("Exception: " + e.getMessage());
+                intlogger.error("ProxyServlet.copyEntityContent: " + e.getMessage(), e);
             }
         }
     }
index 76a983f..2ef5087 100644 (file)
@@ -169,7 +169,7 @@ public class PublishServlet extends BaseServlet {
                 }\r
             }\r
         } catch (IOException ioe) {\r
-            intlogger.error("IOException" + ioe.getMessage());\r
+            intlogger.error("PROV0151 PublishServlet.redirect: " + ioe.getMessage(), ioe);\r
         }\r
     }\r
 \r
@@ -235,6 +235,7 @@ public class PublishServlet extends BaseServlet {
             }\r
             return -1;\r
         } catch (NumberFormatException | JSONException e) {\r
+            intlogger.debug("PROV0152 PublishServlet.checkPath: " + e.getMessage(), e);\r
             return -1;\r
         }\r
     }\r
index 4dd422a..383798f 100644 (file)
@@ -129,6 +129,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
  */\r
 @SuppressWarnings("serial")\r
 public class RouteServlet extends ProxyServlet {\r
+\r
     /**\r
      * DELETE route table entries by deleting part of the route table tree.\r
      */\r
@@ -136,10 +137,10 @@ public class RouteServlet extends ProxyServlet {
     public void doDelete(HttpServletRequest req, HttpServletResponse resp) {\r
         EventLogRecord elr = new EventLogRecord(req);\r
         if (!isAuthorizedForInternal(req)) {\r
-            elr.setMessage("Unauthorized.");\r
+            elr.setMessage(UNAUTHORIZED);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
             eventlogger.error(elr.toString());\r
-            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);\r
+            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);\r
             return;\r
         }\r
         if (isProxyOK(req) && isProxyServer()) {\r
@@ -150,7 +151,7 @@ public class RouteServlet extends ProxyServlet {
         String path = req.getPathInfo();\r
         String[] parts = path.substring(1).split("/");\r
         Deleteable[] d = null;\r
-        if (parts[0].equals("ingress")) {\r
+        if ("ingress".equals(parts[0])) {\r
             if (parts.length == 4) {\r
                 // /internal/route/ingress/<feed>/<user>/<subnet>\r
                 try {\r
@@ -179,7 +180,7 @@ public class RouteServlet extends ProxyServlet {
                 sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid number of arguments in 'delete ingress' command.", eventlogger);\r
                 return;\r
             }\r
-        } else if (parts[0].equals("egress")) {\r
+        } else if ("egress".equals(parts[0])) {\r
             if (parts.length == 2) {\r
                 // /internal/route/egress/<sub>\r
                 try {\r
@@ -198,7 +199,7 @@ public class RouteServlet extends ProxyServlet {
                 sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid number of arguments in 'delete egress' command.", eventlogger);\r
                 return;\r
             }\r
-        } else if (parts[0].equals("network")) {\r
+        } else if ("network".equals(parts[0])) {\r
             if (parts.length == 3) {\r
                 // /internal/route/network/<from>/<to>\r
                 try {//\r
@@ -208,7 +209,9 @@ public class RouteServlet extends ProxyServlet {
                     );\r
                     d = new Deleteable[] { nr };\r
                 } catch (IllegalArgumentException e) {\r
-                    sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "The specified network route does not exist.", eventlogger);\r
+                    String message = "The specified network route does not exist.";\r
+                    eventlogger.error(message, e);\r
+                    sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);\r
                     return;\r
                 }\r
             } else {\r
@@ -217,7 +220,7 @@ public class RouteServlet extends ProxyServlet {
             }\r
         }\r
         if (d == null) {\r
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);\r
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);\r
             return;\r
         }\r
         boolean rv = true;\r
@@ -244,10 +247,10 @@ public class RouteServlet extends ProxyServlet {
     public void doGet(HttpServletRequest req, HttpServletResponse resp) {\r
         EventLogRecord elr = new EventLogRecord(req);\r
         if (!isAuthorizedForInternal(req)) {\r
-            elr.setMessage("Unauthorized.");\r
+            elr.setMessage(UNAUTHORIZED);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
             eventlogger.error(elr.toString());\r
-            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);\r
+            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);\r
             return;\r
         }\r
         if (isProxyOK(req) && isProxyServer()) {\r
@@ -258,14 +261,14 @@ public class RouteServlet extends ProxyServlet {
         String path = req.getPathInfo();\r
         if (!path.endsWith("/"))\r
             path += "/";\r
-        if (!path.equals("/") && !path.equals("/ingress/") && !path.equals("/egress/") && !path.equals("/network/")) {\r
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);\r
+        if (!"/".equals(path) && !INGRESS.equals(path) && !EGRESS.equals(path) && !NETWORK.equals(path)) {\r
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);\r
             return;\r
         }\r
 \r
         StringBuilder sb = new StringBuilder("{\n");\r
         String px2 = "";\r
-        if (path.equals("/") || path.equals("/ingress/")) {\r
+        if ("/".equals(path) || INGRESS.equals(path)) {\r
             String pfx = "\n";\r
             sb.append("\"ingress\": [");\r
             for (IngressRoute in : IngressRoute.getAllIngressRoutes()) {\r
@@ -277,7 +280,7 @@ public class RouteServlet extends ProxyServlet {
             px2 = ",\n";\r
         }\r
 \r
-        if (path.equals("/") || path.equals("/egress/")) {\r
+        if ("/".equals(path) || EGRESS.equals(path)) {\r
             String pfx = "\n";\r
             sb.append(px2);\r
             sb.append("\"egress\": {");\r
@@ -289,7 +292,7 @@ public class RouteServlet extends ProxyServlet {
                     try {\r
                         sb.append("\"").append(jx.getString(key)).append("\"");\r
                     } catch (JSONException je) {\r
-                        eventlogger.error("JSONException" + je.getMessage());\r
+                        eventlogger.error("PROV0161 RouteServlet.doGet: " + je.getMessage(), je);\r
                     }\r
                     pfx = ",\n";\r
                 }\r
@@ -298,7 +301,7 @@ public class RouteServlet extends ProxyServlet {
             px2 = ",\n";\r
         }\r
 \r
-        if (path.equals("/") || path.equals("/network/")) {\r
+        if ("/".equals(path) || NETWORK.equals(path)) {\r
             String pfx = "\n";\r
             sb.append(px2);\r
             sb.append("\"routing\": [");\r
@@ -315,7 +318,7 @@ public class RouteServlet extends ProxyServlet {
         try {\r
             resp.getOutputStream().print(sb.toString());\r
         } catch (IOException ioe) {\r
-            eventlogger.error("IOException" + ioe.getMessage());\r
+            eventlogger.error("PROV0162 RouteServlet.doGet: " + ioe.getMessage(), ioe);\r
         }\r
     }\r
     /**\r
@@ -325,13 +328,13 @@ public class RouteServlet extends ProxyServlet {
     public void doPut(HttpServletRequest req, HttpServletResponse resp) {\r
         EventLogRecord elr = new EventLogRecord(req);\r
         if (!isAuthorizedForInternal(req)) {\r
-            elr.setMessage("Unauthorized.");\r
+            elr.setMessage(UNAUTHORIZED);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
             eventlogger.error(elr.toString());\r
-            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);\r
+            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);\r
             return;\r
         }\r
-        sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);\r
+        sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);\r
     }\r
     /**\r
      * POST - modify existing route table entries in the route table tree specified by the URL path.\r
@@ -340,10 +343,10 @@ public class RouteServlet extends ProxyServlet {
     public void doPost(HttpServletRequest req, HttpServletResponse resp) {\r
         EventLogRecord elr = new EventLogRecord(req);\r
         if (!isAuthorizedForInternal(req)) {\r
-            elr.setMessage("Unauthorized.");\r
+            elr.setMessage(UNAUTHORIZED);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
             eventlogger.error(elr.toString());\r
-            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);\r
+            sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);\r
             return;\r
         }\r
         if (isProxyOK(req) && isProxyServer()) {\r
@@ -352,7 +355,7 @@ public class RouteServlet extends ProxyServlet {
         }\r
         String path = req.getPathInfo();\r
         Insertable[] ins = null;\r
-        if (path.startsWith("/ingress/")) {\r
+        if (path.startsWith(INGRESS)) {\r
             // /internal/route/ingress/?feed=%s&amp;user=%s&amp;subnet=%s&amp;nodepatt=%s\r
             try {\r
                 // Although it probably doesn't make sense, you can install two identical routes in the IRT\r
@@ -368,11 +371,11 @@ public class RouteServlet extends ProxyServlet {
                 int seq = (t != null) ? Integer.parseInt(t) : (IngressRoute.getMaxSequence() + 100);\r
                 ins = new Insertable[] { new IngressRoute(seq, feedid, user, subnet, NodeClass.lookupNodeNames(nodepatt)) };\r
             } catch (Exception e) {\r
-                intlogger.info(e.toString());\r
+                intlogger.info(e.toString(), e);\r
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add ingress' command.", intlogger);\r
                 return;\r
             }\r
-        } else if (path.startsWith("/egress/")) {\r
+        } else if (path.startsWith(EGRESS)) {\r
             // /internal/route/egress/?sub=%s&amp;node=%s\r
             try {\r
                 int subid = Integer.parseInt(req.getParameter("sub"));\r
@@ -384,11 +387,11 @@ public class RouteServlet extends ProxyServlet {
                 String node = NodeClass.normalizeNodename(req.getParameter("node"));\r
                 ins = new Insertable[] { new EgressRoute(subid, node) };\r
             } catch (Exception e) {\r
-                intlogger.info(e.toString());\r
+                intlogger.info(e.toString(), e);\r
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add egress' command.", intlogger);\r
                 return;\r
             }\r
-        } else if (path.startsWith("/network/")) {\r
+        } else if (path.startsWith(NETWORK)) {\r
             // /internal/route/network/?from=%s&amp;to=%s&amp;via=%s\r
             try {\r
                 String nfrom = req.getParameter("from");\r
@@ -410,13 +413,13 @@ public class RouteServlet extends ProxyServlet {
                 }\r
                 ins = new Insertable[] { nr };\r
             } catch (IllegalArgumentException e) {\r
-                intlogger.info(e.toString());\r
+                intlogger.info(e.toString(), e);\r
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add network' command.", intlogger);\r
                 return;\r
             }\r
         }\r
         if (ins == null) {\r
-            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", intlogger);\r
+            sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, intlogger);\r
             return;\r
         }\r
         boolean rv = true;\r
index 34ba5d3..9cbce0a 100755 (executable)
@@ -57,8 +57,9 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
 public class StatisticsServlet extends BaseServlet {\r
 \r
   private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);\r
-  private static final String fmt1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
-  private static final String fmt2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
+  private static final String FMT1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";\r
+  private static final String FMT2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";\r
+\r
 \r
 \r
   /**\r
@@ -92,97 +93,83 @@ public class StatisticsServlet extends BaseServlet {
     resp.setContentType(LOGLIST_CONTENT_TYPE);\r
 \r
     String outputType = "json";\r
-    String feedids = null;\r
 \r
-    if (req.getParameter("feedid") == null && req.getParameter("groupid") == null) {\r
+    if (req.getParameter(FEEDID) == null && req.getParameter(GROUPID) == null) {\r
       try {\r
         resp.getOutputStream().print("Invalid request, Feedid or Group ID is required.");\r
       } catch (IOException ioe) {\r
-        eventlogger.error("IOException: " + ioe.getMessage());\r
+        eventlogger.error("PROV0171 StatisticsServlet.doGet: " + ioe.getMessage(), ioe);\r
       }\r
     }\r
 \r
-    if (req.getParameter("feedid") != null && req.getParameter("groupid") == null) {\r
-      map.put("feedids", req.getParameter("feedid").replace("|", ",").toString());\r
+    if (req.getParameter(FEEDID) != null && req.getParameter(GROUPID) == null) {\r
+      map.put(FEEDIDS, req.getParameter(FEEDID).replace("|", ","));\r
     }\r
 \r
-    if (req.getParameter("groupid") != null && req.getParameter("feedid") == null) {\r
+    if (req.getParameter(GROUPID) != null && req.getParameter(FEEDID) == null) {\r
       StringBuffer groupid1 = new StringBuffer();\r
 \r
       try {\r
-        System.out.println("feeedidsssssssss");\r
-        groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter("groupid")));\r
-        System.out.println("feeedids" + req.getParameter("groupid"));\r
-\r
-        map.put("feedids", groupid1.toString());\r
-        System.out.println("groupid1" + groupid1.toString());\r
-\r
-\r
+        groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter(GROUPID)));\r
+        map.put(FEEDIDS, groupid1.toString());\r
       } catch (NumberFormatException | SQLException e) {\r
-        eventlogger.error(e.getMessage());\r
+        eventlogger.error("PROV0172 StatisticsServlet.doGet: " + e.getMessage(), e);\r
       }\r
     }\r
-    if (req.getParameter("groupid") != null && req.getParameter("feedid") != null) {\r
+    if (req.getParameter(GROUPID) != null && req.getParameter(FEEDID) != null) {\r
       StringBuffer groupid1 = new StringBuffer();\r
 \r
       try {\r
-        System.out.println("both r not null");\r
-        groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter("groupid")));\r
-        System.out.println("feeedids" + req.getParameter("groupid"));\r
+        groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter(GROUPID)));\r
         groupid1.append(",");\r
-        groupid1.append(req.getParameter("feedid").replace("|", ",").toString());\r
-\r
-        map.put("feedids", groupid1.toString());\r
-\r
-        System.out.println("groupid1" + groupid1.toString());\r
-\r
-\r
+        groupid1.append(req.getParameter(FEEDID).replace("|", ","));\r
+        map.put(FEEDIDS, groupid1.toString());\r
       } catch (NumberFormatException | SQLException e) {\r
-        eventlogger.error(e.getMessage());\r
+        eventlogger.error("PROV0173 StatisticsServlet.doGet: " + e.getMessage(), e);\r
       }\r
     }\r
 \r
-    if (req.getParameter("subid") != null && req.getParameter("feedid") != null) {\r
+    if (req.getParameter(SUBID) != null && req.getParameter(FEEDID) != null) {\r
       StringBuffer subidstr = new StringBuffer();\r
       subidstr.append("and e.DELIVERY_SUBID in(");\r
 \r
-      subidstr.append(req.getParameter("subid").replace("|", ",").toString());\r
+      subidstr.append(req.getParameter(SUBID).replace("|", ","));\r
       subidstr.append(")");\r
-      map.put("subid", subidstr.toString());\r
+      map.put(SUBID, subidstr.toString());\r
     }\r
-    if (req.getParameter("subid") != null && req.getParameter("groupid") != null) {\r
+    if (req.getParameter(SUBID) != null && req.getParameter(GROUPID) != null) {\r
       StringBuffer subidstr = new StringBuffer();\r
       subidstr.append("and e.DELIVERY_SUBID in(");\r
 \r
-      subidstr.append(req.getParameter("subid").replace("|", ",").toString());\r
+      subidstr.append(req.getParameter(SUBID).replace("|", ","));\r
       subidstr.append(")");\r
-      map.put("subid", subidstr.toString());\r
+      map.put(SUBID, subidstr.toString());\r
     }\r
     if (req.getParameter("type") != null) {\r
-      map.put("eventType", req.getParameter("type").replace("|", ",").toString());\r
+      map.put(EVENT_TYPE, req.getParameter("type").replace("|", ","));\r
     }\r
-    if (req.getParameter("output_type") != null) {\r
-      map.put("output_type", req.getParameter("output_type").toString());\r
+    if (req.getParameter(OUTPUT_TYPE) != null) {\r
+      map.put(OUTPUT_TYPE, req.getParameter(OUTPUT_TYPE));\r
     }\r
-    if (req.getParameter("start_time") != null) {\r
-      map.put("start_time", req.getParameter("start_time").toString());\r
+    if (req.getParameter(START_TIME) != null) {\r
+      map.put(START_TIME, req.getParameter(START_TIME));\r
     }\r
-    if (req.getParameter("end_time") != null) {\r
-      map.put("end_time", req.getParameter("end_time").toString());\r
+    if (req.getParameter(END_TIME) != null) {\r
+      map.put(END_TIME, req.getParameter(END_TIME));\r
     }\r
 \r
     if (req.getParameter("time") != null) {\r
-      map.put("start_time", req.getParameter("time").toString());\r
-      map.put("end_time", null);\r
+      map.put(START_TIME, req.getParameter("time"));\r
+      map.put(END_TIME, null);\r
     }\r
 \r
-    if (req.getParameter("output_type") != null) {\r
-      outputType = req.getParameter("output_type");\r
+    if (req.getParameter(OUTPUT_TYPE) != null) {\r
+      outputType = req.getParameter(OUTPUT_TYPE);\r
     }\r
     try {\r
       this.getRecordsForSQL(map, outputType, resp.getOutputStream(), resp);\r
     } catch (IOException ioe) {\r
-      eventlogger.error("IOException: " + ioe.getMessage());\r
+      eventlogger.error("PROV0174 StatisticsServlet.doGet: " +  ioe.getMessage(), ioe);\r
     }\r
 \r
   }\r
@@ -238,7 +225,7 @@ public class StatisticsServlet extends BaseServlet {
    */\r
   public void rsToJson(ResultSet rs, ServletOutputStream out) throws IOException, SQLException {\r
 \r
-    String fields[] = {"FEEDNAME", "FEEDID", "FILES_PUBLISHED", "PUBLISH_LENGTH", "FILES_DELIVERED",\r
+    String[] fields = {"FEEDNAME", "FEEDID", "FILES_PUBLISHED", "PUBLISH_LENGTH", "FILES_DELIVERED",\r
         "DELIVERED_LENGTH", "SUBSCRIBER_URL", "SUBID", "PUBLISH_TIME", "DELIVERY_TIME",\r
         "AverageDelay"};\r
     StringBuffer line = new StringBuffer();\r
@@ -271,7 +258,6 @@ public class StatisticsServlet extends BaseServlet {
 \r
     DB db = null;\r
     Connection conn = null;\r
-    //PreparedStatement prepareStatement = null;\r
     ResultSet resultSet = null;\r
     String sqlGoupid = null;\r
     StringBuffer feedIds = new StringBuffer();\r
@@ -291,7 +277,7 @@ public class StatisticsServlet extends BaseServlet {
           System.out.println("feedIds" + feedIds.toString());\r
       }\r
     } catch (SQLException e) {\r
-      eventlogger.error(e.getMessage());\r
+      eventlogger.error("PROV0175 StatisticsServlet.getFeedIdsByGroupId: " + e.getMessage(), e);\r
     } finally {\r
       try {\r
         if (resultSet != null) {\r
@@ -302,7 +288,7 @@ public class StatisticsServlet extends BaseServlet {
           db.release(conn);\r
         }\r
       } catch (Exception e) {\r
-        eventlogger.error(e.getMessage());\r
+        eventlogger.error("PROV0176 StatisticsServlet.getFeedIdsByGroupId: " + e.getMessage(), e);\r
       }\r
     }\r
     return feedIds;\r
@@ -322,23 +308,23 @@ public class StatisticsServlet extends BaseServlet {
     String start_time = null;\r
     String end_time = null;\r
     String subid = " ";\r
-    if (map.get("eventType") != null) {\r
-      eventType = (String) map.get("eventType");\r
+    if (map.get(EVENT_TYPE) != null) {\r
+      eventType =  map.get(EVENT_TYPE);\r
     }\r
-    if (map.get("feedids") != null) {\r
-      feedids = (String) map.get("feedids");\r
+    if (map.get(FEEDIDS) != null) {\r
+      feedids = map.get(FEEDIDS);\r
     }\r
-    if (map.get("start_time") != null) {\r
-      start_time = (String) map.get("start_time");\r
+    if (map.get(START_TIME) != null) {\r
+      start_time = map.get(START_TIME);\r
     }\r
-    if (map.get("end_time") != null) {\r
-      end_time = (String) map.get("end_time");\r
+    if (map.get(END_TIME) != null) {\r
+      end_time =  map.get(END_TIME);\r
     }\r
     if ("all".equalsIgnoreCase(eventType)) {\r
       eventType = "PUB','DEL, EXP, PBF";\r
     }\r
-    if (map.get("subid") != null) {\r
-      subid = (String) map.get("subid");\r
+    if (map.get(SUBID) != null) {\r
+      subid = map.get(SUBID);\r
     }\r
 \r
     eventlogger.info("Generating sql query to get Statistics resultset. ");\r
@@ -425,10 +411,10 @@ public class StatisticsServlet extends BaseServlet {
   }\r
 \r
   private Map<String, String> buildMapFromRequest(HttpServletRequest req) {\r
-    Map<String, String> map = new HashMap<String, String>();\r
+    Map<String, String> map = new HashMap<>();\r
     String s = req.getParameter("type");\r
     if (s != null) {\r
-      if (s.equals("pub") || s.equals("del") || s.equals("exp")) {\r
+      if ("pub".equals(s) || "del".equals(s) || "exp".equals(s)) {\r
         map.put("type", s);\r
       } else {\r
         map.put("err", "bad type");\r
@@ -440,7 +426,7 @@ public class StatisticsServlet extends BaseServlet {
     map.put("publishSQL", "");\r
     map.put("statusSQL", "");\r
     map.put("resultSQL", "");\r
-    map.put("reasonSQL", "");\r
+    map.put(REASON_SQL, "");\r
 \r
     s = req.getParameter("publishId");\r
     if (s != null) {\r
@@ -454,11 +440,11 @@ public class StatisticsServlet extends BaseServlet {
     s = req.getParameter("statusCode");\r
     if (s != null) {\r
       String sql = null;\r
-      if (s.equals("success")) {\r
+      if ("success".equals(s)) {\r
         sql = " AND STATUS >= 200 AND STATUS < 300";\r
-      } else if (s.equals("redirect")) {\r
+      } else if ("redirect".equals(s)) {\r
         sql = " AND STATUS >= 300 AND STATUS < 400";\r
-      } else if (s.equals("failure")) {\r
+      } else if ("failure".equals(s)) {\r
         sql = " AND STATUS >= 400";\r
       } else {\r
         try {\r
@@ -480,14 +466,14 @@ public class StatisticsServlet extends BaseServlet {
     s = req.getParameter("expiryReason");\r
     if (s != null) {\r
       map.put("type", "exp");\r
-      if (s.equals("notRetryable")) {\r
-        map.put("reasonSQL", " AND REASON = 'notRetryable'");\r
-      } else if (s.equals("retriesExhausted")) {\r
-        map.put("reasonSQL", " AND REASON = 'retriesExhausted'");\r
-      } else if (s.equals("diskFull")) {\r
-        map.put("reasonSQL", " AND REASON = 'diskFull'");\r
-      } else if (s.equals("other")) {\r
-        map.put("reasonSQL", " AND REASON = 'other'");\r
+      if ("notRetryable".equals(s)) {\r
+        map.put(REASON_SQL, " AND REASON = 'notRetryable'");\r
+      } else if ("retriesExhausted".equals(s)) {\r
+        map.put(REASON_SQL, " AND REASON = 'retriesExhausted'");\r
+      } else if ("diskFull".equals(s)) {\r
+        map.put(REASON_SQL, " AND REASON = 'diskFull'");\r
+      } else if ("other".equals("other")) {\r
+        map.put(REASON_SQL, " AND REASON = 'other'");\r
       } else {\r
         map.put("err", "bad expiryReason");\r
         return map;\r
@@ -522,7 +508,7 @@ public class StatisticsServlet extends BaseServlet {
     }\r
     try {\r
       // First, look for an RFC 3339 date\r
-      String fmt = (s.indexOf('.') > 0) ? fmt2 : fmt1;\r
+      String fmt = (s.indexOf('.') > 0) ? FMT2 : FMT1;\r
       SimpleDateFormat sdf = new SimpleDateFormat(fmt);\r
       Date d = sdf.parse(s);\r
       return d.getTime();\r
@@ -530,8 +516,7 @@ public class StatisticsServlet extends BaseServlet {
     }\r
     try {\r
       // Also allow a long (in ms); useful for testing\r
-      long n = Long.parseLong(s);\r
-      return n;\r
+      return Long.parseLong(s);\r
     } catch (NumberFormatException e) {\r
     }\r
     intlogger.info("Error parsing time=" + s);\r
@@ -548,7 +533,7 @@ public class StatisticsServlet extends BaseServlet {
       DB db = new DB();\r
       try (Connection conn = db.getConnection()) {\r
         try (ResultSet rs = conn.prepareStatement(filterQuery).executeQuery()) {\r
-          if (outputType.equals("csv")) {\r
+          if ("csv".equals(outputType)) {\r
             resp.setContentType("application/octet-stream");\r
             Date date = new Date();\r
             SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");\r
index 69451a3..8e70e69 100644 (file)
@@ -112,7 +112,7 @@ public class SubscribeServlet extends ProxyServlet {
             }
             int feedid = getIdFromPath(req);
             if (feedid < 0) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -121,7 +121,7 @@ public class SubscribeServlet extends ProxyServlet {
             }
             Feed feed = Feed.getFeedById(feedid);
             if (feed == null || feed.isDeleted()) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -140,7 +140,7 @@ public class SubscribeServlet extends ProxyServlet {
             try {
                 resp.getOutputStream().print(t);
             } catch (IOException ioe) {
-                eventlogger.error("IOException: " + ioe.getMessage());
+                eventlogger.error("PROV0181 SubscribeServlet.doGet: " + ioe.getMessage(), ioe);
             }
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
@@ -201,7 +201,7 @@ public class SubscribeServlet extends ProxyServlet {
             }
             int feedid = getIdFromPath(req);
             if (feedid < 0) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -210,7 +210,7 @@ public class SubscribeServlet extends ProxyServlet {
             }
             Feed feed = Feed.getFeedById(feedid);
             if (feed == null || feed.isDeleted()) {
-                message = "Missing or bad feed number.";
+                message = MISSING_FEED;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);
                 eventlogger.error(elr.toString());
@@ -220,7 +220,7 @@ public class SubscribeServlet extends ProxyServlet {
             // check content type is SUB_CONTENT_TYPE, version 1.0
             ContentHeader ch = getContentHeader(req);
             String ver = ch.getAttribute("version");
-            if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+            if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
                 intlogger.debug("Content-type is: " + req.getHeader("Content-Type"));
                 message = "Incorrect content-type";
                 elr.setMessage(message);
@@ -231,7 +231,7 @@ public class SubscribeServlet extends ProxyServlet {
             }
             JSONObject jo = getJSONfromInput(req);
             if (jo == null) {
-                message = "Badly formed JSON";
+                message = BAD_JSON;
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
                 eventlogger.error(elr.toString());
@@ -258,7 +258,7 @@ public class SubscribeServlet extends ProxyServlet {
                 message = e.getMessage();
                 elr.setMessage(message);
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
-                eventlogger.error(elr.toString());
+                eventlogger.error(elr.toString(), e);
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
                 return;
             }
@@ -271,14 +271,14 @@ public class SubscribeServlet extends ProxyServlet {
              */
             String feedAafInstance = feed.getAafInstance();
             String subAafInstance = sub.getAafInstance();
-            boolean subAafLegacyEmptyOrNull = (subAafInstance == null || subAafInstance.equals("") || subAafInstance.equalsIgnoreCase("legacy"));
+            boolean subAafLegacyEmptyOrNull = (subAafInstance == null || "".equals(subAafInstance) || "legacy".equalsIgnoreCase(subAafInstance));
 
             // This extra check added to verify AAF feed with AAF subscriber having empty aaf instance check
-            if (feedAafInstance == null || feedAafInstance.equals("") || feedAafInstance.equalsIgnoreCase("legacy")) {
+            if (feedAafInstance == null || "".equals(feedAafInstance) || "legacy".equalsIgnoreCase(feedAafInstance)) {
                 if (subAafLegacyEmptyOrNull) {
                     AuthorizationResponse aresp = authz.decide(req);
                     if (!aresp.isAuthorized()) {
-                        message = "Policy Engine disallows access";
+                        message = POLICY_ENGINE;
                         elr.setMessage(message);
                         elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                         eventlogger.error(elr.toString());
@@ -299,7 +299,7 @@ public class SubscribeServlet extends ProxyServlet {
                 if (subAafLegacyEmptyOrNull) {
                     AuthorizationResponse aresp = authz.decide(req);
                     if (!aresp.isAuthorized()) {
-                        message = "Policy Engine disallows access.";
+                        message = POLICY_ENGINE;
                         elr.setMessage(message);
                         elr.setResult(HttpServletResponse.SC_FORBIDDEN);
                         eventlogger.error(elr.toString());
@@ -341,7 +341,7 @@ public class SubscribeServlet extends ProxyServlet {
                 try {
                     resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
                 } catch (IOException ioe) {
-                    eventlogger.error("IOException: " + ioe.getMessage());
+                    eventlogger.error("PROV0182 SubscribeServlet.doPost: " + ioe.getMessage(), ioe);
                 }
 
                 provisioningDataChanged();
index 63ff84d..125c50d 100644 (file)
@@ -63,6 +63,10 @@ public class SubscriptionServlet extends ProxyServlet {
     private static EELFLogger eelfLogger = EELFManager.getInstance()\r
         .getLogger(SubscriptionServlet.class);\r
 \r
+\r
+\r
+\r
+\r
     /**\r
      * DELETE on the &lt;subscriptionUrl&gt; -- delete a subscription. See the <i>Deleting a Subscription</i> section in\r
      * the <b>Provisioning API</b> document for details on how this method should be invoked.\r
@@ -88,7 +92,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             String bhdr = req.getHeader(BEHALF_HEADER);\r
             if (bhdr == null) {\r
-                message = "Missing " + BEHALF_HEADER + " header.";\r
+                message = MISSING_ON_BEHALF;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -97,7 +101,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             int subid = getIdFromPath(req);\r
             if (subid < 0) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -106,7 +110,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             Subscription sub = Subscription.getSubscriptionById(subid);\r
             if (sub == null) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);\r
                 eventlogger.error(elr.toString());\r
@@ -119,10 +123,10 @@ public class SubscriptionServlet extends ProxyServlet {
              * CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove subscription\r
              */\r
             String aafInstance = sub.getAafInstance();\r
-            if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {\r
+            if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {\r
                 AuthorizationResponse aresp = authz.decide(req);\r
                 if (!aresp.isAuthorized()) {\r
-                    message = "Policy Engine disallows access.";\r
+                    message = POLICY_ENGINE;\r
                     elr.setMessage(message);\r
                     elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
                     eventlogger.error(elr.toString());\r
@@ -189,7 +193,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             String bhdr = req.getHeader(BEHALF_HEADER);\r
             if (bhdr == null) {\r
-                message = "Missing " + BEHALF_HEADER + " header.";\r
+                message = MISSING_ON_BEHALF;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -198,7 +202,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             int subid = getIdFromPath(req);\r
             if (subid < 0) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -207,7 +211,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             Subscription sub = Subscription.getSubscriptionById(subid);\r
             if (sub == null) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);\r
                 eventlogger.error(elr.toString());\r
@@ -217,7 +221,7 @@ public class SubscriptionServlet extends ProxyServlet {
             // Check with the Authorizer\r
             AuthorizationResponse aresp = authz.decide(req);\r
             if (!aresp.isAuthorized()) {\r
-                message = "Policy Engine disallows access.";\r
+                message = POLICY_ENGINE;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
                 eventlogger.error(elr.toString());\r
@@ -233,7 +237,7 @@ public class SubscriptionServlet extends ProxyServlet {
             try {\r
                 resp.getOutputStream().print(sub.asJSONObject(true).toString());\r
             } catch (IOException ioe) {\r
-                eventlogger.error("IOException: " + ioe.getMessage());\r
+                eventlogger.error("PROV0191 SubscriptionServlet.doGet: " + ioe.getMessage(), ioe);\r
             }\r
         } finally {\r
             eelfLogger.info(EelfMsgs.EXIT);\r
@@ -265,7 +269,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             String bhdr = req.getHeader(BEHALF_HEADER);\r
             if (bhdr == null) {\r
-                message = "Missing " + BEHALF_HEADER + " header.";\r
+                message = MISSING_ON_BEHALF;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -274,7 +278,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             int subid = getIdFromPath(req);\r
             if (subid < 0) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -283,7 +287,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             Subscription oldsub = Subscription.getSubscriptionById(subid);\r
             if (oldsub == null) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_NOT_FOUND);\r
                 eventlogger.error(elr.toString());\r
@@ -293,7 +297,7 @@ public class SubscriptionServlet extends ProxyServlet {
             // check content type is SUB_CONTENT_TYPE, version 1.0\r
             ContentHeader ch = getContentHeader(req);\r
             String ver = ch.getAttribute("version");\r
-            if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {\r
+            if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {\r
                 message = "Incorrect content-type";\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);\r
@@ -303,7 +307,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             JSONObject jo = getJSONfromInput(req);\r
             if (jo == null) {\r
-                message = "Badly formed JSON";\r
+                message = BAD_JSON;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -320,7 +324,7 @@ public class SubscriptionServlet extends ProxyServlet {
                 message = e.getMessage();\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
-                eventlogger.error(elr.toString());\r
+                eventlogger.error(elr.toString(), e);\r
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);\r
                 return;\r
             }\r
@@ -331,10 +335,10 @@ public class SubscriptionServlet extends ProxyServlet {
              * CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove subscription\r
              */\r
             String aafInstance = sub.getAafInstance();\r
-            if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {\r
+            if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {\r
                 AuthorizationResponse aresp = authz.decide(req);\r
                 if (!aresp.isAuthorized()) {\r
-                    message = "Policy Engine disallows access.";\r
+                    message = POLICY_ENGINE;\r
                     elr.setMessage(message);\r
                     elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
                     eventlogger.error(elr.toString());\r
@@ -380,7 +384,7 @@ public class SubscriptionServlet extends ProxyServlet {
                 try {\r
                     resp.getOutputStream().print(sub.asLimitedJSONObject().toString());\r
                 } catch (IOException ioe) {\r
-                    eventlogger.error("IOException: " + ioe.getMessage());\r
+                    eventlogger.error("PROV0192 SubscriptionServlet.doPut: " + ioe.getMessage(), ioe);\r
                 }\r
 \r
                 /**Change Owner ship of Subscriber     Adding for group feature:Rally US708115*/\r
@@ -392,7 +396,7 @@ public class SubscriptionServlet extends ProxyServlet {
                             sub.changeOwnerShip();\r
                         }\r
                     } catch (JSONException je) {\r
-                        eventlogger.error("JSONException: " + je.getMessage());\r
+                        eventlogger.error("PROV0193 SubscriptionServlet.doPut: " + je.getMessage(), je);\r
                     }\r
                 }\r
                 /***End of change ownership*/\r
@@ -435,7 +439,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             String bhdr = req.getHeader(BEHALF_HEADER);\r
             if (bhdr == null) {\r
-                message = "Missing " + BEHALF_HEADER + " header.";\r
+                message = MISSING_ON_BEHALF;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -444,7 +448,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             final int subid = getIdFromPath(req);\r
             if (subid < 0 || Subscription.getSubscriptionById(subid) == null) {\r
-                message = "Missing or bad subscription number.";\r
+                message = BAD_SUB;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -454,7 +458,7 @@ public class SubscriptionServlet extends ProxyServlet {
             // check content type is SUBCNTRL_CONTENT_TYPE, version 1.0\r
             ContentHeader ch = getContentHeader(req);\r
             String ver = ch.getAttribute("version");\r
-            if (!ch.getType().equals(SUBCNTRL_CONTENT_TYPE) || !ver.equals("1.0")) {\r
+            if (!ch.getType().equals(SUBCNTRL_CONTENT_TYPE) || !"1.0".equals(ver)) {\r
                 message = "Incorrect content-type";\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);\r
@@ -465,7 +469,7 @@ public class SubscriptionServlet extends ProxyServlet {
             // Check with the Authorizer\r
             AuthorizationResponse aresp = authz.decide(req);\r
             if (!aresp.isAuthorized()) {\r
-                message = "Policy Engine disallows access.";\r
+                message = POLICY_ENGINE;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
                 eventlogger.error(elr.toString());\r
@@ -474,7 +478,7 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
             JSONObject jo = getJSONfromInput(req);\r
             if (jo == null) {\r
-                message = "Badly formed JSON";\r
+                message = BAD_JSON;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
                 eventlogger.error(elr.toString());\r
@@ -496,10 +500,10 @@ public class SubscriptionServlet extends ProxyServlet {
                 eventlogger.info(elr.toString());\r
                 resp.setStatus(HttpServletResponse.SC_ACCEPTED);\r
             } catch (JSONException e) {\r
-                message = "Badly formed JSON";\r
+                message = BAD_JSON;\r
                 elr.setMessage(message);\r
                 elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
-                eventlogger.error(elr.toString());\r
+                eventlogger.error(elr.toString(), e);\r
                 sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);\r
             }\r
         } finally {\r
@@ -514,7 +518,7 @@ public class SubscriptionServlet extends ProxyServlet {
     public class SubscriberNotifyThread extends Thread {\r
 \r
         public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";\r
-        private List<String> urls = new Vector<String>();\r
+        private List<String> urls = new Vector<>();\r
 \r
         public SubscriberNotifyThread() {\r
             setName("SubscriberNotifyThread");\r
@@ -527,7 +531,9 @@ public class SubscriptionServlet extends ProxyServlet {
             }\r
         }\r
 \r
+        @Override\r
         public void run() {\r
+\r
             try {\r
                 while (!urls.isEmpty()) {\r
                     String u = urls.remove(0);\r
@@ -538,11 +544,11 @@ public class SubscriptionServlet extends ProxyServlet {
                         conn.getContentLength();    // Force the GET through\r
                         conn.disconnect();\r
                     } catch (IOException e) {\r
-                        intlogger.info("IOException Error accessing URL: " + u + ": " + e.getMessage());\r
+                        intlogger.info("PROV0194 Error accessing URL: " + u + ": " + e.getMessage(), e);\r
                     }\r
                 }\r
             } catch (Exception e) {\r
-                intlogger.warn("Caught exception in SubscriberNotifyThread: " + e.getMessage());\r
+                intlogger.warn("PROV0195 Caught exception in SubscriberNotifyThread: " + e.getMessage(), e);\r
             }\r
         }\r
     }\r
index 3097a9d..8c5a49a 100644 (file)
 
 package org.onap.dmaap.datarouter.provisioning;
 
+import static org.onap.dmaap.datarouter.provisioning.BaseServlet.TEXT_CT;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -50,8 +55,6 @@ import java.util.TreeSet;
 
 import javax.servlet.http.HttpServletResponse;
 
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpGet;
@@ -85,7 +88,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
  * <li>Checking DNS once per minute to see which POD the DNS CNAME points to. The CNAME will point to
  * the active (master) POD.</li>
  * <li>On non-master (standby) PODs, fetches provisioning data and logs in order to keep MariaDB in sync.</li>
- * <li>Providing information to other parts of the system as to the current role (ACTIVE, STANDBY, UNKNOWN)
+ * <li>Providing information to other parts of the system as to the current role (ACTIVE_POD, STANDBY_POD, UNKNOWN_POD)
  * of this POD.</li>
  * </ol>
  * <p>For this to work correctly, the following code needs to be placed at the beginning of main().</p>
@@ -99,167 +102,152 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
 public class SynchronizerTask extends TimerTask {
 
     /**
-     * This is a singleton -- there is only one SynchronizerTask object in the server
+     * This is a singleton -- there is only one SynchronizerTask object in the server.
      */
     private static SynchronizerTask synctask;
 
     /**
-     * This POD is unknown -- not on the list of PODs
+     * This POD is unknown -- not on the list of PODs.
      */
-    public static final int UNKNOWN = 0;
+    public static final int UNKNOWN_POD = 0;
     /**
-     * This POD is active -- on the list of PODs, and the DNS CNAME points to us
+     * This POD is active -- on the list of PODs, and the DNS CNAME points to us.
      */
-    public static final int ACTIVE = 1;
+    public static final int ACTIVE_POD = 1;
     /**
-     * This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us
+     * This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us.
      */
-    public static final int STANDBY = 2;
-    private static final String[] stnames = {"UNKNOWN", "ACTIVE", "STANDBY"};
+    public static final int STANDBY_POD = 2;
+
+    private static final String[] stnames = {"UNKNOWN_POD", "ACTIVE_POD", "STANDBY_POD"};
     private static final long ONE_HOUR = 60 * 60 * 1000L;
 
+    private long nextMsg = 0;    // only display the "Current podState" msg every 5 mins.
+
     private final EELFLogger logger;
     private final Timer rolex;
     private final String spooldir;
-    private int state;
+    private int podState;
     private boolean doFetch;
     private long nextsynctime;
     private AbstractHttpClient httpclient = null;
 
-    /**
-     * Get the singleton SynchronizerTask object.
-     *
-     * @return the SynchronizerTask
-     */
-    public static synchronized SynchronizerTask getSynchronizer() {
-        if (synctask == null) {
-            synctask = new SynchronizerTask();
-        }
-        return synctask;
-    }
-
     @SuppressWarnings("deprecation")
     private SynchronizerTask() {
         logger = EELFManager.getInstance().getLogger("InternalLog");
         rolex = new Timer();
         spooldir = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
-        state = UNKNOWN;
+        podState = UNKNOWN_POD;
         doFetch = true;        // start off with a fetch
         nextsynctime = 0;
 
-        logger.info("PROV5000: Sync task starting, server state is UNKNOWN");
+        logger.info("PROV5000: Sync task starting, server podState is UNKNOWN_POD");
         try {
             Properties props = (new DB()).getProperties();
             String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
             String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
             String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
             KeyStore keyStore = KeyStore.getInstance(type);
-            try(FileInputStream instream = new FileInputStream(new File(store))) {
+            try (FileInputStream instream = new FileInputStream(new File(store))) {
                 keyStore.load(instream, pass.toCharArray());
 
             }
-                store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
-                pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
-                KeyStore trustStore = null;
-                if (store != null && store.length() > 0) {
-                    trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
-                    try(FileInputStream instream = new FileInputStream(new File(store))){
-                        trustStore.load(instream, pass.toCharArray());
+            store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
+            pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
+            KeyStore trustStore = null;
+            if (store != null && store.length() > 0) {
+                trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+                try (FileInputStream instream = new FileInputStream(new File(store))) {
+                    trustStore.load(instream, pass.toCharArray());
 
-                    }
                 }
+            }
 
             // We are connecting with the node name, but the certificate will have the CNAME
             // So we need to accept a non-matching certificate name
-            String keystorepass = props.getProperty(
-                Main.KEYSTORE_PASS_PROPERTY); //itrack.web.att.com/browse/DATARTR-6 for changing hard coded passphase ref
-           try(AbstractHttpClient hc = new DefaultHttpClient()) {
-               SSLSocketFactory socketFactory =
-                       (trustStore == null)
-                               ? new SSLSocketFactory(keyStore, keystorepass)
-                               : new SSLSocketFactory(keyStore, keystorepass, trustStore);
-               socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
-               Scheme sch = new Scheme("https", 443, socketFactory);
-               hc.getConnectionManager().getSchemeRegistry().register(sch);
-            httpclient = hc;
-           }
-            // Run once every 5 seconds to check DNS, etc.
-            long interval = 0;
-            try {
-                String s = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000");
-                interval = Long.parseLong(s);
-            } catch (NumberFormatException e) {
-                interval = 5000L;
+            String keystorepass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
+            try (AbstractHttpClient hc = new DefaultHttpClient()) {
+                SSLSocketFactory socketFactory =
+                        (trustStore == null)
+                                ? new SSLSocketFactory(keyStore, keystorepass)
+                                : new SSLSocketFactory(keyStore, keystorepass, trustStore);
+                socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+                Scheme sch = new Scheme("https", 443, socketFactory);
+                hc.getConnectionManager().getSchemeRegistry().register(sch);
+                httpclient = hc;
             }
-            rolex.scheduleAtFixedRate(this, 0L, interval);
+            setSynchTimer(props);
         } catch (Exception e) {
             logger.warn("PROV5005: Problem starting the synchronizer: " + e);
         }
     }
 
+    private void setSynchTimer(Properties props) {
+        // Run once every 5 seconds to check DNS, etc.
+        long interval;
+        try {
+            String s = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000");
+            interval = Long.parseLong(s);
+        } catch (NumberFormatException e) {
+            interval = 5000L;
+        }
+        rolex.scheduleAtFixedRate(this, 0L, interval);
+    }
+
+    /**
+     * Get the singleton SynchronizerTask object.
+     *
+     * @return the SynchronizerTask
+     */
+    public static synchronized SynchronizerTask getSynchronizer() {
+        if (synctask == null) {
+            synctask = new SynchronizerTask();
+        }
+        return synctask;
+    }
+
     /**
-     * What is the state of this POD?
+     * What is the podState of this POD?.
      *
-     * @return one of ACTIVE, STANDBY, UNKNOWN
+     * @return one of ACTIVE_POD, STANDBY_POD, UNKNOWN_POD
      */
-    public int getState() {
-        return state;
+    public int getPodState() {
+        return podState;
     }
 
     /**
-     * Is this the active POD?
+     * Is this the active POD?.
      *
      * @return true if we are active (the master), false otherwise
      */
     public boolean isActive() {
-        return state == ACTIVE;
+        return podState == ACTIVE_POD;
     }
 
     /**
      * This method is used to signal that another POD (the active POD) has sent us a /fetchProv request, and that we
      * should re-synchronize with the master.
      */
-    public void doFetch() {
+    void doFetch() {
         doFetch = true;
     }
 
     /**
      * Runs once a minute in order to <ol>
      * <li>lookup DNS names,</li>
-     * <li>determine the state of this POD,</li>
-     * <li>if this is a standby POD, and the fetch flag is set, perform a fetch of state from the active POD.</li>
+     * <li>determine the podState of this POD,</li>
+     * <li>if this is a standby POD, and the fetch flag is set, perform a fetch of podState from the active POD.</li>
      * <li>if this is a standby POD, check if there are any new log records to be replicated.</li>
-     * </ol>
+     * </ol>.
      */
     @Override
     public void run() {
         try {
-            state = lookupState();
-            if (state == STANDBY) {
+            podState = lookupState();
+            if (podState == STANDBY_POD) {
                 // Only copy provisioning data FROM the active server TO the standby
                 if (doFetch || (System.currentTimeMillis() >= nextsynctime)) {
-                    logger.debug("Initiating a sync...");
-                    JSONObject jo = readProvisioningJSON();
-                    if (jo != null) {
-                        doFetch = false;
-                        syncFeeds(jo.getJSONArray("feeds"));
-                        syncSubs(jo.getJSONArray("subscriptions"));
-                        syncGroups(jo.getJSONArray("groups")); //Rally:US708115 - 1610
-                        syncParams(jo.getJSONObject("parameters"));
-                        // The following will not be present in a version=1.0 provfeed
-                        JSONArray ja = jo.optJSONArray("ingress");
-                        if (ja != null) {
-                            syncIngressRoutes(ja);
-                        }
-                        JSONObject j2 = jo.optJSONObject("egress");
-                        if (j2 != null) {
-                            syncEgressRoutes(j2);
-                        }
-                        ja = jo.optJSONArray("routing");
-                        if (ja != null) {
-                            syncNetworkRoutes(ja);
-                        }
-                    }
+                    syncProvisioningData();
                     logger.info("PROV5013: Sync completed.");
                     nextsynctime = System.currentTimeMillis() + ONE_HOUR;
                 }
@@ -278,7 +266,7 @@ public class SynchronizerTask extends TimerTask {
                 remote.andNot(local);
                 if (!remote.isEmpty()) {
                     logger.debug(" Replicating logs: " + remote);
-                    replicateDRLogs(remote);
+                    replicateDataRouterLogs(remote);
                 }
             }
         } catch (Exception e) {
@@ -286,14 +274,39 @@ public class SynchronizerTask extends TimerTask {
         }
     }
 
+    private void syncProvisioningData() {
+        logger.debug("Initiating a sync...");
+        JSONObject jo = readProvisioningJson();
+        if (jo != null) {
+            doFetch = false;
+            syncFeeds(jo.getJSONArray("feeds"));
+            syncSubs(jo.getJSONArray("subscriptions"));
+            syncGroups(jo.getJSONArray("groups")); //Rally:US708115 - 1610
+            syncParams(jo.getJSONObject("parameters"));
+            // The following will not be present in a version=1.0 provfeed
+            JSONArray ja = jo.optJSONArray("ingress");
+            if (ja != null) {
+                syncIngressRoutes(ja);
+            }
+            JSONObject j2 = jo.optJSONObject("egress");
+            if (j2 != null) {
+                syncEgressRoutes(j2);
+            }
+            ja = jo.optJSONArray("routing");
+            if (ja != null) {
+                syncNetworkRoutes(ja);
+            }
+        }
+    }
+
     /**
-     * This method is used to lookup the CNAME that points to the active server. It returns 0 (UNKNOWN), 1(ACTIVE), or 2
-     * (STANDBY) to indicate the state of this server.
+     * This method is used to lookup the CNAME that points to the active server.
+     * It returns 0 (UNKNOWN_POD), 1(ACTIVE_POD), or (STANDBY_POD) to indicate the podState of this server.
      *
-     * @return the current state
+     * @return the current podState
      */
-    private int lookupState() {
-        int newstate = UNKNOWN;
+    int lookupState() {
+        int newPodState = UNKNOWN_POD;
         try {
             InetAddress myaddr = InetAddress.getLocalHost();
             if (logger.isTraceEnabled()) {
@@ -303,27 +316,25 @@ public class SynchronizerTask extends TimerTask {
             Set<String> pods = new TreeSet<>(Arrays.asList(BaseServlet.getPods()));
             if (pods.contains(thisPod)) {
                 InetAddress pserver = InetAddress.getByName(BaseServlet.getActiveProvName());
-                newstate = myaddr.equals(pserver) ? ACTIVE : STANDBY;
+                newPodState = myaddr.equals(pserver) ? ACTIVE_POD : STANDBY_POD;
                 if (logger.isDebugEnabled() && System.currentTimeMillis() >= nextMsg) {
-                    logger.debug("Active POD = " + pserver + ", Current state is " + stnames[newstate]);
+                    logger.debug("Active POD = " + pserver + ", Current podState is " + stnames[newPodState]);
                     nextMsg = System.currentTimeMillis() + (5 * 60 * 1000L);
                 }
             } else {
                 logger.warn("PROV5003: My name (" + thisPod + ") is missing from the list of provisioning servers.");
             }
         } catch (UnknownHostException e) {
-            logger.warn("PROV5002: Cannot determine the name of this provisioning server.");
+            logger.warn("PROV5002: Cannot determine the name of this provisioning server.", e);
         }
 
-        if (newstate != state) {
-            logger
-                .info(String.format("PROV5001: Server state changed from %s to %s", stnames[state], stnames[newstate]));
+        if (newPodState != podState) {
+            logger.info(String.format("PROV5001: Server podState changed from %s to %s",
+                    stnames[podState], stnames[newPodState]));
         }
-        return newstate;
+        return newPodState;
     }
 
-    private static long nextMsg = 0;    // only display the "Current state" msg every 5 mins.
-
     /**
      * Synchronize the Feeds in the JSONArray, with the Feeds in the DB.
      */
@@ -334,7 +345,7 @@ public class SynchronizerTask extends TimerTask {
                 Feed f = new Feed(ja.getJSONObject(n));
                 coll.add(f);
             } catch (Exception e) {
-                logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n));
+                logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n), e);
             }
         }
         if (sync(coll, Feed.getAllFeeds())) {
@@ -355,7 +366,7 @@ public class SynchronizerTask extends TimerTask {
                 Subscription s = new Subscription(j);
                 coll.add(s);
             } catch (Exception e) {
-                logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n));
+                logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n), e);
             }
         }
         if (sync(coll, Subscription.getAllSubscriptions())) {
@@ -373,7 +384,7 @@ public class SynchronizerTask extends TimerTask {
                 Group g = new Group(ja.getJSONObject(n));
                 coll.add(g);
             } catch (Exception e) {
-                logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n));
+                logger.warn("PROV5004: Invalid object in group: " + ja.optJSONObject(n), e);
             }
         }
         if (sync(coll, Group.getAllgroups())) {
@@ -392,9 +403,11 @@ public class SynchronizerTask extends TimerTask {
             try {
                 v = jo.getString(k);
             } catch (JSONException e) {
+                logger.warn("PROV5004: Invalid object in parameters: " + jo.optJSONObject(k), e);
                 try {
                     v = "" + jo.getInt(k);
                 } catch (JSONException e1) {
+                    logger.warn("PROV5004: Invalid object in parameters: " + jo.optInt(k), e1);
                     JSONArray ja = jo.getJSONArray(k);
                     for (int i = 0; i < ja.length(); i++) {
                         if (i > 0) {
@@ -436,9 +449,9 @@ public class SynchronizerTask extends TimerTask {
                 EgressRoute er = new EgressRoute(sub, node);
                 coll.add(er);
             } catch (NumberFormatException e) {
-                logger.warn("PROV5004: Invalid subid in egress routes: " + key);
+                logger.warn("PROV5004: Invalid subid in egress routes: " + key, e);
             } catch (IllegalArgumentException e) {
-                logger.warn("PROV5004: Invalid node name in egress routes: " + key);
+                logger.warn("PROV5004: Invalid node name in egress routes: " + key, e);
             }
         }
         if (sync(coll, EgressRoute.getAllEgressRoutes())) {
@@ -453,7 +466,7 @@ public class SynchronizerTask extends TimerTask {
                 NetworkRoute nr = new NetworkRoute(ja.getJSONObject(n));
                 coll.add(nr);
             } catch (JSONException e) {
-                logger.warn("PROV5004: Invalid object in network routes: " + ja.optJSONObject(n));
+                logger.warn("PROV5004: Invalid object in network routes: " + ja.optJSONObject(n), e);
             }
         }
         if (sync(coll, NetworkRoute.getAllNetworkRoutes())) {
@@ -475,29 +488,11 @@ public class SynchronizerTask extends TimerTask {
                 Syncable newobj = newmap.get(n);
                 Syncable oldobj = oldmap.get(n);
                 if (oldobj == null) {
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("  Inserting record: " + newobj);
-                    }
-                    newobj.doInsert(conn);
-                    changes = true;
+                    changes = insertRecord(conn, newobj);
                 } else if (newobj == null) {
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("  Deleting record: " + oldobj);
-                    }
-                    oldobj.doDelete(conn);
-                    changes = true;
+                    changes = deleteRecord(conn, oldobj);
                 } else if (!newobj.equals(oldobj)) {
-                    if (logger.isDebugEnabled()) {
-                        logger.debug("  Updating record: " + newobj);
-                    }
-                    newobj.doUpdate(conn);
-
-                    /**Rally US708115
-                     * Change Ownership of FEED - 1610, Syncronised with secondary DB.
-                     * */
-                    checkChnageOwner(newobj, oldobj);
-
-                    changes = true;
+                    changes = updateRecord(conn, newobj, oldobj);
                 }
             }
             db.release(conn);
@@ -507,6 +502,30 @@ public class SynchronizerTask extends TimerTask {
         return changes;
     }
 
+    private boolean updateRecord(Connection conn, Syncable newobj, Syncable oldobj) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("  Updating record: " + newobj);
+        }
+        boolean changes = newobj.doUpdate(conn);
+        checkChangeOwner(newobj, oldobj);
+
+        return changes;
+    }
+
+    private boolean deleteRecord(Connection conn, Syncable oldobj) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("  Deleting record: " + oldobj);
+        }
+        return oldobj.doDelete(conn);
+    }
+
+    private boolean insertRecord(Connection conn, Syncable newobj) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("  Inserting record: " + newobj);
+        }
+        return newobj.doInsert(conn);
+    }
+
     private Map<String, Syncable> getMap(Collection<? extends Syncable> c) {
         Map<String, Syncable> map = new HashMap<>();
         for (Syncable v : c) {
@@ -515,18 +534,18 @@ public class SynchronizerTask extends TimerTask {
         return map;
     }
 
-    /**Change owner of FEED/SUBSCRIPTION*/
     /**
+     * Change owner of FEED/SUBSCRIPTION.
      * Rally US708115 Change Ownership of FEED - 1610
      */
-    private void checkChnageOwner(Syncable newobj, Syncable oldobj) {
+    private void checkChangeOwner(Syncable newobj, Syncable oldobj) {
         if (newobj instanceof Feed) {
             Feed oldfeed = (Feed) oldobj;
             Feed newfeed = (Feed) newobj;
 
             if (!oldfeed.getPublisher().equals(newfeed.getPublisher())) {
-                logger.info("PROV5013 -  Previous publisher: " + oldfeed.getPublisher() + ": New publisher-" + newfeed
-                    .getPublisher());
+                logger.info("PROV5013 -  Previous publisher: "
+                                    + oldfeed.getPublisher() + ": New publisher-" + newfeed.getPublisher());
                 oldfeed.setPublisher(newfeed.getPublisher());
                 oldfeed.changeOwnerShip();
             }
@@ -535,8 +554,8 @@ public class SynchronizerTask extends TimerTask {
             Subscription newsub = (Subscription) newobj;
 
             if (!oldsub.getSubscriber().equals(newsub.getSubscriber())) {
-                logger.info("PROV5013 -  Previous subscriber: " + oldsub.getSubscriber() + ": New subscriber-" + newsub
-                    .getSubscriber());
+                logger.info("PROV5013 -  Previous subscriber: "
+                                    + oldsub.getSubscriber() + ": New subscriber-" + newsub.getSubscriber());
                 oldsub.setSubscriber(newsub.getSubscriber());
                 oldsub.changeOwnerShip();
             }
@@ -549,26 +568,26 @@ public class SynchronizerTask extends TimerTask {
      *
      * @return the provisioning data (as a JONObject)
      */
-    private synchronized JSONObject readProvisioningJSON() {
+    private synchronized JSONObject readProvisioningJson() {
         String url = URLUtilities.generatePeerProvURL();
         HttpGet get = new HttpGet(url);
         try {
             HttpResponse response = httpclient.execute(get);
             int code = response.getStatusLine().getStatusCode();
             if (code != HttpServletResponse.SC_OK) {
-                logger.warn("PROV5010: readProvisioningJSON failed, bad error code: " + code);
+                logger.warn("PROV5010: readProvisioningJson failed, bad error code: " + code);
                 return null;
             }
             HttpEntity entity = response.getEntity();
             String ctype = entity.getContentType().getValue().trim();
-            if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1) && !ctype
-                .equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
-                logger.warn("PROV5011: readProvisioningJSON failed, bad content type: " + ctype);
+            if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1)
+                        && !ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
+                logger.warn("PROV5011: readProvisioningJson failed, bad content type: " + ctype);
                 return null;
             }
             return new JSONObject(new JSONTokener(entity.getContent()));
         } catch (Exception e) {
-            logger.warn("PROV5012: readProvisioningJSON failed, exception: " + e);
+            logger.warn("PROV5012: readProvisioningJson failed, exception: " + e);
             return null;
         } finally {
             get.releaseConnection();
@@ -581,18 +600,18 @@ public class SynchronizerTask extends TimerTask {
      *
      * @return the bitset
      */
-    private RLEBitSet readRemoteLoglist() {
+    RLEBitSet readRemoteLoglist() {
         RLEBitSet bs = new RLEBitSet();
         String url = URLUtilities.generatePeerLogsURL();
 
         //Fixing if only one Prov is configured, not to give exception to fill logs, return empty bitset.
-        if (url.equals("")) {
+        if ("".equals(url)) {
             return bs;
         }
         //End of fix.
 
         HttpGet get = new HttpGet(url);
-        try {
+        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
             HttpResponse response = httpclient.execute(get);
             int code = response.getStatusLine().getStatusCode();
             if (code != HttpServletResponse.SC_OK) {
@@ -601,13 +620,12 @@ public class SynchronizerTask extends TimerTask {
             }
             HttpEntity entity = response.getEntity();
             String ctype = entity.getContentType().getValue().trim();
-            if (!ctype.equals("text/plain")) {
+            if (!TEXT_CT.equals(ctype)) {
                 logger.warn("PROV5011: readRemoteLoglist failed, bad content type: " + ctype);
                 return bs;
             }
             InputStream is = entity.getContent();
-            ByteArrayOutputStream bos = new ByteArrayOutputStream();
-            int ch = 0;
+            int ch;
             while ((ch = is.read()) >= 0) {
                 bos.write(ch);
             }
@@ -628,12 +646,12 @@ public class SynchronizerTask extends TimerTask {
      *
      * @param bs the bitset (an RELBitSet) of log records to fetch
      */
-    private void replicateDRLogs(RLEBitSet bs) {
+    void replicateDataRouterLogs(RLEBitSet bs) {
         String url = URLUtilities.generatePeerLogsURL();
         HttpPost post = new HttpPost(url);
         try {
             String t = bs.toString();
-            HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create("text/plain"));
+            HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create(TEXT_CT));
             post.setEntity(body);
             if (logger.isDebugEnabled()) {
                 logger.debug("Requesting records: " + t);
@@ -642,13 +660,13 @@ public class SynchronizerTask extends TimerTask {
             HttpResponse response = httpclient.execute(post);
             int code = response.getStatusLine().getStatusCode();
             if (code != HttpServletResponse.SC_OK) {
-                logger.warn("PROV5010: replicateDRLogs failed, bad error code: " + code);
+                logger.warn("PROV5010: replicateDataRouterLogs failed, bad error code: " + code);
                 return;
             }
             HttpEntity entity = response.getEntity();
             String ctype = entity.getContentType().getValue().trim();
-            if (!ctype.equals("text/plain")) {
-                logger.warn("PROV5011: replicateDRLogs failed, bad content type: " + ctype);
+            if (!TEXT_CT.equals(ctype)) {
+                logger.warn("PROV5011: replicateDataRouterLogs failed, bad content type: " + ctype);
                 return;
             }
 
@@ -659,7 +677,7 @@ public class SynchronizerTask extends TimerTask {
             Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
             logger.info("Approximately " + bs.cardinality() + " records replicated.");
         } catch (Exception e) {
-            logger.warn("PROV5012: replicateDRLogs failed, exception: " + e);
+            logger.warn("PROV5012: replicateDataRouterLogs failed, exception: " + e);
         } finally {
             post.releaseConnection();
         }
index 2a959f3..0e5342a 100644 (file)
@@ -44,12 +44,7 @@ public class DeliveryExtraRecord extends BaseLogRecord {
         this.subid = Integer.parseInt(pp[4]);\r
         this.contentLength2 = Long.parseLong(pp[6]);\r
     }\r
-    public DeliveryExtraRecord(ResultSet rs) throws SQLException {\r
-        super(rs);\r
-        // Note: because this record should be "rare" these fields are mapped to unconventional fields in the DB\r
-        this.subid  = rs.getInt("DELIVERY_SUBID");\r
-        this.contentLength2 = rs.getInt("CONTENT_LENGTH_2");\r
-    }\r
+\r
     @Override\r
     public void load(PreparedStatement ps) throws SQLException {\r
         ps.setString(1, "dlx");        // field 1: type\r
index 1213596..e766e70 100644 (file)
@@ -47,6 +47,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
 public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+    private static final String SQLEXCEPTION = "SQLException: ";\r
     private final int subid;\r
     private final int nodeid;\r
 \r
@@ -57,7 +58,7 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
      * @return the sorted set\r
      */\r
     public static SortedSet<EgressRoute> getAllEgressRoutes() {\r
-        SortedSet<EgressRoute> set = new TreeSet<EgressRoute>();\r
+        SortedSet<EgressRoute> set = new TreeSet<>();\r
         try {\r
             DB db = new DB();\r
             @SuppressWarnings("resource")\r
@@ -74,7 +75,7 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
 \r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0008 EgressRoute.getAllEgressRoutes: " + e.getMessage(), e);\r
         }\r
         return set;\r
     }\r
@@ -104,20 +105,20 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
             ps.close();\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0009 EgressRoute.getEgressRoute: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return v;\r
     }\r
 \r
-    public EgressRoute(int subid, int nodeid) throws IllegalArgumentException {\r
+    public EgressRoute(int subid, int nodeid) {\r
         this.subid = subid;\r
         this.nodeid = nodeid;\r
 // Note: unlike for Feeds, it subscriptions can be removed from the tables, so it is\r
@@ -126,7 +127,7 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
 //            throw new IllegalArgumentException("No such subscription: "+subid);\r
     }\r
 \r
-    public EgressRoute(int subid, String node) throws IllegalArgumentException {\r
+    public EgressRoute(int subid, String node) {\r
         this(subid, lookupNodeName(node));\r
     }\r
 \r
@@ -141,15 +142,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -169,14 +169,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
             ps.close();\r
             rv = true;\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
+            intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -194,14 +194,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
index 506821e..1cfd0f6 100644 (file)
@@ -47,6 +47,7 @@ import java.util.*;
 public class Feed extends Syncable {\r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
     private static int next_feedid = getMaxFeedID() + 1;\r
+    private static final String SQLEXCEPTION = "SQLException: ";\r
 \r
     private int feedid;\r
     private int groupid; //New field is added - Groups feature Rally:US708115 - 1610\r
@@ -85,7 +86,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0024 Feed.isFeedValid: ", e.getMessage());\r
+            intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);\r
         }\r
         return count != 0;\r
     }\r
@@ -135,7 +136,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0025 Feed.countActiveFeeds: ", e.getMessage());\r
+            intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);\r
         }\r
         return count;\r
     }\r
@@ -155,7 +156,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0026 Feed.getMaxFeedID: ", e.getMessage());\r
+            intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);\r
         }\r
         return max;\r
     }\r
@@ -201,7 +202,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0027 Feed.getAllFeeds: ", e.getMessage());\r
+            intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);\r
         }\r
         return map.values();\r
     }\r
@@ -235,7 +236,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: ", e.getMessage());\r
+            intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);\r
         }\r
         return list;\r
     }\r
@@ -272,7 +273,7 @@ public class Feed extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0029 Feed.getFeedBySQL: ", e.getMessage());\r
+            intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);\r
         }\r
         return feed;\r
     }\r
@@ -338,6 +339,7 @@ public class Feed extends Syncable {
             try {\r
                 this.version = jo.getString("version");\r
             } catch (JSONException e) {\r
+                intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);\r
                 this.version = null;\r
             }\r
             if(version != null && version.length() > 20)\r
@@ -379,11 +381,10 @@ public class Feed extends Syncable {
             JSONObject jol = jo.optJSONObject("links");\r
             this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));\r
         } catch (InvalidObjectException e) {\r
-            intlogger.warn("PROV0030 Feed.Feed: ", e.getMessage());\r
             throw e;\r
         } catch (Exception e) {\r
-            intlogger.error("PROV0031 Feed.Feed: invalid JSON: "+e);\r
-            throw new InvalidObjectException("invalid JSON: " + e.getMessage());\r
+            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
         }\r
     }\r
 \r
@@ -496,14 +497,6 @@ public class Feed extends Syncable {
         this.suspended = suspended;\r
     }\r
 \r
-    public Date getLast_mod() {\r
-        return last_mod;\r
-    }\r
-\r
-    public Date getCreated_date() {\r
-        return created_date;\r
-    }\r
-\r
     @Override\r
     public JSONObject asJSONObject() {\r
         JSONObject jo = new JSONObject();\r
@@ -555,15 +548,14 @@ public class Feed extends Syncable {
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if(ps!=null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -624,8 +616,7 @@ public class Feed extends Syncable {
             }\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);\r
         }\r
         return rv;\r
     }\r
@@ -705,13 +696,13 @@ public class Feed extends Syncable {
             ps.close();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null)\r
                     ps.close();\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -737,14 +728,14 @@ public class Feed extends Syncable {
             ps.close();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if(ps!=null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
index cd482c6..384d9f6 100644 (file)
@@ -39,10 +39,6 @@ public class FeedEndpointID implements JSONable {
     private String id;\r
     private String password;\r
 \r
-    public FeedEndpointID() {\r
-        this("", "");\r
-    }\r
-\r
     public FeedEndpointID(String id, String password) {\r
         this.id = id;\r
         this.password = password;\r
index 8904765..da682d7 100644 (file)
@@ -46,6 +46,7 @@ public class Group extends Syncable {
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
     private static int next_groupid = getMaxGroupID() + 1;\r
+    private static final String SQLEXCEPTION = "SQLException: ";\r
 \r
     private int groupid;\r
     private String authid;\r
@@ -107,7 +108,7 @@ public class Group extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0009 getGroupsForSQL: " + e.getMessage(), e);\r
         }\r
         return list;\r
     }\r
@@ -127,59 +128,11 @@ public class Group extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.info("getMaxSubID: " + e.getMessage());\r
+            intlogger.info("PROV0001 getMaxSubID: " + e.getMessage(), e);\r
         }\r
         return max;\r
     }\r
 \r
-    public static Collection<String> getGroupsByClassfication(String classfication) {\r
-        List<String> list = new ArrayList<>();\r
-        String sql = "select * from GROUPS where classification = ?";\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (PreparedStatement stmt = conn.prepareStatement(sql)) {\r
-                stmt.setString(1, classfication);\r
-                try (ResultSet rs = stmt.executeQuery()) {\r
-                    while (rs.next()) {\r
-                        int groupid = rs.getInt("groupid");\r
-\r
-                    }\r
-                }\r
-            }\r
-            db.release(conn);\r
-        } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
-        }\r
-        return list;\r
-    }\r
-\r
-    /**\r
-     * Return a count of the number of active subscriptions in the DB.\r
-     *\r
-     * @return the count\r
-     */\r
-    public static int countActiveSubscriptions() {\r
-        int count = 0;\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (Statement stmt = conn.createStatement()) {\r
-                try (ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) {\r
-                    if (rs.next()) {\r
-                        count = rs.getInt(1);\r
-                    }\r
-                }\r
-            }\r
-            db.release(conn);\r
-        } catch (SQLException e) {\r
-            intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());\r
-        }\r
-        return count;\r
-    }\r
-\r
     public Group() {\r
         this("", "", "");\r
     }\r
@@ -229,7 +182,8 @@ public class Group extends Syncable {
         } catch (InvalidObjectException e) {\r
             throw e;\r
         } catch (Exception e) {\r
-            throw new InvalidObjectException("invalid JSON: " + e.getMessage());\r
+            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
         }\r
     }\r
 \r
@@ -249,14 +203,6 @@ public class Group extends Syncable {
         Group.intlogger = intlogger;\r
     }\r
 \r
-    public static int getNext_groupid() {\r
-        return next_groupid;\r
-    }\r
-\r
-    public static void setNext_groupid(int next_groupid) {\r
-        Group.next_groupid = next_groupid;\r
-    }\r
-\r
     public String getAuthid() {\r
         return authid;\r
     }\r
@@ -293,19 +239,6 @@ public class Group extends Syncable {
         return members;\r
     }\r
 \r
-    public void setMembers(String members) {\r
-        this.members = members;\r
-    }\r
-\r
-    public Date getLast_mod() {\r
-        return last_mod;\r
-    }\r
-\r
-    public void setLast_mod(Date last_mod) {\r
-        this.last_mod = last_mod;\r
-    }\r
-\r
-\r
     @Override\r
     public JSONObject asJSONObject() {\r
         JSONObject jo = new JSONObject();\r
@@ -346,14 +279,14 @@ public class Group extends Syncable {
             ps.close();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
+            intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -375,14 +308,14 @@ public class Group extends Syncable {
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -399,14 +332,14 @@ public class Group extends Syncable {
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
+            intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
index bbed37a..329e77f 100644 (file)
@@ -55,6 +55,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
 public class IngressRoute extends NodeClass implements Comparable<IngressRoute> {\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+    private static final String SQLEXCEPTION = "SQLException: ";\r
     private final int seq;\r
     private final int feedid;\r
     private final String userid;\r
@@ -102,7 +103,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0001 getAllIngressRoutesForSQL: " + e.getMessage(), e);\r
         }\r
         return set;\r
     }\r
@@ -140,7 +141,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0002 getMax: " + e.getMessage(), e);\r
         }\r
         return rv;\r
     }\r
@@ -175,51 +176,19 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             ps.close();\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error("PROV0003 getIngressRoute: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return v;\r
     }\r
 \r
-    /**\r
-     * Get a collection of all Ingress Routes with a particular sequence number.\r
-     *\r
-     * @param seq the sequence number to look for\r
-     * @return the collection (may be empty).\r
-     */\r
-    public static Collection<IngressRoute> getIngressRoute(int seq) {\r
-        Collection<IngressRoute> rv = new ArrayList<IngressRoute>();\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            String sql = "select FEEDID, USERID, SUBNET, NODESET from INGRESS_ROUTES where SEQUENCE = ?";\r
-            try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
-                ps.setInt(1, seq);\r
-                try (ResultSet rs = ps.executeQuery()) {\r
-                    while (rs.next()) {\r
-                        int feedid = rs.getInt("FEEDID");\r
-                        String user = rs.getString("USERID");\r
-                        String subnet = rs.getString("SUBNET");\r
-                        int nodeset = rs.getInt("NODESET");\r
-                        rv.add(new IngressRoute(seq, feedid, user, subnet, nodeset));\r
-                    }\r
-                }\r
-            }\r
-            db.release(conn);\r
-        } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
-        }\r
-        return rv;\r
-    }\r
-\r
     public IngressRoute(int seq, int feedid, String user, String subnet, Collection<String> nodes)\r
             throws IllegalArgumentException {\r
         this(seq, feedid, user, subnet);\r
@@ -307,6 +276,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
                 SubnetMatcher sm = new SubnetMatcher(subnet);\r
                 return sm.matches(inet.getAddress());\r
             } catch (UnknownHostException e) {\r
+                intlogger.error("PROV0008 matches: " + e.getMessage(), e);\r
                 return false;\r
             }\r
         }\r
@@ -337,6 +307,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
                     len = sn.length;\r
                     valid = true;\r
                 } catch (UnknownHostException e) {\r
+                    intlogger.error("PROV0008 SubnetMatcher: " + e.getMessage(), e);\r
                     len = 0;\r
                     valid = false;\r
                 }\r
@@ -347,6 +318,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
                     sn = InetAddress.getByName(subnet.substring(0, i)).getAddress();\r
                     valid = true;\r
                 } catch (UnknownHostException e) {\r
+                    intlogger.error("PROV0008 SubnetMatcher: " + e.getMessage(), e);\r
                     valid = false;\r
                 }\r
                 len = n / 8;\r
@@ -390,7 +362,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
     }\r
 \r
     private Collection<String> readNodes() {\r
-        Collection<String> set = new TreeSet<String>();\r
+        Collection<String> set = new TreeSet<>();\r
         try {\r
             DB db = new DB();\r
             @SuppressWarnings("resource")\r
@@ -407,7 +379,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
         }\r
         return set;\r
     }\r
@@ -434,14 +406,14 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
+            intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -477,14 +449,14 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             ps.close();\r
             rv = true;\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
+            intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -524,14 +496,10 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
 \r
     @Override\r
     public boolean equals(Object obj) {\r
-        try {\r
-            if (!(obj instanceof IngressRoute)) {\r
-                return false;\r
-            }\r
-            return this.compareTo((IngressRoute) obj) == 0;\r
-        } catch (NullPointerException e) {\r
+        if (!(obj instanceof IngressRoute)) {\r
             return false;\r
         }\r
+        return this.compareTo((IngressRoute) obj) == 0;\r
     }\r
 \r
     @Override\r
index 86d1fae..cbddbf4 100644 (file)
@@ -77,7 +77,7 @@ public class LogRecord extends BaseLogRecord {
                 }\r
             }\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException: " + e.getMessage());\r
+            intlogger.error("PROV0001 printLogRecords: " + e.getMessage(), e);\r
         }\r
     }\r
 \r
index 94eeec4..6ac0544 100644 (file)
@@ -47,6 +47,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
 public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute> {\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+    private static final String SQLEXCEPTION = "SQLException: ";\r
     private final int fromnode;\r
     private final int tonode;\r
     private final int vianode;\r
@@ -58,7 +59,7 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
      * @return the sorted set\r
      */\r
     public static SortedSet<NetworkRoute> getAllNetworkRoutes() {\r
-        SortedSet<NetworkRoute> set = new TreeSet<NetworkRoute>();\r
+        SortedSet<NetworkRoute> set = new TreeSet<>();\r
         try {\r
             DB db = new DB();\r
             @SuppressWarnings("resource")\r
@@ -75,30 +76,30 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
         }\r
         return set;\r
     }\r
 \r
-    public NetworkRoute(String fromnode, String tonode) throws IllegalArgumentException {\r
+    public NetworkRoute(String fromnode, String tonode) {\r
         this.fromnode = lookupNodeName(fromnode);\r
         this.tonode = lookupNodeName(tonode);\r
         this.vianode = -1;\r
     }\r
 \r
-    public NetworkRoute(String fromnode, String tonode, String vianode) throws IllegalArgumentException {\r
+    public NetworkRoute(String fromnode, String tonode, String vianode) {\r
         this.fromnode = lookupNodeName(fromnode);\r
         this.tonode = lookupNodeName(tonode);\r
         this.vianode = lookupNodeName(vianode);\r
     }\r
 \r
-    public NetworkRoute(JSONObject jo) throws IllegalArgumentException {\r
+    public NetworkRoute(JSONObject jo) {\r
         this.fromnode = lookupNodeName(jo.getString("from"));\r
         this.tonode = lookupNodeName(jo.getString("to"));\r
         this.vianode = lookupNodeName(jo.getString("via"));\r
     }\r
 \r
-    public NetworkRoute(int fromnode, int tonode, int vianode) throws IllegalArgumentException {\r
+    public NetworkRoute(int fromnode, int tonode, int vianode) {\r
         this.fromnode = fromnode;\r
         this.tonode = tonode;\r
         this.vianode = vianode;\r
@@ -112,10 +113,6 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
         return tonode;\r
     }\r
 \r
-    public int getVianode() {\r
-        return vianode;\r
-    }\r
-\r
     @Override\r
     public boolean doDelete(Connection c) {\r
         boolean rv = true;\r
@@ -128,14 +125,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
+            intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -157,14 +154,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
                 ps.close();\r
                 rv = true;\r
             } catch (SQLException e) {\r
-                intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
+                intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
             } finally {\r
                 try {\r
                     if (ps != null) {\r
                         ps.close();\r
                     }\r
                 } catch (SQLException e) {\r
-                    intlogger.error("SQLException " + e.getMessage());\r
+                    intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
                 }\r
             }\r
         }\r
@@ -184,14 +181,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
index 0891486..9e7071b 100644 (file)
@@ -57,6 +57,7 @@ public class Parameters extends Syncable {
     public static final String PROV_POKETIMER2 = "PROV_POKETIMER2";\r
     public static final String PROV_SPECIAL_SUBNET = "PROV_SPECIAL_SUBNET";\r
     public static final String PROV_LOG_RETENTION = "PROV_LOG_RETENTION";\r
+    public static final String DEFAULT_LOG_RETENTION = "DEFAULT_LOG_RETENTION";\r
     public static final String NODES = "NODES";\r
     public static final String ACTIVE_POD = "ACTIVE_POD";\r
     public static final String STANDBY_POD = "STANDBY_POD";\r
@@ -69,6 +70,7 @@ public class Parameters extends Syncable {
     public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; //Adding new param for static Routing - Rally:US664862-1610\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
+    private static final String SQLEXCEPTION = "SQLException: ";\r
 \r
     private String keyname;\r
     private String value;\r
@@ -103,7 +105,7 @@ public class Parameters extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage());\r
         }\r
         return coll;\r
     }\r
@@ -131,7 +133,7 @@ public class Parameters extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error("SQLException " + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage());\r
         }\r
         return v;\r
     }\r
@@ -154,10 +156,6 @@ public class Parameters extends Syncable {
         return keyname;\r
     }\r
 \r
-    public void setKeyname(String keyname) {\r
-        this.keyname = keyname;\r
-    }\r
-\r
     public String getValue() {\r
         return value;\r
     }\r
@@ -187,14 +185,14 @@ public class Parameters extends Syncable {
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
+            intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage());\r
             }\r
         }\r
         return rv;\r
@@ -213,14 +211,14 @@ public class Parameters extends Syncable {
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(),e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -238,14 +236,14 @@ public class Parameters extends Syncable {
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
+            intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error("SQLException " + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
index 88d4882..a38d8bd 100644 (file)
@@ -24,7 +24,6 @@
 package org.onap.dmaap.datarouter.provisioning.beans;\r
 \r
 import java.sql.PreparedStatement;\r
-import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
 import java.sql.Types;\r
 import java.text.ParseException;\r
@@ -49,15 +48,6 @@ public class PubFailRecord extends BaseLogRecord {
         this.error = pp[11];\r
     }\r
 \r
-    public PubFailRecord(ResultSet rs) throws SQLException {\r
-        super(rs);\r
-        // Note: because this record should be "rare" these fields are mapped to unconventional fields in the DB\r
-        this.contentLengthReceived = rs.getLong("CONTENT_LENGTH_2");\r
-        this.sourceIP = rs.getString("REMOTE_ADDR");\r
-        this.user = rs.getString("USER");\r
-        this.error = rs.getString("FEED_FILEID");\r
-    }\r
-\r
     public long getContentLengthReceived() {\r
         return contentLengthReceived;\r
     }\r
index 98981a3..5a3457b 100644 (file)
@@ -43,10 +43,6 @@ public class SubDelivery implements JSONable {
     private String password;\r
     private boolean use100;\r
 \r
-    public SubDelivery() {\r
-        this("", "", "", false);\r
-    }\r
-\r
     public SubDelivery(String url, String user, String password, boolean use100) {\r
         this.url = url;\r
         this.user = user;\r
@@ -90,10 +86,6 @@ public class SubDelivery implements JSONable {
         return use100;\r
     }\r
 \r
-    public void setUse100(boolean use100) {\r
-        this.use100 = use100;\r
-    }\r
-\r
     @Override\r
     public JSONObject asJSONObject() {\r
         JSONObject jo = new JSONObject();\r
index 442a764..1cb1f2b 100644 (file)
@@ -23,6 +23,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.beans;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.io.InvalidObjectException;\r
 import java.sql.Connection;\r
 import java.sql.PreparedStatement;\r
@@ -34,9 +36,6 @@ import java.util.Collection;
 import java.util.Date;\r
 import java.util.List;\r
 import java.util.Properties;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
 import org.json.JSONObject;\r
 import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;\r
@@ -117,7 +116,7 @@ public class Subscription extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error(e.toString());\r
+            intlogger.error("PROV0001 getSubscriptionsForSQL: " + e.toString(), e);\r
         }\r
         return list;\r
     }\r
@@ -137,7 +136,7 @@ public class Subscription extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.info("getMaxSubID: " + e.getMessage());\r
+            intlogger.info("getMaxSubID: " + e.getMessage(), e);\r
         }\r
         return max;\r
     }\r
@@ -161,7 +160,7 @@ public class Subscription extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error(SQLEXCEPTION + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
         }\r
         return list;\r
     }\r
@@ -186,7 +185,7 @@ public class Subscription extends Syncable {
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());\r
+            intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage(), e);\r
         }\r
         return count;\r
     }\r
@@ -274,7 +273,8 @@ public class Subscription extends Syncable {
         } catch (InvalidObjectException e) {\r
             throw e;\r
         } catch (Exception e) {\r
-            throw new InvalidObjectException("invalid JSON: " + e.getMessage());\r
+            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
         }\r
     }\r
 \r
@@ -474,14 +474,14 @@ public class Subscription extends Syncable {
             ps.close();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0005 doInsert: " + e.getMessage());\r
+            intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -508,14 +508,14 @@ public class Subscription extends Syncable {
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -541,14 +541,14 @@ public class Subscription extends Syncable {
             ps.close();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0006 doUpdate: " + e.getMessage());\r
+            intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -566,14 +566,14 @@ public class Subscription extends Syncable {
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\r
-            intlogger.warn("PROV0007 doDelete: " + e.getMessage());\r
+            intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             try {\r
                 if (ps != null) {\r
                     ps.close();\r
                 }\r
             } catch (SQLException e) {\r
-                intlogger.error(SQLEXCEPTION + e.getMessage());\r
+                intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
             }\r
         }\r
         return rv;\r
@@ -596,8 +596,8 @@ public class Subscription extends Syncable {
         if (feedid != os.feedid) {\r
             return false;\r
         }\r
-        if (groupid != os.groupid) //New field is added - Groups feature Rally:US708115 - 1610\r
-        {\r
+        if (groupid != os.groupid) {\r
+            //New field is added - Groups feature Rally:US708115 - 1610\r
             return false;\r
         }\r
         if (!delivery.equals(os.delivery)) {\r
index d29876f..7700a58 100644 (file)
@@ -84,7 +84,7 @@ public class DB {
                 HTTP_PORT = (String) props.get("org.onap.dmaap.datarouter.provserver.http.port");\r
                 Class.forName(DB_DRIVER);\r
             } catch (IOException e) {\r
-                intlogger.error("PROV9003 Opening properties: " + e.getMessage());\r
+                intlogger.error("PROV9003 Opening properties: " + e.getMessage(), e);\r
                 System.exit(1);\r
             } catch (ClassNotFoundException e) {\r
                 intlogger.error("PROV9004 cannot find the DB driver: " + e);\r
@@ -115,6 +115,7 @@ public class DB {
                 try {\r
                     connection = queue.remove();\r
                 } catch (NoSuchElementException nseEx) {\r
+                    intlogger.error("PROV9006 No connection on queue: " + nseEx.getMessage(), nseEx);\r
                     int n = 0;\r
                     do {\r
                         // Try up to 3 times to get a connection\r
@@ -194,8 +195,7 @@ public class DB {
                 runInitScript(connection, 1);\r
             }\r
         } catch (SQLException e) {\r
-            intlogger\r
-                .error("PROV9000: The database credentials are not working: " + e.getMessage());\r
+            intlogger.error("PROV9000: The database credentials are not working: " + e.getMessage(), e);\r
             return false;\r
         } finally {\r
             if (connection != null) {\r
@@ -223,7 +223,7 @@ public class DB {
                 rs.close();\r
             }\r
         } catch (SQLException e) {\r
-            intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage());\r
+            intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage(), e);\r
         }\r
         return tables;\r
     }\r
@@ -264,7 +264,7 @@ public class DB {
             lineReader.close();\r
             strBuilder.setLength(0);\r
         } catch (Exception e) {\r
-            intlogger.error("PROV9002 Error when initializing table: " + e.getMessage());\r
+            intlogger.error("PROV9002 Error when initializing table: " + e.getMessage(), e);\r
             System.exit(1);\r
         }\r
     }\r
index 46cfabe..d5521ba 100644 (file)
@@ -211,7 +211,7 @@ public class DRProvCadiFilter extends CadiFilter {
             }
 
         } catch (Exception e) {
-            intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: ", e.getMessage());
+            intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: " + e.getMessage(), e);
             return false;
         }
         return false;
@@ -241,7 +241,7 @@ public class DRProvCadiFilter extends CadiFilter {
                 intlogger.debug(message);
             }
         } catch (Exception e) {
-            intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: ", e.getMessage());
+            intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: " + e.getMessage(), e);
             return false;
         }
         return false;
index af8bd6d..a593c8a 100644 (file)
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.io.File;\r
 import java.io.FileInputStream;\r
 import java.io.IOException;\r
@@ -97,6 +99,7 @@ public class DRRouteCLI {
     public static final String ENV_VAR = "PROVSRVR";\r
     public static final String PROMPT = "dr-route> ";\r
     public static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";\r
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
 \r
     private final String server;\r
     private int width = 120;        // screen width (for list)\r
@@ -130,12 +133,13 @@ public class DRRouteCLI {
             try {\r
                 trustStore.load(instream, truststore_pw.toCharArray());\r
             } catch (Exception x) {\r
-                System.err.println("Problem reading truststore: " + x);\r
+                intlogger.error("Problem reading truststore: " + x.getMessage(), x);\r
                 throw x;\r
             } finally {\r
                 try {\r
                     instream.close();\r
                 } catch (Exception ignore) {\r
+                    intlogger.error("Ignore error closing input stream: " + ignore.getMessage(), ignore);\r
                 }\r
             }\r
         }\r
@@ -397,6 +401,7 @@ public class DRRouteCLI {
                 printErrorText(entity);\r
             }\r
         } catch (Exception e) {\r
+            intlogger.error("PROV0006 doDelete: " + e.getMessage(), e);\r
         } finally {\r
             meth.releaseConnection();\r
         }\r
@@ -416,7 +421,7 @@ public class DRRouteCLI {
                 printErrorText(entity);\r
             }\r
         } catch (Exception e) {\r
-            System.err.println(e);\r
+            intlogger.error("PROV0005 doGet: " + e.getMessage(), e);\r
         } finally {\r
             meth.releaseConnection();\r
         }\r
@@ -438,6 +443,7 @@ public class DRRouteCLI {
                 printErrorText(entity);\r
             }\r
         } catch (Exception e) {\r
+            intlogger.error("PROV0009 doPost: " + e.getMessage(), e);\r
         } finally {\r
             meth.releaseConnection();\r
         }\r
index 3aa3bd2..f59dc91 100644 (file)
  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * *
  ******************************************************************************/
-package org.onap.dmaap.datarouter.provisioning.utils;
 
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+package org.onap.dmaap.datarouter.provisioning.utils;
 
 import com.att.eelf.configuration.EELFLogger;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
 
 public class HttpServletUtils {
+
+    private HttpServletUtils(){
+
+    }
+
     public static void sendResponseError(HttpServletResponse response, int errorCode, String message, EELFLogger intlogger) {
         try {
             response.sendError(errorCode, message);
         } catch (IOException ioe) {
-            intlogger.error("IOException" + ioe.getMessage());
+            intlogger.error("IOException" + ioe.getMessage(), ioe);
         }
     }
 }
index 915aa61..2d4e22b 100644 (file)
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 import java.util.Collection;\r
@@ -35,6 +37,8 @@ import java.util.Collection;
  * @version $Id: JSONUtilities.java,v 1.1 2013/04/26 21:00:26 eby Exp $\r
  */\r
 public class JSONUtilities {\r
+\r
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
     /**\r
      * Does the String <i>v</i> represent a valid Internet address (with or without a\r
      * mask length appended).\r
@@ -56,6 +60,7 @@ public class JSONUtilities {
             }\r
             return true;\r
         } catch (UnknownHostException e) {\r
+            intlogger.error("PROV0001: " + e.getMessage(), e);\r
             return false;\r
         }\r
     }\r
index 1518859..1140a1c 100644 (file)
@@ -23,6 +23,8 @@ package org.onap.dmaap.datarouter.provisioning.utils;
  * *
  ******************************************************************************/
 
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -104,6 +106,8 @@ public class LOGJSONObject {
      */
     private static Map<String, Object> keyPool = new LinkedHashMap<String, Object>(keyPoolSize);
 
+    private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+
     /**
      * JSONObject.NULL is equivalent to the value that JavaScript calls null,
      * whilst Java's null is equivalent to the value that JavaScript calls
@@ -182,13 +186,11 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * The map where the JSONObject's properties are kept.
      */
     private final Map<String, Object> map;
 
-
     /**
      * It is sometimes more convenient and less ambiguous to have a
      * <code>NULL</code> object than to use Java's <code>null</code> value.
@@ -197,15 +199,13 @@ public class LOGJSONObject {
      */
     public static final Object NULL = new Null();
 
-
     /**
      * Construct an empty JSONObject.
      */
     public LOGJSONObject() {
-        this.map = new LinkedHashMap<String, Object>();
+        this.map = new LinkedHashMap<>();
     }
 
-
     /**
      * Construct a JSONObject from a subset of another JSONObject.
      * An array of strings is used to identify the keys that should be copied.
@@ -213,8 +213,6 @@ public class LOGJSONObject {
      *
      * @param jo    A JSONObject.
      * @param names An array of strings.
-     * @throws JSONException
-     * @throws JSONException If a value is a non-finite number or if a name is duplicated.
      */
     public LOGJSONObject(LOGJSONObject jo, String[] names) {
         this();
@@ -222,11 +220,11 @@ public class LOGJSONObject {
             try {
                 this.putOnce(names[i], jo.opt(names[i]));
             } catch (Exception ignore) {
+                intlogger.error("PROV0001 LOGJSONObject: " + ignore.getMessage(), ignore);
             }
         }
     }
 
-
     /**
      * Construct a JSONObject from a JSONTokener.
      *
@@ -234,7 +232,7 @@ public class LOGJSONObject {
      * @throws JSONException If there is a syntax error in the source string
      *                       or a duplicated key.
      */
-    public LOGJSONObject(JSONTokener x) throws JSONException {
+    public LOGJSONObject(JSONTokener x) {
         this();
         char c;
         String key;
@@ -284,7 +282,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Construct a JSONObject from a Map.
      *
@@ -306,7 +303,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Construct a JSONObject from an Object using bean getters.
      * It reflects on all of the public methods of the object.
@@ -331,7 +327,6 @@ public class LOGJSONObject {
         this.populateMap(bean);
     }
 
-
     /**
      * Construct a JSONObject from an Object, using reflection to find the
      * public members. The resulting JSONObject's keys will be the strings
@@ -356,7 +351,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Construct a JSONObject from a source JSON text string.
      * This is the most commonly used JSONObject constructor.
@@ -371,7 +365,6 @@ public class LOGJSONObject {
         this(new JSONTokener(source));
     }
 
-
     /**
      * Construct a JSONObject from a ResourceBundle.
      *
@@ -412,7 +405,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Accumulate values under a key. It is similar to the put method except
      * that if there is already an object stored under the key then a
@@ -448,7 +440,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Append values to the array under a key. If the key does not exist in the
      * JSONObject, then the key is put in the JSONObject with its value being a
@@ -475,7 +466,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Produce a string from a double. The string "null" will be returned if
      * the number is not finite.
@@ -503,7 +493,6 @@ public class LOGJSONObject {
         return string;
     }
 
-
     /**
      * Get the value object associated with a key.
      *
@@ -523,7 +512,6 @@ public class LOGJSONObject {
         return object;
     }
 
-
     /**
      * Get the boolean value associated with a key.
      *
@@ -546,7 +534,6 @@ public class LOGJSONObject {
                 "] is not a Boolean.");
     }
 
-
     /**
      * Get the double value associated with a key.
      *
@@ -555,19 +542,18 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or
      *                       if the value is not a Number object and cannot be converted to a number.
      */
-    public double getDouble(String key) throws JSONException {
+    public double getDouble(String key) {
         Object object = this.get(key);
         try {
             return object instanceof Number
                     ? ((Number) object).doubleValue()
                     : Double.parseDouble((String) object);
         } catch (Exception e) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] is not a number.");
+            intlogger.error("JSONObject[" + quote(key) + "] is not a number.", e);
+            throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
         }
     }
 
-
     /**
      * Get the int value associated with a key.
      *
@@ -576,19 +562,18 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or if the value cannot
      *                       be converted to an integer.
      */
-    public int getInt(String key) throws JSONException {
+    public int getInt(String key) {
         Object object = this.get(key);
         try {
             return object instanceof Number
                     ? ((Number) object).intValue()
                     : Integer.parseInt((String) object);
         } catch (Exception e) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] is not an int.");
+            intlogger.error("JSONObject[" + quote(key) + "] is not an int.", e);
+            throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
         }
     }
 
-
     /**
      * Get the JSONArray value associated with a key.
      *
@@ -606,7 +591,6 @@ public class LOGJSONObject {
                 "] is not a JSONArray.");
     }
 
-
     /**
      * Get the JSONObject value associated with a key.
      *
@@ -624,7 +608,6 @@ public class LOGJSONObject {
                 "] is not a JSONObject.");
     }
 
-
     /**
      * Get the long value associated with a key.
      *
@@ -640,12 +623,11 @@ public class LOGJSONObject {
                     ? ((Number) object).longValue()
                     : Long.parseLong((String) object);
         } catch (Exception e) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] is not a long.");
+            intlogger.error("JSONObject[" + quote(key) + "] is not a long.", e);
+            throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
         }
     }
 
-
     /**
      * Get an array of field names from a JSONObject.
      *
@@ -666,30 +648,6 @@ public class LOGJSONObject {
         return names;
     }
 
-
-    /**
-     * Get an array of field names from an Object.
-     *
-     * @return An array of field names, or null if there are no names.
-     */
-    public static String[] getNames(Object object) {
-        if (object == null) {
-            return null;
-        }
-        Class<? extends Object> klass = object.getClass();
-        Field[] fields = klass.getFields();
-        int length = fields.length;
-        if (length == 0) {
-            return null;
-        }
-        String[] names = new String[length];
-        for (int i = 0; i < length; i += 1) {
-            names[i] = fields[i].getName();
-        }
-        return names;
-    }
-
-
     /**
      * Get the string associated with a key.
      *
@@ -697,7 +655,7 @@ public class LOGJSONObject {
      * @return A string which is the value.
      * @throws JSONException if there is no string value for the key.
      */
-    public String getString(String key) throws JSONException {
+    public String getString(String key) {
         Object object = this.get(key);
         if (object instanceof String) {
             return (String) object;
@@ -706,7 +664,6 @@ public class LOGJSONObject {
                 "] not a string.");
     }
 
-
     /**
      * Determine if the JSONObject contains a specific key.
      *
@@ -717,7 +674,6 @@ public class LOGJSONObject {
         return this.map.containsKey(key);
     }
 
-
     /**
      * Increment a property of a JSONObject. If there is no such property,
      * create one with a value of 1. If there is such a property, and if
@@ -728,7 +684,7 @@ public class LOGJSONObject {
      * @throws JSONException If there is already a property with this name
      *                       that is not an Integer, Long, Double, or Float.
      */
-    public LOGJSONObject increment(String key) throws JSONException {
+    public LOGJSONObject increment(String key) {
         Object value = this.opt(key);
         if (value == null) {
             this.put(key, 1);
@@ -746,20 +702,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
-    /**
-     * Determine if the value associated with the key is null or if there is
-     * no value.
-     *
-     * @param key A key string.
-     * @return true if there is no value associated with the key or if
-     * the value is the JSONObject.NULL object.
-     */
-    public boolean isNull(String key) {
-        return LOGJSONObject.NULL.equals(this.opt(key));
-    }
-
-
     /**
      * Get an enumeration of the keys of the JSONObject.
      *
@@ -769,7 +711,6 @@ public class LOGJSONObject {
         return this.keySet().iterator();
     }
 
-
     /**
      * Get a set of keys of the JSONObject.
      *
@@ -779,7 +720,6 @@ public class LOGJSONObject {
         return this.map.keySet();
     }
 
-
     /**
      * Get the number of keys stored in the JSONObject.
      *
@@ -789,7 +729,6 @@ public class LOGJSONObject {
         return this.map.size();
     }
 
-
     /**
      * Produce a JSONArray containing the names of the elements of this
      * JSONObject.
@@ -835,7 +774,6 @@ public class LOGJSONObject {
         return string;
     }
 
-
     /**
      * Get an optional value associated with a key.
      *
@@ -846,20 +784,6 @@ public class LOGJSONObject {
         return key == null ? null : this.map.get(key);
     }
 
-
-    /**
-     * Get an optional boolean associated with a key.
-     * It returns false if there is no such key, or if the value is not
-     * Boolean.TRUE or the String "true".
-     *
-     * @param key A key string.
-     * @return The truth.
-     */
-    public boolean optBoolean(String key) {
-        return this.optBoolean(key, false);
-    }
-
-
     /**
      * Get an optional boolean associated with a key.
      * It returns the defaultValue if there is no such key, or if it is not
@@ -873,25 +797,11 @@ public class LOGJSONObject {
         try {
             return this.getBoolean(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
 
-
-    /**
-     * Get an optional double associated with a key,
-     * or NaN if there is no such key or if its value is not a number.
-     * If the value is a string, an attempt will be made to evaluate it as
-     * a number.
-     *
-     * @param key A string which is the key.
-     * @return An object which is the value.
-     */
-    public double optDouble(String key) {
-        return this.optDouble(key, Double.NaN);
-    }
-
-
     /**
      * Get an optional double associated with a key, or the
      * defaultValue if there is no such key or if its value is not a number.
@@ -906,25 +816,11 @@ public class LOGJSONObject {
         try {
             return this.getDouble(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
 
-
-    /**
-     * Get an optional int value associated with a key,
-     * or zero if there is no such key or if the value is not a number.
-     * If the value is a string, an attempt will be made to evaluate it as
-     * a number.
-     *
-     * @param key A key string.
-     * @return An object which is the value.
-     */
-    public int optInt(String key) {
-        return this.optInt(key, 0);
-    }
-
-
     /**
      * Get an optional int value associated with a key,
      * or the default if there is no such key or if the value is not a number.
@@ -939,25 +835,11 @@ public class LOGJSONObject {
         try {
             return this.getInt(key);
         } catch (Exception e) {
+            intlogger.trace("Using defaultValue: " + defaultValue, e);
             return defaultValue;
         }
     }
 
-
-    /**
-     * Get an optional JSONArray associated with a key.
-     * It returns null if there is no such key, or if its value is not a
-     * JSONArray.
-     *
-     * @param key A key string.
-     * @return A JSONArray which is the value.
-     */
-    public JSONArray optJSONArray(String key) {
-        Object o = this.opt(key);
-        return o instanceof JSONArray ? (JSONArray) o : null;
-    }
-
-
     /**
      * Get an optional JSONObject associated with a key.
      * It returns null if there is no such key, or if its value is not a
@@ -971,21 +853,6 @@ public class LOGJSONObject {
         return object instanceof LOGJSONObject ? (LOGJSONObject) object : null;
     }
 
-
-    /**
-     * Get an optional long value associated with a key,
-     * or zero if there is no such key or if the value is not a number.
-     * If the value is a string, an attempt will be made to evaluate it as
-     * a number.
-     *
-     * @param key A key string.
-     * @return An object which is the value.
-     */
-    public long optLong(String key) {
-        return this.optLong(key, 0);
-    }
-
-
     /**
      * Get an optional long value associated with a key,
      * or the default if there is no such key or if the value is not a number.
@@ -1004,20 +871,6 @@ public class LOGJSONObject {
         }
     }
 
-
-    /**
-     * Get an optional string associated with a key.
-     * It returns an empty string if there is no such key. If the value is not
-     * a string and is not null, then it is converted to a string.
-     *
-     * @param key A key string.
-     * @return A string which is the value.
-     */
-    public String optString(String key) {
-        return this.optString(key, "");
-    }
-
-
     /**
      * Get an optional string associated with a key.
      * It returns the defaultValue if there is no such key.
@@ -1031,7 +884,6 @@ public class LOGJSONObject {
         return NULL.equals(object) ? defaultValue : object.toString();
     }
 
-
     private void populateMap(Object bean) {
         Class<? extends Object> klass = bean.getClass();
 
@@ -1075,11 +927,11 @@ public class LOGJSONObject {
                     }
                 }
             } catch (Exception ignore) {
+                intlogger.trace("populateMap: " + ignore.getMessage(), ignore);
             }
         }
     }
 
-
     /**
      * Put a key/boolean pair in the JSONObject.
      *
@@ -1093,7 +945,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/value pair in the JSONObject, where the value will be a
      * JSONArray which is produced from a Collection.
@@ -1108,7 +959,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/double pair in the JSONObject.
      *
@@ -1122,7 +972,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/int pair in the JSONObject.
      *
@@ -1136,7 +985,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/long pair in the JSONObject.
      *
@@ -1150,7 +998,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/value pair in the JSONObject, where the value will be a
      * JSONObject which is produced from a Map.
@@ -1165,7 +1012,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/value pair in the JSONObject. If the value is null,
      * then the key will be removed from the JSONObject if it is present.
@@ -1201,7 +1047,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/value pair in the JSONObject, but only if the key and the
      * value are both non-null, and only if there is not already a member
@@ -1222,7 +1067,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Put a key/value pair in the JSONObject, but only if the
      * key and the value are both non-null.
@@ -1241,7 +1085,6 @@ public class LOGJSONObject {
         return this;
     }
 
-
     /**
      * Produce a string in double quotes with backslash sequences in all the
      * right places. A backslash will be inserted within </, producing <\/,
@@ -1256,8 +1099,8 @@ public class LOGJSONObject {
         synchronized (sw.getBuffer()) {
             try {
                 return quote(string, sw).toString();
-            } catch (IOException ignored) {
-                // will never happen - we are writing to a string writer
+            } catch (IOException e) {
+                intlogger.trace("Ignore Exception message: ", e);
                 return "";
             }
         }
@@ -1380,20 +1223,20 @@ public class LOGJSONObject {
                         return myLong;
                     }
                 }
-            } catch (Exception ignore) {
+            } catch (Exception e) {
+                intlogger.trace("Ignore Exception message: ", e);
             }
         }
         return string;
     }
 
-
     /**
      * Throw an exception if the object is a NaN or infinite number.
      *
      * @param o The object to test.
      * @throws JSONException If o is a non-finite number.
      */
-    public static void testValidity(Object o) throws JSONException {
+    public static void testValidity(Object o) {
         if (o != null) {
             if (o instanceof Double) {
                 if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
@@ -1409,7 +1252,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Produce a JSONArray containing the values of the members of this
      * JSONObject.
@@ -1446,11 +1288,11 @@ public class LOGJSONObject {
         try {
             return this.toString(0);
         } catch (Exception e) {
+            intlogger.trace("Exception: ", e);
             return "";
         }
     }
 
-
     /**
      * Make a prettyprinted JSON text of this JSONObject.
      * <p>
@@ -1579,25 +1421,11 @@ public class LOGJSONObject {
             }
             return new LOGJSONObject(object);
         } catch (Exception exception) {
+            intlogger.trace("Exception: ", exception);
             return null;
         }
     }
 
-
-    /**
-     * Write the contents of the JSONObject as JSON text to a writer.
-     * For compactness, no whitespace is added.
-     * <p>
-     * Warning: This method assumes that the data structure is acyclical.
-     *
-     * @return The writer.
-     * @throws JSONException
-     */
-    public Writer write(Writer writer) throws JSONException {
-        return this.write(writer, 0, 0);
-    }
-
-
     @SuppressWarnings("unchecked")
     static final Writer writeValue(Writer writer, Object value,
                                    int indentFactor, int indent) throws JSONException, IOException {
index 8223188..c78a5b1 100644 (file)
-/*******************************************************************************\r
- * ============LICENSE_START==================================================\r
- * * org.onap.dmaap\r
- * * ===========================================================================\r
- * * Copyright Â© 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * *\r
- *  *      http://www.apache.org/licenses/LICENSE-2.0\r
- * *\r
- *  * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-\r
-\r
-package org.onap.dmaap.datarouter.provisioning.utils;\r
-\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileNotFoundException;\r
-import java.io.FileReader;\r
-import java.io.FilenameFilter;\r
-import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.io.LineNumberReader;\r
-import java.io.Reader;\r
-import java.sql.Connection;\r
-import java.sql.PreparedStatement;\r
-import java.sql.ResultSet;\r
-import java.sql.SQLException;\r
-import java.sql.Statement;\r
-import java.text.ParseException;\r
-import java.util.Date;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.TreeSet;\r
-import java.util.zip.GZIPInputStream;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
-import org.onap.dmaap.datarouter.provisioning.beans.DeliveryExtraRecord;\r
-import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord;\r
-import org.onap.dmaap.datarouter.provisioning.beans.ExpiryRecord;\r
-import org.onap.dmaap.datarouter.provisioning.beans.Loadable;\r
-import org.onap.dmaap.datarouter.provisioning.beans.LogRecord;\r
-import org.onap.dmaap.datarouter.provisioning.beans.Parameters;\r
-import org.onap.dmaap.datarouter.provisioning.beans.PubFailRecord;\r
-import org.onap.dmaap.datarouter.provisioning.beans.PublishRecord;\r
-\r
-/**\r
- * This class provides methods that run in a separate thread, in order to process logfiles uploaded into the spooldir.\r
- * These logfiles are loaded into the MariaDB LOG_RECORDS table. In a running provisioning server, there should only be\r
- * two places where records can be loaded into this table; here, and in the method DB.retroFit4() which may be run at\r
- * startup to load the old (1.0) style log tables into LOG_RECORDS;\r
- * <p>This method maintains an {@link RLEBitSet} which can be used to easily see what records are presently in the\r
- * database.\r
- * This bit set is used to synchronize between provisioning servers.</p>\r
- *\r
- * @author Robert Eby\r
- * @version $Id: LogfileLoader.java,v 1.22 2014/03/12 19:45:41 eby Exp $\r
- */\r
-public class LogfileLoader extends Thread {\r
-    /**\r
-     * Default number of log records to keep when pruning.  Keep 10M by default.\r
-     */\r
-    public static final long DEFAULT_LOG_RETENTION = 10000000L;\r
-    /**\r
-     * NOT USED: Percentage of free space required before old records are removed.\r
-     */\r
-    public static final int REQUIRED_FREE_PCT = 20;\r
-\r
-    /**\r
-     * This is a singleton -- there is only one LogfileLoader object in the server\r
-     */\r
-    private static LogfileLoader logfileLoader;\r
-\r
-    /**\r
-     * Get the singleton LogfileLoader object, and start it if it is not running.\r
-     *\r
-     * @return the LogfileLoader\r
-     */\r
-    public static synchronized LogfileLoader getLoader() {\r
-        if (logfileLoader == null)\r
-            logfileLoader = new LogfileLoader();\r
-        if (!logfileLoader.isAlive())\r
-            logfileLoader.start();\r
-        return logfileLoader;\r
-    }\r
-\r
-    /**\r
-     * The PreparedStatement which is loaded by a <i>Loadable</i>.\r
-     */\r
-    public static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";\r
-    /**\r
-     * Each server can assign this many IDs\r
-     */\r
-    private static final long SET_SIZE = (1L << 56);\r
-\r
-    private final EELFLogger logger;\r
-    private final DB db;\r
-    private final String spooldir;\r
-    private final long set_start;\r
-    private final long set_end;\r
-    private RLEBitSet seq_set;\r
-    private long nextid;\r
-    private boolean idle;\r
-\r
-    private LogfileLoader() {\r
-        this.logger = EELFManager.getInstance().getLogger("InternalLog");\r
-        this.db = new DB();\r
-        this.spooldir = db.getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");\r
-        this.set_start = getIdRange();\r
-        this.set_end = set_start + SET_SIZE - 1;\r
-        this.seq_set = new RLEBitSet();\r
-        this.nextid = 0;\r
-        this.idle = false;\r
-\r
-        // This is a potentially lengthy operation, so has been moved to run()\r
-        //initializeNextid();\r
-        this.setDaemon(true);\r
-        this.setName("LogfileLoader");\r
-    }\r
-\r
-    private long getIdRange() {\r
-        long n;\r
-        if (BaseServlet.isInitialActivePOD())\r
-            n = 0;\r
-        else if (BaseServlet.isInitialStandbyPOD())\r
-            n = SET_SIZE;\r
-        else\r
-            n = SET_SIZE * 2;\r
-        String r = String.format("[%X .. %X]", n, n + SET_SIZE - 1);\r
-        logger.debug("This server shall assign RECORD_IDs in the range " + r);\r
-        return n;\r
-    }\r
-\r
-    /**\r
-     * Return the bit set representing the record ID's that are loaded in this database.\r
-     *\r
-     * @return the bit set\r
-     */\r
-    public RLEBitSet getBitSet() {\r
-        return seq_set;\r
-    }\r
-\r
-    /**\r
-     * True if the LogfileLoader is currently waiting for work.\r
-     *\r
-     * @return true if idle\r
-     */\r
-    public boolean isIdle() {\r
-        return idle;\r
-    }\r
-\r
-    /**\r
-     * Run continuously to look for new logfiles in the spool directory and import them into the DB.\r
-     * The spool is checked once per second.  If free space on the MariaDB filesystem falls below\r
-     * REQUIRED_FREE_PCT (normally 20%) then the oldest logfile entries are removed and the LOG_RECORDS\r
-     * table is compacted until free space rises above the threshold.\r
-     */\r
-    @Override\r
-    public void run() {\r
-        initializeNextid();    // moved from the constructor\r
-        while (true) {\r
-            try {\r
-                File dirfile = new File(spooldir);\r
-                while (true) {\r
-                    // process IN files\r
-                    File[] infiles = dirfile.listFiles(new FilenameFilter() {\r
-                        @Override\r
-                        public boolean accept(File dir, String name) {\r
-                            return name.startsWith("IN.");\r
-                        }\r
-                    });\r
-\r
-                    if (infiles.length == 0) {\r
-                        idle = true;\r
-                        try {\r
-                            Thread.sleep(1000L);\r
-                        } catch (InterruptedException e) {\r
-                            Thread.currentThread().interrupt();\r
-                        }\r
-                        idle = false;\r
-                    } else {\r
-                        // Remove old rows\r
-                        if (pruneRecords()) {\r
-                            // Removed at least some entries, recompute the bit map\r
-                            initializeNextid();\r
-                        }\r
-\r
-                        // Process incoming logfiles\r
-                        for (File f : infiles) {\r
-                            if (logger.isDebugEnabled())\r
-                                logger.debug("PROV8001 Starting " + f + " ...");\r
-                            long time = System.currentTimeMillis();\r
-                            int[] n = process(f);\r
-                            time = System.currentTimeMillis() - time;\r
-                            logger.info(String\r
-                                    .format("PROV8000 Processed %s in %d ms; %d of %d records.",\r
-                                            f.toString(), time, n[0], n[1]));\r
-                            f.delete();\r
-                        }\r
-                    }\r
-                }\r
-            } catch (Exception e) {\r
-                logger.warn("PROV0020: Caught exception in LogfileLoader: " + e);\r
-            }\r
-        }\r
-    }\r
-\r
-    boolean pruneRecords() {\r
-        boolean did1 = false;\r
-        long count = countRecords();\r
-        long threshold = DEFAULT_LOG_RETENTION;\r
-        Parameters param = Parameters.getParameter(Parameters.PROV_LOG_RETENTION);\r
-        if (param != null) {\r
-            try {\r
-                long n = Long.parseLong(param.getValue());\r
-                // This check is to prevent inadvertent errors from wiping the table out\r
-                if (n > 1000000L)\r
-                    threshold = n;\r
-            } catch (NumberFormatException e) {\r
-                // ignore\r
-            }\r
-        }\r
-        logger.debug("Pruning LOG_RECORD table: records in DB=" + count + ", threshold=" + threshold);\r
-        if (count > threshold) {\r
-            count -= threshold;                        // we need to remove this many records;\r
-            Map<Long, Long> hist = getHistogram();    // histogram of records per day\r
-            // Determine the cutoff point to remove the needed number of records\r
-            long sum = 0;\r
-            long cutoff = 0;\r
-            for (Long day : new TreeSet<Long>(hist.keySet())) {\r
-                sum += hist.get(day);\r
-                cutoff = day;\r
-                if (sum >= count)\r
-                    break;\r
-            }\r
-            cutoff++;\r
-            cutoff *= 86400000L;        // convert day to ms\r
-            logger.debug("  Pruning records older than=" + (cutoff / 86400000L) + " (" + new Date(cutoff) + ")");\r
-\r
-            Connection conn = null;\r
-            try {\r
-                // Limit to a million at a time to avoid typing up the DB for too long.\r
-                conn = db.getConnection();\r
-                try(PreparedStatement ps = conn.prepareStatement("DELETE from LOG_RECORDS where EVENT_TIME < ? limit 1000000")) {\r
-                    ps.setLong(1, cutoff);\r
-                    while (count > 0) {\r
-                        if (!ps.execute()) {\r
-                            int dcount = ps.getUpdateCount();\r
-                            count -= dcount;\r
-                            logger.debug("  " + dcount + " rows deleted.");\r
-                            did1 |= (dcount != 0);\r
-                            if (dcount == 0)\r
-                                count = 0;    // prevent inf. loops\r
-                        } else {\r
-                            count = 0;    // shouldn't happen!\r
-                        }\r
-                    }\r
-                }\r
-             try(Statement stmt = conn.createStatement()) {\r
-                 stmt.execute("OPTIMIZE TABLE LOG_RECORDS");\r
-             }\r
-            } catch (SQLException e) {\r
-                System.err.println(e);\r
-                logger.error(e.toString());\r
-            } finally {\r
-                db.release(conn);\r
-            }\r
-        }\r
-        return did1;\r
-    }\r
-\r
-    long countRecords() {\r
-        long count = 0;\r
-        Connection conn = null;\r
-        try {\r
-            conn = db.getConnection();\r
-           try(Statement stmt = conn.createStatement()) {\r
-               try(ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS")) {\r
-                   if (rs.next()) {\r
-                       count = rs.getLong("COUNT");\r
-                   }\r
-               }\r
-           }\r
-         } catch (SQLException e) {\r
-            System.err.println(e);\r
-            logger.error(e.toString());\r
-        } finally {\r
-            db.release(conn);\r
-        }\r
-        return count;\r
-    }\r
-\r
-    Map<Long, Long> getHistogram() {\r
-        Map<Long, Long> map = new HashMap<Long, Long>();\r
-        Connection conn = null;\r
-        try {\r
-            logger.debug("  LOG_RECORD table histogram...");\r
-            conn = db.getConnection();\r
-            try(Statement stmt = conn.createStatement()) {\r
-                try(ResultSet rs = stmt.executeQuery("SELECT FLOOR(EVENT_TIME/86400000) AS DAY, COUNT(*) AS COUNT FROM LOG_RECORDS GROUP BY DAY")) {\r
-                    while (rs.next()) {\r
-                        long day = rs.getLong("DAY");\r
-                        long cnt = rs.getLong("COUNT");\r
-                        map.put(day, cnt);\r
-                        logger.debug("  " + day + "  " + cnt);\r
-                    }\r
-                }\r
-            }\r
-           } catch (SQLException e) {\r
-            System.err.println(e);\r
-            logger.error(e.toString());\r
-        } finally {\r
-            db.release(conn);\r
-        }\r
-        return map;\r
-    }\r
-\r
-    private void initializeNextid() {\r
-        Connection conn = null;\r
-        try {\r
-            conn = db.getConnection();\r
-            RLEBitSet nbs = new RLEBitSet();\r
-            try(Statement stmt = conn.createStatement()) {\r
-                // Build a bitset of all records in the LOG_RECORDS table\r
-                // We need to run this SELECT in stages, because otherwise we run out of memory!\r
-                final long stepsize = 6000000L;\r
-                boolean go_again = true;\r
-                for (long i = 0; go_again; i += stepsize) {\r
-                    String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize);\r
-                    try (ResultSet rs = stmt.executeQuery(sql)) {\r
-                        go_again = false;\r
-                        while (rs.next()) {\r
-                            long n = rs.getLong("RECORD_ID");\r
-                            nbs.set(n);\r
-                            go_again = true;\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-            seq_set = nbs;\r
-            // Compare with the range for this server\r
-            // Determine the next ID for this set of record IDs\r
-            RLEBitSet tbs = (RLEBitSet) nbs.clone();\r
-            RLEBitSet idset = new RLEBitSet();\r
-            idset.set(set_start, set_start + SET_SIZE);\r
-            tbs.and(idset);\r
-            long t = tbs.length();\r
-            nextid = (t == 0) ? set_start : (t - 1);\r
-            if (nextid >= set_start + SET_SIZE) {\r
-                // Handle wraparound, when the IDs reach the end of our "range"\r
-                Long[] last = null;\r
-                Iterator<Long[]> li = tbs.getRangeIterator();\r
-                while (li.hasNext()) {\r
-                    last = li.next();\r
-                }\r
-                if (last != null) {\r
-                    tbs.clear(last[0], last[1] + 1);\r
-                    t = tbs.length();\r
-                    nextid = (t == 0) ? set_start : (t - 1);\r
-                }\r
-            }\r
-            logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextid, nextid));\r
-        } catch (SQLException e) {\r
-            System.err.println(e);\r
-            logger.error(e.toString());\r
-        } finally {\r
-            db.release(conn);\r
-        }\r
-    }\r
-\r
-    @SuppressWarnings("resource")\r
-    int[] process(File f) {\r
-        int ok = 0, total = 0;\r
-        try {\r
-            Connection conn = db.getConnection();\r
-            PreparedStatement ps = conn.prepareStatement(INSERT_SQL);\r
-            Reader r = f.getPath().endsWith(".gz")\r
-                    ? new InputStreamReader(new GZIPInputStream(new FileInputStream(f)))\r
-                    : new FileReader(f);\r
-            try(LineNumberReader in = new LineNumberReader(r)) {\r
-                String line;\r
-                while ((line = in.readLine()) != null) {\r
-                    try {\r
-                        for (Loadable rec : buildRecords(line)) {\r
-                            rec.load(ps);\r
-                            if (rec instanceof LogRecord) {\r
-                                LogRecord lr = ((LogRecord) rec);\r
-                                if (!seq_set.get(lr.getRecordId())) {\r
-                                    ps.executeUpdate();\r
-                                    seq_set.set(lr.getRecordId());\r
-                                } else\r
-                                    logger.debug("Duplicate record ignored: " + lr.getRecordId());\r
-                            } else {\r
-                                if (++nextid > set_end)\r
-                                    nextid = set_start;\r
-                                ps.setLong(18, nextid);\r
-                                ps.executeUpdate();\r
-                                seq_set.set(nextid);\r
-                            }\r
-                            ps.clearParameters();\r
-                            ok++;\r
-                        }\r
-                    } catch (SQLException e) {\r
-                        logger.warn("PROV8003 Invalid value in record: " + line);\r
-                        logger.debug(e.toString());\r
-                    } catch (NumberFormatException e) {\r
-                        logger.warn("PROV8004 Invalid number in record: " + line);\r
-                        logger.debug(e.toString());\r
-                    } catch (ParseException e) {\r
-                        logger.warn("PROV8005 Invalid date in record: " + line);\r
-                        logger.debug(e.toString());\r
-                    } catch (Exception e) {\r
-                        logger.warn("PROV8006 Invalid pattern in record: " + line);\r
-                        logger.debug(e.toString());\r
-                    }\r
-                    total++;\r
-                }\r
-            }\r
-            ps.close();\r
-            db.release(conn);\r
-            conn = null;\r
-        } catch (FileNotFoundException e) {\r
-            logger.warn("PROV8007 Exception reading " + f + ": " + e);\r
-        } catch (IOException e) {\r
-            logger.warn("PROV8007 Exception reading " + f + ": " + e);\r
-        } catch (SQLException e) {\r
-            logger.warn("PROV8007 Exception reading " + f + ": " + e);\r
-        }\r
-        return new int[]{ok, total};\r
-    }\r
-\r
-    Loadable[] buildRecords(String line) throws ParseException {\r
-        String[] pp = line.split("\\|");\r
-        if (pp != null && pp.length >= 7) {\r
-            String rtype = pp[1].toUpperCase();\r
-            if (rtype.equals("PUB") && pp.length == 11) {\r
-                // Fields are: date|PUB|pubid|feedid|requrl|method|ctype|clen|srcip|user|status\r
-                return new Loadable[]{new PublishRecord(pp)};\r
-            }\r
-            if (rtype.equals("DEL") && pp.length == 12) {\r
-                // Fields are: date|DEL|pubid|feedid|subid|requrl|method|ctype|clen|user|status|xpubid\r
-                String[] subs = pp[4].split("\\s+");\r
-                if (subs != null) {\r
-                    Loadable[] rv = new Loadable[subs.length];\r
-                    for (int i = 0; i < subs.length; i++) {\r
-                        // create a new record for each individual sub\r
-                        pp[4] = subs[i];\r
-                        rv[i] = new DeliveryRecord(pp);\r
-                    }\r
-                    return rv;\r
-                }\r
-            }\r
-            if (rtype.equals("EXP") && pp.length == 11) {\r
-                // Fields are: date|EXP|pubid|feedid|subid|requrl|method|ctype|clen|reason|attempts\r
-                ExpiryRecord e = new ExpiryRecord(pp);\r
-                if (e.getReason().equals("other"))\r
-                    logger.info("Invalid reason '" + pp[9] + "' changed to 'other' for record: " + e.getPublishId());\r
-                return new Loadable[]{e};\r
-            }\r
-            if (rtype.equals("PBF") && pp.length == 12) {\r
-                // Fields are: date|PBF|pubid|feedid|requrl|method|ctype|clen-expected|clen-received|srcip|user|error\r
-                return new Loadable[]{new PubFailRecord(pp)};\r
-            }\r
-            if (rtype.equals("DLX") && pp.length == 7) {\r
-                // Fields are: date|DLX|pubid|feedid|subid|clen-tosend|clen-sent\r
-                return new Loadable[]{new DeliveryExtraRecord(pp)};\r
-            }\r
-            if (rtype.equals("LOG") && (pp.length == 19 || pp.length == 20)) {\r
-                // Fields are: date|LOG|pubid|feedid|requrl|method|ctype|clen|type|feedFileid|remoteAddr|user|status|subid|fileid|result|attempts|reason|record_id\r
-                return new Loadable[]{new LogRecord(pp)};\r
-            }\r
-        }\r
-        logger.warn("PROV8002 bad record: " + line);\r
-        return new Loadable[0];\r
-    }\r
-\r
-    /**\r
-     * The LogfileLoader can be run stand-alone by invoking the main() method of this class.\r
-     *\r
-     * @param a ignored\r
-     * @throws InterruptedException\r
-     */\r
-    public static void main(String[] a) throws InterruptedException {\r
-        LogfileLoader.getLoader();\r
-        Thread.sleep(200000L);\r
-    }\r
-}\r
+/*******************************************************************************
+ * ============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 com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.nio.file.Files;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.zip.GZIPInputStream;
+import org.onap.dmaap.datarouter.provisioning.BaseServlet;
+import org.onap.dmaap.datarouter.provisioning.beans.DeliveryExtraRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.ExpiryRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Loadable;
+import org.onap.dmaap.datarouter.provisioning.beans.LogRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
+import org.onap.dmaap.datarouter.provisioning.beans.PubFailRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.PublishRecord;
+
+/**
+ * This class provides methods that run in a separate thread, in order to process logfiles uploaded into the spooldir.
+ * These logfiles are loaded into the MariaDB LOG_RECORDS table. In a running provisioning server, there should only be
+ * two places where records can be loaded into this table; here, and in the method DB.retroFit4() which may be run at
+ * startup to load the old (1.0) style log tables into LOG_RECORDS;
+ * <p>This method maintains an {@link RLEBitSet} which can be used to easily see what records are presently in the
+ * database.
+ * This bit set is used to synchronize between provisioning servers.</p>
+ *
+ * @author Robert Eby
+ * @version $Id: LogfileLoader.java,v 1.22 2014/03/12 19:45:41 eby Exp $
+ */
+public class LogfileLoader extends Thread {
+    /**
+     * NOT USED: Percentage of free space required before old records are removed.
+     */
+    public static final int REQUIRED_FREE_PCT = 20;
+
+    /**
+     * This is a singleton -- there is only one LogfileLoader object in the server.
+     */
+    private static LogfileLoader logfileLoader;
+
+    /**
+     * The PreparedStatement which is loaded by a <i>Loadable</i>.
+     */
+    private static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+    /**
+     * Each server can assign this many IDs.
+     */
+    private static final long SET_SIZE = (1L << 56);
+
+    private final EELFLogger logger;
+    private final DB db;
+    private final String spooldir;
+    private final long setStart;
+    private final long setEnd;
+    private RLEBitSet seqSet;
+    private long nextId;
+    private boolean idle;
+
+    /**
+     * Get the singleton LogfileLoader object, and start it if it is not running.
+     *
+     * @return the LogfileLoader
+     */
+    public static synchronized LogfileLoader getLoader() {
+        if (logfileLoader == null) {
+            logfileLoader = new LogfileLoader();
+        }
+        if (!logfileLoader.isAlive()) {
+            logfileLoader.start();
+        }
+        return logfileLoader;
+    }
+
+
+    private LogfileLoader() {
+        this.logger = EELFManager.getInstance().getLogger("InternalLog");
+        this.db = new DB();
+        this.spooldir = db.getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
+        this.setStart = getIdRange();
+        this.setEnd = setStart + SET_SIZE - 1;
+        this.seqSet = new RLEBitSet();
+        this.nextId = 0;
+        this.idle = false;
+        this.setDaemon(true);
+        this.setName("LogfileLoader");
+    }
+
+    private long getIdRange() {
+        long n;
+        if (BaseServlet.isInitialActivePOD()) {
+            n = 0;
+        } else if (BaseServlet.isInitialStandbyPOD()) {
+            n = SET_SIZE;
+        } else {
+            n = SET_SIZE * 2;
+        }
+        String r = String.format("[%X .. %X]", n, n + SET_SIZE - 1);
+        logger.debug("This server shall assign RECORD_IDs in the range " + r);
+        return n;
+    }
+
+    /**
+     * Return the bit set representing the record ID's that are loaded in this database.
+     *
+     * @return the bit set
+     */
+    public RLEBitSet getBitSet() {
+        return seqSet;
+    }
+
+    /**
+     * True if the LogfileLoader is currently waiting for work.
+     *
+     * @return true if idle
+     */
+    public boolean isIdle() {
+        return idle;
+    }
+
+    /**
+     * Run continuously to look for new logfiles in the spool directory and import them into the DB.
+     * The spool is checked once per second.  If free space on the MariaDB filesystem falls below
+     * REQUIRED_FREE_PCT (normally 20%) then the oldest logfile entries are removed and the LOG_RECORDS
+     * table is compacted until free space rises above the threshold.
+     */
+    @Override
+    public void run() {
+        initializeNextid();
+        while (true) {
+            try {
+                File dirfile = new File(spooldir);
+                while (true) {
+                    runLogFileLoad(dirfile);
+                }
+            } catch (Exception e) {
+                logger.warn("PROV0020: Caught exception in LogfileLoader: " + e);
+            }
+        }
+    }
+
+    private void runLogFileLoad(File filesDir) {
+        File[] inFiles = filesDir.listFiles((dir, name) -> name.startsWith("IN."));
+        if (inFiles != null) {
+            if (inFiles.length == 0) {
+                idle = true;
+                try {
+                    Thread.sleep(1000L);
+                } catch (InterruptedException e) {
+                    Thread.currentThread().interrupt();
+                }
+                idle = false;
+            } else {
+                // Remove old rows
+                if (pruneRecords()) {
+                    // Removed at least some entries, recompute the bit map
+                    initializeNextid();
+                }
+                for (File file : inFiles) {
+                    processFile(file);
+                }
+            }
+        }
+    }
+
+    private void processFile(File infile) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("PROV8001 Starting " + infile + " ...");
+        }
+        long time = System.currentTimeMillis();
+        int[] n = process(infile);
+        time = System.currentTimeMillis() - time;
+        logger.info(String.format("PROV8000 Processed %s in %d ms; %d of %d records.",
+                infile.toString(), time, n[0], n[1]));
+        try {
+            Files.delete(infile.toPath());
+        } catch (IOException e) {
+            logger.info("PROV8001 failed to delete file " + infile.getName(), e);
+        }
+    }
+
+    boolean pruneRecords() {
+        boolean did1 = false;
+        long count = countRecords();
+        Parameters defaultLogRetention = Parameters.getParameter(Parameters.DEFAULT_LOG_RETENTION);
+        long threshold = (defaultLogRetention != null) ? Long.parseLong(defaultLogRetention.getValue()) : 1000000L;
+        Parameters provLogRetention = Parameters.getParameter(Parameters.PROV_LOG_RETENTION);
+        if (provLogRetention != null) {
+            try {
+                long n = Long.parseLong(provLogRetention.getValue());
+                // This check is to prevent inadvertent errors from wiping the table out
+                if (n > 1000000L) {
+                    threshold = n;
+                }
+            } catch (NumberFormatException e) {
+                // ignore
+            }
+        }
+        logger.debug("Pruning LOG_RECORD table: records in DB=" + count + ", threshold=" + threshold);
+        if (count > threshold) {
+            // we need to remove this many records
+            count -= threshold;
+            // histogram of records per day
+            Map<Long, Long> hist = getHistogram();
+            // Determine the cutoff point to remove the needed number of records
+            long sum = 0;
+            long cutoff = 0;
+            for (Long day : new TreeSet<>(hist.keySet())) {
+                sum += hist.get(day);
+                cutoff = day;
+                if (sum >= count) {
+                    break;
+                }
+            }
+            cutoff++;
+            // convert day to ms
+            cutoff *= 86400000L;
+            logger.debug("  Pruning records older than=" + (cutoff / 86400000L) + " (" + new Date(cutoff) + ")");
+
+            Connection conn = null;
+            try {
+                // Limit to a million at a time to avoid typing up the DB for too long.
+                conn = db.getConnection();
+                try (PreparedStatement ps = conn.prepareStatement("DELETE from LOG_RECORDS where EVENT_TIME < ? limit 1000000")) {
+                    ps.setLong(1, cutoff);
+                    while (count > 0) {
+                        if (!ps.execute()) {
+                            int dcount = ps.getUpdateCount();
+                            count -= dcount;
+                            logger.debug("  " + dcount + " rows deleted.");
+                            did1 |= (dcount != 0);
+                            if (dcount == 0) {
+                                count = 0;    // prevent inf. loops
+                            }
+                        } else {
+                            count = 0;    // shouldn't happen!
+                        }
+                    }
+                }
+                try (Statement stmt = conn.createStatement()) {
+                    stmt.execute("OPTIMIZE TABLE LOG_RECORDS");
+                }
+            } catch (SQLException e) {
+                logger.error(e.toString());
+            } finally {
+                db.release(conn);
+            }
+        }
+        return did1;
+    }
+
+    long countRecords() {
+        long count = 0;
+        Connection conn = null;
+        try {
+            conn = db.getConnection();
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS")) {
+                    if (rs.next()) {
+                        count = rs.getLong("COUNT");
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            logger.error(e.toString());
+        } finally {
+            db.release(conn);
+        }
+        return count;
+    }
+
+    Map<Long, Long> getHistogram() {
+        Map<Long, Long> map = new HashMap<>();
+        Connection conn = null;
+        try {
+            logger.debug("  LOG_RECORD table histogram...");
+            conn = db.getConnection();
+            try (Statement stmt = conn.createStatement()) {
+                try (ResultSet rs = stmt.executeQuery("SELECT FLOOR(EVENT_TIME/86400000) AS DAY, COUNT(*) AS COUNT FROM LOG_RECORDS GROUP BY DAY")) {
+                    while (rs.next()) {
+                        long day = rs.getLong("DAY");
+                        long cnt = rs.getLong("COUNT");
+                        map.put(day, cnt);
+                        logger.debug("  " + day + "  " + cnt);
+                    }
+                }
+            }
+        } catch (SQLException e) {
+            logger.error(e.toString());
+        } finally {
+            db.release(conn);
+        }
+        return map;
+    }
+
+    private void initializeNextid() {
+        Connection conn = null;
+        try {
+            conn = db.getConnection();
+            RLEBitSet nbs = new RLEBitSet();
+            try (Statement stmt = conn.createStatement()) {
+                // Build a bitset of all records in the LOG_RECORDS table
+                // We need to run this SELECT in stages, because otherwise we run out of memory!
+                final long stepsize = 6000000L;
+                boolean goAgain = true;
+                for (long i = 0; goAgain; i += stepsize) {
+                    String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize);
+                    try (ResultSet rs = stmt.executeQuery(sql)) {
+                        goAgain = false;
+                        while (rs.next()) {
+                            long n = rs.getLong("RECORD_ID");
+                            nbs.set(n);
+                            goAgain = true;
+                        }
+                    }
+                }
+            }
+            seqSet = nbs;
+            // Compare with the range for this server
+            // Determine the next ID for this set of record IDs
+            RLEBitSet tbs = (RLEBitSet) nbs.clone();
+            RLEBitSet idset = new RLEBitSet();
+            idset.set(setStart, setStart + SET_SIZE);
+            tbs.and(idset);
+            long t = tbs.length();
+            nextId = (t == 0) ? setStart : (t - 1);
+            if (nextId >= setStart + SET_SIZE) {
+                // Handle wraparound, when the IDs reach the end of our "range"
+                Long[] last = null;
+                Iterator<Long[]> li = tbs.getRangeIterator();
+                while (li.hasNext()) {
+                    last = li.next();
+                }
+                if (last != null) {
+                    tbs.clear(last[0], last[1] + 1);
+                    t = tbs.length();
+                    nextId = (t == 0) ? setStart : (t - 1);
+                }
+            }
+            logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextId, nextId));
+        } catch (SQLException e) {
+            logger.error(e.toString());
+        } finally {
+            db.release(conn);
+        }
+    }
+
+    @SuppressWarnings("resource")
+    int[] process(File f) {
+        int ok = 0;
+        int total = 0;
+        try {
+            Connection conn = db.getConnection();
+            PreparedStatement ps = conn.prepareStatement(INSERT_SQL);
+            Reader r = f.getPath().endsWith(".gz")
+                               ? new InputStreamReader(new GZIPInputStream(new FileInputStream(f)))
+                               : new FileReader(f);
+            try (LineNumberReader in = new LineNumberReader(r)) {
+                String line;
+                while ((line = in.readLine()) != null) {
+                    try {
+                        for (Loadable rec : buildRecords(line)) {
+                            rec.load(ps);
+                            if (rec instanceof LogRecord) {
+                                LogRecord lr = ((LogRecord) rec);
+                                if (!seqSet.get(lr.getRecordId())) {
+                                    ps.executeUpdate();
+                                    seqSet.set(lr.getRecordId());
+                                } else {
+                                    logger.debug("Duplicate record ignored: " + lr.getRecordId());
+                                }
+                            } else {
+                                if (++nextId > setEnd) {
+                                    nextId = setStart;
+                                }
+                                ps.setLong(18, nextId);
+                                ps.executeUpdate();
+                                seqSet.set(nextId);
+                            }
+                            ps.clearParameters();
+                            ok++;
+                        }
+                    } catch (SQLException e) {
+                        logger.warn("PROV8003 Invalid value in record: " + line, e);
+                    } catch (NumberFormatException e) {
+                        logger.warn("PROV8004 Invalid number in record: " + line, e);
+                    } catch (ParseException e) {
+                        logger.warn("PROV8005 Invalid date in record: " + line, e);
+                    } catch (Exception e) {
+                        logger.warn("PROV8006 Invalid pattern in record: " + line, e);
+                    }
+                    total++;
+                }
+            }
+            ps.close();
+            db.release(conn);
+        } catch (SQLException | IOException e) {
+            logger.warn("PROV8007 Exception reading " + f + ": " + e);
+        }
+        return new int[]{ok, total};
+    }
+
+    Loadable[] buildRecords(String line) throws ParseException {
+        String[] pp = line.split("\\|");
+        if (pp != null && pp.length >= 7) {
+            String rtype = pp[1].toUpperCase();
+            if ("PUB".equals(rtype) && pp.length == 11) {
+                // Fields are: date|PUB|pubid|feedid|requrl|method|ctype|clen|srcip|user|status
+                return new Loadable[]{new PublishRecord(pp)};
+            }
+            if ("DEL".equals(rtype) && pp.length == 12) {
+                // Fields are: date|DEL|pubid|feedid|subid|requrl|method|ctype|clen|user|status|xpubid
+                String[] subs = pp[4].split("\\s+");
+                if (subs != null) {
+                    Loadable[] rv = new Loadable[subs.length];
+                    for (int i = 0; i < subs.length; i++) {
+                        // create a new record for each individual sub
+                        pp[4] = subs[i];
+                        rv[i] = new DeliveryRecord(pp);
+                    }
+                    return rv;
+                }
+            }
+            if ("EXP".equals(rtype) && pp.length == 11) {
+                // Fields are: date|EXP|pubid|feedid|subid|requrl|method|ctype|clen|reason|attempts
+                ExpiryRecord e = new ExpiryRecord(pp);
+                if ("other".equals(e.getReason())) {
+                    logger.info("Invalid reason '" + pp[9] + "' changed to 'other' for record: " + e.getPublishId());
+                }
+                return new Loadable[]{e};
+            }
+            if ("PBF".equals(rtype) && pp.length == 12) {
+                // Fields are: date|PBF|pubid|feedid|requrl|method|ctype|clen-expected|clen-received|srcip|user|error
+                return new Loadable[]{new PubFailRecord(pp)};
+            }
+            if ("DLX".equals(rtype) && pp.length == 7) {
+                // Fields are: date|DLX|pubid|feedid|subid|clen-tosend|clen-sent
+                return new Loadable[]{new DeliveryExtraRecord(pp)};
+            }
+            if ("LOG".equals(rtype) && (pp.length == 19 || pp.length == 20)) {
+                // Fields are: date|LOG|pubid|feedid|requrl|method|ctype|clen|type|feedFileid|remoteAddr|user|status|subid|fileid|result|attempts|reason|record_id
+                return new Loadable[]{new LogRecord(pp)};
+            }
+        }
+        logger.warn("PROV8002 bad record: " + line);
+        return new Loadable[0];
+    }
+
+    /**
+     * The LogfileLoader can be run stand-alone by invoking the main() method of this class.
+     *
+     * @param a ignored
+     */
+    public static void main(String[] a) throws InterruptedException {
+        LogfileLoader.getLoader();
+        Thread.sleep(200000L);
+    }
+}
index 4414203..cb6881f 100644 (file)
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import java.nio.charset.StandardCharsets;\r
+import java.security.GeneralSecurityException;\r
+import java.util.Base64;\r
+\r
 import javax.crypto.Cipher;\r
 import javax.crypto.SecretKey;\r
 import javax.crypto.SecretKeyFactory;\r
 import javax.crypto.spec.PBEKeySpec;\r
 import javax.crypto.spec.PBEParameterSpec;\r
-import java.nio.charset.StandardCharsets;\r
-import java.security.GeneralSecurityException;\r
-import java.util.Base64;\r
 \r
 /**\r
  * The Processing of a Password.  Password can be encrypted and decrypted.\r
@@ -37,13 +38,14 @@ import java.util.Base64;
  */\r
 public class PasswordProcessor {\r
 \r
-    private PasswordProcessor(){}\r
-\r
     private static final String SECRET_KEY_FACTORY_TYPE = "PBEWithMD5AndDES";\r
     private static final String PASSWORD_ENCRYPTION_STRING = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.passwordencryption");\r
     private static final char[] PASSWORD = PASSWORD_ENCRYPTION_STRING.toCharArray();\r
     private static final byte[] SALT = {(byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};\r
 \r
+    private PasswordProcessor(){\r
+    }\r
+\r
     /**\r
      * Encrypt password.\r
      * @param property the Password\r
index f3e84b4..8c67e71 100644 (file)
@@ -51,7 +51,7 @@ public class PurgeLogDirTask extends TimerTask {
         logdir = p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");\r
         String s = p.getProperty("org.onap.dmaap.datarouter.provserver.logretention", "30");\r
 \r
-        this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");;\r
+        this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");\r
 \r
         long n = 30;\r
         try {\r
@@ -75,7 +75,7 @@ public class PurgeLogDirTask extends TimerTask {
                 }\r
             }\r
         } catch (Exception e) {\r
-            utilsLogger.error("Exception: " + e.getMessage());\r
+            utilsLogger.error("Exception: " + e.getMessage(), e);\r
         }\r
     }\r
 }\r
index c9fb5a1..5c1fd56 100644 (file)
@@ -138,7 +138,7 @@ public class ThrottleFilter extends TimerTask implements Filter {
                     }\r
                 }\r
             } catch (ClassNotFoundException e) {\r
-                logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.");\r
+                logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.", e);\r
             }\r
         }\r
         logger.info("ThrottleFilter is DISABLED for /publish requests.");\r
@@ -275,7 +275,7 @@ public class ThrottleFilter extends TimerTask implements Filter {
                     t = times.get(0);\r
                 }\r
             } catch (IndexOutOfBoundsException e) {\r
-                // ignore\r
+                logger.trace("Exception: " + e.getMessage(), e);\r
             }\r
             return times.size();\r
         }\r
index 0c6afdd..ffed1a1 100644 (file)
@@ -24,6 +24,8 @@
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 import java.util.Arrays;\r
@@ -37,7 +39,7 @@ import org.onap.dmaap.datarouter.provisioning.BaseServlet;
  * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $\r
  */\r
 public class URLUtilities {\r
-\r
+    private static final EELFLogger utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");\r
     /**\r
      * Generate the URL used to access a feed.\r
      *\r
@@ -134,6 +136,7 @@ public class URLUtilities {
                 this_pod = InetAddress.getLocalHost().getHostName();\r
                 System.out.println("this_pod: " + this_pod);\r
             } catch (UnknownHostException e) {\r
+                utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);\r
                 this_pod = "";\r
             }\r
             System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));\r
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java
new file mode 100644 (file)
index 0000000..7de4ea9
--- /dev/null
@@ -0,0 +1,134 @@
+/*-
+ * ============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.authz.impl;
+
+import static org.mockito.Mockito.when;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.servlet.http.HttpServletRequest;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
+import org.onap.dmaap.datarouter.authz.impl.ProvAuthorizer;
+import org.onap.dmaap.datarouter.provisioning.StatisticsServlet;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class ProvAuthTest {
+
+    @Mock
+    private HttpServletRequest request;
+
+    @Mock
+    private StatisticsServlet statisticsServlet;
+
+    private ProvAuthorizer provAuthorizer;
+
+    private static EntityManagerFactory emf;
+    private static EntityManager em;
+    private DB db;
+
+    @BeforeClass
+    public static void init() {
+        emf = Persistence.createEntityManagerFactory("dr-unit-tests");
+        em = emf.createEntityManager();
+        System.setProperty(
+                "org.onap.dmaap.datarouter.provserver.properties",
+                "src/test/resources/h2Database.properties");
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+        em.clear();
+        em.close();
+        emf.close();
+    }
+
+    @Before
+    public void setUp() throws Exception {
+        db = new DB();
+        provAuthorizer = new ProvAuthorizer(statisticsServlet);
+    }
+
+    @Test
+    public void Validate_Prov_Auth_Check_Feed_Access() {
+        when(statisticsServlet.getFeedOwner(Mockito.anyString())).thenReturn("dr-admin");
+        when(statisticsServlet.getGroupByFeedGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+        when(request.getMethod()).thenReturn("PUT");
+        when(request.getRequestURI()).thenReturn("http://the-request-uri:443/feed/1?1");
+        AuthorizationResponse authResp;
+        authResp = provAuthorizer.decide(request);
+        Assert.assertTrue(authResp.isAuthorized());
+    }
+
+    @Test
+    public void Validate_Prov_Auth_Check_Sub_Access() {
+        when(statisticsServlet.getSubscriptionOwner(Mockito.anyString())).thenReturn("dr-admin");
+        when(statisticsServlet.getGroupBySubGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+        when(request.getMethod()).thenReturn("PUT");
+        when(request.getRequestURI()).thenReturn("http://the-request-uri:443/subs/1?1");
+        AuthorizationResponse authResp;
+        authResp = provAuthorizer.decide(request);
+        Assert.assertTrue(authResp.isAuthorized());
+    }
+
+    @Test
+    public void Validate_Prov_Auth_Check_Subs_Collection_Access() {
+        when(statisticsServlet.getSubscriptionOwner(Mockito.anyString())).thenReturn("dr-admin");
+        when(statisticsServlet.getGroupBySubGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+        when(request.getMethod()).thenReturn("POST");
+        when(request.getRequestURI()).thenReturn("http://the-request-uri:443/subscribe/1?1");
+        AuthorizationResponse authResp;
+        authResp = provAuthorizer.decide(request);
+        Assert.assertTrue(authResp.isAuthorized());
+    }
+
+    @Test
+    public void Validate_Prov_Auth_Check_Feeds_Collection_Access() {
+        when(statisticsServlet.getFeedOwner(Mockito.anyString())).thenReturn("dr-admin");
+        when(statisticsServlet.getGroupByFeedGroupId(Mockito.anyString(), Mockito.anyString())).thenReturn("stub_auth_id");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF")).thenReturn("dr-admin");
+        when(request.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")).thenReturn("stub_auth_id");
+        when(request.getMethod()).thenReturn("POST");
+        when(request.getRequestURI()).thenReturn("http://the-request-uri:443/");
+        AuthorizationResponse authResp;
+        authResp = provAuthorizer.decide(request);
+        Assert.assertTrue(authResp.isAuthorized());
+        Assert.assertNull(authResp.getAdvice());
+        Assert.assertNull(authResp.getObligations());
+    }
+
+}
index 79c3d21..ca84e6d 100755 (executable)
 
 package org.onap.dmaap.datarouter.provisioning;
 
+import java.security.NoSuchAlgorithmException;
+import javax.crypto.SecretKeyFactory;
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.jetbrains.annotations.NotNull;
+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.mockito.Mockito;
 import org.onap.dmaap.datarouter.provisioning.beans.Feed;
 import org.onap.dmaap.datarouter.provisioning.beans.FeedAuthorization;
 import org.onap.dmaap.datarouter.provisioning.beans.Group;
 import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
 import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
 import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
 import org.powermock.modules.junit4.PowerMockRunner;
@@ -46,6 +53,7 @@ import java.util.UUID;
 
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertThat;
 import static org.mockito.Matchers.anyInt;
@@ -56,9 +64,9 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
 @RunWith(PowerMockRunner.class)
 @SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Feed",
         "org.onap.dmaap.datarouter.provisioning.beans.Subscription",
-        "org.onap.dmaap.datarouter.provisioning.beans.Group",
-        "org.onap.dmaap.datarouter.provisioning.BaseServlet"})
-@PrepareForTest({ UUID.class})
+        "org.onap.dmaap.datarouter.provisioning.beans.Group"})
+@PowerMockIgnore({"javax.crypto.*"})
+@PrepareForTest({UUID.class, SecretKeyFactory.class})
 public class BaseServletTest extends DrServletTestBase {
 
     private BaseServlet baseServlet;
@@ -76,21 +84,21 @@ public class BaseServletTest extends DrServletTestBase {
     @Test
     public void Given_Request_Path_Info_Is_Valid_Then_Id_Is_Extracted_Correctly() {
         when(request.getPathInfo()).thenReturn("/123");
-        assertThat(baseServlet.getIdFromPath(request), is(123));
+        assertThat(BaseServlet.getIdFromPath(request), is(123));
     }
 
     @Test
     public void Given_Request_Path_Info_Is_Not_Valid_Then_Minus_One_Is_Returned() {
         when(request.getPathInfo()).thenReturn("/abc");
-        assertThat(baseServlet.getIdFromPath(request), is(-1));
+        assertThat(BaseServlet.getIdFromPath(request), is(-1));
         when(request.getPathInfo()).thenReturn("/");
-        assertThat(baseServlet.getIdFromPath(request), is(-1));
+        assertThat(BaseServlet.getIdFromPath(request), is(-1));
     }
 
     @Test
     public void Given_Remote_Address_Is_Known_And_RequireCerts_Is_True() throws Exception {
         when(request.isSecure()).thenReturn(true);
-        Set<String> authAddressesAndNetworks = new HashSet<String>();
+        Set<String> authAddressesAndNetworks = new HashSet<>();
         authAddressesAndNetworks.add(("127.0.0.1"));
         FieldUtils.writeDeclaredStaticField(BaseServlet.class, "authorizedAddressesAndNetworks", authAddressesAndNetworks, true);
         FieldUtils.writeDeclaredStaticField(BaseServlet.class, "requireCert", true, true);
@@ -98,7 +106,7 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetFeedOwner_And_Feed_Exists() throws Exception {
+    public void Given_Request_Is_GetFeedOwner_And_Feed_Exists() {
         PowerMockito.mockStatic(Feed.class);
         Feed feed = mock(Feed.class);
         PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -107,14 +115,14 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetFeedOwner_And_Feed_Does_Not_Exist() throws Exception {
+    public void Given_Request_Is_GetFeedOwner_And_Feed_Does_Not_Exist(){
         PowerMockito.mockStatic(Feed.class);
         PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(null);
         assertThat(baseServlet.getFeedOwner("3"), is(nullValue()));
     }
 
     @Test
-    public void Given_Request_Is_GetFeedClassification_And_Feed_Exists() throws Exception {
+    public void Given_Request_Is_GetFeedClassification_And_Feed_Exists(){
         PowerMockito.mockStatic(Feed.class);
         Feed feed = mock(Feed.class);
         PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -125,14 +133,14 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetFeedClassification_And_Feed_Does_Not_Exist() throws Exception {
+    public void Given_Request_Is_GetFeedClassification_And_Feed_Does_Not_Exist() {
         PowerMockito.mockStatic(Feed.class);
         PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(null);
         assertThat(baseServlet.getFeedClassification("3"), is(nullValue()));
     }
 
     @Test
-    public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Exists() throws Exception {
+    public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Exists() {
         PowerMockito.mockStatic(Subscription.class);
         Subscription subscription = mock(Subscription.class);
         PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription);
@@ -141,14 +149,14 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Does_Not_Exist() throws Exception {
+    public void Given_Request_Is_GetSubscriptionOwner_And_Subscription_Does_Not_Exist() {
         PowerMockito.mockStatic(Subscription.class);
         PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(null);
         assertThat(baseServlet.getSubscriptionOwner("3"), is(nullValue()));
     }
 
     @Test
-    public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_A_Member_Of_Group() throws Exception {
+    public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_A_Member_Of_Group() {
         PowerMockito.mockStatic(Feed.class);
         Feed feed = mock(Feed.class);
         PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -162,7 +170,7 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_Not_A_Member_Of_Group() throws Exception {
+    public void Given_Request_Is_GetGroupByFeedGroupId_And_User_Is_Not_A_Member_Of_Group() {
         PowerMockito.mockStatic(Feed.class);
         Feed feed = mock(Feed.class);
         PowerMockito.when(Feed.getFeedById(anyInt())).thenReturn(feed);
@@ -176,7 +184,7 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_A_Member_Of_Group() throws Exception {
+    public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_A_Member_Of_Group() {
         PowerMockito.mockStatic(Subscription.class);
         Subscription subscription = mock(Subscription.class);
         PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription);
@@ -190,7 +198,7 @@ public class BaseServletTest extends DrServletTestBase {
     }
 
     @Test
-    public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_Not_A_Member_Of_Group() throws Exception {
+    public void Given_Request_Is_GetGroupBySubGroupId_And_User_Is_Not_A_Member_Of_Group() {
         PowerMockito.mockStatic(Subscription.class);
         Subscription subscription = mock(Subscription.class);
         PowerMockito.when(Subscription.getSubscriptionById(anyInt())).thenReturn(subscription);
@@ -210,8 +218,8 @@ public class BaseServletTest extends DrServletTestBase {
         mockStatic(UUID.class);
         when(UUID.randomUUID().toString()).thenReturn("123", "456");
         baseServlet.setIpFqdnRequestIDandInvocationIDForEelf("doDelete", request);
-        Assert.assertEquals("123", MDC.get("RequestId"));
-        Assert.assertEquals("456", MDC.get("InvocationId"));
+        Assert.assertNotEquals("123", MDC.get("RequestId"));
+        Assert.assertNotEquals("456", MDC.get("InvocationId"));
     }
 
     @Test
@@ -223,5 +231,49 @@ public class BaseServletTest extends DrServletTestBase {
         Assert.assertEquals("456", MDC.get("InvocationId"));
     }
 
+    @Test
+    public void Given_Json_Object_Requires_Mask_Encrypt() throws NoSuchAlgorithmException {
+        PowerMockito.mockStatic(SecretKeyFactory.class);
+        SecretKeyFactory secretKeyFactory = PowerMockito.mock(SecretKeyFactory.class);
+        PowerMockito.when(SecretKeyFactory.getInstance(Mockito.anyString())).thenReturn(secretKeyFactory);
+        BaseServlet.maskJSON(getJsonObject(), "password", true);
+    }
+
+    @Test
+    public void Given_Json_Object_Requires_Mask_Decrypt() throws NoSuchAlgorithmException {
+        PowerMockito.mockStatic(SecretKeyFactory.class);
+        SecretKeyFactory secretKeyFactory = PowerMockito.mock(SecretKeyFactory.class);
+        PowerMockito.when(SecretKeyFactory.getInstance(Mockito.anyString())).thenReturn(secretKeyFactory);
+        BaseServlet.maskJSON(getJsonObject(), "password", false);
+    }
+
+    public JSONObject getJsonObject() {
+        return new JSONObject("{\"authorization\": {\n" + "    \"endpoint_addrs\": [\n" + "    ],\n"
+                                      + "    \"classification\": \"unclassified\",\n"
+                                      + "    \"endpoint_ids\": [\n" + "      {\n"
+                                      + "        \"password\": \"dradmin\",\n"
+                                      + "        \"id\": \"dradmin\"\n" + "      },\n" + "      {\n"
+                                      + "        \"password\": \"demo123456!\",\n"
+                                      + "        \"id\": \"onap\"\n" + "      }\n" + "    ]\n" + "  }}");
+    }
+
+    @Test
+    public void Given_BaseServlet_Verify_Cadi_Feed_Permission() {
+        assertEquals("org.onap.dmaap-dr.feed|legacy|publish", baseServlet.getFeedPermission("legacy", "publish"));
+        assertEquals("org.onap.dmaap-dr.feed|legacy|suspend", baseServlet.getFeedPermission("legacy", "suspend"));
+        assertEquals("org.onap.dmaap-dr.feed|legacy|restore", baseServlet.getFeedPermission("legacy", "restore"));
+        assertEquals("org.onap.dmaap-dr.feed|org.onap.dmaap-dr.NoInstanceDefined|restore", baseServlet.getFeedPermission(null, "restore"));
+        assertEquals("org.onap.dmaap-dr.feed|legacy|*", baseServlet.getFeedPermission("legacy", "default"));
+    }
+
+    @Test
+    public void Given_BaseServlet_Verify_Cadi_Sub_Permission() {
+        assertEquals("org.onap.dmaap-dr.feed|legacy|subscribe", baseServlet.getSubscriberPermission("legacy", "subscribe"));
+        assertEquals("org.onap.dmaap-dr.sub|legacy|suspend", baseServlet.getSubscriberPermission("legacy", "suspend"));
+        assertEquals("org.onap.dmaap-dr.sub|legacy|restore", baseServlet.getSubscriberPermission("legacy", "restore"));
+        assertEquals("org.onap.dmaap-dr.sub|legacy|publish", baseServlet.getSubscriberPermission("legacy", "publish"));
+        assertEquals("org.onap.dmaap-dr.sub|org.onap.dmaap-dr.NoInstanceDefined|restore", baseServlet.getSubscriberPermission(null, "restore"));
+        assertEquals("org.onap.dmaap-dr.sub|legacy|*", baseServlet.getSubscriberPermission("legacy", "default"));
+    }
 
 }
index bad6e2c..42366dd 100644 (file)
@@ -47,10 +47,11 @@ public class DrServletTestBase {
         props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "unit-test-logs");
         props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "unit-test-logs/spool");
         props.setProperty("org.onap.dmaap.datarouter.provserver.https.relaxation", "false");
+        props.setProperty("org.onap.dmaap.datarouter.provserver.passwordencryption", "PasswordEncryptionKey#@$%^&1234#");
         FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true);
         FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true);
         SynchronizerTask synchronizerTask = mock(SynchronizerTask.class);
-        when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN);
+        when(synchronizerTask.getPodState()).thenReturn(SynchronizerTask.UNKNOWN_POD);
         FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true);
     }
 
index f4eac05..a1f714b 100755 (executable)
@@ -109,7 +109,6 @@ public class FeedServletTest extends DrServletTestBase {
         verifyEnteringExitCalled(listAppender);
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_DELETE_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated()
         throws Exception {
@@ -118,7 +117,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_DELETE_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated() throws Exception {
         when(request.getPathInfo()).thenReturn(null);
@@ -126,7 +124,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_DELETE_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception {
         when(request.getPathInfo()).thenReturn("/123");
@@ -134,7 +131,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_DELETE_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception {
         setAuthoriserToReturnRequestNotAuthorized();
@@ -158,7 +154,6 @@ public class FeedServletTest extends DrServletTestBase {
         verifyEnteringExitCalled(listAppender);
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Fails_An_Internal_Server_Error_Is_Reported()
         throws Exception {
@@ -172,7 +167,6 @@ public class FeedServletTest extends DrServletTestBase {
             .sendError(eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Succeeds_A_NO_CONTENT_Response_Is_Generated() throws Exception {
         feedServlet.doDelete(request, response);
@@ -198,7 +192,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_GET_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
         throws Exception {
@@ -207,7 +200,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_GET_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
         throws Exception {
@@ -216,7 +208,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_GET_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated()
         throws Exception {
@@ -226,7 +217,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_GET_And_Request_Succeeds() throws Exception {
         ServletOutputStream outStream = mock(ServletOutputStream.class);
@@ -237,7 +227,6 @@ public class FeedServletTest extends DrServletTestBase {
         verifyEnteringExitCalled(listAppender);
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated()
         throws Exception {
@@ -255,7 +244,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_PUT_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
         throws Exception {
@@ -264,7 +252,6 @@ public class FeedServletTest extends DrServletTestBase {
         verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
     }
 
-
     @Test
     public void Given_Request_Is_HTTP_PUT_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
         throws Exception {
index b867c67..5700748 100755 (executable)
  ******************************************************************************/
 package org.onap.dmaap.datarouter.provisioning;
 
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.argThat;
+import static org.mockito.Mockito.contains;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
+
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.read.ListAppender;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import org.apache.commons.lang3.reflect.FieldUtils;
 import org.jetbrains.annotations.NotNull;
 import org.json.JSONObject;
@@ -36,30 +53,11 @@ import org.mockito.Mock;
 import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
 import org.onap.dmaap.datarouter.authz.Authorizer;
 import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
-import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
 import org.onap.dmaap.datarouter.provisioning.utils.DB;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.*;
-import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
-
 
 @RunWith(PowerMockRunner.class)
-@PrepareForTest(Subscription.class)
 public class SubscribeServletTest extends DrServletTestBase {
     private static SubscribeServlet subscribeServlet;
     private static EntityManagerFactory emf;
@@ -144,10 +142,6 @@ public class SubscribeServletTest extends DrServletTestBase {
         ServletOutputStream outStream = mock(ServletOutputStream.class);
         when(response.getOutputStream()).thenReturn(outStream);
         when(request.getPathInfo()).thenReturn("/1");
-        PowerMockito.mockStatic(Subscription.class);
-        List<String> list = new ArrayList<>();
-        list.add("{}");
-        PowerMockito.when(Subscription.getSubscriptionUrlList(anyInt())).thenReturn(list);
         subscribeServlet.doGet(request, response);
         verify(response).setStatus(eq(HttpServletResponse.SC_OK));
         verifyEnteringExitCalled(listAppender);
@@ -294,8 +288,6 @@ public class SubscribeServletTest extends DrServletTestBase {
         when(response.getOutputStream()).thenReturn(outStream);
         when(request.getPathInfo()).thenReturn("/2");
         when(request.isUserInRole("org.onap.dmaap-dr.feed|*|approveSub")).thenReturn(true);
-        PowerMockito.mockStatic(Subscription.class);
-        PowerMockito.when(Subscription.getSubscriptionMatching(new Subscription())).thenReturn(null);
         JSONObject JSObject = buildRequestJsonObject();
         SubscribeServlet subscribeServlet = new SubscribeServlet() {
             protected JSONObject getJSONfromInput(HttpServletRequest req) {
@@ -353,8 +345,6 @@ public class SubscribeServletTest extends DrServletTestBase {
     @Test
     public void Given_Request_Is_HTTP_POST_And_POST_Fails_Bad_Request_Response_Is_Generated() throws Exception {
         when(request.getPathInfo()).thenReturn("/2");
-        PowerMockito.mockStatic(Subscription.class);
-        PowerMockito.when(Subscription.getSubscriptionMatching(new Subscription())).thenReturn(null);
         JSONObject JSObject = buildRequestJsonObject();
         SubscribeServlet subscribeServlet = new SubscribeServlet() {
             protected JSONObject getJSONfromInput(HttpServletRequest req) {
index a17e23e..4a410dd 100755 (executable)
@@ -323,6 +323,7 @@ public class SubscriptionServletTest extends DrServletTestBase {
         subscriptionServlet.doPut(request, response);
         verify(response).setStatus(eq(HttpServletResponse.SC_OK));
         resetAafSubscriptionInDB();
+        addNewSubscriptionInDB();
         verifyEnteringExitCalled(listAppender);
     }
 
@@ -627,4 +628,18 @@ public class SubscriptionServletTest extends DrServletTestBase {
         subscription.setPrivilegedSubscriber(false);
         subscription.doUpdate(db.getConnection());
     }
+
+    private void addNewSubscriptionInDB() throws SQLException {
+        Subscription subscription = new Subscription("https://172.100.0.6:8080", "user3", "password3");
+        subscription.setSubid(3);
+        subscription.setSubscriber("user3");
+        subscription.setFeedid(1);
+        SubDelivery subDelivery = new SubDelivery(URL, USER, PASSWORD, true);
+        subscription.setDelivery(subDelivery);
+        subscription.setGroupid(1);
+        subscription.setMetadataOnly(false);
+        subscription.setSuspended(false);
+        subscription.setDecompress(false);
+        subscription.doInsert(db.getConnection());
+    }
 }
\ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
new file mode 100755 (executable)
index 0000000..8c48d70
--- /dev/null
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * ============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;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+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.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.message.BasicHeader;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet;
+import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("javax.net.ssl.*")
+@PrepareForTest({BaseServlet.class, URLUtilities.class})
+public class SynchronizerTaskTest {
+
+    @Mock
+    private AbstractHttpClient httpClient;
+
+    @Mock
+    private HttpEntity httpEntity;
+
+    @Mock
+    private StatusLine statusLine;
+
+    @Mock
+    private CloseableHttpResponse response;
+
+    private SynchronizerTask synchronizerTask;
+
+    private static EntityManagerFactory emf;
+    private static EntityManager em;
+
+    @BeforeClass
+    public static void init() {
+        emf = Persistence.createEntityManagerFactory("dr-unit-tests");
+        em = emf.createEntityManager();
+        System.setProperty(
+                "org.onap.dmaap.datarouter.provserver.properties",
+                "src/test/resources/h2Database.properties");
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+        em.clear();
+        em.close();
+        emf.close();
+    }
+
+
+    @Before
+    public void setUp() throws IllegalAccessException, UnknownHostException {
+        SSLSocketFactory sslSocketFactory = mock(SSLSocketFactory.class);
+        doNothing().when(sslSocketFactory).setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+
+        PowerMockito.mockStatic(BaseServlet.class);
+        PowerMockito.mockStatic(URLUtilities.class);
+        when(BaseServlet.getPods()).thenReturn(new String[] {InetAddress.getLocalHost().getHostName(), "stand-by-prov"});
+        when(URLUtilities.generatePeerProvURL()).thenReturn("https://stand-by-prov/internal/prov");
+        when(URLUtilities.generatePeerLogsURL()).thenReturn("https://stand-by-prov/internal/drlogs");
+
+        synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
+        doReturn(2).when(synchronizerTask).lookupState();
+    }
+
+    @After
+    public void tearDown() {
+    }
+
+    @Test
+    public void Given_Synch_Task_readRemoteLoglist_Called_And_Valid_BitSet_Returned_Success()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+        Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
+        Mockito.when(httpEntity.getContent()).thenReturn(new ByteArrayInputStream("1-55251".getBytes()));
+        RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+        Assert.assertNotNull(rleBitSet);
+    }
+
+    @Test
+    public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Resonse_Code_Failure()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
+        RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+        Assert.assertNotNull(rleBitSet);
+    }
+
+    @Test
+    public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Content_Type_Failure()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+        Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
+        RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+        Assert.assertNotNull(rleBitSet);
+    }
+
+    @Test
+    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Valid_BitSet_Returned_Success()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+        Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
+        RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+        synchronizerTask.replicateDataRouterLogs(rleBitSet);
+    }
+
+    @Test
+    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Content_Type_Failure()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+        Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
+        RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+        synchronizerTask.replicateDataRouterLogs(rleBitSet);
+    }
+
+    @Test
+    public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Resonse_Code_Failure()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
+        RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+        synchronizerTask.replicateDataRouterLogs(rleBitSet);
+    }
+
+    @Test
+    public void Given_Synch_Task_Is_Started_And_LogFileLoader_Is_Idle_Then_Standby_Pod_Synch_Is_Successful()
+            throws IOException, IllegalAccessException {
+        mockHttpClientForGetRequest();
+        Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+        Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "application/vnd.dmaap-dr.provfeed-full; version=1.0"));
+        mockResponseFromGet();
+        synchronizerTask.run();
+    }
+
+
+    private void mockHttpClientForGetRequest() throws IllegalAccessException, IOException {
+        FieldUtils.writeField(synchronizerTask, "httpclient", httpClient, true);
+        Mockito.when(httpClient.execute(anyObject())).thenReturn(response);
+        Mockito.when(response.getEntity()).thenReturn(httpEntity);
+        Mockito.when(response.getStatusLine()).thenReturn(statusLine);
+
+    }
+
+    private void mockResponseFromGet() throws IOException {
+        InputStream in = getClass().getClassLoader().getResourceAsStream("prov_data.json");
+        Mockito.when(httpEntity.getContent()).thenReturn(in);
+    }
+}
index d859e08..214cc6e 100644 (file)
 
 package org.onap.dmaap.datarouter.provisioning.beans;
 
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-
 @RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Subscription"})
 public class SubscriptionTest {
 
     private Subscription subscription;
 
+    private static EntityManagerFactory emf;
+    private static EntityManager em;
+    private DB db;
+
+    @BeforeClass
+    public static void init() {
+        emf = Persistence.createEntityManagerFactory("dr-unit-tests");
+        em = emf.createEntityManager();
+        System.setProperty(
+                "org.onap.dmaap.datarouter.provserver.properties",
+                "src/test/resources/h2Database.properties");
+    }
+
+    @AfterClass
+    public static void tearDownClass() {
+        em.clear();
+        em.close();
+        emf.close();
+    }
+    @Before
+    public void setUp() throws Exception {
+        db = new DB();
+        subscription = new 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(), "");
@@ -56,13 +84,13 @@ public class SubscriptionTest {
         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.setPrivilegedSubscriber(false);
+        subscription.setFollowRedirect(true);
         subscription.setLinks(subLinks);
         subscription.setDecompress(false);
 
@@ -73,5 +101,19 @@ public class SubscriptionTest {
         Assert.assertFalse(subscription.isSuspended());
         Assert.assertFalse(subscription.isPrivilegedSubscriber());
         Assert.assertFalse(subscription.isDecompress());
+
+        Subscription sub2 = new Subscription();
+        sub2.setGroupid(2);
+        sub2.setDelivery(subDelivery);
+        sub2.setMetadataOnly(false);
+        sub2.setSubscriber(subscriber);
+        sub2.setSuspended(false);
+        sub2.setPrivilegedSubscriber(false);
+        sub2.setFollowRedirect(true);
+        sub2.setLinks(subLinks);
+        sub2.setDecompress(false);
+        Assert.assertTrue(subscription.equals(sub2));
+        Assert.assertNotNull(sub2.toString());
+        sub2.hashCode();
     }
 }
\ No newline at end of file
index 7f6d7de..a15509b 100644 (file)
 
 package org.onap.dmaap.datarouter.provisioning.utils;
 
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.Assert;
+import org.junit.Before;
 import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TemporaryFolder;
+import org.junit.Test;
 import org.junit.runner.RunWith;
-
 import org.onap.dmaap.datarouter.provisioning.InternalServlet;
 import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
 import org.powermock.modules.junit4.PowerMockRunner;
 
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Test;
-
-
-
 @RunWith(PowerMockRunner.class)
 @SuppressStaticInitializationFor("org.onap.dmaap.datarouter.provisioning.beans.Parameters")
 public class LogfileLoaderTest {
@@ -53,10 +50,18 @@ public class LogfileLoaderTest {
     private static EntityManagerFactory emf;
     private static EntityManager em;
     private LogfileLoader lfl = LogfileLoader.getLoader();
+    private File testLog;
 
-    @Rule
-    public TemporaryFolder folder = new TemporaryFolder();
+    @Before
+    public void setUp() throws Exception {
+        testLog = new File(System.getProperty("user.dir") + "/src/test/resources/IN.test_prov_logs");
+        prepFile(testLog);
+    }
 
+    @After
+    public void tearDown() throws IOException {
+        Files.deleteIfExists(testLog.toPath());
+    }
 
     @BeforeClass
     public static void init() {
@@ -68,7 +73,6 @@ public class LogfileLoaderTest {
         InternalServlet internalServlet = new InternalServlet();
     }
 
-
     @AfterClass
     public static void tearDownClass() {
         em.clear();
@@ -76,42 +80,47 @@ public class LogfileLoaderTest {
         emf.close();
     }
 
-
     @Test
-    public void Verify_File_Processing_when_Req_Type_LOG() throws IOException {
-        String fileContent = "2018-08-29-10-10-10-543.|LOG|1|1|url/file123|method|1|1|type|1|128.0.0.9|user123|2|1|1|1|other|1";
-        int[] actual = lfl.process(prepFile(fileContent, "file1"));
-        int[] expect = {0, 1};
+    public void Verify_File_Processing_Returns_Expected_Array() {
+        int[] actual = lfl.process(testLog);
+        int[] expect = {5, 7};
         Assert.assertArrayEquals(expect, actual);
+        Assert.assertNotNull(lfl.getBitSet());
+        Assert.assertTrue(lfl.isIdle());
     }
 
-
     @Test
-    public void Verify_File_Processing_when_Req_Type_EXP() throws IOException{
-        String fileContent = "2018-08-29-10-10-10-543.|EXP|1|1|1|'url/file123'|method|ctype|3|other|4";
-        int[] actual = lfl.process(prepFile(fileContent, "file2"));
-        int[] expect = {0, 1};
-        Assert.assertArrayEquals(expect, actual);
+    public void Verify_Records_Prune_When_Record_Count_Is_Less_Then_Threshold() {
+        lfl.process(testLog);
+        PowerMockito.mockStatic(Parameters.class);
+        PowerMockito.when(Parameters.getParameter(Parameters.PROV_LOG_RETENTION)).thenReturn(new Parameters(Parameters.PROV_LOG_RETENTION, "0"));
+        PowerMockito.when(Parameters.getParameter(Parameters.DEFAULT_LOG_RETENTION)).thenReturn(new Parameters(Parameters.DEFAULT_LOG_RETENTION, "1000000"));
+        assertFalse(lfl.pruneRecords());
     }
 
-
     @Test
-    public void Verify_Records_Prune_When_Record_Count_Is_Less_Then_Threshold() throws IOException{
-        String fileContent = "2018-08-29-10-10-10-543.|PUB|1|1|https://dmaap-dr-prov:8443/publish/1/file123/|POST|application/vnd.att-dr.feed|2|128.0.0.9|user123|200";
-        lfl.process(prepFile(fileContent, "file3"));
+    public void Verify_Records_Prune_When_Record_Count_Is_Greater_Then_Threshold() {
+        lfl.process(testLog);
         PowerMockito.mockStatic(Parameters.class);
         PowerMockito.when(Parameters.getParameter(Parameters.PROV_LOG_RETENTION)).thenReturn(new Parameters(Parameters.PROV_LOG_RETENTION, "0"));
-        assertFalse(lfl.pruneRecords());
+        PowerMockito.when(Parameters.getParameter(Parameters.DEFAULT_LOG_RETENTION)).thenReturn(new Parameters(Parameters.DEFAULT_LOG_RETENTION, "1"));
+        assertTrue(lfl.pruneRecords());
     }
 
 
-    private File prepFile(String content, String fileName) throws IOException{
-        File file1 = folder.newFile(fileName);
-        try (FileWriter fileWriter = new FileWriter(file1)) {
-            fileWriter.write(content);
-        }catch (IOException e){
+    private void prepFile(File logFile) {
+        String testLogs =           "2018-08-29-10-10-10-543.|LOG|1|1|https://dmaap-dr-prov:/url/file123|POST|application/vnd.att-dr.feed|100|mockType|file123|https://dmaap-dr-prov|user123|200|1|1|200|2|2\n"
+                                  + "2018-08-29-10-10-10-543.|EXP|1|1|1|'url/file123'|PUT|null|3|new reason|4\n"
+                                  + "2018-08-29-10-10-10-543.|PUB|1|1|https://dmaap-dr-prov:8443/publish/1/file123/|POST|application/vnd.att-dr.feed|2|128.0.0.9|user123|200\n"
+                                  + "2018-08-29-10-10-10-543.|PBF|1|1|https://dmaap-dr-prov:8443/publish/1/file123/|POST|application/vnd.att-dr.feed|100|100|128.0.0.9|user123|failed\n"
+                                  + "2018-08-29-10-10-10-543.|DLX|1|1|1|100|100\n"
+                                  + "2018-08-29-10-10-10-543.|Bad Record|||\n"
+                                  + "2018-08-29-10-10-10-543.|DEL|2|1|2|https://dmaap-dr-prov:8443/publish/1/file123/|PUT|application/vnd.att-dr.feed|100|user123|200|123456";
+        try (FileWriter fileWriter = new FileWriter(logFile)) {
+            fileWriter.write(testLogs);
+        }
+        catch (IOException e){
             System.out.println(e.getMessage());
         }
-        return file1;
     }
 }
index 7c10672..a811847 100755 (executable)
@@ -185,6 +185,9 @@ VALUES (1,1,'user',null,2);
 insert into INGRESS_ROUTES(SEQUENCE, FEEDID , USERID, SUBNET, NODESET)
 VALUES (2,1,'user',null,2);
 
+insert into NODESETS(SETID, NODEID)
+VALUES (1,1);
+
 insert into NODESETS(SETID, NODEID)
 VALUES (2,2);
 
index fee9c68..cb47241 100755 (executable)
@@ -27,6 +27,13 @@ org.onap.dmaap.datarouter.db.url                           = jdbc:h2:mem:test;DB
 org.onap.dmaap.datarouter.provserver.isaddressauthenabled  = true
 org.onap.dmaap.datarouter.provserver.https.relaxation      = false
 org.onap.dmaap.datarouter.provserver.accesslog.dir         = unit-test-logs
-org.onap.dmaap.datarouter.provserver.spooldir              = unit-test-logs/spool
+org.onap.dmaap.datarouter.provserver.spooldir              = src/test/resources
 org.onap.dmaap.datarouter.provserver.localhost             = 127.0.0.1
-org.onap.dmaap.datarouter.provserver.passwordencryption    = PasswordEncryptionKey#@$%^&1234#
\ No newline at end of file
+org.onap.dmaap.datarouter.provserver.passwordencryption    = PasswordEncryptionKey#@$%^&1234#
+
+org.onap.dmaap.datarouter.provserver.keystore.type       = jks
+org.onap.dmaap.datarouter.provserver.keymanager.password = FZNkU,B%NJzcT1v7;^v]M#ZX
+org.onap.dmaap.datarouter.provserver.keystore.path       = aaf_certs/org.onap.dmaap-dr.jks
+org.onap.dmaap.datarouter.provserver.keystore.password   = FZNkU,B%NJzcT1v7;^v]M#ZX
+org.onap.dmaap.datarouter.provserver.truststore.path     = aaf_certs/org.onap.dmaap-dr.trust.jks
+org.onap.dmaap.datarouter.provserver.truststore.password = +mzf@J.D^;3!![*Xr.z$c#?b
\ No newline at end of file
diff --git a/datarouter-prov/src/test/resources/prov_data.json b/datarouter-prov/src/test/resources/prov_data.json
new file mode 100644 (file)
index 0000000..3253631
--- /dev/null
@@ -0,0 +1,129 @@
+{
+  "feeds": [
+    {
+      "suspend": false,
+      "groupid": 0,
+      "description": "Default feed provisioned for PM File collector",
+      "version": "m1.0",
+      "authorization": {
+        "endpoint_addrs": [
+
+        ],
+        "classification": "unclassified",
+        "endpoint_ids": [
+          {
+            "password": "dradmin",
+            "id": "dradmin"
+          }
+        ]
+      },
+      "last_mod": 1560871903000,
+      "deleted": false,
+      "feedid": 1,
+      "name": "Default PM Feed",
+      "business_description": "Default Feed",
+      "aaf_instance": "legacy",
+      "publisher": "dradmin",
+      "links": {
+        "subscribe": "https://dmaap-dr-prov/subscribe/1",
+        "log": "https://dmaap-dr-prov/feedlog/1",
+        "publish": "https://dmaap-dr-prov/publish/1",
+        "self": "https://dmaap-dr-prov/feed/1"
+      },
+      "created_date": 1560871903000
+    }
+  ],
+  "groups": [
+    {
+      "authid": "GROUP-0000-c2754bb7-92ef-4869-9c6b-1bc1283be4c0",
+      "name": "Test Group",
+      "description": "Test Description of Group .",
+      "classification": "publisher/subscriber",
+      "members": "{id=attuid, name=User1}, {id=attuid, name=User 2]"
+    }
+  ],
+  "subscriptions": [
+    {
+      "suspend": false,
+      "delivery": {
+        "use100": true,
+        "password": "PASSWORD",
+        "user": "LOGIN",
+        "url": "https://dcae-pm-mapper:8443/delivery"
+      },
+      "subscriber": "dradmin",
+      "groupid": 0,
+      "metadataOnly": false,
+      "privilegedSubscriber": true,
+      "subid": 1,
+      "last_mod": 1560872889000,
+      "feedid": 1,
+      "follow_redirect": false,
+      "decompress": true,
+      "aaf_instance": "legacy",
+      "links": {
+        "feed": "https://dmaap-dr-prov/feed/1",
+        "log": "https://dmaap-dr-prov/sublog/1",
+        "self": "https://dmaap-dr-prov/subs/1"
+      },
+      "created_date": 1560872889000
+    }
+  ],
+  "parameters": {
+    "ACTIVE_POD": "dmaap-dr-prov",
+    "DELIVERY_FILE_PROCESS_INTERVAL": 10,
+    "DELIVERY_INIT_RETRY_INTERVAL": 10,
+    "DELIVERY_MAX_AGE": 86400,
+    "DELIVERY_MAX_RETRY_INTERVAL": 3600,
+    "DELIVERY_RETRY_RATIO": 2,
+    "LOGROLL_INTERVAL": 30,
+    "NODES": [
+      "dmaap-dr-node"
+    ],
+    "PROV_ACTIVE_NAME": "dmaap-dr-prov",
+    "PROV_AUTH_ADDRESSES": [
+      "dmaap-dr-prov",
+      "dmaap-dr-node"
+    ],
+    "PROV_AUTH_SUBJECTS": [
+      ""
+    ],
+    "PROV_DOMAIN": "",
+    "PROV_MAXFEED_COUNT": 10000,
+    "PROV_MAXSUB_COUNT": 100000,
+    "PROV_NAME": "dmaap-dr-prov",
+    "PROV_REQUIRE_CERT": "false",
+    "PROV_REQUIRE_SECURE": "true",
+    "STANDBY_POD": "",
+    "_INT_VALUES": [
+      "LOGROLL_INTERVAL",
+      "PROV_MAXFEED_COUNT",
+      "PROV_MAXSUB_COUNT",
+      "DELIVERY_INIT_RETRY_INTERVAL",
+      "DELIVERY_MAX_RETRY_INTERVAL",
+      "DELIVERY_RETRY_RATIO",
+      "DELIVERY_MAX_AGE",
+      "DELIVERY_FILE_PROCESS_INTERVAL"
+    ]
+  },
+  "ingress": [
+    {
+      "feedid": 1,
+      "subnet": "",
+      "user": "",
+      "node": [
+        "stub_from."
+      ]
+    }
+  ],
+  "egress": {
+    "1": "stub_to."
+  },
+  "routing": [
+    {
+      "from": 1,
+      "to": 3,
+      "via": 2
+    }
+  ]
+}
\ No newline at end of file
index 315207e..e9a0bf9 100644 (file)
@@ -63,7 +63,7 @@ public class SampleSubscriberServlet extends HttpServlet {
     try {
       Files.createDirectory(Paths.get(outputDirectory));
     } catch (IOException e) {
-      logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage());
+      logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage(), e);
     }
     basicAuth = "Basic " + Base64.encodeBase64String((login + ":" + password).getBytes());
   }
index 329c06a..f05ca5d 100644 (file)
@@ -45,7 +45,7 @@ public class SubscriberProps {
             try {
                 instance = new SubscriberProps(propsPath);
             } catch (IOException ioe) {
-                subLogger.error("IO Exception: " + ioe.getMessage());
+                subLogger.error("IO Exception: " + ioe.getMessage(), ioe);
             }
         }
         return instance;
index 4f2ddb6..88bd296 100644 (file)
@@ -10,7 +10,7 @@ Release-notes
 Version: 2.1.0 (Dublin)
 ---------------------------
 
-:Release Date: 2019-05-30
+:Release Date: 2019-06-06
 
 The DataRouter(DR) provisioning API is a HTTPS-based, REST-like API for creating and managing DR feeds and
 subscriptions.
diff --git a/pom.xml b/pom.xml
index 6db34b6..ccd761c 100755 (executable)
--- a/pom.xml
+++ b/pom.xml
     <parent>
         <groupId>org.onap.oparent</groupId>
         <artifactId>oparent</artifactId>
-        <version>1.2.3</version>
+        <version>2.0.0</version>
     </parent>
     <properties>
-        <!--revision can be set in the version.properties file at project root and is loaded by all sub modules-->
-        <revision>${snapshot_version}</revision>
+        <!--revision must also be set in the version.properties file at project root-->
+        <revision>2.1.0-SNAPSHOT</revision>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <maven.compiler.source>1.8</maven.compiler.source>
         <maven.compiler.target>1.8</maven.compiler.target>
     </dependencyManagement>
     <build>
         <plugins>
-            <plugin>
-                <groupId>org.sonatype.plugins</groupId>
-                <artifactId>nexus-staging-maven-plugin</artifactId>
-            </plugin>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
             </plugins>
         </pluginManagement>
     </build>
-    <distributionManagement>
-        <repository>
-            <id>ecomp-releases</id>
-            <name>DR Release Repository</name>
-            <url>${onap.nexus.url}${releaseNexusPath}</url>
-        </repository>
-        <snapshotRepository>
-            <id>ecomp-snapshots</id>
-            <name>DR Snapshot Repository</name>
-            <url>${onap.nexus.url}${snapshotNexusPath}</url>
-        </snapshotRepository>
-        <site>
-            <id>ecomp-site</id>
-            <url>dav:${onap.nexus.url}${sitePath}</url>
-        </site>
-    </distributionManagement>
     <pluginRepositories>
         <pluginRepository>
             <id>onap-plugin-snapshots</id>