From 9d93b8b4c3577a381e9b5181965d2ceb31e446ed Mon Sep 17 00:00:00 2001 From: jhh Date: Mon, 13 May 2019 23:31:44 -0500 Subject: Ensure passive policies are injected when active Add vim package for testing support Change-Id: Icefcf8a57eea80b4fed97d4c63080f6159d8167a Issue-ID: POLICY-1748 Signed-off-by: jhh --- .../main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java | 6 +++++- .../java/org/onap/policy/drools/lifecycle/LifecycleState.java | 9 ++++++++- .../org/onap/policy/drools/lifecycle/LifecycleStateDefault.java | 8 ++++++++ .../org/onap/policy/drools/lifecycle/LifecycleStatePassive.java | 6 +++--- .../org/onap/policy/drools/lifecycle/LifecycleStateRunning.java | 3 ++- .../onap/policy/drools/lifecycle/LifecycleStateUnsupported.java | 7 +++++++ 6 files changed, 33 insertions(+), 6 deletions(-) (limited to 'feature-lifecycle/src/main/java/org') 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 7431097a..0e853e80 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 @@ -288,11 +288,15 @@ public class LifecycleFsm implements Startable { } protected List resetPoliciesAction() { - ArrayList policies = new ArrayList<>(policiesMap.values()); + List policies = new ArrayList<>(policiesMap.values()); policiesMap.clear(); return policies; } + protected boolean updatePoliciesAction(List toscaPolicies) { + return (this.scheduler.submit( () -> state.updatePolicies(toscaPolicies)) != null); + } + /* ** Action Helpers ** */ private boolean startIo() { diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleState.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleState.java index 2976732e..726e1d46 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleState.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleState.java @@ -20,12 +20,14 @@ package org.onap.policy.drools.lifecycle; +import java.util.List; import lombok.NonNull; import org.onap.policy.common.capabilities.Startable; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; import org.onap.policy.models.pdp.enums.PdpState; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,7 +69,12 @@ public abstract class LifecycleState implements Startable { public abstract boolean update(@NonNull PdpUpdate update); /** - * state change event . + * state change event. */ public abstract boolean stateChange(@NonNull PdpStateChange change); + + /** + * update policies with the current list. + */ + public abstract boolean updatePolicies(List toscaPolicies); } \ No newline at end of file diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateDefault.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateDefault.java index 330d02f4..db5d610a 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateDefault.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateDefault.java @@ -20,9 +20,11 @@ package org.onap.policy.drools.lifecycle; +import java.util.List; import lombok.NonNull; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -90,4 +92,10 @@ public abstract class LifecycleStateDefault extends LifecycleStateUnsupported { public boolean isAlive() { return false; } + + @Override + public boolean updatePolicies(List toscaPolicies) { + logger.warn("{}: updatePolicies", this); + return false; + } } diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStatePassive.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStatePassive.java index 98829eeb..b88a200c 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStatePassive.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStatePassive.java @@ -49,8 +49,8 @@ public class LifecycleStatePassive extends LifecycleStateRunning { @Override protected boolean stateChangeToActive(@NonNull PdpStateChange change) { fsm.transitionToAction(new LifecycleStateActive(fsm)); - super.updatePolicies(fsm.resetPoliciesAction()); - return fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS,null)); + fsm.statusAction(response(change.getRequestId(), PdpResponseStatus.SUCCESS,null)); + return fsm.updatePoliciesAction(fsm.resetPoliciesAction()); } @Override @@ -60,7 +60,7 @@ public class LifecycleStatePassive extends LifecycleStateRunning { @Override protected boolean deployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) { - logger.info("{}: deploy {} from {}", this, policy.getIdentifier(), controller.getName()); + logger.info("{}: deploy {} to {}", this, policy.getIdentifier(), controller.getName()); fsm.deployedPolicyAction(policy); return true; } 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 fcff4904..f50eab51 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 @@ -127,7 +127,8 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault { } } - protected boolean updatePolicies(List policies) { + @Override + public boolean updatePolicies(List policies) { if (policies == null) { return true; } diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupported.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupported.java index 11ce7f34..f37cf68d 100644 --- a/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupported.java +++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupported.java @@ -20,8 +20,10 @@ package org.onap.policy.drools.lifecycle; +import java.util.List; import org.onap.policy.models.pdp.concepts.PdpStateChange; import org.onap.policy.models.pdp.concepts.PdpUpdate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; /** * Support class for those unsupported states not yet implemented. @@ -75,4 +77,9 @@ public abstract class LifecycleStateUnsupported extends LifecycleState { public boolean stateChange(PdpStateChange change) { throw new UnsupportedOperationException("stateChange: " + this); } + + @Override + public boolean updatePolicies(List toscaPolicies) { + throw new UnsupportedOperationException("updatePolicies: " + this); + } } -- cgit 1.2.3-korg