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=6082953252b334ec7535a4169d46d2aa94205398;hb=c5d97e8a9a6bea71f3be329a2e44bdbe5fe50882;hp=18c2017374a3fd92a519474f0ddd82b4b3ef0a4c;hpb=80f072f60509ef3a35369a60857fe05f6c2a993a;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 18c201737..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. @@ -180,6 +180,14 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { private static volatile boolean configThreadTerminate = false; private transient ONAPLoggingContext baseLoggingContext = null; private transient IntegrityMonitor im; + public IntegrityMonitor getIm() { + return im; + } + + public void setIm(IntegrityMonitor im) { + this.im = im; + } + /** * Default constructor. */ @@ -200,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 @@ -221,8 +229,8 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { baseLoggingContext = new ONAPLoggingContext(); // fixed data that will be the same in all logging output goes here try { - String ipaddress = InetAddress.getLocalHost().getHostAddress(); - baseLoggingContext.setServer(ipaddress); + String hostname = InetAddress.getLocalHost().getCanonicalHostName(); + baseLoggingContext.setServer(hostname); } catch (UnknownHostException e) { logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging"+e); } @@ -469,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"); @@ -496,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"); @@ -534,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"); @@ -548,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"); @@ -571,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 @@ -1230,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, ""); } @@ -1261,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);