ConfigFromDirContext.java revision eb4855e3f510e32c6034710868ef87e67081f921
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder/*
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * CDDL HEADER START
e6d40133bc9f858308654afb1262b8b483ec5922Till Mossakowski *
333780eae2be9f20fe46dedbf5eb46ffa0cbfd02Christian Maeder * The contents of this file are subject to the terms of the
98890889ffb2e8f6f722b00e265a211f13b5a861Corneliu-Claudiu Prodescu * Common Development and Distribution License, Version 1.0 only
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * (the "License"). You may not use this file except in compliance
cfbd735270fe52115cef0508d265785efcb99cd7Christian Maeder * with the License.
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski *
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * or http://forgerock.org/license/CDDLv1.0.html.
703d52d129c8ac510a6f3e8fe28008dbf82ef772Till Mossakowski * See the License for the specific language governing permissions
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * and limitations under the License.
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski *
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * When distributing Covered Code, include this CDDL HEADER in each
41eeec8620877f96835b4d543b6a6b615847d6f2Till Mossakowski * file and include the License file at legal-notices/CDDLv1_0.txt.
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder * If applicable, add the following below this CDDL HEADER, with the
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder * fields enclosed by brackets "[]" replaced with your own identifying
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder * information:
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder * Portions Copyright [yyyy] [name of copyright owner]
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder *
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder * CDDL HEADER END
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken *
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken *
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maeder * Copyright 2008-2011 Sun Microsystems, Inc.
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken * Portions Copyright 2013-2015 ForgeRock AS.
c208973c890b8f993297720fd0247bc7481d4304Christian Maeder */
55c5e901b5c3466300009135585bc70bd576dcb6Christian Maederpackage org.opends.guitools.controlpanel.util;
54ea981a0503c396c2923a1c06421c6235baf27fChristian Maeder
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport static org.opends.messages.AdminToolMessages.*;
54ea981a0503c396c2923a1c06421c6235baf27fChristian Maeder
54ea981a0503c396c2923a1c06421c6235baf27fChristian Maederimport java.net.InetAddress;
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport java.text.DateFormat;
54ea981a0503c396c2923a1c06421c6235baf27fChristian Maederimport java.text.SimpleDateFormat;
697e63e30aa3c309a1ef1f9357745111f8dfc5a9Christian Maederimport java.util.ArrayList;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport java.util.Collection;
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerkenimport java.util.Collections;
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerkenimport java.util.HashMap;
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maederimport java.util.HashSet;
afe76697dd6888856a066934a1112a38809b27faChristian Maederimport java.util.List;
58aa0caa9f05787b4bffc2e32d1494cc1766b8cfRazvan Pascanuimport java.util.Map;
2c81e2bd9f9dee247c74a642c03620a2f799d0a4Razvan Pascanuimport java.util.Set;
a5c67efbd82e10368fda4e30d528157066d45c03Christian Maederimport java.util.SortedSet;
a5c67efbd82e10368fda4e30d528157066d45c03Christian Maederimport java.util.TimeZone;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport java.util.TreeSet;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder
2c81e2bd9f9dee247c74a642c03620a2f799d0a4Razvan Pascanuimport javax.naming.NamingEnumeration;
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maederimport javax.naming.NamingException;
a5c67efbd82e10368fda4e30d528157066d45c03Christian Maederimport javax.naming.directory.SearchControls;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport javax.naming.directory.SearchResult;
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maederimport javax.naming.ldap.InitialLdapContext;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport javax.naming.ldap.LdapName;
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder
333780eae2be9f20fe46dedbf5eb46ffa0cbfd02Christian Maederimport org.forgerock.i18n.LocalizableMessage;
2c81e2bd9f9dee247c74a642c03620a2f799d0a4Razvan Pascanuimport org.forgerock.i18n.slf4j.LocalizedLogger;
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maederimport org.forgerock.opendj.config.server.ConfigException;
da955132262baab309a50fdffe228c9efe68251dCui Jianimport org.opends.admin.ads.util.ConnectionUtils;
c458c6f5a2ce173d8af7a7f5cb434813eb870937Jorina Freya Gerkenimport org.opends.guitools.controlpanel.datamodel.AbstractIndexDescriptor;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.guitools.controlpanel.datamodel.BackendDescriptor;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.guitools.controlpanel.datamodel.BaseDNDescriptor;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.guitools.controlpanel.datamodel.ConnectionHandlerDescriptor;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.guitools.controlpanel.datamodel.CustomSearchResult;
fd4856f5eeac6f144f6116002233e5ce4cc8f41bJorina Freya Gerkenimport org.opends.guitools.controlpanel.datamodel.IndexDescriptor;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.guitools.controlpanel.datamodel.IndexTypeDescriptor;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.guitools.controlpanel.datamodel.VLVIndexDescriptor;
7ec5cb48d588cc641d27fb2dbeccb6c28856c8daChristian Maederimport org.opends.guitools.controlpanel.datamodel.VLVSortOrder;
7ec5cb48d588cc641d27fb2dbeccb6c28856c8daChristian Maederimport org.opends.guitools.controlpanel.task.OnlineUpdateException;
c458c6f5a2ce173d8af7a7f5cb434813eb870937Jorina Freya Gerkenimport org.opends.server.admin.client.AuthorizationException;
fd4856f5eeac6f144f6116002233e5ce4cc8f41bJorina Freya Gerkenimport org.opends.server.admin.client.CommunicationException;
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maederimport org.opends.server.admin.client.ConcurrentModificationException;
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maederimport org.opends.server.admin.client.ManagementContext;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.server.admin.client.ldap.JNDIDirContextAdaptor;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.server.admin.client.ldap.LDAPManagementContext;
d11391a2447a2005329a95b5d770f24e62bf5b63Christian Maederimport org.opends.server.admin.std.client.AdministrationConnectorCfgClient;
d11391a2447a2005329a95b5d770f24e62bf5b63Christian Maederimport org.opends.server.admin.std.client.BackendCfgClient;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.server.admin.std.client.BackendIndexCfgClient;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.server.admin.std.client.BackendVLVIndexCfgClient;
d11391a2447a2005329a95b5d770f24e62bf5b63Christian Maederimport org.opends.server.admin.std.client.BackupBackendCfgClient;
d11391a2447a2005329a95b5d770f24e62bf5b63Christian Maederimport org.opends.server.admin.std.client.ConnectionHandlerCfgClient;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.server.admin.std.client.HTTPConnectionHandlerCfgClient;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.server.admin.std.client.JMXConnectionHandlerCfgClient;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.server.admin.std.client.LDAPConnectionHandlerCfgClient;
c458c6f5a2ce173d8af7a7f5cb434813eb870937Jorina Freya Gerkenimport org.opends.server.admin.std.client.LDIFBackendCfgClient;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport org.opends.server.admin.std.client.LDIFConnectionHandlerCfgClient;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport org.opends.server.admin.std.client.LocalDBBackendCfgClient;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport org.opends.server.admin.std.client.LocalDBIndexCfgClient;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport org.opends.server.admin.std.client.LocalDBVLVIndexCfgClient;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport org.opends.server.admin.std.client.MemoryBackendCfgClient;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.server.admin.std.client.MonitorBackendCfgClient;
afe76697dd6888856a066934a1112a38809b27faChristian Maederimport org.opends.server.admin.std.client.PluggableBackendCfgClient;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.admin.std.client.ReplicationDomainCfgClient;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.admin.std.client.ReplicationServerCfgClient;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.admin.std.client.ReplicationSynchronizationProviderCfgClient;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.admin.std.client.RootCfgClient;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.admin.std.client.RootDNCfgClient;
fd4856f5eeac6f144f6116002233e5ce4cc8f41bJorina Freya Gerkenimport org.opends.server.admin.std.client.RootDNUserCfgClient;
afe76697dd6888856a066934a1112a38809b27faChristian Maederimport org.opends.server.admin.std.client.SNMPConnectionHandlerCfgClient;
fb88eac77c89b668f5c306173a6fbe2d513e4bccMarkus Grossimport org.opends.server.admin.std.client.TaskBackendCfgClient;
fb88eac77c89b668f5c306173a6fbe2d513e4bccMarkus Grossimport org.opends.server.backends.jeb.RemoveOnceLocalDBBackendIsPluggable;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.backends.pluggable.SuffixContainer;
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maederimport org.opends.server.config.ConfigConstants;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maederimport org.opends.server.core.DirectoryServer;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.server.tools.tasks.TaskEntry;
fd4856f5eeac6f144f6116002233e5ce4cc8f41bJorina Freya Gerkenimport org.opends.server.types.DN;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maederimport org.opends.server.types.OpenDsException;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maederimport org.opends.server.util.ServerConstants;
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder
fd4856f5eeac6f144f6116002233e5ce4cc8f41bJorina Freya Gerken/**
ce3e8067c8e5c5ffe7e76d75ead46e2b67adcafcChristian Maeder * A class that reads the configuration and monitoring information using a
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder * DirContext through LDAP.
afe76697dd6888856a066934a1112a38809b27faChristian Maeder */
afe76697dd6888856a066934a1112a38809b27faChristian Maederpublic class ConfigFromDirContext extends ConfigReader
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder{
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder
2c81e2bd9f9dee247c74a642c03620a2f799d0a4Razvan Pascanu private static final String DATABASE_ENVIRONMENT_SUFFIX = " Database Environment";
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder private static final String SYNC_PROVIDER_NAME = "Multimaster Synchronization";
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder private CustomSearchResult rootMonitor;
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder private CustomSearchResult jvmMemoryUsage;
e49fd57c63845c7806860a9736ad09f6d44dbaedChristian Maeder private CustomSearchResult systemInformation;
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder private CustomSearchResult entryCaches;
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken private CustomSearchResult workQueue;
d5aadb569823a9d41ef761433f27dd00d7e4e147Christian Maeder private CustomSearchResult versionMonitor;
58aa0caa9f05787b4bffc2e32d1494cc1766b8cfRazvan Pascanu
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken private boolean isLocal = true;
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder private final Map<String, CustomSearchResult> hmConnectionHandlersMonitor =
afe76697dd6888856a066934a1112a38809b27faChristian Maeder new HashMap<String, CustomSearchResult>();
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder /** The monitor root entry DN. */
afe76697dd6888856a066934a1112a38809b27faChristian Maeder protected DN monitorDN = DN.rootDN();
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder /** The JVM memory usage monitoring entry DN. */
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder protected DN jvmMemoryUsageDN = DN.rootDN();
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder /** The system information monitoring entry DN. */
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder protected DN systemInformationDN = DN.rootDN();
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder /**The entry cache monitoring entry DN. */
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder protected DN entryCachesDN = DN.rootDN();
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder /** The work queue monitoring entry DN. */
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder protected DN workQueueDN = DN.rootDN();
07eb349813c50aff304df13337b5cbc42f48c0a5Jorina Freya Gerken
f45fad43ee1673ab280fbc700821d5d20a493eaaChristian Maeder /** The version monitoring entry DN. */
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken protected DN versionDN = DN.rootDN();
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder {
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken try
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder {
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder monitorDN = DN.valueOf("cn=monitor");
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder jvmMemoryUsageDN = DN.valueOf("cn=JVM Memory Usage,cn=monitor");
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken systemInformationDN = DN.valueOf("cn=System Information,cn=monitor");
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder entryCachesDN = DN.valueOf("cn=Entry Caches,cn=monitor");
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder workQueueDN = DN.valueOf("cn=Work Queue,cn=monitor");
04d04d19fdd5320953c78ad5b6d2d11f85bc4bcfChristian Maeder versionDN = DN.valueOf("cn=Version,cn=monitor");
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder }
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken catch (Throwable t)
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken {
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken throw new RuntimeException("Could not decode DNs: "+t, t);
c458c6f5a2ce173d8af7a7f5cb434813eb870937Jorina Freya Gerken }
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder }
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder /** The date formatter to be used to parse GMT dates. */
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder public static final SimpleDateFormat utcParser = new SimpleDateFormat(ServerConstants.DATE_FORMAT_GMT_TIME);
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder {
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder utcParser.setTimeZone(TimeZone.getTimeZone("UTC"));
9192fdd8f0e682ac0f0183dd854d5210fbfa4ec5Christian Maeder }
0cbb0121c81f5307eeefe7ffbeeac79ff6c5cdf2Jorina Freya Gerken
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder /** The date formatter to be used to format dates. */
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder public static final DateFormat formatter = DateFormat.getDateTimeInstance();
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder
54a0a1e10bd93721cf52dbd9b816c8f108997ec0Christian Maeder /**
07eb349813c50aff304df13337b5cbc42f48c0a5Jorina Freya Gerken * Returns the monitoring entry for the entry caches.
4b136ad539bd9f4e115dff4eee4d552a42d4437eChristian Maeder *
07eb349813c50aff304df13337b5cbc42f48c0a5Jorina Freya Gerken * @return the monitoring entry for the entry caches.
07eb349813c50aff304df13337b5cbc42f48c0a5Jorina Freya Gerken */
07eb349813c50aff304df13337b5cbc42f48c0a5Jorina Freya Gerken public CustomSearchResult getEntryCaches()
0a5165c161ce13d434b5c0488b533a8de98aafaaChristian Maeder {
e953bea49e7f0e1a43bccf2a66c5e2a2b50848e0Christian Maeder 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)
{
this.isLocal = 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.
*/
public void readConfiguration(final InitialLdapContext context)
{
final List<OpenDsException> errors = new ArrayList<OpenDsException>();
final Set<ConnectionHandlerDescriptor> connectionHandlers = new HashSet<ConnectionHandlerDescriptor>();
final Set<BackendDescriptor> backendDescriptors = new HashSet<BackendDescriptor>();
final Set<DN> as = new HashSet<DN>();
final Set<TaskEntry> tasks = new HashSet<TaskEntry>();
rootMonitor = null;
jvmMemoryUsage = null;
systemInformation = null;
entryCaches = null;
workQueue = null;
versionMonitor = null;
hmConnectionHandlersMonitor.clear();
readSchemaIfNeeded(context, errors);
try
{
readConfig(context, connectionHandlers, backendDescriptors, as, errors);
}
catch (final Throwable t)
{
errors.add(new OnlineUpdateException(ERR_READING_CONFIG_LDAP.get(t), t));
}
for (OpenDsException oe : errors)
{
logger.warn(LocalizableMessage.raw("Error reading configuration: " + oe, oe));
}
administrativeUsers = Collections.unmodifiableSet(as);
listeners = Collections.unmodifiableSet(connectionHandlers);
backends = Collections.unmodifiableSet(backendDescriptors);
try
{
updateMonitorInformation(context, errors);
}
catch (Throwable t)
{
logger.warn(LocalizableMessage.raw("Error reading monitoring: " + t, t));
errors.add(new OnlineUpdateException(ERR_READING_CONFIG_LDAP.get(t), t));
}
try
{
updateTaskInformation(context, errors, tasks);
}
catch (Throwable t)
{
logger.warn(LocalizableMessage.raw("Error reading task information: " + t, t));
errors.add(new OnlineUpdateException(ERR_READING_CONFIG_LDAP.get(t), t));
}
taskEntries = Collections.unmodifiableSet(tasks);
for (ConnectionHandlerDescriptor ch : getConnectionHandlers())
{
ch.setMonitoringEntries(getMonitoringEntries(ch));
}
if (adminConnector != null)
{
adminConnector.setMonitoringEntries(getMonitoringEntries(adminConnector));
}
exceptions = Collections.unmodifiableList(errors);
}
private void readSchemaIfNeeded(final InitialLdapContext context, final List<OpenDsException> errors)
{
if (mustReadSchema())
{
try
{
readSchema(context);
if (getSchema() != null)
{
// Update the schema: so that when we call the server code the
// latest schema read on the server we are managing is used.
DirectoryServer.setSchema(getSchema());
}
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
}
private void readConfig(final InitialLdapContext context,
final Set<ConnectionHandlerDescriptor> connectionHandlers, final Set<BackendDescriptor> backendDescriptors,
final Set<DN> alternateBindDNs, final List<OpenDsException> errors) throws Exception
{
// Get the Directory Server configuration handler and use it.
ManagementContext mCtx = LDAPManagementContext.createFromContext(JNDIDirContextAdaptor.adapt(context));
final RootCfgClient root = mCtx.getRootConfiguration();
readAdminConnector(root, errors);
readConnectionHandlers(connectionHandlers, root, errors);
isSchemaEnabled = root.getGlobalConfiguration().isCheckSchema();
readBackendConfiguration(backendDescriptors, root, errors);
boolean isReplicationSecure = readIfReplicationIsSecure(root, errors);
final ReplicationSynchronizationProviderCfgClient sync = readSyncProviderIfExists(root);
if (sync != null)
{
readReplicationConfig(connectionHandlers, backendDescriptors, sync, isReplicationSecure, errors);
}
readAlternateBindDNs(alternateBindDNs, root, errors);
}
private void readAdminConnector(final RootCfgClient root, final List<OpenDsException> errors)
{
try
{
AdministrationConnectorCfgClient adminConnector = root.getAdministrationConnector();
this.adminConnector = getConnectionHandler(adminConnector);
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
private void readConnectionHandlers(final Set<ConnectionHandlerDescriptor> connectionHandlers,
RootCfgClient root, final List<OpenDsException> errors) throws ConcurrentModificationException,
AuthorizationException, CommunicationException
{
for (String connHandler : root.listConnectionHandlers())
{
try
{
ConnectionHandlerCfgClient connectionHandler = root.getConnectionHandler(connHandler);
connectionHandlers.add(getConnectionHandler(connectionHandler, connHandler));
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
}
private void readBackendConfiguration(final Set<BackendDescriptor> backendDescriptors,
final RootCfgClient root, final List<OpenDsException> errors) throws Exception
{
for (final String backendName : root.listBackends())
{
try
{
BackendCfgClient backend = root.getBackend(backendName);
Set<BaseDNDescriptor> baseDNs = new HashSet<BaseDNDescriptor>();
for (DN dn : backend.getBaseDN())
{
BaseDNDescriptor baseDN = new BaseDNDescriptor(BaseDNDescriptor.Type.NOT_REPLICATED, dn, null, -1, -1, -1);
baseDNs.add(baseDN);
}
Set<IndexDescriptor> indexes = new HashSet<IndexDescriptor>();
Set<VLVIndexDescriptor> vlvIndexes = new HashSet<VLVIndexDescriptor>();
BackendDescriptor.Type type;
if (backend instanceof LocalDBBackendCfgClient)
{
type = BackendDescriptor.Type.LOCAL_DB;
refreshLocalDBBackendConfig(indexes, vlvIndexes, backend, errors);
}
else if (backend instanceof PluggableBackendCfgClient)
{
type = BackendDescriptor.Type.PLUGGABLE;
refreshBackendConfig(indexes, vlvIndexes, backend, errors);
}
else if (backend instanceof LDIFBackendCfgClient)
{
type = BackendDescriptor.Type.LDIF;
}
else if (backend instanceof MemoryBackendCfgClient)
{
type = BackendDescriptor.Type.MEMORY;
}
else if (backend instanceof BackupBackendCfgClient)
{
type = BackendDescriptor.Type.BACKUP;
}
else if (backend instanceof MonitorBackendCfgClient)
{
type = BackendDescriptor.Type.MONITOR;
}
else if (backend instanceof TaskBackendCfgClient)
{
type = BackendDescriptor.Type.TASK;
}
else
{
type = BackendDescriptor.Type.OTHER;
}
BackendDescriptor desc = new BackendDescriptor(
backend.getBackendId(), baseDNs, indexes, vlvIndexes, -1, backend.isEnabled(), type);
for (AbstractIndexDescriptor index: indexes)
{
index.setBackend(desc);
}
for (AbstractIndexDescriptor index: vlvIndexes)
{
index.setBackend(desc);
}
for (BaseDNDescriptor baseDN : baseDNs)
{
baseDN.setBackend(desc);
}
backendDescriptors.add(desc);
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
}
private void refreshBackendConfig(final Set<IndexDescriptor> indexes,
final Set<VLVIndexDescriptor> vlvIndexes, final BackendCfgClient backend, final List<OpenDsException> errors)
{
final PluggableBackendCfgClient db = (PluggableBackendCfgClient) backend;
readBackendIndexes(indexes, errors, db);
readBackendVLVIndexes(vlvIndexes, errors, db);
}
private void readBackendIndexes(final Set<IndexDescriptor> indexes, final List<OpenDsException> errors,
final PluggableBackendCfgClient db)
{
indexes.add(new IndexDescriptor(
SuffixContainer.DN2ID_INDEX_NAME, null, null, new TreeSet<IndexTypeDescriptor>(), -1));
// FIXME: Remove the two following indexes when they will be deleted
indexes.add(new IndexDescriptor(
SuffixContainer.ID2CHILDREN_INDEX_NAME, null, null, new TreeSet<IndexTypeDescriptor>(), -1));
indexes.add(new IndexDescriptor(
SuffixContainer.ID2SUBTREE_INDEX_NAME, null, null, new TreeSet<IndexTypeDescriptor>(), -1));
try
{
for (final String indexName : db.listBackendIndexes())
{
final BackendIndexCfgClient index = db.getBackendIndex(indexName);
indexes.add(new IndexDescriptor(
index.getAttribute().getNameOrOID(), index.getAttribute(),
null, IndexTypeDescriptor.fromBackendIndexTypes(index.getIndexType()), index.getIndexEntryLimit()));
}
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
private void readBackendVLVIndexes(final Set<VLVIndexDescriptor> vlvIndexes,
final List<OpenDsException> errors, final PluggableBackendCfgClient db)
{
try
{
for (final String vlvIndexName : db.listBackendVLVIndexes())
{
final BackendVLVIndexCfgClient index = db.getBackendVLVIndex(vlvIndexName);
final List<VLVSortOrder> sortOrder = getVLVSortOrder(index.getSortOrder());
vlvIndexes.add(new VLVIndexDescriptor(
index.getName(), null, index.getBaseDN(), VLVIndexDescriptor.toSearchScope(index.getScope()),
index.getFilter(), sortOrder));
}
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
@RemoveOnceLocalDBBackendIsPluggable
private void refreshLocalDBBackendConfig(final Set<IndexDescriptor> indexes,
final Set<VLVIndexDescriptor> vlvIndexes, final BackendCfgClient backend, final List<OpenDsException> errors)
{
LocalDBBackendCfgClient localDBBackend = (LocalDBBackendCfgClient)backend;
try
{
for (String indexName : localDBBackend.listLocalDBIndexes())
{
LocalDBIndexCfgClient index = localDBBackend.getLocalDBIndex(indexName);
indexes.add(new IndexDescriptor(
index.getAttribute().getNameOrOID(), index.getAttribute(),
null, IndexTypeDescriptor.fromLocalDBIndexTypes(index.getIndexType()), index.getIndexEntryLimit()));
}
}
catch (OpenDsException oe)
{
errors.add(oe);
}
indexes.add(new IndexDescriptor(
SuffixContainer.DN2ID_INDEX_NAME, null, null, new TreeSet<IndexTypeDescriptor>(), -1));
if (localDBBackend.isSubordinateIndexesEnabled())
{
indexes.add(new IndexDescriptor(
SuffixContainer.ID2CHILDREN_INDEX_NAME, null, null, new TreeSet<IndexTypeDescriptor>(), -1));
indexes.add(new IndexDescriptor(
SuffixContainer.ID2SUBTREE_INDEX_NAME, null, null, new TreeSet<IndexTypeDescriptor>(), -1));
}
try
{
for (String vlvIndexName : localDBBackend.listLocalDBVLVIndexes())
{
LocalDBVLVIndexCfgClient index = localDBBackend.getLocalDBVLVIndex(vlvIndexName);
String s = index.getSortOrder();
List<VLVSortOrder> sortOrder = getVLVSortOrder(s);
vlvIndexes.add(new VLVIndexDescriptor(
index.getName(), null, index.getBaseDN(), VLVIndexDescriptor.toSearchScope(index.getScope()),
index.getFilter(), sortOrder));
}
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
private boolean readIfReplicationIsSecure(final RootCfgClient root, final List<OpenDsException> errors)
{
try
{
return root.getCryptoManager().isSSLEncryption();
}
catch (OpenDsException oe)
{
errors.add(oe);
return false;
}
}
private ReplicationSynchronizationProviderCfgClient readSyncProviderIfExists(final RootCfgClient root)
{
try
{
return (ReplicationSynchronizationProviderCfgClient) root.getSynchronizationProvider(SYNC_PROVIDER_NAME);
}
catch (OpenDsException oe)
{
return null;
}
}
private void readReplicationConfig(final Set<ConnectionHandlerDescriptor> connectionHandlers,
final Set<BackendDescriptor> backendDescriptors, final ReplicationSynchronizationProviderCfgClient sync,
boolean isReplicationSecure, final List<OpenDsException> errors)
{
replicationPort = -1;
try
{
if (sync.isEnabled() && sync.hasReplicationServer())
{
ReplicationServerCfgClient replicationServer = sync.getReplicationServer();
if (replicationServer != null)
{
replicationPort = replicationServer.getReplicationPort();
ConnectionHandlerDescriptor.Protocol protocol =
isReplicationSecure ? ConnectionHandlerDescriptor.Protocol.REPLICATION_SECURE
: ConnectionHandlerDescriptor.Protocol.REPLICATION;
Set<CustomSearchResult> emptySet = Collections.emptySet();
ConnectionHandlerDescriptor connHandler = new ConnectionHandlerDescriptor(
new HashSet<InetAddress>(), replicationPort, protocol, ConnectionHandlerDescriptor.State.ENABLED,
SYNC_PROVIDER_NAME, emptySet);
connectionHandlers.add(connHandler);
}
}
String[] domains = sync.listReplicationDomains();
if (domains != null)
{
for (String domain2 : domains)
{
ReplicationDomainCfgClient domain = sync.getReplicationDomain(domain2);
DN dn = domain.getBaseDN();
for (BackendDescriptor backend : backendDescriptors)
{
for (BaseDNDescriptor baseDN : backend.getBaseDns())
{
if (baseDN.getDn().equals(dn))
{
baseDN.setType(sync.isEnabled() ? BaseDNDescriptor.Type.REPLICATED
: BaseDNDescriptor.Type.DISABLED);
baseDN.setReplicaID(domain.getServerId());
}
}
}
}
}
}
catch (OpenDsException oe)
{
errors.add(oe);
}
}
private void readAlternateBindDNs(final Set<DN> alternateBindDNs, final RootCfgClient root,
final List<OpenDsException> errors)
{
try
{
RootDNCfgClient rootDN = root.getRootDN();
String[] rootUsers = rootDN.listRootDNUsers();
if (rootUsers != null)
{
for (String rootUser2 : rootUsers)
{
RootDNUserCfgClient rootUser = rootDN.getRootDNUser(rootUser2);
alternateBindDNs.addAll(rootUser.getAlternateBindDN());
}
}
}
catch (OpenDsException oe)
{
errors.add(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.
*/
private void readSchema(InitialLdapContext ctx) throws OpenDsException
{
try
{
if (isLocal)
{
super.readSchema();
}
else
{
RemoteSchemaLoader loader = new RemoteSchemaLoader();
loader.readSchema(ctx);
schema = loader.getSchema();
}
}
catch (NamingException ne)
{
throw new OnlineUpdateException(ERR_READING_SCHEMA_LDAP.get(ne), ne);
}
catch (ConfigException ce)
{
throw new org.opends.server.config.ConfigException(ce.getMessageObject(), 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.
*/
protected void handleMonitoringSearchResult(SearchResult sr,
String searchBaseDN)
throws NamingException
{
if (javaVersion == null)
{
javaVersion = ConnectionUtils.getFirstValue(sr, "javaVersion");
}
if (numberConnections == -1)
{
String v = ConnectionUtils.getFirstValue(sr, "currentConnections");
if (v != null)
{
numberConnections = Integer.parseInt(v);
}
}
String dn = ConnectionUtils.getFirstValue(sr, "domain-name");
String replicaId = ConnectionUtils.getFirstValue(sr, "server-id");
String missingChanges = ConnectionUtils.getFirstValue(sr, "missing-changes");
if ((dn != null) && (replicaId != null) && (missingChanges != null))
{
for (BackendDescriptor backend : backends)
{
for (BaseDNDescriptor baseDN : backend.getBaseDns())
{
try
{
if (baseDN.getDn().equals(DN.valueOf(dn)) &&
Integer.toString(baseDN.getReplicaID()).equals(replicaId))
{
try
{
baseDN.setAgeOfOldestMissingChange(
Long.valueOf(ConnectionUtils.getFirstValue(sr, "approx-older-change-not-synchronized-millis")));
}
catch (Throwable t)
{
}
try
{
baseDN.setMissingChanges(Integer.valueOf(missingChanges));
}
catch (Throwable t)
{
}
}
}
catch (Throwable t)
{
}
}
}
}
else
{
CustomSearchResult csr = new CustomSearchResult(sr, searchBaseDN);
String backendID = ConnectionUtils.getFirstValue(sr, "ds-backend-id");
String entryCount = ConnectionUtils.getFirstValue(sr, "ds-backend-entry-count");
Set<String> baseDnEntries = ConnectionUtils.getValues(sr, "ds-base-dn-entry-count");
if ((backendID != null) && ((entryCount != null) || (baseDnEntries != null)))
{
for (BackendDescriptor backend : backends)
{
if (backend.getBackendID().equalsIgnoreCase(backendID))
{
if (entryCount != null)
{
backend.setEntries(Integer.parseInt(entryCount));
}
if (baseDnEntries != null)
{
for (String s : baseDnEntries)
{
int index = s.indexOf(" ");
if (index != -1)
{
for (BaseDNDescriptor baseDN : backend.getBaseDns())
{
dn = s.substring(index +1);
if (Utilities.areDnsEqual(dn,
baseDN.getDn().toString()))
{
try
{
baseDN.setEntries(
Integer.parseInt(s.substring(0, index)));
}
catch (Throwable t)
{
/* Ignore */
}
break;
}
}
}
}
}
}
}
}
else
{
// Check if it is the DB monitor entry
String cn = ConnectionUtils.getFirstValue(sr, "cn");
if ((cn != null) && cn.endsWith(DATABASE_ENVIRONMENT_SUFFIX))
{
String monitorBackendID = cn.substring(0, cn.length() - DATABASE_ENVIRONMENT_SUFFIX.length());
for (BackendDescriptor backend : backends)
{
if (backend.getBackendID().equalsIgnoreCase(monitorBackendID))
{
backend.setMonitoringEntry(csr);
}
}
}
}
try
{
if ((rootMonitor == null) && isRootMonitor(csr))
{
rootMonitor = csr;
}
else if ((entryCaches == null) && isEntryCaches(csr))
{
entryCaches = csr;
}
else if ((workQueue == null) && isWorkQueue(csr))
{
workQueue = csr;
}
else if ((jvmMemoryUsage == null) && isJvmMemoryUsage(csr))
{
jvmMemoryUsage = csr;
}
else if ((systemInformation == null) && isSystemInformation(csr))
{
systemInformation = csr;
}
else if ((versionMonitor == null) && isVersionMonitor(csr))
{
versionMonitor = csr;
}
else if (isConnectionHandler(csr))
{
String statistics = " Statistics";
String cn = ConnectionUtils.getFirstValue(sr, "cn");
if (cn.endsWith(statistics))
{
// Assume it is a connection handler
String name = cn.substring(0, cn.length() - statistics.length());
hmConnectionHandlersMonitor.put(getKey(name), csr);
}
}
}
catch (OpenDsException ode)
{
exceptions.add(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,
List<OpenDsException> ex) throws NamingException
{
CustomSearchResult csr = new CustomSearchResult(sr, searchBaseDN);
try
{
if (isTaskEntry(csr))
{
taskEntries.add(new TaskEntry(csr.getEntry()));
}
}
catch (OpenDsException ode)
{
ex.add(ode);
}
}
private void updateMonitorInformation(InitialLdapContext ctx,
List<OpenDsException> ex)
{
// Read monitoring information: since it is computed, it is faster
// to get everything in just one request.
SearchControls ctls = new SearchControls();
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctls.setReturningAttributes(getMonitoringAttributes());
String filter = "(objectclass=*)";
try
{
LdapName jndiName = new LdapName("cn=monitor");
NamingEnumeration<SearchResult> monitorEntries = ctx.search(jndiName, filter, ctls);
javaVersion = null;
numberConnections = -1;
try
{
while (monitorEntries.hasMore())
{
SearchResult sr = monitorEntries.next();
handleMonitoringSearchResult(sr, "cn=monitor");
}
}
finally
{
monitorEntries.close();
}
}
catch (NamingException ne)
{
ex.add(new OnlineUpdateException(ERR_READING_CONFIG_LDAP.get(ne.getMessage()), 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.
SearchControls ctls = new SearchControls();
ctls.setSearchScope(SearchControls.SUBTREE_SCOPE);
ctls.setReturningAttributes(getMonitoringAttributes());
String filter = "(objectclass=ds-task)";
try
{
LdapName jndiName = new LdapName(ConfigConstants.DN_TASK_ROOT);
NamingEnumeration<SearchResult> taskEntries = ctx.search(jndiName, filter, ctls);
try
{
while (taskEntries.hasMore())
{
SearchResult sr = taskEntries.next();
handleTaskSearchResult(sr, ConfigConstants.DN_TASK_ROOT, ts, ex);
}
}
finally
{
taskEntries.close();
}
}
catch (NamingException ne)
{
ex.add(new OnlineUpdateException(ERR_READING_CONFIG_LDAP.get(ne.getMessage()), ne));
}
}
private ConnectionHandlerDescriptor getConnectionHandler(ConnectionHandlerCfgClient connHandler, String name)
throws OpenDsException
{
SortedSet<InetAddress> addresses = new TreeSet<InetAddress>(getInetAddressComparator());
int port;
ConnectionHandlerDescriptor.Protocol protocol;
ConnectionHandlerDescriptor.State state = connHandler.isEnabled() ? ConnectionHandlerDescriptor.State.ENABLED
: ConnectionHandlerDescriptor.State.DISABLED;
if (connHandler instanceof LDAPConnectionHandlerCfgClient)
{
LDAPConnectionHandlerCfgClient ldap = (LDAPConnectionHandlerCfgClient)connHandler;
if (ldap.isUseSSL())
{
protocol = ConnectionHandlerDescriptor.Protocol.LDAPS;
}
else if (ldap.isAllowStartTLS())
{
protocol = ConnectionHandlerDescriptor.Protocol.LDAP_STARTTLS;
}
else
{
protocol = ConnectionHandlerDescriptor.Protocol.LDAP;
}
addAll(addresses, ldap.getListenAddress());
port = ldap.getListenPort();
}
else if (connHandler instanceof HTTPConnectionHandlerCfgClient)
{
HTTPConnectionHandlerCfgClient http = (HTTPConnectionHandlerCfgClient) connHandler;
if (http.isUseSSL())
{
protocol = ConnectionHandlerDescriptor.Protocol.HTTPS;
}
else
{
protocol = ConnectionHandlerDescriptor.Protocol.HTTP;
}
addAll(addresses, http.getListenAddress());
port = http.getListenPort();
}
else if (connHandler instanceof JMXConnectionHandlerCfgClient)
{
JMXConnectionHandlerCfgClient jmx = (JMXConnectionHandlerCfgClient)connHandler;
if (jmx.isUseSSL())
{
protocol = ConnectionHandlerDescriptor.Protocol.JMXS;
}
else
{
protocol = ConnectionHandlerDescriptor.Protocol.JMX;
}
addresses.add(jmx.getListenAddress());
port = jmx.getListenPort();
}
else if (connHandler instanceof LDIFConnectionHandlerCfgClient)
{
protocol = ConnectionHandlerDescriptor.Protocol.LDIF;
port = -1;
}
else if (connHandler instanceof SNMPConnectionHandlerCfgClient)
{
protocol = ConnectionHandlerDescriptor.Protocol.SNMP;
SNMPConnectionHandlerCfgClient snmp = (SNMPConnectionHandlerCfgClient)connHandler;
addAll(addresses, snmp.getListenAddress());
port = snmp.getListenPort();
}
else
{
protocol = ConnectionHandlerDescriptor.Protocol.OTHER;
port = -1;
}
Set<CustomSearchResult> emptySet = Collections.emptySet();
return new ConnectionHandlerDescriptor(addresses, port, protocol, state, name, emptySet);
}
private <T> void addAll(Collection<T> target, Collection<T> source)
{
if (source != null)
{
target.addAll(source);
}
}
private ConnectionHandlerDescriptor getConnectionHandler(AdministrationConnectorCfgClient adminConnector)
throws OpenDsException
{
SortedSet<InetAddress> addresses = new TreeSet<InetAddress>(getInetAddressComparator());
ConnectionHandlerDescriptor.Protocol protocol = ConnectionHandlerDescriptor.Protocol.ADMINISTRATION_CONNECTOR;
ConnectionHandlerDescriptor.State state = ConnectionHandlerDescriptor.State.ENABLED;
addAll(addresses, adminConnector.getListenAddress());
int port = adminConnector.getListenPort();
Set<CustomSearchResult> emptySet = Collections.emptySet();
return new ConnectionHandlerDescriptor(
addresses, port, protocol, state, INFO_CTRL_PANEL_CONN_HANDLER_ADMINISTRATION.get().toString(), emptySet);
}
private boolean isRootMonitor(CustomSearchResult csr) throws OpenDsException
{
return monitorDN.equals(DN.valueOf(csr.getDN()));
}
private boolean isVersionMonitor(CustomSearchResult csr) throws OpenDsException
{
return versionDN.equals(DN.valueOf(csr.getDN()));
}
private boolean isSystemInformation(CustomSearchResult csr) throws OpenDsException
{
return systemInformationDN.equals(DN.valueOf(csr.getDN()));
}
private boolean isJvmMemoryUsage(CustomSearchResult csr) throws OpenDsException
{
return jvmMemoryUsageDN.equals(DN.valueOf(csr.getDN()));
}
private boolean isWorkQueue(CustomSearchResult csr) throws OpenDsException
{
return workQueueDN.equals(DN.valueOf(csr.getDN()));
}
private boolean isEntryCaches(CustomSearchResult csr) throws OpenDsException
{
return entryCachesDN.equals(DN.valueOf(csr.getDN()));
}
private boolean isConnectionHandler(CustomSearchResult csr) throws OpenDsException
{
boolean isConnectionHandler = false;
DN dn = DN.valueOf(csr.getDN());
DN parent = dn.parent();
if ((parent != null) && parent.equals(monitorDN))
{
List<?> vs = csr.getAttributeValues("cn");
if ((vs != null) && !vs.isEmpty())
{
String cn = (String) vs.iterator().next();
String statistics = " Statistics";
if (cn.endsWith(statistics))
{
isConnectionHandler = true;
}
}
}
return isConnectionHandler;
}
private static boolean isTaskEntry(CustomSearchResult csr) throws OpenDsException
{
boolean isTaskEntry = false;
List<Object> vs = csr.getAttributeValues("objectclass");
if ((vs != null) && !vs.isEmpty())
{
for (Object oc : vs)
{
if (oc.toString().equalsIgnoreCase("ds-task"))
{
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.
*/
private String getKey(String value)
{
return value.toLowerCase();
}
private Set<CustomSearchResult>getMonitoringEntries(ConnectionHandlerDescriptor ch)
{
Set<CustomSearchResult> monitorEntries = new HashSet<CustomSearchResult>();
if (ch.getState() == ConnectionHandlerDescriptor.State.ENABLED)
{
for (String key : hmConnectionHandlersMonitor.keySet())
{
// 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.
if (key.contains(getKey("port " + ch.getPort())))
{
boolean hasAllAddresses = true;
for (InetAddress a : ch.getAddresses())
{
if (!key.contains(getKey(a.getHostAddress())))
{
hasAllAddresses = false;
break;
}
}
if (hasAllAddresses)
{
monitorEntries.add(hmConnectionHandlersMonitor.get(key));
}
}
}
}
return monitorEntries;
}
}