HADOOP-17011. Tolerate leading and trailing spaces in fs.defaultFS. Contributed by Ctest

Signed-off-by: Ayush Saxena <ayushsaxena@apache.org>
This commit is contained in:
Mingliang Liu 2020-04-30 14:13:21 -07:00
parent 6bdab3723e
commit 263c76b678
No known key found for this signature in database
GPG Key ID: BC2FB8C6908A0C16
9 changed files with 16 additions and 11 deletions

View File

@ -483,7 +483,7 @@ public class FileContext implements PathCapabilities {
*/
public static FileContext getFileContext(final Configuration aConf)
throws UnsupportedFileSystemException {
final URI defaultFsUri = URI.create(aConf.get(FS_DEFAULT_NAME_KEY,
final URI defaultFsUri = URI.create(aConf.getTrimmed(FS_DEFAULT_NAME_KEY,
FS_DEFAULT_NAME_DEFAULT));
if ( defaultFsUri.getScheme() != null
&& !defaultFsUri.getScheme().trim().isEmpty()) {

View File

@ -278,7 +278,8 @@ public abstract class FileSystem extends Configured
* @return the uri of the default filesystem
*/
public static URI getDefaultUri(Configuration conf) {
URI uri = URI.create(fixName(conf.get(FS_DEFAULT_NAME_KEY, DEFAULT_FS)));
URI uri =
URI.create(fixName(conf.getTrimmed(FS_DEFAULT_NAME_KEY, DEFAULT_FS)));
if (uri.getScheme() == null) {
throw new IllegalArgumentException("No scheme in default FS: " + uri);
}

View File

@ -108,7 +108,7 @@ abstract public class FsCommand extends Command {
HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY,
HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_DEFAULT);
if (displayWarnings) {
final String defaultFs = getConf().get(FS_DEFAULT_NAME_KEY);
final String defaultFs = getConf().getTrimmed(FS_DEFAULT_NAME_KEY);
final boolean missingDefaultFs =
defaultFs == null || defaultFs.equals(FS_DEFAULT_NAME_DEFAULT);
if (missingDefaultFs) {

View File

@ -101,7 +101,7 @@ public class HttpFSServerWebApp extends ServerWebApp {
adminGroup = getConfig().get(getPrefixedName(CONF_ADMIN_GROUP), "admin");
LOG.info("Connects to Namenode [{}]",
get().get(FileSystemAccess.class).getFileSystemConfiguration().
get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY));
getTrimmed(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY));
}
/**

View File

@ -341,8 +341,9 @@ public class FileSystemAccessService extends BaseService implements FileSystemAc
}
try {
validateNamenode(
new URI(conf.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)).
getAuthority());
new URI(conf.getTrimmed(
CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)).
getAuthority());
UserGroupInformation ugi = getUGI(user);
return ugi.doAs(new PrivilegedExceptionAction<T>() {
@Override
@ -377,7 +378,9 @@ public class FileSystemAccessService extends BaseService implements FileSystemAc
}
try {
validateNamenode(
new URI(conf.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)).getAuthority());
new URI(conf.getTrimmed(
CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY)).
getAuthority());
UserGroupInformation ugi = getUGI(user);
return ugi.doAs(new PrivilegedExceptionAction<FileSystem>() {
@Override

View File

@ -70,7 +70,7 @@ public final class NameNodeUtils {
final Collection<String> nameservices =
DFSUtilClient.getNameServiceIds(conf);
final String nnAddr = conf.get(FS_DEFAULT_NAME_KEY);
final String nnAddr = conf.getTrimmed(FS_DEFAULT_NAME_KEY);
if (nnAddr == null) {
// default fs is not set.
return null;

View File

@ -302,7 +302,8 @@ public class JobHistoryUtils {
FileContext fc = getDefaultFileContext();
if (fc == null ||
fc.getDefaultFileSystem().getUri().toString().equals(
conf.get(CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, "")) ||
conf.getTrimmed(
CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY, "")) ||
path.toUri().getAuthority() != null ||
path.toUri().getScheme()!= null) {
return sourcePath;

View File

@ -566,7 +566,7 @@ public class FrameworkUploader implements Runnable {
path.startsWith("file://");
if (fs == null) {
fs = conf.get(FS_DEFAULT_NAME_KEY);
fs = conf.getTrimmed(FS_DEFAULT_NAME_KEY);
if (fs == null && !isFullPath) {
LOG.error("No filesystem specified in either fs or target.");
printHelp(opts);

View File

@ -86,7 +86,7 @@ class ClusterSummarizer implements StatListener<ClusterStats> {
void start(Configuration conf) {
jobTrackerInfo = conf.get(JTConfig.JT_IPC_ADDRESS);
namenodeInfo = conf.get(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY);
namenodeInfo = conf.getTrimmed(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY);
}
// Getters