Search in sources :

Example 6 with BashCommand

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();
}
Also used : BashCommand(com.hazelcast.simulator.utils.BashCommand) AgentData.publicAddressesString(com.hazelcast.simulator.coordinator.registry.AgentData.publicAddressesString)

Example 7 with BashCommand

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();
}
Also used : BashCommand(com.hazelcast.simulator.utils.BashCommand)

Example 8 with BashCommand

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);
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) BashCommand(com.hazelcast.simulator.utils.BashCommand) Future(java.util.concurrent.Future) UuidUtil.newUnsecureUuidString(com.hazelcast.simulator.utils.UuidUtil.newUnsecureUuidString) CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) HashSet(java.util.HashSet)

Example 9 with BashCommand

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);
}
Also used : BashCommand(com.hazelcast.simulator.utils.BashCommand) FileUtils.newFile(com.hazelcast.simulator.utils.FileUtils.newFile) AgentsFile(com.hazelcast.simulator.common.AgentsFile) File(java.io.File) FileUtils.getConfigurationFile(com.hazelcast.simulator.utils.FileUtils.getConfigurationFile) ProvisionerUtils.getInitScriptFile(com.hazelcast.simulator.provisioner.ProvisionerUtils.getInitScriptFile)

Example 10 with BashCommand

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!");
    }
}
Also used : BashCommand(com.hazelcast.simulator.utils.BashCommand) AgentData(com.hazelcast.simulator.coordinator.registry.AgentData) UuidUtil.newUnsecureUuidString(com.hazelcast.simulator.utils.UuidUtil.newUnsecureUuidString) LinkedList(java.util.LinkedList)

Aggregations

BashCommand (com.hazelcast.simulator.utils.BashCommand)12 AgentData.publicAddressesString (com.hazelcast.simulator.coordinator.registry.AgentData.publicAddressesString)4 AgentData (com.hazelcast.simulator.coordinator.registry.AgentData)2 CommandLineExitException (com.hazelcast.simulator.utils.CommandLineExitException)2 UuidUtil.newUnsecureUuidString (com.hazelcast.simulator.utils.UuidUtil.newUnsecureUuidString)2 AgentsFile (com.hazelcast.simulator.common.AgentsFile)1 ProvisionerUtils.getInitScriptFile (com.hazelcast.simulator.provisioner.ProvisionerUtils.getInitScriptFile)1 FileUtils.getConfigurationFile (com.hazelcast.simulator.utils.FileUtils.getConfigurationFile)1 FileUtils.newFile (com.hazelcast.simulator.utils.FileUtils.newFile)1 File (java.io.File)1 Collections.singletonList (java.util.Collections.singletonList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 Future (java.util.concurrent.Future)1