From 2155def10e32885ae6f05fa8556bd9099c400f39 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 01 May 2007 21:47:07 +0000
Subject: [PATCH] This code introduces creation of a log file in the system's temporary directory for detailed log messages that can be used by any of the quicksetup applications (install, uninstall, upgrade). Right now logging if fairly meager but we should work on this soon. This work is being done in anticipation of changes that Brian has suggested in reducing the verbosity of the quicksetup applications. The idea is to put the details in the file and omit the messages in the progress panel details area (for instance messages about moving files around).
---
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java | 29 ++++++
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java | 20 +++++
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java | 28 +++++++
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java | 11 ++
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java | 88 ++++++++++++++++++++++
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/resources/Resources.properties | 5
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/ui/GuiApplication.java | 14 +++
7 files changed, 188 insertions(+), 7 deletions(-)
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
index 7966c54..aa40450 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/Launcher.java
@@ -32,6 +32,8 @@
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.util.logging.Logger;
/**
* Responsible for providing initial evaluation of command line arguments
@@ -39,6 +41,8 @@
*/
public abstract class Launcher {
+ static private final Logger LOG = Logger.getLogger(Launcher.class.getName());
+
/** Arguments with which this launcher was invoked. */
protected String[] args;
@@ -107,6 +111,20 @@
}
/**
+ * Creates an internationaized message based on the input key and
+ * properly formatted for the terminal.
+ * @param key for the message in the bundle
+ * @param args String... arguments for the message
+ * @return String message properly formatted for the terminal
+ */
+ protected String getMsg(String key, String... args)
+ {
+ return org.opends.server.util.StaticUtils.wrapText(
+ getI18n().getMsg(key, args),
+ Utils.getCommandLineMaxLineWidth());
+ }
+
+ /**
* Prints a usage message to the terminal and exits
* with exit code QuickSetupCli.USER_DATA_ERROR.
* @param i18nMsg localized user message that will
@@ -240,6 +258,7 @@
printUsage();
} else if (isCli()) {
int exitCode = launchCli(args, createCliApplication());
+ preExit();
System.exit(exitCode);
} else {
willLaunchGui();
@@ -248,12 +267,21 @@
guiLaunchFailed();
exitCode = launchCli(args, createCliApplication());
if (exitCode != 0) {
+ preExit();
System.exit(exitCode);
}
}
}
}
+ private void preExit() {
+ File logFile = QuickSetupLog.getLogFile();
+ if (logFile != null) {
+ System.out.println(getMsg("general-see-for-details",
+ QuickSetupLog.getLogFile().getPath()));
+ }
+ }
+
/**
* This class is used to avoid displaying the error message related to display
* problems that we might have when trying to display the SplashWindow.
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java
index 4ba3e66..3327919 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupCli.java
@@ -69,6 +69,11 @@
*/
static public int BUG = 5;
+ /**
+ * Return code for errors that are non-specified.
+ */
+ static public int UNKNOWN = 100;
+
/** Platform dependent filesystem separator. */
public static String LINE_SEPARATOR = System.getProperty("line.separator");
@@ -152,9 +157,9 @@
returnValue = BUG;
break;
- default:
- throw new IllegalStateException(
- "Unknown ApplicationException type: "+ue.getType());
+ default:
+ returnValue = UNKNOWN;
+ break;
}
}
else
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java
new file mode 100644
index 0000000..2527d63
--- /dev/null
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/QuickSetupLog.java
@@ -0,0 +1,88 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE
+ * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at
+ * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
+ * add the following below this CDDL HEADER, with the fields enclosed
+ * by brackets "[]" replaced with your own identifying information:
+ * Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ *
+ *
+ * Portions Copyright 2007 Sun Microsystems, Inc.
+ */
+
+package org.opends.quicksetup;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.logging.FileHandler;
+import java.util.logging.SimpleFormatter;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import java.util.Date;
+import java.text.DateFormat;
+
+/**
+ * Utilities for setting up QuickSetup application log.
+ */
+public class QuickSetupLog {
+
+ static private File logFile = null;
+
+ /**
+ * Creates a new file handler for writing log messages to the file indicated
+ * by <code>file</code>.
+ * @param file log file to which log messages will be written
+ * @throws IOException if something goes wrong
+ */
+ static public void initLogFileHandler(File file) throws IOException {
+ if (!isInitialized()) {
+ logFile = file;
+ FileHandler fileHandler = new FileHandler(logFile.getCanonicalPath());
+ fileHandler.setFormatter(new SimpleFormatter());
+ Logger logger = Logger.getLogger("org.opends.quicksetup");
+ logger.addHandler(fileHandler);
+ logger.log(Level.INFO, getInitialLogRecord());
+ }
+ }
+
+ /**
+ * Gets the name of the log file.
+ * @return File representing the log file
+ */
+ static public File getLogFile() {
+ return logFile;
+ }
+
+ /**
+ * Indicates whether or not the log file has been initialized.
+ * @return true when the log file has been initialized
+ */
+ static public boolean isInitialized() {
+ return logFile != null;
+ }
+
+ static private String getInitialLogRecord() {
+ StringBuffer sb = new StringBuffer()
+ .append("QuickSetup application launched " +
+ DateFormat.getDateTimeInstance(DateFormat.LONG,
+ DateFormat.LONG).
+ format(new Date()));
+ return sb.toString();
+ }
+
+}
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 89682d0..51e1da0 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
@@ -799,7 +799,7 @@
summary-upgrade-finished-successfully-cli=OpenDS QuickSetup Completed \
Successfully. The OpenDS installation at {0} has now been upgraded \
to version {1}.
-summary-upgrade-finished-with-errors=Upgrade Operation Aborted
+summary-upgrade-finished-with-errors=Upgrade Operation Failed
#
# Progress messages
@@ -982,4 +982,5 @@
upgrade-review-panel-start-server-tooltip=Check this check box if you want to \
start the server once the upgrade has completed
-general-loading=Loading...
\ No newline at end of file
+general-loading=Loading...
+general-see-for-details=See {0} for a detailed log of this operation.
\ No newline at end of file
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 52842d1..09e74db 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
@@ -34,6 +34,7 @@
import javax.swing.*;
import java.awt.event.WindowEvent;
import java.io.IOException;
+import java.io.File;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.logging.Level;
@@ -492,4 +493,17 @@
msg, e);
}
}
+
+ /**
+ * Conditionally notifies listeners of the log file if it
+ * has been initialized.
+ */
+ protected void notifyListenersOfLog() {
+ File logFile = QuickSetupLog.getLogFile();
+ if (logFile != null) {
+ notifyListeners(getMsg("general-see-for-details", logFile.getPath()) +
+ formatter.getLineBreak());
+ }
+ }
+
}
diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
index abd55ed..79b4d1c 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/UpgradeLauncher.java
@@ -30,14 +30,27 @@
import org.opends.quicksetup.Launcher;
import org.opends.quicksetup.CliApplication;
import org.opends.quicksetup.Installation;
+import org.opends.quicksetup.QuickSetupLog;
import org.opends.quicksetup.util.Utils;
+import java.util.logging.Logger;
+import java.io.File;
+
/**
* This class is called by the upgrade and upgrade.bat
* command line utilities to launch an upgrade process.
*/
public class UpgradeLauncher extends Launcher {
+ /** Prefix for log files. */
+ static public final String LOG_FILE_PREFIX = "opends-upgrade-";
+
+ /** Suffix for log files. */
+ static public final String LOG_FILE_SUFFIX = ".log";
+
+ static private final Logger LOG =
+ Logger.getLogger(UpgradeLauncher.class.getName());
+
/**
* The main method which is called by the setup command lines.
*
@@ -46,6 +59,13 @@
* will pass to the org.opends.server.tools.InstallDS class.
*/
public static void main(String[] args) {
+ try {
+ QuickSetupLog.initLogFileHandler(
+ File.createTempFile(LOG_FILE_PREFIX, LOG_FILE_SUFFIX));
+ } catch (Throwable t) {
+ System.err.println("Unable to initialize log");
+ t.printStackTrace();
+ }
new UpgradeLauncher(args).launch();
}
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 5aef1df..bf2b4ac 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
@@ -227,6 +227,15 @@
* Creates a default instance.
*/
public Upgrader() {
+ try {
+ if (!QuickSetupLog.isInitialized())
+ QuickSetupLog.initLogFileHandler(
+ File.createTempFile(
+ UpgradeLauncher.LOG_FILE_PREFIX,
+ UpgradeLauncher.LOG_FILE_SUFFIX));
+ } catch (IOException e) {
+ System.err.println("Failed to initialize log");
+ }
if (Utils.isWebStart()) {
initLoader();
}
@@ -615,7 +624,17 @@
Utils.getPath(buildZip), null);
}
}
- getRemoteBuildManager().download(buildToDownload, buildZip);
+ LOG.log(Level.FINE, "Preparing to download " +
+ buildToDownload.getUrl() +
+ " to " + Utils.getPath(buildZip));
+ try {
+ getRemoteBuildManager().download(buildToDownload, buildZip);
+ } catch (IOException e) {
+ throw new ApplicationException(
+ ApplicationException.Type.APPLICATION,
+ "Failed to download build package .zip " +
+ "file from " + buildToDownload.getUrl(), e);
+ }
notifyListeners(formatter.getFormattedDone() +
formatter.getLineBreak());
} catch (ApplicationException e) {
@@ -812,6 +831,8 @@
if (runException == null) {
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
@@ -831,6 +852,8 @@
} else {
if (!Utils.isCli()) {
notifyListeners(formatter.getFormattedError(runException, true));
+ notifyListenersOfLog();
+ notifyListeners(null);
setCurrentProgressStep(UpgradeProgressStep.FINISHED_WITH_ERRORS);
} else {
runException.printStackTrace();
@@ -865,7 +888,9 @@
control.stopServer();
} catch (Exception e) {
throw new ApplicationException(ApplicationException.Type.APPLICATION,
- "Server health check failed", e);
+ "Server health check failed. Make sure the server is capable " +
+ "of starting without errors before running the upgrade " +
+ "tool.", e);
}
}
--
Gitblit v1.10.0