diff options
Diffstat (limited to 'ECOMP-PDP-REST')
9 files changed, 103 insertions, 117 deletions
diff --git a/ECOMP-PDP-REST/config/xacml.pip.properties b/ECOMP-PDP-REST/config/xacml.pip.properties index 162bb745f..2286b5dc1 100644 --- a/ECOMP-PDP-REST/config/xacml.pip.properties +++ b/ECOMP-PDP-REST/config/xacml.pip.properties @@ -1,6 +1,3 @@ # -#Thu Feb 16 16:33:31 EST 2017 -AAF.description=AAFEngine to communicate with AT&T AAF to take decisions -AAF.classname=org.openecomp.policy.xacml.std.pip.engines.aaf.AAFEngine -AAF.name=AAFEngine -xacml.pip.engines=AAF +#Wed May 31 15:42:12 EDT 2017 + diff --git a/ECOMP-PDP-REST/config/xacml.policy.properties b/ECOMP-PDP-REST/config/xacml.policy.properties index 695a10b1a..5c884ed8b 100644 --- a/ECOMP-PDP-REST/config/xacml.policy.properties +++ b/ECOMP-PDP-REST/config/xacml.policy.properties @@ -1,4 +1,4 @@ # -#Thu Feb 16 16:33:31 EST 2017 +#Wed May 31 15:42:12 EDT 2017 xacml.referencedPolicies= xacml.rootPolicies= diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java index 44a1f5e17..9d7ebbe6e 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/PapUrlResolver.java @@ -24,35 +24,34 @@ import java.net.URI; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; +import java.util.Arrays; import java.util.Date; import java.util.NoSuchElementException; import java.util.Properties; +import org.openecomp.policy.common.logging.flexlogger.FlexLogger; +import org.openecomp.policy.common.logging.flexlogger.Logger; import org.openecomp.policy.rest.XACMLRestProperties; import com.att.research.xacml.util.XACMLProperties; -import org.openecomp.policy.common.logging.flexlogger.*; - public class PapUrlResolver { private static final Logger LOGGER = FlexLogger.getLogger(PapUrlResolver.class); //how long to keep a pap failed before making it un-failed, in milli-seconds private static final long FAIL_TIMEOUT = 18000000; //thread locks - public static Object propertyLock = new Object(); + public static final Object propertyLock = new Object(); - public static void setPapUrls(String[] papUrls){ - - } //keeping this here for backward compatibility public static String extractIdFromUrl(String url){ return extractQuery(url); } public static String extractQuery(String url){ try{ - return URI.create(url).getQuery(); + return URI.create(url).getQuery(); } catch(Exception e){ + LOGGER.error("Exception occured while extracting query. So, empty string is returned"+e); return ""; } } @@ -92,22 +91,24 @@ public class PapUrlResolver { //because it is used for a difference purpose. private PapUrlResolver(String urlList, String failedList, String succeededList, boolean autoUpdateProperties){ this.autoUpdateProperties = autoUpdateProperties; - //synchronized(propertyLock){ - if(urlList == null){ - urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URLS); - if(urlList == null){ - urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); + String papUrlLists = urlList; + String papUrlFailedList = failedList; + String papUrlSuccessList = succeededList; + if(papUrlLists == null){ + papUrlLists = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URLS); + if(papUrlLists == null){ + papUrlLists = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL); } - failedList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); - succeededList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); + papUrlFailedList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS); + papUrlSuccessList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS); } - //} - String[] urls = urlList.split(","); + + String[] urls = papUrlLists.split(","); if(urls.length == 0){ //log error } - String[] failed = emptyOrSplit(failedList,urls.length); - String[] succeeded = emptyOrSplit(succeededList,urls.length); + String[] failed = emptyOrSplit(papUrlFailedList,urls.length); + String[] succeeded = emptyOrSplit(papUrlSuccessList,urls.length); sortedUrlNodes = new PapUrlNode[urls.length]; for(int i=0;i<urls.length;i++){ @@ -130,7 +131,6 @@ public class PapUrlResolver { if(sortedUrlNodes[i] == null){ sortedUrlNodes[i] = newNode; } - } originalUrlNodes = sortedUrlNodes.clone(); sort(sortedUrlNodes); @@ -243,8 +243,7 @@ public class PapUrlResolver { if(sortedUrlNodes[pointer]== null){ throw new NoSuchElementException(); } else { - String finalUrl = sortedUrlNodes[pointer].getUrl().concat("?").concat(query); - return finalUrl; + return sortedUrlNodes[pointer].getUrl().concat("?").concat(query); } } @@ -324,13 +323,12 @@ public class PapUrlResolver { //parses string into a date or a null date, if the url never failed/succeeded (since -1 will be in the property) private Date setHandler(Object time){ if(time instanceof String){ - if(((String)time).equals("-1")){ + if("-1".equals((String)time)){ return null; } try { DateFormat df = new SimpleDateFormat(); - Date parsedTime = df.parse((String)time); - return parsedTime; + return df.parse((String)time); } catch (ParseException e) { return null; } @@ -362,7 +360,8 @@ public class PapUrlResolver { public String getUrl(){ return papUrl; } - + + @Override public int compareTo(PapUrlNode other){ if(this.failedTime == null && other.failedTime != null){ return -1; diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java index 6770c7ebb..a247fe65c 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/XACMLPdpServlet.java @@ -124,7 +124,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // audit logger private static final Log auditLogger = LogFactory.getLog("auditLogger"); - private static final PdpRestMonitor monitor = PdpRestMonitor.singleton; + private static final PdpRestMonitor monitor = PdpRestMonitor.getSingleton(); // // This thread may getting invoked on startup, to let the PAP know @@ -154,8 +154,8 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // Queue of PUT requests // public static class PutRequest { - public Properties policyProperties = null; - public Properties pipConfigProperties = null; + private Properties policyProperties = null; + private Properties pipConfigProperties = null; PutRequest(Properties policies, Properties pips) { this.policyProperties = policies; @@ -170,7 +170,6 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { } private static String pdpResourceName; - private static String dependencyGroups = null; private static String[] dependencyNodes = null; // @@ -181,17 +180,20 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { private volatile boolean configThreadTerminate = false; private ECOMPLoggingContext baseLoggingContext = null; private IntegrityMonitor im; - private String createUpdateResourceName = null; /** * Default constructor. */ public XACMLPdpServlet() { + //Default constructor. } /** * @see Servlet#init(ServletConfig) */ + @Override public void init(ServletConfig config) throws ServletException { + String createUpdateResourceName = null; + String dependencyGroups = null; // // Initialize // @@ -200,7 +202,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { try{ XACMLPdpServlet.notificationDelay = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_NOTIFICATION_DELAY)); }catch(Exception e){ - logger.info("Notification Delay Not set. Keeping it 0 as default."); + logger.info("Notification Delay Not set. Keeping it 0 as default."+e); } // Load Queue size. int queueSize = 5; // Set default Queue Size here. @@ -221,10 +223,10 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { baseLoggingContext = new ECOMPLoggingContext(); // fixed data that will be the same in all logging output goes here try { - String hostname = InetAddress.getLocalHost().getCanonicalHostName(); - baseLoggingContext.setServer(hostname); + String ipaddress = InetAddress.getLocalHost().getHostAddress(); + baseLoggingContext.setServer(ipaddress); } catch (UnknownHostException e) { - logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging"); + logger.warn(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Unable to get hostname for logging"+e); } Properties properties; @@ -305,6 +307,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { /** * @see Servlet#destroy() */ + @Override public void destroy() { super.destroy(); logger.info("Destroying...."); @@ -386,10 +389,11 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { * * @see HttpServlet#doPut(HttpServletRequest request, HttpServletResponse response) */ + @Override protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); loggingContext.transactionStarted(); - if ((loggingContext.getRequestID() == null) || (loggingContext.getRequestID() == "")){ + if ((loggingContext.getRequestID() == null) || "".equals(loggingContext.getRequestID())){ UUID requestID = UUID.randomUUID(); loggingContext.setRequestID(requestID.toString()); PolicyLogger.info("requestID not provided in call to XACMLPdpSrvlet (doPut) so we generated one"); @@ -414,7 +418,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { } catch (AdministrativeStateException | StandbyStatusException e) { String message = e.toString(); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed - See Error.log"); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); @@ -576,6 +580,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { * * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); loggingContext.transactionStarted(); @@ -753,6 +758,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { * * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ + @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ECOMPLoggingContext loggingContext = ECOMPLoggingUtils.getLoggingContextForRequest(request, baseLoggingContext); @@ -778,7 +784,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { } catch (AdministrativeStateException | StandbyStatusException e) { String message = e.toString(); - PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); + PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message + e); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed - See Error.log"); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); @@ -787,7 +793,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // // no point in doing any work if we know from the get-go that we cannot do anything with the request // - if (status.getLoadedRootPolicies().size() == 0) { + if (status.getLoadedRootPolicies().isEmpty()) { logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "Request from PEP at " + request.getRequestURI() + " for service when PDP has No Root Policies loaded"); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "Request from PEP at " + request.getRequestURI() + " for service when PDP has No Root Policies loaded"); loggingContext.transactionEnded(); @@ -865,9 +871,14 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { StringBuilder buffer = new StringBuilder(); BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); String line; - while((line = reader.readLine()) != null){ - buffer.append(line); + try{ + while((line = reader.readLine()) != null){ + buffer.append(line); + } + }catch(Exception e){ + logger.error("Exception Occured while reading line"+e); } + incomingRequestString = buffer.toString(); logger.info(incomingRequestString); // @@ -920,7 +931,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // // Authenticating the Request here. // - if(!authorizeRequest(request, pdpRequest)){ + if(!authorizeRequest(request)){ String message = "PEP not Authorized for making this Request!! \n Contact Administrator for this Scope. "; logger.error(XACMLErrorConstants.ERROR_PERMISSIONS + message ); PolicyLogger.error(MessageCodes.ERROR_PERMISSIONS, message); @@ -950,23 +961,10 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // // Send the request and save the response // - long lTimeStart, lTimeEnd; + long lTimeStart; + long lTimeEnd; Response pdpResponse = null; - //TODO - Make this unnecessary - //TODO It seems that the PDP Engine is not thread-safe, so when a configuration change occurs in the middle of processing - //TODO a PEP Request, that Request fails (it throws a NullPointerException in the decide() method). - //TODO Using synchronize will slow down processing of PEP requests, possibly by a significant amount. - //TODO Since configuration changes are rare, it would be A Very Good Thing if we could eliminate this sychronized block. - //TODO - //TODO This problem was found by starting one PDP then - //TODO RestLoadTest switching between 2 configurations, 1 second apart - //TODO both configurations contain the datarouter policy - //TODO both configurations already have all policies cached in the PDPs config directory - //TODO RestLoadTest started with the Datarouter test requests, 5 threads, no interval - //TODO With that configuration this code (without the synchronized) throws a NullPointerException - //TODO within a few seconds. - // synchronized(pdpEngineLock) { myEngine = XACMLPdpServlet.pdpEngine; try { @@ -976,7 +974,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { lTimeEnd = System.currentTimeMillis(); } catch (PDPException e) { String message = "Exception during decide: " + e.getMessage(); - logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message); + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + message +e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, message); loggingContext.transactionEnded(); PolicyLogger.audit("Transaction Failed - See Error.log"); @@ -1005,7 +1003,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // if (pdpResponse == null) { requestLogger.info(lTimeStart + "=" + "{}"); - throw new Exception("Failed to get response from PDP engine."); + throw new PDPException("Failed to get response from PDP engine."); } // // Set our content-type @@ -1086,16 +1084,12 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { /* * Added for Authorizing the PEP Requests for Environment check. */ - private boolean authorizeRequest(HttpServletRequest request, Request pepRequest) { - if(request instanceof HttpServletRequest) { - // Get the client Credentials from the Request header. - HttpServletRequest httpServletRequest = (HttpServletRequest) request; - String clientCredentials = httpServletRequest.getHeader(ENVIORNMENT_HEADER); - if(clientCredentials!=null && clientCredentials.equalsIgnoreCase(environment)){ - return true; - }else{ - return false; - } + private boolean authorizeRequest(HttpServletRequest request) { + // Get the client Credentials from the Request header. + HttpServletRequest httpServletRequest = request; + String clientCredentials = httpServletRequest.getHeader(ENVIORNMENT_HEADER); + if(clientCredentials!=null && clientCredentials.equalsIgnoreCase(environment)){ + return true; }else{ return false; } @@ -1108,22 +1102,15 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { // try { // variable not used, but constructor has needed side-effects so don't remove: - @SuppressWarnings("unused") - ECOMPLoggingContext loggingContext = new ECOMPLoggingContext(baseLoggingContext); while (! this.configThreadTerminate) { PutRequest request = XACMLPdpServlet.queue.take(); StdPDPStatus newStatus = new StdPDPStatus(); - - //TODO - This is related to the problem discussed in the doPost() method about the PDPEngine not being thread-safe. - //TODO See that discussion, and when the PDPEngine is made thread-safe it should be ok to move the loadEngine out of - //TODO the synchronized block. - //TODO However, since configuration changes should be rare we may not care about changing this. + PDPEngine newEngine = null; synchronized(pdpStatusLock) { XACMLPdpServlet.status.setStatus(Status.UPDATING_CONFIGURATION); newEngine = XACMLPdpLoader.loadEngine(newStatus, request.policyProperties, request.pipConfigProperties); } - // PDPEngine newEngine = XACMLPdpLoader.loadEngine(newStatus, request.policyProperties, request.pipConfigProperties); if (newEngine != null) { synchronized(XACMLPdpServlet.pdpEngineLock) { XACMLPdpServlet.pdpEngine = newEngine; @@ -1141,7 +1128,7 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { } newStatus.setStatus(Status.UP_TO_DATE); } catch (Exception e) { - logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to store new properties."); + logger.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to store new properties."+e); PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, "Failed to store new properties"); newStatus.setStatus(Status.LOAD_ERRORS); newStatus.addLoadWarning("Unable to save configuration: " + e.getMessage()); @@ -1155,8 +1142,9 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { } } } catch (InterruptedException e) { - logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "interrupted"); + logger.error(XACMLErrorConstants.ERROR_SYSTEM_ERROR + "interrupted"+e); PolicyLogger.error(MessageCodes.ERROR_SYSTEM_ERROR, "interrupted"); + Thread.currentThread().interrupt(); } } @@ -1171,5 +1159,4 @@ public class XACMLPdpServlet extends HttpServlet implements Runnable { public static Constructor<?> getCreateUpdatePolicyConstructor(){ return createUpdatePolicyConstructor; } - } diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/controller/PolicyEngineServices.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/controller/PolicyEngineServices.java index 47afcda67..a9d80fdc2 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/controller/PolicyEngineServices.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/api/controller/PolicyEngineServices.java @@ -81,7 +81,7 @@ import springfox.documentation.annotations.ApiIgnore; @Api(value = "Policy Engine Services") @RequestMapping("/") public class PolicyEngineServices { - private static Logger LOGGER = FlexLogger + private static Logger logger = FlexLogger .getLogger(PolicyEngineServices.class.getName()); private final AtomicLong configCounter = new AtomicLong(); private final AtomicLong configNameCounter = new AtomicLong(); @@ -118,8 +118,7 @@ public class PolicyEngineServices { status = getConfigService.getResponseCode(); } configCounter.incrementAndGet(); - return new ResponseEntity<Collection<PolicyConfig>>(policyConfig, - status); + return new ResponseEntity<Collection<PolicyConfig>>(policyConfig, status); } @ApiImplicitParams({ @@ -147,8 +146,7 @@ public class PolicyEngineServices { status = getConfigService.getResponseCode(); } configNameCounter.incrementAndGet(); - return new ResponseEntity<Collection<PolicyConfig>>(policyConfig, - status); + return new ResponseEntity<>(policyConfig, status); } @ApiImplicitParams({ @@ -172,7 +170,7 @@ public class PolicyEngineServices { status = listConfigService.getResponseCode(); } configCounter.incrementAndGet(); - return new ResponseEntity<Collection<String>>(results, status); + return new ResponseEntity<>(results, status); } @ApiImplicitParams({ @@ -194,7 +192,7 @@ public class PolicyEngineServices { status = getMetricsService.getResponseCode(); } metricCounter.incrementAndGet(); - return new ResponseEntity<MetricsResponse>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -217,7 +215,7 @@ public class PolicyEngineServices { status = sendEventService.getResponseCode(); } eventCounter.incrementAndGet(); - return new ResponseEntity<Collection<PolicyResponse>>(policyResponse, + return new ResponseEntity<>(policyResponse, status); } @@ -242,7 +240,7 @@ public class PolicyEngineServices { status = getDecisionService.getResponseCode(); } decisionCounter.incrementAndGet(); - return new ResponseEntity<DecisionResponse>(decisionResponse, status); + return new ResponseEntity<>(decisionResponse, status); } @ApiImplicitParams({ @@ -266,7 +264,7 @@ public class PolicyEngineServices { status = pushPolicyService.getResponseCode(); } pushCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -290,7 +288,7 @@ public class PolicyEngineServices { status = deletePolicyService.getResponseCode(); } deleteCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -316,13 +314,13 @@ public class PolicyEngineServices { status = createPolicyService.getResponseCode(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - LOGGER.error(e.getMessage()); + logger.error(e.getMessage()); response = "Problem with CreateUpdate Policy Service. "; status = HttpStatus.INTERNAL_SERVER_ERROR; } } createPolicyCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -348,13 +346,13 @@ public class PolicyEngineServices { status = updatePolicyService.getResponseCode(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - LOGGER.error(e.getMessage()); + logger.error(e.getMessage()); response = "Problem with CreateUpdate Policy Service. "; status = HttpStatus.INTERNAL_SERVER_ERROR; } } updatePolicyCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -378,7 +376,7 @@ public class PolicyEngineServices { status = createDictionaryService.getResponseCode(); } createDictionaryCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -402,7 +400,7 @@ public class PolicyEngineServices { status = updateDictionaryService.getResponseCode(); } updateDictionaryCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -426,7 +424,7 @@ public class PolicyEngineServices { status = getDictionaryService.getResponseCode(); } getDictionaryCounter.incrementAndGet(); - return new ResponseEntity<DictionaryResponse>(dictionaryResponse, + return new ResponseEntity<>(dictionaryResponse, status); } @@ -452,7 +450,7 @@ public class PolicyEngineServices { status = policyEngineImportService.getResponseCode(); } policyEngineImportCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -477,7 +475,7 @@ public class PolicyEngineServices { status = createPolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -502,7 +500,7 @@ public class PolicyEngineServices { status = updatePolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -527,7 +525,7 @@ public class PolicyEngineServices { status = createFirewallPolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -552,7 +550,7 @@ public class PolicyEngineServices { status = updateFirewallPolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity<String>(response, status); + return new ResponseEntity<>(response, status); } @ApiOperation(value = "Gets the API Services usage Information") @@ -579,7 +577,7 @@ public class PolicyEngineServices { @ExceptionHandler({ HttpMessageNotReadableException.class }) public ResponseEntity<String> messageNotReadableExceptionHandler( HttpServletRequest req, HttpMessageNotReadableException exception) { - LOGGER.error("Request not readable: {}", exception); + logger.error("Request not readable: {}", exception); StringBuilder message = new StringBuilder(); message.append(exception.getMessage()); if (exception.getCause() != null) { diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/config/PDPApiAuth.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/config/PDPApiAuth.java index e6122d324..a5d3adb7a 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/config/PDPApiAuth.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/config/PDPApiAuth.java @@ -91,7 +91,7 @@ public class PDPApiAuth { StringTokenizer tokenizer = new StringTokenizer(usernameAndPassword, ":"); String username = tokenizer.nextToken(); String password = tokenizer.nextToken(); - userNamePass= new String[]{username, password}; + userNamePass= new String[]{username, password}; } PolicyLogger.info("User " + userNamePass[0] + " is Accessing Policy Engine API."); Boolean result = false; diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java index e956cd363..c56ddba9a 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMBeanListener.java @@ -51,7 +51,7 @@ public class PdpRestMBeanListener implements ServletContextListener { final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); try { objectName = new ObjectName(JMX_OBJECT_NAME); - server.registerMBean(PdpRestMonitor.singleton, objectName); + server.registerMBean(PdpRestMonitor.getSingleton(), objectName); LOGGER.info("MBean registered: " + objectName); } catch (Exception e) { diff --git a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java index e814e7408..1c088b24e 100644 --- a/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java +++ b/ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp/rest/jmx/PdpRestMonitor.java @@ -29,7 +29,7 @@ import org.openecomp.policy.xacml.util.MetricsUtil.MaxLatency; import org.openecomp.policy.xacml.util.MetricsUtil.MinLatency; public class PdpRestMonitor implements PdpRestMonitorMBean { - public static PdpRestMonitor singleton = new PdpRestMonitor(); + private static PdpRestMonitor singleton = new PdpRestMonitor(); private final AtomicLong pdpEvaluationAttempts = new AtomicLong(); private final AtomicLong pdpEvaluationSuccesses = new AtomicLong(); @@ -136,22 +136,27 @@ public class PdpRestMonitor implements PdpRestMonitorMBean { } public void policyCountAdd(String policyID, Integer count){ + int countValue = count; if (policyCount.containsKey(policyID)){ - count = count + policyCount.get(policyID); + countValue = countValue + policyCount.get(policyID); } - policyCount.put(policyID, count); + policyCount.put(policyID, countValue); } public Map<String, Integer> getpolicyMap() { return policyCount; } public Integer getpolicyCount(String policyID) { - // TODO Auto-generated method stub if (policyCount.containsKey(policyID)){ return policyCount.get(policyID); } return null; } - + public static PdpRestMonitor getSingleton() { + return singleton; + } + public static void setSingleton(PdpRestMonitor singleton) { + PdpRestMonitor.singleton = singleton; + } } diff --git a/ECOMP-PDP-REST/xacml.pdp.properties b/ECOMP-PDP-REST/xacml.pdp.properties index 1193648bc..1f20856c1 100644 --- a/ECOMP-PDP-REST/xacml.pdp.properties +++ b/ECOMP-PDP-REST/xacml.pdp.properties @@ -84,7 +84,7 @@ DMAAP_AAF_PASSWORD= # xacml.rest.pdp.config=config -xacml.rest.pdp.webapps=/webapps +xacml.rest.pdp.webapps=/home/users/PolicyEngine/webapps/ConfigPAP/ # # Initialize register with PAP servlet # |