From cfb5767d9216efaf0c1738b5ce1ae243630fd8f5 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Mon, 30 Apr 2007 21:31:38 +0000
Subject: [PATCH] This commit is mainly intended to prevent the sort of false positives that occur when the upgrader assumes the server has been upgraded properly but leaves the server in a corrupt state (see issues 1546 and 1559).  The following changes are introduced:

---
 opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java |   49 +++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java b/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
index 0982969..3a19f43 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/ServerController.java
@@ -33,6 +33,7 @@
 import javax.naming.NamingException;
 import java.util.ArrayList;
 import java.util.Map;
+import java.util.List;
 import java.io.BufferedReader;
 import java.io.InputStreamReader;
 import java.io.IOException;
@@ -224,19 +225,26 @@
 
   /**
    * This methods starts the server.
+   * @return OperationOutput object containing output from the start server
+   * command invocation.
    * @throws org.opends.quicksetup.ApplicationException if something goes wrong.
    */
-  public void startServer() throws ApplicationException {
-    startServer(true);
+  public OperationOutput startServer() throws ApplicationException {
+    return startServer(true);
   }
 
   /**
    * This methods starts the server.
    * @param verify boolean indicating whether this method will attempt to
    * connect to the server after starting to verify that it is listening.
+   * @return OperationOutput object containing output from the start server
+   * command invocation.
    * @throws org.opends.quicksetup.ApplicationException if something goes wrong.
    */
-  private void startServer(boolean verify) throws ApplicationException {
+  private OperationOutput startServer(boolean verify)
+          throws ApplicationException
+  {
+    OperationOutput output = new OperationOutput();
     application.notifyListeners(
             application.getFormattedProgress(
                     application.getMsg("progress-starting")) +
@@ -275,7 +283,7 @@
       StartReader errReader = new StartReader(err, startedId, true);
       StartReader outputReader = new StartReader(out, startedId, false);
 
-      while (!errReader.isFinished() && !outputReader.isFinished())
+      while (!errReader.isFinished() || !outputReader.isFinished())
       {
         try
         {
@@ -284,6 +292,17 @@
         {
         }
       }
+
+      // Collect any errors found in the output
+      List<String> errors = errReader.getErrors();
+      if (outputReader.getErrors() != null) {
+        if (errors == null) {
+          errors = new ArrayList<String>();
+        }
+        errors.addAll(outputReader.getErrors());
+      }
+      output.setErrors(errors);
+
       // Check if something wrong occurred reading the starting of the server
       ApplicationException ex = errReader.getException();
       if (ex == null)
@@ -292,6 +311,11 @@
       }
       if (ex != null)
       {
+        // This is meaningless right now since we throw
+        // the exception below, but in case we change out
+        // minds later or add the ability to return exceptions
+        // in the output only instead of throwing...
+        output.setException(ex);
         throw ex;
 
       } else if (verify)
@@ -369,6 +393,7 @@
       throw new ApplicationException(ApplicationException.Type.START_ERROR,
           application.getThrowableMsg("error-starting-server", ioe), ioe);
     }
+    return output;
   }
 
   /**
@@ -481,6 +506,8 @@
   {
     private ApplicationException ex;
 
+    private List<String> errors;
+
     private boolean isFinished;
 
     private boolean isFirstLine;
@@ -530,6 +557,16 @@
               {
                 isFinished = true;
               }
+
+              // Collect lines that would seem to indicate all is
+              // not well with the server
+              if (line.indexOf("severity=SEVERE_ERROR") != -1) {
+                if (errors == null) {
+                  errors = new ArrayList<String>();
+                }
+                errors.add(line);
+              }
+
               line = reader.readLine();
             }
           } catch (IOException ioe)
@@ -563,6 +600,10 @@
       return ex;
     }
 
+    public List<String> getErrors() {
+      return errors;
+    }
+
     /**
      * Returns <CODE>true</CODE> if the server starting process finished
      * (successfully or not) and <CODE>false</CODE> otherwise.

--
Gitblit v1.10.0