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));
}
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;
}
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);
}
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);
}
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);
}
}
}
Aggregations