Search in sources :

Example 11 with CommandLineExitException

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

the class AgentsSshCli method findAgents.

private List<AgentData> findAgents() {
    List<AgentData> agents = registry.getAgents();
    String agentAddress = agentSpec.value(options);
    if (agentAddress == null) {
        return agents;
    }
    for (AgentData agent : agents) {
        if (agent.getPublicAddress().equals(agentAddress) || agent.getPrivateAddress().equals(agentAddress) || agent.getAddress().toString().equals(agentAddress)) {
            return singletonList(agent);
        }
    }
    throw new CommandLineExitException(format("Could not found agent [%s]", agentAddress));
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) AgentData(com.hazelcast.simulator.coordinator.registry.AgentData) AgentData.publicAddressesString(com.hazelcast.simulator.coordinator.registry.AgentData.publicAddressesString)

Example 12 with CommandLineExitException

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

the class AgentsFile method load.

public static Registry load(File agentFile) {
    Registry registry = new Registry();
    String content = fileAsText(agentFile);
    String[] lines = content.split(NEW_LINE);
    int lineNumber = 0;
    for (String line : lines) {
        lineNumber++;
        line = cleanLine(line);
        if (line.isEmpty()) {
            continue;
        }
        int tagsIndex = line.indexOf('|');
        String addressesString = tagsIndex == -1 ? line : line.substring(0, tagsIndex);
        String tagsString = tagsIndex == -1 ? "" : line.substring(tagsIndex + 1);
        String publicIpAddress;
        String privateIpAddress;
        String[] addresses = addressesString.split(",");
        switch(addresses.length) {
            case 1:
                publicIpAddress = addresses[0];
                privateIpAddress = addresses[0];
                break;
            case 2:
                publicIpAddress = addresses[0];
                privateIpAddress = addresses[1];
                break;
            default:
                throw new CommandLineExitException(format("Line %s of file %s is invalid!" + " It should contain one or two IP addresses separated by a comma," + " but it contains %s", lineNumber, agentFile, addresses.length));
        }
        Map<String, String> tags = TagUtils.parseTags(tagsString);
        registry.addAgent(publicIpAddress, privateIpAddress, tags);
    }
    return registry;
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) Registry(com.hazelcast.simulator.coordinator.registry.Registry) TagUtils.tagsToString(com.hazelcast.simulator.utils.TagUtils.tagsToString)

Example 13 with CommandLineExitException

use of com.hazelcast.simulator.utils.CommandLineExitException 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 14 with CommandLineExitException

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

the class VendorDriver method loadWorkerScript.

protected String loadWorkerScript(String workerType) {
    List<File> files = new LinkedList<File>();
    File confDir = new File(getSimulatorHome(), "conf");
    String vendor = properties.get("VENDOR");
    files.add(new File("worker-" + vendor + "-" + workerType + ".sh").getAbsoluteFile());
    files.add(new File("worker-" + workerType + ".sh").getAbsoluteFile());
    files.add(new File("worker-" + vendor + ".sh").getAbsoluteFile());
    files.add(new File("worker.sh").getAbsoluteFile());
    files.add(new File(confDir, "worker-" + vendor + "-" + workerType + ".sh").getAbsoluteFile());
    files.add(new File(confDir, "worker-" + vendor + ".sh").getAbsoluteFile());
    files.add(new File(confDir, "worker.sh").getAbsoluteFile());
    for (File file : files) {
        if (file.exists()) {
            String key = workerType + "#" + file.getName();
            String config = configCache.get(key);
            if (config == null) {
                config = fileAsText(file);
                configCache.put(key, config);
                LOGGER.info("Loading " + vendor + " " + workerType + " worker script: " + file.getAbsolutePath());
            }
            return config;
        }
    }
    throw new CommandLineExitException("Failed to load worker script from the following locations:" + files);
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) File(java.io.File) FileUtils.getConfigurationFile(com.hazelcast.simulator.utils.FileUtils.getConfigurationFile) LinkedList(java.util.LinkedList)

Example 15 with CommandLineExitException

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

the class VendorDriver method loadVendorDriver.

public static VendorDriver loadVendorDriver(String vendorName) {
    LOGGER.info(format("Loading vendor-driver [%s]", vendorName));
    if (vendorName.equals("hazelcast") || vendorName.equals("hazelcast-enterprise")) {
        return new HazelcastDriver();
    } else {
        String driverName = "com.hazelcast.simulator." + vendorName + "." + vendorName.substring(0, 1).toUpperCase() + vendorName.substring(1) + "Driver";
        Class driverClass;
        try {
            driverClass = VendorDriver.class.getClassLoader().loadClass(driverName);
        } catch (ClassNotFoundException e) {
            throw new CommandLineExitException(format("Could not locate driver class [%s]", driverName));
        }
        try {
            return (VendorDriver) driverClass.newInstance();
        } catch (Exception e) {
            throw new CommandLineExitException(format("Failed to create an instance of driver [%s]", driverName), e);
        }
    }
}
Also used : CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) CommandLineExitException(com.hazelcast.simulator.utils.CommandLineExitException) IOException(java.io.IOException)

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