summaryrefslogtreecommitdiffstats
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.java27
-rw-r--r--feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java6
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java4
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java8
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java6
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActiveTest.java8
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStatePassiveTest.java12
-rw-r--r--feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateRunningTest.java6
-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/lifecycle/PolicyTypeNativeDroolsControllerTest.java4
10 files changed, 49 insertions, 36 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 611ac240..09dcab00 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
@@ -39,6 +39,7 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
+import lombok.AccessLevel;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
@@ -153,6 +154,8 @@ public class LifecycleFsm implements Startable {
@Setter
protected String pdpType;
+ protected volatile String pdpName;
+
@Getter
protected Set<String> mandatoryPolicyTypes = new HashSet<>();
@@ -186,12 +189,6 @@ public class LifecycleFsm implements Startable {
logger.info("The mandatory Policy Types are {}. Compliance is {}",
mandatoryPolicyTypes, isMandatoryPolicyTypesCompliant());
-
- stats.setPdpInstanceId(PolicyEngineConstants.PDP_NAME);
- }
-
- public String getName() {
- return PolicyEngineConstants.PDP_NAME;
}
@GsonJsonIgnore
@@ -205,6 +202,18 @@ public class LifecycleFsm implements Startable {
}
/**
+ * Returns the PDP Name.
+ */
+ public String getPdpName() {
+ if (this.pdpName == null) {
+ this.pdpName = PolicyEngineConstants.getManager().getPdpName();
+ this.stats.setPdpInstanceId(pdpName);
+ }
+
+ return this.pdpName;
+ }
+
+ /**
* Current state.
*/
public PdpState state() {
@@ -231,6 +240,8 @@ public class LifecycleFsm implements Startable {
@Override
public synchronized boolean start() {
+ this.pdpName = PolicyEngineConstants.getManager().getPdpName();
+ stats.setPdpInstanceId(pdpName);
logger.info("lifecycle event: start engine");
return state.start();
}
@@ -651,7 +662,7 @@ public class LifecycleFsm implements Startable {
protected PdpStatus statusPayload(@NonNull PdpState state) {
var status = new PdpStatus();
- status.setName(getName());
+ status.setName(getPdpName());
status.setPdpGroup(group);
status.setPdpSubgroup(subGroup);
status.setState(state);
@@ -711,7 +722,7 @@ public class LifecycleFsm implements Startable {
}
protected boolean isItMe(String name, String group, String subgroup) {
- if (Objects.equals(name, getName())) {
+ if (Objects.equals(name, getPdpName())) {
return true;
}
diff --git a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
index 494c708b..5a534639 100644
--- a/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
+++ b/feature-lifecycle/src/main/java/org/onap/policy/drools/server/restful/RestLifecycleManager.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -155,7 +155,7 @@ public class RestLifecycleManager {
change.setPdpGroup(LifecycleFeature.getFsm().getGroup());
change.setPdpSubgroup(LifecycleFeature.getFsm().getSubGroup());
change.setState(PdpState.valueOf(state));
- change.setName(LifecycleFeature.getFsm().getName());
+ change.setName(LifecycleFeature.getFsm().getPdpName());
return Response.status(Response.Status.OK).entity(LifecycleFeature.getFsm().stateChange(change)).build();
}
@@ -442,7 +442,7 @@ public class RestLifecycleManager {
private PdpUpdate getPolicyUpdate() {
var update = new PdpUpdate();
- update.setName(LifecycleFeature.getFsm().getName());
+ update.setName(LifecycleFeature.getFsm().getPdpName());
update.setPdpGroup(LifecycleFeature.getFsm().getGroup());
update.setPdpSubgroup(LifecycleFeature.getFsm().getSubGroup());
return update;
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
index 0ad776cc..8c3aeef1 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmTest.java
@@ -30,6 +30,7 @@ import java.nio.file.Paths;
import java.util.Collections;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import org.junit.AfterClass;
@@ -106,6 +107,7 @@ public class LifecycleFsmTest {
LoggerUtils.setLevel("org.onap.policy.common.endpoints", "WARN");
LoggerUtils.setLevel("org.onap.policy.drools", "INFO");
SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
+ PolicyEngineConstants.getManager().configure(new Properties());
fsm = new LifecycleFsm() {
@Override
@@ -240,7 +242,7 @@ public class LifecycleFsmTest {
assertEquals(fsm.getGroup(), status.getStatistics().getPdpGroupName());
assertEquals(fsm.getSubGroup(), status.getStatistics().getPdpSubGroupName());
- assertEquals(PolicyEngineConstants.PDP_NAME, status.getStatistics().getPdpInstanceId());
+ assertEquals(PolicyEngineConstants.getManager().getPdpName(), status.getStatistics().getPdpInstanceId());
assertEquals(6, status.getStatistics().getPolicyDeploySuccessCount());
assertEquals(2, status.getStatistics().getPolicyDeployFailCount());
assertEquals(8, status.getStatistics().getPolicyDeployCount());
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
index c97133b5..5d56143d 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleFsmUpdateTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2021-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -160,7 +160,7 @@ public class LifecycleFsmUpdateTest {
Files.deleteIfExists(Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
"foo-controller.properties.bak"));
} catch (IOException ignored) { // NOSONAR
- ; // checkstyle
+ // checkstyle
}
ControllerSupport.setStaticField(LifecycleFeature.class, "fsm", savedFsm);
@@ -186,7 +186,7 @@ public class LifecycleFsmUpdateTest {
change.setPdpGroup("A");
change.setPdpSubgroup("a");
change.setState(PdpState.ACTIVE);
- change.setName(fsm.getName());
+ change.setName(fsm.getPdpName());
fsm.setSubGroup("a");
fsm.source.offer(new StandardCoder().encode(change));
@@ -359,7 +359,7 @@ public class LifecycleFsmUpdateTest {
protected PdpUpdate getPdpUpdate(List<ToscaPolicy> policiesToDeploy, List<ToscaPolicy> policiesToUndeploy) {
PdpUpdate update = new PdpUpdate();
- update.setName(PolicyEngineConstants.PDP_NAME);
+ update.setName(PolicyEngineConstants.getManager().getPdpName());
update.setPdpGroup("A");
update.setPdpSubgroup("a");
update.setPoliciesToBeDeployed(policiesToDeploy);
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
index f37e8ef7..67efa72a 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/LifecycleStateActivePoliciesTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -77,7 +77,7 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
change.setPdpGroup("A");
change.setPdpSubgroup("a");
change.setState(PdpState.ACTIVE);
- change.setName(fsm.getName());
+ change.setName(fsm.getPdpName());
fsm.setSubGroup("a");
fsm.source.offer(new StandardCoder().encode(change));
@@ -116,7 +116,7 @@ public class LifecycleStateActivePoliciesTest extends LifecycleStateRunningTest
getPolicyFromFile(EXAMPLE_NATIVE_DROOLS_POLICY_JSON, EXAMPLE_NATIVE_DROOLS_CONTROLLER_POLICY_NAME);
PdpUpdate update = new PdpUpdate();
- update.setName(PolicyEngineConstants.PDP_NAME);
+ update.setName(PolicyEngineConstants.getManager().getPdpName());
update.setPdpGroup("W");
update.setPdpSubgroup("w");
update.setPoliciesToBeDeployed(List.of(policyNativeController));
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 f4c33140..d00c8a41 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-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -75,7 +75,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
change.setPdpGroup("A");
change.setPdpSubgroup("a");
change.setState(PdpState.ACTIVE);
- change.setName(fsm.getName());
+ change.setName(fsm.getPdpName());
fsm.setSubGroup("a");
fsm.source.offer(new StandardCoder().encode(change));
@@ -161,7 +161,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
assertNotEquals("b", fsm.getSubGroup());
- change.setName(fsm.getName());
+ change.setName(fsm.getPdpName());
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
assertEquals(LifecycleFsm.DEFAULT_PDP_GROUP, fsm.getGroup());
@@ -189,7 +189,7 @@ public class LifecycleStateActiveTest extends LifecycleStateRunningTest {
// TODO: extract repeated similar assertion blocks into their own helper methods
PdpUpdate update = new PdpUpdate();
- update.setName(PolicyEngineConstants.PDP_NAME);
+ update.setName(PolicyEngineConstants.getManager().getPdpName());
update.setPdpGroup("W");
update.setPdpSubgroup("w");
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 d99f011d..d6c94996 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-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -143,7 +143,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
PdpUpdate update = new PdpUpdate();
- update.setName(PolicyEngineConstants.PDP_NAME);
+ update.setName(PolicyEngineConstants.getManager().getPdpName());
update.setPdpGroup("Z");
update.setPdpSubgroup("z");
@@ -269,7 +269,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertNull(fsm.getSubGroup());
PdpUpdate update = new PdpUpdate();
- update.setName(PolicyEngineConstants.PDP_NAME);
+ update.setName(PolicyEngineConstants.getManager().getPdpName());
update.setPdpGroup("A");
update.setPdpSubgroup("a");
@@ -294,7 +294,7 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals(0, controllerSupport.getController().getDrools().factCount("junits"));
/* correct name */
- change.setName(fsm.getName());
+ change.setName(fsm.getPdpName());
fsm.source.offer(new StandardCoder().encode(change));
assertEquals(PdpState.ACTIVE, fsm.state());
@@ -330,8 +330,8 @@ public class LifecycleStatePassiveTest extends LifecycleStateRunningTest {
assertEquals("foo", status.getPdpType());
assertEquals(PdpState.TERMINATED, status.getState());
assertEquals(PdpHealthStatus.HEALTHY, status.getHealthy());
- assertEquals(PolicyEngineConstants.PDP_NAME, status.getName());
- assertEquals(fsm.getName(), status.getName());
+ assertEquals(PolicyEngineConstants.getManager().getPdpName(), status.getName());
+ assertEquals(fsm.getPdpName(), status.getName());
assertEquals(PdpMessageType.PDP_STATUS, status.getMessageName());
}
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 eeac888d..7b210db8 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-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 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.
@@ -75,8 +75,8 @@ public abstract class LifecycleStateRunningTest {
try {
Files.deleteIfExists(Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
CONTROLLER_NAME + "-controller.properties.bak"));
- } catch (IOException e) {
- ;
+ } catch (IOException ignored) {
+ // ignored
}
SystemPersistenceConstants.getManager().setConfigurationDir(null);
}
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 3d8d08b7..23643302 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2022 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -139,7 +139,7 @@ public class LifecycleStateTerminatedTest {
@Test
public void testUpdate() {
PdpUpdate update = new PdpUpdate();
- update.setName(PolicyEngineConstants.PDP_NAME);
+ update.setName(PolicyEngineConstants.getManager().getPdpName());
update.setPdpGroup("A");
update.setPdpSubgroup("a");
update.setPoliciesToBeDeployed(Collections.emptyList());
diff --git a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java
index 2d8b8688..b6f354e4 100644
--- a/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java
+++ b/feature-lifecycle/src/test/java/org/onap/policy/drools/lifecycle/PolicyTypeNativeDroolsControllerTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2022 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.
@@ -50,7 +50,7 @@ public class PolicyTypeNativeDroolsControllerTest extends LifecycleStateRunningT
* Test initialization.
*/
@Before
- public void init() throws IOException, CoderException {
+ public void init() {
fsm = makeFsmWithPseudoTime();
}