summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Hernandez <jorge.hernandez-herrero@att.com>2020-03-03 15:36:20 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-03 15:36:20 +0000
commitd9289d8c8fe1a89269cd8086582f668c0dfbb084 (patch)
tree191bf995b106c938406e4dd6b7f0fde03cf65fb1
parentce6397158e6ec07809de6216d0425ce98c98d015 (diff)
parentf2f56be75cb55096acca3ab41222dc1fef47ea48 (diff)
Merge "http server/client management"
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java76
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java102
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/Main.java22
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java42
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java105
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java44
6 files changed, 360 insertions, 31 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
index ca1ad371..1347eb6c 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/FileSystemPersistence.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -71,27 +71,23 @@ public class FileSystemPersistence implements SystemPersistence {
public static final String TOPIC_SUFFIX_IDENTIFIER = "-topic";
/**
- * Policy controller properties file suffix.
+ * Topic properties file suffix.
*/
public static final String PROPERTIES_FILE_TOPIC_SUFFIX = TOPIC_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION;
/**
- * Policy topic properties file suffix.
- */
- public static final String PROPERTIES_FILE_TOPIC_BACKUP_SUFFIX =
- TOPIC_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION + ".bak";
-
- /**
- * Policy controller properties file suffix.
- */
- public static final String PROPERTIES_FILE_CONTROLLER_BACKUP_SUFFIX =
- CONTROLLER_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION + ".bak";
-
- /**
* Policy engine properties file name.
*/
public static final String PROPERTIES_FILE_ENGINE = "engine" + PROPERTIES_FILE_EXTENSION;
+ public static final String HTTP_SERVER_SUFFIX_IDENTIFIER = "-http-server";
+ public static final String PROPERTIES_FILE_HTTP_SERVER_SUFFIX =
+ HTTP_SERVER_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION;
+
+ public static final String HTTP_CLIENT_SUFFIX_IDENTIFIER = "-http-client";
+ public static final String PROPERTIES_FILE_HTTP_CLIENT_SUFFIX =
+ HTTP_CLIENT_SUFFIX_IDENTIFIER + PROPERTIES_FILE_EXTENSION;
+
/**
* Installation environment suffix for files.
*/
@@ -260,6 +256,26 @@ public class FileSystemPersistence implements SystemPersistence {
return getPropertiesList(PROPERTIES_FILE_TOPIC_SUFFIX);
}
+ @Override
+ public Properties getHttpServerProperties(String serverName) {
+ return this.getProperties(serverName + HTTP_SERVER_SUFFIX_IDENTIFIER);
+ }
+
+ @Override
+ public List<Properties> getHttpServerProperties() {
+ return getPropertiesList(PROPERTIES_FILE_HTTP_SERVER_SUFFIX);
+ }
+
+ @Override
+ public Properties getHttpClientProperties(String clientName) {
+ return this.getProperties(clientName + HTTP_CLIENT_SUFFIX_IDENTIFIER);
+ }
+
+ @Override
+ public List<Properties> getHttpClientProperties() {
+ return getPropertiesList(PROPERTIES_FILE_HTTP_CLIENT_SUFFIX);
+ }
+
private boolean testControllerName(String controllerFilename, Properties controllerProperties) {
String controllerName = controllerFilename
.substring(0, controllerFilename.length() - PROPERTIES_FILE_CONTROLLER_SUFFIX.length());
@@ -285,6 +301,16 @@ public class FileSystemPersistence implements SystemPersistence {
return backup(topicName, PROPERTIES_FILE_TOPIC_SUFFIX);
}
+ @Override
+ public boolean backupHttpServer(String serverName) {
+ return backup(serverName, PROPERTIES_FILE_HTTP_SERVER_SUFFIX);
+ }
+
+ @Override
+ public boolean backupHttpClient(String clientName) {
+ return backup(clientName, PROPERTIES_FILE_HTTP_CLIENT_SUFFIX);
+ }
+
protected boolean backup(String name, String fileSuffix) {
Path path = Paths.get(this.configurationDirectory.toString(), name + fileSuffix);
if (Files.exists(path)) {
@@ -313,6 +339,18 @@ public class FileSystemPersistence implements SystemPersistence {
return store(topicName, (Properties) configuration, PROPERTIES_FILE_TOPIC_SUFFIX);
}
+ @Override
+ public boolean storeHttpServer(String serverName, Object configuration) {
+ checkPropertiesParam(configuration);
+ return store(serverName, (Properties) configuration, PROPERTIES_FILE_HTTP_SERVER_SUFFIX);
+ }
+
+ @Override
+ public boolean storeHttpClient(String clientName, Object configuration) {
+ checkPropertiesParam(configuration);
+ return store(clientName, (Properties) configuration, PROPERTIES_FILE_HTTP_CLIENT_SUFFIX);
+ }
+
private boolean store(String name, Properties properties, String fileSuffix) {
Path path = Paths.get(this.configurationDirectory.toString(), name + fileSuffix);
if (Files.exists(path)) {
@@ -360,6 +398,16 @@ public class FileSystemPersistence implements SystemPersistence {
return delete(topicName, PROPERTIES_FILE_TOPIC_SUFFIX);
}
+ @Override
+ public boolean deleteHttpServer(String serverName) {
+ return delete(serverName, PROPERTIES_FILE_HTTP_SERVER_SUFFIX);
+ }
+
+ @Override
+ public boolean deleteHttpClient(String clientName) {
+ return delete(clientName, PROPERTIES_FILE_HTTP_CLIENT_SUFFIX);
+ }
+
protected boolean delete(String name, String fileSuffix) {
Path path = Paths.get(this.configurationDirectory.toString(), name + fileSuffix);
diff --git a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
index d5a35c32..b5fc88e0 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/persistence/SystemPersistence.java
@@ -1,8 +1,8 @@
/*
* ============LICENSE_START=======================================================
- * policy-management
+ * ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -65,12 +65,28 @@ public interface SystemPersistence {
boolean backupTopic(String topicName);
/**
+ * backs up an http server configuration.
+ *
+ * @param serverName the HTTP server name
+ * @return true if the configuration is backed up
+ */
+ boolean backupHttpServer(String serverName);
+
+ /**
+ * backs up an http client configuration.
+ *
+ * @param clientName the HTTP client name
+ * @return true if the configuration is backed up
+ */
+ boolean backupHttpClient(String clientName);
+
+ /**
* persists controller configuration.
*
* @param controllerName the controller name
* @param configuration object containing the configuration
*
- * @return true if storage is succesful, false otherwise
+ * @return true if storage is successful, false otherwise
* @throws IllegalArgumentException if the configuration cannot be handled by the persistence
* manager
*/
@@ -82,17 +98,41 @@ public interface SystemPersistence {
* @param topicName the controller name
* @param configuration object containing the configuration
*
- * @return true if storage is succesful, false otherwise
+ * @return true if storage is successful, false otherwise
* @throws IllegalArgumentException if the configuration cannot be handled by the persistence
* manager
*/
boolean storeTopic(String topicName, Object configuration);
/**
+ * persists http server configuration.
+ *
+ * @param serverName the server name
+ * @param configuration object containing the configuration
+ *
+ * @return true if storage is successful, false otherwise
+ * @throws IllegalArgumentException if the configuration cannot be handled by the persistence
+ * manager
+ */
+ boolean storeHttpServer(String serverName, Object configuration);
+
+ /**
+ * persists http client configuration.
+ *
+ * @param clientName the client name
+ * @param configuration object containing the configuration
+ *
+ * @return true if storage is successful, false otherwise
+ * @throws IllegalArgumentException if the configuration cannot be handled by the persistence
+ * manager
+ */
+ boolean storeHttpClient(String clientName, Object configuration);
+
+ /**
* delete controller configuration.
*
* @param controllerName the controller name
- * @return true if storage is succesful, false otherwise
+ * @return true if storage is successful, false otherwise
*/
boolean deleteController(String controllerName);
@@ -100,11 +140,27 @@ public interface SystemPersistence {
* delete topic configuration.
*
* @param topicName the topic name
- * @return true if storage is succesful, false otherwise
+ * @return true if storage is successful, false otherwise
*/
boolean deleteTopic(String topicName);
/**
+ * deletes an http server configuration.
+ *
+ * @param serverName the HTTP server name
+ * @return true if storage is successful, false otherwise
+ */
+ boolean deleteHttpServer(String serverName);
+
+ /**
+ * deletes an http client configuration.
+ *
+ * @param clientName the HTTP client name
+ * @return true if storage is successful, false otherwise
+ */
+ boolean deleteHttpClient(String clientName);
+
+ /**
* get controllers configuration.
*
* @return list of controllers properties
@@ -140,6 +196,40 @@ public interface SystemPersistence {
Properties getTopicProperties(String topicName);
/**
+ * get HTTP Servers configuration.
+ *
+ * @return list of HTTP server properties
+ */
+ List<Properties> getHttpServerProperties();
+
+ /**
+ * get HTTP Server properties.
+ *
+ * @param serverName name
+ * @return properties for this server
+ *
+ * @throws IllegalArgumentException if topicName is invalid
+ */
+ Properties getHttpServerProperties(String serverName);
+
+ /**
+ * get HTTP Client configuration.
+ *
+ * @return list of HTTP client properties
+ */
+ List<Properties> getHttpClientProperties();
+
+ /**
+ * get HTTP Client properties.
+ *
+ * @param clientName name
+ * @return properties for this client
+ *
+ * @throws IllegalArgumentException if topicName is invalid
+ */
+ Properties getHttpClientProperties(String clientName);
+
+ /**
* get environments.
*
*/
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
index da4e1548..ea687e03 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/Main.java
@@ -23,7 +23,11 @@ package org.onap.policy.drools.system;
import java.util.Properties;
import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.http.client.HttpClientConfigException;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
import org.onap.policy.common.utils.security.CryptoUtils;
+import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
import org.onap.policy.drools.properties.DroolsPropertyConstants;
import org.onap.policy.drools.utils.PropertyUtil;
@@ -87,12 +91,28 @@ public class Main {
PolicyEngineConstants.getManager().setEnvironment(env);
}
- /* 2. Add topics */
+ /* 2.a Add topics */
for (Properties topicProperties : SystemPersistenceConstants.getManager().getTopicProperties()) {
TopicEndpointManager.getManager().addTopics(topicProperties);
}
+ /* 2.b Add HTTP Servers */
+
+ for (Properties serverProperties : SystemPersistenceConstants.getManager().getHttpServerProperties()) {
+ HttpServletServerFactoryInstance.getServerFactory().build(serverProperties);
+ }
+
+ /* 2.c Add HTTP Clients */
+
+ for (Properties clientProperties : SystemPersistenceConstants.getManager().getHttpClientProperties()) {
+ try {
+ HttpClientFactoryInstance.getClientFactory().build(clientProperties);
+ } catch (HttpClientConfigException e) {
+ logger.warn("Main: http client properties errors found. Using default configuration.", e);
+ }
+ }
+
/* 3. Start the Engine with the basic services only (no Policy Controllers) */
MdcTransaction trans =
diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
index 0edb06f8..95ee88cb 100644
--- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
+++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngineManager.java
@@ -36,6 +36,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
+import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.AccessLevel;
import lombok.Getter;
@@ -47,6 +48,9 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
@@ -588,12 +592,21 @@ class PolicyEngineManager implements PolicyEngine {
success.set(false);
}
- /* Start Policy Engine exclusively-owned (unmanaged) http servers */
+ /* Start managed and unmanaged http servers */
- attempt(success, this.httpServers,
+ attempt(success,
+ Stream.concat(getServletFactory().inventory().stream(), this.httpServers.stream())
+ .collect(Collectors.toList()),
httpServer -> httpServer.waitedStart(10 * 1000L),
- (item, ex) -> logger.error("{}: cannot start http-server {} because of {}",
- this, item, ex.getMessage(), ex));
+ (item, ex) -> logger.error("{}: cannot start http-server {} because of {}", this, item,
+ ex.getMessage(), ex));
+
+ /* Start managed Http Clients */
+
+ attempt(success, getHttpClientFactory().inventory(),
+ HttpClient::start,
+ (item, ex) -> logger.error("{}: cannot start http-client {} because of {}",
+ this, item, ex.getMessage(), ex));
/* Start Policy Controllers */
@@ -615,7 +628,6 @@ class PolicyEngineManager implements PolicyEngine {
logger.warn("{}: Topic Endpoint Manager is in an invalid state because of {}", this, e.getMessage(), e);
}
-
// Start the JMX listener
startPdpJmxListener();
@@ -722,11 +734,20 @@ class PolicyEngineManager implements PolicyEngine {
success.set(false);
}
- /* stop all unmanaged http servers */
- attempt(success, this.httpServers,
+ /* stop all managed and unmanaged http servers */
+ attempt(success,
+ Stream.concat(getServletFactory().inventory().stream(), this.httpServers.stream())
+ .collect(Collectors.toList()),
HttpServletServer::stop,
(item, ex) -> logger.error("{}: cannot stop http-server {} because of {}", this, item,
- ex.getMessage(), ex));
+ ex.getMessage(), ex));
+
+ /* stop all managed http clients */
+ attempt(success,
+ getHttpClientFactory().inventory(),
+ HttpClient::stop,
+ (item, ex) -> logger.error("{}: cannot stop http-client {} because of {}", this, item,
+ ex.getMessage(), ex));
try {
success.compareAndSet(true, this.lockManager.stop());
@@ -783,6 +804,7 @@ class PolicyEngineManager implements PolicyEngine {
getControllerFactory().shutdown();
getTopicEndpointManager().shutdown();
getServletFactory().destroy();
+ getHttpClientFactory().destroy();
try {
this.lockManager.shutdown();
@@ -1341,6 +1363,10 @@ class PolicyEngineManager implements PolicyEngine {
return HttpServletServerFactoryInstance.getServerFactory();
}
+ protected HttpClientFactory getHttpClientFactory() {
+ return HttpClientFactoryInstance.getClientFactory();
+ }
+
protected PolicyControllerFactory getControllerFactory() {
return PolicyControllerConstants.getFactory();
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
index 8cd4ee6e..15a0b18f 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/persistence/SystemPersistenceTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-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.
@@ -54,12 +54,23 @@ public class SystemPersistenceTest {
*/
private static final String TEST_CONTROLLER_NAME = "foo";
+
/**
* Test JUnit Topic Name.
*/
private static final String TEST_TOPIC_NAME = TEST_CONTROLLER_NAME;
/**
+ * Test JUnit HTTP Server Name.
+ */
+ private static final String TEST_HTTP_SERVER_NAME = TEST_CONTROLLER_NAME;
+
+ /**
+ * Test JUnit HTTP Client Name.
+ */
+ private static final String TEST_HTTP_CLIENT_NAME = TEST_CONTROLLER_NAME;
+
+ /**
* Test JUnit Controller File.
*/
private static final String TEST_CONTROLLER_FILE = TEST_CONTROLLER_NAME + "-controller.properties";
@@ -80,6 +91,28 @@ public class SystemPersistenceTest {
private static final String TEST_TOPIC_FILE_BAK = TEST_TOPIC_FILE + ".bak";
/**
+ * Test JUnit Http Server File.
+ */
+ private static final String TEST_HTTP_SERVER_FILE = TEST_CONTROLLER_NAME
+ + FileSystemPersistence.PROPERTIES_FILE_HTTP_SERVER_SUFFIX;
+
+ /**
+ * Test JUnit Backup Http Server File.
+ */
+ private static final String TEST_HTTP_SERVER_FILE_BAK = TEST_HTTP_SERVER_FILE + ".bak";
+
+ /**
+ * Test JUnit Http Client File.
+ */
+ private static final String TEST_HTTP_CLIENT_FILE = TEST_CONTROLLER_NAME
+ + FileSystemPersistence.PROPERTIES_FILE_HTTP_CLIENT_SUFFIX;
+
+ /**
+ * Test JUnit Backup Http Server File.
+ */
+ private static final String TEST_HTTP_CLIENT_FILE_BAK = TEST_HTTP_CLIENT_FILE + ".bak";
+
+ /**
* Test JUnit Environment/Engine properties.
*/
private static final String ENV_PROPS = TEST_CONTROLLER_NAME;
@@ -188,7 +221,67 @@ public class SystemPersistenceTest {
}
@Test
- public void test4Controller() {
+ public void test4HttpServer() {
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+
+ Path httpServerPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_SERVER_FILE);
+
+ Path httpServerBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_SERVER_FILE_BAK);
+
+ assertTrue(Files.notExists(httpServerPath));
+ assertTrue(Files.notExists(httpServerBakPath));
+
+ SystemPersistenceConstants.getManager().storeHttpServer(TEST_HTTP_SERVER_NAME, new Properties());
+
+ assertTrue(Files.exists(httpServerPath));
+
+ Properties properties = SystemPersistenceConstants.getManager().getHttpServerProperties(TEST_HTTP_SERVER_NAME);
+ assertNotNull(properties);
+
+ List<Properties> httpServerPropsList = SystemPersistenceConstants.getManager().getHttpServerProperties();
+ assertEquals(1, httpServerPropsList.size());
+
+ SystemPersistenceConstants.getManager().backupHttpServer(TEST_HTTP_SERVER_NAME);
+ assertTrue(Files.exists(httpServerBakPath));
+
+ SystemPersistenceConstants.getManager().deleteHttpServer(TEST_HTTP_SERVER_NAME);
+ assertTrue(Files.notExists(httpServerPath));
+ }
+
+ @Test
+ public void test5HttpClient() {
+ SystemPersistenceConstants.getManager().setConfigurationDir(null);
+
+ Path httpClientPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_CLIENT_FILE);
+
+ Path httpClientBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_CLIENT_FILE_BAK);
+
+ assertTrue(Files.notExists(httpClientPath));
+ assertTrue(Files.notExists(httpClientBakPath));
+
+ SystemPersistenceConstants.getManager().storeHttpClient(TEST_HTTP_CLIENT_NAME, new Properties());
+
+ assertTrue(Files.exists(httpClientPath));
+
+ Properties properties = SystemPersistenceConstants.getManager().getHttpClientProperties(TEST_HTTP_CLIENT_NAME);
+ assertNotNull(properties);
+
+ List<Properties> httpClientPropsList = SystemPersistenceConstants.getManager().getHttpClientProperties();
+ assertEquals(1, httpClientPropsList.size());
+
+ SystemPersistenceConstants.getManager().backupHttpClient(TEST_HTTP_CLIENT_NAME);
+ assertTrue(Files.exists(httpClientBakPath));
+
+ SystemPersistenceConstants.getManager().deleteHttpClient(TEST_HTTP_CLIENT_NAME);
+ assertTrue(Files.notExists(httpClientPath));
+ }
+
+ @Test
+ public void test6Controller() {
SystemPersistenceConstants.getManager().setConfigurationDir(null);
Path controllerPath = Paths
@@ -233,6 +326,8 @@ public class SystemPersistenceTest {
}
SystemPersistenceConstants.getManager().deleteTopic(TEST_TOPIC_NAME);
+ SystemPersistenceConstants.getManager().deleteHttpServer(TEST_HTTP_SERVER_NAME);
+ SystemPersistenceConstants.getManager().deleteHttpClient(TEST_HTTP_CLIENT_NAME);
final Path testControllerBakPath =
Paths.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(),
@@ -240,6 +335,10 @@ public class SystemPersistenceTest {
final Path testTopicBakPath = Paths
.get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_TOPIC_FILE_BAK);
+ final Path testHttpServerBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_SERVER_FILE_BAK);
+ final Path testHttpClientBakPath = Paths
+ .get(SystemPersistenceConstants.getManager().getConfigurationPath().toString(), TEST_HTTP_CLIENT_FILE_BAK);
final Path policyEnginePath = Paths.get(OTHER_CONFIG_DIR, FileSystemPersistence.PROPERTIES_FILE_ENGINE);
final Path environmentPath = Paths.get(OTHER_CONFIG_DIR, ENV_PROPS_FILE);
@@ -247,6 +346,8 @@ public class SystemPersistenceTest {
Files.deleteIfExists(testControllerBakPath);
Files.deleteIfExists(testTopicBakPath);
+ Files.deleteIfExists(testHttpServerBakPath);
+ Files.deleteIfExists(testHttpClientBakPath);
Files.deleteIfExists(policyEnginePath);
Files.deleteIfExists(environmentPath);
Files.deleteIfExists(systemPath);
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 412e704a..b5c83e43 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
@@ -52,6 +52,8 @@ import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory;
import org.onap.policy.common.utils.gson.GsonTestUtils;
@@ -109,6 +111,10 @@ public class PolicyEngineManagerTest {
private HttpServletServer server2;
private List<HttpServletServer> servers;
private HttpServletServerFactory serverFactory;
+ private HttpClientFactory clientFactory;
+ private HttpClient client1;
+ private HttpClient client2;
+ private List<HttpClient> clients;
private TopicEndpoint endpoint;
private PolicyController controller;
private PolicyController controller2;
@@ -163,6 +169,10 @@ public class PolicyEngineManagerTest {
server2 = mock(HttpServletServer.class);
servers = Arrays.asList(server1, server2);
serverFactory = mock(HttpServletServerFactory.class);
+ client1 = mock(HttpClient.class);
+ client2 = mock(HttpClient.class);
+ clients = Arrays.asList(client1, client2);
+ clientFactory = mock(HttpClientFactory.class);
endpoint = mock(TopicEndpoint.class);
controller = mock(PolicyController.class);
controller2 = mock(PolicyController.class);
@@ -216,6 +226,16 @@ public class PolicyEngineManagerTest {
when(serverFactory.build(any())).thenReturn(servers);
+ when(client1.getPort()).thenReturn(2001);
+ when(client1.start()).thenReturn(true);
+ when(client1.stop()).thenReturn(true);
+
+ when(client2.getPort()).thenReturn(2002);
+ when(client2.start()).thenReturn(true);
+ when(client2.stop()).thenReturn(true);
+
+ when(clientFactory.inventory()).thenReturn(clients);
+
when(source1.getTopic()).thenReturn("source1-topic");
when(source1.start()).thenReturn(true);
when(source1.stop()).thenReturn(true);
@@ -515,6 +535,7 @@ public class PolicyEngineManagerTest {
when(endpoint.addTopicSources(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
when(endpoint.addTopicSinks(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
when(serverFactory.build(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
+ when(clientFactory.build(properties)).thenThrow(new IllegalArgumentException(EXPECTED));
mgr.configure(properties);
verify(prov2).afterConfigure(mgr);
@@ -763,6 +784,7 @@ public class PolicyEngineManagerTest {
when(prov1.beforeStart(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(prov1.afterStart(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(server1.waitedStart(anyLong())).thenThrow(new RuntimeException(EXPECTED));
+ when(client1.start()).thenThrow(new RuntimeException(EXPECTED));
when(source1.start()).thenThrow(new RuntimeException(EXPECTED));
when(sink1.start()).thenThrow(new RuntimeException(EXPECTED));
});
@@ -776,6 +798,9 @@ public class PolicyEngineManagerTest {
// servlet wait fails - still does everything
testStart(false, () -> when(server1.waitedStart(anyLong())).thenReturn(false));
+ // client fails - still does everything
+ testStart(false, () -> when(client1.start()).thenReturn(false));
+
// topic source is not started with start
testStart(true, () -> when(source1.start()).thenReturn(false));
@@ -841,6 +866,9 @@ public class PolicyEngineManagerTest {
verify(server1).waitedStart(anyLong());
verify(server2).waitedStart(anyLong());
+ verify(client1).start();
+ verify(client2).start();
+
verify(source1, never()).start();
verify(source2, never()).start();
@@ -866,6 +894,7 @@ public class PolicyEngineManagerTest {
when(prov1.beforeStop(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(prov1.afterStop(mgr)).thenThrow(new RuntimeException(EXPECTED));
when(server1.stop()).thenThrow(new RuntimeException(EXPECTED));
+ when(client1.stop()).thenThrow(new RuntimeException(EXPECTED));
when(source1.stop()).thenThrow(new RuntimeException(EXPECTED));
when(sink1.stop()).thenThrow(new RuntimeException(EXPECTED));
});
@@ -881,6 +910,7 @@ public class PolicyEngineManagerTest {
verify(sink1, never()).stop();
verify(endpoint, never()).stop();
verify(server1, never()).stop();
+ verify(client1, never()).stop();
verify(prov1, never()).afterStop(mgr);
verify(prov2, never()).afterStop(mgr);
@@ -902,6 +932,9 @@ public class PolicyEngineManagerTest {
// servlet fails to stop - still does everything
testStop(false, () -> when(server1.stop()).thenReturn(false));
+ // client fails to stop - still does everything
+ testStop(false, () -> when(client1.stop()).thenReturn(false));
+
// lock manager fails to stop - still does everything
testStop(false, () -> when(lockmgr.stop()).thenReturn(false));
@@ -954,6 +987,9 @@ public class PolicyEngineManagerTest {
verify(server1).stop();
verify(server2).stop();
+ verify(client1).stop();
+ verify(client2).stop();
+
verify(prov1).afterStop(mgr);
verify(prov2).afterStop(mgr);
}
@@ -1017,6 +1053,7 @@ public class PolicyEngineManagerTest {
verify(controllerFactory).shutdown();
verify(endpoint).shutdown();
verify(serverFactory).destroy();
+ verify(clientFactory).destroy();
assertTrue(jmxStopped);
@@ -1058,6 +1095,8 @@ public class PolicyEngineManagerTest {
verify(server1).shutdown();
verify(server2).shutdown();
+
+ verify(clientFactory).destroy();
}
@Test
@@ -1910,6 +1949,11 @@ public class PolicyEngineManagerTest {
}
@Override
+ protected HttpClientFactory getHttpClientFactory() {
+ return clientFactory;
+ }
+
+ @Override
protected PolicyControllerFactory getControllerFactory() {
return controllerFactory;
}