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

Nicolas Capponi
04.05.2016 acdfa16f35b3c3d0c79fad91585b0d03695452e4
OPENDJ-3417 Several minor fixes to apply PR comments

- Fix initialization of BackendConfigManager for client use
- Rename BackendMonitorTestCase to LocalBackendMonitorTestCase
- Other minor fixes
4 files modified
1 files renamed
99 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/api/LocalBackend.java 8 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java 69 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/monitors/LocalBackendMonitorTestCase.java 4 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/api/LocalBackend.java
@@ -731,9 +731,9 @@
   *
   * @param  parentBackend  The parent backend for this backend.
   */
  public final synchronized void setParentBackend(Backend<?> parentBackend)
  public final synchronized void setParentBackend(LocalBackend<?> parentBackend)
  {
    this.parentBackend = (LocalBackend<?>) parentBackend;
    this.parentBackend = parentBackend;
  }
  /**
@@ -756,12 +756,12 @@
   *                             subordinate backends for this
   *                             backend.
   */
  public final synchronized void addSubordinateBackend(Backend<?> subordinateBackend)
  public final synchronized void addSubordinateBackend(LocalBackend<?> subordinateBackend)
  {
    LinkedHashSet<LocalBackend<?>> backendSet = new LinkedHashSet<>();
    Collections.addAll(backendSet, subordinateBackends);
    if (backendSet.add((LocalBackend<?>) subordinateBackend))
    if (backendSet.add(subordinateBackend))
    {
      subordinateBackends = backendSet.toArray(new LocalBackend[backendSet.size()]);
    }
opendj-server-legacy/src/main/java/org/opends/server/backends/RootDSEBackend.java
@@ -426,8 +426,6 @@
  private Set<DN> getTopLevelPublicNamingContexts()
  {
    // TODO: this implementation is insufficient because it handles only the local backends
    // The non-local backends must be added for completeness
    return new HashSet<DN>(serverContext.getBackendConfigManager().getPublicNamingContexts().keySet());
  }
@@ -490,12 +488,7 @@
  @Override
  public boolean entryExists(DN entryDN) throws DirectoryException
  {
    // If the specified DN was the null DN, then it exists.
    if (entryDN.isRootDN())
    {
      return true;
    }
    return false;
    return entryDN.isRootDN();
  }
  @Override
opendj-server-legacy/src/main/java/org/opends/server/core/BackendConfigManager.java
@@ -39,6 +39,7 @@
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageDescriptor.Arg2;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.opendj.config.server.ConfigChangeResult;
import org.forgerock.opendj.config.server.ConfigException;
@@ -160,17 +161,10 @@
      throw new ConfigException(ERR_CONFIG_BACKEND_BASE_DOES_NOT_EXIST.get());
    }
    initializeBackends(backendIDsToStart, root);
    initializeRootDSEBackend();
  }
  /**
   * Creates and initializes the Root DSE backend.
   *
   * @throws InitializationException
   *            If the configuration entry can't be found
   * @throws ConfigException
   *            If an error occurs during configuration
   */
  public void initializeRootDSEBackend() throws InitializationException, ConfigException
  private void initializeRootDSEBackend() throws InitializationException, ConfigException
  {
    RootDSEBackendCfg rootDSECfg;
    try
@@ -180,8 +174,7 @@
    catch (Exception e)
    {
      logger.traceException(e);
      throw new InitializationException(ERR_CANNOT_GET_ROOT_DSE_CONFIG_ENTRY.get(
          stackTraceToSingleLineString(e)), e);
      throw new InitializationException(ERR_CANNOT_GET_ROOT_DSE_CONFIG_ENTRY.get(stackTraceToSingleLineString(e)), e);
    }
    rootDSEBackend = new RootDSEBackend();
    rootDSEBackend.configureBackend(rootDSECfg, serverContext);
@@ -347,7 +340,7 @@
    ccr.addMessage(message);
  }
  private void releaseSharedLock(Backend<?> backend, String backendID)
  private void releaseSharedLock(Arg2<Object, Object> errorMessage, Backend<?> backend, String backendID)
  {
    try
    {
@@ -355,16 +348,13 @@
      StringBuilder failureReason = new StringBuilder();
      if (! LockFileManager.releaseLock(lockFile, failureReason))
      {
        logger.warn(WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK, backendID, failureReason);
        // FIXME -- Do we need to send an admin alert?
        logger.warn(errorMessage, backendID, failureReason);
      }
    }
    catch (Exception e2)
    catch (Exception e)
    {
      logger.traceException(e2);
      logger.warn(WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK, backendID, stackTraceToSingleLineString(e2));
      // FIXME -- Do we need to send an admin alert?
      logger.traceException(e);
      logger.warn(errorMessage, backendID, stackTraceToSingleLineString(e));
    }
  }
@@ -792,7 +782,7 @@
          backend.finalizeBackend();
          releaseSharedLock(backend, backend.getBackendID());
          releaseSharedLock(WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK, backend, backend.getBackendID());
          return ccr;
        } // else already disabled, no need to do anything.
@@ -914,8 +904,7 @@
      registeredBackends.put(backendCfg.dn(), backend);
      return true;
    }
    // TODO: manage proxy registration here
    return true;
    throw new RuntimeException("registerBackend() is not yet supported for proxy backend.");
  }
  @Override
@@ -1073,7 +1062,7 @@
      ccr.addMessage(ERR_CONFIG_BACKEND_CANNOT_INITIALIZE.get(
          cfg.getJavaClass(), cfg.dn(), stackTraceToSingleLineString(e)));
      releaseSharedLock(backend, cfg.getBackendId());
      releaseSharedLock(WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK, backend, cfg.getBackendId());
      return false;
    }
  }
@@ -1113,7 +1102,6 @@
  {
    DN backendDN = configEntry.dn();
    // See if this backend config manager has a backend registered with the
    // provided DN.  If not, then we don't care if the entry is deleted.  If we
    // do know about it, then that means that it is enabled and we will not
@@ -1124,7 +1112,6 @@
      return true;
    }
    // TODO: what about non local backend ?
    if (backend instanceof LocalBackend)
    {
      // See if the backend has any subordinate backends.  If so, then it is not
@@ -1135,8 +1122,9 @@
        unacceptableReason.add(NOTE_CONFIG_BACKEND_CANNOT_REMOVE_BACKEND_WITH_SUBORDINATES.get(backendDN));
        return false;
      }
      return true;
    }
    return true;
    throw new RuntimeException("isConfigurationDeleteAcceptable() is not yet supported for proxy backend.");
  }
  @Override
@@ -1153,7 +1141,6 @@
      return ccr;
    }
    // TODO: what about non local backend ?
    if (backend instanceof LocalBackend)
    {
      // See if the backend has any subordinate backends.  If so, then it is not
@@ -1166,6 +1153,10 @@
        return ccr;
      }
    }
    else
    {
      throw new RuntimeException("applyConfigurationDelete() is not yet supported for proxy backend.");
    }
    deregisterBackend(backendDN, backend);
@@ -1180,7 +1171,7 @@
    configEntry.removeChangeListener(this);
    releaseSharedLock(backend, backend.getBackendID());
    releaseSharedLock(WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK, backend, backend.getBackendID());
    return ccr;
  }
@@ -1204,7 +1195,7 @@
      }
    }
    else {
      // TODO: manage proxy deregistering here
      throw new RuntimeException("deregisterBackend() is not yet supported for proxy backend.");
    }
  }
@@ -1227,25 +1218,7 @@
          listener.performBackendPostFinalizationProcessing(backend);
        }
        // Remove the shared lock for this backend.
        try
        {
          String lockFile = LockFileManager.getBackendLockFileName(backend);
          StringBuilder failureReason = new StringBuilder();
          if (!LockFileManager.releaseLock(lockFile, failureReason))
          {
            logger.warn(WARN_SHUTDOWN_CANNOT_RELEASE_SHARED_BACKEND_LOCK, backend.getBackendID(), failureReason);
            // FIXME -- Do we need to send an admin alert?
          }
        }
        catch (Exception e2)
        {
          logger.traceException(e2);
          logger.warn(WARN_SHUTDOWN_CANNOT_RELEASE_SHARED_BACKEND_LOCK, backend.getBackendID(),
              stackTraceToSingleLineString(e2));
          // FIXME -- Do we need to send an admin alert?
        }
        releaseSharedLock(WARN_SHUTDOWN_CANNOT_RELEASE_SHARED_BACKEND_LOCK, backend, backend.getBackendID());
      }
      catch (Exception e)
      {
opendj-server-legacy/src/main/java/org/opends/server/core/DirectoryServer.java
@@ -868,6 +868,7 @@
      try
      {
        directoryServer.initializeBackendConfigManager();
        directoryServer.initializeRootAndAdminDataBackends();
      }
      catch (InitializationException | ConfigException e)
@@ -1481,7 +1482,7 @@
      new AlertHandlerConfigManager(serverContext).initializeAlertHandlers();
      backendConfigManager = new BackendConfigManager(serverContext);
      initializeBackendConfigManager();
      // Initialize the default entry cache. We have to have one before
      // <CODE>initializeRootAndAdminDataBackends()</CODE> method kicks in further down.
@@ -1608,6 +1609,11 @@
    }
  }
  private void initializeBackendConfigManager()
  {
    backendConfigManager = new BackendConfigManager(serverContext);
  }
  /** Delete "server.starting" and "hostname" files if they are present. */
  private void deleteUnnecessaryFiles()
  {
@@ -1754,7 +1760,6 @@
  private void initializeRootAndAdminDataBackends() throws ConfigException, InitializationException
  {
    backendConfigManager.initializeBackendConfig(Arrays.asList("adminRoot", "ads-truststore"));
    backendConfigManager.initializeRootDSEBackend();
  }
  private void initializeRemainingBackends() throws ConfigException, InitializationException
opendj-server-legacy/src/test/java/org/opends/server/monitors/LocalBackendMonitorTestCase.java
File was renamed from opendj-server-legacy/src/test/java/org/opends/server/monitors/BackendMonitorTestCase.java
@@ -22,14 +22,14 @@
/** This class defines a set of tests for the {@link LocalBackendMonitor} class. */
@Test
public class BackendMonitorTestCase extends GenericMonitorTestCase
public class LocalBackendMonitorTestCase extends GenericMonitorTestCase
{
  /**
   * Creates a new instance of this test case class.
   *
   * @throws  Exception  If an unexpected problem occurred.
   */
  public BackendMonitorTestCase() throws Exception
  public LocalBackendMonitorTestCase() throws Exception
  {
    super(null);
  }