HADOOP-12043. Display warning if defaultFs is not set when running fs commands. Contributed by Eddy Xu.
(cherry picked from commit 374ddd9f9e
)
This commit is contained in:
parent
bde4031a02
commit
600f5f5232
|
@ -138,6 +138,9 @@ Release 2.8.0 - UNRELEASED
|
||||||
HADOOP-11894. Bump the version of Apache HTrace to 3.2.0-incubating
|
HADOOP-11894. Bump the version of Apache HTrace to 3.2.0-incubating
|
||||||
(Masatake Iwasaki via Colin P. McCabe)
|
(Masatake Iwasaki via Colin P. McCabe)
|
||||||
|
|
||||||
|
HADOOP-12043. Display warning if defaultFs is not set when running fs
|
||||||
|
commands. (Lei Xu via wang)
|
||||||
|
|
||||||
OPTIMIZATIONS
|
OPTIMIZATIONS
|
||||||
|
|
||||||
HADOOP-11785. Reduce the number of listStatus operation in distcp
|
HADOOP-11785. Reduce the number of listStatus operation in distcp
|
||||||
|
|
|
@ -376,5 +376,11 @@ public class CommonConfigurationKeysPublic {
|
||||||
"hadoop.security.random.device.file.path";
|
"hadoop.security.random.device.file.path";
|
||||||
public static final String HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT =
|
public static final String HADOOP_SECURITY_SECURE_RANDOM_DEVICE_FILE_PATH_DEFAULT =
|
||||||
"/dev/urandom";
|
"/dev/urandom";
|
||||||
|
|
||||||
|
/** See <a href="{@docRoot}/../core-default.html">core-default.xml</a> */
|
||||||
|
public static final String HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY =
|
||||||
|
"hadoop.shell.missing.defaultFs.warning";
|
||||||
|
public static final boolean HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_DEFAULT =
|
||||||
|
false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.apache.hadoop.fs.shell;
|
package org.apache.hadoop.fs.shell;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.classification.InterfaceStability;
|
import org.apache.hadoop.classification.InterfaceStability;
|
||||||
|
@ -27,8 +28,13 @@ import org.apache.hadoop.fs.FsShellPermissions;
|
||||||
import org.apache.hadoop.fs.Path;
|
import org.apache.hadoop.fs.Path;
|
||||||
import org.apache.hadoop.fs.shell.find.Find;
|
import org.apache.hadoop.fs.shell.find.Find;
|
||||||
|
|
||||||
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_DEFAULT;
|
||||||
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.FS_DEFAULT_NAME_KEY;
|
||||||
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_DEFAULT;
|
||||||
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all "hadoop fs" commands
|
* Base class for all "hadoop fs" commands.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@InterfaceAudience.Private
|
@InterfaceAudience.Private
|
||||||
|
@ -90,4 +96,26 @@ abstract public class FsCommand extends Command {
|
||||||
public int runAll() {
|
public int runAll() {
|
||||||
return run(args);
|
return run(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void processRawArguments(LinkedList<String> args)
|
||||||
|
throws IOException {
|
||||||
|
LinkedList<PathData> expendedArgs = expandArguments(args);
|
||||||
|
// If "fs.defaultFs" is not set appropriately, it warns the user that the
|
||||||
|
// command is not running against HDFS.
|
||||||
|
final boolean displayWarnings = getConf().getBoolean(
|
||||||
|
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 boolean missingDefaultFs =
|
||||||
|
defaultFs == null || defaultFs.equals(FS_DEFAULT_NAME_DEFAULT);
|
||||||
|
if (missingDefaultFs) {
|
||||||
|
err.printf(
|
||||||
|
"Warning: fs.defaultFs is not set when running \"%s\" command.%n",
|
||||||
|
getCommandName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
processArguments(expendedArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import org.apache.hadoop.conf.Configuration;
|
||||||
import org.apache.hadoop.util.StringUtils;
|
import org.apache.hadoop.util.StringUtils;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
|
@ -102,6 +104,12 @@ class Ls extends FsCommand {
|
||||||
|
|
||||||
protected boolean humanReadable = false;
|
protected boolean humanReadable = false;
|
||||||
|
|
||||||
|
protected Ls() {}
|
||||||
|
|
||||||
|
protected Ls(Configuration conf) {
|
||||||
|
super(conf);
|
||||||
|
}
|
||||||
|
|
||||||
protected String formatSize(long size) {
|
protected String formatSize(long size) {
|
||||||
return humanReadable
|
return humanReadable
|
||||||
? StringUtils.TraditionalBinaryPrefix.long2String(size, "", 1)
|
? StringUtils.TraditionalBinaryPrefix.long2String(size, "", 1)
|
||||||
|
|
|
@ -1901,4 +1901,12 @@ for ldap providers in the same way as above does.
|
||||||
<value>Client</value>
|
<value>Client</value>
|
||||||
</property>
|
</property>
|
||||||
|
|
||||||
|
<property>
|
||||||
|
<description>
|
||||||
|
Enable hdfs shell commands to display warnings if (fs.defaultFS) property
|
||||||
|
is not set.
|
||||||
|
</description>
|
||||||
|
<name>hadoop.shell.missing.defaultFs.warning</name>
|
||||||
|
<value>false</value>
|
||||||
|
</property>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|
|
@ -17,10 +17,12 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.fs.shell;
|
package org.apache.hadoop.fs.shell;
|
||||||
|
|
||||||
|
import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintStream;
|
import java.io.PrintStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -1048,6 +1050,29 @@ public class TestLs {
|
||||||
verifyNoMoreInteractions(out);
|
verifyNoMoreInteractions(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void displayWarningOnLocalFileSystem(boolean shouldDisplay)
|
||||||
|
throws IOException {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
conf.setBoolean(
|
||||||
|
HADOOP_SHELL_MISSING_DEFAULT_FS_WARNING_KEY, shouldDisplay);
|
||||||
|
|
||||||
|
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||||
|
PrintStream err = new PrintStream(buf, true);
|
||||||
|
Ls ls = new Ls(conf);
|
||||||
|
ls.err = err;
|
||||||
|
ls.run("file:///.");
|
||||||
|
assertEquals(shouldDisplay, buf.toString().contains(
|
||||||
|
"Warning: fs.defaultFs is not set when running \"ls\" command."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void displayWarningsOnLocalFileSystem() throws IOException {
|
||||||
|
// Display warnings.
|
||||||
|
displayWarningOnLocalFileSystem(true);
|
||||||
|
// Does not display warnings.
|
||||||
|
displayWarningOnLocalFileSystem(false);
|
||||||
|
}
|
||||||
|
|
||||||
// check the deprecated flag isn't set
|
// check the deprecated flag isn't set
|
||||||
@Test
|
@Test
|
||||||
public void isDeprecated() {
|
public void isDeprecated() {
|
||||||
|
|
Loading…
Reference in New Issue