本文整理汇总了Java中org.apache.hadoop.util.Shell.ShellCommandExecutor类的典型用法代码示例。如果您正苦于以下问题:Java ShellCommandExecutor类的具体用法?Java ShellCommandExecutor怎么用?Java ShellCommandExecutor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ShellCommandExecutor类属于org.apache.hadoop.util.Shell包,在下文中一共展示了ShellCommandExecutor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chmod
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Change the permissions on a file / directory, recursively, if
* needed.
* @param filename name of the file whose permissions are to change
* @param perm permission string
* @param recursive true, if permissions should be changed recursively
* @return the exit code from the command.
* @throws IOException
*/
public static int chmod(String filename, String perm, boolean recursive)
throws IOException {
String [] cmd = Shell.getSetPermissionCommand(perm, recursive);
String[] args = new String[cmd.length + 1];
System.arraycopy(cmd, 0, args, 0, cmd.length);
args[cmd.length] = new File(filename).getPath();
ShellCommandExecutor shExec = new ShellCommandExecutor(args);
try {
shExec.execute();
}catch(IOException e) {
if(LOG.isDebugEnabled()) {
LOG.debug("Error while changing permission : " + filename
+" Exception: " + StringUtils.stringifyException(e));
}
}
return shExec.getExitCode();
}
示例2: createGroupExecutor
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Create a ShellCommandExecutor object which returns exit code 1,
* emulating the case that the user does not exist.
*
* @param userName not used
* @return a mock ShellCommandExecutor object
*/
@Override
protected ShellCommandExecutor createGroupExecutor(String userName) {
ShellCommandExecutor executor = mock(ShellCommandExecutor.class);
try {
doThrow(new ExitCodeException(1,
"id: foobarusernotexist: No such user")).
when(executor).execute();
when(executor.getOutput()).thenReturn("");
} catch (IOException e) {
LOG.warn(e.getMessage());
}
return executor;
}
示例3: isAvailable
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
public static boolean isAvailable() {
if (Shell.WINDOWS) {
ShellCommandExecutor shellExecutor = new ShellCommandExecutor(
new String[] { Shell.WINUTILS, "help" });
try {
shellExecutor.execute();
} catch (IOException e) {
LOG.error(StringUtils.stringifyException(e));
} finally {
String output = shellExecutor.getOutput();
if (output != null &&
output.contains("Prints to stdout a list of processes in the task")) {
return true;
}
}
}
return false;
}
示例4: run
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
public void run() {
try {
Vector<String> args = new Vector<String>();
if (isSetsidAvailable()) {
args.add("setsid");
}
args.add("bash");
args.add("-c");
args.add(" echo $$ > " + pidFile + "; sh " + shellScript + " " + N
+ ";");
shexec = new ShellCommandExecutor(args.toArray(new String[0]));
shexec.execute();
} catch (ExitCodeException ee) {
LOG.info("Shell Command exit with a non-zero exit code. This is"
+ " expected as we are killing the subprocesses of the"
+ " task intentionally. " + ee);
} catch (IOException ioe) {
LOG.info("Error executing shell command " + ioe);
} finally {
LOG.info("Exit code: " + shexec.getExitCode());
}
}
示例5: hasPerlSupport
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Is perl supported on this machine ?
* @return true if perl is available and is working as expected
*/
public static boolean hasPerlSupport() {
boolean hasPerl = false;
ShellCommandExecutor shexec = new ShellCommandExecutor(
new String[] { "perl", "-e", "print 42" });
try {
shexec.execute();
if (shexec.getOutput().equals("42")) {
hasPerl = true;
}
else {
LOG.warn("Perl is installed, but isn't behaving as expected.");
}
} catch (Exception e) {
LOG.warn("Could not run perl: " + e);
}
return hasPerl;
}
示例6: chmod
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Change the permissions on a file / directory, recursively, if
* needed.
* @param filename name of the file whose permissions are to change
* @param perm permission string
* @param recursive true, if permissions should be changed recursively
* @return the exit code from the command.
* @throws IOException
*/
public static int chmod(String filename, String perm, boolean recursive)
throws IOException {
String [] cmd = Shell.getSetPermissionCommand(perm, recursive);
String[] args = new String[cmd.length + 1];
System.arraycopy(cmd, 0, args, 0, cmd.length);
args[cmd.length] = new File(filename).getPath();
ShellCommandExecutor shExec = new ShellCommandExecutor(args);
try {
shExec.execute();
}catch(IOException e) {
if(LOG.isDebugEnabled()) {
LOG.debug("Error while changing permission : " + filename
+" Exception: " + StringUtils.stringifyException(e));
}
}
return shExec.getExitCode();
}
示例7: isAvailable
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
public static boolean isAvailable() {
if (Shell.WINDOWS) {
if (!Shell.hasWinutilsPath()) {
return false;
}
ShellCommandExecutor shellExecutor = new ShellCommandExecutor(
new String[] { Shell.getWinUtilsPath(), "help" });
try {
shellExecutor.execute();
} catch (IOException e) {
LOG.error(StringUtils.stringifyException(e));
} finally {
String output = shellExecutor.getOutput();
if (output != null &&
output.contains("Prints to stdout a list of processes in the task")) {
return true;
}
}
}
return false;
}
示例8: init
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
@Override
public void init() throws IOException {
// Send command to executor which will just start up,
// verify configuration/permissions and exit
List<String> command = new ArrayList<String>(
Arrays.asList(containerExecutorExe,
"--checksetup"));
String[] commandArray = command.toArray(new String[command.size()]);
ShellCommandExecutor shExec = new ShellCommandExecutor(commandArray);
if (LOG.isDebugEnabled()) {
LOG.debug("checkLinuxExecutorSetup: " + Arrays.toString(commandArray));
}
try {
shExec.execute();
} catch (ExitCodeException e) {
int exitCode = shExec.getExitCode();
LOG.warn("Exit code from container executor initialization is : "
+ exitCode, e);
logOutput(shExec.getOutput());
throw new IOException("Linux container executor not configured properly"
+ " (error=" + exitCode + ")", e);
}
resourcesHandler.init(this);
}
示例9: mountCgroups
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
public void mountCgroups(List<String> cgroupKVs, String hierarchy)
throws IOException {
List<String> command = new ArrayList<String>(
Arrays.asList(containerExecutorExe, "--mount-cgroups", hierarchy));
command.addAll(cgroupKVs);
String[] commandArray = command.toArray(new String[command.size()]);
ShellCommandExecutor shExec = new ShellCommandExecutor(commandArray);
if (LOG.isDebugEnabled()) {
LOG.debug("mountCgroups: " + Arrays.toString(commandArray));
}
try {
shExec.execute();
} catch (IOException e) {
int ret_code = shExec.getExitCode();
LOG.warn("Exception in LinuxContainerExecutor mountCgroups ", e);
logOutput(shExec.getOutput());
throw new IOException("Problem mounting cgroups " + cgroupKVs +
"; exit code = " + ret_code + " and output: " + shExec.getOutput(), e);
}
}
示例10: createHardLink
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Creates a hardlink
* @param file - existing source file
* @param linkName - desired target link file
*/
public static void createHardLink(File file, File linkName)
throws IOException {
if (file == null) {
throw new IOException(
"invalid arguments to createHardLink: source file is null");
}
if (linkName == null) {
throw new IOException(
"invalid arguments to createHardLink: link name is null");
}
// construct and execute shell command
String[] hardLinkCommand = getHardLinkCommand.linkOne(file, linkName);
ShellCommandExecutor shexec = new ShellCommandExecutor(hardLinkCommand);
try {
shexec.execute();
} catch (ExitCodeException e) {
throw new IOException("Failed to execute command " +
Arrays.toString(hardLinkCommand) +
"; command output: \"" + shexec.getOutput() + "\"" +
"; WrappedException: \"" + e.getMessage() + "\"");
}
}
示例11: setup
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
@Override
public void setup(LocalDirAllocator allocator, LocalStorage localStorage)
throws IOException {
// Check the permissions of the task-controller binary by running
// it plainly. If permissions are correct, it returns an error
// code 1, else it returns 24 or something else if some other bugs
// are also present.
String[] taskControllerCmd =
new String[] { taskControllerExe };
ShellCommandExecutor shExec = new ShellCommandExecutor(taskControllerCmd);
try {
shExec.execute();
} catch (ExitCodeException e) {
int exitCode = shExec.getExitCode();
if (exitCode != 1) {
LOG.warn("Exit code from checking binary permissions is : " + exitCode);
logOutput(shExec.getOutput());
throw new IOException("Task controller setup failed because of invalid"
+ "permissions/ownership with exit code " + exitCode, e);
}
}
this.allocator = allocator;
this.localStorage = localStorage;
}
示例12: createLogDir
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
@Override
public void createLogDir(TaskAttemptID taskID,
boolean isCleanup) throws IOException {
// Log dirs are created during attempt dir creation when running the task
String[] command =
new String[]{taskControllerExe,
jobUserMap.get(taskID.getJobID().toString()),
localStorage.getDirsString(),
Integer.toString(Commands.INITIALIZE_TASK.getValue()),
taskID.getJobID().toString(),
taskID.toString()};
ShellCommandExecutor shExec = new ShellCommandExecutor(command);
if (LOG.isDebugEnabled()) {
LOG.debug("createLogDir: " + Arrays.toString(command));
}
shExec.execute();
}
示例13: signalTask
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
@Override
public void signalTask(String user, int taskPid,
Signal signal) throws IOException {
String[] command =
new String[]{taskControllerExe,
user,
localStorage.getDirsString(),
Integer.toString(Commands.SIGNAL_TASK.getValue()),
Integer.toString(taskPid),
Integer.toString(signal.getValue())};
ShellCommandExecutor shExec = new ShellCommandExecutor(command);
if (LOG.isDebugEnabled()) {
LOG.debug("signalTask: " + Arrays.toString(command));
}
try {
shExec.execute();
} catch (ExitCodeException e) {
int ret_code = shExec.getExitCode();
if (ret_code != ResultCode.INVALID_TASK_PID.getValue()) {
logOutput(shExec.getOutput());
throw new IOException("Problem signalling task " + taskPid + " with " +
signal + "; exit = " + ret_code);
}
}
}
示例14: killProcess
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Sends signal to process, forcefully terminating the process.
*
* @param pid process id
* @param signal the signal number to send
*/
public static void killProcess(String pid, Signal signal) {
//If process tree is not alive then return immediately.
if(!ProcessTree.isAlive(pid)) {
return;
}
String[] args = { "kill", "-" + signal.getValue(), pid };
ShellCommandExecutor shexec = new ShellCommandExecutor(args);
try {
shexec.execute();
} catch (IOException e) {
LOG.warn("Error sending signal " + signal + " to process "+ pid + " ."+
StringUtils.stringifyException(e));
} finally {
LOG.info("Killing process " + pid + " with signal " + signal +
". Exit code " + shexec.getExitCode());
}
}
示例15: killProcessGroup
import org.apache.hadoop.util.Shell.ShellCommandExecutor; //导入依赖的package包/类
/**
* Sends signal to all process belonging to same process group,
* forcefully terminating the process group.
*
* @param pgrpId process group id
* @param signal the signal number to send
*/
public static void killProcessGroup(String pgrpId, Signal signal) {
//If process tree is not alive then return immediately.
if(!ProcessTree.isProcessGroupAlive(pgrpId)) {
return;
}
String[] args = { "kill", "-" + signal.getValue() , "-"+pgrpId };
ShellCommandExecutor shexec = new ShellCommandExecutor(args);
try {
shexec.execute();
} catch (IOException e) {
LOG.warn("Error sending signal " + signal + " to process group "+
pgrpId + " ."+
StringUtils.stringifyException(e));
} finally {
LOG.info("Killing process group" + pgrpId + " with signal " + signal +
". Exit code " + shexec.getExitCode());
}
}