KNOX-1357 - Add configurable list of AutoDeploy topologies to deploy on server start
authorLarry McCay <lmccay@HW14155.home>
Thu, 14 Jun 2018 16:51:24 +0000 (12:51 -0400)
committerLarry McCay <lmccay@HW14155.home>
Thu, 14 Jun 2018 16:51:24 +0000 (12:51 -0400)
gateway-server/src/main/java/org/apache/knox/gateway/GatewayServer.java
gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java

index 2d6011e..fc92f48 100644 (file)
@@ -549,11 +549,18 @@ public class GatewayServer {
         "org.eclipse.jetty.annotations.AnnotationConfiguration" );
 
     // Load the current topologies.
+    // Redeploy autodeploy topologies.
     File topologiesDir = calculateAbsoluteTopologiesDir();
     log.loadingTopologiesFromDirectory(topologiesDir.getAbsolutePath());
     monitor = services.getService(GatewayServices.TOPOLOGY_SERVICE);
     monitor.addTopologyChangeListener(listener);
     monitor.reloadTopologies();
+    List<String> autoDeploys = config.getAutoDeployTopologyNames();
+    if (autoDeploys != null) {
+      for (String topologyName : autoDeploys) {
+        monitor.redeployTopologies(topologyName);
+      }
+    }
 
     final Collection<Topology> topologies = monitor.getTopologies();
     final Map<String, Integer> topologyPortMap = config.getGatewayPortMappings();
index e0898a2..815bb95 100644 (file)
@@ -250,6 +250,8 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
   static final String CUSTOM_FEDERATION_HEADER_NAME = GATEWAY_CONFIG_FILE_PREFIX + ".custom.federation.header.name";
   /* Default federated header name, see HeaderPreAuthFederationFilter.headerName */
   static final String DEFAULT_FEDERATION_HEADER_NAME = "SM_USER";
+  static final String AUTO_DEPLOY_TOPOLOGIES = GATEWAY_CONFIG_FILE_PREFIX + ".auto.deploy.topologies";
+  static final String DEFAULT_AUTO_DEPLOY_TOPOLOGIES = "manager,admin";
 
   private static List<String> DEFAULT_GLOBAL_RULES_SERVICES;
 
@@ -1074,4 +1076,17 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig {
     return get(CUSTOM_FEDERATION_HEADER_NAME, DEFAULT_FEDERATION_HEADER_NAME);
   }
 
+  @Override
+  public List<String> getAutoDeployTopologyNames() {
+    List<String> topologyNames = new ArrayList<>();
+
+    String value = get(AUTO_DEPLOY_TOPOLOGIES);
+    if (value == null) {
+      value = DEFAULT_AUTO_DEPLOY_TOPOLOGIES;
+    }
+    topologyNames.addAll(Arrays.asList(value.trim().split("\\s*,\\s*")));
+
+    return topologyNames;
+  }
+
 }
index 78ae227..8a43cb7 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.knox.gateway.config;
 
 import java.net.InetSocketAddress;
 import java.net.UnknownHostException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -409,4 +410,12 @@ public interface GatewayConfig {
    */
   String getFederationHeaderName();
 
+  /**
+   * Get the list of topology names that should be redeployed on restart.
+   * manager and admin are default topologies as they may depend on gateway-site.xml
+   * configuration for deployment time config. 
+   * @return
+   */
+  List<String> getAutoDeployTopologyNames();
+
 }
index f9afa32..ef5c1c4 100644 (file)
@@ -715,4 +715,12 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig {
     return "SM_USER";
   }
 
+  @Override
+  public List<String> getAutoDeployTopologyNames() {
+    ArrayList<String> names = new ArrayList<String>();
+    names.add("manager");
+    names.add("admin");
+    return null;
+  }
+
 }