/*
* 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 legal-notices/CDDLv1_0.txt
* 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 legal-notices/CDDLv1_0.txt.
* 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
*
*
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions copyright 2012-2014 ForgeRock AS.
*/
/**
* This class defines a backend to hold Directory Server monitor entries. It
* will not actually store anything, but upon request will retrieve the
* requested monitor and dynamically generate the associated entry. It will also
* construct a base monitor entry with some useful server-wide data.
*/
{
/**
* The tracer object for the debug logger.
*/
/**
* The set of user-defined attributes that will be included in the base
* monitor entry.
*/
/** The set of objectclasses that will be used in monitor entries. */
/** The DN of the configuration entry for this backend. */
/** The current configuration state. */
/** The DN for the base monitor entry. */
/** The set of base DNs for this backend. */
/**
* Creates a new backend with the provided information. All backend
* implementations must implement a default constructor that use
* <CODE>super()</CODE> to invoke this constructor.
*/
public MonitorBackend()
{
super();
}
/** {@inheritDoc} */
throws DirectoryException
{
}
/** {@inheritDoc} */
final MonitorBackendCfg backendCfg)
{
final boolean adminActionRequired = false;
// Check to see if there is a new set of user-defined attributes.
try
{
.getUserAttributes().values())
{
{
if (!isMonitorConfigAttribute(a))
{
}
}
}
{
{
if (!isMonitorConfigAttribute(a))
{
}
}
}
}
catch (final Exception e)
{
if (debugEnabled())
{
}
}
}
/** {@inheritDoc} */
throws ConfigException
{
// Make sure that a configuration entry was provided. If not, then we will
// not be able to complete initialization.
if (configEntry == null)
{
throw new ConfigException(message);
}
// Get the set of user-defined attributes for the configuration entry. Any
// attributes that we don't recognize will be included directly in the base
// monitor entry.
.getUserAttributes().values())
{
{
if (!isMonitorConfigAttribute(a))
{
}
}
}
{
{
if (!isMonitorConfigAttribute(a))
{
}
}
}
// Construct the set of objectclasses to include in the base monitor entry.
OC_MONITOR_ENTRY, true);
// Create the set of base DNs that we will handle. In this case, it's just
// the DN of the base monitor entry.
try
{
}
catch (final Exception e)
{
if (debugEnabled())
{
}
.get(getExceptionMessage(e));
throw new ConfigException(message, e);
}
// FIXME -- Deal with this more correctly.
currentConfig = cfg;
}
/** {@inheritDoc} */
throws DirectoryException
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
throws DirectoryException
{
// TODO export-ldif reports nonsense for upTime etc.
// Create the LDIF writer.
try
{
}
catch (final Exception e)
{
if (debugEnabled())
{
}
message);
}
// Write the base monitor entry to the LDIF.
try
{
}
catch (final Exception e)
{
if (debugEnabled())
{
}
message);
}
// Get all the monitor providers, convert them to entries, and write them to
// LDIF.
.getMonitorProviders().values())
{
try
{
// TODO implementation of export is incomplete
}
catch (final Exception e)
{
if (debugEnabled())
{
}
throw new DirectoryException(
}
}
}
/** {@inheritDoc} */
public void finalizeBackend()
{
super.finalizeBackend();
try
{
}
catch (final Exception e)
{
if (debugEnabled())
{
}
}
}
/** {@inheritDoc} */
{
return baseDNs;
}
/** {@inheritDoc} */
{
// If the requested entry was null, then throw an exception.
{
}
// If the requested entry was the monitor base entry, then retrieve it
// without constructing the DIT.
{
return getBaseMonitorEntry();
}
// From now on we'll need the DIT.
{
}
}
/** {@inheritDoc} */
public long getEntryCount()
{
}
/** {@inheritDoc} */
{
return Collections.emptySet();
}
/** {@inheritDoc} */
{
return Collections.emptySet();
}
/** {@inheritDoc} */
throws DirectoryException
{
{
return ConditionResult.UNDEFINED;
}
else
{
{
return ConditionResult.FALSE;
}
else
{
return ConditionResult.TRUE;
}
}
}
/** {@inheritDoc} */
throws DirectoryException
{
}
/** {@inheritDoc} */
{
// Register with the Directory Server as a configurable component.
// Register the monitor base as a private suffix.
try
{
}
catch (final Exception e)
{
if (debugEnabled())
{
}
throw new InitializationException(message, e);
}
}
/** {@inheritDoc} */
public boolean isConfigurationChangeAcceptable(
final MonitorBackendCfg backendCfg,
{
// We'll pretty much accept anything here as long as it isn't one of our
// private attributes.
return true;
}
/** {@inheritDoc} */
{
// All searches in this backend will always be considered indexed.
return true;
}
/** {@inheritDoc} */
public boolean isLocal()
{
// For the purposes of this method, this is a local backend.
return true;
}
/** {@inheritDoc} */
throws DirectoryException
{
{
return -1L;
}
else
{
long count = 0;
{
{
break;
}
{
count++;
}
}
return count;
}
}
/** {@inheritDoc} */
{
throw new UnsupportedOperationException("Operation not supported.");
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
{
}
/** {@inheritDoc} */
throws DirectoryException
{
}
/** {@inheritDoc} */
throws DirectoryException
{
// Get the base DN, scope, and filter for the search.
// Compute the current monitor DIT.
// Resolve the base entry and return no such object if it does not exist.
{
// Not found, so find the nearest match.
{
{
break;
}
}
}
// Walk through all entries and send the ones that match.
.entrySet())
{
{
{
}
}
{
// No more entries will be in scope.
break;
}
}
}
/** {@inheritDoc} */
public boolean supportsBackup()
{
return false;
}
/** {@inheritDoc} */
final StringBuilder unsupportedReason)
{
return false;
}
/** {@inheritDoc} */
public boolean supportsLDIFExport()
{
// We can export all the monitor entries as a point-in-time snapshot.
// TODO implementation of export is incomplete
// TODO export-ldif reports nonsense for upTime etc.
return false;
}
/** {@inheritDoc} */
public boolean supportsLDIFImport()
{
return false;
}
/** {@inheritDoc} */
public boolean supportsRestore()
{
return false;
}
/**
* Creates an attribute for a monitor entry with the following criteria.
*
* @param name
* The name for the attribute.
* @param lowerName
* The name for the attribute formatted in all lowercase characters.
* @param value
* The value to use for the attribute.
* @return The constructed attribute.
*/
{
}
/**
* Retrieves the base monitor entry for the Directory Server.
*
* @return The base monitor entry for the Directory Server.
*/
{
OC_EXTENSIBLE_OBJECT_LC, true);
// Add the "cn" attribute.
ATTR_COMMON_NAME, "monitor");
// Add the server product name.
// Add the vendor name.
// Add the vendor version.
// Add the server startup time.
// Add the current time.
// Add the uptime as a human-readable string.
upSeconds %= 86400;
upSeconds %= 3600;
upSeconds %= 60;
// Add the number of connections currently established.
// Add the maximum number of connections established at one time.
// Add the total number of connections the server has accepted.
// Add all the user-defined attributes.
for (final Attribute a : userDefinedAttributes)
{
if (type.isOperational())
{
{
}
else
{
}
}
else
{
{
}
else
{
}
}
}
// Construct and return the entry.
return e;
}
/**
* Retrieves the branch monitor entry for the Directory Server.
*
* @param dn
* to get.
* @return The branch monitor entry for the Directory Server.
*/
{
OC_MONITOR_BRANCH, true);
{
// Add the RDN values
{
}
}
// Construct and return the entry.
return e;
}
/**
* Returns a map containing records for each DN in the monitor backend's DIT.
* Each record maps the entry DN to the associated monitor provider, or
* {@code null} if the entry is a glue (branch) entry.
*
* @return A map containing records for each DN in the monitor backend's DIT.
*/
{
.getMonitorProviders().values())
{
// Added glue records.
{
{
break;
}
else
{
}
}
}
return dit;
}
/**
* Creates the monitor entry having the specified DN.
*
* @param entryDN
* The name of the monitor entry.
* @param dit
* The monitor DIT.
* @return Returns the monitor entry having the specified DN.
*/
{
// Get the monitor provider.
if (monitorProvider != null)
{
}
{
// The monitor base entry needs special treatment.
return getBaseMonitorEntry();
}
else
{
// Create a generic glue branch entry.
return getBranchMonitorEntry(entryDN);
}
}
/**
* Generates and returns a monitor entry based on the contents of the provided
* monitor provider.
*
* @param entryDN
* The DN to use for the entry.
* @param monitorProvider
* The monitor provider to use to obtain the information for the
* entry.
* @return The monitor entry generated from the information in the provided
* monitor provider.
*/
final MonitorProvider<?> monitorProvider)
{
3);
// Make sure to include the RDN attribute.
// Take the rest of the information from the monitor data.
for (final Attribute a : monitorAttrs)
{
{
}
else
{
}
}
return e;
}
/**
* Indicates whether the provided attribute is one that is used in the
* configuration of this backend.
*
* @param attribute
* The attribute for which to make the determination.
* @return <CODE>true</CODE> if the provided attribute is one that is used in
* the configuration of this backend, <CODE>false</CODE> if not.
*/
{
}
}