diff options
Diffstat (limited to 'applications/common/src')
3 files changed, 34 insertions, 31 deletions
diff --git a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.java b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.java index 2b70c9be..b4ee5594 100644 --- a/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.java +++ b/applications/common/src/main/java/org/onap/policy/pdp/xacml/application/common/operationshistory/Dbao.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. @@ -24,17 +24,18 @@ package org.onap.policy.pdp.xacml.application.common.operationshistory; import java.io.Serializable; import java.util.Date; - import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.Index; import javax.persistence.Table; - import lombok.Data; @Entity -@Table(name = "operationshistory") +@Table(name = "operationshistory", + indexes = {@Index(name = "operationshistory_clreqid_index", columnList = "closedLoopName,requestId"), + @Index(name = "operationshistory_target_index", columnList = "target,operation,actor")}) @Data public class Dbao implements Serializable { 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 fb018b02..60e26a2e 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 @@ -28,13 +28,13 @@ import com.att.research.xacml.std.pip.StdPIPResponse; import com.google.common.base.Strings; import java.util.Arrays; import java.util.Collection; + import javax.persistence.NoResultException; import org.onap.policy.pdp.xacml.application.common.ToscaDictionary; import org.onap.policy.pdp.xacml.application.common.std.StdOnapPip; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - public class GetOperationOutcomePip extends StdOnapPip { public static final String ISSUER_NAME = "get-operation-outcome"; private static Logger logger = LoggerFactory.getLogger(GetOperationOutcomePip.class); @@ -57,12 +57,13 @@ public class GetOperationOutcomePip extends StdOnapPip { * @return PIPResponse */ @Override - public PIPResponse getAttributes(PIPRequest pipRequest, PIPFinder pipFinder) throws PIPException { + public PIPResponse getAttributes(PIPRequest pipRequest, PIPFinder pipFinder) + throws PIPException { if (this.shutdown) { throw new PIPException("Engine is shutdown"); } logger.debug("getAttributes requesting attribute {} of type {} for issuer {}", - pipRequest.getAttributeId(), pipRequest.getDataTypeId(), pipRequest.getIssuer()); + pipRequest.getAttributeId(), pipRequest.getDataTypeId(), pipRequest.getIssuer()); // // Determine if the issuer is correct // @@ -73,7 +74,7 @@ public class GetOperationOutcomePip extends StdOnapPip { // return StdPIPResponse.PIP_RESPONSE_EMPTY; } - if (! pipRequest.getIssuer().startsWith(ToscaDictionary.GUARD_ISSUER_PREFIX)) { + if (!pipRequest.getIssuer().startsWith(ToscaDictionary.GUARD_ISSUER_PREFIX)) { logger.error("Issuer does not start with guard"); // // We only respond to ourself as the issuer @@ -91,14 +92,11 @@ public class GetOperationOutcomePip extends StdOnapPip { logger.debug("Going to query DB about: clname={}, target={}", clname, target); String outcome = doDatabaseQuery(clname); - logger.debug("Query result is: {}", outcome); + logger.info("Query result is: {}", outcome); StdMutablePIPResponse pipResponse = new StdMutablePIPResponse(); - this.addStringAttribute(pipResponse, - XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, - ToscaDictionary.ID_RESOURCE_GUARD_OPERATIONOUTCOME, - outcome, - pipRequest); + this.addStringAttribute(pipResponse, XACML3.ID_ATTRIBUTE_CATEGORY_RESOURCE, + ToscaDictionary.ID_RESOURCE_GUARD_OPERATIONOUTCOME, outcome, pipRequest); return new StdPIPResponse(pipResponse); } @@ -118,13 +116,17 @@ public class GetOperationOutcomePip extends StdOnapPip { // // We are expecting a single result // - return em.createQuery("select e.outcome from Dbao e" - + " where e.closedLoopName= ?1" - + " order by e.endtime desc", - String.class) - .setParameter(1, clname) - .setMaxResults(1) - .getSingleResult(); + String result = em + .createQuery("select e.outcome from Dbao e" + " where e.closedLoopName= ?1" + + " order by e.starttime desc", String.class) + .setParameter(1, clname).setMaxResults(1).getSingleResult(); + + // Check the value of result + if (result.equalsIgnoreCase("Started")) { + return ("In_Progress"); + } else { + return ("Complete"); + } } catch (NoResultException e) { logger.trace("No results", e); } catch (Exception e) { diff --git a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java index dcb172e6..b5273e6d 100644 --- a/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java +++ b/applications/common/src/test/java/org/onap/policy/pdp/xacml/application/common/operationshistory/GetOperationOutcomePipTest.java @@ -35,8 +35,8 @@ import com.att.research.xacml.api.pip.PIPResponse; import com.att.research.xacml.std.pip.StdPIPResponse; import java.io.FileInputStream; import java.lang.reflect.Method; -import java.sql.Date; import java.time.Instant; +import java.util.Date; import java.util.Properties; import java.util.UUID; import javax.persistence.EntityManager; @@ -199,28 +199,28 @@ public class GetOperationOutcomePipTest { // // Insert entry // - insertEntry("testcl1", "testtarget1", "1"); + insertEntry("testcl1", "testtarget1", "Started"); // // Test pipEngine // outcome = (String) method.invoke(pipEngine, "testcl1"); // - // outcome should be "1" + // outcome should be "In_Progress" // - assertEquals("1", outcome); + assertEquals("In_Progress", outcome); // // Insert more entries // - insertEntry("testcl1", "testtarget1", "2"); - insertEntry("testcl2", "testtarget2", "3"); + insertEntry("testcl2", "testtarget1", "Success"); + insertEntry("testcl3", "testtarget2", "Failed"); // // Test pipEngine // - outcome = (String) method.invoke(pipEngine, "testcl1"); - assertEquals("2", outcome); - outcome = (String) method.invoke(pipEngine, "testcl2"); - assertEquals("3", outcome); + assertEquals("Complete", outcome); + + outcome = (String) method.invoke(pipEngine, "testcl3"); + assertEquals("Complete", outcome); // // Shut it down |