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.Debug; 033import com.unboundid.util.NotMutable; 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 information about a 043 * load-balancing algorithm used by the Directory Proxy 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 * Information that it may make available includes: 056 * <UL> 057 * <LI>The aggregate health check state for servers associated with the 058 * load-balancing algorithm.</LI> 059 * <LI>Information about each server associated with the load-balancing 060 * algorithm, including the address, port, and health check state for the 061 * server.</LI> 062 * <LI>The number of available, degraded, and unavailable servers associated 063 * with the load-balancing algorithm.</LI> 064 * </UL> 065 * The server should present a load-balancing algorithm monitor entry for each 066 * load-balancing algorithm used by a proxying request processor. These entries 067 * can be retrieved using the 068 * {@link MonitorManager#getLoadBalancingAlgorithmMonitorEntries} method. These 069 * entries provide specific methods for accessing this information. 070 * Alternately, the information may be accessed using the generic API. See the 071 * {@link MonitorManager} class documentation for an example that demonstrates 072 * the use of the generic API for accessing monitor data. 073 */ 074@NotMutable() 075@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 076public final class LoadBalancingAlgorithmMonitorEntry 077 extends MonitorEntry 078{ 079 /** 080 * The structural object class used in LDAP external server monitor entries. 081 */ 082 protected static final String LOAD_BALANCING_ALGORITHM_MONITOR_OC = 083 "ds-load-balancing-algorithm-monitor-entry"; 084 085 086 087 /** 088 * The name of the attribute used to provide the name of the load-balancing 089 * algorithm. 090 */ 091 private static final String ATTR_ALGORITHM_NAME = "algorithm-name"; 092 093 094 095 /** 096 * The name of the attribute used to provide the DN of the configuration entry 097 * for the load-balancing algorithm. 098 */ 099 private static final String ATTR_CONFIG_ENTRY_DN = "config-entry-dn"; 100 101 102 103 /** 104 * The name of the attribute used to provide the aggregate health check state 105 * for the load-balancing algorithm. 106 */ 107 private static final String ATTR_HEALTH_CHECK_STATE = "health-check-state"; 108 109 110 111 /** 112 * The name of the attribute used to provide information about the health 113 * check states of each of the LDAP external servers associated with the 114 * load-balancing algorithm. 115 */ 116 private static final String ATTR_LDAP_EXTERNAL_SERVER = 117 "ldap-external-server"; 118 119 120 121 /** 122 * The name of the attribute used to provide the aggregate health check state 123 * for local servers for the load-balancing algorithm. 124 */ 125 private static final String ATTR_LOCAL_SERVERS_HEALTH_CHECK_STATE = 126 "local-servers-health-check-state"; 127 128 129 130 /** 131 * The name of the attribute used to provide the aggregate health check state 132 * for non-local servers for the load-balancing algorithm. 133 */ 134 private static final String ATTR_NON_LOCAL_SERVERS_HEALTH_CHECK_STATE = 135 "non-local-servers-health-check-state"; 136 137 138 139 /** 140 * The name of the attribute used to provide the number of servers associated 141 * with the load-balancing algorithm with a health check state of AVAILABLE. 142 */ 143 private static final String ATTR_NUM_AVAILABLE = "num-available-servers"; 144 145 146 147 /** 148 * The name of the attribute used to provide the number of servers associated 149 * with the load-balancing algorithm with a health check state of DEGRADED. 150 */ 151 private static final String ATTR_NUM_DEGRADED = "num-degraded-servers"; 152 153 154 155 /** 156 * The name of the attribute used to provide the number of servers associated 157 * with the load-balancing algorithm with a health check state of UNAVAILABLE. 158 */ 159 private static final String ATTR_NUM_UNAVAILABLE = "num-unavailable-servers"; 160 161 162 163 /** 164 * The serial version UID for this serializable class. 165 */ 166 private static final long serialVersionUID = -5251924301718025205L; 167 168 169 170 // The aggregate health check state for the load-balancing algorithm. 171 private final HealthCheckState healthCheckState; 172 173 // The aggregate health check state for local servers for the load-balancing 174 // algorithm. 175 private final HealthCheckState localServersHealthCheckState; 176 177 // The aggregate health check state for non-local servers for the 178 // load-balancing algorithm. 179 private final HealthCheckState nonLocalServersHealthCheckState; 180 181 // The list of server availability objects. 182 private final List<LoadBalancingAlgorithmServerAvailabilityData> 183 serverAvailabilityData; 184 185 // The number of servers with a health check state of AVAILABLE. 186 private final Long numAvailableServers; 187 188 // The number of servers with a health check state of DEGRADED. 189 private final Long numDegradedServers; 190 191 // The number of servers with a health check state of UNAVAILABLE. 192 private final Long numUnavailableServers; 193 194 // The name of the load-balancing algorithm. 195 private final String algorithmName; 196 197 // The DN of the configuration entry for the load-balancing algorithm. 198 private final String configEntryDN; 199 200 201 202 /** 203 * Creates a new load-balancing algorithm monitor entry from the provided 204 * entry. 205 * 206 * @param entry The entry to be parsed as a load-balancing algorithm monitor 207 * entry. It must not be {@code null}. 208 */ 209 public LoadBalancingAlgorithmMonitorEntry(final Entry entry) 210 { 211 super(entry); 212 213 algorithmName = getString(ATTR_ALGORITHM_NAME); 214 configEntryDN = getString(ATTR_CONFIG_ENTRY_DN); 215 numAvailableServers = getLong(ATTR_NUM_AVAILABLE); 216 numDegradedServers = getLong(ATTR_NUM_DEGRADED); 217 numUnavailableServers = getLong(ATTR_NUM_UNAVAILABLE); 218 219 final String hcStateStr = getString(ATTR_HEALTH_CHECK_STATE); 220 if (hcStateStr == null) 221 { 222 healthCheckState = null; 223 } 224 else 225 { 226 healthCheckState = HealthCheckState.forName(hcStateStr); 227 } 228 229 final String localHCStateStr = 230 getString(ATTR_LOCAL_SERVERS_HEALTH_CHECK_STATE); 231 if (localHCStateStr == null) 232 { 233 localServersHealthCheckState = null; 234 } 235 else 236 { 237 localServersHealthCheckState = HealthCheckState.forName(localHCStateStr); 238 } 239 240 final String nonLocalHCStateStr = 241 getString(ATTR_NON_LOCAL_SERVERS_HEALTH_CHECK_STATE); 242 if (nonLocalHCStateStr == null) 243 { 244 nonLocalServersHealthCheckState = null; 245 } 246 else 247 { 248 nonLocalServersHealthCheckState = 249 HealthCheckState.forName(nonLocalHCStateStr); 250 } 251 252 final List<String> externalServerStrings = 253 getStrings(ATTR_LDAP_EXTERNAL_SERVER); 254 final ArrayList<LoadBalancingAlgorithmServerAvailabilityData> serverData = 255 new ArrayList<>(externalServerStrings.size()); 256 for (final String s : externalServerStrings) 257 { 258 try 259 { 260 serverData.add(new LoadBalancingAlgorithmServerAvailabilityData(s)); 261 } 262 catch (final Exception e) 263 { 264 Debug.debugException(e); 265 } 266 } 267 serverAvailabilityData = Collections.unmodifiableList(serverData); 268 } 269 270 271 272 /** 273 * Retrieves the name of the load-balancing algorithm. 274 * 275 * @return The name of the load-balancing algorithm, or {@code null} if it 276 * was not included in the monitor entry. 277 */ 278 public String getAlgorithmName() 279 { 280 return algorithmName; 281 } 282 283 284 285 /** 286 * Retrieves the DN of the configuration entry for the load-balancing 287 * algorithm. 288 * 289 * @return The DN of the configuration entry for the load-balancing 290 * algorithm, or {@code null} if it was not included in the monitor 291 * entry. 292 */ 293 public String getConfigEntryDN() 294 { 295 return configEntryDN; 296 } 297 298 299 300 /** 301 * Retrieves the aggregate health check state for the load-balancing 302 * algorithm. 303 * 304 * @return The aggregate health check state for the load-balancing algorithm, 305 * or {@code null} if it was not included in the monitor 306 * entry. 307 */ 308 public HealthCheckState getHealthCheckState() 309 { 310 return healthCheckState; 311 } 312 313 314 315 /** 316 * Retrieves the aggregate health check state for local servers for the 317 * load-balancing algorithm. 318 * 319 * @return The aggregate health check state for local servers for the 320 * load-balancing algorithm, or {@code null} if it was not included 321 * in the monitor entry. 322 */ 323 public HealthCheckState getLocalServersHealthCheckState() 324 { 325 return localServersHealthCheckState; 326 } 327 328 329 330 /** 331 * Retrieves the aggregate health check state for non-local servers for the 332 * load-balancing algorithm. 333 * 334 * @return The aggregate health check state for non-local servers for the 335 * load-balancing algorithm, or {@code null} if it was not included 336 * in the monitor entry. 337 */ 338 public HealthCheckState getNonLocalServersHealthCheckState() 339 { 340 return nonLocalServersHealthCheckState; 341 } 342 343 344 345 /** 346 * Retrieves a list with information about the healths of the individual LDAP 347 * external servers associated with the load-balancing algorithm. 348 * 349 * @return A list with information about the healths of the individual LDAP 350 * external servers associated with the load-balancing algorithm, or 351 * an empty list if it was not included in the monitor entry. 352 */ 353 public List<LoadBalancingAlgorithmServerAvailabilityData> 354 getServerAvailabilityData() 355 { 356 return serverAvailabilityData; 357 } 358 359 360 361 /** 362 * Retrieves the number of servers associated with the load-balancing 363 * algorithm that have a health check state of AVAILABLE. 364 * 365 * @return The number of servers associated with the load-balancing algorithm 366 * that have a health check state of AVAILABLE, or {@code null} if it 367 * was not included in the monitor entry. 368 */ 369 public Long getNumAvailableServers() 370 { 371 return numAvailableServers; 372 } 373 374 375 376 /** 377 * Retrieves the number of servers associated with the load-balancing 378 * algorithm that have a health check state of DEGRADED. 379 * 380 * @return The number of servers associated with the load-balancing algorithm 381 * that have a health check state of DEGRADED, or {@code null} if it 382 * was not included in the monitor entry. 383 */ 384 public Long getNumDegradedServers() 385 { 386 return numDegradedServers; 387 } 388 389 390 391 /** 392 * Retrieves the number of servers associated with the load-balancing 393 * algorithm that have a health check state of UNAVAILABLE. 394 * 395 * @return The number of servers associated with the load-balancing algorithm 396 * that have a health check state of UNAVAILABLE, or {@code null} if 397 * it was not included in the monitor entry. 398 */ 399 public Long getNumUnavailableServers() 400 { 401 return numUnavailableServers; 402 } 403 404 405 406 /** 407 * {@inheritDoc} 408 */ 409 @Override() 410 public String getMonitorDisplayName() 411 { 412 return INFO_LOAD_BALANCING_ALGORITHM_MONITOR_DISPNAME.get(); 413 } 414 415 416 417 /** 418 * {@inheritDoc} 419 */ 420 @Override() 421 public String getMonitorDescription() 422 { 423 return INFO_LOAD_BALANCING_ALGORITHM_MONITOR_DESC.get(); 424 } 425 426 427 428 /** 429 * {@inheritDoc} 430 */ 431 @Override() 432 public Map<String,MonitorAttribute> getMonitorAttributes() 433 { 434 final LinkedHashMap<String,MonitorAttribute> attrs = new LinkedHashMap<>(9); 435 436 if (algorithmName != null) 437 { 438 addMonitorAttribute(attrs, 439 ATTR_ALGORITHM_NAME, 440 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_ALGORITHM_NAME.get(), 441 INFO_LOAD_BALANCING_ALGORITHM_DESC_ALGORITHM_NAME.get(), 442 algorithmName); 443 } 444 445 if (configEntryDN != null) 446 { 447 addMonitorAttribute(attrs, 448 ATTR_CONFIG_ENTRY_DN, 449 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_CONFIG_ENTRY_DN.get(), 450 INFO_LOAD_BALANCING_ALGORITHM_DESC_CONFIG_ENTRY_DN.get(), 451 configEntryDN); 452 } 453 454 if (healthCheckState != null) 455 { 456 addMonitorAttribute(attrs, 457 ATTR_HEALTH_CHECK_STATE, 458 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_HEALTH_CHECK_STATE.get(), 459 INFO_LOAD_BALANCING_ALGORITHM_DESC_HEALTH_CHECK_STATE.get(), 460 healthCheckState.name()); 461 } 462 463 if (localServersHealthCheckState != null) 464 { 465 addMonitorAttribute(attrs, 466 ATTR_LOCAL_SERVERS_HEALTH_CHECK_STATE, 467 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_L_HEALTH_CHECK_STATE.get(), 468 INFO_LOAD_BALANCING_ALGORITHM_DESC_L_HEALTH_CHECK_STATE.get(), 469 localServersHealthCheckState.name()); 470 } 471 472 if (nonLocalServersHealthCheckState != null) 473 { 474 addMonitorAttribute(attrs, 475 ATTR_NON_LOCAL_SERVERS_HEALTH_CHECK_STATE, 476 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_NL_HEALTH_CHECK_STATE.get(), 477 INFO_LOAD_BALANCING_ALGORITHM_DESC_NL_HEALTH_CHECK_STATE.get(), 478 nonLocalServersHealthCheckState.name()); 479 } 480 481 if ((serverAvailabilityData != null) && 482 (! serverAvailabilityData.isEmpty())) 483 { 484 final ArrayList<String> availabilityStrings = 485 new ArrayList<>(serverAvailabilityData.size()); 486 for (final LoadBalancingAlgorithmServerAvailabilityData d : 487 serverAvailabilityData) 488 { 489 availabilityStrings.add(d.toCompactString()); 490 } 491 addMonitorAttribute(attrs, 492 ATTR_LDAP_EXTERNAL_SERVER, 493 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_SERVER_DATA.get(), 494 INFO_LOAD_BALANCING_ALGORITHM_DESC_SERVER_DATA.get(), 495 availabilityStrings); 496 } 497 498 if (numAvailableServers != null) 499 { 500 addMonitorAttribute(attrs, 501 ATTR_NUM_AVAILABLE, 502 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_NUM_AVAILABLE.get(), 503 INFO_LOAD_BALANCING_ALGORITHM_DESC_NUM_AVAILABLE.get(), 504 numAvailableServers); 505 } 506 507 if (numDegradedServers != null) 508 { 509 addMonitorAttribute(attrs, 510 ATTR_NUM_DEGRADED, 511 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_NUM_DEGRADED.get(), 512 INFO_LOAD_BALANCING_ALGORITHM_DESC_NUM_DEGRADED.get(), 513 numDegradedServers); 514 } 515 516 if (numUnavailableServers != null) 517 { 518 addMonitorAttribute(attrs, 519 ATTR_NUM_UNAVAILABLE, 520 INFO_LOAD_BALANCING_ALGORITHM_DISPNAME_NUM_UNAVAILABLE.get(), 521 INFO_LOAD_BALANCING_ALGORITHM_DESC_NUM_UNAVAILABLE.get(), 522 numUnavailableServers); 523 } 524 525 return Collections.unmodifiableMap(attrs); 526 } 527}