opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -781,9 +781,17 @@ } if (!secureReplication1) { try { secureReplication1 = askConfirmation(INFO_REPLICATION_ENABLE_SECURE1_PROMPT.get( String.valueOf(replicationPort1)), false, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -980,9 +988,17 @@ } if (!secureReplication2) { try { secureReplication2 = askConfirmation(INFO_REPLICATION_ENABLE_SECURE2_PROMPT.get( String.valueOf(replicationPort2)), false, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -1219,30 +1235,55 @@ if (disableADS) { println(); try { cancelled = !askConfirmation(INFO_REPLICATION_CONFIRM_DISABLE_ADS.get( ADSContext.getAdministrationSuffixDN()), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } if (disableSchema) { println(); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_SCHEMA.get(), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } if (!disableSchema && !disableADS) { println(); try { if (disableAllBaseDns(ctx, uData)) { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_LAST_SUFFIXES.get(), true, LOG); INFO_REPLICATION_CONFIRM_DISABLE_LAST_SUFFIXES.get(), true, LOG); } else { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_GENERIC.get(), true, LOG); } } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -1359,17 +1400,34 @@ if (initializeADS) { println(); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_ADS.get( ADSContext.getAdministrationSuffixDN(), hostPortSource), true, LOG); ADSContext.getAdministrationSuffixDN(), hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } else { println(); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_GENERIC.get( hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -1456,10 +1514,18 @@ if (!argParser.isExternalInitializationLocalOnly()) { println(); try { localOnly = askConfirmation( INFO_REPLICATION_PRE_EXTERNAL_INITIALIZATION_LOCAL_PROMPT.get( ConnectionUtils.getHostPort(ctx)), false, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } } else { localOnly = true; @@ -1856,21 +1922,38 @@ } String hostPortSource = ConnectionUtils.getHostPort(ctxSource); String hostPortDestination = ConnectionUtils.getHostPort(ctxDestination); if (initializeADS) { println(); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ADS.get( ADSContext.getAdministrationSuffixDN(), hostPortDestination, hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } else { println(); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_GENERIC.get( hostPortDestination, hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -2478,11 +2561,19 @@ } else { try { cancelled = !askConfirmation( ERR_REPLICATION_READING_REGISTERED_SERVERS_CONFIRM_UPDATE_REMOTE. get(Utils.getMessageFromCollection(exceptionMsgs, Constants.LINE_SEPARATOR).toString()), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } } } } } @@ -3552,7 +3643,7 @@ } if (interactive) { boolean confirmationLimitReached = false; while (suffixes.isEmpty()) { boolean noSchemaOrAds = false; @@ -3585,16 +3676,30 @@ !Utils.areDnsEqual(dn, Constants.SCHEMA_DN) && !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { try { if (askConfirmation( INFO_REPLICATION_ENABLE_SUFFIX_PROMPT.get(dn), true, LOG)) { suffixes.add(dn); } } catch (CLIException ce) { println(ce.getMessageObject()); confirmationLimitReached = true; break; } } } } if (confirmationLimitReached) { suffixes.clear(); break; } } } } } @@ -3709,6 +3814,7 @@ } if (interactive) { boolean confirmationLimitReached = false; while (suffixes.isEmpty()) { boolean noSchemaOrAds = false; @@ -3740,16 +3846,30 @@ !Utils.areDnsEqual(dn, Constants.SCHEMA_DN) && !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { try { if (askConfirmation( INFO_REPLICATION_DISABLE_SUFFIX_PROMPT.get(dn), true, LOG)) { suffixes.add(dn); } } catch (CLIException ce) { println(ce.getMessageObject()); confirmationLimitReached = true; break; } } } } if (confirmationLimitReached) { suffixes.clear(); break; } } } } } @@ -3872,6 +3992,7 @@ } if (interactive) { boolean confirmationLimitReached = false; while (suffixes.isEmpty()) { boolean noSchemaOrAds = false; @@ -3926,6 +4047,8 @@ !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { boolean addSuffix; try { if (argParser.isPreExternalInitializationSubcommand()) { addSuffix = askConfirmation( @@ -3944,6 +4067,13 @@ INFO_REPLICATION_INITIALIZE_ALL_SUFFIX_PROMPT.get(dn), true, LOG); } } catch (CLIException ce) { println(ce.getMessageObject()); confirmationLimitReached = true; break; } if (addSuffix) { suffixes.add(dn); @@ -3951,6 +4081,11 @@ } } } if (confirmationLimitReached) { suffixes.clear(); break; } } } } @@ -4010,6 +4145,7 @@ } if (interactive) { boolean confirmationLimitReached = false; while (suffixes.isEmpty()) { boolean noSchemaOrAds = false; @@ -4042,6 +4178,8 @@ !Utils.areDnsEqual(dn, Constants.SCHEMA_DN) && !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { try { if (askConfirmation( INFO_REPLICATION_INITIALIZE_SUFFIX_PROMPT.get(dn), true, LOG)) @@ -4049,6 +4187,13 @@ suffixes.add(dn); } } catch (CLIException ce) { println(ce.getMessageObject()); confirmationLimitReached = true; break; } } } } } opends/src/guitools/org/opends/guitools/uninstaller/UninstallCliHelper.java
@@ -342,7 +342,7 @@ else { boolean somethingSelected = false; while (!somethingSelected) while (!somethingSelected && !cancelled) { println(); // Ask for confirmation for the different items @@ -363,6 +363,8 @@ }; boolean[] answers = new boolean[msgs.length]; try { for (int i=0; i<msgs.length; i++) { boolean ignore = ((i == 6) && (outsideDbs.size() == 0)) || @@ -376,7 +378,16 @@ answers[i] = false; } } } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } if (!cancelled) { for (int i=0; i<answers.length; i++) { switch (i) @@ -439,6 +450,7 @@ } } } } return cancelled; } @@ -477,6 +489,8 @@ { if (interactive) { try { if (confirmToUpdateRemote()) { println(); @@ -505,6 +519,13 @@ cancelled = !confirmToStopServer(); } } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } } else { cancelled = @@ -516,6 +537,8 @@ if (interactive) { println(); try { if (confirmToUpdateRemoteAndStart()) { boolean startWorked = startServer(userData.isQuiet()); @@ -531,7 +554,8 @@ } else { cancelled = !updateUserUninstallDataWithRemoteServers(userData); cancelled = !updateUserUninstallDataWithRemoteServers(userData); if (cancelled) { println(); @@ -555,6 +579,13 @@ cancelled = !confirmDeleteFiles(); } } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } } else { boolean startWorked = startServer(userData.isQuiet()); @@ -583,6 +614,8 @@ { if (conf.isServerRunning()) { try { if (interactive) { println(); @@ -597,6 +630,13 @@ Installation.getLocal().getStatus().isServerRunning()); } } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = false; } } else { userData.setStopServer(false); @@ -604,8 +644,17 @@ { println(); /* Ask for confirmation to delete files */ try { cancelled = !confirmDeleteFiles(); } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } } } } return cancelled; @@ -615,8 +664,9 @@ * Ask for confirmation to stop server. * @return <CODE>true</CODE> if the user wants to continue and stop the * server. <CODE>false</CODE> otherwise. * @throws CLIException if the user reached the confirmation limit. */ private boolean confirmToStopServer() private boolean confirmToStopServer() throws CLIException { return askConfirmation(INFO_CLI_UNINSTALL_CONFIRM_STOP.get(), true, LOG); } @@ -625,8 +675,9 @@ * Ask for confirmation to delete files. * @return <CODE>true</CODE> if the user wants to continue and delete the * files. <CODE>false</CODE> otherwise. * @throws CLIException if the user reached the confirmation limit. */ private boolean confirmDeleteFiles() private boolean confirmDeleteFiles() throws CLIException { return askConfirmation(INFO_CLI_UNINSTALL_CONFIRM_DELETE_FILES.get(), true, LOG); @@ -636,8 +687,9 @@ * Ask for confirmation to update configuration on remote servers. * @return <CODE>true</CODE> if the user wants to continue and stop the * server. <CODE>false</CODE> otherwise. * @throws CLIException if the user reached the confirmation limit. */ private boolean confirmToUpdateRemote() private boolean confirmToUpdateRemote() throws CLIException { return askConfirmation(INFO_CLI_UNINSTALL_CONFIRM_UPDATE_REMOTE.get(), true, LOG); @@ -647,8 +699,9 @@ * Ask for confirmation to update configuration on remote servers. * @return <CODE>true</CODE> if the user wants to continue and stop the * server. <CODE>false</CODE> otherwise. * @throws CLIException if the user reached the confirmation limit. */ private boolean confirmToUpdateRemoteAndStart() private boolean confirmToUpdateRemoteAndStart() throws CLIException { return askConfirmation( INFO_CLI_UNINSTALL_CONFIRM_UPDATE_REMOTE_AND_START.get(), true, LOG); @@ -657,9 +710,10 @@ /** * Ask for confirmation to provide again authentication. * @return <CODE>true</CODE> if the user wants to provide authentication * againr. <CODE>false</CODE> otherwise. * again. <CODE>false</CODE> otherwise. * @throws CLIException if the user reached the confirmation limit. */ private boolean promptToProvideAuthenticationAgain() private boolean promptToProvideAuthenticationAgain() throws CLIException { return askConfirmation( INFO_UNINSTALL_CONFIRM_PROVIDE_AUTHENTICATION_AGAIN.get(), true, LOG); @@ -830,6 +884,8 @@ if (!couldConnect) { try { accepted = promptToProvideAuthenticationAgain(); if (accepted) { @@ -837,6 +893,13 @@ pwd = null; } } catch (CLIException ce) { println(ce.getMessageObject()); println(); accepted = false; } } } if (accepted) @@ -1113,9 +1176,18 @@ } else { accepted = askConfirmation(ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT.get(), try { accepted = askConfirmation( ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT.get(), false, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); accepted = false; } } } userData.setUpdateRemoteReplication(accepted); return accepted; @@ -1210,11 +1282,20 @@ if (!stopProcessing && (exceptionMsgs.size() > 0)) { println(); try { returnValue = askConfirmation( ERR_UNINSTALL_READING_REGISTERED_SERVERS_CONFIRM_UPDATE_REMOTE.get( Utils.getMessageFromCollection(exceptionMsgs, Constants.LINE_SEPARATOR).toString()), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); println(); returnValue = false; } } else if (reloadTopologyCache) { returnValue = updateUserUninstallDataWithRemoteServers(userData); opends/src/messages/messages/utility.properties
@@ -550,3 +550,5 @@ INFO_ARGPARSER_USAGE_JAVA_CLASSNAME_264=Usage: java %s {options} INFO_ARGPARSER_USAGE_JAVA_SCRIPTNAME_265=Usage: %s {options} INFO_ARGPARSER_USAGE_TRAILINGARGS_266={trailing-arguments} MILD_ERR_CONFIRMATION_TRIES_LIMIT_REACHED_267=Confirmation tries limit reached \ (%d) opends/src/server/org/opends/server/util/cli/ConsoleApplication.java
@@ -102,7 +102,8 @@ // The output stream which this application should use. private final PrintStream out; // The maximum number of times we try to confirm. private final static int CONFIRMATION_MAX_TRIES = 5; /** * Creates a new console application instance. @@ -221,12 +222,7 @@ } }; try { return readValidatedInput(prompt, validator); } catch (CLIException e) { // Should never happen. throw new RuntimeException(e); } return readValidatedInput(prompt, validator, CONFIRMATION_MAX_TRIES); } @@ -658,6 +654,40 @@ } /** * Interactively prompts for user input and continues until valid * input is provided. * * @param <T> * The type of decoded user input. * @param prompt * The interactive prompt which should be displayed on each * input attempt. * @param validator * An input validator responsible for validating and * decoding the user's response. * @param maxTries * The maximum number of tries that we can make. * @return Returns the decoded user's response. * @throws CLIException * If an unexpected error occurred which prevented * validation or if the maximum number of tries was reached. */ public final <T> T readValidatedInput(Message prompt, ValidationCallback<T> validator, int maxTries) throws CLIException { int nTries = 0; while (nTries < maxTries) { String response = readLineOfInput(prompt); T value = validator.validate(this, response); if (value != null) { return value; } nTries++; } throw new CLIException(ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get( CONFIRMATION_MAX_TRIES)); } /** * Commodity method that interactively confirms whether a user wishes to * perform an action. If the application is non-interactive, then the provided * default is returned automatically. If there is an error an error message @@ -672,18 +702,45 @@ * @param logger the Logger to be used to log the error message. * @return Returns <code>true</code> if the user wishes the action * to be performed, or <code>false</code> if they refused. * @throws CLIException if the user did not provide valid answer after * a certain number of tries * (ConsoleApplication.CONFIRMATION_MAX_TRIES) */ protected final boolean askConfirmation(Message prompt, boolean defaultValue, Logger logger) Logger logger) throws CLIException { boolean v = defaultValue; boolean done = false; int nTries = 0; while (!done && (nTries < CONFIRMATION_MAX_TRIES)) { nTries++; try { v = confirmAction(prompt, defaultValue); done = true; } catch (CLIException ce) { if (ce.getMessageObject().equals( ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get( CONFIRMATION_MAX_TRIES))) { throw ce; } logger.log(Level.WARNING, "Error reading input: "+ce, ce); // Try again... println(); } } if (!done) { // This means we reached the maximum number of tries throw new CLIException(ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get( CONFIRMATION_MAX_TRIES)); } return v; }