示例#1
0
  /**
   * Displays usage message.
   *
   * @param options available command line options
   */
  private static void printUsage(Options options) {
    String header =
        ConsoleTranslate.get("console.launches", PRODUCT_NAME)
            + System.getProperty("line.separator")
            + "Options:";

    (new HelpFormatter()).printHelp(80, "console(.sh|.bat) [options]", header, options, "");
  }
示例#2
0
 private static String[] getDumpsDescriptions() {
   String[] desc = new String[7];
   desc[0] = ConsoleTranslate.get("admin.command.view.dumps.prop.name"); // $NON-NLS-1$
   desc[1] = ConsoleTranslate.get("admin.command.view.dumps.prop.checkpoint"); // $NON-NLS-1$
   desc[2] = ConsoleTranslate.get("admin.command.view.dumps.prop.format"); // $NON-NLS-1$
   desc[3] = ConsoleTranslate.get("admin.command.view.dumps.prop.path"); // $NON-NLS-1$
   desc[4] = ConsoleTranslate.get("admin.command.view.dumps.prop.date"); // $NON-NLS-1$
   desc[5] = ConsoleTranslate.get("admin.command.view.dumps.prop.backend"); // $NON-NLS-1$
   desc[6] = ConsoleTranslate.get("admin.command.view.dumps.prop.tables"); // $NON-NLS-1$
   return desc;
 }
示例#3
0
 /** @see org.continuent.sequoia.console.text.commands.ConsoleCommand#parse(java.lang.String) */
 public void parse(String commandText) throws Exception {
   VirtualDatabaseMBean vdjc = jmxClient.getVirtualDatabaseProxy(dbName, user, password);
   DumpInfo[] dumps = vdjc.getAvailableDumps();
   if (dumps.length == 0) {
     console.printError(ConsoleTranslate.get("admin.command.view.dumps.nodump")); // $NON-NLS-1$
   } else {
     String formattedDumps =
         TableFormatter.format(
             getDumpsDescriptions(), getDumpsAsStrings(dumps), true); // FIXME should display dumps
     // headers in colums
     console.println(formattedDumps);
   }
 }
示例#4
0
  /**
   * Launchs the Sequoia console. The available options are: <il>
   * <li><code>-d</code> or <code>--debug</code>: show stack trace when error occurs.
   * <li><code>-f</code> or <code>--file</code>: use a given file as the source of commands instead
   *     of reading commands interactively.
   * <li><code>-h</code> or <code>--help</code>: displays usage information.
   * <li><code>-i</code> or <code>--ip</code>: IP address of the host name where the JMX Server
   *     hosting the controller is running (the default is '0.0.0.0').
   * <li><code>-n</code> or <code>--nocolor</code>: do not print colors in interactive mode for
   *     supported systems.
   * <li><code>-e</code> or <code>--exitonerror</code>: exit on error in non interactive mode.
   * <li><code>-p</code> or <code>--port</code>: JMX/RMI Port number of (the default is {@link
   *     org.continuent.sequoia.common.jmx.JmxConstants#DEFAULT_JMX_RMI_PORT}).
   * <li><code>-s</code> or <code>--secret</code>: password for JMX connection.
   * <li><code>-u</code> or <code>--username</code>: username for JMX connection.
   * <li><code>-m</code> or <code>--multiline</code>: enable multiline statements in the SQL console
   *     (disabled by default for backwards compatibility)
   * <li><code>-r</code> or <code>--requestdelimiter</code>: Request delimiter to use when multiline
   *     statement is enabled (<code>;</code> by default) connection.
   * <li><code>-v</code> or <code>--version</code>: displays version information.
   * </ul>
   *
   * @param args command line arguments (see above)
   * @throws Exception if fails
   */
  public static void main(String[] args) throws Exception {
    // Create options object
    Options options = createOptions();

    // Parse command line
    CommandLineParser parser = new GnuParser();
    CommandLine commandLine = null;
    try {
      commandLine = parser.parse(options, args);
    } catch (ParseException e) {
      System.err.println("Syntax error (" + e + ")");
      printUsage(options);
      System.exit(1);
    }

    // Non-recognized options
    int n = commandLine.getArgs().length;
    for (int i = 0; i < n; i++) {
      System.err.println("Syntax error (unrecognized option: " + commandLine.getArgs()[i] + ")");
      printUsage(options);
      System.exit(1);
    }

    // Handle --help option
    if (commandLine.hasOption('h')) {
      if (commandLine.getOptions().length > 1) System.err.println("Syntax error");

      printUsage(options);
      System.exit(1);
    }

    // Handle --version option
    if (commandLine.hasOption('v')) {
      if (commandLine.getOptions().length > 1) {
        System.err.println("Syntax error");
        printUsage(options);
      } else
        System.out.println(
            ConsoleTranslate.get(
                "console.version", new String[] {PRODUCT_NAME, Constants.VERSION}));

      System.exit(1);
    }

    startTextConsole(commandLine);
  }
示例#5
0
 /** @see org.continuent.sequoia.console.text.commands.ConsoleCommand#getCommandDescription() */
 public String getCommandDescription() {
   return ConsoleTranslate.get("admin.command.view.dumps.description"); // $NON-NLS-1$
 }
示例#6
0
  /**
   * Starts the text console with the given commandline
   *
   * @param commandLine parameters for the text console
   * @throws Exception if fails
   */
  public static void startTextConsole(CommandLine commandLine) throws Exception {
    // check if we are in interactive mode, and if so, output no traces
    boolean isInteractive = !commandLine.hasOption('f');

    // Handle --ip option
    String ip;
    try {
      // localhost
      ip = InetAddress.getByName(null).getHostName();
    } catch (UnknownHostException e1) {
      // not IPv6 compliant, but "null" is never unknown anyway
      ip = "127.0.0.1";
    }
    if (commandLine.hasOption('i')) {
      String tmp = commandLine.getOptionValue('i');
      if (tmp != null) {
        ip = tmp;
      }
    }

    boolean exitOnError = commandLine.hasOption('e');

    // Handle --debug option
    boolean debug = commandLine.hasOption('d');
    // Handle --silent option
    boolean silent = commandLine.hasOption('l');

    // Launch the console (handle --file option)
    Console console;
    InputStream in = null;
    if (commandLine.hasOption('f')) {
      String filename = commandLine.getOptionValue('f');
      if ("-".equals(filename)) {
        in = System.in;
      } else {
        try {
          in = new FileInputStream(filename);
        } catch (FileNotFoundException e) {
          System.err.println("Failed to open file '" + filename + "' (" + e + ")");
          System.exit(1);
        }
      }
    } else {
      System.out.println(
          ConsoleTranslate.get("console.interactive.mode", PRODUCT_NAME)); // $NON-NLS-1$
      in = System.in;
    }

    RmiJmxClient jmxClient = null;
    boolean sqlClientOnly = commandLine.hasOption('q');
    if (!sqlClientOnly) {
      jmxClient = getJmxClient(commandLine, ip, exitOnError);
    }
    console = new Console(jmxClient, in, isInteractive, debug, silent, exitOnError, sqlClientOnly);
    console.setPrintColor(!commandLine.hasOption('n'));
    console.enableMultilineStatements(commandLine.hasOption('m'));
    if (commandLine.hasOption('r')) {
      console.setRequestDelimiter(commandLine.getOptionValue('r'));
    }
    console.handlePrompt();
    System.exit(0);
  }