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.Entry;
032import com.unboundid.util.NotMutable;
033import com.unboundid.util.StaticUtils;
034import com.unboundid.util.ThreadSafety;
035import com.unboundid.util.ThreadSafetyLevel;
036
037import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
038
039
040
041/**
042 * This class defines a monitor entry that provides summary information about
043 * a replicated data set within the Directory Server.
044 * <BR>
045 * <BLOCKQUOTE>
046 *   <B>NOTE:</B>  This class, and other classes within the
047 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
048 *   supported for use against Ping Identity, UnboundID, and
049 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
050 *   for proprietary functionality or for external specifications that are not
051 *   considered stable or mature enough to be guaranteed to work in an
052 *   interoperable way with other types of LDAP servers.
053 * </BLOCKQUOTE>
054 * <BR>
055 * The server will present a replication summary monitor entry for each base DN
056 * for which replication is enabled, and it will include information about each
057 * replica and replication server processing changes for that base DN.
058 * Replication summary monitor entries can be retrieved using the
059 * {@link MonitorManager#getReplicationSummaryMonitorEntries} method.  The
060 * {@link #getBaseDN} method may be used to retrieve information about the
061 * replicated base DN, the {@link #getReplicationServers} method may be used to
062 * retrieve information about the replication servers for that base DN, and the
063 * {@link #getReplicas} method may be used to retrieve information about the
064 * replicas for that base DN.  Alternately, this information may be accessed
065 * using the generic API.  See the {@link MonitorManager} class documentation
066 * for an example that demonstrates the use of the generic API for accessing
067 * monitor data.
068 */
069@NotMutable()
070@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
071public final class ReplicationSummaryMonitorEntry
072       extends MonitorEntry
073{
074  /**
075   * The structural object class used in replication summary monitor entries.
076   */
077  static final String REPLICATION_SUMMARY_MONITOR_OC =
078       "ds-replication-server-summary-monitor-entry";
079
080
081
082  /**
083   * The name of the attribute that contains the base DN for the replicated
084   * data.
085   */
086  private static final String ATTR_BASE_DN = "base-dn";
087
088
089
090  /**
091   * The name of the attribute that contains information about the replication
092   * servers for the replicated data.
093   */
094  private static final String ATTR_REPLICATION_SERVER = "replication-server";
095
096
097
098  /**
099   * The name of the attribute that contains information about the replicas
100   * for the replicated data.
101   */
102  private static final String ATTR_REPLICA = "replica";
103
104
105
106  /**
107   * The serial version UID for this serializable class.
108   */
109  private static final long serialVersionUID = 3144471025744197014L;
110
111
112
113  // The base DN for the replicated data.
114  private final String baseDN;
115
116  // The list of replicas for the replicated data.
117  private final List<ReplicationSummaryReplica> replicas;
118
119  // The list of replication servers for the replicated data.
120  private final List<ReplicationSummaryReplicationServer> replicationServers;
121
122
123
124  /**
125   * Creates a new replication summary monitor entry from the provided entry.
126   *
127   * @param  entry  The entry to be parsed as a replication summary monitor
128   *                entry.  It must not be {@code null}.
129   */
130  public ReplicationSummaryMonitorEntry(final Entry entry)
131  {
132    super(entry);
133
134    baseDN = getString(ATTR_BASE_DN);
135
136    final List<String> replicaStrings = getStrings(ATTR_REPLICA);
137    final ArrayList<ReplicationSummaryReplica> replList =
138         new ArrayList<>(replicaStrings.size());
139    for (final String s : replicaStrings)
140    {
141      replList.add(new ReplicationSummaryReplica(s));
142    }
143    replicas = Collections.unmodifiableList(replList);
144
145    final List<String> serverStrings = getStrings(ATTR_REPLICATION_SERVER);
146    final ArrayList<ReplicationSummaryReplicationServer> serverList =
147         new ArrayList<>(serverStrings.size());
148    for (final String s : serverStrings)
149    {
150      serverList.add(new ReplicationSummaryReplicationServer(s));
151    }
152    replicationServers = Collections.unmodifiableList(serverList);
153  }
154
155
156
157  /**
158   * Retrieves the base DN for this replication summary monitor entry.
159   *
160   * @return  The base DN for this replication summary monitor entry, or
161   *          {@code null} if it was not included in the monitor entry.
162   */
163  public String getBaseDN()
164  {
165    return baseDN;
166  }
167
168
169
170  /**
171   * Retrieves a list of information about the replicas described in this
172   * replication server summary monitor entry.
173   *
174   * @return  A list of information about the replicas described in this
175   *          replication server summary monitor entry, or an empty list if it
176   *          was not included in the monitor entry.
177   */
178  public List<ReplicationSummaryReplica> getReplicas()
179  {
180    return replicas;
181  }
182
183
184
185  /**
186   * Retrieves a list of information about the replication servers described in
187   * this replication server summary monitor entry.
188   *
189   * @return  A list of information about the replication servers described in
190   *          this replication server summary monitor entry, or an empty list if
191   *          it was not included in the monitor entry.
192   */
193  public List<ReplicationSummaryReplicationServer> getReplicationServers()
194  {
195    return replicationServers;
196  }
197
198
199
200  /**
201   * {@inheritDoc}
202   */
203  @Override()
204  public String getMonitorDisplayName()
205  {
206    return INFO_REPLICATION_SUMMARY_MONITOR_DISPNAME.get();
207  }
208
209
210
211  /**
212   * {@inheritDoc}
213   */
214  @Override()
215  public String getMonitorDescription()
216  {
217    return INFO_REPLICATION_SUMMARY_MONITOR_DESC.get();
218  }
219
220
221
222  /**
223   * {@inheritDoc}
224   */
225  @Override()
226  public Map<String,MonitorAttribute> getMonitorAttributes()
227  {
228    final LinkedHashMap<String,MonitorAttribute> attrs =
229         new LinkedHashMap<>(StaticUtils.computeMapCapacity(10));
230
231    if (baseDN != null)
232    {
233      addMonitorAttribute(attrs,
234           ATTR_BASE_DN,
235           INFO_REPLICATION_SUMMARY_DISPNAME_BASE_DN.get(),
236           INFO_REPLICATION_SUMMARY_DESC_BASE_DN.get(),
237           baseDN);
238    }
239
240    if (! replicas.isEmpty())
241    {
242      final ArrayList<String> replStrings = new ArrayList<>(replicas.size());
243      for (final ReplicationSummaryReplica r : replicas)
244      {
245        replStrings.add(r.toString());
246      }
247
248      addMonitorAttribute(attrs,
249           ATTR_REPLICA,
250           INFO_REPLICATION_SUMMARY_DISPNAME_REPLICA.get(),
251           INFO_REPLICATION_SUMMARY_DESC_REPLICA.get(),
252           replStrings);
253    }
254
255    if (! replicationServers.isEmpty())
256    {
257      final ArrayList<String> serverStrings =
258           new ArrayList<>(replicationServers.size());
259      for (final ReplicationSummaryReplicationServer s : replicationServers)
260      {
261        serverStrings.add(s.toString());
262      }
263
264      addMonitorAttribute(attrs,
265           ATTR_REPLICATION_SERVER,
266           INFO_REPLICATION_SUMMARY_DISPNAME_REPLICATION_SERVER.get(),
267           INFO_REPLICATION_SUMMARY_DESC_REPLICATION_SERVER.get(),
268           serverStrings);
269    }
270
271    return Collections.unmodifiableMap(attrs);
272  }
273}