Search in sources :

Example 1 with Console

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);
}
Also used : OWorkload(com.orientechnologies.orient.stresstest.workload.OWorkload) Console(java.io.Console) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File)

Example 2 with Console

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));
}
Also used : UserDAO(keywhiz.service.daos.UserDAO) MetricRegistry(com.codahale.metrics.MetricRegistry) Console(java.io.Console) DSLContext(org.jooq.DSLContext) DataSource(javax.sql.DataSource)

Example 3 with Console

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));
    }
}
Also used : Console(java.io.Console)

Example 4 with Console

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();
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) InputStreamReader(java.io.InputStreamReader) Console(java.io.Console) BufferedReader(java.io.BufferedReader) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Example 5 with Console

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;
}
Also used : Scanner(java.util.Scanner) Console(java.io.Console)

Aggregations

Console (java.io.Console)23 IOException (java.io.IOException)6 BufferedReader (java.io.BufferedReader)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStreamReader (java.io.InputStreamReader)5 IOError (java.io.IOError)4 SshClient (org.apache.sshd.client.SshClient)4 UserInteraction (org.apache.sshd.client.auth.keyboard.UserInteraction)4 ClientChannel (org.apache.sshd.client.channel.ClientChannel)4 ClientSession (org.apache.sshd.client.session.ClientSession)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 Scanner (java.util.Scanner)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 Reader (java.io.Reader)2 HashMap (java.util.HashMap)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ChannelShell (org.apache.sshd.client.channel.ChannelShell)2 PtyCapableChannelSession (org.apache.sshd.client.channel.PtyCapableChannelSession)2