ConfigFromDirContext.java revision e3fed6978fb8085b119df2966b5c27785756d70b
/*
* 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 2008-2011 Sun Microsystems, Inc.
* Portions Copyright 2013-2014 ForgeRock AS.
*/
/**
* A class that reads the configuration and monitoring information using a
* DirContext through LDAP.
*
*/
public class ConfigFromDirContext extends ConfigReader
{
private static final String DATABASE_ENVIRONMENT_SUFFIX =
" Database Environment";
private CustomSearchResult rootMonitor;
private CustomSearchResult jvmMemoryUsage;
private CustomSearchResult systemInformation;
private CustomSearchResult entryCaches;
private CustomSearchResult workQueue;
private CustomSearchResult versionMonitor;
private boolean isLocal = true;
/**
* The monitor root entry DN.
*/
/**
* The JVM memory usage monitoring entry DN.
*/
/**
* The system information monitoring entry DN.
*/
/**
* The entry cache monitoring entry DN.
*/
/**
* The work queue monitoring entry DN.
*/
/**
* The version monitoring entry DN.
*/
{
try
{
}
catch (Throwable t)
{
throw new RuntimeException("Could not decode DNs: "+t, t);
}
}
/**
* The date formatter to be used to parse GMT dates.
*/
{
}
/**
* The date formatter to be used to format dates.
*/
/**
* Returns the monitoring entry for the entry caches.
* @return the monitoring entry for the entry caches.
*/
public CustomSearchResult getEntryCaches()
{
return entryCaches;
}
/**
* Returns the monitoring entry for the JVM memory usage.
* @return the monitoring entry for the JVM memory usage.
*/
public CustomSearchResult getJvmMemoryUsage()
{
return jvmMemoryUsage;
}
/**
* Returns the root entry of the monitoring tree.
* @return the root entry of the monitoring tree.
*/
public CustomSearchResult getRootMonitor()
{
return rootMonitor;
}
/**
* Returns the version entry of the monitoring tree.
* @return the version entry of the monitoring tree.
*/
public CustomSearchResult getVersionMonitor()
{
return versionMonitor;
}
/**
* Returns the monitoring entry for the system information.
* @return the monitoring entry for the system information.
*/
public CustomSearchResult getSystemInformation()
{
return systemInformation;
}
/**
* Returns the monitoring entry for the work queue.
* @return the monitoring entry for the work queue.
*/
public CustomSearchResult getWorkQueue()
{
return workQueue;
}
/**
* Sets whether this server represents the local instance or a remote server.
* @param isLocal whether this server represents the local instance or a
* remote server (in another machine or in another installation on the same
* machine).
*/
public void setIsLocal(boolean isLocal)
{
}
/**
* Returns <CODE>true</CODE> if we are trying to manage the local host and
* <CODE>false</CODE> otherwise.
* @return <CODE>true</CODE> if we are trying to manage the local host and
* <CODE>false</CODE> otherwise.
*/
public boolean isLocal()
{
return isLocal;
}
/**
* Reads configuration and monitoring information using the provided
* connection.
* @param ctx the connection to be used to read the information.
*/
{
new HashSet<ConnectionHandlerDescriptor>();
rootMonitor = null;
entryCaches = null;
if (mustReadSchema())
{
try
{
{
// Update the schema: so that when we call the server code the
// latest schema read on the server we are managing is used.
}
}
catch (OpenDsException oe)
{
}
}
try
{
// Get the Directory Server configuration handler and use it.
try
{
}
catch (OpenDsException oe)
{
}
{
try
{
}
catch (OpenDsException oe)
{
}
}
{
try
{
{
}
new HashSet<VLVIndexDescriptor>();
if (backend instanceof LocalDBBackendCfgClient)
{
try
{
{
}
}
catch (OpenDsException oe)
{
}
try
{
{
}
}
catch (OpenDsException oe)
{
}
}
else if (backend instanceof LDIFBackendCfgClient)
{
}
else if (backend instanceof MemoryBackendCfgClient)
{
}
else if (backend instanceof BackupBackendCfgClient)
{
}
else if (backend instanceof MonitorBackendCfgClient)
{
}
else if (backend instanceof TaskBackendCfgClient)
{
}
else
{
}
{
}
{
}
{
}
}
catch (OpenDsException oe)
{
}
}
boolean isReplicationSecure = false;
try
{
}
catch (OpenDsException oe)
{
}
replicationPort = -1;
try
{
}
catch (OpenDsException oe)
{
// Ignore this one
}
{
try
{
{
if (replicationServer != null)
{
new HashSet<InetAddress>(),
"Multimaster Synchronization",
emptySet);
}
}
{
{
{
{
{
}
}
}
}
}
}
catch (OpenDsException oe)
{
}
}
try
{
{
{
}
}
}
catch (OpenDsException oe)
{
}
}
catch (final Throwable t)
{
}
{
}
try
{
}
catch (Throwable t)
{
}
try
{
}
catch (Throwable t)
{
}
{
}
if (adminConnector != null)
{
}
}
/**
* Returns an array of monitoring attributes to be returned in the request.
* @return an array of monitoring attributes to be returned in the request.
*/
protected String[] getMonitoringAttributes()
{
return new String[] {
"*"
};
}
/**
* Reads the schema from the files.
* @param ctx the connection to be used to load the schema.
* @throws OpenDsException if an error occurs reading the schema.
*/
{
try
{
if (isLocal)
{
super.readSchema();
}
else
{
}
}
catch (NamingException ne)
{
}
catch (ConfigException ce)
{
}
}
/**
* Takes the provided search result and updates the monitoring information
* accordingly.
* @param sr the search result.
* @param searchBaseDN the base search.
* @throws NamingException if there is an error retrieving the values of the
* search result.
*/
throws NamingException
{
if (javaVersion == null)
{
}
if (numberConnections == -1)
{
if (v != null)
{
}
}
"missing-changes");
{
{
{
try
{
{
try
{
"approx-older-change-not-synchronized-millis")));
}
catch (Throwable t)
{
}
try
{
}
catch (Throwable t)
{
}
}
}
catch (Throwable t)
{
}
}
}
}
else
{
"ds-backend-id");
"ds-backend-entry-count");
"ds-base-dn-entry-count");
(baseDnEntries != null)))
{
{
{
if (entryCount != null)
{
}
if (baseDnEntries != null)
{
for (String s : baseDnEntries)
{
if (index != -1)
{
{
{
try
{
}
catch (Throwable t)
{
/* Ignore */
}
break;
}
}
}
}
}
}
}
}
else
{
// Check if it is the DB monitor entry
{
{
{
}
}
}
}
try
{
{
rootMonitor = csr;
}
{
entryCaches = csr;
}
{
}
{
}
{
}
{
}
else if (isConnectionHandler(csr))
{
{
// Assume it is a connection handler
}
}
}
catch (OpenDsException ode)
{
}
}
}
/**
* Takes the provided search result and updates the task information
* accordingly.
* @param sr the search result.
* @param searchBaseDN the base search.
* @param taskEntries the collection of TaskEntries to be updated.
* @param ex the list of exceptions to be updated if an error occurs.
* @throws NamingException if there is an error retrieving the values of the
* search result.
*/
throws NamingException
{
try
{
if (isTaskEntry(csr))
{
}
}
catch (OpenDsException ode)
{
}
}
{
// Read monitoring information: since it is computed, it is faster
// to get everything in just one request.
try
{
javaVersion = null;
numberConnections = -1;
try
{
while (monitorEntries.hasMore())
{
}
}
finally
{
}
}
catch (NamingException ne)
{
}
}
/**
* Updates the provided list of TaskEntry with the task entries found in
* a server.
* @param ctx the connection to the server.
* @param ex the list of exceptions encountered while retrieving the task
* entries.
* @param ts the list of task entries to be updated.
*/
{
// Read monitoring information: since it is computed, it is faster
// to get everything in just one request.
try
{
try
{
while (taskEntries.hasMore())
{
}
}
finally
{
taskEntries.close();
}
}
catch (NamingException ne)
{
}
}
throws OpenDsException
{
int port;
if (connHandler instanceof LDAPConnectionHandlerCfgClient)
{
{
}
else if (ldap.isAllowStartTLS())
{
}
else
{
}
}
else if (connHandler instanceof HTTPConnectionHandlerCfgClient)
{
{
}
else
{
}
}
else if (connHandler instanceof JMXConnectionHandlerCfgClient)
{
{
}
else
{
}
}
else if (connHandler instanceof LDIFConnectionHandlerCfgClient)
{
port = -1;
}
else if (connHandler instanceof SNMPConnectionHandlerCfgClient)
{
}
else
{
port = -1;
}
}
{
{
}
}
{
}
throws OpenDsException
{
}
throws OpenDsException
{
}
throws OpenDsException
{
}
throws OpenDsException
{
}
throws OpenDsException
{
}
throws OpenDsException
{
}
throws OpenDsException
{
boolean isConnectionHandler = false;
{
{
{
isConnectionHandler = true;
}
}
}
return isConnectionHandler;
}
throws OpenDsException
{
boolean isTaskEntry = false;
{
{
{
isTaskEntry = true;
break;
}
}
}
return isTaskEntry;
}
/**
* Commodity method to get the string representation to be used in the
* hash maps as key.
* @param value the value to be transformed into a key for a hash map.
* @return the string representation to be used in the hash maps as key.
*/
{
return value.toLowerCase();
}
{
{
{
// The name of the connection handler does not appear necessarily in the
// key (which is based on the DN of the monitoring entry). In general
// the DN contains the String specified in
// LDAPConnectionHandler.DEFAULT_FRIENDLY_NAME, so we have to check that
// this connection handler is the right one.
// See org.opends.server.protocols.ldap.LDAPConnectionHandler to see
// how the DN of the monitoring entry is generated.
{
boolean hasAllAddresses = true;
{
{
hasAllAddresses = false;
break;
}
}
if (hasAllAddresses)
{
}
}
}
}
return monitorEntries;
}
}