@Override public void setupBlobPermissions(File path, String user) throws IOException { String logPrefix = "setup blob permissions for " + path; ClientSupervisorUtils.processLauncherAndWait(_conf, user, Arrays.asList("blob", path.toString()), null, logPrefix); }
/** * Sanity check if everything the topology needs is there for it to run. * * @param conf the config of the supervisor * @param topologyId the ID of the topology * @return true if everything is there, else false * * @throws IOException on any error */ public boolean doRequiredTopoFilesExist(Map<String, Object> conf, String topologyId) throws IOException { return ClientSupervisorUtils.doRequiredTopoFilesExist(conf, topologyId); }
@Override public void setupStormCodeDir(String user, File path) throws IOException { ClientSupervisorUtils.setupStormCodeDir(_conf, user, path.getCanonicalPath()); }
/** * Launch the worker process (non-blocking). * * @param command the command to run * @param env the environment to run the command * @param processExitCallback a callback for when the process exits * @param logPrefix the prefix to include in the logs * @param targetDir the working directory to run the command in * @return true if it ran successfully, else false * * @throws IOException on any error */ protected void launchWorkerProcess(List<String> command, Map<String, String> env, String logPrefix, ExitCodeCallback processExitCallback, File targetDir) throws IOException { if (_resourceIsolationManager != null) { command = _resourceIsolationManager.getLaunchCommand(_workerId, command); } ClientSupervisorUtils.launchProcess(command, env, logPrefix, processExitCallback, targetDir); }
public static int processLauncherAndWait(Map<String, Object> conf, String user, List<String> args, final Map<String, String> environment, final String logPreFix) throws IOException { int ret = 0; Process process = processLauncher(conf, user, null, args, environment, logPreFix, null, null); if (StringUtils.isNotBlank(logPreFix)) { Utils.readAndLogStream(logPreFix, process.getInputStream()); } try { process.waitFor(); } catch (InterruptedException e) { LOG.info("{} interrupted.", logPreFix); } ret = process.exitValue(); return ret; }
@Override public void setupWorkerArtifactsDir(String user, File path) throws IOException { ClientSupervisorUtils.setupWorkerArtifactsDir(_conf, user, path.getCanonicalPath()); } }
/** * Run the given command for profiling. * * @param command the command to run * @param env the environment to run the command * @param logPrefix the prefix to include in the logs * @param targetDir the working directory to run the command in * @return true if it ran successfully, else false * * @throws IOException on any error * @throws InterruptedException if interrupted wile waiting for the process to exit. */ protected boolean runProfilingCommand(List<String> command, Map<String, String> env, String logPrefix, File targetDir) throws IOException, InterruptedException { _type.assertFull(); Process p = ClientSupervisorUtils.launchProcess(command, env, logPrefix, null, targetDir); int ret = p.waitFor(); return ret == 0; }
@Override protected void launchWorkerProcess(List<String> command, Map<String, String> env, String logPrefix, ExitCodeCallback processExitCallback, File targetDir) throws IOException { String workerDir = targetDir.getAbsolutePath(); String user = this.getWorkerUser(); List<String> args = Arrays.asList("worker", workerDir, ServerUtils.writeScript(workerDir, command, env)); List<String> commandPrefix = null; if (_resourceIsolationManager != null) { commandPrefix = _resourceIsolationManager.getLaunchCommandPrefix(_workerId); } ClientSupervisorUtils.processLauncher(_conf, user, commandPrefix, args, null, logPrefix, processExitCallback, targetDir); }
public static void setupStormCodeDir(Map<String, Object> conf, String user, String dir) throws IOException { if (ObjectReader.getBoolean(conf.get(Config.SUPERVISOR_RUN_WORKER_AS_USER), false)) { String logPrefix = "Storm Code Dir Setup for " + dir; List<String> commands = new ArrayList<>(); commands.add("code-dir"); commands.add(dir); processLauncherAndWait(conf, user, commands, null, logPrefix); } }
static Process processLauncher(Map<String, Object> conf, String user, List<String> commandPrefix, List<String> args, Map<String, String> environment, final String logPreFix, final ExitCodeCallback exitCodeCallback, File dir) throws IOException { if (StringUtils.isBlank(user)) { throw new IllegalArgumentException("User cannot be blank when calling processLauncher."); } String wlinitial = (String) (conf.get(Config.SUPERVISOR_WORKER_LAUNCHER)); String stormHome = ConfigUtils.concatIfNotNull(System.getProperty(ConfigUtils.STORM_HOME)); String wl; if (StringUtils.isNotBlank(wlinitial)) { wl = wlinitial; } else { wl = stormHome + "/bin/worker-launcher"; } List<String> commands = new ArrayList<>(); if (commandPrefix != null) { commands.addAll(commandPrefix); } commands.add(wl); commands.add(user); commands.addAll(args); LOG.info("Running as user: {} command: {}", user, commands); return launchProcess(commands, environment, logPreFix, exitCodeCallback, dir); }
if (ClientSupervisorUtils.doRequiredTopoFilesExist(conf, currentAssignment.get_topology_id())) { container = containerLauncher.recoverContainer(port, currentAssignment, localState); } else {
public static void setupWorkerArtifactsDir(Map<String, Object> conf, String user, String dir) throws IOException { if (ObjectReader.getBoolean(conf.get(Config.SUPERVISOR_RUN_WORKER_AS_USER), false)) { String logPrefix = "Worker Artifacts Setup for " + dir; List<String> commands = new ArrayList<>(); commands.add("artifacts-dir"); commands.add(dir); processLauncherAndWait(conf, user, commands, null, logPrefix); } } }
private void signal(long pid, int signal) throws IOException { List<String> commands = Arrays.asList("signal", String.valueOf(pid), String.valueOf(signal)); String user = getWorkerUser(); String logPrefix = "kill -" + signal + " " + pid; ClientSupervisorUtils.processLauncherAndWait(_conf, user, commands, null, logPrefix); }
public static void rmrAsUser(Map<String, Object> conf, String id, String path) throws IOException { String user = ServerUtils.getFileOwner(path); String logPreFix = "rmr " + id; List<String> commands = new ArrayList<>(); commands.add("rmr"); commands.add(path); ClientSupervisorUtils.processLauncherAndWait(conf, user, commands, null, logPreFix); if (Utils.checkFileExists(path)) { throw new RuntimeException(path + " was not deleted."); } }
/** * Set permission of log file so that logviewer can serve the file. * * @param fileName log file */ public void setLogFilePermission(String fileName) throws IOException { File file = new File(logRootDir, fileName).getCanonicalFile(); boolean runAsUser = ObjectReader.getBoolean(stormConf.get(SUPERVISOR_RUN_WORKER_AS_USER), false); File parent = new File(logRootDir, fileName).getParentFile(); Optional<File> mdFile = (parent == null) ? Optional.empty() : getMetadataFileForWorkerLogDir(parent); Optional<String> topoOwner = mdFile.isPresent() ? Optional.of(getTopologyOwnerFromMetadataFile(mdFile.get().getCanonicalPath())) : Optional.empty(); if (runAsUser && topoOwner.isPresent() && file.exists() && !Files.isReadable(file.toPath())) { LOG.debug("Setting permissions on file {} with topo-owner {}", fileName, topoOwner); try { ClientSupervisorUtils.processLauncherAndWait(stormConf, topoOwner.get(), Lists.newArrayList("blob", file.getCanonicalPath()), null, "setup group read permissions for file: " + fileName); } catch (IOException e) { numSetPermissionsExceptions.mark(); throw e; } } }
@Override public void deleteIfExists(File path, String user, String logPrefix) throws IOException { String absolutePath = path.getAbsolutePath(); if (Utils.checkFileExists(absolutePath)) { LOG.info("Deleting path (runAsUser) {}", absolutePath); if (user == null) { user = Files.getOwner(path.toPath()).getName(); } List<String> commands = new ArrayList<>(); commands.add("rmr"); commands.add(absolutePath); ClientSupervisorUtils.processLauncherAndWait(_conf, user, commands, null, logPrefix); if (Utils.checkFileExists(absolutePath)) { // It's possible that permissions were not set properly on the directory, and // the user who is *supposed* to own the dir does not. In this case, try the // delete as the supervisor user. Utils.forceDelete(absolutePath); if (Utils.checkFileExists(absolutePath)) { throw new RuntimeException(path + " was not deleted."); } } } }
@Override protected boolean runProfilingCommand(List<String> command, Map<String, String> env, String logPrefix, File targetDir) throws IOException, InterruptedException { String user = this.getWorkerUser(); String td = targetDir.getAbsolutePath(); LOG.info("Running as user: {} command: {}", user, command); String containerFile = ServerUtils.containerFilePath(td); if (Utils.checkFileExists(containerFile)) { SupervisorUtils.rmrAsUser(_conf, containerFile, containerFile); } String scriptFile = ServerUtils.scriptFilePath(td); if (Utils.checkFileExists(scriptFile)) { SupervisorUtils.rmrAsUser(_conf, scriptFile, scriptFile); } String script = ServerUtils.writeScript(td, command, env); List<String> args = Arrays.asList("profiler", td, script); int ret = ClientSupervisorUtils.processLauncherAndWait(_conf, user, args, env, logPrefix); return ret == 0; }