Search in sources :

Example 1 with CommandLineExitException

use of com.hazelcast.simulator.utils.CommandLineExitException in project hazelcast-simulator by hazelcast.

the class HarakiriMonitor method start.

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

Example 2 with CommandLineExitException

use of com.hazelcast.simulator.utils.CommandLineExitException in project hazelcast-simulator by hazelcast.

the class CoordinatorCli method loadRawTestSuite.

private TestSuite loadRawTestSuite() {
    String content;
    List testsuiteFiles = options.nonOptionArguments();
    File defaultTestProperties = new File("test.properties");
    if (testsuiteFiles.size() > 1) {
        throw new CommandLineExitException(format("Too many TestSuite files specified: %s", testsuiteFiles));
    } else if (testsuiteFiles.size() == 1) {
        content = (String) testsuiteFiles.get(0);
    } else if (defaultTestProperties.exists()) {
        content = defaultTestProperties.getPath();
    } else {
        return null;
    }
    TestSuite testSuite;
    File testSuiteFile = new File(content);
    if (testSuiteFile.exists()) {
        LOGGER.info("Loading TestSuite file: " + testSuiteFile.getAbsolutePath());
        testSuite = new TestSuite(testSuiteFile);
    } else if (!content.endsWith(".properties")) {
        testSuite = new TestSuite(content);
    } else {
        throw new CommandLineExitException(format("TestSuite file '%s' not found", testSuiteFile));
    }
    return testSuite;
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) List(java.util.List) File(java.io.File)

Example 3 with CommandLineExitException

use of com.hazelcast.simulator.utils.CommandLineExitException in project hazelcast-simulator by hazelcast.

the class CoordinatorCli method getDurationSeconds.

public static int getDurationSeconds(OptionSet options, OptionSpec<String> optionSpec) {
    int duration;
    String value = options.valueOf(optionSpec);
    try {
        if (value.endsWith("s")) {
            duration = parseDurationWithoutLastChar(SECONDS, value);
        } else if (value.endsWith("m")) {
            duration = parseDurationWithoutLastChar(MINUTES, value);
        } else if (value.endsWith("h")) {
            duration = parseDurationWithoutLastChar(HOURS, value);
        } else if (value.endsWith("d")) {
            duration = parseDurationWithoutLastChar(DAYS, value);
        } else {
            duration = Integer.parseInt(value);
        }
    } catch (NumberFormatException e) {
        throw new CommandLineExitException(format("Failed to parse duration '%s'", value), e);
    }
    if (duration < 0) {
        throw new CommandLineExitException("duration must be a positive number, but was: " + duration);
    }
    return duration;
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException)

Example 4 with CommandLineExitException

use of com.hazelcast.simulator.utils.CommandLineExitException in project hazelcast-simulator by hazelcast.

the class CoordinatorRemoteCli method loadAddresses.

private static List<String> loadAddresses(OptionSet options, OptionSpec<String> spec, AddressLevel addressLevel) {
    String addresses = options.valueOf(spec);
    if (addresses == null) {
        return null;
    }
    List<String> result = new LinkedList<String>();
    for (String addressString : addresses.split(",")) {
        if (addressString != null) {
            SimulatorAddress address;
            try {
                address = SimulatorAddress.fromString(addressString);
            } catch (Exception e) {
                throw new CommandLineExitException("Worker address [" + addressString + "] is not a valid simulator address", e);
            }
            if (!address.getAddressLevel().equals(addressLevel)) {
                throw new CommandLineExitException("address [" + addressString + "] is not a valid " + addressLevel + " address, it's a " + address.getAddressLevel() + " address");
            }
        }
        result.add(addressString);
    }
    return result;
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) SimulatorAddress(com.hazelcast.simulator.protocol.core.SimulatorAddress) LinkedList(java.util.LinkedList) CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) NotBoundException(java.rmi.NotBoundException) MalformedURLException(java.net.MalformedURLException) RemoteException(java.rmi.RemoteException)

Example 5 with CommandLineExitException

use of com.hazelcast.simulator.utils.CommandLineExitException in project hazelcast-simulator by hazelcast.

the class AgentsSshCli method executeCommand.

private void executeCommand() {
    List commands = options.nonOptionArguments();
    if (commands.size() != 1) {
        throw new CommandLineExitException("1 argument expected");
    }
    String command = (String) commands.get(0);
    String sshOptions = properties.get("SSH_OPTIONS");
    String simulatorUser = properties.get("SIMULATOR_USER");
    for (AgentData agent : findAgents()) {
        System.out.println("[" + agent.getPublicAddress() + "]");
        new BashCommand("ssh -n -o LogLevel=quiet " + sshOptions + " " + simulatorUser + "@" + agent.getPublicAddress() + " '" + command + "'").setSystemOut(true).addEnvironment(properties.asMap()).execute();
    }
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) BashCommand(com.hazelcast.simulator.utils.BashCommand) AgentData(com.hazelcast.simulator.coordinator.registry.AgentData) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) AgentData.publicAddressesString(com.hazelcast.simulator.coordinator.registry.AgentData.publicAddressesString)

Aggregations

CommandLineExitException (com.hazelcast.simulator.utils.CommandLineExitException)16 File (java.io.File)6 AgentData (com.hazelcast.simulator.coordinator.registry.AgentData)3 AgentData.publicAddressesString (com.hazelcast.simulator.coordinator.registry.AgentData.publicAddressesString)2 Registry (com.hazelcast.simulator.coordinator.registry.Registry)2 BashCommand (com.hazelcast.simulator.utils.BashCommand)2 FileUtils.ensureExistingFile (com.hazelcast.simulator.utils.FileUtils.ensureExistingFile)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 AgentsFile (com.hazelcast.simulator.common.AgentsFile)1 SimulatorAddress (com.hazelcast.simulator.protocol.core.SimulatorAddress)1 FileUtils.getConfigurationFile (com.hazelcast.simulator.utils.FileUtils.getConfigurationFile)1 FileUtils.newFile (com.hazelcast.simulator.utils.FileUtils.newFile)1 FileUtils.toTextFromResourceFile (com.hazelcast.simulator.utils.FileUtils.toTextFromResourceFile)1 TagUtils.tagsToString (com.hazelcast.simulator.utils.TagUtils.tagsToString)1 UuidUtil.newUnsecureUuidString (com.hazelcast.simulator.utils.UuidUtil.newUnsecureUuidString)1 WizardUtils.copyResourceFile (com.hazelcast.simulator.wizard.WizardUtils.copyResourceFile)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 NotBoundException (java.rmi.NotBoundException)1