Merge "Logging changes and unit tests"
authorFiachra Corcoran <fiachra.corcoran@est.tech>
Thu, 25 Jul 2019 13:59:27 +0000 (13:59 +0000)
committerGerrit Code Review <gerrit@onap.org>
Thu, 25 Jul 2019 13:59:27 +0000 (13:59 +0000)
54 files changed:
datarouter-node/pom.xml
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/NodeConfigManager.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/ProvData.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
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/JettyFilter.java
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/eelf/MetricsFilter.java
datarouter-node/src/test/java/org/onap/dmaap/datarouter/node/TaskListTest.java [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/GroupServlet.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/Insertable.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/JSONable.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LOGJSONable.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Loadable.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/NodeClass.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/utils/DB.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/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/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/InternalServletTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java [new file with mode: 0644]
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java [new file with mode: 0644]
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java [new file with mode: 0644]
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObjectTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java [new file with mode: 0644]
datarouter-prov/src/test/resources/META-INF/persistence.xml
datarouter-prov/src/test/resources/create.sql
datarouter-prov/src/test/resources/h2Database.properties
datarouter-prov/src/test/resources/sql_init_01.sql [new file with mode: 0755]
datarouter-subscriber/pom.xml
docs/release-notes.rst

index 42c1c9a..6ebfd96 100755 (executable)
@@ -36,6 +36,7 @@
         <sitePath>/content/sites/site/${project.groupId}/${project.artifactId}/${project.version}</sitePath>
         <docker.location>${basedir}/target/${project.artifactId}</docker.location>
         <datarouter.node.image.name>${docker.image.root}${project.artifactId}</datarouter.node.image.name>
+        <sonar.exclusions>src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java</sonar.exclusions>
         <sonar.language>java</sonar.language>
         <sonar.skip>false</sonar.skip>
     </properties>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
+                <configuration>
+                    <excludes>
+                        <exclude>src/main/java/org/onap/dmaap/datarouter/node/NodeMain.java</exclude>
+                    </excludes>
+                </configuration>
             </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
index 90aaf0a..be77d24 100644 (file)
@@ -496,13 +496,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (purl + "/" + fileid);
     }
 
-    /**
-     * 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.
      */
@@ -520,23 +513,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (false);
     }
 
-    /**
-     * 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.
      */
@@ -606,16 +582,6 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return (config.getTargets(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) {
-        return (config.getCreatedDate(feedid));
-    }
-
     /**
      * Get the spool directory for temporary files.
      */
@@ -811,30 +777,14 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return enabledprotocols;
     }
 
-    public void setEnabledprotocols(String[] enabledprotocols) {
-        this.enabledprotocols = enabledprotocols.clone();
-    }
-
     public String getAafType() {
         return aafType;
     }
 
-    public void setAafType(String aafType) {
-        this.aafType = aafType;
-    }
-
-    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
      * */
@@ -842,18 +792,10 @@ public class NodeConfigManager implements DeliveryQueueHelper {
         return aafURL;
     }
 
-    public void setAafURL(String aafURL) {
-        this.aafURL = aafURL;
-    }
-
     public boolean getCadiEnabled() {
         return cadiEnabled;
     }
 
-    public void setCadiEnabled(boolean cadiEnabled) {
-        this.cadiEnabled = cadiEnabled;
-    }
-
     /**
      * Builds the permissions string to be verified.
      *
index c436076..03e952c 100644 (file)
@@ -152,7 +152,7 @@ public class ProvData {
     }
 
     /**
-     * Get the raw node configuration entries
+     * Get the raw node configuration entries.
      */
     public NodeConfig.ProvNode[] getNodes() {
         return (pn);
@@ -333,6 +333,9 @@ public class ProvData {
         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;
                 }
index 7fa0dc4..a77277f 100644 (file)
@@ -38,7 +38,7 @@ import java.util.Iterator;
  * called.
  * </ul>
  */
-public class TaskList {
+class TaskList {
 
     private Iterator<Runnable> runlist;
     private HashSet<Runnable> tasks = new HashSet<>();
@@ -50,7 +50,7 @@ public class TaskList {
     /**
      * Start executing the sequence of tasks.
      */
-    public synchronized void startRun() {
+    synchronized void startRun() {
         sofar = new HashSet<>();
         added = new HashSet<>();
         removed = new HashSet<>();
@@ -61,7 +61,7 @@ public class TaskList {
     /**
      * Get the next task to execute.
      */
-    public synchronized Runnable next() {
+    synchronized Runnable next() {
         while (runlist != null) {
             if (runlist.hasNext()) {
                 Runnable task = runlist.next();
@@ -88,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);
@@ -99,7 +99,7 @@ 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);
index 33103db..a278c2e 100644 (file)
@@ -17,9 +17,9 @@
  * 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;
index 8b5f2a6..d5e520e 100644 (file)
@@ -17,6 +17,7 @@
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.dmaap.datarouter.node.eelf;
 
 import ch.qos.logback.classic.spi.ILoggingEvent;
index 890d56b..f3e27fe 100644 (file)
@@ -17,6 +17,7 @@
  * SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
+
 package org.onap.dmaap.datarouter.node.eelf;
 
 import ch.qos.logback.classic.Level;
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();
+    }
+}
index c71d877..7a464fc 100755 (executable)
         <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/datarouter/authz/impl/AuthRespSupplementImpl.java,
+            src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java,
+            src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java</sonar.exclusions>
         <sonar.language>java</sonar.language>
         <sonar.skip>false</sonar.skip>
     </properties>
                 <configuration>
                     <excludes>
                         <exclude>**/src/main/java/org/onap/dmaap/datarouter/reports/**</exclude>
+                        <exclude>src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java</exclude>
+                        <exclude>src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java</exclude>
+                        <exclude>src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.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 ef106ab..e730db4 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,127 +131,119 @@ 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
-    public static final String MISSING_ON_BEHALF = "Missing X-DMAAP-DR-ON-BEHALF-OF header.";
-    public static final String MISSING_FEED = "Missing or bad feed number.";
-    public static final String POLICY_ENGINE = "Policy Engine disallows access.";
-    public static final String UNAUTHORIZED = "Unauthorized.";
-    public static final String BAD_SUB = "Missing or bad subscription number.";
-    public static final String BAD_JSON = "Badly formed JSON";
-    public static final String BAD_URL = "Bad URL.";
+    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/";
-    public static final String LOGS = "/logs/";
-    public static final String TEXT_CT = "text/plain";
-    public static final String INGRESS = "/ingress/";
-    public static final String EGRESS = "/egress/";
-    public static final String NETWORK = "/network/";
-    public static final String GROUPID = "groupid";
+    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";
-    public static final String FEEDIDS = "feedids";
-    public static final String SUBID = "subid";
-    public static final String EVENT_TYPE = "eventType";
-    public static final String OUTPUT_TYPE = "output_type";
-    public static final String START_TIME = "start_time";
-    public static final String END_TIME = "end_time";
-    public static final String REASON_SQL = "reasonSQL";
+    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
-     */
-    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_POD 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;
     /**
@@ -258,21 +251,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()
@@ -285,10 +274,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) {
@@ -329,7 +318,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
@@ -348,35 +337,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
@@ -393,20 +387,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(), e);
-            return "Unauthorized address: " + remote;
+        String remoteHostCheck = checkRemoteHostAuthorization(request);
+        if (remoteHostCheck != null) {
+            return remoteHostCheck;
         }
         // Does remote have a valid certificate?
         if (requireCert) {
@@ -425,6 +408,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.
      *
@@ -438,19 +441,19 @@ 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) {
@@ -468,7 +471,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);
@@ -528,16 +531,16 @@ 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 {
@@ -559,9 +562,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
             }
         }
 
-        //[DATARTR-27] Poke all the DR nodes: assigning DR Nodes
-        drnodes = nodes.clone();
-
         //Reset Nodes arr after - removing static routing Nodes, Rally Userstory - US664862 .
         List<String> filterNodes = new ArrayList<>();
         for (String node : nodes) {
@@ -597,78 +597,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(), e);
-                System.exit(1);
-            }
-        }
-    }
-
-
-    /**
-     * 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) {
-        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);
-
-            intlogger.info(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, e);
-        } catch (UnknownHostException uhe) {
-            intlogger.error("UnknownHostException", uhe);
-        }
-    }
-
     public static String getProvName() {
         return provName;
     }
 
-    public static String getActiveProvName() {
+    static String getActiveProvName() {
         return activeProvName;
     }
 
@@ -681,22 +614,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;
     }
 
@@ -814,7 +737,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) && "true".equalsIgnoreCase(s);
+        return "true".equalsIgnoreCase(s);
     }
 
     private static String getString(Map<String, String> map, String name, String dflt) {
@@ -854,7 +777,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() {
@@ -870,7 +793,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 = "";
@@ -976,19 +899,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();
                     }
                 }
@@ -1002,7 +923,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) {
@@ -1013,8 +934,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();
                     }
                 }
index 544a480..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;
-            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.";
index 2a959f3..0a5258e 100644 (file)
@@ -25,7 +25,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
@@ -44,12 +43,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 e766e70..a78a9c1 100644 (file)
@@ -24,6 +24,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.sql.Connection;\r
 import java.sql.PreparedStatement;\r
 import java.sql.ResultSet;\r
@@ -32,9 +34,6 @@ import java.sql.Statement;
 import java.util.Objects;\r
 import java.util.SortedSet;\r
 import java.util.TreeSet;\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
 \r
@@ -47,10 +46,22 @@ 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
+    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
+        // possible that an orphan ERT entry can exist if a sub is removed.\r
+        //        if (Subscription.getSubscriptionById(subid) == null)\r
+        //            throw new IllegalArgumentException("No such subscription: "+subid);\r
+    }\r
+\r
+    public EgressRoute(int subid, String node) {\r
+        this(subid, lookupNodeName(node));\r
+    }\r
+\r
     /**\r
      * Get a set of all Egress Routes in the DB.  The set is sorted according to the natural sorting order of the routes\r
      * (based on the subscription ID in each route).\r
@@ -59,27 +70,30 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
      */\r
     public static SortedSet<EgressRoute> getAllEgressRoutes() {\r
         SortedSet<EgressRoute> set = new TreeSet<>();\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
+        DB db = new DB();\r
+        String sql = "select SUBID, NODEID from EGRESS_ROUTES";\r
+        try (Connection conn = db.getConnection()) {\r
             try (Statement stmt = conn.createStatement()) {\r
-                try (ResultSet rs = stmt.executeQuery("select SUBID, NODEID from EGRESS_ROUTES")) {\r
-                    while (rs.next()) {\r
-                        int subid = rs.getInt("SUBID");\r
-                        int nodeid = rs.getInt("NODEID");\r
-                        set.add(new EgressRoute(subid, nodeid));\r
-                    }\r
+                try (ResultSet rs = stmt.executeQuery(sql)) {\r
+                    addEgressRouteToSet(set, rs);\r
                 }\r
+            } finally {\r
+                db.release(conn);\r
             }\r
-\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.error("PROV0008 EgressRoute.getAllEgressRoutes: " + e.getMessage(), e);\r
         }\r
         return set;\r
     }\r
 \r
+    private static void addEgressRouteToSet(SortedSet<EgressRoute> set, ResultSet rs) throws SQLException {\r
+        while (rs.next()) {\r
+            int subid = rs.getInt("SUBID");\r
+            int nodeid = rs.getInt("NODEID");\r
+            set.add(new EgressRoute(subid, nodeid));\r
+        }\r
+    }\r
+\r
     /**\r
      * Get a single Egress Route for the subscription <i>sub</i>.\r
      *\r
@@ -88,69 +102,35 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
      */\r
     public static EgressRoute getEgressRoute(int sub) {\r
         EgressRoute v = null;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?";\r
-            ps = conn.prepareStatement(sql);\r
+        DB db = new DB();\r
+        String sql = "select NODEID from EGRESS_ROUTES where SUBID = ?";\r
+        try (Connection conn = db.getConnection();\r
+                PreparedStatement ps = conn.prepareStatement(sql)) {\r
             ps.setInt(1, sub);\r
             try (ResultSet rs = ps.executeQuery()) {\r
                 if (rs.next()) {\r
                     int node = rs.getInt("NODEID");\r
                     v = new EgressRoute(sub, node);\r
                 }\r
+            } finally {\r
+                db.release(conn);\r
             }\r
-            ps.close();\r
-            db.release(conn);\r
         } catch (SQLException e) {\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(), e);\r
-            }\r
         }\r
         return v;\r
     }\r
 \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
-// possible that an orphan ERT entry can exist if a sub is removed.\r
-//        if (Subscription.getSubscriptionById(subid) == null)\r
-//            throw new IllegalArgumentException("No such subscription: "+subid);\r
-    }\r
-\r
-    public EgressRoute(int subid, String node) {\r
-        this(subid, lookupNodeName(node));\r
-    }\r
-\r
     @Override\r
     public boolean doDelete(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            String sql = "delete from EGRESS_ROUTES where SUBID = ?";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "delete from EGRESS_ROUTES where SUBID = ?";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setInt(1, subid);\r
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -158,11 +138,9 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
     @Override\r
     public boolean doInsert(Connection c) {\r
         boolean rv = false;\r
-        PreparedStatement ps = null;\r
-        try {\r
+        String sql = "insert into EGRESS_ROUTES (SUBID, NODEID) values (?, ?)";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             // Create the NETWORK_ROUTES row\r
-            String sql = "insert into EGRESS_ROUTES (SUBID, NODEID) values (?, ?)";\r
-            ps = c.prepareStatement(sql);\r
             ps.setInt(1, this.subid);\r
             ps.setInt(2, this.nodeid);\r
             ps.execute();\r
@@ -170,14 +148,6 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
             rv = true;\r
         } catch (SQLException e) {\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -185,24 +155,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
     @Override\r
     public boolean doUpdate(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            String sql = "update EGRESS_ROUTES set NODEID = ? where SUBID = ?";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "update EGRESS_ROUTES set NODEID = ? where SUBID = ?";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setInt(1, nodeid);\r
             ps.setInt(2, subid);\r
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
index cab4d3d..1cfd0f6 100644 (file)
@@ -497,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
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 be4c640..4d6b0ee 100644 (file)
 \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
 import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
 import java.sql.Statement;\r
-import java.util.*;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.Date;\r
+import java.util.List;\r
+import java.util.Objects;\r
 import org.json.JSONObject;\r
 import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 \r
@@ -44,8 +47,9 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
  */\r
 public class Group extends Syncable {\r
 \r
+    private static final String GROUP_ID_CONST = "groupid";\r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
-    private static int next_groupid = getMaxGroupID() + 1;\r
+    private static int nextGroupid = getMaxGroupID() + 1;\r
     private static final String SQLEXCEPTION = "SQLException: ";\r
 \r
     private int groupid;\r
@@ -56,6 +60,60 @@ public class Group extends Syncable {
     private String members;\r
     private Date last_mod;\r
 \r
+    public Group() {\r
+        this("", "", "");\r
+    }\r
+\r
+    public Group(String name, String desc, String members) {\r
+        this.groupid = -1;\r
+        this.authid = "";\r
+        this.name = name;\r
+        this.description = desc;\r
+        this.members = members;\r
+        this.classification = "";\r
+        this.last_mod = new Date();\r
+    }\r
+\r
+\r
+    public Group(ResultSet rs) throws SQLException {\r
+        this.groupid = rs.getInt("GROUPID");\r
+        this.authid = rs.getString("AUTHID");\r
+        this.name = rs.getString("NAME");\r
+        this.description = rs.getString("DESCRIPTION");\r
+        this.classification = rs.getString("CLASSIFICATION");\r
+        this.members = rs.getString("MEMBERS");\r
+        this.last_mod = rs.getDate("LAST_MOD");\r
+    }\r
+\r
+\r
+    public Group(JSONObject jo) throws InvalidObjectException {\r
+        this("", "", "");\r
+        try {\r
+            // The JSONObject is assumed to contain a vnd.dmaap-dr.group representation\r
+            this.groupid = jo.optInt(GROUP_ID_CONST, -1);\r
+            String gname = jo.getString("name");\r
+            String gdescription = jo.getString("description");\r
+\r
+            this.authid = jo.getString("authid");\r
+            this.name = gname;\r
+            this.description = gdescription;\r
+            this.classification = jo.getString("classification");\r
+            this.members = jo.getString("members");\r
+\r
+            if (gname.length() > 50) {\r
+                throw new InvalidObjectException("Group name is too long");\r
+            }\r
+            if (gdescription.length() > 256) {\r
+                throw new InvalidObjectException("Group Description is too long");\r
+            }\r
+        } catch (InvalidObjectException e) {\r
+            throw e;\r
+        } catch (Exception e) {\r
+            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
+            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
+        }\r
+    }\r
+\r
 \r
     public static Group getGroupMatching(Group gup) {\r
         String sql = String.format(\r
@@ -82,7 +140,7 @@ public class Group extends Syncable {
         return list.size() > 0 ? list.get(0) : null;\r
     }\r
 \r
-    public static Group getGroupByAuthId(String id) {\r
+    static Group getGroupByAuthId(String id) {\r
         String sql = "select * from GROUPS where AUTHID = '" + id + "'";\r
         List<Group> list = getGroupsForSQL(sql);\r
         return list.size() > 0 ? list.get(0) : null;\r
@@ -93,7 +151,7 @@ public class Group extends Syncable {
     }\r
 \r
     private static List<Group> getGroupsForSQL(String sql) {\r
-        List<Group> list = new ArrayList<Group>();\r
+        List<Group> list = new ArrayList<>();\r
         try {\r
             DB db = new DB();\r
             @SuppressWarnings("resource")\r
@@ -113,7 +171,7 @@ public class Group extends Syncable {
         return list;\r
     }\r
 \r
-    public static int getMaxGroupID() {\r
+    private static int getMaxGroupID() {\r
         int max = 0;\r
         try {\r
             DB db = new DB();\r
@@ -133,108 +191,6 @@ public class Group extends Syncable {
         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("PROV0002 getGroupsByClassfication: " + e.getMessage(), e);\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(), e);\r
-        }\r
-        return count;\r
-    }\r
-\r
-    public Group() {\r
-        this("", "", "");\r
-    }\r
-\r
-    public Group(String name, String desc, String members) {\r
-        this.groupid = -1;\r
-        this.authid = "";\r
-        this.name = name;\r
-        this.description = desc;\r
-        this.members = members;\r
-        this.classification = "";\r
-        this.last_mod = new Date();\r
-    }\r
-\r
-\r
-    public Group(ResultSet rs) throws SQLException {\r
-        this.groupid = rs.getInt("GROUPID");\r
-        this.authid = rs.getString("AUTHID");\r
-        this.name = rs.getString("NAME");\r
-        this.description = rs.getString("DESCRIPTION");\r
-        this.classification = rs.getString("CLASSIFICATION");\r
-        this.members = rs.getString("MEMBERS");\r
-        this.last_mod = rs.getDate("LAST_MOD");\r
-    }\r
-\r
-\r
-    public Group(JSONObject jo) throws InvalidObjectException {\r
-        this("", "", "");\r
-        try {\r
-            // The JSONObject is assumed to contain a vnd.dmaap-dr.group representation\r
-            this.groupid = jo.optInt("groupid", -1);\r
-            String gname = jo.getString("name");\r
-            String gdescription = jo.getString("description");\r
-\r
-            this.authid = jo.getString("authid");\r
-            this.name = gname;\r
-            this.description = gdescription;\r
-            this.classification = jo.getString("classification");\r
-            this.members = jo.getString("members");\r
-\r
-            if (gname.length() > 50) {\r
-                throw new InvalidObjectException("Group name is too long");\r
-            }\r
-            if (gdescription.length() > 256) {\r
-                throw new InvalidObjectException("Group Description is too long");\r
-            }\r
-        } catch (InvalidObjectException e) {\r
-            throw e;\r
-        } catch (Exception e) {\r
-            intlogger.warn("Invalid JSON: " + e.getMessage(), e);\r
-            throw new InvalidObjectException("Invalid JSON: " + e.getMessage());\r
-        }\r
-    }\r
-\r
     public int getGroupid() {\r
         return groupid;\r
     }\r
@@ -251,14 +207,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
@@ -295,23 +243,10 @@ 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
-        jo.put("groupid", groupid);\r
+        jo.put(GROUP_ID_CONST, groupid);\r
         jo.put("authid", authid);\r
         jo.put("name", name);\r
         jo.put("description", description);\r
@@ -328,11 +263,11 @@ public class Group extends Syncable {
         try {\r
             if (groupid == -1) {\r
                 // No feed ID assigned yet, so assign the next available one\r
-                setGroupid(next_groupid++);\r
+                setGroupid(nextGroupid++);\r
             }\r
             // In case we insert a gropup from synchronization\r
-            if (groupid > next_groupid) {\r
-                next_groupid = groupid + 1;\r
+            if (groupid > nextGroupid) {\r
+                nextGroupid = groupid + 1;\r
             }\r
 \r
             // Create the GROUPS row\r
index 4332d7d..1df093d 100644 (file)
@@ -24,6 +24,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.net.InetAddress;\r
 import java.net.UnknownHostException;\r
 import java.sql.Connection;\r
@@ -31,16 +33,11 @@ import java.sql.PreparedStatement;
 import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
 import java.sql.Statement;\r
-import java.util.ArrayList;\r
 import java.util.Collection;\r
 import java.util.Set;\r
 import java.util.SortedSet;\r
 import java.util.TreeSet;\r
-\r
 import javax.servlet.http.HttpServletRequest;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
 import org.apache.commons.codec.binary.Base64;\r
 import org.json.JSONArray;\r
 import org.json.JSONObject;\r
@@ -54,6 +51,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
  */\r
 public class IngressRoute extends NodeClass implements Comparable<IngressRoute> {\r
 \r
+    private static final String NODESET = "NODESET";\r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
     private static final String SQLEXCEPTION = "SQLException: ";\r
     private final int seq;\r
@@ -63,6 +61,52 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
     private int nodelist;\r
     private SortedSet<String> nodes;\r
 \r
+    public IngressRoute(int seq, int feedid, String user, String subnet, Collection<String> nodes) {\r
+        this(seq, feedid, user, subnet);\r
+        this.nodelist = -1;\r
+        this.nodes = new TreeSet<>(nodes);\r
+    }\r
+\r
+    private IngressRoute(int seq, int feedid, String user, String subnet, int nodeset) {\r
+        this(seq, feedid, user, subnet);\r
+        this.nodelist = nodeset;\r
+        this.nodes = new TreeSet<>(readNodes());\r
+    }\r
+\r
+    private IngressRoute(int seq, int feedid, String user, String subnet) {\r
+        this.seq = seq;\r
+        this.feedid = feedid;\r
+        this.userid = (user == null) ? "-" : user;\r
+        this.subnet = (subnet == null) ? "-" : subnet;\r
+        this.nodelist = -1;\r
+        this.nodes = null;\r
+        if (Feed.getFeedById(feedid) == null) {\r
+            throw new IllegalArgumentException("No such feed: " + feedid);\r
+        }\r
+        if (!"-".equals(this.subnet)) {\r
+            SubnetMatcher sm = new SubnetMatcher(subnet);\r
+            if (!sm.isValid()) {\r
+                throw new IllegalArgumentException("Invalid subnet: " + subnet);\r
+            }\r
+        }\r
+    }\r
+\r
+    public IngressRoute(JSONObject jo) {\r
+        this.seq = jo.optInt("seq");\r
+        this.feedid = jo.optInt("feedid");\r
+        String t = jo.optString("user");\r
+        this.userid = "".equals(t) ? "-" : t;\r
+        t = jo.optString("subnet");\r
+        this.subnet = "".equals(t) ? "-" : t;\r
+        this.nodelist = -1;\r
+        this.nodes = new TreeSet<>();\r
+        JSONArray ja = jo.getJSONArray("node");\r
+        for (int i = 0; i < ja.length(); i++) {\r
+            this.nodes.add(ja.getString(i));\r
+        }\r
+    }\r
+\r
+\r
     /**\r
      * Get all IngressRoutes in the database, sorted in order according to their sequence field.\r
      *\r
@@ -84,21 +128,14 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
     }\r
 \r
     private static SortedSet<IngressRoute> getAllIngressRoutesForSQL(String sql) {\r
-        SortedSet<IngressRoute> set = new TreeSet<IngressRoute>();\r
+        SortedSet<IngressRoute> set = new TreeSet<>();\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(sql)) {\r
-                    while (rs.next()) {\r
-                        int seq = rs.getInt("SEQUENCE");\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
-                        set.add(new IngressRoute(seq, feedid, user, subnet, nodeset));\r
-                    }\r
+                    addIngressRouteToSet(set, rs);\r
                 }\r
             }\r
             db.release(conn);\r
@@ -108,12 +145,23 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
         return set;\r
     }\r
 \r
+    private static void addIngressRouteToSet(SortedSet<IngressRoute> set, ResultSet rs) throws SQLException {\r
+        while (rs.next()) {\r
+            int seq = rs.getInt("SEQUENCE");\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
+            set.add(new IngressRoute(seq, feedid, user, subnet, nodeset));\r
+        }\r
+    }\r
+\r
     /**\r
      * Get the maximum node set ID in use in the DB.\r
      *\r
      * @return the integer value of the maximum\r
      */\r
-    public static int getMaxNodeSetID() {\r
+    private static int getMaxNodeSetID() {\r
         return getMax("select max(SETID) as MAX from NODESETS");\r
     }\r
 \r
@@ -128,15 +176,12 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
 \r
     private static int getMax(String sql) {\r
         int rv = 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(sql)) {\r
-                    if (rs.next()) {\r
-                        rv = rs.getInt("MAX");\r
-                    }\r
+        DB db = new DB();\r
+        try (Connection conn = db.getConnection();\r
+                Statement stmt = conn.createStatement()) {\r
+            try (ResultSet rs = stmt.executeQuery(sql)) {\r
+                if (rs.next()) {\r
+                    rv = rs.getInt("MAX");\r
                 }\r
             }\r
             db.release(conn);\r
@@ -147,7 +192,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
     }\r
 \r
     /**\r
-     * Get an Ingress Route for a particular feed ID, user, and subnet\r
+     * Get an Ingress Route for a particular feed ID, user, and subnet.\r
      *\r
      * @param feedid the Feed ID to look for\r
      * @param user the user name to look for\r
@@ -156,119 +201,27 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
      */\r
     public static IngressRoute getIngressRoute(int feedid, String user, String subnet) {\r
         IngressRoute v = null;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            String sql = "select SEQUENCE, NODESET from INGRESS_ROUTES where FEEDID = ? AND USERID = ? and SUBNET = ?";\r
-            ps = conn.prepareStatement(sql);\r
+        DB db = new DB();\r
+        String sql = "select SEQUENCE, NODESET from INGRESS_ROUTES where FEEDID = ? AND USERID = ? and SUBNET = ?";\r
+        try (Connection conn = db.getConnection();\r
+                PreparedStatement ps = conn.prepareStatement(sql)) {\r
             ps.setInt(1, feedid);\r
             ps.setString(2, user);\r
             ps.setString(3, subnet);\r
             try (ResultSet rs = ps.executeQuery()) {\r
                 if (rs.next()) {\r
                     int seq = rs.getInt("SEQUENCE");\r
-                    int nodeset = rs.getInt("NODESET");\r
+                    int nodeset = rs.getInt(NODESET);\r
                     v = new IngressRoute(seq, feedid, user, subnet, nodeset);\r
                 }\r
             }\r
-            ps.close();\r
             db.release(conn);\r
         } catch (SQLException e) {\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(), 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("PROV0004 getIngressRoute: " + e.getMessage(), e);\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
-        this.nodelist = -1;\r
-        this.nodes = new TreeSet<String>(nodes);\r
-    }\r
-\r
-    public IngressRoute(int seq, int feedid, String user, String subnet, int nodeset)\r
-            throws IllegalArgumentException {\r
-        this(seq, feedid, user, subnet);\r
-        this.nodelist = nodeset;\r
-        this.nodes = new TreeSet<String>(readNodes());\r
-    }\r
-\r
-    private IngressRoute(int seq, int feedid, String user, String subnet)\r
-            throws IllegalArgumentException {\r
-        this.seq = seq;\r
-        this.feedid = feedid;\r
-        this.userid = (user == null) ? "-" : user;\r
-        this.subnet = (subnet == null) ? "-" : subnet;\r
-        this.nodelist = -1;\r
-        this.nodes = null;\r
-        if (Feed.getFeedById(feedid) == null) {\r
-            throw new IllegalArgumentException("No such feed: " + feedid);\r
-        }\r
-        if (!this.subnet.equals("-")) {\r
-            SubnetMatcher sm = new SubnetMatcher(subnet);\r
-            if (!sm.isValid()) {\r
-                throw new IllegalArgumentException("Invalid subnet: " + subnet);\r
-            }\r
-        }\r
-    }\r
-\r
-    public IngressRoute(JSONObject jo) {\r
-        this.seq = jo.optInt("seq");\r
-        this.feedid = jo.optInt("feedid");\r
-        String t = jo.optString("user");\r
-        this.userid = t.equals("") ? "-" : t;\r
-        t = jo.optString("subnet");\r
-        this.subnet = t.equals("") ? "-" : t;\r
-        this.nodelist = -1;\r
-        this.nodes = new TreeSet<String>();\r
-        JSONArray ja = jo.getJSONArray("node");\r
-        for (int i = 0; i < ja.length(); i++) {\r
-            this.nodes.add(ja.getString(i));\r
-        }\r
-    }\r
-\r
     /**\r
      * Does this particular IngressRoute match a request, represented by feedid and req? To match, <i>feedid</i> must\r
      * match the feed ID in the route, the user in the route (if specified) must match the user in the request, and the\r
@@ -283,10 +236,9 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
         if (this.feedid != feedid) {\r
             return false;\r
         }\r
-\r
         // Get user from request and compare\r
         // Note: we don't check the password; the node will do that\r
-        if (userid.length() > 0 && !userid.equals("-")) {\r
+        if (userid.length() > 0 && !"-".equals(userid)) {\r
             String credentials = req.getHeader("Authorization");\r
             if (credentials == null || !credentials.startsWith("Basic ")) {\r
                 return false;\r
@@ -300,9 +252,8 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
                 return false;\r
             }\r
         }\r
-\r
         // If this route has a subnet, match it against the requester's IP addr\r
-        if (subnet.length() > 0 && !subnet.equals("-")) {\r
+        if (subnet.length() > 0 && !"-".equals(subnet)) {\r
             try {\r
                 InetAddress inet = InetAddress.getByName(req.getRemoteAddr());\r
                 SubnetMatcher sm = new SubnetMatcher(subnet);\r
@@ -327,7 +278,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
         private boolean valid;\r
 \r
         /**\r
-         * Construct a subnet matcher given a CIDR\r
+         * Construct a subnet matcher given a CIDR.\r
          *\r
          * @param subnet The CIDR to match\r
          */\r
@@ -358,18 +309,18 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
             }\r
         }\r
 \r
-        public boolean isValid() {\r
+        boolean isValid() {\r
             return valid;\r
         }\r
 \r
         /**\r
-         * Is the IP address in the CIDR?\r
+         * Is the IP address in the CIDR?.\r
          *\r
          * @param addr the IP address as bytes in network byte order\r
          * @return true if the IP address matches.\r
          */\r
-        public boolean matches(byte[] addr) {\r
-            if (!valid || addr.length != sn.length) {\r
+        boolean matches(byte[] addr) {\r
+            if (!valid || (addr.length != sn.length)) {\r
                 return false;\r
             }\r
             for (int i = 0; i < len; i++) {\r
@@ -395,19 +346,12 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
 \r
     private Collection<String> readNodes() {\r
         Collection<String> set = new TreeSet<>();\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            String sql = "select NODEID from NODESETS where SETID = ?";\r
+        DB db = new DB();\r
+        String sql = "select NODEID from NODESETS where SETID = ?";\r
+        try (Connection conn = db.getConnection()) {\r
             try (PreparedStatement ps = conn.prepareStatement(sql)) {\r
                 ps.setInt(1, nodelist);\r
-                try (ResultSet rs = ps.executeQuery()) {\r
-                    while (rs.next()) {\r
-                        int id = rs.getInt("NODEID");\r
-                        set.add(lookupNodeID(id));\r
-                    }\r
-                }\r
+                addNodeToSet(set, ps);\r
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
@@ -416,6 +360,15 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
         return set;\r
     }\r
 \r
+    private void addNodeToSet(Collection<String> set, PreparedStatement ps) throws SQLException {\r
+        try (ResultSet rs = ps.executeQuery()) {\r
+            while (rs.next()) {\r
+                int id = rs.getInt("NODEID");\r
+                set.add(lookupNodeID(id));\r
+            }\r
+        }\r
+    }\r
+\r
     /**\r
      * Delete the IRT route having this IngressRoutes feed ID, user ID, and subnet from the database.\r
      *\r
@@ -424,72 +377,49 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
     @Override\r
     public boolean doDelete(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            ps = c.prepareStatement("delete from INGRESS_ROUTES where FEEDID = ? and USERID = ? and SUBNET = ?");\r
+        try (PreparedStatement ps = c.prepareStatement(\r
+                 "delete from INGRESS_ROUTES where FEEDID = ? and USERID = ? and SUBNET = ?");\r
+                PreparedStatement ps2 = c.prepareStatement("delete from NODESETS where SETID = ?")) {\r
+            // Delete the Ingress Route\r
             ps.setInt(1, feedid);\r
             ps.setString(2, userid);\r
             ps.setString(3, subnet);\r
             ps.execute();\r
             ps.close();\r
-\r
-            ps = c.prepareStatement("delete from NODESETS where SETID = ?");\r
-            ps.setInt(1, nodelist);\r
-            ps.execute();\r
+            // Delete the NodeSet\r
+            ps2.setInt(1, nodelist);\r
+            ps2.execute();\r
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
 \r
-    @SuppressWarnings("resource")\r
     @Override\r
     public boolean doInsert(Connection c) {\r
         boolean rv = false;\r
-        PreparedStatement ps = null;\r
-        try {\r
+        try (PreparedStatement ps = c.prepareStatement("insert into NODESETS (SETID, NODEID) values (?,?)");\r
+                PreparedStatement ps2 = c.prepareStatement("insert into INGRESS_ROUTES (SEQUENCE, FEEDID, USERID,"\r
+                        + " SUBNET, NODESET) values (?, ?, ?, ?, ?)")) {\r
             // Create the NODESETS rows & set nodelist\r
-            int set = getMaxNodeSetID() + 1;\r
-            this.nodelist = set;\r
+            this.nodelist = getMaxNodeSetID() + 1;\r
             for (String node : nodes) {\r
                 int id = lookupNodeName(node);\r
-                ps = c.prepareStatement("insert into NODESETS (SETID, NODEID) values (?,?)");\r
                 ps.setInt(1, this.nodelist);\r
                 ps.setInt(2, id);\r
                 ps.execute();\r
-                ps.close();\r
             }\r
-\r
             // Create the INGRESS_ROUTES row\r
-            ps = c.prepareStatement(\r
-                    "insert into INGRESS_ROUTES (SEQUENCE, FEEDID, USERID, SUBNET, NODESET) values (?, ?, ?, ?, ?)");\r
-            ps.setInt(1, this.seq);\r
-            ps.setInt(2, this.feedid);\r
-            ps.setString(3, this.userid);\r
-            ps.setString(4, this.subnet);\r
-            ps.setInt(5, this.nodelist);\r
-            ps.execute();\r
-            ps.close();\r
+            ps2.setInt(1, this.seq);\r
+            ps2.setInt(2, this.feedid);\r
+            ps2.setString(3, this.userid);\r
+            ps2.setString(4, this.subnet);\r
+            ps2.setInt(5, this.nodelist);\r
+            ps2.execute();\r
             rv = true;\r
         } catch (SQLException e) {\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -504,10 +434,10 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
         JSONObject jo = new JSONObject();\r
         jo.put("feedid", feedid);\r
         // Note: for user and subnet, null, "", and "-" are equivalent\r
-        if (userid != null && !userid.equals("-") && !userid.equals("")) {\r
+        if (userid != null && !"-".equals(userid) && !"".equals(userid)) {\r
             jo.put("user", userid);\r
         }\r
-        if (subnet != null && !subnet.equals("-") && !subnet.equals("")) {\r
+        if (subnet != null && !"-".equals(subnet) && !"".equals(subnet)) {\r
             jo.put("subnet", subnet);\r
         }\r
         jo.put("seq", seq);\r
index 6a677ce..ed0815e 100644 (file)
@@ -32,6 +32,7 @@ import java.sql.Connection;
  * @author Robert Eby\r
  * @version $Id: Insertable.java,v 1.2 2013/05/29 14:44:36 eby Exp $\r
  */\r
+@FunctionalInterface\r
 public interface Insertable {\r
     /**\r
      * Insert this object into the DB.\r
@@ -39,5 +40,5 @@ public interface Insertable {
      * @param c the JDBC Connection to use\r
      * @return true if the INSERT succeeded, false otherwise\r
      */\r
-    public boolean doInsert(Connection c);\r
+    boolean doInsert(Connection c);\r
 }\r
index 8231327..44cea0f 100644 (file)
@@ -32,11 +32,12 @@ import org.json.JSONObject;
  * @author Robert Eby\r
  * @version $Id: JSONable.java,v 1.1 2013/04/26 21:00:26 eby Exp $\r
  */\r
+@FunctionalInterface\r
 public interface JSONable {\r
     /**\r
      * Get a JSONObject representing this object.\r
      *\r
      * @return the JSONObject\r
      */\r
-    public JSONObject asJSONObject();\r
+    JSONObject asJSONObject();\r
 }\r
index 3b7add5..24f65b1 100644 (file)
@@ -32,11 +32,12 @@ import org.onap.dmaap.datarouter.provisioning.utils.LOGJSONObject;
  * @author Robert Eby\r
  * @version $Id: JSONable.java,v 1.1 2013/04/26 21:00:26 eby Exp $\r
  */\r
+@FunctionalInterface\r
 public interface LOGJSONable {\r
     /**\r
      * Get a JSONObject representing this object.\r
      *\r
      * @return the JSONObject\r
      */\r
-    public LOGJSONObject asJSONObject();\r
+    LOGJSONObject asJSONObject();\r
 }\r
index ae64e84..adeaa46 100644 (file)
@@ -36,6 +36,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
  * @author Robert Eby\r
  * @version $Id: Loadable.java,v 1.2 2013/08/06 13:28:33 eby Exp $\r
  */\r
+@FunctionalInterface\r
 public interface Loadable {\r
     /**\r
      * Load the 18 fields in the PreparedStatement <i>ps</i>. The fields are:\r
@@ -62,5 +63,5 @@ public interface Loadable {
      *\r
      * @param ps the PreparedStatement to load\r
      */\r
-    public void load(PreparedStatement ps) throws SQLException;\r
+    void load(PreparedStatement ps) throws SQLException;\r
 }\r
index eeca090..fa3d4e0 100644 (file)
@@ -24,6 +24,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.sql.Connection;\r
 import java.sql.PreparedStatement;\r
 import java.sql.ResultSet;\r
@@ -32,9 +34,6 @@ import java.sql.Statement;
 import java.util.Objects;\r
 import java.util.SortedSet;\r
 import java.util.TreeSet;\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
 \r
@@ -52,6 +51,30 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
     private final int tonode;\r
     private final int vianode;\r
 \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) {\r
+        this.fromnode = lookupNodeName(fromnode);\r
+        this.tonode = lookupNodeName(tonode);\r
+        this.vianode = lookupNodeName(vianode);\r
+    }\r
+\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
+    private NetworkRoute(int fromnode, int tonode, int vianode) {\r
+        this.fromnode = fromnode;\r
+        this.tonode = tonode;\r
+        this.vianode = vianode;\r
+    }\r
+\r
     /**\r
      * Get a set of all Network Routes in the DB.  The set is sorted according to the natural sorting order of the\r
      * routes (based on the from and to node names in each route).\r
@@ -66,43 +89,24 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
             Connection conn = db.getConnection();\r
             try (Statement stmt = conn.createStatement()) {\r
                 try (ResultSet rs = stmt.executeQuery("select FROMNODE, TONODE, VIANODE from NETWORK_ROUTES")) {\r
-                    while (rs.next()) {\r
-                        int fromnode = rs.getInt("FROMNODE");\r
-                        int tonode = rs.getInt("TONODE");\r
-                        int vianode = rs.getInt("VIANODE");\r
-                        set.add(new NetworkRoute(fromnode, tonode, vianode));\r
-                    }\r
+                    addNetworkRouteToSet(set, rs);\r
                 }\r
+            } finally {\r
+                db.release(conn);\r
             }\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
             intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
         }\r
         return set;\r
     }\r
 \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) {\r
-        this.fromnode = lookupNodeName(fromnode);\r
-        this.tonode = lookupNodeName(tonode);\r
-        this.vianode = lookupNodeName(vianode);\r
-    }\r
-\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) {\r
-        this.fromnode = fromnode;\r
-        this.tonode = tonode;\r
-        this.vianode = vianode;\r
+    private static void addNetworkRouteToSet(SortedSet<NetworkRoute> set, ResultSet rs) throws SQLException {\r
+        while (rs.next()) {\r
+            int fromnode = rs.getInt("FROMNODE");\r
+            int tonode = rs.getInt("TONODE");\r
+            int vianode = rs.getInt("VIANODE");\r
+            set.add(new NetworkRoute(fromnode, tonode, vianode));\r
+        }\r
     }\r
 \r
     public int getFromnode() {\r
@@ -120,24 +124,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
     @Override\r
     public boolean doDelete(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            String sql = "delete from NETWORK_ROUTES where FROMNODE = ? AND TONODE = ?";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "delete from NETWORK_ROUTES where FROMNODE = ? AND TONODE = ?";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setInt(1, fromnode);\r
             ps.setInt(2, tonode);\r
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -145,28 +139,17 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
     @Override\r
     public boolean doInsert(Connection c) {\r
         boolean rv = false;\r
+        String sql = "insert into NETWORK_ROUTES (FROMNODE, TONODE, VIANODE) values (?, ?, ?)";\r
         if (this.vianode >= 0) {\r
-            PreparedStatement ps = null;\r
-            try {\r
+            try (PreparedStatement ps = c.prepareStatement(sql)) {\r
                 // Create the NETWORK_ROUTES row\r
-                String sql = "insert into NETWORK_ROUTES (FROMNODE, TONODE, VIANODE) values (?, ?, ?)";\r
-                ps = c.prepareStatement(sql);\r
                 ps.setInt(1, this.fromnode);\r
                 ps.setInt(2, this.tonode);\r
                 ps.setInt(3, this.vianode);\r
                 ps.execute();\r
-                ps.close();\r
                 rv = true;\r
             } catch (SQLException e) {\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(), e);\r
-                }\r
             }\r
         }\r
         return rv;\r
@@ -175,10 +158,8 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
     @Override\r
     public boolean doUpdate(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            String sql = "update NETWORK_ROUTES set VIANODE = ? where FROMNODE = ? and TONODE = ?";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "update NETWORK_ROUTES set VIANODE = ? where FROMNODE = ? and TONODE = ?";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setInt(1, vianode);\r
             ps.setInt(2, fromnode);\r
             ps.setInt(3, tonode);\r
@@ -186,14 +167,6 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
index f3ef5d6..d11c20f 100755 (executable)
@@ -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.sql.Connection;\r
 import java.sql.PreparedStatement;\r
 import java.sql.ResultSet;\r
@@ -32,9 +34,6 @@ import java.util.HashMap;
 import java.util.Map;\r
 import java.util.Set;\r
 import java.util.TreeSet;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
 import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 \r
 /**\r
@@ -45,9 +44,11 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
  */\r
 public abstract class NodeClass extends Syncable {\r
 \r
+    private static final String PROV_0005_DO_INSERT = "PROV0005 doInsert: ";\r
     private static Map<String, Integer> map;\r
     private static EELFLogger intLogger = EELFManager.getInstance().getLogger("InternalLog");\r
-    public NodeClass() {\r
+\r
+    NodeClass() {\r
         // init on first use\r
         if (map == null) {\r
             reload();\r
@@ -77,67 +78,50 @@ public abstract class NodeClass extends Syncable {
             if (!map.containsKey(node)) {\r
                 intLogger.info("..adding " + node + " to NODES with index " + nextid);\r
                 map.put(node, nextid);\r
-                PreparedStatement ps = null;\r
-                try {\r
-                    DB db = new DB();\r
-                    @SuppressWarnings("resource")\r
-                    Connection conn = db.getConnection();\r
-                    ps = conn.prepareStatement("insert into NODES (NODEID, NAME, ACTIVE) values (?, ?, 1)");\r
-                    ps.setInt(1, nextid);\r
-                    ps.setString(2, node);\r
-                    ps.execute();\r
-                    ps.close();\r
-                    db.release(conn);\r
-                } catch (SQLException e) {\r
-                    intLogger.error("PROV0005 doInsert: " + e.getMessage(),e);\r
-                } finally {\r
-                    try {\r
-                        if(ps!=null){\r
-                            ps.close();\r
-                        }\r
-                    } catch (SQLException e) {\r
-                        intLogger.error("Error in closing PreparedStatement: " + e.getMessage(),e);\r
-                    }\r
-                }\r
+                insertNodesToTable(nextid, node);\r
                 nextid++;\r
             }\r
         }\r
     }\r
 \r
-    public static void reload() {\r
-        Map<String, Integer> m = new HashMap<String, Integer>();\r
-        PreparedStatement ps = null;\r
+    private static void insertNodesToTable(int nextid, String node) {\r
+        DB db = new DB();\r
+        try (Connection conn = db.getConnection()) {\r
+            try (PreparedStatement ps = conn\r
+                    .prepareStatement("insert into NODES (NODEID, NAME, ACTIVE) values (?, ?, 1)")) {\r
+                ps.setInt(1, nextid);\r
+                ps.setString(2, node);\r
+                ps.execute();\r
+            } finally {\r
+                db.release(conn);\r
+            }\r
+        } catch (SQLException e) {\r
+            intLogger.error(PROV_0005_DO_INSERT + e.getMessage(), e);\r
+        }\r
+    }\r
 \r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            String sql = "select NODEID, NAME from NODES";\r
-            ps = conn.prepareStatement(sql);\r
-            try(ResultSet rs = ps.executeQuery()) {\r
+    private static void reload() {\r
+        Map<String, Integer> m = new HashMap<>();\r
+        String sql = "select NODEID, NAME from NODES";\r
+        DB db = new DB();\r
+        try (Connection conn = db.getConnection();\r
+                PreparedStatement ps = conn.prepareStatement(sql)) {\r
+            try (ResultSet rs = ps.executeQuery()) {\r
                 while (rs.next()) {\r
                     int id = rs.getInt("NODEID");\r
                     String name = rs.getString("NAME");\r
                     m.put(name, id);\r
                 }\r
+            } finally {\r
+                db.release(conn);\r
             }\r
-            ps.close();\r
-            db.release(conn);\r
         } catch (SQLException e) {\r
-            intLogger.error("PROV0005 doInsert: " + e.getMessage(),e);\r
-        } finally {\r
-            try {\r
-                if(ps!=null){\r
-                    ps.close();\r
-                }\r
-            } catch (SQLException e) {\r
-                intLogger.error("PROV0005 doInsert: " + e.getMessage(),e);\r
-            }\r
+            intLogger.error(PROV_0005_DO_INSERT + e.getMessage(),e);\r
         }\r
         map = m;\r
     }\r
 \r
-    public static Integer lookupNodeName(final String name) {\r
+    static Integer lookupNodeName(final String name) {\r
         Integer n = map.get(name);\r
         if (n == null) {\r
             throw new IllegalArgumentException("Invalid node name: " + name);\r
@@ -146,16 +130,11 @@ public abstract class NodeClass extends Syncable {
     }\r
 \r
     public static Collection<String> lookupNodeNames(String patt) {\r
-        Collection<String> coll = new TreeSet<String>();\r
+        Collection<String> coll = new TreeSet<>();\r
         final Set<String> keyset = map.keySet();\r
         for (String s : patt.toLowerCase().split(",")) {\r
             if (s.endsWith("*")) {\r
-                s = s.substring(0, s.length() - 1);\r
-                for (String s2 : keyset) {\r
-                    if (s2.startsWith(s)) {\r
-                        coll.add(s2);\r
-                    }\r
-                }\r
+                addNodeToCollection(coll, keyset, s);\r
             } else if (keyset.contains(s)) {\r
                 coll.add(s);\r
             } else if (keyset.contains(normalizeNodename(s))) {\r
@@ -167,6 +146,15 @@ public abstract class NodeClass extends Syncable {
         return coll;\r
     }\r
 \r
+    private static void addNodeToCollection(Collection<String> coll, Set<String> keyset, String s) {\r
+        s = s.substring(0, s.length() - 1);\r
+        for (String s2 : keyset) {\r
+            if (s2.startsWith(s)) {\r
+                coll.add(s2);\r
+            }\r
+        }\r
+    }\r
+\r
     public static String normalizeNodename(String s) {\r
         if (s != null && s.indexOf('.') <= 0) {\r
             Parameters p = Parameters.getParameter(Parameters.PROV_DOMAIN);\r
@@ -175,17 +163,16 @@ public abstract class NodeClass extends Syncable {
                 s += "." + domain;\r
             }\r
             return s.toLowerCase();\r
-        }\r
-        else{\r
+        } else {\r
             return s;\r
         }\r
 \r
     }\r
 \r
-    protected String lookupNodeID(int n) {\r
-        for (String s : map.keySet()) {\r
-            if (map.get(s) == n) {\r
-                return s;\r
+    String lookupNodeID(int n) {\r
+        for (Map.Entry<String, Integer> entry : map.entrySet()) {\r
+            if (entry.getValue() == n) {\r
+                return entry.getKey();\r
             }\r
         }\r
         return null;\r
index fff10ac..78ed96d 100644 (file)
 \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.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.util.*;\r
-\r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
+import java.util.ArrayList;\r
+import java.util.Collection;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Objects;\r
 import org.json.JSONObject;\r
 import org.onap.dmaap.datarouter.provisioning.utils.DB;\r
 \r
@@ -57,6 +60,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
@@ -66,7 +70,7 @@ public class Parameters extends Syncable {
     public static final String DELIVERY_RETRY_RATIO = "DELIVERY_RETRY_RATIO";\r
     public static final String DELIVERY_MAX_AGE = "DELIVERY_MAX_AGE";\r
     public static final String THROTTLE_FILTER = "THROTTLE_FILTER";\r
-    public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; //Adding new param for static Routing - Rally:US664862-1610\r
+    public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES";\r
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
     private static final String SQLEXCEPTION = "SQLException: ";\r
@@ -74,13 +78,23 @@ public class Parameters extends Syncable {
     private String keyname;\r
     private String value;\r
 \r
+    public Parameters(String k, String v) {\r
+        this.keyname = k;\r
+        this.value = v;\r
+    }\r
+\r
+    public Parameters(ResultSet rs) throws SQLException {\r
+        this.keyname = rs.getString("KEYNAME");\r
+        this.value = rs.getString("VALUE");\r
+    }\r
+\r
     /**\r
      * Get all parameters in the DB as a Map.\r
      *\r
      * @return the Map of keynames/values from the DB.\r
      */\r
     public static Map<String, String> getParameters() {\r
-        Map<String, String> props = new HashMap<String, String>();\r
+        Map<String, String> props = new HashMap<>();\r
         for (Parameters p : getParameterCollection()) {\r
             props.put(p.getKeyname(), p.getValue());\r
         }\r
@@ -88,23 +102,20 @@ public class Parameters extends Syncable {
     }\r
 \r
     public static Collection<Parameters> getParameterCollection() {\r
-        Collection<Parameters> coll = new ArrayList<Parameters>();\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (Statement stmt = conn.createStatement()) {\r
-                String sql = "select * from PARAMETERS";\r
-                try (ResultSet rs = stmt.executeQuery(sql)) {\r
-                    while (rs.next()) {\r
-                        Parameters p = new Parameters(rs);\r
-                        coll.add(p);\r
-                    }\r
+        Collection<Parameters> coll = new ArrayList<>();\r
+        DB db = new DB();\r
+        String sql = "select * from PARAMETERS";\r
+        try (Connection conn = db.getConnection();\r
+                Statement stmt = conn.createStatement()) {\r
+            try (ResultSet rs = stmt.executeQuery(sql)) {\r
+                while (rs.next()) {\r
+                    Parameters p = new Parameters(rs);\r
+                    coll.add(p);\r
                 }\r
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error(SQLEXCEPTION + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
         }\r
         return coll;\r
     }\r
@@ -117,48 +128,27 @@ public class Parameters extends Syncable {
      */\r
     public static Parameters getParameter(String k) {\r
         Parameters v = null;\r
-        try {\r
-            DB db = new DB();\r
-            @SuppressWarnings("resource")\r
-            Connection conn = db.getConnection();\r
-            try (PreparedStatement stmt = conn\r
-                    .prepareStatement("select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?")) {\r
-                stmt.setString(1, k);\r
-                try (ResultSet rs = stmt.executeQuery()) {\r
-                    if (rs.next()) {\r
-                        v = new Parameters(rs);\r
-                    }\r
+        DB db = new DB();\r
+        String sql = "select KEYNAME, VALUE from PARAMETERS where KEYNAME = ?";\r
+        try (Connection conn = db.getConnection();\r
+                PreparedStatement stmt = conn.prepareStatement(sql)) {\r
+            stmt.setString(1, k);\r
+            try (ResultSet rs = stmt.executeQuery()) {\r
+                if (rs.next()) {\r
+                    v = new Parameters(rs);\r
                 }\r
             }\r
             db.release(conn);\r
         } catch (SQLException e) {\r
-            intlogger.error(SQLEXCEPTION + e.getMessage());\r
+            intlogger.error(SQLEXCEPTION + e.getMessage(), e);\r
         }\r
         return v;\r
     }\r
 \r
-    public Parameters() {\r
-        this("", "");\r
-    }\r
-\r
-    public Parameters(String k, String v) {\r
-        this.keyname = k;\r
-        this.value = v;\r
-    }\r
-\r
-    public Parameters(ResultSet rs) throws SQLException {\r
-        this.keyname = rs.getString("KEYNAME");\r
-        this.value = rs.getString("VALUE");\r
-    }\r
-\r
     public String getKeyname() {\r
         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
@@ -178,25 +168,14 @@ public class Parameters extends Syncable {
     @Override\r
     public boolean doInsert(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            // Create the SUBSCRIPTIONS row\r
-            String sql = "insert into PARAMETERS values (?, ?)";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "insert into PARAMETERS values (?, ?)";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setString(1, getKeyname());\r
             ps.setString(2, getValue());\r
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\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
-            }\r
         }\r
         return rv;\r
     }\r
@@ -204,25 +183,14 @@ public class Parameters extends Syncable {
     @Override\r
     public boolean doUpdate(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            // Update the PARAMETERS row\r
-            String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "update PARAMETERS set VALUE = ? where KEYNAME = ?";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setString(1, getValue());\r
             ps.setString(2, getKeyname());\r
             ps.executeUpdate();\r
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -230,24 +198,13 @@ public class Parameters extends Syncable {
     @Override\r
     public boolean doDelete(Connection c) {\r
         boolean rv = true;\r
-        PreparedStatement ps = null;\r
-        try {\r
-            // Create the SUBSCRIPTIONS row\r
-            String sql = "delete from PARAMETERS where KEYNAME = ?";\r
-            ps = c.prepareStatement(sql);\r
+        String sql = "delete from PARAMETERS where KEYNAME = ?";\r
+        try (PreparedStatement ps = c.prepareStatement(sql)) {\r
             ps.setString(1, getKeyname());\r
             ps.execute();\r
         } catch (SQLException e) {\r
             rv = false;\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(), e);\r
-            }\r
         }\r
         return rv;\r
     }\r
@@ -263,13 +220,7 @@ public class Parameters extends Syncable {
             return false;\r
         }\r
         Parameters of = (Parameters) obj;\r
-        if (!keyname.equals(of.keyname)) {\r
-            return false;\r
-        }\r
-        if (!value.equals(of.value)) {\r
-            return false;\r
-        }\r
-        return true;\r
+        return (!value.equals(of.value)) && (!keyname.equals(of.keyname));\r
     }\r
 \r
     @Override\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 7700a58..55b2c03 100644 (file)
 \r
 package org.onap.dmaap.datarouter.provisioning.utils;\r
 \r
+import static java.lang.System.exit;\r
+import static java.lang.System.getProperty;\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.FileReader;\r
@@ -42,9 +47,6 @@ import java.util.Properties;
 import java.util.Queue;\r
 import java.util.Set;\r
 \r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-\r
 /**\r
  * Load the DB JDBC driver, and manage a simple pool of connections to the DB.\r
  *\r
@@ -55,14 +57,14 @@ public class DB {
 \r
     private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");\r
 \r
-    private static String DB_URL;\r
-    private static String DB_LOGIN;\r
-    private static String DB_PASSWORD;\r
+    private static String dbUrl;\r
+    private static String dbLogin;\r
+    private static String dbPassword;\r
     private static Properties props;\r
     private static final Queue<Connection> queue = new LinkedList<>();\r
 \r
-    private static String HTTPS_PORT;\r
-    private static String HTTP_PORT;\r
+    private static String httpsPort;\r
+    private static String httpPort;\r
 \r
     /**\r
      * Construct a DB object.  If this is the very first creation of this object, it will load a copy of the properties\r
@@ -73,22 +75,22 @@ public class DB {
         if (props == null) {\r
             props = new Properties();\r
             try {\r
-                props.load(new FileInputStream(System.getProperty(\r
+                props.load(new FileInputStream(getProperty(\r
                     "org.onap.dmaap.datarouter.provserver.properties",\r
                     "/opt/app/datartr/etc/provserver.properties")));\r
-                String DB_DRIVER = (String) props.get("org.onap.dmaap.datarouter.db.driver");\r
-                DB_URL = (String) props.get("org.onap.dmaap.datarouter.db.url");\r
-                DB_LOGIN = (String) props.get("org.onap.dmaap.datarouter.db.login");\r
-                DB_PASSWORD = (String) props.get("org.onap.dmaap.datarouter.db.password");\r
-                HTTPS_PORT = (String) props.get("org.onap.dmaap.datarouter.provserver.https.port");\r
-                HTTP_PORT = (String) props.get("org.onap.dmaap.datarouter.provserver.http.port");\r
-                Class.forName(DB_DRIVER);\r
+                String dbDriver = (String) props.get("org.onap.dmaap.datarouter.db.driver");\r
+                dbUrl = (String) props.get("org.onap.dmaap.datarouter.db.url");\r
+                dbLogin = (String) props.get("org.onap.dmaap.datarouter.db.login");\r
+                dbPassword = (String) props.get("org.onap.dmaap.datarouter.db.password");\r
+                httpsPort = (String) props.get("org.onap.dmaap.datarouter.provserver.https.port");\r
+                httpPort = (String) props.get("org.onap.dmaap.datarouter.provserver.http.port");\r
+                Class.forName(dbDriver);\r
             } catch (IOException e) {\r
                 intlogger.error("PROV9003 Opening properties: " + e.getMessage(), e);\r
-                System.exit(1);\r
+                exit(1);\r
             } catch (ClassNotFoundException e) {\r
                 intlogger.error("PROV9004 cannot find the DB driver: " + e);\r
-                System.exit(1);\r
+                exit(1);\r
             }\r
         }\r
     }\r
@@ -107,7 +109,6 @@ public class DB {
      *\r
      * @return the Connection\r
      */\r
-    @SuppressWarnings("resource")\r
     public Connection getConnection() throws SQLException {\r
         Connection connection = null;\r
         while (connection == null) {\r
@@ -120,7 +121,7 @@ public class DB {
                     do {\r
                         // Try up to 3 times to get a connection\r
                         try {\r
-                            connection = DriverManager.getConnection(DB_URL, DB_LOGIN, DB_PASSWORD);\r
+                            connection = DriverManager.getConnection(dbUrl, dbLogin, dbPassword);\r
                         } catch (SQLException sqlEx) {\r
                             if (++n >= 3) {\r
                                 throw sqlEx;\r
@@ -164,11 +165,11 @@ public class DB {
 \r
 \r
     public static String getHttpsPort() {\r
-        return HTTPS_PORT;\r
+        return httpsPort;\r
     }\r
 \r
     public static String getHttpPort() {\r
-        return HTTP_PORT;\r
+        return httpPort;\r
     }\r
 \r
     /**\r
@@ -238,34 +239,35 @@ public class DB {
      */\r
     private void runInitScript(Connection connection, int scriptId) {\r
         String scriptDir = (String) props.get("org.onap.dmaap.datarouter.provserver.dbscripts");\r
-        StringBuilder strBuilder = new StringBuilder();\r
-        try {\r
-            String scriptFile = String.format("%s/sql_init_%02d.sql", scriptDir, scriptId);\r
-            if (!(new File(scriptFile)).exists()) {\r
-                intlogger.error("PROV9005 Failed to load sql script from : " + scriptFile);\r
-                System.exit(1);\r
-            }\r
-            LineNumberReader lineReader = new LineNumberReader(new FileReader(scriptFile));\r
+        String scriptFile = String.format("%s/sql_init_%02d.sql", scriptDir, scriptId);\r
+        if (!(new File(scriptFile)).exists()) {\r
+            intlogger.error("PROV9005 Failed to load sql script from : " + scriptFile);\r
+            exit(1);\r
+        }\r
+        try (LineNumberReader lineReader = new LineNumberReader(new FileReader(scriptFile));\r
+                Statement statement = connection.createStatement()) {\r
+            StringBuilder strBuilder = new StringBuilder();\r
             String line;\r
             while ((line = lineReader.readLine()) != null) {\r
                 if (!line.startsWith("--")) {\r
                     line = line.trim();\r
                     strBuilder.append(line);\r
-                    if (line.endsWith(";")) {\r
-                        // Execute one DDL statement\r
-                        String sql = strBuilder.toString();\r
-                        strBuilder.setLength(0);\r
-                        Statement statement = connection.createStatement();\r
-                        statement.execute(sql);\r
-                        statement.close();\r
-                    }\r
+                    executeDdlStatement(statement, strBuilder, line);\r
                 }\r
             }\r
-            lineReader.close();\r
             strBuilder.setLength(0);\r
         } catch (Exception e) {\r
             intlogger.error("PROV9002 Error when initializing table: " + e.getMessage(), e);\r
-            System.exit(1);\r
+            exit(1);\r
+        }\r
+    }\r
+\r
+    private void executeDdlStatement(Statement statement, StringBuilder strBuilder, String line) throws SQLException {\r
+        if (line.endsWith(";")) {\r
+            // Execute one DDL statement\r
+            String sql = strBuilder.toString();\r
+            strBuilder.setLength(0);\r
+            statement.execute(sql);\r
         }\r
     }\r
 }\r
index d9f36de..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);
index f7e0874..bc1f449 100644 (file)
@@ -28,11 +28,14 @@ import com.att.eelf.configuration.EELFManager;
 import java.io.IOException;
 import java.io.StringWriter;
 import java.io.Writer;
-import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
-import java.util.*;
-
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONString;
@@ -93,10 +96,13 @@ import org.json.JSONTokener;
  * @version 2012-12-01
  */
 public class LOGJSONObject {
+
     /**
      * The maximum number of keys in the key pool.
      */
-    private static final int keyPoolSize = 100;
+    private static final int KEY_POOL_SIZE = 100;
+    private static final String USING_DEFAULT_VALUE = "Using defaultValue: ";
+    private static final String JSON_OBJECT_CONST = "JSONObject[";
 
     /**
      * Key pooling is like string interning, but without permanently tying up
@@ -104,7 +110,7 @@ public class LOGJSONObject {
      * JSONObjects will be avoided by using a key pool to manage unique key
      * string objects. This is used by JSONObject.put(string, object).
      */
-    private static Map<String, Object> keyPool = new LinkedHashMap<String, Object>(keyPoolSize);
+    private static Map<String, Object> keyPool = new LinkedHashMap<>(KEY_POOL_SIZE);
 
     private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
 
@@ -186,21 +192,18 @@ 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.
      * <code>JSONObject.NULL.equals(null)</code> returns <code>true</code>.
      * <code>JSONObject.NULL.toString()</code> returns <code>"null"</code>.
      */
-    public static final Object NULL = new Null();
-
+    private static final Object NULL = new Null();
 
     /**
      * Construct an empty JSONObject.
@@ -209,7 +212,6 @@ public class LOGJSONObject {
         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.
@@ -229,7 +231,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Construct a JSONObject from a JSONTokener.
      *
@@ -287,7 +288,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Construct a JSONObject from a Map.
      *
@@ -296,7 +296,7 @@ public class LOGJSONObject {
      * @throws JSONException
      */
     public LOGJSONObject(Map<String, Object> map) {
-        this.map = new LinkedHashMap<String, Object>();
+        this.map = new LinkedHashMap<>();
         if (map != null) {
             Iterator<Map.Entry<String, Object>> i = map.entrySet().iterator();
             while (i.hasNext()) {
@@ -309,7 +309,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Construct a JSONObject from an Object using bean getters.
      * It reflects on all of the public methods of the object.
@@ -334,88 +333,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
-     * from the names array, and the values will be the field values associated
-     * with those keys in the object. If a key is not found or not visible,
-     * then it will not be copied into the new JSONObject.
-     *
-     * @param object An object that has fields that should be used to make a
-     *               JSONObject.
-     * @param names  An array of strings, the names of the fields to be obtained
-     *               from the object.
-     */
-    public LOGJSONObject(Object object, String names[]) {
-        this();
-        Class<? extends Object> c = object.getClass();
-        for (int i = 0; i < names.length; i += 1) {
-            String name = names[i];
-            try {
-                this.putOpt(name, c.getField(name).get(object));
-            } catch (Exception ignore) {
-            }
-        }
-    }
-
-
-    /**
-     * Construct a JSONObject from a source JSON text string.
-     * This is the most commonly used JSONObject constructor.
-     *
-     * @param source A string beginning
-     *               with <code>{</code>&nbsp;<small>(left brace)</small> and ending
-     *               with <code>}</code>&nbsp;<small>(right brace)</small>.
-     * @throws JSONException If there is a syntax error in the source
-     *                       string or a duplicated key.
-     */
-    public LOGJSONObject(String source) throws JSONException {
-        this(new JSONTokener(source));
-    }
-
-
-    /**
-     * Construct a JSONObject from a ResourceBundle.
-     *
-     * @param baseName The ResourceBundle base name.
-     * @param locale   The Locale to load the ResourceBundle for.
-     * @throws JSONException If any JSONExceptions are detected.
-     */
-    public LOGJSONObject(String baseName, Locale locale) throws JSONException {
-        this();
-        ResourceBundle bundle = ResourceBundle.getBundle(baseName, locale,
-                Thread.currentThread().getContextClassLoader());
-
-// Iterate through the keys in the bundle.
-
-        Enumeration<?> keys = bundle.getKeys();
-        while (keys.hasMoreElements()) {
-            Object key = keys.nextElement();
-            if (key instanceof String) {
-
-// Go through the path, ensuring that there is a nested JSONObject for each
-// segment except the last. Add the value using the last segment's name into
-// the deepest nested JSONObject.
-
-                String[] path = ((String) key).split("\\.");
-                int last = path.length - 1;
-                LOGJSONObject target = this;
-                for (int i = 0; i < last; i += 1) {
-                    String segment = path[i];
-                    LOGJSONObject nextTarget = target.optJSONObject(segment);
-                    if (nextTarget == null) {
-                        nextTarget = new LOGJSONObject();
-                        target.put(segment, nextTarget);
-                    }
-                    target = nextTarget;
-                }
-                target.put(path[last], bundle.getString((String) key));
-            }
-        }
-    }
-
-
     /**
      * 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
@@ -434,15 +351,15 @@ public class LOGJSONObject {
      *                       or if the key is null.
      */
     public LOGJSONObject accumulate(
-            String key,
-            Object value
-    ) throws JSONException {
+        String key,
+        Object value
+    ) {
         testValidity(value);
         Object object = this.opt(key);
         if (object == null) {
             this.put(key, value instanceof JSONArray
-                    ? new JSONArray().put(value)
-                    : value);
+                ? new JSONArray().put(value)
+                : value);
         } else if (object instanceof JSONArray) {
             ((JSONArray) object).put(value);
         } else {
@@ -451,7 +368,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
@@ -464,7 +380,7 @@ public class LOGJSONObject {
      * @throws JSONException If the key is null or if the current value
      *                       associated with the key is not a JSONArray.
      */
-    public LOGJSONObject append(String key, Object value) throws JSONException {
+    public LOGJSONObject append(String key, Object value) {
         testValidity(value);
         Object object = this.opt(key);
         if (object == null) {
@@ -472,13 +388,12 @@ public class LOGJSONObject {
         } else if (object instanceof JSONArray) {
             this.put(key, ((JSONArray) object).put(value));
         } else {
-            throw new JSONException("JSONObject[" + key +
-                    "] is not a JSONArray.");
+            throw new JSONException(JSON_OBJECT_CONST + key +
+                "] is not a JSONArray.");
         }
         return this;
     }
 
-
     /**
      * Produce a string from a double. The string "null" will be returned if
      * the number is not finite.
@@ -494,8 +409,8 @@ public class LOGJSONObject {
 // Shave off trailing zeros and decimal point, if possible.
 
         String string = Double.toString(d);
-        if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
-                string.indexOf('E') < 0) {
+        if (string.indexOf('.') > 0 && string.indexOf('e') < 0
+            && string.indexOf('E') < 0) {
             while (string.endsWith("0")) {
                 string = string.substring(0, string.length() - 1);
             }
@@ -506,7 +421,6 @@ public class LOGJSONObject {
         return string;
     }
 
-
     /**
      * Get the value object associated with a key.
      *
@@ -514,19 +428,18 @@ public class LOGJSONObject {
      * @return The object associated with the key.
      * @throws JSONException if the key is not found.
      */
-    public Object get(String key) throws JSONException {
+    public Object get(String key) {
         if (key == null) {
             throw new JSONException("Null key.");
         }
         Object object = this.opt(key);
         if (object == null) {
-            throw new JSONException("JSONObject[" + quote(key) +
-                    "] not found.");
+            throw new JSONException(JSON_OBJECT_CONST + quote(key) +
+                "] not found.");
         }
         return object;
     }
 
-
     /**
      * Get the boolean value associated with a key.
      *
@@ -534,22 +447,21 @@ public class LOGJSONObject {
      * @return The truth.
      * @throws JSONException if the value is not a Boolean or the String "true" or "false".
      */
-    public boolean getBoolean(String key) throws JSONException {
+    public boolean getBoolean(String key) {
         Object object = this.get(key);
         if (object.equals(Boolean.FALSE) ||
-                (object instanceof String &&
-                        ((String) object).equalsIgnoreCase("false"))) {
+            (object instanceof String &&
+                "false".equalsIgnoreCase((String) object))) {
             return false;
         } else if (object.equals(Boolean.TRUE) ||
-                (object instanceof String &&
-                        ((String) object).equalsIgnoreCase("true"))) {
+            (object instanceof String &&
+                "true".equalsIgnoreCase((String) object))) {
             return true;
         }
-        throw new JSONException("JSONObject[" + quote(key) +
-                "] is not a Boolean.");
+        throw new JSONException(JSON_OBJECT_CONST + quote(key) +
+            "] is not a Boolean.");
     }
 
-
     /**
      * Get the double value associated with a key.
      *
@@ -562,15 +474,14 @@ public class LOGJSONObject {
         Object object = this.get(key);
         try {
             return object instanceof Number
-                    ? ((Number) object).doubleValue()
-                    : Double.parseDouble((String) object);
+                ? ((Number) object).doubleValue()
+                : Double.parseDouble((String) object);
         } catch (Exception e) {
-            intlogger.error("JSONObject[" + quote(key) + "] is not a number.", e);
-            throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
+            intlogger.error(JSON_OBJECT_CONST + quote(key) + "] is not a number.", e);
+            throw new JSONException(JSON_OBJECT_CONST + quote(key) + "] is not a number.");
         }
     }
 
-
     /**
      * Get the int value associated with a key.
      *
@@ -583,15 +494,14 @@ public class LOGJSONObject {
         Object object = this.get(key);
         try {
             return object instanceof Number
-                    ? ((Number) object).intValue()
-                    : Integer.parseInt((String) object);
+                ? ((Number) object).intValue()
+                : Integer.parseInt((String) object);
         } catch (Exception e) {
-            intlogger.error("JSONObject[" + quote(key) + "] is not an int.", e);
-            throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
+            intlogger.error(JSON_OBJECT_CONST + quote(key) + "] is not an int.", e);
+            throw new JSONException(JSON_OBJECT_CONST + quote(key) + "] is not an int.");
         }
     }
 
-
     /**
      * Get the JSONArray value associated with a key.
      *
@@ -600,16 +510,15 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or
      *                       if the value is not a JSONArray.
      */
-    public JSONArray getJSONArray(String key) throws JSONException {
+    public JSONArray getJSONArray(String key) {
         Object object = this.get(key);
         if (object instanceof JSONArray) {
             return (JSONArray) object;
         }
-        throw new JSONException("JSONObject[" + quote(key) +
-                "] is not a JSONArray.");
+        throw new JSONException(JSON_OBJECT_CONST + quote(key) +
+            "] is not a JSONArray.");
     }
 
-
     /**
      * Get the JSONObject value associated with a key.
      *
@@ -618,16 +527,15 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or
      *                       if the value is not a JSONObject.
      */
-    public LOGJSONObject getJSONObject(String key) throws JSONException {
+    public LOGJSONObject getJSONObject(String key) {
         Object object = this.get(key);
         if (object instanceof LOGJSONObject) {
             return (LOGJSONObject) object;
         }
-        throw new JSONException("JSONObject[" + quote(key) +
-                "] is not a JSONObject.");
+        throw new JSONException(JSON_OBJECT_CONST + quote(key) +
+            "] is not a JSONObject.");
     }
 
-
     /**
      * Get the long value associated with a key.
      *
@@ -636,19 +544,18 @@ public class LOGJSONObject {
      * @throws JSONException if the key is not found or if the value cannot
      *                       be converted to a long.
      */
-    public long getLong(String key) throws JSONException {
+    public long getLong(String key) {
         Object object = this.get(key);
         try {
             return object instanceof Number
-                    ? ((Number) object).longValue()
-                    : Long.parseLong((String) object);
+                ? ((Number) object).longValue()
+                : Long.parseLong((String) object);
         } catch (Exception e) {
-            intlogger.error("JSONObject[" + quote(key) + "] is not a long.", e);
-            throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
+            intlogger.error(JSON_OBJECT_CONST + quote(key) + "] is not a long.", e);
+            throw new JSONException(JSON_OBJECT_CONST + quote(key) + "] is not a long.");
         }
     }
 
-
     /**
      * Get an array of field names from a JSONObject.
      *
@@ -657,7 +564,7 @@ public class LOGJSONObject {
     public static String[] getNames(LOGJSONObject jo) {
         int length = jo.length();
         if (length == 0) {
-            return null;
+            return new String[]{};
         }
         Iterator<String> iterator = jo.keys();
         String[] names = new String[length];
@@ -669,30 +576,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.
      *
@@ -705,11 +588,10 @@ public class LOGJSONObject {
         if (object instanceof String) {
             return (String) object;
         }
-        throw new JSONException("JSONObject[" + quote(key) +
-                "] not a string.");
+        throw new JSONException(JSON_OBJECT_CONST + quote(key) +
+            "] not a string.");
     }
 
-
     /**
      * Determine if the JSONObject contains a specific key.
      *
@@ -720,7 +602,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
@@ -749,20 +630,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.
      *
@@ -772,7 +639,6 @@ public class LOGJSONObject {
         return this.keySet().iterator();
     }
 
-
     /**
      * Get a set of keys of the JSONObject.
      *
@@ -782,7 +648,6 @@ public class LOGJSONObject {
         return this.map.keySet();
     }
 
-
     /**
      * Get the number of keys stored in the JSONObject.
      *
@@ -792,7 +657,6 @@ public class LOGJSONObject {
         return this.map.size();
     }
 
-
     /**
      * Produce a JSONArray containing the names of the elements of this
      * JSONObject.
@@ -817,7 +681,7 @@ public class LOGJSONObject {
      * @throws JSONException If n is a non-finite number.
      */
     public static String numberToString(Number number)
-            throws JSONException {
+        {
         if (number == null) {
             throw new JSONException("Null pointer");
         }
@@ -827,7 +691,7 @@ public class LOGJSONObject {
 
         String string = number.toString();
         if (string.indexOf('.') > 0 && string.indexOf('e') < 0 &&
-                string.indexOf('E') < 0) {
+            string.indexOf('E') < 0) {
             while (string.endsWith("0")) {
                 string = string.substring(0, string.length() - 1);
             }
@@ -838,7 +702,6 @@ public class LOGJSONObject {
         return string;
     }
 
-
     /**
      * Get an optional value associated with a key.
      *
@@ -849,20 +712,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
@@ -876,26 +725,11 @@ public class LOGJSONObject {
         try {
             return this.getBoolean(key);
         } catch (Exception e) {
-            intlogger.trace("Using defaultValue: " + defaultValue, e);
+            intlogger.trace(USING_DEFAULT_VALUE + 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.
@@ -910,26 +744,11 @@ public class LOGJSONObject {
         try {
             return this.getDouble(key);
         } catch (Exception e) {
-            intlogger.trace("Using defaultValue: " + defaultValue, e);
+            intlogger.trace(USING_DEFAULT_VALUE + 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.
@@ -944,54 +763,12 @@ public class LOGJSONObject {
         try {
             return this.getInt(key);
         } catch (Exception e) {
-            intlogger.trace("Using defaultValue: " + defaultValue, e);
+            intlogger.trace(USING_DEFAULT_VALUE + 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
-     * JSONObject.
-     *
-     * @param key A key string.
-     * @return A JSONObject which is the value.
-     */
-    public LOGJSONObject optJSONObject(String key) {
-        Object object = this.opt(key);
-        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.
@@ -1010,20 +787,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.
@@ -1037,17 +800,16 @@ public class LOGJSONObject {
         return NULL.equals(object) ? defaultValue : object.toString();
     }
 
-
     private void populateMap(Object bean) {
-        Class<? extends Object> klass = bean.getClass();
+        Class<?> klass = bean.getClass();
 
 // If klass is a System class then set includeSuperClass to false.
 
         boolean includeSuperClass = klass.getClassLoader() != null;
 
         Method[] methods = includeSuperClass
-                ? klass.getMethods()
-                : klass.getDeclaredMethods();
+            ? klass.getMethods()
+            : klass.getDeclaredMethods();
         for (int i = 0; i < methods.length; i += 1) {
             try {
                 Method method = methods[i];
@@ -1056,7 +818,7 @@ public class LOGJSONObject {
                     String key = "";
                     if (name.startsWith("get")) {
                         if ("getClass".equals(name) ||
-                                "getDeclaringClass".equals(name)) {
+                            "getDeclaringClass".equals(name)) {
                             key = "";
                         } else {
                             key = name.substring(3);
@@ -1065,13 +827,13 @@ public class LOGJSONObject {
                         key = name.substring(2);
                     }
                     if (key.length() > 0 &&
-                            Character.isUpperCase(key.charAt(0)) &&
-                            method.getParameterTypes().length == 0) {
+                        Character.isUpperCase(key.charAt(0)) &&
+                        method.getParameterTypes().length == 0) {
                         if (key.length() == 1) {
                             key = key.toLowerCase();
                         } else if (!Character.isUpperCase(key.charAt(1))) {
                             key = key.substring(0, 1).toLowerCase() +
-                                    key.substring(1);
+                                key.substring(1);
                         }
 
                         Object result = method.invoke(bean, (Object[]) null);
@@ -1086,36 +848,6 @@ public class LOGJSONObject {
         }
     }
 
-
-    /**
-     * Put a key/boolean pair in the JSONObject.
-     *
-     * @param key   A key string.
-     * @param value A boolean which is the value.
-     * @return this.
-     * @throws JSONException If the key is null.
-     */
-    public LOGJSONObject put(String key, boolean value) throws JSONException {
-        this.put(key, value ? Boolean.TRUE : Boolean.FALSE);
-        return this;
-    }
-
-
-    /**
-     * Put a key/value pair in the JSONObject, where the value will be a
-     * JSONArray which is produced from a Collection.
-     *
-     * @param key   A key string.
-     * @param value A Collection value.
-     * @return this.
-     * @throws JSONException
-     */
-    public LOGJSONObject put(String key, Collection<Object> value) throws JSONException {
-        this.put(key, new JSONArray(value));
-        return this;
-    }
-
-
     /**
      * Put a key/double pair in the JSONObject.
      *
@@ -1124,12 +856,11 @@ public class LOGJSONObject {
      * @return this.
      * @throws JSONException If the key is null or if the number is invalid.
      */
-    public LOGJSONObject put(String key, double value) throws JSONException {
+    public LOGJSONObject put(String key, double value) {
         this.put(key, new Double(value));
         return this;
     }
 
-
     /**
      * Put a key/int pair in the JSONObject.
      *
@@ -1138,12 +869,11 @@ public class LOGJSONObject {
      * @return this.
      * @throws JSONException If the key is null.
      */
-    public LOGJSONObject put(String key, int value) throws JSONException {
+    public LOGJSONObject put(String key, int value) {
         this.put(key, new Integer(value));
         return this;
     }
 
-
     /**
      * Put a key/long pair in the JSONObject.
      *
@@ -1152,27 +882,11 @@ public class LOGJSONObject {
      * @return this.
      * @throws JSONException If the key is null.
      */
-    public LOGJSONObject put(String key, long value) throws JSONException {
+    public LOGJSONObject put(String key, long value) {
         this.put(key, new Long(value));
         return this;
     }
 
-
-    /**
-     * Put a key/value pair in the JSONObject, where the value will be a
-     * JSONObject which is produced from a Map.
-     *
-     * @param key   A key string.
-     * @param value A Map value.
-     * @return this.
-     * @throws JSONException
-     */
-    public LOGJSONObject put(String key, Map<String, Object> value) throws JSONException {
-        this.put(key, new LOGJSONObject(value));
-        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.
@@ -1185,7 +899,7 @@ public class LOGJSONObject {
      * @throws JSONException If the value is non-finite number
      *                       or if the key is null.
      */
-    public LOGJSONObject put(String key, Object value) throws JSONException {
+    public LOGJSONObject put(String key, Object value) {
         String pooled;
         if (key == null) {
             throw new JSONException("Null key.");
@@ -1194,8 +908,8 @@ public class LOGJSONObject {
             testValidity(value);
             pooled = (String) keyPool.get(key);
             if (pooled == null) {
-                if (keyPool.size() >= keyPoolSize) {
-                    keyPool = new LinkedHashMap<String, Object>(keyPoolSize);
+                if (keyPool.size() >= KEY_POOL_SIZE) {
+                    keyPool = new LinkedHashMap<>(KEY_POOL_SIZE);
                 }
                 keyPool.put(key, key);
             } else {
@@ -1208,7 +922,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
@@ -1219,7 +932,7 @@ public class LOGJSONObject {
      * @return his.
      * @throws JSONException if the key is a duplicate
      */
-    public LOGJSONObject putOnce(String key, Object value) throws JSONException {
+    public LOGJSONObject putOnce(String key, Object value) {
         if (key != null && value != null) {
             if (this.opt(key) != null) {
                 throw new JSONException("Duplicate key \"" + key + "\"");
@@ -1229,26 +942,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.
-     *
-     * @param key   A key string.
-     * @param value An object which is the value. It should be of one of these
-     *              types: Boolean, Double, Integer, JSONArray, JSONObject, Long, String,
-     *              or the JSONObject.NULL object.
-     * @return this.
-     * @throws JSONException If the value is a non-finite number.
-     */
-    public LOGJSONObject putOpt(String key, Object value) throws JSONException {
-        if (key != null && value != null) {
-            this.put(key, value);
-        }
-        return this;
-    }
-
-
     /**
      * Produce a string in double quotes with backslash sequences in all the
      * right places. A backslash will be inserted within </, producing <\/,
@@ -1315,7 +1008,7 @@ public class LOGJSONObject {
                     break;
                 default:
                     if (c < ' ' || (c >= '\u0080' && c < '\u00a0')
-                            || (c >= '\u2000' && c < '\u2100')) {
+                        || (c >= '\u2000' && c < '\u2100')) {
                         w.write("\\u");
                         hhhh = Integer.toHexString(c);
                         w.write("0000", 0, 4 - hhhh.length());
@@ -1349,16 +1042,16 @@ public class LOGJSONObject {
      */
     public static Object stringToValue(String string) {
         Double d;
-        if (string.equals("")) {
+        if ("".equals(string)) {
             return string;
         }
-        if (string.equalsIgnoreCase("true")) {
+        if ("true".equalsIgnoreCase(string)) {
             return Boolean.TRUE;
         }
-        if (string.equalsIgnoreCase("false")) {
+        if ("false".equalsIgnoreCase(string)) {
             return Boolean.FALSE;
         }
-        if (string.equalsIgnoreCase("null")) {
+        if ("null".equalsIgnoreCase(string)) {
             return LOGJSONObject.NULL;
         }
 
@@ -1373,16 +1066,16 @@ public class LOGJSONObject {
         char b = string.charAt(0);
         if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') {
             try {
-                if (string.indexOf('.') > -1 ||
-                        string.indexOf('e') > -1 || string.indexOf('E') > -1) {
+                if (string.indexOf('.') > -1 || string.indexOf('e') > -1
+                    || string.indexOf('E') > -1) {
                     d = Double.valueOf(string);
                     if (!d.isInfinite() && !d.isNaN()) {
                         return d;
                     }
                 } else {
                     Long myLong = new Long(string);
-                    if (myLong.longValue() == myLong.intValue()) {
-                        return new Integer(myLong.intValue());
+                    if (myLong == myLong.intValue()) {
+                        return myLong.intValue();
                     } else {
                         return myLong;
                     }
@@ -1394,7 +1087,6 @@ public class LOGJSONObject {
         return string;
     }
 
-
     /**
      * Throw an exception if the object is a NaN or infinite number.
      *
@@ -1406,18 +1098,15 @@ public class LOGJSONObject {
             if (o instanceof Double) {
                 if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
                     throw new JSONException(
-                            "JSON does not allow non-finite numbers.");
-                }
-            } else if (o instanceof Float) {
-                if (((Float) o).isInfinite() || ((Float) o).isNaN()) {
-                    throw new JSONException(
-                            "JSON does not allow non-finite numbers.");
+                        "JSON does not allow non-finite numbers.");
                 }
+            } else if (o instanceof Float && (((Float) o).isInfinite() || ((Float) o).isNaN())) {
+                throw new JSONException(
+                    "JSON does not allow non-finite numbers.");
             }
         }
     }
 
-
     /**
      * Produce a JSONArray containing the values of the members of this
      * JSONObject.
@@ -1427,7 +1116,7 @@ public class LOGJSONObject {
      * @return A JSONArray of values.
      * @throws JSONException If any of the values are non-finite numbers.
      */
-    public JSONArray toJSONArray(JSONArray names) throws JSONException {
+    public JSONArray toJSONArray(JSONArray names) {
         if (names == null || names.length() == 0) {
             return null;
         }
@@ -1459,7 +1148,6 @@ public class LOGJSONObject {
         }
     }
 
-
     /**
      * Make a prettyprinted JSON text of this JSONObject.
      * <p>
@@ -1473,7 +1161,7 @@ public class LOGJSONObject {
      * with <code>}</code>&nbsp;<small>(right brace)</small>.
      * @throws JSONException If the object contains an invalid number.
      */
-    public String toString(int indentFactor) throws JSONException {
+    public String toString(int indentFactor) {
         StringWriter w = new StringWriter();
         synchronized (w.getBuffer()) {
             return this.write(w, indentFactor, 0).toString();
@@ -1503,27 +1191,27 @@ public class LOGJSONObject {
      * @throws JSONException If the value is or contains an invalid number.
      */
     @SuppressWarnings("unchecked")
-    public static String valueToString(Object value) throws JSONException {
+    public static String valueToString(Object value) {
         if (value == null) {
             return "null";
         }
         if (value instanceof JSONString) {
-            Object object;
+            String object;
             try {
                 object = ((JSONString) value).toJSONString();
             } catch (Exception e) {
                 throw new JSONException(e);
             }
-            if (object instanceof String) {
-                return (String) object;
+            if (object != null) {
+                return object;
             }
             throw new JSONException("Bad value from toJSONString: " + object);
         }
         if (value instanceof Number) {
             return numberToString((Number) value);
         }
-        if (value instanceof Boolean || value instanceof LOGJSONObject ||
-                value instanceof JSONArray) {
+        if (value instanceof Boolean || value instanceof LOGJSONObject
+            || value instanceof JSONArray) {
             return value.toString();
         }
         if (value instanceof Map) {
@@ -1557,12 +1245,12 @@ public class LOGJSONObject {
                 return NULL;
             }
             if (object instanceof LOGJSONObject || object instanceof JSONArray ||
-                    NULL.equals(object) || object instanceof JSONString ||
-                    object instanceof Byte || object instanceof Character ||
-                    object instanceof Short || object instanceof Integer ||
-                    object instanceof Long || object instanceof Boolean ||
-                    object instanceof Float || object instanceof Double ||
-                    object instanceof String) {
+                NULL.equals(object) || object instanceof JSONString ||
+                object instanceof Byte || object instanceof Character ||
+                object instanceof Short || object instanceof Integer ||
+                object instanceof Long || object instanceof Boolean ||
+                object instanceof Float || object instanceof Double ||
+                object instanceof String) {
                 return object;
             }
 
@@ -1577,13 +1265,13 @@ public class LOGJSONObject {
             }
             Package objectPackage = object.getClass().getPackage();
             String objectPackageName = objectPackage != null
-                    ? objectPackage.getName()
-                    : "";
+                ? objectPackage.getName()
+                : "";
             if (
-                    objectPackageName.startsWith("java.") ||
-                            objectPackageName.startsWith("javax.") ||
-                            object.getClass().getClassLoader() == null
-                    ) {
+                objectPackageName.startsWith("java.") ||
+                    objectPackageName.startsWith("javax.") ||
+                    object.getClass().getClassLoader() == null
+            ) {
                 return object.toString();
             }
             return new LOGJSONObject(object);
@@ -1593,24 +1281,8 @@ public class LOGJSONObject {
         }
     }
 
-
-    /**
-     * 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 {
+    static Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws IOException {
         if (value == null) {
             writer.write("null");
         } else if (value instanceof LOGJSONObject) {
@@ -1620,8 +1292,7 @@ public class LOGJSONObject {
         } else if (value instanceof Map) {
             new LOGJSONObject((Map<String, Object>) value).write(writer, indentFactor, indent);
         } else if (value instanceof Collection) {
-            new JSONArray((Collection<Object>) value).write(writer, indentFactor,
-                    indent);
+            new JSONArray((Collection<Object>) value).write(writer, indentFactor, indent);
         } else if (value.getClass().isArray()) {
             new JSONArray(value).write(writer, indentFactor, indent);
         } else if (value instanceof Number) {
@@ -1642,7 +1313,7 @@ public class LOGJSONObject {
         return writer;
     }
 
-    static final void indent(Writer writer, int indent) throws IOException {
+    private static void indent(Writer writer, int indent) throws IOException {
         for (int i = 0; i < indent; i += 1) {
             writer.write(' ');
         }
@@ -1658,7 +1329,7 @@ public class LOGJSONObject {
      * @throws JSONException
      */
     Writer write(Writer writer, int indentFactor, int indent)
-            throws JSONException {
+        {
         try {
             boolean commanate = false;
             final int length = this.length();
@@ -1690,7 +1361,7 @@ public class LOGJSONObject {
                         writer.write(' ');
                     }
                     writeValue(writer, this.map.get(key), indentFactor,
-                            newindent);
+                        newindent);
                     commanate = true;
                 }
                 if (indentFactor > 0) {
index 3ba1a15..b48907f 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(), e);\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(), e);\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;
+
+    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");
+    }
+
+    /**
+     * 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 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("LogfileLoader.pruneRecords: " + e.getMessage(), e);
+            } finally {
+                db.release(conn);
+            }
+        }
+        return did1;
+    }
+
+    private long countRecords() {
+        long count = 0;
+        try (Connection conn = db.getConnection();
+            Statement stmt = conn.createStatement()) {
+            try (ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS")) {
+                if (rs.next()) {
+                    count = rs.getLong("COUNT");
+                }
+            } finally {
+                db.release(conn);
+            }
+        } catch (SQLException e) {
+            logger.error("LogfileLoader.countRecords: " + e.getMessage(), e);
+        }
+        return count;
+    }
+
+    private Map<Long, Long> getHistogram() {
+        Map<Long, Long> map = new HashMap<>();
+        try (Connection conn = db.getConnection();
+            Statement stmt = conn.createStatement()) {
+            logger.debug("  LOG_RECORD table histogram...");
+            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);
+                }
+            } finally {
+                db.release(conn);
+            }
+        } catch (SQLException e) {
+            logger.error("LogfileLoader.getHistogram: " + e.getMessage(), e);
+        }
+        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("LogfileLoader.initializeNextid, next ID is %d (%x)", nextId, nextId));
+        } catch (SQLException e) {
+            logger.error("LogfileLoader.initializeNextid: " + e.getMessage(), e);
+        } 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 8c67e71..c34e954 100644 (file)
 \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.util.Objects;\r
 import java.util.Properties;\r
 import java.util.TimerTask;\r
 \r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-\r
 /**\r
  * This class provides a {@link TimerTask} that purges old logfiles (older than the number of days specified by the\r
  * org.onap.dmaap.datarouter.provserver.logretention property).\r
@@ -50,9 +50,7 @@ public class PurgeLogDirTask extends TimerTask {
         Properties p = (new DB()).getProperties();\r
         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
-\r
         long n = 30;\r
         try {\r
             n = Long.parseLong(s);\r
@@ -67,15 +65,19 @@ public class PurgeLogDirTask extends TimerTask {
         try {\r
             File dir = new File(logdir);\r
             if (dir.exists()) {\r
-                long exptime = System.currentTimeMillis() - interval;\r
-                for (File logfile : dir.listFiles()) {\r
-                    if (logfile.lastModified() < exptime) {\r
-                        logfile.delete();\r
-                    }\r
-                }\r
+                purgeLogFiles(dir);\r
             }\r
         } catch (Exception e) {\r
             utilsLogger.error("Exception: " + e.getMessage(), e);\r
         }\r
     }\r
+\r
+    private void purgeLogFiles(File dir) {\r
+        long exptime = System.currentTimeMillis() - interval;\r
+        for (File logfile : Objects.requireNonNull(dir.listFiles())) {\r
+            if (logfile.lastModified() < exptime) {\r
+                logfile.delete();\r
+            }\r
+        }\r
+    }\r
 }\r
index ffed1a1..5813024 100644 (file)
@@ -28,7 +28,6 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;\r
 import java.net.InetAddress;\r
 import java.net.UnknownHostException;\r
-import java.util.Arrays;\r
 \r
 import org.onap.dmaap.datarouter.provisioning.BaseServlet;\r
 \r
@@ -39,7 +38,14 @@ 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
+    private static final String HTTPS = "https://";\r
+    private static String otherPod;\r
+\r
+    private URLUtilities() {\r
+    }\r
+\r
     /**\r
      * Generate the URL used to access a feed.\r
      *\r
@@ -47,7 +53,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateFeedURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/feed/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/feed/" + feedid;\r
     }\r
 \r
     /**\r
@@ -57,7 +63,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generatePublishURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/publish/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/publish/" + feedid;\r
     }\r
 \r
     /**\r
@@ -67,7 +73,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubscribeURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/subscribe/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/subscribe/" + feedid;\r
     }\r
 \r
     /**\r
@@ -77,7 +83,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateFeedLogURL(int feedid) {\r
-        return "https://" + BaseServlet.getProvName() + "/feedlog/" + feedid;\r
+        return HTTPS + BaseServlet.getProvName() + "/feedlog/" + feedid;\r
     }\r
 \r
     /**\r
@@ -87,7 +93,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubscriptionURL(int subid) {\r
-        return "https://" + BaseServlet.getProvName() + "/subs/" + subid;\r
+        return HTTPS + BaseServlet.getProvName() + "/subs/" + subid;\r
     }\r
 \r
     /**\r
@@ -97,7 +103,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generateSubLogURL(int subid) {\r
-        return "https://" + BaseServlet.getProvName() + "/sublog/" + subid;\r
+        return HTTPS + BaseServlet.getProvName() + "/sublog/" + subid;\r
     }\r
 \r
     /**\r
@@ -106,7 +112,7 @@ public class URLUtilities {
      * @return the URL\r
      */\r
     public static String generatePeerProvURL() {\r
-        return "https://" + getPeerPodName() + "/internal/prov";\r
+        return HTTPS + getPeerPodName() + "/internal/prov";\r
     }\r
 \r
     /**\r
@@ -117,11 +123,11 @@ public class URLUtilities {
     public static String generatePeerLogsURL() {\r
         //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.\r
         String peerPodUrl = getPeerPodName();\r
-        if (peerPodUrl == null || peerPodUrl.equals("")) {\r
+        if (peerPodUrl == null || "".equals(peerPodUrl)) {\r
             return "";\r
         }\r
 \r
-        return "https://" + peerPodUrl + "/internal/drlogs/";\r
+        return HTTPS + peerPodUrl + "/internal/drlogs/";\r
     }\r
 \r
     /**\r
@@ -130,24 +136,21 @@ public class URLUtilities {
      * @return the name\r
      */\r
     public static String getPeerPodName() {\r
-        if (other_pod == null) {\r
-            String this_pod = "";\r
+        if (otherPod == null) {\r
+            String thisPod;\r
             try {\r
-                this_pod = InetAddress.getLocalHost().getHostName();\r
-                System.out.println("this_pod: " + this_pod);\r
+                thisPod = InetAddress.getLocalHost().getHostName();\r
             } catch (UnknownHostException e) {\r
                 utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);\r
-                this_pod = "";\r
+                thisPod = "";\r
             }\r
-            System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));\r
             for (String pod : BaseServlet.getPods()) {\r
-                if (!pod.equals(this_pod)) {\r
-                    other_pod = pod;\r
+                if (!pod.equals(thisPod)) {\r
+                    otherPod = pod;\r
                 }\r
             }\r
         }\r
-        return other_pod;\r
+        return otherPod;\r
     }\r
 \r
-    private static String other_pod;\r
 }\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 e2076b9..42366dd 100644 (file)
@@ -47,6 +47,7 @@ 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);
index edf9ef5..5239b80 100644 (file)
@@ -44,6 +44,7 @@ import javax.servlet.http.HttpServletResponse;
 import ch.qos.logback.classic.spi.ILoggingEvent;
 import ch.qos.logback.core.read.ListAppender;
 import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -54,6 +55,7 @@ import org.mockito.Mock;
 import org.onap.dmaap.datarouter.provisioning.beans.Deleteable;
 import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
 import org.onap.dmaap.datarouter.provisioning.beans.LogRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
 import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
 import org.powermock.api.mockito.PowerMockito;
 import org.powermock.core.classloader.annotations.PrepareForTest;
@@ -276,6 +278,16 @@ public class InternalServletTest extends DrServletTestBase {
     verifyEnteringExitCalled(listAppender);
   }
 
+  @Test
+  public void Given_Request_Is_HTTP_DELETE_With_LogRollInterval_Api_In_Endpoint_Request_Succeeds() {
+    when(request.getPathInfo()).thenReturn("/api/LOGROLL_INTERVAL");
+    internalServlet.doDelete(request, response);
+    verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+    Parameters p1 = Parameters.getParameter("NODES");
+    Assert.assertEquals("{\"keyname\":\"NODES\",\"value\":\"dmaap-dr-node\"}", p1.asJSONObject().toString());
+    Assert.assertEquals("PARAM: keyname=NODES, value=dmaap-dr-node", p1.toString());
+  }
+
   @Test
   public void Given_Request_Is_HTTP_DELETE_With_Api_In_Endpoint_And_Delete_Fails_Then_Internal_Server_Error_Is_Generated()
       throws Exception {
@@ -332,8 +344,7 @@ public class InternalServletTest extends DrServletTestBase {
   }
 
   @Test
-  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
-      throws Exception {
+  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Header_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() {
     when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
     when(request.getPathInfo()).thenReturn("/logs/");
     internalServlet.doPost(request, response);
@@ -341,8 +352,7 @@ public class InternalServletTest extends DrServletTestBase {
   }
 
   @Test
-  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Encoding_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated()
-      throws Exception {
+  public void Given_Request_Is_HTTP_POST_To_Logs_And_Content_Encoding_Is_Not_Supported_Type_Then_Unsupported_Media_Type_Response_Is_Generated() {
     when(request.getHeader("Content-Encoding")).thenReturn("not-supported");
     when(request.getPathInfo()).thenReturn("/logs/");
     internalServlet.doPost(request, response);
@@ -364,8 +374,7 @@ public class InternalServletTest extends DrServletTestBase {
   }
 
   @Test
-  public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated()
-      throws Exception {
+  public void Given_Request_Is_HTTP_POST_To_Drlogs_And_Then_Unsupported_Media_Type_Response_Is_Generated() {
     when(request.getHeader("Content-Type")).thenReturn("stub_contentType");
     when(request.getPathInfo()).thenReturn("/drlogs/");
     internalServlet.doPost(request, response);
@@ -383,6 +392,13 @@ public class InternalServletTest extends DrServletTestBase {
     verify(response).setStatus(eq(HttpServletResponse.SC_OK));
   }
 
+  @Test
+  public void Given_Request_Is_HTTP_POST_To_Api_And_Request_Succeeds() {
+    when(request.getPathInfo()).thenReturn("/api/NEW_PARAM?val=blah");
+    internalServlet.doPost(request, response);
+    verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+  }
+
   @Test
   public void Given_Request_Is_HTTP_POST_With_Incorrect_Endpoint_Then_Not_Found_Error_Is_Generated()
       throws Exception {
index 8bbf231..8c48d70 100755 (executable)
@@ -34,9 +34,6 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.net.InetAddress;
 import java.net.UnknownHostException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
@@ -81,7 +78,6 @@ public class SynchronizerTaskTest {
     private CloseableHttpResponse response;
 
     private SynchronizerTask synchronizerTask;
-    private ExecutorService executorService;
 
     private static EntityManagerFactory emf;
     private static EntityManager em;
@@ -116,15 +112,10 @@ public class SynchronizerTaskTest {
 
         synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
         doReturn(2).when(synchronizerTask).lookupState();
-
-        executorService = Executors.newCachedThreadPool();
-        executorService.execute(synchronizerTask);
     }
 
     @After
-    public void tearDown() throws InterruptedException {
-        executorService.shutdown();
-        executorService.awaitTermination(2, TimeUnit.SECONDS);
+    public void tearDown() {
     }
 
     @Test
@@ -193,6 +184,7 @@ public class SynchronizerTaskTest {
         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();
     }
 
 
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRouteTest.java
new file mode 100644 (file)
index 0000000..7ef52ff
--- /dev/null
@@ -0,0 +1,90 @@
+/*-
+ * ============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.provisioning.beans;
+
+import java.sql.SQLException;
+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.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class EgressRouteTest {
+
+    private EgressRoute egressRoute;
+
+    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();
+        egressRoute = new EgressRoute(2, 1);
+    }
+
+    @Test
+    public void Verify_NetworkRoute_Is_Added_Successfully() throws SQLException {
+        Assert.assertEquals(1, EgressRoute.getAllEgressRoutes().size());
+        egressRoute.doInsert(db.getConnection());
+        Assert.assertEquals(2, EgressRoute.getAllEgressRoutes().size());
+        egressRoute.doDelete(db.getConnection());
+    }
+
+    @Test
+    public void Verify_NetworkRoute_Is_Removed_Successfully() throws SQLException {
+        Assert.assertEquals(1, EgressRoute.getAllEgressRoutes().size());
+        EgressRoute egressRoute = new EgressRoute(1, 1);
+        egressRoute.doDelete(db.getConnection());
+        Assert.assertEquals(0, EgressRoute.getAllEgressRoutes().size());
+    }
+
+    @Test
+    public void Verify_NetworkRoute_Is_Updated_Successfully() throws SQLException {
+        EgressRoute egressRoute = new EgressRoute(1, 1);
+        EgressRoute egressRoute1 = new EgressRoute(1, 1);
+        Assert.assertEquals(egressRoute.hashCode(), egressRoute1.hashCode());
+        Assert.assertEquals(egressRoute, egressRoute1);
+        Assert.assertEquals(egressRoute.toString(), egressRoute1.toString());
+    }
+}
\ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRouteTest.java
new file mode 100644 (file)
index 0000000..df786b5
--- /dev/null
@@ -0,0 +1,96 @@
+/*-
+ * ============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.provisioning.beans;
+
+import java.sql.SQLException;
+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.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class NetworkRouteTest {
+
+    private NetworkRoute networkRoute;
+
+    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();
+        networkRoute = new NetworkRoute("node01.","node03.","node02.");
+    }
+
+    @Test
+    public void Verify_NetworkRoute_Is_Added_Successfully() throws SQLException {
+        Assert.assertEquals(1, NetworkRoute.getAllNetworkRoutes().size());
+        networkRoute.doInsert(db.getConnection());
+        Assert.assertEquals(2, NetworkRoute.getAllNetworkRoutes().size());
+        networkRoute.doDelete(db.getConnection());
+    }
+
+    @Test
+    public void Verify_NetworkRoute_Is_Removed_Successfully() throws SQLException {
+        Assert.assertEquals(1, NetworkRoute.getAllNetworkRoutes().size());
+        NetworkRoute networkRoute = new NetworkRoute("stub_from.", "stub_to.");
+        networkRoute.doDelete(db.getConnection());
+        Assert.assertEquals(0, NetworkRoute.getAllNetworkRoutes().size());
+    }
+
+    @Test
+    public void Verify_NetworkRoute_Is_Updated_Successfully() throws SQLException {
+        NetworkRoute networkRoute = new NetworkRoute("stub_from.", "stub_to.", "node02.");
+        networkRoute.doUpdate(db.getConnection());
+        //Assert.assertTrue(NetworkRoute.getAllNetworkRoutes().contains(networkRoute));
+        for (NetworkRoute net :
+            NetworkRoute.getAllNetworkRoutes()) {
+            Assert.assertEquals(5, net.getVianode());
+        }
+        NetworkRoute networkRoute1 = new NetworkRoute("stub_from.", "stub_to.", "node02.");
+        Assert.assertEquals(networkRoute.hashCode(), networkRoute1.hashCode());
+        Assert.assertEquals(networkRoute, networkRoute1);
+        Assert.assertEquals(networkRoute.toString(), networkRoute1.toString());
+    }
+}
\ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/DbTest.java
new file mode 100644 (file)
index 0000000..056469a
--- /dev/null
@@ -0,0 +1,61 @@
+/*-
+ * ============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.provisioning.utils;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class DbTest {
+    private static EntityManagerFactory emf;
+    private static EntityManager em;
+
+    private DB db = new DB();
+
+    @BeforeClass
+    public static void init() {
+        emf = Persistence.createEntityManagerFactory("db-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();
+    }
+
+    @Test
+    public void Verify_DB_Is_Initialised_Successfully() {
+        Assert.assertTrue(db.runRetroFits());
+    }
+
+}
index 4dd1b47..ae81f15 100755 (executable)
@@ -24,6 +24,7 @@
 package org.onap.dmaap.datarouter.provisioning.utils;
 
 import java.io.CharArrayWriter;
+import java.io.IOException;
 import java.io.Writer;
 import org.json.JSONArray;
 import org.json.JSONTokener;
@@ -50,8 +51,7 @@ public class LOGJSONObjectTest {
   }
 
   @Test
-  public void Construct_JSONObject_From_A_Subset_Of_Values_From_Another_JSONObject()
-      throws Exception {
+  public void Construct_JSONObject_From_A_Subset_Of_Values_From_Another_JSONObject()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key1", "value1");
     map.put("key2", "value2");
@@ -63,48 +63,41 @@ public class LOGJSONObjectTest {
   }
 
   @Test
-  public void Construct_JSONObject_From_A_JSONTokener()
-      throws Exception {
+  public void Construct_JSONObject_From_A_JSONTokener()  {
     JSONTokener x = new JSONTokener("{\"key1\":\"value1\",\"key3\":\"value3\"}");
     LOGJSONObject logJObject = new LOGJSONObject(x);
     assertThat(logJObject.toString(), is("{\"key1\":\"value1\",\"key3\":\"value3\"}"));
   }
 
   @Test
-  public void Construct_JSONObject_From_A_Bean_Object_And_Populate_From_Its_Getters_And_Setters()
-      throws Exception {
+  public void Construct_JSONObject_From_A_Bean_Object_And_Populate_From_Its_Getters_And_Setters()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key1", "value1");
     map.put("key2", "value2");
     map.put("key3", "value3");
-    Object bean = map;
-    LOGJSONObject logJObject = new LOGJSONObject(bean);
+    LOGJSONObject logJObject = new LOGJSONObject((Object) map);
     assertThat(logJObject.toString(), is("{\"empty\":false}"));
   }
 
   @Test
-  public void Given_Method_Is_Accumulate_And_Value_Is_Valid_Put_Value_Into_New_JSONArray()
-      throws Exception {
+  public void Given_Method_Is_Accumulate_And_Value_Is_Valid_Put_Value_Into_New_JSONArray()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key", 3);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     logJObject.accumulate(s, null);
     assertThat(logJObject.get("key").toString(), is("[3,null]"));
   }
 
   @Test
-  public void Given_Method_Is_Accumulate_And_Value_Is_Null_Dont_Add_Key_Value_Pair()
-      throws Exception {
+  public void Given_Method_Is_Accumulate_And_Value_Is_Null_Dont_Add_Key_Value_Pair()  {
     String s = "key";
     logJO.accumulate(s, null);
     assertThat(logJO.has("key"), is(false));
   }
 
   @Test
-  public void Given_Method_Is_Append_And_Value_Is_Null_Append_New_Value()
-      throws Exception {
+  public void Given_Method_Is_Append_And_Value_Is_Null_Append_New_Value()  {
     String s = "key";
     double d = 2.0;
     logJO.append(s, d);
@@ -113,417 +106,334 @@ public class LOGJSONObjectTest {
 
 
   @Test
-  public void Given_Method_Is_DoubleToString_And_Value_Is_NaN_Return_Null()
-      throws Exception {
+  public void Given_Method_Is_DoubleToString_And_Value_Is_NaN_Return_Null()  {
     double d = 2.0;
-    assertThat(logJO.doubleToString(d), is("2"));
+    assertThat(LOGJSONObject.doubleToString(d), is("2"));
   }
 
 
   @Test
-  public void Given_Method_Is_GetBoolean_And_Value_Is_False_Return_False()
-      throws Exception {
+  public void Given_Method_Is_GetBoolean_And_Value_Is_False_Return_False()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key", false);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getBoolean(s), is(false));
   }
 
   @Test
-  public void Given_Method_Is_GetBoolean_And_Value_Is_True_Return_True()
-      throws Exception {
+  public void Given_Method_Is_GetBoolean_And_Value_Is_True_Return_True()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key", true);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getBoolean(s), is(true));
   }
 
   @Test
-  public void Given_Method_Is_GetDouble_And_Value_Is_A_Double_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_GetDouble_And_Value_Is_A_Double_Return_Value()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key", 2.0);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getDouble(s), is(2.0));
   }
 
   @Test
-  public void Given_Method_Is_GetInt_And_Value_Is_An_Int_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_GetInt_And_Value_Is_An_Int_Return_Value()  {
     Map<String, Object> map = new HashMap<>();
     map.put("key", 3);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getInt(s), is(3));
   }
 
   @Test
-  public void Given_Method_Is_GetJSONArray_And_Value_Is_A_JSONArray_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_GetJSONArray_And_Value_Is_A_JSONArray_Return_Value()  {
     JSONArray jA = new JSONArray();
     Map<String, Object> map = new HashMap<>();
     map.put("key", jA);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getJSONArray(s), is(jA));
   }
 
   @Test
-  public void Given_Method_Is_GetJSONObject_And_Value_Is_A_JSONObject_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_GetJSONObject_And_Value_Is_A_JSONObject_Return_Value()  {
     LOGJSONObject logJObj = new LOGJSONObject();
     logJObj.put("stub_key", 1);
     Map<String, Object> map = new HashMap<>();
     map.put("key", logJObj);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getJSONObject(s), is(logJObj));
   }
 
   @Test
-  public void Given_Method_Is_GetLong_And_Value_Is_A_Long_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_GetLong_And_Value_Is_A_Long_Return_Value() {
     long l = 5;
     Map<String, Object> map = new HashMap<>();
     map.put("key", l);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getLong(s), is(5L));
   }
 
   @Test
-  public void Given_Method_Is_getNames_And_Value_Is_A_LOGJSONObject_Return_StringArray()
-      throws Exception {
+  public void Given_Method_Is_getNames_And_Value_Is_A_LOGJSONObject_Return_StringArray() {
     LOGJSONObject logJObj = new LOGJSONObject();
     logJObj.put("name1", "elyk");
     String[] sArray = new String[logJObj.length()];
     sArray[0] = "name1";
-    LOGJSONObject logJObject = new LOGJSONObject();
-
-    assertThat(logJObject.getNames(logJObj), is(sArray));
+    assertThat(LOGJSONObject.getNames(logJObj), is(sArray));
   }
 
   @Test
-  public void Given_Method_Is_GetString_And_Value_Is_A_String_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_GetString_And_Value_Is_A_String_Return_Value() {
     String val = "value";
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.getString(s), is("value"));
   }
 
   @Test
-  public void Given_Method_Is_Increment_And_Value_Is_Null_Put_Defualt_Value()
-      throws Exception {
+  public void Given_Method_Is_Increment_And_Value_Is_Null_Put_Defualt_Value() {
     Map<String, Object> mapResult = new HashMap<>();
     mapResult.put("key", 1);
     LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
     String val = null;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     logJObject.increment(s);
     assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
   }
 
   @Test
-  public void Given_Method_Is_Increment_And_Value_Is_An_Int_Put_Value_Plus_One()
-      throws Exception {
+  public void Given_Method_Is_Increment_And_Value_Is_An_Int_Put_Value_Plus_One() {
     Map<String, Object> mapResult = new HashMap<>();
     mapResult.put("key", 3);
     LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
     int val = 2;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     logJObject.increment(s);
     assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
   }
 
   @Test
-  public void Given_Method_Is_Increment_And_Value_Is_A_Long_Put_Value_Plus_One()
-      throws Exception {
+  public void Given_Method_Is_Increment_And_Value_Is_A_Long_Put_Value_Plus_One() {
     Map<String, Object> mapResult = new HashMap<>();
     mapResult.put("key", 4L);
     LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
     long val = 3;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     logJObject.increment(s);
     assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
   }
 
   @Test
-  public void Given_Method_Is_Increment_And_Value_Is_A_Double_Put_Value_Plus_One()
-      throws Exception {
+  public void Given_Method_Is_Increment_And_Value_Is_A_Double_Put_Value_Plus_One() {
     Map<String, Object> mapResult = new HashMap<>();
     mapResult.put("key", 5.0);
     LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
     double val = 4.0;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     logJObject.increment(s);
     assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
   }
 
   @Test
-  public void Given_Method_Is_Increment_And_Value_Is_A_Float_Put_Value_Plus_One()
-      throws Exception {
+  public void Given_Method_Is_Increment_And_Value_Is_A_Float_Put_Value_Plus_One() {
     Map<String, Object> mapResult = new HashMap<>();
     mapResult.put("key", 5.0);
     LOGJSONObject logJObjectResult = new LOGJSONObject(mapResult);
-
     float val = 4.0f;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     logJObject.increment(s);
     assertThat(logJObject.get("key"), is(logJObjectResult.get("key")));
   }
 
   @Test
-  public void Given_Method_Is_Names_And_Object_Contains_Keys_Put_Keys_Into_New_JSONArray()
-      throws Exception {
+  public void Given_Method_Is_Names_And_Object_Contains_Keys_Put_Keys_Into_New_JSONArray() {
     JSONArray ja = new JSONArray();
     ja.put("key");
-
     String val = "value";
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
-    String s = "key";
     assertThat(logJObject.names().get(0), is(ja.get(0)));
   }
 
   @Test
-  public void Given_Method_Is_NumberToString_And_Number_is_Not_Null_Return_Reformatted_Number_As_String()
-      throws Exception {
+  public void Given_Method_Is_NumberToString_And_Number_is_Not_Null_Return_Reformatted_Number_As_String() {
     Number num = 3.0;
-
     String val = "value";
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.numberToString(num), is("3"));
   }
 
   @Test
-  public void Given_Method_Is_OptBoolean_And_Value_is_Boolean_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_OptBoolean_And_Value_is_Boolean_Return_Value() {
     boolean val = true;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optBoolean(s, false), is(true));
   }
 
   @Test
-  public void Given_Method_Is_OptBoolean_And_Value_is_Not_Boolean_Return_Default_Value()
-      throws Exception {
+  public void Given_Method_Is_OptBoolean_And_Value_is_Not_Boolean_Return_Default_Value() {
     String val = "not_boolean";
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optBoolean(s, false), is(false));
   }
 
   @Test
-  public void Given_Method_Is_OptDouble_And_Value_is_Double_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_OptDouble_And_Value_is_Double_Return_Value() {
     double val = 2.0;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optDouble(s, 0.0), is(2.0));
   }
 
   @Test
-  public void Given_Method_Is_OptDouble_And_Value_is_Not_Double_Return_Default_Value()
-      throws Exception {
+  public void Given_Method_Is_OptDouble_And_Value_is_Not_Double_Return_Default_Value() {
     String val = "not_double";
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optDouble(s, 0.0), is(0.0));
   }
 
   @Test
-  public void Given_Method_Is_OptInt_And_Value_is_Int_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_OptInt_And_Value_is_Int_Return_Value() {
     int val = 1;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optInt(s, 0), is(1));
   }
 
   @Test
-  public void Given_Method_Is_OptInt_And_Value_Is_Null_Return_Default_Value()
-      throws Exception {
+  public void Given_Method_Is_OptInt_And_Value_Is_Null_Return_Default_Value() {
     Map<String, Object> map = new HashMap<>();
     map.put("key", null);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optInt(s, 0), is(0));
   }
 
   @Test
-  public void Given_Method_Is_OptLong_And_Value_is_Long_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_OptLong_And_Value_is_Long_Return_Value() {
     long val = 4;
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optLong(s, 0), is(4L));
   }
 
   @Test
-  public void Given_Method_Is_OptLong_And_Value_is_Not_Long_Return_Default_Value()
-      throws Exception {
+  public void Given_Method_Is_OptLong_And_Value_is_Not_Long_Return_Default_Value() {
     Map<String, Object> map = new HashMap<>();
     map.put("key", null);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optLong(s, 0), is(0L));
   }
 
   @Test
-  public void Given_Method_Is_OptString_And_Value_is_String_Return_Value()
-      throws Exception {
+  public void Given_Method_Is_OptString_And_Value_is_String_Return_Value() {
     String val = "value";
     Map<String, Object> map = new HashMap<>();
     map.put("key", val);
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.optString(s, "default_value"), is("value"));
   }
 
   @Test
-  public void Given_Method_Is_putOnce_And_KeyValuePair_Does_Not_Exist_In_logJObject_Put_KeyValuePair_Into_logJObject()
-      throws Exception {
+  public void Given_Method_Is_putOnce_And_KeyValuePair_Does_Not_Exist_In_logJObject_Put_KeyValuePair_Into_logJObject() {
     String val = "value";
     Map<String, Object> map = new HashMap<>();
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     String s = "key";
     assertThat(logJObject.putOnce(s, val).get("key"), is("value"));
   }
 
   @Test
-  public void Given_Method_Is_StringToValue_And_Value_Is_Number_Return_Number()
-      throws Exception {
+  public void Given_Method_Is_StringToValue_And_Value_Is_Number_Return_Number() {
     String val = "312";
     Map<String, Object> map = new HashMap<>();
-    LOGJSONObject logJObject = new LOGJSONObject(map);
-
-    assertThat(logJObject.stringToValue(val), is(312));
+    assertThat(LOGJSONObject.stringToValue(val), is(312));
   }
 
   @Test
-  public void Given_Method_Is_ToJSONArray_And_KeyValue_Exists_Return_Value_Array()
-      throws Exception {
+  public void Given_Method_Is_ToJSONArray_And_KeyValue_Exists_Return_Value_Array() {
     JSONArray names = new JSONArray();
     Map<String, Object> map = new HashMap<>();
     map.put("name", "value");
     names.put("name");
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     assertThat(logJObject.toJSONArray(names).get(0), is("value"));
   }
 
   @Test
-  public void Given_Method_Is_ValueToString_And_Value_Is_JSONArray_Return_Value_To_String()
-      throws Exception {
+  public void Given_Method_Is_ValueToString_And_Value_Is_JSONArray_Return_Value_To_String() {
     JSONArray val = new JSONArray();
-    Map<String, Object> map = new HashMap<>();
-    map.put("key", "value");
     val.put("value");
-    LOGJSONObject logJObject = new LOGJSONObject(map);
-
-    assertThat(logJObject.valueToString(val), is("[\"value\"]"));
+    assertThat(LOGJSONObject.valueToString(val), is("[\"value\"]"));
   }
 
   @Test
-  public void Given_Method_Is_writeValue_And_Value_IS_Not_Null_Return_Writer_With_Value()
-      throws Exception {
+  public void Given_Method_Is_writeValue_And_Value_IS_Not_Null_Return_Writer_With_Value() throws IOException {
     Writer writer = new CharArrayWriter();
     String val = "value";
-    Map<String, Object> map = new HashMap<>();
-    map.put("key", "value");
-    LOGJSONObject logJObject = new LOGJSONObject(map);
-
-    assertThat(logJObject.writeValue(writer, val, 3, 1).toString(), is("\"value\""));
+    assertThat(LOGJSONObject.writeValue(writer, val, 3, 1).toString(), is("\"value\""));
   }
 
   @Test
-  public void Given_Method_Is_write_And_Length_Of_logJObject_Is_One_Write_Value_With_Indent()
-      throws Exception {
+  public void Given_Method_Is_write_And_Length_Of_logJObject_Is_One_Write_Value_With_Indent() {
     Writer writer = new CharArrayWriter();
-    String val = "value";
     Map<String, Object> map = new HashMap<>();
     map.put("key", "value");
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     assertThat(logJObject.write(writer, 3, 1).toString(), is("{\"key\": \"value\"}"));
   }
 
   @Test
-  public void Given_Method_Is_write_And_Length_Of_logJObject_Is_Not_One_Or_Zero_Write_Value_With_New_Indent()
-      throws Exception {
+  public void Given_Method_Is_write_And_Length_Of_logJObject_Is_Not_One_Or_Zero_Write_Value_With_New_Indent() {
     Writer writer = new CharArrayWriter();
-    String val = "value";
     Map<String, Object> map = new HashMap<>();
     map.put("key", "value");
     map.put("key1", "value1");
     LOGJSONObject logJObject = new LOGJSONObject(map);
-
     assertThat(logJObject.write(writer, 3, 1).toString(), is("{\n    \"key1\": \"value1\",\n    \"key\": \"value\"\n }"));
   }
 }
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;
     }
 }
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTaskTest.java
new file mode 100644 (file)
index 0000000..604b4c0
--- /dev/null
@@ -0,0 +1,87 @@
+/*-
+ * ============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.provisioning.utils;
+
+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.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+public class PurgeLogDirTaskTest {
+
+    private static EntityManagerFactory emf;
+    private static EntityManager em;
+    private PurgeLogDirTask purgeLogDirTask = new PurgeLogDirTask();
+    private File testLog;
+
+    @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() {
+        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();
+    }
+
+    @Test
+    public void Verify_Logs_Are_Purged() {
+        purgeLogDirTask.run();
+    }
+
+    private void prepFile(File logFile) {
+        try (FileWriter fileWriter = new FileWriter(logFile)) {
+            fileWriter.write("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");
+        }
+        catch (IOException e){
+            System.out.println(e.getMessage());
+        }
+    }
+}
index 83813e2..2cb798a 100755 (executable)
 
         </properties>
     </persistence-unit>
+    <persistence-unit name="db-unit-tests" transaction-type="RESOURCE_LOCAL">
+        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
+        <properties>
+            <!-- Configuring JDBC properties -->
+            <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1"/>
+            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
+            <!-- Hibernate properties -->
+            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
+            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+            <property name="hibernate.format_sql" value="false"/>
+            <property name="hibernate.show_sql" value="true"/>
+
+        </properties>
+    </persistence-unit>
 </persistence>
index a811847..74b6324 100755 (executable)
@@ -180,10 +180,10 @@ INSERT INTO FEEDS(FEEDID, GROUPID, NAME, VERSION, DESCRIPTION, BUSINESS_DESCRIPT
 VALUES (3, 1,'DeleteableAafFeed','v0.1', 'AAF Feed3 for testing', 'AAF Feed3 for testing', 'auth_class', 'pub','self_link','publish_link','subscribe_link','log_link','*');
 
 insert into INGRESS_ROUTES(SEQUENCE, FEEDID , USERID, SUBNET, NODESET)
-VALUES (1,1,'user',null,2);
+VALUES (1,1,'user','172.100.0.0/25',2);
 
 insert into INGRESS_ROUTES(SEQUENCE, FEEDID , USERID, SUBNET, NODESET)
-VALUES (2,1,'user',null,2);
+VALUES (2,1,'user2',null,2);
 
 insert into NODESETS(SETID, NODEID)
 VALUES (1,1);
index 9c63aea..991fadc 100755 (executable)
@@ -27,7 +27,8 @@ 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.dbscripts             = src/test/resources
 org.onap.dmaap.datarouter.provserver.localhost             = 127.0.0.1
 org.onap.dmaap.datarouter.provserver.passwordencryption    = PasswordEncryptionKey#@$%^&1234#
 
diff --git a/datarouter-prov/src/test/resources/sql_init_01.sql b/datarouter-prov/src/test/resources/sql_init_01.sql
new file mode 100755 (executable)
index 0000000..1ac74a0
--- /dev/null
@@ -0,0 +1,146 @@
+CREATE TABLE FEEDS (
+    FEEDID         INT UNSIGNED NOT NULL PRIMARY KEY,
+    GROUPID        INT(10) UNSIGNED NOT NULL DEFAULT 0,
+    NAME           VARCHAR(256) NOT NULL,
+    VERSION        VARCHAR(20) NULL,
+    DESCRIPTION    VARCHAR(1000),
+    BUSINESS_DESCRIPTION VARCHAR(1000) DEFAULT NULL,
+    AUTH_CLASS     VARCHAR(32) NOT NULL,
+    PUBLISHER      VARCHAR(8) NOT NULL,
+    SELF_LINK      VARCHAR(256),
+    PUBLISH_LINK   VARCHAR(256),
+    SUBSCRIBE_LINK VARCHAR(256),
+    LOG_LINK       VARCHAR(256),
+    DELETED        BOOLEAN DEFAULT FALSE,
+    LAST_MOD       TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+    SUSPENDED      BOOLEAN DEFAULT FALSE,
+    CREATED_DATE   TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+    AAF_INSTANCE   VARCHAR(256)
+);
+
+CREATE TABLE FEED_ENDPOINT_IDS (
+    FEEDID        INT UNSIGNED NOT NULL,
+    USERID        VARCHAR(60) NOT NULL,
+    PASSWORD      VARCHAR(100) NOT NULL
+);
+
+CREATE TABLE FEED_ENDPOINT_ADDRS (
+    FEEDID        INT UNSIGNED NOT NULL,
+    ADDR          VARCHAR(44) NOT NULL
+);
+
+CREATE TABLE SUBSCRIPTIONS (
+    SUBID                       INT UNSIGNED NOT NULL PRIMARY KEY,
+    FEEDID                      INT UNSIGNED NOT NULL,
+    GROUPID                     INT(10) UNSIGNED NOT NULL DEFAULT 0,
+    DELIVERY_URL                VARCHAR(256),
+    FOLLOW_REDIRECTS            TINYINT(1) NOT NULL DEFAULT 0,
+    DELIVERY_USER               VARCHAR(60),
+    DELIVERY_PASSWORD           VARCHAR(100),
+    DELIVERY_USE100             BOOLEAN DEFAULT FALSE,
+    METADATA_ONLY               BOOLEAN DEFAULT FALSE,
+    SUBSCRIBER                  VARCHAR(8) NOT NULL,
+    SELF_LINK                   VARCHAR(256),
+    LOG_LINK                    VARCHAR(256),
+    LAST_MOD                    TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+    SUSPENDED                   BOOLEAN DEFAULT FALSE,
+    PRIVILEGED_SUBSCRIBER       BOOLEAN DEFAULT FALSE,
+    CREATED_DATE                TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
+    DECOMPRESS                  BOOLEAN DEFAULT FALSE,
+    AAF_INSTANCE                VARCHAR(256)
+
+);
+
+CREATE TABLE PARAMETERS (
+    KEYNAME        VARCHAR(32) NOT NULL PRIMARY KEY,
+    VALUE          VARCHAR(4096) NOT NULL
+);
+
+CREATE TABLE LOG_RECORDS (
+    TYPE           ENUM('pub', 'del', 'exp', 'pbf', 'dlx') NOT NULL,
+    EVENT_TIME     BIGINT NOT NULL,           /* time of the publish request */
+    PUBLISH_ID     VARCHAR(64) NOT NULL,      /* unique ID assigned to this publish attempt */
+    FEEDID         INT UNSIGNED NOT NULL,     /* pointer to feed in FEEDS */
+    REQURI         VARCHAR(256) NOT NULL,     /* request URI */
+    METHOD         ENUM('DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'POST', 'TRACE') NOT NULL, /* HTTP method */
+    CONTENT_TYPE   VARCHAR(256) NOT NULL,     /* content type of published file */
+    CONTENT_LENGTH BIGINT NOT NULL,  /* content length of published file */
+
+    FEED_FILEID    VARCHAR(256),        /* file ID of published file */
+    REMOTE_ADDR    VARCHAR(40),         /* IP address of publishing endpoint */
+    USER           VARCHAR(50),         /* user name of publishing endpoint */
+    STATUS         SMALLINT,            /* status code returned to delivering agent */
+
+    DELIVERY_SUBID INT UNSIGNED,        /* pointer to subscription in SUBSCRIPTIONS */
+    DELIVERY_FILEID  VARCHAR(256),      /* file ID of file being delivered */
+    RESULT         SMALLINT,            /* result received from subscribing agent */
+
+    ATTEMPTS       INT,             /* deliveries attempted */
+    REASON         ENUM('notRetryable', 'retriesExhausted', 'diskFull', 'other'),
+
+    RECORD_ID      BIGINT UNSIGNED NOT NULL PRIMARY KEY, /* unique ID for this record */
+    CONTENT_LENGTH_2 BIGINT,
+    FILENAME       VARCHAR(256),        /* Name of the file being published on DR */
+
+) ENGINE = MyISAM;
+
+CREATE TABLE INGRESS_ROUTES (
+    SEQUENCE  INT UNSIGNED NOT NULL,
+    FEEDID    INT UNSIGNED NOT NULL,
+    USERID    VARCHAR(50),
+    SUBNET    VARCHAR(44),
+    NODESET   INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE EGRESS_ROUTES (
+    SUBID    INT UNSIGNED NOT NULL PRIMARY KEY,
+    NODEID   INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NETWORK_ROUTES (
+    FROMNODE INT UNSIGNED NOT NULL,
+    TONODE   INT UNSIGNED NOT NULL,
+    VIANODE  INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NODESETS (
+    SETID   INT UNSIGNED NOT NULL,
+    NODEID  INT UNSIGNED NOT NULL
+);
+
+CREATE TABLE NODES (
+    NODEID  INT UNSIGNED NOT NULL PRIMARY KEY,
+    NAME    VARCHAR(255) NOT NULL,
+    ACTIVE  BOOLEAN DEFAULT TRUE
+);
+
+CREATE TABLE GROUPS (
+    GROUPID        INT UNSIGNED NOT NULL PRIMARY KEY,
+    AUTHID         VARCHAR(100) NOT NULL,
+    NAME           VARCHAR(50) NOT NULL,
+    DESCRIPTION    VARCHAR(255),
+    CLASSIFICATION VARCHAR(20) NOT NULL,
+    MEMBERS        TINYTEXT,
+    LAST_MOD       TIMESTAMP DEFAULT CURRENT_TIMESTAMP
+);
+
+INSERT INTO PARAMETERS VALUES
+    ('ACTIVE_POD',  'dmaap-dr-prov'),
+    ('PROV_ACTIVE_NAME',  'dmaap-dr-prov'),
+    ('STANDBY_POD', ''),
+    ('PROV_NAME',   'dmaap-dr-prov'),
+    ('NODES',       'dmaap-dr-node'),
+    ('PROV_DOMAIN', ''),
+    ('DELIVERY_INIT_RETRY_INTERVAL', '10'),
+    ('DELIVERY_MAX_AGE', '86400'),
+    ('DELIVERY_MAX_RETRY_INTERVAL', '3600'),
+    ('DELIVERY_FILE_PROCESS_INTERVAL', '600'),
+    ('DELIVERY_RETRY_RATIO', '2'),
+    ('LOGROLL_INTERVAL', '30'),
+    ('PROV_AUTH_ADDRESSES', 'dmaap-dr-prov|dmaap-dr-node'),
+    ('PROV_AUTH_SUBJECTS', ''),
+    ('PROV_MAXFEED_COUNT',  '10000'),
+    ('PROV_MAXSUB_COUNT',   '100000'),
+    ('PROV_REQUIRE_CERT', 'false'),
+    ('PROV_REQUIRE_SECURE', 'true'),
+    ('_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');
\ No newline at end of file
index 6c577a3..d7294a3 100755 (executable)
@@ -35,6 +35,7 @@
         <sitePath>/content/sites/site/${project.groupId}/${project.artifactId}/${project.version}</sitePath>
         <docker.location>${basedir}/target/${project.artifactId}</docker.location>
         <datarouter.sub.image.name>${docker.image.root}${project.artifactId}</datarouter.sub.image.name>
+        <sonar.exclusions>src/main/java/org/onap/dmaap/datarouter/subscriber/**</sonar.exclusions>
         <sonar.language>java</sonar.language>
         <sonar.skip>false</sonar.skip>
     </properties>
             <plugin>
                 <groupId>org.jacoco</groupId>
                 <artifactId>jacoco-maven-plugin</artifactId>
+                  <configuration>
+                    <excludes>
+                      <exclude>src/main/java/org/onap/dmaap/datarouter/subscriber/**</exclude>
+                    </excludes>
+                  </configuration>
             </plugin>
             <plugin>
                 <groupId>org.codehaus.mojo</groupId>
index 397d64e..88bd296 100644 (file)
@@ -47,6 +47,15 @@ Known Issues
 N/A
 
 Security Issues
+
+*Fixed Security Issues*
+
+*Known Security Issues*
+
+- In default deployment DMAAP (dmaap-dr-prov) exposes HTTP port 30259 outside of cluster. [`OJSI-158 <https://jira.onap.org/browse/OJSI-158>`_]
+
+*Known Vulnerabilities in Used Modules*
+
 DMAAP code has been formally scanned during build time using NexusIQ and all Critical vulnerabilities have been
 addressed, items that remain open have been assessed for risk and determined to be false positive. The DMAAP open
 Critical security vulnerabilities and their risk assessment have been documented as part of the `project <https://wiki.onap.org/pages/viewpage.action?pageId=42598688>`_.