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