Skip to content

Commit

Permalink
KNOX-2871 - Refine should perform discovery check (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroflag authored Feb 3, 2023
1 parent e9b3d9e commit 49983cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class SimpleDescriptorHandlerFuncTest {
" <param><name>localhost</name><value>sandbox,sandbox.hortonworks.com</value></param>\n" +
" </provider>\n" +
" </gateway>\n";
public static final String DISCOVERY_ADDRESS = "http://dummy_address";


/*
Expand Down Expand Up @@ -147,7 +148,7 @@ public void testSimpleDescriptorHandlerQueryStringCredentialAliasCreation() thro
// Mock out the simple descriptor
SimpleDescriptor testDescriptor = EasyMock.createNiceMock(SimpleDescriptor.class);
EasyMock.expect(testDescriptor.getName()).andReturn("mysimpledescriptor").anyTimes();
EasyMock.expect(testDescriptor.getDiscoveryAddress()).andReturn(null).anyTimes();
EasyMock.expect(testDescriptor.getDiscoveryAddress()).andReturn(DISCOVERY_ADDRESS).anyTimes();
EasyMock.expect(testDescriptor.getDiscoveryType()).andReturn(discoveryType).anyTimes();
EasyMock.expect(testDescriptor.getDiscoveryUser()).andReturn(null).anyTimes();
EasyMock.expect(testDescriptor.getProviderConfig()).andReturn(providerConfig.getAbsolutePath()).anyTimes();
Expand Down Expand Up @@ -245,6 +246,7 @@ public void testSimpleDescriptorHandlerQueryStringCredentialAliasCreation() thro
assertEquals("Unexpected alias value (should be master secret + topology name.",
testMasterSecret + testDescriptor.getName(), capturedPwd.getValue());

assertEquals(1, NoOpServiceDiscovery.discoveryCalled);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
Expand Down Expand Up @@ -274,6 +276,7 @@ public ServiceDiscovery newInstance(GatewayConfig gatewayConfig) {

private static final class NoOpServiceDiscovery implements ServiceDiscovery {
static final String TYPE = "NO_OP";
static int discoveryCalled;

@Override
public String getType() {
Expand All @@ -290,12 +293,12 @@ public String getName() {

@Override
public List<String> getServiceURLs(String serviceName) {
return null;
return Collections.emptyList();
}

@Override
public List<String> getServiceURLs(String serviceName, Map<String, String> serviceParams) {
return null;
return Collections.emptyList();
}

@Override
Expand All @@ -307,6 +310,7 @@ public ZooKeeperConfig getZooKeeperConfiguration(String serviceName) {

@Override
public Cluster discover(GatewayConfig gwConfig, ServiceDiscoveryConfig config, String clusterName, Collection<String> includedServices) {
discoveryCalled++;
return discover(gwConfig, config, clusterName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.knox.gateway.topology.simple;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.knox.gateway.config.GatewayConfig;
import org.apache.knox.gateway.i18n.messages.MessagesFactory;
Expand Down Expand Up @@ -210,8 +211,7 @@ public static Map<String, File> handle(GatewayConfig config, SimpleDescriptor de
*/
private static boolean shouldPerformDiscovery(final SimpleDescriptor desc) {
// If there is a discovery type specified, then discovery should be performed
final String discoveryType = desc.getDiscoveryType();
if (discoveryType != null && !discoveryType.isEmpty()) {
if (StringUtils.isNotBlank(desc.getDiscoveryType()) && StringUtils.isNotBlank(desc.getDiscoveryAddress())) {
return true;
}
log.missingDiscoveryTypeInDescriptor(desc.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface SimpleDescriptorMessages {
void discoveryNotConfiguredForDescriptor(String descriptorName);

@Message(level = MessageLevel.INFO,
text = "The \"{0}\" descriptor does not include discovery-type.")
text = "The \"{0}\" descriptor does not include discovery-type or discovery-address.")
void missingDiscoveryTypeInDescriptor(String descriptorName);

@Message(level = MessageLevel.WARN,
Expand Down

0 comments on commit 49983cb

Please sign in to comment.