aboutsummaryrefslogtreecommitdiffstats
path: root/services/services-onappf/src
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-onappf/src')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java4
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java80
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java4
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java4
4 files changed, 59 insertions, 33 deletions
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index f3b883141..7aa663c58 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -96,7 +96,7 @@ public class ApexEngineHandler {
*/
public void updateApexEngine(List<ToscaPolicy> polsToDeploy, List<ToscaConceptIdentifier> polsToUndeploy)
throws ApexStarterException {
- List<ToscaConceptIdentifier> runningPolicies = getRunningPolicies();
+ Set<ToscaConceptIdentifier> runningPolicies = new HashSet<>(getRunningPolicies());
List<ToscaPolicy> policiesToDeploy = polsToDeploy;
policiesToDeploy.removeIf(p -> runningPolicies.contains(p.getIdentifier()));
List<ToscaConceptIdentifier> policiesToUnDeploy = polsToUndeploy;
@@ -112,7 +112,7 @@ public class ApexEngineHandler {
LOGGER.error("Shutting down policy {} failed", policyId, e);
}
});
- if (!undeployedPoliciesMainMap.isEmpty()) {
+ if (!undeployedPoliciesMainMap.isEmpty() && !apexMainMap.isEmpty()) {
updateModelAndParameterServices(undeployedPoliciesMainMap);
}
if (!policiesToDeploy.isEmpty()) {
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
index 0e7465d19..479ec9a72 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
@@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
import org.onap.policy.apex.service.engine.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.ApexStarterConstants;
@@ -99,8 +100,10 @@ public class PdpUpdateMessageHandler {
List<ToscaPolicy> policies = Registry.getOrDefault(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST,
List.class, new ArrayList<>());
policies.addAll(pdpUpdateMsg.getPoliciesToBeDeployed());
- pdpStatusContext.setPolicies(policies.stream().map(ToscaPolicy::getIdentifier)
- .collect(Collectors.toList()));
+ Set<ToscaConceptIdentifier> policiesInDeployment = policies.stream().map(ToscaPolicy::getIdentifier)
+ .collect(Collectors.toSet());
+ policiesInDeployment.removeAll(pdpUpdateMsg.getPoliciesToBeUndeployed());
+ pdpStatusContext.setPolicies(new ArrayList<>(policiesInDeployment));
Registry.registerOrReplace(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST,
policies);
if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
@@ -177,28 +180,14 @@ public class PdpUpdateMessageHandler {
try {
if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
apexEngineHandler.updateApexEngine(pdpUpdateMsg.getPoliciesToBeDeployed(),
- pdpUpdateMsg.getPoliciesToBeUndeployed());
+ pdpUpdateMsg.getPoliciesToBeUndeployed());
} else {
apexEngineHandler = new ApexEngineHandler(pdpUpdateMsg.getPoliciesToBeDeployed());
Registry.registerOrReplace(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, apexEngineHandler);
}
if (apexEngineHandler.isApexEngineRunning()) {
- List<ToscaConceptIdentifier> runningPolicies = apexEngineHandler.getRunningPolicies();
- if (new HashSet<>(runningPolicies).containsAll(new HashSet<>(pdpMessageHandler
- .getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed())))
- && !containsAny(runningPolicies, pdpUpdateMsg.getPoliciesToBeUndeployed())) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.SUCCESS, "Apex engine started and policies are running.");
- } else {
- StringBuilder message =
- new StringBuilder("Apex engine started. But, only the following polices are running - ");
- for (ToscaConceptIdentifier policy : runningPolicies) {
- message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
- }
- message.append(". Other policies failed execution. Please see the logs for more details.");
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
- PdpResponseStatus.SUCCESS, message.toString());
- }
+ pdpResponseDetails =
+ populateResponseForEngineInitiation(pdpUpdateMsg, pdpMessageHandler, apexEngineHandler);
} else {
pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine failed to start.");
@@ -217,6 +206,43 @@ public class PdpUpdateMessageHandler {
return pdpResponseDetails;
}
+ private PdpResponseDetails populateResponseForEngineInitiation(final PdpUpdate pdpUpdateMsg,
+ final PdpMessageHandler pdpMessageHandler, ApexEngineHandler apexEngineHandler) {
+ PdpResponseDetails pdpResponseDetails;
+ Set<ToscaConceptIdentifier> runningPolicies = new HashSet<>(apexEngineHandler.getRunningPolicies());
+ List<ToscaConceptIdentifier> policiesToBeDeployed =
+ pdpMessageHandler.getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed());
+ List<ToscaConceptIdentifier> policiesToBeUndeployed = pdpUpdateMsg.getPoliciesToBeUndeployed();
+ if (runningPolicies.containsAll(policiesToBeDeployed)
+ && !containsAny(runningPolicies, policiesToBeUndeployed)) {
+ StringBuilder message = new StringBuilder("Apex engine started. ");
+ if (!policiesToBeDeployed.isEmpty()) {
+ message.append("Deployed policies are: ");
+ for (ToscaConceptIdentifier policy : policiesToBeDeployed) {
+ message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
+ }
+ }
+ if (!policiesToBeUndeployed.isEmpty()) {
+ message.append("Undeployed policies are: ");
+ for (ToscaConceptIdentifier policy : policiesToBeUndeployed) {
+ message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
+ }
+ }
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.SUCCESS, message.toString());
+ } else {
+ StringBuilder message =
+ new StringBuilder("Apex engine started. But, only the following polices are running - ");
+ for (ToscaConceptIdentifier policy : runningPolicies) {
+ message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
+ }
+ message.append(". Other policies failed execution. Please see the logs for more details.");
+ pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ PdpResponseStatus.SUCCESS, message.toString());
+ }
+ return pdpResponseDetails;
+ }
+
/**
* Method checks if the Pdp update message is already handled by checking the values in the context.
*
@@ -226,13 +252,13 @@ public class PdpUpdateMessageHandler {
*/
private boolean checkIfAlreadyHandled(final PdpUpdate pdpUpdateMsg, final PdpStatus pdpStatusContext) {
return null != pdpStatusContext.getPdpGroup()
- && pdpStatusContext.getPdpGroup().equals(pdpUpdateMsg.getPdpGroup())
- && null != pdpStatusContext.getPdpSubgroup()
- && pdpStatusContext.getPdpSubgroup().equals(pdpUpdateMsg.getPdpSubgroup())
- && null != pdpStatusContext.getPolicies()
- && pdpStatusContext.getPolicies().containsAll(new PdpMessageHandler().getToscaPolicyIdentifiers(
- pdpUpdateMsg.getPoliciesToBeDeployed()))
- && !containsAny(pdpStatusContext.getPolicies(), pdpUpdateMsg.getPoliciesToBeUndeployed());
+ && pdpStatusContext.getPdpGroup().equals(pdpUpdateMsg.getPdpGroup())
+ && null != pdpStatusContext.getPdpSubgroup()
+ && pdpStatusContext.getPdpSubgroup().equals(pdpUpdateMsg.getPdpSubgroup())
+ && null != pdpStatusContext.getPolicies()
+ && pdpStatusContext.getPolicies()
+ .containsAll(new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()))
+ && !containsAny(new HashSet<>(pdpStatusContext.getPolicies()), pdpUpdateMsg.getPoliciesToBeUndeployed());
}
/**
@@ -255,7 +281,7 @@ public class PdpUpdateMessageHandler {
* @param listToCheckAgainst list to check against other list for similarities
* @return boolean flag which tells if lists share same elements or not
*/
- private boolean containsAny(List<ToscaConceptIdentifier> listToCheckWith,
+ private boolean containsAny(Set<ToscaConceptIdentifier> listToCheckWith,
List<ToscaConceptIdentifier> listToCheckAgainst) {
return listToCheckAgainst.stream().anyMatch(listToCheckWith::contains);
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
index 10f82633f..dda98db94 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 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.
@@ -169,7 +169,7 @@ public class TestPdpStateChangeListener {
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
new ArrayList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
- assertThat(outContent.toString()).contains("Apex engine started and policies are running.");
+ assertThat(outContent.toString()).contains("Apex engine started. Deployed policies are: apex_policy_name:1.0");
assertEquals(PdpState.ACTIVE, pdpStatus.getState());
final ApexPolicyStatisticsManager policyCounterManager = ApexPolicyStatisticsManager.getInstanceFromRegistry();
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
index ec3da9bc3..9d314b41a 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2020-2021 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.
@@ -161,7 +161,7 @@ public class TestPdpUpdateListener {
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
- assertThat(outString).contains("Apex engine started and policies are running.");
+ assertThat(outString).contains("Apex engine started. Deployed policies are: apex_policy_name:1.0");
}
@Test