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 2021/01/26 18:43:37 UTC
[knox] branch master updated: KNOX-2533 - Qualifying service params
for discovery improvements (#401)
This is an automated email from the ASF dual-hosted git repository.
pzampino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git
The following commit(s) were added to refs/heads/master by this push:
new 85d8236 KNOX-2533 - Qualifying service params for discovery improvements (#401)
85d8236 is described below
commit 85d82366bf489851a7e5e5e1c294d96f817ac98f
Author: Phil Zampino <pz...@apache.org>
AuthorDate: Tue Jan 26 13:43:28 2021 -0500
KNOX-2533 - Qualifying service params for discovery improvements (#401)
---
.../discovery/cm/ClouderaManagerCluster.java | 17 +-
.../ClouderaManagerServiceDiscoveryMessages.java | 4 +
.../topology/discovery/cm/ServiceModel.java | 11 +-
.../model/hdfs/NameNodeServiceModelGenerator.java | 2 +-
.../cm/model/solr/SolrServiceModelGenerator.java | 4 +-
.../discovery/cm/ClouderaManagerClusterTest.java | 175 +++++++++++++++++++++
.../hdfs/NameNodeServiceModelGeneratorTest.java | 6 +-
.../hdfs/WebHdfsServiceModelGeneratorTest.java | 6 +-
.../model/solr/SolrServiceModelGeneratorTest.java | 17 +-
.../gateway/topology/simple/SimpleDescriptor.java | 2 +
.../topology/simple/SimpleDescriptorHandler.java | 8 +-
11 files changed, 230 insertions(+), 22 deletions(-)
diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerCluster.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerCluster.java
index c26ee56..bd6beea 100644
--- a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerCluster.java
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerCluster.java
@@ -16,6 +16,7 @@
*/
package org.apache.knox.gateway.topology.discovery.cm;
+import org.apache.knox.gateway.i18n.messages.MessagesFactory;
import org.apache.knox.gateway.topology.discovery.ServiceDiscovery;
import org.apache.knox.gateway.topology.discovery.cm.collector.ServiceURLCollectors;
@@ -30,6 +31,9 @@ import java.util.Set;
*/
public class ClouderaManagerCluster implements ServiceDiscovery.Cluster {
+ private static final ClouderaManagerServiceDiscoveryMessages log =
+ MessagesFactory.get(ClouderaManagerServiceDiscoveryMessages.class);
+
private String name;
private Map<String, List<ServiceModel>> serviceModels = new HashMap<>();
@@ -60,8 +64,17 @@ public class ClouderaManagerCluster implements ServiceDiscovery.Cluster {
boolean isMatchingModel = true;
if (serviceParams != null) {
for (Map.Entry<String, String> serviceParam : serviceParams.entrySet()) {
- if (!serviceParam.getValue().equals(model.getQualifyingServiceParam(serviceParam.getKey()))) {
- isMatchingModel = false;
+ String serviceParamKey = serviceParam.getKey();
+ // If it's a qualifying service param, then perform the qualification check
+ if (serviceParamKey.startsWith(ServiceModel.QUALIFYING_SERVICE_PARAM_PREFIX)) {
+ if (!serviceParam.getValue().equals(model.getQualifyingServiceParam(serviceParamKey))) {
+ isMatchingModel = false;
+ log.qualifyingServiceParamMismatch(serviceName,
+ serviceParamKey,
+ serviceParam.getValue(),
+ model.getQualifyingServiceParam(serviceParamKey));
+ break;
+ }
}
}
}
diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryMessages.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryMessages.java
index d04c777..7c6782d 100644
--- a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryMessages.java
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerServiceDiscoveryMessages.java
@@ -101,6 +101,10 @@ public interface ClouderaManagerServiceDiscoveryMessages {
text = "No password configured for Cloudera Manager service discovery.")
void aliasServicePasswordNotFound();
+ @Message(level = MessageLevel.INFO,
+ text = "The value of the qualifying parameter {1} for service {0} does not match: Expected={2}, Actual={3}")
+ void qualifyingServiceParamMismatch(String serviceName, String paramName, String expectedValue, String actualValue);
+
@Message(level = MessageLevel.ERROR,
text = "Unable to access the ClouderaManager Configuration Change Monitor: {0}")
void errorAccessingConfigurationChangeMonitor(@StackTrace(level = MessageLevel.DEBUG) Exception e);
diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ServiceModel.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ServiceModel.java
index 0d379a0..1b311e8 100644
--- a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ServiceModel.java
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/ServiceModel.java
@@ -16,6 +16,8 @@
*/
package org.apache.knox.gateway.topology.discovery.cm;
+import org.apache.knox.gateway.topology.simple.SimpleDescriptor;
+
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@@ -29,6 +31,8 @@ public class ServiceModel {
public enum Type {API, UI}
+ public static final String QUALIFYING_SERVICE_PARAM_PREFIX = SimpleDescriptor.DISCOVERY_PARAM_PREFIX;
+
private static final String NULL_VALUE = "null";
private final Type type;
@@ -66,7 +70,9 @@ public class ServiceModel {
}
public void addQualifyingServiceParam(final String name, final String value) {
- qualifyingServiceParams.put(name, (value != null ? value : NULL_VALUE));
+ // Fix the name if it doesn't include the prefix
+ String paramName = name.startsWith(QUALIFYING_SERVICE_PARAM_PREFIX) ? name : QUALIFYING_SERVICE_PARAM_PREFIX + name;
+ qualifyingServiceParams.put(paramName, (value != null ? value : NULL_VALUE));
}
public void addServiceProperty(final String name, final String value) {
@@ -88,7 +94,8 @@ public class ServiceModel {
* @return The value of the metadata property associated with the model, which can be used to qualify service discovery.
*/
public String getQualifyingServiceParam(final String name) {
- return qualifyingServiceParams.get(name);
+ String paramName = name.startsWith(QUALIFYING_SERVICE_PARAM_PREFIX) ? name : QUALIFYING_SERVICE_PARAM_PREFIX + name;
+ return qualifyingServiceParams.get(paramName);
}
/**
diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGenerator.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGenerator.java
index c867809..2e75b53 100644
--- a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGenerator.java
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGenerator.java
@@ -31,7 +31,7 @@ public class NameNodeServiceModelGenerator extends AbstractServiceModelGenerator
public static final String SERVICE_TYPE = "HDFS";
public static final String ROLE_TYPE = "NAMENODE";
- static final String DISCOVERY_NAMESERVICE = "discovery-nameservice";
+ static final String DISCOVERY_NAMESERVICE = "nameservice";
static final String AUTOFAILOVER_ENABLED = "autofailover_enabled";
static final String NN_NAMESERVICE = "dfs_federation_namenode_nameservice";
diff --git a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGenerator.java b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGenerator.java
index 772d3d6..6733e85 100644
--- a/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGenerator.java
+++ b/gateway-discovery-cm/src/main/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGenerator.java
@@ -30,8 +30,8 @@ public class SolrServiceModelGenerator extends AbstractServiceModelGenerator {
public static final String SERVICE_TYPE = "SOLR";
public static final String ROLE_TYPE = "SOLR_SERVER";
- static final String DISCOVERY_SERVICE_NAME = "discovery-service-name";
- static final String DISCOVERY_SERVICE_DISPLAY_NAME = "discovery-service-display-name";
+ public static final String DISCOVERY_SERVICE_NAME = "service-name";
+ public static final String DISCOVERY_SERVICE_DISPLAY_NAME = "service-display-name";
static final String USE_SSL = "solr_use_ssl";
static final String HTTP_PORT = "solr_http_port";
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerClusterTest.java b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerClusterTest.java
new file mode 100644
index 0000000..d7f04e5
--- /dev/null
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/ClouderaManagerClusterTest.java
@@ -0,0 +1,175 @@
+/*
+ *
+ * * Licensed to the Apache Software Foundation (ASF) under one or more
+ * * contributor license agreements. See the NOTICE file distributed with this
+ * * work for additional information regarding copyright ownership. The ASF
+ * * licenses this file to you under the Apache License, Version 2.0 (the
+ * * "License"); you may not use this file except in compliance with the License.
+ * * You may obtain a copy of the License at
+ * *
+ * * http://www.apache.org/licenses/LICENSE-2.0
+ * *
+ * * Unless required by applicable law or agreed to in writing, software
+ * * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * * License for the specific language governing permissions and limitations under
+ * * the License.
+ *
+ */
+package org.apache.knox.gateway.topology.discovery.cm;
+
+import org.apache.knox.gateway.topology.discovery.cm.model.solr.SolrServiceModelGenerator;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.knox.gateway.topology.discovery.cm.ServiceModel.QUALIFYING_SERVICE_PARAM_PREFIX;
+import static org.apache.knox.gateway.topology.discovery.cm.model.solr.SolrServiceModelGenerator.DISCOVERY_SERVICE_DISPLAY_NAME;
+import static org.apache.knox.gateway.topology.discovery.cm.model.solr.SolrServiceModelGenerator.DISCOVERY_SERVICE_NAME;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ClouderaManagerClusterTest {
+
+ /**
+ * This is the default case, with no service parameters declared for the SOLR service.
+ */
+ @Test
+ public void testGetUnqualifiedMultipleSOLRServiceURLs_NoServiceParams() {
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-1", "SOLR-2"),
+ Collections.emptyMap(),
+ Arrays.asList("SOLR-1", "SOLR-2"));
+ }
+
+ /**
+ * Ensure that declared service parameters, which are NOT qualifying service parameters, do not affect the default
+ * discovery.
+ */
+ @Test
+ public void testGetUnqualifiedMultipleSOLRServiceURLs_NoDiscoveryServiceParams() {
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-3", "SOLR-7"),
+ Collections.singletonMap("test-param", "test-value"),
+ Arrays.asList("SOLR-3", "SOLR-7"));
+ }
+
+ /**
+ * Ensure that an incorrectly-specified SOLR service display name qualifying parameter results in no matching
+ * services, and consequently with no service URLs.
+ */
+ @Test
+ public void testGetIncorrectlyQualifiedSOLRServiceURLs() {
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-3", "SOLR-7"),
+ Collections.singletonMap(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME, "SOLR-5Display"),
+ Collections.emptyList());
+ }
+
+ /**
+ * Ensure that a correctly-specified SOLR service display name qualifying parameter is honored.
+ */
+ @Test
+ public void testGetDisplayNameQualifiedSOLRServiceURLs() {
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-3", "SOLR-7"),
+ Collections.singletonMap(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME, "SOLR-7Display"),
+ Collections.singletonList("SOLR-7"));
+ }
+
+ /**
+ * Ensure that a correctly-specified SOLR service name qualifying parameter is honored.
+ */
+ @Test
+ public void testGetServiceNameQualifiedSOLRServiceURLs() {
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-5", "SOLR-6"),
+ Collections.singletonMap(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_NAME, "SOLR-5"),
+ Collections.singletonList("SOLR-5"));
+ }
+
+ /**
+ * Ensure that a correctly-specified SOLR service name and display name qualifying parameters are honored.
+ */
+ @Test
+ public void testGetServiceAndDisplayNameQualifiedSOLRServiceURLs() {
+ Map<String, String> serviceParams = new HashMap<>();
+ serviceParams.put(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_NAME, "SOLR-6");
+ serviceParams.put(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME, "SOLR-6Display");
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-5", "SOLR-6"),
+ serviceParams,
+ Collections.singletonList("SOLR-6"));
+ }
+
+ /**
+ * Ensure that an incorrectly-specified service name qualifying parameter, even with a correctly-specified SOLR
+ * display name qualifying parameter, results in no matching services.
+ */
+ @Test
+ public void testGetServiceAndDisplayNameQualifiedSOLRServiceURLs_IncorrectServiceName() {
+ Map<String, String> serviceParams = new HashMap<>();
+ serviceParams.put(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_NAME, "SOLR-3");
+ serviceParams.put(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME, "SOLR-6Display");
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-5", "SOLR-6"),
+ serviceParams,
+ Collections.emptyList());
+ }
+
+ /**
+ * Ensure that an incorrectly-specified service display name qualifying parameter, even with a correctly-specified
+ * SOLR service name qualifying parameter, results in no matching services.
+ */
+ @Test
+ public void testGetServiceAndDisplayNameQualifiedSOLRServiceURLs_IncorrectDisplayName() {
+ Map<String, String> serviceParams = new HashMap<>();
+ serviceParams.put(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_NAME, "SOLR-6");
+ serviceParams.put(QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME, "SOLR-8Display");
+ doTestGetSOLRServiceURLs(Arrays.asList("SOLR-5", "SOLR-6"),
+ serviceParams,
+ Collections.emptyList());
+ }
+
+ /**
+ * Test the SOLR service URL discovery based on the specified parameters.
+ *
+ * @param serviceNames The name(s) of the SOLR service(s) in the cluster.
+ * @param serviceParams Any service parameter declarations (i.e., from the supposed descriptor)
+ * @param serviceNamesToExpectURLs The service(s) for which URLs are expected.
+ */
+ private void doTestGetSOLRServiceURLs(final List<String> serviceNames,
+ final Map<String, String> serviceParams,
+ final List<String> serviceNamesToExpectURLs) {
+ final Set<ServiceModel> testSolrServiceModels = new HashSet<>();
+ final List<String> expectedURLs = new ArrayList<>();
+
+ for (String serviceName : serviceNames) {
+ ServiceModel model = createSOLRServiceModel("http://" + serviceName + "-host:1234/solr");
+ model.addQualifyingServiceParam(DISCOVERY_SERVICE_NAME, serviceName);
+ model.addQualifyingServiceParam(DISCOVERY_SERVICE_DISPLAY_NAME, serviceName + "Display");
+ testSolrServiceModels.add(model);
+ if (serviceNamesToExpectURLs.contains(serviceName)) {
+ expectedURLs.add(model.getServiceUrl());
+ }
+ }
+
+ final ClouderaManagerCluster cluster = new ClouderaManagerCluster("test");
+ cluster.addServiceModels(testSolrServiceModels);
+
+ List<String> solrURLs = cluster.getServiceURLs("SOLR", serviceParams);
+ assertEquals("Unexpected URL count.", expectedURLs.size(), solrURLs.size());
+ for (String expectedURL : expectedURLs) {
+ assertTrue("Missing expected URL: " + expectedURL, solrURLs.contains(expectedURL));
+ }
+ }
+
+ private static ServiceModel createSOLRServiceModel(final String url) {
+ return new ServiceModel(ServiceModel.Type.API,
+ SolrServiceModelGenerator.SERVICE,
+ SolrServiceModelGenerator.SERVICE_TYPE,
+ SolrServiceModelGenerator.ROLE_TYPE,
+ url);
+ }
+
+}
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGeneratorTest.java b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGeneratorTest.java
index 928e0d9..23a67e2 100644
--- a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGeneratorTest.java
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/NameNodeServiceModelGeneratorTest.java
@@ -41,11 +41,13 @@ public class NameNodeServiceModelGeneratorTest extends AbstractServiceModelGener
validateServiceModel(generated, serviceConfig, roleConfig);
// Validate model metadata properties
+ final String qualifyingProperty =
+ ServiceModel.QUALIFYING_SERVICE_PARAM_PREFIX + NameNodeServiceModelGenerator.DISCOVERY_NAMESERVICE;
Map<String, String> modelProps = generated.getQualifyingServiceParams();
assertEquals("Expected one service model properties", 1, modelProps.size());
- assertEquals("Expected " + NameNodeServiceModelGenerator.DISCOVERY_NAMESERVICE + " model property.",
+ assertEquals("Expected " + qualifyingProperty + " model property.",
roleConfig.get(NameNodeServiceModelGenerator.NN_NAMESERVICE),
- modelProps.get(NameNodeServiceModelGenerator.DISCOVERY_NAMESERVICE));
+ modelProps.get(qualifyingProperty));
}
@Test
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/WebHdfsServiceModelGeneratorTest.java b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/WebHdfsServiceModelGeneratorTest.java
index 12b33f5..19b92d9 100644
--- a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/WebHdfsServiceModelGeneratorTest.java
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/hdfs/WebHdfsServiceModelGeneratorTest.java
@@ -74,11 +74,13 @@ public class WebHdfsServiceModelGeneratorTest extends AbstractServiceModelGenera
validateServiceModel(generated, serviceConfig, roleConfig, false);
// Validate model metadata properties
+ final String qualifyingProperty =
+ ServiceModel.QUALIFYING_SERVICE_PARAM_PREFIX + WebHdfsServiceModelGenerator.DISCOVERY_NAMESERVICE;
Map<String, String> modelProps = generated.getQualifyingServiceParams();
assertEquals("Expected one service model properties", 1, modelProps.size());
- assertEquals("Expected " + NameNodeServiceModelGenerator.DISCOVERY_NAMESERVICE + " model property.",
+ assertEquals("Expected " + qualifyingProperty + " model property.",
roleConfig.get(WebHdfsServiceModelGenerator.NN_NAMESERVICE),
- modelProps.get(WebHdfsServiceModelGenerator.DISCOVERY_NAMESERVICE));
+ modelProps.get(qualifyingProperty));
}
@Override
diff --git a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGeneratorTest.java b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGeneratorTest.java
index 4c2d2fc..d05f9c0 100644
--- a/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGeneratorTest.java
+++ b/gateway-discovery-cm/src/test/java/org/apache/knox/gateway/topology/discovery/cm/model/solr/SolrServiceModelGeneratorTest.java
@@ -24,6 +24,9 @@ import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
+import static org.apache.knox.gateway.topology.discovery.cm.ServiceModel.QUALIFYING_SERVICE_PARAM_PREFIX;
+import static org.apache.knox.gateway.topology.discovery.cm.model.solr.SolrServiceModelGenerator.DISCOVERY_SERVICE_DISPLAY_NAME;
+import static org.apache.knox.gateway.topology.discovery.cm.model.solr.SolrServiceModelGenerator.DISCOVERY_SERVICE_NAME;
import static org.junit.Assert.assertEquals;
public class SolrServiceModelGeneratorTest extends AbstractServiceModelGeneratorTest {
@@ -40,14 +43,16 @@ public class SolrServiceModelGeneratorTest extends AbstractServiceModelGenerator
validateServiceModel(generated, serviceConfig, roleConfig);
// Validate model metadata properties
+ final String serviceNameQualifier = QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_NAME;
+ final String displayNameQualifier = QUALIFYING_SERVICE_PARAM_PREFIX + DISCOVERY_SERVICE_DISPLAY_NAME;
Map<String, String> modelProps = generated.getQualifyingServiceParams();
assertEquals("Expected two service model properties", 2, modelProps.size());
- assertEquals("Expected " + SolrServiceModelGenerator.DISCOVERY_SERVICE_NAME + " model property.",
- getServiceType() + "-1",
- modelProps.get(SolrServiceModelGenerator.DISCOVERY_SERVICE_NAME));
- assertEquals("Expected " + SolrServiceModelGenerator.DISCOVERY_SERVICE_DISPLAY_NAME + " model property.",
- "null",
- modelProps.get(SolrServiceModelGenerator.DISCOVERY_SERVICE_DISPLAY_NAME));
+ assertEquals("Expected " + serviceNameQualifier + " model property.",
+ getServiceType() + "-1",
+ modelProps.get(serviceNameQualifier));
+ assertEquals("Expected " + displayNameQualifier + " model property.",
+ "null",
+ modelProps.get(displayNameQualifier));
}
@Override
diff --git a/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptor.java b/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptor.java
index 4ffc3ba..04b06c7 100644
--- a/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptor.java
+++ b/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptor.java
@@ -24,6 +24,8 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
public interface SimpleDescriptor {
+ String DISCOVERY_PARAM_PREFIX = "discovery-";
+
String getName();
String getDiscoveryType();
diff --git a/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java b/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
index 3a8de56..ca22b68 100644
--- a/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
+++ b/gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java
@@ -86,9 +86,7 @@ public class SimpleDescriptorHandler {
private static final SimpleDescriptorMessages log = MessagesFactory.get(SimpleDescriptorMessages.class);
- private static final String DISCOVERY_PARAM_PREFIX = "discovery-";
-
- private static Map<String, ServiceDiscovery> discoveryInstances = new HashMap<>();
+ private static final Map<String, ServiceDiscovery> discoveryInstances = new HashMap<>();
private static final Set<String> ALLOWED_SERVICES_WITHOUT_URLS_AND_PARAMS = Collections.unmodifiableSet(Stream.of("KNOX", "KNOX-METADATA", "KNOXSSOUT", "KNOX-SESSION").collect(Collectors.toSet()));
@@ -162,7 +160,7 @@ public class SimpleDescriptorHandler {
boolean hasNonDiscoveryParams = false;
// Determine if there are any params which are not discovery-only
for (String paramName : descriptorServiceParams.keySet()) {
- if (!paramName.startsWith(DISCOVERY_PARAM_PREFIX)) {
+ if (!paramName.startsWith(SimpleDescriptor.DISCOVERY_PARAM_PREFIX)) {
hasNonDiscoveryParams = true;
break;
}
@@ -556,7 +554,7 @@ public class SimpleDescriptorHandler {
Map<String, String> svcParams = serviceParams.get(serviceName);
if (svcParams != null) {
for (Entry<String, String> svcParam : svcParams.entrySet()) {
- if (!(svcParam.getKey().toLowerCase(Locale.ROOT)).startsWith(DISCOVERY_PARAM_PREFIX)) {
+ if (!(svcParam.getKey().toLowerCase(Locale.ROOT)).startsWith(SimpleDescriptor.DISCOVERY_PARAM_PREFIX)) {
sw.write(" <param>\n");
sw.write(" <name>" + svcParam.getKey() + "</name>\n");
sw.write(" <value>" + svcParam.getValue() + "</value>\n");