mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

kenneth_suter
19.03.2007 64211fec78618eca2c8303abe50c85299ecc9b9e
This commit would clarifies the local operation vs. task scheduling behavior by:

Printing a helpful error message if the user provides a start time without LDAP connection information.

Printing a helpful error message if the user tries to provide LDAP connection information without a the startTime option.

Allows the user to schedule a task for immediate execution in the server by providing the startTime argument value of '0' in addition to a numberic value in 'YYYYMMDDhhmmss'.
5 files modified
115 ■■■■ changed files
opends/src/messages/messages/tools.properties 15 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java 59 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/RestoreDB.java 2 ●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/tasks/TaskTool.java 33 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java 6 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties
@@ -2140,8 +2140,19 @@
SEVERE_ERR_TASK_CLIENT_TASK_STATE_UNKNOWN_1455=State for task '%s' cannot be \
  determined
INFO_DESCRIPTION_START_DATETIME_1456=Indicates the date/time at which the this \
  task will start when scheduled expressed in format 'YYYYMMDDhhmmss'. \
  Omission of this option will cause the task to be for immediate execution
  operation will start when scheduled as a server task expressed in format \
  'YYYYMMDDhhmmss'.  A value of '0' will cause the task to be scheduled for \
  immediate execution
SEVERE_ERR_START_DATETIME_FORMAT_1457=The start date/time must in format \
  'YYYYMMDDhhmmss'
INFO_TASK_TOOL_TASK_SCHEDULED_FUTURE_1458=%s task %s scheduled to start %s
SEVERE_ERR_TASK_TOOL_START_TIME_NO_LDAP_1459=You have provided a task start \
  time but options provided for connecting to the server's tasks backend \
  resulted in the following error: '%s'
SEVERE_ERR_TASK_TOOL_LDAP_NO_START_TIME_1460=You have provided options that \
  specify information for specifying a connection to the Directory Server but \
  no -t/--startTime option.  In order to schedule a server task you must \
  provide the -t/--startTime argument with either the start time in format \
  'YYYYMMDDhhmmss' as the value or '0' to schedule the task for immediate \
  execution.  To run this operation locally and not as a server task omit the \
  Directory Server connection options
opends/src/server/org/opends/server/admin/client/cli/SecureConnectionCliArgs.java
@@ -154,6 +154,10 @@
   */
  public StringArgument  saslOptionArg = null;
  /**
   * Private container for global arguments.
   */
  private LinkedHashSet<Argument> argList = null;
  // the trust manager.
  private ApplicationTrustManager trustManager;
@@ -182,6 +186,25 @@
  }
  /**
   * Indicates whether or not any of the arguments are present.
   *
   * @return boolean where true indicates that at least one of the
   *         arguments is present
   */
  public boolean argumentsPresent() {
    boolean present = false;
    if (argList != null) {
      for (Argument arg : argList) {
        if (arg.isPresent()) {
          present = true;
          break;
        }
      }
    }
    return present;
  }
  /**
   * Get the bindDN which has to be used for the command.
   *
   * @return The bindDN specified by the command line argument, or the
@@ -360,42 +383,42 @@
  public LinkedHashSet<Argument> createGlobalArguments()
  throws ArgumentException
  {
    LinkedHashSet<Argument> set = new LinkedHashSet<Argument>();
    argList = new LinkedHashSet<Argument>();
    useSSLArg = new BooleanArgument("useSSL", OPTION_SHORT_USE_SSL,
        OPTION_LONG_USE_SSL, INFO_DESCRIPTION_USE_SSL.get());
    set.add(useSSLArg);
    argList.add(useSSLArg);
    useStartTLSArg = new BooleanArgument("startTLS", OPTION_SHORT_START_TLS,
        OPTION_LONG_START_TLS,
        INFO_DESCRIPTION_START_TLS.get());
    set.add(useStartTLSArg);
    argList.add(useStartTLSArg);
    hostNameArg = new StringArgument("host", OPTION_SHORT_HOST,
        OPTION_LONG_HOST, false, false, true, OPTION_VALUE_HOST, "localhost",
        null, INFO_DESCRIPTION_HOST.get());
    set.add(hostNameArg);
    argList.add(hostNameArg);
    portArg = new IntegerArgument("port", OPTION_SHORT_PORT, OPTION_LONG_PORT,
        false, false, true, OPTION_VALUE_PORT, 389, null,
        INFO_DESCRIPTION_PORT.get());
    set.add(portArg);
    argList.add(portArg);
    bindDnArg = new StringArgument("bindDN", OPTION_SHORT_BINDDN,
        OPTION_LONG_BINDDN, false, false, true, OPTION_VALUE_BINDDN,
        "cn=Directory Manager", null, INFO_DESCRIPTION_BINDDN.get());
    set.add(bindDnArg);
    argList.add(bindDnArg);
    bindPasswordArg = new StringArgument("bindPassword",
        OPTION_SHORT_BINDPWD, OPTION_LONG_BINDPWD, false, false, true,
        OPTION_VALUE_BINDPWD, null, null, INFO_DESCRIPTION_BINDPASSWORD.get());
    set.add(bindPasswordArg);
    argList.add(bindPasswordArg);
    bindPasswordFileArg = new FileBasedArgument("bindPasswordFile",
        OPTION_SHORT_BINDPWD_FILE, OPTION_LONG_BINDPWD_FILE, false, false,
        OPTION_VALUE_BINDPWD_FILE, null, null,
        INFO_DESCRIPTION_BINDPASSWORDFILE.get());
    set.add(bindPasswordFileArg);
    argList.add(bindPasswordFileArg);
    saslOptionArg = new StringArgument(
            "sasloption", OPTION_SHORT_SASLOPTION,
@@ -403,56 +426,56 @@
            true, true,
            OPTION_VALUE_SASLOPTION, null, null,
            INFO_LDAP_CONN_DESCRIPTION_SASLOPTIONS.get());
    set.add(saslOptionArg);
    argList.add(saslOptionArg);
    trustAllArg = new BooleanArgument("trustAll", OPTION_SHORT_TRUSTALL,
        OPTION_LONG_TRUSTALL, INFO_DESCRIPTION_TRUSTALL.get());
    set.add(trustAllArg);
    argList.add(trustAllArg);
    trustStorePathArg = new StringArgument("trustStorePath",
        OPTION_SHORT_TRUSTSTOREPATH, OPTION_LONG_TRUSTSTOREPATH, false,
        false, true, OPTION_VALUE_TRUSTSTOREPATH, null, null,
        INFO_DESCRIPTION_TRUSTSTOREPATH.get());
    set.add(trustStorePathArg);
    argList.add(trustStorePathArg);
    trustStorePasswordArg = new StringArgument("trustStorePassword",
        OPTION_SHORT_TRUSTSTORE_PWD, OPTION_LONG_TRUSTSTORE_PWD, false, false,
        true, OPTION_VALUE_TRUSTSTORE_PWD, null, null,
        INFO_DESCRIPTION_TRUSTSTOREPASSWORD.get());
    set.add(trustStorePasswordArg);
    argList.add(trustStorePasswordArg);
    trustStorePasswordFileArg = new FileBasedArgument("trustStorePasswordFile",
        OPTION_SHORT_TRUSTSTORE_PWD_FILE, OPTION_LONG_TRUSTSTORE_PWD_FILE,
        false, false, OPTION_VALUE_TRUSTSTORE_PWD_FILE, null, null,
        INFO_DESCRIPTION_TRUSTSTOREPASSWORD_FILE.get());
    set.add(trustStorePasswordFileArg);
    argList.add(trustStorePasswordFileArg);
    keyStorePathArg = new StringArgument("keyStorePath",
        OPTION_SHORT_KEYSTOREPATH, OPTION_LONG_KEYSTOREPATH, false, false,
        true, OPTION_VALUE_KEYSTOREPATH, null, null,
        INFO_DESCRIPTION_KEYSTOREPATH.get());
    set.add(keyStorePathArg);
    argList.add(keyStorePathArg);
    keyStorePasswordArg = new StringArgument("keyStorePassword",
        OPTION_SHORT_KEYSTORE_PWD,
        OPTION_LONG_KEYSTORE_PWD, false, false, true,
        OPTION_VALUE_KEYSTORE_PWD, null, null,
        INFO_DESCRIPTION_KEYSTOREPASSWORD.get());
    set.add(keyStorePasswordArg);
    argList.add(keyStorePasswordArg);
    keyStorePasswordFileArg = new FileBasedArgument("keystorePasswordFile",
        OPTION_SHORT_KEYSTORE_PWD_FILE, OPTION_LONG_KEYSTORE_PWD_FILE, false,
        false, OPTION_VALUE_KEYSTORE_PWD_FILE, null, null,
        INFO_DESCRIPTION_KEYSTOREPASSWORD_FILE.get());
    set.add(keyStorePasswordFileArg);
    argList.add(keyStorePasswordFileArg);
    certNicknameArg = new StringArgument("certNickname",
        OPTION_SHORT_CERT_NICKNAME, OPTION_LONG_CERT_NICKNAME,
        false, false, true, OPTION_VALUE_CERT_NICKNAME, null, null,
        INFO_DESCRIPTION_CERT_NICKNAME.get());
    set.add(certNicknameArg);
    argList.add(certNicknameArg);
    return set;
    return argList;
  }
  /**
opends/src/server/org/opends/server/tools/RestoreDB.java
@@ -265,7 +265,7 @@
    }
    if (listBackups.isPresent() && argParser.isLdapOperation()) {
    if (listBackups.isPresent() && argParser.argumentsPresent()) {
      Message message = ERR_LDAP_CONN_INCOMPATIBLE_ARGS.get(
              listBackups.getLongIdentifier());
      err.println(wrapText(message, MAX_LINE_WIDTH));
opends/src/server/org/opends/server/tools/tasks/TaskTool.java
@@ -56,6 +56,13 @@
 */
public abstract class TaskTool implements TaskScheduleInformation {
  /**
   * Magic value used to indicate that the user would like to schedule
   * this operation to run immediately as a task as opposed to running
   * the operation in the local VM.
   */
  public static final String NOW = "0";
  LDAPConnectionArgumentParser argParser;
  StringArgument startArg;
@@ -85,8 +92,8 @@
  protected LDAPConnectionArgumentParser createArgParser(String className,
                                           Message toolDescription)
  {
    LDAPConnectionArgumentParser argParser = new LDAPConnectionArgumentParser(
            className, toolDescription, false);
    argParser = new LDAPConnectionArgumentParser(className,
            toolDescription, false);
    try {
      startArg =
@@ -113,7 +120,7 @@
   * @throws ArgumentException if there is a problem with the arguments
   */
  protected void validateTaskArgs() throws ArgumentException {
    if (startArg.isPresent()) {
    if (startArg.isPresent() && !NOW.equals(startArg.getValue())) {
      try {
        StaticUtils.parseDateTimeString(startArg.getValue());
      } catch (ParseException pe) {
@@ -128,10 +135,14 @@
  public Date getStartDateTime() {
    Date start = null;
    if (startArg != null && startArg.isPresent()) {
      try {
        start = StaticUtils.parseDateTimeString(startArg.getValue());
      } catch (ParseException pe) {
        // ignore; valiidated in validateTaskArgs()
      if (NOW.equals(startArg.getValue())) {
        start = new Date();
      } else {
        try {
          start = StaticUtils.parseDateTimeString(startArg.getValue());
        } catch (ParseException pe) {
          // ignore; valiidated in validateTaskArgs()
        }
      }
    }
    return start;
@@ -153,7 +164,7 @@
                        PrintStream out, PrintStream err) {
    int ret;
    if (argParser.isLdapOperation())
    if (startArg.isPresent())
    {
      if (initializeServer)
      {
@@ -193,7 +204,7 @@
        }
        ret = 0;
      } catch (LDAPConnectionException e) {
        Message message = ERR_LDAP_CONN_CANNOT_CONNECT.get(e.getMessage());
        Message message = ERR_TASK_TOOL_START_TIME_NO_LDAP.get(e.getMessage());
        if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
        ret = 1;
      } catch (IOException ioe) {
@@ -213,6 +224,10 @@
        if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
        ret = 1;
      }
    } else if (argParser.argumentsPresent()) {
      Message message = ERR_TASK_TOOL_LDAP_NO_START_TIME.get();
      if (err != null) err.println(wrapText(message, MAX_LINE_WIDTH));
      ret = 1;
    } else {
      ret = processLocal(initializeServer, out, err);
    }
opends/src/server/org/opends/server/util/args/LDAPConnectionArgumentParser.java
@@ -124,10 +124,8 @@
   * @return true if the user wants to perform a remote operation;
   *         false otherwise
   */
  public boolean isLdapOperation() {
    return args.hostNameArg.isPresent() ||
            args.portArg.isPresent() ||
            args.bindDnArg.isPresent();
  public boolean argumentsPresent() {
    return args != null && args.argumentsPresent();
  }
  /**