aboutsummaryrefslogtreecommitdiffstats
path: root/policy-management/src/test
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2022-10-18 12:08:45 -0500
committerjhh <jorge.hernandez-herrero@att.com>2022-10-19 08:31:02 -0500
commit6652164b384221018bf605b1d5fb809425b26a8e (patch)
tree6e440f5379010f5bbb20841384c55b86da37b533 /policy-management/src/test
parente58a8c52dadfe14b8b77c8eb7c236697c710ddd5 (diff)
Support optional cluster name in policy engine
This allows also for correlation with running pod hostnames in the case of multiple drools pdp flavors coexist. Issue-ID: POLICY-4403 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: I81affeeec622e6c0e9627651bf34c0775a796827 Signed-off-by: jhh <jorge.hernandez-herrero@att.com>
Diffstat (limited to 'policy-management/src/test')
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java33
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java13
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json3
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json3
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json3
5 files changed, 49 insertions, 6 deletions
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 82c28695..fe307f28 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -23,6 +23,7 @@ package org.onap.policy.drools.system;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -46,6 +47,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
+import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
@@ -330,6 +332,8 @@ public class PolicyEngineManagerTest {
@Test
public void testSerialize() {
+ mgr.setHostName("foo");
+ mgr.setClusterName("bar");
mgr.configure(properties);
assertThatCode(() -> gson.compareGson(mgr, PolicyEngineManagerTest.class)).doesNotThrowAnyException();
}
@@ -443,6 +447,35 @@ public class PolicyEngineManagerTest {
assertFalse(config.isEmpty());
}
+ @Test
+ public void testGetPdpName() {
+ properties.setProperty(PolicyEngineManager.CLUSTER_NAME_PROP, "east1");
+ mgr.configure(properties);
+
+ var pdpName = mgr.getPdpName();
+ assertEquals("east1", extractCluster(pdpName));
+ assertEquals(mgr.getClusterName(), extractCluster(pdpName));
+ assertEquals(mgr.getHostName(), extractHostname(pdpName));
+
+ mgr.setHostName("foo");
+ mgr.setClusterName("bar");
+ mgr.setPdpName("foo.bar");
+
+ pdpName = mgr.getPdpName();
+ assertEquals("bar", extractCluster(pdpName));
+ assertEquals(mgr.getClusterName(), extractCluster(pdpName));
+ assertEquals("foo", extractHostname(pdpName));
+ assertEquals(mgr.getHostName(), extractHostname(pdpName));
+ }
+
+ private String extractCluster(String name) {
+ return name.substring(name.lastIndexOf(".") + 1);
+ }
+
+ private String extractHostname(String name) {
+ return name.substring(0, name.lastIndexOf("."));
+ }
+
/**
* Tests that makeExecutorService() uses the value from the thread
* property.
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
index 0fdc00a6..2054d91d 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -155,17 +155,18 @@ public class PolicyEngineTest {
@Test
public void test100Configure() {
- logger.info("enter");
-
- final Properties engineProps = PolicyEngineConstants.getManager().defaultTelemetryConfig();
+ var manager = (PolicyEngineManager) PolicyEngineConstants.getManager();
+ var engineProps = manager.defaultTelemetryConfig();
/* override default port */
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
+ PolicyEngineConstants.TELEMETRY_SERVER_DEFAULT_NAME
+ PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "" + DEFAULT_TELEMETRY_PORT);
- assertFalse(PolicyEngineConstants.getManager().isAlive());
- PolicyEngineConstants.getManager().configure(engineProps);
+ assertFalse(manager.isAlive());
+ manager.setHostName("foo");
+ manager.setClusterName("0");
+ manager.configure(engineProps);
assertFalse(PolicyEngineConstants.getManager().isAlive());
logger.info("engine {} has configuration {}", PolicyEngineConstants.getManager(), engineProps);
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json
index d2d2075e..4c7e1f03 100644
--- a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json
@@ -13,6 +13,9 @@
{ "port": 1002 }
],
"locked": false,
+ "hostName": "foo",
+ "clusterName": "bar",
+ "pdpName": "foo.bar",
"sinks": [
{ "name": "sink1-topic" },
{ "name": "sink2-topic" }
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json
index 555f361f..35afaff8 100644
--- a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json
@@ -1,6 +1,9 @@
{
"alive": true,
"locked": false,
+ "hostName": "foo",
+ "clusterName": "0",
+ "pdpName": "foo.0",
"sources": [],
"sinks": [],
"httpServers": [
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json
index 0e010323..9053c90a 100644
--- a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json
@@ -14,6 +14,9 @@
"prometheus": false
}
],
+ "clusterName": "0",
+ "hostName": "foo",
+ "pdpName": "foo.0",
"features": [],
"controllers": [],
"stats": {