aboutsummaryrefslogtreecommitdiffstats
path: root/feature-lifecycle
diff options
context:
space:
mode:
Diffstat (limited to 'feature-lifecycle')
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleFsm.java31
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/lifecycle/LifecycleStateRunning.java8
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java23
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java42
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java27
5 files changed, 60 insertions, 71 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 27f375d0..805dfd01 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,8 +45,6 @@ import org.onap.policy.common.endpoints.listeners.ScoListener;
import org.onap.policy.common.gson.annotation.GsonJsonIgnore;
import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.common.utils.network.NetworkUtil;
-import org.onap.policy.drools.controller.DroolsController;
-import org.onap.policy.drools.controller.DroolsControllerConstants;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.system.PolicyController;
import org.onap.policy.models.pdp.concepts.PdpResponseDetails;
@@ -70,7 +68,6 @@ public class LifecycleFsm implements Startable {
protected static final String CONFIGURATION_PROPERTIES_NAME = "feature-lifecycle";
protected static final String GROUP_NAME = "lifecycle.pdp.group";
protected static final String DEFAULT_PDP_GROUP = "defaultGroup";
- protected static final String POLICY_TYPE_VERSION = "1.0.0";
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";
@@ -112,6 +109,7 @@ public class LifecycleFsm implements Startable {
@Getter
protected String subgroup;
+ @Getter
protected final Map<ToscaPolicyTypeIdentifier, PolicyController> policyTypesMap = new HashMap<>();
protected final Map<ToscaPolicyIdentifier, ToscaPolicy> policiesMap = new HashMap<>();
@@ -150,7 +148,9 @@ public class LifecycleFsm implements Startable {
public synchronized void start(@NonNull PolicyController controller) {
logger.info("lifecycle event: start controller: {}", controller.getName());
for (ToscaPolicyTypeIdentifier id : controller.getPolicyTypes()) {
- policyTypesMap.put(id, controller);
+ if (isToscaPolicyType(id.getName())) {
+ policyTypesMap.put(id, controller);
+ }
}
}
@@ -342,7 +342,6 @@ public class LifecycleFsm implements Startable {
status.setState(state);
status.setHealthy(isAlive() ? PdpHealthStatus.HEALTHY : PdpHealthStatus.NOT_HEALTHY);
status.setPdpType("drools");
- status.setSupportedPolicyTypes(getCapabilities());
status.setPolicies(new ArrayList<>(policiesMap.keySet()));
return status;
}
@@ -379,23 +378,9 @@ public class LifecycleFsm implements Startable {
return this.client.getSink().start();
}
- private List<ToscaPolicyTypeIdentifier> getCapabilities() {
- List<ToscaPolicyTypeIdentifier> capabilities = new ArrayList<>();
- for (DroolsController dc : DroolsControllerConstants.getFactory().inventory()) {
- if (!dc.isBrained()) {
- continue;
- }
-
- for (String domain : dc.getBaseDomainNames()) {
- // HACK: until legacy controllers are removed
- if (StringUtils.countMatches(domain, ".") > 1) {
- capabilities.add(new ToscaPolicyTypeIdentifier(domain, POLICY_TYPE_VERSION));
- } else {
- logger.info("legacy controller {} with domain {}", dc.getCanonicalSessionNames(), domain);
- }
- }
- }
- return capabilities;
+ protected boolean isToscaPolicyType(String domain) {
+ // HACK: until legacy controllers support is removed
+ return StringUtils.countMatches(domain, ".") > 1;
}
protected boolean isItMe(String name, String group, String subgroup) {
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 78414fe8..a80c8853 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Bell Canada.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,7 +80,11 @@ public abstract class LifecycleStateRunning extends LifecycleStateDefault {
@Override
public boolean status() {
synchronized (fsm) {
- return fsm.statusAction();
+ if (fsm.getPolicyTypesMap().isEmpty()) {
+ return true;
+ } else {
+ return fsm.statusAction();
+ }
}
}
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 bb8e4940..2a258305 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
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +34,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -44,7 +43,6 @@ import org.onap.policy.common.utils.network.NetworkUtil;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.concepts.PdpStatus;
import org.onap.policy.models.pdp.concepts.PdpUpdate;
-import org.onap.policy.models.pdp.enums.PdpMessageType;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
@@ -127,28 +125,19 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertTrue(fsm.statusTask.isDone());
}
- private Callable<Boolean> isStatus(PdpState state) {
- return () -> {
- if (fsm.client.getSink().getRecentEvents().length == 0) {
- return false;
- }
-
- List<String> events = Arrays.asList(fsm.client.getSink().getRecentEvents());
- PdpStatus status =
- new StandardCoder().decode(events.get(events.size() - 1), PdpStatus.class);
-
- return status.getMessageName() == PdpMessageType.PDP_STATUS && state == status.getState();
- };
- }
-
@Test
public void status() {
waitUntil(fsm.getStatusTimerSeconds() + 1, TimeUnit.SECONDS, isStatus(PdpState.ACTIVE));
int preCount = fsm.client.getSink().getRecentEvents().length;
assertTrue(fsm.status());
+ assertEquals(preCount, fsm.client.getSink().getRecentEvents().length);
+
+ fsm.start(controllerSupport.getController());
+ assertTrue(fsm.status());
assertEquals(preCount + 1, fsm.client.getSink().getRecentEvents().length);
+ fsm.stop(controllerSupport.getController());
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 341d9857..f242e4c6 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,7 +33,6 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
-import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
@@ -94,23 +93,6 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
fsm.shutdown();
}
- private Callable<Boolean> isStatus(PdpState state, int count) {
- return () -> {
- if (!fsm.client.getSink().isAlive()) {
- return false;
- }
-
- if (fsm.client.getSink().getRecentEvents().length != count) {
- return false;
- }
-
- String[] events = fsm.client.getSink().getRecentEvents();
- PdpStatus status = new StandardCoder().decode(events[events.length - 1], PdpStatus.class);
-
- return status.getMessageName() == PdpMessageType.PDP_STATUS && state == status.getState();
- };
- }
-
@Test
public void stop() {
simpleStop();
@@ -137,19 +119,23 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
@Test
public void status() {
- status(PdpState.PASSIVE);
- fsm.shutdown();
- }
-
- private void status(PdpState state) {
- waitUntil(5, TimeUnit.SECONDS, isStatus(state, 1));
+ assertTrue(fsm.client.getSink().isAlive());
+ assertTrue(fsm.status());
+ assertSame(0, fsm.client.getSink().getRecentEvents().length);
- waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, 2));
- waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, 3));
+ fsm.start(controllerSupport.getController());
+ status(PdpState.PASSIVE, 1);
+ fsm.stop(controllerSupport.getController());
+ fsm.shutdown();
+ }
+ private void status(PdpState state, int initial) {
+ waitUntil(5, TimeUnit.SECONDS, isStatus(state, initial));
+ waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, initial + 1));
+ waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, initial + 2));
assertTrue(fsm.status());
- waitUntil(200, TimeUnit.MILLISECONDS, isStatus(state, 4));
+ waitUntil(200, TimeUnit.MILLISECONDS, isStatus(state, initial + 3));
}
@Test
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
index b5b59767..fe3566db 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,10 +28,14 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.time.PseudoScheduledExecutorService;
import org.onap.policy.common.utils.time.TestTimeMulti;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.utils.logging.LoggerUtil;
+import org.onap.policy.models.pdp.concepts.PdpStatus;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+import org.onap.policy.models.pdp.enums.PdpState;
public abstract class LifecycleStateRunningTest {
@@ -84,4 +88,25 @@ public abstract class LifecycleStateRunningTest {
public void waitUntil(long twait, TimeUnit units, Callable<Boolean> condition) {
time.waitUntil(twait, units, condition);
}
+
+ protected Callable<Boolean> isStatus(PdpState state, int count) {
+ return () -> {
+ if (fsm.client.getSink().getRecentEvents().length != count) {
+ return false;
+ }
+
+ String[] events = fsm.client.getSink().getRecentEvents();
+ PdpStatus status = new StandardCoder().decode(events[events.length - 1], PdpStatus.class);
+
+ if (status.getSupportedPolicyTypes() != null) {
+ return false;
+ }
+
+ return status.getMessageName() == PdpMessageType.PDP_STATUS && state == status.getState();
+ };
+ }
+
+ protected Callable<Boolean> isStatus(PdpState state) {
+ return isStatus(state, fsm.client.getSink().getRecentEvents().length);
+ }
}