mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
11.37.2016 d48536f1cf5e4b6714122fc0d85a5e77bf731346
OPENDJ-2730 Fix upgrade on case insensitive file systems

Chris spotted that since ed3930d, the upgrade removes opendj.jar and
opendj_*.jar from case insensitive file systems (case preserving fs are not impacted).
This is caused by the "cleanup lib directory" upgrade task which wants to delete old OpenDJ
camel case jars which have been overridden by "valid" lower case jars on
case insensitive/preserving file systems.
On case preverving file systems, the delete fails.
On case insensitive file systems, it works.
This commit fixes the issue by checking whether the file system is case
sensitive before removing old OpenDJ[_*].jar jars.
The fix does not concern OpenDJ[-*].jar jars because the have to be
removed anyway (see OPENDJ-2692).
4 files modified
91 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java 41 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeCli.java 2 ●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java 46 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/messages/org/opends/messages/tool.properties 2 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java
@@ -56,21 +56,18 @@
  private static LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** Upgrade supports version from 2.4.5. */
  private static BuildVersion UPGRADESUPPORTSVERSIONFROM = BuildVersion.valueOf("2.4.5.0000");
  private static BuildVersion UPGRADE_SUPPORTS_VERSION_FROM = BuildVersion.valueOf("2.4.5.0000");
  /** The success exit code value. */
  static final int EXIT_CODE_SUCCESS = 0;
  /** The error exit code value. */
  static final int EXIT_CODE_ERROR = 1;
  /**
   * The exit code value that will be used if upgrade requires manual
   * intervention.
   */
  static final int EXIT_CODE_MANUAL_INTERVENTION = 2;
  /** If the upgrade contains some post upgrade tasks to do. */
  static boolean hasPostUpgradeTask;
  private static boolean hasPostUpgradeTask;
  /** If the upgrade script should exit with error code (useful for warnings) */
  private static boolean exitWithErrorCode;
  /** Developers should register upgrade tasks below. */
  private static final NavigableMap<BuildVersion, List<UpgradeTask>> TASKS = new TreeMap<>();
@@ -863,10 +860,10 @@
    }
    // The upgrade only supports version >= 2.4.5.
    if (context.getFromVersion().compareTo(UPGRADESUPPORTSVERSIONFROM) < 0)
    if (context.getFromVersion().compareTo(UPGRADE_SUPPORTS_VERSION_FROM) < 0)
    {
      final LocalizableMessage message =
          INFO_UPGRADE_VERSION_IS_NOT_SUPPORTED.get(UPGRADESUPPORTSVERSIONFROM, UPGRADESUPPORTSVERSIONFROM);
          INFO_UPGRADE_VERSION_IS_NOT_SUPPORTED.get(UPGRADE_SUPPORTS_VERSION_FROM, UPGRADE_SUPPORTS_VERSION_FROM);
      context.notify(message, NOTICE_CALLBACK);
      throw new ClientException(ReturnCode.ERROR_UNEXPECTED, message);
    }
@@ -970,25 +967,25 @@
    }
  }
  /**
   * Returns {@code true} if the current upgrade contains post upgrade tasks.
   *
   * @return {@code true} if the current upgrade contains post upgrade tasks.
   */
  static boolean hasPostUpgradeTask()
  static void needToRunPostUpgradePhase()
  {
    return hasPostUpgradeTask;
    Upgrade.hasPostUpgradeTask = true;
  }
  /** This method should be used when the upgrade tool has issued a warning. */
  static void needToExitWithErrorCode()
  {
    Upgrade.exitWithErrorCode = true;
  }
  /**
   * Sets {@code true} if the current upgrade contains post upgrade tasks.
   * {@code true} if the upgrade succeeded.
   *
   * @param hasPostUpgradeTask
   *          {@code true} if the current upgrade contains post upgrade tasks.
   * @return {@code true} if the upgrade succeeded.
   */
  static void setHasPostUpgradeTask(boolean hasPostUpgradeTask)
  static boolean isSuccess()
  {
    Upgrade.hasPostUpgradeTask = hasPostUpgradeTask;
    return !exitWithErrorCode;
  }
  /** Prevent instantiation. */
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeCli.java
@@ -330,7 +330,7 @@
      return EXIT_CODE_ERROR;
    }
    return EXIT_CODE_SUCCESS;
    return Upgrade.isSuccess() ? EXIT_CODE_SUCCESS : EXIT_CODE_ERROR;
  }
  /** {@inheritDoc} */
opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -563,7 +563,7 @@
      @Override
      public void prepare(UpgradeContext context) throws ClientException
      {
        Upgrade.setHasPostUpgradeTask(true);
        Upgrade.needToRunPostUpgradePhase();
        // Requires answer from the user.
        isATaskToPerform = context.confirmYN(summary, NO) == YES;
        isRebuildAllIndexesIsPresent = true;
@@ -618,7 +618,7 @@
      @Override
      public void prepare(UpgradeContext context) throws ClientException
      {
        Upgrade.setHasPostUpgradeTask(true);
        Upgrade.needToRunPostUpgradePhase();
        // Requires answer from the user.
        isATaskToPerform = context.confirmYN(summary, NO) == YES;
      }
@@ -1059,7 +1059,7 @@
          {
            while (jeBackends.hasNext())
            {
              Upgrade.setHasPostUpgradeTask(true);
              Upgrade.needToRunPostUpgradePhase();
              reimportRequired = true;
              Entry jeBackend = jeBackends.readEntry();
@@ -1322,6 +1322,7 @@
  {
    return new AbstractUpgradeTask()
    {
      @Override
      public void perform(final UpgradeContext context) throws ClientException
      {
@@ -1329,19 +1330,30 @@
            INFORMATION, INFO_UPGRADE_TASK_REMOVE_OLD_JARS.get(), 0);
        context.notifyProgress(pnc);
        final boolean fileSystemIsCaseSensitive = fileSystemIsCaseSensitive(context);
        deleteJarFilesIfFileSystemIsCaseSensitive(fileSystemIsCaseSensitive, "OpenDJ");
        for (final String locale : SUPPORTED_LOCALES_FOR_3_0_0)
        {
          deleteJarFileIfExists("OpenDJ_" + locale);
          deleteJarFileIfExists("OpenDJ-" + locale);
          deleteJarFiles("OpenDJ-" + locale);
          deleteJarFilesIfFileSystemIsCaseSensitive(fileSystemIsCaseSensitive, "OpenDJ_" + locale);
        }
        deleteJarFileIfExists("OpenDJ",
            // Jar files from 2.6.x
            "jackson-core-asl", "jackson-mapper-asl", "json-fluent", "json-resource-servlet",
        deleteJarFiles("jackson-core-asl", "jackson-mapper-asl", "json-fluent", "json-resource-servlet",
            "mail", "opendj-ldap-sdk", "opendj-rest2ldap-servlet", "opendj-server2x-adapter");
        context.notifyProgress(pnc.setProgress(100));
      }
      private void deleteJarFileIfExists(final String... jarFileNames)
      private void deleteJarFilesIfFileSystemIsCaseSensitive(
          final boolean fileSystemIsCaseSensitive, final String... jarFileNames)
      {
        if (fileSystemIsCaseSensitive)
        {
          deleteJarFiles(jarFileNames);
        }
      }
      private void deleteJarFiles(final String... jarFileNames)
      {
        for (final String jarFileName : jarFileNames)
        {
@@ -1352,6 +1364,24 @@
          }
        }
      }
      /** Used to know if we have to remove old "camel case" OpenDJ[_]*.jar(see OPENDJ-2692). */
      private boolean fileSystemIsCaseSensitive(final UpgradeContext context) throws ClientException
      {
        final File openDJCamelCaseJar = new File(libDirectory, "OpenDJ.jar");
        try
        {
          // getCanonicalPath() will return the new "opendj.jar" on case insensitive file systems
          return openDJCamelCaseJar.getCanonicalPath().equals(openDJCamelCaseJar.getAbsolutePath());
        }
        catch (final IOException unlikely)
        {
          // Warn the user that he may have some old camel case jars to remove
          context.notify(INFO_UPGRADE_TASK_UNABLE_TO_REMOVE_OLD_JARS.get());
          Upgrade.needToExitWithErrorCode();
          return false;
        }
      }
    };
  }
opendj-server-legacy/src/messages/org/opends/messages/tool.properties
@@ -2623,6 +2623,8 @@
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.
INFO_LDAP_CONN_PROMPT_SECURITY_LDAP=LDAP
INFO_LDAP_CONN_PROMPT_SECURITY_USE_SSL=LDAP with SSL