diff options
author | 2021-01-15 16:51:47 -0600 | |
---|---|---|
committer | 2021-01-27 00:39:32 -0600 | |
commit | 77d088a607c33c236bc41c58d9567e10299357a5 (patch) | |
tree | c35c7d92a58f49cc6d069910a4eab20a6bd08993 /feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java | |
parent | 6d94c4ec33520776971c781c6ea6e80e6d0070b5 (diff) |
sync policies when native artifact policies added
interoperability between native and non-native policies
present several difficulties. The code submitted
operates in deltas where deploy and undeploy operations
are performed on the deltas of the updates.
In order to support interoperability, policies not
part of a delta update may need to be reapplied.
For example, in the case when the delta is just
a new native controller artifact, we should go
through the set of already deployed policies and
reapply non-native policies as long as the policy types that
the native artifact policy supports.
Issue-ID: POLICY-2762
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: Ieb8e5e17862e9d607433a1d4e86a026725d73498
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java')
-rw-r--r-- | feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java | 52 |
1 files changed, 37 insertions, 15 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 5478136f..d56e06e9 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 @@ -156,9 +156,7 @@ public class LifecycleFsm implements Startable { String commaSeparatedPolicyTypes = this.properties.getProperty(MANDATORY_POLICY_TYPES); if (!StringUtils.isBlank(commaSeparatedPolicyTypes)) { - for (String mpt: commaSeparatedPolicyTypes.split("\\s*,\\s*")) { - this.mandatoryPolicyTypes.add(mpt); - } + Collections.addAll(this.mandatoryPolicyTypes, commaSeparatedPolicyTypes.split("\\s*,\\s*")); } logger.info("The mandatory Policy Types are {}. Compliance is {}", @@ -347,7 +345,7 @@ public class LifecycleFsm implements Startable { protected List<ToscaPolicy> getDeployablePoliciesAction(@NonNull List<ToscaPolicy> policies) { List<ToscaPolicy> deployPolicies = new ArrayList<>(policies); - deployPolicies.removeAll(policiesMap.values()); + deployPolicies.removeAll(getActivePolicies()); // Ensure that the sequence of policy deployments is sane to minimize potential errors, // First policies to deploy are the controller related ones, those that affect the lifecycle of @@ -359,13 +357,12 @@ public class LifecycleFsm implements Startable { Map<String, List<ToscaPolicy>> policyTypeGroups = groupPoliciesByPolicyType(deployPolicies); // place native controller policies at the start of the list - List<ToscaPolicy> orderedDeployableList = - new ArrayList<>(policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER.getName(), - Collections.EMPTY_LIST)); + List<ToscaPolicy> orderedDeployableList = new ArrayList<>( + policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER.getName(), Collections.emptyList())); // add to the working list the native controller policies orderedDeployableList.addAll( - policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_RULES.getName(), Collections.EMPTY_LIST)); + policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_RULES.getName(), Collections.emptyList())); // place non-native policies to place at the end of the list orderedDeployableList.addAll(getNonNativePolicies(policyTypeGroups)); @@ -374,7 +371,7 @@ public class LifecycleFsm implements Startable { } protected List<ToscaPolicy> getUndeployablePoliciesAction(@NonNull List<ToscaPolicy> policies) { - List<ToscaPolicy> undeployPolicies = new ArrayList<>(policiesMap.values()); + List<ToscaPolicy> undeployPolicies = new ArrayList<>(getActivePolicies()); undeployPolicies.removeAll(policies); if (undeployPolicies.isEmpty()) { return undeployPolicies; @@ -396,11 +393,11 @@ public class LifecycleFsm implements Startable { // add to the working list the native rules policies if any orderedUndeployableList.addAll( - policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_RULES.getName(), Collections.EMPTY_LIST)); + policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_RULES.getName(), Collections.emptyList())); // finally add to the working list native controller policies if any orderedUndeployableList.addAll( - policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER.getName(), Collections.EMPTY_LIST)); + policyTypeGroups.getOrDefault(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER.getName(), Collections.emptyList())); return orderedUndeployableList; } @@ -414,13 +411,13 @@ public class LifecycleFsm implements Startable { } protected List<ToscaPolicy> resetPoliciesAction() { - List<ToscaPolicy> policies = new ArrayList<>(policiesMap.values()); + List<ToscaPolicy> policies = new ArrayList<>(getActivePolicies()); policiesMap.clear(); return policies; } - protected boolean updatePoliciesAction(List<ToscaPolicy> toscaPolicies) { - return (this.scheduler.submit(() -> state.updatePolicies(toscaPolicies)) != null); + protected void updatePoliciesAction(List<ToscaPolicy> toscaPolicies) { + this.scheduler.submit(() -> state.updatePolicies(toscaPolicies)); } protected PolicyTypeController getController(ToscaConceptIdentifier policyType) { @@ -428,7 +425,9 @@ public class LifecycleFsm implements Startable { } protected Map<String, List<ToscaPolicy>> groupPoliciesByPolicyType(List<ToscaPolicy> deployPolicies) { - return deployPolicies.stream().collect(Collectors.groupingBy(policy -> policy.getTypeIdentifier().getName())); + return deployPolicies.stream() + .distinct() + .collect(Collectors.groupingBy(policy -> policy.getTypeIdentifier().getName())); } protected List<ToscaPolicy> getNonNativePolicies(@NonNull Map<String, List<ToscaPolicy>> policyTypeGroups) { @@ -438,6 +437,25 @@ public class LifecycleFsm implements Startable { .flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList()); } + protected List<ToscaPolicy> getNativeArtifactPolicies(@NonNull Map<String, List<ToscaPolicy>> policyTypeGroups) { + return policyTypeGroups.entrySet().stream() + .filter(entry -> entry.getKey().equals(POLICY_TYPE_DROOLS_NATIVE_RULES.getName())) + .flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList()); + } + + protected List<ToscaPolicy> getNativeControllerPolicies(@NonNull Map<String, List<ToscaPolicy>> policyTypeGroups) { + return policyTypeGroups.entrySet().stream() + .filter(entry -> entry.getKey().equals(POLICY_TYPE_DROOLS_NATIVE_CONTROLLER.getName())) + .flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList()); + } + + protected String getPolicyIdsMessage(List<ToscaPolicy> policies) { + return policies.stream() + .distinct() + .map(ToscaPolicy::getIdentifier).collect(Collectors.toList()) + .toString(); + } + /** * Do I support the mandatory policy types?. */ @@ -450,6 +468,10 @@ public class LifecycleFsm implements Startable { .map(ToscaConceptIdentifier::getName).collect(Collectors.toSet()); } + protected List<ToscaPolicy> getActivePolicies() { + return new ArrayList<>(policiesMap.values()); + } + /* ** Action Helpers ** */ private boolean startIo() { |