public static RuntimeException rethrow(Throwable throwable) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } else { throw new CommandLineExitException(throwable); } }
public static RuntimeException rethrow(Throwable throwable) { if (throwable instanceof RuntimeException) { throw (RuntimeException) throwable; } else { throw new CommandLineExitException(throwable); } }
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)); } }
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(); }
private CoordinatorRemoteCli(String[] args) { SimulatorProperties simulatorProperties = new SimulatorProperties(); File file = new File(FileUtils.getUserDir(), "simulator.properties"); if (file.exists()) { simulatorProperties.init(file); } this.args = args; this.coordinatorPort = simulatorProperties.getCoordinatorPort(); if (coordinatorPort == 0) { throw new CommandLineExitException("Coordinator port is disabled!"); } }
public static ComponentRegistry loadComponentRegister(File agentsFile, boolean sizeCheck) { ensureExistingFile(agentsFile); ComponentRegistry componentRegistry = AgentsFile.load(agentsFile); if (sizeCheck && componentRegistry.agentCount() == 0) { throw new CommandLineExitException("Agents file " + agentsFile + " is empty."); } return componentRegistry; }
private DeploymentPlan newDeploymentPlan() { WorkerType workerType = new WorkerType(options.valueOf(clientTypeSpec)); if (workerType.isMember()) { throw new CommandLineExitException("client workerType can't be [member]"); } int members = options.valueOf(membersSpec); int clients = options.valueOf(clientsSpec); if (clients < 0) { throw new CommandLineExitException("--client must be a equal or larger than 0"); } return createDeploymentPlan(componentRegistry, workerParametersMap, workerType, members, clients); }
static void printHelpAndExit(OptionParser parser, OutputStream sink) { try { parser.formatHelpWith(new BuiltinHelpFormatter(HELP_WIDTH, HELP_INDENTATION)); parser.printHelpOn(sink); } catch (Exception e) { throw new CommandLineExitException("Could not print command line help", e); } exit(0); } }
@SuppressWarnings("PMD.PreserveStackTrace") public static OptionSet initOptionsWithHelp(OptionParser parser, String[] args) { try { OptionSpec helpSpec = parser.accepts("help", "Shows the help.").forHelp(); OptionSet options = parser.parse(args); if (options.has(helpSpec)) { printHelpAndExit(parser, System.out); } return options; } catch (OptionException e) { throw new CommandLineExitException(e.getMessage() + ". Use --help to get overview of the help options."); } }
void sshConnectionCheck(SimulatorProperties simulatorProperties, Bash bash) { if (isLocal(simulatorProperties)) { throw new CommandLineExitException("SSH is not supported for local setups."); } ComponentRegistry componentRegistry = loadComponentRegister(agentFile, true); String userName = simulatorProperties.getUser(); for (AgentData agentData : componentRegistry.getAgents()) { String publicAddress = agentData.getPublicAddress(); echo("Connecting to %s@%s...", userName, publicAddress); bash.ssh(publicAddress, "echo ok 2>&1"); } echo("Connected successfully to all remote machines!"); }