aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2021-02-22 10:54:15 -0600
committerjhh <jorge.hernandez-herrero@att.com>2021-02-22 10:54:15 -0600
commit0b54008e634faf5a111ea61ea94c1e4f9ae2a347 (patch)
tree896e90b98065f27ff8abb0fdb7252465bf57b40f
parent9ca3f1b4c7891fab169d13f91434793c3a7a8678 (diff)
support policy execution counts in lifecycle
Issue-ID: POLICY-3033 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ic9150b9b76a04ee39cb0c0a78081ad22b21dcd02
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java2
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java28
2 files changed, 28 insertions, 2 deletions
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
index 1fb1d4f5..438db030 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java
@@ -591,7 +591,7 @@ public class LifecycleFsm implements Startable {
updateStats.setTimeStamp(Instant.now());
try {
- BeanUtils.copyProperties(updateStats, PolicyEngineConstants.getManager().getStats());
+ BeanUtils.copyProperties(updateStats, PolicyEngineConstants.getManager().getStats().getGroupStat());
} catch (IllegalAccessException | InvocationTargetException ex) {
logger.debug("statistics mapping failure", ex);
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
index 9dda01df..1a2d9ded 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
@@ -30,6 +30,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;
+import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
@@ -39,6 +40,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
+import org.onap.policy.drools.system.PolicyEngineConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.enums.PdpState;
@@ -98,7 +100,7 @@ public class LifecycleFsmTest {
* Test initialization.
*/
@Before
- public void init() throws CoderException, IOException {
+ public void beforeTest() throws CoderException, IOException {
LoggerUtil.setLevel(LoggerUtil.ROOT_LOGGER, "INFO");
LoggerUtil.setLevel("org.onap.policy.common.endpoints", "WARN");
LoggerUtil.setLevel("org.onap.policy.drools", "INFO");
@@ -123,6 +125,26 @@ public class LifecycleFsmTest {
getPolicyFromFile(EXAMPLE_OTHER_VAL_POLICY_JSON, EXAMPLE_OTHER_VAL_POLICY_NAME);
unvalPolicy =
getPolicyFromFile(EXAMPLE_OTHER_UNVAL_POLICY_JSON, EXAMPLE_OTHER_UNVAL_POLICY_NAME);
+
+ fsm.resetDeployCountsAction();
+ resetExecutionStats();
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ resetExecutionStats();
+ }
+
+ private static void resetExecutionStats() {
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedCount(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedFailCount(0L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedSuccessCount(0L);
+ }
+
+ private void setExecutionCounts() {
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedCount(7L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedFailCount(2L);
+ PolicyEngineConstants.getManager().getStats().getGroupStat().setPolicyExecutedSuccessCount(5L);
}
@Test
@@ -199,6 +221,7 @@ public class LifecycleFsmTest {
@Test
public void testStatusPayload() {
+ setExecutionCounts();
fsm.updateDeployCountsAction(8L, 6L, 2L);
PdpStatus status = fsm.statusPayload(PdpState.ACTIVE);
@@ -209,6 +232,9 @@ public class LifecycleFsmTest {
assertEquals(2, status.getStatistics().getPolicyDeployFailCount());
assertEquals(8, status.getStatistics().getPolicyDeployCount());
assertNotNull(status.getStatistics().getTimeStamp());
+ assertEquals(7, status.getStatistics().getPolicyExecutedCount());
+ assertEquals(2, status.getStatistics().getPolicyExecutedFailCount());
+ assertEquals(5, status.getStatistics().getPolicyExecutedSuccessCount());
}
protected void deployAllPolicies() {