X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PDP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpdp%2Frest%2FXACMLPdpServlet.java;h=c227d9d2a4f2b6b13bc4ddb767fa92b5a718714a;hb=2cc2acb29f4d7f925bb922a99e672844f2948260;hp=87cafc4ef2a61b156bdcee80da6eaa13f5766c7d;hpb=5aeeaae2e6ea881dd11601bedc2ffc94443bc9d3;p=policy%2Fengine.git 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 87cafc4ef..c227d9d2a 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-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -276,6 +276,13 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, e, "Failed to create IntegrityMonitor" + e); throw new ServletException(e); } + + try { + System.setProperty("msToscaModel.home", properties.getProperty("msToscaModel.home")); + } catch (Exception e) { + logger.error("ERROR: Unable to set msToscaModel.home- Please check the configuration"); + } + startThreads(baseLoggingContext, new Thread(this)); } @@ -497,7 +504,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { } protected void doPutConfig(String config, HttpServletRequest request, HttpServletResponse response, - ONAPLoggingContext loggingContext) throws ServletException, IOException { + ONAPLoggingContext loggingContext) throws IOException { try { // prevent multiple configuration changes from stacking up logger.info("XACMLPdpServlet: checking remainingCapacity of Queue."); @@ -649,92 +656,63 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { XACMLRest.dumpRequest(request); String pathInfo = request.getRequestURI(); - if (pathInfo != null) { + if (pathInfo != null && "/pdp/test".equals(pathInfo)) { // health check from Global Site Selector (iDNS). // DO NOT do a im.startTransaction for the test request - if (pathInfo.equals("/pdp/test")) { - loggingContext.setServiceName("iDNS:PDP.test"); + loggingContext.setServiceName("iDNS:PDP.test"); + try { + im.evaluateSanity(); + // If we make it this far, all is well + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is OK"; + PolicyLogger.debug(message); + PolicyLogger.audit("Success"); + response.setStatus(HttpServletResponse.SC_OK); + return; + } catch (ForwardProgressException | AdministrativeStateException | StandbyStatusException fpe) { + // No forward progress is being made + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is not making forward progress." + + " Exception Message: " + fpe.getMessage(); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + fpe); + PolicyLogger.audit("Transaction Failed - See Error.log"); try { - im.evaluateSanity(); - // If we make it this far, all is well - String message = "GET:/pdp/test called and PDP " + pdpResourceName + " is OK"; - PolicyLogger.debug(message); - loggingContext.transactionEnded(); - PolicyLogger.audit("Success"); - response.setStatus(HttpServletResponse.SC_OK); - return; - } catch (ForwardProgressException fpe) { - // No forward progress is being made - String message = "GET:/pdp/test called and PDP " + pdpResourceName - + " is not making forward progress." + " Exception Message: " + fpe.getMessage(); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + fpe); - loggingContext.transactionEnded(); - PolicyLogger.audit("Transaction Failed - See Error.log"); - try { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); - } catch (Exception e1) { - logger.error("Exception occured while sending error in response" + e1); - } - return; - } catch (AdministrativeStateException ase) { - // Administrative State is locked - String message = "GET:/pdp/test called and PDP " + pdpResourceName - + " Administrative State is LOCKED " + " Exception Message: " + ase.getMessage(); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + ase); - loggingContext.transactionEnded(); - PolicyLogger.audit("Transaction Failed - See Error.log"); - try { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); - } catch (Exception e1) { - logger.error("Exception occured while sending error in response" + e1); - } - return; - } catch (StandbyStatusException sse) { - // Administrative State is locked - String message = "GET:/pdp/test called and PDP " + pdpResourceName - + " Standby Status is NOT PROVIDING SERVICE " + " Exception Message: " + sse.getMessage(); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + sse); - loggingContext.transactionEnded(); - PolicyLogger.audit("Transaction Failed - See Error.log"); - try { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); - } catch (Exception e1) { - logger.error("Exception occured while sending error in response" + e1); - } - return; - } catch (Exception e) { - // A subsystem is not making progress or is not responding - String eMsg = e.getMessage(); - if (eMsg == null) { - eMsg = "No Exception Message"; - } - String message = "GET:/pdp/test called and PDP " + pdpResourceName + " has had a subsystem failure." - + " Exception Message: " + eMsg; - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); - // Get the specific list of subsystems that failed - String failedNodeList = null; - for (String node : dependencyNodes) { - if (eMsg.contains(node)) { - if (failedNodeList == null) { - failedNodeList = node; - } else { - failedNodeList = failedNodeList.concat("," + node); - } + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + } catch (Exception e1) { + logger.error("Exception occured while sending error in response" + e1); + } + return; + } catch (Exception e) { + // A subsystem is not making progress or is not responding + String eMsg = e.getMessage(); + if (eMsg == null) { + eMsg = "No Exception Message"; + } + String message = "GET:/pdp/test called and PDP " + pdpResourceName + " has had a subsystem failure." + + " Exception Message: " + eMsg; + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + // Get the specific list of subsystems that failed + String failedNodeList = null; + for (String node : dependencyNodes) { + if (eMsg.contains(node)) { + if (failedNodeList == null) { + failedNodeList = node; + } else { + failedNodeList = failedNodeList.concat("," + node); } } - if (failedNodeList == null) { - failedNodeList = "UnknownSubSystem"; - } - response.addHeader("X-ONAP-SubsystemFailure", failedNodeList); - try { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); - } catch (Exception e1) { - logger.error("Exception occured while sending error in response" + e1); - } - loggingContext.transactionEnded(); - PolicyLogger.audit("Transaction Failed - See Error.log" + e); - return; } + if (failedNodeList == null) { + failedNodeList = "UnknownSubSystem"; + } + response.addHeader("X-ONAP-SubsystemFailure", failedNodeList); + try { + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); + } catch (Exception e1) { + logger.error("Exception occured while sending error in response" + e1); + } + PolicyLogger.audit("Transaction Failed - See Error.log" + e); + return; + } finally { + loggingContext.transactionEnded(); } } @@ -1001,7 +979,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_JSON.getMimeType())) { pdpRequest = JSONRequest.load(incomingRequestString); } else if (contentType.getMimeType().equalsIgnoreCase(ContentType.APPLICATION_XML.getMimeType()) - || contentType.getMimeType().equalsIgnoreCase("application/xacml+xml")) { + || "application/xacml+xml".equalsIgnoreCase(contentType.getMimeType())) { pdpRequest = DOMRequest.load(incomingRequestString); } } catch (Exception e) { @@ -1035,7 +1013,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // Did we successfully get and parse a request? // if (pdpRequest == null || pdpRequest.getRequestAttributes() == null - || pdpRequest.getRequestAttributes().size() <= 0) { + || pdpRequest.getRequestAttributes().isEmpty()) { String message = "Zero Attributes found in the request"; logger.error(XACMLErrorConstants.ERROR_DATA_ISSUE + message); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, message);