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

Jean-Noel Rouvignac
13.00.2015 a873d6d0b57a360b7ff038cf6aac11e8e7369cfa
ImportStrategy.java:
In importLDIF(), added InitializationException as a checked exception.

Importer.java:
Simplified the code as a consequence of the changes to ImportStrategy.

RootContainer.java:
Moved import related code to BackendImpl.

BackendImpl.java:
Moved import related code from RootContainer here.
Simplified code in various methods + used multi catch.
4 files modified
132 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java 71 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/ImportStrategy.java 13 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java 34 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/RootContainer.java 14 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java
@@ -56,6 +56,7 @@
import org.opends.server.backends.pluggable.spi.WriteableTransaction;
import org.opends.server.core.*;
import org.opends.server.types.*;
import org.opends.server.util.LDIFException;
import org.opends.server.util.RuntimeInformation;
/**
@@ -350,16 +351,8 @@
  public long getNumberOfEntriesInBaseDN(DN baseDN) throws DirectoryException
  {
    checkNotNull(baseDN, "baseDN must not be null");
    final EntryContainer ec;
    try {
      ec = accessBegin(null, baseDN);
    }
    catch (DirectoryException de)
    {
      throw de;
    }
    final EntryContainer ec = accessBegin(null, baseDN);
    ec.sharedLock.lock();
    try
    {
@@ -367,8 +360,7 @@
    }
    catch (Exception e)
    {
      throw new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), LocalizableMessage.raw(e.getMessage()), e);
      throw new DirectoryException(getServerErrorResultCode(), LocalizableMessage.raw(e.getMessage()), e);
    }
    finally
    {
@@ -587,7 +579,7 @@
    if (rootContainer == null)
    {
      LocalizableMessage msg = ERR_ROOT_CONTAINER_NOT_INITIALIZED.get(getBackendID());
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), msg);
      throw new DirectoryException(getServerErrorResultCode(), msg);
    }
  }
@@ -599,7 +591,6 @@
    // If the backend already has the root container open, we must use the same
    // underlying root container
    boolean openRootContainer = mustOpenRootContainer();
    final ResultCode errorRC = DirectoryServer.getServerErrorResultCode();
    try
    {
      if (openRootContainer)
@@ -612,23 +603,15 @@
    }
    catch (IOException ioe)
    {
      throw new DirectoryException(errorRC, ERR_EXPORT_IO_ERROR.get(ioe.getMessage()), ioe);
      throw new DirectoryException(getServerErrorResultCode(), ERR_EXPORT_IO_ERROR.get(ioe.getMessage()), ioe);
    }
    catch (StorageRuntimeException de)
    {
      throw createDirectoryException(de);
    }
    catch (ConfigException ce)
    catch (ConfigException | InitializationException | LDIFException e)
    {
      throw new DirectoryException(errorRC, ce.getMessageObject(), ce);
    }
    catch (IdentifiedException e)
    {
      if (e instanceof DirectoryException)
      {
        throw (DirectoryException) e;
      }
      throw new DirectoryException(errorRC, e.getMessageObject(), e);
      throw new DirectoryException(getServerErrorResultCode(), e.getMessageObject(), e);
    }
    finally
    {
@@ -671,21 +654,17 @@
      }
      rootContainer = initializeRootContainer();
      return rootContainer.importLDIF(importConfig, serverContext);
      return getImportStrategy().importLDIF(importConfig, rootContainer, serverContext);
    }
    catch (StorageRuntimeException e)
    {
      throw new DirectoryException(getServerErrorResultCode(), LocalizableMessage.raw(e.getMessage()), e);
      throw createDirectoryException(e);
    }
    catch (DirectoryException e)
    {
      throw e;
    }
    catch (OpenDsException e)
    {
      throw new DirectoryException(getServerErrorResultCode(), e.getMessageObject(), e);
    }
    catch (ConfigException e)
    catch (OpenDsException | ConfigException e)
    {
      throw new DirectoryException(getServerErrorResultCode(), e.getMessageObject(), e);
    }
@@ -712,6 +691,12 @@
    }
  }
  private ImportStrategy getImportStrategy() throws DirectoryException
  {
    // TODO JNR may call new SuccessiveAddsImportStrategy() depending on configured import strategy
    return new Importer.StrategyImpl(cfg);
  }
  /** {@inheritDoc} */
  @Override
  public long verifyBackend(VerifyConfig verifyConfig)
@@ -771,10 +756,9 @@
     * If the rootContainer is open, the backend is initialized by something else.
     * We can't do any rebuild of system indexes while others are using this backend.
     */
    final ResultCode errorRC = DirectoryServer.getServerErrorResultCode();
    if (!openRootContainer && rebuildConfig.includesSystemIndex())
    {
      throw new DirectoryException(errorRC, ERR_REBUILD_BACKEND_ONLINE.get());
      throw new DirectoryException(getServerErrorResultCode(), ERR_REBUILD_BACKEND_ONLINE.get());
    }
    try
@@ -787,23 +771,23 @@
    }
    catch (ExecutionException execEx)
    {
      throw new DirectoryException(errorRC, ERR_EXECUTION_ERROR.get(execEx.getMessage()), execEx);
      throw new DirectoryException(getServerErrorResultCode(), ERR_EXECUTION_ERROR.get(execEx.getMessage()), execEx);
    }
    catch (InterruptedException intEx)
    {
      throw new DirectoryException(errorRC, ERR_INTERRUPTED_ERROR.get(intEx.getMessage()), intEx);
      throw new DirectoryException(getServerErrorResultCode(), ERR_INTERRUPTED_ERROR.get(intEx.getMessage()), intEx);
    }
    catch (ConfigException ce)
    {
      throw new DirectoryException(errorRC, ce.getMessageObject(), ce);
      throw new DirectoryException(getServerErrorResultCode(), ce.getMessageObject(), ce);
    }
    catch (StorageRuntimeException e)
    {
      throw new DirectoryException(errorRC, LocalizableMessage.raw(e.getMessage()), e);
      throw createDirectoryException(e);
    }
    catch (InitializationException e)
    {
      throw new InitializationException(e.getMessageObject(), e);
      throw e;
    }
    finally
    {
@@ -896,7 +880,7 @@
    }
    catch (Exception e)
    {
      ccr.setResultCode(DirectoryServer.getServerErrorResultCode());
      ccr.setResultCode(getServerErrorResultCode());
      ccr.addMessage(LocalizableMessage.raw(stackTraceToSingleLineString(e)));
    }
    return ccr;
@@ -934,7 +918,7 @@
        {
          logger.traceException(e);
          ccr.setResultCode(DirectoryServer.getServerErrorResultCode());
          ccr.setResultCode(getServerErrorResultCode());
          ccr.addMessage(ERR_BACKEND_CANNOT_REGISTER_BASEDN.get(baseDN, e));
          return false;
        }
@@ -985,14 +969,11 @@
    Throwable cause = e.getCause();
    if (cause instanceof OpenDsException)
    {
      return new DirectoryException(
          DirectoryServer.getServerErrorResultCode(), (OpenDsException) cause);
      return new DirectoryException(getServerErrorResultCode(), (OpenDsException) cause);
    }
    else
    {
      return new DirectoryException(
          DirectoryServer.getServerErrorResultCode(),
          LocalizableMessage.raw(e.getMessage()), e);
      return new DirectoryException(getServerErrorResultCode(), LocalizableMessage.raw(e.getMessage()), e);
    }
  }
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/ImportStrategy.java
@@ -26,6 +26,7 @@
import org.opends.server.core.ServerContext;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.LDIFImportResult;
@@ -36,14 +37,18 @@
   * Imports information from an LDIF file into the supplied root container.
   *
   * @param importConfig
   *          The configuration to use when performing the import.
   *          The configuration to use when performing the import
   * @param rootContainer
   *          The root container where to do the import
   * @param serverContext
   *          The server context
   * @return Information about the result of the import processing.
   * @return Information about the result of the import processing
   * @throws DirectoryException
   *           If a problem occurs while performing the LDIF import.
   *           If a problem occurs while performing the LDIF import
   * @throws InitializationException
   *           If a problem occurs while initializing the LDIF import
   * @see {@link Backend#importLDIF(LDIFImportConfig, ServerContext)}
   */
  LDIFImportResult importLDIF(LDIFImportConfig importConfig, RootContainer rootContainer, ServerContext serverContext)
      throws DirectoryException;
      throws DirectoryException, InitializationException;
}
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Importer.java
@@ -144,18 +144,18 @@
    @Override
    public LDIFImportResult importLDIF(LDIFImportConfig importConfig, RootContainer rootContainer,
        ServerContext serverContext) throws DirectoryException
        ServerContext serverContext) throws DirectoryException, InitializationException
    {
      try
      {
        return new Importer(rootContainer, importConfig, backendCfg, serverContext).processImport();
      }
      catch (DirectoryException e)
      catch (DirectoryException | InitializationException e)
      {
        logger.traceException(e);
        throw e;
      }
      catch (InitializationException | ConfigException e)
      catch (ConfigException e)
      {
        logger.traceException(e);
        throw new DirectoryException(getServerErrorResultCode(), e.getMessageObject(), e);
@@ -640,8 +640,7 @@
    }
  }
  private void initializeSuffixes(WriteableTransaction txn) throws StorageRuntimeException,
      ConfigException
  private void initializeSuffixes(WriteableTransaction txn) throws ConfigException, DirectoryException
  {
    for (EntryContainer ec : rootContainer.getEntryContainers())
    {
@@ -683,7 +682,7 @@
  }
  private Suffix getSuffix(WriteableTransaction txn, EntryContainer entryContainer)
      throws ConfigException
      throws ConfigException, DirectoryException
  {
    DN baseDN = entryContainer.getBaseDN();
    EntryContainer sourceEntryContainer = null;
@@ -754,34 +753,23 @@
            && includeBranches.get(0).equals(baseDN))
        {
          // This entire base DN is explicitly included in the import with
          // no exclude branches that we need to migrate. Just clear the entry
          // container.
          // no exclude branches that we need to migrate.
          // Just clear the entry container.
          clearSuffix(entryContainer);
        }
        else
        {
          // Create a temp entry container
          sourceEntryContainer = entryContainer;
          entryContainer = createEntryContainer(txn, baseDN);
          // Create a temp entry container
          DN tempDN = baseDN.child(DN.valueOf("dc=importTmp"));
          entryContainer = rootContainer.openEntryContainer(tempDN, txn);
        }
      }
    }
    return new Suffix(entryContainer, sourceEntryContainer, includeBranches, excludeBranches);
  }
  private EntryContainer createEntryContainer(WriteableTransaction txn, DN baseDN) throws ConfigException
  {
    try
    {
      DN tempDN = baseDN.child(DN.valueOf("dc=importTmp"));
      return rootContainer.openEntryContainer(tempDN, txn);
    }
    catch (DirectoryException e)
    {
      throw new ConfigException(e.getMessageObject());
    }
  }
  private static void clearSuffix(EntryContainer entryContainer)
  {
    entryContainer.lock();
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/RootContainer.java
@@ -53,12 +53,9 @@
import org.opends.server.backends.pluggable.spi.WriteOperation;
import org.opends.server.backends.pluggable.spi.WriteableTransaction;
import org.opends.server.core.SearchOperation;
import org.opends.server.core.ServerContext;
import org.opends.server.types.DN;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.InitializationException;
import org.opends.server.types.LDIFImportConfig;
import org.opends.server.types.LDIFImportResult;
import org.opends.server.types.Operation;
import org.opends.server.types.Privilege;
@@ -120,17 +117,6 @@
    return storage;
  }
  LDIFImportResult importLDIF(LDIFImportConfig importConfig, ServerContext serverContext) throws DirectoryException
  {
    return getImportStrategy().importLDIF(importConfig, this, serverContext);
  }
  private ImportStrategy getImportStrategy() throws DirectoryException
  {
    //TODO JNR may call new SuccessiveAddsImportStrategy() depending on configured import strategy
    return new Importer.StrategyImpl(config);
  }
  /**
   * Opens the root container.
   *