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