aboutsummaryrefslogtreecommitdiffstats
path: root/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
diff options
context:
space:
mode:
authorrb7147 <rb7147@att.com>2017-06-09 15:11:06 -0400
committerrb7147 <rb7147@att.com>2017-06-12 16:59:35 -0400
commit685ed1545ed28b777a3ba6e7d315b78f355154cb (patch)
tree1e37d639242c5f1e9cbf5623821f8498542b81dc /ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
parentfc5c07705edc4dcb7083b39116a43844bb6a1490 (diff)
[Policy-20] getConfig & Policy resolved blockers
Change-Id: If08e4c90d419e8d6e1426d817a12dde5b7cafba3 Signed-off-by: rb7147 <rb7147@att.com>
Diffstat (limited to 'ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java')
-rw-r--r--ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java157
1 files changed, 58 insertions, 99 deletions
diff --git a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
index edbc2acb7..4ceae062b 100644
--- a/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
+++ b/ECOMP-PAP-REST/src/main/java/org/openecomp/policy/pap/xacml/rest/XACMLPapServlet.java
@@ -403,6 +403,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
}
}
policyDBDao.setPapEngine((PAPPolicyEngine) XACMLPapServlet.papEngine);
+ //boolean performFileToDatabaseAudit = false;
+ if (Boolean.parseBoolean(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_RUN_AUDIT_FLAG))){
+ //get an AuditTransaction to lock out all other transactions
+ PolicyDBDaoTransaction auditTrans = policyDBDao.getNewAuditTransaction();
+ policyDBDao.auditLocalDatabase(XACMLPapServlet.papEngine);
+ //release the transaction lock
+ auditTrans.close();
+ }
+
// Sanity check for URL.
if (XACMLPapServlet.papURL == null) {
throw new PAPException("The property " + XACMLRestProperties.PROP_PAP_URL + " is not valid: " + XACMLPapServlet.papURL);
@@ -856,7 +865,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String message = "PUT interface called for PAP " + papResourceName + " but it has an Administrative"
+ " state of " + im.getStateManager().getAdminState()
+ "\n Exception Message: " + ae.getMessage();
- LOGGER.info(message);
+ LOGGER.info(message +ae);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -866,7 +875,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
String message = "PUT interface called for PAP " + papResourceName + " but it has a Standby Status"
+ " of " + im.getStateManager().getStandbyStatus()
+ "\n Exception Message: " + se.getMessage();
- LOGGER.info(message);
+ LOGGER.info(message +se);
PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message);
loggingContext.transactionEnded();
PolicyLogger.audit("Transaction Failed - See Error.log");
@@ -897,69 +906,6 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
im.endTransaction();
return;
}
- //This would occur if we received a notification of a policy creation or update
- String policyToCreateUpdate = request.getParameter("policyToCreateUpdate");
- if(policyToCreateUpdate != null){
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPapServlet.doPut() - before decoding"
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- }
- //decode it
- try{
- policyToCreateUpdate = URLDecoder.decode(policyToCreateUpdate, "UTF-8");
- if(LOGGER.isDebugEnabled()){
- LOGGER.debug("\nXACMLPapServlet.doPut() - after decoding"
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- }
- } catch(UnsupportedEncodingException e){
- PolicyLogger.error("\nXACMLPapServlet.doPut() - Unsupported URL encoding of policyToCreateUpdate (UTF-8)"
- + "\npolicyToCreateUpdate = " + policyToCreateUpdate);
- response.sendError(500,"policyToCreateUpdate encoding not supported"
- + "\nfailure with the following exception: " + e);
- loggingContext.transactionEnded();
- PolicyLogger.audit("Transaction Failed - See error.log");
- im.endTransaction();
- return;
- }
- //send it to PolicyDBDao
- PolicyDBDaoTransaction createUpdateTransaction = policyDBDao.getNewTransaction();
- try{
- createUpdateTransaction.createPolicy(policyToCreateUpdate, "XACMLPapServlet.doPut");
- }catch(Exception e){
- createUpdateTransaction.rollbackTransaction();
- response.sendError(500,"createUpdateTransaction.createPolicy(policyToCreateUpdate, XACMLPapServlet.doPut) "
- + "\nfailure with the following exception: " + e);
- loggingContext.transactionEnded();
- PolicyLogger.audit("Transaction Failed - See error.log");
- im.endTransaction();
- return;
- }
- createUpdateTransaction.commitTransaction();
- // Before sending Ok. Lets call AutoPush.
- if(autoPushFlag){
- Set<StdPDPGroup> changedGroups = autoPushPolicy.checkGroupsToPush(policyToCreateUpdate, XACMLPapServlet.papEngine);
- if(!changedGroups.isEmpty()){
- for(StdPDPGroup group: changedGroups){
- try{
- papEngine.updateGroup(group);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("Group '" + group.getId() + "' updated");
- }
- notifyAC();
- // Group changed, which might include changing the policies
- groupChanged(group);
- }catch(Exception e){
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " Failed to Push policy. ");
- }
- }
- }
- }
- response.setStatus(HttpServletResponse.SC_OK);
- loggingContext.transactionEnded();
- PolicyLogger.audit("Transaction Ended Successfully");
- im.endTransaction();
- return;
- }
/*
* Request for ImportService
*/
@@ -1343,7 +1289,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
loggingContext.transactionEnded();
auditLogger.info("Success");
- if (policy != null && (policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param"))) {
+ if (policy != null && ((policy.getId().contains("Config_MS_")) || (policy.getId().contains("BRMS_Param")))) {
PushPolicyHandler pushPolicyHandler = PushPolicyHandler.getInstance();
if (pushPolicyHandler.preSafetyCheck(policy, CONFIG_HOME)) {
LOGGER.debug("Precheck Successful.");
@@ -1798,44 +1744,53 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
response.sendError(500, "Bad input, pdpid="+pdpId+" object="+objectFromJSON);
}
StdPDP pdp = (StdPDP) objectFromJSON;
- if (papEngine.getPDP(pdpId) == null) {
- // this is a request to create a new PDP object
- try{
- acPutTransaction.addPdpToGroup(pdp == null ? "PDP is null" : pdp.getId(), group.getId(), pdp == null ? "PDP is null" : pdp.getName(),
- pdp == null ? "PDP is null" : pdp.getDescription(),
- pdp == null ? 0 : pdp.getJmxPort(),"XACMLPapServlet.doACPut");
- } catch(Exception e){
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: "
- +"pdp="+ (pdp == null ? "PDP is null" : pdp.getId()) +",to group="+group.getId());
- throw new PAPException(e.getMessage());
+ if(pdp != null){
+ if (papEngine.getPDP(pdpId) == null) {
+ // this is a request to create a new PDP object
+ try{
+ acPutTransaction.addPdpToGroup(pdp == null ? "PDP is null" : pdp.getId(), group.getId(), pdp.getName(),
+ pdp.getDescription(), pdp.getJmxPort(),"XACMLPapServlet.doACPut");
+ } catch(Exception e){
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while adding pdp to group in the database: "
+ +"pdp="+ (pdp == null ? "PDP is null" : pdp.getId()) +",to group="+group.getId());
+ throw new PAPException(e.getMessage());
+ }
+ papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
+ } else {
+ try{
+ acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
+ } catch(Exception e){
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating pdp in the database: "
+ +"pdp="+ pdp.getId());
+ throw new PAPException(e.getMessage());
+ }
+ // this is a request to update the pdp
+ papEngine.updatePDP(pdp);
}
- papEngine.newPDP(pdp.getId(), group, pdp.getName(), pdp.getDescription(), pdp.getJmxPort());
- } else {
+ response.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ if (LOGGER.isDebugEnabled()) {
+ LOGGER.debug("PDP '" + pdpId + "' created/updated");
+ }
+ // adjust the group's state including the new PDP
+ ((StdPDPGroup)group).resetStatus();
+ // tell the Admin Consoles there is a change
+ notifyAC();
+ // this might affect the PDP, so notify it of the change
+ pdpChanged(pdp);
+ acPutTransaction.commitTransaction();
+ loggingContext.transactionEnded();
+ auditLogger.info("Success");
+ PolicyLogger.audit("Transaction Ended Successfully");
+ return;
+ }else{
try{
- acPutTransaction.updatePdp(pdp, "XACMLPapServlet.doACPut");
+ PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "XACMLPapServlet", " Error while adding pdp to group in the database: "
+ +"pdp=null" + ",to group="+group.getId());
+ throw new PAPException("PDP is null");
} catch(Exception e){
- PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "XACMLPapServlet", " Error while updating pdp in the database: "
- +"pdp="+(pdp == null ? "PDP is null" : pdp.getId()));
- throw new PAPException(e.getMessage());
+ throw new PAPException("PDP is null" + e.getMessage() +e);
}
- // this is a request to update the pdp
- papEngine.updatePDP(pdp);
}
- response.setStatus(HttpServletResponse.SC_NO_CONTENT);
- if (LOGGER.isDebugEnabled()) {
- LOGGER.debug("PDP '" + pdpId + "' created/updated");
- }
- // adjust the group's state including the new PDP
- ((StdPDPGroup)group).resetStatus();
- // tell the Admin Consoles there is a change
- notifyAC();
- // this might affect the PDP, so notify it of the change
- pdpChanged(pdp);
- acPutTransaction.commitTransaction();
- loggingContext.transactionEnded();
- auditLogger.info("Success");
- PolicyLogger.audit("Transaction Ended Successfully");
- return;
} else if (request.getParameter("pipId") != null) {
// group=<groupId> pipId=<pipEngineId> contents=pip properties <= add a PIP to pip config, or replace it if it already exists (lenient operation)
loggingContext.setServiceName("AC:PAP.putPIP");
@@ -2595,6 +2550,10 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList
return emf;
}
+ public IntegrityAudit getIa() {
+ return ia;
+ }
+
public static String getPDPFile(){
return XACMLPapServlet.pdpFile;
}