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
| | |
| | | * 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 |
| | |
| | | * 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 |
| | | { |
| | |
| | | } |
| | | |
| | | VerifyJob verifyJob = new VerifyJob(verifyConfig); |
| | | verifyJob.verifyBackend(rootContainer, statEntry); |
| | | errorCount = verifyJob.verifyBackend(rootContainer, statEntry); |
| | | } |
| | | catch (DatabaseException e) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | return errorCount; |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @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; |
| | |
| | | { |
| | | entryContainer.sharedLock.unlock(); |
| | | } |
| | | return errorCount; |
| | | } |
| | | |
| | | /** |
| | |
| | | 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. |
| | | */ |
| | |
| | | "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\""); |
| | |
| | | } |
| | | |
| | | // Launch the rebuild process. |
| | | int returnCode = 0; |
| | | try |
| | | { |
| | | BackendImpl jebBackend = (BackendImpl)backend; |
| | |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | | returnCode = 1; |
| | | } |
| | | finally |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | return 0; |
| | | return returnCode; |
| | | } |
| | | } |
| | |
| | | StringArgument baseDNString = null; |
| | | StringArgument indexList = null; |
| | | BooleanArgument cleanMode = null; |
| | | BooleanArgument countErrors = null; |
| | | BooleanArgument displayUsage = null; |
| | | |
| | | |
| | |
| | | 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, |
| | |
| | | |
| | | |
| | | // 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) |
| | | { |
| | |
| | | String message = getMessage(msgID, getExceptionMessage(e)); |
| | | logError(ErrorLogCategory.BACKEND, ErrorLogSeverity.SEVERE_ERROR, message, |
| | | msgID); |
| | | returnCode = 1; |
| | | } |
| | | |
| | | |
| | |
| | | message, msgID); |
| | | } |
| | | |
| | | return 0; |
| | | return returnCode; |
| | | } |
| | | } |
| New file |
| | |
| | | /* |
| | | * 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); |
| | | } |
| | | } |
| | | |
| New file |
| | |
| | | /* |
| | | * 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); |
| | | } |
| | | } |
| | | |