aboutsummaryrefslogtreecommitdiffstats
path: root/ONAP-PDP-REST/src
diff options
context:
space:
mode:
authorPamela Dragosh <pdragosh@research.att.com>2018-02-08 17:55:25 +0000
committerGerrit Code Review <gerrit@onap.org>2018-02-08 17:55:25 +0000
commit321417267ab93b0a8f0244aef07c45cdc37dbef4 (patch)
treef795a51f0e61f2f1bac11529f55eaf1e963835f6 /ONAP-PDP-REST/src
parent9a322232dd7840065a37004000372f4332b055c9 (diff)
parentc5d97e8a9a6bea71f3be329a2e44bdbe5fe50882 (diff)
Merge "MS Model Input Validation"
Diffstat (limited to 'ONAP-PDP-REST/src')
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java7
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java26
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java16
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java20
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/NotificationService.java5
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java27
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationController.java36
-rw-r--r--ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java6
-rw-r--r--ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java18
9 files changed, 102 insertions, 59 deletions
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
index 9b2b61f76..5c9f8602f 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpLoader.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -107,10 +107,12 @@ public class XACMLPdpLoader {
// - creating new "<PolicyId>.file" properties for files existing
// local
//
+ LOGGER.info("XACMLPdpLoader: cache the policies.");
XACMLPdpLoader.cachePolicies(policyProperties);
//
// Validate the policies
//
+ LOGGER.info("XACMLPdpLoader: validating the policies.");
XACMLPdpLoader.validatePolicies(policyProperties, status);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Status: " + status);
@@ -215,12 +217,13 @@ public class XACMLPdpLoader {
.getReferencedPolicyIDs(properties);
policyContainer = new HashMap<String, PolicyDef>();
+ LOGGER.info("XACMLPdpLoader: load rootPolicies");
for (String id : rootPolicies) {
loadPolicy(properties, status, id, true);
}
// remember which policies were root policies
status.addAllLoadedRootPolicies(status.getLoadedPolicies());
-
+ LOGGER.info("XACMLPdpLoader: load referencedPolicies");
for (String id : refPolicies) {
loadPolicy(properties, status, id, false);
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
index 04572ccbc..608295325 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/XACMLPdpServlet.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -208,8 +208,8 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
XACMLRest.xacmlInit(config);
// Load the Notification Delay.
setNotificationDelay();
- // Load Queue size.
- int queueSize = 5; // Set default Queue Size here.
+ // Load Queue size. Not sure if we really need to have the queue bounded, we should look further into this
+ int queueSize = 50; // Set default Queue Size here.
queueSize = Integer.parseInt(XACMLProperties.getProperty("REQUEST_BUFFER_SIZE",String.valueOf(queueSize)));
initQueue(queueSize);
// Load our engine - this will use the latest configuration
@@ -477,6 +477,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
im.endTransaction();
return;
}
+ logger.info("XACMLPdpServlet: calling doPutConfig to add properties to the queue");
this.doPutConfig(cache, request, response, loggingContext);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction ended");
@@ -504,6 +505,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
protected void doPutConfig(String config, HttpServletRequest request, HttpServletResponse response, ONAPLoggingContext loggingContext) throws ServletException, IOException {
try {
// prevent multiple configuration changes from stacking up
+ logger.info("XACMLPdpServlet: checking remainingCapacity of Queue.");
if (XACMLPdpServlet.queue.remainingCapacity() <= 0) {
logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Queue capacity reached");
PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Queue capacity reached");
@@ -542,6 +544,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=policies must contain at least one policy property");
return;
}
+ logger.info("XACMLPdpServlet: offer policies to queue. No pip properties added.");
XACMLPdpServlet.queue.offer(new PutRequest(newProperties, null));
loggingContext.transactionEnded();
auditLogger.info("Success");
@@ -556,6 +559,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=pips must contain at least one pip property");
return;
}
+ logger.info("XACMLPdpServlet: offer pips to queue. No policy properties added.");
XACMLPdpServlet.queue.offer(new PutRequest(null, newProperties));
loggingContext.transactionEnded();
auditLogger.info("Success");
@@ -579,10 +583,12 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "PUT with cache=all must contain at least one pip property");
return;
}
+ logger.info("XACMLPdpServlet: offer policies and pips to queue.");
XACMLPdpServlet.queue.offer(new PutRequest(newPolicyProperties, newPipProperties));
loggingContext.transactionEnded();
auditLogger.info("Success");
PolicyLogger.audit("Success");
+
} else {
//
// Invalid value
@@ -1238,25 +1244,32 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
try {
// variable not used, but constructor has needed side-effects so don't remove:
while (! XACMLPdpServlet.configThreadTerminate) {
+ logger.info("XACMLPdpServlet: Taking requests from the queue");
PutRequest request = XACMLPdpServlet.queue.take();
+ logger.info("XACMLPdpServlet: Taking requests from the queue COMPLETED");
StdPDPStatus newStatus = new StdPDPStatus();
PDPEngine newEngine = null;
synchronized(pdpStatusLock) {
XACMLPdpServlet.status.setStatus(Status.UPDATING_CONFIGURATION);
+
+ logger.info("created new PDPEngine");
newEngine = XACMLPdpLoader.loadEngine(newStatus, request.policyProperties, request.pipConfigProperties);
}
if (newEngine != null) {
+ logger.info("XACMLPdpServlet: newEngine created, assigning newEngine to the pdpEngine.");
synchronized(XACMLPdpServlet.pdpEngineLock) {
XACMLPdpServlet.pdpEngine = newEngine;
try {
logger.info("Saving configuration.");
if (request.policyProperties != null) {
+ logger.info("Saving configuration: Policy Properties: " + request.policyProperties);
try (OutputStream os = Files.newOutputStream(XACMLPdpLoader.getPDPPolicyCache())) {
request.policyProperties.store(os, "");
}
}
if (request.pipConfigProperties != null) {
+ logger.info("Saving configuration: PIP Properties: " + request.pipConfigProperties);
try (OutputStream os = Files.newOutputStream(XACMLPdpLoader.getPIPConfig())) {
request.pipConfigProperties.store(os, "");
}
@@ -1269,14 +1282,17 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable {
newStatus.addLoadWarning("Unable to save configuration: " + e.getMessage());
}
}
- // Notification will be Sent Here.
- XACMLPdpLoader.sendNotification();
} else {
newStatus.setStatus(Status.LAST_UPDATE_FAILED);
}
synchronized(pdpStatusLock) {
XACMLPdpServlet.status.set(newStatus);
}
+ logger.info("New PDP Servlet Status: " + newStatus.getStatus());
+ if (Status.UP_TO_DATE.equals(newStatus.getStatus())) {
+ // Notification will be Sent Here.
+ XACMLPdpLoader.sendNotification();
+ }
}
} catch (InterruptedException e) {
logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "interrupted"+e);
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
index f91f6e2f2..62b850370 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/CreateUpdatePolicyServiceImpl.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -177,7 +177,7 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
response = microServicesPolicyService.getResult(updateFlag);
break;
default:
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " Invalid Config Type Present";
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " Invalid Config Type Present";
LOGGER.error(message);
status = HttpStatus.BAD_REQUEST;
return message;
@@ -208,7 +208,7 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
break;
}
}else {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Class found.";
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Class found.";
LOGGER.error(message);
status = HttpStatus.BAD_REQUEST;
response = message;
@@ -254,7 +254,12 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
try {
PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
PolicyRestAdapter policyData = wrapper.populateRequestParameters(policyParameters);
- responseString = validation.validatePolicy(policyData);
+ if(policyData!=null) {
+ responseString = validation.validatePolicy(policyData);
+ } else {
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE+ " improper JSON object : " + policyParameters.getConfigBody();
+ return false;
+ }
} catch (Exception e) {
LOGGER.error("Exception Occured during Policy Validation" +e);
if(e.getMessage()!=null){
@@ -277,7 +282,8 @@ public class CreateUpdatePolicyServiceImpl implements CreateUpdatePolicyService
}
if (responseString!=null){
- if("success".equals(responseString.toString())||"success@#".equals(responseString.toString())){
+ String response = responseString.toString().substring(0, 7);
+ if("success".equals(response)) {
return true;
} else {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + PolicyApiUtils.formatResponse(responseString);
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
index 01670a5fd..144d3a48d 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/DeletePolicyService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -75,13 +75,15 @@ public class DeletePolicyService {
return;
}
if (deleteResult.contains("BAD REQUEST")||deleteResult.contains("PE300")||deleteResult.contains("PE200")||deleteResult.contains("not exist")||deleteResult.contains("Invalid policyName")) {
- status = HttpStatus.BAD_REQUEST;
+ if(deleteResult.contains("groupId")) {
+ status = HttpStatus.NOT_FOUND;
+ } else {
+ status = HttpStatus.BAD_REQUEST;
+ }
} else if (deleteResult.contains("locked down")){
status = HttpStatus.ACCEPTED;
} else if (deleteResult.contains("not Authorized")) {
status = HttpStatus.FORBIDDEN;
- } else if (deleteResult.contains("groupId")) {
- status = HttpStatus.NOT_FOUND;
} else if (deleteResult.contains("JPAUtils")||deleteResult.contains("database")||deleteResult.contains("policy file")||
deleteResult.contains("unknown")||deleteResult.contains("configuration")) {
status = HttpStatus.INTERNAL_SERVER_ERROR;
@@ -148,7 +150,7 @@ public class DeletePolicyService {
if ("PAP".equalsIgnoreCase(deletePolicyParameters.getPolicyComponent())) {
if (deletePolicyParameters.getDeleteCondition()==null||deletePolicyParameters.getDeleteCondition().toString().trim().isEmpty()){
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Delete Condition given.";
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Delete Condition given.";
LOGGER.error(message);
return message;
}
@@ -158,14 +160,14 @@ public class DeletePolicyService {
response = (String) papServices.callPAP(deletePapPolicy, new String[] {"groupId="+pdpGroup, "apiflag=deletePapApi", "operation=delete" }, deletePolicyParameters.getRequestID(), clientScope);
} else if ("PDP".equalsIgnoreCase(deletePolicyParameters.getPolicyComponent())) {
if (deletePolicyParameters.getPdpGroup()==null||deletePolicyParameters.getPdpGroup().trim().isEmpty()){
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No PDP Group given.";
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No PDP Group given.";
LOGGER.error(message);
return message;
}
//send JSON object to PAP
response = (String) papServices.callPAP(null, new String[] {"policyName="+fullPolicyName, "groupId="+pdpGroup, "apiflag=deletePdpApi", "operation=delete" }, deletePolicyParameters.getRequestID(), clientScope);
} else {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Component does not exist. Please enter either PAP or PDP to delete the policy from a specified Policy Component.";
+ message = XACMLErrorConstants.ERROR_DATA_ISSUE + "Policy Component does not exist. Please enter either PAP or PDP to delete the policy from a specified Policy Component.";
LOGGER.error(message);
response = message;
}
@@ -181,9 +183,9 @@ public class DeletePolicyService {
if (!deletePolicyParameters.getPolicyName().contains("xml")) {
if (deletePolicyParameters.getPolicyName() != null
&& deletePolicyParameters.getPolicyName().contains(".")) {
- policyName = deletePolicyParameters.getPolicyName().substring(deletePolicyParameters.getPolicyName().lastIndexOf(".") + 1,
+ policyName = deletePolicyParameters.getPolicyName().substring(deletePolicyParameters.getPolicyName().lastIndexOf('.') + 1,
deletePolicyParameters.getPolicyName().length());
- policyScope = deletePolicyParameters.getPolicyName().substring(0,deletePolicyParameters.getPolicyName().lastIndexOf("."));
+ policyScope = deletePolicyParameters.getPolicyName().substring(0,deletePolicyParameters.getPolicyName().lastIndexOf('.'));
LOGGER.info("Name is " + policyName + " scope is " + policyScope);
} else {
message = XACMLErrorConstants.ERROR_DATA_ISSUE + "No Policy Scope given.";
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/NotificationService.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/NotificationService.java
index bba51965b..3806d26d9 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/NotificationService.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/NotificationService.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -304,8 +304,9 @@ public class NotificationService {
aafLogin,
aafPassword);
// Sending notification through DMaaP Message Router
+ logger.info("NotificationService: send DMaaP Message. ");
publisher.send( "MyPartitionKey", notification);
- logger.debug("Message Published on DMaaP :" + dmaapList.get(0) + "for Topic: " + topic);
+ logger.info("Message Published on DMaaP :" + dmaapList.get(0) + "for Topic: " + topic);
publisher.close();
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
index 72d8fdeec..57a80b5d1 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/api/services/PAPServices.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -111,7 +111,7 @@ public class PAPServices {
// This makes it Real-Time to change the list depending on their
// availability.
if (paps == null || paps.isEmpty()) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty.";
+ String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty.";
LOGGER.error(message);
throw new PolicyException(message);
}
@@ -215,7 +215,7 @@ public class PAPServices {
}
return response;
} else {
- response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ response = XACMLErrorConstants.ERROR_DATA_ISSUE
+ "Unable to get valid response from PAP(s) " + paps;
return response;
}
@@ -415,10 +415,10 @@ public class PAPServices {
+ ". PEP is not Authorized for making this Request!! \n Contact Administrator for this Scope. ";
LOGGER.error(response);
} else if (connection.getResponseCode() == 404 && connection.getHeaderField("error") != null) {
- if ("unknownGroupId".equals(connection.getHeaderField("error"))) {
+ if ("UnknownGroup".equals(connection.getHeaderField("error"))) {
response = XACMLErrorConstants.ERROR_DATA_ISSUE
+ connection.getHeaderField("message")
- + " Please check the pdpGroup you are requesting to move the policy to.";
+ + " Please check the pdpGroup you are requesting to push the policy to.";
LOGGER.error(response);
} else if ("policyNotAvailableForEdit".equals(connection.getHeaderField("error"))) {
response = XACMLErrorConstants.ERROR_DATA_ISSUE
@@ -490,13 +490,16 @@ public class PAPServices {
response = XACMLErrorConstants.ERROR_UNKNOWN
+ "Could not create or update the policy for and unknown reason";
}else{
- response = XACMLErrorConstants.ERROR_DATA_ISSUE
- + "BAD REQUEST: Error occured while attempting perform this operation.. the request may be incorrect. " + connection.getHeaderField("error");
+ response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ + "Error occured while attempting perform this operation.. "
+ + "the request may be incorrect or the PAP is unreachable. "
+ + connection.getHeaderField("error");
}
LOGGER.error(response);
} else {
- response = XACMLErrorConstants.ERROR_DATA_ISSUE
- + "BAD REQUEST: Error occured while attempting perform this operation.. the request may be incorrect.";
+ response = XACMLErrorConstants.ERROR_SYSTEM_ERROR
+ + "Error occured while attempting perform this operation.. "
+ + "the request may be incorrect or the PAP is unreachable.";
LOGGER.error(response);
}
return response;
@@ -544,11 +547,11 @@ public class PAPServices {
+ "\"policyName\": \""+policyName+"\","
+ "\"clientScope\": \""+clientScope+"\","
+ "\"pdpGroup\": \""+pdpGroup+"\"}";
- //String response = null;
- HttpURLConnection connection = null;
+
+ HttpURLConnection connection = null;
responseCode = 0;
if (paps == null || paps.isEmpty()) {
- String message = XACMLErrorConstants.ERROR_DATA_ISSUE + "PAPs List is Empty.";
+ String message = XACMLErrorConstants.ERROR_SYSTEM_ERROR + "PAPs List is Empty.";
LOGGER.error(message);
throw new PolicyException(message);
}
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationController.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationController.java
index 8121bdc8f..c62872fbd 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationController.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationController.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -81,8 +81,10 @@ public class NotificationController {
private static Boolean notificationFlag = false;
public void check(PDPStatus newStatus, Map<String, PolicyDef> policyContainer) {
- boolean updated = false;
- boolean removed = false;
+
+ LOGGER.info("NotificationController: checking for updated and removed policies.");
+ boolean isUpdated = false;
+ boolean isRemoved = false;
Notification notification = new Notification();
HashSet<Removed> removedPolicies = new HashSet<>();
HashSet<Updated> updatedPolicies = new HashSet<>();
@@ -90,16 +92,18 @@ public class NotificationController {
if (oldStatus == null) {
oldStatus = newStatus;
}
- // Debugging purpose only.
- LOGGER.debug("old config Status :" + oldStatus.getStatus());
- LOGGER.debug("new config Status :" + newStatus.getStatus());
+
+ LOGGER.info("old config Status :" + oldStatus.getStatus());
+ LOGGER.info("new config Status :" + newStatus.getStatus());
// Depending on the above condition taking the Change as an Update.
if (oldStatus.getStatus().toString() != newStatus.getStatus().toString()) {
LOGGER.info("There is an Update to the PDP");
LOGGER.debug(oldStatus.getLoadedPolicies());
LOGGER.debug(newStatus.getLoadedPolicies());
+
// Check if there is an Update/additions in the policy.
+ LOGGER.info("NotificationController: check for updated or new policies");
for (PDPPolicy newPolicy : newStatus.getLoadedPolicies()) {
boolean change = true;
for (PDPPolicy oldPolicy : oldStatus.getLoadedPolicies()) {
@@ -113,12 +117,14 @@ public class NotificationController {
}
// if there is a change Send the notifications to the Client.
if (change) {
+ LOGGER.info("NotificationController: sending update/new policy notification");
sendUpdate(newPolicy, policyContainer);
- updated = true;
+ isUpdated = true;
updatedPolicies.add(this.updated);
}
}
// Check if there is any removal of policy.
+ LOGGER.info("NotificationController: check for removed policies");
for (PDPPolicy oldPolicy : oldStatus.getLoadedPolicies()) {
boolean change = true;
for (PDPPolicy newPolicy : newStatus.getLoadedPolicies()) {
@@ -132,8 +138,9 @@ public class NotificationController {
}
// if there is a change Send the notifications to the Client.
if (change) {
+ LOGGER.info("NotificationController: sending removal notification");
sendremove(oldPolicy);
- removed = true;
+ isRemoved = true;
removedPolicies.add(this.removed);
}
}
@@ -141,15 +148,15 @@ public class NotificationController {
// At the end the oldStatus must be updated with the newStatus.
oldStatus = newStatus;
// Sending Notification to the Server to pass over to the clients
- if (updated || removed) {
+ if (isUpdated || isRemoved) {
// Call the Notification Server..
notification.setRemovedPolicies(removedPolicies);
notification.setLoadedPolicies(updatedPolicies);
- notification = setUpdateTypes(updated, removed, notification);
+ notification = setUpdateTypes(isUpdated, isRemoved, notification);
ObjectWriter om = new ObjectMapper().writer();
try {
setNotificationJSON(om.writeValueAsString(notification));
- LOGGER.info(notificationJSON);
+ LOGGER.info("NotificationController notificationJson: " + notificationJSON);
// NotificationServer Method here.
setPropNotification();
if (("ueb".equals(propNotificationType) || "dmaap".equals(propNotificationType))
@@ -191,6 +198,7 @@ public class NotificationController {
public static void sendNotification() {
if (notificationFlag) {
try {
+ LOGGER.info("NotificationController: calling NotificationServer to sendNotification");
NotificationServer.sendNotification(notificationJSON, propNotificationType, pdpURL);
} catch (Exception e) {
LOGGER.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in sending the Event Notification: "
@@ -255,7 +263,7 @@ public class NotificationController {
} else if (newPolicy.getName().contains(".Action_")) {
// Take Configuration copy to PDP Webapps.
// Action policies have .json as extension.
- String urlString = "$URL/Action/" + newPolicy.getId().substring(0, newPolicy.getId().lastIndexOf("."))
+ String urlString = "$URL/Action/" + newPolicy.getId().substring(0, newPolicy.getId().lastIndexOf('.'))
+ ".json";
callPap(urlString, "Action");
}
@@ -390,7 +398,7 @@ public class NotificationController {
}
if (delete) {
FileFilter fileFilter = new WildcardFileFilter(
- oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf(".")) + ".*");
+ oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf('.')) + ".*");
File[] configFile = dir.listFiles(fileFilter);
if (configFile.length == 1) {
Files.deleteIfExists(configFile[0].toPath());
@@ -418,7 +426,7 @@ public class NotificationController {
String papPath = papUrls.getUrl();
papPath = papPath.substring(0, papPath.lastIndexOf("/pap"));
String papAddress = urlString.replace("$URL", papPath);
- String fileName = papAddress.substring(papAddress.lastIndexOf("/") + 1);
+ String fileName = papAddress.substring(papAddress.lastIndexOf('/') + 1);
String fileLocation = configLocation.toString() + File.separator + fileName;
try {
URL papURL = new URL(papAddress);
diff --git a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java
index 2f3d58203..4c2d1ef57 100644
--- a/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java
+++ b/ONAP-PDP-REST/src/main/java/org/onap/policy/pdp/rest/notifications/NotificationServer.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -208,11 +208,15 @@ public class NotificationServer {
for(Session session: queue) {
try {
+ LOGGER.info("\n Sending Notification: " + notification + " for client session id: " + session.getId() + "\n "
+ + "PDPUrl is " + pdpURL);
+ LOGGER.info("NotificationServer: sending text message");
session.getBasicRemote().sendText(notification);
} catch (IOException e) {
LOGGER.info(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error in sending the Event Notification: "+ e.getMessage() + e);
}
}
+
NotificationService.sendNotification(notification);
}
diff --git a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java
index 8fea627c9..471f1a9a2 100644
--- a/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java
+++ b/ONAP-PDP-REST/src/test/java/org/onap/policy/pdp/rest/api/test/PolicyEngineServicesTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP-PDP-REST
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 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.
@@ -168,9 +168,9 @@ public class PolicyEngineServicesTest {
mockMvc.perform(get("/getMetrics")).andExpect(status().isBadRequest());
mockMvc.perform(get("/getMetrics").header(CLIENTAUTHHEADER, "Basic 123")).andExpect(status().isUnauthorized());
//Service Tests.
- mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, "123")).andExpect(status().isOk());
- mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isOk());
- mockMvc.perform(get("/getMetrics").headers(headers)).andExpect(status().isOk());
+ mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
+ mockMvc.perform(get("/getMetrics").headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
+ mockMvc.perform(get("/getMetrics").headers(headers)).andExpect(status().isBadRequest());
}
@Test
@@ -699,9 +699,9 @@ public class PolicyEngineServicesTest {
.headers(headers)).andExpect(status().isBadRequest());
pep.setActionPerformer("PEP");
mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isInternalServerError());
+ .headers(headers)).andExpect(status().isBadRequest());
mockMvc.perform(put("/updatePolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isInternalServerError());
+ .headers(headers)).andExpect(status().isBadRequest());
// Checks for Decision Policy.
pep.setPolicyClass(PolicyClass.Decision);
mockMvc.perform(put("/createPolicy").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
@@ -743,7 +743,7 @@ public class PolicyEngineServicesTest {
.headers(headers)).andExpect(status().isBadRequest());
pep.setDictionaryJson("{\"test\":\"value\"}");
mockMvc.perform(put("/createDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isInternalServerError());
+ .headers(headers).header(UUIDHEADER, UUID.randomUUID())).andExpect(status().isBadRequest());
pep.setDictionaryJson("test123");
mockMvc.perform(put("/updateDictionaryItem").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
.headers(headers).header(UUIDHEADER, "123")).andExpect(status().isBadRequest());
@@ -766,10 +766,10 @@ public class PolicyEngineServicesTest {
.headers(headers).header(UUIDHEADER, UUID.randomUUID().toString())).andExpect(status().isBadRequest());
pep.setDictionary("OnapName");
mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isInternalServerError());
+ .headers(headers)).andExpect(status().isBadRequest());
pep.setRequestID(UUID.randomUUID());
mockMvc.perform(post("/getDictionaryItems").content(PolicyUtils.objectToJsonString(pep)).contentType(MediaType.APPLICATION_JSON)
- .headers(headers)).andExpect(status().isInternalServerError());
+ .headers(headers)).andExpect(status().isBadRequest());
}
@Test