From e6367a1a7441ab27f4d152f7ee13c6f803621463 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 10 May 2007 18:55:38 +0000
Subject: [PATCH] This chunk of code:

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java               |  142 +++++++++++++++++++++++++++-------
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java             |    4 
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/ui/UpgraderReviewPanel.java |   15 +++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Step.java                            |    9 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/WizardStep.java                      |    8 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java         |    4 
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java                   |   13 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties       |    8 ++
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java               |    6 +
 9 files changed, 171 insertions(+), 38 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Step.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Step.java
index d568dec..bf532dc 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Step.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Step.java
@@ -96,4 +96,13 @@
   public String getMessageKey() {
     return msgKey;
   }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean isProgressStep() {
+    return this == PROGRESS;
+  }
+
+
 }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/WizardStep.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/WizardStep.java
index 9c255fc..28a8e57 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/WizardStep.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/WizardStep.java
@@ -39,4 +39,12 @@
    */
   String getMessageKey();
 
+  /**
+   * Indicates that when this step is displayed the application will
+   * be asked to launch itself.
+   * @return true indicating that this is the progress step for the
+   * application
+   */
+  boolean isProgressStep();
+
 }
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
index 8d16787..7946edc 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/installer/Installer.java
@@ -267,7 +267,7 @@
   /**
    * {@inheritDoc}
    */
-  public void finishClicked(final WizardStep cStep, final QuickSetup qs) {
+  public boolean finishClicked(final WizardStep cStep, final QuickSetup qs) {
     if (cStep == Step.REVIEW) {
         updateUserDataForReviewPanel(qs);
         qs.launch();
@@ -276,6 +276,8 @@
         throw new IllegalStateException(
                 "Cannot click on finish when we are not in the Review window");
     }
+    // Installer responsible for updating the user data and launching
+    return false;
   }
 
   /**
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties
index 387a351..1d8a199 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties
@@ -827,6 +827,14 @@
   The upgrade operation could not complete successfully due to errors and \
   the installation has been restored to the state it was in before the upgrade \
   operation.  See the logs for details on why the upgrade operation failed.
+summary-upgrade-finished-with-warnings=<b>OpenDS QuickUpgrade Succeeded With \
+  Warnings</b><br>The upgrade operation completed successfully but the upgrader \
+  had problems that require attention. See the 'Details' text for more \
+  information on the problems.
+summary-upgrade-finished-with-warnings-cli=OpenDS QuickUpgrade Succeeded With \
+  Warnings. The upgrade operation completed successfully but the upgrader \
+  had problems that require attention. See the logs for details on the \
+  problems.
 
 #
 # Progress messages
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
index de7893a..6050545 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java
@@ -307,8 +307,12 @@
    * Called when the user has clicked the 'finish' button.
    * @param cStep WizardStep at which the user clicked the previous button
    * @param qs QuickSetup controller
+   * @return boolean that the application uses to indicate the the
+   * application should be launched.  If false, the application is
+   * responsible for updating the user data for the final screen and
+   * launching the application if this is the desired behavior.
    */
-  public abstract void finishClicked(final WizardStep cStep,
+  public abstract boolean finishClicked(final WizardStep cStep,
                                      final QuickSetup qs);
 
   /**
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
index fd57361..78e6492 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/QuickSetup.java
@@ -258,6 +258,10 @@
   {
     final WizardStep cStep = getCurrentStep();
     application.nextClicked(cStep, this);
+    updateUserData(cStep);
+  }
+
+  private void updateUserData(final WizardStep cStep) {
     BackgroundTask worker = new BackgroundTask() {
       public Object processBackgroundTask() throws UserDataException {
         try {
@@ -294,6 +298,9 @@
         } else {
           setCurrentStep(application.getNextWizardStep(cStep));
         }
+        if (currentStep.isProgressStep()) {
+          launch();
+        }
       }
     };
     getDialog().workerStarted();
@@ -307,7 +314,9 @@
   private void finishClicked()
   {
     final WizardStep cStep = getCurrentStep();
-    application.finishClicked(cStep, this);
+    if (application.finishClicked(cStep, this)) {
+      updateUserData(cStep);
+    }
   }
 
   /**
@@ -445,7 +454,7 @@
   public void launch()
   {
     application.addProgressUpdateListener(this);
-    new Thread(application).start();
+    new Thread(application, "Application Thread").start();
     Thread t = new Thread(new Runnable()
     {
       public void run()
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
index 0cebc3f..d6f8775 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
@@ -284,7 +284,7 @@
   /**
    * {@inheritDoc}
    */
-  public void finishClicked(final WizardStep cStep, final QuickSetup qs) {
+  public boolean finishClicked(final WizardStep cStep, final QuickSetup qs) {
     if (cStep == Step.CONFIRM_UNINSTALL) {
       BackgroundTask worker = new BackgroundTask() {
         public Object processBackgroundTask() throws UserDataException {
@@ -333,6 +333,8 @@
       qs.getDialog().workerStarted();
       worker.startBackgroundTask();
     }
+    // Uninstaller is responsible for updating user data and launching
+    return false;
   }
 
   /**
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
index 8048941..d232f54 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -28,7 +28,6 @@
 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;
@@ -85,6 +84,14 @@
     public String getMessageKey() {
       return msgKey;
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isProgressStep() {
+      return this == PROGRESS;
+    }
+
   }
 
   /**
@@ -130,6 +137,8 @@
 
     FINISHED_WITH_ERRORS("summary-upgrade-finished-with-errors", 100),
 
+    FINISHED_WITH_WARNINGS("summary-upgrade-finished-with-warnings", 100),
+
     FINISHED("summary-upgrade-finished-successfully", 100);
 
     private String summaryMsgKey;
@@ -162,7 +171,8 @@
      */
     public boolean isLast() {
       return this == FINISHED ||
-              this == FINISHED_WITH_ERRORS;
+              this == FINISHED_WITH_ERRORS ||
+              this == FINISHED_WITH_WARNINGS;
     }
 
     /**
@@ -207,7 +217,13 @@
   /**
    * Assigned if an exception occurs during run().
    */
-  private ApplicationException runException = null;
+  private ApplicationException runError = null;
+
+  /**
+   * Assigned if a non-fatal error happened during the upgrade that the
+   * user needs to be warned about during run().
+   */
+  private ApplicationException runWarning = null;
 
   /**
    * Helps with CLI specific tasks.
@@ -380,6 +396,8 @@
       txt = getFinalSuccessMessage();
     } else if (step == UpgradeProgressStep.FINISHED_WITH_ERRORS) {
       txt = getFinalErrorMessage();
+    } else if (step == UpgradeProgressStep.FINISHED_WITH_WARNINGS) {
+      txt = getFinalWarningMessage();
     }
     else {
       txt = getMsg(((UpgradeProgressStep) step).getSummaryMesssageKey());
@@ -524,8 +542,10 @@
   public boolean isFinished() {
     return getCurrentProgressStep() ==
             UpgradeProgressStep.FINISHED
-    || getCurrentProgressStep() ==
-            UpgradeProgressStep.FINISHED_WITH_ERRORS;
+            || getCurrentProgressStep() ==
+            UpgradeProgressStep.FINISHED_WITH_ERRORS
+            || getCurrentProgressStep() ==
+            UpgradeProgressStep.FINISHED_WITH_WARNINGS;
   }
 
   /**
@@ -618,6 +638,10 @@
       }
       uud.setBuildToDownload(buildToDownload);
       uud.setInstallPackage(buildFile);
+    } else if (cStep == UpgradeWizardStep.REVIEW) {
+      Boolean startServer =
+              (Boolean) qs.getFieldValue(FieldName.SERVER_START);
+      uud.setStartServer(startServer);
     }
 
     if (errorMsgs.size() > 0) {
@@ -636,9 +660,8 @@
   /**
    * {@inheritDoc}
    */
-  public void finishClicked(final WizardStep cStep, final QuickSetup qs) {
-    qs.launch();
-    qs.setCurrentStep(UpgradeWizardStep.PROGRESS);
+  public boolean finishClicked(final WizardStep cStep, final QuickSetup qs) {
+    return true;
   }
 
   /**
@@ -668,7 +691,7 @@
   public void run() {
     // Reset exception just in case this application is rerun
     // for some reason
-    runException = null;
+    runError = null;
 
     try {
 
@@ -943,10 +966,42 @@
         throw e;
       }
 
+      // Leave the server in the state requested by the user via the
+      // checkbox on the review panel.  The upgrade has already been
+      // verified at this point to in the unlikely event of an error,
+      // we call this a warning instead of an error.
+      try {
+        ServerController control = getServerController();
+        boolean serverRunning = getInstallation().getStatus().isServerRunning();
+        boolean userRequestsStart = getUserData().getStartServer();
+        if (userRequestsStart && !serverRunning) {
+          try {
+            LOG.log(Level.INFO, "starting server");
+            control.startServer();
+          } catch (ApplicationException e) {
+            LOG.log(Level.INFO, "error starting server");
+            this.runWarning = e;
+          }
+        } else if (!userRequestsStart && serverRunning) {
+          try {
+            LOG.log(Level.INFO, "stopping server");
+            control.stopServer();
+          } catch (ApplicationException e) {
+            LOG.log(Level.INFO, "error stopping server");
+            this.runWarning = e;
+          }
+        }
+      } catch (IOException ioe) {
+        LOG.log(Level.INFO, "error determining if server running");
+        this.runWarning = new ApplicationException(
+                ApplicationException.Type.TOOL_ERROR,
+                "Error determining whether or not server running", ioe);
+      }
+
     } catch (ApplicationException ae) {
-      this.runException = ae;
+      this.runError = ae;
     } catch (Throwable t) {
-      this.runException =
+      this.runError =
               new ApplicationException(ApplicationException.Type.BUG,
                       "Unexpected error: " + t.getLocalizedMessage(),
                       t);
@@ -954,11 +1009,11 @@
       try {
         HistoricalRecord.Status status;
         String note = null;
-        if (runException == null) {
+        if (runError == null) {
           status = HistoricalRecord.Status.SUCCESS;
         } else {
           status = HistoricalRecord.Status.FAILURE;
-          note = runException.getLocalizedMessage();
+          note = runError.getLocalizedMessage();
 
           // Abort the upgrade and put things back like we found it
           LOG.log(Level.INFO, "canceling upgrade");
@@ -1007,7 +1062,34 @@
       // skipped because the process has already exited by the time
       // processing messages has finished.  Need to resolve these
       // issues.
-      if (runException == null) {
+      if (runError != null) {
+        LOG.log(Level.INFO, "upgrade completed with errors", runError);
+        if (!Utils.isCli()) {
+          notifyListenersOfLog();
+          this.currentProgressStep = UpgradeProgressStep.FINISHED_WITH_ERRORS;
+          notifyListeners(formatter.getFormattedError(runError, true));
+        } else {
+          notifyListeners(formatter.getFormattedError(runError, true) +
+                          formatter.getLineBreak());
+          notifyListeners(formatter.getLineBreak());
+          setCurrentProgressStep(UpgradeProgressStep.FINISHED_WITH_ERRORS);
+          notifyListeners(formatter.getLineBreak());
+        }
+      } else if (runWarning != null) {
+        LOG.log(Level.INFO, "upgrade completed with warnings");
+        String warningText = runWarning.getLocalizedMessage();
+        if (!Utils.isCli()) {
+          notifyListenersOfLog();
+          this.currentProgressStep = UpgradeProgressStep.FINISHED_WITH_WARNINGS;
+          notifyListeners(formatter.getFormattedWarning(warningText, true));
+        } else {
+          notifyListeners(formatter.getFormattedWarning(warningText, true) +
+                          formatter.getLineBreak());
+          notifyListeners(formatter.getLineBreak());
+          setCurrentProgressStep(UpgradeProgressStep.FINISHED_WITH_WARNINGS);
+          notifyListeners(formatter.getLineBreak());
+        }
+      } else {
         LOG.log(Level.INFO, "upgrade completed successfully");
         if (!Utils.isCli()) {
           notifyListenersOfLog();
@@ -1017,19 +1099,6 @@
           notifyListeners(null);
           this.currentProgressStep = UpgradeProgressStep.FINISHED;
         }
-      } else {
-        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());
-        }
       }
     }
 
@@ -1066,9 +1135,9 @@
       control.stopServer();
     } catch (Exception e) {
       throw new ApplicationException(ApplicationException.Type.APPLICATION,
-              "Server health check failed.  Make sure the server is capable " +
-                      "of starting without errors before running the upgrade " +
-                      "tool.", e);
+              "Server health check failed.  Please resolve the following " +
+                      "before running the upgrade " +
+                      "tool: " + e.getLocalizedMessage(), e);
     }
   }
 
@@ -1591,7 +1660,7 @@
    * {@inheritDoc}
    */
   public ApplicationException getException() {
-    return runException;
+    return runError;
   }
 
   private void setCurrentProgressStep(UpgradeProgressStep step) {
@@ -1646,6 +1715,17 @@
     return txt;
   }
 
+  private String getFinalWarningMessage() {
+    String txt;
+    if (Utils.isCli()) {
+      txt = getMsg("summary-upgrade-finished-with-warnings-cli");
+    } else {
+      txt = getFormattedWarning(
+              getMsg("summary-upgrade-finished-with-warnings"));
+    }
+    return txt;
+  }
+
   private File getStageDirectory()
           throws ApplicationException, IOException {
     return getInstallation().getTemporaryUpgradeDirectory();
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/ui/UpgraderReviewPanel.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/ui/UpgraderReviewPanel.java
index ca37042..c3e356c 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/ui/UpgraderReviewPanel.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/ui/UpgraderReviewPanel.java
@@ -30,6 +30,7 @@
 import org.opends.quicksetup.ui.ReviewPanel;
 import org.opends.quicksetup.ui.UIFactory;
 import org.opends.quicksetup.ui.LabelFieldDescriptor;
+import org.opends.quicksetup.ui.FieldName;
 import org.opends.quicksetup.upgrader.Upgrader;
 import org.opends.quicksetup.upgrader.UpgradeUserData;
 import org.opends.quicksetup.upgrader.Build;
@@ -85,8 +86,18 @@
   /**
    * {@inheritDoc}
    */
-  public boolean blockingBeginDisplay()
-  {
+  public Object getFieldValue(FieldName fieldName) {
+    Object value = null;
+    if (fieldName == FieldName.SERVER_START) {
+      value = getCheckBox().isSelected();
+    }
+    return value;
+  }
+
+  /**
+   * {@inheritDoc}
+   */
+  public boolean blockingBeginDisplay() {
     return true;
   }
 

--
Gitblit v1.10.0