summaryrefslogtreecommitdiffstats
path: root/feature-lifecycle
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2019-05-07 20:51:34 -0500
committerjhh <jorge.hernandez-herrero@att.com>2019-05-08 21:59:33 -0500
commitc3351f687be075d91908d04dfc4e7e9da243f395 (patch)
tree8845bb8f411bc212a466b1b98efd02f65290af97 /feature-lifecycle
parent6da702fafb473a08efd112cdc38cef1cfdef2f7a (diff)
Track policies when active.
Do not honor group/subgroup changes with status messages. When no present group/subgroups in update messages, assume that they have to be reset. Keep the policy cache of non-installed policies tracking them when in passive state besides active. Wait until go active to enable them. Remove legacy PAP and PDP-X healtchecks as it was basically testing reachability. There are conflicts with maintaining 2 different sets of PAPs and PDPs, trying to avoid it. Alternative healtchecks are being placed on the robot test framework. What to healtcheck should be considered more carefully in the near future. Change-Id: I574f30bb5899faf521123c79046793d16b4a46e0 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.java8
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStatePassive.java3
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java12
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java5
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java7
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java55
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java4
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java2
8 files changed, 75 insertions, 21 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 ada29ede..7431097a 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
@@ -67,7 +67,7 @@ public class LifecycleFsm implements Startable {
protected static final String CONFIGURATION_PROPERTIES_NAME = "feature-lifecycle";
protected static final String POLICY_TYPE_VERSION = "1.0.0";
- protected static final long DEFAULT_STATUS_TIMER_SECONDS = 60L;
+ protected static final long DEFAULT_STATUS_TIMER_SECONDS = 120L;
protected static final long MIN_STATUS_INTERVAL_SECONDS = 5L;
protected static final String PDP_MESSAGE_NAME = "messageName";
@@ -287,6 +287,12 @@ public class LifecycleFsm implements Startable {
policiesMap.remove(policy.getIdentifier());
}
+ protected List<ToscaPolicy> resetPoliciesAction() {
+ ArrayList<ToscaPolicy> policies = new ArrayList<>(policiesMap.values());
+ policiesMap.clear();
+ return policies;
+ }
+
/* ** Action Helpers ** */
private boolean startIo() {
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 e9f4b9bf..98829eeb 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,6 +49,7 @@ 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));
}
@@ -60,12 +61,14 @@ public class LifecycleStatePassive extends LifecycleStateRunning {
@Override
protected boolean deployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) {
logger.info("{}: deploy {} from {}", this, policy.getIdentifier(), controller.getName());
+ fsm.deployedPolicyAction(policy);
return true;
}
@Override
protected boolean undeployPolicy(@NonNull PolicyController controller, @NonNull ToscaPolicy policy) {
logger.info("{}: undeploy {} from {}", this, policy.getIdentifier(), controller.getName());
+ fsm.undeployedPolicyAction(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 ed200ea6..fcff4904 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
@@ -92,12 +92,10 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
public boolean stateChange(@NonNull PdpStateChange change) {
synchronized (fsm) {
if (change.getState() == PdpState.PASSIVE) {
- group(change.getPdpGroup(), change.getPdpSubgroup());
return stateChangeToPassive(change);
}
if (change.getState() == PdpState.ACTIVE) {
- group(change.getPdpGroup(), change.getPdpSubgroup());
return stateChangeToActive(change);
}
@@ -118,7 +116,7 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
return false;
}
- group(update.getPdpGroup(), update.getPdpSubgroup());
+ fsm.setGroupAction(update.getPdpGroup(), update.getPdpSubgroup());
if (!updatePolicies(update.getPolicies())) {
fsm.statusAction(response(update.getRequestId(), PdpResponseStatus.FAIL, "cannot process policies"));
@@ -187,12 +185,4 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
return response;
}
-
- protected void group(String group, String subgroup) {
- if (group == null || subgroup == null) {
- return;
- }
-
- fsm.setGroupAction(group, subgroup);
- }
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
index c22a0d88..3a3434ac 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/ControllerSupport.java
@@ -30,6 +30,7 @@ import org.kie.api.builder.ReleaseId;
import org.onap.policy.drools.properties.DroolsProperties;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.drools.util.KieUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
/**
* Controller Test Support.
@@ -59,7 +60,9 @@ public class ControllerSupport {
*/
public PolicyController createController() throws IOException {
try {
- getController();
+ PolicyController controller = getController();
+ controller.getDrools().delete(ToscaPolicy.class);
+ return controller;
} catch (IllegalArgumentException e) {
;
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
index d28ab14c..550379be 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java
@@ -74,6 +74,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
change.setState(PdpState.ACTIVE);
change.setName(fsm.getName());
+ fsm.setGroupAction("A", "a");
fsm.source.offer(new StandardCoder().encode(change));
controllerSupport.getController().start();
}
@@ -169,8 +170,8 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
change.setName(fsm.getName());
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
- assertEquals("B", fsm.getGroup());
- assertEquals("b", fsm.getSubgroup());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
change.setState(PdpState.SAFE);
fsm.source.offer(new StandardCoder().encode(change));
@@ -319,6 +320,8 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertTrue(controllerSupport.getController().getDrools().delete(ToscaPolicy.class));
+
fsm.shutdown();
}
}
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 181b11cf..71147e2a 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
@@ -167,6 +167,9 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
@Test
public void update() throws IOException, CoderException {
+ controllerSupport.getController().getDrools().delete(ToscaPolicy.class);
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
+
PdpUpdate update = new PdpUpdate();
update.setName(NetworkUtil.getHostname());
update.setPdpGroup("Z");
@@ -206,13 +209,59 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertTrue(fsm.policyTypesMap.isEmpty());
assertTrue(fsm.policiesMap.isEmpty());
+ update.setPdpGroup(null);
+ update.setPdpSubgroup(null);
+
+ assertFalse(fsm.update(update));
+
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
+ assertBasicPassive();
+ assertTrue(fsm.policyTypesMap.isEmpty());
+ assertTrue(fsm.policiesMap.isEmpty());
+
+ update.setPdpGroup("A");
+ update.setPdpSubgroup("a");
+
+ assertFalse(fsm.update(update));
+
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
+ assertBasicPassive();
+ assertTrue(fsm.policyTypesMap.isEmpty());
+ assertTrue(fsm.policiesMap.isEmpty());
+
fsm.start(controllerSupport.getController());
assertEquals(1, fsm.policyTypesMap.size());
assertTrue(fsm.policiesMap.isEmpty());
assertTrue(fsm.update(update));
assertEquals(1, fsm.policyTypesMap.size());
- assertTrue(fsm.policiesMap.isEmpty());
+ assertEquals(1, fsm.policiesMap.size());
+ assertEquals(fsm.policiesMap.get(toscaPolicy.getIdentifier()), toscaPolicy);
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertEquals("A", fsm.getGroup());
+ assertEquals("a", fsm.getSubgroup());
+ assertBasicPassive();
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
+
+ update.setPdpGroup(null);
+ update.setPdpSubgroup(null);
+ update.setPolicies(Collections.emptyList());
+ assertTrue(fsm.update(update));
+ assertEquals(1, fsm.policyTypesMap.size());
+ assertEquals(0, fsm.policiesMap.size());
+ assertEquals(PdpState.PASSIVE, fsm.state());
+ assertEquals(interval, fsm.getStatusTimerSeconds());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
+ assertBasicPassive();
+ assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
fsm.shutdown();
}
@@ -238,8 +287,8 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
- assertEquals("A", fsm.getGroup());
- assertEquals("a", fsm.getSubgroup());
+ assertNull(fsm.getGroup());
+ assertNull(fsm.getSubgroup());
fsm.shutdown();
}
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
index 587098f8..50c4f1a7 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateTerminatedTest.java
@@ -142,12 +142,12 @@ public class LifecycleStateTerminatedTest {
update.setPdpGroup("A");
update.setPdpSubgroup("a");
update.setPolicies(Collections.emptyList());
- update.setPdpHeartbeatIntervalMs(2 * 600000L);
+ update.setPdpHeartbeatIntervalMs(4 * 600000L);
assertFalse(fsm.update(update));
assertEquals(PdpState.TERMINATED, fsm.state.state());
- assertNotEquals((2 * 60000L) / 1000L, fsm.getStatusTimerSeconds());
+ assertNotEquals((4 * 60000L) / 1000L, fsm.getStatusTimerSeconds());
}
@Test
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
index a11bc020..3cf5c596 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/server/restful/RestLifecycleManagerTest.java
@@ -87,4 +87,4 @@ public class RestLifecycleManagerTest {
assertEquals(PdpState.TERMINATED, HttpClient.getBody(response, PdpState.class));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
}
-} \ No newline at end of file
+}