summaryrefslogtreecommitdiffstats
path: root/policy-management/src/main/java/org
diff options
context:
space:
mode:
authorjhh <jorge.hernandez-herrero@att.com>2020-03-02 21:45:18 -0600
committerjhh <jorge.hernandez-herrero@att.com>2020-03-02 21:47:52 -0600
commitf2f56be75cb55096acca3ab41222dc1fef47ea48 (patch)
tree0aa83d3c9e98198b0e2652957ee195524cb5ff9f /policy-management/src/main/java/org
parent300e6ff3003823e6efeaef73a48fa9b3234ca8a0 (diff)
http server/client management
This is to support the new actor architecture configuration. Issue-ID: POLICY-1625 Signed-off-by: jhh <jorge.hernandez-herrero@att.com> Change-Id: Ieda56be38b8572d75a5fbb3775067ab537310aa1
Diffstat (limited to 'policy-management/src/main/java/org')
-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
4 files changed, 213 insertions, 29 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();
}