Remove supported policy types from status message
Issue-ID: POLICY-2233
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Change-Id: I2168b9616d35ee3b9aa491aaa5d363b8609adb84
Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
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 27f375d..805dfd0 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.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 @@
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 @@
@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 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 @@
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 @@
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 78414fe..a80c885 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 @@
@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 bb8e494..2a25830 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.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.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 @@
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 341d985..f242e4c 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.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 @@
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 @@
@Test
public void status() {
- status(PdpState.PASSIVE);
+ assertTrue(fsm.client.getSink().isAlive());
+ assertTrue(fsm.status());
+ assertSame(0, fsm.client.getSink().getRecentEvents().length);
+
+
+ fsm.start(controllerSupport.getController());
+ status(PdpState.PASSIVE, 1);
+ fsm.stop(controllerSupport.getController());
fsm.shutdown();
}
- private void status(PdpState state) {
- waitUntil(5, TimeUnit.SECONDS, isStatus(state, 1));
-
- waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, 2));
-
- waitUntil(fsm.statusTimerSeconds + 2, TimeUnit.SECONDS, isStatus(state, 3));
-
+ 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 b5b5976..fe3566d 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.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 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);
+ }
}