summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main
diff options
context:
space:
mode:
authorGuo Ruijing <ruijing.guo@intel.com>2017-09-04 13:28:23 +0000
committerGuo Ruijing <ruijing.guo@intel.com>2017-09-04 13:30:33 +0000
commit7f93aa65ce1612d1a321e50adf8c24b4e6f84d20 (patch)
treeefafff25b8f852e52f6a7177e1eb9bb08bdc4d45 /ONAP-PAP-REST/src/main
parentaf7f65b6cdc759e4968604e7fa9ff45562bdd8e2 (diff)
Fix critical sonar for ONAP-PAP-REST
This patch is to fix sonar issue for ONAP-PAP-REST. Change-Id: I81f316dbedc994486cce1331d3e9c406ea90aaa7 Issue-Id: POLICY-174 Signed-off-by: Guo Ruijing <ruijing.guo@intel.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java17
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java24
2 files changed, 35 insertions, 6 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
index 0297f30c0..b45d2941a 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/MicroServiceConfigPolicy.java
@@ -66,7 +66,15 @@ public class MicroServiceConfigPolicy extends Policy {
private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceConfigPolicy.class);
private static Map<String, String> mapAttribute = new HashMap<>();
- private static Map<String, String> matchMap = new HashMap<>();
+ private static Map<String, String> mapMatch = new HashMap<>();
+
+ private static synchronized Map<String, String> getMatchMap () {
+ return mapMatch;
+ }
+
+ private static synchronized void setMatchMap(Map<String, String> mm) {
+ mapMatch = mm;
+ }
public MicroServiceConfigPolicy() {
super();
@@ -176,9 +184,11 @@ public class MicroServiceConfigPolicy extends Policy {
String jsonVersion = StringUtils.replaceEach(rootNode.get("version").toString(), new String[]{"\""}, new String[]{""});
matching = getValueFromDictionary(policyAdapter.getServiceType() + "-v" + jsonVersion);
}
-
+
+ Map<String, String> matchMap = null;
if (matching != null && !matching.isEmpty()){
matchMap = Splitter.on(",").withKeyValueSeparator("=").split(matching);
+ setMatchMap(matchMap);
if(policyAdapter.getJsonBody() != null){
pullMatchValue(rootNode);
}
@@ -422,7 +432,8 @@ public class MicroServiceConfigPolicy extends Policy {
assignment7.setExpression(new ObjectFactory().createAttributeValue(configNameAttributeValue7));
advice.getAttributeAssignmentExpression().add(assignment7);
-
+
+ Map<String, String> matchMap = getMatchMap();
if (matchMap==null || matchMap.isEmpty()){
AttributeAssignmentExpressionType assignment6 = new AttributeAssignmentExpressionType();
assignment6.setAttributeId("matching:" + CONFIGID);
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index d2ed1ad51..876e87580 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -217,6 +217,7 @@ public class PolicyDBDao {
try{
em.getTransaction().commit();
} catch(Exception e){
+ logger.warn("List of remote PolicyDBDaos will be empty", e);
try{
em.getTransaction().rollback();
} catch(Exception e2){
@@ -390,14 +391,17 @@ public class PolicyDBDao {
try{
newPolicyDBDaoEntity.setPassword(encryptPassword(url[2]));
} catch(Exception e){
+ logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not encrypt PAP password");
}
try{
em.getTransaction().commit();
} catch(Exception e){
+ logger.debug(e);
try{
em.getTransaction().rollback();
} catch(Exception e2){
+ logger.debug(e2);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Could not add new PolicyDBDao to the database");
}
}
@@ -407,6 +411,7 @@ public class PolicyDBDao {
try{
encryptedPassword = encryptPassword(url[2]);
} catch(Exception e){
+ logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Could not encrypt PAP password");
}
if(url[1] != null && !stringEquals(url[1], foundPolicyDBDaoEntity.getUsername())){
@@ -419,9 +424,11 @@ public class PolicyDBDao {
try{
em.getTransaction().commit();
} catch(Exception e){
+ logger.debug(e);
try{
em.getTransaction().rollback();
} catch(Exception e2){
+ logger.debug(e2);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e2, "PolicyDBDao", "Could not update PolicyDBDao in the database");
}
}
@@ -480,6 +487,7 @@ public class PolicyDBDao {
try{
password = decryptPassword(dbdEntity.getPassword());
} catch(Exception e){
+ logger.debug(e);
//if we can't decrypt, might as well try it anyway
password = dbdEntity.getPassword();
}
@@ -547,7 +555,7 @@ public class PolicyDBDao {
readTimeout = Integer.parseInt(XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_NOTIFY_TIMEOUT));
} catch(Exception e){
- logger.error("xacml.rest.pap.notify.timeoutms property not set, using a default.");
+ logger.error("xacml.rest.pap.notify.timeoutms property not set, using a default.", e);
readTimeout = 10000;
}
connection.setReadTimeout(readTimeout);
@@ -643,11 +651,13 @@ public class PolicyDBDao {
handleIncomingPolicyChange(url, entityId,extraData);
break;
} catch(Exception e){
+ logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught exception on handleIncomingPolicyChange("+url+", "+entityId+", "+extraData+")");
}
try{
Thread.sleep(pauseBetweenRetries);
}catch(InterruptedException ie){
+ Thread.currentThread().interrupt();
break;
}
}
@@ -658,11 +668,13 @@ public class PolicyDBDao {
handleIncomingPdpChange(url, entityId, transaction);
break;
} catch(Exception e){
+ logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught exception on handleIncomingPdpChange("+url+", "+entityId+", "+transaction+")");
}
try{
Thread.sleep(pauseBetweenRetries);
}catch(InterruptedException ie){
+ Thread.currentThread().interrupt();
break;
}
}
@@ -673,11 +685,13 @@ public class PolicyDBDao {
handleIncomingGroupChange(url, entityId, extraData, transaction, xacmlPapServlet);
break;
}catch(Exception e){
+ logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught exception on handleIncomingGroupChange("+url+", "+entityId+", "+extraData+", "+transaction+", "+xacmlPapServlet+")");
}
try{
Thread.sleep(pauseBetweenRetries);
}catch(InterruptedException ie){
+ Thread.currentThread().interrupt();
break;
}
}
@@ -1338,6 +1352,7 @@ public class PolicyDBDao {
try{
startTransactionSynced(this.em,transactionWaitTime);
} catch(Exception e){
+ logger.debug(e);
throw new PersistenceException("Could not lock transaction within "+transactionWaitTime+" milliseconds");
}
}
@@ -1366,6 +1381,7 @@ public class PolicyDBDao {
+ "\n TimeStamp = " + date.getTime()
+ "\n\n");
}
+ Thread.currentThread().interrupt();
return;
}
if(logger.isDebugEnabled()){
@@ -1486,7 +1502,7 @@ public class PolicyDBDao {
try{
em.close();
}catch(Exception e){
- logger.warn("Could not close already closed transaction");
+ logger.warn("Could not close already closed transaction", e);
}
}
@@ -2079,7 +2095,7 @@ public class PolicyDBDao {
try{
configPath = Paths.get(configPath).toString();
} catch(InvalidPathException e){
- logger.error("Invalid config path: "+configPath);
+ logger.error("Invalid config path: "+configPath, e);
throw new IllegalArgumentException("Invalid config path: "+configPath);
}
return configPath;
@@ -2701,6 +2717,7 @@ public class PolicyDBDao {
try{
policyQueryList = policyQuery.getResultList();
} catch(Exception e){
+ logger.debug(e);
PolicyLogger.error(MessageCodes.EXCEPTION_ERROR, e, "PolicyDBDao", "Caught Exception trying to check if policy exists policyQuery.getResultList()");
throw new PersistenceException("Query failed trying to check if policy "+policyNameScopeAndVersion[0]+" exists");
}
@@ -2723,6 +2740,7 @@ public class PolicyDBDao {
}
}
}catch(Exception e){
+ logger.debug(e);
PolicyLogger.error("Could not delete old versions for policy "+policy.getPolicyName()+", ID: "+policy.getPolicyId());
}
group.addPolicyToGroup(policy);