Exemplo n.º 1
0
 /**
  * Return {@code true} if the specified dn is contained in the parent set, or in the specified DN
  * cache. This would indicate that the parent has already been processed. It returns {@code false}
  * otherwise.
  *
  * <p>It will optionally check the dn2id database for the dn if the specified cleared backend
  * boolean is {@code true}.
  *
  * @param dn The DN to check for.
  * @param dnCache The importer DN cache.
  * @param clearedBackend Set to {@code true} if the import process cleared the backend before
  *     processing.
  * @return {@code true} if the dn is contained in the parent ID, or {@code false} otherwise.
  * @throws DatabaseException If an error occurred searching the DN cache, or dn2id database.
  * @throws InterruptedException If an error occurred processing the pending map.
  */
 public boolean isParentProcessed(DN dn, DNCache dnCache, boolean clearedBackend)
     throws DatabaseException, InterruptedException {
   synchronized (synchObject) {
     if (parentSet.contains(dn)) {
       return true;
     }
   }
   // The DN was not in the parent set. Make sure it isn't pending.
   try {
     assureNotPending(dn);
   } catch (InterruptedException e) {
     logger.error(ERR_IMPORT_LDIF_PENDING_ERR, e.getMessage());
     throw e;
   }
   // Either parent is in the DN cache,
   // or else check the dn2id database for the DN (only if backend wasn't cleared)
   final boolean parentThere =
       dnCache.contains(dn)
           || (!clearedBackend && getDN2ID().get(null, dn, LockMode.DEFAULT) != null);
   // Add the DN to the parent set if needed.
   if (parentThere) {
     synchronized (synchObject) {
       if (parentSet.size() >= PARENT_ID_SET_SIZE) {
         Iterator<DN> iterator = parentSet.iterator();
         iterator.next();
         iterator.remove();
       }
       parentSet.add(dn);
     }
   }
   return parentThere;
 }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void configureBackend(Configuration cfg) throws ConfigException {
    Validator.ensureNotNull(cfg);
    Validator.ensureTrue(cfg instanceof LocalDBBackendCfg);

    this.cfg = (LocalDBBackendCfg) cfg;

    Set<DN> dnSet = this.cfg.getBaseDN();
    baseDNs = new DN[dnSet.size()];
    dnSet.toArray(baseDNs);
  }
Exemplo n.º 3
0
  /** {@inheritDoc} */
  @Override
  public ConfigChangeResult applyConfigurationChange(BackupBackendCfg cfg) {
    ResultCode resultCode = ResultCode.SUCCESS;
    boolean adminActionRequired = false;
    ArrayList<Message> messages = new ArrayList<Message>();

    Set<String> values = cfg.getBackupDirectory();
    backupDirectories = new LinkedHashSet<File>(values.size());
    for (String s : values) {
      backupDirectories.add(getFileForPath(s));
    }

    currentConfig = cfg;
    return new ConfigChangeResult(resultCode, adminActionRequired, messages);
  }
Exemplo n.º 4
0
  /** {@inheritDoc} */
  @Override
  public void initializeBackend() throws ConfigException, InitializationException {
    // Create the set of base DNs that we will handle.  In this case, it's just
    // the DN of the base backup entry.
    try {
      backupBaseDN = DN.decode(DN_BACKUP_ROOT);
    } catch (Exception e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }

      Message message =
          ERR_BACKEND_CANNOT_DECODE_BACKEND_ROOT_DN.get(getExceptionMessage(e), getBackendID());
      throw new InitializationException(message, e);
    }

    // FIXME -- Deal with this more correctly.
    this.baseDNs = new DN[] {backupBaseDN};

    // Determine the set of backup directories that we will use by default.
    Set<String> values = currentConfig.getBackupDirectory();
    backupDirectories = new LinkedHashSet<File>(values.size());
    for (String s : values) {
      backupDirectories.add(getFileForPath(s));
    }

    // Construct the backup base entry.
    LinkedHashMap<ObjectClass, String> objectClasses = new LinkedHashMap<ObjectClass, String>(2);
    objectClasses.put(DirectoryServer.getTopObjectClass(), OC_TOP);

    ObjectClass untypedOC = DirectoryServer.getObjectClass(OC_UNTYPED_OBJECT_LC, true);
    objectClasses.put(untypedOC, OC_UNTYPED_OBJECT);

    LinkedHashMap<AttributeType, List<Attribute>> opAttrs =
        new LinkedHashMap<AttributeType, List<Attribute>>(0);
    LinkedHashMap<AttributeType, List<Attribute>> userAttrs =
        new LinkedHashMap<AttributeType, List<Attribute>>(1);

    RDN rdn = backupBaseDN.getRDN();
    int numAVAs = rdn.getNumValues();
    for (int i = 0; i < numAVAs; i++) {
      AttributeType attrType = rdn.getAttributeType(i);
      ArrayList<Attribute> attrList = new ArrayList<Attribute>(1);
      attrList.add(Attributes.create(attrType, rdn.getAttributeValue(i)));

      userAttrs.put(attrType, attrList);
    }

    backupBaseEntry = new Entry(backupBaseDN, objectClasses, userAttrs, opAttrs);

    currentConfig.addBackupChangeListener(this);

    // Register the backup base as a private suffix.
    try {
      DirectoryServer.registerBaseDN(backupBaseDN, this, true);
    } catch (Exception e) {
      if (debugEnabled()) {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }

      Message message =
          ERR_BACKEND_CANNOT_REGISTER_BASEDN.get(backupBaseDN.toString(), getExceptionMessage(e));
      throw new InitializationException(message, e);
    }
  }