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