X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2FXACMLPapServlet.java;h=8dc52b861553e2a6ceab6c33820bcaf7597dbf00;hb=92febb7abd1e6dfe89633d3d92cd70fabf5f0434;hp=b5951d823370f50bf062752228024f7f844a547d;hpb=1b1640ae538cfdb3667fd3222dc4dec469b0e3f7;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java index b5951d823..8dc52b861 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/XACMLPapServlet.java @@ -20,13 +20,6 @@ package org.onap.policy.pap.xacml.rest; -import com.att.research.xacml.api.pap.PAPException; -import com.att.research.xacml.api.pap.PDPPolicy; -import com.att.research.xacml.api.pap.PDPStatus; -import com.att.research.xacml.util.FactoryException; -import com.att.research.xacml.util.XACMLProperties; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.base.Splitter; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -59,8 +52,8 @@ import org.onap.policy.common.im.IntegrityMonitor; import org.onap.policy.common.im.IntegrityMonitorException; import org.onap.policy.common.im.IntegrityMonitorProperties; import org.onap.policy.common.im.StandbyStatusException; -import org.onap.policy.common.logging.ONAPLoggingContext; -import org.onap.policy.common.logging.ONAPLoggingUtils; +import org.onap.policy.common.logging.OnapLoggingContext; +import org.onap.policy.common.logging.OnapLoggingUtils; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -87,6 +80,13 @@ import org.onap.policy.xacml.std.pap.StdPDPGroup; import org.onap.policy.xacml.std.pap.StdPDPItemSetChangeNotifier.StdItemSetChangeListener; import org.onap.policy.xacml.std.pap.StdPDPPolicy; import org.onap.policy.xacml.std.pap.StdPDPStatus; +import com.att.research.xacml.api.pap.PAPException; +import com.att.research.xacml.api.pap.PDPPolicy; +import com.att.research.xacml.api.pap.PDPStatus; +import com.att.research.xacml.util.FactoryException; +import com.att.research.xacml.util.XACMLProperties; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.base.Splitter; /** * Servlet implementation class XacmlPapServlet. @@ -158,7 +158,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList * this servlet starts. Its configurable by the admin. */ private static transient Thread initiateThread = null; - private transient ONAPLoggingContext baseLoggingContext = null; + private transient OnapLoggingContext baseLoggingContext = null; private static final String GROUPID = "groupId"; /** @@ -175,7 +175,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList public void init(ServletConfig config) throws ServletException { try { // Logging - baseLoggingContext = new ONAPLoggingContext(); + baseLoggingContext = new OnapLoggingContext(); // fixed data that will be the same in all logging output goes here try { String hostname = InetAddress.getLocalHost().getCanonicalHostName(); @@ -546,8 +546,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ONAPLoggingContext loggingContext = - ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + OnapLoggingContext loggingContext = + OnapLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); setLoggingContext(loggingContext, "doPost", "PAP.post"); PolicyDBDaoTransaction pdpTransaction = null; try { @@ -557,7 +557,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList PolicyLogger.metrics("XACMLPapServlet doPost im startTransaction"); } catch (AdministrativeStateException ae) { String message = "POST interface called for PAP " + papResourceName - + " but it has an Administrative" + " state of " + + " but it has an Administrative state of " + im.getStateManager().getAdminState() + "\n Exception Message: " + PolicyUtils.CATCH_EXCEPTION; LOGGER.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message, ae); @@ -567,12 +567,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList PolicyLogger.audit("Transaction Failed - See Error.log"); setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); return; - } catch (StandbyStatusException se) { + } catch (IntegrityMonitorException ime) { String message = "POST interface called for PAP " + papResourceName - + " but it has a Standby Status" + " of " - + im.getStateManager().getStandbyStatus() + "\n Exception Message: " - + se.getMessage(); - LOGGER.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message, se); + + " but it has an Administrative state of " + + im.getStateManager().getAdminState() + + " and a Standby Status of " + + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + + ime.getMessage(); + LOGGER.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message, ime); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet doPost im startTransaction"); loggingContext.transactionEnded(); @@ -807,8 +810,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ONAPLoggingContext loggingContext = - ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + OnapLoggingContext loggingContext = + OnapLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); setLoggingContext(loggingContext, "doGet", "PAP.get"); loggingContext.metricStarted(); XACMLRest.dumpRequest(request); @@ -831,23 +834,15 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList im.startTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet doGet im startTransaction"); - } catch (AdministrativeStateException ae) { + } catch (IntegrityMonitorException ime) { String message = "GET interface called for PAP " + papResourceName - + " but it has an Administrative" + " state of " - + im.getStateManager().getAdminState() + "\n Exception Message: " - + ae.getMessage(); - LOGGER.info(message, ae); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); - loggingContext.transactionEnded(); - PolicyLogger.audit("Transaction Failed - See Error.log"); - setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); - return; - } catch (StandbyStatusException se) { - String message = "GET interface called for PAP " + papResourceName - + " but it has a Standby Status" + " of " - + im.getStateManager().getStandbyStatus() + "\n Exception Message: " - + se.getMessage(); - LOGGER.info(message, se); + + " but it has an Administrative state of " + + im.getStateManager().getAdminState() + + " and a Standby Status of " + + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + + ime.getMessage(); + LOGGER.info(message, ime); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed - See Error.log"); @@ -1022,8 +1017,8 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList @Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ONAPLoggingContext loggingContext = - ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + OnapLoggingContext loggingContext = + OnapLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); setLoggingContext(loggingContext, "doPut", "PAP.put"); try { loggingContext.metricStarted(); @@ -1031,19 +1026,13 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet doPut im startTransaction"); } catch (IntegrityMonitorException e) { - String message = "PUT interface called for PAP " + papResourceName; - if (e instanceof AdministrativeStateException) { - message += " but it has an Administrative state of " - + im.getStateManager().getAdminState(); - } else if (e instanceof StandbyStatusException) { - message += " but it has a Standby Status of " - + im.getStateManager().getStandbyStatus(); - } else { - message += " but an exception occurred"; - - } - message += "\n Exception Message: " + e.getMessage(); - + String message = "PUT interface called for PAP " + papResourceName + + " but it has an Administrative state of " + + im.getStateManager().getAdminState() + + " and a Standby Status of " + + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + + e.getMessage(); LOGGER.info(message, e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); loggingContext.transactionEnded(); @@ -1245,31 +1234,23 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList @Override protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - ONAPLoggingContext loggingContext = - ONAPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); + OnapLoggingContext loggingContext = + OnapLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); setLoggingContext(loggingContext, "doDelete", "PAP.delete"); try { loggingContext.metricStarted(); im.startTransaction(); loggingContext.metricEnded(); PolicyLogger.metrics("XACMLPapServlet doDelete im startTransaction"); - } catch (AdministrativeStateException ae) { + } catch (IntegrityMonitorException ime) { String message = "DELETE interface called for PAP " + papResourceName - + " but it has an Administrative" + " state of " - + im.getStateManager().getAdminState() + "\n Exception Message: " - + ae.getMessage(); - LOGGER.info(message, ae); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); - loggingContext.transactionEnded(); - PolicyLogger.audit("Transaction Failed - See Error.log"); - setResponseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); - return; - } catch (StandbyStatusException se) { - 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, se); + + " but it has an Administrative state of " + + im.getStateManager().getAdminState() + + " and a Standby Status of " + + im.getStateManager().getStandbyStatus() + + "\n Exception Message: " + + ime.getMessage(); + LOGGER.info(message, ime); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR + " " + message); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed - See Error.log"); @@ -1416,7 +1397,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList * @throws IOException */ public void updateGroupsFromAPI(HttpServletRequest request, HttpServletResponse response, - String groupId, ONAPLoggingContext loggingContext) throws IOException { + String groupId, OnapLoggingContext loggingContext) throws IOException { PolicyDBDaoTransaction acPutTransaction = policyDbDao.getNewTransaction(); PolicyLogger.audit("PolicyDBDaoTransaction started for updateGroupsFromAPI"); try { @@ -1560,7 +1541,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList } } - public void changed(ONAPLoggingContext loggingContext) { + public void changed(OnapLoggingContext loggingContext) { // all PDPs in all groups need to be updated/sync'd Set groups; try { @@ -1584,7 +1565,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList } } - public void groupChanged(OnapPDPGroup group, ONAPLoggingContext loggingContext) { + public void groupChanged(OnapPDPGroup group, OnapLoggingContext loggingContext) { // all PDPs within one group need to be updated/sync'd for (OnapPDP pdp : group.getOnapPdps()) { pdpChanged(pdp, loggingContext, getPdpDataByGroup(group)); @@ -1604,7 +1585,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList } } - public void pdpChanged(OnapPDP pdp, ONAPLoggingContext loggingContext) { + public void pdpChanged(OnapPDP pdp, OnapLoggingContext loggingContext) { // kick off a thread to do an event notification for each PDP. // This needs to be on a separate thread so that PDPs that do not // respond (down, non-existent, etc) @@ -1623,7 +1604,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList } } - private void pdpChanged(OnapPDP pdp, ONAPLoggingContext loggingContext, + private void pdpChanged(OnapPDP pdp, OnapLoggingContext loggingContext, List pdpDataByGroup) { Thread t = new Thread(new UpdatePdpThread(pdp, loggingContext, pdpDataByGroup)); if (CheckPDP.validateID(pdp.getId())) { @@ -1641,7 +1622,7 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList return dataToNotify.setPolicyConfigProperties(pdp, papEngine); } - private void testService(ONAPLoggingContext loggingContext, HttpServletResponse response) + private void testService(OnapLoggingContext loggingContext, HttpServletResponse response) throws IOException { LOGGER.info("Test request received"); try { @@ -1705,13 +1686,13 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList } } - private void setLoggingContext(ONAPLoggingContext loggingContext, String methodType, + private void setLoggingContext(OnapLoggingContext loggingContext, String methodType, String serviceName) { loggingContext.transactionStarted(); loggingContext.setServiceName(serviceName); - if (loggingContext.getRequestID() == null || "".equals(loggingContext.getRequestID())) { + if (loggingContext.getRequestId() == null || "".equals(loggingContext.getRequestId())) { UUID requestID = UUID.randomUUID(); - loggingContext.setRequestID(requestID.toString()); + loggingContext.setRequestId(requestID.toString()); PolicyLogger.info("requestID not provided in call to XACMLPapServlet ('" + methodType + "') so we generated one"); } else { @@ -1861,11 +1842,11 @@ public class XACMLPapServlet extends HttpServlet implements StdItemSetChangeList XACMLPapServlet.msPolicyName = msPolicyName; } - public ONAPLoggingContext getBaseLoggingContext() { + public OnapLoggingContext getBaseLoggingContext() { return baseLoggingContext; } - public void setBaseLoggingContext(ONAPLoggingContext baseLoggingContext) { + public void setBaseLoggingContext(OnapLoggingContext baseLoggingContext) { this.baseLoggingContext = baseLoggingContext; } }