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