| | |
| | | |
| | | package org.opends.server.tools.upgrade; |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.tools.upgrade.FormattedNotificationCallback.*; |
| | | import static org.opends.server.tools.upgrade.UpgradeTasks.*; |
| | |
| | | import org.opends.server.util.BuildVersion; |
| | | import org.opends.server.util.StaticUtils; |
| | | |
| | | |
| | | |
| | | /** |
| | | * This class contains the table of upgrade tasks that need performing when |
| | | * upgrading from one version to another. |
| | |
| | | // @formatter:on |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Returns a list containing all the tasks which are required in order to |
| | | * upgrade from {@code fromVersion} to {@code toVersion}. |
| | |
| | | isVersionCanBeUpdated(context); |
| | | |
| | | // Server must be offline. |
| | | checkIfServerIsRunning(); |
| | | checkIfServerIsRunning(context); |
| | | |
| | | context.notify( INFO_UPGRADE_TITLE.get(), TITLE_CALLBACK); |
| | | context.notify( INFO_UPGRADE_SUMMARY.get(context.getFromVersion() |
| | | .toString(), context.getToVersion().toString()), NOTICE_CALLBACK); |
| | | context.notify( INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS |
| | | .get(UpgradeUtils.getInstallationPath() + File.separator |
| | | + UpgradeLog.UPGRADELOGNAME), NOTICE_CALLBACK); |
| | | context.notify(INFO_UPGRADE_TITLE.get(), TITLE_CALLBACK); |
| | | context.notify( |
| | | INFO_UPGRADE_SUMMARY.get(context.getFromVersion().toString(), context |
| | | .getToVersion().toString()), NOTICE_CALLBACK); |
| | | context.notify(INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS.get(UpgradeUtils |
| | | .getInstallationPath() |
| | | + File.separator + UpgradeLog.UPGRADELOGNAME), NOTICE_CALLBACK); |
| | | |
| | | // Checks License. |
| | | checkLicence(context); |
| | |
| | | /* |
| | | * Get the list of required upgrade tasks. |
| | | */ |
| | | final List<UpgradeTask> tasks = getUpgradeTasks(context.getFromVersion(), |
| | | context.getToVersion()); |
| | | final List<UpgradeTask> tasks = |
| | | getUpgradeTasks(context.getFromVersion(), context.getToVersion()); |
| | | if (tasks.isEmpty()) |
| | | { |
| | | changeBuildInfoVersion(context); |
| | |
| | | } |
| | | |
| | | /* |
| | | * Verify tasks requirements. |
| | | * E.g. if a task requires mandatory user interaction |
| | | * and the application is non-interactive then, the process |
| | | * may abort immediately. |
| | | * Verify tasks requirements. E.g. if a task requires mandatory user |
| | | * interaction and the application is non-interactive then, the process may |
| | | * abort immediately. |
| | | */ |
| | | for (final UpgradeTask task : tasks) |
| | | { |
| | |
| | | } |
| | | |
| | | // Starts upgrade |
| | | final int userResponse = context.confirmYN( |
| | | INFO_UPGRADE_DISPLAY_CONFIRM_START.get(), ConfirmationCallback.YES); |
| | | final int userResponse = |
| | | context.confirmYN(INFO_UPGRADE_DISPLAY_CONFIRM_START.get(), |
| | | ConfirmationCallback.YES); |
| | | if (userResponse == ConfirmationCallback.NO) |
| | | { |
| | | throw new ClientException(EXIT_CODE_ERROR, |
| | | INFO_UPGRADE_ABORTED_BY_USER.get()); |
| | | final Message message = INFO_UPGRADE_ABORTED_BY_USER.get(); |
| | | context.notify(message, WARNING); |
| | | throw new ClientException(EXIT_CODE_ERROR, message); |
| | | } |
| | | |
| | | try |
| | |
| | | /* |
| | | * Perform the upgrade tasks. |
| | | */ |
| | | context.notify(INFO_UPGRADE_PERFORMING_TASKS.get(), |
| | | TITLE_CALLBACK); |
| | | context.notify(INFO_UPGRADE_PERFORMING_TASKS.get(), TITLE_CALLBACK); |
| | | for (final UpgradeTask task : tasks) |
| | | { |
| | | task.perform(context); |
| | |
| | | if (UpgradeTasks.countErrors == 0) |
| | | { |
| | | /* |
| | | * The end of a successful upgrade is marked up with the build info |
| | | * file update and the license, if present, requires the creation of |
| | | * an approval file. |
| | | * The end of a successful upgrade is marked up with the build info file |
| | | * update and the license, if present, requires the creation of an |
| | | * approval file. |
| | | */ |
| | | changeBuildInfoVersion(context); |
| | | |
| | |
| | | } |
| | | else |
| | | { |
| | | context.notify( |
| | | ERR_UPGRADE_FAILS.get(UpgradeTasks.countErrors), TITLE_CALLBACK); |
| | | context.notify(ERR_UPGRADE_FAILS.get(UpgradeTasks.countErrors), |
| | | TITLE_CALLBACK); |
| | | } |
| | | |
| | | /* |
| | |
| | | } |
| | | catch (final ClientException e) |
| | | { |
| | | LOG.log(Level.SEVERE, e.getMessage()); |
| | | context.notify( e.getMessageObject()); |
| | | context.notify(e.getMessageObject(), ERROR_CALLBACK); |
| | | throw e; |
| | | } |
| | | catch (final Exception e) |
| | | { |
| | | LOG.log(Level.SEVERE, e.getMessage()); |
| | | context.notify(ERR_UPGRADE_TASKS_FAIL.get(e.getMessage())); |
| | | throw new ClientException(EXIT_CODE_ERROR, Message.raw(e.getMessage())); |
| | | final Message message = ERR_UPGRADE_TASKS_FAIL.get(e.getMessage()); |
| | | context.notify(message, ERROR_CALLBACK); |
| | | throw new ClientException(EXIT_CODE_ERROR, message); |
| | | } |
| | | finally |
| | | { |
| | | context.notify(INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS |
| | | .get(UpgradeUtils.getInstallationPath() + File.separator |
| | | + UpgradeLog.UPGRADELOGNAME), NOTICE_CALLBACK); |
| | | context.notify(INFO_UPGRADE_GENERAL_SEE_FOR_DETAILS.get(UpgradeUtils |
| | | .getInstallationPath() |
| | | + File.separator + UpgradeLog.UPGRADELOGNAME), NOTICE_CALLBACK); |
| | | LOG.log(Level.CONFIG, INFO_UPGRADE_PROCESS_END.get().toString()); |
| | | } |
| | | } |
| | | |
| | | private static void performPostUpgradeTasks(final UpgradeContext context, |
| | | final List<UpgradeTask> tasks) |
| | | throws ClientException |
| | | final List<UpgradeTask> tasks) throws ClientException |
| | | { |
| | | boolean isOk = true; |
| | | for (final UpgradeTask task : tasks) |
| | |
| | | * @throws ClientException |
| | | * An exception is thrown if the server is currently running. |
| | | */ |
| | | private final static void checkIfServerIsRunning() throws ClientException |
| | | private final static void checkIfServerIsRunning(final UpgradeContext context) |
| | | throws ClientException |
| | | { |
| | | final String lockFile = LockFileManager.getServerLockFileName(); |
| | | |
| | |
| | | // running. |
| | | if (!LockFileManager.acquireExclusiveLock(lockFile, failureReason)) |
| | | { |
| | | LOG.log(Level.SEVERE, failureReason.toString()); |
| | | throw new ClientException(EXIT_CODE_ERROR, |
| | | ERR_UPGRADE_REQUIRES_SERVER_OFFLINE.get()); |
| | | final Message message = ERR_UPGRADE_REQUIRES_SERVER_OFFLINE.get(); |
| | | context.notify(message, NOTICE_CALLBACK); |
| | | throw new ClientException(EXIT_CODE_ERROR, message); |
| | | } |
| | | } |
| | | finally |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Checks if the version can be updated. |
| | | * |
| | |
| | | * If the server is already up to date then treat it as a successful |
| | | * upgrade so that upgrade is idempotent. |
| | | */ |
| | | final Message message = ERR_UPGRADE_VERSION_UP_TO_DATE.get(context |
| | | .getToVersion().toString()); |
| | | final Message message = |
| | | ERR_UPGRADE_VERSION_UP_TO_DATE.get(context.getToVersion().toString()); |
| | | context.notify(message, NOTICE_CALLBACK); |
| | | throw new ClientException(EXIT_CODE_SUCCESS, message); |
| | | } |
| | | |
| | | // The upgrade only supports version >= 2.4.5. |
| | | if (context.getFromVersion().compareTo(UPGRADESUPPORTSVERSIONFROM) < 0) |
| | | { |
| | | throw new ClientException(EXIT_CODE_ERROR, |
| | | final Message message = |
| | | INFO_UPGRADE_VERSION_IS_NOT_SUPPORTED.get(UPGRADESUPPORTSVERSIONFROM |
| | | .toString(), UPGRADESUPPORTSVERSIONFROM.toString())); |
| | | .toString(), UPGRADESUPPORTSVERSIONFROM.toString()); |
| | | context.notify(message, NOTICE_CALLBACK); |
| | | throw new ClientException(EXIT_CODE_ERROR, message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Writes the up to date's version number within the build info file. |
| | | * |
| | |
| | | FileWriter buildInfo = null; |
| | | try |
| | | { |
| | | buildInfo = new FileWriter(new File(UpgradeUtils.configDirectory, |
| | | Installation.BUILDINFO_RELATIVE_PATH), false); |
| | | buildInfo = |
| | | new FileWriter(new File(UpgradeUtils.configDirectory, |
| | | Installation.BUILDINFO_RELATIVE_PATH), false); |
| | | |
| | | // Write the new version |
| | | buildInfo.write(context.getToVersion().toString()); |
| | | |
| | | context.notify(INFO_UPGRADE_SUCCESSFUL.get(context |
| | | .getFromVersion().toString(), context.getToVersion().toString()), |
| | | TITLE_CALLBACK); |
| | | context.notify(INFO_UPGRADE_SUCCESSFUL.get(context.getFromVersion() |
| | | .toString(), context.getToVersion().toString()), TITLE_CALLBACK); |
| | | |
| | | } |
| | | catch (IOException e) |
| | | { |
| | | throw new ClientException(EXIT_CODE_ERROR, Message.raw(e.getMessage())); |
| | | final Message message = Message.raw(e.getMessage()); |
| | | context.notify(message, ERROR_CALLBACK); |
| | | throw new ClientException(EXIT_CODE_ERROR, message); |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | private static void checkLicence(final UpgradeContext context) |
| | | throws ClientException |
| | | { |