public static String getFilePath(OptionSet options, String name) { String path = (String) options.valueOf(name); return path.replace("~", System.getProperty("user.home")); }
public static String getFilePath(OptionSet options, String name) { String path = (String) options.valueOf(name); return path.replace("~", System.getProperty("user.home")); }
public static Integer parseInterval(OptionSet optionSet) { Integer interval = OptionAdvanceParser.DEFAULT_INTERVAL; if (optionSet.hasArgument("interval")) { interval = (Integer) (optionSet.valueOf("interval")); if (interval < 1) { throw new IllegalArgumentException("Interval cannot be set below 1.0"); } } return interval; } }
public static OutputFormat parseOutputFormat(OptionSet optionSet) { OutputFormat outputFormat = OutputFormat.console; if (optionSet.hasArgument("output")) { String format = (String) optionSet.valueOf("output"); if (format.equals("clean")) { outputFormat = OutputFormat.cleanConsole; } else if (format.equals("text")) { outputFormat = OutputFormat.text; } } return outputFormat; }
public static ContentMode parseContentMode(OptionSet optionSet) { ContentMode contentMode = ContentMode.all; if (optionSet.hasArgument("content")) { String format = (String) optionSet.valueOf("content"); if (format.equals("jvm")) { contentMode = ContentMode.jvm; } else if (format.equals("thread")) { contentMode = ContentMode.thread; } } return contentMode; }
protected String fetchOption(String name, OptionSet options, Properties properties, String defaultVal) { if ( options != null && options.has(name) ) return (String) options.valueOf(name); else if ( (properties != null) && properties.containsKey(name) ) return properties.getProperty(name); else return defaultVal; }
private String validateAndGetPassword(OptionSet options, OptionSpec<String> optionPassword) { if (!isInteractive) { if (options.has(optionPassword)) { return options.valueOf(optionPassword); } else { return null; // No encryption, no password. } } else { return null; // Will be set in callback! } }
protected boolean fetchBooleanOption(String name, OptionSet options, Properties properties, boolean defaultVal) { if ( options != null && options.has(name) ) { if ( !options.hasArgument(name) ) return true; else return Boolean.valueOf((String) options.valueOf(name)); } else if ( (properties != null) && properties.containsKey(name) ) return Boolean.valueOf(properties.getProperty(name)); else return defaultVal; }
public static ThreadInfoMode parseThreadInfoMode(OptionSet optionSet) { ThreadInfoMode threadInfoMode = ThreadInfoMode.cpu; if (optionSet.hasArgument("mode")) { String mode = (String) optionSet.valueOf("mode"); threadInfoMode = ThreadInfoMode.parse(mode); } return threadInfoMode; }
private void initLocalDir(OptionSet options, OptionSpec<File> optionLocalDir) throws ConfigException, Exception { // Find config or use --localdir option if (options.has(optionLocalDir)) { localDir = options.valueOf(optionLocalDir); } else { File currentDir = new File(".").getAbsoluteFile(); localDir = ConfigHelper.findLocalDirInPath(currentDir); // If no local directory was found, choose current directory if (localDir == null) { localDir = currentDir; } } }
private static boolean extractBoolOption(OptionSet options, String optionName) { boolean optionValue = false; if(options.has(optionName)) { if(options.hasArgument(optionName)) { optionValue = (Boolean) options.valueOf(optionName); } else { optionValue = true; } } return optionValue; }
public static void main(String[] args) throws Exception { setupParser(); OptionSet options = getValidOptions(args); String clusterXML = (String) options.valueOf("cluster"); String storesXML = (String) options.valueOf("stores"); Cluster currentCluster = new ClusterMapper().readCluster(new File(clusterXML)); List<StoreDefinition> storeDefs = new StoreDefinitionsMapper().readStoreList(new File(storesXML)); PartitionBalance partitionBalance = new PartitionBalance(currentCluster, storeDefs); System.out.println(partitionBalance); }
public static void main(String[] args) throws Exception { setupParser(); OptionSet options = getValidOptions(args); // Required args String url = (String) options.valueOf(OPT_URL); Integer nodeId = (Integer) options.valueOf(OPT_NODE); PrintStream outputStream; if(options.has(OPT_OUTPUT)) { String output = (String) options.valueOf(OPT_OUTPUT); outputStream = new PrintStream(output); } else { outputStream = System.out; } Boolean local = options.has(OPT_LOCAL); AdminClient adminClient = new AdminClient(url); outputStream.println("src_host_name,src_node_id,src_rel_path,dest_rel_path"); List<String> infoList = getReadOnlyReplicationInfo(adminClient, nodeId, local); for(String info: infoList) { outputStream.println(info); } if(outputStream != System.out) { outputStream.close(); } } }
public static void main(String[] argv) throws Exception { OptionParser parser = getParser(); OptionSet options = parser.parse(argv); validateOptions(options); ZoneShrinkageCLI cli = new ZoneShrinkageCLI((String) options.valueOf("url"), (Integer) options.valueOf("drop-zoneid")); try { cli.executeShrink(options.has("real-run")); } catch(Exception e) { e.printStackTrace(); logAbort(); } }
protected TransferSettings createTransferSettingsFromOptions(OptionSet options, OptionSpec<String> optionPlugin, OptionSpec<String> optionPluginOpts) throws Exception { TransferPlugin plugin; TransferSettings transferSettings; // Parse --plugin and --plugin-option values List<String> pluginOptionStrings = options.valuesOf(optionPluginOpts); Map<String, String> knownPluginSettings = parsePluginSettingsFromOptions(pluginOptionStrings); // Validation of some constraints if (!options.has(optionPlugin) && knownPluginSettings.size() > 0) { throw new IllegalArgumentException("Provided plugin settings without a plugin name."); } plugin = options.has(optionPlugin) ? initPlugin(options.valueOf(optionPlugin)) : askPlugin(); transferSettings = askPluginSettings(plugin.createEmptySettings(), knownPluginSettings); return transferSettings; }
private Configure analyzeConfigure(String[] args) { final OptionParser parser = new OptionParser(); parser.accepts("pid").withRequiredArg().ofType(int.class).required(); parser.accepts("target").withOptionalArg().ofType(String.class); parser.accepts("multi").withOptionalArg().ofType(int.class); parser.accepts("core").withOptionalArg().ofType(String.class); parser.accepts("agent").withOptionalArg().ofType(String.class); final OptionSet os = parser.parse(args); final Configure configure = new Configure(); if (os.has("target")) { final String[] strSplit = ((String) os.valueOf("target")).split(":"); configure.setTargetIp(strSplit[0]); configure.setTargetPort(Integer.valueOf(strSplit[1])); } configure.setJavaPid((Integer) os.valueOf("pid")); configure.setGreysAgent((String) os.valueOf("agent")); configure.setGreysCore((String) os.valueOf("core")); return configure; }
public DownOperationOptions parseOptions(String[] operationArguments) { DownOperationOptions operationOptions = new DownOperationOptions(); OptionParser parser = new OptionParser(); parser.allowsUnrecognizedOptions(); OptionSpec<String> optionConflictStrategy = parser.acceptsAll(asList("C", "conflict-strategy")).withRequiredArg(); OptionSpec<Void> optionNoApply = parser.acceptsAll(asList("A", "no-apply")); OptionSet options = parser.parse(operationArguments); // --conflict-strategy=<strategy> if (options.has(optionConflictStrategy)) { String conflictStrategyStr = options.valueOf(optionConflictStrategy).toUpperCase(); operationOptions.setConflictStrategy(DownConflictStrategy.valueOf(conflictStrategyStr)); } // --no-apply if (options.has(optionNoApply)) { operationOptions.setApplyChanges(false); } return operationOptions; }
@SuppressWarnings("unchecked") public static void main(String[] args) throws IOException { OptionParser parser = new OptionParser(); parser.accepts("k", "key size").withRequiredArg().ofType(Integer.class); parser.accepts("v", "value size").withRequiredArg().ofType(Integer.class); parser.accepts("p", "prefix").withRequiredArg(); OptionSet options = parser.parse(args); List<String> nonOptions = (List<String>) options.nonOptionArguments(); if(nonOptions.size() != 3) { printUsage(System.err, parser); } String url = nonOptions.get(0); String storeName = nonOptions.get(1); int requests = Integer.parseInt(nonOptions.get(2)); int keySize = CmdUtils.valueOf(options, "k", 128); int valueSize = CmdUtils.valueOf(options, "v", 256); int workers = CmdUtils.valueOf(options, "threads", MAX_WORKERS); String postfix = (String) (options.has("p") ? options.valueOf("p") : null); RemoteDataGenerator rdg = new RemoteDataGenerator(url, storeName, workers); rdg.generateData(requests, keySize, valueSize, postfix); } }