static Integer getPidFromManagementBean() { String name = ManagementFactory.getRuntimeMXBean().getName(); return getPidFromBeanString(name); }
/** * http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id * * @return the PID of this JVM or <tt>-1</tt> if not PID was retrieved */ public static int getPID() { Integer pid = getPidFromManagementBean(); if (pid != null) { return pid; } pid = getPidViaReflection(); if (pid != null) { return pid; } return -1; }
private void downloadLocal() { LOGGER.info("Retrieving artifacts of local machine"); File workerHome = newFile(getSimulatorHome(), WORKERS_HOME_NAME); String workerPath = workerHome.getAbsolutePath(); if ("*".equals(sessionId)) { execute(format("cp -r %s/* %s || true", workerPath, outputDirectory.getAbsolutePath())); } else { execute(format("cp -r %s/%s/* %s || true", workerPath, sessionId, outputDirectory.getAbsolutePath())); } execute(format("mv ./agent.err %s/ || true", outputDirectory.getAbsolutePath())); execute(format("mv ./agent.out %s/ || true", outputDirectory.getAbsolutePath())); }
private void createPidFile() { deleteQuiet(pidFile); writeText("" + getPID(), pidFile); }
public static void main(String[] args) { int pid = NativeUtils.getPID(); LOGGER.info("PID: " + pid); writeText("" + pid, new File(getUserDir(), "worker.pid")); try { startWorker(); } catch (Exception e) { ExceptionReporter.report(null, e); exitWithError(LOGGER, "Could not start Hazelcast Simulator Worker!", e); } }
/** * http://stackoverflow.com/questions/35842/how-can-a-java-program-get-its-own-process-id * * @return the PID of this JVM or <tt>-1</tt> if not PID was retrieved */ public static int getPID() { Integer pid = getPidFromManagementBean(); if (pid != null) { return pid; } pid = getPidViaReflection(); if (pid != null) { return pid; } return -1; }
static Integer getPidFromManagementBean() { String name = ManagementFactory.getRuntimeMXBean().getName(); return getPidFromBeanString(name); }
logInputArguments(); logInterestingSystemProperties(); echo("process ID: " + getPID());
private void cleanLocal() { File workerHome = newFile(getSimulatorHome(), WORKERS_HOME_NAME); LOGGER.info(format("Cleaning local worker directory %s ...", workerHome.getAbsolutePath())); String workerPath = workerHome.getAbsolutePath(); execute(format("rm -fr %s || true", workerPath)); LOGGER.info("Cleaning local worker directory complete!"); }
private void copyResourcesToWorkerHome(String workerId) { File workersHome = new File(getSimulatorHome(), WORKERS_HOME_NAME); String sessionId = agent.getSessionId(); File uploadDirectory = new File(workersHome, sessionId + "/upload/").getAbsoluteFile(); if (!uploadDirectory.exists() || !uploadDirectory.isDirectory()) { LOGGER.debug("Skip copying upload directory to workers since no upload directory was found"); return; } String copyCommand = format("cp -rfv %s/%s/upload/* %s/%s/%s/ || true", workersHome, sessionId, workersHome, sessionId, workerId); execute(copyCommand); LOGGER.info(format("Finished copying '%s' to Worker", workersHome)); }
void start() { if (!isEC2(cloudProvider)) { LOGGER.info("No Harakiri monitor is active: only on AWS-EC2 unused machines will be terminated."); return; } LOGGER.info(format("Harakiri monitor is active and will wait %d seconds to kill this instance", waitSeconds)); sleepSeconds(waitSeconds); LOGGER.info("Trying to commit Harakiri once!"); try { LOGGER.info("Harakiri command: " + command); execute(command); } catch (Exception e) { throw new CommandLineExitException("Failed to execute Harakiri", e); } }
static void copyResourceFile(File workDir, String targetName, String sourceName) { File runScript = ensureExistingFile(workDir, targetName); writeText(getResourceFile(sourceName), runScript); execute(format("chmod u+x %s", runScript.getAbsolutePath())); }
void createSshCopyIdScript(SimulatorProperties simulatorProperties) { ComponentRegistry componentRegistry = loadComponentRegister(agentFile, true); String userName = simulatorProperties.getUser(); ensureExistingFile(SSH_COPY_ID_FILE); writeText("#!/bin/bash" + NEW_LINE + NEW_LINE, SSH_COPY_ID_FILE); for (AgentData agentData : componentRegistry.getAgents()) { String publicAddress = agentData.getPublicAddress(); appendText(format("ssh-copy-id -i ~/.ssh/id_rsa.pub %s@%s%n", userName, publicAddress), SSH_COPY_ID_FILE); } execute(format("chmod u+x %s", SSH_COPY_ID_FILE.getAbsoluteFile())); echo("Please execute './%s' to copy your public RSA key to all remote machines.", SSH_COPY_ID_FILE.getName()); }
simulatorProperties.get("MACHINE_SPEC")), simulatorPropertiesFile); } else if (isGCE(cloudProvider)) { String currentUser = execute("whoami").trim();