public ArtifactCleanTask(ComponentRegistry componentRegistry, SimulatorProperties simulatorProperties) { this.componentRegistry = componentRegistry; this.simulatorProperties = simulatorProperties; this.bash = new Bash(simulatorProperties); }
public String executeQuiet(String command) { return execute(command + " || true"); }
private void runRemote() { logger.info(format("Killing Java processes on %s", ip)); bash.killAllJavaProcesses(ip); logger.info(format("Starting Agent on %s", ip)); bash.ssh(ip, format("nohup hazelcast-simulator-%s/bin/agent %s%s%s > agent.out 2> agent.err < /dev/null &", SIMULATOR_VERSION, mandatoryParameters, optionalParameters, ec2Parameters)); bash.ssh(ip, format("hazelcast-simulator-%s/bin/.await-file-exists agent.pid", SIMULATOR_VERSION)); } }
private void uploadJARs(String ip) { String simulatorVersion = getSimulatorVersion(); bash.ssh(ip, format("mkdir -p hazelcast-simulator-%s/lib/", simulatorVersion)); bash.ssh(ip, format("mkdir -p hazelcast-simulator-%s/user-lib/", simulatorVersion)); bash.sshQuiet(ip, format("rm -f hazelcast-simulator-%s/lib/*", simulatorVersion)); bash.sshQuiet(ip, format("rm -f hazelcast-simulator-%s/user-lib/*", simulatorVersion)); bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/bin/", "bin"); bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/conf/", "conf"); bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/jdk-install/", "jdk-install"); bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/tests/", "tests"); bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/test-lib/", "test-lib/"); bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/user-lib/", "user-lib/"); bash.sshQuiet(ip, format("rm -rf hazelcast-simulator-%s/hz-lib", simulatorVersion));
public String ssh(String ip, String command) { return ssh(ip, command, false, false); }
private void uploadJava(String ip) { if ("outofthebox".equals(properties.getJdkFlavor())) { return; } bash.scpToRemote(ip, getJavaSupportScript(), "jdk-support.sh"); bash.scpToRemote(ip, getJavaInstallScript(), "install-java.sh"); bash.ssh(ip, "bash install-java.sh"); }
private void executeInitScript(String ip) { File initFile = newFile("init-" + newUnsecureUuidString() + ".sh"); writeText(loadInitScript(), initFile); bash.scpToRemote(ip, initFile, "init.sh"); bash.sshTTY(ip, "bash init.sh"); deleteQuiet(initFile); }
@Override public void run() { String workersPath = format("hazelcast-simulator-%s/workers/%s", getSimulatorVersion(), sessionId); String targetDirectory = "*".equals(sessionId) ? outputDirectory.getAbsolutePath() : outputDirectory.getParentFile().getAbsolutePath(); String rsyncCommand = format(RSYNC_COMMAND, "", sshOptions, sshUser, targetDirectory); LOGGER.info(format("Downloading Worker logs from %s", ip)); bash.executeQuiet(format(rsyncCommand, ip, workersPath)); } }
public void killAllJavaProcesses(String ip) { sshQuiet(ip, "killall -9 java"); }
private void uploadLibraryJar(String ip, String jarName) { bash.uploadToRemoteSimulatorDir(ip, simulatorPath + "/lib/" + jarName, "lib"); }
@Override public void run() { echo("Killing Java processes on %s", agentData.getPublicAddress()); bash.killAllJavaProcesses(agentData.getPublicAddress()); } });
public String sshTTY(String ip, String command) { return ssh(ip, command, false, true); }
private void download(AgentData agentData) { String ip = agentData.getPublicAddress(); String agentAddress = agentData.getAddress().toString(); LOGGER.info(format("Downloading Agent logs from %s", ip)); String outputPath = outputDirectory.getAbsolutePath(); String rsyncCommand = format(RSYNC_COMMAND, "--backup --suffix=-%s ", sshOptions, sshUser, outputPath); bash.executeQuiet(format(rsyncCommand, ip, ip, "agent.out")); bash.executeQuiet(format(rsyncCommand, ip, ip, "agent.err")); File agentOut = new File(outputPath, "agent.out"); File agentErr = new File(outputPath, "agent.err"); rename(agentOut, new File(outputPath, agentAddress + '-' + ip + "-agent.out")); rename(agentErr, new File(outputPath, agentAddress + '-' + ip + "-agent.err")); } }
public void sshQuiet(String ip, String command) { ssh(ip, command + " || true"); }
private static Bash newBash(SimulatorProperties simulatorProperties) { return new Bash(simulatorProperties); }
public void scpToRemote(String ip, File src, String target) { String command = format("scp -r %s %s %s@%s:%s", scpOptions, src.getAbsolutePath(), user, ip, target); execute(command); } }
private void runRemote() { logger.info(format("Stopping Agent %s", ip)); bash.ssh(ip, format("hazelcast-simulator-%s/bin/.kill-from-pid-file agent.pid", SIMULATOR_VERSION)); if (startHarakiriMonitorCommand != null) { logger.info(format("Starting HarakiriMonitor on %s", ip)); bash.ssh(ip, startHarakiriMonitorCommand); } } }
public ArtifactDownloadTask(String sessionId, SimulatorProperties simulatorProperties, File outputDirectory, ComponentRegistry componentRegistry) { this.sessionId = sessionId; this.simulatorProperties = simulatorProperties; this.outputDirectory = outputDirectory; this.componentRegistry = componentRegistry; this.bash = new Bash(simulatorProperties); this.sshOptions = simulatorProperties.getSshOptions(); this.sshUser = simulatorProperties.getUser(); }
public void uploadToRemoteSimulatorDir(String ip, String src, String target) { String command = format("rsync --checksum -avv -L -e \"ssh %s\" %s %s@%s:hazelcast-simulator-%s/%s", scpOptions, src, user, ip, getSimulatorVersion(), target); execute(command); }
@Override public void run() { if (!"outofthebox".equals(properties.getJdkFlavor())) { echo(INDENTATION + ip + " JAVA INSTALLATION STARTED..."); uploadJava(ip); echo(INDENTATION + ip + " JAVA INSTALLED"); } echo(INDENTATION + ip + " SIMULATOR INSTALLATION STARTED..."); uploadJARs(ip); echo(INDENTATION + ip + " SIMULATOR INSTALLED"); if (startHarakiriMonitorCommand != null) { bash.ssh(ip, startHarakiriMonitorCommand); echo(INDENTATION + ip + " HARAKIRI MONITOR STARTED"); } } }