HADOOP-15523. Shell command timeout given is in seconds whereas it is taken as millisec while scheduling. Contributed by Bilwa S T.

(cherry picked from commit 3905fdb793)
This commit is contained in:
Surendra Singh Lilhore 2018-06-17 12:12:01 +05:30
parent 9e148aa0bc
commit 59686179ae
4 changed files with 43 additions and 12 deletions

View File

@ -554,7 +554,7 @@ public class CommonConfigurationKeysPublic {
* <a href="{@docRoot}/../hadoop-project-dist/hadoop-common/core-default.xml"> * <a href="{@docRoot}/../hadoop-project-dist/hadoop-common/core-default.xml">
* core-default.xml</a> * core-default.xml</a>
*/ */
public static final String HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS = public static final String HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_KEY =
"hadoop.security.groups.shell.command.timeout"; "hadoop.security.groups.shell.command.timeout";
/** /**
* @see * @see
@ -562,7 +562,7 @@ public class CommonConfigurationKeysPublic {
* core-default.xml</a> * core-default.xml</a>
*/ */
public static final long public static final long
HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS_DEFAULT = HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_DEFAULT =
0L; 0L;
/** /**
* @see * @see

View File

@ -18,7 +18,6 @@
package org.apache.hadoop.security; package org.apache.hadoop.security;
import java.io.IOException; import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.StringTokenizer;
@ -52,7 +51,8 @@ public class ShellBasedUnixGroupsMapping extends Configured
protected static final Logger LOG = protected static final Logger LOG =
LoggerFactory.getLogger(ShellBasedUnixGroupsMapping.class); LoggerFactory.getLogger(ShellBasedUnixGroupsMapping.class);
private long timeout = 0L; private long timeout = CommonConfigurationKeys.
HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_DEFAULT;
private static final List<String> EMPTY_GROUPS = new LinkedList<>(); private static final List<String> EMPTY_GROUPS = new LinkedList<>();
@Override @Override
@ -61,10 +61,10 @@ public class ShellBasedUnixGroupsMapping extends Configured
if (conf != null) { if (conf != null) {
timeout = conf.getTimeDuration( timeout = conf.getTimeDuration(
CommonConfigurationKeys. CommonConfigurationKeys.
HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS, HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_KEY,
CommonConfigurationKeys. CommonConfigurationKeys.
HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS_DEFAULT, HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_DEFAULT,
TimeUnit.SECONDS); TimeUnit.MILLISECONDS);
} }
} }

View File

@ -1194,7 +1194,7 @@ public abstract class Shell {
/** /**
* Returns the timeout value set for the executor's sub-commands. * Returns the timeout value set for the executor's sub-commands.
* @return The timeout value in seconds * @return The timeout value in milliseconds
*/ */
@VisibleForTesting @VisibleForTesting
public long getTimeoutInterval() { public long getTimeoutInterval() {

View File

@ -173,6 +173,37 @@ public class TestShellBasedUnixGroupsMapping {
assertTrue(groups.contains("zzz")); assertTrue(groups.contains("zzz"));
} }
public long getTimeoutInterval(String timeout) {
Configuration conf = new Configuration();
String userName = "foobarnonexistinguser";
conf.set(
CommonConfigurationKeys.HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_KEY,
timeout);
TestDelayedGroupCommand mapping = ReflectionUtils
.newInstance(TestDelayedGroupCommand.class, conf);
ShellCommandExecutor executor = mapping.createGroupExecutor(userName);
return executor.getTimeoutInterval();
}
@Test
public void testShellTimeOutConf() {
// Test a 1 second max-runtime timeout
assertEquals(
"Expected the group names executor to carry the configured timeout",
1000L, getTimeoutInterval("1s"));
// Test a 1 minute max-runtime timeout
assertEquals(
"Expected the group names executor to carry the configured timeout",
60000L, getTimeoutInterval("1m"));
// Test a 1 millisecond max-runtime timeout
assertEquals(
"Expected the group names executor to carry the configured timeout",
1L, getTimeoutInterval("1"));
}
private class TestGroupResolvable private class TestGroupResolvable
extends ShellBasedUnixGroupsMapping { extends ShellBasedUnixGroupsMapping {
/** /**
@ -222,7 +253,7 @@ public class TestShellBasedUnixGroupsMapping {
private static class TestDelayedGroupCommand private static class TestDelayedGroupCommand
extends ShellBasedUnixGroupsMapping { extends ShellBasedUnixGroupsMapping {
private Long timeoutSecs = 2L; private Long timeoutSecs = 1L;
TestDelayedGroupCommand() { TestDelayedGroupCommand() {
super(); super();
@ -249,12 +280,12 @@ public class TestShellBasedUnixGroupsMapping {
String userName = "foobarnonexistinguser"; String userName = "foobarnonexistinguser";
String commandTimeoutMessage = String commandTimeoutMessage =
"ran longer than the configured timeout limit"; "ran longer than the configured timeout limit";
long testTimeout = 1L; long testTimeout = 500L;
// Test a 1 second max-runtime timeout // Test a 1 second max-runtime timeout
conf.setLong( conf.setLong(
CommonConfigurationKeys. CommonConfigurationKeys.
HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS, HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_KEY,
testTimeout); testTimeout);
TestDelayedGroupCommand mapping = TestDelayedGroupCommand mapping =
@ -306,7 +337,7 @@ public class TestShellBasedUnixGroupsMapping {
conf = new Configuration(); conf = new Configuration();
long defaultTimeout = long defaultTimeout =
CommonConfigurationKeys. CommonConfigurationKeys.
HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_SECS_DEFAULT; HADOOP_SECURITY_GROUP_SHELL_COMMAND_TIMEOUT_DEFAULT;
mapping = mapping =
ReflectionUtils.newInstance(TestDelayedGroupCommand.class, conf); ReflectionUtils.newInstance(TestDelayedGroupCommand.class, conf);