From 1387e05a497147cd1a320c9651a47f122e942b93 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Mon, 09 Apr 2007 12:24:58 +0000
Subject: [PATCH] historical log for upgrader tool
---
opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java | 81 +++++++++++++++++++++++++++++++++++++---
1 files changed, 74 insertions(+), 7 deletions(-)
diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
index 0fe630e..a6ce096 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -41,10 +41,7 @@
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.io.IOException;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileFilter;
+import java.io.*;
import static org.opends.quicksetup.Installation.*;
@@ -154,7 +151,7 @@
DATABASES_PATH_RELATIVE, // db
LOGS_PATH_RELATIVE, // logs
LOCKS_PATH_RELATIVE, // locks
- HISTORY_PATH_RELATIVE // history; TODO: should we do this?
+ HISTORY_PATH_RELATIVE // history
};
private ProgressStep currentProgressStep = UpgradeProgressStep.NOT_STARTED;
@@ -171,6 +168,11 @@
/** Directory where backup is kept in case the upgrade needs reversion. */
private File backupDirectory = null;
+ /** ID that uniquely identifieds this invocation of the Upgrader in the
+ * historical logs.
+ */
+ private Long historicalOperationId;
+
/**
* {@inheritDoc}
*/
@@ -317,11 +319,17 @@
// Reset exception just in case this application is rerun
// for some reason
runException = null;
+ Integer fromVersion = null;
+ Integer toVersion = null;
try {
try {
setCurrentProgressStep(UpgradeProgressStep.INITIALIZING);
initialize();
+ fromVersion = getStagedInstallation().getSvnRev();
+ toVersion = getInstallation().getSvnRev();
+ this.historicalOperationId =
+ writeInitialHistoricalRecord(fromVersion, toVersion);
} catch (ApplicationException e) {
LOG.log(Level.INFO, "error initializing upgrader", e);
throw e;
@@ -390,8 +398,8 @@
// sleepFor1();
// setCurrentProgressStep(UpgradeProgressStep.VERIFYING);
// sleepFor1();
-// setCurrentProgressStep(UpgradeProgressStep.RECORDING_HISTORY);
-// sleepFor1();
+
+
} catch (ApplicationException ae) {
this.runException = ae;
@@ -404,6 +412,23 @@
try {
setCurrentProgressStep(UpgradeProgressStep.CLEANUP);
cleanup();
+
+ // Write a record in the log file indicating success/failure
+ setCurrentProgressStep(UpgradeProgressStep.RECORDING_HISTORY);
+ HistoricalRecord.Status status;
+ String note = null;
+ if (runException == null) {
+ status = HistoricalRecord.Status.SUCCESS;
+ } else {
+ status = HistoricalRecord.Status.FAILURE;
+ note = runException.getLocalizedMessage();
+ }
+ writeHistoricalRecord(historicalOperationId,
+ fromVersion,
+ toVersion,
+ status,
+ note);
+
} catch (ApplicationException e) {
System.err.print("error cleaning up after upgrade: " +
e.getLocalizedMessage());
@@ -419,6 +444,48 @@
}
+ private Long writeInitialHistoricalRecord(
+ Integer fromVersion,
+ Integer toVersion)
+ throws ApplicationException
+ {
+ Long id;
+ try {
+ HistoricalLog log =
+ new HistoricalLog(getInstallation().getHistoryLogFile());
+ id = log.append(fromVersion, toVersion,
+ HistoricalRecord.Status.STARTED, null);
+ } catch (IOException e) {
+ throw ApplicationException.createFileSystemException(
+ "error logging operation", e);
+ }
+ return id;
+ }
+
+ private void writeHistoricalRecord(
+ Long id,
+ Integer from,
+ Integer to,
+ HistoricalRecord.Status status,
+ String note)
+ throws ApplicationException {
+ try {
+ HistoricalLog log =
+ new HistoricalLog(getInstallation().getHistoryLogFile());
+ log.append(id, from, to, status, note);
+
+ // FOR TESTING
+ List<HistoricalRecord> records = log.getRecords();
+ for(HistoricalRecord record : records) {
+ System.out.println(record);
+ }
+
+ } catch (IOException e) {
+ throw ApplicationException.createFileSystemException(
+ "error logging operation", e);
+ }
+ }
+
private void upgradeComponents() throws ApplicationException {
try {
File stageDir = getStageDirectory();
--
Gitblit v1.10.0