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

lutoff
13.09.2007 339ab397cebba87b904e4a3af1ea29e2c8a44ed5
fix for issue #1897 (verif-index , rebuild-index return 0 in case of errors):
return code '1' is now returned in case of error.
In addition to that, the following argument has been add in order to get the number of errors found by
verify-index: "--countErrors"
2 files added
5 files modified
289 ■■■■■ changed files
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java 7 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java 4 ●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/messages/ToolMessages.java 12 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/RebuildIndex.java 4 ●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/tools/VerifyIndex.java 22 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/RebuildIndexTestCase.java 120 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/VerifyIndexTestCase.java 120 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/BackendImpl.java
@@ -1185,6 +1185,7 @@
   * Verify the integrity of the backend instance.
   * @param verifyConfig The verify configuration.
   * @param statEntry Optional entry to save stats into.
   * @return The error count.
   * @throws  ConfigException  If an unrecoverable problem arises during
   *                           initialization.
   * @throws  InitializationException  If a problem occurs during initialization
@@ -1192,12 +1193,13 @@
   *                                   configuration.
   * @throws DirectoryException If a Directory Server error occurs.
   */
  public void verifyBackend(VerifyConfig verifyConfig, Entry statEntry)
  public long verifyBackend(VerifyConfig verifyConfig, Entry statEntry)
      throws InitializationException, ConfigException, DirectoryException
  {
    // If the backend already has the root container open, we must use the same
    // underlying root container
    boolean openRootContainer = rootContainer == null;
    long errorCount = 0 ;
    try
    {
@@ -1217,7 +1219,7 @@
      }
      VerifyJob verifyJob = new VerifyJob(verifyConfig);
      verifyJob.verifyBackend(rootContainer, statEntry);
      errorCount = verifyJob.verifyBackend(rootContainer, statEntry);
    }
    catch (DatabaseException e)
    {
@@ -1260,6 +1262,7 @@
        }
      }
    }
    return errorCount;
  }
opendj-sdk/opends/src/server/org/opends/server/backends/jeb/VerifyJob.java
@@ -197,10 +197,11 @@
   *
   * @param rootContainer The root container that holds the entries to verify.
   * @param statEntry Optional statistics entry.
   * @return The error count.
   * @throws DatabaseException If an error occurs in the JE database.
   * @throws JebException If an error occurs in the JE backend.
   */
  public void verifyBackend(RootContainer rootContainer, Entry statEntry) throws
  public long verifyBackend(RootContainer rootContainer, Entry statEntry) throws
      DatabaseException, JebException
  {
    this.rootContainer = rootContainer;
@@ -416,6 +417,7 @@
    {
      entryContainer.sharedLock.unlock();
    }
    return errorCount;
  }
  /**
opendj-sdk/opends/src/server/org/opends/server/messages/ToolMessages.java
@@ -9017,6 +9017,14 @@
       CATEGORY_MASK_TOOLS | SEVERITY_MASK_SEVERE_ERROR | 1198;
  /**
   * The message ID for the message that will be used as the description of the
   * countErrors argument. This does not take any arguments.
   */
  public static final int MSGID_VERIFYINDEX_DESCRIPTION_COUNT_ERRORS =
    CATEGORY_MASK_TOOLS | SEVERITY_MASK_INFORMATIONAL | 1199;
  /**
   * Associates a set of generic messages with the message IDs defined in this
   * class.
   */
@@ -9822,6 +9830,10 @@
                    "shared lock for backend %s:  %s.  This lock should " +
                    "automatically be cleared when the verification process " +
                    "exits, so no further action should be required");
    registerMessage(MSGID_VERIFYINDEX_DESCRIPTION_COUNT_ERRORS,
                    "Count the number of errors found during the verification "+
                    "and return that value as the exit code (values > 255 " +
                    "will be reduced to 255 due to exit code restrictions)");
    registerMessage(MSGID_MULTIPLE_BACKENDS_FOR_BASE,
                    "Multiple Directory Server backends are configured to " +
                    "support base DN \"%s\"");
opendj-sdk/opends/src/server/org/opends/server/tools/RebuildIndex.java
@@ -497,6 +497,7 @@
    }
    // Launch the rebuild process.
    int returnCode = 0;
    try
    {
      BackendImpl jebBackend = (BackendImpl)backend;
@@ -508,6 +509,7 @@
      String message = getMessage(msgID, getExceptionMessage(e));
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
               msgID);
      returnCode = 1;
    }
    finally
    {
@@ -535,6 +537,6 @@
      }
    }
    return 0;
    return returnCode;
  }
}
opendj-sdk/opends/src/server/org/opends/server/tools/VerifyIndex.java
@@ -137,6 +137,7 @@
    StringArgument  baseDNString            = null;
    StringArgument  indexList               = null;
    BooleanArgument cleanMode               = null;
    BooleanArgument countErrors             = null;
    BooleanArgument displayUsage            = null;
@@ -189,6 +190,10 @@
                               MSGID_VERIFYINDEX_DESCRIPTION_VERIFY_CLEAN);
      argParser.addArgument(cleanMode);
      countErrors =
           new BooleanArgument("counterrors", null, "countErrors",
                               MSGID_VERIFYINDEX_DESCRIPTION_COUNT_ERRORS);
      argParser.addArgument(countErrors);
      displayUsage =
           new BooleanArgument("help", OPTION_SHORT_HELP, OPTION_LONG_HELP,
@@ -521,10 +526,22 @@
    // Launch the verify process.
    int returnCode = 0 ;
    try
    {
      BackendImpl jebBackend = (BackendImpl)backend;
      jebBackend.verifyBackend(verifyConfig, null);
      long errorCount = jebBackend.verifyBackend(verifyConfig, null);
      if (countErrors.isPresent())
      {
        if (errorCount > Integer.MAX_VALUE)
        {
          returnCode = Integer.MAX_VALUE;
        }
        else
        {
          returnCode = (int) errorCount;
        }
      }
    }
    catch (Exception e)
    {
@@ -532,6 +549,7 @@
      String message = getMessage(msgID, getExceptionMessage(e));
      logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message,
               msgID);
      returnCode = 1;
    }
@@ -558,6 +576,6 @@
               message, msgID);
    }
    return 0;
    return returnCode;
  }
}
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/RebuildIndexTestCase.java
New file
@@ -0,0 +1,120 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.tools;
import java.util.ArrayList;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.DN;
import org.opends.server.types.Modification;
import org.opends.server.types.ModificationType;
import org.opends.server.types.ResultCode;
import static org.testng.Assert.*;
/**
 * A set of test cases for the rebuild-index tool (see issue #1897)
 */
public class RebuildIndexTestCase
       extends ToolsTestCase
{
  private String configFilePath ;
  /**
   * Ensures that the Directory Server is running and performs other necessary
   * setup.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @BeforeClass()
  public void setup()
         throws Exception
  {
    TestCaseUtils.startServer();
    configFilePath = DirectoryServer.getConfigFile();
    // Add the airius.com suffix to userRoot
    InternalClientConnection rootConnection =
      InternalClientConnection.getRootConnection();
    ArrayList<Modification> mods = new ArrayList<Modification>();
    mods.add(new Modification(ModificationType.ADD,
                      new Attribute("ds-cfg-backend-base-dn", "o=airius.com")));
    String userRootDN  = "ds-cfg-backend-id=userRoot,cn=Backends,cn=config";
    ModifyOperation modifyOperation =
         rootConnection.processModify(DN.decode(userRootDN), mods);
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
  }
  /**
   * Performs necessary cleanup.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @AfterClass()
  public void cleanup()
         throws Exception
  {
    // remove the airius.com suffix to userRoot
    InternalClientConnection rootConnection =
      InternalClientConnection.getRootConnection();
    ArrayList<Modification> mods = new ArrayList<Modification>();
    mods.add(new Modification(ModificationType.DELETE,
                      new Attribute("ds-cfg-backend-base-dn", "o=airius.com")));
    String userRootDN  = "ds-cfg-backend-id=userRoot,cn=Backends,cn=config";
    ModifyOperation modifyOperation =
         rootConnection.processModify(DN.decode(userRootDN), mods);
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
  }
  /**
   * Tests the rebuild-index -b o=airius.com -i description
   */
  @Test()
  public void testNoIndexOnDescription()
  {
    String[] args = {
        "-f",configFilePath,
        "-b", "o=airius.com",
        "-i", "description" };
    assertEquals(RebuildIndex.mainRebuildIndex(args, false, null, null), 1);
  }
}
opendj-sdk/opends/tests/unit-tests-testng/src/server/org/opends/server/tools/VerifyIndexTestCase.java
New file
@@ -0,0 +1,120 @@
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE
 * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at
 * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
 * add the following below this CDDL HEADER, with the fields enclosed
 * by brackets "[]" replaced with your own identifying information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
 */
package org.opends.server.tools;
import java.util.ArrayList;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.opends.server.TestCaseUtils;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ModifyOperation;
import org.opends.server.protocols.internal.InternalClientConnection;
import org.opends.server.types.Attribute;
import org.opends.server.types.DN;
import org.opends.server.types.Modification;
import org.opends.server.types.ModificationType;
import org.opends.server.types.ResultCode;
import static org.testng.Assert.*;
/**
 * A set of test cases for the verify-index tool (see issue #1897)
 */
public class VerifyIndexTestCase
       extends ToolsTestCase
{
  private String configFilePath ;
  /**
   * Ensures that the Directory Server is running and performs other necessary
   * setup.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @BeforeClass()
  public void setup()
         throws Exception
  {
    TestCaseUtils.startServer();
    configFilePath = DirectoryServer.getConfigFile();
    // Add the airius.com suffix to userRoot
    InternalClientConnection rootConnection =
      InternalClientConnection.getRootConnection();
    ArrayList<Modification> mods = new ArrayList<Modification>();
    mods.add(new Modification(ModificationType.ADD,
                      new Attribute("ds-cfg-backend-base-dn", "o=airius.com")));
    String userRootDN  = "ds-cfg-backend-id=userRoot,cn=Backends,cn=config";
    ModifyOperation modifyOperation =
         rootConnection.processModify(DN.decode(userRootDN), mods);
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
  }
  /**
   * Performs necessary cleanup.
   *
   * @throws  Exception  If an unexpected problem occurs.
   */
  @AfterClass()
  public void cleanup()
         throws Exception
  {
    // remove the airius.com suffix to userRoot
    InternalClientConnection rootConnection =
      InternalClientConnection.getRootConnection();
    ArrayList<Modification> mods = new ArrayList<Modification>();
    mods.add(new Modification(ModificationType.DELETE,
                      new Attribute("ds-cfg-backend-base-dn", "o=airius.com")));
    String userRootDN  = "ds-cfg-backend-id=userRoot,cn=Backends,cn=config";
    ModifyOperation modifyOperation =
         rootConnection.processModify(DN.decode(userRootDN), mods);
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);
  }
  /**
   * Tests the verify-index -b o=airius.com -i description
   */
  @Test()
  public void testNoIndexOnDescription()
  {
    String[] args = {
        "-f",configFilePath,
        "-b", "o=airius.com",
        "-i", "description" };
    assertEquals(VerifyIndex.mainVerifyIndex(args, false, null, null), 1);
  }
}