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

Matthew Swift
21.43.2012 7a6f3dd0c046db02a9cebddd7e635c2189e378ff
Fix OPENDJ-522: Add capability to force the upgrade to complete if errors occur during non-interactive mode
15 files modified
218 ■■■■■ changed files
opends/build.properties 2 ●●● patch | view | raw | blame | history
opends/src/messages/messages/admin_tool.properties 6 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/Application.java 10 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java 39 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/UserInteraction.java 27 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java 40 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/ui/GuiUserInteraction.java 21 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java 6 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/ReversionIssueNotifier.java 7 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java 9 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeIssueNotifier.java 7 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java 33 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java 6 ●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java 2 ●●●●● patch | view | raw | blame | history
opends/src/quicksetup/org/opends/quicksetup/upgrader/VersionIssueNotifier.java 3 ●●●● patch | view | raw | blame | history
opends/build.properties
@@ -1,2 +1,2 @@
opendmk.lib.dir=
opendmk.lib.dir=../opendmk/lib
opends/src/messages/messages/admin_tool.properties
@@ -21,7 +21,7 @@
# 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.
@@ -3055,4 +3055,8 @@
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.
opends/src/quicksetup/org/opends/quicksetup/Application.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup;
@@ -666,12 +667,7 @@
   */
  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());
  }
  /**
@@ -735,8 +731,6 @@
   * @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,
opends/src/quicksetup/org/opends/quicksetup/CliUserInteraction.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup;
@@ -43,8 +44,6 @@
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.
@@ -54,21 +53,25 @@
  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;
  }
  /**
@@ -174,15 +177,6 @@
    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);
@@ -203,7 +197,7 @@
   * {@inheritDoc}
   */
  public boolean isInteractive() {
    return true;
    return isInteractive;
  }
@@ -250,4 +244,11 @@
  {
    return true;
  }
  /**
   * {@inheritDoc}
   */
  public boolean isForceOnError() {
    return isForceOnError;
  }
}
opends/src/quicksetup/org/opends/quicksetup/UserInteraction.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup;
@@ -107,19 +108,27 @@
  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();
}
opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.ui;
@@ -46,6 +47,7 @@
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;
@@ -605,27 +607,27 @@
  /**
   * {@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());
    }
  }
  /**
opends/src/quicksetup/org/opends/quicksetup/ui/GuiUserInteraction.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.ui;
@@ -152,24 +153,28 @@
  /**
   * {@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.
   */
opends/src/quicksetup/org/opends/quicksetup/upgrader/MigrationManager.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.upgrader;
@@ -354,7 +355,7 @@
      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();
@@ -377,6 +378,9 @@
                ReturnCode.CANCELED,
                INFO_UPGRADE_CANCELED.get(), firstException);
          }
        } else if (ui.isForceOnError()) {
          // Continue.
          remainingChanges.remove(0);
        } else {
          throw firstException;
        }
opends/src/quicksetup/org/opends/quicksetup/upgrader/ReversionIssueNotifier.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2008-2009 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.upgrader;
@@ -91,7 +92,7 @@
                        reason.toMessage()),
                null);
      } else {
        if (ui != null) {
        if (ui.isInteractive()) {
          for (Directive directive : issues) {
            Message title;
            Message summary;
@@ -155,7 +156,7 @@
                      INFO_REVERSION_CANCELED.get(), null);
            }
          }
        } else {
        } else if (!ui.isForceOnError()) {
          throw new ApplicationException(
              ReturnCode.APPLICATION_ERROR,
              INFO_ORACLE_NO_SILENT.get(), null);
@@ -178,7 +179,7 @@
    // 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;
opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.upgrader;
@@ -514,7 +515,7 @@
      // 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();
@@ -1106,11 +1107,7 @@
    }
    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();
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeIssueNotifier.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2009 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.upgrader;
@@ -92,7 +93,7 @@
                        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) {
@@ -156,7 +157,7 @@
                      INFO_UPGRADE_CANCELED.get(), null);
            }
          }
        } else {
        } else if (!ui.isForceOnError()) {
          throw new ApplicationException(
              ReturnCode.APPLICATION_ERROR,
              INFO_ORACLE_NO_SILENT.get(), null);
@@ -179,7 +180,7 @@
    // 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;
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
@@ -23,12 +23,13 @@
 *
 *
 *      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.*;
@@ -106,6 +107,7 @@
  private StringArgument file;
  private BooleanArgument quiet;
  private BooleanArgument noPrompt;
  private BooleanArgument forceOnError;
  private BooleanArgument verbose;
  private BooleanArgument revertMostRecent;
  private StringArgument reversionArchive;
@@ -211,6 +213,17 @@
  }
  /**
   * 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
@@ -348,6 +361,14 @@
              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,
@@ -392,6 +413,16 @@
          }
        }
        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);
opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -23,7 +23,7 @@
 *
 *
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2011 ForgeRock AS
 *      Portions Copyright 2011-2012 ForgeRock AS
 */
package org.opends.quicksetup.upgrader;
@@ -1199,7 +1199,7 @@
                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
@@ -1224,7 +1224,7 @@
          } 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
opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgraderCliHelper.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.upgrader;
@@ -65,6 +66,7 @@
    uud.setQuiet(launcher.isQuiet());
    uud.setInteractive(!launcher.isNoPrompt());
    uud.setVerbose(launcher.isVerbose());
    uud.setForceOnError(launcher.isForceOnError());
    return uud;
  }
opends/src/quicksetup/org/opends/quicksetup/upgrader/VersionIssueNotifier.java
@@ -23,6 +23,7 @@
 *
 *
 *      Copyright 2007-2010 Sun Microsystems, Inc.
 *      Portions copyright 2012 ForgeRock AS.
 */
package org.opends.quicksetup.upgrader;
@@ -317,7 +318,7 @@
   */
  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());
    }