001/* 002 * Copyright 2009-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2019 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.monitors; 022 023 024 025import java.util.ArrayList; 026import java.util.Collections; 027import java.util.LinkedHashMap; 028import java.util.List; 029import java.util.Map; 030 031import com.unboundid.ldap.sdk.DN; 032import com.unboundid.ldap.sdk.Entry; 033import com.unboundid.util.Debug; 034import com.unboundid.util.NotMutable; 035import com.unboundid.util.StaticUtils; 036import com.unboundid.util.ThreadSafety; 037import com.unboundid.util.ThreadSafetyLevel; 038 039import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 040 041 042 043/** 044 * This class defines a monitor entry that provides information about the state 045 * of a replication server, including the base DNs for replicated content, the 046 * generation ID for each of those base DNs, the replication server ID, and the 047 * port number on which the replication server is listening. 048 * <BR> 049 * <BLOCKQUOTE> 050 * <B>NOTE:</B> This class, and other classes within the 051 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 052 * supported for use against Ping Identity, UnboundID, and 053 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 054 * for proprietary functionality or for external specifications that are not 055 * considered stable or mature enough to be guaranteed to work in an 056 * interoperable way with other types of LDAP servers. 057 * </BLOCKQUOTE> 058 * <BR> 059 * The server should present at most one replication server monitor entry. It 060 * can be retrieved using the 061 * {@link MonitorManager#getReplicationServerMonitorEntry} method. This entry 062 * provides specific methods for accessing information about the replication 063 * server. Alternately, this information may be accessed using the generic API. 064 * See the {@link MonitorManager} class documentation for an example that 065 * demonstrates the use of the generic API for accessing monitor data. 066 */ 067@NotMutable() 068@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 069public final class ReplicationServerMonitorEntry 070 extends MonitorEntry 071{ 072 /** 073 * The structural object class used in replication server monitor entries. 074 */ 075 static final String REPLICATION_SERVER_MONITOR_OC = 076 "ds-replication-server-monitor-entry"; 077 078 079 080 /** 081 * The name of the attribute that contains the base DNs for the replicated 082 * data. 083 */ 084 private static final String ATTR_BASE_DN = "base-dn"; 085 086 087 088 /** 089 * The name of the attribute that contains the generation IDs that correspond 090 * to the replicated base DNs. 091 */ 092 private static final String ATTR_BASE_DN_GENERATION_ID = 093 "base-dn-generation-id"; 094 095 096 097 /** 098 * The name of the attribute that contains the server ID for the replication 099 * server. 100 */ 101 private static final String ATTR_REPLICATION_SERVER_ID = 102 "replication-server-id"; 103 104 105 106 /** 107 * The name of the attribute that contains the port number on which the 108 * replication server listens for communication from other servers. 109 */ 110 private static final String ATTR_REPLICATION_SERVER_PORT = 111 "replication-server-port"; 112 113 114 115 /** 116 * The name of the attribute that indicates whether SSL encryption is 117 * available for use. 118 */ 119 private static final String ATTR_SSL_AVAILABLE = 120 "ssl-encryption-available"; 121 122 123 124 /** 125 * The serial version UID for this serializable class. 126 */ 127 private static final long serialVersionUID = 7488640967498574690L; 128 129 130 131 // Indicates whether SSL encryption is available. 132 private final Boolean sslEncryptionAvailable; 133 134 // The base DNs for the replicated data. 135 private final List<String> baseDNs; 136 137 // The port number on which the replication server listens for communication 138 // from other servers. 139 private final Long replicationServerPort; 140 141 // A map of the generation IDs for each of the replicated base DNs. 142 private final Map<DN,String> generationIDs; 143 144 // The replication server ID for the replication server. 145 private final String replicationServerID; 146 147 148 149 /** 150 * Creates a new replication server monitor entry from the provided entry. 151 * 152 * @param entry The entry to be parsed as a replication server monitor 153 * entry. It must not be {@code null}. 154 */ 155 public ReplicationServerMonitorEntry(final Entry entry) 156 { 157 super(entry); 158 159 baseDNs = getStrings(ATTR_BASE_DN); 160 replicationServerID = getString(ATTR_REPLICATION_SERVER_ID); 161 replicationServerPort = getLong(ATTR_REPLICATION_SERVER_PORT); 162 sslEncryptionAvailable = getBoolean(ATTR_SSL_AVAILABLE); 163 164 final List<String> baseDNsAndIDs = getStrings(ATTR_BASE_DN_GENERATION_ID); 165 final Map<DN,String> idMap = new LinkedHashMap<>( 166 StaticUtils.computeMapCapacity(baseDNsAndIDs.size())); 167 for (final String s : baseDNsAndIDs) 168 { 169 try 170 { 171 final int lastSpacePos = s.lastIndexOf(' '); 172 final DN dn = new DN(s.substring(0, lastSpacePos)); 173 idMap.put(dn, s.substring(lastSpacePos+1)); 174 } 175 catch (final Exception e) 176 { 177 Debug.debugException(e); 178 } 179 } 180 generationIDs = Collections.unmodifiableMap(idMap); 181 } 182 183 184 185 /** 186 * Retrieves the base DNs for replicated content managed by this replication 187 * server. 188 * 189 * @return The base DNs for replicated content managed by this replication 190 * server, or an empty list if it was not included in the monitor 191 * entry. 192 */ 193 public List<String> getBaseDNs() 194 { 195 return baseDNs; 196 } 197 198 199 200 /** 201 * Retrieves a map of generation IDs for the available base DNs. 202 * 203 * @return A map of generation IDs for the available base DNs, or an empty 204 * map if it was not included in the monitor entry. 205 */ 206 public Map<DN,String> getGenerationIDs() 207 { 208 return generationIDs; 209 } 210 211 212 213 /** 214 * Retrieves the generation ID for the specified base DN. 215 * 216 * @param baseDN The base DN for which to retrieve the generation ID. 217 * 218 * @return The generation ID for the specified base DN, or {@code null} if 219 * there no generation ID is available for the provided base DN, or 220 * the provided base DN is not a valid DN. 221 */ 222 public String getGenerationID(final String baseDN) 223 { 224 try 225 { 226 return getGenerationID(new DN(baseDN)); 227 } 228 catch (final Exception e) 229 { 230 Debug.debugException(e); 231 return null; 232 } 233 } 234 235 236 237 /** 238 * Retrieves the generation ID for the specified base DN. 239 * 240 * @param baseDN The base DN for which to retrieve the generation ID. 241 * 242 * @return The generation ID for the specified base DN, or {@code null} if 243 * there no generation ID is available for the provided base DN. 244 */ 245 public String getGenerationID(final DN baseDN) 246 { 247 return generationIDs.get(baseDN); 248 } 249 250 251 252 /** 253 * Retrieves the server ID for the replication server. 254 * 255 * @return The server ID for the replication server, or {@code null} if it 256 * was not included in the monitor entry. 257 */ 258 public String getReplicationServerID() 259 { 260 return replicationServerID; 261 } 262 263 264 265 /** 266 * Retrieves the port number for the replication server. 267 * 268 * @return The port number for the replication server, or {@code null} if it 269 * was not included in the monitor entry. 270 */ 271 public Long getReplicationServerPort() 272 { 273 return replicationServerPort; 274 } 275 276 277 278 /** 279 * Indicates whether the replication server provides support for SSL 280 * encryption. 281 * 282 * @return {@code true} if the replication server supports SSL encryption, 283 * {@code false} if it does not, or {@code null} if that information 284 * was not included in the monitor entry. 285 */ 286 public Boolean sslEncryptionAvailable() 287 { 288 return sslEncryptionAvailable; 289 } 290 291 292 293 /** 294 * {@inheritDoc} 295 */ 296 @Override() 297 public String getMonitorDisplayName() 298 { 299 return INFO_REPLICATION_SERVER_MONITOR_DISPNAME.get(); 300 } 301 302 303 304 /** 305 * {@inheritDoc} 306 */ 307 @Override() 308 public String getMonitorDescription() 309 { 310 return INFO_REPLICATION_SERVER_MONITOR_DESC.get(); 311 } 312 313 314 315 /** 316 * {@inheritDoc} 317 */ 318 @Override() 319 public Map<String,MonitorAttribute> getMonitorAttributes() 320 { 321 final LinkedHashMap<String,MonitorAttribute> attrs = 322 new LinkedHashMap<>(StaticUtils.computeMapCapacity(10)); 323 324 if (! baseDNs.isEmpty()) 325 { 326 addMonitorAttribute(attrs, 327 ATTR_BASE_DN, 328 INFO_REPLICATION_SERVER_DISPNAME_BASE_DN.get(), 329 INFO_REPLICATION_SERVER_DESC_BASE_DN.get(), 330 baseDNs); 331 } 332 333 if (! generationIDs.isEmpty()) 334 { 335 final ArrayList<String> idStrings = 336 new ArrayList<>(generationIDs.size()); 337 for (final Map.Entry<DN,String> e : generationIDs.entrySet()) 338 { 339 idStrings.add(e.getKey().toNormalizedString() + ' ' + e.getValue()); 340 } 341 342 addMonitorAttribute(attrs, 343 ATTR_BASE_DN_GENERATION_ID, 344 INFO_REPLICATION_SERVER_DISPNAME_BASE_DN_GENERATION_ID.get(), 345 INFO_REPLICATION_SERVER_DESC_BASE_DN_GENERATION_ID.get(), 346 idStrings); 347 } 348 349 if (replicationServerID != null) 350 { 351 addMonitorAttribute(attrs, 352 ATTR_REPLICATION_SERVER_ID, 353 INFO_REPLICATION_SERVER_DISPNAME_REPLICATION_SERVER_ID.get(), 354 INFO_REPLICATION_SERVER_DESC_REPLICATION_SERVER_ID.get(), 355 replicationServerID); 356 } 357 358 if (replicationServerPort != null) 359 { 360 addMonitorAttribute(attrs, 361 ATTR_REPLICATION_SERVER_PORT, 362 INFO_REPLICATION_SERVER_DISPNAME_REPLICATION_SERVER_PORT.get(), 363 INFO_REPLICATION_SERVER_DESC_REPLICATION_SERVER_PORT.get(), 364 replicationServerPort); 365 } 366 367 if (sslEncryptionAvailable != null) 368 { 369 addMonitorAttribute(attrs, 370 ATTR_SSL_AVAILABLE, 371 INFO_REPLICATION_SERVER_DISPNAME_SSL_AVAILABLE.get(), 372 INFO_REPLICATION_SERVER_DESC_SSL_AVAILABLE.get(), 373 sslEncryptionAvailable); 374 } 375 376 return Collections.unmodifiableMap(attrs); 377 } 378}