use of joptsimple.OptionSet in project voldemort by voldemort.
the class ConsistencyCheck method main.
@SuppressWarnings("unchecked")
public static void main(String[] args) throws Exception {
OptionSet options = getParser().parse(args);
/* validate options */
if (options.hasArgument("help")) {
printUsage();
return;
}
if (!options.hasArgument("urls") || !options.hasArgument("partitions") || !options.hasArgument("store") || !options.hasArgument("bad-key-file")) {
printUsage();
return;
}
List<String> urls = (List<String>) options.valuesOf("urls");
String storeName = (String) options.valueOf("store");
List<Integer> partitionIds = (List<Integer>) options.valuesOf("partitions");
String badKeyFile = (String) options.valueOf("bad-key-file");
ComparisonType comparisonType = ComparisonType.VERSION;
if (options.hasArgument(ComparisonTypeArgument)) {
String comparisonArgument = (String) options.valueOf(ComparisonTypeArgument);
comparisonArgument = comparisonArgument.toUpperCase();
comparisonType = ComparisonType.valueOf(comparisonArgument);
}
BufferedWriter badKeyWriter = null;
try {
badKeyWriter = new BufferedWriter(new FileWriter(badKeyFile));
} catch (IOException e) {
Utils.croak("Failure to open output file : " + e.getMessage());
}
Map<Integer, Reporter> partitionStatsMap = new HashMap<Integer, Reporter>();
/* scan each partitions */
try {
for (Integer partitionId : partitionIds) {
ConsistencyCheck checker = new ConsistencyCheck(urls, storeName, partitionId, badKeyWriter, comparisonType);
checker.connect();
Reporter reporter = checker.execute();
partitionStatsMap.put(partitionId, reporter);
}
} catch (Exception e) {
Utils.croak("Exception during consistency checking : " + e.getMessage());
} finally {
badKeyWriter.close();
}
/* print stats */
StringBuilder statsString = new StringBuilder();
long totalGoodKeys = 0;
long totalTotalKeys = 0;
// each partition
statsString.append("TYPE,Store,PartitionId,KeysConsistent,KeysTotal,Consistency\n");
for (Map.Entry<Integer, Reporter> entry : partitionStatsMap.entrySet()) {
Integer partitionId = entry.getKey();
Reporter reporter = entry.getValue();
totalGoodKeys += reporter.numGoodKeys;
totalTotalKeys += reporter.numTotalKeys;
statsString.append("STATS,");
statsString.append(storeName + ",");
statsString.append(partitionId + ",");
statsString.append(reporter.numGoodKeys + ",");
statsString.append(reporter.numTotalKeys + ",");
statsString.append((double) (reporter.numGoodKeys) / (double) reporter.numTotalKeys);
statsString.append("\n");
}
// all partitions
statsString.append("STATS,");
statsString.append(storeName + ",");
statsString.append("aggregate,");
statsString.append(totalGoodKeys + ",");
statsString.append(totalTotalKeys + ",");
statsString.append((double) (totalGoodKeys) / (double) totalTotalKeys);
statsString.append("\n");
for (String line : statsString.toString().split("\n")) {
logger.info(line);
}
}
use of joptsimple.OptionSet in project voldemort by voldemort.
the class ConsistencyFixCLI method parseArgs.
/**
* All the logic for parsing and validating options.
*
* @param args
* @return A struct containing validated options.
* @throws IOException
*/
private static ConsistencyFixCLI.Options parseArgs(String[] args) {
OptionParser parser = new OptionParser();
parser.accepts("help", "print help information");
parser.accepts("url", "The bootstrap url.").withRequiredArg().describedAs("bootstrapUrl").ofType(String.class);
parser.accepts("store", "The store name.").withRequiredArg().describedAs("storeName").ofType(String.class);
parser.accepts("bad-key-file-in", "Name of bad-key-file-in. " + "Each key must be in hexadecimal format. " + "Each key must be on a separate line in the file. ").withRequiredArg().describedAs("badKeyFileIn").ofType(String.class);
parser.accepts("orphan-format", "Indicates format of bad-key-file-in is of 'orphan' key-values.");
parser.accepts("dry-run", "Indicates to go through all of the read actions until the point of issuing repair puts. Then, do a 'no-op'.");
parser.accepts("parse-only", "Indicates to only parse the input file. Does not perform any key queries or repair puts. " + "Does bootstrap though so bootstrapUrl and storeName must be specified.");
parser.accepts("bad-key-file-out", "Name of bad-key-file-out. " + "Keys that are not mae consistent are output to this file.").withRequiredArg().describedAs("badKeyFileOut").ofType(String.class);
parser.accepts("parallelism", "Number of consistency fix messages outstanding in parallel. ").withRequiredArg().describedAs("parallelism [Default value: " + Options.defaultParallelism + "]").ofType(Integer.class);
parser.accepts("progress-period-ops", "Number of operations between 'info' progress messages. ").withRequiredArg().describedAs("period (in operations) between outputting progress [Default value: " + Options.defaultProgressPeriodOps + "]").ofType(Long.class);
parser.accepts("per-server-qps-limit", "Number of operations that the consistency fixer will issue to any individual server in one second. ").withRequiredArg().describedAs("perServerQPSLimit [Default value: " + Options.defaultPerServerQPSLimit + "]").ofType(Long.class);
OptionSet optionSet = parser.parse(args);
if (optionSet.hasArgument("help")) {
try {
parser.printHelpOn(System.out);
} catch (IOException e) {
e.printStackTrace();
}
printUsage();
System.exit(0);
}
if (!optionSet.hasArgument("url")) {
printUsage("Missing required 'url' argument.", parser);
}
if (!optionSet.hasArgument("store")) {
printUsage("Missing required 'store' argument.", parser);
}
if (!optionSet.has("bad-key-file-in")) {
printUsage("Missing required 'bad-key-file-in' argument.", parser);
}
if (!optionSet.has("bad-key-file-out")) {
printUsage("Missing required 'bad-key-file-out' argument.", parser);
}
Options options = new Options();
options.url = (String) optionSet.valueOf("url");
options.storeName = (String) optionSet.valueOf("store");
options.badKeyFileIn = (String) optionSet.valueOf("bad-key-file-in");
options.badKeyFileOut = (String) optionSet.valueOf("bad-key-file-out");
if (optionSet.has("orphan-format")) {
options.badKeyFileInOrphanFormat = true;
}
if (optionSet.has("parallelism")) {
options.parallelism = (Integer) optionSet.valueOf("parallelism");
}
if (optionSet.has("progress-period-ops")) {
options.progressPeriodOps = (Long) optionSet.valueOf("progress-period-ops");
}
if (optionSet.has("per-server-qps-limit")) {
options.perServerQPSLimit = (Long) optionSet.valueOf("per-server-qps-limit");
}
if (optionSet.has("dry-run")) {
options.dryRun = true;
}
if (optionSet.has("parse-only")) {
options.parseOnly = true;
}
return options;
}
use of joptsimple.OptionSet in project voldemort by voldemort.
the class ReplaceNodeCLI method main.
public static void main(String[] args) throws Exception {
OptionParser parser = null;
OptionSet options = null;
try {
parser = getParser();
options = parser.parse(args);
} catch (OptionException oe) {
parser.printHelpOn(System.out);
printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
return;
}
/* validate options */
if (options.hasArgument("help")) {
parser.printHelpOn(System.out);
printUsage();
return;
}
if (!options.hasArgument("url") || !options.hasArgument("node") || !options.hasArgument("newurl")) {
parser.printHelpOn(System.out);
printUsageAndDie("Missing a required argument.");
return;
}
String url = (String) options.valueOf("url");
String newUrl = (String) options.valueOf("newurl");
int nodeId = ((Integer) options.valueOf("node")).intValue();
boolean skipRestore = options.has("skip-restore");
int parallelism = ((Integer) options.valueOf("parallelism")).intValue();
if (parallelism <= 0) {
Utils.croak(" parallelism " + parallelism + " should be a positive integer ");
}
ReplaceNodeCLI nodeReplacer = new ReplaceNodeCLI(url, nodeId, newUrl, skipRestore, parallelism);
try {
nodeReplacer.execute();
} catch (VoldemortApplicationException e) {
logger.error("Error during node replace", e);
Utils.croak(e.getMessage());
}
}
use of joptsimple.OptionSet in project voldemort by voldemort.
the class PartitionAnalysisCLI method getValidOptions.
private static OptionSet getValidOptions(String[] args) {
OptionSet options = null;
try {
options = parser.parse(args);
} catch (OptionException oe) {
printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
}
if (options.has("help")) {
printUsage();
System.exit(0);
}
Set<String> missing = CmdUtils.missing(options, "cluster", "stores");
if (missing.size() > 0) {
printUsageAndDie("Missing required arguments: " + Joiner.on(", ").join(missing));
}
return options;
}
use of joptsimple.OptionSet in project voldemort by voldemort.
the class ReadOnlyReplicationHelperCLI method getValidOptions.
private static OptionSet getValidOptions(String[] args) {
OptionSet options = null;
try {
options = parser.parse(args);
} catch (OptionException oe) {
printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
}
if (options.has(OPT_HELP)) {
printUsage();
System.exit(0);
}
Set<String> missing = CmdUtils.missing(options, OPT_URL, OPT_NODE);
if (missing.size() > 0) {
printUsageAndDie("Missing required arguments: " + Joiner.on(", ").join(missing));
}
return options;
}
Aggregations