ConfigFromDirContext.java revision 8196da2152209c8c628611aeeb4adae32079921e
/*
* 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-2015 ForgeRock AS.
*/
/**
* A class that reads the configuration and monitoring information using a
* DirContext through LDAP.
*/
public class ConfigFromDirContext extends ConfigReader
{
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. */
public static final SimpleDateFormat utcParser = new SimpleDateFormat(ServerConstants.DATE_FORMAT_GMT_TIME);
{
}
/** 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 context
* the connection to be used to read the information.
*/
{
rootMonitor = null;
entryCaches = null;
try
{
}
catch (final Throwable t)
{
}
{
}
try
{
}
catch (Throwable t)
{
}
try
{
}
catch (Throwable t)
{
}
{
}
if (adminConnector != null)
{
}
}
private void readSchemaIfNeeded(final InitialLdapContext context, final List<OpenDsException> errors)
{
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)
{
}
}
}
final Set<ConnectionHandlerDescriptor> connectionHandlers, final Set<BackendDescriptor> backendDescriptors,
{
// Get the Directory Server configuration handler and use it.
ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(context));
{
}
}
{
try
{
}
catch (OpenDsException oe)
{
}
}
{
{
try
{
}
catch (OpenDsException oe)
{
}
}
}
{
{
try
{
{
BaseDNDescriptor baseDN = new BaseDNDescriptor(BaseDNDescriptor.Type.NOT_REPLICATED, dn, null, -1, -1, -1);
}
{
}
{
}
{
}
{
}
}
catch (OpenDsException oe)
{
}
}
}
{
if (backend instanceof PluggableBackendCfgClient)
{
}
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
{
}
}
final Set<VLVIndexDescriptor> vlvIndexes, final BackendCfgClient backend, final List<OpenDsException> errors)
{
}
private void readBackendIndexes(final Set<IndexDescriptor> indexes, final List<OpenDsException> errors,
final PluggableBackendCfgClient db)
{
try
{
{
null, IndexTypeDescriptor.fromBackendIndexTypes(index.getIndexType()), index.getIndexEntryLimit()));
}
}
catch (OpenDsException oe)
{
}
}
{
try
{
{
}
}
catch (OpenDsException oe)
{
}
}
private boolean readIfReplicationIsSecure(final RootCfgClient root, final List<OpenDsException> errors)
{
try
{
}
catch (OpenDsException oe)
{
return false;
}
}
private ReplicationSynchronizationProviderCfgClient readSyncProviderIfExists(final RootCfgClient root)
{
try
{
return (ReplicationSynchronizationProviderCfgClient) root.getSynchronizationProvider(SYNC_PROVIDER_NAME);
}
catch (OpenDsException oe)
{
return null;
}
}
final Set<BackendDescriptor> backendDescriptors, final ReplicationSynchronizationProviderCfgClient sync,
{
replicationPort = -1;
try
{
{
if (replicationServer != null)
{
}
}
{
{
{
{
{
}
}
}
}
}
}
catch (OpenDsException oe)
{
}
}
{
try
{
{
{
}
}
}
catch (OpenDsException oe)
{
}
}
/**
* 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)
{
}
}
{
{
{
try
{
{
try
{
}
catch (Throwable t)
{
}
try
{
}
catch (Throwable t)
{
}
}
}
catch (Throwable t)
{
}
}
}
}
else
{
{
{
{
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.
*/
private void handleTaskSearchResult(SearchResult sr, String searchBaseDN, Collection<TaskEntry> taskEntries,
{
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.
*/
public void updateTaskInformation(InitialLdapContext ctx, List<OpenDsException> ex, Collection<TaskEntry> ts)
{
// 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)
{
}
}
private ConnectionHandlerDescriptor getConnectionHandler(ConnectionHandlerCfgClient connHandler, String name)
throws OpenDsException
{
ConnectionHandlerDescriptor.State state = connHandler.isEnabled() ? ConnectionHandlerDescriptor.State.ENABLED
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;
}
}
{
{
}
}
private ConnectionHandlerDescriptor getConnectionHandler(AdministrationConnectorCfgClient adminConnector)
throws OpenDsException
{
ConnectionHandlerDescriptor.Protocol protocol = ConnectionHandlerDescriptor.Protocol.ADMINISTRATION_CONNECTOR;
return new ConnectionHandlerDescriptor(
addresses, port, protocol, state, INFO_CTRL_PANEL_CONN_HANDLER_ADMINISTRATION.get().toString(), emptySet);
}
{
}
{
}
{
}
{
}
{
}
{
}
{
{
{
{
return true;
}
}
}
return false;
}
{
{
{
{
return true;
}
}
}
return false;
}
/**
* 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.
{
}
}
}
return monitorEntries;
}
{
{
{
return false;
}
}
return true;
}
}