diff options
Diffstat (limited to 'controlloop/common/guard')
-rw-r--r-- | controlloop/common/guard/src/main/java/org/onap/policy/guard/PIPEngineGetHistory.java | 38 | ||||
-rw-r--r-- | controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java | 14 |
2 files changed, 25 insertions, 27 deletions
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 d35726a64..3e93bd761 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 @@ -23,6 +23,7 @@ package org.onap.policy.guard; import java.math.BigInteger; import java.sql.Timestamp; import java.util.Collection; +import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.Iterator; @@ -112,13 +113,13 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{ @Override public Collection<PIPRequest> attributesRequired() { // TODO Auto-generated method stub - return null; + return Collections.emptySet(); } @Override public Collection<PIPRequest> attributesProvided() { // TODO Auto-generated method stub - return null; + return Collections.emptySet(); } @Override @@ -190,23 +191,25 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{ try { pipResponse = pipFinder.getMatchingAttributes(pipRequest, this); - if (pipResponse != null) { - if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) { - logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString()); - pipResponse = null; - } - if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) { - logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString()); - logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus()); - pipResponse = null; - } - if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) { - logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus()); - pipResponse = null; - } - } } catch (PIPException ex) { logger.error("getAttribute threw:", ex); + return null; + } + if (pipResponse == null) { + return null; + } + if (pipResponse.getStatus() != null && !pipResponse.getStatus().isOk()) { + logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString()); + return null; + } + if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) { + logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus().toString()); + logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus()); + return null; + } + if (pipResponse.getAttributes() != null && pipResponse.getAttributes().isEmpty()) { + logger.warn("Error retrieving {}: {}", pipRequest.getAttributeId().stringValue(), pipResponse.getStatus()); + return null; } return pipResponse; } @@ -312,6 +315,7 @@ public class PIPEngineGetHistory extends StdConfigurableEngine{ }catch(Exception ex){ logger.error("PIP thread got Exception. Can't connect to Operations History DB -- {}", OpsHistPU); logger.error("getCountFromDB threw: ", ex); + return 0; } DateUtil dateUtil = new DateUtil(){ diff --git a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java index 6018c2cab..b594aff0a 100644 --- a/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java +++ b/controlloop/common/guard/src/main/java/org/onap/policy/guard/Util.java @@ -24,19 +24,17 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import org.apache.commons.io.IOUtils; -import org.yaml.snakeyaml.Yaml; -import org.yaml.snakeyaml.constructor.Constructor; - import org.onap.policy.controlloop.policy.ControlLoopPolicy; import org.onap.policy.controlloop.policy.guard.ControlLoopGuard; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.constructor.Constructor; public final class Util { @@ -60,14 +58,11 @@ public final class Util { Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class)); Object obj = yaml.load(contents); - //String ttt = ((ControlLoopPolicy)obj).policies.getFirst().payload.get("asdas"); logger.debug(contents); - //for(Policy policy : ((ControlLoopPolicy)obj).policies){ return new Pair<ControlLoopPolicy, String>((ControlLoopPolicy) obj, contents); - } catch (FileNotFoundException e) { - fail(e.getLocalizedMessage()); } catch (IOException e) { + logger.error(e.getLocalizedMessage(), e); fail(e.getLocalizedMessage()); } return null; @@ -82,9 +77,8 @@ public final class Util { Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class)); Object obj = yaml.load(contents); return (ControlLoopGuard) obj; - } catch (FileNotFoundException e) { - fail(e.getLocalizedMessage()); } catch (IOException e) { + logger.error(e.getLocalizedMessage(), e); fail(e.getLocalizedMessage()); } return null; |