in gateway-discovery-ambari/src/main/java/org/apache/knox/gateway/topology/discovery/ambari/HDFSURLCreatorBase.java [56:133]
public List<String> create(String service, Map<String, String> serviceParams) {
List<String> urls = new ArrayList<>();
if (getTargetService().equals(service)) {
AmbariCluster.ServiceConfiguration sc =
cluster.getServiceConfiguration(CONFIG_SERVICE_HDFS, CONFIG_TYPE_HDFS_SITE);
if (sc != null) {
// First, check if it's HA config
String nameServices = sc.getProperties().get("dfs.nameservices");
if (nameServices != null && !nameServices.isEmpty()) {
String ns = null;
// Parse the nameservices value
String[] namespaces = nameServices.split(",");
String nsParam = (serviceParams != null) ? serviceParams.get(NAMESERVICE_PARAM) : null;
if (namespaces.length > 1 || nsParam != null) {
if (nsParam != null) {
if (!validateDeclaredNameService(namespaces, nsParam)) {
log.undefinedHDFSNameService(nsParam);
}
ns = nsParam;
} else {
// core-site.xml : dfs.defaultFS property (e.g., hdfs://ns1)
AmbariCluster.ServiceConfiguration coreSite =
cluster.getServiceConfiguration(CONFIG_SERVICE_HDFS, CONFIG_TYPE_CORE_SITE);
if (coreSite != null) {
String defaultFS = coreSite.getProperties().get("fs.defaultFS");
if (defaultFS != null) {
ns = defaultFS.substring(defaultFS.lastIndexOf('/') + 1);
}
}
}
}
// If only a single namespace, or no namespace specified and no default configured, use the first in the "list"
if (ns == null) {
ns = namespaces[0];
}
// If it is an HA configuration
Map<String, String> props = sc.getProperties();
// More recent HDFS configurations support a property enumerating the node names associated with a
// nameservice. If this property is present, use its value to create the correct URLs.
String nameServiceNodes = props.get("dfs.ha.namenodes." + ns);
if (nameServiceNodes != null) {
String addressPropertyPrefix = getAddressPropertyPrefix();
String[] nodes = nameServiceNodes.split(",");
for (String node : nodes) {
String propertyValue = getHANameNodeHttpAddress(addressPropertyPrefix, props, ns, node);
if (propertyValue != null) {
urls.add(createURL(propertyValue));
}
}
} else {
// Name node HTTP[S] addresses are defined as properties of the form:
// dfs.namenode.http[s]-address.<NAMESERVICE>.nn<INDEX>
// So, this iterates over the nn<INDEX> properties until there is no such property (since it cannot be
// known how many are defined by any other means).
String addressPropertyPrefix = getAddressPropertyPrefix();
int i = 1;
String propertyValue = getHANameNodeHttpAddress(addressPropertyPrefix, props, ns, i++);
while (propertyValue != null) {
urls.add(createURL(propertyValue));
propertyValue = getHANameNodeHttpAddress(addressPropertyPrefix, props, ns, i++);
}
}
} else { // If it's not an HA configuration, get the single name node HTTP[S] address
urls.add(createURL(sc.getProperties().get(getAddressPropertyPrefix())));
}
}
}
return urls;
}