try { s.execute(); allOutput.append(s.getOutput()).append(" "); } catch (Exception e) { LOG.warn("Exception running " + s, e);
private static long getConf(String attr) { if(Shell.LINUX) { try { ShellCommandExecutor shellExecutorClk = new ShellCommandExecutor( new String[] {"getconf", attr }); shellExecutorClk.execute(); return Long.parseLong(shellExecutorClk.getOutput().replace("\n", "")); } catch (IOException|NumberFormatException e) { return -1; } } return -1; }
break; case FAILED: setHealthStatus(false, shexec.getOutput()); break;
private String[] getGroupIdInfo(String userName) throws ContainerExecutionException { String[] id = null; Shell.ShellCommandExecutor shexec = new Shell.ShellCommandExecutor( new String[]{"id", "-G", userName}); try { shexec.execute(); id = shexec.getOutput().replace("\n", "").split(" "); } catch (Exception e) { throw new ContainerExecutionException(e); } return id; }
/** * Static method to execute a shell command. * Covers most of the simple cases without requiring the user to implement * the <code>Shell</code> interface. * @param cmd shell command to execute. * @return the output of the executed command. */ public static String execCommand(String ... cmd) throws IOException { ShellCommandExecutor exec = new ShellCommandExecutor(cmd); exec.execute(); return exec.getOutput(); } }
private String getUserIdInfo(String userName) throws ContainerExecutionException { String id = ""; Shell.ShellCommandExecutor shexec = new Shell.ShellCommandExecutor( new String[]{"id", "-u", userName}); try { shexec.execute(); id = shexec.getOutput().replaceAll("[^0-9]", ""); } catch (Exception e) { throw new ContainerExecutionException(e); } return id; }
String getSystemInfoInfoFromShell() { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] { Shell.WINUTILS, "systeminfo" }); try { shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
String getAllProcessInfoFromShell() { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] { Shell.WINUTILS, "task", "processList", taskProcessId }); try { shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
String getSystemInfoInfoFromShell() { try { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] {Shell.getWinUtilsFile().getCanonicalPath(), "systeminfo" }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
String getAllProcessInfoFromShell() { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] { Shell.WINUTILS, "task", "processList", taskProcessId }); try { shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
String getSystemInfoInfoFromShell() { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] { Shell.WINUTILS, "systeminfo" }); try { shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
String getAllProcessInfoFromShell() { try { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] {Shell.getWinUtilsFile().getCanonicalPath(), "task", "processList", taskProcessId }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }
partialResolver.execute(); return parsePartialGroupNames( groupNames, partialResolver.getOutput()); } catch (ExitCodeException ece) {
try { executor.execute(); groups = resolveFullGroupNames(executor.getOutput()); } catch (ExitCodeException e) { if (handleExecutorTimeout(executor, user)) { try { groups = resolvePartialGroupNames(user, e.getMessage(), executor.getOutput()); } catch (PartialGroupNameException pge) { LOG.warn("unable to return groups for user {}", user, pge);
@Override public void run() { HealthCheckerExitStatus status = HealthCheckerExitStatus.SUCCESS; try { shexec.execute(); } catch (ExitCodeException e) { // ignore the exit code of the script status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; // On Windows, we will not hit the Stream closed IOException // thrown by stdout buffered reader for timeout event. if (Shell.WINDOWS && shexec.isTimedOut()) { status = HealthCheckerExitStatus.TIMED_OUT; } } catch (Exception e) { LOG.warn("Caught exception : " + e.getMessage()); if (!shexec.isTimedOut()) { status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; } else { status = HealthCheckerExitStatus.TIMED_OUT; } exceptionStackTrace = StringUtils.stringifyException(e); } finally { if (status == HealthCheckerExitStatus.SUCCESS) { if (hasErrors(shexec.getOutput())) { status = HealthCheckerExitStatus.FAILED; } } reportHealthStatus(status); } }
public HealthReport checkHealth() { HealthCheckerExitStatus status = HealthCheckerExitStatus.SUCCESS; try { // Calling this execute leaves around running executor threads. shexec.execute(); } catch (ExitCodeException e) { // ignore the exit code of the script LOG.warn("Caught exception : " + e + ",exit code:" + e.getExitCode()); status = HealthCheckerExitStatus.FAILED_WITH_EXIT_CODE; } catch (IOException e) { LOG.warn("Caught exception : " + e); status = HealthCheckerExitStatus.FAILED_WITH_EXCEPTION; exceptionStackTrace = org.apache.hadoop.util.StringUtils.stringifyException(e); } finally { if (shexec.isTimedOut()) { status = HealthCheckerExitStatus.TIMED_OUT; } if (status == HealthCheckerExitStatus.SUCCESS) { if (hasErrors(shexec.getOutput())) { status = HealthCheckerExitStatus.FAILED; } } } return new HealthReport(status, getHealthReport(status)); }
private String getHealthReport(HealthCheckerExitStatus status){ String healthReport = null; switch (status) { case SUCCESS: healthReport = "Server is healthy."; break; case TIMED_OUT: healthReport = "Health script timed out"; break; case FAILED_WITH_EXCEPTION: healthReport = exceptionStackTrace; break; case FAILED_WITH_EXIT_CODE: healthReport = "Health script failed with exit code."; break; case FAILED: healthReport = shexec.getOutput(); break; } return healthReport; } }
/** * Static method to execute a shell command. * Covers most of the simple cases without requiring the user to implement * the <code>Shell</code> interface. * @param env the map of environment key=value * @param cmd shell command to execute. * @param timeout time in milliseconds after which script should be marked timeout * @return the output of the executed command. * @throws IOException on any problem. */ public static String execCommand(Map<String, String> env, String[] cmd, long timeout) throws IOException { ShellCommandExecutor exec = new ShellCommandExecutor(cmd, null, env, timeout); exec.execute(); return exec.getOutput(); }
String getSystemInfoInfoFromShell() { try { ShellCommandExecutor shellExecutor = new ShellCommandExecutor( new String[] {Shell.getWinUtilsFile().getCanonicalPath(), "systeminfo" }); shellExecutor.execute(); return shellExecutor.getOutput(); } catch (IOException e) { LOG.error(StringUtils.stringifyException(e)); } return null; }