summaryrefslogtreecommitdiffstats
path: root/services/services-onappf
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-03-19 17:49:07 +0000
committera.sreekumar <ajith.sreekumar@bell.ca>2021-03-19 18:15:06 +0000
commite3f1349915f425c2f0c09688a2cc6d8d246f4110 (patch)
treed966ee71f35eef0cba464778ef646f88f4db8287 /services/services-onappf
parentcc52ec6f85b6aa2712c11b38d66844f8595211b4 (diff)
Fixing issues around deploying APEX policies with duplicate concepts
Deploying invalid APEX policies with duplicate concepts resulting in corrupting all the policies in memory. This is fixed here. This entire functionality handling multiple policies will be revisited as part of https://jira.onap.org/browse/POLICY-3018 Change-Id: I751102d5dddcb92cdcede8222855e2f467bb724d Issue-ID: POLICY-3141 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'services/services-onappf')
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java60
1 files changed, 35 insertions, 25 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 5a113a77d..9fe3c94ce 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
@@ -24,6 +24,7 @@ package org.onap.policy.apex.services.onappf.handler;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
@@ -133,12 +134,12 @@ public class ApexEngineHandler {
List<String> executorParamKeysToRetain = new ArrayList<>();
List<String> schemaParamKeysToRetain = new ArrayList<>();
- List<AxArtifactKey> keyInfoKeystoRetain = new ArrayList<>();
- List<AxArtifactKey> schemaKeystoRetain = new ArrayList<>();
- List<AxArtifactKey> eventKeystoRetain = new ArrayList<>();
- List<AxArtifactKey> albumKeystoRetain = new ArrayList<>();
- List<AxArtifactKey> taskKeystoRetain = new ArrayList<>();
- List<AxArtifactKey> policyKeystoRetain = new ArrayList<>();
+ Map<AxArtifactKey, AxKeyInfo> keyInfoMapToRetain = new HashMap<>();
+ Map<AxArtifactKey, AxContextSchema> schemaMapToRetain = new HashMap<>();
+ Map<AxArtifactKey, AxEvent> eventMapToRetain = new HashMap<>();
+ Map<AxArtifactKey, AxContextAlbum> albumMapToRetain = new HashMap<>();
+ Map<AxArtifactKey, AxTask> taskMapToRetain = new HashMap<>();
+ Map<AxArtifactKey, AxPolicy> policyMapToRetain = new HashMap<>();
apexMainMap.values().forEach(main -> {
inputParamKeysToRetain.addAll(main.getApexParameters().getEventInputParameters().keySet());
@@ -150,21 +151,21 @@ public class ApexEngineHandler {
schemaParamKeysToRetain.addAll(main.getApexParameters().getEngineServiceParameters().getEngineParameters()
.getContextParameters().getSchemaParameters().getSchemaHelperParameterMap().keySet());
- keyInfoKeystoRetain
- .addAll(main.getActivator().getPolicyModel().getKeyInformation().getKeyInfoMap().keySet());
- schemaKeystoRetain.addAll(main.getActivator().getPolicyModel().getSchemas().getSchemasMap().keySet());
- eventKeystoRetain.addAll(main.getActivator().getPolicyModel().getEvents().getEventMap().keySet());
- albumKeystoRetain.addAll(main.getActivator().getPolicyModel().getAlbums().getAlbumsMap().keySet());
- taskKeystoRetain.addAll(main.getActivator().getPolicyModel().getTasks().getTaskMap().keySet());
- policyKeystoRetain.addAll(main.getActivator().getPolicyModel().getPolicies().getPolicyMap().keySet());
+ AxPolicyModel policyModel = main.getActivator().getPolicyModel();
+ keyInfoMapToRetain.putAll(policyModel.getKeyInformation().getKeyInfoMap());
+ schemaMapToRetain.putAll(policyModel.getSchemas().getSchemasMap());
+ eventMapToRetain.putAll(policyModel.getEvents().getEventMap());
+ albumMapToRetain.putAll(policyModel.getAlbums().getAlbumsMap());
+ taskMapToRetain.putAll(policyModel.getTasks().getTaskMap());
+ policyMapToRetain.putAll(policyModel.getPolicies().getPolicyMap());
});
for (ApexMain main : undeployedPoliciesMainMap.values()) {
handleParametersRemoval(inputParamKeysToRetain, outputParamKeysToRetain, taskParametersToRetain,
executorParamKeysToRetain, schemaParamKeysToRetain, main);
if (null != main.getActivator() && null != main.getActivator().getPolicyModel()) {
- handleAxConceptsRemoval(keyInfoKeystoRetain, schemaKeystoRetain, eventKeystoRetain, albumKeystoRetain,
- taskKeystoRetain, policyKeystoRetain, main);
+ handleAxConceptsRemoval(keyInfoMapToRetain, schemaMapToRetain, eventMapToRetain, albumMapToRetain,
+ taskMapToRetain, policyMapToRetain, main);
}
}
}
@@ -195,23 +196,23 @@ public class ApexEngineHandler {
.getSchemaHelperParameterMap()::remove);
}
- private void handleAxConceptsRemoval(List<AxArtifactKey> keyInfoKeystoRetain,
- List<AxArtifactKey> schemaKeystoRetain, List<AxArtifactKey> eventKeystoRetain,
- List<AxArtifactKey> albumKeystoRetain, List<AxArtifactKey> taskKeystoRetain,
- List<AxArtifactKey> policyKeystoRetain, ApexMain main) {
+ private void handleAxConceptsRemoval(Map<AxArtifactKey, AxKeyInfo> keyInfoMapToRetain,
+ Map<AxArtifactKey, AxContextSchema> schemaMapToRetain, Map<AxArtifactKey, AxEvent> eventMapToRetain,
+ Map<AxArtifactKey, AxContextAlbum> albumMapToRetain, Map<AxArtifactKey, AxTask> taskMapToRetain,
+ Map<AxArtifactKey, AxPolicy> policyMapToRetain, ApexMain main) {
final AxPolicyModel policyModel = main.getActivator().getPolicyModel();
final List<AxArtifactKey> keyInfoKeystoRemove = policyModel.getKeyInformation().getKeyInfoMap().keySet()
- .stream().filter(key -> !keyInfoKeystoRetain.contains(key)).collect(Collectors.toList());
+ .stream().filter(key -> !keyInfoMapToRetain.containsKey(key)).collect(Collectors.toList());
final List<AxArtifactKey> schemaKeystoRemove = policyModel.getSchemas().getSchemasMap().keySet().stream()
- .filter(key -> !schemaKeystoRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !schemaMapToRetain.containsKey(key)).collect(Collectors.toList());
final List<AxArtifactKey> eventKeystoRemove = policyModel.getEvents().getEventMap().keySet().stream()
- .filter(key -> !eventKeystoRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !eventMapToRetain.containsKey(key)).collect(Collectors.toList());
final List<AxArtifactKey> albumKeystoRemove = policyModel.getAlbums().getAlbumsMap().keySet().stream()
- .filter(key -> !albumKeystoRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !albumMapToRetain.containsKey(key)).collect(Collectors.toList());
final List<AxArtifactKey> taskKeystoRemove = policyModel.getTasks().getTaskMap().keySet().stream()
- .filter(key -> !taskKeystoRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !taskMapToRetain.containsKey(key)).collect(Collectors.toList());
final List<AxArtifactKey> policyKeystoRemove = policyModel.getPolicies().getPolicyMap().keySet().stream()
- .filter(key -> !policyKeystoRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !policyMapToRetain.containsKey(key)).collect(Collectors.toList());
final Map<AxArtifactKey, AxKeyInfo> keyInfoMap = ModelService.getModel(AxKeyInformation.class).getKeyInfoMap();
final Map<AxArtifactKey, AxContextSchema> schemasMap =
@@ -222,6 +223,15 @@ public class ApexEngineHandler {
final Map<AxArtifactKey, AxTask> taskMap = ModelService.getModel(AxTasks.class).getTaskMap();
final Map<AxArtifactKey, AxPolicy> policyMap = ModelService.getModel(AxPolicies.class).getPolicyMap();
+ // replace the ModelService with the right concept definition
+ // this can get corrupted in case of deploying policies with duplicate concept keys
+ keyInfoMap.putAll(keyInfoMapToRetain);
+ schemasMap.putAll(schemaMapToRetain);
+ eventMap.putAll(eventMapToRetain);
+ albumsMap.putAll(albumMapToRetain);
+ taskMap.putAll(taskMapToRetain);
+ policyMap.putAll(policyMapToRetain);
+
keyInfoKeystoRemove.forEach(keyInfoMap::remove);
schemaKeystoRemove.forEach(schemasMap::remove);
eventKeystoRemove.forEach(eventMap::remove);