BackendConfigManager.java revision f4d85fde4c95d5f49f683641815e0463d6166720
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at
* trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
* add the following below this CDDL HEADER, with the fields enclosed
* by brackets "[]" replaced with your own identifying information:
* Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
*
* Portions Copyright 2006-2007 Sun Microsystems, Inc.
*/
/**
* This class defines a utility that will be used to manage the configuration
* for the set of backends defined in the Directory Server. It will perform
* the necessary initialization of those backends when the server is first
* started, and then will manage any changes to them while the server is
* running.
*/
public class BackendConfigManager
{
// The mapping between configuration entry DNs and their corresponding
// backend implementations.
// The DN of the associated configuration entry.
private DN configEntryDN;
/**
* Creates a new instance of this backend config manager.
*/
public BackendConfigManager()
{
// No implementation is required.
}
/**
* Initializes the configuration associated with the Directory Server
* backends. This should only be called at Directory Server startup.
*
* @throws ConfigException If a critical configuration problem prevents the
* backend initialization from succeeding.
*
* @throws InitializationException If a problem occurs while initializing
* the backends that is not related to the
* server configuration.
*/
public void initializeBackendConfig()
{
// Get the configuration entry that is at the root of all the backends in
// the server.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// If the configuration root entry is null, then assume it doesn't exist.
// In that case, then fail. At least that entry must exist in the
// configuration, even if there are no backends defined below it.
if (backendRoot == null)
{
}
// Register as an add and delete listener for the base entry so that we can
// be notified if new backends are added or existing backends are removed.
backendRoot.registerAddListener(this);
// Iterate through the set of immediate children below the backend config
// root.
{
// Register as a change listener for this backend entry so that we will
// be notified of any changes that may be made to it.
// Check to see if this entry appears to contain a backend configuration.
// If not, log a warning and skip it.
try
{
")");
{
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
continue;
}
// See if the entry contains an attribute that indicates whether the
// backend should be enabled. If it does not, or if it is not set to
// "true", then skip it.
false);
try
{
if (enabledAttr == null)
{
// The attribute is not present, so this backend will be disabled.
// Log a message and continue.
continue;
}
else if (! enabledAttr.activeValue())
{
// The backend is explicitly disabled. Log a mild warning and
// continue.
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
continue;
}
// See if the entry contains an attribute that specifies the backend ID.
// If it does not, then log an error and skip it.
true, false, true);
try
{
{
continue;
}
else
{
// If there is already a backend registered with the specified ID,
// then log an error and skip it.
{
continue;
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
continue;
}
// Get the writability mode for this backend. It must be provided.
getMessage(msgID), true, false, false,
try
{
if (writabilityAttr == null)
{
continue;
}
else
{
if (writabilityMode == null)
{
continue;
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
continue;
}
// See if the entry contains an attribute that specifies the base DNs for
// the backend. If it does not, then log an error and skip it.
true, true, true);
try
{
if (baseDNAttr == null)
{
continue;
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
continue;
}
// 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.
true, false, true);
try
{
{
continue;
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
continue;
}
try
{
// FIXME -- Should we use a custom class loader for this?
}
catch (Exception e)
{
if (debugEnabled())
{
}
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;
}
// Set the backend ID and writability mode for this backend.
// Acquire a shared lock on this backend. This will prevent operations
// like LDIF import or restore from occurring while the backend is active.
try
{
{
// FIXME -- Do we need to send an admin alert?
continue;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
continue;
}
// Perform the necessary initialization for the backend entry.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
try
{
{
// FIXME -- Do we need to send an admin alert?
}
}
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
}
continue;
}
// Notify any backend initialization listeners.
{
}
// Register the backend with the server.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
}
// Put this backend in the hash so that we will be able to find it if it
// is altered.
}
}
/**
* Indicates whether the configuration entry that will result from a proposed
* modification is acceptable to this change listener.
*
* @param configEntry The configuration entry that will result from
* the requested update.
* @param unacceptableReason A buffer to which this method can append a
* human-readable message explaining why the
* proposed change is not acceptable.
*
* @return <CODE>true</CODE> if the proposed entry contains an acceptable
* configuration, or <CODE>false</CODE> if it does not.
*/
{
// Check to see if this entry appears to contain a backend configuration.
// If not, log a warning and skip it.
try
{
")");
{
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that indicates whether the
// backend should be enabled. If it does not, or if it is not set to
// "true", then skip it.
false);
try
{
if (enabledAttr == null)
{
// The attribute is not present, so this backend will be disabled.
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that specifies the backend ID. If
// it does not, then reject it.
false, true);
try
{
{
// The attribute is not present. We will not allow this.
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that specifies the writability
// mode. If it does not, then reject it.
getMessage(msgID), true, false, false,
try
{
if (writabilityAttr == null)
{
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that specifies the set of base DNs
// for the backend. If it does not, then skip it.
true, true);
try
{
if (baseDNAttr == null)
{
// The attribute is not present. We will not allow this.
return false;
}
// See if the backend is registered with the server. If it is, then
// see what's changed and whether those changes are acceptable.
{
{
}
{
}
{
{
}
}
{
try
{
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
return false;
}
}
{
try
{
}
catch (DirectoryException de)
{
if (debugEnabled())
{
}
return false;
}
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
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.
true, false, true);
try
{
{
return false;
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
try
{
// FIXME -- Should we use a custom class loader for this?
{
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// If we've gotten to this point, then it is acceptable as far as we are
// concerned. If it is unacceptable according to the configuration for that
// backend, then the backend itself will need to make that determination.
return true;
}
/**
* Attempts to apply a new configuration to this Directory Server component
* based on the provided changed entry.
*
* @param configEntry The configuration entry that containing the updated
* configuration for this component.
*
* @return Information about the result of processing the configuration
* change.
*/
{
boolean adminActionRequired = false;
// Check to see if this entry appears to contain a backend configuration.
// If not, log a warning and skip it.
try
{
")");
{
messages);
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that indicates whether the
// backend should be enabled.
boolean needToEnable = false;
false);
try
{
if (enabledAttr == null)
{
// The attribute is not present. We won't allow this.
messages);
}
else if (enabledAttr.pendingValue())
{
// The backend is marked as enabled. See if that is already true.
{
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.
{
// It isn't disabled, so we will do so now and deregister it from the
// Directory Server.
{
}
// Remove the shared lock for this backend.
try
{
{
// FIXME -- Do we need to send an admin alert?
}
}
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
}
messages);
}
else
{
// It's already disabled, so we don't need to do anything.
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that specifies the backend ID for
// the backend.
false, true);
try
{
{
// The attribute is not present. We won't allow this.
messages);
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that specifies the writability
// mode.
getMessage(msgID), true, false, false,
try
{
if (writabilityStub == null)
{
messages);
}
else
{
if (writabilityMode == null)
{
messages);
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that specifies the base DNs for
// the backend.
true, true);
try
{
if (baseDNAttr == null)
{
// The attribute is not present. We won't allow this.
messages);
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// 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.
true, false, true);
try
{
{
messages);
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
messages);
}
// See if this backend is currently active and if so if the name of the
// class is the same.
{
{
// It is not the same. Try to load it and see if it is a valid backend
// implementation.
try
{
// FIXME -- Should we use a custom class loader for this?
{
// It appears to be a valid backend class. We'll return that the
// change is successful, but indicate that some administrative
// action is required.
adminActionRequired = true;
messages);
}
else
{
// It is not a valid backend class. This is an error.
messages);
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
messages);
}
}
}
// If we've gotten here, then that should mean that we need to enable the
// backend. Try to do so.
if (needToEnable)
{
try
{
// FIXME -- Should we use a custom class loader for this?
}
catch (Exception e)
{
// It is not a valid backend class. This is an error.
messages);
}
// Set the backend ID and writability mode for this backend.
// Acquire a shared lock on this backend. This will prevent operations
// like LDIF import or restore from occurring while the backend is active.
try
{
{
// FIXME -- Do we need to send an admin alert?
adminActionRequired = true;
messages);
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
adminActionRequired = true;
messages);
}
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
try
{
{
// FIXME -- Do we need to send an admin alert?
}
}
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
}
messages);
}
// Notify any backend initialization listeners.
{
}
// Register the backend with the server.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
messages);
}
}
{
// The backend is already enabled, so we may need to apply a
// configuration change. Check to see if the writability mode has been
// changed.
{
}
}
}
/**
* Indicates whether the configuration entry that will result from a proposed
* add is acceptable to this add listener.
*
* @param configEntry The configuration entry that will result from
* the requested add.
* @param unacceptableReason A buffer to which this method can append a
* human-readable message explaining why the
* proposed entry is not acceptable.
*
* @return <CODE>true</CODE> if the proposed entry contains an acceptable
* configuration, or <CODE>false</CODE> if it does not.
*/
{
// Check to see if this entry appears to contain a backend configuration.
// If not then fail.
try
{
")");
{
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that indicates whether the
// backend should be enabled. If it does not, or if it is not set to
// "true", then skip it.
false);
try
{
if (enabledAttr == null)
{
// The attribute is not present. We will not allow this.
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that specifies the backend ID. If
// it does not, then skip it.
false, true);
try
{
{
// The attribute is not present. We will not allow this.
return false;
}
else
{
{
return false;
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that specifies the writability
// mode. If it does not, then reject it.
getMessage(msgID), true, false, false,
try
{
if (writabilityAttr == null)
{
return false;
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// See if the entry contains an attribute that specifies the set of base DNs
// for the backend. If it does not, then skip it.
true, true);
try
{
if (baseDNAttr == null)
{
// The attribute is not present. We will not allow this.
return false;
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
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.
true, false, true);
try
{
{
return false;
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
try
{
// FIXME -- Should we use a custom class loader for this?
}
catch (Exception e)
{
if (debugEnabled())
{
}
return false;
}
// If the backend is a configurable component, then make sure that its
// configuration is valid.
if (backend instanceof ConfigurableComponent)
{
{
if (errorMessages.isEmpty())
{
}
else
{
{
}
}
return false;
}
}
// Make sure that all of the base DNs are acceptable for use in the server.
{
try
{
}
catch (DirectoryException de)
{
return false;
}
catch (Exception e)
{
return false;
}
}
// If we've gotten to this point, then it is acceptable as far as we are
// concerned. If it is unacceptable according to the configuration for that
// backend, then the backend itself will need to make that determination.
return true;
}
/**
* Attempts to apply a new configuration based on the provided added entry.
*
* @param configEntry The new configuration entry that contains the
* configuration to apply.
*
* @return Information about the result of processing the configuration
* change.
*/
{
boolean adminActionRequired = false;
// Register as a change listener for this backend entry so that we will
// be notified of any changes that may be made to it.
// Check to see if this entry appears to contain a backend configuration.
// If not then fail.
try
{
")");
{
messages);
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that indicates whether the
// backend should be enabled. If it does not, or if it is not set to
// "true", then skip it.
false);
try
{
if (enabledAttr == null)
{
// The attribute is not present, so this backend will be disabled. We
// will log a message to indicate that it won't be enabled and return.
messages);
}
else if (! enabledAttr.activeValue())
{
// The backend is explicitly disabled. We will log a message to
// indicate that it won't be enabled and return.
messages);
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that specifies the backend ID. If
// it does not, then skip it.
false, true);
try
{
{
messages);
}
else
{
{
messages);
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that specifies the writability
// mode.
getMessage(msgID), true, false, false,
try
{
if (writabilityAttr == null)
{
messages);
}
else
{
if (writabilityMode == null)
{
messages);
}
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// See if the entry contains an attribute that specifies the base DNs for
// the entry. If it does not, then skip it.
true, true, true);
try
{
if (baseDNAttr == null)
{
messages);
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
// 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.
true, false, true);
try
{
{
messages);
}
else
{
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
try
{
// FIXME -- Should we use a custom class loader for this?
}
catch (Exception e)
{
if (debugEnabled())
{
}
messages);
}
// Set the backend ID and writability mode for this backend.
// Acquire a shared lock on this backend. This will prevent operations
// like LDIF import or restore from occurring while the backend is active.
try
{
{
// FIXME -- Do we need to send an admin alert?
adminActionRequired = true;
messages);
}
}
catch (Exception e)
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
adminActionRequired = true;
messages);
}
// Perform the necessary initialization for the backend entry.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
try
{
{
// FIXME -- Do we need to send an admin alert?
}
}
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
}
}
// Notify any backend initialization listeners.
{
}
// At this point, the backend should be online. Add it as one of the
// registered backends for this backend config manager.
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
// FIXME -- Do we need to send an admin alert?
messages);
}
}
/**
* Indicates whether it is acceptable to remove the provided configuration
* entry.
*
* @param configEntry The configuration entry that will be removed
* from the configuration.
* @param unacceptableReason A buffer to which this method can append a
* human-readable message explaining why the
* proposed delete is not acceptable.
*
* @return <CODE>true</CODE> if the proposed entry may be removed from the
* configuration, or <CODE>false</CODE> if not.
*/
{
// 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.
{
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.
{
return true;
}
else
{
return false;
}
}
/**
* Attempts to apply a new configuration based on the provided deleted entry.
*
* @param configEntry The new configuration entry that has been deleted.
*
* @return Information about the result of processing the configuration
* change.
*/
{
boolean adminActionRequired = false;
// 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.
{
messages);
}
// See if the backend has any subordinate backends. If so, then it is not
// acceptable to remove it. Otherwise, it should be fine.
{
try
{
}
catch (Exception e)
{
if (debugEnabled())
{
}
}
{
}
messages);
}
else
{
}
}
}