diff options
Diffstat (limited to 'applications/common/src/main')
8 files changed, 46 insertions, 138 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java index e66c9943..b000db92 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/OnapPolicyFinderFactory.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -40,19 +40,12 @@ import com.att.research.xacmlatt.pdp.std.StdPolicyFinder; import com.att.research.xacmlatt.pdp.util.ATTPDPProperties; import com.google.common.base.Splitter; import com.google.common.base.Strings; - import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; import java.util.UUID; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -123,14 +116,6 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { } } - propLocation = this.properties.getProperty(policyId + PROP_URL); - if (propLocation != null) { - PolicyDef policy = this.loadPolicyUrlDef(propLocation); - if (policy != null) { - return policy; - } - } - logger.error("No known location for Policy {}", policyId); return null; } @@ -153,41 +138,9 @@ public class OnapPolicyFinderFactory extends PolicyFinderFactory { } return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, "DOM Could not load policy"); } catch (DOMStructureException ex) { - logger.error("Error loading policy file {}: {}", fileLocation.getAbsolutePath(), ex); - return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage()); - } - } - - protected PolicyDef loadPolicyUrlDef(String propLocation) { - InputStream is = null; - try { - URL url = new URL(propLocation); - URLConnection urlConnection = url.openConnection(); - OnapPolicyFinderFactory.logger.info("Loading policy file {}", url); - is = urlConnection.getInputStream(); - PolicyDef policyDef = DOMPolicyDef.load(is); - if (policyDef != null) { - return policyDef; - } - } catch (MalformedURLException ex) { - logger.error("Invalid URL " + propLocation + ": " + ex.getMessage(), ex); - } catch (IOException ex) { - logger.error("IOException opening URL {}: {}{}", - propLocation, ex.getMessage(), ex); - } catch (DOMStructureException ex) { - logger.error("Invalid Policy " + propLocation + ": " + ex.getMessage(), ex); + logger.error("Error loading policy file {}", fileLocation.getAbsolutePath(), ex); return new Policy(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, ex.getMessage()); - } finally { - if (is != null) { - try { - is.close(); - } catch (IOException e) { - logger.error("Exception closing InputStream for GET of url {}: {}", - propLocation, e.getMessage() + " (May be memory leak)", e); - } - } } - return null; } /** diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java index 7304dfca..4bf87779 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/CountRecentOperationsPip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -28,17 +28,11 @@ import com.att.research.xacml.api.pip.PIPResponse; import com.att.research.xacml.std.pip.StdMutablePIPResponse; import com.att.research.xacml.std.pip.StdPIPResponse; import com.google.common.base.Strings; - import java.sql.Timestamp; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.Arrays; -import java.util.Base64; import java.util.Collection; -import java.util.Properties; - -import javax.persistence.Persistence; - import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip; import org.slf4j.Logger; @@ -51,6 +45,7 @@ public class CountRecentOperationsPip extends StdOnapPip { public CountRecentOperationsPip() { super(); + this.issuer = ISSUER_NAME; } @Override @@ -58,38 +53,6 @@ public class CountRecentOperationsPip extends StdOnapPip { return Arrays.asList(PIP_REQUEST_ACTOR, PIP_REQUEST_RECIPE, PIP_REQUEST_TARGET); } - @Override - public void configure(String id, Properties properties) throws PIPException { - super.configure(id, properties); - // - // Create our entity manager - // - em = null; - try { - // - // In case there are any overloaded properties for the JPA - // - Properties emProperties = new Properties(); - emProperties.putAll(properties); - - // - // Need to decode the password before creating the EntityManager - // - String decodedPassword = new String(Base64.getDecoder() - .decode(emProperties.getProperty("javax.persistence.jdbc.password"))); - emProperties.setProperty("javax.persistence.jdbc.password", decodedPassword); - - // - // Create the entity manager factory - // - em = Persistence.createEntityManagerFactory( - properties.getProperty(ISSUER_NAME + ".persistenceunit"), - emProperties).createEntityManager(); - } catch (Exception e) { - logger.error("Persistence failed {} operations history db {}", e.getLocalizedMessage(), e); - } - } - /** * getAttributes. * diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java index 56d68d55..0f970f7e 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePip.java @@ -16,7 +16,6 @@ * ============LICENSE_END========================================================= */ - package org.onap.policy.pdp.xacml.application.common.operationshistory; import com.att.research.xacml.api.XACML3; @@ -27,14 +26,9 @@ import com.att.research.xacml.api.pip.PIPResponse; import com.att.research.xacml.std.pip.StdMutablePIPResponse; import com.att.research.xacml.std.pip.StdPIPResponse; import com.google.common.base.Strings; - import java.util.Arrays; -import java.util.Base64; import java.util.Collection; -import java.util.Properties; import javax.persistence.NoResultException; -import javax.persistence.Persistence; - import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip; import org.slf4j.Logger; @@ -47,6 +41,7 @@ public class GetOperationOutcomePip extends StdOnapPip { public GetOperationOutcomePip() { super(); + this.issuer = ISSUER_NAME; } @Override @@ -54,38 +49,6 @@ public class GetOperationOutcomePip extends StdOnapPip { return Arrays.asList(PIP_REQUEST_TARGET); } - @Override - public void configure(String id, Properties properties) throws PIPException { - super.configure(id, properties); - // - // Create our entity manager - // - em = null; - try { - // - // In case there are any overloaded properties for the JPA - // - Properties emProperties = new Properties(); - emProperties.putAll(properties); - - // - // Need to decode the password before creating the EntityManager - // - String decodedPassword = new String(Base64.getDecoder() - .decode(emProperties.getProperty("javax.persistence.jdbc.password"))); - emProperties.setProperty("javax.persistence.jdbc.password", decodedPassword); - - // - // Create the entity manager factory - // - em = Persistence.createEntityManagerFactory( - properties.getProperty(ISSUER_NAME + ".persistenceunit"), - emProperties).createEntityManager(); - } catch (Exception e) { - logger.error("Persistence failed {} operations history db {}", e.getLocalizedMessage(), e); - } - } - /** * getAttributes. * diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java index 0a1ace2b..aba5e252 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdCombinedPolicyResultsTranslator.java @@ -132,7 +132,7 @@ public class StdCombinedPolicyResultsTranslator extends StdBaseTranslator { try { return RequestParser.parseRequest(StdCombinedPolicyRequest.createInstance(request)); } catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) { - LOGGER.error("Failed to convert DecisionRequest: {}", e); + LOGGER.error("Failed to convert DecisionRequest", e); } // // TODO throw exception diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java index 2cb82942..d0ae524c 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchablePolicyRequest.java @@ -86,7 +86,7 @@ public class StdMatchablePolicyRequest { } dataTypeFactory = DataTypeFactory.newInstance(); } catch (FactoryException e) { - LOGGER.error("Can't get Data type Factory: {}", e); + LOGGER.error("Can't get Data type Factory", e); } return dataTypeFactory; } diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java index e84a9e77..d5e2a395 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdMatchableTranslator.java @@ -105,7 +105,7 @@ public class StdMatchableTranslator extends StdBaseTranslator { try { return StdMatchablePolicyRequest.createInstance(request); } catch (XacmlApplicationException e) { - LOGGER.error("Failed to convert DecisionRequest: {}", e); + LOGGER.error("Failed to convert DecisionRequest", e); } // // TODO throw exception diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java index 69838599..ca07f22f 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdOnapPip.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -36,13 +36,14 @@ import com.att.research.xacml.std.pip.StdPIPRequest; import com.att.research.xacml.std.pip.engines.StdConfigurableEngine; import java.math.BigInteger; +import java.util.Base64; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.Properties; import javax.persistence.EntityManager; - +import javax.persistence.Persistence; import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,6 +69,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { protected Properties properties; protected EntityManager em; + protected String issuer; public StdOnapPip() { super(); @@ -83,6 +85,33 @@ public abstract class StdOnapPip extends StdConfigurableEngine { super.configure(id, properties); logger.info("Configuring historyDb PIP {}", properties); this.properties = properties; + // + // Create our entity manager + // + em = null; + try { + // + // In case there are any overloaded properties for the JPA + // + Properties emProperties = new Properties(); + emProperties.putAll(properties); + + // + // Need to decode the password before creating the EntityManager + // + String decodedPassword = new String(Base64.getDecoder() + .decode(emProperties.getProperty("javax.persistence.jdbc.password"))); + emProperties.setProperty("javax.persistence.jdbc.password", decodedPassword); + + // + // Create the entity manager factory + // + em = Persistence.createEntityManagerFactory( + properties.getProperty(this.issuer + ".persistenceunit"), + emProperties).createEntityManager(); + } catch (Exception e) { + logger.error("Persistence failed {} operations history db", e.getLocalizedMessage(), e); + } } protected String getAttribute(PIPFinder pipFinder, PIPRequest pipRequest) { @@ -114,7 +143,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { pipResponse = null; } } catch (PIPException ex) { - logger.error("PIPException getting subject-id attribute: " + ex.getMessage(), ex); + logger.error("PIPException getting subject-id attribute", ex); } return pipResponse; } @@ -138,7 +167,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { try { attributeValue = makeInteger(value); } catch (Exception e) { - logger.error("Failed to convert {} to integer {}", value, e); + logger.error("Failed to convert {} to integer", value, e); } if (attributeValue != null) { stdPipResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, @@ -152,7 +181,7 @@ public abstract class StdOnapPip extends StdConfigurableEngine { try { attributeValue = makeLong(value); } catch (Exception e) { - logger.error("Failed to convert {} to long {}", value, e); + logger.error("Failed to convert {} to long", value, e); } if (attributeValue != null) { stdPipResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java index e43e6519..11271651 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/std/StdXacmlApplicationServiceProvider.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP * ================================================================================ - * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2019-2020 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. @@ -194,7 +194,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica Files.delete(refPolicy); } catch (IOException e) { LOGGER.error("Failed to delete policy {} from disk {}", toscaPolicy.getMetadata(), - refPolicy.toAbsolutePath().toString(), e); + refPolicy.toAbsolutePath(), e); } // // Write the properties to disk @@ -277,7 +277,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica this.pdpEngine = engine; } } catch (FactoryException e) { - LOGGER.error("Failed to create XACML PDP Engine {}", e); + LOGGER.error("Failed to create XACML PDP Engine", e); } } @@ -299,7 +299,7 @@ public abstract class StdXacmlApplicationServiceProvider implements XacmlApplica try { response = this.pdpEngine.decide(request); } catch (PDPException e) { - LOGGER.error("Xacml PDP Engine failed {}", e); + LOGGER.error("Xacml PDP Engine decide failed", e); } finally { // // Track the end of timing |