opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java
@@ -21,7 +21,7 @@ * CDDL HEADER END * * * Portions Copyright 2013-2015 ForgeRock AS * Portions Copyright 2013-2016 ForgeRock AS */ package org.opends.server.tools.upgrade; @@ -38,7 +38,6 @@ import org.forgerock.i18n.slf4j.LocalizedLogger; import org.opends.server.core.LockFileManager; import org.opends.server.util.BuildVersion; import org.opends.server.util.StaticUtils; import com.forgerock.opendj.cli.ClientException; import com.forgerock.opendj.cli.ReturnCode; @@ -413,6 +412,11 @@ public boolean shouldPerformUpgradeTasks(UpgradeContext context) throws ClientException { return !isOEMVersion(); } @Override public String toString() { return "!isOEMVersion"; } }, migrateLocalDBBackendsToJEBackends(), modifyConfigEntry(INFO_UPGRADE_TASK_MIGRATE_JE_SUMMARY_2.get(), @@ -460,6 +464,11 @@ public boolean shouldPerformUpgradeTasks(UpgradeContext context) throws ClientException { return isOEMVersion(); } @Override public String toString() { return "isOEMVersion"; } }, deleteFile(new File(libDirectory, "je.jar")), requireConfirmation(INFO_UPGRADE_TASK_LOCAL_DB_TO_PDB_1_SUMMARY.get(), NO, @@ -809,11 +818,9 @@ private static void changeBuildInfoVersion(final UpgradeContext context) throws ClientException { FileWriter buildInfo = null; try File buildInfoFile = new File(UpgradeUtils.configDirectory, Installation.BUILDINFO_RELATIVE_PATH); try (FileWriter buildInfo = new FileWriter(buildInfoFile, false)) { buildInfo = new FileWriter(new File(UpgradeUtils.configDirectory, Installation.BUILDINFO_RELATIVE_PATH), false); // Write the new version buildInfo.write(context.getToVersion().toString()); @@ -826,10 +833,6 @@ context.notify(message, ERROR_CALLBACK); throw new ClientException(ReturnCode.ERROR_UNEXPECTED, message); } finally { StaticUtils.close(buildInfo); } } private static void checkLicence(final UpgradeContext context) @@ -896,9 +899,9 @@ } } } catch (SecurityException se) catch (SecurityException e) { logger.debug(LocalizableMessage.raw(se.getMessage())); logger.debug(LocalizableMessage.raw(e.getMessage()), e); } } opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeContext.java
@@ -21,13 +21,10 @@ * CDDL HEADER END * * * Portions Copyright 2013-2014 ForgeRock AS * Portions Copyright 2013-2016 ForgeRock AS */ package org.opends.server.tools.upgrade; import static org.opends.messages.ToolMessages.*; import javax.security.auth.callback.Callback; @@ -36,14 +33,11 @@ import javax.security.auth.callback.TextOutputCallback; import org.forgerock.i18n.LocalizableMessage; import com.forgerock.opendj.cli.ClientException; import com.forgerock.opendj.cli.ReturnCode; import org.opends.server.types.InitializationException; import org.opends.server.util.BuildVersion; import com.forgerock.opendj.cli.ClientException; import com.forgerock.opendj.cli.ReturnCode; /** * Context information which is passed to upgrade tasks. This might include @@ -51,44 +45,23 @@ */ public final class UpgradeContext { /** * The version we upgrade from. */ /** The version we upgrade from. */ private final BuildVersion fromVersion; /** * The version we want to upgrade to. */ /** The version we want to upgrade to. */ private final BuildVersion toVersion; /** * The call-back handler for interacting with the upgrade application. */ /** The call-back handler for interacting with the upgrade application. */ private final CallbackHandler handler; /** * If ignore errors is enabled. */ /** If ignore errors is enabled. */ private boolean isIgnoreErrorsMode; /** * If accept license is enabled. */ /** If accept license is enabled. */ private boolean isAcceptLicenseMode; /** * If interactive mode is enabled. */ /** If interactive mode is enabled. */ private boolean isInteractiveMode; /** * If force upgrade is enabled. */ /** If force upgrade is enabled. */ private boolean isForceUpgradeMode; /** * Creates a new upgrade context for upgrading from the instance version (as * obtained from config/buildinfo) to the binary version. @@ -104,8 +77,6 @@ this(BuildVersion.instanceVersion(), BuildVersion.binaryVersion(), handler); } /** * Constructor for the upgrade context. * @@ -125,8 +96,6 @@ this.handler = handler; } /** * Returns the old version. * @@ -137,8 +106,6 @@ return fromVersion; } /** * Returns the new version. * @@ -149,8 +116,6 @@ return toVersion; } /** * Returns the ignore error mode. * @@ -161,8 +126,6 @@ return isIgnoreErrorsMode; } /** * Sets the ignore errors mode. * @@ -176,8 +139,6 @@ return this; } /** * Returns the accept license mode. * @@ -188,8 +149,6 @@ return isAcceptLicenseMode; } /** * Sets the accept license mode. * @@ -203,8 +162,6 @@ return this; } /** * Returns the callback handler. * @@ -215,8 +172,6 @@ return handler; } /** * Returns the status of the interactive mode. * @@ -227,8 +182,6 @@ return isInteractiveMode; } /** * Sets the interactive mode. * @@ -242,8 +195,6 @@ return this; } /** * Returns the status of the force upgrade mode. * @@ -254,8 +205,6 @@ return isForceUpgradeMode; } /** * Sets the force upgrade mode. * @@ -269,8 +218,6 @@ return this; } /** * Sends notification message to the application via the call-back handler. * @@ -293,8 +240,6 @@ } } /** * Sends notification message to the application via the call-back handler * containing specific sub type message. @@ -320,8 +265,6 @@ } } /** * Displays a progress callback. * @@ -344,8 +287,6 @@ } } /** * Asks a confirmation to the user. Answer is yes or no. * @@ -374,4 +315,10 @@ } return confirmYNCallback.getSelectedIndex(); } @Override public String toString() { return "Upgrade from " + fromVersion + " to " + toVersion; } } opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -21,7 +21,7 @@ * CDDL HEADER END * * * Portions Copyright 2013-2015 ForgeRock AS * Portions Copyright 2013-2016 ForgeRock AS */ package org.opends.server.tools.upgrade; @@ -57,6 +57,7 @@ import org.forgerock.opendj.ldap.requests.Requests; import org.forgerock.opendj.ldap.requests.SearchRequest; import org.forgerock.opendj.ldif.EntryReader; import org.forgerock.util.Utils; import org.opends.server.backends.pluggable.spi.TreeName; import org.opends.server.tools.JavaPropertiesTool; import org.opends.server.tools.RebuildIndex; @@ -72,9 +73,7 @@ import com.sleepycat.je.Transaction; import com.sleepycat.je.TransactionConfig; /** * Factory methods for create new upgrade tasks. */ /** Factory methods for create new upgrade tasks. */ public final class UpgradeTasks { /** Logger for the upgrade. */ @@ -151,6 +150,12 @@ schemaFileTemplate.getName(), e.getMessage()), pnc); } } @Override public String toString() { return INFO_UPGRADE_TASK_REPLACE_SCHEMA_FILE.get(fileName).toString(); } }; } @@ -190,6 +195,12 @@ configFile.getName(), e.getMessage()), pnc); } } @Override public String toString() { return INFO_UPGRADE_TASK_ADD_CONFIG_FILE.get(fileName).toString(); } }; } @@ -287,6 +298,12 @@ schemaFileTemplate.getName(), e.getMessage()), pnc); } } @Override public String toString() { return String.valueOf(summary); } }; } @@ -348,6 +365,12 @@ schemaFileTemplate.getName(), e.getMessage()), pnc); } } @Override public String toString() { return String.valueOf(summary); } }; } @@ -378,6 +401,12 @@ throw new ClientException(ReturnCode.ERROR_UNEXPECTED, ERR_UPGRADE_DSJAVAPROPERTIES_FAILED.get()); } } @Override public String toString() { return String.valueOf(summary); } }; } @@ -407,6 +436,12 @@ { return context.getFromVersion().compareTo(version) >= 0; } @Override public String toString() { return "Regression in version \"" + versionString + "\""; } }, tasks); } @@ -431,13 +466,19 @@ { return context.confirmYN(INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM.get(message), defaultResponse) == YES; } @Override public String toString() { return INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM.get(message).toString(); } }, tasks); } /** Determines whether conditional tasks should be performed. */ interface UpgradeCondition { boolean shouldPerformUpgradeTasks(final UpgradeContext context) throws ClientException; boolean shouldPerformUpgradeTasks(UpgradeContext context) throws ClientException; } static UpgradeTask conditionalUpgradeTasks(final UpgradeCondition condition, final UpgradeTask... tasks) @@ -499,6 +540,16 @@ } } @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append(condition).append(" = ").append(shouldPerformUpgradeTasks).append('\n'); sb.append('['); Utils.joinAsString(sb, "\n", (Object[]) tasks); sb.append(']'); return sb.toString(); } }; } @@ -513,7 +564,7 @@ { return new AbstractUpgradeTask() { private boolean isATaskToPerform = false; private boolean isATaskToPerform; @Override public void prepare(UpgradeContext context) throws ClientException @@ -539,11 +590,15 @@ { context.notify(INFO_UPGRADE_ALL_REBUILD_INDEX_DECLINED.get(), TextOutputCallback.WARNING); } @Override public String toString() { return String.valueOf(summary); } }; } /** * Creates a rebuild index task for a given single index. As this task is * possibly lengthy, it's considered as a post upgrade task. This task is not @@ -565,7 +620,7 @@ { return new AbstractUpgradeTask() { private boolean isATaskToPerform = false; private boolean isATaskToPerform; @Override public void prepare(UpgradeContext context) throws ClientException @@ -596,6 +651,12 @@ context.notify(INFO_UPGRADE_REBUILD_INDEX_DECLINED.get(index), TextOutputCallback.WARNING); } } @Override public String toString() { return String.valueOf(summary); } }; } @@ -653,8 +714,14 @@ * upgrade log file. */ final List<String> backends = UpgradeUtils.getIndexedBackendsFromConfig(); if (!backends.isEmpty()) if (backends.isEmpty()) { logger.debug(INFO_UPGRADE_REBUILD_INDEX_NO_BACKEND_FOUND); logger.debug(INFO_UPGRADE_REBUILD_INDEX_DECLINED, indexesToRebuild); context.notifyProgress(pnc.setProgress(100)); return; } for (final String be : backends) { args.add("-b"); @@ -685,12 +752,11 @@ throw new ClientException(ReturnCode.ERROR_UNEXPECTED, msg); } } else @Override public String toString() { logger.debug(INFO_UPGRADE_REBUILD_INDEX_NO_BACKEND_FOUND); logger.debug(INFO_UPGRADE_REBUILD_INDEX_DECLINED, indexesToRebuild); context.notifyProgress(pnc.setProgress(100)); } return "Post upgrade rebuild indexes task"; } }; } @@ -719,7 +785,7 @@ try { String toRevision = String.valueOf(context.getToVersion().getRevision()); String toRevision = context.getToVersion().getRevision(); updateConfigUpgradeSchemaFile(configSchemaDirectory, toRevision); context.notifyProgress(pnc.setProgress(100)); @@ -729,6 +795,12 @@ manageTaskException(context, ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER.get(ex.getMessage()), pnc); } } @Override public String toString() { return INFO_UPGRADE_TASK_REFRESH_UPGRADE_DIRECTORY.get().toString(); } }; } @@ -778,6 +850,12 @@ } } } @Override public String toString() { return String.valueOf(summary); } }; } @@ -808,6 +886,12 @@ manageTaskException(context, LocalizableMessage.raw(e.getMessage()), pnc); } } @Override public String toString() { return INFO_UPGRADE_TASK_DELETE_FILE.get(file).toString(); } }; } @@ -954,6 +1038,12 @@ builder.append("_id2entry"); return builder.toString(); } @Override public String toString() { return INFO_UPGRADE_TASK_MIGRATE_JE_SUMMARY_1.get("%s").toString(); } }; } @@ -965,7 +1055,7 @@ { return new AbstractUpgradeTask() { private boolean reimportRequired = false; private boolean reimportRequired; @Override public void perform(UpgradeContext context) throws ClientException @@ -1019,6 +1109,12 @@ context.notify(INFO_UPGRADE_TASK_RENAME_JE_DB_DIR_WARNING.get(), TextOutputCallback.WARNING); } } @Override public String toString() { return INFO_UPGRADE_TASK_RENAME_JE_DB_DIR.get("%s", "%s").toString(); } }; } @@ -1115,6 +1211,12 @@ { performConfigFileUpdate(summary, filter, changeOperationType, context, ldif); } @Override public String toString() { return String.valueOf(summary); } }; } @@ -1212,6 +1314,12 @@ manageTaskException(context, LocalizableMessage.raw(e.getLocalizedMessage()), pnc); } } @Override public String toString() { return INFO_UPGRADE_TASK_DELETE_CHANGELOG_SUMMARY.get(replicationDbDir).toString(); } }; }