aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov/src')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespImpl.java26
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java8
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthzResource.java11
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java88
-rwxr-xr-xdatarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java394
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java30
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java40
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java90
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java80
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java85
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java10
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java20
-rwxr-xr-xdatarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java20
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java3
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java59
-rwxr-xr-xdatarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java143
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java26
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java66
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java328
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryExtraRecord.java7
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java26
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java43
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedEndpointID.java4
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java89
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java64
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java2
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java29
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java22
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecord.java10
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubDelivery.java8
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java36
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java10
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java4
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java10
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java13
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java5
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java228
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java999
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java12
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java4
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java4
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java5
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java134
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java90
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java3
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java13
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java44
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java15
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java203
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java52
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java91
-rwxr-xr-xdatarouter-prov/src/test/resources/create.sql3
-rwxr-xr-xdatarouter-prov/src/test/resources/h2Database.properties11
-rw-r--r--datarouter-prov/src/test/resources/prov_data.json129
54 files changed, 2048 insertions, 1901 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespImpl.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespImpl.java
index f3278332..c7d71996 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespImpl.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespImpl.java
@@ -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.
*
* @param authorized flag indicating whether the response carried a permit response (<code>true</code>)
- * or something else (<code>false</code>).
+ * or something else (<code>false</code>).
* @param advice list of advice elements returned in the response.
* @param obligations list of obligation elements returned in the response.
*/
- public AuthRespImpl(boolean authorized, List<AuthorizationResponseSupplement> advice, List<AuthorizationResponseSupplement> obligations) {
+ private AuthRespImpl(boolean authorized, List<AuthorizationResponseSupplement> advice,
+ List<AuthorizationResponseSupplement> obligations) {
this.authorized = authorized;
- this.advice = (advice == null ? null : new ArrayList<AuthorizationResponseSupplement> (advice));
- this.obligations = (obligations == null ? null : new ArrayList<AuthorizationResponseSupplement> (obligations));
+ this.advice = (advice == null ? null : new ArrayList<>(advice));
+ this.obligations = (obligations == null ? null : new ArrayList<>(obligations));
}
/** Constructor. Simple version for authorization responses that have no advice and no obligations.
*
- * @param authorized flag indicating whether the response carried a permit (<code>true</code>) or something else (<code>false</code>).
+ * @param authorized flag indicating whether the response carried a permit (<code>true</code>)
+ * or something else (<code>false</code>).
*/
- public AuthRespImpl(boolean authorized) {
+ AuthRespImpl(boolean authorized) {
this(authorized, null, null);
}
@@ -69,25 +71,25 @@ public class AuthRespImpl implements AuthorizationResponse {
*/
@Override
public boolean isAuthorized() {
- return authorized;
+ return authorized;
}
/**
* Returns any advice elements that were included in the authorization response.
*
- * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface, with each object representing an
- * advice element from the authorization response.
+ * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface,
+ * with each object representing an advice element from the authorization response.
*/
@Override
public List<AuthorizationResponseSupplement> getAdvice() {
- return advice;
+ return advice;
}
/**
* Returns any obligation elements that were included in the authorization response.
*
- * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface, with each object representing an
- * obligation element from the authorization response.
+ * @return A list of objects implementing the <code>AuthorizationResponseSupplement</code> interface,
+ * with each object representing an obligation element from the authorization response.
*/
@Override
public List<AuthorizationResponseSupplement> getObligations() {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java
index d995270e..b61c00e5 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthRespSupplementImpl.java
@@ -36,17 +36,17 @@ import org.onap.dmaap.datarouter.authz.AuthorizationResponseSupplement;
*/
public class AuthRespSupplementImpl implements AuthorizationResponseSupplement {
- private String id = null;
- private Map<String, String> attributes = null;
+ private String id;
+ private Map<String, String> attributes;
/** Constructor, available within the package.
*
* @param id The identifier for the advice or obligation element
* @param attributes The attributes (name-value pairs) for the advice or obligation element.
*/
- AuthRespSupplementImpl (String id, Map<String, String> attributes) {
+ AuthRespSupplementImpl(String id, Map<String, String> attributes) {
this.id = id;
- this.attributes = new HashMap<String,String>(attributes);
+ this.attributes = new HashMap<>(attributes);
}
/** Return the identifier for the supplementary information element.
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthzResource.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthzResource.java
index 0357fa74..c248468f 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthzResource.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/AuthzResource.java
@@ -30,7 +30,6 @@ import java.util.regex.Pattern;
/** Internal representation of an authorization resource (the entity to which access is being requested). Consists
* of a type and an identifier. The constructor takes the request URI from an HTTP request and checks it against
* patterns for the the different resource types. In DR R1, there are four resource types:
- * <ul>
* <li>the feeds collection resource, the target of POST requests to create a new feed and GET requests to list
* the existing feeds. This is the root resource for the DR provisioning system, and it has no explicit id.
* </li>
@@ -53,10 +52,10 @@ public class AuthzResource {
private String id = "";
/* Construct an AuthzResource by matching a request URI against the various patterns */
- public AuthzResource(String rURI) {
- if (rURI != null) {
+ AuthzResource(String requestUri) {
+ if (requestUri != null) {
for (ResourceType t : ResourceType.values()) {
- Matcher m = t.getPattern().matcher(rURI);
+ Matcher m = t.getPattern().matcher(requestUri);
if (m.find(0)) {
this.type = t;
if (m.group("id") != null) {
@@ -83,13 +82,13 @@ public class AuthzResource {
*/
public enum ResourceType {
FEEDS_COLLECTION("((://[^/]+/)|(^/))(?<id>)$"),
- SUBS_COLLECTION ("((://[^/]+/)|(^/{0,1}))subscribe/(?<id>[^/]+)$"),
+ SUBS_COLLECTION("((://[^/]+/)|(^/{0,1}))subscribe/(?<id>[^/]+)$"),
FEED("((://[^/]+/)|(^/{0,1}))feed/(?<id>[^/]+)$"),
SUB("((://[^/]+/)|(^/{0,1}))subs/(?<id>[^/]+)$");
private Pattern uriPattern;
- private ResourceType(String patternString) {
+ ResourceType(String patternString) {
this.uriPattern = Pattern.compile(patternString);
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java
index 745e339d..595b626c 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthorizer.java
@@ -23,17 +23,15 @@
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);
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
index deb78b16..c6b1cde7 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java
@@ -24,30 +24,33 @@
package org.onap.dmaap.datarouter.provisioning;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
-
import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
-
-
-import java.io.IOException;
-import java.io.InputStream;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.net.InetAddress;
import java.net.UnknownHostException;
+import java.security.GeneralSecurityException;
import java.security.cert.X509Certificate;
import java.sql.Connection;
import java.sql.SQLException;
-
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.apache.commons.lang3.StringUtils;
+import org.jetbrains.annotations.Nullable;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -55,21 +58,19 @@ import org.json.JSONTokener;
import org.onap.dmaap.datarouter.authz.Authorizer;
import org.onap.dmaap.datarouter.authz.impl.ProvAuthorizer;
import org.onap.dmaap.datarouter.authz.impl.ProvDataProvider;
-import org.onap.dmaap.datarouter.provisioning.beans.*;
+import org.onap.dmaap.datarouter.provisioning.beans.Deleteable;
+import org.onap.dmaap.datarouter.provisioning.beans.Feed;
+import org.onap.dmaap.datarouter.provisioning.beans.Group;
+import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
+import org.onap.dmaap.datarouter.provisioning.beans.NodeClass;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
+import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
+import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.onap.dmaap.datarouter.provisioning.utils.PasswordProcessor;
import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
import org.slf4j.MDC;
-import javax.mail.*;
-import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeBodyPart;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeMultipart;
-import java.security.GeneralSecurityException;
-import java.util.*;
-import java.util.regex.Pattern;
-
/**
* This is the base class for all Servlets in the provisioning code. It provides standard constants and some common
@@ -94,10 +95,10 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
static final String CREATE_PERMISSION = "create";
static final String EDIT_PERMISSION = "edit";
static final String DELETE_PERMISSION = "delete";
- static final String PUBLISH_PERMISSION = "publish";
- static final String SUSPEND_PERMISSION = "suspend";
- static final String RESTORE_PERMISSION = "restore";
- static final String SUBSCRIBE_PERMISSION = "subscribe";
+ private static final String PUBLISH_PERMISSION = "publish";
+ private static final String SUSPEND_PERMISSION = "suspend";
+ private static final String RESTORE_PERMISSION = "restore";
+ private static final String SUBSCRIBE_PERMISSION = "subscribe";
static final String APPROVE_SUB_PERMISSION = "approveSub";
static final String FEED_BASECONTENT_TYPE = "application/vnd.dmaap-dr.feed";
@@ -113,7 +114,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
//Adding groups functionality, ...1610
static final String GROUP_BASECONTENT_TYPE = "application/vnd.dmaap-dr.group";
static final String GROUP_CONTENT_TYPE = "application/vnd.dmaap-dr.group; version=2.0";
- public static final String GROUPFULL_CONTENT_TYPE = "application/vnd.dmaap-dr.group-full; version=2.0";
+ static final String GROUPFULL_CONTENT_TYPE = "application/vnd.dmaap-dr.group-full; version=2.0";
public static final String GROUPLIST_CONTENT_TYPE = "application/vnd.dmaap-dr.fegrouped-list; version=1.0";
@@ -130,101 +131,123 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
private static final int DEFAULT_POKETIMER2 = 30;
private static final String DEFAULT_DOMAIN = "onap";
private static final String DEFAULT_PROVSRVR_NAME = "dmaap-dr-prov";
- private static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610
+
+ //Common Errors
+ static final String MISSING_ON_BEHALF = "Missing X-DMAAP-DR-ON-BEHALF-OF header.";
+ static final String MISSING_FEED = "Missing or bad feed number.";
+ static final String POLICY_ENGINE = "Policy Engine disallows access.";
+ static final String UNAUTHORIZED = "Unauthorized.";
+ static final String BAD_SUB = "Missing or bad subscription number.";
+ static final String BAD_JSON = "Badly formed JSON";
+ static final String BAD_URL = "Bad URL.";
+
+ public static final String API = "/api/";
+ static final String LOGS = "/logs/";
+ static final String TEXT_CT = "text/plain";
+ static final String INGRESS = "/ingress/";
+ static final String EGRESS = "/egress/";
+ static final String NETWORK = "/network/";
+ static final String GROUPID = "groupid";
+ public static final String FEEDID = "feedid";
+ static final String FEEDIDS = "feedids";
+ static final String SUBID = "subid";
+ static final String EVENT_TYPE = "eventType";
+ static final String OUTPUT_TYPE = "output_type";
+ static final String START_TIME = "start_time";
+ static final String END_TIME = "end_time";
+ static final String REASON_SQL = "reasonSQL";
+
/**
- * A boolean to trigger one time "provisioning changed" event on startup
+ * A boolean to trigger one time "provisioning changed" event on startup.
*/
private static boolean startmsgFlag = true;
/**
- * This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE)
+ * This POD should require SSL connections from clients; pulled from the DB (PROV_REQUIRE_SECURE).
*/
private static boolean requireSecure = true;
/**
- * This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT)
+ * This POD should require signed, recognized certificates from clients; pulled from the DB (PROV_REQUIRE_CERT).
*/
private static boolean requireCert = true;
/**
- * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES)
+ * The set of authorized addresses and networks; pulled from the DB (PROV_AUTH_ADDRESSES).
*/
private static Set<String> authorizedAddressesAndNetworks = new HashSet<>();
/**
- * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS)
+ * The set of authorized names; pulled from the DB (PROV_AUTH_SUBJECTS).
*/
private static Set<String> authorizedNames = new HashSet<>();
/**
- * The FQDN of the initially "active" provisioning server in this Data Router ecosystem
+ * The FQDN of the initially "active" provisioning server in this Data Router ecosystem.
*/
private static String initialActivePod;
/**
- * The FQDN of the initially "standby" provisioning server in this Data Router ecosystem
+ * The FQDN of the initially "standby" provisioning server in this Data Router ecosystem.
*/
private static String initialStandbyPod;
/**
- * The FQDN of this provisioning server in this Data Router ecosystem
+ * The FQDN of this provisioning server in this Data Router ecosystem.
*/
private static String thisPod;
/**
- * "Timer 1" - used to determine when to notify nodes of provisioning changes
+ * "Timer 1" - used to determine when to notify nodes of provisioning changes.
*/
private static long pokeTimer1;
/**
- * "Timer 2" - used to determine when to notify nodes of provisioning changes
+ * "Timer 2" - used to determine when to notify nodes of provisioning changes.
*/
private static long pokeTimer2;
/**
- * Array of nodes names and/or FQDNs
+ * Array of nodes names and/or FQDNs.
*/
private static String[] nodes = new String[0];
/**
- * [DATARTR-27] Poke all the DR nodes : Array of nodes names and/or FQDNs
+ * [DATARTR-27] Poke all the DR nodes : Array of nodes names and/or FQDNs.
*/
private static String[] drnodes = new String[0];
/**
- * Array of node IP addresses
+ * Array of node IP addresses.
*/
private static InetAddress[] nodeAddresses = new InetAddress[0];
/**
- * Array of POD IP addresses
+ * Array of POD IP addresses.
*/
private static InetAddress[] podAddresses = new InetAddress[0];
/**
- * The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT)
+ * The maximum number of feeds allowed; pulled from the DB (PROV_MAXFEED_COUNT).
*/
static int maxFeeds = 0;
/**
- * The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT)
+ * The maximum number of subscriptions allowed; pulled from the DB (PROV_MAXSUB_COUNT).
*/
static int maxSubs = 0;
/**
- * The current number of feeds in the system
+ * The current number of feeds in the system.
*/
static int activeFeeds = 0;
/**
- * The current number of subscriptions in the system
+ * The current number of subscriptions in the system.
*/
static int activeSubs = 0;
/**
- * The domain used to generate a FQDN from the "bare" node names
+ * The domain used to generate a FQDN from the "bare" node names.
*/
private static String provDomain = "web.att.com";
/**
- * The standard FQDN of the provisioning server in this Data Router ecosystem
+ * The standard FQDN of the provisioning server in this Data Router ecosystem.
*/
private static String provName = "feeds-drtr.web.att.com";
/**
- * The standard FQDN of the ACTIVE provisioning server in this Data Router ecosystem
+ * The standard FQDN of the ACTIVE_POD provisioning server in this Data Router ecosystem.
*/
private static String activeProvName = "feeds-drtr.web.att.com";
- //Adding new param for static Routing - Rally:US664862-1610
- private static String staticRoutingNodes = STATIC_ROUTING_NODES;
-
/**
- * This logger is used to log provisioning events
+ * This logger is used to log provisioning events.
*/
protected static EELFLogger eventlogger;
/**
@@ -232,21 +255,17 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
*/
protected static EELFLogger intlogger;
/**
- * Authorizer - interface to the Policy Engine
+ * Authorizer - interface to the Policy Engine.
*/
protected static Authorizer authz;
/**
- * The Synchronizer used to sync active DB to standby one
+ * The Synchronizer used to sync active DB to standby one.
*/
private static SynchronizerTask synctask = null;
//Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
private InetAddress thishost;
private InetAddress loopback;
- private static Boolean mailSendFlag = false;
-
- private static final String MAILCONFIG_FILE = "mail.properties";
- private static Properties mailprops;
//DMAAP-597 (Tech Dept) REST request source IP auth relaxation to accommodate OOM kubernetes deploy
private static String isAddressAuthEnabled = (new DB()).getProperties()
@@ -259,10 +278,10 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
* Initialize data common to all the provisioning server servlets.
*/
protected BaseServlet() {
- if(eventlogger == null) {
- this.eventlogger = EELFManager.getInstance().getLogger("EventLog");
+ if (eventlogger == null) {
+ eventlogger = EELFManager.getInstance().getLogger("EventLog");
}
- if(intlogger == null) {
+ if (intlogger == null) {
this.intlogger = EELFManager.getInstance().getLogger("InternalLog");
}
if (authz == null) {
@@ -285,9 +304,8 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
try {
thishost = InetAddress.getLocalHost();
loopback = InetAddress.getLoopbackAddress();
- //checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
} catch (UnknownHostException e) {
- // ignore
+ intlogger.info("BaseServlet.init: " + e.getMessage(), e);
}
}
@@ -304,7 +322,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/**
- * Read the request's input stream and return a JSONObject from it
+ * Read the request's input stream and return a JSONObject from it.
*
* @param req the HTTP request
* @return the JSONObject, or null if the stream cannot be parsed
@@ -323,35 +341,40 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/**
- * This method encrypt/decrypt the key in the JSON passed by user request inside the authorisation header object in request before logging the JSON.
+ * This method encrypt/decrypt the key in the JSON passed by user request inside the authorisation
+ * header object in request before logging the JSON.
*
- * @param jo- the JSON passed in http request.
- * @param maskKey- the key to be masked in the JSON passed.
- * @param action- whether to mask the key or unmask it in a JSON passed.
+ * @param jo the JSON passed in http request.
+ * @param maskKey the key to be masked in the JSON passed.
+ * @param action whether to mask the key or unmask it in a JSON passed.
* @return the JSONObject, or null if the stream cannot be parsed.
*/
- public static JSONObject maskJSON(JSONObject jo, String maskKey, boolean action) {
+ static JSONObject maskJSON(JSONObject jo, String maskKey, boolean action) {
if (!jo.isNull("authorization")) {
- JSONObject j2 = jo.getJSONObject("authorization");
- JSONArray ja = j2.getJSONArray("endpoint_ids");
- for (int i = 0; i < ja.length(); i++) {
- if ((!ja.getJSONObject(i).isNull(maskKey))) {
- String password = ja.getJSONObject(i).get(maskKey).toString();
- try {
- if (action) {
- ja.getJSONObject(i).put(maskKey, PasswordProcessor.encrypt(password));
- } else {
- ja.getJSONObject(i).put(maskKey, PasswordProcessor.decrypt(password));
- }
- } catch (JSONException | GeneralSecurityException e) {
- intlogger.info("Error reading JSON while masking: " + e);
- }
+ JSONArray endpointIds = jo.getJSONObject("authorization").getJSONArray("endpoint_ids");
+ for (int index = 0; index < endpointIds.length(); index++) {
+ if ((!endpointIds.getJSONObject(index).isNull(maskKey))) {
+ String password = endpointIds.getJSONObject(index).get(maskKey).toString();
+ processPassword(maskKey, action, endpointIds, index, password);
}
}
}
return jo;
}
+ private static void processPassword(String maskKey, boolean action, JSONArray endpointIds, int index,
+ String password) {
+ try {
+ if (action) {
+ endpointIds.getJSONObject(index).put(maskKey, PasswordProcessor.encrypt(password));
+ } else {
+ endpointIds.getJSONObject(index).put(maskKey, PasswordProcessor.decrypt(password));
+ }
+ } catch (JSONException | GeneralSecurityException e) {
+ intlogger.info("Error reading JSON while masking: " + e);
+ }
+ }
+
/**
* Check if the remote host is authorized to perform provisioning. Is the request secure? Is it coming from an
* authorized IP address or network (configured via PROV_AUTH_ADDRESSES)? Does it have a valid client certificate
@@ -368,20 +391,9 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
if (requireSecure && !request.isSecure()) {
return "Request must be made over an HTTPS connection.";
}
- // Is remote IP authorized?
- String remote = request.getRemoteAddr();
- try {
- boolean found = false;
- InetAddress ip = InetAddress.getByName(remote);
- for (String addrnet : authorizedAddressesAndNetworks) {
- found |= addressMatchesNetwork(ip, addrnet);
- }
- if (!found) {
- return "Unauthorized address: " + remote;
- }
- } catch (UnknownHostException e) {
- intlogger.error("PROV0051 BaseServlet.isAuthorizedForProvisioning: ", e.getMessage());
- return "Unauthorized address: " + remote;
+ String remoteHostCheck = checkRemoteHostAuthorization(request);
+ if (remoteHostCheck != null) {
+ return remoteHostCheck;
}
// Does remote have a valid certificate?
if (requireCert) {
@@ -400,6 +412,26 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
return null;
}
+ @Nullable
+ private String checkRemoteHostAuthorization(HttpServletRequest request) {
+ // Is remote IP authorized?
+ String remote = request.getRemoteAddr();
+ try {
+ boolean found = false;
+ InetAddress ip = InetAddress.getByName(remote);
+ for (String addrnet : authorizedAddressesAndNetworks) {
+ found |= addressMatchesNetwork(ip, addrnet);
+ }
+ if (!found) {
+ return "Unauthorized address: " + remote;
+ }
+ } catch (UnknownHostException e) {
+ intlogger.error("PROV0051 BaseServlet.isAuthorizedForProvisioning: " + e.getMessage(), e);
+ return "Unauthorized address: " + remote;
+ }
+ return null;
+ }
+
/**
* Check if the remote IP address is authorized to see the /internal URL tree.
*
@@ -413,23 +445,23 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
InetAddress ip = InetAddress.getByName(request.getRemoteAddr());
for (InetAddress node : getNodeAddresses()) {
- if (node != null && ip.equals(node)) {
+ if (ip.equals(node)) {
return true;
}
}
for (InetAddress pod : getPodAddresses()) {
- if (pod != null && ip.equals(pod)) {
+ if (ip.equals(pod)) {
return true;
}
}
- if (thishost != null && ip.equals(thishost)) {
+ if (ip.equals(thishost)) {
return true;
}
- if (loopback != null && ip.equals(loopback)) {
+ if (ip.equals(loopback)) {
return true;
}
} catch (UnknownHostException e) {
- intlogger.error("PROV0052 BaseServlet.isAuthorizedForInternal: ", e.getMessage());
+ intlogger.error("PROV0052 BaseServlet.isAuthorizedForInternal: " + e.getMessage(), e);
}
return false;
}
@@ -443,7 +475,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
*/
private static boolean addressMatchesNetwork(InetAddress ip, String s) {
int mlen = -1;
- int n = s.indexOf("/");
+ int n = s.indexOf('/');
if (n >= 0) {
mlen = Integer.parseInt(s.substring(n + 1));
s = s.substring(0, n);
@@ -473,7 +505,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
}
} catch (UnknownHostException e) {
- intlogger.error("PROV0053 BaseServlet.addressMatchesNetwork: ", e.getMessage());
+ intlogger.error("PROV0053 BaseServlet.addressMatchesNetwork: " + e.getMessage(), e);
return false;
}
return true;
@@ -503,23 +535,23 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
maxSubs = getInt(map, Parameters.PROV_MAXSUB_COUNT, DEFAULT_MAX_SUBS);
pokeTimer1 = getInt(map, Parameters.PROV_POKETIMER1, DEFAULT_POKETIMER1);
pokeTimer2 = getInt(map, Parameters.PROV_POKETIMER2, DEFAULT_POKETIMER2);
- /**
- * The domain used to generate a FQDN from the "bare" node names
- */
+
+ // The domain used to generate a FQDN from the "bare" node names
provDomain = getString(map, Parameters.PROV_DOMAIN, DEFAULT_DOMAIN);
provName = getString(map, Parameters.PROV_NAME, DEFAULT_PROVSRVR_NAME);
activeProvName = getString(map, Parameters.PROV_ACTIVE_NAME, provName);
initialActivePod = getString(map, Parameters.ACTIVE_POD, "");
initialStandbyPod = getString(map, Parameters.STANDBY_POD, "");
- staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES,
- ""); //Adding new param for static Routing - Rally:US664862-1610
+
+ //Adding new param for static Routing - Rally:US664862-1610
+ String staticRoutingNodes = getString(map, Parameters.STATIC_ROUTING_NODES, "");
activeFeeds = Feed.countActiveFeeds();
activeSubs = Subscription.countActiveSubscriptions();
try {
thisPod = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
thisPod = "";
- intlogger.warn("PROV0014 Cannot determine the name of this provisioning server.");
+ intlogger.warn("PROV0014 Cannot determine the name of this provisioning server.", e);
}
// Normalize the nodes, and fill in nodeAddresses
@@ -530,7 +562,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
intlogger.debug("PROV0003 DNS lookup: " + nodes[i] + " => " + na[i].toString());
} catch (UnknownHostException e) {
na[i] = null;
- intlogger.warn("PROV0004 Cannot lookup " + nodes[i] + ": " + e.getMessage());
+ intlogger.warn("PROV0004 Cannot lookup " + nodes[i] + ": " + e.getMessage(), e);
}
}
@@ -558,7 +590,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
intlogger.debug("PROV0003 DNS lookup: " + pods[i] + " => " + na[i].toString());
} catch (UnknownHostException e) {
na[i] = null;
- intlogger.warn("PROV0004 Cannot lookup " + pods[i] + ": " + e.getMessage());
+ intlogger.warn("PROV0004 Cannot lookup " + pods[i] + ": " + e.getMessage(), e);
}
}
podAddresses = na;
@@ -572,96 +604,11 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
}
-
- /**
- * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Load mail properties.
- *
- * @author vs215k
- **/
- private void loadMailProperties() {
- if (mailprops == null) {
- mailprops = new Properties();
- try (InputStream inStream = getClass().getClassLoader().getResourceAsStream(MAILCONFIG_FILE)) {
- mailprops.load(inStream);
- } catch (IOException e) {
- intlogger.error("PROV9003 Opening properties: " + e.getMessage());
- System.exit(1);
- }
- }
- }
-
- /**
- * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Check if HTTPS Relexaction is enabled
- *
- * @author vs215k
- **/
- private void checkHttpsRelaxation() {
- if (!mailSendFlag) {
- Properties p = (new DB()).getProperties();
- intlogger.info("HTTPS relaxation: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation"));
-
- if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) {
- try {
- notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString());
- } catch (Exception e) {
- intlogger.warn("Exception: " + e.getMessage());
- }
- }
- mailSendFlag = true;
- }
- }
-
- /**
- * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047.
- *
- * @param email - list of email ids to notify if HTTP relexcation is enabled.
- * @author vs215k
- **/
- private void notifyPSTeam(String email) throws Exception {
- loadMailProperties(); //Load HTTPS Relex mail properties.
- String[] emails = email.split(Pattern.quote("|"));
-
- Properties mailproperties = new Properties();
- mailproperties.put("mail.smtp.host", mailprops.get("com.att.dmaap.datarouter.mail.server"));
- mailproperties.put("mail.transport.protocol", mailprops.get("com.att.dmaap.datarouter.mail.protocol"));
-
- Session session = Session.getDefaultInstance(mailproperties, null);
- Multipart mp = new MimeMultipart();
- MimeBodyPart htmlPart = new MimeBodyPart();
-
- try {
-
- Message msg = new MimeMessage(session);
- msg.setFrom(new InternetAddress(mailprops.get("com.att.dmaap.datarouter.mail.from").toString()));
-
- InternetAddress[] addressTo = new InternetAddress[emails.length];
- for (int x = 0; x < emails.length; x++) {
- addressTo[x] = new InternetAddress(emails[x]);
- }
-
- msg.addRecipients(Message.RecipientType.TO, addressTo);
- msg.setSubject(mailprops.get("com.att.dmaap.datarouter.mail.subject").toString());
- htmlPart.setContent(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
- .replace("[SERVER]", InetAddress.getLocalHost().getHostName()), "text/html");
- mp.addBodyPart(htmlPart);
- msg.setContent(mp);
-
- System.out.println(mailprops.get("com.att.dmaap.datarouter.mail.body").toString()
- .replace("[SERVER]", InetAddress.getLocalHost().getHostName()));
-
- Transport.send(msg);
- intlogger.info("HTTPS relaxation mail is sent to - : " + email);
-
- } catch (MessagingException e) {
- intlogger.error("Invalid email address, unable to send https relaxation mail to - : " + email);
- }
- }
-
public static String getProvName() {
return provName;
}
- public static String getActiveProvName() {
+ static String getActiveProvName() {
return activeProvName;
}
@@ -675,21 +622,11 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/**
- * [DATARTR-27] Poke all the DR nodes
- * Get an array of all node names in the DR network.
- *
- * @return an array of Strings
- */
- public static String[] getDRNodes() {
- return drnodes;
- }
-
- /**
* Get an array of all node InetAddresses in the DR network.
*
* @return an array of InetAddresses
*/
- public static InetAddress[] getNodeAddresses() {
+ private static InetAddress[] getNodeAddresses() {
return nodeAddresses;
}
@@ -712,7 +649,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/**
- * Gets the FQDN of the initially ACTIVE provisioning server (POD). Note: this used to be called isActivePOD(),
+ * Gets the FQDN of the initially ACTIVE_POD provisioning server (POD). Note: this used to be called isActivePOD(),
* however, that is a misnomer, as the active status could shift to the standby POD without these parameters
* changing. Hence, the function names have been changed to more accurately reflect their purpose.
*
@@ -723,7 +660,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/**
- * Gets the FQDN of the initially STANDBY provisioning server (POD). Note: this used to be called isStandbyPOD(),
+ * Gets the FQDN of the initially STANDBY_POD provisioning server (POD). Note: this used to be called isStandbyPOD(),
* however, that is a misnomer, as the standby status could shift to the active POD without these parameters
* changing. Hence, the function names have been changed to more accurately reflect their purpose.
*
@@ -748,7 +685,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
rv = bean.doInsert(conn);
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
if (conn != null) {
db.release(conn);
@@ -772,7 +709,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
rv = bean.doUpdate(conn);
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
if (conn != null) {
db.release(conn);
@@ -796,7 +733,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
rv = bean.doDelete(conn);
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
if (conn != null) {
db.release(conn);
@@ -807,7 +744,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
private static boolean getBoolean(Map<String, String> map, String name) {
String s = map.get(name);
- return (s != null) && s.equalsIgnoreCase("true");
+ return "true".equalsIgnoreCase(s);
}
private static String getString(Map<String, String> map, String name, String dflt) {
@@ -847,7 +784,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
*/
public class ContentHeader {
- private String type = "";
+ private String type;
private Map<String, String> map = new HashMap<>();
ContentHeader() {
@@ -863,7 +800,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
return type;
}
- public String getAttribute(String key) {
+ String getAttribute(String key) {
String s = map.get(key);
if (s == null) {
s = "";
@@ -959,7 +896,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
return true;
}
} catch (JSONException e) {
- intlogger.error("JSONException: " + e.getMessage());
+ intlogger.error("JSONException: " + e.getMessage(), e);
}
}
return false;
@@ -969,19 +906,17 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
/*
* @Method - getGroupByFeedGroupId- Rally:US708115
* @Params - User to check in group and feedid which is assigned the group.
- * @return - string value grupid/null
+ * @return - string value groupid/null
*/
@Override
public String getGroupByFeedGroupId(String owner, String feedId) {
try {
- int n = Integer.parseInt(feedId);
- Feed f = Feed.getFeedById(n);
+ Feed f = Feed.getFeedById(Integer.parseInt(feedId));
if (f != null) {
int groupid = f.getGroupid();
if (groupid > 0) {
Group group = Group.getGroupById(groupid);
- assert group != null;
- if (isUserMemberOfGroup(group, owner)) {
+ if (group != null && isUserMemberOfGroup(group, owner)) {
return group.getAuthid();
}
}
@@ -995,7 +930,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
/*
* @Method - getGroupBySubGroupId - Rally:US708115
* @Params - User to check in group and subid which is assigned the group.
- * @return - string value grupid/null
+ * @return - string value groupid/null
*/
@Override
public String getGroupBySubGroupId(String owner, String subId) {
@@ -1006,8 +941,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
int groupid = s.getGroupid();
if (groupid > 0) {
Group group = Group.getGroupById(groupid);
- assert group != null;
- if (isUserMemberOfGroup(group, owner)) {
+ if (group != null && isUserMemberOfGroup(group, owner)) {
return group.getAuthid();
}
}
@@ -1048,7 +982,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
} catch (Exception e) {
- intlogger.error("Exception: " + e.getMessage());
+ intlogger.error("Exception: " + e.getMessage(), e);
}
}
@@ -1086,12 +1020,12 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
default:
action = "*";
}
- if (aafInstance == null || aafInstance.equals("")) {
+ if (aafInstance == null || "".equals(aafInstance)) {
aafInstance = props.getProperty(AAF_INSTANCE, "org.onap.dmaap-dr.NoInstanceDefined");
}
return type + "|" + aafInstance + "|" + action;
} catch (Exception e) {
- intlogger.error("PROV7005 BaseServlet.getFeedPermission: ", e.getMessage());
+ intlogger.error("PROV7005 BaseServlet.getFeedPermission: " + e.getMessage(), e);
}
return null;
}
@@ -1134,12 +1068,12 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
default:
action = "*";
}
- if (aafInstance == null || aafInstance.equals("")) {
+ if (aafInstance == null || "".equals(aafInstance)) {
aafInstance = props.getProperty(AAF_INSTANCE, "org.onap.dmaap-dr.NoInstanceDefined");
}
return type + "|" + aafInstance + "|" + action;
} catch (Exception e) {
- intlogger.error("PROV7005 BaseServlet.getSubscriberPermission: ", e.getMessage());
+ intlogger.error("PROV7005 BaseServlet.getSubscriberPermission: " + e.getMessage(), e);
}
return null;
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
index 86e0268d..960d5094 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java
@@ -109,8 +109,8 @@ public class DRFeedsServlet extends ProxyServlet {
}
// Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
String path = req.getRequestURI();
- if (path != null && !path.equals("/")) {
- message = "Bad URL.";
+ if (path != null && !"/".equals(path)) {
+ message = BAD_URL;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -120,7 +120,7 @@ public class DRFeedsServlet extends ProxyServlet {
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -150,7 +150,7 @@ public class DRFeedsServlet extends ProxyServlet {
try {
resp.getOutputStream().print(feed.asJSONObject(true).toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0111 DRFeedServlet.doGet " + ioe.getMessage(), ioe);
}
}
} else {
@@ -174,7 +174,7 @@ public class DRFeedsServlet extends ProxyServlet {
try {
resp.getOutputStream().print(t);
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0112 DRFeedServlet.doGet " + ioe.getMessage(), ioe);
}
}
} finally {
@@ -236,8 +236,8 @@ public class DRFeedsServlet extends ProxyServlet {
}
// Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
String path = req.getRequestURI();
- if (path != null && !path.equals("/")) {
- message = "Bad URL.";
+ if (path != null && !"/".equals(path)) {
+ message = BAD_URL;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -247,7 +247,7 @@ public class DRFeedsServlet extends ProxyServlet {
// check content type is FEED_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+ if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -257,7 +257,7 @@ public class DRFeedsServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -283,7 +283,7 @@ public class DRFeedsServlet extends ProxyServlet {
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
@@ -295,11 +295,11 @@ public class DRFeedsServlet extends ProxyServlet {
*/
String aafInstance = feed.getAafInstance();
if (Boolean.parseBoolean(isCadiEnabled)) {
- if ((aafInstance == null || aafInstance.equals("") || (aafInstance.equalsIgnoreCase("legacy")) && req.getHeader(EXCLUDE_AAF_HEADER).equalsIgnoreCase("true"))) {
+ if ((aafInstance == null || "".equals(aafInstance) || ("legacy".equalsIgnoreCase(aafInstance)) && "true".equalsIgnoreCase(req.getHeader(EXCLUDE_AAF_HEADER)))) {
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -307,7 +307,7 @@ public class DRFeedsServlet extends ProxyServlet {
return;
}
} else {
- if (req.getHeader(EXCLUDE_AAF_HEADER).equalsIgnoreCase("true")) {
+ if ("true".equalsIgnoreCase(req.getHeader(EXCLUDE_AAF_HEADER))) {
message = "DRFeedsServlet.doPost() -Invalid request exclude_AAF should not be true if passing AAF_Instance value= " + aafInstance;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -329,7 +329,7 @@ public class DRFeedsServlet extends ProxyServlet {
} else {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -365,7 +365,7 @@ public class DRFeedsServlet extends ProxyServlet {
try {
resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0113 DRFeedServlet.doPost " + ioe.getMessage(), ioe);
}
provisioningDataChanged();
} else {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
index 3cbaac3c..e1938cd8 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
@@ -82,7 +82,7 @@ public class FeedServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -91,7 +91,7 @@ public class FeedServlet extends ProxyServlet {
}
int feedid = getIdFromPath(req);
if (feedid < 0) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -100,7 +100,7 @@ public class FeedServlet extends ProxyServlet {
}
Feed feed = Feed.getFeedById(feedid);
if (feed == null || feed.isDeleted()) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -113,10 +113,10 @@ public class FeedServlet extends ProxyServlet {
* CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove feed
*/
String aafInstance = feed.getAafInstance();
- if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+ if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
AuthorizationResponse aresp = authz.decide(req);
if (! aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -183,7 +183,7 @@ public class FeedServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -192,7 +192,7 @@ public class FeedServlet extends ProxyServlet {
}
int feedid = getIdFromPath(req);
if (feedid < 0) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -201,7 +201,7 @@ public class FeedServlet extends ProxyServlet {
}
Feed feed = Feed.getFeedById(feedid);
if (feed == null || feed.isDeleted()) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -211,7 +211,7 @@ public class FeedServlet extends ProxyServlet {
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (! aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -227,7 +227,7 @@ public class FeedServlet extends ProxyServlet {
try {
resp.getOutputStream().print(feed.asJSONObject(true).toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0101 FeedServlet.doGet: " + ioe.getMessage(), ioe);
}
} finally {
eelfLogger.info(EelfMsgs.EXIT);
@@ -259,7 +259,7 @@ public class FeedServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -268,7 +268,7 @@ public class FeedServlet extends ProxyServlet {
}
int feedid = getIdFromPath(req);
if (feedid < 0) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -277,7 +277,7 @@ public class FeedServlet extends ProxyServlet {
}
Feed oldFeed = Feed.getFeedById(feedid);
if (oldFeed == null || oldFeed.isDeleted()) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -287,7 +287,7 @@ public class FeedServlet extends ProxyServlet {
// check content type is FEED_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+ if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -297,7 +297,7 @@ public class FeedServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -313,7 +313,7 @@ public class FeedServlet extends ProxyServlet {
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
@@ -355,11 +355,11 @@ public class FeedServlet extends ProxyServlet {
* CADI code - check on permissions based on Legacy/AAF users to allow feed edit/update/modify
*/
String aafInstance = feed.getAafInstance();
- if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+ if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -392,7 +392,7 @@ public class FeedServlet extends ProxyServlet {
try {
resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0102 FeedServlet.doPut: " + ioe.getMessage(), ioe);
}
@@ -405,7 +405,7 @@ public class FeedServlet extends ProxyServlet {
feed.changeOwnerShip();
}
} catch (JSONException je) {
- eventlogger.error("JSONException" + je.getMessage());
+ eventlogger.error("PROV0103 FeedServlet.doPut: " + je.getMessage(), je);
}
}
/***End of change ownership*/
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
index 188dce61..4432913f 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java
@@ -88,31 +88,6 @@ public class GroupServlet extends ProxyServlet {
return;
}
- // Check with the Authorizer
- /*AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.error(elr.toString());
- resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
- return;
- }*/
-
-
- /*ContentHeader ch = getContentHeader(req);
- String ver = ch.getAttribute("version");
- if (!ch.getType().equals(GROUPLIST_CONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
- intlogger.debug("Content-type is: "+req.getHeader("Content-Type"));
- message = "Incorrect content-type";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.error(elr.toString());
- resp.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message);
- return;
- }*/
-
-
int groupid = getIdFromPath(req);
if (groupid < 0) {
message = "Missing or bad group number.";
@@ -132,19 +107,9 @@ public class GroupServlet extends ProxyServlet {
try {
resp.getOutputStream().print(gup.asJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0121 GroupServlet.doGet: " + ioe.getMessage(), ioe);
}
- // Display a list of Groups
- /*Collection<Group> list = Group.getGroupById(groupid);
- String t = JSONUtilities.createJSONArray(list);
-
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr.toString());
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(GROUPLIST_CONTENT_TYPE);
- resp.getOutputStream().print(t);*/
}
/**
* PUT on the &lt;GROUPS&gt; -- not supported.
@@ -191,20 +156,11 @@ public class GroupServlet extends ProxyServlet {
sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
return;
}
- // Check with the Authorizer
- /*AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.error(elr.toString());
- resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
- return;
- }*/
+
// check content type is SUB_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(GROUP_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+ if (!ch.getType().equals(GROUP_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -214,7 +170,7 @@ public class GroupServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -230,7 +186,7 @@ public class GroupServlet extends ProxyServlet {
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
@@ -253,7 +209,7 @@ public class GroupServlet extends ProxyServlet {
try {
resp.getOutputStream().print(gup.asJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0122 GroupServlet.doPut: " + ioe.getMessage(), ioe);
}
provisioningDataChanged();
} else {
@@ -292,34 +248,6 @@ public class GroupServlet extends ProxyServlet {
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
- /*int feedid = getIdFromPath(req);
- if (feedid < 0) {
- message = "Missing or bad feed number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr.toString());
- resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
- return;
- }
- Feed feed = Feed.getFeedById(feedid);
- if (feed == null || feed.isDeleted()) {
- message = "Missing or bad feed number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr.toString());
- resp.sendError(HttpServletResponse.SC_NOT_FOUND, message);
- return;
- }*/
- // Check with the Authorizer
- /*AuthorizationResponse aresp = authz.decide(req);
- if (! aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr.toString());
- resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
- return;
- }*/
// check content type is SUB_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
@@ -335,7 +263,7 @@ public class GroupServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -352,7 +280,7 @@ public class GroupServlet extends ProxyServlet {
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
@@ -379,7 +307,7 @@ public class GroupServlet extends ProxyServlet {
try {
resp.getOutputStream().print(gup.asJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0122 GroupServlet.doPost: " + ioe.getMessage(), ioe);
}
provisioningDataChanged();
} else {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
index 56b40e04..8ae9fa20 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java
@@ -156,6 +156,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
@SuppressWarnings("serial")
public class InternalServlet extends ProxyServlet {
+
private static final Object lock = new Object();
private static Integer logseq = 0; // another piece of info to make log spool file names unique
//Adding EELF Logger Rally:US664892
@@ -174,15 +175,15 @@ public class InternalServlet extends ProxyServlet {
eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
String path = req.getPathInfo();
- if (path.startsWith("/api/")) {
+ if (path.startsWith(API)) {
if (isProxyOK(req) && isProxyServer()) {
super.doDelete(req, resp);
return;
@@ -207,7 +208,7 @@ public class InternalServlet extends ProxyServlet {
}
}
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
} finally {
eelfLogger.info(EelfMsgs.EXIT);
}
@@ -225,7 +226,7 @@ public class InternalServlet extends ProxyServlet {
eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
String path = req.getPathInfo();
Properties props = (new DB()).getProperties();
- if (path.equals("/halt") && !req.isSecure()) {
+ if ("/halt".equals(path) && !req.isSecure()) {
// request to halt the server - can ONLY come from localhost
String remote = req.getRemoteAddr();
if (remote.equals(props.getProperty("org.onap.dmaap.datarouter.provserver.localhost"))) {
@@ -241,20 +242,20 @@ public class InternalServlet extends ProxyServlet {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
- if (path.equals("/fetchProv") && !req.isSecure()) {
+ if ("/fetchProv".equals(path) && !req.isSecure()) {
// if request came from active_pod or standby_pod and it is not us, reload prov data
SynchronizerTask s = SynchronizerTask.getSynchronizer();
s.doFetch();
resp.setStatus(HttpServletResponse.SC_OK);
return;
}
- if (path.equals("/prov")) {
+ if ("/prov".equals(path)) {
if (isProxyOK(req) && isProxyServer()) {
if (super.doGetWithFallback(req, resp)) {
return;
@@ -268,33 +269,33 @@ public class InternalServlet extends ProxyServlet {
try {
resp.getOutputStream().print(p.getProvisioningString());
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0131 InternalServlet.doGet: " + ioe.getMessage(), ioe);
}
return;
}
- if (path.equals("/logs") || path.equals("/logs/")) {
+ if ("/logs".equals(path) || LOGS.equals(path)) {
resp.setStatus(HttpServletResponse.SC_OK);
resp.setContentType("application/json");
try {
resp.getOutputStream().print(generateLogfileList().toString());
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0132 InternalServlet.doGet: " + ioe.getMessage(), ioe);
}
return;
}
- if (path.startsWith("/logs/")) {
+ if (path.startsWith(LOGS)) {
String logdir = props.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");
String logfile = path.substring(6);
if (logdir != null && logfile != null && logfile.indexOf('/') < 0) {
File log = new File(logdir + "/" + logfile);
if (log.exists() && log.isFile()) {
resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType("text/plain");
+ resp.setContentType(TEXT_CT);
Path logpath = Paths.get(log.getAbsolutePath());
try {
Files.copy(logpath, resp.getOutputStream());
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0133 InternalServlet.doGet: " + ioe.getMessage(), ioe);
}
return;
}
@@ -302,7 +303,7 @@ public class InternalServlet extends ProxyServlet {
sendResponseError(resp, HttpServletResponse.SC_NO_CONTENT, "No file.", eventlogger);
return;
}
- if (path.startsWith("/api/")) {
+ if (path.startsWith(API)) {
if (isProxyOK(req) && isProxyServer()) {
super.doGet(req, resp);
return;
@@ -312,29 +313,29 @@ public class InternalServlet extends ProxyServlet {
Parameters param = Parameters.getParameter(key);
if (param != null) {
resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType("text/plain");
+ resp.setContentType(TEXT_CT);
try {
resp.getOutputStream().print(param.getValue() + "\n");
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0134 InternalServlet.doGet: " + ioe.getMessage(), ioe);
}
return;
}
}
}
- if (path.equals("/drlogs") || path.equals("/drlogs/")) {
+ if ("/drlogs".equals(path) || "/drlogs/".equals(path)) {
// Special POD <=> POD API to determine what log file records are loaded here
LogfileLoader lfl = LogfileLoader.getLoader();
resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType("text/plain");
+ resp.setContentType(TEXT_CT);
try {
resp.getOutputStream().print(lfl.getBitSet().toString());
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0135 InternalServlet.doGet: " + ioe.getMessage(), ioe);
}
return;
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
} finally {
eelfLogger.info(EelfMsgs.EXIT);
}
@@ -352,14 +353,14 @@ public class InternalServlet extends ProxyServlet {
eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
String path = req.getPathInfo();
- if (path.startsWith("/api/")) {
+ if (path.startsWith(API)) {
if (isProxyOK(req) && isProxyServer()) {
super.doPut(req, resp);
return;
@@ -386,7 +387,7 @@ public class InternalServlet extends ProxyServlet {
}
}
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
} finally {
eelfLogger.info(EelfMsgs.EXIT);
}
@@ -405,15 +406,15 @@ public class InternalServlet extends ProxyServlet {
eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
String path = req.getPathInfo();
- if (path.startsWith("/api/")) {
+ if (path.startsWith(API)) {
if (isProxyOK(req) && isProxyServer()) {
super.doPost(req, resp);
return;
@@ -441,9 +442,9 @@ public class InternalServlet extends ProxyServlet {
}
}
- if (path.equals("/logs") || path.equals("/logs/")) {
+ if ("/logs".equals(path) || LOGS.equals(path)) {
String ctype = req.getHeader("Content-Type");
- if (ctype == null || !ctype.equals("text/plain")) {
+ if (ctype == null || !TEXT_CT.equals(ctype)) {
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
elr.setMessage("Bad media type: " + ctype);
resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -459,7 +460,7 @@ public class InternalServlet extends ProxyServlet {
}
String encoding = req.getHeader("Content-Encoding");
if (encoding != null) {
- if (encoding.trim().equals("gzip")) {
+ if ("gzip".equals(encoding.trim())) {
spoolname += ".gz";
} else {
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -477,12 +478,13 @@ public class InternalServlet extends ProxyServlet {
total += store.getTotalSpace();
avail += store.getUsableSpace();
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0136 InternalServlet.doPost: " + ioe.getMessage(), ioe);
}
}
try {
fs.close();
} catch (Exception e) {
+ intlogger.error("PROV0137 InternalServlet.doPost: " + e.getMessage(), e);
}
if (((avail * 100) / total) < 5) {
elr.setResult(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
@@ -500,15 +502,15 @@ public class InternalServlet extends ProxyServlet {
eventlogger.info(elr.toString());
LogfileLoader.getLoader(); // This starts the logfile loader "task"
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0138 InternalServlet.doPost: " + ioe.getMessage(), ioe);
}
return;
}
- if (path.equals("/drlogs") || path.equals("/drlogs/")) {
+ if ("/drlogs".equals(path) || "/drlogs/".equals(path)) {
// Receive post request and generate log entries
String ctype = req.getHeader("Content-Type");
- if (ctype == null || !ctype.equals("text/plain")) {
+ if (ctype == null || !TEXT_CT.equals(ctype)) {
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
elr.setMessage("Bad media type: " + ctype);
resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -525,17 +527,17 @@ public class InternalServlet extends ProxyServlet {
RLEBitSet bs = new RLEBitSet(bos.toString()); // The set of records to retrieve
elr.setResult(HttpServletResponse.SC_OK);
resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType("text/plain");
+ resp.setContentType(TEXT_CT);
LogRecord.printLogRecords(resp.getOutputStream(), bs);
eventlogger.info(elr.toString());
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0139 InternalServlet.doPost: " + ioe.getMessage(), ioe);
}
return;
}
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
eventlogger.error(elr.toString());
} finally {
eelfLogger.info(EelfMsgs.EXIT);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
index 77bcbddc..762ab4e5 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java
@@ -68,6 +68,12 @@ public class LogServlet extends BaseServlet {
private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);
private static final String FMT_1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final String FMT_2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+ private static final String PUBLISHSQL = "publishSQL";
+ private static final String STATUSSQL = "statusSQL";
+ private static final String RESULTSQL = "resultSQL";
+ private static final String FILENAMESQL = "filenameSQL";
+ private static final String TIMESQL = "timeSQL";
+ private static final String LOG_RECORDSSQL = "select * from LOG_RECORDS where FEEDID = ";
private final boolean isfeedlog;
@@ -226,7 +232,7 @@ public class LogServlet extends BaseServlet {
}
out.print("]");
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0141 LogServlet.doGet: " + ioe.getMessage(), ioe);
}
} finally {
eelfLogger.info(EelfMsgs.EXIT);
@@ -275,7 +281,7 @@ public class LogServlet extends BaseServlet {
Map<String, String> map = new HashMap<>();
String s = req.getParameter("type");
if (s != null) {
- if (s.equals("pub") || s.equals("del") || s.equals("exp")) {
+ if ("pub".equals(s) || "del".equals(s) || "exp".equals(s)) {
map.put("type", s);
} else {
map.put("err", "bad type");
@@ -284,11 +290,11 @@ public class LogServlet extends BaseServlet {
} else {
map.put("type", "all");
}
- map.put("publishSQL", "");
- map.put("statusSQL", "");
- map.put("resultSQL", "");
- map.put("reasonSQL", "");
- map.put("filenameSQL", "");
+ map.put(PUBLISHSQL, "");
+ map.put(STATUSSQL, "");
+ map.put(RESULTSQL, "");
+ map.put(REASON_SQL, "");
+ map.put(FILENAMESQL, "");
s = req.getParameter("publishId");
if (s != null) {
@@ -296,22 +302,22 @@ public class LogServlet extends BaseServlet {
map.put("err", "bad publishId");
return map;
}
- map.put("publishSQL", " AND PUBLISH_ID = '"+s+"'");
+ map.put(PUBLISHSQL, " AND PUBLISH_ID = '"+s+"'");
}
s = req.getParameter("filename");
if (s != null) {
- map.put("filenameSQL", " AND FILENAME = '"+s+"'");
+ map.put(FILENAMESQL, " AND FILENAME = '"+s+"'");
}
s = req.getParameter("statusCode");
if (s != null) {
String sql = null;
- if (s.equals("success")) {
+ if ("success".equals(s)) {
sql = " AND STATUS >= 200 AND STATUS < 300";
- } else if (s.equals("redirect")) {
+ } else if ("redirect".equals(s)) {
sql = " AND STATUS >= 300 AND STATUS < 400";
- } else if (s.equals("failure")) {
+ } else if ("failure".equals(s)) {
sql = " AND STATUS >= 400";
} else {
try {
@@ -325,21 +331,21 @@ public class LogServlet extends BaseServlet {
map.put("err", "bad statusCode");
return map;
}
- map.put("statusSQL", sql);
- map.put("resultSQL", sql.replaceAll("STATUS", "RESULT"));
+ map.put(STATUSSQL, sql);
+ map.put(RESULTSQL, sql.replaceAll("STATUS", "RESULT"));
}
s = req.getParameter("expiryReason");
if (s != null) {
map.put("type", "exp");
- if (s.equals("notRetryable")) {
- map.put("reasonSQL", " AND REASON = 'notRetryable'");
- } else if (s.equals("retriesExhausted")) {
- map.put("reasonSQL", " AND REASON = 'retriesExhausted'");
- } else if (s.equals("diskFull")) {
- map.put("reasonSQL", " AND REASON = 'diskFull'");
- } else if (s.equals("other")) {
- map.put("reasonSQL", " AND REASON = 'other'");
+ if ("notRetryable".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'notRetryable'");
+ } else if ("retriesExhausted".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'retriesExhausted'");
+ } else if ("diskFull".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'diskFull'");
+ } else if ("other".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'other'");
} else {
map.put("err", "bad expiryReason");
return map;
@@ -364,7 +370,7 @@ public class LogServlet extends BaseServlet {
} else if (etime == 0) {
etime = stime + TWENTYFOUR_HOURS;
}
- map.put("timeSQL", String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));
+ map.put(TIMESQL, String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));
return map;
}
private long getTimeFromParam(final String s) {
@@ -381,8 +387,7 @@ public class LogServlet extends BaseServlet {
}
try {
// Also allow a long (in ms); useful for testing
- long n = Long.parseLong(s);
- return n;
+ return Long.parseLong(s);
} catch (NumberFormatException numberFormatException) {
intlogger.error("Exception in getting Time :- "+numberFormatException.getMessage(),numberFormatException);
}
@@ -392,51 +397,51 @@ public class LogServlet extends BaseServlet {
private void getPublishRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("pub")) {
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid
+ if ("all".equals(type) || "pub".equals(type)) {
+ String sql = LOG_RECORDSSQL+feedid
+ " AND TYPE = 'pub'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL") + map.get("filenameSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(STATUSSQL) + map.get(FILENAMESQL);
getRecordsForSQL(sql, rh);
}
}
private void getDeliveryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("del")) {
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid
+ if ("all".equals(type) || "del".equals(type)) {
+ String sql = LOG_RECORDSSQL+feedid
+ " AND TYPE = 'del'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(RESULTSQL);
getRecordsForSQL(sql, rh);
}
}
private void getDeliveryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("del")) {
+ if ("all".equals(type) || "del".equals(type)) {
String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid
+ " AND TYPE = 'del'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(RESULTSQL);
getRecordsForSQL(sql, rh);
}
}
private void getExpiryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("exp")) {
- String st = map.get("statusSQL");
+ if ("all".equals(type) || "exp".equals(type)) {
+ String st = map.get(STATUSSQL);
if (st == null || st.length() == 0) {
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid
+ String sql = LOG_RECORDSSQL+feedid
+ " AND TYPE = 'exp'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(REASON_SQL);
getRecordsForSQL(sql, rh);
}
}
}
private void getExpiryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("exp")) {
- String st = map.get("statusSQL");
+ if ("all".equals(type) || "exp".equals(type)) {
+ String st = map.get(STATUSSQL);
if (st == null || st.length() == 0) {
String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid
+ " AND TYPE = 'exp'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(REASON_SQL);
getRecordsForSQL(sql, rh);
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
index a0d8664f..7c693bd2 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Main.java
@@ -102,7 +102,7 @@ public class Main {
try {
in = getClass().getClassLoader().getResourceAsStream("drProvCadi.properties");
} catch (Exception e) {
- intlogger.error("Exception in Main.getCadiProps() method ", e.getMessage());
+ intlogger.error("Exception in Main.getCadiProps(): " + e.getMessage(), e);
}
return in;
}
@@ -247,8 +247,8 @@ public class Main {
Inner obj = new Main().new Inner();
InputStream in = obj.getCadiProps();
cadiProperties.load(in);
- } catch (IOException e1) {
- intlogger.error("PROV0001 Exception loading CADI properties", e1.getMessage());
+ } catch (IOException ioe) {
+ intlogger.error("PROV0001 Exception loading CADI properties: " + ioe.getMessage(), ioe);
}
cadiProperties.setProperty("aaf_locate_url", provProperties.getProperty("org.onap.dmaap.datarouter.provserver.cadi.aaf.url", "https://aaf-onap-test.osaaf.org:8095"));
intlogger.info("PROV0001 aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
@@ -281,7 +281,7 @@ public class Main {
server.start();
intlogger.info("Prov Server started-" + server.getState());
} catch (Exception e) {
- intlogger.info("Jetty failed to start. Reporting will we unavailable", e.getMessage());
+ intlogger.info("Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e);
}
server.join();
intlogger.info("PROV0001 **** AT&T Data Router Provisioning Server halted.");
@@ -302,7 +302,7 @@ public class Main {
Thread.sleep(5000L);
System.exit(0);
} catch (Exception e) {
- intlogger.error("Exception in Main.shutdown() method " + e.getMessage());
+ intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e);
}
});
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
index b9d5e7a6..6cb8520d 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java
@@ -66,6 +66,7 @@ public class Poker extends TimerTask {
private static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";
private static final Object lock = new Object();
+ private static final String CARRIAGE_RETURN = "\n],\n";
/**
* This is a singleton -- there is only one Poker object in the server
@@ -77,6 +78,7 @@ public class Poker extends TimerTask {
private EELFLogger logger;
private String provString;
+
private Poker() {
timer1 = timer2 = 0;
Timer rolex = new Timer();
@@ -84,8 +86,8 @@ public class Poker extends TimerTask {
try {
thisPod = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
- thisPod = "*UNKNOWN*"; // not a major problem
- logger.info("UnknownHostException: Setting thisPod to \"*UNKNOWN*\"");
+ thisPod = "*UNKNOWN_POD*"; // not a major problem
+ logger.info("UnknownHostException: Setting thisPod to \"*UNKNOWN_POD*\"", e);
}
provString = buildProvisioningString();
@@ -195,10 +197,10 @@ public class Poker extends TimerTask {
} catch (MalformedURLException e) {
logger.warn(
"PROV0013 MalformedURLException Error poking node at " + nodeUrl + " : " + e
- .getMessage());
+ .getMessage(), e);
} catch (IOException e) {
logger.warn("PROV0013 IOException Error poking node at " + nodeUrl + " : " + e
- .getMessage());
+ .getMessage(), e);
}
};
r.run();
@@ -215,7 +217,7 @@ public class Poker extends TimerTask {
sb.append(f.asJSONObject().toString());
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
//Append groups to the string - Rally:US708115 - 1610
pfx = "\n";
@@ -225,7 +227,7 @@ public class Poker extends TimerTask {
sb.append(s.asJSONObject().toString());
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
// Append Subscriptions to the string
pfx = "\n";
@@ -237,13 +239,13 @@ public class Poker extends TimerTask {
}
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
// Append Parameters to the string
pfx = "\n";
sb.append("\"parameters\": {");
Map<String, String> props = Parameters.getParameters();
- Set<String> ivals = new HashSet<String>();
+ Set<String> ivals = new HashSet<>();
String intv = props.get("_INT_VALUES");
if (intv != null) {
ivals.addAll(Arrays.asList(intv.split("\\|")));
@@ -280,7 +282,7 @@ public class Poker extends TimerTask {
sb.append(in.asJSONObject().toString());
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
pfx = "\n";
sb.append("\"egress\": {");
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
index 67a74de3..75423602 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java
@@ -101,7 +101,7 @@ public class ProxyServlet extends BaseServlet {
sch = new Scheme("https", 443, socketFactory);
inited = true;
} catch (Exception e) {
- intlogger.error("ProxyServlet: " + e.getMessage());
+ intlogger.error("ProxyServlet.init: " + e.getMessage(), e);
}
intlogger.info("ProxyServlet: inited = " + inited);
}
@@ -111,7 +111,7 @@ public class ProxyServlet extends BaseServlet {
try (FileInputStream instream = new FileInputStream(new File(store))) {
ks.load(instream, pass.toCharArray());
} catch (FileNotFoundException fileNotFoundException) {
- intlogger.error("ProxyServlet: " + fileNotFoundException.getMessage());
+ intlogger.error("ProxyServlet.readStore: " + fileNotFoundException.getMessage(), fileNotFoundException);
} catch (Exception x) {
intlogger.error("READING TRUSTSTORE: " + x);
}
@@ -130,7 +130,7 @@ public class ProxyServlet extends BaseServlet {
if (t != null) {
t = t.replaceAll("&amp;", "&");
for (String s : t.split("&")) {
- if (s.equals("noproxy") || s.startsWith("noproxy=")) {
+ if ("noproxy".equals(s) || s.startsWith("noproxy=")) {
return false;
}
}
@@ -146,7 +146,7 @@ public class ProxyServlet extends BaseServlet {
*/
public boolean isProxyServer() {
SynchronizerTask st = SynchronizerTask.getSynchronizer();
- return st.getState() == SynchronizerTask.STANDBY;
+ return st.getPodState() == SynchronizerTask.STANDBY_POD;
}
/**
@@ -211,7 +211,7 @@ public class ProxyServlet extends BaseServlet {
rv = true;
} catch (IOException e) {
- intlogger.error("ProxyServlet: " + e.getMessage());
+ intlogger.error("ProxyServlet.doGetWithFallback: " + e.getMessage(), e);
} finally {
proxy.releaseConnection();
httpclient.getConnectionManager().shutdown();
@@ -234,7 +234,7 @@ public class ProxyServlet extends BaseServlet {
// Copy request headers and request body
copyRequestHeaders(req, proxy);
- if (method.equals("POST") || method.equals("PUT")) {
+ if ("POST".equals(method) || "PUT".equals(method)) {
BasicHttpEntity body = new BasicHttpEntity();
body.setContent(req.getInputStream());
body.setContentLength(-1); // -1 = unknown
@@ -250,7 +250,7 @@ public class ProxyServlet extends BaseServlet {
copyResponseHeaders(pxyResponse, resp);
copyEntityContent(pxyResponse, resp);
} catch (IOException e) {
- intlogger.warn("ProxyServlet: " + e.getMessage());
+ intlogger.warn("ProxyServlet.doProxy: " + e.getMessage(), e);
sendResponseError(resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE, "", intlogger);
} finally {
proxy.releaseConnection();
@@ -279,7 +279,7 @@ public class ProxyServlet extends BaseServlet {
List<String> list = Collections.list(from.getHeaderNames());
for (String name : list) {
// Proxy code will add this one
- if (!name.equalsIgnoreCase("Content-Length")) {
+ if (!"Content-Length".equalsIgnoreCase(name)) {
to.addHeader(name, from.getHeader(name));
}
}
@@ -288,7 +288,7 @@ public class ProxyServlet extends BaseServlet {
private void copyResponseHeaders(HttpResponse from, HttpServletResponse to) {
for (Header hdr : from.getAllHeaders()) {
// Don't copy Date: our Jetty will add another Date header
- if (!hdr.getName().equals("Date")) {
+ if (!"Date".equals(hdr.getName())) {
to.addHeader(hdr.getName(), hdr.getValue());
}
}
@@ -300,7 +300,7 @@ public class ProxyServlet extends BaseServlet {
try (InputStream in = entity.getContent()) {
IOUtils.copy(in, resp.getOutputStream());
} catch (Exception e) {
- intlogger.error("Exception: " + e.getMessage());
+ intlogger.error("ProxyServlet.copyEntityContent: " + e.getMessage(), e);
}
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
index 76a983f8..2ef5087f 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
@@ -169,7 +169,7 @@ public class PublishServlet extends BaseServlet {
}
}
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("PROV0151 PublishServlet.redirect: " + ioe.getMessage(), ioe);
}
}
@@ -235,6 +235,7 @@ public class PublishServlet extends BaseServlet {
}
return -1;
} catch (NumberFormatException | JSONException e) {
+ intlogger.debug("PROV0152 PublishServlet.checkPath: " + e.getMessage(), e);
return -1;
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
index 4dd422a0..383798fb 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java
@@ -129,6 +129,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
*/
@SuppressWarnings("serial")
public class RouteServlet extends ProxyServlet {
+
/**
* DELETE route table entries by deleting part of the route table tree.
*/
@@ -136,10 +137,10 @@ public class RouteServlet extends ProxyServlet {
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
if (isProxyOK(req) && isProxyServer()) {
@@ -150,7 +151,7 @@ public class RouteServlet extends ProxyServlet {
String path = req.getPathInfo();
String[] parts = path.substring(1).split("/");
Deleteable[] d = null;
- if (parts[0].equals("ingress")) {
+ if ("ingress".equals(parts[0])) {
if (parts.length == 4) {
// /internal/route/ingress/<feed>/<user>/<subnet>
try {
@@ -179,7 +180,7 @@ public class RouteServlet extends ProxyServlet {
sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid number of arguments in 'delete ingress' command.", eventlogger);
return;
}
- } else if (parts[0].equals("egress")) {
+ } else if ("egress".equals(parts[0])) {
if (parts.length == 2) {
// /internal/route/egress/<sub>
try {
@@ -198,7 +199,7 @@ public class RouteServlet extends ProxyServlet {
sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid number of arguments in 'delete egress' command.", eventlogger);
return;
}
- } else if (parts[0].equals("network")) {
+ } else if ("network".equals(parts[0])) {
if (parts.length == 3) {
// /internal/route/network/<from>/<to>
try {//
@@ -208,7 +209,9 @@ public class RouteServlet extends ProxyServlet {
);
d = new Deleteable[] { nr };
} catch (IllegalArgumentException e) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "The specified network route does not exist.", eventlogger);
+ String message = "The specified network route does not exist.";
+ eventlogger.error(message, e);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
return;
}
} else {
@@ -217,7 +220,7 @@ public class RouteServlet extends ProxyServlet {
}
}
if (d == null) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
return;
}
boolean rv = true;
@@ -244,10 +247,10 @@ public class RouteServlet extends ProxyServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
if (isProxyOK(req) && isProxyServer()) {
@@ -258,14 +261,14 @@ public class RouteServlet extends ProxyServlet {
String path = req.getPathInfo();
if (!path.endsWith("/"))
path += "/";
- if (!path.equals("/") && !path.equals("/ingress/") && !path.equals("/egress/") && !path.equals("/network/")) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ if (!"/".equals(path) && !INGRESS.equals(path) && !EGRESS.equals(path) && !NETWORK.equals(path)) {
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
return;
}
StringBuilder sb = new StringBuilder("{\n");
String px2 = "";
- if (path.equals("/") || path.equals("/ingress/")) {
+ if ("/".equals(path) || INGRESS.equals(path)) {
String pfx = "\n";
sb.append("\"ingress\": [");
for (IngressRoute in : IngressRoute.getAllIngressRoutes()) {
@@ -277,7 +280,7 @@ public class RouteServlet extends ProxyServlet {
px2 = ",\n";
}
- if (path.equals("/") || path.equals("/egress/")) {
+ if ("/".equals(path) || EGRESS.equals(path)) {
String pfx = "\n";
sb.append(px2);
sb.append("\"egress\": {");
@@ -289,7 +292,7 @@ public class RouteServlet extends ProxyServlet {
try {
sb.append("\"").append(jx.getString(key)).append("\"");
} catch (JSONException je) {
- eventlogger.error("JSONException" + je.getMessage());
+ eventlogger.error("PROV0161 RouteServlet.doGet: " + je.getMessage(), je);
}
pfx = ",\n";
}
@@ -298,7 +301,7 @@ public class RouteServlet extends ProxyServlet {
px2 = ",\n";
}
- if (path.equals("/") || path.equals("/network/")) {
+ if ("/".equals(path) || NETWORK.equals(path)) {
String pfx = "\n";
sb.append(px2);
sb.append("\"routing\": [");
@@ -315,7 +318,7 @@ public class RouteServlet extends ProxyServlet {
try {
resp.getOutputStream().print(sb.toString());
} catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eventlogger.error("PROV0162 RouteServlet.doGet: " + ioe.getMessage(), ioe);
}
}
/**
@@ -325,13 +328,13 @@ public class RouteServlet extends ProxyServlet {
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
}
/**
* POST - modify existing route table entries in the route table tree specified by the URL path.
@@ -340,10 +343,10 @@ public class RouteServlet extends ProxyServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
if (isProxyOK(req) && isProxyServer()) {
@@ -352,7 +355,7 @@ public class RouteServlet extends ProxyServlet {
}
String path = req.getPathInfo();
Insertable[] ins = null;
- if (path.startsWith("/ingress/")) {
+ if (path.startsWith(INGRESS)) {
// /internal/route/ingress/?feed=%s&amp;user=%s&amp;subnet=%s&amp;nodepatt=%s
try {
// Although it probably doesn't make sense, you can install two identical routes in the IRT
@@ -368,11 +371,11 @@ public class RouteServlet extends ProxyServlet {
int seq = (t != null) ? Integer.parseInt(t) : (IngressRoute.getMaxSequence() + 100);
ins = new Insertable[] { new IngressRoute(seq, feedid, user, subnet, NodeClass.lookupNodeNames(nodepatt)) };
} catch (Exception e) {
- intlogger.info(e.toString());
+ intlogger.info(e.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add ingress' command.", intlogger);
return;
}
- } else if (path.startsWith("/egress/")) {
+ } else if (path.startsWith(EGRESS)) {
// /internal/route/egress/?sub=%s&amp;node=%s
try {
int subid = Integer.parseInt(req.getParameter("sub"));
@@ -384,11 +387,11 @@ public class RouteServlet extends ProxyServlet {
String node = NodeClass.normalizeNodename(req.getParameter("node"));
ins = new Insertable[] { new EgressRoute(subid, node) };
} catch (Exception e) {
- intlogger.info(e.toString());
+ intlogger.info(e.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add egress' command.", intlogger);
return;
}
- } else if (path.startsWith("/network/")) {
+ } else if (path.startsWith(NETWORK)) {
// /internal/route/network/?from=%s&amp;to=%s&amp;via=%s
try {
String nfrom = req.getParameter("from");
@@ -410,13 +413,13 @@ public class RouteServlet extends ProxyServlet {
}
ins = new Insertable[] { nr };
} catch (IllegalArgumentException e) {
- intlogger.info(e.toString());
+ intlogger.info(e.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add network' command.", intlogger);
return;
}
}
if (ins == null) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", intlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, intlogger);
return;
}
boolean rv = true;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
index 34ba5d34..9cbce0a8 100755
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java
@@ -57,8 +57,9 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
public class StatisticsServlet extends BaseServlet {
private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);
- private static final String fmt1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
- private static final String fmt2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+ private static final String FMT1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+ private static final String FMT2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+
/**
@@ -92,97 +93,83 @@ public class StatisticsServlet extends BaseServlet {
resp.setContentType(LOGLIST_CONTENT_TYPE);
String outputType = "json";
- String feedids = null;
- if (req.getParameter("feedid") == null && req.getParameter("groupid") == null) {
+ if (req.getParameter(FEEDID) == null && req.getParameter(GROUPID) == null) {
try {
resp.getOutputStream().print("Invalid request, Feedid or Group ID is required.");
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0171 StatisticsServlet.doGet: " + ioe.getMessage(), ioe);
}
}
- if (req.getParameter("feedid") != null && req.getParameter("groupid") == null) {
- map.put("feedids", req.getParameter("feedid").replace("|", ",").toString());
+ if (req.getParameter(FEEDID) != null && req.getParameter(GROUPID) == null) {
+ map.put(FEEDIDS, req.getParameter(FEEDID).replace("|", ","));
}
- if (req.getParameter("groupid") != null && req.getParameter("feedid") == null) {
+ if (req.getParameter(GROUPID) != null && req.getParameter(FEEDID) == null) {
StringBuffer groupid1 = new StringBuffer();
try {
- System.out.println("feeedidsssssssss");
- groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter("groupid")));
- System.out.println("feeedids" + req.getParameter("groupid"));
-
- map.put("feedids", groupid1.toString());
- System.out.println("groupid1" + groupid1.toString());
-
-
+ groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter(GROUPID)));
+ map.put(FEEDIDS, groupid1.toString());
} catch (NumberFormatException | SQLException e) {
- eventlogger.error(e.getMessage());
+ eventlogger.error("PROV0172 StatisticsServlet.doGet: " + e.getMessage(), e);
}
}
- if (req.getParameter("groupid") != null && req.getParameter("feedid") != null) {
+ if (req.getParameter(GROUPID) != null && req.getParameter(FEEDID) != null) {
StringBuffer groupid1 = new StringBuffer();
try {
- System.out.println("both r not null");
- groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter("groupid")));
- System.out.println("feeedids" + req.getParameter("groupid"));
+ groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter(GROUPID)));
groupid1.append(",");
- groupid1.append(req.getParameter("feedid").replace("|", ",").toString());
-
- map.put("feedids", groupid1.toString());
-
- System.out.println("groupid1" + groupid1.toString());
-
-
+ groupid1.append(req.getParameter(FEEDID).replace("|", ","));
+ map.put(FEEDIDS, groupid1.toString());
} catch (NumberFormatException | SQLException e) {
- eventlogger.error(e.getMessage());
+ eventlogger.error("PROV0173 StatisticsServlet.doGet: " + e.getMessage(), e);
}
}
- if (req.getParameter("subid") != null && req.getParameter("feedid") != null) {
+ if (req.getParameter(SUBID) != null && req.getParameter(FEEDID) != null) {
StringBuffer subidstr = new StringBuffer();
subidstr.append("and e.DELIVERY_SUBID in(");
- subidstr.append(req.getParameter("subid").replace("|", ",").toString());
+ subidstr.append(req.getParameter(SUBID).replace("|", ","));
subidstr.append(")");
- map.put("subid", subidstr.toString());
+ map.put(SUBID, subidstr.toString());
}
- if (req.getParameter("subid") != null && req.getParameter("groupid") != null) {
+ if (req.getParameter(SUBID) != null && req.getParameter(GROUPID) != null) {
StringBuffer subidstr = new StringBuffer();
subidstr.append("and e.DELIVERY_SUBID in(");
- subidstr.append(req.getParameter("subid").replace("|", ",").toString());
+ subidstr.append(req.getParameter(SUBID).replace("|", ","));
subidstr.append(")");
- map.put("subid", subidstr.toString());
+ map.put(SUBID, subidstr.toString());
}
if (req.getParameter("type") != null) {
- map.put("eventType", req.getParameter("type").replace("|", ",").toString());
+ map.put(EVENT_TYPE, req.getParameter("type").replace("|", ","));
}
- if (req.getParameter("output_type") != null) {
- map.put("output_type", req.getParameter("output_type").toString());
+ if (req.getParameter(OUTPUT_TYPE) != null) {
+ map.put(OUTPUT_TYPE, req.getParameter(OUTPUT_TYPE));
}
- if (req.getParameter("start_time") != null) {
- map.put("start_time", req.getParameter("start_time").toString());
+ if (req.getParameter(START_TIME) != null) {
+ map.put(START_TIME, req.getParameter(START_TIME));
}
- if (req.getParameter("end_time") != null) {
- map.put("end_time", req.getParameter("end_time").toString());
+ if (req.getParameter(END_TIME) != null) {
+ map.put(END_TIME, req.getParameter(END_TIME));
}
if (req.getParameter("time") != null) {
- map.put("start_time", req.getParameter("time").toString());
- map.put("end_time", null);
+ map.put(START_TIME, req.getParameter("time"));
+ map.put(END_TIME, null);
}
- if (req.getParameter("output_type") != null) {
- outputType = req.getParameter("output_type");
+ if (req.getParameter(OUTPUT_TYPE) != null) {
+ outputType = req.getParameter(OUTPUT_TYPE);
}
try {
this.getRecordsForSQL(map, outputType, resp.getOutputStream(), resp);
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0174 StatisticsServlet.doGet: " + ioe.getMessage(), ioe);
}
}
@@ -238,7 +225,7 @@ public class StatisticsServlet extends BaseServlet {
*/
public void rsToJson(ResultSet rs, ServletOutputStream out) throws IOException, SQLException {
- String fields[] = {"FEEDNAME", "FEEDID", "FILES_PUBLISHED", "PUBLISH_LENGTH", "FILES_DELIVERED",
+ String[] fields = {"FEEDNAME", "FEEDID", "FILES_PUBLISHED", "PUBLISH_LENGTH", "FILES_DELIVERED",
"DELIVERED_LENGTH", "SUBSCRIBER_URL", "SUBID", "PUBLISH_TIME", "DELIVERY_TIME",
"AverageDelay"};
StringBuffer line = new StringBuffer();
@@ -271,7 +258,6 @@ public class StatisticsServlet extends BaseServlet {
DB db = null;
Connection conn = null;
- //PreparedStatement prepareStatement = null;
ResultSet resultSet = null;
String sqlGoupid = null;
StringBuffer feedIds = new StringBuffer();
@@ -291,7 +277,7 @@ public class StatisticsServlet extends BaseServlet {
System.out.println("feedIds" + feedIds.toString());
}
} catch (SQLException e) {
- eventlogger.error(e.getMessage());
+ eventlogger.error("PROV0175 StatisticsServlet.getFeedIdsByGroupId: " + e.getMessage(), e);
} finally {
try {
if (resultSet != null) {
@@ -302,7 +288,7 @@ public class StatisticsServlet extends BaseServlet {
db.release(conn);
}
} catch (Exception e) {
- eventlogger.error(e.getMessage());
+ eventlogger.error("PROV0176 StatisticsServlet.getFeedIdsByGroupId: " + e.getMessage(), e);
}
}
return feedIds;
@@ -322,23 +308,23 @@ public class StatisticsServlet extends BaseServlet {
String start_time = null;
String end_time = null;
String subid = " ";
- if (map.get("eventType") != null) {
- eventType = (String) map.get("eventType");
+ if (map.get(EVENT_TYPE) != null) {
+ eventType = map.get(EVENT_TYPE);
}
- if (map.get("feedids") != null) {
- feedids = (String) map.get("feedids");
+ if (map.get(FEEDIDS) != null) {
+ feedids = map.get(FEEDIDS);
}
- if (map.get("start_time") != null) {
- start_time = (String) map.get("start_time");
+ if (map.get(START_TIME) != null) {
+ start_time = map.get(START_TIME);
}
- if (map.get("end_time") != null) {
- end_time = (String) map.get("end_time");
+ if (map.get(END_TIME) != null) {
+ end_time = map.get(END_TIME);
}
if ("all".equalsIgnoreCase(eventType)) {
eventType = "PUB','DEL, EXP, PBF";
}
- if (map.get("subid") != null) {
- subid = (String) map.get("subid");
+ if (map.get(SUBID) != null) {
+ subid = map.get(SUBID);
}
eventlogger.info("Generating sql query to get Statistics resultset. ");
@@ -425,10 +411,10 @@ public class StatisticsServlet extends BaseServlet {
}
private Map<String, String> buildMapFromRequest(HttpServletRequest req) {
- Map<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<>();
String s = req.getParameter("type");
if (s != null) {
- if (s.equals("pub") || s.equals("del") || s.equals("exp")) {
+ if ("pub".equals(s) || "del".equals(s) || "exp".equals(s)) {
map.put("type", s);
} else {
map.put("err", "bad type");
@@ -440,7 +426,7 @@ public class StatisticsServlet extends BaseServlet {
map.put("publishSQL", "");
map.put("statusSQL", "");
map.put("resultSQL", "");
- map.put("reasonSQL", "");
+ map.put(REASON_SQL, "");
s = req.getParameter("publishId");
if (s != null) {
@@ -454,11 +440,11 @@ public class StatisticsServlet extends BaseServlet {
s = req.getParameter("statusCode");
if (s != null) {
String sql = null;
- if (s.equals("success")) {
+ if ("success".equals(s)) {
sql = " AND STATUS >= 200 AND STATUS < 300";
- } else if (s.equals("redirect")) {
+ } else if ("redirect".equals(s)) {
sql = " AND STATUS >= 300 AND STATUS < 400";
- } else if (s.equals("failure")) {
+ } else if ("failure".equals(s)) {
sql = " AND STATUS >= 400";
} else {
try {
@@ -480,14 +466,14 @@ public class StatisticsServlet extends BaseServlet {
s = req.getParameter("expiryReason");
if (s != null) {
map.put("type", "exp");
- if (s.equals("notRetryable")) {
- map.put("reasonSQL", " AND REASON = 'notRetryable'");
- } else if (s.equals("retriesExhausted")) {
- map.put("reasonSQL", " AND REASON = 'retriesExhausted'");
- } else if (s.equals("diskFull")) {
- map.put("reasonSQL", " AND REASON = 'diskFull'");
- } else if (s.equals("other")) {
- map.put("reasonSQL", " AND REASON = 'other'");
+ if ("notRetryable".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'notRetryable'");
+ } else if ("retriesExhausted".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'retriesExhausted'");
+ } else if ("diskFull".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'diskFull'");
+ } else if ("other".equals("other")) {
+ map.put(REASON_SQL, " AND REASON = 'other'");
} else {
map.put("err", "bad expiryReason");
return map;
@@ -522,7 +508,7 @@ public class StatisticsServlet extends BaseServlet {
}
try {
// First, look for an RFC 3339 date
- String fmt = (s.indexOf('.') > 0) ? fmt2 : fmt1;
+ String fmt = (s.indexOf('.') > 0) ? FMT2 : FMT1;
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
Date d = sdf.parse(s);
return d.getTime();
@@ -530,8 +516,7 @@ public class StatisticsServlet extends BaseServlet {
}
try {
// Also allow a long (in ms); useful for testing
- long n = Long.parseLong(s);
- return n;
+ return Long.parseLong(s);
} catch (NumberFormatException e) {
}
intlogger.info("Error parsing time=" + s);
@@ -548,7 +533,7 @@ public class StatisticsServlet extends BaseServlet {
DB db = new DB();
try (Connection conn = db.getConnection()) {
try (ResultSet rs = conn.prepareStatement(filterQuery).executeQuery()) {
- if (outputType.equals("csv")) {
+ if ("csv".equals(outputType)) {
resp.setContentType("application/octet-stream");
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
index 69451a3b..8e70e693 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java
@@ -112,7 +112,7 @@ public class SubscribeServlet extends ProxyServlet {
}
int feedid = getIdFromPath(req);
if (feedid < 0) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -121,7 +121,7 @@ public class SubscribeServlet extends ProxyServlet {
}
Feed feed = Feed.getFeedById(feedid);
if (feed == null || feed.isDeleted()) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -140,7 +140,7 @@ public class SubscribeServlet extends ProxyServlet {
try {
resp.getOutputStream().print(t);
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0181 SubscribeServlet.doGet: " + ioe.getMessage(), ioe);
}
} finally {
eelfLogger.info(EelfMsgs.EXIT);
@@ -201,7 +201,7 @@ public class SubscribeServlet extends ProxyServlet {
}
int feedid = getIdFromPath(req);
if (feedid < 0) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -210,7 +210,7 @@ public class SubscribeServlet extends ProxyServlet {
}
Feed feed = Feed.getFeedById(feedid);
if (feed == null || feed.isDeleted()) {
- message = "Missing or bad feed number.";
+ message = MISSING_FEED;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -220,7 +220,7 @@ public class SubscribeServlet extends ProxyServlet {
// check content type is SUB_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+ if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
intlogger.debug("Content-type is: " + req.getHeader("Content-Type"));
message = "Incorrect content-type";
elr.setMessage(message);
@@ -231,7 +231,7 @@ public class SubscribeServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -258,7 +258,7 @@ public class SubscribeServlet extends ProxyServlet {
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
@@ -271,14 +271,14 @@ public class SubscribeServlet extends ProxyServlet {
*/
String feedAafInstance = feed.getAafInstance();
String subAafInstance = sub.getAafInstance();
- boolean subAafLegacyEmptyOrNull = (subAafInstance == null || subAafInstance.equals("") || subAafInstance.equalsIgnoreCase("legacy"));
+ boolean subAafLegacyEmptyOrNull = (subAafInstance == null || "".equals(subAafInstance) || "legacy".equalsIgnoreCase(subAafInstance));
// This extra check added to verify AAF feed with AAF subscriber having empty aaf instance check
- if (feedAafInstance == null || feedAafInstance.equals("") || feedAafInstance.equalsIgnoreCase("legacy")) {
+ if (feedAafInstance == null || "".equals(feedAafInstance) || "legacy".equalsIgnoreCase(feedAafInstance)) {
if (subAafLegacyEmptyOrNull) {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -299,7 +299,7 @@ public class SubscribeServlet extends ProxyServlet {
if (subAafLegacyEmptyOrNull) {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -341,7 +341,7 @@ public class SubscribeServlet extends ProxyServlet {
try {
resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0182 SubscribeServlet.doPost: " + ioe.getMessage(), ioe);
}
provisioningDataChanged();
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
index 63ff84de..125c50d8 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
@@ -63,6 +63,10 @@ public class SubscriptionServlet extends ProxyServlet {
private static EELFLogger eelfLogger = EELFManager.getInstance()
.getLogger(SubscriptionServlet.class);
+
+
+
+
/**
* DELETE on the &lt;subscriptionUrl&gt; -- delete a subscription. See the <i>Deleting a Subscription</i> section in
* the <b>Provisioning API</b> document for details on how this method should be invoked.
@@ -88,7 +92,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -97,7 +101,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
int subid = getIdFromPath(req);
if (subid < 0) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -106,7 +110,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
Subscription sub = Subscription.getSubscriptionById(subid);
if (sub == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -119,10 +123,10 @@ public class SubscriptionServlet extends ProxyServlet {
* CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove subscription
*/
String aafInstance = sub.getAafInstance();
- if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+ if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -189,7 +193,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -198,7 +202,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
int subid = getIdFromPath(req);
if (subid < 0) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -207,7 +211,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
Subscription sub = Subscription.getSubscriptionById(subid);
if (sub == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -217,7 +221,7 @@ public class SubscriptionServlet extends ProxyServlet {
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -233,7 +237,7 @@ public class SubscriptionServlet extends ProxyServlet {
try {
resp.getOutputStream().print(sub.asJSONObject(true).toString());
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0191 SubscriptionServlet.doGet: " + ioe.getMessage(), ioe);
}
} finally {
eelfLogger.info(EelfMsgs.EXIT);
@@ -265,7 +269,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -274,7 +278,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
int subid = getIdFromPath(req);
if (subid < 0) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -283,7 +287,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
Subscription oldsub = Subscription.getSubscriptionById(subid);
if (oldsub == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -293,7 +297,7 @@ public class SubscriptionServlet extends ProxyServlet {
// check content type is SUB_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+ if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -303,7 +307,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -320,7 +324,7 @@ public class SubscriptionServlet extends ProxyServlet {
message = e.getMessage();
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
@@ -331,10 +335,10 @@ public class SubscriptionServlet extends ProxyServlet {
* CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove subscription
*/
String aafInstance = sub.getAafInstance();
- if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+ if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -380,7 +384,7 @@ public class SubscriptionServlet extends ProxyServlet {
try {
resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
} catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ eventlogger.error("PROV0192 SubscriptionServlet.doPut: " + ioe.getMessage(), ioe);
}
/**Change Owner ship of Subscriber Adding for group feature:Rally US708115*/
@@ -392,7 +396,7 @@ public class SubscriptionServlet extends ProxyServlet {
sub.changeOwnerShip();
}
} catch (JSONException je) {
- eventlogger.error("JSONException: " + je.getMessage());
+ eventlogger.error("PROV0193 SubscriptionServlet.doPut: " + je.getMessage(), je);
}
}
/***End of change ownership*/
@@ -435,7 +439,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -444,7 +448,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
final int subid = getIdFromPath(req);
if (subid < 0 || Subscription.getSubscriptionById(subid) == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -454,7 +458,7 @@ public class SubscriptionServlet extends ProxyServlet {
// check content type is SUBCNTRL_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(SUBCNTRL_CONTENT_TYPE) || !ver.equals("1.0")) {
+ if (!ch.getType().equals(SUBCNTRL_CONTENT_TYPE) || !"1.0".equals(ver)) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -465,7 +469,7 @@ public class SubscriptionServlet extends ProxyServlet {
// Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -474,7 +478,7 @@ public class SubscriptionServlet extends ProxyServlet {
}
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -496,10 +500,10 @@ public class SubscriptionServlet extends ProxyServlet {
eventlogger.info(elr.toString());
resp.setStatus(HttpServletResponse.SC_ACCEPTED);
} catch (JSONException e) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.error(elr.toString());
+ eventlogger.error(elr.toString(), e);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
}
} finally {
@@ -514,7 +518,7 @@ public class SubscriptionServlet extends ProxyServlet {
public class SubscriberNotifyThread extends Thread {
public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";
- private List<String> urls = new Vector<String>();
+ private List<String> urls = new Vector<>();
public SubscriberNotifyThread() {
setName("SubscriberNotifyThread");
@@ -527,7 +531,9 @@ public class SubscriptionServlet extends ProxyServlet {
}
}
+ @Override
public void run() {
+
try {
while (!urls.isEmpty()) {
String u = urls.remove(0);
@@ -538,11 +544,11 @@ public class SubscriptionServlet extends ProxyServlet {
conn.getContentLength(); // Force the GET through
conn.disconnect();
} catch (IOException e) {
- intlogger.info("IOException Error accessing URL: " + u + ": " + e.getMessage());
+ intlogger.info("PROV0194 Error accessing URL: " + u + ": " + e.getMessage(), e);
}
}
} catch (Exception e) {
- intlogger.warn("Caught exception in SubscriberNotifyThread: " + e.getMessage());
+ intlogger.warn("PROV0195 Caught exception in SubscriberNotifyThread: " + e.getMessage(), e);
}
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
index 3097a9db..8c5a49a4 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java
@@ -24,6 +24,11 @@
package org.onap.dmaap.datarouter.provisioning;
+import static org.onap.dmaap.datarouter.provisioning.BaseServlet.TEXT_CT;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -50,8 +55,6 @@ import java.util.TreeSet;
import javax.servlet.http.HttpServletResponse;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
@@ -85,7 +88,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
* <li>Checking DNS once per minute to see which POD the DNS CNAME points to. The CNAME will point to
* the active (master) POD.</li>
* <li>On non-master (standby) PODs, fetches provisioning data and logs in order to keep MariaDB in sync.</li>
- * <li>Providing information to other parts of the system as to the current role (ACTIVE, STANDBY, UNKNOWN)
+ * <li>Providing information to other parts of the system as to the current role (ACTIVE_POD, STANDBY_POD, UNKNOWN_POD)
* of this POD.</li>
* </ol>
* <p>For this to work correctly, the following code needs to be placed at the beginning of main().</p>
@@ -99,167 +102,152 @@ import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
public class SynchronizerTask extends TimerTask {
/**
- * This is a singleton -- there is only one SynchronizerTask object in the server
+ * This is a singleton -- there is only one SynchronizerTask object in the server.
*/
private static SynchronizerTask synctask;
/**
- * This POD is unknown -- not on the list of PODs
+ * This POD is unknown -- not on the list of PODs.
*/
- public static final int UNKNOWN = 0;
+ public static final int UNKNOWN_POD = 0;
/**
- * This POD is active -- on the list of PODs, and the DNS CNAME points to us
+ * This POD is active -- on the list of PODs, and the DNS CNAME points to us.
*/
- public static final int ACTIVE = 1;
+ public static final int ACTIVE_POD = 1;
/**
- * This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us
+ * This POD is standby -- on the list of PODs, and the DNS CNAME does not point to us.
*/
- public static final int STANDBY = 2;
- private static final String[] stnames = {"UNKNOWN", "ACTIVE", "STANDBY"};
+ public static final int STANDBY_POD = 2;
+
+ private static final String[] stnames = {"UNKNOWN_POD", "ACTIVE_POD", "STANDBY_POD"};
private static final long ONE_HOUR = 60 * 60 * 1000L;
+ private long nextMsg = 0; // only display the "Current podState" msg every 5 mins.
+
private final EELFLogger logger;
private final Timer rolex;
private final String spooldir;
- private int state;
+ private int podState;
private boolean doFetch;
private long nextsynctime;
private AbstractHttpClient httpclient = null;
- /**
- * Get the singleton SynchronizerTask object.
- *
- * @return the SynchronizerTask
- */
- public static synchronized SynchronizerTask getSynchronizer() {
- if (synctask == null) {
- synctask = new SynchronizerTask();
- }
- return synctask;
- }
-
@SuppressWarnings("deprecation")
private SynchronizerTask() {
logger = EELFManager.getInstance().getLogger("InternalLog");
rolex = new Timer();
spooldir = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
- state = UNKNOWN;
+ podState = UNKNOWN_POD;
doFetch = true; // start off with a fetch
nextsynctime = 0;
- logger.info("PROV5000: Sync task starting, server state is UNKNOWN");
+ logger.info("PROV5000: Sync task starting, server podState is UNKNOWN_POD");
try {
Properties props = (new DB()).getProperties();
String type = props.getProperty(Main.KEYSTORE_TYPE_PROPERTY, "jks");
String store = props.getProperty(Main.KEYSTORE_PATH_PROPERTY);
String pass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
KeyStore keyStore = KeyStore.getInstance(type);
- try(FileInputStream instream = new FileInputStream(new File(store))) {
+ try (FileInputStream instream = new FileInputStream(new File(store))) {
keyStore.load(instream, pass.toCharArray());
}
- store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
- pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
- KeyStore trustStore = null;
- if (store != null && store.length() > 0) {
- trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
- try(FileInputStream instream = new FileInputStream(new File(store))){
- trustStore.load(instream, pass.toCharArray());
+ store = props.getProperty(Main.TRUSTSTORE_PATH_PROPERTY);
+ pass = props.getProperty(Main.TRUSTSTORE_PASS_PROPERTY);
+ KeyStore trustStore = null;
+ if (store != null && store.length() > 0) {
+ trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
+ try (FileInputStream instream = new FileInputStream(new File(store))) {
+ trustStore.load(instream, pass.toCharArray());
- }
}
+ }
// We are connecting with the node name, but the certificate will have the CNAME
// So we need to accept a non-matching certificate name
- String keystorepass = props.getProperty(
- Main.KEYSTORE_PASS_PROPERTY); //itrack.web.att.com/browse/DATARTR-6 for changing hard coded passphase ref
- try(AbstractHttpClient hc = new DefaultHttpClient()) {
- SSLSocketFactory socketFactory =
- (trustStore == null)
- ? new SSLSocketFactory(keyStore, keystorepass)
- : new SSLSocketFactory(keyStore, keystorepass, trustStore);
- socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
- Scheme sch = new Scheme("https", 443, socketFactory);
- hc.getConnectionManager().getSchemeRegistry().register(sch);
- httpclient = hc;
- }
- // Run once every 5 seconds to check DNS, etc.
- long interval = 0;
- try {
- String s = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000");
- interval = Long.parseLong(s);
- } catch (NumberFormatException e) {
- interval = 5000L;
+ String keystorepass = props.getProperty(Main.KEYSTORE_PASS_PROPERTY);
+ try (AbstractHttpClient hc = new DefaultHttpClient()) {
+ SSLSocketFactory socketFactory =
+ (trustStore == null)
+ ? new SSLSocketFactory(keyStore, keystorepass)
+ : new SSLSocketFactory(keyStore, keystorepass, trustStore);
+ socketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+ Scheme sch = new Scheme("https", 443, socketFactory);
+ hc.getConnectionManager().getSchemeRegistry().register(sch);
+ httpclient = hc;
}
- rolex.scheduleAtFixedRate(this, 0L, interval);
+ setSynchTimer(props);
} catch (Exception e) {
logger.warn("PROV5005: Problem starting the synchronizer: " + e);
}
}
+ private void setSynchTimer(Properties props) {
+ // Run once every 5 seconds to check DNS, etc.
+ long interval;
+ try {
+ String s = props.getProperty("org.onap.dmaap.datarouter.provserver.sync_interval", "5000");
+ interval = Long.parseLong(s);
+ } catch (NumberFormatException e) {
+ interval = 5000L;
+ }
+ rolex.scheduleAtFixedRate(this, 0L, interval);
+ }
+
+ /**
+ * Get the singleton SynchronizerTask object.
+ *
+ * @return the SynchronizerTask
+ */
+ public static synchronized SynchronizerTask getSynchronizer() {
+ if (synctask == null) {
+ synctask = new SynchronizerTask();
+ }
+ return synctask;
+ }
+
/**
- * What is the state of this POD?
+ * What is the podState of this POD?.
*
- * @return one of ACTIVE, STANDBY, UNKNOWN
+ * @return one of ACTIVE_POD, STANDBY_POD, UNKNOWN_POD
*/
- public int getState() {
- return state;
+ public int getPodState() {
+ return podState;
}
/**
- * Is this the active POD?
+ * Is this the active POD?.
*
* @return true if we are active (the master), false otherwise
*/
public boolean isActive() {
- return state == ACTIVE;
+ return podState == ACTIVE_POD;
}
/**
* This method is used to signal that another POD (the active POD) has sent us a /fetchProv request, and that we
* should re-synchronize with the master.
*/
- public void doFetch() {
+ void doFetch() {
doFetch = true;
}
/**
* Runs once a minute in order to <ol>
* <li>lookup DNS names,</li>
- * <li>determine the state of this POD,</li>
- * <li>if this is a standby POD, and the fetch flag is set, perform a fetch of state from the active POD.</li>
+ * <li>determine the podState of this POD,</li>
+ * <li>if this is a standby POD, and the fetch flag is set, perform a fetch of podState from the active POD.</li>
* <li>if this is a standby POD, check if there are any new log records to be replicated.</li>
- * </ol>
+ * </ol>.
*/
@Override
public void run() {
try {
- state = lookupState();
- if (state == STANDBY) {
+ podState = lookupState();
+ if (podState == STANDBY_POD) {
// Only copy provisioning data FROM the active server TO the standby
if (doFetch || (System.currentTimeMillis() >= nextsynctime)) {
- logger.debug("Initiating a sync...");
- JSONObject jo = readProvisioningJSON();
- if (jo != null) {
- doFetch = false;
- syncFeeds(jo.getJSONArray("feeds"));
- syncSubs(jo.getJSONArray("subscriptions"));
- syncGroups(jo.getJSONArray("groups")); //Rally:US708115 - 1610
- syncParams(jo.getJSONObject("parameters"));
- // The following will not be present in a version=1.0 provfeed
- JSONArray ja = jo.optJSONArray("ingress");
- if (ja != null) {
- syncIngressRoutes(ja);
- }
- JSONObject j2 = jo.optJSONObject("egress");
- if (j2 != null) {
- syncEgressRoutes(j2);
- }
- ja = jo.optJSONArray("routing");
- if (ja != null) {
- syncNetworkRoutes(ja);
- }
- }
+ syncProvisioningData();
logger.info("PROV5013: Sync completed.");
nextsynctime = System.currentTimeMillis() + ONE_HOUR;
}
@@ -278,7 +266,7 @@ public class SynchronizerTask extends TimerTask {
remote.andNot(local);
if (!remote.isEmpty()) {
logger.debug(" Replicating logs: " + remote);
- replicateDRLogs(remote);
+ replicateDataRouterLogs(remote);
}
}
} catch (Exception e) {
@@ -286,14 +274,39 @@ public class SynchronizerTask extends TimerTask {
}
}
+ private void syncProvisioningData() {
+ logger.debug("Initiating a sync...");
+ JSONObject jo = readProvisioningJson();
+ if (jo != null) {
+ doFetch = false;
+ syncFeeds(jo.getJSONArray("feeds"));
+ syncSubs(jo.getJSONArray("subscriptions"));
+ syncGroups(jo.getJSONArray("groups")); //Rally:US708115 - 1610
+ syncParams(jo.getJSONObject("parameters"));
+ // The following will not be present in a version=1.0 provfeed
+ JSONArray ja = jo.optJSONArray("ingress");
+ if (ja != null) {
+ syncIngressRoutes(ja);
+ }
+ JSONObject j2 = jo.optJSONObject("egress");
+ if (j2 != null) {
+ syncEgressRoutes(j2);
+ }
+ ja = jo.optJSONArray("routing");
+ if (ja != null) {
+ syncNetworkRoutes(ja);
+ }
+ }
+ }
+
/**
- * This method is used to lookup the CNAME that points to the active server. It returns 0 (UNKNOWN), 1(ACTIVE), or 2
- * (STANDBY) to indicate the state of this server.
+ * This method is used to lookup the CNAME that points to the active server.
+ * It returns 0 (UNKNOWN_POD), 1(ACTIVE_POD), or (STANDBY_POD) to indicate the podState of this server.
*
- * @return the current state
+ * @return the current podState
*/
- private int lookupState() {
- int newstate = UNKNOWN;
+ int lookupState() {
+ int newPodState = UNKNOWN_POD;
try {
InetAddress myaddr = InetAddress.getLocalHost();
if (logger.isTraceEnabled()) {
@@ -303,27 +316,25 @@ public class SynchronizerTask extends TimerTask {
Set<String> pods = new TreeSet<>(Arrays.asList(BaseServlet.getPods()));
if (pods.contains(thisPod)) {
InetAddress pserver = InetAddress.getByName(BaseServlet.getActiveProvName());
- newstate = myaddr.equals(pserver) ? ACTIVE : STANDBY;
+ newPodState = myaddr.equals(pserver) ? ACTIVE_POD : STANDBY_POD;
if (logger.isDebugEnabled() && System.currentTimeMillis() >= nextMsg) {
- logger.debug("Active POD = " + pserver + ", Current state is " + stnames[newstate]);
+ logger.debug("Active POD = " + pserver + ", Current podState is " + stnames[newPodState]);
nextMsg = System.currentTimeMillis() + (5 * 60 * 1000L);
}
} else {
logger.warn("PROV5003: My name (" + thisPod + ") is missing from the list of provisioning servers.");
}
} catch (UnknownHostException e) {
- logger.warn("PROV5002: Cannot determine the name of this provisioning server.");
+ logger.warn("PROV5002: Cannot determine the name of this provisioning server.", e);
}
- if (newstate != state) {
- logger
- .info(String.format("PROV5001: Server state changed from %s to %s", stnames[state], stnames[newstate]));
+ if (newPodState != podState) {
+ logger.info(String.format("PROV5001: Server podState changed from %s to %s",
+ stnames[podState], stnames[newPodState]));
}
- return newstate;
+ return newPodState;
}
- private static long nextMsg = 0; // only display the "Current state" msg every 5 mins.
-
/**
* Synchronize the Feeds in the JSONArray, with the Feeds in the DB.
*/
@@ -334,7 +345,7 @@ public class SynchronizerTask extends TimerTask {
Feed f = new Feed(ja.getJSONObject(n));
coll.add(f);
} catch (Exception e) {
- logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in feed: " + ja.optJSONObject(n), e);
}
}
if (sync(coll, Feed.getAllFeeds())) {
@@ -355,7 +366,7 @@ public class SynchronizerTask extends TimerTask {
Subscription s = new Subscription(j);
coll.add(s);
} catch (Exception e) {
- logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n), e);
}
}
if (sync(coll, Subscription.getAllSubscriptions())) {
@@ -373,7 +384,7 @@ public class SynchronizerTask extends TimerTask {
Group g = new Group(ja.getJSONObject(n));
coll.add(g);
} catch (Exception e) {
- logger.warn("PROV5004: Invalid object in subscription: " + ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in group: " + ja.optJSONObject(n), e);
}
}
if (sync(coll, Group.getAllgroups())) {
@@ -392,9 +403,11 @@ public class SynchronizerTask extends TimerTask {
try {
v = jo.getString(k);
} catch (JSONException e) {
+ logger.warn("PROV5004: Invalid object in parameters: " + jo.optJSONObject(k), e);
try {
v = "" + jo.getInt(k);
} catch (JSONException e1) {
+ logger.warn("PROV5004: Invalid object in parameters: " + jo.optInt(k), e1);
JSONArray ja = jo.getJSONArray(k);
for (int i = 0; i < ja.length(); i++) {
if (i > 0) {
@@ -436,9 +449,9 @@ public class SynchronizerTask extends TimerTask {
EgressRoute er = new EgressRoute(sub, node);
coll.add(er);
} catch (NumberFormatException e) {
- logger.warn("PROV5004: Invalid subid in egress routes: " + key);
+ logger.warn("PROV5004: Invalid subid in egress routes: " + key, e);
} catch (IllegalArgumentException e) {
- logger.warn("PROV5004: Invalid node name in egress routes: " + key);
+ logger.warn("PROV5004: Invalid node name in egress routes: " + key, e);
}
}
if (sync(coll, EgressRoute.getAllEgressRoutes())) {
@@ -453,7 +466,7 @@ public class SynchronizerTask extends TimerTask {
NetworkRoute nr = new NetworkRoute(ja.getJSONObject(n));
coll.add(nr);
} catch (JSONException e) {
- logger.warn("PROV5004: Invalid object in network routes: " + ja.optJSONObject(n));
+ logger.warn("PROV5004: Invalid object in network routes: " + ja.optJSONObject(n), e);
}
}
if (sync(coll, NetworkRoute.getAllNetworkRoutes())) {
@@ -475,29 +488,11 @@ public class SynchronizerTask extends TimerTask {
Syncable newobj = newmap.get(n);
Syncable oldobj = oldmap.get(n);
if (oldobj == null) {
- if (logger.isDebugEnabled()) {
- logger.debug(" Inserting record: " + newobj);
- }
- newobj.doInsert(conn);
- changes = true;
+ changes = insertRecord(conn, newobj);
} else if (newobj == null) {
- if (logger.isDebugEnabled()) {
- logger.debug(" Deleting record: " + oldobj);
- }
- oldobj.doDelete(conn);
- changes = true;
+ changes = deleteRecord(conn, oldobj);
} else if (!newobj.equals(oldobj)) {
- if (logger.isDebugEnabled()) {
- logger.debug(" Updating record: " + newobj);
- }
- newobj.doUpdate(conn);
-
- /**Rally US708115
- * Change Ownership of FEED - 1610, Syncronised with secondary DB.
- * */
- checkChnageOwner(newobj, oldobj);
-
- changes = true;
+ changes = updateRecord(conn, newobj, oldobj);
}
}
db.release(conn);
@@ -507,6 +502,30 @@ public class SynchronizerTask extends TimerTask {
return changes;
}
+ private boolean updateRecord(Connection conn, Syncable newobj, Syncable oldobj) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(" Updating record: " + newobj);
+ }
+ boolean changes = newobj.doUpdate(conn);
+ checkChangeOwner(newobj, oldobj);
+
+ return changes;
+ }
+
+ private boolean deleteRecord(Connection conn, Syncable oldobj) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(" Deleting record: " + oldobj);
+ }
+ return oldobj.doDelete(conn);
+ }
+
+ private boolean insertRecord(Connection conn, Syncable newobj) {
+ if (logger.isDebugEnabled()) {
+ logger.debug(" Inserting record: " + newobj);
+ }
+ return newobj.doInsert(conn);
+ }
+
private Map<String, Syncable> getMap(Collection<? extends Syncable> c) {
Map<String, Syncable> map = new HashMap<>();
for (Syncable v : c) {
@@ -515,18 +534,18 @@ public class SynchronizerTask extends TimerTask {
return map;
}
- /**Change owner of FEED/SUBSCRIPTION*/
/**
+ * Change owner of FEED/SUBSCRIPTION.
* Rally US708115 Change Ownership of FEED - 1610
*/
- private void checkChnageOwner(Syncable newobj, Syncable oldobj) {
+ private void checkChangeOwner(Syncable newobj, Syncable oldobj) {
if (newobj instanceof Feed) {
Feed oldfeed = (Feed) oldobj;
Feed newfeed = (Feed) newobj;
if (!oldfeed.getPublisher().equals(newfeed.getPublisher())) {
- logger.info("PROV5013 - Previous publisher: " + oldfeed.getPublisher() + ": New publisher-" + newfeed
- .getPublisher());
+ logger.info("PROV5013 - Previous publisher: "
+ + oldfeed.getPublisher() + ": New publisher-" + newfeed.getPublisher());
oldfeed.setPublisher(newfeed.getPublisher());
oldfeed.changeOwnerShip();
}
@@ -535,8 +554,8 @@ public class SynchronizerTask extends TimerTask {
Subscription newsub = (Subscription) newobj;
if (!oldsub.getSubscriber().equals(newsub.getSubscriber())) {
- logger.info("PROV5013 - Previous subscriber: " + oldsub.getSubscriber() + ": New subscriber-" + newsub
- .getSubscriber());
+ logger.info("PROV5013 - Previous subscriber: "
+ + oldsub.getSubscriber() + ": New subscriber-" + newsub.getSubscriber());
oldsub.setSubscriber(newsub.getSubscriber());
oldsub.changeOwnerShip();
}
@@ -549,26 +568,26 @@ public class SynchronizerTask extends TimerTask {
*
* @return the provisioning data (as a JONObject)
*/
- private synchronized JSONObject readProvisioningJSON() {
+ private synchronized JSONObject readProvisioningJson() {
String url = URLUtilities.generatePeerProvURL();
HttpGet get = new HttpGet(url);
try {
HttpResponse response = httpclient.execute(get);
int code = response.getStatusLine().getStatusCode();
if (code != HttpServletResponse.SC_OK) {
- logger.warn("PROV5010: readProvisioningJSON failed, bad error code: " + code);
+ logger.warn("PROV5010: readProvisioningJson failed, bad error code: " + code);
return null;
}
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
- if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1) && !ctype
- .equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
- logger.warn("PROV5011: readProvisioningJSON failed, bad content type: " + ctype);
+ if (!ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE1)
+ && !ctype.equals(BaseServlet.PROVFULL_CONTENT_TYPE2)) {
+ logger.warn("PROV5011: readProvisioningJson failed, bad content type: " + ctype);
return null;
}
return new JSONObject(new JSONTokener(entity.getContent()));
} catch (Exception e) {
- logger.warn("PROV5012: readProvisioningJSON failed, exception: " + e);
+ logger.warn("PROV5012: readProvisioningJson failed, exception: " + e);
return null;
} finally {
get.releaseConnection();
@@ -581,18 +600,18 @@ public class SynchronizerTask extends TimerTask {
*
* @return the bitset
*/
- private RLEBitSet readRemoteLoglist() {
+ RLEBitSet readRemoteLoglist() {
RLEBitSet bs = new RLEBitSet();
String url = URLUtilities.generatePeerLogsURL();
//Fixing if only one Prov is configured, not to give exception to fill logs, return empty bitset.
- if (url.equals("")) {
+ if ("".equals(url)) {
return bs;
}
//End of fix.
HttpGet get = new HttpGet(url);
- try {
+ try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
HttpResponse response = httpclient.execute(get);
int code = response.getStatusLine().getStatusCode();
if (code != HttpServletResponse.SC_OK) {
@@ -601,13 +620,12 @@ public class SynchronizerTask extends TimerTask {
}
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
- if (!ctype.equals("text/plain")) {
+ if (!TEXT_CT.equals(ctype)) {
logger.warn("PROV5011: readRemoteLoglist failed, bad content type: " + ctype);
return bs;
}
InputStream is = entity.getContent();
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- int ch = 0;
+ int ch;
while ((ch = is.read()) >= 0) {
bos.write(ch);
}
@@ -628,12 +646,12 @@ public class SynchronizerTask extends TimerTask {
*
* @param bs the bitset (an RELBitSet) of log records to fetch
*/
- private void replicateDRLogs(RLEBitSet bs) {
+ void replicateDataRouterLogs(RLEBitSet bs) {
String url = URLUtilities.generatePeerLogsURL();
HttpPost post = new HttpPost(url);
try {
String t = bs.toString();
- HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create("text/plain"));
+ HttpEntity body = new ByteArrayEntity(t.getBytes(), ContentType.create(TEXT_CT));
post.setEntity(body);
if (logger.isDebugEnabled()) {
logger.debug("Requesting records: " + t);
@@ -642,13 +660,13 @@ public class SynchronizerTask extends TimerTask {
HttpResponse response = httpclient.execute(post);
int code = response.getStatusLine().getStatusCode();
if (code != HttpServletResponse.SC_OK) {
- logger.warn("PROV5010: replicateDRLogs failed, bad error code: " + code);
+ logger.warn("PROV5010: replicateDataRouterLogs failed, bad error code: " + code);
return;
}
HttpEntity entity = response.getEntity();
String ctype = entity.getContentType().getValue().trim();
- if (!ctype.equals("text/plain")) {
- logger.warn("PROV5011: replicateDRLogs failed, bad content type: " + ctype);
+ if (!TEXT_CT.equals(ctype)) {
+ logger.warn("PROV5011: replicateDataRouterLogs failed, bad content type: " + ctype);
return;
}
@@ -659,7 +677,7 @@ public class SynchronizerTask extends TimerTask {
Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
logger.info("Approximately " + bs.cardinality() + " records replicated.");
} catch (Exception e) {
- logger.warn("PROV5012: replicateDRLogs failed, exception: " + e);
+ logger.warn("PROV5012: replicateDataRouterLogs failed, exception: " + e);
} finally {
post.releaseConnection();
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryExtraRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryExtraRecord.java
index 2a959f3d..0e5342a6 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryExtraRecord.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/DeliveryExtraRecord.java
@@ -44,12 +44,7 @@ public class DeliveryExtraRecord extends BaseLogRecord {
this.subid = Integer.parseInt(pp[4]);
this.contentLength2 = Long.parseLong(pp[6]);
}
- public DeliveryExtraRecord(ResultSet rs) throws SQLException {
- super(rs);
- // Note: because this record should be "rare" these fields are mapped to unconventional fields in the DB
- this.subid = rs.getInt("DELIVERY_SUBID");
- this.contentLength2 = rs.getInt("CONTENT_LENGTH_2");
- }
+
@Override
public void load(PreparedStatement ps) throws SQLException {
ps.setString(1, "dlx"); // field 1: type
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
index 12135969..e766e704 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/EgressRoute.java
@@ -47,6 +47,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+ private static final String SQLEXCEPTION = "SQLException: ";
private final int subid;
private final int nodeid;
@@ -57,7 +58,7 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
* @return the sorted set
*/
public static SortedSet<EgressRoute> getAllEgressRoutes() {
- SortedSet<EgressRoute> set = new TreeSet<EgressRoute>();
+ SortedSet<EgressRoute> set = new TreeSet<>();
try {
DB db = new DB();
@SuppressWarnings("resource")
@@ -74,7 +75,7 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0008 EgressRoute.getAllEgressRoutes: " + e.getMessage(), e);
}
return set;
}
@@ -104,20 +105,20 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
ps.close();
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0009 EgressRoute.getEgressRoute: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return v;
}
- public EgressRoute(int subid, int nodeid) throws IllegalArgumentException {
+ public EgressRoute(int subid, int nodeid) {
this.subid = subid;
this.nodeid = nodeid;
// Note: unlike for Feeds, it subscriptions can be removed from the tables, so it is
@@ -126,7 +127,7 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
// throw new IllegalArgumentException("No such subscription: "+subid);
}
- public EgressRoute(int subid, String node) throws IllegalArgumentException {
+ public EgressRoute(int subid, String node) {
this(subid, lookupNodeName(node));
}
@@ -141,15 +142,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -169,14 +169,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
ps.close();
rv = true;
} catch (SQLException e) {
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -194,14 +194,14 @@ public class EgressRoute extends NodeClass implements Comparable<EgressRoute> {
ps.executeUpdate();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
index 506821e2..1cfd0f6b 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Feed.java
@@ -47,6 +47,7 @@ import java.util.*;
public class Feed extends Syncable {
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
private static int next_feedid = getMaxFeedID() + 1;
+ private static final String SQLEXCEPTION = "SQLException: ";
private int feedid;
private int groupid; //New field is added - Groups feature Rally:US708115 - 1610
@@ -85,7 +86,7 @@ public class Feed extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0024 Feed.isFeedValid: ", e.getMessage());
+ intlogger.warn("PROV0024 Feed.isFeedValid: " + e.getMessage(), e);
}
return count != 0;
}
@@ -135,7 +136,7 @@ public class Feed extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0025 Feed.countActiveFeeds: ", e.getMessage());
+ intlogger.warn("PROV0025 Feed.countActiveFeeds: " + e.getMessage(), e);
}
return count;
}
@@ -155,7 +156,7 @@ public class Feed extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0026 Feed.getMaxFeedID: ", e.getMessage());
+ intlogger.warn("PROV0026 Feed.getMaxFeedID: " + e.getMessage(), e);
}
return max;
}
@@ -201,7 +202,7 @@ public class Feed extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0027 Feed.getAllFeeds: ", e.getMessage());
+ intlogger.warn("PROV0027 Feed.getAllFeeds: " + e.getMessage(), e);
}
return map.values();
}
@@ -235,7 +236,7 @@ public class Feed extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: ", e.getMessage());
+ intlogger.warn("PROV0028 Feed.getFilteredFeedUrlList: " + e.getMessage(), e);
}
return list;
}
@@ -272,7 +273,7 @@ public class Feed extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0029 Feed.getFeedBySQL: ", e.getMessage());
+ intlogger.warn("PROV0029 Feed.getFeedBySQL: " + e.getMessage(), e);
}
return feed;
}
@@ -338,6 +339,7 @@ public class Feed extends Syncable {
try {
this.version = jo.getString("version");
} catch (JSONException e) {
+ intlogger.warn("PROV0023 Feed.Feed: " + e.getMessage(), e);
this.version = null;
}
if(version != null && version.length() > 20)
@@ -379,11 +381,10 @@ public class Feed extends Syncable {
JSONObject jol = jo.optJSONObject("links");
this.links = (jol == null) ? (new FeedLinks()) : (new FeedLinks(jol));
} catch (InvalidObjectException e) {
- intlogger.warn("PROV0030 Feed.Feed: ", e.getMessage());
throw e;
} catch (Exception e) {
- intlogger.error("PROV0031 Feed.Feed: invalid JSON: "+e);
- throw new InvalidObjectException("invalid JSON: " + e.getMessage());
+ intlogger.warn("Invalid JSON: " + e.getMessage(), e);
+ throw new InvalidObjectException("Invalid JSON: " + e.getMessage());
}
}
@@ -496,14 +497,6 @@ public class Feed extends Syncable {
this.suspended = suspended;
}
- public Date getLast_mod() {
- return last_mod;
- }
-
- public Date getCreated_date() {
- return created_date;
- }
-
@Override
public JSONObject asJSONObject() {
JSONObject jo = new JSONObject();
@@ -555,15 +548,14 @@ public class Feed extends Syncable {
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -624,8 +616,7 @@ public class Feed extends Syncable {
}
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0005 doInsert: " + e.getMessage(), e);
}
return rv;
}
@@ -705,13 +696,13 @@ public class Feed extends Syncable {
ps.close();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
try {
if (ps != null)
ps.close();
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -737,14 +728,14 @@ public class Feed extends Syncable {
ps.close();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0008 changeOwnerShip: " + e.getMessage(), e);
} finally {
try {
if(ps!=null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedEndpointID.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedEndpointID.java
index cd482c61..384d9f64 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedEndpointID.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/FeedEndpointID.java
@@ -39,10 +39,6 @@ public class FeedEndpointID implements JSONable {
private String id;
private String password;
- public FeedEndpointID() {
- this("", "");
- }
-
public FeedEndpointID(String id, String password) {
this.id = id;
this.password = password;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
index 8904765a..da682d74 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Group.java
@@ -46,6 +46,7 @@ public class Group extends Syncable {
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
private static int next_groupid = getMaxGroupID() + 1;
+ private static final String SQLEXCEPTION = "SQLException: ";
private int groupid;
private String authid;
@@ -107,7 +108,7 @@ public class Group extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0009 getGroupsForSQL: " + e.getMessage(), e);
}
return list;
}
@@ -127,59 +128,11 @@ public class Group extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.info("getMaxSubID: " + e.getMessage());
+ intlogger.info("PROV0001 getMaxSubID: " + e.getMessage(), e);
}
return max;
}
- public static Collection<String> getGroupsByClassfication(String classfication) {
- List<String> list = new ArrayList<>();
- String sql = "select * from GROUPS where classification = ?";
- try {
- DB db = new DB();
- @SuppressWarnings("resource")
- Connection conn = db.getConnection();
- try (PreparedStatement stmt = conn.prepareStatement(sql)) {
- stmt.setString(1, classfication);
- try (ResultSet rs = stmt.executeQuery()) {
- while (rs.next()) {
- int groupid = rs.getInt("groupid");
-
- }
- }
- }
- db.release(conn);
- } catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
- }
- return list;
- }
-
- /**
- * Return a count of the number of active subscriptions in the DB.
- *
- * @return the count
- */
- public static int countActiveSubscriptions() {
- int count = 0;
- try {
- DB db = new DB();
- @SuppressWarnings("resource")
- Connection conn = db.getConnection();
- try (Statement stmt = conn.createStatement()) {
- try (ResultSet rs = stmt.executeQuery("select count(*) from SUBSCRIPTIONS")) {
- if (rs.next()) {
- count = rs.getInt(1);
- }
- }
- }
- db.release(conn);
- } catch (SQLException e) {
- intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());
- }
- return count;
- }
-
public Group() {
this("", "", "");
}
@@ -229,7 +182,8 @@ public class Group extends Syncable {
} catch (InvalidObjectException e) {
throw e;
} catch (Exception e) {
- throw new InvalidObjectException("invalid JSON: " + e.getMessage());
+ intlogger.warn("Invalid JSON: " + e.getMessage(), e);
+ throw new InvalidObjectException("Invalid JSON: " + e.getMessage());
}
}
@@ -249,14 +203,6 @@ public class Group extends Syncable {
Group.intlogger = intlogger;
}
- public static int getNext_groupid() {
- return next_groupid;
- }
-
- public static void setNext_groupid(int next_groupid) {
- Group.next_groupid = next_groupid;
- }
-
public String getAuthid() {
return authid;
}
@@ -293,19 +239,6 @@ public class Group extends Syncable {
return members;
}
- public void setMembers(String members) {
- this.members = members;
- }
-
- public Date getLast_mod() {
- return last_mod;
- }
-
- public void setLast_mod(Date last_mod) {
- this.last_mod = last_mod;
- }
-
-
@Override
public JSONObject asJSONObject() {
JSONObject jo = new JSONObject();
@@ -346,14 +279,14 @@ public class Group extends Syncable {
ps.close();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -375,14 +308,14 @@ public class Group extends Syncable {
ps.executeUpdate();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -399,14 +332,14 @@ public class Group extends Syncable {
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
index bbed37a3..329e77fa 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/IngressRoute.java
@@ -55,6 +55,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
public class IngressRoute extends NodeClass implements Comparable<IngressRoute> {
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+ private static final String SQLEXCEPTION = "SQLException: ";
private final int seq;
private final int feedid;
private final String userid;
@@ -102,7 +103,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0001 getAllIngressRoutesForSQL: " + e.getMessage(), e);
}
return set;
}
@@ -140,7 +141,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0002 getMax: " + e.getMessage(), e);
}
return rv;
}
@@ -175,51 +176,19 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
ps.close();
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error("PROV0003 getIngressRoute: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return v;
}
- /**
- * Get a collection of all Ingress Routes with a particular sequence number.
- *
- * @param seq the sequence number to look for
- * @return the collection (may be empty).
- */
- public static Collection<IngressRoute> getIngressRoute(int seq) {
- Collection<IngressRoute> rv = new ArrayList<IngressRoute>();
- try {
- DB db = new DB();
- @SuppressWarnings("resource")
- Connection conn = db.getConnection();
- String sql = "select FEEDID, USERID, SUBNET, NODESET from INGRESS_ROUTES where SEQUENCE = ?";
- try (PreparedStatement ps = conn.prepareStatement(sql)) {
- ps.setInt(1, seq);
- try (ResultSet rs = ps.executeQuery()) {
- while (rs.next()) {
- int feedid = rs.getInt("FEEDID");
- String user = rs.getString("USERID");
- String subnet = rs.getString("SUBNET");
- int nodeset = rs.getInt("NODESET");
- rv.add(new IngressRoute(seq, feedid, user, subnet, nodeset));
- }
- }
- }
- db.release(conn);
- } catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
- }
- return rv;
- }
-
public IngressRoute(int seq, int feedid, String user, String subnet, Collection<String> nodes)
throws IllegalArgumentException {
this(seq, feedid, user, subnet);
@@ -307,6 +276,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
SubnetMatcher sm = new SubnetMatcher(subnet);
return sm.matches(inet.getAddress());
} catch (UnknownHostException e) {
+ intlogger.error("PROV0008 matches: " + e.getMessage(), e);
return false;
}
}
@@ -337,6 +307,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
len = sn.length;
valid = true;
} catch (UnknownHostException e) {
+ intlogger.error("PROV0008 SubnetMatcher: " + e.getMessage(), e);
len = 0;
valid = false;
}
@@ -347,6 +318,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
sn = InetAddress.getByName(subnet.substring(0, i)).getAddress();
valid = true;
} catch (UnknownHostException e) {
+ intlogger.error("PROV0008 SubnetMatcher: " + e.getMessage(), e);
valid = false;
}
len = n / 8;
@@ -390,7 +362,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
}
private Collection<String> readNodes() {
- Collection<String> set = new TreeSet<String>();
+ Collection<String> set = new TreeSet<>();
try {
DB db = new DB();
@SuppressWarnings("resource")
@@ -407,7 +379,7 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
return set;
}
@@ -434,14 +406,14 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -477,14 +449,14 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
ps.close();
rv = true;
} catch (SQLException e) {
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -524,14 +496,10 @@ public class IngressRoute extends NodeClass implements Comparable<IngressRoute>
@Override
public boolean equals(Object obj) {
- try {
- if (!(obj instanceof IngressRoute)) {
- return false;
- }
- return this.compareTo((IngressRoute) obj) == 0;
- } catch (NullPointerException e) {
+ if (!(obj instanceof IngressRoute)) {
return false;
}
+ return this.compareTo((IngressRoute) obj) == 0;
}
@Override
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
index 86d1faea..cbddbf43 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/LogRecord.java
@@ -77,7 +77,7 @@ public class LogRecord extends BaseLogRecord {
}
}
} catch (SQLException e) {
- intlogger.error("SQLException: " + e.getMessage());
+ intlogger.error("PROV0001 printLogRecords: " + e.getMessage(), e);
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
index 94eeec4a..6ac05445 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/NetworkRoute.java
@@ -47,6 +47,7 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute> {
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+ private static final String SQLEXCEPTION = "SQLException: ";
private final int fromnode;
private final int tonode;
private final int vianode;
@@ -58,7 +59,7 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
* @return the sorted set
*/
public static SortedSet<NetworkRoute> getAllNetworkRoutes() {
- SortedSet<NetworkRoute> set = new TreeSet<NetworkRoute>();
+ SortedSet<NetworkRoute> set = new TreeSet<>();
try {
DB db = new DB();
@SuppressWarnings("resource")
@@ -75,30 +76,30 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
return set;
}
- public NetworkRoute(String fromnode, String tonode) throws IllegalArgumentException {
+ public NetworkRoute(String fromnode, String tonode) {
this.fromnode = lookupNodeName(fromnode);
this.tonode = lookupNodeName(tonode);
this.vianode = -1;
}
- public NetworkRoute(String fromnode, String tonode, String vianode) throws IllegalArgumentException {
+ public NetworkRoute(String fromnode, String tonode, String vianode) {
this.fromnode = lookupNodeName(fromnode);
this.tonode = lookupNodeName(tonode);
this.vianode = lookupNodeName(vianode);
}
- public NetworkRoute(JSONObject jo) throws IllegalArgumentException {
+ public NetworkRoute(JSONObject jo) {
this.fromnode = lookupNodeName(jo.getString("from"));
this.tonode = lookupNodeName(jo.getString("to"));
this.vianode = lookupNodeName(jo.getString("via"));
}
- public NetworkRoute(int fromnode, int tonode, int vianode) throws IllegalArgumentException {
+ public NetworkRoute(int fromnode, int tonode, int vianode) {
this.fromnode = fromnode;
this.tonode = tonode;
this.vianode = vianode;
@@ -112,10 +113,6 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
return tonode;
}
- public int getVianode() {
- return vianode;
- }
-
@Override
public boolean doDelete(Connection c) {
boolean rv = true;
@@ -128,14 +125,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -157,14 +154,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
ps.close();
rv = true;
} catch (SQLException e) {
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
}
@@ -184,14 +181,14 @@ public class NetworkRoute extends NodeClass implements Comparable<NetworkRoute>
ps.executeUpdate();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
index 08914868..9e7071bb 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Parameters.java
@@ -57,6 +57,7 @@ public class Parameters extends Syncable {
public static final String PROV_POKETIMER2 = "PROV_POKETIMER2";
public static final String PROV_SPECIAL_SUBNET = "PROV_SPECIAL_SUBNET";
public static final String PROV_LOG_RETENTION = "PROV_LOG_RETENTION";
+ public static final String DEFAULT_LOG_RETENTION = "DEFAULT_LOG_RETENTION";
public static final String NODES = "NODES";
public static final String ACTIVE_POD = "ACTIVE_POD";
public static final String STANDBY_POD = "STANDBY_POD";
@@ -69,6 +70,7 @@ public class Parameters extends Syncable {
public static final String STATIC_ROUTING_NODES = "STATIC_ROUTING_NODES"; //Adding new param for static Routing - Rally:US664862-1610
private static EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+ private static final String SQLEXCEPTION = "SQLException: ";
private String keyname;
private String value;
@@ -103,7 +105,7 @@ public class Parameters extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage());
}
return coll;
}
@@ -131,7 +133,7 @@ public class Parameters extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage());
}
return v;
}
@@ -154,10 +156,6 @@ public class Parameters extends Syncable {
return keyname;
}
- public void setKeyname(String keyname) {
- this.keyname = keyname;
- }
-
public String getValue() {
return value;
}
@@ -187,14 +185,14 @@ public class Parameters extends Syncable {
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage());
}
}
return rv;
@@ -213,14 +211,14 @@ public class Parameters extends Syncable {
ps.executeUpdate();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(),e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -238,14 +236,14 @@ public class Parameters extends Syncable {
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error("SQLException " + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecord.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecord.java
index 88d48826..a38d8bd2 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecord.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/PubFailRecord.java
@@ -24,7 +24,6 @@
package org.onap.dmaap.datarouter.provisioning.beans;
import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.text.ParseException;
@@ -49,15 +48,6 @@ public class PubFailRecord extends BaseLogRecord {
this.error = pp[11];
}
- public PubFailRecord(ResultSet rs) throws SQLException {
- super(rs);
- // Note: because this record should be "rare" these fields are mapped to unconventional fields in the DB
- this.contentLengthReceived = rs.getLong("CONTENT_LENGTH_2");
- this.sourceIP = rs.getString("REMOTE_ADDR");
- this.user = rs.getString("USER");
- this.error = rs.getString("FEED_FILEID");
- }
-
public long getContentLengthReceived() {
return contentLengthReceived;
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubDelivery.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubDelivery.java
index 98981a30..5a3457b9 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubDelivery.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/SubDelivery.java
@@ -43,10 +43,6 @@ public class SubDelivery implements JSONable {
private String password;
private boolean use100;
- public SubDelivery() {
- this("", "", "", false);
- }
-
public SubDelivery(String url, String user, String password, boolean use100) {
this.url = url;
this.user = user;
@@ -90,10 +86,6 @@ public class SubDelivery implements JSONable {
return use100;
}
- public void setUse100(boolean use100) {
- this.use100 = use100;
- }
-
@Override
public JSONObject asJSONObject() {
JSONObject jo = new JSONObject();
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
index 442a7642..1cb1f2bb 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/beans/Subscription.java
@@ -23,6 +23,8 @@
package org.onap.dmaap.datarouter.provisioning.beans;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.InvalidObjectException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@@ -34,9 +36,6 @@ import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Properties;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
import org.json.JSONObject;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
@@ -117,7 +116,7 @@ public class Subscription extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error(e.toString());
+ intlogger.error("PROV0001 getSubscriptionsForSQL: " + e.toString(), e);
}
return list;
}
@@ -137,7 +136,7 @@ public class Subscription extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.info("getMaxSubID: " + e.getMessage());
+ intlogger.info("getMaxSubID: " + e.getMessage(), e);
}
return max;
}
@@ -161,7 +160,7 @@ public class Subscription extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.error(SQLEXCEPTION + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
return list;
}
@@ -186,7 +185,7 @@ public class Subscription extends Syncable {
}
db.release(conn);
} catch (SQLException e) {
- intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage());
+ intlogger.warn("PROV0008 countActiveSubscriptions: " + e.getMessage(), e);
}
return count;
}
@@ -274,7 +273,8 @@ public class Subscription extends Syncable {
} catch (InvalidObjectException e) {
throw e;
} catch (Exception e) {
- throw new InvalidObjectException("invalid JSON: " + e.getMessage());
+ intlogger.warn("Invalid JSON: " + e.getMessage(), e);
+ throw new InvalidObjectException("Invalid JSON: " + e.getMessage());
}
}
@@ -474,14 +474,14 @@ public class Subscription extends Syncable {
ps.close();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0005 doInsert: " + e.getMessage());
+ intlogger.warn("PROV0005 doInsert: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error(SQLEXCEPTION + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -508,14 +508,14 @@ public class Subscription extends Syncable {
ps.executeUpdate();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error(SQLEXCEPTION + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -541,14 +541,14 @@ public class Subscription extends Syncable {
ps.close();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0006 doUpdate: " + e.getMessage());
+ intlogger.warn("PROV0006 doUpdate: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error(SQLEXCEPTION + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -566,14 +566,14 @@ public class Subscription extends Syncable {
ps.execute();
} catch (SQLException e) {
rv = false;
- intlogger.warn("PROV0007 doDelete: " + e.getMessage());
+ intlogger.warn("PROV0007 doDelete: " + e.getMessage(), e);
} finally {
try {
if (ps != null) {
ps.close();
}
} catch (SQLException e) {
- intlogger.error(SQLEXCEPTION + e.getMessage());
+ intlogger.error(SQLEXCEPTION + e.getMessage(), e);
}
}
return rv;
@@ -596,8 +596,8 @@ public class Subscription extends Syncable {
if (feedid != os.feedid) {
return false;
}
- if (groupid != os.groupid) //New field is added - Groups feature Rally:US708115 - 1610
- {
+ if (groupid != os.groupid) {
+ //New field is added - Groups feature Rally:US708115 - 1610
return false;
}
if (!delivery.equals(os.delivery)) {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
index d29876fb..7700a583 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DB.java
@@ -84,7 +84,7 @@ public class DB {
HTTP_PORT = (String) props.get("org.onap.dmaap.datarouter.provserver.http.port");
Class.forName(DB_DRIVER);
} catch (IOException e) {
- intlogger.error("PROV9003 Opening properties: " + e.getMessage());
+ intlogger.error("PROV9003 Opening properties: " + e.getMessage(), e);
System.exit(1);
} catch (ClassNotFoundException e) {
intlogger.error("PROV9004 cannot find the DB driver: " + e);
@@ -115,6 +115,7 @@ public class DB {
try {
connection = queue.remove();
} catch (NoSuchElementException nseEx) {
+ intlogger.error("PROV9006 No connection on queue: " + nseEx.getMessage(), nseEx);
int n = 0;
do {
// Try up to 3 times to get a connection
@@ -194,8 +195,7 @@ public class DB {
runInitScript(connection, 1);
}
} catch (SQLException e) {
- intlogger
- .error("PROV9000: The database credentials are not working: " + e.getMessage());
+ intlogger.error("PROV9000: The database credentials are not working: " + e.getMessage(), e);
return false;
} finally {
if (connection != null) {
@@ -223,7 +223,7 @@ public class DB {
rs.close();
}
} catch (SQLException e) {
- intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage());
+ intlogger.error("PROV9010: Failed to get TABLE data from DB: " + e.getMessage(), e);
}
return tables;
}
@@ -264,7 +264,7 @@ public class DB {
lineReader.close();
strBuilder.setLength(0);
} catch (Exception e) {
- intlogger.error("PROV9002 Error when initializing table: " + e.getMessage());
+ intlogger.error("PROV9002 Error when initializing table: " + e.getMessage(), e);
System.exit(1);
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
index 46cfabec..d5521ba8 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
@@ -211,7 +211,7 @@ public class DRProvCadiFilter extends CadiFilter {
}
} catch (Exception e) {
- intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: ", e.getMessage());
+ intlogger.error("PROV0073 DRProvCadiFilter.isAAFFeed: " + e.getMessage(), e);
return false;
}
return false;
@@ -241,7 +241,7 @@ public class DRProvCadiFilter extends CadiFilter {
intlogger.debug(message);
}
} catch (Exception e) {
- intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: ", e.getMessage());
+ intlogger.error("PROV0073 DRProvCadiFilter.isAAFSubscriber: " + e.getMessage(), e);
return false;
}
return false;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
index af8bd6d3..a593c8a7 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRRouteCLI.java
@@ -24,6 +24,8 @@
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.IOException;
@@ -97,6 +99,7 @@ public class DRRouteCLI {
public static final String ENV_VAR = "PROVSRVR";
public static final String PROMPT = "dr-route> ";
public static final String DEFAULT_TRUSTSTORE_PATH = /* $JAVA_HOME + */ "/jre/lib/security/cacerts";
+ private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
private final String server;
private int width = 120; // screen width (for list)
@@ -130,12 +133,13 @@ public class DRRouteCLI {
try {
trustStore.load(instream, truststore_pw.toCharArray());
} catch (Exception x) {
- System.err.println("Problem reading truststore: " + x);
+ intlogger.error("Problem reading truststore: " + x.getMessage(), x);
throw x;
} finally {
try {
instream.close();
} catch (Exception ignore) {
+ intlogger.error("Ignore error closing input stream: " + ignore.getMessage(), ignore);
}
}
}
@@ -397,6 +401,7 @@ public class DRRouteCLI {
printErrorText(entity);
}
} catch (Exception e) {
+ intlogger.error("PROV0006 doDelete: " + e.getMessage(), e);
} finally {
meth.releaseConnection();
}
@@ -416,7 +421,7 @@ public class DRRouteCLI {
printErrorText(entity);
}
} catch (Exception e) {
- System.err.println(e);
+ intlogger.error("PROV0005 doGet: " + e.getMessage(), e);
} finally {
meth.releaseConnection();
}
@@ -438,6 +443,7 @@ public class DRRouteCLI {
printErrorText(entity);
}
} catch (Exception e) {
+ intlogger.error("PROV0009 doPost: " + e.getMessage(), e);
} finally {
meth.releaseConnection();
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
index 3aa3bd28..f59dc919 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/HttpServletUtils.java
@@ -20,19 +20,24 @@
* * ECOMP is a trademark and service mark of AT&T Intellectual Property.
* *
******************************************************************************/
-package org.onap.dmaap.datarouter.provisioning.utils;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
+package org.onap.dmaap.datarouter.provisioning.utils;
import com.att.eelf.configuration.EELFLogger;
+import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
public class HttpServletUtils {
+
+ private HttpServletUtils(){
+
+ }
+
public static void sendResponseError(HttpServletResponse response, int errorCode, String message, EELFLogger intlogger) {
try {
response.sendError(errorCode, message);
} catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ intlogger.error("IOException" + ioe.getMessage(), ioe);
}
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
index 915aa610..2d4e22b3 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/JSONUtilities.java
@@ -24,6 +24,8 @@
package org.onap.dmaap.datarouter.provisioning.utils;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Collection;
@@ -35,6 +37,8 @@ import java.util.Collection;
* @version $Id: JSONUtilities.java,v 1.1 2013/04/26 21:00:26 eby Exp $
*/
public class JSONUtilities {
+
+ private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
/**
* Does the String <i>v</i> represent a valid Internet address (with or without a
* mask length appended).
@@ -56,6 +60,7 @@ public class JSONUtilities {
}
return true;
} catch (UnknownHostException e) {
+ intlogger.error("PROV0001: " + e.getMessage(), e);
return false;
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
index 1518859a..1140a1ce 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LOGJSONObject.java
@@ -23,6 +23,8 @@ package org.onap.dmaap.datarouter.provisioning.utils;
* *
******************************************************************************/
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
@@ -104,6 +106,8 @@ public class LOGJSONObject {
*/
private static Map<String, Object> keyPool = new LinkedHashMap<String, Object>(keyPoolSize);
+ private static final EELFLogger intlogger = EELFManager.getInstance().getLogger("InternalLog");
+
/**
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
* whilst Java's null is equivalent to the value that JavaScript calls
@@ -182,13 +186,11 @@ public class LOGJSONObject {
}
}
-
/**
* The map where the JSONObject's properties are kept.
*/
private final Map<String, Object> map;
-
/**
* It is sometimes more convenient and less ambiguous to have a
* <code>NULL</code> object than to use Java's <code>null</code> value.
@@ -197,15 +199,13 @@ public class LOGJSONObject {
*/
public static final Object NULL = new Null();
-
/**
* Construct an empty JSONObject.
*/
public LOGJSONObject() {
- this.map = new LinkedHashMap<String, Object>();
+ this.map = new LinkedHashMap<>();
}
-
/**
* Construct a JSONObject from a subset of another JSONObject.
* An array of strings is used to identify the keys that should be copied.
@@ -213,8 +213,6 @@ public class LOGJSONObject {
*
* @param jo A JSONObject.
* @param names An array of strings.
- * @throws JSONException
- * @throws JSONException If a value is a non-finite number or if a name is duplicated.
*/
public LOGJSONObject(LOGJSONObject jo, String[] names) {
this();
@@ -222,11 +220,11 @@ public class LOGJSONObject {
try {
this.putOnce(names[i], jo.opt(names[i]));
} catch (Exception ignore) {
+ intlogger.error("PROV0001 LOGJSONObject: " + ignore.getMessage(), ignore);
}
}
}
-
/**
* Construct a JSONObject from a JSONTokener.
*
@@ -234,7 +232,7 @@ public class LOGJSONObject {
* @throws JSONException If there is a syntax error in the source string
* or a duplicated key.
*/
- public LOGJSONObject(JSONTokener x) throws JSONException {
+ public LOGJSONObject(JSONTokener x) {
this();
char c;
String key;
@@ -284,7 +282,6 @@ public class LOGJSONObject {
}
}
-
/**
* Construct a JSONObject from a Map.
*
@@ -306,7 +303,6 @@ public class LOGJSONObject {
}
}
-
/**
* Construct a JSONObject from an Object using bean getters.
* It reflects on all of the public methods of the object.
@@ -331,7 +327,6 @@ public class LOGJSONObject {
this.populateMap(bean);
}
-
/**
* Construct a JSONObject from an Object, using reflection to find the
* public members. The resulting JSONObject's keys will be the strings
@@ -356,7 +351,6 @@ public class LOGJSONObject {
}
}
-
/**
* Construct a JSONObject from a source JSON text string.
* This is the most commonly used JSONObject constructor.
@@ -371,7 +365,6 @@ public class LOGJSONObject {
this(new JSONTokener(source));
}
-
/**
* Construct a JSONObject from a ResourceBundle.
*
@@ -412,7 +405,6 @@ public class LOGJSONObject {
}
}
-
/**
* Accumulate values under a key. It is similar to the put method except
* that if there is already an object stored under the key then a
@@ -448,7 +440,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Append values to the array under a key. If the key does not exist in the
* JSONObject, then the key is put in the JSONObject with its value being a
@@ -475,7 +466,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Produce a string from a double. The string "null" will be returned if
* the number is not finite.
@@ -503,7 +493,6 @@ public class LOGJSONObject {
return string;
}
-
/**
* Get the value object associated with a key.
*
@@ -523,7 +512,6 @@ public class LOGJSONObject {
return object;
}
-
/**
* Get the boolean value associated with a key.
*
@@ -546,7 +534,6 @@ public class LOGJSONObject {
"] is not a Boolean.");
}
-
/**
* Get the double value associated with a key.
*
@@ -555,19 +542,18 @@ public class LOGJSONObject {
* @throws JSONException if the key is not found or
* if the value is not a Number object and cannot be converted to a number.
*/
- public double getDouble(String key) throws JSONException {
+ public double getDouble(String key) {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number) object).doubleValue()
: Double.parseDouble((String) object);
} catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a number.");
+ intlogger.error("JSONObject[" + quote(key) + "] is not a number.", e);
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a number.");
}
}
-
/**
* Get the int value associated with a key.
*
@@ -576,19 +562,18 @@ public class LOGJSONObject {
* @throws JSONException if the key is not found or if the value cannot
* be converted to an integer.
*/
- public int getInt(String key) throws JSONException {
+ public int getInt(String key) {
Object object = this.get(key);
try {
return object instanceof Number
? ((Number) object).intValue()
: Integer.parseInt((String) object);
} catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not an int.");
+ intlogger.error("JSONObject[" + quote(key) + "] is not an int.", e);
+ throw new JSONException("JSONObject[" + quote(key) + "] is not an int.");
}
}
-
/**
* Get the JSONArray value associated with a key.
*
@@ -606,7 +591,6 @@ public class LOGJSONObject {
"] is not a JSONArray.");
}
-
/**
* Get the JSONObject value associated with a key.
*
@@ -624,7 +608,6 @@ public class LOGJSONObject {
"] is not a JSONObject.");
}
-
/**
* Get the long value associated with a key.
*
@@ -640,12 +623,11 @@ public class LOGJSONObject {
? ((Number) object).longValue()
: Long.parseLong((String) object);
} catch (Exception e) {
- throw new JSONException("JSONObject[" + quote(key) +
- "] is not a long.");
+ intlogger.error("JSONObject[" + quote(key) + "] is not a long.", e);
+ throw new JSONException("JSONObject[" + quote(key) + "] is not a long.");
}
}
-
/**
* Get an array of field names from a JSONObject.
*
@@ -666,30 +648,6 @@ public class LOGJSONObject {
return names;
}
-
- /**
- * Get an array of field names from an Object.
- *
- * @return An array of field names, or null if there are no names.
- */
- public static String[] getNames(Object object) {
- if (object == null) {
- return null;
- }
- Class<? extends Object> klass = object.getClass();
- Field[] fields = klass.getFields();
- int length = fields.length;
- if (length == 0) {
- return null;
- }
- String[] names = new String[length];
- for (int i = 0; i < length; i += 1) {
- names[i] = fields[i].getName();
- }
- return names;
- }
-
-
/**
* Get the string associated with a key.
*
@@ -697,7 +655,7 @@ public class LOGJSONObject {
* @return A string which is the value.
* @throws JSONException if there is no string value for the key.
*/
- public String getString(String key) throws JSONException {
+ public String getString(String key) {
Object object = this.get(key);
if (object instanceof String) {
return (String) object;
@@ -706,7 +664,6 @@ public class LOGJSONObject {
"] not a string.");
}
-
/**
* Determine if the JSONObject contains a specific key.
*
@@ -717,7 +674,6 @@ public class LOGJSONObject {
return this.map.containsKey(key);
}
-
/**
* Increment a property of a JSONObject. If there is no such property,
* create one with a value of 1. If there is such a property, and if
@@ -728,7 +684,7 @@ public class LOGJSONObject {
* @throws JSONException If there is already a property with this name
* that is not an Integer, Long, Double, or Float.
*/
- public LOGJSONObject increment(String key) throws JSONException {
+ public LOGJSONObject increment(String key) {
Object value = this.opt(key);
if (value == null) {
this.put(key, 1);
@@ -746,20 +702,6 @@ public class LOGJSONObject {
return this;
}
-
- /**
- * Determine if the value associated with the key is null or if there is
- * no value.
- *
- * @param key A key string.
- * @return true if there is no value associated with the key or if
- * the value is the JSONObject.NULL object.
- */
- public boolean isNull(String key) {
- return LOGJSONObject.NULL.equals(this.opt(key));
- }
-
-
/**
* Get an enumeration of the keys of the JSONObject.
*
@@ -769,7 +711,6 @@ public class LOGJSONObject {
return this.keySet().iterator();
}
-
/**
* Get a set of keys of the JSONObject.
*
@@ -779,7 +720,6 @@ public class LOGJSONObject {
return this.map.keySet();
}
-
/**
* Get the number of keys stored in the JSONObject.
*
@@ -789,7 +729,6 @@ public class LOGJSONObject {
return this.map.size();
}
-
/**
* Produce a JSONArray containing the names of the elements of this
* JSONObject.
@@ -835,7 +774,6 @@ public class LOGJSONObject {
return string;
}
-
/**
* Get an optional value associated with a key.
*
@@ -846,20 +784,6 @@ public class LOGJSONObject {
return key == null ? null : this.map.get(key);
}
-
- /**
- * Get an optional boolean associated with a key.
- * It returns false if there is no such key, or if the value is not
- * Boolean.TRUE or the String "true".
- *
- * @param key A key string.
- * @return The truth.
- */
- public boolean optBoolean(String key) {
- return this.optBoolean(key, false);
- }
-
-
/**
* Get an optional boolean associated with a key.
* It returns the defaultValue if there is no such key, or if it is not
@@ -873,25 +797,11 @@ public class LOGJSONObject {
try {
return this.getBoolean(key);
} catch (Exception e) {
+ intlogger.trace("Using defaultValue: " + defaultValue, e);
return defaultValue;
}
}
-
- /**
- * Get an optional double associated with a key,
- * or NaN if there is no such key or if its value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A string which is the key.
- * @return An object which is the value.
- */
- public double optDouble(String key) {
- return this.optDouble(key, Double.NaN);
- }
-
-
/**
* Get an optional double associated with a key, or the
* defaultValue if there is no such key or if its value is not a number.
@@ -906,25 +816,11 @@ public class LOGJSONObject {
try {
return this.getDouble(key);
} catch (Exception e) {
+ intlogger.trace("Using defaultValue: " + defaultValue, e);
return defaultValue;
}
}
-
- /**
- * Get an optional int value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public int optInt(String key) {
- return this.optInt(key, 0);
- }
-
-
/**
* Get an optional int value associated with a key,
* or the default if there is no such key or if the value is not a number.
@@ -939,25 +835,11 @@ public class LOGJSONObject {
try {
return this.getInt(key);
} catch (Exception e) {
+ intlogger.trace("Using defaultValue: " + defaultValue, e);
return defaultValue;
}
}
-
- /**
- * Get an optional JSONArray associated with a key.
- * It returns null if there is no such key, or if its value is not a
- * JSONArray.
- *
- * @param key A key string.
- * @return A JSONArray which is the value.
- */
- public JSONArray optJSONArray(String key) {
- Object o = this.opt(key);
- return o instanceof JSONArray ? (JSONArray) o : null;
- }
-
-
/**
* Get an optional JSONObject associated with a key.
* It returns null if there is no such key, or if its value is not a
@@ -971,21 +853,6 @@ public class LOGJSONObject {
return object instanceof LOGJSONObject ? (LOGJSONObject) object : null;
}
-
- /**
- * Get an optional long value associated with a key,
- * or zero if there is no such key or if the value is not a number.
- * If the value is a string, an attempt will be made to evaluate it as
- * a number.
- *
- * @param key A key string.
- * @return An object which is the value.
- */
- public long optLong(String key) {
- return this.optLong(key, 0);
- }
-
-
/**
* Get an optional long value associated with a key,
* or the default if there is no such key or if the value is not a number.
@@ -1004,20 +871,6 @@ public class LOGJSONObject {
}
}
-
- /**
- * Get an optional string associated with a key.
- * It returns an empty string if there is no such key. If the value is not
- * a string and is not null, then it is converted to a string.
- *
- * @param key A key string.
- * @return A string which is the value.
- */
- public String optString(String key) {
- return this.optString(key, "");
- }
-
-
/**
* Get an optional string associated with a key.
* It returns the defaultValue if there is no such key.
@@ -1031,7 +884,6 @@ public class LOGJSONObject {
return NULL.equals(object) ? defaultValue : object.toString();
}
-
private void populateMap(Object bean) {
Class<? extends Object> klass = bean.getClass();
@@ -1075,11 +927,11 @@ public class LOGJSONObject {
}
}
} catch (Exception ignore) {
+ intlogger.trace("populateMap: " + ignore.getMessage(), ignore);
}
}
}
-
/**
* Put a key/boolean pair in the JSONObject.
*
@@ -1093,7 +945,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONArray which is produced from a Collection.
@@ -1108,7 +959,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/double pair in the JSONObject.
*
@@ -1122,7 +972,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/int pair in the JSONObject.
*
@@ -1136,7 +985,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/long pair in the JSONObject.
*
@@ -1150,7 +998,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/value pair in the JSONObject, where the value will be a
* JSONObject which is produced from a Map.
@@ -1165,7 +1012,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/value pair in the JSONObject. If the value is null,
* then the key will be removed from the JSONObject if it is present.
@@ -1201,7 +1047,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/value pair in the JSONObject, but only if the key and the
* value are both non-null, and only if there is not already a member
@@ -1222,7 +1067,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Put a key/value pair in the JSONObject, but only if the
* key and the value are both non-null.
@@ -1241,7 +1085,6 @@ public class LOGJSONObject {
return this;
}
-
/**
* Produce a string in double quotes with backslash sequences in all the
* right places. A backslash will be inserted within </, producing <\/,
@@ -1256,8 +1099,8 @@ public class LOGJSONObject {
synchronized (sw.getBuffer()) {
try {
return quote(string, sw).toString();
- } catch (IOException ignored) {
- // will never happen - we are writing to a string writer
+ } catch (IOException e) {
+ intlogger.trace("Ignore Exception message: ", e);
return "";
}
}
@@ -1380,20 +1223,20 @@ public class LOGJSONObject {
return myLong;
}
}
- } catch (Exception ignore) {
+ } catch (Exception e) {
+ intlogger.trace("Ignore Exception message: ", e);
}
}
return string;
}
-
/**
* Throw an exception if the object is a NaN or infinite number.
*
* @param o The object to test.
* @throws JSONException If o is a non-finite number.
*/
- public static void testValidity(Object o) throws JSONException {
+ public static void testValidity(Object o) {
if (o != null) {
if (o instanceof Double) {
if (((Double) o).isInfinite() || ((Double) o).isNaN()) {
@@ -1409,7 +1252,6 @@ public class LOGJSONObject {
}
}
-
/**
* Produce a JSONArray containing the values of the members of this
* JSONObject.
@@ -1446,11 +1288,11 @@ public class LOGJSONObject {
try {
return this.toString(0);
} catch (Exception e) {
+ intlogger.trace("Exception: ", e);
return "";
}
}
-
/**
* Make a prettyprinted JSON text of this JSONObject.
* <p>
@@ -1579,25 +1421,11 @@ public class LOGJSONObject {
}
return new LOGJSONObject(object);
} catch (Exception exception) {
+ intlogger.trace("Exception: ", exception);
return null;
}
}
-
- /**
- * Write the contents of the JSONObject as JSON text to a writer.
- * For compactness, no whitespace is added.
- * <p>
- * Warning: This method assumes that the data structure is acyclical.
- *
- * @return The writer.
- * @throws JSONException
- */
- public Writer write(Writer writer) throws JSONException {
- return this.write(writer, 0, 0);
- }
-
-
@SuppressWarnings("unchecked")
static final Writer writeValue(Writer writer, Object value,
int indentFactor, int indent) throws JSONException, IOException {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
index 82231884..c78a5b10 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoader.java
@@ -1,501 +1,498 @@
-/*******************************************************************************
- * ============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 java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
-import java.io.Reader;
-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 com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-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 {
- /**
- * Default number of log records to keep when pruning. Keep 10M by default.
- */
- public static final long DEFAULT_LOG_RETENTION = 10000000L;
- /**
- * 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;
-
- /**
- * 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;
- }
-
- /**
- * The PreparedStatement which is loaded by a <i>Loadable</i>.
- */
- public 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 set_start;
- private final long set_end;
- private RLEBitSet seq_set;
- 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.set_start = getIdRange();
- this.set_end = set_start + SET_SIZE - 1;
- this.seq_set = new RLEBitSet();
- this.nextid = 0;
- this.idle = false;
-
- // This is a potentially lengthy operation, so has been moved to run()
- //initializeNextid();
- this.setDaemon(true);
- this.setName("LogfileLoader");
- }
-
- private long getIdRange() {
- long n;
- if (BaseServlet.isInitialActivePOD())
- n = 0;
- else if (BaseServlet.isInitialStandbyPOD())
- n = SET_SIZE;
- else
- n = SET_SIZE * 2;
- String r = String.format("[%X .. %X]", n, n + SET_SIZE - 1);
- logger.debug("This server shall assign RECORD_IDs in the range " + r);
- return n;
- }
-
- /**
- * Return the bit set representing the record ID's that are loaded in this database.
- *
- * @return the bit set
- */
- public RLEBitSet getBitSet() {
- return seq_set;
- }
-
- /**
- * 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(); // moved from the constructor
- while (true) {
- try {
- File dirfile = new File(spooldir);
- while (true) {
- // process IN files
- File[] infiles = dirfile.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.startsWith("IN.");
- }
- });
-
- 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();
- }
-
- // Process incoming logfiles
- for (File f : infiles) {
- if (logger.isDebugEnabled())
- logger.debug("PROV8001 Starting " + f + " ...");
- long time = System.currentTimeMillis();
- int[] n = process(f);
- time = System.currentTimeMillis() - time;
- logger.info(String
- .format("PROV8000 Processed %s in %d ms; %d of %d records.",
- f.toString(), time, n[0], n[1]));
- f.delete();
- }
- }
- }
- } catch (Exception e) {
- logger.warn("PROV0020: Caught exception in LogfileLoader: " + e);
- }
- }
- }
-
- boolean pruneRecords() {
- boolean did1 = false;
- long count = countRecords();
- long threshold = DEFAULT_LOG_RETENTION;
- Parameters param = Parameters.getParameter(Parameters.PROV_LOG_RETENTION);
- if (param != null) {
- try {
- long n = Long.parseLong(param.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) {
- count -= threshold; // we need to remove this many records;
- Map<Long, Long> hist = getHistogram(); // histogram of records per day
- // Determine the cutoff point to remove the needed number of records
- long sum = 0;
- long cutoff = 0;
- for (Long day : new TreeSet<Long>(hist.keySet())) {
- sum += hist.get(day);
- cutoff = day;
- if (sum >= count)
- break;
- }
- cutoff++;
- cutoff *= 86400000L; // convert day to ms
- 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) {
- System.err.println(e);
- logger.error(e.toString());
- } finally {
- db.release(conn);
- }
- }
- return did1;
- }
-
- long countRecords() {
- long count = 0;
- Connection conn = null;
- try {
- conn = db.getConnection();
- try(Statement stmt = conn.createStatement()) {
- try(ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS")) {
- if (rs.next()) {
- count = rs.getLong("COUNT");
- }
- }
- }
- } catch (SQLException e) {
- System.err.println(e);
- logger.error(e.toString());
- } finally {
- db.release(conn);
- }
- return count;
- }
-
- Map<Long, Long> getHistogram() {
- Map<Long, Long> map = new HashMap<Long, Long>();
- Connection conn = null;
- try {
- logger.debug(" LOG_RECORD table histogram...");
- conn = db.getConnection();
- try(Statement stmt = conn.createStatement()) {
- try(ResultSet rs = stmt.executeQuery("SELECT FLOOR(EVENT_TIME/86400000) AS DAY, COUNT(*) AS COUNT FROM LOG_RECORDS GROUP BY DAY")) {
- while (rs.next()) {
- long day = rs.getLong("DAY");
- long cnt = rs.getLong("COUNT");
- map.put(day, cnt);
- logger.debug(" " + day + " " + cnt);
- }
- }
- }
- } catch (SQLException e) {
- System.err.println(e);
- logger.error(e.toString());
- } finally {
- db.release(conn);
- }
- return map;
- }
-
- private void initializeNextid() {
- Connection conn = null;
- try {
- conn = db.getConnection();
- RLEBitSet nbs = new RLEBitSet();
- try(Statement stmt = conn.createStatement()) {
- // Build a bitset of all records in the LOG_RECORDS table
- // We need to run this SELECT in stages, because otherwise we run out of memory!
- final long stepsize = 6000000L;
- boolean go_again = true;
- for (long i = 0; go_again; i += stepsize) {
- String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize);
- try (ResultSet rs = stmt.executeQuery(sql)) {
- go_again = false;
- while (rs.next()) {
- long n = rs.getLong("RECORD_ID");
- nbs.set(n);
- go_again = true;
- }
- }
- }
- }
- seq_set = 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(set_start, set_start + SET_SIZE);
- tbs.and(idset);
- long t = tbs.length();
- nextid = (t == 0) ? set_start : (t - 1);
- if (nextid >= set_start + 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) ? set_start : (t - 1);
- }
- }
- logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextid, nextid));
- } catch (SQLException e) {
- System.err.println(e);
- logger.error(e.toString());
- } finally {
- db.release(conn);
- }
- }
-
- @SuppressWarnings("resource")
- int[] process(File f) {
- int ok = 0, 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 (!seq_set.get(lr.getRecordId())) {
- ps.executeUpdate();
- seq_set.set(lr.getRecordId());
- } else
- logger.debug("Duplicate record ignored: " + lr.getRecordId());
- } else {
- if (++nextid > set_end)
- nextid = set_start;
- ps.setLong(18, nextid);
- ps.executeUpdate();
- seq_set.set(nextid);
- }
- ps.clearParameters();
- ok++;
- }
- } catch (SQLException e) {
- logger.warn("PROV8003 Invalid value in record: " + line);
- logger.debug(e.toString());
- } catch (NumberFormatException e) {
- logger.warn("PROV8004 Invalid number in record: " + line);
- logger.debug(e.toString());
- } catch (ParseException e) {
- logger.warn("PROV8005 Invalid date in record: " + line);
- logger.debug(e.toString());
- } catch (Exception e) {
- logger.warn("PROV8006 Invalid pattern in record: " + line);
- logger.debug(e.toString());
- }
- total++;
- }
- }
- ps.close();
- db.release(conn);
- conn = null;
- } catch (FileNotFoundException e) {
- logger.warn("PROV8007 Exception reading " + f + ": " + e);
- } catch (IOException e) {
- logger.warn("PROV8007 Exception reading " + f + ": " + e);
- } catch (SQLException 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 (rtype.equals("PUB") && pp.length == 11) {
- // Fields are: date|PUB|pubid|feedid|requrl|method|ctype|clen|srcip|user|status
- return new Loadable[]{new PublishRecord(pp)};
- }
- if (rtype.equals("DEL") && 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 (rtype.equals("EXP") && pp.length == 11) {
- // Fields are: date|EXP|pubid|feedid|subid|requrl|method|ctype|clen|reason|attempts
- ExpiryRecord e = new ExpiryRecord(pp);
- if (e.getReason().equals("other"))
- logger.info("Invalid reason '" + pp[9] + "' changed to 'other' for record: " + e.getPublishId());
- return new Loadable[]{e};
- }
- if (rtype.equals("PBF") && 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 (rtype.equals("DLX") && pp.length == 7) {
- // Fields are: date|DLX|pubid|feedid|subid|clen-tosend|clen-sent
- return new Loadable[]{new DeliveryExtraRecord(pp)};
- }
- if (rtype.equals("LOG") && (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
- * @throws InterruptedException
- */
- public static void main(String[] a) throws InterruptedException {
- LogfileLoader.getLoader();
- Thread.sleep(200000L);
- }
-}
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+
+
+package org.onap.dmaap.datarouter.provisioning.utils;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.nio.file.Files;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeSet;
+import java.util.zip.GZIPInputStream;
+import org.onap.dmaap.datarouter.provisioning.BaseServlet;
+import org.onap.dmaap.datarouter.provisioning.beans.DeliveryExtraRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.DeliveryRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.ExpiryRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Loadable;
+import org.onap.dmaap.datarouter.provisioning.beans.LogRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.Parameters;
+import org.onap.dmaap.datarouter.provisioning.beans.PubFailRecord;
+import org.onap.dmaap.datarouter.provisioning.beans.PublishRecord;
+
+/**
+ * This class provides methods that run in a separate thread, in order to process logfiles uploaded into the spooldir.
+ * These logfiles are loaded into the MariaDB LOG_RECORDS table. In a running provisioning server, there should only be
+ * two places where records can be loaded into this table; here, and in the method DB.retroFit4() which may be run at
+ * startup to load the old (1.0) style log tables into LOG_RECORDS;
+ * <p>This method maintains an {@link RLEBitSet} which can be used to easily see what records are presently in the
+ * database.
+ * This bit set is used to synchronize between provisioning servers.</p>
+ *
+ * @author Robert Eby
+ * @version $Id: LogfileLoader.java,v 1.22 2014/03/12 19:45:41 eby Exp $
+ */
+public class LogfileLoader extends Thread {
+ /**
+ * NOT USED: Percentage of free space required before old records are removed.
+ */
+ public static final int REQUIRED_FREE_PCT = 20;
+
+ /**
+ * This is a singleton -- there is only one LogfileLoader object in the server.
+ */
+ private static LogfileLoader logfileLoader;
+
+ /**
+ * The PreparedStatement which is loaded by a <i>Loadable</i>.
+ */
+ private static final String INSERT_SQL = "insert into LOG_RECORDS values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ /**
+ * Each server can assign this many IDs.
+ */
+ private static final long SET_SIZE = (1L << 56);
+
+ private final EELFLogger logger;
+ private final DB db;
+ private final String spooldir;
+ private final long setStart;
+ private final long setEnd;
+ private RLEBitSet seqSet;
+ private long nextId;
+ private boolean idle;
+
+ /**
+ * Get the singleton LogfileLoader object, and start it if it is not running.
+ *
+ * @return the LogfileLoader
+ */
+ public static synchronized LogfileLoader getLoader() {
+ if (logfileLoader == null) {
+ logfileLoader = new LogfileLoader();
+ }
+ if (!logfileLoader.isAlive()) {
+ logfileLoader.start();
+ }
+ return logfileLoader;
+ }
+
+
+ private LogfileLoader() {
+ this.logger = EELFManager.getInstance().getLogger("InternalLog");
+ this.db = new DB();
+ this.spooldir = db.getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
+ this.setStart = getIdRange();
+ this.setEnd = setStart + SET_SIZE - 1;
+ this.seqSet = new RLEBitSet();
+ this.nextId = 0;
+ this.idle = false;
+ this.setDaemon(true);
+ this.setName("LogfileLoader");
+ }
+
+ private long getIdRange() {
+ long n;
+ if (BaseServlet.isInitialActivePOD()) {
+ n = 0;
+ } else if (BaseServlet.isInitialStandbyPOD()) {
+ n = SET_SIZE;
+ } else {
+ n = SET_SIZE * 2;
+ }
+ String r = String.format("[%X .. %X]", n, n + SET_SIZE - 1);
+ logger.debug("This server shall assign RECORD_IDs in the range " + r);
+ return n;
+ }
+
+ /**
+ * Return the bit set representing the record ID's that are loaded in this database.
+ *
+ * @return the bit set
+ */
+ public RLEBitSet getBitSet() {
+ return seqSet;
+ }
+
+ /**
+ * True if the LogfileLoader is currently waiting for work.
+ *
+ * @return true if idle
+ */
+ public boolean isIdle() {
+ return idle;
+ }
+
+ /**
+ * Run continuously to look for new logfiles in the spool directory and import them into the DB.
+ * The spool is checked once per second. If free space on the MariaDB filesystem falls below
+ * REQUIRED_FREE_PCT (normally 20%) then the oldest logfile entries are removed and the LOG_RECORDS
+ * table is compacted until free space rises above the threshold.
+ */
+ @Override
+ public void run() {
+ initializeNextid();
+ while (true) {
+ try {
+ File dirfile = new File(spooldir);
+ while (true) {
+ runLogFileLoad(dirfile);
+ }
+ } catch (Exception e) {
+ logger.warn("PROV0020: Caught exception in LogfileLoader: " + e);
+ }
+ }
+ }
+
+ private void runLogFileLoad(File filesDir) {
+ File[] inFiles = filesDir.listFiles((dir, name) -> name.startsWith("IN."));
+ if (inFiles != null) {
+ if (inFiles.length == 0) {
+ idle = true;
+ try {
+ Thread.sleep(1000L);
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ }
+ idle = false;
+ } else {
+ // Remove old rows
+ if (pruneRecords()) {
+ // Removed at least some entries, recompute the bit map
+ initializeNextid();
+ }
+ for (File file : inFiles) {
+ processFile(file);
+ }
+ }
+ }
+ }
+
+ private void processFile(File infile) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("PROV8001 Starting " + infile + " ...");
+ }
+ long time = System.currentTimeMillis();
+ int[] n = process(infile);
+ time = System.currentTimeMillis() - time;
+ logger.info(String.format("PROV8000 Processed %s in %d ms; %d of %d records.",
+ infile.toString(), time, n[0], n[1]));
+ try {
+ Files.delete(infile.toPath());
+ } catch (IOException e) {
+ logger.info("PROV8001 failed to delete file " + infile.getName(), e);
+ }
+ }
+
+ boolean pruneRecords() {
+ boolean did1 = false;
+ long count = countRecords();
+ Parameters defaultLogRetention = Parameters.getParameter(Parameters.DEFAULT_LOG_RETENTION);
+ long threshold = (defaultLogRetention != null) ? Long.parseLong(defaultLogRetention.getValue()) : 1000000L;
+ Parameters provLogRetention = Parameters.getParameter(Parameters.PROV_LOG_RETENTION);
+ if (provLogRetention != null) {
+ try {
+ long n = Long.parseLong(provLogRetention.getValue());
+ // This check is to prevent inadvertent errors from wiping the table out
+ if (n > 1000000L) {
+ threshold = n;
+ }
+ } catch (NumberFormatException e) {
+ // ignore
+ }
+ }
+ logger.debug("Pruning LOG_RECORD table: records in DB=" + count + ", threshold=" + threshold);
+ if (count > threshold) {
+ // we need to remove this many records
+ count -= threshold;
+ // histogram of records per day
+ Map<Long, Long> hist = getHistogram();
+ // Determine the cutoff point to remove the needed number of records
+ long sum = 0;
+ long cutoff = 0;
+ for (Long day : new TreeSet<>(hist.keySet())) {
+ sum += hist.get(day);
+ cutoff = day;
+ if (sum >= count) {
+ break;
+ }
+ }
+ cutoff++;
+ // convert day to ms
+ cutoff *= 86400000L;
+ logger.debug(" Pruning records older than=" + (cutoff / 86400000L) + " (" + new Date(cutoff) + ")");
+
+ Connection conn = null;
+ try {
+ // Limit to a million at a time to avoid typing up the DB for too long.
+ conn = db.getConnection();
+ try (PreparedStatement ps = conn.prepareStatement("DELETE from LOG_RECORDS where EVENT_TIME < ? limit 1000000")) {
+ ps.setLong(1, cutoff);
+ while (count > 0) {
+ if (!ps.execute()) {
+ int dcount = ps.getUpdateCount();
+ count -= dcount;
+ logger.debug(" " + dcount + " rows deleted.");
+ did1 |= (dcount != 0);
+ if (dcount == 0) {
+ count = 0; // prevent inf. loops
+ }
+ } else {
+ count = 0; // shouldn't happen!
+ }
+ }
+ }
+ try (Statement stmt = conn.createStatement()) {
+ stmt.execute("OPTIMIZE TABLE LOG_RECORDS");
+ }
+ } catch (SQLException e) {
+ logger.error(e.toString());
+ } finally {
+ db.release(conn);
+ }
+ }
+ return did1;
+ }
+
+ long countRecords() {
+ long count = 0;
+ Connection conn = null;
+ try {
+ conn = db.getConnection();
+ try (Statement stmt = conn.createStatement()) {
+ try (ResultSet rs = stmt.executeQuery("SELECT COUNT(*) as COUNT from LOG_RECORDS")) {
+ if (rs.next()) {
+ count = rs.getLong("COUNT");
+ }
+ }
+ }
+ } catch (SQLException e) {
+ logger.error(e.toString());
+ } finally {
+ db.release(conn);
+ }
+ return count;
+ }
+
+ Map<Long, Long> getHistogram() {
+ Map<Long, Long> map = new HashMap<>();
+ Connection conn = null;
+ try {
+ logger.debug(" LOG_RECORD table histogram...");
+ conn = db.getConnection();
+ try (Statement stmt = conn.createStatement()) {
+ try (ResultSet rs = stmt.executeQuery("SELECT FLOOR(EVENT_TIME/86400000) AS DAY, COUNT(*) AS COUNT FROM LOG_RECORDS GROUP BY DAY")) {
+ while (rs.next()) {
+ long day = rs.getLong("DAY");
+ long cnt = rs.getLong("COUNT");
+ map.put(day, cnt);
+ logger.debug(" " + day + " " + cnt);
+ }
+ }
+ }
+ } catch (SQLException e) {
+ logger.error(e.toString());
+ } finally {
+ db.release(conn);
+ }
+ return map;
+ }
+
+ private void initializeNextid() {
+ Connection conn = null;
+ try {
+ conn = db.getConnection();
+ RLEBitSet nbs = new RLEBitSet();
+ try (Statement stmt = conn.createStatement()) {
+ // Build a bitset of all records in the LOG_RECORDS table
+ // We need to run this SELECT in stages, because otherwise we run out of memory!
+ final long stepsize = 6000000L;
+ boolean goAgain = true;
+ for (long i = 0; goAgain; i += stepsize) {
+ String sql = String.format("select RECORD_ID from LOG_RECORDS LIMIT %d,%d", i, stepsize);
+ try (ResultSet rs = stmt.executeQuery(sql)) {
+ goAgain = false;
+ while (rs.next()) {
+ long n = rs.getLong("RECORD_ID");
+ nbs.set(n);
+ goAgain = true;
+ }
+ }
+ }
+ }
+ seqSet = nbs;
+ // Compare with the range for this server
+ // Determine the next ID for this set of record IDs
+ RLEBitSet tbs = (RLEBitSet) nbs.clone();
+ RLEBitSet idset = new RLEBitSet();
+ idset.set(setStart, setStart + SET_SIZE);
+ tbs.and(idset);
+ long t = tbs.length();
+ nextId = (t == 0) ? setStart : (t - 1);
+ if (nextId >= setStart + SET_SIZE) {
+ // Handle wraparound, when the IDs reach the end of our "range"
+ Long[] last = null;
+ Iterator<Long[]> li = tbs.getRangeIterator();
+ while (li.hasNext()) {
+ last = li.next();
+ }
+ if (last != null) {
+ tbs.clear(last[0], last[1] + 1);
+ t = tbs.length();
+ nextId = (t == 0) ? setStart : (t - 1);
+ }
+ }
+ logger.debug(String.format("initializeNextid, next ID is %d (%x)", nextId, nextId));
+ } catch (SQLException e) {
+ logger.error(e.toString());
+ } finally {
+ db.release(conn);
+ }
+ }
+
+ @SuppressWarnings("resource")
+ int[] process(File f) {
+ int ok = 0;
+ int total = 0;
+ try {
+ Connection conn = db.getConnection();
+ PreparedStatement ps = conn.prepareStatement(INSERT_SQL);
+ Reader r = f.getPath().endsWith(".gz")
+ ? new InputStreamReader(new GZIPInputStream(new FileInputStream(f)))
+ : new FileReader(f);
+ try (LineNumberReader in = new LineNumberReader(r)) {
+ String line;
+ while ((line = in.readLine()) != null) {
+ try {
+ for (Loadable rec : buildRecords(line)) {
+ rec.load(ps);
+ if (rec instanceof LogRecord) {
+ LogRecord lr = ((LogRecord) rec);
+ if (!seqSet.get(lr.getRecordId())) {
+ ps.executeUpdate();
+ seqSet.set(lr.getRecordId());
+ } else {
+ logger.debug("Duplicate record ignored: " + lr.getRecordId());
+ }
+ } else {
+ if (++nextId > setEnd) {
+ nextId = setStart;
+ }
+ ps.setLong(18, nextId);
+ ps.executeUpdate();
+ seqSet.set(nextId);
+ }
+ ps.clearParameters();
+ ok++;
+ }
+ } catch (SQLException e) {
+ logger.warn("PROV8003 Invalid value in record: " + line, e);
+ } catch (NumberFormatException e) {
+ logger.warn("PROV8004 Invalid number in record: " + line, e);
+ } catch (ParseException e) {
+ logger.warn("PROV8005 Invalid date in record: " + line, e);
+ } catch (Exception e) {
+ logger.warn("PROV8006 Invalid pattern in record: " + line, e);
+ }
+ total++;
+ }
+ }
+ ps.close();
+ db.release(conn);
+ } catch (SQLException | IOException e) {
+ logger.warn("PROV8007 Exception reading " + f + ": " + e);
+ }
+ return new int[]{ok, total};
+ }
+
+ Loadable[] buildRecords(String line) throws ParseException {
+ String[] pp = line.split("\\|");
+ if (pp != null && pp.length >= 7) {
+ String rtype = pp[1].toUpperCase();
+ if ("PUB".equals(rtype) && pp.length == 11) {
+ // Fields are: date|PUB|pubid|feedid|requrl|method|ctype|clen|srcip|user|status
+ return new Loadable[]{new PublishRecord(pp)};
+ }
+ if ("DEL".equals(rtype) && pp.length == 12) {
+ // Fields are: date|DEL|pubid|feedid|subid|requrl|method|ctype|clen|user|status|xpubid
+ String[] subs = pp[4].split("\\s+");
+ if (subs != null) {
+ Loadable[] rv = new Loadable[subs.length];
+ for (int i = 0; i < subs.length; i++) {
+ // create a new record for each individual sub
+ pp[4] = subs[i];
+ rv[i] = new DeliveryRecord(pp);
+ }
+ return rv;
+ }
+ }
+ if ("EXP".equals(rtype) && pp.length == 11) {
+ // Fields are: date|EXP|pubid|feedid|subid|requrl|method|ctype|clen|reason|attempts
+ ExpiryRecord e = new ExpiryRecord(pp);
+ if ("other".equals(e.getReason())) {
+ logger.info("Invalid reason '" + pp[9] + "' changed to 'other' for record: " + e.getPublishId());
+ }
+ return new Loadable[]{e};
+ }
+ if ("PBF".equals(rtype) && pp.length == 12) {
+ // Fields are: date|PBF|pubid|feedid|requrl|method|ctype|clen-expected|clen-received|srcip|user|error
+ return new Loadable[]{new PubFailRecord(pp)};
+ }
+ if ("DLX".equals(rtype) && pp.length == 7) {
+ // Fields are: date|DLX|pubid|feedid|subid|clen-tosend|clen-sent
+ return new Loadable[]{new DeliveryExtraRecord(pp)};
+ }
+ if ("LOG".equals(rtype) && (pp.length == 19 || pp.length == 20)) {
+ // Fields are: date|LOG|pubid|feedid|requrl|method|ctype|clen|type|feedFileid|remoteAddr|user|status|subid|fileid|result|attempts|reason|record_id
+ return new Loadable[]{new LogRecord(pp)};
+ }
+ }
+ logger.warn("PROV8002 bad record: " + line);
+ return new Loadable[0];
+ }
+
+ /**
+ * The LogfileLoader can be run stand-alone by invoking the main() method of this class.
+ *
+ * @param a ignored
+ */
+ public static void main(String[] a) throws InterruptedException {
+ LogfileLoader.getLoader();
+ Thread.sleep(200000L);
+ }
+}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java
index 44142031..cb6881fb 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java
@@ -21,14 +21,15 @@
package org.onap.dmaap.datarouter.provisioning.utils;
+import java.nio.charset.StandardCharsets;
+import java.security.GeneralSecurityException;
+import java.util.Base64;
+
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
-import java.nio.charset.StandardCharsets;
-import java.security.GeneralSecurityException;
-import java.util.Base64;
/**
* The Processing of a Password. Password can be encrypted and decrypted.
@@ -37,13 +38,14 @@ import java.util.Base64;
*/
public class PasswordProcessor {
- private PasswordProcessor(){}
-
private static final String SECRET_KEY_FACTORY_TYPE = "PBEWithMD5AndDES";
private static final String PASSWORD_ENCRYPTION_STRING = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.passwordencryption");
private static final char[] PASSWORD = PASSWORD_ENCRYPTION_STRING.toCharArray();
private static final byte[] SALT = {(byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12, (byte) 0xde, (byte) 0x33, (byte) 0x10, (byte) 0x12,};
+ private PasswordProcessor(){
+ }
+
/**
* Encrypt password.
* @param property the Password
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
index f3e84b4a..8c67e71f 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PurgeLogDirTask.java
@@ -51,7 +51,7 @@ public class PurgeLogDirTask extends TimerTask {
logdir = p.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir");
String s = p.getProperty("org.onap.dmaap.datarouter.provserver.logretention", "30");
- this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");;
+ this.utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");
long n = 30;
try {
@@ -75,7 +75,7 @@ public class PurgeLogDirTask extends TimerTask {
}
}
} catch (Exception e) {
- utilsLogger.error("Exception: " + e.getMessage());
+ utilsLogger.error("Exception: " + e.getMessage(), e);
}
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
index c9fb5a16..5c1fd560 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ThrottleFilter.java
@@ -138,7 +138,7 @@ public class ThrottleFilter extends TimerTask implements Filter {
}
}
} catch (ClassNotFoundException e) {
- logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.");
+ logger.warn("Class " + JETTY_REQUEST + " is not available; this filter requires Jetty.", e);
}
}
logger.info("ThrottleFilter is DISABLED for /publish requests.");
@@ -275,7 +275,7 @@ public class ThrottleFilter extends TimerTask implements Filter {
t = times.get(0);
}
} catch (IndexOutOfBoundsException e) {
- // ignore
+ logger.trace("Exception: " + e.getMessage(), e);
}
return times.size();
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
index 0c6afdd7..ffed1a1b 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/URLUtilities.java
@@ -24,6 +24,8 @@
package org.onap.dmaap.datarouter.provisioning.utils;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Arrays;
@@ -37,7 +39,7 @@ import org.onap.dmaap.datarouter.provisioning.BaseServlet;
* @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $
*/
public class URLUtilities {
-
+ private static final EELFLogger utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");
/**
* Generate the URL used to access a feed.
*
@@ -134,6 +136,7 @@ public class URLUtilities {
this_pod = InetAddress.getLocalHost().getHostName();
System.out.println("this_pod: " + this_pod);
} catch (UnknownHostException e) {
+ utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);
this_pod = "";
}
System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));
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
index 00000000..7de4ea91
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/authz/impl/ProvAuthTest.java
@@ -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());
+ }
+
+}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
index 79c3d219..ca84e6d5 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
@@ -23,17 +23,24 @@
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"));
+ }
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
index bad6e2cb..42366dd0 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
@@ -47,10 +47,11 @@ public class DrServletTestBase {
props.setProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir", "unit-test-logs");
props.setProperty("org.onap.dmaap.datarouter.provserver.spooldir", "unit-test-logs/spool");
props.setProperty("org.onap.dmaap.datarouter.provserver.https.relaxation", "false");
+ props.setProperty("org.onap.dmaap.datarouter.provserver.passwordencryption", "PasswordEncryptionKey#@$%^&1234#");
FieldUtils.writeDeclaredStaticField(DB.class, "props", props, true);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "startmsgFlag", false, true);
SynchronizerTask synchronizerTask = mock(SynchronizerTask.class);
- when(synchronizerTask.getState()).thenReturn(SynchronizerTask.UNKNOWN);
+ when(synchronizerTask.getPodState()).thenReturn(SynchronizerTask.UNKNOWN_POD);
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true);
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
index f4eac05f..a1f714bb 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
@@ -109,7 +109,6 @@ public class FeedServletTest extends DrServletTestBase {
verifyEnteringExitCalled(listAppender);
}
-
@Test
public void Given_Request_Is_HTTP_DELETE_And_BEHALF_HEADER_Is_Not_Set_In_Request_Then_Bad_Request_Response_Is_Generated()
throws Exception {
@@ -118,7 +117,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_DELETE_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated() throws Exception {
when(request.getPathInfo()).thenReturn(null);
@@ -126,7 +124,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_DELETE_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated() throws Exception {
when(request.getPathInfo()).thenReturn("/123");
@@ -134,7 +131,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_DELETE_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated() throws Exception {
setAuthoriserToReturnRequestNotAuthorized();
@@ -158,7 +154,6 @@ public class FeedServletTest extends DrServletTestBase {
verifyEnteringExitCalled(listAppender);
}
-
@Test
public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Fails_An_Internal_Server_Error_Is_Reported()
throws Exception {
@@ -172,7 +167,6 @@ public class FeedServletTest extends DrServletTestBase {
.sendError(eq(HttpServletResponse.SC_INTERNAL_SERVER_ERROR), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Succeeds_A_NO_CONTENT_Response_Is_Generated() throws Exception {
feedServlet.doDelete(request, response);
@@ -198,7 +192,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_GET_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
throws Exception {
@@ -207,7 +200,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_GET_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
throws Exception {
@@ -216,7 +208,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_NOT_FOUND), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_GET_And_Request_Is_Not_Authorized_Then_Forbidden_Response_Is_Generated()
throws Exception {
@@ -226,7 +217,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_GET_And_Request_Succeeds() throws Exception {
ServletOutputStream outStream = mock(ServletOutputStream.class);
@@ -237,7 +227,6 @@ public class FeedServletTest extends DrServletTestBase {
verifyEnteringExitCalled(listAppender);
}
-
@Test
public void Given_Request_Is_HTTP_PUT_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated()
throws Exception {
@@ -255,7 +244,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_PUT_And_Path_Header_Is_Not_Set_In_Request_With_Valid_Path_Then_Bad_Request_Response_Is_Generated()
throws Exception {
@@ -264,7 +252,6 @@ public class FeedServletTest extends DrServletTestBase {
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
}
-
@Test
public void Given_Request_Is_HTTP_PUT_And_Feed_Id_Is_Invalid_Then_Not_Found_Response_Is_Generated()
throws Exception {
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
index b867c672..57007489 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
@@ -22,8 +22,25 @@
******************************************************************************/
package org.onap.dmaap.datarouter.provisioning;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.mockito.Mockito.argThat;
+import static org.mockito.Mockito.contains;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
+
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
+import java.util.HashSet;
+import java.util.Set;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
@@ -36,30 +53,11 @@ import org.mockito.Mock;
import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
import org.onap.dmaap.datarouter.authz.Authorizer;
import org.onap.dmaap.datarouter.provisioning.beans.Insertable;
-import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import javax.servlet.ServletOutputStream;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import static org.hamcrest.Matchers.notNullValue;
-import static org.mockito.Mockito.*;
-import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
-
@RunWith(PowerMockRunner.class)
-@PrepareForTest(Subscription.class)
public class SubscribeServletTest extends DrServletTestBase {
private static SubscribeServlet subscribeServlet;
private static EntityManagerFactory emf;
@@ -144,10 +142,6 @@ public class SubscribeServletTest extends DrServletTestBase {
ServletOutputStream outStream = mock(ServletOutputStream.class);
when(response.getOutputStream()).thenReturn(outStream);
when(request.getPathInfo()).thenReturn("/1");
- PowerMockito.mockStatic(Subscription.class);
- List<String> list = new ArrayList<>();
- list.add("{}");
- PowerMockito.when(Subscription.getSubscriptionUrlList(anyInt())).thenReturn(list);
subscribeServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
verifyEnteringExitCalled(listAppender);
@@ -294,8 +288,6 @@ public class SubscribeServletTest extends DrServletTestBase {
when(response.getOutputStream()).thenReturn(outStream);
when(request.getPathInfo()).thenReturn("/2");
when(request.isUserInRole("org.onap.dmaap-dr.feed|*|approveSub")).thenReturn(true);
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionMatching(new Subscription())).thenReturn(null);
JSONObject JSObject = buildRequestJsonObject();
SubscribeServlet subscribeServlet = new SubscribeServlet() {
protected JSONObject getJSONfromInput(HttpServletRequest req) {
@@ -353,8 +345,6 @@ public class SubscribeServletTest extends DrServletTestBase {
@Test
public void Given_Request_Is_HTTP_POST_And_POST_Fails_Bad_Request_Response_Is_Generated() throws Exception {
when(request.getPathInfo()).thenReturn("/2");
- PowerMockito.mockStatic(Subscription.class);
- PowerMockito.when(Subscription.getSubscriptionMatching(new Subscription())).thenReturn(null);
JSONObject JSObject = buildRequestJsonObject();
SubscribeServlet subscribeServlet = new SubscribeServlet() {
protected JSONObject getJSONfromInput(HttpServletRequest req) {
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
index a17e23e0..4a410ddd 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
@@ -323,6 +323,7 @@ public class SubscriptionServletTest extends DrServletTestBase {
subscriptionServlet.doPut(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
resetAafSubscriptionInDB();
+ addNewSubscriptionInDB();
verifyEnteringExitCalled(listAppender);
}
@@ -627,4 +628,18 @@ public class SubscriptionServletTest extends DrServletTestBase {
subscription.setPrivilegedSubscriber(false);
subscription.doUpdate(db.getConnection());
}
+
+ private void addNewSubscriptionInDB() throws SQLException {
+ Subscription subscription = new Subscription("https://172.100.0.6:8080", "user3", "password3");
+ subscription.setSubid(3);
+ subscription.setSubscriber("user3");
+ subscription.setFeedid(1);
+ SubDelivery subDelivery = new SubDelivery(URL, USER, PASSWORD, true);
+ subscription.setDelivery(subDelivery);
+ subscription.setGroupid(1);
+ subscription.setMetadataOnly(false);
+ subscription.setSuspended(false);
+ subscription.setDecompress(false);
+ subscription.doInsert(db.getConnection());
+ }
} \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
new file mode 100755
index 00000000..8c48d705
--- /dev/null
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTaskTest.java
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * ============LICENSE_START==================================================
+ * * org.onap.dmaap
+ * * ===========================================================================
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * * ===========================================================================
+ * * Licensed under the Apache License, Version 2.0 (the "License");
+ * * you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS,
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * * See the License for the specific language governing permissions and
+ * * limitations under the License.
+ * * ============LICENSE_END====================================================
+ * *
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * *
+ ******************************************************************************/
+
+package org.onap.dmaap.datarouter.provisioning;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.powermock.api.mockito.PowerMockito.when;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.http.HttpEntity;
+import org.apache.http.StatusLine;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.client.AbstractHttpClient;
+import org.apache.http.message.BasicHeader;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.onap.dmaap.datarouter.provisioning.utils.RLEBitSet;
+import org.onap.dmaap.datarouter.provisioning.utils.URLUtilities;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("javax.net.ssl.*")
+@PrepareForTest({BaseServlet.class, URLUtilities.class})
+public class SynchronizerTaskTest {
+
+ @Mock
+ private AbstractHttpClient httpClient;
+
+ @Mock
+ private HttpEntity httpEntity;
+
+ @Mock
+ private StatusLine statusLine;
+
+ @Mock
+ private CloseableHttpResponse response;
+
+ private SynchronizerTask synchronizerTask;
+
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+
+ @BeforeClass
+ public static void init() {
+ emf = Persistence.createEntityManagerFactory("dr-unit-tests");
+ em = emf.createEntityManager();
+ System.setProperty(
+ "org.onap.dmaap.datarouter.provserver.properties",
+ "src/test/resources/h2Database.properties");
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ em.clear();
+ em.close();
+ emf.close();
+ }
+
+
+ @Before
+ public void setUp() throws IllegalAccessException, UnknownHostException {
+ SSLSocketFactory sslSocketFactory = mock(SSLSocketFactory.class);
+ doNothing().when(sslSocketFactory).setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
+
+ PowerMockito.mockStatic(BaseServlet.class);
+ PowerMockito.mockStatic(URLUtilities.class);
+ when(BaseServlet.getPods()).thenReturn(new String[] {InetAddress.getLocalHost().getHostName(), "stand-by-prov"});
+ when(URLUtilities.generatePeerProvURL()).thenReturn("https://stand-by-prov/internal/prov");
+ when(URLUtilities.generatePeerLogsURL()).thenReturn("https://stand-by-prov/internal/drlogs");
+
+ synchronizerTask = Mockito.spy(SynchronizerTask.getSynchronizer());
+ doReturn(2).when(synchronizerTask).lookupState();
+ }
+
+ @After
+ public void tearDown() {
+ }
+
+ @Test
+ public void Given_Synch_Task_readRemoteLoglist_Called_And_Valid_BitSet_Returned_Success()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+ Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
+ Mockito.when(httpEntity.getContent()).thenReturn(new ByteArrayInputStream("1-55251".getBytes()));
+ RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+ Assert.assertNotNull(rleBitSet);
+ }
+
+ @Test
+ public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Resonse_Code_Failure()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
+ RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+ Assert.assertNotNull(rleBitSet);
+ }
+
+ @Test
+ public void Given_Synch_Task_readRemoteLoglist_Called_And_Invalid_Content_Type_Failure()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+ Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
+ RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+ Assert.assertNotNull(rleBitSet);
+ }
+
+ @Test
+ public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Valid_BitSet_Returned_Success()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+ Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "text/plain"));
+ RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+ synchronizerTask.replicateDataRouterLogs(rleBitSet);
+ }
+
+ @Test
+ public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Content_Type_Failure()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+ Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "invalid_content_type"));
+ RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+ synchronizerTask.replicateDataRouterLogs(rleBitSet);
+ }
+
+ @Test
+ public void Given_Synch_Task_replicateDataRouterLogs_Called_And_Invalid_Resonse_Code_Failure()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(404);
+ RLEBitSet rleBitSet = synchronizerTask.readRemoteLoglist();
+ synchronizerTask.replicateDataRouterLogs(rleBitSet);
+ }
+
+ @Test
+ public void Given_Synch_Task_Is_Started_And_LogFileLoader_Is_Idle_Then_Standby_Pod_Synch_Is_Successful()
+ throws IOException, IllegalAccessException {
+ mockHttpClientForGetRequest();
+ Mockito.when(response.getStatusLine().getStatusCode()).thenReturn(200);
+ Mockito.when(httpEntity.getContentType()).thenReturn(new BasicHeader("header", "application/vnd.dmaap-dr.provfeed-full; version=1.0"));
+ mockResponseFromGet();
+ synchronizerTask.run();
+ }
+
+
+ private void mockHttpClientForGetRequest() throws IllegalAccessException, IOException {
+ FieldUtils.writeField(synchronizerTask, "httpclient", httpClient, true);
+ Mockito.when(httpClient.execute(anyObject())).thenReturn(response);
+ Mockito.when(response.getEntity()).thenReturn(httpEntity);
+ Mockito.when(response.getStatusLine()).thenReturn(statusLine);
+
+ }
+
+ private void mockResponseFromGet() throws IOException {
+ InputStream in = getClass().getClassLoader().getResourceAsStream("prov_data.json");
+ Mockito.when(httpEntity.getContent()).thenReturn(in);
+ }
+}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
index d859e082..214cc6e7 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/beans/SubscriptionTest.java
@@ -23,22 +23,50 @@
package org.onap.dmaap.datarouter.provisioning.beans;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.powermock.modules.junit4.PowerMockRunner;
-
@RunWith(PowerMockRunner.class)
-@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Subscription"})
public class SubscriptionTest {
private Subscription subscription;
+ private static EntityManagerFactory emf;
+ private static EntityManager em;
+ private DB db;
+
+ @BeforeClass
+ public static void init() {
+ emf = Persistence.createEntityManagerFactory("dr-unit-tests");
+ em = emf.createEntityManager();
+ System.setProperty(
+ "org.onap.dmaap.datarouter.provserver.properties",
+ "src/test/resources/h2Database.properties");
+ }
+
+ @AfterClass
+ public static void tearDownClass() {
+ em.clear();
+ em.close();
+ emf.close();
+ }
+ @Before
+ public void setUp() throws Exception {
+ db = new DB();
+ subscription = new Subscription();
+ }
+
@Test
public void validate_Subscription_Created_With_Default_Constructor() {
- subscription = new Subscription();
Assert.assertEquals(subscription.getSubid(), -1);
Assert.assertEquals(subscription.getGroupid(), -1);
Assert.assertEquals(subscription.getSubscriber(), "");
@@ -56,13 +84,13 @@ public class SubscriptionTest {
subLinks.setLog("log");
subLinks.setSelf("self");
- subscription = new Subscription();
subscription.setGroupid(2);
subscription.setDelivery(subDelivery);
subscription.setMetadataOnly(false);
subscription.setSubscriber(subscriber);
subscription.setSuspended(false);
subscription.setPrivilegedSubscriber(false);
+ subscription.setFollowRedirect(true);
subscription.setLinks(subLinks);
subscription.setDecompress(false);
@@ -73,5 +101,19 @@ public class SubscriptionTest {
Assert.assertFalse(subscription.isSuspended());
Assert.assertFalse(subscription.isPrivilegedSubscriber());
Assert.assertFalse(subscription.isDecompress());
+
+ Subscription sub2 = new Subscription();
+ sub2.setGroupid(2);
+ sub2.setDelivery(subDelivery);
+ sub2.setMetadataOnly(false);
+ sub2.setSubscriber(subscriber);
+ sub2.setSuspended(false);
+ sub2.setPrivilegedSubscriber(false);
+ sub2.setFollowRedirect(true);
+ sub2.setLinks(subLinks);
+ sub2.setDecompress(false);
+ Assert.assertTrue(subscription.equals(sub2));
+ Assert.assertNotNull(sub2.toString());
+ sub2.hashCode();
}
} \ No newline at end of file
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
index 7f6d7de6..a15509b4 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/utils/LogfileLoaderTest.java
@@ -20,32 +20,29 @@
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/resources/create.sql b/datarouter-prov/src/test/resources/create.sql
index 7c106723..a811847c 100755
--- a/datarouter-prov/src/test/resources/create.sql
+++ b/datarouter-prov/src/test/resources/create.sql
@@ -186,6 +186,9 @@ insert into INGRESS_ROUTES(SEQUENCE, FEEDID , USERID, SUBNET, NODESET)
VALUES (2,1,'user',null,2);
insert into NODESETS(SETID, NODEID)
+VALUES (1,1);
+
+insert into NODESETS(SETID, NODEID)
VALUES (2,2);
insert into LOG_RECORDS(RECORD_ID,TYPE,EVENT_TIME,PUBLISH_ID,FEEDID,REQURI,METHOD,CONTENT_TYPE,CONTENT_LENGTH,FEED_FILEID,REMOTE_ADDR,USER,STATUS,DELIVERY_SUBID,DELIVERY_FILEID,RESULT,ATTEMPTS,REASON,FILENAME)
diff --git a/datarouter-prov/src/test/resources/h2Database.properties b/datarouter-prov/src/test/resources/h2Database.properties
index fee9c688..cb472419 100755
--- a/datarouter-prov/src/test/resources/h2Database.properties
+++ b/datarouter-prov/src/test/resources/h2Database.properties
@@ -27,6 +27,13 @@ org.onap.dmaap.datarouter.db.url = jdbc:h2:mem:test;DB
org.onap.dmaap.datarouter.provserver.isaddressauthenabled = true
org.onap.dmaap.datarouter.provserver.https.relaxation = false
org.onap.dmaap.datarouter.provserver.accesslog.dir = unit-test-logs
-org.onap.dmaap.datarouter.provserver.spooldir = unit-test-logs/spool
+org.onap.dmaap.datarouter.provserver.spooldir = src/test/resources
org.onap.dmaap.datarouter.provserver.localhost = 127.0.0.1
-org.onap.dmaap.datarouter.provserver.passwordencryption = PasswordEncryptionKey#@$%^&1234# \ No newline at end of file
+org.onap.dmaap.datarouter.provserver.passwordencryption = PasswordEncryptionKey#@$%^&1234#
+
+org.onap.dmaap.datarouter.provserver.keystore.type = jks
+org.onap.dmaap.datarouter.provserver.keymanager.password = FZNkU,B%NJzcT1v7;^v]M#ZX
+org.onap.dmaap.datarouter.provserver.keystore.path = aaf_certs/org.onap.dmaap-dr.jks
+org.onap.dmaap.datarouter.provserver.keystore.password = FZNkU,B%NJzcT1v7;^v]M#ZX
+org.onap.dmaap.datarouter.provserver.truststore.path = aaf_certs/org.onap.dmaap-dr.trust.jks
+org.onap.dmaap.datarouter.provserver.truststore.password = +mzf@J.D^;3!![*Xr.z$c#?b \ No newline at end of file
diff --git a/datarouter-prov/src/test/resources/prov_data.json b/datarouter-prov/src/test/resources/prov_data.json
new file mode 100644
index 00000000..32536316
--- /dev/null
+++ b/datarouter-prov/src/test/resources/prov_data.json
@@ -0,0 +1,129 @@
+{
+ "feeds": [
+ {
+ "suspend": false,
+ "groupid": 0,
+ "description": "Default feed provisioned for PM File collector",
+ "version": "m1.0",
+ "authorization": {
+ "endpoint_addrs": [
+
+ ],
+ "classification": "unclassified",
+ "endpoint_ids": [
+ {
+ "password": "dradmin",
+ "id": "dradmin"
+ }
+ ]
+ },
+ "last_mod": 1560871903000,
+ "deleted": false,
+ "feedid": 1,
+ "name": "Default PM Feed",
+ "business_description": "Default Feed",
+ "aaf_instance": "legacy",
+ "publisher": "dradmin",
+ "links": {
+ "subscribe": "https://dmaap-dr-prov/subscribe/1",
+ "log": "https://dmaap-dr-prov/feedlog/1",
+ "publish": "https://dmaap-dr-prov/publish/1",
+ "self": "https://dmaap-dr-prov/feed/1"
+ },
+ "created_date": 1560871903000
+ }
+ ],
+ "groups": [
+ {
+ "authid": "GROUP-0000-c2754bb7-92ef-4869-9c6b-1bc1283be4c0",
+ "name": "Test Group",
+ "description": "Test Description of Group .",
+ "classification": "publisher/subscriber",
+ "members": "{id=attuid, name=User1}, {id=attuid, name=User 2]"
+ }
+ ],
+ "subscriptions": [
+ {
+ "suspend": false,
+ "delivery": {
+ "use100": true,
+ "password": "PASSWORD",
+ "user": "LOGIN",
+ "url": "https://dcae-pm-mapper:8443/delivery"
+ },
+ "subscriber": "dradmin",
+ "groupid": 0,
+ "metadataOnly": false,
+ "privilegedSubscriber": true,
+ "subid": 1,
+ "last_mod": 1560872889000,
+ "feedid": 1,
+ "follow_redirect": false,
+ "decompress": true,
+ "aaf_instance": "legacy",
+ "links": {
+ "feed": "https://dmaap-dr-prov/feed/1",
+ "log": "https://dmaap-dr-prov/sublog/1",
+ "self": "https://dmaap-dr-prov/subs/1"
+ },
+ "created_date": 1560872889000
+ }
+ ],
+ "parameters": {
+ "ACTIVE_POD": "dmaap-dr-prov",
+ "DELIVERY_FILE_PROCESS_INTERVAL": 10,
+ "DELIVERY_INIT_RETRY_INTERVAL": 10,
+ "DELIVERY_MAX_AGE": 86400,
+ "DELIVERY_MAX_RETRY_INTERVAL": 3600,
+ "DELIVERY_RETRY_RATIO": 2,
+ "LOGROLL_INTERVAL": 30,
+ "NODES": [
+ "dmaap-dr-node"
+ ],
+ "PROV_ACTIVE_NAME": "dmaap-dr-prov",
+ "PROV_AUTH_ADDRESSES": [
+ "dmaap-dr-prov",
+ "dmaap-dr-node"
+ ],
+ "PROV_AUTH_SUBJECTS": [
+ ""
+ ],
+ "PROV_DOMAIN": "",
+ "PROV_MAXFEED_COUNT": 10000,
+ "PROV_MAXSUB_COUNT": 100000,
+ "PROV_NAME": "dmaap-dr-prov",
+ "PROV_REQUIRE_CERT": "false",
+ "PROV_REQUIRE_SECURE": "true",
+ "STANDBY_POD": "",
+ "_INT_VALUES": [
+ "LOGROLL_INTERVAL",
+ "PROV_MAXFEED_COUNT",
+ "PROV_MAXSUB_COUNT",
+ "DELIVERY_INIT_RETRY_INTERVAL",
+ "DELIVERY_MAX_RETRY_INTERVAL",
+ "DELIVERY_RETRY_RATIO",
+ "DELIVERY_MAX_AGE",
+ "DELIVERY_FILE_PROCESS_INTERVAL"
+ ]
+ },
+ "ingress": [
+ {
+ "feedid": 1,
+ "subnet": "",
+ "user": "",
+ "node": [
+ "stub_from."
+ ]
+ }
+ ],
+ "egress": {
+ "1": "stub_to."
+ },
+ "routing": [
+ {
+ "from": 1,
+ "to": 3,
+ "via": 2
+ }
+ ]
+} \ No newline at end of file