knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pzamp...@apache.org
Subject knox git commit: KNOX-1229 - Ambari service discovery REST invocations need reasonable timeout
Date Wed, 28 Mar 2018 19:02:32 GMT
Repository: knox
Updated Branches:
  refs/heads/master 98dbfe990 -> c8a58d3c7


KNOX-1229 - Ambari service discovery REST invocations need reasonable timeout


Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/c8a58d3c
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/c8a58d3c
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/c8a58d3c

Branch: refs/heads/master
Commit: c8a58d3c73d9ea2afe85cb030f5d7bb1d1ad0188
Parents: 98dbfe9
Author: Phil Zampino <pzampino@apache.org>
Authored: Wed Mar 28 14:41:18 2018 -0400
Committer: Phil Zampino <pzampino@apache.org>
Committed: Wed Mar 28 14:48:23 2018 -0400

----------------------------------------------------------------------
 .../discovery/ambari/AmbariClientCommon.java    |  5 +--
 .../ambari/AmbariConfigurationMonitor.java      |  2 +-
 .../ambari/AmbariServiceDiscovery.java          | 19 ++++++-----
 .../ambari/AmbariServiceDiscoveryMessages.java  | 11 +++---
 .../topology/discovery/ambari/RESTInvoker.java  | 36 ++++++++++++++++++--
 .../ambari/AmbariServiceDiscoveryTest.java      | 16 +++++++--
 .../topology/impl/DefaultTopologyService.java   |  9 +++--
 .../simple/SimpleDescriptorHandler.java         | 29 ++++++++--------
 .../topology/DefaultTopologyServiceTest.java    |  3 +-
 .../PropertiesFileServiceDiscoveryTest.java     |  8 +++--
 .../test/extension/DummyServiceDiscovery.java   |  5 +--
 .../PropertiesFileServiceDiscovery.java         | 12 ++++---
 .../extension/SneakyServiceDiscoveryImpl.java   |  5 +--
 .../simple/SimpleDescriptorHandlerTest.java     | 27 ++++++++++-----
 .../topology/discovery/ServiceDiscovery.java    |  6 ++--
 .../SimpleDescriptorHandlerFuncTest.java        |  7 ++--
 16 files changed, 136 insertions(+), 64 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClientCommon.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClientCommon.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClientCommon.java
index c340056..9d4915b 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClientCommon.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariClientCommon.java
@@ -18,6 +18,7 @@ package org.apache.knox.gateway.topology.discovery.ambari;
 
 import net.minidev.json.JSONArray;
 import net.minidev.json.JSONObject;
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.services.security.AliasService;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig;
 
@@ -38,8 +39,8 @@ class AmbariClientCommon {
     private RESTInvoker restClient;
 
 
-    AmbariClientCommon(AliasService aliasService) {
-        this(new RESTInvoker(aliasService));
+    AmbariClientCommon(GatewayConfig config, AliasService aliasService) {
+        this(new RESTInvoker(config, aliasService));
     }
 
 

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
index b0aab4d..4a8d747 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariConfigurationMonitor.java
@@ -84,7 +84,7 @@ class AmbariConfigurationMonitor implements ClusterConfigurationMonitor
{
 
     AmbariConfigurationMonitor(GatewayConfig config, AliasService aliasService) {
         this.gatewayConfig   = config;
-        this.ambariClient    = new AmbariClientCommon(aliasService);
+        this.ambariClient    = new AmbariClientCommon(config, aliasService);
         this.internalMonitor = new PollingConfigAnalyzer(this);
 
         // Override the default polling interval if it has been configured

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
index bd794a3..4264bc6 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscovery.java
@@ -29,6 +29,7 @@ import java.util.Properties;
 
 import net.minidev.json.JSONArray;
 import net.minidev.json.JSONObject;
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.i18n.messages.MessagesFactory;
 import org.apache.knox.gateway.services.GatewayServices;
 import org.apache.knox.gateway.services.security.AliasService;
@@ -137,10 +138,10 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
      * construction time. This is called internally prior to discovery invocations to make
sure the clients have been
      * initialized.
      */
-    private void init() {
+    private void init(GatewayConfig config) {
         if (!isInitialized) {
             if (this.restClient == null) {
-                this.restClient = new RESTInvoker(aliasService);
+                this.restClient = new RESTInvoker(config, aliasService);
             }
             this.ambariClient = new AmbariClientCommon(restClient);
             this.configChangeMonitor = getConfigurationChangeMonitor();
@@ -188,24 +189,24 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
 
 
     @Override
-    public Map<String, Cluster> discover(ServiceDiscoveryConfig config) {
+    public Map<String, Cluster> discover(GatewayConfig gatewayConfig, ServiceDiscoveryConfig
discoveryConfig) {
         Map<String, Cluster> clusters = new HashMap<>();
 
-        init();
+        init(gatewayConfig);
 
-        String discoveryAddress = config.getAddress();
+        String discoveryAddress = discoveryConfig.getAddress();
 
         // Invoke Ambari REST API to discover the available clusters
         String clustersDiscoveryURL = String.format("%s" + AMBARI_CLUSTERS_URI, discoveryAddress);
 
-        JSONObject json = restClient.invoke(clustersDiscoveryURL, config.getUser(), config.getPasswordAlias());
+        JSONObject json = restClient.invoke(clustersDiscoveryURL, discoveryConfig.getUser(),
discoveryConfig.getPasswordAlias());
 
         // Parse the cluster names from the response, and perform the cluster discovery
         JSONArray clusterItems = (JSONArray) json.get("items");
         for (Object clusterItem : clusterItems) {
             String clusterName = (String) ((JSONObject)((JSONObject) clusterItem).get("Clusters")).get("cluster_name");
             try {
-                Cluster c = discover(config, clusterName);
+                Cluster c = discover(gatewayConfig, discoveryConfig, clusterName);
                 clusters.put(clusterName, c);
             } catch (Exception e) {
                 log.clusterDiscoveryError(clusterName, e);
@@ -217,12 +218,12 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
 
 
     @Override
-    public Cluster discover(ServiceDiscoveryConfig config, String clusterName) {
+    public Cluster discover(GatewayConfig gatewayConfig, ServiceDiscoveryConfig config, String
clusterName) {
         AmbariCluster cluster = new AmbariCluster(clusterName);
 
         Map<String, String> serviceComponents = new HashMap<>();
 
-        init();
+        init(gatewayConfig);
 
         String discoveryAddress = config.getAddress();
         String discoveryUser = config.getUser();

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryMessages.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryMessages.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryMessages.java
index 258f4e1..84a3462 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryMessages.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryMessages.java
@@ -59,14 +59,17 @@ public interface AmbariServiceDiscoveryMessages {
 
     @Message(level = MessageLevel.ERROR,
              text = "Encountered an error during cluster {0} discovery: {1}")
-    void clusterDiscoveryError(final String clusterName,
-                               @StackTrace(level = MessageLevel.DEBUG) Exception e);
+    void clusterDiscoveryError(final String clusterName, @StackTrace(level = MessageLevel.DEBUG)
Exception e);
+
+
+    @Message(level = MessageLevel.ERROR,
+             text = "REST invocation {0} timed out")
+    void restInvocationTimedOut(final String url, @StackTrace(level = MessageLevel.DEBUG)
Exception e);
 
 
     @Message(level = MessageLevel.DEBUG,
              text = "REST invocation {0} failed: {1}")
-    void restInvocationError(final String url,
-                             @StackTrace(level = MessageLevel.DEBUG) Exception e);
+    void restInvocationError(final String url, @StackTrace(level = MessageLevel.DEBUG) Exception
e);
 
 
     @Message(level = MessageLevel.ERROR,

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
index 221e907..b51bd1c 100644
--- a/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
+++ b/gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/RESTInvoker.java
@@ -18,7 +18,11 @@ package org.apache.knox.gateway.topology.discovery.ambari;
 
 import net.minidev.json.JSONObject;
 import net.minidev.json.JSONValue;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.conn.ConnectTimeoutException;
+import org.apache.http.impl.client.HttpClientBuilder;
 import org.apache.knox.gateway.config.ConfigurationException;
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.i18n.messages.MessagesFactory;
 import org.apache.knox.gateway.services.security.AliasService;
 import org.apache.knox.gateway.services.security.AliasServiceException;
@@ -39,13 +43,38 @@ class RESTInvoker {
 
     private static final AmbariServiceDiscoveryMessages log = MessagesFactory.get(AmbariServiceDiscoveryMessages.class);
 
-    private AliasService aliasService = null;
+    private static final int DEFAULT_TIMEOUT = 10000;
 
-    private CloseableHttpClient httpClient = org.apache.http.impl.client.HttpClients.createDefault();
+    private AliasService aliasService;
+
+    private CloseableHttpClient httpClient;
 
 
     RESTInvoker(AliasService aliasService) {
+        this(null, aliasService);
+    }
+
+
+    RESTInvoker(GatewayConfig config, AliasService aliasService) {
         this.aliasService = aliasService;
+
+        // Initialize the HTTP client
+        this.httpClient = HttpClientBuilder.create().setDefaultRequestConfig(getRequestConfig(config)).build();
+    }
+
+
+    private static RequestConfig getRequestConfig(GatewayConfig config) {
+        RequestConfig.Builder builder = RequestConfig.custom();
+        if (config != null) {
+            builder.setConnectTimeout(config.getHttpClientConnectionTimeout())
+                   .setConnectionRequestTimeout(config.getHttpClientConnectionTimeout())
+                   .setSocketTimeout(config.getHttpClientSocketTimeout());
+        } else {
+            builder.setConnectTimeout(DEFAULT_TIMEOUT)
+                   .setConnectionRequestTimeout(DEFAULT_TIMEOUT)
+                   .setSocketTimeout(DEFAULT_TIMEOUT);
+        }
+        return builder.build();
     }
 
 
@@ -121,7 +150,8 @@ class RESTInvoker {
             } else {
                 log.unexpectedRestResponseStatusCode(url, response.getStatusLine().getStatusCode());
             }
-
+        } catch (ConnectTimeoutException e) {
+            log.restInvocationTimedOut(url, e);
         } catch (IOException e) {
             log.restInvocationError(url, e);
         } finally {

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
index c93e8cf..a33f74d 100644
--- a/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
+++ b/gateway-discovery-ambari/src/test/java/org/apache/knox/gateway/topology/discovery/ambari/AmbariServiceDiscoveryTest.java
@@ -19,6 +19,7 @@ package org.apache.knox.gateway.topology.discovery.ambari;
 import net.minidev.json.JSONObject;
 import net.minidev.json.JSONValue;
 import org.apache.commons.io.FileUtils;
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig;
 import org.easymock.EasyMock;
@@ -50,12 +51,15 @@ public class AmbariServiceDiscoveryTest {
         final String clusterName = "testCluster";
         ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
+        GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.replay(gc);
+
         ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
         EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
         EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
         EasyMock.replay(sdc);
 
-        ServiceDiscovery.Cluster cluster = sd.discover(sdc, clusterName);
+        ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, clusterName);
         assertNotNull(cluster);
         assertEquals(clusterName, cluster.getName());
         assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
@@ -71,12 +75,15 @@ public class AmbariServiceDiscoveryTest {
         final String clusterName = "anotherCluster";
         ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
+        GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.replay(gc);
+
         ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
         EasyMock.expect(sdc.getAddress()).andReturn(discoveryAddress).anyTimes();
         EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
         EasyMock.replay(sdc);
 
-        Map<String, ServiceDiscovery.Cluster> clusters = sd.discover(sdc);
+        Map<String, ServiceDiscovery.Cluster> clusters = sd.discover(gc, sdc);
         assertNotNull(clusters);
         assertEquals(1, clusters.size());
         ServiceDiscovery.Cluster cluster = clusters.get(clusterName);
@@ -94,6 +101,9 @@ public class AmbariServiceDiscoveryTest {
         final String discoveryAddress = "http://ambarihost:8080";
         final String clusterName = "myCluster";
 
+        GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.replay(gc);
+
         // Create component config mapping override
         Properties compConfOverrideProps = new Properties();
         compConfOverrideProps.setProperty("DISCOVERY_TEST", "test-site");
@@ -135,7 +145,7 @@ public class AmbariServiceDiscoveryTest {
         EasyMock.replay(sdc);
 
         try {
-            ServiceDiscovery.Cluster cluster = sd.discover(sdc, clusterName);
+            ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, clusterName);
             assertNotNull(cluster);
             assertEquals(clusterName, cluster.getName());
             assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
index 28a7e61..5a01651 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
@@ -632,7 +632,7 @@ public class DefaultTopologyService
       initListener(topologiesDirectory, this, this);
 
       // Add support for conf/descriptors
-      descriptorsMonitor = new DescriptorsMonitor(topologiesDirectory, aliasService);
+      descriptorsMonitor = new DescriptorsMonitor(config, topologiesDirectory, aliasService);
       initListener(descriptorsDirectory,
                    descriptorsMonitor,
                    descriptorsMonitor);
@@ -798,6 +798,8 @@ public class DefaultTopologyService
       SUPPORTED_EXTENSIONS.add("yaml");
     }
 
+    private GatewayConfig gatewayConfig;
+
     private File topologiesDir;
 
     private AliasService aliasService;
@@ -809,7 +811,8 @@ public class DefaultTopologyService
       return SUPPORTED_EXTENSIONS.contains(FilenameUtils.getExtension(filename));
     }
 
-    public DescriptorsMonitor(File topologiesDir, AliasService aliasService) {
+    public DescriptorsMonitor(GatewayConfig config, File topologiesDir, AliasService aliasService)
{
+      this.gatewayConfig  = config;
       this.topologiesDir  = topologiesDir;
       this.aliasService   = aliasService;
     }
@@ -855,7 +858,7 @@ public class DefaultTopologyService
     public void onFileChange(File file) {
       try {
         // When a simple descriptor has been created or modified, generate the new topology
descriptor
-        Map<String, File> result = SimpleDescriptorHandler.handle(file, topologiesDir,
aliasService);
+        Map<String, File> result = SimpleDescriptorHandler.handle(gatewayConfig, file,
topologiesDir, aliasService);
         log.generatedTopologyForDescriptorChange(result.get(SimpleDescriptorHandler.RESULT_TOPOLOGY).getName(),
                                                  file.getName());
 

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
index bb09a1a..4edb2a7 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
@@ -34,6 +34,7 @@ import java.util.Map.Entry;
 import java.util.Set;
 
 import org.apache.knox.gateway.GatewayServer;
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.i18n.messages.MessagesFactory;
 import org.apache.knox.gateway.services.GatewayServices;
 import org.apache.knox.gateway.services.Service;
@@ -81,27 +82,27 @@ public class SimpleDescriptorHandler {
 
     private static Map<String, ServiceDiscovery> discoveryInstances = new HashMap<>();
 
-    public static Map<String, File> handle(File desc) throws IOException {
-        return handle(desc, NO_GATEWAY_SERVICES);
+    public static Map<String, File> handle(GatewayConfig config, File desc) throws
IOException {
+        return handle(config, desc, NO_GATEWAY_SERVICES);
     }
 
-    public static Map<String, File> handle(File desc, Service...gatewayServices) throws
IOException {
-        return handle(desc, desc.getParentFile(), gatewayServices);
+    public static Map<String, File> handle(GatewayConfig config, File desc, Service...gatewayServices)
throws IOException {
+        return handle(config, desc, desc.getParentFile(), gatewayServices);
     }
 
-    public static Map<String, File> handle(File desc, File destDirectory) throws IOException
{
-        return handle(desc, destDirectory, NO_GATEWAY_SERVICES);
+    public static Map<String, File> handle(GatewayConfig config, File desc, File destDirectory)
throws IOException {
+        return handle(config, desc, destDirectory, NO_GATEWAY_SERVICES);
     }
 
-    public static Map<String, File> handle(File desc, File destDirectory, Service...gatewayServices)
throws IOException {
-        return handle(SimpleDescriptorFactory.parse(desc.getAbsolutePath()), desc.getParentFile(),
destDirectory, gatewayServices);
+    public static Map<String, File> handle(GatewayConfig config, File desc, File destDirectory,
Service...gatewayServices) throws IOException {
+        return handle(config, SimpleDescriptorFactory.parse(desc.getAbsolutePath()), desc.getParentFile(),
destDirectory, gatewayServices);
     }
 
-    public static Map<String, File> handle(SimpleDescriptor desc, File srcDirectory,
File destDirectory) {
-        return handle(desc, srcDirectory, destDirectory, NO_GATEWAY_SERVICES);
+    public static Map<String, File> handle(GatewayConfig config, SimpleDescriptor desc,
File srcDirectory, File destDirectory) {
+        return handle(config, desc, srcDirectory, destDirectory, NO_GATEWAY_SERVICES);
     }
 
-    public static Map<String, File> handle(SimpleDescriptor desc, File srcDirectory,
File destDirectory, Service...gatewayServices) {
+    public static Map<String, File> handle(GatewayConfig config, SimpleDescriptor desc,
File srcDirectory, File destDirectory, Service...gatewayServices) {
 
         List<String> validServiceNames = new ArrayList<>();
         Map<String, String> serviceVersions = new HashMap<>();
@@ -111,7 +112,7 @@ public class SimpleDescriptorHandler {
         ServiceDiscovery.Cluster cluster = null;
         if (desc.getDiscoveryAddress() != null) {
             // Discover the cluster details required by the descriptor
-            cluster = performDiscovery(desc, gatewayServices);
+            cluster = performDiscovery(config, desc, gatewayServices);
             if (cluster == null) {
                 log.failedToDiscoverClusterServices(desc.getClusterName());
             }
@@ -176,7 +177,7 @@ public class SimpleDescriptorHandler {
     }
 
 
-    private static ServiceDiscovery.Cluster performDiscovery(SimpleDescriptor desc, Service...gatewayServices)
{
+    private static ServiceDiscovery.Cluster performDiscovery(GatewayConfig config, SimpleDescriptor
desc, Service...gatewayServices) {
         DefaultServiceDiscoveryConfig sdc = new DefaultServiceDiscoveryConfig(desc.getDiscoveryAddress());
         sdc.setUser(desc.getDiscoveryUser());
         sdc.setPasswordAlias(desc.getDiscoveryPasswordAlias());
@@ -194,7 +195,7 @@ public class SimpleDescriptorHandler {
             discoveryInstances.put(discoveryType, sd);
         }
 
-        return sd.discover(sdc, desc.getClusterName());
+        return sd.discover(config, sdc, desc.getClusterName());
     }
 
 

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
index 60cf633..91a017b 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
@@ -227,13 +227,12 @@ public class DefaultTopologyServiceTest {
       provider.addTopologyChangeListener(topoListener);
       provider.reloadTopologies();
 
-
       // Add a simple descriptor to the descriptors dir to verify topology generation and
loading (KNOX-1006)
       AliasService aliasService = EasyMock.createNiceMock(AliasService.class);
       EasyMock.expect(aliasService.getPasswordFromAliasForGateway(anyObject(String.class))).andReturn(null).anyTimes();
       EasyMock.replay(aliasService);
       DefaultTopologyService.DescriptorsMonitor dm =
-              new DefaultTopologyService.DescriptorsMonitor(topologyDir, aliasService);
+              new DefaultTopologyService.DescriptorsMonitor(config, topologyDir, aliasService);
 
       // Listener to simulate the topologies directory monitor, to notice when a topology
has been deleted
       provider.addTopologyChangeListener(new TestTopologyDeleteListener((DefaultTopologyService)provider));

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
index ca36cd8..59dd247 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
@@ -16,7 +16,8 @@
  */
 package org.apache.knox.gateway.topology.discovery;
 
-import org.apache.knox.gateway.services.security.impl.DefaultAliasService;
+import org.apache.knox.gateway.config.GatewayConfig;
+import org.easymock.EasyMock;
 import org.junit.Test;
 
 import java.io.File;
@@ -55,13 +56,16 @@ public class PropertiesFileServiceDiscoveryTest {
         ServiceDiscovery sd = ServiceDiscoveryFactory.get("PROPERTIES_FILE");
         assertNotNull(sd);
 
+        GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.replay(gc);
+
         String discoveryAddress = this.getClass().getName() + "__test-discovery-source.properties";
         File discoverySource = new File(discoveryAddress);
         try {
             config.store(new FileOutputStream(discoverySource), "Test discovery source for
PropertiesFileServiceDiscovery");
 
             ServiceDiscovery.Cluster c =
-                        sd.discover(new DefaultServiceDiscoveryConfig(discoverySource.getAbsolutePath()),
"mycluster");
+                    sd.discover(gc, new DefaultServiceDiscoveryConfig(discoverySource.getAbsolutePath()),
"mycluster");
             assertNotNull(c);
             for (String name : clusterProperties.keySet()) {
                 assertEquals(clusterProperties.get(name), c.getServiceURLs(name.split("\\.")[1]).get(0));

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/DummyServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/DummyServiceDiscovery.java
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/DummyServiceDiscovery.java
index 4ac88d3..9904492 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/DummyServiceDiscovery.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/DummyServiceDiscovery.java
@@ -16,6 +16,7 @@
  */
 package org.apache.knox.gateway.topology.discovery.test.extension;
 
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig;
 
@@ -65,12 +66,12 @@ public class DummyServiceDiscovery implements ServiceDiscovery {
     }
 
     @Override
-    public Map<String, Cluster> discover(ServiceDiscoveryConfig config) {
+    public Map<String, Cluster> discover(GatewayConfig gwConfig, ServiceDiscoveryConfig
config) {
         return CLUSTERS;
     }
 
     @Override
-    public Cluster discover(ServiceDiscoveryConfig config, String clusterName) {
+    public Cluster discover(GatewayConfig gwConfig, ServiceDiscoveryConfig config, String
clusterName) {
         return DUMMY;
     }
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
index 1d89733..3bf8117 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
@@ -17,6 +17,7 @@
  */
 package org.apache.knox.gateway.topology.discovery.test.extension;
 
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.services.security.AliasService;
 import org.apache.knox.gateway.topology.discovery.GatewayService;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
@@ -39,13 +40,14 @@ class PropertiesFileServiceDiscovery implements ServiceDiscovery {
     }
 
     @Override
-    public Map<String, ServiceDiscovery.Cluster> discover(ServiceDiscoveryConfig config)
{
+    public Map<String, ServiceDiscovery.Cluster> discover(GatewayConfig gatewayConfig,
+                                                          ServiceDiscoveryConfig discoveryConfig)
{
 
         Map<String, ServiceDiscovery.Cluster> result = new HashMap<>();
 
         Properties p = new Properties();
         try {
-            p.load(new FileInputStream(config.getAddress()));
+            p.load(new FileInputStream(discoveryConfig.getAddress()));
 
             Map<String, Map<String, List<String>>> clusters = new HashMap<>();
             for (Object key : p.keySet()) {
@@ -79,8 +81,10 @@ class PropertiesFileServiceDiscovery implements ServiceDiscovery {
 
 
     @Override
-    public ServiceDiscovery.Cluster discover(ServiceDiscoveryConfig config, String clusterName)
{
-        Map<String, ServiceDiscovery.Cluster> clusters = discover(config);
+    public ServiceDiscovery.Cluster discover(GatewayConfig          gwConfig,
+                                             ServiceDiscoveryConfig discoveryConfig,
+                                             String                 clusterName) {
+        Map<String, ServiceDiscovery.Cluster> clusters = discover(gwConfig, discoveryConfig);
         return clusters.get(clusterName);
     }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/SneakyServiceDiscoveryImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/SneakyServiceDiscoveryImpl.java
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/SneakyServiceDiscoveryImpl.java
index f57a1d8..f0cbcb9 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/SneakyServiceDiscoveryImpl.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/SneakyServiceDiscoveryImpl.java
@@ -16,6 +16,7 @@
  */
 package org.apache.knox.gateway.topology.discovery.test.extension;
 
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
 import org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig;
 
@@ -28,12 +29,12 @@ public class SneakyServiceDiscoveryImpl implements ServiceDiscovery {
     }
 
     @Override
-    public Map<String, Cluster> discover(ServiceDiscoveryConfig config) {
+    public Map<String, Cluster> discover(GatewayConfig gwConfig, ServiceDiscoveryConfig
config) {
         return null;
     }
 
     @Override
-    public Cluster discover(ServiceDiscoveryConfig config, String clusterName) {
+    public Cluster discover(GatewayConfig gwConfig, ServiceDiscoveryConfig config, String
clusterName) {
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
b/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
index f66de38..c19df66 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandlerTest.java
@@ -17,6 +17,7 @@
  */
 package org.apache.knox.gateway.topology.simple;
 
+import org.apache.knox.gateway.config.GatewayConfig;
 import org.apache.knox.gateway.topology.validation.TopologyValidator;
 import org.apache.knox.gateway.util.XmlUtils;
 import java.io.ByteArrayInputStream;
@@ -45,7 +46,6 @@ import org.apache.commons.io.FileUtils;
 import org.easymock.EasyMock;
 import org.junit.Test;
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 import org.xml.sax.SAXException;
@@ -175,6 +175,9 @@ public class SimpleDescriptorHandlerTest {
             knoxssoParams.put("knoxsso.token.ttl", "100000");
             serviceParameters.put("KNOXSSO", knoxssoParams);
 
+            GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+            EasyMock.replay(gc);
+
             // Mock out the simple descriptor
             SimpleDescriptor testDescriptor = EasyMock.createNiceMock(SimpleDescriptor.class);
             EasyMock.expect(testDescriptor.getName()).andReturn("mysimpledescriptor").anyTimes();
@@ -198,9 +201,10 @@ public class SimpleDescriptorHandlerTest {
 
             // Invoke the simple descriptor handler
             Map<String, File> files =
-                           SimpleDescriptorHandler.handle(testDescriptor,
-                                                          providerConfig.getParentFile(),
// simple desc co-located with provider config
-                                                          destDir);
+               SimpleDescriptorHandler.handle(gc,
+                                              testDescriptor,
+                                              providerConfig.getParentFile(), // simple desc
co-located with provider config
+                                              destDir);
             topologyFile = files.get("topology");
 
             // Validate the resulting topology descriptor
@@ -347,6 +351,9 @@ public class SimpleDescriptorHandlerTest {
         try {
             File destDir = (new File(".")).getCanonicalFile();
 
+            GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+            EasyMock.replay(gc);
+
             // Mock out the simple descriptor
             SimpleDescriptor testDescriptor = EasyMock.createNiceMock(SimpleDescriptor.class);
             EasyMock.expect(testDescriptor.getName()).andReturn("mysimpledescriptor").anyTimes();
@@ -368,9 +375,10 @@ public class SimpleDescriptorHandlerTest {
 
             // Invoke the simple descriptor handler
             Map<String, File> files =
-                    SimpleDescriptorHandler.handle(testDescriptor,
-                                                   providerConfig.getParentFile(), // simple
desc co-located with provider config
-                                                   destDir);
+                SimpleDescriptorHandler.handle(gc,
+                                               testDescriptor,
+                                               providerConfig.getParentFile(), // simple
desc co-located with provider config
+                                               destDir);
 
             topologyFile = files.get("topology");
 
@@ -458,6 +466,9 @@ public class SimpleDescriptorHandlerTest {
 
         File destDir = new File(System.getProperty("java.io.tmpdir")).getCanonicalFile();
 
+        GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.replay(gc);
+
         // Mock out the simple descriptor
         SimpleDescriptor testDescriptor = EasyMock.createNiceMock(SimpleDescriptor.class);
         EasyMock.expect(testDescriptor.getName()).andReturn("mysimpledescriptor").anyTimes();
@@ -477,7 +488,7 @@ public class SimpleDescriptorHandlerTest {
 
         try {
             // Invoke the simple descriptor handler
-            SimpleDescriptorHandler.handle(testDescriptor, destDir, destDir);
+            SimpleDescriptorHandler.handle(gc, testDescriptor, destDir, destDir);
             fail("Expected an IllegalArgumentException because the provider configuration
reference is missing.");
         } catch (IllegalArgumentException e) {
             // Expected

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-spi/src/main/java/org/apache/knox/gateway/topology/discovery/ServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/topology/discovery/ServiceDiscovery.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/topology/discovery/ServiceDiscovery.java
index 14d6c75..b0e441b 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/topology/discovery/ServiceDiscovery.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/topology/discovery/ServiceDiscovery.java
@@ -16,6 +16,8 @@
  */
 package org.apache.knox.gateway.topology.discovery;
 
+import org.apache.knox.gateway.config.GatewayConfig;
+
 import java.util.List;
 import java.util.Map;
 
@@ -43,7 +45,7 @@ public interface ServiceDiscovery {
      *
      * @return A Map of the discovered service data, keyed by the cluster name.
      */
-    Map<String, Cluster> discover(ServiceDiscoveryConfig config);
+    Map<String, Cluster> discover(GatewayConfig gwConfig, ServiceDiscoveryConfig config);
 
 
     /**
@@ -54,7 +56,7 @@ public interface ServiceDiscovery {
      *
      * @return The discovered service data for the specified cluster
      */
-    Cluster discover(ServiceDiscoveryConfig config, String clusterName);
+    Cluster discover(GatewayConfig gwConfig, ServiceDiscoveryConfig config, String clusterName);
 
 
     /**

http://git-wip-us.apache.org/repos/asf/knox/blob/c8a58d3c/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
b/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
index 5b29e19..33e3c1e 100644
--- a/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/knox/gateway/SimpleDescriptorHandlerFuncTest.java
@@ -213,7 +213,8 @@ public class SimpleDescriptorHandlerFuncTest {
 
       // Invoke the simple descriptor handler, which will also create the credential store
       // (because it doesn't exist) and the encryptQueryString alias
-      Map<String, File> files = SimpleDescriptorHandler.handle(testDescriptor,
+      Map<String, File> files = SimpleDescriptorHandler.handle(config,
+                                                               testDescriptor,
                                                                providerConfig.getParentFile(),
                                                                destDir);
       topologyFile = files.get("topology");
@@ -262,12 +263,12 @@ public class SimpleDescriptorHandlerFuncTest {
     }
 
     @Override
-    public Map<String, Cluster> discover(ServiceDiscoveryConfig config) {
+    public Map<String, Cluster> discover(GatewayConfig gwConfig, ServiceDiscoveryConfig
config) {
       return Collections.emptyMap();
     }
 
     @Override
-    public Cluster discover(ServiceDiscoveryConfig config, String clusterName) {
+    public Cluster discover(GatewayConfig gwConfig, ServiceDiscoveryConfig config, String
clusterName) {
       return null;
     }
   }


Mime
View raw message