summaryrefslogtreecommitdiffstats
path: root/model/policy-model/src
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2020-07-23 10:36:32 +0100
committera.sreekumar <ajith.sreekumar@bell.ca>2020-07-24 17:13:47 +0100
commitf68190af4f0251934734841352a77758ba53653e (patch)
tree27dcbdf0399740f307fee1fc0937afb18b52dd41 /model/policy-model/src
parent2169b3fbf66153ea7e066ba0057585822208d6f4 (diff)
APEX changes to support policy disable/enable and some improvements
1) Do not stop all the marshallers/unmarshallers while updating the engine. Stop and remove only those that are part of the policies that are undeployed. 2) Do not reinitilaize any marshaller/unmarshaller that is already initilaized as part of the policies which were already deployed. Initialize only the ones as part of any newly deployed policy. 3) EngineParameters could be different in different policies. Aggregate these parameters and make it available in the engine for any running policy. 4) Enable support for running policies with same model and different configurations. Change-Id: If74807a0515a741ef4e53bd0a93e43b05872f6b5 Issue-ID: POLICY-2536 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'model/policy-model/src')
-rw-r--r--model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java16
-rw-r--r--model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java12
2 files changed, 13 insertions, 15 deletions
diff --git a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
index 37c3b2368..90d5b7fd2 100644
--- a/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
+++ b/model/policy-model/src/main/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMerger.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -115,9 +116,9 @@ public final class PolicyModelMerger {
if (failOnDuplicateKeys) {
StringBuilder errorMessage = new StringBuilder();
- checkForDuplicateContextItem(mergedSchemasMap, copyOverSchemasMap, errorMessage, "schema");
+ checkForDuplicateItem(mergedSchemasMap, copyOverSchemasMap, errorMessage, "schema");
checkForDuplicateItem(mergedEventMap, copyOverEventMap, errorMessage, "event");
- checkForDuplicateContextItem(mergedAlbumsMap, copyOverAlbumsMap, errorMessage, "album");
+ checkForDuplicateItem(mergedAlbumsMap, copyOverAlbumsMap, errorMessage, "album");
checkForDuplicateItem(mergedTaskMap, copyOverTaskMap, errorMessage, "task");
checkForDuplicateItem(mergedPolicyMap, copyOverPolicyMap, errorMessage, "policy");
if (errorMessage.length() > 0) {
@@ -146,18 +147,9 @@ public final class PolicyModelMerger {
private static <V> void checkForDuplicateItem(Map<AxArtifactKey, V> mergedItemsMap,
Map<AxArtifactKey, V> copyOverItemsMap, StringBuilder errorMessage, String itemType) {
- for (AxArtifactKey key : copyOverItemsMap.keySet()) {
- if (mergedItemsMap.containsKey(key)) {
- errorMessage.append("\n Duplicate " + itemType + " found - ").append(key.getId());
- }
- }
- }
-
- private static <V> void checkForDuplicateContextItem(Map<AxArtifactKey, V> mergedItemsMap,
- Map<AxArtifactKey, V> copyOverItemsMap, StringBuilder errorMessage, String itemType) {
for (Entry<AxArtifactKey, V> entry : copyOverItemsMap.entrySet()) {
V item = mergedItemsMap.get(entry.getKey());
- // same context schema name with different definitions cannot occur in multiple policies
+ // same item with different definitions cannot occur in multiple policies
if (null != item) {
if (item.equals(entry.getValue())) {
LOGGER.info("Same {} - {} is used by multiple policies.", itemType, entry.getKey().getId());
diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java
index 560ddc6a9..2bdf7499f 100644
--- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java
+++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/PolicyModelMergerTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2020 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.
@@ -29,6 +30,7 @@ import org.junit.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
/**
* Test model merging.
@@ -79,8 +81,12 @@ public class PolicyModelMergerTest {
assertNotNull(mergedPolicyModel);
final AxPolicyModel rightPolicyModel3 = new SupportApexPolicyModelCreator().getModel();
- assertThatThrownBy(
- () -> PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel3, true, true))
- .hasMessageContaining("Duplicate policy found");
+ AxArtifactKey taskArtifactKey = new AxArtifactKey("task", "0.0.1");
+ // fail when concepts in two policies have same name but different definition
+ // here make up some change so as to update the definition of the task in second policy
+ rightPolicyModel3.getTasks().getTaskMap().get(taskArtifactKey)
+ .setTaskLogic(new AxTaskLogic(taskArtifactKey, "logicName", "logicFlavour", "logicImpl"));
+ assertThatThrownBy(() -> PolicyModelMerger.getMergedPolicyModel(leftPolicyModel, rightPolicyModel3, true, true))
+ .hasMessage("\n Same task - task:0.0.1 with different definitions used in different policies");
}
}