You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by pz...@apache.org on 2018/05/09 18:55:35 UTC
knox git commit: KNOX-1266 - Support aliases for default discovery
address and cluster name
Repository: knox
Updated Branches:
refs/heads/master c06cebd7e -> 4bdf635ce
KNOX-1266 - Support aliases for default discovery address and cluster name
Project: http://git-wip-us.apache.org/repos/asf/knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/knox/commit/4bdf635c
Tree: http://git-wip-us.apache.org/repos/asf/knox/tree/4bdf635c
Diff: http://git-wip-us.apache.org/repos/asf/knox/diff/4bdf635c
Branch: refs/heads/master
Commit: 4bdf635cedd6da93d2ea0b3a629749838f3b41ba
Parents: c06cebd
Author: Phil Zampino <pz...@apache.org>
Authored: Wed May 9 14:41:51 2018 -0400
Committer: Phil Zampino <pz...@apache.org>
Committed: Wed May 9 14:41:51 2018 -0400
----------------------------------------------------------------------
.../ambari/AmbariServiceDiscovery.java | 181 ++++++++++++-------
.../ambari/AmbariServiceDiscoveryMessages.java | 13 ++
.../ambari/AmbariServiceDiscoveryTest.java | 179 ++++++++++++++++++
.../simple/SimpleDescriptorHandler.java | 10 +-
.../simple/SimpleDescriptorMessages.java | 12 +-
.../simple/SimpleDescriptorHandlerTest.java | 2 +
6 files changed, 318 insertions(+), 79 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/knox/blob/4bdf635c/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 392909d..9f40f8c 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,6 +33,7 @@ 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;
@@ -63,6 +64,9 @@ 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 {
@@ -219,89 +223,134 @@ class AmbariServiceDiscovery implements ServiceDiscovery {
@Override
public Cluster discover(GatewayConfig gatewayConfig, ServiceDiscoveryConfig config, String clusterName) {
- AmbariCluster cluster = new AmbariCluster(clusterName);
-
- Map<String, String> serviceComponents = new HashMap<>();
-
- init(gatewayConfig);
+ AmbariCluster cluster = null;
String discoveryAddress = config.getAddress();
String discoveryUser = config.getUser();
String discoveryPwdAlias = config.getPasswordAlias();
- Map<String, List<String>> componentHostNames = new HashMap<>();
- String hostRolesURL = String.format("%s" + AMBARI_HOSTROLES_URI, discoveryAddress, clusterName);
- JSONObject hostRolesJSON = restClient.invoke(hostRolesURL, discoveryUser, discoveryPwdAlias);
- if (hostRolesJSON != null) {
- // Process the host roles JSON
- JSONArray items = (JSONArray) hostRolesJSON.get("items");
- for (Object obj : items) {
- JSONArray components = (JSONArray) ((JSONObject) obj).get("components");
- for (Object component : components) {
- JSONArray hostComponents = (JSONArray) ((JSONObject) component).get("host_components");
- for (Object hostComponent : hostComponents) {
- JSONObject hostRoles = (JSONObject) ((JSONObject) hostComponent).get("HostRoles");
- String serviceName = (String) hostRoles.get("service_name");
- String componentName = (String) hostRoles.get("component_name");
-
- serviceComponents.put(componentName, serviceName);
-
- // Assuming public host name is more applicable than host_name
- String hostName = (String) hostRoles.get("public_host_name");
- if (hostName == null) {
- // Some (even slightly) older versions of Ambari/HDP do not return public_host_name,
- // so fall back to host_name in those cases.
- hostName = (String) hostRoles.get("host_name");
- }
+ // Handle missing discovery address value with the default alias 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());
+ }
+ }
+
+ // If no default address could be determined
+ if (discoveryAddress == null) {
+ log.missingDiscoveryAddress();
+ }
+ }
+
+ // Handle missing discovery cluster value with the default alias 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());
+ }
+ }
+
+ // If no default cluster could be determined
+ if (clusterName == null) {
+ log.missingDiscoveryCluster();
+ }
+ }
+
+ // There must be a discovery address and cluster or discovery cannot be performed
+ if (discoveryAddress != null && clusterName != null) {
+ cluster = new AmbariCluster(clusterName);
+
+ Map<String, String> serviceComponents = new HashMap<>();
+
+ init(gatewayConfig);
+
+ Map<String, List<String>> componentHostNames = new HashMap<>();
+ String hostRolesURL = String.format("%s" + AMBARI_HOSTROLES_URI, discoveryAddress, clusterName);
+ JSONObject hostRolesJSON = restClient.invoke(hostRolesURL, discoveryUser, discoveryPwdAlias);
+ if (hostRolesJSON != null) {
+ // Process the host roles JSON
+ JSONArray items = (JSONArray) hostRolesJSON.get("items");
+ for (Object obj : items) {
+ JSONArray components = (JSONArray) ((JSONObject) obj).get("components");
+ for (Object component : components) {
+ JSONArray hostComponents = (JSONArray) ((JSONObject) component).get("host_components");
+ for (Object hostComponent : hostComponents) {
+ JSONObject hostRoles = (JSONObject) ((JSONObject) hostComponent).get("HostRoles");
+ String serviceName = (String) hostRoles.get("service_name");
+ String componentName = (String) hostRoles.get("component_name");
+
+ serviceComponents.put(componentName, serviceName);
+
+ // Assuming public host name is more applicable than host_name
+ String hostName = (String) hostRoles.get("public_host_name");
+ if (hostName == null) {
+ // Some (even slightly) older versions of Ambari/HDP do not return public_host_name,
+ // so fall back to host_name in those cases.
+ hostName = (String) hostRoles.get("host_name");
+ }
- if (hostName != null) {
- log.discoveredServiceHost(serviceName, hostName);
- if (!componentHostNames.containsKey(componentName)) {
- componentHostNames.put(componentName, new ArrayList<>());
+ if (hostName != null) {
+ log.discoveredServiceHost(serviceName, hostName);
+ if (!componentHostNames.containsKey(componentName)) {
+ componentHostNames.put(componentName, new ArrayList<>());
+ }
+ componentHostNames.get(componentName).add(hostName);
}
- componentHostNames.get(componentName).add(hostName);
}
}
}
}
- }
- // Service configurations
- Map<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfigurations =
- ambariClient.getActiveServiceConfigurations(discoveryAddress,
- clusterName,
- discoveryUser,
- discoveryPwdAlias);
- for (Entry<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfiguration : serviceConfigurations.entrySet()) {
- for (Map.Entry<String, AmbariCluster.ServiceConfiguration> serviceConfig : serviceConfiguration.getValue().entrySet()) {
- cluster.addServiceConfiguration(serviceConfiguration.getKey(), serviceConfig.getKey(), serviceConfig.getValue());
+ // Service configurations
+ Map<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfigurations =
+ ambariClient.getActiveServiceConfigurations(discoveryAddress,
+ clusterName,
+ discoveryUser,
+ discoveryPwdAlias);
+ for (Entry<String, Map<String, AmbariCluster.ServiceConfiguration>> serviceConfiguration : serviceConfigurations.entrySet()) {
+ for (Map.Entry<String, AmbariCluster.ServiceConfiguration> serviceConfig : serviceConfiguration.getValue().entrySet()) {
+ cluster.addServiceConfiguration(serviceConfiguration.getKey(), serviceConfig.getKey(), serviceConfig.getValue());
+ }
}
- }
- // Construct the AmbariCluster model
- for (String componentName : serviceComponents.keySet()) {
- String serviceName = serviceComponents.get(componentName);
- List<String> hostNames = componentHostNames.get(componentName);
-
- Map<String, AmbariCluster.ServiceConfiguration> configs = serviceConfigurations.get(serviceName);
- String configType = componentServiceConfigs.get(componentName);
- if (configType != null) {
- AmbariCluster.ServiceConfiguration svcConfig = configs.get(configType);
- if (svcConfig != null) {
- AmbariComponent c = new AmbariComponent(componentName,
- svcConfig.getVersion(),
- clusterName,
- serviceName,
- hostNames,
- svcConfig.getProperties());
- cluster.addComponent(c);
+ // Construct the AmbariCluster model
+ for (String componentName : serviceComponents.keySet()) {
+ String serviceName = serviceComponents.get(componentName);
+ List<String> hostNames = componentHostNames.get(componentName);
+
+ Map<String, AmbariCluster.ServiceConfiguration> configs = serviceConfigurations.get(serviceName);
+ String configType = componentServiceConfigs.get(componentName);
+ if (configType != null) {
+ AmbariCluster.ServiceConfiguration svcConfig = configs.get(configType);
+ if (svcConfig != null) {
+ AmbariComponent c = new AmbariComponent(componentName,
+ svcConfig.getVersion(),
+ clusterName,
+ serviceName,
+ hostNames,
+ svcConfig.getProperties());
+ cluster.addComponent(c);
+ }
}
}
- }
- if (configChangeMonitor != null) {
- // Notify the cluster config monitor about these cluster configuration details
- configChangeMonitor.addClusterConfigVersions(cluster, config);
+ if (configChangeMonitor != null) {
+ // Notify the cluster config monitor about these cluster configuration details
+ configChangeMonitor.addClusterConfigVersions(cluster, config);
+ }
}
return cluster;
http://git-wip-us.apache.org/repos/asf/knox/blob/4bdf635c/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 84a3462..5cc764c 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
@@ -73,6 +73,19 @@ public interface AmbariServiceDiscoveryMessages {
@Message(level = MessageLevel.ERROR,
+ text = "No address for Ambari service discovery has been configured.")
+ void missingDiscoveryAddress();
+
+ @Message(level = MessageLevel.ERROR,
+ text = "No cluster for Ambari service discovery has been configured.")
+ void missingDiscoveryCluster();
+
+ @Message(level = MessageLevel.ERROR,
+ text = "Encountered an error attempting to determine the value for alias {0} : {1}")
+ void aliasServiceError(final String alias, final String error);
+
+
+ @Message(level = MessageLevel.ERROR,
text = "Encountered an error attempting to determine the user for alias {0} : {1}")
void aliasServiceUserError(final String alias, final String error);
http://git-wip-us.apache.org/repos/asf/knox/blob/4bdf635c/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 a33f74d..dd49e72 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
@@ -20,6 +20,7 @@ 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.services.security.AliasService;
import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
import org.apache.knox.gateway.topology.discovery.ServiceDiscoveryConfig;
import org.easymock.EasyMock;
@@ -27,6 +28,7 @@ import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
+import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -34,6 +36,7 @@ import java.util.Properties;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -70,6 +73,167 @@ public class AmbariServiceDiscoveryTest {
@Test
+ public void testSingleClusterDiscoveryWithDefaultAddress() throws Exception {
+ 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);
+
+ GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.replay(gc);
+
+ ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
+ EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
+ EasyMock.replay(sdc);
+
+ ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, clusterName);
+ assertNotNull(cluster);
+ assertEquals(clusterName, cluster.getName());
+ assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
+ assertEquals(6, ((AmbariCluster) cluster).getComponents().size());
+ }
+
+
+ @Test
+ public void testSingleClusterDiscoveryWithDefaultClusterName() throws Exception {
+ 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);
+
+ 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(gc, sdc, null);
+ assertNotNull(cluster);
+ assertEquals(clusterName, cluster.getName());
+ assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
+ assertEquals(6, ((AmbariCluster) cluster).getComponents().size());
+ }
+
+
+ @Test
+ public void testSingleClusterDiscoveryWithDefaultAddressAndClusterName() throws Exception {
+ 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);
+
+ GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.replay(gc);
+
+ ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
+ EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
+ EasyMock.replay(sdc);
+
+ ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, null);
+ assertNotNull(cluster);
+ assertEquals(clusterName, cluster.getName());
+ assertTrue(AmbariCluster.class.isAssignableFrom(cluster.getClass()));
+ assertEquals(6, ((AmbariCluster) cluster).getComponents().size());
+ }
+
+
+ @Test
+ public void testSingleClusterDiscoveryWithMissingAddressAndClusterName() throws Exception {
+ final String clusterName = "testCluster";
+
+ AliasService as = EasyMock.createNiceMock(AliasService.class);
+ EasyMock.replay(as);
+
+ ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+
+ GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.replay(gc);
+
+ ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
+ EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
+ EasyMock.replay(sdc);
+
+ ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, null);
+ assertNull(cluster);
+ }
+
+
+ @Test
+ public void testSingleClusterDiscoveryWithMissingAddress() throws Exception {
+ final String clusterName = "testCluster";
+
+ AliasService as = EasyMock.createNiceMock(AliasService.class);
+ EasyMock.replay(as);
+
+ ServiceDiscovery sd = new TestAmbariServiceDiscovery(clusterName, as);
+
+ GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.replay(gc);
+
+ ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
+ EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
+ EasyMock.replay(sdc);
+
+ ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, clusterName);
+ assertNull(cluster);
+ }
+
+
+ @Test
+ public void testSingleClusterDiscoveryWithMissingClusterName() throws Exception {
+ 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);
+
+ GatewayConfig gc = EasyMock.createNiceMock(GatewayConfig.class);
+ EasyMock.replay(gc);
+
+ ServiceDiscoveryConfig sdc = EasyMock.createNiceMock(ServiceDiscoveryConfig.class);
+ EasyMock.expect(sdc.getUser()).andReturn(null).anyTimes();
+ EasyMock.replay(sdc);
+
+ ServiceDiscovery.Cluster cluster = sd.discover(gc, sdc, null);
+ assertNull(cluster);
+ }
+
+
+ @Test
public void testBulkClusterDiscovery() throws Exception {
final String discoveryAddress = "http://ambarihost:8080";
final String clusterName = "anotherCluster";
@@ -206,6 +370,21 @@ public class AmbariServiceDiscoveryTest {
super(new TestRESTInvoker(clusterName));
}
+ TestAmbariServiceDiscovery(String clusterName, AliasService aliasService) {
+ super(new TestRESTInvoker(clusterName));
+
+ // Try to set the AliasService member, which is normally injected at runtime
+ try {
+ Field f = getClass().getSuperclass().getDeclaredField("aliasService");
+ if (f != null) {
+ f.setAccessible(true);
+ f.set(this, aliasService);
+ }
+ } catch (Exception e) {
+ //
+ }
+ }
+
}
private static final class TestRESTInvoker extends RESTInvoker {
http://git-wip-us.apache.org/repos/asf/knox/blob/4bdf635c/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 89020d8..19521e3 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
@@ -110,13 +110,9 @@ public class SimpleDescriptorHandler {
Map<String, Map<String, String>> serviceParams = new HashMap<>();
Map<String, List<String>> serviceURLs = new HashMap<>();
- ServiceDiscovery.Cluster cluster = null;
- if (desc.getDiscoveryAddress() != null) {
- // Discover the cluster details required by the descriptor
- cluster = performDiscovery(config, desc, gatewayServices);
- if (cluster == null) {
- log.failedToDiscoverClusterServices(desc.getClusterName());
- }
+ ServiceDiscovery.Cluster cluster = performDiscovery(config, desc, gatewayServices);
+ if (cluster == null) {
+ log.failedToDiscoverClusterServices(desc.getName());
}
for (SimpleDescriptor.Service descService : desc.getServices()) {
http://git-wip-us.apache.org/repos/asf/knox/blob/4bdf635c/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorMessages.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorMessages.java b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorMessages.java
index 869c27b..0ce44b3 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorMessages.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorMessages.java
@@ -25,8 +25,8 @@ import org.apache.knox.gateway.i18n.messages.StackTrace;
public interface SimpleDescriptorMessages {
@Message(level = MessageLevel.ERROR,
- text = "Service discovery for cluster {0} failed.")
- void failedToDiscoverClusterServices(final String cluster);
+ text = "Unable to complete service discovery for cluster {0}.")
+ void failedToDiscoverClusterServices(final String descriptorName);
@Message(level = MessageLevel.ERROR,
text = "No valid URLs were discovered for {0} in the {1} cluster.")
@@ -37,7 +37,7 @@ public interface SimpleDescriptorMessages {
void failedToResolveProviderConfigRef(final String providerConfigRef);
@Message(level = MessageLevel.ERROR,
- text = "Failed to parse the referenced provider configuration {0}: {1}")
+ text = "Failed to parse the referenced provider configuration {0}: {1}")
void failedToParseProviderConfig(final String providerConfigRef,
@StackTrace( level = MessageLevel.DEBUG ) Exception e);
@@ -52,12 +52,12 @@ public interface SimpleDescriptorMessages {
void failedToGenerateTopologyFromSimpleDescriptor(final String topologyFile,
@StackTrace( level = MessageLevel.DEBUG ) Exception e);
- @Message( level = MessageLevel.ERROR,
- text = "Error creating a password for query string encryption for {0}: {1}" )
+ @Message(level = MessageLevel.ERROR,
+ text = "Error creating a password for query string encryption for {0}: {1}" )
void exceptionCreatingPasswordForEncryption(String topologyName,
@StackTrace( level = MessageLevel.DEBUG) Exception e);
- @Message( level = MessageLevel.ERROR,
+ @Message(level = MessageLevel.ERROR,
text = "Failed to create a password for query string encryption for {0}." )
void unableCreatePasswordForEncryption(String topologyName);
http://git-wip-us.apache.org/repos/asf/knox/blob/4bdf635c/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 0063a4e..ec78155 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
@@ -18,6 +18,7 @@
package org.apache.knox.gateway.topology.simple;
import org.apache.knox.gateway.config.GatewayConfig;
+import org.apache.knox.gateway.topology.discovery.test.extension.DummyServiceDiscoveryType;
import org.apache.knox.gateway.topology.validation.TopologyValidator;
import org.apache.knox.gateway.util.XmlUtils;
import java.io.ByteArrayInputStream;
@@ -485,6 +486,7 @@ public class SimpleDescriptorHandlerTest {
// Mock out the simple descriptor
SimpleDescriptor testDescriptor = EasyMock.createNiceMock(SimpleDescriptor.class);
EasyMock.expect(testDescriptor.getName()).andReturn("mysimpledescriptor").anyTimes();
+ EasyMock.expect(testDescriptor.getDiscoveryType()).andReturn("DUMMY").anyTimes();
EasyMock.expect(testDescriptor.getDiscoveryUser()).andReturn(null).anyTimes();
EasyMock.expect(testDescriptor.getProviderConfig()).andReturn(null).anyTimes();
List<SimpleDescriptor.Service> serviceMocks = new ArrayList<>();