From 0d1119f92ba0455deeeaf7f92d4905f77a18da53 Mon Sep 17 00:00:00 2001
From: Jean-Noël Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Fri, 17 Jun 2016 08:42:29 +0000
Subject: [PATCH] Moved exception handling of upgrade tasks to a higher level
---
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java | 9 ++
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java | 61 +++++++++++--------
opendj-server-legacy/src/messages/org/opends/messages/tool.properties | 52 ++++++++--------
3 files changed, 69 insertions(+), 53 deletions(-)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java
index 68cddea..f79be75 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java
@@ -771,7 +771,14 @@
context.notify(INFO_UPGRADE_PERFORMING_TASKS.get(), TITLE_CALLBACK);
for (final UpgradeTask task : tasks)
{
- task.perform(context);
+ try
+ {
+ task.perform(context);
+ }
+ catch (ClientException e)
+ {
+ handleClientException(context, e);
+ }
}
if (UpgradeTasks.countErrors == 0)
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
index 43dda75..a68875c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -139,8 +139,8 @@
}
catch (final IOException e)
{
- manageTaskException(context, ERR_UPGRADE_COPYSCHEMA_FAILS.get(
- schemaFileTemplate.getName(), e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, ERR_UPGRADE_COPYSCHEMA_FAILS.get(
+ schemaFileTemplate.getName(), e.getMessage()));
}
}
@@ -184,8 +184,8 @@
}
catch (final IOException e)
{
- manageTaskException(context, ERR_UPGRADE_ADD_CONFIG_FILE_FAILS.get(
- configFile.getName(), e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, ERR_UPGRADE_ADD_CONFIG_FILE_FAILS.get(
+ configFile.getName(), e.getMessage()));
}
}
@@ -276,14 +276,13 @@
try
{
final int changeCount = updateSchemaFile(schemaFileTemplate, pathDestination, attributeOids, null);
-
displayChangeCount(pathDestination, changeCount);
context.notifyProgress(pnc.setProgress(100));
}
catch (final IOException | IllegalStateException e)
{
- manageTaskException(context, ERR_UPGRADE_ADDATTRIBUTE_FAILS.get(
- schemaFileTemplate.getName(), e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, ERR_UPGRADE_ADDATTRIBUTE_FAILS.get(
+ schemaFileTemplate.getName(), e.getMessage()));
}
}
@@ -332,19 +331,18 @@
try
{
final int changeCount = updateSchemaFile(schemaFileTemplate, pathDestination, null, objectClassesOids);
-
displayChangeCount(pathDestination, changeCount);
context.notifyProgress(pnc.setProgress(100));
}
catch (final IOException e)
{
- manageTaskException(context, ERR_UPGRADE_ADDOBJECTCLASS_FAILS.get(
- schemaFileTemplate.getName(), e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, ERR_UPGRADE_ADDOBJECTCLASS_FAILS.get(
+ schemaFileTemplate.getName(), e.getMessage()));
}
catch (final IllegalStateException e)
{
- manageTaskException(context, ERR_UPGRADE_ADDATTRIBUTE_FAILS.get(
- schemaFileTemplate.getName(), e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, ERR_UPGRADE_ADDATTRIBUTE_FAILS.get(
+ schemaFileTemplate.getName(), e.getMessage()));
}
}
@@ -489,7 +487,14 @@
{
for (UpgradeTask task : tasks)
{
- task.perform(context);
+ try
+ {
+ task.perform(context);
+ }
+ catch (ClientException e)
+ {
+ handleClientException(context, e);
+ }
}
}
}
@@ -510,7 +515,7 @@
}
catch (ClientException e)
{
- logger.error(LocalizableMessage.raw(e.getMessage()));
+ logger.error(e.getMessageObject());
isOk = false;
}
}
@@ -763,7 +768,7 @@
}
catch (final Exception ex)
{
- manageTaskException(context, ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER.get(ex.getMessage()), pnc);
+ throw unexpectedException(context, pnc, ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER.get(ex.getMessage()));
}
}
@@ -817,7 +822,7 @@
catch (final Exception ex)
{
LocalizableMessage msg = ERR_UPGRADE_RENAME_SNMP_SECURITY_CONFIG_FILE.get(ex.getMessage());
- manageTaskException(context, msg, pnc);
+ throw unexpectedException(context, pnc, msg);
}
}
}
@@ -854,7 +859,7 @@
}
catch (Exception e)
{
- manageTaskException(context, LocalizableMessage.raw(e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, LocalizableMessage.raw(e.getMessage()));
}
}
@@ -979,7 +984,7 @@
JEHelper.migrateDatabases(backend.envDir, backend.renamedDbs);
context.notifyProgress(pnc.setProgress(100));
} catch (ClientException e) {
- manageTaskException(context, e.getMessageObject(), pnc);
+ throw unexpectedException(context, pnc, e.getMessageObject());
}
} else {
// Skip backends which have been disabled.
@@ -1163,16 +1168,20 @@
}
}
- private static void manageTaskException(final UpgradeContext context,
- final LocalizableMessage message, final ProgressNotificationCallback pnc)
- throws ClientException
+ private static ClientException unexpectedException(final UpgradeContext context,
+ final ProgressNotificationCallback pnc, final LocalizableMessage message) throws ClientException
{
countErrors++;
context.notifyProgress(pnc.setProgress(-100));
- logger.error(message);
+ return new ClientException(ReturnCode.ERROR_UNEXPECTED, message);
+ }
+
+ static void handleClientException(final UpgradeContext context, ClientException e) throws ClientException
+ {
+ logger.error(e.getMessageObject());
if (!context.isIgnoreErrorsMode())
{
- throw new ClientException(ReturnCode.ERROR_UNEXPECTED, message);
+ throw e;
}
}
@@ -1214,7 +1223,7 @@
}
catch (final Exception e)
{
- manageTaskException(context, LocalizableMessage.raw(e.getMessage()), pnc);
+ throw unexpectedException(context, pnc, LocalizableMessage.raw(e.getMessage()));
}
}
@@ -1276,11 +1285,11 @@
}
catch (ClientException e)
{
- manageTaskException(context, e.getMessageObject(), pnc);
+ throw unexpectedException(context, pnc, e.getMessageObject());
}
catch (Exception e)
{
- manageTaskException(context, LocalizableMessage.raw(e.getLocalizedMessage()), pnc);
+ throw unexpectedException(context, pnc, LocalizableMessage.raw(e.getLocalizedMessage()));
}
}
diff --git a/opendj-server-legacy/src/messages/org/opends/messages/tool.properties b/opendj-server-legacy/src/messages/org/opends/messages/tool.properties
index 123bbff..bab1bc2 100644
--- a/opendj-server-legacy/src/messages/org/opends/messages/tool.properties
+++ b/opendj-server-legacy/src/messages/org/opends/messages/tool.properties
@@ -2456,6 +2456,9 @@
ERR_CANNOT_INITIALIZE_BACKENDS_1897=An error occurred while initializing server backends: %s
ERR_CANNOT_INITIALIZE_SERVER_PLUGINS_1898=An error occurred while initializing plugins: %s
ERR_CANNOT_SUBSYSTEM_NOT_INITIALIZED_1899=Subsystem %s should be initialized first
+INFO_INSTALLDS_BACKEND_TYPE_USED_1900=Backend Type: %s
+ERR_STARTTLS_FAILED_1901=StartTLS failed: the connection has been closed without receiving a response. \
+ This may indicate you tried to connect to an LDAPS port instead of the LDAP port, or that the network is down
# Upgrade tasks
INFO_UPGRADE_TASK_6869_SUMMARY_10000=Fixing de-DE collation matching rule OID
@@ -2540,6 +2543,28 @@
INFO_UPGRADE_TASK_BCRYPT_SCHEME_SUMMARY_10056=Adding Bcrypt password storage scheme configuration
INFO_UPGRADE_TASK_CONFIGURATION_BACKEND_NOT_CONFIGURABLE_10057=Removing config entry \
for the non-configurable configuration backend
+INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_1_SUMMARY_10058=WARNING: OpenDJ %s OEM Edition removes support for the \
+ Berkeley JE backend.\n\nThe upgrade tool will reconfigure all JE \
+ backends as PDB backends.\n\nAfter the upgrade the new PDB backend(s) \
+ will be empty. It is therefore very strongly recommended that any data that was \
+ in the JE backends be exported to LDIF so that it can be re-imported once the \
+ upgrade completes
+INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_2_SUMMARY_10059=Reconfiguring local-db backends to PDB backends
+INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_3_SUMMARY_10060=Reconfiguring local-db backend indexes to PDB backend indexes
+INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_4_SUMMARY_10061=Reconfiguring local-db backend VLV indexes to PDB backend VLV indexes
+INFO_UPGRADE_TASK_RENAME_JE_DB_DIR_10062=Renaming local-db backend directory '%s' to '%s'
+INFO_UPGRADE_TASK_RENAME_JE_DB_DIR_WARNING_10063=You must reimport all your data into the PDB \
+ backends in order to have a fully functional server
+INFO_UPGRADE_TASK_REMOVE_MATCHING_RULES_10064=Removing configuration for matching rules
+INFO_UPGRADE_TASK_2716_1_SUMMARY_10065=Adding 'includedAttributes' attribute type to changelog schema
+INFO_UPGRADE_TASK_2716_2_SUMMARY_10066=Updating 'changeLogEntry' object class in changelog schema
+INFO_UPGRADE_TASK_REMOVE_OLD_JARS_10067=Removing old OpenDJ library files
+INFO_UPGRADE_REBUILD_INDEXES_DISTINGUISHED_NAME_10068=OpenDJ 4.0.0 introduced a new format for all equality indexes \
+based on "distinguishedName" attribute type, like "member", "owner", "roleOccupant" and "seeAlso". \
+They all have to be rebuilt if they exist on your server and this could take a long time to proceed. \
+Do you want to launch this process automatically at the end of the upgrade?
+INFO_UPGRADE_TASK_UNABLE_TO_REMOVE_OLD_JARS_10069=Unable to determine whether the file system is case sensitive. \
+ If the file system is case sensitive, then remove OpenDJ.jar and all OpenDJ_*.jar before starting the upgraded server.
# Strings for generated reference documentation.
REF_SHORT_DESC_BACKUP_15000=back up OpenDJ directory data
@@ -2587,7 +2612,7 @@
The supported backend types are %s.
ERR_CONFIGDS_BACKEND_TYPE_UNKNOWN_20010=The backend type '%s' is not recognized. \
The supported backend types are %s.
-ERR_CONFIGDS_SET_BACKEND_TYPE_20011=An error occured while trying to create userRoot \
+ERR_CONFIGDS_SET_BACKEND_TYPE_20011=An error occurred while trying to create userRoot \
backend type %s. Error message: %s
ERR_INSTANCE_NOT_CONFIGURED_20013=The local instance is not configured or you do not \
have permissions to access it.
@@ -2595,31 +2620,6 @@
ERR_FILE_NOT_FULLY_READABLE_20015=Could not completely read file '%s'
SUPPLEMENT_DESCRIPTION_BACKEND_TOOL_SUBCMD_LIST_INDEX_STATUS_20016=\
<xinclude:include href="variablelist-backendstat-index-status.xml" />
-INFO_INSTALLDS_BACKEND_TYPE_USED_20017=Backend Type: %s
-INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_1_SUMMARY_20018=WARNING: OpenDJ %s OEM Edition removes support for the \
- Berkeley JE backend.\n\nThe upgrade tool will reconfigure all JE \
- backends as PDB backends.\n\nAfter the upgrade the new PDB backend(s) \
- will be empty. It is therefore very strongly recommended that any data that was \
- in the JE backends be exported to LDIF so that it can be re-imported once the \
- upgrade completes
-INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_2_SUMMARY_20019=Reconfiguring local-db backends to PDB backends
-INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_3_SUMMARY_20020=Reconfiguring local-db backend indexes to PDB backend indexes
-INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_4_SUMMARY_20021=Reconfiguring local-db backend VLV indexes to PDB backend VLV indexes
-INFO_UPGRADE_TASK_RENAME_JE_DB_DIR_20022=Renaming local-db backend directory '%s' to '%s'
-INFO_UPGRADE_TASK_RENAME_JE_DB_DIR_WARNING_20023=You must reimport all your data into the PDB \
- backends in order to have a fully functional server
-INFO_UPGRADE_TASK_REMOVE_MATCHING_RULES_20024=Removing configuration for matching rules
-INFO_UPGRADE_TASK_2716_1_SUMMARY_20025=Adding 'includedAttributes' attribute type to changelog schema
-INFO_UPGRADE_TASK_2716_2_SUMMARY_20026=Updating 'changeLogEntry' object class in changelog schema
-INFO_UPGRADE_TASK_REMOVE_OLD_JARS_20027=Removing old OpenDJ library files
-INFO_UPGRADE_REBUILD_INDEXES_DISTINGUISHED_NAME_20028=OpenDJ 4.0.0 introduced a new format for all equality indexes \
-based on "distinguishedName" attribute type, like "member", "owner", "roleOccupant" and "seeAlso". \
-They all have to be rebuilt if they exist on your server and this could take a long time to proceed. \
-Do you want to launch this process automatically at the end of the upgrade?
-INFO_UPGRADE_TASK_UNABLE_TO_REMOVE_OLD_JARS_20029=Unable to determine whether the file system is case sensitive. \
- If the file system is case sensitive, then remove OpenDJ.jar and all OpenDJ_*.jar before starting the upgraded server.
-ERR_STARTTLS_FAILED_20030=StartTLS failed: the connection has been closed without receiving a response. \
- This may indicate you tried to connect to an LDAPS port instead of the LDAP port, or that the network is down
INFO_LDAP_CONN_PROMPT_SECURITY_LDAP=LDAP
INFO_LDAP_CONN_PROMPT_SECURITY_USE_SSL=LDAP with SSL
--
Gitblit v1.10.0