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

Jean-Noël Rouvignac
19.03.2016 17ec2cfa9d04e6942a694ab5c3778ac26f17bb35
opendj-server-legacy/src/main/java/org/opends/server/backends/MonitorBackend.java
@@ -24,6 +24,7 @@
import static org.opends.server.util.ServerConstants.*;
import static org.opends.server.util.StaticUtils.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -89,7 +90,7 @@
{
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
  /** The set of user-defined attributes that will be included in the base monitor entry.   */
  /** The set of user-defined attributes that will be included in the base monitor entry. */
  private ArrayList<Attribute> userDefinedAttributes;
  /** The set of objectclasses that will be used in monitor entries. */
  private final HashMap<ObjectClass, String> monitorObjectClasses = new LinkedHashMap<>(2);
@@ -112,7 +113,6 @@
    super();
  }
  /** {@inheritDoc} */
  @Override
  public void addEntry(final Entry entry, final AddOperation addOperation)
      throws DirectoryException
@@ -121,7 +121,6 @@
        ERR_BACKEND_ADD_NOT_SUPPORTED.get(entry.getName(), getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public ConfigChangeResult applyConfigurationChange(
      final MonitorBackendCfg backendCfg)
@@ -226,7 +225,6 @@
    addAllNonMonitorConfigAttributes(attributes, attributesToAdd);
  }
  /** {@inheritDoc} */
  @Override
  public void createBackup(final BackupConfig backupConfig)
      throws DirectoryException
@@ -235,7 +233,6 @@
        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void deleteEntry(final DN entryDN,
      final DeleteOperation deleteOperation) throws DirectoryException
@@ -244,77 +241,69 @@
        ERR_BACKEND_DELETE_NOT_SUPPORTED.get(entryDN, getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public boolean entryExists(final DN entryDN) throws DirectoryException
  {
    return getDIT().containsKey(entryDN);
  }
  /** {@inheritDoc} */
  @Override
  public void exportLDIF(final LDIFExportConfig exportConfig)
      throws DirectoryException
  {
    // TODO export-ldif reports nonsense for upTime etc.
    // Create the LDIF writer.
    LDIFWriter ldifWriter;
    try
    try (LDIFWriter ldifWriter = newLDIFWriter(exportConfig))
    {
      ldifWriter = new LDIFWriter(exportConfig);
    }
    catch (final Exception e)
    {
      logger.traceException(e);
      final LocalizableMessage message = ERR_ROOTDSE_UNABLE_TO_CREATE_LDIF_WRITER
          .get(stackTraceToSingleLineString(e));
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    }
    // Write the base monitor entry to the LDIF.
    try
    {
      ldifWriter.writeEntry(getBaseMonitorEntry());
    }
    catch (final Exception e)
    {
      logger.traceException(e);
      close(ldifWriter);
      final LocalizableMessage message = ERR_MONITOR_UNABLE_TO_EXPORT_BASE
          .get(stackTraceToSingleLineString(e));
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    }
    // Get all the monitor providers, convert them to entries, and write them to
    // LDIF.
    for (final MonitorProvider<?> monitorProvider : DirectoryServer
        .getMonitorProviders().values())
    {
      // Write the base monitor entry to the LDIF.
      try
      {
        // TODO implementation of export is incomplete
        ldifWriter.writeEntry(getBaseMonitorEntry());
      }
      catch (final Exception e)
      {
        logger.traceException(e);
        final LocalizableMessage message = ERR_MONITOR_UNABLE_TO_EXPORT_BASE.get(stackTraceToSingleLineString(e));
        throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
      }
        close(ldifWriter);
        final LocalizableMessage message = ERR_MONITOR_UNABLE_TO_EXPORT_PROVIDER_ENTRY
            .get(monitorProvider.getMonitorInstanceName(), stackTraceToSingleLineString(e));
        throw new DirectoryException(
            DirectoryServer.getServerErrorResultCode(), message);
      // Get all the monitor providers, convert them to entries, and write them to LDIF.
      for (final MonitorProvider<?> monitorProvider : DirectoryServer.getMonitorProviders().values())
      {
        try
        {
          // TODO implementation of export is incomplete
        }
        catch (final Exception e)
        {
          logger.traceException(e);
          final LocalizableMessage message =
              ERR_MONITOR_UNABLE_TO_EXPORT_PROVIDER_ENTRY.get(monitorProvider.getMonitorInstanceName(),
                  stackTraceToSingleLineString(e));
          throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
        }
      }
    }
    close(ldifWriter);
    catch (IOException ignoreOnClose)
    {
      logger.traceException(ignoreOnClose);
    }
  }
  /** {@inheritDoc} */
  private LDIFWriter newLDIFWriter(final LDIFExportConfig exportConfig) throws DirectoryException
  {
    try
    {
      return new LDIFWriter(exportConfig);
    }
    catch (final Exception e)
    {
      logger.traceException(e);
      final LocalizableMessage message = ERR_ROOTDSE_UNABLE_TO_CREATE_LDIF_WRITER.get(stackTraceToSingleLineString(e));
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(), message);
    }
  }
  @Override
  public void closeBackend()
  {
@@ -364,28 +353,24 @@
    return getEntry(entryDN, dit);
  }
  /** {@inheritDoc} */
  @Override
  public long getEntryCount()
  {
    return getDIT().size();
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getSupportedControls()
  {
    return Collections.emptySet();
  }
  /** {@inheritDoc} */
  @Override
  public Set<String> getSupportedFeatures()
  {
    return Collections.emptySet();
  }
  /** {@inheritDoc} */
  @Override
  public ConditionResult hasSubordinates(final DN entryDN)
      throws DirectoryException
@@ -399,7 +384,6 @@
    return ConditionResult.UNDEFINED;
  }
  /** {@inheritDoc} */
  @Override
  public LDIFImportResult importLDIF(final LDIFImportConfig importConfig, ServerContext serverContext)
      throws DirectoryException
@@ -408,7 +392,6 @@
        ERR_BACKEND_IMPORT_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void openBackend() throws ConfigException, InitializationException
  {
@@ -430,7 +413,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean isConfigurationChangeAcceptable(
      final MonitorBackendCfg backendCfg,
@@ -441,7 +423,6 @@
    return true;
  }
  /** {@inheritDoc} */
  @Override
  public boolean isIndexed(final AttributeType attributeType,
      final IndexType indexType)
@@ -450,14 +431,12 @@
    return true;
  }
  /** {@inheritDoc} */
  @Override
  public long getNumberOfEntriesInBaseDN(final DN baseDN) throws DirectoryException {
    checkNotNull(baseDN, "baseDN must not be null");
    return getNumberOfSubordinates(baseDN, true) + 1;
  }
  /** {@inheritDoc} */
  @Override
  public long getNumberOfChildren(final DN parentDN) throws DirectoryException {
    checkNotNull(parentDN, "parentDN must not be null");
@@ -487,7 +466,6 @@
    return count;
  }
  /** {@inheritDoc} */
  @Override
  public void removeBackup(final BackupDirectory backupDirectory,
      final String backupID) throws DirectoryException
@@ -496,7 +474,6 @@
        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void renameEntry(final DN currentDN, final Entry entry,
      final ModifyDNOperation modifyDNOperation) throws DirectoryException
@@ -505,7 +482,6 @@
        ERR_BACKEND_MODIFY_DN_NOT_SUPPORTED.get(currentDN, getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void replaceEntry(final Entry oldEntry, final Entry newEntry,
      final ModifyOperation modifyOperation) throws DirectoryException
@@ -514,7 +490,6 @@
        ERR_MONITOR_MODIFY_NOT_SUPPORTED.get(newEntry.getName(), configEntryDN));
  }
  /** {@inheritDoc} */
  @Override
  public void restoreBackup(final RestoreConfig restoreConfig)
      throws DirectoryException
@@ -523,7 +498,6 @@
        ERR_BACKEND_BACKUP_AND_RESTORE_NOT_SUPPORTED.get(getBackendID()));
  }
  /** {@inheritDoc} */
  @Override
  public void search(final SearchOperation searchOperation)
      throws DirectoryException
@@ -574,7 +548,6 @@
    }
  }
  /** {@inheritDoc} */
  @Override
  public boolean supports(BackendOperation backendOperation)
  {
@@ -709,8 +682,6 @@
    return dit;
  }
  /**
   * Creates the monitor entry having the specified DN.
   *
@@ -741,8 +712,6 @@
    }
  }
  /**
   * Generates and returns a monitor entry based on the contents of the provided
   * monitor provider.