Fix OPENDJ-522: Add capability to force the upgrade to complete if errors occur during non-interactive mode
| | |
| | | opendmk.lib.dir= |
| | | opendmk.lib.dir=../opendmk/lib |
| | | |
| | |
| | | # CDDL HEADER END |
| | | # |
| | | # Copyright 2006-2010 Sun Microsystems, Inc. |
| | | # Portions copyright 2011 ForgeRock AS. |
| | | # Portions copyright 2011-2012 ForgeRock AS. |
| | | # Portions copyright 2012 profiq s.r.o. |
| | | |
| | | |
| | |
| | | SEVERE_ERR_DEPENDENCY_TASK_NOT_DEFINED=There is no task with ID '%s' in the \ |
| | | server. |
| | | INFO_AVAILABLE_DEFINED_TASKS=The available defined tasks are:%s |
| | | INFO_UPGRADE_DESCRIPTION_FORCE=Specifies whether the upgrade should \ |
| | | continue if there is an error while migrating configuration files or if \ |
| | | additional actions need to be performed after the upgrade. This option can \ |
| | | only be used with the %s option. |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup; |
| | |
| | | */ |
| | | public UserInteraction userInteraction() { |
| | | // Note: overridden in GuiApplication |
| | | UserInteraction ui = null; |
| | | UserData ud = getUserData(); |
| | | if (ud != null && ud.isInteractive()) { |
| | | ui = new CliUserInteraction(); |
| | | } |
| | | return ui; |
| | | return new CliUserInteraction(getUserData()); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param status of the operation |
| | | * @param note string with additional information |
| | | * @throws ApplicationException if something goes wrong |
| | | * @see {@link #writeInitialHistoricalRecord(BuildInformation, |
| | | BuildInformation)} |
| | | */ |
| | | protected void writeHistoricalRecord( |
| | | Long id, |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup; |
| | |
| | | import java.util.List; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | import java.io.PrintStream; |
| | | import java.io.InputStream; |
| | | |
| | | /** |
| | | * Supports user interactions for a command line driven application. |
| | |
| | | static private final Logger LOG = |
| | | Logger.getLogger(CliUserInteraction.class.getName()); |
| | | |
| | | private final boolean isInteractive; |
| | | private final boolean isForceOnError; |
| | | |
| | | /** |
| | | * Creates an instance that will use standard streams for interaction. |
| | | */ |
| | | public CliUserInteraction() { |
| | | super(System.in, System.out, System.err); |
| | | this(null); |
| | | } |
| | | |
| | | /** |
| | | * Creates an instance using specific streams. |
| | | * @param out OutputStream where prompts will be written |
| | | * @param err OutputStream where errors will be written |
| | | * @param in InputStream from which information will be read |
| | | * Creates an instance that will use standard streams for interaction and with |
| | | * the provided CLI arguments. |
| | | * @param ud The CLI arguments. |
| | | */ |
| | | public CliUserInteraction(PrintStream out, PrintStream err, InputStream in) { |
| | | super(in, out, err); |
| | | public CliUserInteraction(UserData ud) { |
| | | super(System.in, System.out, System.err); |
| | | isInteractive = ud != null ? ud.isInteractive() : true; |
| | | isForceOnError = ud != null ? ud.isForceOnError() : false; |
| | | } |
| | | |
| | | /** |
| | |
| | | return sb.toString(); |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public String promptForString(Message prompt, Message title, |
| | | String defaultValue) { |
| | | |
| | | return readInput(prompt, defaultValue, LOG); |
| | | } |
| | | |
| | | private void println(String text) { |
| | | text = Utils.convertHtmlBreakToLineSeparator(text); |
| | | text = Utils.stripHtml(text); |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isInteractive() { |
| | | return true; |
| | | return isInteractive; |
| | | } |
| | | |
| | | |
| | |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isForceOnError() { |
| | | return isForceOnError; |
| | | } |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup; |
| | |
| | | String createUnorderedList(List<?> list); |
| | | |
| | | /** |
| | | * Promt the user for a string. |
| | | * @param prompt for string |
| | | * @param title of prompt dialog |
| | | * @param defaultValue for default |
| | | * @return String typed by user |
| | | */ |
| | | String promptForString(Message prompt, Message title, String defaultValue); |
| | | |
| | | /** |
| | | * Tells whether the interaction is command-line based. |
| | | * @return <CODE>true</CODE> if the user interaction is command-line based and |
| | | * <CODE>false</CODE> otherwise. |
| | | */ |
| | | boolean isCLI(); |
| | | |
| | | /** |
| | | * Indicates whether or not the CLI based user has requested to continue when |
| | | * a non critical error occurs. |
| | | * |
| | | * @return boolean where true indicates to continue if there is a non critical |
| | | * error. |
| | | */ |
| | | boolean isForceOnError(); |
| | | |
| | | /** |
| | | * Indicates whether or not the CLI user has requested interactive behavior. |
| | | * |
| | | * @return <code>true</code> if the CLI user has requested interactive |
| | | * behavior. |
| | | */ |
| | | boolean isInteractive(); |
| | | |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.ui; |
| | |
| | | |
| | | import javax.swing.*; |
| | | import java.awt.event.WindowEvent; |
| | | import java.lang.reflect.Constructor; |
| | | import java.security.cert.X509Certificate; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.Set; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public UserInteraction userInteraction() { |
| | | UserInteraction ui = null; |
| | | if (getUserData().isInteractive()) { |
| | | if (Utils.isCli()) { |
| | | // Use reflection to avoid breaking the java web start in some |
| | | // platforms. |
| | | try |
| | | { |
| | | Class<?> cl = |
| | | Class.forName("org.opends.quicksetup.CliUserInteraction"); |
| | | ui = (UserInteraction) cl.newInstance(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | throw new IllegalStateException("Unexpected error: "+t, t); |
| | | } |
| | | } else { |
| | | ui = new GuiUserInteraction(qs.getFrame()); |
| | | public UserInteraction userInteraction() |
| | | { |
| | | if (Utils.isCli()) |
| | | { |
| | | // Use reflection to avoid breaking the java web start in some |
| | | // platforms. |
| | | try |
| | | { |
| | | Class<?> cl = Class.forName("org.opends.quicksetup.CliUserInteraction"); |
| | | Constructor<?> c = cl.getConstructor(UserData.class); |
| | | return (UserInteraction) c.newInstance(getUserData()); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | throw new IllegalStateException("Unexpected error: " + t, t); |
| | | } |
| | | } |
| | | return ui; |
| | | else |
| | | { |
| | | return new GuiUserInteraction(qs.getFrame()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.ui; |
| | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public String promptForString(Message prompt, Message title, |
| | | String defaultValue) { |
| | | Object o = JOptionPane.showInputDialog( |
| | | parent, prompt.toString(), title.toString(), |
| | | JOptionPane.QUESTION_MESSAGE, |
| | | null, null, defaultValue); |
| | | return o != null ? o.toString() : null; |
| | | public boolean isCLI() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isCLI() |
| | | public boolean isForceOnError() |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | public boolean isInteractive() |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * JOptionPane that controls the number of characters that are allowed |
| | | * to appear on a single line in the input area of the dialog. |
| | | */ |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | remainingChanges.removeAll(appliedChanges); |
| | | if ((firstException != null) && (appliedChanges.size() == 0)) |
| | | { |
| | | if (ui != null) { |
| | | if (ui.isInteractive()) { |
| | | Message cancel = INFO_CANCEL_BUTTON_LABEL.get(); |
| | | Message cont = INFO_CONTINUE_BUTTON_LABEL.get(); |
| | | Message retry = INFO_RETRY_BUTTON_LABEL.get(); |
| | |
| | | ReturnCode.CANCELED, |
| | | INFO_UPGRADE_CANCELED.get(), firstException); |
| | | } |
| | | } else if (ui.isForceOnError()) { |
| | | // Continue. |
| | | remainingChanges.remove(0); |
| | | } else { |
| | | throw firstException; |
| | | } |
| | |
| | | * |
| | | * |
| | | * Copyright 2008-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | reason.toMessage()), |
| | | null); |
| | | } else { |
| | | if (ui != null) { |
| | | if (ui.isInteractive()) { |
| | | for (Directive directive : issues) { |
| | | Message title; |
| | | Message summary; |
| | |
| | | INFO_REVERSION_CANCELED.get(), null); |
| | | } |
| | | } |
| | | } else { |
| | | } else if (!ui.isForceOnError()) { |
| | | throw new ApplicationException( |
| | | ReturnCode.APPLICATION_ERROR, |
| | | INFO_ORACLE_NO_SILENT.get(), null); |
| | |
| | | // If the import/export effect is present, append the detailed |
| | | // instructions. |
| | | if (effects.contains(Effect.REVERSION_DATA_EXPORT_AND_REIMPORT_REQUIRED)) { |
| | | if (ui != null) |
| | | if (ui.isInteractive()) |
| | | { |
| | | String lineBreak = ui.isCLI() ? Constants.LINE_SEPARATOR |
| | | : Constants.HTML_LINE_BREAK; |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | |
| | | // Get the user to confirm if possible |
| | | UserInteraction ui = userInteraction(); |
| | | if (ui != null) { |
| | | if (ui.isInteractive()) { |
| | | Message cont = INFO_CONTINUE_BUTTON_LABEL.get(); |
| | | Message cancel = INFO_CANCEL_BUTTON_LABEL.get(); |
| | | |
| | |
| | | } |
| | | |
| | | if (currentVersion != null && newVersion != null) { |
| | | UserInteraction ui = userInteraction() ; |
| | | if (ui == null) |
| | | { |
| | | ui = new CliUserInteraction(); |
| | | } |
| | | UserInteraction ui = userInteraction(); |
| | | ReversionIssueNotifier uo = new ReversionIssueNotifier( |
| | | ui,currentVersion,newVersion); |
| | | uo.notifyUser(); |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | reason.toMessage()), |
| | | null); |
| | | } else { |
| | | if (ui != null) { |
| | | if (ui.isInteractive()) { |
| | | String lineBreak = ui.isCLI() ? |
| | | Constants.LINE_SEPARATOR : Constants.HTML_LINE_BREAK; |
| | | for (VersionIssueNotifier.Directive directive : issues) { |
| | |
| | | INFO_UPGRADE_CANCELED.get(), null); |
| | | } |
| | | } |
| | | } else { |
| | | } else if (!ui.isForceOnError()) { |
| | | throw new ApplicationException( |
| | | ReturnCode.APPLICATION_ERROR, |
| | | INFO_ORACLE_NO_SILENT.get(), null); |
| | |
| | | // If the import/export effect is present, append the detailed |
| | | // instructions. |
| | | if (effects.contains(Effect.UPGRADE_DATA_EXPORT_AND_REIMPORT_REQUIRED)) { |
| | | if (ui != null) |
| | | if (ui.isInteractive()) |
| | | { |
| | | String lineBreak = ui.isCLI() ? Constants.LINE_SEPARATOR |
| | | : Constants.HTML_LINE_BREAK; |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | * Portions Copyright 2011-2012 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | | |
| | | import org.opends.messages.Message; |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | |
| | | private StringArgument file; |
| | | private BooleanArgument quiet; |
| | | private BooleanArgument noPrompt; |
| | | private BooleanArgument forceOnError; |
| | | private BooleanArgument verbose; |
| | | private BooleanArgument revertMostRecent; |
| | | private StringArgument reversionArchive; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Tells whether the user specified to force on non critical error in the non |
| | | * interactive mode. |
| | | * @return <CODE>true</CODE> if the user specified to force on |
| | | * non critical error and <CODE>false</CODE> otherwise. |
| | | */ |
| | | public boolean isForceOnError() |
| | | { |
| | | return forceOnError.isPresent(); |
| | | } |
| | | |
| | | /** |
| | | * Indicates whether this invocation is intended to upgrade the current |
| | | * build as opposed to revert. |
| | | * @return boolean where true indicates upgrade |
| | |
| | | INFO_UPGRADE_DESCRIPTION_NO_PROMPT.get()); |
| | | argParser.addArgument(noPrompt); |
| | | |
| | | forceOnError = new BooleanArgument( |
| | | "forceOnError", |
| | | null, |
| | | "forceOnError", |
| | | INFO_UPGRADE_DESCRIPTION_FORCE.get( |
| | | "--"+noPrompt.getLongIdentifier())); |
| | | argParser.addArgument(forceOnError); |
| | | |
| | | quiet = new BooleanArgument( |
| | | OPTION_LONG_QUIET, |
| | | OPTION_SHORT_QUIET, |
| | |
| | | |
| | | } |
| | | } |
| | | |
| | | if (!noPrompt.isPresent() && forceOnError.isPresent()) |
| | | { |
| | | Message message = |
| | | ERR_UNINSTALL_FORCE_REQUIRES_NO_PROMPT.get("--" |
| | | + forceOnError.getLongIdentifier(), "--" |
| | | + noPrompt.getLongIdentifier()); |
| | | System.err.println(message); |
| | | System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode()); |
| | | } |
| | | } catch (ArgumentException ae) { |
| | | System.err.println(ae.getMessageObject()); |
| | | printUsage(false); |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011 ForgeRock AS |
| | | * Portions Copyright 2011-2012 ForgeRock AS |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | INFO_ERROR_UPGRADED_SERVER_STARTS_WITH_ERRORS.get( |
| | | Constants.LINE_SEPARATOR + formattedDetails), null); |
| | | UserInteraction ui = userInteraction(); |
| | | if (ui != null) { |
| | | if (ui.isInteractive()) { |
| | | |
| | | // We are about to present the problems with the upgrade to the |
| | | // user and ask if they would like to continue. Regardless of |
| | |
| | | } else { |
| | | // User wants to continue; nothing to do |
| | | } |
| | | } else { |
| | | } else if (!ui.isForceOnError()) { |
| | | // We can't ask the user if they want to continue so we |
| | | // just bail on the upgrade by throwing an exception which |
| | | // will cause upgrader to exit unsuccessfully |
| | |
| | | * |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | uud.setQuiet(launcher.isQuiet()); |
| | | uud.setInteractive(!launcher.isNoPrompt()); |
| | | uud.setVerbose(launcher.isVerbose()); |
| | | uud.setForceOnError(launcher.isForceOnError()); |
| | | return uud; |
| | | } |
| | | |
| | |
| | | * |
| | | * |
| | | * Copyright 2007-2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.upgrader; |
| | |
| | | */ |
| | | protected List<Message> getExportImportInstructions() { |
| | | List<Message> instructions = new ArrayList<Message>(); |
| | | if ((ui == null) || (ui.isCLI())) |
| | | if (ui.isCLI()) |
| | | { |
| | | instructions.add(INFO_ORACLE_EI_ACTION_STEP1_CLI.get()); |
| | | } |