public static void sendSignalToProcess(long lpid, int signum) throws IOException { String pid = Long.toString(lpid); try { if (Utils.isOnWindows()) { if (signum == SIGKILL) { execCommand("taskkill", "/f", "/pid", pid); } else { execCommand("taskkill", "/pid", pid); } } else { execCommand("kill", "-" + signum, pid); } } catch (ExecuteException e) { LOG.info("Error when trying to kill {}. Process is probably already dead.", pid); } catch (IOException e) { LOG.info("IOException Error when trying to kill {}.", pid); throw e; } }
public static BlobStore getNimbusBlobStore(Map<String, Object> conf, NimbusInfo nimbusInfo, ILeaderElector leaderElector) { return getNimbusBlobStore(conf, null, nimbusInfo, leaderElector); }
private static String resourcesJar() throws IOException { String path = ServerUtils.currentClasspath(); if (path == null) { return null; } for (String jpath : path.split(File.pathSeparator)) { if (jpath.endsWith(".jar")) { if (ServerUtils.zipDoesContainDir(jpath, ServerConfigUtils.RESOURCES_SUBDIR)) { return jpath; } } } return null; }
/** * Given a Tar File as input it will untar the file in a the untar directory passed as the second parameter * <p/> * This utility will untar ".tar" files and ".tar.gz","tgz" files. * * @param inFile The tar file as input. * @param untarDir The untar directory where to untar the tar file. * @param symlinksDisabled true if symlinks should be disabled, else false. * @throws IOException */ public static void unTar(File inFile, File untarDir, boolean symlinksDisabled) throws IOException { ensureDirectory(untarDir); boolean gzipped = inFile.toString().endsWith("gz"); if (Utils.isOnWindows() || symlinksDisabled) { // Tar is not native to Windows. Use simple Java based implementation for // tests and simple tar archives unTarUsingJava(inFile, untarDir, gzipped, symlinksDisabled); } else { // spawn tar utility to untar archive for full fledged unix behavior such // as resolving symlinks in tar archives unTarUsingTar(inFile, untarDir, gzipped); } }
@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; }
ensureDirectory(target); for (TarArchiveEntry e : entry.getDirectoryEntries()) { unpackEntries(tis, e, target, base, symlinksDisabled); ensureDirectory(target.getParentFile()); try (BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(target))) { IOUtils.copy(tis, outputStream); Files.setPosixFilePermissions(p, parsePerms(mode)); } catch (UnsupportedOperationException e) {
String key = getKey(); ReadableBlobMeta meta = store.getBlobMeta(key); if (!ServerUtils.canUserReadBlob(meta, user, conf)) { throw new WrappedAuthorizationException(user + " does not have READ access to " + key); Path downloadFile = finalLocation; finalLocation = constructBlobWithVersionFileName(baseDir, getKey(), downloadMeta.getVersion()); ServerUtils.unpack(downloadFile.toFile(), finalLocation.toFile(), symLinksDisabled); LOG.debug("Uncompressed {} to: {}", downloadFile, finalLocation);
/** * Extract dir from the jar to destdir * * @param jarpath Path to the jar file * @param dir Directory in the jar to pull out * @param destdir Path to the directory where the extracted directory will be put */ public static void extractDirFromJar(String jarpath, String dir, File destdir) { _instance.extractDirFromJarImpl(jarpath, dir, destdir); }
/** * Returns the value of java.class.path System property. Kept separate for testing. * * @return the classpath */ public static String currentClasspath() { return _instance.currentClasspathImpl(); }
/** * Meant to be called only by the supervisor for stormjar/stormconf/stormcode files. * * @param key * @param localFile * @param cb * @throws AuthorizationException * @throws KeyNotFoundException * @throws IOException */ public static void downloadResourcesAsSupervisor(String key, String localFile, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException, IOException { _instance.downloadResourcesAsSupervisorImpl(key, localFile, cb); }
public void downloadResourcesAsSupervisorImpl(String key, String localFile, ClientBlobStore cb) throws AuthorizationException, KeyNotFoundException, IOException { final int MAX_RETRY_ATTEMPTS = 2; final int ATTEMPTS_INTERVAL_TIME = 100; for (int retryAttempts = 0; retryAttempts < MAX_RETRY_ATTEMPTS; retryAttempts++) { if (downloadResourcesAsSupervisorAttempt(cb, key, localFile)) { break; } Utils.sleep(ATTEMPTS_INTERVAL_TIME); } } }
private static void extractZipFile(ZipFile zipFile, File toDir, String prefix) throws IOException { ensureDirectory(toDir); final String base = toDir.getCanonicalPath(); Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (!entry.isDirectory()) { if (prefix != null && !entry.getName().startsWith(prefix)) { //No need to extract it, it is not what we are looking for. continue; } File file = new File(toDir, entry.getName()); String found = file.getCanonicalPath(); if (!found.startsWith(base)) { LOG.error("Invalid location {} is outside of {}", found, base); continue; } try (InputStream in = zipFile.getInputStream(entry)) { ensureDirectory(file.getParentFile()); try (OutputStream out = new FileOutputStream(file)) { IOUtils.copy(in, out); } } } } }
public static ClientBlobStore getClientBlobStoreForSupervisor(Map<String, Object> conf) { ClientBlobStore store; if (ConfigUtils.isLocalMode(conf)) { store = new LocalModeClientBlobStore(getNimbusBlobStore(conf, null, null)); } else { store = (ClientBlobStore) ReflectionUtils.newInstance( (String) conf.get(DaemonConfig.SUPERVISOR_BLOBSTORE)); } store.prepare(conf); return store; }
public static void main(String[] args) throws Exception { if (args.length <= 1) { LOG.error("Arguments should be of the form: <path_to_jar> [argument...]"); System.exit(-1); } Map<String,Object> conf = ConfigUtils.readStormConfig(); try (NimbusClient client = NimbusClient.getConfiguredClient(conf)) { NimbusSummary ns = client.getClient().getLeader(); String host = ns.get_host(); int port = ns.get_port(); String jarPath = StormSubmitter.submitJar(conf, args[0]); String[] newArgs = (String[]) ArrayUtils.addAll(Arrays.copyOfRange(args, 1, args.length), new String[]{host, String.valueOf(port), jarPath}); ServerUtils.execCommand(newArgs); } } }
@Override public void run(String[] args, Map<String, Object> conf, String command) throws Exception { for (String arg: args) { System.out.println(arg + ":"); StormTopology topo; File f = new File(arg); if (f.exists()) { topo = Utils.deserialize(FileUtils.readFileToByteArray(f), StormTopology.class); } else { //assume it is a topology id final String key = ConfigUtils.masterStormCodeKey(arg); try (BlobStore store = ServerUtils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf), null)) { topo = Utils.deserialize(store.readBlob(key, Nimbus.NIMBUS_SUBJECT), StormTopology.class); } } System.out.println(prettyPrint(topo)); } }
@Override public void run(String[] args, Map<String, Object> conf, String command) throws Exception { try (BlobStore nimbusBlobStore = ServerUtils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf), null)) { IStormClusterState stormClusterState = ClusterUtils.mkStormClusterState(conf, new ClusterStateContext(DaemonType.NIMBUS, conf)); Set<String> blobStoreTopologyIds = nimbusBlobStore.filterAndListKeys(key -> ConfigUtils.getIdFromBlobKey(key)); Set<String> activeTopologyIds = new HashSet<>(stormClusterState.activeStorms()); Sets.SetView<String> diffTopology = Sets.difference(activeTopologyIds, blobStoreTopologyIds); LOG.info("active-topology-ids [{}] blob-topology-ids [{}] diff-topology [{}]", activeTopologyIds, blobStoreTopologyIds, diffTopology); for (String corruptId : diffTopology) { stormClusterState.removeStorm(corruptId); } } }
BlobStore bs = ServerUtils.getNimbusBlobStore(conf, NimbusInfo.fromConf(conf), null); try { Subject nimbusSubject = new Subject();
blobStore = ServerUtils.getNimbusBlobStore(conf, this.nimbusHostPortInfo, null);