use of joptsimple.OptionParser in project jgnash by ccavanaugh.
the class Main method buildParser.
private static OptionParser buildParser() {
final OptionParser parser = new OptionParser() {
{
acceptsAll(asList(HELP_OPTION_SHORT, HELP_OPTION_LONG), "This help").forHelp();
acceptsAll(asList(UNINSTALL_OPTION_SHORT, UNINSTALL_OPTION_LONG), "Remove registry settings");
acceptsAll(asList(VERBOSE_OPTION_SHORT, VERBOSE_OPTION_LONG), "Enable verbose application messages");
acceptsAll(asList(FILE_OPTION_SHORT, FILE_OPTION_LONG), "File to load at start").withRequiredArg().ofType(File.class);
accepts(PASSWORD_OPTION, "Password for a local File, server or client").withRequiredArg();
acceptsAll(asList(PORTABLE_OPTION_SHORT, PORTABLE_OPTION_LONG), "Enable portable preferences");
accepts(PORTABLE_FILE_OPTION, "Enable portable preferences and specify the file").withRequiredArg().ofType(File.class);
accepts(PORT_OPTION, "Network port server is running on (default: " + JpaNetworkServer.DEFAULT_PORT + ")").withRequiredArg().ofType(Integer.class);
accepts(HOST_OPTION, "Server host name or address").requiredIf(PORT_OPTION).withRequiredArg();
accepts(SERVER_OPTION, "Runs as a server using the specified file").withRequiredArg().ofType(File.class);
accepts(XRENDER_OPTION, "Enable the XRender-based Java 2D rendering pipeline");
accepts(OPEN_GL_OPTION, "Enable OpenGL acceleration");
accepts(HANG_DETECT_OPTION, "Enable hang detection on the EDT");
accepts(SHUTDOWN_OPTION, "Issues a shutdown request to a server");
accepts(EDT_OPTION, "Check for EDT violations");
accepts(ENCRYPT_OPTION, "Enable encryption for network communication");
}
};
parser.allowsUnrecognizedOptions();
return parser;
}
use of joptsimple.OptionParser in project jgnash by ccavanaugh.
the class Main method init.
private void init(final String[] args) {
configureLogging();
final OptionParser parser = buildParser();
try {
final OptionSet options = parser.parse(args);
/* handle a file name passed in as an argument without use of the -file argument
assumed behavior for windows users */
if (!options.nonOptionArguments().isEmpty()) {
// Check for no-option version of a file load
for (final Object object : options.nonOptionArguments()) {
if (object instanceof String) {
if (Files.exists(Paths.get((String) object))) {
file = new File((String) object);
break;
} else {
System.err.println(object + " was not a valid file");
}
}
}
}
if (options.has(EDT_OPTION)) {
enableEDT = true;
}
if (options.has(VERBOSE_OPTION_SHORT)) {
verbose = true;
}
if (options.has(HANG_DETECT_OPTION)) {
hangDetect = true;
}
if (options.has(PORT_OPTION)) {
port = (Integer) options.valueOf(PORT_OPTION);
}
if (options.has(PASSWORD_OPTION)) {
password = ((String) options.valueOf(PASSWORD_OPTION)).toCharArray();
}
if (options.has(HOST_OPTION)) {
hostName = (String) options.valueOf(HOST_OPTION);
}
if (options.has(FILE_OPTION_SHORT) && file == null) {
file = (File) options.valueOf(FILE_OPTION_SHORT);
if (!file.exists()) {
file = null;
}
}
if (options.has(SERVER_OPTION)) {
final File file = (File) options.valueOf(SERVER_OPTION);
if (file.exists()) {
serverFile = file;
}
}
// Check to see if portable preferences are being used
if (options.has(PORTABLE_FILE_OPTION)) {
final File file = (File) options.valueOf(PORTABLE_FILE_OPTION);
if (file.exists()) {
portableFile = file;
}
} else if (options.has(PORTABLE_OPTION_SHORT)) {
// simple use of portable preferences
portable = true;
}
/* If a shutdown request is found, it trumps any other commandline options */
if (options.has(SHUTDOWN_OPTION)) {
if (hostName == null) {
hostName = EngineFactory.LOCALHOST;
}
MessageBus.getInstance().shutDownRemoteServer(hostName, port + 1, password);
} else if (options.has(UNINSTALL_OPTION_SHORT)) {
/* Dump the registry settings if requested */
PortablePreferences.deleteUserPreferences();
} else if (serverFile != null) {
try {
if (!FileUtils.isFileLocked(serverFile.getAbsolutePath())) {
JpaNetworkServer networkServer = new JpaNetworkServer();
networkServer.startServer(serverFile.getAbsolutePath(), port, password);
} else {
System.err.println(ResourceUtils.getString("Message.FileIsLocked"));
}
} catch (FileNotFoundException e) {
logSevere(Main.class, e);
System.err.println("File " + serverFile.getAbsolutePath() + " was not found");
} catch (Exception e) {
logSevere(Main.class, e);
}
} else {
// start the UI
if (portable || portableFile != null) {
// must hook in the preferences implementation first
// for best operation
PortablePreferences.initPortablePreferences(portableFile.getAbsolutePath());
}
enableAntialiasing();
if (options.has(OPEN_GL_OPTION)) {
System.setProperty("sun.java2d.opengl", "True");
}
if (options.has(XRENDER_OPTION)) {
System.setProperty("sun.java2d.xrender", "True");
}
if (OS.isSystemOSX()) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
}
setupNetworking();
if (hostName != null) {
new UIApplication(hostName, port, password);
} else if (file != null && file.exists()) {
new UIApplication(file.toPath(), password);
} else {
new UIApplication(null, null);
}
}
} catch (final Exception e) {
try {
parser.printHelpOn(System.err);
} catch (final IOException ioe) {
logSevere(Main.class, ioe);
}
}
}
use of joptsimple.OptionParser in project jgnash by ccavanaugh.
the class jGnashFx method buildParser.
private static OptionParser buildParser() {
final OptionParser parser = new OptionParser() {
{
acceptsAll(asList(HELP_OPTION_SHORT, HELP_OPTION_LONG), "This help").forHelp();
acceptsAll(asList(UNINSTALL_OPTION_SHORT, UNINSTALL_OPTION_LONG), "Remove registry settings");
acceptsAll(asList(VERBOSE_OPTION_SHORT, VERBOSE_OPTION_LONG), "Enable verbose application messages");
acceptsAll(asList(FILE_OPTION_SHORT, FILE_OPTION_LONG), "File to load at start").withRequiredArg().ofType(File.class);
accepts(PASSWORD_OPTION, "Password for a local File, server or client").withRequiredArg();
acceptsAll(asList(PORTABLE_OPTION_SHORT, PORTABLE_OPTION_LONG), "Enable portable preferences");
accepts(PORTABLE_FILE_OPTION, "Enable portable preferences and specify the file").withRequiredArg().ofType(File.class);
accepts(PORT_OPTION, "Network port server is running on (default: " + JpaNetworkServer.DEFAULT_PORT + ")").withRequiredArg().ofType(Integer.class);
accepts(HOST_OPTION, "Server host name or address").requiredIf(PORT_OPTION).withRequiredArg();
accepts(SERVER_OPTION, "Runs as a server using the specified file").withRequiredArg().ofType(File.class);
}
};
parser.allowsUnrecognizedOptions();
return parser;
}
use of joptsimple.OptionParser in project elasticsearch by elastic.
the class TruncateTranslogIT method testCorruptTranslogTruncation.
public void testCorruptTranslogTruncation() throws Exception {
internalCluster().startNodes(1, Settings.EMPTY);
assertAcked(prepareCreate("test").setSettings(Settings.builder().put("index.number_of_shards", 1).put("index.number_of_replicas", 0).put("index.refresh_interval", "-1").put(MockEngineSupport.DISABLE_FLUSH_ON_CLOSE.getKey(), // never flush - always recover from translog
true)));
ensureYellow();
// Index some documents
int numDocs = scaledRandomIntBetween(100, 1000);
IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
for (int i = 0; i < builders.length; i++) {
builders[i] = client().prepareIndex("test", "type").setSource("foo", "bar");
}
disableTranslogFlush("test");
indexRandom(false, false, false, Arrays.asList(builders));
Set<Path> translogDirs = getTranslogDirs("test");
TruncateTranslogCommand ttc = new TruncateTranslogCommand();
MockTerminal t = new MockTerminal();
OptionParser parser = ttc.getParser();
for (Path translogDir : translogDirs) {
OptionSet options = parser.parse("-d", translogDir.toAbsolutePath().toString(), "-b");
// Try running it before the shard is closed, it should flip out because it can't acquire the lock
try {
logger.info("--> running truncate while index is open on [{}]", translogDir.toAbsolutePath());
ttc.execute(t, options, null);
fail("expected the truncate command to fail not being able to acquire the lock");
} catch (Exception e) {
assertThat(e.getMessage(), containsString("Failed to lock shard's directory"));
}
}
// Corrupt the translog file(s)
logger.info("--> corrupting translog");
corruptRandomTranslogFiles("test");
// Restart the single node
logger.info("--> restarting node");
internalCluster().fullRestart();
client().admin().cluster().prepareHealth().setWaitForYellowStatus().setTimeout(new TimeValue(1000, TimeUnit.MILLISECONDS)).setWaitForEvents(Priority.LANGUID).get();
try {
client().prepareSearch("test").setQuery(matchAllQuery()).get();
fail("all shards should be failed due to a corrupted translog");
} catch (SearchPhaseExecutionException e) {
// Good, all shards should be failed because there is only a
// single shard and its translog is corrupt
}
// Close the index so we can actually truncate the translog
logger.info("--> closing 'test' index");
client().admin().indices().prepareClose("test").get();
for (Path translogDir : translogDirs) {
final Path idxLocation = translogDir.getParent().resolve("index");
assertBusy(() -> {
logger.info("--> checking that lock has been released for {}", idxLocation);
try (Directory dir = FSDirectory.open(idxLocation, NativeFSLockFactory.INSTANCE);
Lock writeLock = dir.obtainLock(IndexWriter.WRITE_LOCK_NAME)) {
// Great, do nothing, we just wanted to obtain the lock
} catch (LockObtainFailedException lofe) {
logger.info("--> failed acquiring lock for {}", idxLocation);
fail("still waiting for lock release at [" + idxLocation + "]");
} catch (IOException ioe) {
fail("Got an IOException: " + ioe);
}
});
OptionSet options = parser.parse("-d", translogDir.toAbsolutePath().toString(), "-b");
logger.info("--> running truncate translog command for [{}]", translogDir.toAbsolutePath());
ttc.execute(t, options, null);
logger.info("--> output:\n{}", t.getOutput());
}
// Re-open index
logger.info("--> opening 'test' index");
client().admin().indices().prepareOpen("test").get();
ensureYellow("test");
// Run a search and make sure it succeeds
SearchResponse resp = client().prepareSearch("test").setQuery(matchAllQuery()).get();
ElasticsearchAssertions.assertNoFailures(resp);
}
use of joptsimple.OptionParser in project voldemort by voldemort.
the class JsonStoreBuilder method main.
/**
* Main method to run on a input text file
*
* @param args see USAGE for details
* @throws IOException
*/
public static void main(String[] args) throws IOException {
OptionParser parser = new OptionParser();
parser.accepts("help", "print usage information");
parser.accepts("cluster", "[REQUIRED] path to cluster xml config file").withRequiredArg().describedAs("cluster.xml");
parser.accepts("stores", "[REQUIRED] path to stores xml config file").withRequiredArg().describedAs("stores.xml");
parser.accepts("name", "[REQUIRED] store name").withRequiredArg().describedAs("store name");
parser.accepts("buffer", "[REQUIRED] number of key/value pairs to buffer in memory").withRequiredArg().ofType(Integer.class);
parser.accepts("input", "[REQUIRED] input file to read from").withRequiredArg().describedAs("input-file");
parser.accepts("output", "[REQUIRED] directory to output stores to").withRequiredArg().describedAs("output directory");
parser.accepts("threads", "number of threads").withRequiredArg().ofType(Integer.class);
parser.accepts("chunks", "number of chunks [per node, per partition, per partition + replica]").withRequiredArg().ofType(Integer.class);
parser.accepts("io-buffer-size", "size of i/o buffers in bytes").withRequiredArg().ofType(Integer.class);
parser.accepts("temp-dir", "temporary directory for sorted file pieces").withRequiredArg().describedAs("temp dir");
parser.accepts("gzip", "compress intermediate chunk files");
parser.accepts("format", "read-only store format [" + ReadOnlyStorageFormat.READONLY_V0.getCode() + "," + ReadOnlyStorageFormat.READONLY_V1.getCode() + "," + ReadOnlyStorageFormat.READONLY_V2.getCode() + "]").withRequiredArg().ofType(String.class);
OptionSet options = parser.parse(args);
if (options.has("help")) {
parser.printHelpOn(System.out);
System.exit(0);
}
Set<String> missing = CmdUtils.missing(options, "cluster", "stores", "name", "buffer", "input", "output");
if (missing.size() > 0) {
System.err.println("Missing required arguments: " + Joiner.on(", ").join(missing));
parser.printHelpOn(System.err);
System.exit(1);
}
String clusterFile = (String) options.valueOf("cluster");
String storeDefFile = (String) options.valueOf("stores");
String storeName = (String) options.valueOf("name");
int sortBufferSize = (Integer) options.valueOf("buffer");
String inputFile = (String) options.valueOf("input");
File outputDir = new File((String) options.valueOf("output"));
int numThreads = CmdUtils.valueOf(options, "threads", 2);
int chunks = CmdUtils.valueOf(options, "chunks", 2);
int ioBufferSize = CmdUtils.valueOf(options, "io-buffer-size", 1000000);
ReadOnlyStorageFormat storageFormat = ReadOnlyStorageFormat.fromCode(CmdUtils.valueOf(options, "format", ReadOnlyStorageFormat.READONLY_V2.getCode()));
boolean gzipIntermediate = options.has("gzip");
File tempDir = new File(CmdUtils.valueOf(options, "temp-dir", System.getProperty("java.io.tmpdir")));
try {
JsonReader reader = new JsonReader(new BufferedReader(new FileReader(inputFile), ioBufferSize));
Cluster cluster = new ClusterMapper().readCluster(new BufferedReader(new FileReader(clusterFile)));
StoreDefinition storeDef = null;
List<StoreDefinition> stores = new StoreDefinitionsMapper().readStoreList(new BufferedReader(new FileReader(storeDefFile)));
for (StoreDefinition def : stores) {
if (def.getName().equals(storeName))
storeDef = def;
}
if (storeDef == null)
Utils.croak("No store found with name \"" + storeName + "\"");
if (!outputDir.exists())
Utils.croak("Directory \"" + outputDir.getAbsolutePath() + "\" does not exist.");
RoutingStrategy routingStrategy = new RoutingStrategyFactory().updateRoutingStrategy(storeDef, cluster);
new JsonStoreBuilder(reader, cluster, storeDef, routingStrategy, outputDir, tempDir, sortBufferSize, numThreads, chunks, ioBufferSize, gzipIntermediate).build(storageFormat);
} catch (FileNotFoundException e) {
Utils.croak(e.getMessage());
}
}
Aggregations