@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); }
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); } }
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 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); } } }
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; }