diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2017-08-19 01:07:49 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-08-19 01:07:49 +0000 |
commit | 1b93494ed7c4808aaf979472a9349177ff99d8d8 (patch) | |
tree | fc3431beff1f0140327677d31328fb72cad115b8 /controlloop/common/guard/src/main | |
parent | 1a5a5b0744e57d71ecca6a79eb5cfcbc1df16a19 (diff) | |
parent | 6d7e231986b84cf6646e46beba7e7e05699bffe6 (diff) |
Merge "Code cleanup to resolve critical sonar issues"
Diffstat (limited to 'controlloop/common/guard/src/main')
4 files changed, 37 insertions, 30 deletions
diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java index dbef0c433..53e972941 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java @@ -23,13 +23,17 @@ package org.onap.policy.guard; import com.att.research.xacml.api.DataTypeException; import com.att.research.xacml.api.pdp.PDPEngine; import com.att.research.xacml.std.annotations.RequestParser; + import java.util.UUID; import org.drools.core.WorkingMemory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class CallGuardTask implements Runnable { + private static final Logger logger = LoggerFactory.getLogger(CallGuardTask.class); WorkingMemory workingMemory; PDPEngine embeddedPdpEngine; String restfulPdpUrl; @@ -59,8 +63,7 @@ public class CallGuardTask implements Runnable { try { request = RequestParser.parseRequest(xacmlReq); } catch (IllegalArgumentException | IllegalAccessException | DataTypeException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("CallGuardTask.run threw: ", e); } diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java index 8f3928cdd..57deee5f1 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java @@ -47,15 +47,16 @@ import com.att.research.xacml.api.Attribute; import com.att.research.xacml.api.AttributeValue; import com.att.research.xacml.api.Identifier; import com.att.research.xacml.std.datatypes.DataTypes; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PIPEngineGetHistory extends StdConfigurableEngine{ - private Log logger = LogFactory.getLog(this.getClass()); + private static final Logger logger = LoggerFactory.getLogger(PIPEngineGetHistory.class); //private static EntityManager em; public static final String DEFAULT_DESCRIPTION = "PIP for retrieving Operations History from DB"; @@ -88,7 +89,7 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{ try { attributeValue = DataTypes.DT_INTEGER.createAttributeValue(value); } catch (Exception ex) { - this.logger.error("Failed to convert " + value + " to an AttributeValue<Boolean>", ex); + this.logger.error("Failed to convert {} to an AttributeValue<Boolean>",value, ex); } if (attributeValue != null) { stdPIPResponse.addAttribute(new StdMutableAttribute(category, attributeId, attributeValue, pipRequest.getIssuer()/*this.getIssuer()*/, false)); @@ -193,7 +194,7 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{ pipResponse = null; } } catch (PIPException ex) { - System.out.println("PIPException getting subject-id attribute: " + ex.getMessage()); + logger.error("getAttribute threw: ", ex); } return pipResponse; } @@ -295,29 +296,28 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{ try{ em = Persistence.createEntityManagerFactory("OperationsHistoryPU").createEntityManager(); }catch(Exception e){ - System.err.println("PIP thread got Exception " + e.getLocalizedMessage() + " Can't connect to Operations History DB."); + logger.error("getCountFromDB threw: ", e); return -1; } - String sql = "select count(*) as count from operationshistory10 where outcome<>'Failure_Guard' and actor='" - + actor - + "' and operation='" - + operation - + "' and target='" - + target - + "' " - + "and endtime between date_sub(now(),interval " - + timeWindow - + ") and now()"; - - Query nq = em.createNativeQuery(sql); + String sql = "select count(*) as count from operationshistory10 where outcome<>'Failure_Guard'" + + " and actor=:actor" + + " and operation=:operation" + + " and target=:target" + + " and endtime between date_sub(now(),interval :timeWindow) and now()"; + + Query nq = em.createNativeQuery(sql); + nq = nq.setParameter("actor", actor); + nq = nq.setParameter("operation", operation); + nq = nq.setParameter("target", target); + nq = nq.setParameter("timeWindow", timeWindow); int ret = -1; try{ ret = ((Number)nq.getSingleResult()).intValue(); } catch(NoResultException | NonUniqueResultException ex){ - System.err.println("PIP thread got Exception " + ex.getLocalizedMessage()); + logger.error("getCountFromDB threw: ", ex); return -1; } diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java index 20d50fd3b..c0ed80086 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java @@ -30,6 +30,8 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; import org.apache.http.entity.ContentType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.att.research.xacml.api.Attribute; import com.att.research.xacml.api.AttributeCategory; @@ -44,7 +46,7 @@ import com.att.research.xacml.std.json.JSONResponse; public class PolicyGuardXacmlHelper { - + private static final Logger logger = LoggerFactory.getLogger(PolicyGuardXacmlHelper.class); public static com.att.research.xacml.api.Response callPDP(PDPEngine xacmlEmbeddedPdpEngine, String restfulPdpUrl, com.att.research.xacml.api.Request request, boolean isREST) { // @@ -133,19 +135,20 @@ public class PolicyGuardXacmlHelper { contentType.getMimeType().equalsIgnoreCase("application/xacml+xml") ) { response = (com.att.research.xacml.api.Response) DOMResponse.load(connection.getInputStream()); } else { - System.err.println("unknown content-type: " + contentType); + logger.error("{}: unknown content-type: ", contentType); } } catch (Exception e) { String message = "Parsing Content-Type: " + connection.getContentType() + ", error=" + e.getMessage(); - System.err.println(message); + logger.error("{}: callRESTfulPDP threw: ", message); } } else { - System.err.println(connection.getResponseCode() + " " + connection.getResponseMessage()); + logger.error("unknown content-type: {} {}", connection.getResponseCode(), connection.getResponseMessage() ); } } catch (Exception e) { - System.err.println(e); + + logger.error("callRESTfulPDP threw: ", e); } return response; diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java index 4d952b58e..21584f0b5 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java @@ -30,11 +30,14 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class PolicyGuardYamlToXacml { + private static final Logger logger = LoggerFactory.getLogger(PolicyGuardYamlToXacml.class); public static void fromYamlToXacml(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput){ @@ -67,8 +70,7 @@ public class PolicyGuardYamlToXacml { Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes()); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("fromYamlToXacml threw: ", e); } } @@ -198,8 +200,7 @@ public class PolicyGuardYamlToXacml { Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes()); } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + logger.error("fromYamlToXacmlBlacklist threw: ", e); } } |