public static RuntimeException rethrow(Throwable throwable) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } else { throw new CommandLineExitException(throwable); } }
@Override public void run() { String ip = agentData.getPublicAddress(); String result; try { result = bash.ssh(ip, format("[[ -f hazelcast-simulator-%s/bin/agent ]] && echo SIM-OK || echo SIM-NOK", SIMULATOR_VERSION), true, false).trim(); } catch (CommandLineExitException e) { throw new CommandLineExitException(format( "Could not connect to %s. Please check your agents.txt file for invalid IP addresses.%n%s", ip, e.getCause().getMessage())); } if (result.endsWith("SIM-NOK")) { throw new CommandLineExitException(format( "Simulator is not installed correctly on %s. Please run provisioner --install to fix this.", ip)); } } }
public static RuntimeException rethrow(Throwable throwable) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } else { throw new CommandLineExitException(throwable); } }
private static void checkParameters(int agentCount, int dedicatedMemberMachineCount, int memberWorkerCount, int clientWorkerCount) { if (agentCount == 0) { throw new CommandLineExitException("You need at least one agent in your cluster!" + " Please configure your agents.txt or run Provisioner."); } if (clientWorkerCount > 0 && agentCount - dedicatedMemberMachineCount < 1) { throw new CommandLineExitException( "there are no machines left for clients!"); } if (memberWorkerCount == 0 && clientWorkerCount == 0) { throw new CommandLineExitException("No workers have been defined!"); } }
public WorkerData getFirstWorker() { synchronized (workers) { if (workers.size() == 0) { throw new CommandLineExitException("No workers running!"); } return workers.get(0); } }
public AgentData getFirstAgent() { if (agents.size() == 0) { throw new CommandLineExitException("No agents running!"); } return agents.get(0); }
static void ensurePublicPrivateKeyExist(File publicKey, File privateKey) { if (!publicKey.exists()) { throw new CommandLineExitException("Public key " + publicKey.getAbsolutePath() + " not found." + NEW_LINE + "To create a public/private key pair execute [ssh-keygen -t rsa -C \"your_email@example.com\"]"); } if (!privateKey.exists()) { throw new CommandLineExitException("Public key " + publicKey.getAbsolutePath() + " was found, " + "but private key " + privateKey.getAbsolutePath() + " is missing" + NEW_LINE + "To create a public/private key pair execute [ssh-keygen -t rsa -C \"your_email@example.com\"]"); } }
private void check(File file) { if (!file.exists()) { throw new CommandLineExitException(format("Could not find %s: %s", PROPERTIES_FILE_NAME, file.getAbsolutePath())); } }
static File getInitScriptFile(String simulatorHome) { File initScript = new File(INIT_SH_SCRIPT_NAME); if (!initScript.exists()) { initScript = new File(simulatorHome + "/conf/" + INIT_SH_SCRIPT_NAME); } if (!initScript.exists()) { throw new CommandLineExitException(format("Could not find %s: %s", INIT_SH_SCRIPT_NAME, initScript)); } return initScript; }
private static File getAgentsFile() { File file = new File("agents.txt"); if (!file.exists()) { throw new CommandLineExitException(format("Agents file [%s] does not exist", file)); } LOGGER.info("Loading Agents file: " + file.getAbsolutePath()); return file; }
@SuppressWarnings("PMD.PreserveStackTrace") private static ContextBuilder newContextBuilder(String cloudProvider) { try { return newBuilder(cloudProvider); } catch (NoSuchElementException e) { throw new CommandLineExitException("Unrecognized cloud-provider [" + cloudProvider + ']'); } }
static void ensureIsRemoteSetup(SimulatorProperties properties, String action) { if (isLocal(properties)) { throw new CommandLineExitException(format("Cannot execute '%s' in local setup", action)); } }
static void ensureIsCloudProviderSetup(SimulatorProperties properties, String action) { if (!isCloudProvider(properties)) { throw new CommandLineExitException(format("Cannot execute '%s' in local or static setup", action)); } }
static File getProfileFile(String directory) { File zshrcFile = new File(directory, ".zshrc"); if (zshrcFile.isFile()) { return zshrcFile; } File bashrcFile = new File(directory, ".bashrc"); if (bashrcFile.isFile()) { return bashrcFile; } File profileFile = new File(directory, ".profile"); if (profileFile.isFile()) { return profileFile; } throw new CommandLineExitException("Could not find one of .zshrc, .bashrc or .profile files" + " under directory '" + directory + "`" + " Installation not supported on this system!"); }
static HistogramLogReader createHistogramLogReader(File latencyFile, String testName) { try { return new HistogramLogReader(latencyFile); } catch (IOException e) { throw new CommandLineExitException("Could not initialize HistogramLogReader for test " + testName, e); } }
private File getTestSuiteFile() { File testSuiteFile; List testsuiteFiles = options.nonOptionArguments(); if (testsuiteFiles.size() > 1) { throw new CommandLineExitException(format("Too many TestSuite files specified: %s", testsuiteFiles)); } else if (testsuiteFiles.size() == 1) { testSuiteFile = new File((String) testsuiteFiles.get(0)); } else { return null; } LOGGER.info("Loading TestSuite file: " + testSuiteFile.getAbsolutePath()); if (!testSuiteFile.exists()) { throw new CommandLineExitException(format("TestSuite file '%s' not found", testSuiteFile)); } return testSuiteFile; }
@SuppressFBWarnings("DM_DEFAULT_ENCODING") private static Properties loadProperties(File file) { FileReader reader = null; try { reader = new FileReader(file); Properties properties = new Properties(); properties.load(reader); return properties; } catch (IOException e) { throw new CommandLineExitException(format("Failed to load TestSuite property file [%s]", file.getAbsolutePath()), e); } finally { closeQuietly(reader); } }
private void validateResponse(SimulatorOperation operation, Response response) { for (Map.Entry<SimulatorAddress, Response.Part> entry : response.getParts()) { ResponseType responseType = entry.getValue().getType(); if (responseType != ResponseType.SUCCESS && responseType != ResponseType.UNBLOCKED_BY_FAILURE) { SimulatorAddress source = entry.getKey(); throw new CommandLineExitException(format("Could not execute %s on %s (%s)", operation, source, responseType)); } } }
@Override protected SimulatorOperation newOperation() { List<String> nonOptionArguments = options.valuesOf(argumentSpec); if (nonOptionArguments.size() != 1) { throw new CommandLineExitException("Too many arguments"); } String versionSpec = nonOptionArguments.get(0); LOGGER.info("Installing [" + versionSpec + "]"); return new RcInstallOperation(versionSpec); } }
private String loadPropertyFromFile(String property) { String path = get(property); File file = newFile(path); if (!file.exists()) { throw new CommandLineExitException(format("File %s for property %s not found", file.getAbsolutePath(), property)); } if (LOGGER.isDebugEnabled()) { LOGGER.debug(format("Loading property value for %s from file: %s", property, file.getAbsolutePath())); } return fileAsText(file).trim(); }