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

Violette Roche-Montane
06.02.2013 33664325e75eed3df9054c3c5a4cb6c9c0aa0c62
CR-2260 Implement Rebuild all indexes Upgrade task
- removed start task action (unused)
- removed verifyTaskType function (unused)
- used LDIF.search to retrieve backends (rebuild index works only on 'enabled' backend).
- added rebuild all index task.
- In case of an upgrade where a rebuild all task is present :
. All the other single rebuild indexes are bypass.
. Rebuild-all is launched only if the the user wants to.
6 files modified
256 ■■■■■ changed files
opends/src/messages/messages/tools.properties 7 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java 10 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/Upgrade.java 58 ●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java 14 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java 146 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java 21 ●●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties
@@ -2545,8 +2545,11 @@
upgrade task. Process aborted. Please check log for further details
INFO_UPGRADE_REBUILD_INDEX_DECLINED_1844 =You have to rebuild the '%s' index \
manually to get a fully functional server
SEVERE_ERR_UPGRADE_INVALID_LOG_FILE_1845=Invalid log file %s
INFO_UPGRADE_REBUILD_INDEX_ARGUMENTS_1846=The rebuild index tool arguments are %s
INFO_UPGRADE_ALL_REBUILD_INDEX_DECLINED_1845=You have to rebuild all indexes \
manually to get a fully functional server
SEVERE_ERR_UPGRADE_INVALID_LOG_FILE_1846=Invalid log file %s
INFO_UPGRADE_REBUILD_INDEX_ARGUMENTS_1847=The rebuild index tool arguments are %s
INFO_UPGRADE_REBUILD_ALL_1848=Rebuilding all indexes
# Upgrade tasks
INFO_UPGRADE_TASK_6869_SUMMARY_10000=Fixing de-DE collation matching rule OID
opends/src/server/org/opends/server/tools/upgrade/AbstractUpgradeTask.java
@@ -55,16 +55,6 @@
   * {@inheritDoc}
   */
  @Override
  public void start(UpgradeContext context)
      throws ClientException
  {
    // Nothing to do.
  }
  /**
   * {@inheritDoc}
   */
  @Override
  public void perform(UpgradeContext context) throws ClientException
  {
    // Must be implemented.
opends/src/server/org/opends/server/tools/upgrade/Upgrade.java
@@ -301,6 +301,8 @@
            rebuildSingleIndex(INFO_UPGRADE_TASK_9013_DESCRIPTION.get(),
                "ds-sync-hist")));
    /*
     * All upgrades will refresh the server configuration schema and generate
     * a new upgrade folder.
@@ -384,15 +386,21 @@
     * and the application is non-interactive then, the process
     * may abort immediately.
     */
    verify(context, tasks);
    for (final UpgradeTask task : tasks)
    {
      task.verify(context);
    }
    /*
     * Asking upgrade requirements if needed to user.
     * Let tasks interact with the user in order to obtain user's selection.
     */
    context.notify(INFO_UPGRADE_REQUIREMENTS.get(), TITLE_CALLBACK);
    interact(context, tasks);
    for (final UpgradeTask task : tasks)
    {
      task.interact(context);
    }
    // Starts upgrade.
    // Starts upgrade
    final int userResponse = context.confirmYN(
        INFO_UPGRADE_DISPLAY_CONFIRM_START.get(), ConfirmationCallback.YES);
    if (userResponse == ConfirmationCallback.NO)
@@ -408,18 +416,6 @@
       */
      context.notify(INFO_UPGRADE_PERFORMING_TASKS.get(),
          TITLE_CALLBACK);
      /*
       * Notify each task that the upgrade is about to be started.
       */
      for (final UpgradeTask task : tasks)
      {
        task.start(context);
      }
      /*
       * Perform each task.
       */
      for (final UpgradeTask task : tasks)
      {
        task.perform(context);
@@ -516,36 +512,6 @@
    MANDATORY_TASKS.addAll(Arrays.asList(tasks));
  }
  private static void interact(final UpgradeContext context,
      final List<UpgradeTask> tasks)
      throws ClientException
  {
    /*
     * Let tasks interact with the user in order to obtain user's selection.
     */
    for (final UpgradeTask task : tasks)
    {
      task.interact(context);
    }
  }
  private static void verify(final UpgradeContext context,
      final List<UpgradeTask> tasks)
      throws ClientException
  {
    /*
     * Let tasks interact with CLI to check if command line is correct.
     */
    for (final UpgradeTask task : tasks)
    {
      task.verify(context);
    }
  }
  /**
   * The server must be offline during the upgrade.
   *
opends/src/server/org/opends/server/tools/upgrade/UpgradeTask.java
@@ -74,20 +74,6 @@
      throws ClientException;
  /**
   * Notifies this task that the upgrade is about to start. This method will be
   * invoked before any upgrade tasks have been performed. Most task
   * implementation will not need to do anything.
   *
   * @param context
   *          Context through which tasks can interact with the server
   *          installation.
   * @throws ClientException
   *           If an error occurred while starting the task.
   */
  void start(UpgradeContext context)
      throws ClientException;
  /**
   * Verifies that this upgrade task can be completed or not.
   *
   * @param context
opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -28,8 +28,6 @@
package org.opends.server.tools.upgrade;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_FORCE_UPGRADE;
import static org.opends.server.tools.ToolConstants.OPTION_LONG_NO_PROMPT;
import static org.opends.server.tools.upgrade.FileManager.copy;
import static org.opends.server.tools.upgrade.Installation
.CURRENT_CONFIG_FILE_NAME;
@@ -53,7 +51,6 @@
import org.opends.server.protocols.ldap.LDAPFilter;
import org.opends.server.tools.ClientException;
import org.opends.server.tools.RebuildIndex;
import org.opends.server.tools.upgrade.UpgradeTask.TaskType;
import org.opends.server.util.BuildVersion;
import org.opends.server.util.ChangeOperationType;
@@ -79,9 +76,14 @@
  static Set<String> indexesListToRebuild = new HashSet<String>();
  /**
   * A flag to avoid rebuild indexes if all already selected.
   * A flag to avoid rebuild single indexes if 'rebuild all' is selected.
   */
  static boolean isRebuildAllIndexes = false;
  static boolean isRebuildAllIndexesIsPresent = false;
  /**
   * A flag for marking 'rebuild all' task accepted by user.
   */
  static boolean isRebuildAllIndexesTaskAccepted = false;
  /**
   * Returns a new upgrade task which applies an LDIF record to all
@@ -406,18 +408,6 @@
      }
      @Override
      public void start(UpgradeContext context) throws ClientException
      {
        if (currentVersionEqualToOrMoreRecentThan(context, version))
        {
          for (UpgradeTask task : tasks)
          {
            task.start(context);
          }
        }
      }
      @Override
      public void perform(UpgradeContext context) throws ClientException
      {
        if (currentVersionEqualToOrMoreRecentThan(context, version))
@@ -477,22 +467,36 @@
  {
    return new AbstractUpgradeTask()
    {
      private boolean isATaskToPerform = false;
      @Override
      public void perform(final UpgradeContext context) throws ClientException
      public void interact(UpgradeContext context) throws ClientException
      {
        // NYI.
        Upgrade.setHasPostUpgradeTask(true);
        // Requires answer from the user.
        final int answer = context.confirmYN(summary, ConfirmationCallback.NO);
        isATaskToPerform = (answer == ConfirmationCallback.YES);
        isRebuildAllIndexesIsPresent =  true;
        isRebuildAllIndexesTaskAccepted =  isATaskToPerform;
      }
      @Override
      public void start(final UpgradeContext context) throws ClientException
      public void postUpgrade(final UpgradeContext context)
          throws ClientException
      {
        context.notify(summary);
        if (!isATaskToPerform)
        {
          postponePostUpgrade(context);
        }
      }
      @Override
      public void verify(final UpgradeContext context) throws ClientException
      public void postponePostUpgrade(UpgradeContext context)
          throws ClientException
      {
        verifyTaskType(TaskType.MANDATORY_USER_INTERACTION, context);
        context.notify(INFO_UPGRADE_ALL_REBUILD_INDEX_DECLINED.get(),
            TextOutputCallback.WARNING);
      }
    };
  }
@@ -549,9 +553,12 @@
      public void postponePostUpgrade(UpgradeContext context)
          throws ClientException
      {
        if (!isRebuildAllIndexesIsPresent)
        {
        context.notify(INFO_UPGRADE_REBUILD_INDEX_DECLINED.get(index),
            TextOutputCallback.WARNING);
      }
      }
    };
  }
@@ -570,19 +577,6 @@
      public void postUpgrade(final UpgradeContext context)
          throws ClientException
      {
        if (isRebuildAllIndexes)
        {
          // TODO To implement
        }
        else if (!indexesListToRebuild.isEmpty())
        {
          final Message message = INFO_UPGRADE_REBUILD_INDEX_STARTS.get(Arrays
              .toString(indexesListToRebuild.toArray()));
          final ProgressNotificationCallback pnc =
              new ProgressNotificationCallback(0, message, 25);
          LOG.log(Level.INFO, message.toString());
          context.notifyProgress(pnc);
          // Sets the arguments like the rebuild index command line.
          final List<String> args = new LinkedList<String>();
          args.addAll(Arrays.asList(
@@ -590,13 +584,6 @@
              new File(configDirectory, CURRENT_CONFIG_FILE_NAME)
                .getAbsolutePath()));
          // Adding all requested indexes.
          for (final String indexToRebuild : indexesListToRebuild)
          {
            args.add("-i");
            args.add(indexToRebuild);
          }
          // Index(es) could be contained in several backends.
          for (final String be : UpgradeUtils.getLocalBackendsFromConfig())
          {
@@ -604,11 +591,39 @@
            args.add(be);
          }
          final String[] commandLineArgs =
              args.toArray(new String[args.size()]);
        Message message = null;
        if (isRebuildAllIndexesIsPresent && isRebuildAllIndexesTaskAccepted)
        {
          args.add("--rebuildAll");
          message = INFO_UPGRADE_REBUILD_ALL.get();
        }
        else if (!indexesListToRebuild.isEmpty()
            && !isRebuildAllIndexesTaskAccepted)
        {
          message =
              INFO_UPGRADE_REBUILD_INDEX_STARTS.get(Arrays
                  .toString(indexesListToRebuild.toArray()));
          // Adding all requested indexes.
          for (final String indexToRebuild : indexesListToRebuild)
          {
            args.add("-i");
            args.add(indexToRebuild);
          }
        } else {
          return;
        }
        ProgressNotificationCallback pnc =
            new ProgressNotificationCallback(0, message, 25);
        LOG.log(Level.INFO, message.toString());
        context.notifyProgress(pnc);
        final String[] commandLineArgs = args.toArray(new String[args.size()]);
          // Displays info about command line args for log only.
          LOG.log(Level.INFO, INFO_UPGRADE_REBUILD_INDEX_ARGUMENTS.get(Arrays
              .toString(commandLineArgs)).toString());
        LOG.log(Level.INFO, INFO_UPGRADE_REBUILD_INDEX_ARGUMENTS.get(
            Arrays.toString(commandLineArgs)).toString());
          /*
           * The rebuild-index process just display a status ok / fails. The
           * logger stream contains all the log linked to this process. The
@@ -619,8 +634,7 @@
                  UpgradeLog.getPrintStream(), commandLineArgs);
          if (result == 0)
          {
            LOG.log(Level.INFO, INFO_UPGRADE_REBUILD_INDEX_ENDS.get()
                .toString());
          LOG.log(Level.INFO, INFO_UPGRADE_REBUILD_INDEX_ENDS.get().toString());
            context.notifyProgress(pnc.setProgress(100));
          }
          else
@@ -630,7 +644,6 @@
            context.notifyProgress(pnc.setProgress(-100));
          }
        }
      }
    };
  }
@@ -897,39 +910,6 @@
    };
  }
  @SuppressWarnings("fallthrough")
  private static void verifyTaskType(final TaskType type,
      final UpgradeContext context) throws ClientException
  {
    /*
     * Checks CLI/GUI options via context. The process will stop
     * if user has selected conflicting options.
     */
    switch (type)
    {
    case NEED_USER_INTERACTION:
    {
      // Nothing to do.
      break;
    }
    case MANDATORY_USER_INTERACTION:
    case TAKE_LONG_TIME_TO_COMPLETE:
    case CANNOT_BE_REVERTED:
      // The option is not present ? Stops the process.
      if (!context.isInteractiveMode() && !context.isForceUpgradeMode())
      {
        context
            .notify(Message.raw(" "), FormattedNotificationCallback.BREAKLINE);
        context.notify(ERR_UPGRADE_USER_INTERACTION_REQUIRED.get(
            OPTION_LONG_NO_PROMPT, OPTION_LONG_FORCE_UPGRADE),
            FormattedNotificationCallback.NOTICE_CALLBACK);
        throw new ClientException(EXIT_CODE_MANUAL_INTERVENTION,
            ERR_UPGRADE_INVALID_USER_OPTIONS_SELECTED.get());
      }
    default:
      break;
    }
  }
  // Prevent instantiation.
  private UpgradeTasks()
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java
@@ -36,10 +36,13 @@
import org.forgerock.opendj.ldap.requests.AddRequest;
import org.forgerock.opendj.ldap.requests.ModifyRequest;
import org.forgerock.opendj.ldap.requests.Requests;
import org.forgerock.opendj.ldap.requests.SearchRequest;
import org.forgerock.opendj.ldap.schema.Schema;
import org.forgerock.opendj.ldap.schema.SchemaBuilder;
import org.forgerock.opendj.ldap.schema.SchemaValidationPolicy;
import org.forgerock.opendj.ldap.schema.UnknownSchemaElementException;
import org.forgerock.opendj.ldif.EntryReader;
import org.forgerock.opendj.ldif.LDIF;
import org.forgerock.opendj.ldif.LDIFEntryReader;
import org.forgerock.opendj.ldif.LDIFEntryWriter;
import org.opends.server.core.DirectoryServer;
@@ -386,7 +389,9 @@
  }
  /**
   * Retrieves the backends from the current configuration file.
   * Retrieves the backends from the current configuration file. The backends
   * must be enabled to be listed. No operations should be done within a
   * disabled backend.
   *
   * @return A backend list.
   */
@@ -400,14 +405,16 @@
          new LDIFEntryReader(new FileInputStream(new File(configDirectory,
              CURRENT_CONFIG_FILE_NAME)));
      final Filter filter =
          Filter.equality("objectclass", "ds-cfg-local-db-backend");
      final Matcher includeFilter = filter.matcher();
      entryReader.setIncludeFilter(includeFilter);
      final SearchRequest sr =
          Requests.newSearchRequest("", SearchScope.WHOLE_SUBTREE,
              "(&(objectclass=ds-cfg-local-db-backend)(ds-cfg-enabled=true))",
              "ds-cfg-base-dn");
      while (entryReader.hasNext())
      final EntryReader resultReader = LDIF.search(entryReader, sr);
      while (resultReader.hasNext())
      {
        final Entry entry = entryReader.readEntry();
        final Entry entry = resultReader.readEntry();
        listBackends.add(entry.getAttribute("ds-cfg-base-dn")
            .firstValueAsString());
      }