summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2019-05-13 23:31:44 -0500
committerjhh <jorge.hernandez-herrero@att.com>2019-05-13 23:40:58 -0500
commit9d93b8b4c3577a381e9b5181965d2ceb31e446ed (patch)
tree9f381d2201ed436c4374f1db5aa419ffe5e97f45 /feature-lifecycle
parent6615d0388a27266a0487ed1b334e613e4e80cc6d (diff)
Ensure passive policies are injected when active
Add vim package for testing support Change-Id: Icefcf8a57eea80b4fed97d4c63080f6159d8167a Issue-ID: POLICY-1748 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'feature-lifecycle')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java6
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleState.java9
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateDefault.java8
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStatePassive.java6
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java3
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateUnsupported.java7
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java38
7 files changed, 68 insertions, 9 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 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<ToscaPolicy> resetPoliciesAction() {
- ArrayList<ToscaPolicy> policies = new ArrayList<>(policiesMap.values());
+ List<ToscaPolicy> policies = new ArrayList<>(policiesMap.values());
policiesMap.clear();
return policies;
}
+ protected boolean updatePoliciesAction(List<ToscaPolicy> 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<ToscaPolicy> 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<ToscaPolicy> 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<ToscaPolicy> policies) {
+ @Override
+ public boolean updatePolicies(List<ToscaPolicy> 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<ToscaPolicy> toscaPolicies) {
+ throw new UnsupportedOperationException("updatePolicies: " + this);
+ }
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
index 71147e2a..711db028 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java
@@ -267,7 +267,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
}
@Test
- public void stateChange() throws CoderException {
+ public void stateChange() throws CoderException, IOException {
/* no name */
PdpStateChange change = new PdpStateChange();
change.setPdpGroup("A");
@@ -282,13 +282,45 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertNull(fsm.getGroup());
assertNull(fsm.getSubgroup());
+ PdpUpdate update = new PdpUpdate();
+ update.setName(NetworkUtil.getHostname());
+ update.setPdpGroup("A");
+ update.setPdpSubgroup("a");
+
+ String rawPolicy =
+ new String(Files.readAllBytes(Paths.get("src/test/resources/tosca-policy-operational-restart.json")));
+ ToscaPolicy toscaPolicy = new StandardCoder().decode(rawPolicy, ToscaPolicy.class);
+ update.setPolicies(Arrays.asList(toscaPolicy));
+
+ controllerSupport.getController().start();
+ fsm.start(controllerSupport.getController());
+ assertEquals(1, fsm.policyTypesMap.size());
+ assertTrue(fsm.policiesMap.isEmpty());
+
+ assertTrue(fsm.update(update));
+ assertEquals(1, fsm.policyTypesMap.size());
+ assertEquals(1, fsm.policiesMap.size());
+ assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy);
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
+ assertBasicPassive();
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
+
/* correct name */
change.setName(fsm.getName());
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
- assertNull(fsm.getGroup());
- assertNull(fsm.getSubgroup());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
+
+ await()
+ .atMost(5, TimeUnit.SECONDS)
+ .until(() -> controllerSupport.getController().getDrools().factCount("junits") == 1);
+
+ assertTrue(controllerSupport.getController().getDrools().delete(ToscaPolicy.class));
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
fsm.shutdown();
}