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

kenneth_suter
10.16.2007 bb1b4f1a882179359bf027bdf6acb8e9c40e5ab7
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -28,6 +28,7 @@
package org.opends.quicksetup.upgrader;
import org.opends.quicksetup.*;
import static org.opends.quicksetup.Step.PROGRESS;
import org.opends.quicksetup.upgrader.ui.WelcomePanel;
import org.opends.quicksetup.upgrader.ui.ChooseVersionPanel;
import org.opends.quicksetup.upgrader.ui.UpgraderReviewPanel;
@@ -51,6 +52,8 @@
import static org.opends.quicksetup.Installation.*;
import javax.swing.*;
/**
 * QuickSetup application of ugrading the bits of an installation of
 * OpenDS.
@@ -239,6 +242,9 @@
  private RemoteBuildManager remoteBuildManager = null;
  /** Set to true if the user decides to close the window while running. */
  private boolean abort = false;
  /**
   * Creates a default instance.
   */
@@ -362,8 +368,7 @@
   * {@inheritDoc}
   */
  public Integer getRatio(ProgressStep step) {
    return ((UpgradeProgressStep) step).ordinal() /
            EnumSet.allOf(UpgradeWizardStep.class).size();
    return ((UpgradeProgressStep) step).getProgress();
  }
  /**
@@ -373,7 +378,10 @@
    String txt = null;
    if (step == UpgradeProgressStep.FINISHED) {
      txt = getFinalSuccessMessage();
    } else {
    } else if (step == UpgradeProgressStep.FINISHED_WITH_ERRORS) {
      txt = getFinalErrorMessage();
    }
    else {
      txt = getMsg(((UpgradeProgressStep) step).getSummaryMesssageKey());
    }
    return txt;
@@ -451,7 +459,7 @@
  /**
   * {@inheritDoc}
   */
  public boolean canCancel(WizardStep step) {
  public boolean canQuit(WizardStep step) {
    return UpgradeWizardStep.WELCOME == step ||
            UpgradeWizardStep.CHOOSE_VERSION == step ||
            UpgradeWizardStep.REVIEW == step;
@@ -460,7 +468,79 @@
  /**
   * {@inheritDoc}
   */
  public void quitClicked(WizardStep step, QuickSetup qs) {
  public boolean canClose(WizardStep step) {
    return step == UpgradeWizardStep.PROGRESS;
  }
  /**
   * {@inheritDoc}
   */
  public String getFinishButtonToolTipKey() {
    return "finish-button-upgrade-tooltip";
  }
  /**
   * {@inheritDoc}
   */
  public String getQuitButtonToolTipKey() {
    return "quit-button-upgrade-tooltip";
  }
  /**
   * {@inheritDoc}
   */
  public void closeClicked(WizardStep cStep, final QuickSetup qs) {
    if (cStep == UpgradeWizardStep.PROGRESS) {
      if (isFinished()) {
        qs.quit();
      } else if (qs.displayConfirmation(getMsg("confirm-close-upgrade-msg"),
              getMsg("confirm-close-upgrade-title"))) {
        abort = true;
        JButton btnClose = qs.getDialog().getButtonsPanel().
                getButton(ButtonName.CLOSE);
        btnClose.setEnabled(false);
        new Thread(new Runnable() {
          public void run() {
            while (!isFinished()) {
              try {
                Thread.sleep(100);
              } catch (InterruptedException e) {
                // do nothing
              }
            }
            qs.quit();
          }
        }).start();
      }
    } else {
      throw new IllegalStateException(
              "Close only can be clicked on PROGRESS step");
    }
  }
  /**
   * {@inheritDoc}
   */
  public boolean isFinished() {
    return getCurrentProgressStep() ==
            UpgradeProgressStep.FINISHED
    || getCurrentProgressStep() ==
            UpgradeProgressStep.FINISHED_WITH_ERRORS;
  }
  /**
   * {@inheritDoc}
   */
  public void quitClicked(WizardStep cStep, final QuickSetup qs) {
    if (cStep == UpgradeWizardStep.PROGRESS) {
      throw new IllegalStateException(
              "Cannot click on quit from progress step");
    } else if (isFinished()) {
      qs.quit();
    } else if (qs.displayConfirmation(getMsg("confirm-quit-upgrade-msg"),
            getMsg("confirm-quit-upgrade-title"))) {
      qs.quit();
    }
  }
  /**
@@ -507,8 +587,10 @@
            uud.setServerLocation(serverLocationString);
          } catch (IllegalArgumentException iae) {
            LOG.log(Level.INFO,
                    "illegal OpenDS installation directory selected", iae);
            errorMsgs.add(getMsg("error-invalid-server-location",
                    iae.getLocalizedMessage()));
                    serverLocationString));
            qs.displayFieldInvalid(FieldName.SERVER_LOCATION, true);
          }
        }
@@ -568,22 +650,6 @@
  /**
   * {@inheritDoc}
   */
  public void closeClicked(WizardStep cStep, QuickSetup qs) {
    // TODO: prompt
    qs.quit();
  }
  /**
   * {@inheritDoc}
   */
  public void cancelClicked(WizardStep cStep, QuickSetup qs) {
    // TODO: confirm cancel
    System.exit(1);
  }
  /**
   * {@inheritDoc}
   */
  public boolean canFinish(WizardStep step) {
    boolean cf = UpgradeWizardStep.REVIEW.equals(step);
    return cf;
@@ -599,13 +665,6 @@
  /**
   * {@inheritDoc}
   */
  public boolean canClose(WizardStep step) {
    return step.equals(UpgradeWizardStep.PROGRESS);
  }
  /**
   * {@inheritDoc}
   */
  public void run() {
    // Reset exception just in case this application is rerun
    // for some reason
@@ -623,6 +682,8 @@
        }
      }
      checkAbort();
      File buildZip;
      Build buildToDownload =
              getUpgradeUserData().getInstallPackageToDownload();
@@ -664,6 +725,8 @@
        LOG.log(Level.INFO, "will use local build " + buildZip);
      }
      checkAbort();
      if (buildZip != null) {
        LOG.log(Level.INFO, "existing local build file " + buildZip.getName());
        try {
@@ -680,6 +743,8 @@
        }
      }
      checkAbort();
      try {
        LOG.log(Level.INFO, "initializing upgrade");
        setCurrentProgressStep(UpgradeProgressStep.INITIALIZING);
@@ -692,6 +757,8 @@
        throw e;
      }
      checkAbort();
      try {
        LOG.log(Level.INFO, "checking server health");
        setCurrentProgressStep(UpgradeProgressStep.CHECK_SERVER_HEALTH);
@@ -704,6 +771,8 @@
        throw e;
      }
      checkAbort();
      boolean schemaCustomizationPresent = false;
      try {
        LOG.log(Level.INFO, "checking for schema customizations");
@@ -718,6 +787,8 @@
        throw e;
      }
      checkAbort();
      boolean configCustimizationPresent = false;
      try {
        LOG.log(Level.INFO, "checking for config customizations");
@@ -733,6 +804,8 @@
        throw e;
      }
      checkAbort();
      try {
        LOG.log(Level.INFO, "backing up databases");
        setCurrentProgressStep(UpgradeProgressStep.BACKING_UP_DATABASES);
@@ -745,6 +818,8 @@
        throw e;
      }
      checkAbort();
      try {
        LOG.log(Level.INFO, "backing up filesystem");
        setCurrentProgressStep(UpgradeProgressStep.BACKING_UP_FILESYSTEM);
@@ -757,6 +832,8 @@
        throw e;
      }
      checkAbort();
      try {
        LOG.log(Level.INFO, "upgrading components");
        setCurrentProgressStep(
@@ -771,6 +848,8 @@
        throw e;
      }
      checkAbort();
      //********************************************
      //*  The two steps following this step require
      //*  the server to be started 'in process'.
@@ -791,6 +870,8 @@
          throw e;
        }
        checkAbort();
        if (schemaCustomizationPresent) {
          try {
            LOG.log(Level.INFO, "applying schema customizatoin");
@@ -807,6 +888,8 @@
          }
        }
        checkAbort();
        if (configCustimizationPresent) {
          try {
            LOG.log(Level.INFO, "applying config customizatoin");
@@ -823,6 +906,8 @@
          }
        }
        checkAbort();
        try {
          LOG.log(Level.INFO, "stopping server");
          getServerController().stopServerInProcess();
@@ -834,6 +919,8 @@
        }
      }
      checkAbort();
      // This allows you to test whether or not he upgrader can successfully
      // abort an upgrade once changes have been made to the installation
      // path's filesystem.
@@ -905,57 +992,55 @@
        LOG.log(Level.INFO, "history recorded");
        notifyListeners("See '" +
                Utils.getPath(getInstallation().getHistoryLogFile()) +
                "' for upgrade history" + formatter.getLineBreak());
                " for upgrade history" + formatter.getLineBreak());
      } catch (ApplicationException e) {
        System.err.print("Error cleaning up after upgrade: " +
                e.getLocalizedMessage());
      }
    }
    // Decide final status based on presense of error
      // Decide final status based on presense of error
    // It would be nice if this were simpler.
    if (runException == null) {
      LOG.log(Level.INFO, "upgrade completed successfully");
      if (!Utils.isCli()) {
        notifyListenersOfLog();
        // This seems to be the preferred way to print
        // a message to the top of the progress panel without
        // having it show up in the Details section which we
        // don't want since it is in HTML
        this.currentProgressStep = UpgradeProgressStep.FINISHED;
        notifyListeners(null);
      // WARNING: change this code at your own risk!  The ordering
      // of these statements is important.  There are differences
      // in how the CLI and GUI application's processes exit.
      // Changing the ordering here may result in messages being
      // skipped because the process has already exited by the time
      // processing messages has finished.  Need to resolve these
      // issues.
      if (runException == null) {
        LOG.log(Level.INFO, "upgrade completed successfully");
        if (!Utils.isCli()) {
          notifyListenersOfLog();
          this.currentProgressStep = UpgradeProgressStep.FINISHED;
          notifyListeners(null);
        } else {
          notifyListeners(null);
          this.currentProgressStep = UpgradeProgressStep.FINISHED;
        }
      } else {
        notifyListeners(100, getFinalSuccessMessage());
        // Don't do this until we've printed out last message
        // as doing so tells the CLI that it is finished and
        // System.exit gets called in QuickSetupCli
        this.currentProgressStep = UpgradeProgressStep.FINISHED;
      }
    } else {
      LOG.log(Level.INFO, "upgrade completed with errors", runException);
      if (!Utils.isCli()) {
        notifyListeners(100,
                getMsg(UpgradeProgressStep.FINISHED_WITH_ERRORS.
                        getSummaryMesssageKey()),
                formatter.getFormattedError(runException, true));
        notifyListenersOfLog();
        notifyListeners(null);
        setCurrentProgressStep(UpgradeProgressStep.FINISHED_WITH_ERRORS);
      } else {
        runException.printStackTrace();
        this.currentProgressStep = UpgradeProgressStep.FINISHED_WITH_ERRORS;
        LOG.log(Level.INFO, "upgrade completed with errors", runException);
        if (!Utils.isCli()) {
          notifyListenersOfLog();
          this.currentProgressStep = UpgradeProgressStep.FINISHED_WITH_ERRORS;
          notifyListeners(formatter.getFormattedError(runException, true));
        } else {
          notifyListeners(formatter.getFormattedError(runException, true) +
                          formatter.getLineBreak());
          notifyListeners(formatter.getLineBreak());
          setCurrentProgressStep(UpgradeProgressStep.FINISHED_WITH_ERRORS);
          notifyListeners(formatter.getLineBreak());
        }
      }
    }
  }
  private void checkAbort() throws ApplicationException {
    if (abort) throw new ApplicationException(
            ApplicationException.Type.APPLICATION,
            "upgrade canceled by user", null);
  }
  /**
   * Stops and starts the server checking for serious errors.  Also
   * has the side effect of having the server write schema.current
@@ -973,7 +1058,7 @@
      if (errors != null) {
        throw new ApplicationException(
                ApplicationException.Type.APPLICATION,
                "The server currently starts with errors with must" +
                "The server currently starts with errors which must" +
                        "be resolved before an upgrade can occur: " +
                        Utils.listToString(errors, " "),
                null);
@@ -1513,7 +1598,7 @@
    this.currentProgressStep = step;
    int progress = step.getProgress();
    String msg = getSummary(step);
    notifyListeners(progress, getFormattedProgress(msg), msg);
    notifyListeners(progress, msg, getFormattedProgress(msg));
  }
  private UpgraderCliHelper getCliHelper() {
@@ -1528,7 +1613,12 @@
    String installPath = Utils.getPath(getInstallation().getRootDirectory());
    String newVersion = null;
    try {
      newVersion = getInstallation().getBuildInformation().getBuildId();
      BuildInformation bi = getInstallation().getBuildInformation();
      if (bi != null) {
        newVersion = bi.toString();
      } else {
        newVersion = getMsg("upgrade-build-id-unknown");
      }
    } catch (ApplicationException e) {
      newVersion = getMsg("upgrade-build-id-unknown");
    }
@@ -1545,6 +1635,17 @@
    return txt;
  }
  private String getFinalErrorMessage() {
    String txt;
    if (Utils.isCli()) {
      txt = getMsg("summary-upgrade-finished-with-errors-cli");
    } else {
      txt = getFormattedError(
              getMsg("summary-upgrade-finished-with-errors"));
    }
    return txt;
  }
  private File getStageDirectory()
          throws ApplicationException, IOException {
    return getInstallation().getTemporaryUpgradeDirectory();