private static void unTarUsingTar(File inFile, File untarDir, boolean gzipped) throws IOException { StringBuffer untarCommand = new StringBuffer(); if (gzipped) { untarCommand.append(" gzip -dc '"); untarCommand.append(inFile.toString()); untarCommand.append("' | ("); } untarCommand.append("cd '"); untarCommand.append(untarDir.toString()); untarCommand.append("' ; "); untarCommand.append("tar -xf "); if (gzipped) { untarCommand.append(" -)"); } else { untarCommand.append(inFile.toString()); } String[] shellCmd = { "bash", "-c", untarCommand.toString() }; ShellUtils.ShellCommandExecutor shexec = new ShellUtils.ShellCommandExecutor(shellCmd); shexec.execute(); int exitcode = shexec.getExitCode(); if (exitcode != 0) { throw new IOException("Error untarring file " + inFile + ". Tar process exited with exit code " + exitcode); } }
private void setBlobPermissions(Map<String, Object> conf, String user, Path path) throws IOException { if (!ObjectReader.getBoolean(conf.get(Config.SUPERVISOR_RUN_WORKER_AS_USER), false)) { return; } String wlCommand = ObjectReader.getString(conf.get(Config.SUPERVISOR_WORKER_LAUNCHER), ""); if (wlCommand.isEmpty()) { String stormHome = System.getProperty(ConfigUtils.STORM_HOME); wlCommand = stormHome + "/bin/worker-launcher"; } List<String> command = new ArrayList<>(Arrays.asList(wlCommand, user, "blob", path.toString())); String[] commandArray = command.toArray(new String[command.size()]); ShellUtils.ShellCommandExecutor shExec = new ShellUtils.ShellCommandExecutor(commandArray); LOG.debug("Setting blob permissions, command: {}", Arrays.toString(commandArray)); try { shExec.execute(); LOG.debug("output: {}", shExec.getOutput()); } catch (ShellUtils.ExitCodeException e) { int exitCode = shExec.getExitCode(); LOG.warn("Exit code from worker-launcher is: {}", exitCode, e); LOG.debug("output: {}", shExec.getOutput()); throw new IOException("Setting blob permissions failed" + " (exitCode=" + exitCode + ") with output: " + shExec.getOutput(), e); } }
private static void unTarUsingTar(File inFile, File untarDir, boolean gzipped) throws IOException { StringBuffer untarCommand = new StringBuffer(); if (gzipped) { untarCommand.append(" gzip -dc '"); untarCommand.append(inFile.toString()); untarCommand.append("' | ("); } untarCommand.append("cd '"); untarCommand.append(untarDir.toString()); untarCommand.append("' ; "); untarCommand.append("tar -xf "); if (gzipped) { untarCommand.append(" -)"); } else { untarCommand.append(inFile.toString()); } String[] shellCmd = {"bash", "-c", untarCommand.toString()}; ShellUtils.ShellCommandExecutor shexec = new ShellUtils.ShellCommandExecutor(shellCmd); shexec.execute(); int exitcode = shexec.getExitCode(); if (exitcode != 0) { throw new IOException("Error untarring file " + inFile + ". Tar process exited with exit code " + exitcode); } }
public void setBlobPermissions(Map conf, String user, String path) throws IOException { if (!Utils.getBoolean(conf.get(Config.SUPERVISOR_RUN_WORKER_AS_USER), false)) { return; } String wlCommand = Utils.getString(conf.get(Config.SUPERVISOR_WORKER_LAUNCHER), ""); if (wlCommand.isEmpty()) { String stormHome = System.getProperty("storm.home"); wlCommand = stormHome + "/bin/worker-launcher"; } List<String> command = new ArrayList<String>(Arrays.asList(wlCommand, user, "blob", path)); String[] commandArray = command.toArray(new String[command.size()]); ShellCommandExecutor shExec = new ShellCommandExecutor(commandArray); LOG.info("Setting blob permissions, command: {}", Arrays.toString(commandArray)); try { shExec.execute(); LOG.debug("output: {}", shExec.getOutput()); } catch (ExitCodeException e) { int exitCode = shExec.getExitCode(); LOG.warn("Exit code from worker-launcher is : " + exitCode, e); LOG.debug("output: {}", shExec.getOutput()); throw new IOException("Setting blob permissions failed" + " (exitCode=" + exitCode + ") with output: " + shExec.getOutput(), e); } }
/** * 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.o */ 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(); }
@Override public String execCommand(Map<String, String> env, String[] cmd, long timeout) throws IOException { ShellUtils.ShellCommandExecutor exec = new ShellUtils.ShellCommandExecutor(cmd, null, env, timeout); exec.execute(); return exec.getOutput(); }