opendj3-server-dev/src/server/org/opends/server/api/Backend.java
@@ -26,6 +26,8 @@ */ package org.opends.server.api; import static org.opends.messages.BackendMessages.*; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -36,8 +38,10 @@ import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.config.server.ConfigException; import org.forgerock.opendj.ldap.ConditionResult; import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.opends.server.admin.Configuration; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.AddOperation; import org.opends.server.core.DeleteOperation; import org.opends.server.core.DirectoryServer; @@ -648,6 +652,37 @@ throws DirectoryException; /** * Indicates whether this backend supports indexing attributes to speed up searches. * * @return {@code true} if this backend supports indexing attributes, {@code false} otherwise */ public boolean supportsIndexing() { return false; } /** * Verify the integrity of the backend instance. * * @param verifyConfig * The verify configuration. * @return The results of the operation. * @throws ConfigException * If an unrecoverable problem arises during initialization. * @throws InitializationException * If a problem occurs during initialization that is not related to the server * configuration. * @throws DirectoryException * If a Directory Server error occurs. */ public long verifyBackend(VerifyConfig verifyConfig) throws InitializationException, ConfigException, DirectoryException { throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, ERR_INDEXES_NOT_SUPPORTED.get(getBackendID())); } /** * Indicates whether this backend provides a backup mechanism of any * kind. This method is used by the backup process when backing up * all backends to determine whether this backend is one that should opendj3-server-dev/src/server/org/opends/server/backends/jeb/BackendImpl.java
@@ -57,6 +57,7 @@ import org.opends.server.api.DiskSpaceMonitorHandler; import org.opends.server.api.MonitorProvider; import org.opends.server.backends.jeb.importLDIF.Importer; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.*; import org.opends.server.extensions.DiskSpaceMonitor; import org.opends.server.types.*; @@ -818,19 +819,16 @@ return envConfig; } /** * 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 * that is not related to the server * configuration. * @throws DirectoryException If a Directory Server error occurs. */ public long verifyBackend(VerifyConfig verifyConfig, Entry statEntry) /** {@inheritDoc} */ @Override public boolean supportsIndexing() { return true; } /** {@inheritDoc} */ @Override public long verifyBackend(VerifyConfig verifyConfig) throws InitializationException, ConfigException, DirectoryException { // If the backend already has the root container open, we must use the same @@ -844,7 +842,7 @@ } VerifyJob verifyJob = new VerifyJob(verifyConfig); return verifyJob.verifyBackend(rootContainer, statEntry); return verifyJob.verifyBackend(rootContainer); } catch (DatabaseException e) { @@ -1030,7 +1028,6 @@ public ConfigChangeResult applyConfigurationChange(LocalDBBackendCfg newCfg) { final ConfigChangeResult ccr = new ConfigChangeResult(); try { if(rootContainer != null) @@ -1064,7 +1061,6 @@ ccr.addMessage(LocalizableMessage.raw(stackTraceToSingleLineString(e))); ccr.setResultCode(DirectoryServer.getServerErrorResultCode()); } return ccr; } opendj3-server-dev/src/server/org/opends/server/backends/jeb/VerifyConfig.java
File was deleted opendj3-server-dev/src/server/org/opends/server/backends/jeb/VerifyJob.java
@@ -39,6 +39,7 @@ import org.forgerock.opendj.ldap.ResultCode; import org.forgerock.opendj.ldap.schema.MatchingRule; import org.forgerock.opendj.ldap.spi.IndexingOptions; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.DirectoryServer; import org.opends.server.types.*; import org.opends.server.util.ServerConstants; @@ -113,14 +114,12 @@ * Verify the backend. * * @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. * @throws DirectoryException If an error occurs while verifying the backend. */ public long verifyBackend(RootContainer rootContainer, Entry statEntry) throws DatabaseException, JebException, DirectoryException public long verifyBackend(RootContainer rootContainer) throws DatabaseException, JebException, DirectoryException { this.rootContainer = rootContainer; EntryContainer entryContainer = @@ -277,8 +276,6 @@ rate = 1000f*keyCount / totalTime; } addStatEntry(statEntry, "verify-error-count", String.valueOf(errorCount)); addStatEntry(statEntry, "verify-key-count", String.valueOf(keyCount)); if (cleanMode) { logger.info(NOTE_JEB_VERIFY_CLEAN_FINAL_STATUS, keyCount, errorCount, totalTime/1000, rate); @@ -291,27 +288,18 @@ averageEntryReferences = entryReferencesCount/keyCount; } if (logger.isDebugEnabled()) { logger.debug(INFO_JEB_VERIFY_MULTIPLE_REFERENCE_COUNT, multiReferenceCount); addStatEntry(statEntry, "verify-multiple-reference-count", String.valueOf(multiReferenceCount)); logger.debug(INFO_JEB_VERIFY_ENTRY_LIMIT_EXCEEDED_COUNT, entryLimitExceededCount); addStatEntry(statEntry, "verify-entry-limit-exceeded-count", String.valueOf(entryLimitExceededCount)); logger.debug(INFO_JEB_VERIFY_AVERAGE_REFERENCE_COUNT, averageEntryReferences); addStatEntry(statEntry, "verify-average-reference-count", String.valueOf(averageEntryReferences)); logger.debug(INFO_JEB_VERIFY_MAX_REFERENCE_COUNT, maxEntryPerValue); addStatEntry(statEntry, "verify-max-reference-count", String.valueOf(maxEntryPerValue)); } } } else { logger.info(NOTE_JEB_VERIFY_FINAL_STATUS, keyCount, errorCount, totalTime/1000, rate); //TODO add entry-limit-stats to the statEntry if (entryLimitMap.size() > 0) { logger.debug(INFO_JEB_VERIFY_ENTRY_LIMIT_STATS_HEADER); @@ -359,13 +347,11 @@ { DiskOrderedCursor cursor = id2entry.openCursor(new DiskOrderedCursorConfig()); long storedEntryCount = id2entry.getRecordCount(); try { DatabaseEntry key = new DatabaseEntry(); DatabaseEntry data = new DatabaseEntry(); Long storedEntryCount = id2entry.getRecordCount(); while (cursor.getNext(key, data, null) == OperationStatus.SUCCESS) { EntryID entryID; @@ -1732,20 +1718,4 @@ previousTime = latestTime; } } /** * Adds an attribute of type t and value v to the statEntry, only if the * statEntry is not null. * @param statEntry passed in from backentryImpl.verifyBackend. * @param t String to be used as the attribute type. * @param v String to be used as the attribute value. */ private void addStatEntry(Entry statEntry, String t, String v) { if (statEntry != null) { Attribute a = Attributes.create(t, v); statEntry.addAttribute(a, null); } } } opendj3-server-dev/src/server/org/opends/server/backends/pluggable/BackendImpl.java
@@ -693,19 +693,16 @@ return new RootContainer(this, cfg).importLDIF(importConfig); } /** * 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 * that is not related to the server * configuration. * @throws DirectoryException If a Directory Server error occurs. */ public long verifyBackend(VerifyConfig verifyConfig, Entry statEntry) /** {@inheritDoc} */ @Override public boolean supportsIndexing() { return true; } /** {@inheritDoc} */ @Override public long verifyBackend(VerifyConfig verifyConfig) throws InitializationException, ConfigException, DirectoryException { // If the backend already has the root container open, we must use the same @@ -719,7 +716,7 @@ } VerifyJob verifyJob = new VerifyJob(verifyConfig); return verifyJob.verifyBackend(rootContainer, statEntry); return verifyJob.verifyBackend(rootContainer); } catch (StorageRuntimeException e) { opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VerifyConfig.java
@@ -22,43 +22,27 @@ * * * Copyright 2006-2008 Sun Microsystems, Inc. * Portions Copyright 2014 ForgeRock AS * Portions Copyright 2014-2015 ForgeRock AS */ package org.opends.server.backends.pluggable; import org.opends.server.types.DN; import java.util.ArrayList; import java.util.List; import org.forgerock.util.Reject; import org.opends.server.types.DN; /** * This class represents the configuration of a JE backend verification process. */ public class VerifyConfig { /** * The base DN to be verified. */ /** The base DN to be verified. */ private DN baseDN; /** * The names of indexes to be verified for completeness. */ private ArrayList<String> completeList; /** * The names of indexes to be verified for cleanliness. */ private ArrayList<String> cleanList; /** * Create a new verify configuration. */ public VerifyConfig() { baseDN = null; completeList = new ArrayList<String>(); cleanList = new ArrayList<String>(); } /** The names of indexes to be verified for completeness. */ private ArrayList<String> completeList = new ArrayList<String>(); /** The names of indexes to be verified for cleanliness. */ private ArrayList<String> cleanList = new ArrayList<String>(); /** * Get the base DN to be verified. @@ -82,7 +66,7 @@ * Get the names of indexes to be verified for completeness. * @return The names of indexes to be verified for completeness. */ public ArrayList<String> getCompleteList() public List<String> getCompleteList() { return completeList; } @@ -93,6 +77,7 @@ */ public void addCompleteIndex(String index) { Reject.ifNull(index); completeList.add(index); } @@ -100,7 +85,7 @@ * Get the names of indexes to be verified for cleanliness. * @return The names of indexes to be verified for cleanliness. */ public ArrayList<String> getCleanList() public List<String> getCleanList() { return cleanList; } @@ -111,6 +96,7 @@ */ public void addCleanIndex(String index) { Reject.ifNull(index); cleanList.add(index); } } opendj3-server-dev/src/server/org/opends/server/backends/pluggable/VerifyJob.java
@@ -59,7 +59,6 @@ import org.opends.server.core.DirectoryServer; import org.opends.server.types.Attribute; import org.opends.server.types.AttributeType; import org.opends.server.types.Attributes; import org.opends.server.types.DN; import org.opends.server.types.DirectoryException; import org.opends.server.types.Entry; @@ -133,13 +132,11 @@ * Verify the backend. * * @param rootContainer The root container that holds the entries to verify. * @param statEntry Optional statistics entry. * @return The error count. * @throws StorageRuntimeException If an error occurs in the JE database. * @throws DirectoryException If an error occurs while verifying the backend. */ public long verifyBackend(final RootContainer rootContainer, final Entry statEntry) throws StorageRuntimeException, DirectoryException public long verifyBackend(final RootContainer rootContainer) throws StorageRuntimeException, DirectoryException { try { @@ -148,7 +145,7 @@ @Override public Long run(ReadableStorage txn) throws Exception { return verifyBackend0(txn, rootContainer, statEntry); return verifyBackend0(txn, rootContainer); } }); } @@ -158,7 +155,7 @@ } } private long verifyBackend0(ReadableStorage txn, RootContainer rootContainer, Entry statEntry) private long verifyBackend0(ReadableStorage txn, RootContainer rootContainer) throws StorageRuntimeException, DirectoryException { this.rootContainer = rootContainer; @@ -316,8 +313,6 @@ rate = 1000f*keyCount / totalTime; } addStatEntry(statEntry, "verify-error-count", String.valueOf(errorCount)); addStatEntry(statEntry, "verify-key-count", String.valueOf(keyCount)); if (cleanMode) { logger.info(NOTE_JEB_VERIFY_CLEAN_FINAL_STATUS, keyCount, errorCount, totalTime/1000, rate); @@ -330,27 +325,18 @@ averageEntryReferences = entryReferencesCount/keyCount; } if (logger.isDebugEnabled()) { logger.debug(INFO_JEB_VERIFY_MULTIPLE_REFERENCE_COUNT, multiReferenceCount); addStatEntry(statEntry, "verify-multiple-reference-count", String.valueOf(multiReferenceCount)); logger.debug(INFO_JEB_VERIFY_ENTRY_LIMIT_EXCEEDED_COUNT, entryLimitExceededCount); addStatEntry(statEntry, "verify-entry-limit-exceeded-count", String.valueOf(entryLimitExceededCount)); logger.debug(INFO_JEB_VERIFY_AVERAGE_REFERENCE_COUNT, averageEntryReferences); addStatEntry(statEntry, "verify-average-reference-count", String.valueOf(averageEntryReferences)); logger.debug(INFO_JEB_VERIFY_MAX_REFERENCE_COUNT, maxEntryPerValue); addStatEntry(statEntry, "verify-max-reference-count", String.valueOf(maxEntryPerValue)); } } } else { logger.info(NOTE_JEB_VERIFY_FINAL_STATUS, keyCount, errorCount, totalTime/1000, rate); //TODO add entry-limit-stats to the statEntry if (entryLimitMap.size() > 0) { logger.debug(INFO_JEB_VERIFY_ENTRY_LIMIT_STATS_HEADER); @@ -1695,20 +1681,4 @@ previousTime = latestTime; } } /** * Adds an attribute of type t and value v to the statEntry, only if the * statEntry is not null. * @param statEntry passed in from backentryImpl.verifyBackend. * @param t String to be used as the attribute type. * @param v String to be used as the attribute value. */ private void addStatEntry(Entry statEntry, String t, String v) { if (statEntry != null) { Attribute a = Attributes.create(t, v); statEntry.addAttribute(a, null); } } } opendj3-server-dev/src/server/org/opends/server/tools/VerifyIndex.java
@@ -22,18 +22,15 @@ * * * Copyright 2006-2008 Sun Microsystems, Inc. * Portions Copyright 2012-2014 ForgeRock AS. * Portions Copyright 2012-2015 ForgeRock AS. */ package org.opends.server.tools; import static com.forgerock.opendj.cli.ArgumentConstants.*; import static com.forgerock.opendj.cli.Utils.*; import static org.opends.messages.ToolMessages.*; import static com.forgerock.opendj.cli.ArgumentConstants.*; import static org.opends.server.util.ServerConstants.*; import static org.opends.server.util.StaticUtils.*; import static com.forgerock.opendj.cli.Utils.wrapText; import static com.forgerock.opendj.cli.Utils.filterExitCode; import java.io.OutputStream; import java.io.PrintStream; @@ -42,11 +39,10 @@ import java.util.logging.Level; import org.forgerock.i18n.LocalizableMessage; import org.forgerock.opendj.config.server.ConfigException; import org.opends.server.admin.std.server.BackendCfg; import org.opends.server.api.Backend; import org.opends.server.backends.jeb.BackendImpl; import org.opends.server.backends.jeb.VerifyConfig; import org.forgerock.opendj.config.server.ConfigException; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.CoreConfigManager; import org.opends.server.core.DirectoryServer; import org.opends.server.core.LockFileManager; @@ -64,7 +60,6 @@ import com.forgerock.opendj.cli.CommonArguments; import com.forgerock.opendj.cli.StringArgument; /** * This program provides a utility to verify the contents of the indexes * of a Directory Server backend. This will be a process that is @@ -82,7 +77,6 @@ public static void main(String[] args) { int retCode = mainVerifyIndex(args, true, System.out, System.err); if(retCode != 0) { System.exit(filterExitCode(retCode)); @@ -384,7 +378,7 @@ // Get information about the backends defined in the server. Iterate // through them, finding the one backend to be verified. Backend backend = null; Backend<?> backend = null; ArrayList<Backend> backendList = new ArrayList<Backend>(); ArrayList<BackendCfg> entryList = new ArrayList<BackendCfg>(); @@ -394,7 +388,7 @@ int numBackends = backendList.size(); for (int i=0; i < numBackends; i++) { Backend b = backendList.get(i); Backend<?> b = backendList.get(i); List<DN> baseDNs = dnList.get(i); for (DN baseDN : baseDNs) @@ -421,7 +415,7 @@ return 1; } if (!(backend instanceof BackendImpl)) if (!backend.supportsIndexing()) { err.println(wrapText(ERR_BACKEND_NO_INDEXING_SUPPORT.get(), MAX_LINE_WIDTH)); return 1; @@ -470,8 +464,7 @@ int returnCode = 0 ; try { BackendImpl jebBackend = (BackendImpl)backend; long errorCount = jebBackend.verifyBackend(verifyConfig, null); final long errorCount = backend.verifyBackend(verifyConfig); if (countErrors.isPresent()) { if (errorCount > Integer.MAX_VALUE) @@ -512,4 +505,3 @@ return returnCode; } } opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestImportJob.java
@@ -26,17 +26,18 @@ */ package org.opends.server.backends.jeb; import static org.testng.Assert.*; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import org.forgerock.opendj.ldap.ByteString; import org.opends.server.TestCaseUtils; import org.opends.server.api.Backend; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.DirectoryServer; import org.opends.server.tasks.TaskUtils; import org.opends.server.types.*; @@ -44,20 +45,15 @@ import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import static org.opends.server.util.ServerConstants.*; import static org.testng.Assert.*; @SuppressWarnings("javadoc") public class TestImportJob extends JebTestCase { private String beID = "importRoot"; private String backendID = "importRoot"; private File tempDir; private String homeDirName; private DN[] baseDNs; private BackendImpl be; private String errorCount = "verify-error-count"; private Backend<?> backend; // @formatter:off private String top = @@ -240,8 +236,7 @@ // This test suite depends on having the schema available, so we'll make // sure the server is started. TestCaseUtils.startServer(); // Enable the backend TestCaseUtils.enableBackend(beID); TestCaseUtils.enableBackend(backendID); tempDir = TestCaseUtils.createTemporaryDirectory("jebimporttest"); homeDirName = tempDir.getAbsolutePath(); @@ -291,8 +286,7 @@ @AfterClass public void cleanUp() throws Exception { TestCaseUtils.disableBackend(beID); //TestCaseUtils.deleteDirectory(tempDir); TestCaseUtils.disableBackend(backendID); } @@ -300,7 +294,7 @@ @Test(enabled = true) public void testImportAll() throws Exception { TestCaseUtils.clearJEBackend(beID); TestCaseUtils.clearJEBackend(backendID); ArrayList<String> fileList = new ArrayList<String>(); fileList.add(homeDirName + File.separator + "top.ldif"); fileList.add(homeDirName + File.separator + "entries1.ldif"); @@ -316,8 +310,8 @@ importLDIF(importConfig); be = (BackendImpl) DirectoryServer.getBackend(beID); RootContainer rootContainer = be.getRootContainer(); backend = DirectoryServer.getBackend(backendID); RootContainer rootContainer = ((BackendImpl) backend).getRootContainer(); EntryContainer entryContainer; assertTrue(rejectedEntries.size() <= 0); @@ -346,10 +340,8 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDN); Entry statEntry = bldStatEntry(""); be = (BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } else if (baseDN.toString().equals("dc=importtest1,dc=com")) { @@ -363,16 +355,13 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDN); Entry statEntry = bldStatEntry(""); be = (BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } } finally { entryContainer.sharedLock.unlock(); } } } @@ -404,8 +393,8 @@ importLDIF(importConfig); be = (BackendImpl) DirectoryServer.getBackend(beID); RootContainer rootContainer = be.getRootContainer(); backend = DirectoryServer.getBackend(backendID); RootContainer rootContainer = ((BackendImpl) backend).getRootContainer(); EntryContainer entryContainer; assertTrue(rejectedEntries.size() <= 0); @@ -433,10 +422,8 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDN); Entry statEntry = bldStatEntry(""); be = (BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } else if (baseDN.toString().equals("dc=importtest1,dc=com")) { @@ -450,16 +437,13 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDN); Entry statEntry = bldStatEntry(""); be = (BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } } finally { entryContainer.sharedLock.unlock(); } } } @@ -479,8 +463,8 @@ importLDIF(importConfig); be = (BackendImpl) DirectoryServer.getBackend(beID); RootContainer rootContainer = be.getRootContainer(); backend = DirectoryServer.getBackend(backendID); RootContainer rootContainer = ((BackendImpl) backend).getRootContainer(); EntryContainer entryContainer; entryContainer = rootContainer.getEntryContainer(DN @@ -503,10 +487,8 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(DN.valueOf("dc=importtest1,dc=com")); Entry statEntry = bldStatEntry(""); be = (BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } finally { @@ -537,7 +519,7 @@ @Test(dependsOnMethods = "testImportReplaceExisting") public void testImportAppend() throws Exception { TestCaseUtils.clearJEBackend(beID); TestCaseUtils.clearJEBackend(backendID); LDIFImportConfig importConfig = new LDIFImportConfig(homeDirName + File.separator + "top.ldif"); @@ -555,8 +537,8 @@ importLDIF(importConfig); be = (BackendImpl) DirectoryServer.getBackend(beID); RootContainer rootContainer = be.getRootContainer(); backend = DirectoryServer.getBackend(backendID); RootContainer rootContainer = ((BackendImpl) backend).getRootContainer(); EntryContainer entryContainer; for (DN baseDN : baseDNs) @@ -590,7 +572,7 @@ finally { entryContainer.sharedLock.unlock(); TaskUtils.enableBackend(beID); TaskUtils.enableBackend(backendID); } } } @@ -640,72 +622,15 @@ private void importLDIF(LDIFImportConfig importConfig) throws DirectoryException { be = (BackendImpl) DirectoryServer.getBackend(beID); TaskUtils.disableBackend(beID); backend = DirectoryServer.getBackend(backendID); TaskUtils.disableBackend(backendID); try { be.importLDIF(importConfig); backend.importLDIF(importConfig); } finally { TaskUtils.enableBackend(beID); TaskUtils.enableBackend(backendID); } } /** * Builds an entry suitable for using in the verify job to gather statistics * about the verify. * * @param dn * to put into the entry. * @return a suitable entry. * @throws DirectoryException * if the cannot be created. */ private Entry bldStatEntry(String dn) throws DirectoryException { DN entryDN = DN.valueOf(dn); HashMap<ObjectClass, String> ocs = new HashMap<ObjectClass, String>(2); ObjectClass topOC = DirectoryServer.getObjectClass(OC_TOP); if (topOC == null) { topOC = DirectoryServer.getDefaultObjectClass(OC_TOP); } ocs.put(topOC, OC_TOP); ObjectClass extensibleObjectOC = DirectoryServer .getObjectClass(OC_EXTENSIBLE_OBJECT); if (extensibleObjectOC == null) { extensibleObjectOC = DirectoryServer .getDefaultObjectClass(OC_EXTENSIBLE_OBJECT); } ocs.put(extensibleObjectOC, OC_EXTENSIBLE_OBJECT); return new Entry(entryDN, ocs, new LinkedHashMap<AttributeType, List<Attribute>>(0), new HashMap<AttributeType, List<Attribute>>(0)); } /** * Gets information from the stat entry and returns that value as a Long. * * @param e * entry to search. * @param type * attribute type * @return Long * @throws NumberFormatException * if the attribute value cannot be parsed. */ private long getStatEntryCount(Entry e, String type) throws NumberFormatException { AttributeType attrType = DirectoryServer.getAttributeType(type); if (attrType == null) attrType = DirectoryServer.getDefaultAttributeType(type); List<Attribute> attrList = e.getAttribute(attrType, null); ByteString v = attrList.get(0).iterator().next(); return Long.parseLong(v.toString()); } } opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestRebuildJob.java
@@ -22,40 +22,35 @@ * * * Copyright 2006-2009 Sun Microsystems, Inc. * Portions Copyright 2011-2014 ForgeRock AS * Portions Copyright 2011-2015 ForgeRock AS */ package org.opends.server.backends.jeb; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import static org.testng.Assert.*; import org.forgerock.opendj.ldap.ByteString; import org.opends.server.TestCaseUtils; import org.opends.server.backends.jeb.RebuildConfig.RebuildMode; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.DirectoryServer; import org.opends.server.tasks.TaskUtils; import org.opends.server.types.*; import org.opends.server.types.DN; import org.opends.server.types.DirectoryException; import org.opends.server.types.InitializationException; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import static org.opends.server.util.ServerConstants.*; import static org.testng.Assert.*; @SuppressWarnings("javadoc") public class TestRebuildJob extends JebTestCase { private String beID="rebuildRoot"; private String backendID = "rebuildRoot"; private static String suffix="dc=rebuild,dc=jeb"; private static String vBranch="ou=rebuild tests," + suffix; private String numUsersLine="define numusers= #numEntries#"; //Attribute type in stat entry containing error count private String errorCount="verify-error-count"; private DN[] baseDNs; private BackendImpl be; private BackendImpl backend; @DataProvider(name = "systemIndexes") public Object[][] systemIndexes() { @@ -129,7 +124,7 @@ @BeforeClass public void setup() throws Exception { TestCaseUtils.startServer(); TestCaseUtils.enableBackend(beID); TestCaseUtils.enableBackend(backendID); baseDNs = new DN[] { DN.valueOf(suffix) }; @@ -137,8 +132,8 @@ @AfterClass public void cleanUp() throws Exception { TestCaseUtils.clearJEBackend(beID); TestCaseUtils.disableBackend(beID); TestCaseUtils.clearJEBackend(backendID); TestCaseUtils.disableBackend(backendID); } /** @@ -147,7 +142,7 @@ * @throws Exception if the entries are not loaded or created. */ private void cleanAndLoad(int numEntries) throws Exception { TestCaseUtils.clearJEBackend(beID); TestCaseUtils.clearJEBackend(backendID); template[2]=numUsersLine; template[2]= template[2].replaceAll("#numEntries#", String.valueOf(numEntries)); @@ -166,8 +161,8 @@ RebuildConfig rebuildConfig = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex(index); be=(BackendImpl) DirectoryServer.getBackend(beID); be.rebuildBackend(rebuildConfig); backend = (BackendImpl) DirectoryServer.getBackend(backendID); backend.rebuildBackend(rebuildConfig); if(index.contains(".") && !index.startsWith("vlv.")) { @@ -193,9 +188,8 @@ RebuildConfig rebuildConfig = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex("id2entry"); be=(BackendImpl) DirectoryServer.getBackend(beID); be.rebuildBackend(rebuildConfig); backend = (BackendImpl) DirectoryServer.getBackend(backendID); backend.rebuildBackend(rebuildConfig); } @@ -213,14 +207,13 @@ RebuildConfig rebuildConfig = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex("id2entry"); be=(BackendImpl) DirectoryServer.getBackend(beID); TaskUtils.disableBackend(beID); backend = (BackendImpl) DirectoryServer.getBackend(backendID); TaskUtils.disableBackend(backendID); try { be.rebuildBackend(rebuildConfig); backend.rebuildBackend(rebuildConfig); } finally { TaskUtils.enableBackend(beID); TaskUtils.enableBackend(backendID); } } @@ -231,9 +224,8 @@ RebuildConfig rebuildConfig = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex(index); be=(BackendImpl) DirectoryServer.getBackend(beID); be.rebuildBackend(rebuildConfig); backend = (BackendImpl) DirectoryServer.getBackend(backendID); backend.rebuildBackend(rebuildConfig); } @Test(dataProvider = "systemIndexes", @@ -244,8 +236,8 @@ RebuildConfig rebuildConfig = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex(index); be=(BackendImpl) DirectoryServer.getBackend(beID); be.rebuildBackend(rebuildConfig); backend = (BackendImpl) DirectoryServer.getBackend(backendID); backend.rebuildBackend(rebuildConfig); } @Test(dataProvider = "systemIndexes") @@ -255,19 +247,19 @@ RebuildConfig rebuildConfig = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex(index); be=(BackendImpl) DirectoryServer.getBackend(beID); backend = (BackendImpl) DirectoryServer.getBackend(backendID); TaskUtils.disableBackend(beID); TaskUtils.disableBackend(backendID); be.rebuildBackend(rebuildConfig); backend.rebuildBackend(rebuildConfig); //TODO: Verify dn2uri database as well. if(!index.equalsIgnoreCase("dn2uri")) if (!"dn2uri".equalsIgnoreCase(index)) { assertEquals(verifyBackend(index), 0); } TaskUtils.enableBackend(beID); TaskUtils.enableBackend(backendID); } @Test @@ -278,15 +270,7 @@ rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.setRebuildMode(RebuildMode.ALL); be=(BackendImpl) DirectoryServer.getBackend(beID); TaskUtils.disableBackend(beID); be.rebuildBackend(rebuildConfig); assertEquals(verifyBackend(null), 0); TaskUtils.enableBackend(beID); rebuildIndexes(rebuildConfig); } @Test @@ -297,18 +281,9 @@ rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.setRebuildMode(RebuildMode.DEGRADED); be=(BackendImpl) DirectoryServer.getBackend(beID); TaskUtils.disableBackend(beID); be.rebuildBackend(rebuildConfig); assertEquals(verifyBackend(null), 0); TaskUtils.enableBackend(beID); rebuildIndexes(rebuildConfig); } @Test public void testRebuildDN2ID() throws Exception { @@ -317,15 +292,22 @@ rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex("dn2id"); be=(BackendImpl) DirectoryServer.getBackend(beID); rebuildIndexes(rebuildConfig); } TaskUtils.disableBackend(beID); be.rebuildBackend(rebuildConfig); private void rebuildIndexes(RebuildConfig rebuildConfig) throws Exception { backend = (BackendImpl) DirectoryServer.getBackend(backendID); TaskUtils.disableBackend(backendID); try { backend.rebuildBackend(rebuildConfig); assertEquals(verifyBackend(null), 0); TaskUtils.enableBackend(beID); } finally { TaskUtils.enableBackend(backendID); } } @Test @@ -349,22 +331,24 @@ public void testRebuildMultipleJobs() throws Exception { RebuildConfig rebuildConfig = new RebuildConfig(); RebuildConfig rebuildConfig2 = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig2.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex("dn2id"); rebuildConfig.addRebuildIndex("id2children"); rebuildConfig2.addRebuildIndex("dn2id"); rebuildConfig.addRebuildIndex("cn"); RebuildConfig rebuildConfig2 = new RebuildConfig(); rebuildConfig2.setBaseDN(baseDNs[0]); rebuildConfig2.addRebuildIndex("dn2id"); assertNotNull(rebuildConfig.checkConflicts(rebuildConfig2)); assertNotNull(rebuildConfig2.checkConflicts(rebuildConfig)); rebuildConfig = new RebuildConfig(); rebuildConfig2 = new RebuildConfig(); rebuildConfig.setBaseDN(baseDNs[0]); rebuildConfig2.setBaseDN(baseDNs[0]); rebuildConfig.addRebuildIndex("cn"); rebuildConfig2 = new RebuildConfig(); rebuildConfig2.setBaseDN(baseDNs[0]); rebuildConfig2.addRebuildIndex("cn.presence"); rebuildConfig2.addRebuildIndex("dn2id"); @@ -380,53 +364,6 @@ { verifyConfig.addCleanIndex(index); } Entry statEntry=bldStatEntry(""); be.verifyBackend(verifyConfig, statEntry); return getStatEntryCount(statEntry, errorCount); } /** * Builds an entry suitable for using in the verify job to gather statistics about * the verify. * @param dn to put into the entry. * @return a suitable entry. * @throws DirectoryException if the cannot be created. */ private Entry bldStatEntry(String dn) throws DirectoryException { DN entryDN = DN.valueOf(dn); HashMap<ObjectClass, String> ocs = new HashMap<ObjectClass, String>(2); ObjectClass topOC = DirectoryServer.getObjectClass(OC_TOP); if (topOC == null) { topOC = DirectoryServer.getDefaultObjectClass(OC_TOP); } ocs.put(topOC, OC_TOP); ObjectClass extensibleObjectOC = DirectoryServer .getObjectClass(OC_EXTENSIBLE_OBJECT); if (extensibleObjectOC == null) { extensibleObjectOC = DirectoryServer .getDefaultObjectClass(OC_EXTENSIBLE_OBJECT); } ocs.put(extensibleObjectOC, OC_EXTENSIBLE_OBJECT); return new Entry(entryDN, ocs, new LinkedHashMap<AttributeType, List<Attribute>>(0), new HashMap<AttributeType, List<Attribute>>(0)); } /** * Gets information from the stat entry and returns that value as a Long. * @param e entry to search. * @param type attribute type * @return Long * @throws NumberFormatException if the attribute value cannot be parsed. */ private long getStatEntryCount(Entry e, String type) throws NumberFormatException { AttributeType attrType = DirectoryServer.getAttributeType(type); if (attrType == null) attrType = DirectoryServer.getDefaultAttributeType(type); List<Attribute> attrList = e.getAttribute(attrType, null); ByteString v = attrList.get(0).iterator().next(); return Long.parseLong(v.toString()); return backend.verifyBackend(verifyConfig); } } opendj3-server-dev/tests/unit-tests-testng/src/server/org/opends/server/backends/jeb/TestVerifyJob.java
@@ -22,16 +22,21 @@ * * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions Copyright 2011-2014 ForgeRock AS * Portions Copyright 2011-2015 ForgeRock AS */ package org.opends.server.backends.jeb; import static org.opends.server.util.ServerConstants.*; import static org.testng.Assert.*; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import org.forgerock.opendj.ldap.ByteString; import org.opends.server.TestCaseUtils; import org.opends.server.api.Backend; import org.opends.server.backends.pluggable.VerifyConfig; import org.opends.server.core.DirectoryServer; import org.opends.server.types.*; import org.opends.server.util.StaticUtils; @@ -46,21 +51,16 @@ import com.sleepycat.je.OperationStatus; import com.sleepycat.je.Transaction; import static org.opends.server.util.ServerConstants.*; import static org.testng.Assert.*; @SuppressWarnings("javadoc") public class TestVerifyJob extends JebTestCase { /** Root suffix for verify backend. */ private static String suffix="dc=verify,dc=jeb"; private static String vBranch="ou=verify tests," + suffix; private String beID="verifyRoot"; private String backendID = "verifyRoot"; private String numUsersLine="define numusers= #numEntries#"; /** Attribute type in stat entry containing error count. */ private String errorCount="verify-error-count"; private DN[] baseDNs; private BackendImpl be; private Backend<?> backend; private EntryContainer eContainer; private DN2ID dn2id; private ID2Entry id2entry; @@ -134,7 +134,7 @@ @BeforeClass public void setup() throws Exception { TestCaseUtils.startServer(); TestCaseUtils.enableBackend(beID); TestCaseUtils.enableBackend(backendID); baseDNs = new DN[] { DN.valueOf(suffix) }; @@ -142,8 +142,8 @@ @AfterClass public void cleanUp() throws Exception { TestCaseUtils.clearJEBackend(beID); TestCaseUtils.disableBackend(beID); TestCaseUtils.clearJEBackend(backendID); TestCaseUtils.disableBackend(backendID); } /** @@ -158,10 +158,8 @@ cleanAndLoad(9); VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDNs[0]); Entry statEntry=bldStatEntry(""); be=(BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } /** @@ -177,10 +175,8 @@ verifyConfig.setBaseDN(baseDNs[0]); verifyConfig.addCleanIndex("telephoneNumber"); verifyConfig.addCleanIndex("givenName"); Entry statEntry=bldStatEntry(""); be=(BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } /** @@ -196,10 +192,8 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDNs[0]); verifyConfig.addCleanIndex(index); Entry statEntry=bldStatEntry(""); be=(BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } /* @@ -448,10 +442,9 @@ //Add entry with short id byte[] shortBytes = new byte[3]; DatabaseEntry key= new DatabaseEntry(shortBytes); Entry testEntry=bldStatEntry(junkDN); ByteString entryBytes = ID2Entry.entryToDatabase(testEntry, new DataConfig(false, false, null)); Entry testEntry = buildEntry(junkDN); DataConfig dataConfig = new DataConfig(false, false, null); ByteString entryBytes = ID2Entry.entryToDatabase(testEntry, dataConfig); DatabaseEntry data= new DatabaseEntry(entryBytes.toByteArray()); assertEquals(id2entry.put(txn, key, data), OperationStatus.SUCCESS); @@ -770,10 +763,8 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDNs[0]); verifyConfig.addCleanIndex("userPassword"); Entry statEntry=bldStatEntry(""); be=(BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), 0); backend = DirectoryServer.getBackend(backendID); assertEquals(backend.verifyBackend(verifyConfig), 0); } /** @@ -786,9 +777,8 @@ VerifyConfig verifyConfig = new VerifyConfig(); verifyConfig.setBaseDN(baseDNs[0]); verifyConfig.addCleanIndex(badIndexName); Entry statEntry=bldStatEntry(""); be=(BackendImpl) DirectoryServer.getBackend(beID); be.verifyBackend(verifyConfig, statEntry); backend = DirectoryServer.getBackend(backendID); backend.verifyBackend(verifyConfig); } /* end tests */ @@ -805,7 +795,7 @@ private DatabaseEntry addID2EntryReturnKey(String dn, long id, boolean trashFormat) throws Exception { DatabaseEntry key= new EntryID(id).getDatabaseEntry(); Entry testEntry=bldStatEntry(dn); Entry testEntry = buildEntry(dn); DataConfig dataConfig = new DataConfig(false, false, null); byte []entryBytes = ID2Entry.entryToDatabase(testEntry, dataConfig).toByteArray(); if(trashFormat) @@ -861,9 +851,7 @@ { verifyConfig.addCleanIndex(indexToDo); } Entry statEntry=bldStatEntry(""); be.verifyBackend(verifyConfig, statEntry); assertEquals(getStatEntryCount(statEntry, errorCount), expectedErrors); assertEquals(backend.verifyBackend(verifyConfig), expectedErrors); } @@ -877,8 +865,8 @@ */ private void preTest(int numEntries) throws Exception { cleanAndLoad(numEntries); be=(BackendImpl) DirectoryServer.getBackend(beID); RootContainer rContainer = be.getRootContainer(); backend = DirectoryServer.getBackend(backendID); RootContainer rContainer = ((BackendImpl) backend).getRootContainer(); eContainer= rContainer.getEntryContainer(DN.valueOf(suffix)); id2child=eContainer.getID2Children(); id2entry=eContainer.getID2Entry(); @@ -893,7 +881,7 @@ * @throws Exception if the entries are not loaded or created. */ private void cleanAndLoad(int numEntries) throws Exception { TestCaseUtils.clearJEBackend(beID); TestCaseUtils.clearJEBackend(backendID); template[2]=numUsersLine; template[2]= template[2].replaceAll("#numEntries#", String.valueOf(numEntries)); @@ -901,32 +889,13 @@ } /** * Gets information from the stat entry and returns that value as a Long. * @param e entry to search. * @param type attribute type * @return Long * @throws NumberFormatException if the attribute value cannot be parsed. */ private long getStatEntryCount(Entry e, String type) throws NumberFormatException { AttributeType attrType = DirectoryServer.getAttributeType(type); if (attrType == null) { attrType = DirectoryServer.getDefaultAttributeType(type); } List<Attribute> attrList = e.getAttribute(attrType, null); ByteString v = attrList.get(0).iterator().next(); return Long.parseLong(v.toString()); } /** * Builds an entry suitable for using in the verify job to gather statistics about * the verify. * Builds an entry. * * @param dn to put into the entry. * @return a suitable entry. * @throws DirectoryException if the cannot be created. * @return a new entry. * @throws DirectoryException if the entry cannot be created. */ private Entry bldStatEntry(String dn) throws DirectoryException { private Entry buildEntry(String dn) throws DirectoryException { DN entryDN = DN.valueOf(dn); HashMap<ObjectClass, String> ocs = new HashMap<ObjectClass, String>(2); ObjectClass topOC = DirectoryServer.getObjectClass(OC_TOP);