From 377bb430a4fd748502a7a71391d06f79340f5c1d Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 19 Mar 2008 17:47:00 +0000
Subject: [PATCH] Fix for issue 3078 (dsreplication interactive mode not consistent with dsconfig)
---
opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 168 insertions(+), 4 deletions(-)
diff --git a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java b/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
index 68626dc..360e3e9 100644
--- a/opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
+++ b/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;
+ }
}
--
Gitblit v1.10.0