use of com.hazelcast.simulator.utils.BashCommand in project hazelcast-simulator by hazelcast.
the class AgentUtils method startAgents.
public static void startAgents(SimulatorProperties properties, Registry registry) {
String startScript = getConfigurationFile("agent_start.sh").getAbsolutePath();
new BashCommand(startScript).ensureJavaOnPath().addParams(publicAddressesString(registry)).addEnvironment(properties.asMap()).addEnvironment("parentPid", NativeUtils.getPID()).execute();
}
use of com.hazelcast.simulator.utils.BashCommand in project hazelcast-simulator by hazelcast.
the class PrepareSessionTask method run.
public void run() {
String installFile = getConfigurationFile("prepare_session.sh").getAbsolutePath();
String agentIps = join(agents, ",");
new BashCommand(installFile).addEnvironment(simulatorProperties).addParams(uploadDir.getAbsolutePath(), sessionId, agentIps).execute();
}
use of com.hazelcast.simulator.utils.BashCommand in project hazelcast-simulator by hazelcast.
the class Provisioner method scaleUp.
@SuppressWarnings("PMD.PreserveStackTrace")
private void scaleUp(int delta, Map<String, String> tags) {
logWithRuler("Provisioning %s %s machines", delta, properties.getCloudProvider());
log("Current number of machines: " + registry.agentCount());
log("Desired number of machines: " + (registry.agentCount() + delta));
String groupName = properties.get("GROUP_NAME", "simulator-agent");
log("GroupName: " + groupName);
log("Username: " + properties.getUser());
log("Using init script: " + initScriptFile.getAbsolutePath());
String jdkFlavor = properties.getJdkFlavor();
if ("outofthebox".equals(jdkFlavor)) {
log("JDK spec: outofthebox");
} else {
String jdkVersion = properties.getJdkVersion();
log("JDK spec: %s %s", jdkFlavor, jdkVersion);
}
long started = System.nanoTime();
String startHarakiriMonitorCommand = getStartHarakiriMonitorCommandOrNull(properties);
try {
log("Creating machines (can take a few minutes)...");
new BashCommand(getConfigurationFile("aws-ec2_provision.sh").getAbsolutePath()).addEnvironment(properties.asMap()).addParams(delta).execute();
String[] agentLines = fileAsText(agentsFile).split("\n");
Set<Future> futures = new HashSet<Future>();
for (int k = 0; k < delta; k++) {
String agentLine = agentLines[k + registry.agentCount()];
String publicIpAddress = agentLine.split(",")[0];
Future future = executor.submit(new InstallNodeTask(publicIpAddress, startHarakiriMonitorCommand));
futures.add(future);
}
for (Future future : futures) {
future.get();
}
} catch (Exception e) {
throw new CommandLineExitException("Failed to provision machines: " + e.getMessage());
}
long elapsed = getElapsedSeconds(started);
logWithRuler("Successfully provisioned %s %s machines (%s seconds)", delta, properties.getCloudProvider(), elapsed);
}
use of com.hazelcast.simulator.utils.BashCommand in project hazelcast-simulator by hazelcast.
the class Provisioner method installSimulator.
private void installSimulator(String ip) {
new BashCommand(getConfigurationFile("install-simulator.sh").getAbsolutePath()).addEnvironment(properties.asMap()).addParams(ip).execute();
// execute the init.sh script
File initFile = newFile("init-" + newUnsecureUuidString() + ".sh");
writeText(loadInitScript(), initFile);
bash.scpToRemote(ip, initFile, "init.sh");
bash.sshTTY(ip, "bash init.sh");
deleteQuiet(initFile);
}
use of com.hazelcast.simulator.utils.BashCommand in project hazelcast-simulator by hazelcast.
the class Provisioner method scaleDown.
private void scaleDown(int count) {
if (count > registry.agentCount()) {
count = registry.agentCount();
}
logWithRuler("Terminating %s %s machines (can take some time)", count, properties.getCloudProvider());
log("Current number of machines: " + registry.agentCount());
log("Desired number of machines: " + (registry.agentCount() - count));
long started = System.nanoTime();
int destroyedCount = 0;
List<String> privateIps = new LinkedList<String>();
List<AgentData> agents = registry.getAgents();
for (int k = 0; k < count; k++) {
privateIps.add(agents.get(k).getPrivateAddress());
destroyedCount++;
}
new BashCommand(getConfigurationFile("aws-ec2_terminate.sh").getAbsolutePath()).addEnvironment(properties.asMap()).addParams(join(privateIps, ",")).execute();
for (int k = 0; k < count; k++) {
registry.removeAgent(agents.get(k));
}
log("Updating " + agentsFile.getAbsolutePath());
AgentsFile.save(agentsFile, registry);
long elapsed = getElapsedSeconds(started);
logWithRuler("Terminated %s of %s machines (%s remaining) (%s seconds)", destroyedCount, count, registry.agentCount(), elapsed);
if (destroyedCount != count) {
throw new IllegalStateException("Terminated " + destroyedCount + " of " + count + NEW_LINE + "1) You are trying to terminate physical hardware that you own (unsupported feature)" + NEW_LINE + "2) If and only if you are using AWS our Harakiri Monitor might have terminated them" + NEW_LINE + "3) You have not payed you bill and your instances have been terminated by your cloud provider" + NEW_LINE + "4) You have terminated your own instances (perhaps via some console interface)" + NEW_LINE + "5) Someone else has terminated your instances" + NEW_LINE + "Please try again!");
}
}
Aggregations