in gateway-topology-simple/src/main/java/org/apache/knox/gateway/topology/simple/SimpleDescriptorHandler.java [103:208]
public static Map<String, File> handle(GatewayConfig config, SimpleDescriptor desc, File srcDirectory, File destDirectory, Service...gatewayServices) {
if (config.getReadOnlyOverrideTopologyNames().contains(desc.getName())) {
log.skipReadOnlyDescriptor(desc.getName());
return Collections.emptyMap();
}
List<String> declaredServiceNames = new ArrayList<>();
Set<String> validServiceNames = new TreeSet<>();
Map<String, String> serviceVersions = new HashMap<>();
Map<String, Map<String, String>> serviceParams = new HashMap<>();
Map<String, List<String>> serviceURLs = new HashMap<>();
ServiceDiscovery.Cluster cluster = null;
if (shouldPerformDiscovery(desc)) {
cluster = performDiscovery(config, desc, gatewayServices);
if (cluster == null) {
throw new DiscoveryException(desc.getCluster(), desc.getName());
}
} else {
log.discoveryNotConfiguredForDescriptor(desc.getName());
}
for (SimpleDescriptor.Service descService : desc.getServices()) {
String serviceName = descService.getName();
declaredServiceNames.add(serviceName);
String serviceVer = descService.getVersion();
if (serviceVer != null) {
serviceVersions.put(serviceName, serviceVer);
}
List<String> descServiceURLs = descService.getURLs();
if (descServiceURLs == null || descServiceURLs.isEmpty()) {
if (cluster != null) {
descServiceURLs = cluster.getServiceURLs(serviceName, descService.getParams());
}
}
// Validate the discovered service URLs
List<String> validURLs = new ArrayList<>();
if (descServiceURLs != null && !descServiceURLs.isEmpty()) {
// Validate the URL(s)
for (String descServiceURL : descServiceURLs) {
if (validateURL(serviceName, descServiceURL)) {
validURLs.add(descServiceURL);
}
}
if (!validURLs.isEmpty()) {
validServiceNames.add(serviceName);
}
}
// If there is at least one valid URL associated with the service, then add it to the map
if (!validURLs.isEmpty()) {
serviceURLs.put(serviceName, validURLs);
} else {
log.failedToDiscoverClusterServiceURLs(serviceName, (cluster != null ? cluster.getName() : ""));
}
// Service params
Map<String, String> descriptorServiceParams = descService.getParams();
if (descriptorServiceParams != null && !descriptorServiceParams.isEmpty()) {
boolean hasNonDiscoveryParams = false;
// Determine if there are any params which are not discovery-only
for (String paramName : descriptorServiceParams.keySet()) {
if (!paramName.startsWith(SimpleDescriptor.DISCOVERY_PARAM_PREFIX)) {
hasNonDiscoveryParams = true;
break;
}
}
// Don't add the service if the only params are discovery-only params
if (hasNonDiscoveryParams) {
serviceParams.put(serviceName, descService.getParams());
validServiceNames.add(serviceName);
}
}
if (ALLOWED_SERVICES_WITHOUT_URLS_AND_PARAMS.contains(serviceName)) {
validServiceNames.add(serviceName);
}
}
GatewayServices gws = getGatewayServices(gatewayServices);
// Provision the query param encryption password here, rather than relying on the random password generated
// when the topology is deployed. This is to support Knox HA deployments, where multiple Knox instances are
// generating topologies based on a shared remote descriptor, and they must all be able to encrypt/decrypt
// query params with the same credentials. (KNOX-1136)
if (desc.isProvisionEncryptQueryStringCredential() && !provisionQueryParamEncryptionCredential(desc.getName(), gws)) {
log.unableCreatePasswordForEncryption(desc.getName());
}
// Generate the topology file
return generateTopology(desc,
srcDirectory,
destDirectory,
cluster,
declaredServiceNames,
validServiceNames,
serviceVersions,
serviceURLs,
serviceParams,
gws);
}