Package org.nasutekds.server.api

Examples of org.nasutekds.server.api.Backend


    // configuration manager could have finalized the object right before.
    if (configuration.isEnabled())
    {
      // Read configuration.
      String newBackendID = configuration.getBackend();
      Backend newBackend  = DirectoryServer.getBackend(newBackendID);

      // If the backend is null (i.e. not found in the list of
      // registered backends, this is probably because we are looking
      // for the config backend
      if (newBackend == null) {
View Full Code Here


    for (AttributeType t : attributeTypes)
    {
      for (DN baseDN : cfgBaseDNs)
      {
        Backend b = DirectoryServer.getBackend(baseDN);
        if ((b != null) && (! b.isIndexed(t, IndexType.EQUALITY)))
        {
          throw new ConfigException(ERR_REGEXMAP_ATTR_UNINDEXED.get(
                                         configuration.dn().toString(),
                                         t.getNameOrOID(),
                                         b.getBackendID()));
        }
      }
    }

View Full Code Here

    for (AttributeType t : configuration.getMatchAttribute())
    {
      for (DN baseDN : cfgBaseDNs)
      {
        Backend b = DirectoryServer.getBackend(baseDN);
        if ((b != null) && (! b.isIndexed(t, IndexType.EQUALITY)))
        {
          unacceptableReasons.add(ERR_REGEXMAP_ATTR_UNINDEXED.get(
                                       configuration.dn().toString(),
                                       t.getNameOrOID(),
                                       b.getBackendID()));
          configAcceptable = false;
        }
      }
    }
View Full Code Here

      DN newDN = parentDN.concat(newRDN);

      // Get the backend for the current entry, and the backend for the new
      // entry.  If either is null, or if they are different, then fail.
      Backend currentBackend = backend;
      if (currentBackend == null)
      {
        setResultCode(ResultCode.NO_SUCH_OBJECT);
        appendErrorMessage(ERR_MODDN_NO_BACKEND_FOR_CURRENT_ENTRY.get(
                                String.valueOf(entryDN)));
        break modifyDNProcessing;
      }

      Backend newBackend = DirectoryServer.getBackend(newDN);
      if (newBackend == null)
      {
        setResultCode(ResultCode.NO_SUCH_OBJECT);
        appendErrorMessage(ERR_MODDN_NO_BACKEND_FOR_NEW_ENTRY.get(
                                String.valueOf(entryDN),
View Full Code Here

        // contain a valid backend implementation, then log an error and skip
        // it.
        String className = backendCfg.getJavaClass();
        Class backendClass;

        Backend backend;
        try
        {
          backendClass = DirectoryServer.loadClass(className);
          backend = (Backend) backendClass.newInstance();
        }
        catch (Exception e)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
          }

          Message message = ERR_CONFIG_BACKEND_CANNOT_INSTANTIATE.
              get(String.valueOf(className), String.valueOf(backendDN),
                  stackTraceToSingleLineString(e));
          logError(message);
          continue;
        }


        // If this backend is a configuration manager, then we don't want to do
        // any more with it because the configuration will have already been
        // started.
        if (backend instanceof ConfigHandler)
        {
          continue;
        }


        // See if the entry contains an attribute that specifies the writability
        // mode.
        WritabilityMode writabilityMode = WritabilityMode.ENABLED;
        BackendCfgDefn.WritabilityMode bwm =
             backendCfg.getWritabilityMode();
        switch (bwm)
        {
          case DISABLED:
            writabilityMode = WritabilityMode.DISABLED;
            break;
          case ENABLED:
            writabilityMode = WritabilityMode.ENABLED;
            break;
          case INTERNAL_ONLY:
            writabilityMode = WritabilityMode.INTERNAL_ONLY;
            break;
        }

        // Set the backend ID and writability mode for this backend.
        backend.setBackendID(backendID);
        backend.setWritabilityMode(writabilityMode);


        // Acquire a shared lock on this backend.  This will prevent operations
        // like LDIF import or restore from occurring while the backend is
        // active.
View Full Code Here

    Set<DN> baseDNs = configEntry.getBaseDN();

    // See if the backend is registered with the server.  If it is, then
    // see what's changed and whether those changes are acceptable.
    Backend backend = registeredBackends.get(backendDN);
    if (backend != null)
    {
      LinkedHashSet<DN> removedDNs = new LinkedHashSet<DN>();
      for (DN dn : backend.getBaseDNs())
      {
        removedDNs.add(dn);
      }

      LinkedHashSet<DN> addedDNs = new LinkedHashSet<DN>();
      for (DN dn : baseDNs)
      {
        addedDNs.add(dn);
      }

      Iterator<DN> iterator = removedDNs.iterator();
      while (iterator.hasNext())
      {
        DN dn = iterator.next();
        if (addedDNs.remove(dn))
        {
          iterator.remove();
        }
      }

      // Copy the directory server's base DN registry and make the
      // requested changes to see if it complains.
      BaseDnRegistry reg = DirectoryServer.copyBaseDnRegistry();
      for (DN dn : removedDNs)
      {
        try
        {
          reg.deregisterBaseDN(dn);
        }
        catch (DirectoryException de)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, de);
          }

          unacceptableReason.add(de.getMessageObject());
          return false;
        }
      }

      for (DN dn : addedDNs)
      {
        try
        {
          reg.registerBaseDN(dn, backend, false);
        }
        catch (DirectoryException de)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, de);
          }

          unacceptableReason.add(de.getMessageObject());
          return false;
        }
      }
    }


    // See if the entry contains an attribute that specifies the class name
    // for the backend implementation.  If it does, then load it and make sure
    // that it's a valid backend implementation.  There is no such attribute,
    // the specified class cannot be loaded, or it does not contain a valid
    // backend implementation, then log an error and skip it.
    String className = configEntry.getJavaClass();
    try
    {
      Class backendClass = DirectoryServer.loadClass(className);
      if (! Backend.class.isAssignableFrom(backendClass))
      {

        unacceptableReason.add(ERR_CONFIG_BACKEND_CLASS_NOT_BACKEND.get(
                String.valueOf(className), String.valueOf(backendDN)));
        return false;
      }

      Backend b = (Backend) backendClass.newInstance();
      if (! b.isConfigurationAcceptable(configEntry, unacceptableReason))
      {
        return false;
      }
    }
    catch (Exception e)
View Full Code Here

   * {@inheritDoc}
   */
  public ConfigChangeResult applyConfigurationChange(BackendCfg cfg)
  {
    DN                 backendDN           = cfg.dn();
    Backend            backend             = registeredBackends.get(backendDN);
    ResultCode         resultCode          = ResultCode.SUCCESS;
    boolean            adminActionRequired = false;
    ArrayList<Message> messages            = new ArrayList<Message>();


    // See if the entry contains an attribute that indicates whether the
    // backend should be enabled.
    boolean needToEnable = false;
    try
    {
      if (cfg.isEnabled())
      {
        // The backend is marked as enabled.  See if that is already true.
        if (backend == null)
        {
          needToEnable = true;
        }
        else
        {
          // It's already enabled, so we don't need to do anything.
        }
      }
      else
      {
        // The backend is marked as disabled.  See if that is already true.
        if (backend != null)
        {
          // It isn't disabled, so we will do so now and deregister it from the
          // Directory Server.
          registeredBackends.remove(backendDN);
          DirectoryServer.deregisterBackend(backend);

          for (BackendInitializationListener listener :
               DirectoryServer.getBackendInitializationListeners())
          {
            listener.performBackendFinalizationProcessing(backend);
          }

          backend.finalizeBackend();

          // Remove the shared lock for this backend.
          try
          {
            String lockFile = LockFileManager.getBackendLockFileName(backend);
            StringBuilder failureReason = new StringBuilder();
            if (! LockFileManager.releaseLock(lockFile, failureReason))
            {
              Message message = WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK.
                  get(backend.getBackendID(), String.valueOf(failureReason));
              logError(message);
              // FIXME -- Do we need to send an admin alert?
            }
          }
          catch (Exception e2)
          {
            if (debugEnabled())
            {
              TRACER.debugCaught(DebugLogLevel.ERROR, e2);
            }

            Message message = WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK.
                get(backend.getBackendID(), stackTraceToSingleLineString(e2));
            logError(message);
            // FIXME -- Do we need to send an admin alert?
          }

          return new ConfigChangeResult(resultCode, adminActionRequired,
                                        messages);
        }
        else
        {
          // It's already disabled, so we don't need to do anything.
        }
      }
    }
    catch (Exception e)
    {
      if (debugEnabled())
      {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }


      messages.add(ERR_CONFIG_BACKEND_UNABLE_TO_DETERMINE_ENABLED_STATE.get(
              String.valueOf(backendDN), stackTraceToSingleLineString(e)));
      resultCode = DirectoryServer.getServerErrorResultCode();
      return new ConfigChangeResult(resultCode, adminActionRequired, messages);
    }


    // See if the entry contains an attribute that specifies the backend ID for
    // the backend.
    String backendID = cfg.getBackendId();

    // See if the entry contains an attribute that specifies the writability
    // mode.
    WritabilityMode writabilityMode = WritabilityMode.ENABLED;
    BackendCfgDefn.WritabilityMode bwm =
         cfg.getWritabilityMode();
    switch (bwm)
    {
      case DISABLED:
        writabilityMode = WritabilityMode.DISABLED;
        break;
      case ENABLED:
        writabilityMode = WritabilityMode.ENABLED;
        break;
      case INTERNAL_ONLY:
        writabilityMode = WritabilityMode.INTERNAL_ONLY;
        break;
    }


    // See if the entry contains an attribute that specifies the base DNs for
    // the backend.
    Set<DN> baseList = cfg.getBaseDN();
    DN[] baseDNs = new DN[baseList.size()];
    baseList.toArray(baseDNs);


    // See if the entry contains an attribute that specifies the class name
    // for the backend implementation.  If it does, then load it and make sure
    // that it's a valid backend implementation.  There is no such attribute,
    // the specified class cannot be loaded, or it does not contain a valid
    // backend implementation, then log an error and skip it.
    String className = cfg.getJavaClass();


    // See if this backend is currently active and if so if the name of the
    // class is the same.
    if (backend != null)
    {
      if (! className.equals(backend.getClass().getName()))
      {
        // It is not the same.  Try to load it and see if it is a valid backend
        // implementation.
        try
        {
          Class backendClass = DirectoryServer.loadClass(className);
          if (Backend.class.isAssignableFrom(backendClass))
          {
            // It appears to be a valid backend class.  We'll return that the
            // change is successful, but indicate that some administrative
            // action is required.

            messages.add(
                    NOTE_CONFIG_BACKEND_ACTION_REQUIRED_TO_CHANGE_CLASS.get(
                            String.valueOf(backendDN),
                            backend.getClass().getName(), className));
            adminActionRequired = true;
            return new ConfigChangeResult(resultCode, adminActionRequired,
                                          messages);
          }
          else
          {
            // It is not a valid backend class.  This is an error.

            messages.add(ERR_CONFIG_BACKEND_CLASS_NOT_BACKEND.get(
                    String.valueOf(className), String.valueOf(backendDN)));
            resultCode = ResultCode.CONSTRAINT_VIOLATION;
            return new ConfigChangeResult(resultCode, adminActionRequired,
                                          messages);
          }
        }
        catch (Exception e)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, e);
          }


          messages.add(ERR_CONFIG_BACKEND_CANNOT_INSTANTIATE.get(
                  String.valueOf(className), String.valueOf(backendDN),
                  stackTraceToSingleLineString(e)));
          resultCode = DirectoryServer.getServerErrorResultCode();
          return new ConfigChangeResult(resultCode, adminActionRequired,
                                        messages);
        }
      }
    }


    // If we've gotten here, then that should mean that we need to enable the
    // backend.  Try to do so.
    if (needToEnable)
    {
      Class backendClass;
      try
      {
        backendClass = DirectoryServer.loadClass(className);
        backend = (Backend) backendClass.newInstance();
      }
      catch (Exception e)
      {
        // It is not a valid backend class.  This is an error.

        messages.add(ERR_CONFIG_BACKEND_CLASS_NOT_BACKEND.get(
                String.valueOf(className), String.valueOf(backendDN)));
        resultCode = ResultCode.CONSTRAINT_VIOLATION;
        return new ConfigChangeResult(resultCode, adminActionRequired,
                                      messages);
      }


      // Set the backend ID and writability mode for this backend.
      backend.setBackendID(backendID);
      backend.setWritabilityMode(writabilityMode);


      // Acquire a shared lock on this backend.  This will prevent operations
      // like LDIF import or restore from occurring while the backend is active.
      try
      {
        String lockFile = LockFileManager.getBackendLockFileName(backend);
        StringBuilder failureReason = new StringBuilder();
        if (! LockFileManager.acquireSharedLock(lockFile, failureReason))
        {
          Message message = ERR_CONFIG_BACKEND_CANNOT_ACQUIRE_SHARED_LOCK.get(
              backendID, String.valueOf(failureReason));
          logError(message);
          // FIXME -- Do we need to send an admin alert?

          resultCode = ResultCode.CONSTRAINT_VIOLATION;
          adminActionRequired = true;
          messages.add(message);
          return new ConfigChangeResult(resultCode, adminActionRequired,
                                        messages);
        }
      }
      catch (Exception e)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }

        Message message = ERR_CONFIG_BACKEND_CANNOT_ACQUIRE_SHARED_LOCK.get(
            backendID, stackTraceToSingleLineString(e));
        logError(message);
        // FIXME -- Do we need to send an admin alert?

        resultCode = ResultCode.CONSTRAINT_VIOLATION;
        adminActionRequired = true;
        messages.add(message);
        return new ConfigChangeResult(resultCode, adminActionRequired,
                                      messages);
      }


      try
      {
        initializeBackend(backend, cfg);
      }
      catch (Exception e)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }

        messages.add(ERR_CONFIG_BACKEND_CANNOT_INITIALIZE.get(
                String.valueOf(className), String.valueOf(backendDN),
                stackTraceToSingleLineString(e)));
        resultCode = DirectoryServer.getServerErrorResultCode();

        try
        {
          String lockFile = LockFileManager.getBackendLockFileName(backend);
          StringBuilder failureReason = new StringBuilder();
          if (! LockFileManager.releaseLock(lockFile, failureReason))
          {
            Message message = WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK.
                get(backendID, String.valueOf(failureReason));
            logError(message);
            // FIXME -- Do we need to send an admin alert?
          }
        }
        catch (Exception e2)
        {
          if (debugEnabled())
          {
            TRACER.debugCaught(DebugLogLevel.ERROR, e2);
          }

          Message message = WARN_CONFIG_BACKEND_CANNOT_RELEASE_SHARED_LOCK.get(
              backendID, stackTraceToSingleLineString(e2));
          logError(message);
          // FIXME -- Do we need to send an admin alert?
        }

        return new ConfigChangeResult(resultCode, adminActionRequired,
                                      messages);
      }


      // Notify any backend initialization listeners.
      for (BackendInitializationListener listener :
           DirectoryServer.getBackendInitializationListeners())
      {
        listener.performBackendInitializationProcessing(backend);
      }


      // Register the backend with the server.
      try
      {
        DirectoryServer.registerBackend(backend);
      }
      catch (Exception e)
      {
        if (debugEnabled())
        {
          TRACER.debugCaught(DebugLogLevel.ERROR, e);
        }

        Message message = WARN_CONFIG_BACKEND_CANNOT_REGISTER_BACKEND.get(
                backendID, getExceptionMessage(e));

        resultCode = DirectoryServer.getServerErrorResultCode();
        messages.add(message);

        logError(message);
        // FIXME -- Do we need to send an admin alert?

        return new ConfigChangeResult(resultCode, adminActionRequired,
                                      messages);
      }


      registeredBackends.put(backendDN, backend);
    }
    else if ((resultCode == ResultCode.SUCCESS) && (backend != null))
    {
      // The backend is already enabled, so we may need to apply a
      // configuration change.  Check to see if the writability mode has been
      // changed.
      if (writabilityMode != backend.getWritabilityMode())
      {
        backend.setWritabilityMode(writabilityMode);
      }
    }


    return new ConfigChangeResult(resultCode, adminActionRequired, messages);
View Full Code Here

    // that it's a valid backend implementation.  There is no such attribute,
    // the specified class cannot be loaded, or it does not contain a valid
    // backend implementation, then log an error and skip it.
    String className = configEntry.getJavaClass();

    Backend backend;
    try
    {
      Class backendClass = DirectoryServer.loadClass(className);
      backend = (Backend) backendClass.newInstance();
    }
View Full Code Here

    // the specified class cannot be loaded, or it does not contain a valid
    // backend implementation, then log an error and skip it.
    String className = cfg.getJavaClass();
    Class backendClass;

    Backend backend;
    try
    {
      backendClass = DirectoryServer.loadClass(className);
      backend = (Backend) backendClass.newInstance();
    }
    catch (Exception e)
    {
      if (debugEnabled())
      {
        TRACER.debugCaught(DebugLogLevel.ERROR, e);
      }

      messages.add(ERR_CONFIG_BACKEND_CANNOT_INSTANTIATE.get(
              String.valueOf(className),
              String.valueOf(backendDN),
              stackTraceToSingleLineString(e)));
      resultCode = DirectoryServer.getServerErrorResultCode();
      return new ConfigChangeResult(resultCode, adminActionRequired,
                                    messages);
    }


    // Set the backend ID and writability mode for this backend.
    backend.setBackendID(backendID);
    backend.setWritabilityMode(writabilityMode);


    // Acquire a shared lock on this backend.  This will prevent operations
    // like LDIF import or restore from occurring while the backend is active.
    try
View Full Code Here

    // 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
    // allow removing a backend that is enabled.
    Backend backend = registeredBackends.get(backendDN);
    if (backend == null)
    {
      return true;
    }


    // See if the backend has any subordinate backends.  If so, then it is not
    // acceptable to remove it.  Otherwise, it should be fine.
    Backend[] subBackends = backend.getSubordinateBackends();
    if ((subBackends == null) || (subBackends.length == 0))
    {
      return true;
    }
    else
View Full Code Here

TOP

Related Classes of org.nasutekds.server.api.Backend

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.