opends/src/guitools/org/opends/guitools/replicationcli/ReplicationCliMain.java
@@ -781,9 +781,17 @@ } if (!secureReplication1) { secureReplication1 = askConfirmation(INFO_REPLICATION_ENABLE_SECURE1_PROMPT.get( 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) { secureReplication2 = askConfirmation(INFO_REPLICATION_ENABLE_SECURE2_PROMPT.get( String.valueOf(replicationPort2)), false, LOG); try { secureReplication2 = askConfirmation(INFO_REPLICATION_ENABLE_SECURE2_PROMPT.get( String.valueOf(replicationPort2)), false, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -1219,29 +1235,54 @@ if (disableADS) { println(); cancelled = !askConfirmation(INFO_REPLICATION_CONFIRM_DISABLE_ADS.get( ADSContext.getAdministrationSuffixDN()), true, LOG); 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(); cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_SCHEMA.get(), true, LOG); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_SCHEMA.get(), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } if (!disableSchema && !disableADS) { println(); if (disableAllBaseDns(ctx, uData)) try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_LAST_SUFFIXES.get(), true, LOG); if (disableAllBaseDns(ctx, uData)) { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_LAST_SUFFIXES.get(), true, LOG); } else { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_GENERIC.get(), true, LOG); } } else catch (CLIException ce) { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_DISABLE_GENERIC.get(), true, LOG); println(ce.getMessageObject()); cancelled = true; } println(); } @@ -1359,17 +1400,34 @@ if (initializeADS) { println(); cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_ADS.get( ADSContext.getAdministrationSuffixDN(), hostPortSource), true, LOG); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_ADS.get( ADSContext.getAdministrationSuffixDN(), hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } else { println(); cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_GENERIC.get( hostPortSource), true, LOG); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ALL_GENERIC.get( hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -1456,9 +1514,17 @@ if (!argParser.isExternalInitializationLocalOnly()) { println(); localOnly = askConfirmation( INFO_REPLICATION_PRE_EXTERNAL_INITIALIZATION_LOCAL_PROMPT.get( ConnectionUtils.getHostPort(ctx)), false, LOG); 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 { @@ -1856,21 +1922,38 @@ } String hostPortSource = ConnectionUtils.getHostPort(ctxSource); String hostPortDestination = ConnectionUtils.getHostPort(ctxDestination); if (initializeADS) { println(); cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_ADS.get( ADSContext.getAdministrationSuffixDN(), hostPortDestination, hostPortSource), true, LOG); 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(); cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_GENERIC.get( hostPortDestination, hostPortSource), true, LOG); try { cancelled = !askConfirmation( INFO_REPLICATION_CONFIRM_INITIALIZE_GENERIC.get( hostPortDestination, hostPortSource), true, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); cancelled = true; } println(); } } @@ -2478,10 +2561,18 @@ } else { cancelled = !askConfirmation( ERR_REPLICATION_READING_REGISTERED_SERVERS_CONFIRM_UPDATE_REMOTE. get(Utils.getMessageFromCollection(exceptionMsgs, Constants.LINE_SEPARATOR).toString()), true, LOG); 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,14 +3676,28 @@ !Utils.areDnsEqual(dn, Constants.SCHEMA_DN) && !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { if (askConfirmation( INFO_REPLICATION_ENABLE_SUFFIX_PROMPT.get(dn), true, LOG)) try { suffixes.add(dn); 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,14 +3846,28 @@ !Utils.areDnsEqual(dn, Constants.SCHEMA_DN) && !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { if (askConfirmation( INFO_REPLICATION_DISABLE_SUFFIX_PROMPT.get(dn), true, LOG)) try { suffixes.add(dn); 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,23 +4047,32 @@ !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { boolean addSuffix; if (argParser.isPreExternalInitializationSubcommand()) try { addSuffix = askConfirmation( if (argParser.isPreExternalInitializationSubcommand()) { addSuffix = askConfirmation( INFO_REPLICATION_PRE_EXTERNAL_INITIALIZATION_SUFFIX_PROMPT. get(dn), true, LOG); } else if (argParser.isPostExternalInitializationSubcommand()) { addSuffix = askConfirmation( get(dn), true, LOG); } else if (argParser.isPostExternalInitializationSubcommand()) { addSuffix = askConfirmation( INFO_REPLICATION_POST_EXTERNAL_INITIALIZATION_SUFFIX_PROMPT. get(dn), true, LOG); get(dn), true, LOG); } else { addSuffix = askConfirmation( INFO_REPLICATION_INITIALIZE_ALL_SUFFIX_PROMPT.get(dn), true, LOG); } } else catch (CLIException ce) { addSuffix = askConfirmation( INFO_REPLICATION_INITIALIZE_ALL_SUFFIX_PROMPT.get(dn), true, LOG); println(ce.getMessageObject()); confirmationLimitReached = true; break; } if (addSuffix) { @@ -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,11 +4178,20 @@ !Utils.areDnsEqual(dn, Constants.SCHEMA_DN) && !Utils.areDnsEqual(dn, Constants.REPLICATION_CHANGES_DN)) { if (askConfirmation( INFO_REPLICATION_INITIALIZE_SUFFIX_PROMPT.get(dn), true, LOG)) try { suffixes.add(dn); if (askConfirmation( INFO_REPLICATION_INITIALIZE_SUFFIX_PROMPT.get(dn), true, LOG)) { 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,80 +363,92 @@ }; boolean[] answers = new boolean[msgs.length]; for (int i=0; i<msgs.length; i++) try { boolean ignore = ((i == 6) && (outsideDbs.size() == 0)) || ((i == 7) && (outsideLogs.size() == 0)); if (!ignore) for (int i=0; i<msgs.length; i++) { answers[i] = askConfirmation(msgs[i], true, LOG); boolean ignore = ((i == 6) && (outsideDbs.size() == 0)) || ((i == 7) && (outsideLogs.size() == 0)); if (!ignore) { answers[i] = askConfirmation(msgs[i], true, LOG); } else { answers[i] = false; } } } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } if (!cancelled) { for (int i=0; i<answers.length; i++) { switch (i) { case 0: userData.setRemoveLibrariesAndTools(answers[i]); break; case 1: userData.setRemoveDatabases(answers[i]); break; case 2: userData.setRemoveLogs(answers[i]); break; case 3: userData.setRemoveConfigurationAndSchema(answers[i]); break; case 4: userData.setRemoveBackups(answers[i]); break; case 5: userData.setRemoveLDIFs(answers[i]); break; case 6: if (answers[i]) { userData.setExternalDbsToRemove(outsideDbs); } break; case 7: if (answers[i]) { userData.setExternalLogsToRemove(outsideLogs); } break; } } if ((userData.getExternalDbsToRemove().size() == 0) && (userData.getExternalLogsToRemove().size() == 0) && !userData.getRemoveLibrariesAndTools() && !userData.getRemoveDatabases() && !userData.getRemoveConfigurationAndSchema() && !userData.getRemoveBackups() && !userData.getRemoveLDIFs() && !userData.getRemoveLogs()) { somethingSelected = false; println(); println(ERR_CLI_UNINSTALL_NOTHING_TO_BE_UNINSTALLED.get()); } else { answers[i] = false; somethingSelected = true; } } for (int i=0; i<answers.length; i++) { switch (i) { case 0: userData.setRemoveLibrariesAndTools(answers[i]); break; case 1: userData.setRemoveDatabases(answers[i]); break; case 2: userData.setRemoveLogs(answers[i]); break; case 3: userData.setRemoveConfigurationAndSchema(answers[i]); break; case 4: userData.setRemoveBackups(answers[i]); break; case 5: userData.setRemoveLDIFs(answers[i]); break; case 6: if (answers[i]) { userData.setExternalDbsToRemove(outsideDbs); } break; case 7: if (answers[i]) { userData.setExternalLogsToRemove(outsideLogs); } break; } } if ((userData.getExternalDbsToRemove().size() == 0) && (userData.getExternalLogsToRemove().size() == 0) && !userData.getRemoveLibrariesAndTools() && !userData.getRemoveDatabases() && !userData.getRemoveConfigurationAndSchema() && !userData.getRemoveBackups() && !userData.getRemoveLDIFs() && !userData.getRemoveLogs()) { somethingSelected = false; println(); println(ERR_CLI_UNINSTALL_NOTHING_TO_BE_UNINSTALLED.get()); } else { somethingSelected = true; } } } @@ -477,56 +489,16 @@ { if (interactive) { if (confirmToUpdateRemote()) try { println(); cancelled = !askForAuthenticationIfNeeded(userData); if (cancelled) if (confirmToUpdateRemote()) { /* Ask for confirmation to stop server */ println(); cancelled = !confirmToStopServer(); } else { cancelled = !updateUserUninstallDataWithRemoteServers(userData); if (cancelled) { println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } } } else { println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } } else { cancelled = !updateUserUninstallDataWithRemoteServers(userData); } } else { if (interactive) { println(); if (confirmToUpdateRemoteAndStart()) { boolean startWorked = startServer(userData.isQuiet()); // Ask for authentication if needed, etc. if (startWorked) { cancelled = !askForAuthenticationIfNeeded(userData); if (cancelled) { println(); /* Ask for confirmation to stop server */ println(); cancelled = !confirmToStopServer(); } else @@ -542,17 +514,76 @@ } else { userData.setStopServer(false); println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } } else { cancelled = !updateUserUninstallDataWithRemoteServers(userData); } } else { if (interactive) { println(); try { if (confirmToUpdateRemoteAndStart()) { boolean startWorked = startServer(userData.isQuiet()); // Ask for authentication if needed, etc. if (startWorked) { cancelled = !askForAuthenticationIfNeeded(userData); if (cancelled) { println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } else { cancelled = !updateUserUninstallDataWithRemoteServers(userData); if (cancelled) { println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } } } else { userData.setStopServer(false); println(); /* Ask for confirmation to delete files */ cancelled = !confirmDeleteFiles(); } } else { println(); /* Ask for confirmation to delete files */ cancelled = !confirmDeleteFiles(); } } else catch (CLIException ce) { println(ce.getMessageObject()); println(); /* Ask for confirmation to delete files */ cancelled = !confirmDeleteFiles(); cancelled = true; } } else @@ -583,18 +614,27 @@ { if (conf.isServerRunning()) { if (interactive) try { println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } if (interactive) { println(); /* Ask for confirmation to stop server */ cancelled = !confirmToStopServer(); } if (!cancelled) if (!cancelled) { /* During all the confirmations, the server might be stopped. */ userData.setStopServer( Installation.getLocal().getStatus().isServerRunning()); } } catch (CLIException ce) { /* During all the confirmations, the server might be stopped. */ userData.setStopServer( Installation.getLocal().getStatus().isServerRunning()); println(ce.getMessageObject()); println(); cancelled = false; } } else @@ -604,7 +644,16 @@ { println(); /* Ask for confirmation to delete files */ cancelled = !confirmDeleteFiles(); try { cancelled = !confirmDeleteFiles(); } catch (CLIException ce) { println(ce.getMessageObject()); println(); cancelled = true; } } } } @@ -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,11 +884,20 @@ if (!couldConnect) { accepted = promptToProvideAuthenticationAgain(); if (accepted) try { uid = null; pwd = null; accepted = promptToProvideAuthenticationAgain(); if (accepted) { uid = null; pwd = null; } } catch (CLIException ce) { println(ce.getMessageObject()); println(); accepted = false; } } } @@ -1113,8 +1176,17 @@ } else { accepted = askConfirmation(ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT.get(), false, LOG); try { accepted = askConfirmation( ERR_UNINSTALL_NOT_UPDATE_REMOTE_PROMPT.get(), false, LOG); } catch (CLIException ce) { println(ce.getMessageObject()); accepted = false; } } } userData.setUpdateRemoteReplication(accepted); @@ -1210,10 +1282,19 @@ if (!stopProcessing && (exceptionMsgs.size() > 0)) { println(); returnValue = askConfirmation( 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) { 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; try boolean done = false; int nTries = 0; while (!done && (nTries < CONFIRMATION_MAX_TRIES)) { v = confirmAction(prompt, defaultValue); 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(); } } catch (CLIException ce) if (!done) { logger.log(Level.WARNING, "Error reading input: "+ce, ce); // This means we reached the maximum number of tries throw new CLIException(ERR_CONFIRMATION_TRIES_LIMIT_REACHED.get( CONFIRMATION_MAX_TRIES)); } return v; }