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