aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java33
1 files changed, 28 insertions, 5 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
index e6fd9e477..af3e93b6a 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Bell Canada. 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.
@@ -21,8 +22,10 @@
package org.onap.policy.apex.services.onappf.handler;
+import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
+import java.util.stream.Collectors;
import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.ApexStarterConstants;
import org.onap.policy.apex.services.onappf.comm.PdpStatusPublisher;
@@ -35,6 +38,7 @@ import org.onap.policy.models.pdp.enums.PdpResponseStatus;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithTypeAndObjectProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -139,6 +143,7 @@ public class PdpStateChangeMessageHandler {
pdpStateChangeMsg.getRequestId(), PdpResponseStatus.SUCCESS, message.toString());
}
pdpStatusContext.setState(PdpState.ACTIVE);
+ updateDeploymentCounts(runningPolicies, policies);
} else {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine failed to start. State cannot be changed to active.");
@@ -148,11 +153,6 @@ public class PdpStateChangeMessageHandler {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
- final var apexPolicyStatisticsManager = ApexPolicyStatisticsManager.getInstanceFromRegistry();
- if (apexPolicyStatisticsManager != null) {
- apexPolicyStatisticsManager
- .updatePolicyDeployCounter(pdpResponseDetails.getResponseStatus() == PdpResponseStatus.SUCCESS);
- }
return pdpResponseDetails;
}
@@ -193,4 +193,27 @@ public class PdpStateChangeMessageHandler {
}
return pdpResponseDetails;
}
+
+ /**
+ * Update count values for deployment on engine startup.
+ * @param runningPolicies the policies running in apex engine
+ * @param policies the list of policies to deploy as per PDP_STATE_CHANGE message from pap
+ */
+ private void updateDeploymentCounts(final List<ToscaConceptIdentifier> runningPolicies,
+ final List<ToscaPolicy> policies) {
+ final var statisticsManager = ApexPolicyStatisticsManager.getInstanceFromRegistry();
+ if (statisticsManager == null || policies == null || policies.isEmpty()) {
+ return;
+ }
+ var policiesToDeploy = policies.stream()
+ .map(ToscaWithTypeAndObjectProperties::getIdentifier).collect(Collectors.toList());
+
+ var policiesSuccessfullyDeployed = new ArrayList<>(policiesToDeploy);
+ policiesSuccessfullyDeployed.retainAll(runningPolicies);
+ policiesSuccessfullyDeployed.forEach(policy -> statisticsManager.updatePolicyDeployCounter(true));
+
+ var policiesFailedToDeploy = new ArrayList<>(policiesToDeploy);
+ policiesFailedToDeploy.removeIf(runningPolicies::contains);
+ policiesFailedToDeploy.forEach(policy -> statisticsManager.updatePolicyDeployCounter(false));
+ }
}