From 208be1c545895cf61bc38fbc7bc5e9e45d085016 Mon Sep 17 00:00:00 2001 From: jhh Date: Thu, 28 Jan 2021 18:21:21 -0600 Subject: small perf improvement passing policy map argument Issue-ID: POLICY-2762 Signed-off-by: jhh Change-Id: I85aeba2e710f6637a6e6bdfd62e1bc8b70f4d19f Signed-off-by: jhh --- .../drools/lifecycle/LifecycleStateRunning.java | 33 +++++++++++++--------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'feature-lifecycle') diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java index 77850824..a4a5d66d 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java @@ -138,6 +138,8 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // policies as given by the PAP in the update message List activePoliciesPreUpdate = fsm.getActivePolicies(); + Map> activePoliciesPreUpdateMap = + fsm.groupPoliciesByPolicyType(activePoliciesPreUpdate); // update policies with the current set of active policies @@ -155,7 +157,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // were neither deployed or undeployed and re-apply them on top // of the controllers. - failedPolicies.addAll(reapplyNativeArtifactPolicies(activePoliciesPreUpdate)); + failedPolicies.addAll(reApplyNativeArtifactPolicies(activePoliciesPreUpdate, activePoliciesPreUpdateMap)); // If there are *new* native artifact policies deployed, there may be existing // non-native policies (previous to the update event processing) @@ -164,7 +166,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // which neither were undeployed or deployed and re-apply them on top of the // new "brained" controllers. - failedPolicies.addAll(reapplyNonNativePolicies(activePoliciesPreUpdate)); + failedPolicies.addAll(reApplyNonNativePolicies(activePoliciesPreUpdateMap)); return fsm.statusAction(response(update.getRequestId(), (failedPolicies.isEmpty()) ? PdpResponseStatus.SUCCESS : PdpResponseStatus.FAIL, @@ -193,7 +195,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { List failedUndeployPolicies = undeployPolicies(policies); if (!failedUndeployPolicies.isEmpty()) { logger.warn("update-policies: undeployment failures: {}", fsm.getPolicyIdsMessage(failedUndeployPolicies)); - failedUndeployPolicies.stream().forEach(fsm::undeployedPolicyAction); + failedUndeployPolicies.forEach(fsm::undeployedPolicyAction); } List failedDeployPolicies = deployPolicies(policies); @@ -204,14 +206,13 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { return Pair.of(failedUndeployPolicies, failedDeployPolicies); } - protected List reapplyNonNativePolicies(List preActivePolicies) { + protected List reApplyNonNativePolicies(Map> preActivePoliciesMap) { // only need to re-apply non native policies if there are new native artifact policies Map> activePoliciesByType = fsm.groupPoliciesByPolicyType(fsm.getActivePolicies()); List activeNativeArtifactPolicies = fsm.getNativeArtifactPolicies(activePoliciesByType); - Map> prePoliciesByType = fsm.groupPoliciesByPolicyType(preActivePolicies); - activeNativeArtifactPolicies.removeAll(fsm.getNativeArtifactPolicies(prePoliciesByType)); + activeNativeArtifactPolicies.removeAll(fsm.getNativeArtifactPolicies(preActivePoliciesMap)); if (activeNativeArtifactPolicies.isEmpty()) { logger.info("reapply-non-native-policies: nothing to reapply, no new native artifact policies"); return Collections.emptyList(); @@ -223,7 +224,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // the original active set, and the new active set (i.e policies that have not changed, // or in other words, have not been neither deployed or undeployed. - List preNonNativePolicies = fsm.getNonNativePolicies(prePoliciesByType); + List preNonNativePolicies = fsm.getNonNativePolicies(preActivePoliciesMap); preNonNativePolicies.retainAll(fsm.getNonNativePolicies(activePoliciesByType)); logger.info("re-applying non-native policies {} because new native artifact policies have been found: {}", @@ -235,14 +236,14 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { return failedPolicies; } - protected List reapplyNativeArtifactPolicies(List preActivePolicies) { + protected List reApplyNativeArtifactPolicies(List preActivePolicies, + Map> preActivePoliciesMap) { // only need to re-apply native artifact policies if there are new native controller policies Map> activePoliciesByType = fsm.groupPoliciesByPolicyType(fsm.getActivePolicies()); List activeNativeControllerPolicies = fsm.getNativeControllerPolicies(activePoliciesByType); - Map> prePoliciesByType = fsm.groupPoliciesByPolicyType(preActivePolicies); - activeNativeControllerPolicies.removeAll(fsm.getNativeControllerPolicies(prePoliciesByType)); + activeNativeControllerPolicies.removeAll(fsm.getNativeControllerPolicies(preActivePoliciesMap)); if (activeNativeControllerPolicies.isEmpty()) { logger.info("reapply-native-artifact-policies: nothing to reapply, no new native controller policies"); return Collections.emptyList(); @@ -252,9 +253,9 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // get the native artifact policies to be reapplied, this is just the intersection of // the original active set, and the new active set (i.e policies that have not changed, - // or in other words, have not been neither deployed or undeployed. + // or in other words, have not been neither deployed or undeployed). - List preNativeArtifactPolicies = fsm.getNativeArtifactPolicies(prePoliciesByType); + List preNativeArtifactPolicies = fsm.getNativeArtifactPolicies(preActivePoliciesMap); preNativeArtifactPolicies.retainAll(fsm.getNativeArtifactPolicies(activePoliciesByType)); logger.info("reapply candidate native artifact policies {} as new native controller policies {} were found", @@ -294,8 +295,12 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { // since we want non-native policies to be reapplied when a new native artifact policy has been // reapplied here, remove it from the preActivePolicies, so it is detected as new. - preActivePolicies.removeAll(preNativeArtifactPoliciesToApply); - + if (!preNativeArtifactPoliciesToApply.isEmpty()) { + preActivePolicies.removeAll(preNativeArtifactPoliciesToApply); + preActivePoliciesMap + .getOrDefault(LifecycleFsm.POLICY_TYPE_DROOLS_NATIVE_RULES.getName(), Collections.emptyList()) + .removeAll(preNativeArtifactPoliciesToApply); + } return failedPolicies; } -- cgit 1.2.3-korg