use of java.io.Console in project orientdb by orientechnologies.
the class OStressTesterCommandLineParser method getStressTester.
/**
* builds a StressTester object using the command line arguments
*
* @param args
*
* @return
*
* @throws Exception
*/
public static OStressTester getStressTester(String[] args) throws Exception {
final Map<String, String> options = checkOptions(readOptions(args));
final OStressTesterSettings settings = new OStressTesterSettings();
settings.dbName = TEMP_DATABASE_NAME + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
if (options.get(OPTION_DBNAME) != null)
settings.dbName = options.get(OPTION_DBNAME);
settings.mode = OStressTester.OMode.valueOf(options.get(OPTION_MODE).toUpperCase());
settings.rootPassword = options.get(OPTION_ROOT_PASSWORD);
settings.resultOutputFile = options.get(OPTION_OUTPUT_FILE);
settings.plocalPath = options.get(OPTION_PLOCAL_PATH);
settings.operationsPerTransaction = getNumber(options.get(OPTION_TRANSACTIONS), "transactions");
settings.delay = getNumber(options.get(OPTION_DELAY), "delay");
settings.concurrencyLevel = getNumber(options.get(OPTION_CONCURRENCY), "concurrency");
settings.remoteIp = options.get(OPTION_REMOTE_IP);
settings.haMetrics = options.get(OPTION_HA_METRICS) != null ? Boolean.parseBoolean(options.get(OPTION_HA_METRICS)) : false;
settings.workloadCfg = options.get(OPTION_WORKLOAD);
settings.keepDatabaseAfterTest = options.get(OPTION_KEEP_DATABASE_AFTER_TEST) != null ? Boolean.parseBoolean(options.get(OPTION_KEEP_DATABASE_AFTER_TEST)) : false;
settings.remotePort = 2424;
settings.checkDatabase = Boolean.parseBoolean(options.get(OPTION_CHECK_DATABASE));
if (options.get(OPTION_LOAD_BALANCING) != null)
settings.loadBalancing = OStorageRemote.CONNECTION_STRATEGY.valueOf(options.get(OPTION_LOAD_BALANCING).toUpperCase());
if (settings.plocalPath != null) {
if (settings.plocalPath.endsWith(File.separator)) {
settings.plocalPath = settings.plocalPath.substring(0, settings.plocalPath.length() - File.separator.length());
}
File plocalFile = new File(settings.plocalPath);
if (!plocalFile.exists()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NOT_EXISTING_PLOCAL_PATH, settings.plocalPath));
}
if (!plocalFile.canWrite()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NO_WRITE_PERMISSION_PLOCAL_PATH, settings.plocalPath));
}
if (!plocalFile.isDirectory()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_PLOCAL_PATH_IS_NOT_DIRECTORY, settings.plocalPath));
}
}
if (settings.resultOutputFile != null) {
File outputFile = new File(settings.resultOutputFile);
if (outputFile.exists()) {
outputFile.delete();
}
File parentFile = outputFile.getParentFile();
// if the filename does not contain a path (both relative and absolute)
if (parentFile == null) {
parentFile = new File(".");
}
if (!parentFile.exists()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NOT_EXISTING_OUTPUT_DIRECTORY, parentFile.getAbsoluteFile()));
}
if (!parentFile.canWrite()) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_NO_WRITE_PERMISSION_OUTPUT_FILE, parentFile.getAbsoluteFile()));
}
}
if (options.get(OPTION_REMOTE_PORT) != null) {
settings.remotePort = getNumber(options.get(OPTION_REMOTE_PORT), "remotePort");
if (settings.remotePort > 65535) {
throw new IllegalArgumentException(String.format(COMMAND_LINE_PARSER_INVALID_REMOTE_PORT_NUMBER, settings.remotePort));
}
}
if (settings.mode == OStressTester.OMode.DISTRIBUTED) {
throw new IllegalArgumentException(String.format("OMode [%s] not yet supported.", settings.mode));
}
if (settings.mode == OStressTester.OMode.REMOTE && settings.remoteIp == null) {
throw new IllegalArgumentException(COMMAND_LINE_PARSER_MISSING_REMOTE_IP);
}
if (settings.rootPassword == null && settings.mode == OStressTester.OMode.REMOTE) {
Console console = System.console();
if (console != null) {
settings.rootPassword = String.valueOf(console.readPassword(String.format(CONSOLE_REMOTE_PASSWORD_PROMPT, settings.remoteIp, settings.remotePort)));
} else {
throw new Exception(ERROR_OPENING_CONSOLE);
}
}
final List<OWorkload> workloads = parseWorkloads(settings.workloadCfg);
final ODatabaseIdentifier databaseIdentifier = new ODatabaseIdentifier(settings);
return new OStressTester(workloads, databaseIdentifier, settings);
}
use of java.io.Console in project keywhiz by square.
the class AddUserCommand method run.
@Override
protected void run(Bootstrap<KeywhizConfig> bootstrap, Namespace namespace, KeywhizConfig config) throws Exception {
DataSource dataSource = config.getDataSourceFactory().build(new MetricRegistry(), "add-user-datasource");
Console console = System.console();
System.out.format("New username:");
String user = console.readLine();
System.out.format("password for '%s': ", user);
char[] password = console.readPassword();
DSLContext dslContext = DSLContexts.databaseAgnostic(dataSource);
new UserDAO(dslContext).createUser(user, new String(password));
}
use of java.io.Console in project flyway by flyway.
the class Main method promptForCredentialsIfMissing.
/**
* If no user or password has been provided, prompt for it. If you want to avoid the prompt,
* pass in an empty user or password.
*
* @param properties The properties object to load to configuration into.
*/
private static void promptForCredentialsIfMissing(Properties properties) {
Console console = System.console();
if (console == null) {
// We are running in an automated build. Prompting is not possible.
return;
}
if (!properties.containsKey("flyway.url")) {
// URL is not set. We are doomed for failure anyway.
return;
}
if (!properties.containsKey("flyway.user")) {
properties.put("flyway.user", console.readLine("Database user: "));
}
if (!properties.containsKey("flyway.password")) {
char[] password = console.readPassword("Database password: ");
properties.put("flyway.password", password == null ? "" : String.valueOf(password));
}
}
use of java.io.Console in project nhin-d by DirectProject.
the class CommandLineTokenLoginCallback method handle.
@Override
public synchronized void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
if (callback instanceof PasswordCallback) {
final Console cons = System.console();
char[] passwd = null;
if (cons != null) {
passwd = cons.readPassword("[%s]", "Enter hardware token password: ");
java.util.Arrays.fill(passwd, ' ');
} else {
System.out.print("Enter hardware token password: ");
final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
passwd = reader.readLine().toCharArray();
}
((PasswordCallback) callback).setPassword(passwd);
}
}
this.notifyAll();
}
use of java.io.Console in project Entitas-Java by Rubentxu.
the class Helper method getUserDecision.
public static boolean getUserDecision(String accept, String cancel) {
String key = "";
Console console = System.console();
Scanner scanIn = new Scanner(System.in);
do {
key = scanIn.nextLine();
} while (!key.equals(accept) && !key.equals(cancel));
scanIn.close();
return key == accept;
}
Aggregations