From d9007d680d19734d5dc106479784c420236cca4b Mon Sep 17 00:00:00 2001 From: Ravindra Bakkamanthala Date: Wed, 31 May 2017 15:54:24 -0400 Subject: [Policy-17] Removed the sql scripts from sdk app Change-Id: I5b017aad569014c7f12eab35e1dbd1c215f90ebe Signed-off-by: Ravindra Bakkamanthala --- .../openecomp/policy/pdp/rest/PapUrlResolver.java | 49 ++++++----- .../openecomp/policy/pdp/rest/XACMLPdpServlet.java | 95 ++++++++++------------ .../rest/api/controller/PolicyEngineServices.java | 46 +++++------ .../policy/pdp/rest/config/PDPApiAuth.java | 2 +- .../policy/pdp/rest/jmx/PdpRestMBeanListener.java | 2 +- .../policy/pdp/rest/jmx/PdpRestMonitor.java | 15 ++-- 6 files changed, 99 insertions(+), 110 deletions(-) (limited to 'ECOMP-PDP-REST/src/main/java/org/openecomp/policy/pdp') 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 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>(policyConfig, - status); + return new ResponseEntity>(policyConfig, status); } @ApiImplicitParams({ @@ -147,8 +146,7 @@ public class PolicyEngineServices { status = getConfigService.getResponseCode(); } configNameCounter.incrementAndGet(); - return new ResponseEntity>(policyConfig, - status); + return new ResponseEntity<>(policyConfig, status); } @ApiImplicitParams({ @@ -172,7 +170,7 @@ public class PolicyEngineServices { status = listConfigService.getResponseCode(); } configCounter.incrementAndGet(); - return new ResponseEntity>(results, status); + return new ResponseEntity<>(results, status); } @ApiImplicitParams({ @@ -194,7 +192,7 @@ public class PolicyEngineServices { status = getMetricsService.getResponseCode(); } metricCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -217,7 +215,7 @@ public class PolicyEngineServices { status = sendEventService.getResponseCode(); } eventCounter.incrementAndGet(); - return new ResponseEntity>(policyResponse, + return new ResponseEntity<>(policyResponse, status); } @@ -242,7 +240,7 @@ public class PolicyEngineServices { status = getDecisionService.getResponseCode(); } decisionCounter.incrementAndGet(); - return new ResponseEntity(decisionResponse, status); + return new ResponseEntity<>(decisionResponse, status); } @ApiImplicitParams({ @@ -266,7 +264,7 @@ public class PolicyEngineServices { status = pushPolicyService.getResponseCode(); } pushCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -290,7 +288,7 @@ public class PolicyEngineServices { status = deletePolicyService.getResponseCode(); } deleteCounter.incrementAndGet(); - return new ResponseEntity(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(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(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -378,7 +376,7 @@ public class PolicyEngineServices { status = createDictionaryService.getResponseCode(); } createDictionaryCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -402,7 +400,7 @@ public class PolicyEngineServices { status = updateDictionaryService.getResponseCode(); } updateDictionaryCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -426,7 +424,7 @@ public class PolicyEngineServices { status = getDictionaryService.getResponseCode(); } getDictionaryCounter.incrementAndGet(); - return new ResponseEntity(dictionaryResponse, + return new ResponseEntity<>(dictionaryResponse, status); } @@ -452,7 +450,7 @@ public class PolicyEngineServices { status = policyEngineImportService.getResponseCode(); } policyEngineImportCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -477,7 +475,7 @@ public class PolicyEngineServices { status = createPolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -502,7 +500,7 @@ public class PolicyEngineServices { status = updatePolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -527,7 +525,7 @@ public class PolicyEngineServices { status = createFirewallPolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity(response, status); + return new ResponseEntity<>(response, status); } @ApiImplicitParams({ @@ -552,7 +550,7 @@ public class PolicyEngineServices { status = updateFirewallPolicyService.getResponseCode(); } deprecatedCounter.incrementAndGet(); - return new ResponseEntity(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 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 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; + } } -- cgit 1.2.3-korg