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-1266 - Employ gateway-site config for default discovery address and cluster values
Date Fri, 11 May 2018 03:17:18 GMT
Repository: knox
Updated Branches:
  refs/heads/master f7f6a21c4 -> 1d5eae8ee


KNOX-1266 - Employ gateway-site config for default discovery address and cluster values


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

Branch: refs/heads/master
Commit: 1d5eae8ee896e6eb7cc7b78beb9fd0fdf56dde39
Parents: f7f6a21
Author: Phil Zampino <pzampino@apache.org>
Authored: Thu May 10 23:01:00 2018 -0400
Committer: Phil Zampino <pzampino@apache.org>
Committed: Thu May 10 23:02:30 2018 -0400

----------------------------------------------------------------------
 .../ambari/AmbariServiceDiscovery.java          | 32 ++----------
 .../ambari/AmbariServiceDiscoveryTest.java      | 53 +++++---------------
 .../gateway/config/impl/GatewayConfigImpl.java  | 14 ++++++
 .../knox/gateway/config/GatewayConfig.java      | 16 +++++-
 .../apache/knox/gateway/GatewayTestConfig.java  | 12 ++++-
 5 files changed, 56 insertions(+), 71 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/knox/blob/1d5eae8e/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 9f40f8c..4deb25f 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
@@ -33,7 +33,6 @@ 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;
-import org.apache.knox.gateway.services.security.AliasServiceException;
 import org.apache.knox.gateway.topology.ClusterConfigurationMonitorService;
 import org.apache.knox.gateway.topology.discovery.ClusterConfigurationMonitor;
 import org.apache.knox.gateway.topology.discovery.GatewayService;
@@ -64,9 +63,6 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
 
     private static final AmbariServiceDiscoveryMessages log = MessagesFactory.get(AmbariServiceDiscoveryMessages.class);
 
-    private static final String DEFAULT_DISCOVERY_ADDRESS_ALIAS = "ambari.discovery.address";
-    private static final String DEFAULT_DISCOVERY_CLUSTER_ALIAS = "ambari.discovery.cluster";
-
     // Map of component names to service configuration types
     private static Map<String, String> componentServiceConfigs = new HashMap<>();
     static {
@@ -229,19 +225,9 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
         String discoveryUser = config.getUser();
         String discoveryPwdAlias = config.getPasswordAlias();
 
-        // Handle missing discovery address value with the default alias if it has been defined
+        // Handle missing discovery address value with the default if it has been defined
         if (discoveryAddress == null || discoveryAddress.isEmpty()) {
-            if (this.aliasService != null) {
-                try {
-                    char[] defaultAddress =
-                                this.aliasService.getPasswordFromAliasForGateway(DEFAULT_DISCOVERY_ADDRESS_ALIAS);
-                    if (defaultAddress != null) {
-                        discoveryAddress = new String(defaultAddress);
-                    }
-                } catch (AliasServiceException e) {
-                    log.aliasServiceError(DEFAULT_DISCOVERY_ADDRESS_ALIAS, e.getLocalizedMessage());
-                }
-            }
+            discoveryAddress = gatewayConfig.getDefaultDiscoveryAddress();
 
             // If no default address could be determined
             if (discoveryAddress == null) {
@@ -249,19 +235,9 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
             }
         }
 
-        // Handle missing discovery cluster value with the default alias if it has been defined
+        // Handle missing discovery cluster value with the default if it has been defined
         if (clusterName == null || clusterName.isEmpty()) {
-            if (this.aliasService != null) {
-                try {
-                    char[] defaultCluster =
-                                this.aliasService.getPasswordFromAliasForGateway(DEFAULT_DISCOVERY_CLUSTER_ALIAS);
-                    if (defaultCluster != null) {
-                        clusterName = new String(defaultCluster);
-                    }
-                } catch (AliasServiceException e) {
-                    log.aliasServiceError(DEFAULT_DISCOVERY_CLUSTER_ALIAS, e.getLocalizedMessage());
-                }
-            }
+            clusterName = gatewayConfig.getDefaultDiscoveryCluster();
 
             // If no default cluster could be determined
             if (clusterName == null) {

http://git-wip-us.apache.org/repos/asf/knox/blob/1d5eae8e/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 dd49e72..40eecdd 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
@@ -77,18 +77,11 @@ public class AmbariServiceDiscoveryTest {
         final String discoveryAddress = "http://ambarihost:8080";
         final String clusterName = "testCluster";
 
-        AliasService as = EasyMock.createNiceMock(AliasService.class);
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.address"))
-                .andReturn(discoveryAddress.toCharArray())
-                .anyTimes();
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.cluster"))
-                .andReturn(clusterName.toCharArray())
-                .anyTimes();
-        EasyMock.replay(as);
-
-        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
         GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.expect(gc.getDefaultDiscoveryAddress()).andReturn(discoveryAddress).anyTimes();
+        EasyMock.expect(gc.getDefaultDiscoveryCluster()).andReturn(clusterName).anyTimes();
         EasyMock.replay(gc);
 
         ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
@@ -108,18 +101,11 @@ public class AmbariServiceDiscoveryTest {
         final String discoveryAddress = "http://ambarihost:8080";
         final String clusterName = "testCluster";
 
-        AliasService as = EasyMock.createNiceMock(AliasService.class);
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.address"))
-                .andReturn(discoveryAddress.toCharArray())
-                .anyTimes();
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.cluster"))
-                .andReturn(clusterName.toCharArray())
-                .anyTimes();
-        EasyMock.replay(as);
-
-        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
         GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.expect(gc.getDefaultDiscoveryAddress()).andReturn(discoveryAddress).anyTimes();
+        EasyMock.expect(gc.getDefaultDiscoveryCluster()).andReturn(clusterName).anyTimes();
         EasyMock.replay(gc);
 
         ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
@@ -140,18 +126,11 @@ public class AmbariServiceDiscoveryTest {
         final String discoveryAddress = "http://ambarihost:8080";
         final String clusterName = "testCluster";
 
-        AliasService as = EasyMock.createNiceMock(AliasService.class);
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.address"))
-                .andReturn(discoveryAddress.toCharArray())
-                .anyTimes();
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.cluster"))
-                .andReturn(clusterName.toCharArray())
-                .anyTimes();
-        EasyMock.replay(as);
-
-        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
         GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.expect(gc.getDefaultDiscoveryAddress()).andReturn(discoveryAddress).anyTimes();
+        EasyMock.expect(gc.getDefaultDiscoveryCluster()).andReturn(clusterName).anyTimes();
         EasyMock.replay(gc);
 
         ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
@@ -191,10 +170,7 @@ public class AmbariServiceDiscoveryTest {
     public void testSingleClusterDiscoveryWithMissingAddress() throws Exception {
         final String clusterName = "testCluster";
 
-        AliasService as = EasyMock.createNiceMock(AliasService.class);
-        EasyMock.replay(as);
-
-        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
         GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
         EasyMock.replay(gc);
@@ -213,15 +189,10 @@ public class AmbariServiceDiscoveryTest {
         final String discoveryAddress = "http://ambarihost:8080";
         final String clusterName = "testCluster";
 
-        AliasService as = EasyMock.createNiceMock(AliasService.class);
-        EasyMock.expect(as.getPasswordFromAliasForGateway("ambari.discovery.address"))
-                .andReturn(discoveryAddress.toCharArray())
-                .anyTimes();
-        EasyMock.replay(as);
-
-        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+        ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName);
 
         GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+        EasyMock.expect(gc.getDefaultDiscoveryAddress()).andReturn(discoveryAddress).anyTimes();
         EasyMock.replay(gc);
 
         ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);

http://git-wip-us.apache.org/repos/asf/knox/blob/1d5eae8e/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
index baa0507..56440f2 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/config/impl/GatewayConfigImpl.java
@@ -234,6 +234,10 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   static final String REMOTE_CONFIG_MONITOR_CLIENT_ALLOW_READ_ACCESS =
                                                   REMOTE_CONFIG_MONITOR_CLIENT_NAME + ".allowUnauthenticatedReadAccess";
 
+  /* @since 1.1.0 Default discovery configuration */
+  static final String DEFAULT_DISCOVERY_ADDRESS = GATEWAY_CONFIG_FILE_PREFIX + ".discovery.default.address";
+  static final String DEFAULT_DISCOVERY_CLUSTER = GATEWAY_CONFIG_FILE_PREFIX + ".discovery.default.cluster";
+
   private static List<String> DEFAULT_GLOBAL_RULES_SERVICES;
 
 
@@ -955,6 +959,16 @@ public class GatewayConfigImpl extends Configuration implements GatewayConfig
{
   }
 
   @Override
+  public String getDefaultDiscoveryAddress() {
+    return getVar(DEFAULT_DISCOVERY_ADDRESS, null);
+  }
+
+  @Override
+  public String getDefaultDiscoveryCluster() {
+    return getVar(DEFAULT_DISCOVERY_CLUSTER, null);
+  }
+
+  @Override
   public int getClusterMonitorPollingInterval(String type) {
     return getInt(CLUSTER_CONFIG_MONITOR_PREFIX + type.toLowerCase() + CLUSTER_CONFIG_MONITOR_INTERVAL_SUFFIX,
-1);
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/1d5eae8e/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
----------------------------------------------------------------------
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
index c727b90..980f602 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/config/GatewayConfig.java
@@ -313,7 +313,21 @@ public interface GatewayConfig {
    * @return
    */
   boolean isGatewayServerHeaderEnabled();
-  
+
+  /**
+   * Determine the default address for discovering service endpoint details.
+   *
+   * @return A valid discovery source address, or null (because this property is optional).
+   */
+  String getDefaultDiscoveryAddress();
+
+  /**
+   * Determine the default target cluster for discovering service endpoint details.
+   *
+   * @return A valid cluster name, or null (because this property is optional).
+   */
+  String getDefaultDiscoveryCluster();
+
   /**
    *
    * @param type The type of cluster configuration monitor for which the interval should
be returned.

http://git-wip-us.apache.org/repos/asf/knox/blob/1d5eae8e/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
----------------------------------------------------------------------
diff --git a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
index 9659fe0..1b198c9 100644
--- a/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
+++ b/gateway-test-release-utils/src/main/java/org/apache/knox/gateway/GatewayTestConfig.java
@@ -608,7 +608,17 @@ public class GatewayTestConfig extends Configuration implements GatewayConfig
{
 
   @Override
   public boolean isGatewayServerHeaderEnabled() {
-	return false;
+	  return false;
+  }
+
+  @Override
+  public String getDefaultDiscoveryAddress() {
+    return null;
+  }
+
+  @Override
+  public String getDefaultDiscoveryCluster() {
+    return null;
   }
 
   @Override


Mime
View raw message