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