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

jvergara
19.47.2008 9ac58eb42e34b77fd29618f9a48b2e102f4c1c56
Fix for issue 3078 (dsreplication interactive mode not consistent with dsconfig)

The fix consists of displaying a menu with the different options of dsreplication when the user does not specify the subcommand on interactive mode.
2 files modified
189 ■■■■■ changed files
opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java 172 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/messages/messages/admin_tool.properties 17 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -114,6 +114,8 @@
import org.opends.server.util.cli.CLIException;
import org.opends.server.util.cli.ConsoleApplication;
import org.opends.server.util.cli.LDAPConnectionConsoleInteraction;
import org.opends.server.util.cli.MenuBuilder;
import org.opends.server.util.cli.MenuResult;
import org.opends.server.util.table.TableBuilder;
import org.opends.server.util.table.TextTablePrinter;
@@ -141,6 +143,57 @@
  private static final Logger LOG =
    Logger.getLogger(ReplicationCliMain.class.getName());
  /**
   * The enumeration containing the different options we display when we ask
   * the user to provide the subcommand interactively.
   */
  private enum SubcommandChoice
  {
    /**
     * Enable replication.
     */
    ENABLE(INFO_REPLICATION_ENABLE_MENU_PROMPT.get()),
    /**
     * Disable replication.
     */
    DISABLE(INFO_REPLICATION_DISABLE_MENU_PROMPT.get()),
    /**
     * Initialize replication.
     */
    INITIALIZE(INFO_REPLICATION_INITIALIZE_MENU_PROMPT.get()),
    /**
     * Initialize All.
     */
    INITIALIZE_ALL(INFO_REPLICATION_INITIALIZE_ALL_MENU_PROMPT.get()),
    /**
     * Pre external initialization.
     */
    PRE_EXTERNAL_INITIALIZATION(
        INFO_REPLICATION_PRE_EXTERNAL_INITIALIZATION_MENU_PROMPT.get()),
    /**
     * Post external initialization.
     */
    POST_EXTERNAL_INITIALIZATION(
        INFO_REPLICATION_POST_EXTERNAL_INITIALIZATION_MENU_PROMPT.get()),
    /**
     * Replication status.
     */
    STATUS(INFO_REPLICATION_STATUS_MENU_PROMPT.get()),
    /**
     * Cancel operation.
     */
    CANCEL(null);
    private Message prompt;
    private SubcommandChoice(Message prompt)
    {
      this.prompt = prompt;
    }
    Message getPrompt()
    {
      return prompt;
    }
  };
  // The argument parser to be used.
  private ReplicationCliArgumentParser argParser;
  private LDAPConnectionConsoleInteraction ci = null;
@@ -367,10 +420,72 @@
        }
        else
        {
          println(ERR_REPLICATION_VALID_SUBCOMMAND_NOT_FOUND.get());
          println(Message.raw(argParser.getUsage()));
          returnValue = ERROR_USER_DATA;
          subcommandLaunched = false;
          if (argParser.isInteractive())
          {
            String subCommand = null;
            switch (promptForSubcommand())
            {
            case ENABLE:
              subCommand =
                ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME;
              break;
            case DISABLE:
              subCommand =
                ReplicationCliArgumentParser.DISABLE_REPLICATION_SUBCMD_NAME;
              break;
            case INITIALIZE:
              subCommand =
                ReplicationCliArgumentParser.INITIALIZE_REPLICATION_SUBCMD_NAME;
              break;
            case INITIALIZE_ALL:
              subCommand =
                ReplicationCliArgumentParser.
                INITIALIZE_ALL_REPLICATION_SUBCMD_NAME;
              break;
            case PRE_EXTERNAL_INITIALIZATION:
              subCommand = ReplicationCliArgumentParser.
              PRE_EXTERNAL_INITIALIZATION_SUBCMD_NAME;
              break;
            case POST_EXTERNAL_INITIALIZATION:
              subCommand = ReplicationCliArgumentParser.
                 POST_EXTERNAL_INITIALIZATION_SUBCMD_NAME;
              break;
            case STATUS:
              subCommand =
                ReplicationCliArgumentParser.STATUS_REPLICATION_SUBCMD_NAME;
              break;
            default:
              // User cancelled
              returnValue = USER_CANCELLED;
            }
            if (subCommand != null)
            {
              String[] newArgs = new String[args.length + 1];
              newArgs[0] = subCommand;
              for (int i=0; i<args.length ; i++)
              {
                newArgs[i+1] = args[i];
              }
              // The server (if requested) has already been initialized.
              return execute(newArgs, false);
            }
          }
          else
          {
            println(ERR_REPLICATION_VALID_SUBCOMMAND_NOT_FOUND.get(
                ToolConstants.OPTION_LONG_NO_PROMPT));
            println(Message.raw(argParser.getUsage()));
            returnValue = ERROR_USER_DATA;
            subcommandLaunched = false;
          }
        }
        // Display the log file only if the operation is successful (when there
@@ -3000,6 +3115,10 @@
                  Installer.WARNING_CLOCK_DIFFERENCE_THRESOLD_MINUTES)));
        }
      }
      printlnProgress();
      printProgress(INFO_REPLICATION_POST_ENABLE_INFO.get("dsreplication",
          ReplicationCliArgumentParser.ENABLE_REPLICATION_SUBCMD_NAME));
      printlnProgress();
    }
    if (ctx1 != null)
@@ -4196,6 +4315,11 @@
              }
            }
          }
          if (confirmationLimitReached)
          {
            suffixes.clear();
            break;
          }
        }
      }
    }
@@ -7423,4 +7547,44 @@
    }
    return hostPort;
  }
  /**
   * Prompts the user for the subcommand that should be executed.
   * @return the subcommand choice of the user.
   */
  private SubcommandChoice promptForSubcommand()
  {
    SubcommandChoice returnValue;
    MenuBuilder<SubcommandChoice> builder =
      new MenuBuilder<SubcommandChoice>(this);
    builder.setPrompt(INFO_REPLICATION_SUBCOMMAND_PROMPT.get());
    builder.addCancelOption(false);
    for (SubcommandChoice choice : SubcommandChoice.values())
    {
      if (choice != SubcommandChoice.CANCEL)
      {
        builder.addNumberedOption(choice.getPrompt(),
            MenuResult.success(choice));
      }
    }
    try
    {
      MenuResult<SubcommandChoice> m = builder.toMenu().run();
      if (m.isSuccess())
      {
        returnValue = m.getValue();
      }
      else
      {
       // The user cancelled
        returnValue = SubcommandChoice.CANCEL;
      }
    }
    catch (CLIException ce)
    {
      returnValue = SubcommandChoice.CANCEL;
      LOG.log(Level.WARNING, "Error reading input: "+ce, ce);
    }
    return returnValue;
  }
}
opendj-sdk/opends/src/messages/messages/admin_tool.properties
@@ -551,7 +551,7 @@
SEVERE_ERR_REPLICATION_SAME_REPLICATION_PORT=You have provided the same \
 replication port (%s) for two servers located on the same machine (%s).
SEVERE_ERR_REPLICATION_VALID_SUBCOMMAND_NOT_FOUND=Could not find a valid \
 subcommand.
 subcommand.  You must specify a subcommand when using the option {%s}.
SEVERE_ERR_REPLICATION_STATUS_QUIET=The {%s} subcommand is not compatible with \
 the {%s} argument.
INFO_REPLICATION_SUCCESSFUL=The operation has been successfully completed
@@ -592,7 +592,7 @@
INFO_REPLICATION_ENABLE_REPLICATIONPORT2_PROMPT=Replication port for the \
 second server (the port must be free)
INFO_REPLICATION_ENABLE_SECURE2_PROMPT=Do want replication to use encrypted \
 communication when connecting to replication port %s on the second server?
 communication when connecting to replication port %s on the second server?
INFO_REPLICATION_ENABLE_BINDDN2_PROMPT=Bind DN for the second server
INFO_REPLICATION_ENABLE_PASSWORD2_PROMPT=Password for %s on the second server:
INFO_REPLICATION_INITIALIZE_SOURCE_CONNECTION_PARAMETERS=>>>> Specify OpenDS \
@@ -798,3 +798,16 @@
 %s for more information.
SEVERE_ERR_LAUNCHING_PRE_EXTERNAL_INITIALIZATION=Error launching the operation.
SEVERE_ERR_LAUNCHING_POST_EXTERNAL_INITIALIZATION=Error launching the operation.
INFO_REPLICATION_SUBCOMMAND_PROMPT=What do you want to do?
INFO_REPLICATION_ENABLE_MENU_PROMPT=Enable Replication
INFO_REPLICATION_DISABLE_MENU_PROMPT=Disable Replication
INFO_REPLICATION_INITIALIZE_MENU_PROMPT=Initialize Replication on one Server
INFO_REPLICATION_INITIALIZE_ALL_MENU_PROMPT=Initialize All Servers
INFO_REPLICATION_PRE_EXTERNAL_INITIALIZATION_MENU_PROMPT=Pre External \
 Initialization
INFO_REPLICATION_POST_EXTERNAL_INITIALIZATION_MENU_PROMPT=Post External \
 Initialization
INFO_REPLICATION_STATUS_MENU_PROMPT=Display Replication Status
INFO_REPLICATION_POST_ENABLE_INFO=Replication has been successfully enabled.  \
 Note that for replication to work you must initialize the contents of the \
 base DNs that are being replicated (use %s %s to do so).