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

Violette Roche-Montane
13.54.2013 2030f68cb29c7aa4cddf811fee2550daf44b35db
CR-2693 OPENDJ-1245 import-ldif changes ds-cfg-enabled attr (for user backend) to TRUE which causes an error in post ugrade task (rebuild-index)
3 files modified
106 ■■■■ changed files
opends/src/messages/messages/tools.properties 2 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java 58 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java 46 ●●●● patch | view | raw | blame | history
opends/src/messages/messages/tools.properties
@@ -2552,6 +2552,8 @@
INFO_UPGRADE_REBUILD_ALL_1848=Rebuilding all indexes
INFO_UPGRADE_PROCESS_END_1849=End of the upgrade process
SEVERE_ERR_UPGRADE_CORRUPTED_TEMPLATE_1850='%s' is missing or empty, it is probably corrupted
INFO_UPGRADE_REBUILD_INDEX_NO_BACKEND_FOUND_1851=No backend found. The rebuild index task \
stops.
# Upgrade tasks
INFO_UPGRADE_TASK_6869_SUMMARY_10000=Fixing de-DE collation matching rule OID
opends/src/server/org/opends/server/tools/upgrade/UpgradeTasks.java
@@ -591,21 +591,9 @@
      public void postUpgrade(final UpgradeContext context)
          throws ClientException
      {
        // Sets the arguments like the rebuild index command line.
        final List<String> args = new LinkedList<String>();
        args.addAll(Arrays.asList(
            "-f",
            new File(configDirectory, CURRENT_CONFIG_FILE_NAME)
              .getAbsolutePath()));
        // Index(es) could be contained in several backends.
        for (final String be : UpgradeUtils.getLocalBackendsFromConfig())
        {
          args.add("-b");
          args.add(be);
        }
        Message message = null;
        final List<String> args = new LinkedList<String>();
        if (isRebuildAllIndexesIsPresent && isRebuildAllIndexesTaskAccepted)
        {
          args.add("--rebuildAll");
@@ -624,16 +612,39 @@
            args.add("-i");
            args.add(indexToRebuild);
          }
        } else {
        }
        else
        {
          return;
        }
        // Startup message.
        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()]);
        // Sets the arguments like the rebuild index command line.
        args.addAll(Arrays.asList(
            "-f",
            new File(configDirectory, CURRENT_CONFIG_FILE_NAME)
              .getAbsolutePath()));
        /*
         * Index(es) could be contained in several backends or none, If none,
         * the post upgrade tasks succeed and a message is printed in the
         * upgrade log file.
         */
        final List<String> backends = UpgradeUtils.getLocalBackendsFromConfig();
        if (!backends.isEmpty())
        {
          for (final String be : backends)
          {
            args.add("-b");
            args.add(be);
          }
          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());
@@ -646,9 +657,11 @@
        final int result =
            new RebuildIndex().rebuildIndexesWithinMultipleBackends(true,
                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
@@ -658,6 +671,15 @@
          throw new ClientException(EXIT_CODE_ERROR, msg);
        }
      }
        else
        {
          final Message msg = INFO_UPGRADE_REBUILD_INDEX_NO_BACKEND_FOUND.get();
          LOG.log(Level.INFO, msg.toString());
          LOG.log(Level.INFO, INFO_UPGRADE_REBUILD_INDEX_DECLINED.get(
              Arrays.toString(indexesListToRebuild.toArray())).toString());
          context.notifyProgress(pnc.setProgress(100));
        }
      }
    };
  }
opends/src/server/org/opends/server/tools/upgrade/UpgradeUtils.java
@@ -398,20 +398,22 @@
   */
  static List<String> getLocalBackendsFromConfig()
  {
    final Schema schema = getUpgradeSchema();
    final List<String> listBackends = new LinkedList<String>();
    LDIFEntryReader entryReader = null;
    try
    {
      entryReader =
          new LDIFEntryReader(new FileInputStream(new File(configDirectory,
              CURRENT_CONFIG_FILE_NAME)));
              CURRENT_CONFIG_FILE_NAME))).setSchema(schema);
      final SearchRequest sr =
          Requests.newSearchRequest("", SearchScope.WHOLE_SUBTREE,
              "(&(objectclass=ds-cfg-local-db-backend)(ds-cfg-enabled=true))",
              "ds-cfg-base-dn");
      final EntryReader resultReader = LDIF.search(entryReader, sr);
      final EntryReader resultReader = LDIF.search(entryReader, sr, schema);
      while (resultReader.hasNext())
      {
@@ -461,12 +463,7 @@
    LDIFEntryWriter writer = null;
    try
    {
      Schema schema =
          new SchemaBuilder(Schema.getCoreSchema()).defaultMatchingRule(
              CoreSchema.getCaseExactMatchingRule()).defaultSyntax(
              CoreSchema.getDirectoryStringSyntax()).toSchema()
              .asNonStrictSchema();
      final Schema schema = getUpgradeSchema();
      entryReader =
          new LDIFEntryReader(new FileInputStream(configPath))
              .setSchema(schema);
@@ -784,6 +781,39 @@
    }
  }
  /**
   * Returns a schema used by upgrade(default octet string matching rule and
   * directory string syntax). Added attribute types which we know we are
   * sensitive to in the unit tests, e.g. ds-cfg-enabled (boolean syntax),
   * ds-cfg-filter(case ingnore), ds-cfg-collation (case ignore)... related to
   * upgrade tasks. See OPENDJ-1245.
   *
   * @return A schema which may used in the upgrade context.
   */
  final static Schema getUpgradeSchema() {
    final SchemaBuilder sb =
        new SchemaBuilder(Schema.getCoreSchema())
        .defaultMatchingRule(CoreSchema.getCaseExactMatchingRule())
        .defaultSyntax(CoreSchema.getDirectoryStringSyntax());
    // Adds ds-cfg-enabled / boolean syntax
    sb.addAttributeType("( 1.3.6.1.4.1.26027.1.1.2 NAME 'ds-cfg-enabled'"
        + " EQUALITY booleanMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.7"
        + " SINGLE-VALUE X-ORIGIN 'OpenDS Directory Server' )", false);
    // Adds ds-cfg-filter / ignore match syntax
    sb.addAttributeType("( 1.3.6.1.4.1.26027.1.1.279 NAME 'ds-cfg-filter'"
        + " EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15"
        + " X-ORIGIN 'OpenDS Directory Server' )", false);
    // Adds ds-cfg-collation / ignore match syntax
    sb.addAttributeType("( 1.3.6.1.4.1.26027.1.1.500 NAME 'ds-cfg-collation'"
        + " EQUALITY caseIgnoreMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15"
        + " X-ORIGIN 'OpenDS Directory Server' )", false);
    return sb.toSchema().asNonStrictSchema();
  }
  private static String[] readLDIFLines(final DN dn,
      final ChangeOperationType changeType, final String... lines)
  {