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