001/* 002 * Copyright 2014-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2014-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.Collections; 041import java.util.LinkedHashMap; 042import java.util.Map; 043 044import com.unboundid.ldap.sdk.Entry; 045import com.unboundid.ldap.sdk.OperationType; 046import com.unboundid.util.NotMutable; 047import com.unboundid.util.StaticUtils; 048import com.unboundid.util.ThreadSafety; 049import com.unboundid.util.ThreadSafetyLevel; 050 051import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 052 053 054 055/** 056 * This class defines a monitor entry that provides information about the result 057 * codes returned from various types of operations. 058 * <BR> 059 * <BLOCKQUOTE> 060 * <B>NOTE:</B> This class, and other classes within the 061 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 062 * supported for use against Ping Identity, UnboundID, and 063 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 064 * for proprietary functionality or for external specifications that are not 065 * considered stable or mature enough to be guaranteed to work in an 066 * interoperable way with other types of LDAP servers. 067 * </BLOCKQUOTE> 068 */ 069@NotMutable() 070@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 071public final class ResultCodeMonitorEntry 072 extends MonitorEntry 073{ 074 /** 075 * The structural object class used in group cache monitor entries. 076 */ 077 static final String RESULT_CODE_MONITOR_OC = 078 "ds-ldap-result-codes-monitor-entry"; 079 080 081 082 /** 083 * The serial version UID for this serializable class. 084 */ 085 private static final long serialVersionUID = -963682306039266913L; 086 087 088 089 // The result code information for extended operations. 090 private final ExtendedOperationResultCodeInfo extendedOperationResultCodeInfo; 091 092 // The result code information for add operations. 093 private final OperationResultCodeInfo addOperationResultCodeInfo; 094 095 // The result code information for all types of operations. 096 private final OperationResultCodeInfo allOperationsResultCodeInfo; 097 098 // The result code information for bind operations. 099 private final OperationResultCodeInfo bindOperationResultCodeInfo; 100 101 // The result code information for compare operations. 102 private final OperationResultCodeInfo compareOperationResultCodeInfo; 103 104 // The result code information for delete operations. 105 private final OperationResultCodeInfo deleteOperationResultCodeInfo; 106 107 // The result code information for modify operations. 108 private final OperationResultCodeInfo modifyOperationResultCodeInfo; 109 110 // The result code information for modify DN operations. 111 private final OperationResultCodeInfo modifyDNOperationResultCodeInfo; 112 113 // The result code information for search operations. 114 private final OperationResultCodeInfo searchOperationResultCodeInfo; 115 116 117 118 /** 119 * Creates a new result code monitor entry from the provided entry. 120 * 121 * @param entry The entry to be parsed as a result code monitor entry. It 122 * must not be {@code null}. 123 */ 124 public ResultCodeMonitorEntry(final Entry entry) 125 { 126 super(entry); 127 128 allOperationsResultCodeInfo = 129 new OperationResultCodeInfo(this, null, "all-ops-"); 130 addOperationResultCodeInfo = 131 new OperationResultCodeInfo(this, OperationType.ADD, "add-op-"); 132 bindOperationResultCodeInfo = 133 new OperationResultCodeInfo(this, OperationType.BIND, "bind-op-"); 134 compareOperationResultCodeInfo = 135 new OperationResultCodeInfo(this, OperationType.COMPARE, 136 "compare-op-"); 137 deleteOperationResultCodeInfo = 138 new OperationResultCodeInfo(this, OperationType.DELETE, "delete-op-"); 139 extendedOperationResultCodeInfo = new ExtendedOperationResultCodeInfo(this); 140 modifyOperationResultCodeInfo = 141 new OperationResultCodeInfo(this, OperationType.MODIFY, "modify-op-"); 142 modifyDNOperationResultCodeInfo = 143 new OperationResultCodeInfo(this, OperationType.MODIFY_DN, 144 "modifydn-op-"); 145 searchOperationResultCodeInfo = 146 new OperationResultCodeInfo(this, OperationType.SEARCH, "search-op-"); 147 } 148 149 150 151 /** 152 * Retrieves result code information that encompasses all types of operations. 153 * 154 * @return Result code information that encompasses all types of operations. 155 */ 156 public OperationResultCodeInfo getAllOperationsResultCodeInfo() 157 { 158 return allOperationsResultCodeInfo; 159 } 160 161 162 163 /** 164 * Retrieves result code information for add operations. 165 * 166 * @return Result code information for add operations. 167 */ 168 public OperationResultCodeInfo getAddOperationResultCodeInfo() 169 { 170 return addOperationResultCodeInfo; 171 } 172 173 174 175 /** 176 * Retrieves result code information for bind operations. 177 * 178 * @return Result code information for bind operations. 179 */ 180 public OperationResultCodeInfo getBindOperationResultCodeInfo() 181 { 182 return bindOperationResultCodeInfo; 183 } 184 185 186 187 /** 188 * Retrieves result code information for compare operations. 189 * 190 * @return Result code information for compare operations. 191 */ 192 public OperationResultCodeInfo getCompareOperationResultCodeInfo() 193 { 194 return compareOperationResultCodeInfo; 195 } 196 197 198 199 /** 200 * Retrieves result code information for delete operations. 201 * 202 * @return Result code information for delete operations. 203 */ 204 public OperationResultCodeInfo getDeleteOperationResultCodeInfo() 205 { 206 return deleteOperationResultCodeInfo; 207 } 208 209 210 211 /** 212 * Retrieves result code information for extended operations. 213 * 214 * @return Result code information for extended operations. 215 */ 216 public ExtendedOperationResultCodeInfo getExtendedOperationResultCodeInfo() 217 { 218 return extendedOperationResultCodeInfo; 219 } 220 221 222 223 /** 224 * Retrieves result code information for modify operations. 225 * 226 * @return Result code information for modify operations. 227 */ 228 public OperationResultCodeInfo getModifyOperationResultCodeInfo() 229 { 230 return modifyOperationResultCodeInfo; 231 } 232 233 234 235 /** 236 * Retrieves result code information for modify DN operations. 237 * 238 * @return Result code information for modify DN operations. 239 */ 240 public OperationResultCodeInfo getModifyDNOperationResultCodeInfo() 241 { 242 return modifyDNOperationResultCodeInfo; 243 } 244 245 246 247 /** 248 * Retrieves result code information for search operations. 249 * 250 * @return Result code information for search operations. 251 */ 252 public OperationResultCodeInfo getSearchOperationResultCodeInfo() 253 { 254 return searchOperationResultCodeInfo; 255 } 256 257 258 259 /** 260 * {@inheritDoc} 261 */ 262 @Override() 263 public String getMonitorDisplayName() 264 { 265 return INFO_RESULT_CODE_MONITOR_DISPNAME.get(); 266 } 267 268 269 270 /** 271 * {@inheritDoc} 272 */ 273 @Override() 274 public String getMonitorDescription() 275 { 276 return INFO_RESULT_CODE_MONITOR_DESC.get(); 277 } 278 279 280 281 /** 282 * {@inheritDoc} 283 */ 284 @Override() 285 public Map<String,MonitorAttribute> getMonitorAttributes() 286 { 287 final LinkedHashMap<String,MonitorAttribute> attrs = 288 new LinkedHashMap<>(StaticUtils.computeMapCapacity(100)); 289 290 addAttrs(attrs, allOperationsResultCodeInfo, "all-ops-"); 291 addAttrs(attrs, addOperationResultCodeInfo, "add-op-"); 292 addAttrs(attrs, bindOperationResultCodeInfo, "bind-op-"); 293 addAttrs(attrs, compareOperationResultCodeInfo, "compare-op-"); 294 addAttrs(attrs, deleteOperationResultCodeInfo, "delete-op-"); 295 addAttrs(attrs, extendedOperationResultCodeInfo); 296 addAttrs(attrs, modifyOperationResultCodeInfo, "modify-op-"); 297 addAttrs(attrs, modifyDNOperationResultCodeInfo, "modifydn-op-"); 298 addAttrs(attrs, searchOperationResultCodeInfo, "search-op-"); 299 300 return Collections.unmodifiableMap(attrs); 301 } 302 303 304 305 /** 306 * Updates the provided map with information about an appropriate set of 307 * monitor attributes. 308 * 309 * @param attrs The set of monitor attributes to be updated. 310 * @param resultCodeInfo The result code information to use. 311 * @param attrPrefix The attribute prefix 312 */ 313 private static void addAttrs( 314 final LinkedHashMap<String,MonitorAttribute> attrs, 315 final OperationResultCodeInfo resultCodeInfo, final String attrPrefix) 316 { 317 final String opName; 318 if (resultCodeInfo.getOperationType() == null) 319 { 320 opName = INFO_RESULT_CODE_OP_NAME_ALL.get(); 321 } 322 else 323 { 324 switch (resultCodeInfo.getOperationType()) 325 { 326 case ADD: 327 opName = INFO_RESULT_CODE_OP_NAME_ADD.get(); 328 break; 329 case BIND: 330 opName = INFO_RESULT_CODE_OP_NAME_BIND.get(); 331 break; 332 case COMPARE: 333 opName = INFO_RESULT_CODE_OP_NAME_COMPARE.get(); 334 break; 335 case DELETE: 336 opName = INFO_RESULT_CODE_OP_NAME_DELETE.get(); 337 break; 338 case MODIFY: 339 opName = INFO_RESULT_CODE_OP_NAME_MODIFY.get(); 340 break; 341 case MODIFY_DN: 342 opName = INFO_RESULT_CODE_OP_NAME_MODIFY_DN.get(); 343 break; 344 case SEARCH: 345 opName = INFO_RESULT_CODE_OP_NAME_SEARCH.get(); 346 break; 347 default: 348 opName = "Unknown"; 349 break; 350 } 351 } 352 353 final String lowerOpName = StaticUtils.toLowerCase(opName); 354 355 final Long totalCount = resultCodeInfo.getTotalCount(); 356 if (totalCount != null) 357 { 358 addMonitorAttribute(attrs, 359 attrPrefix + "total-count", 360 INFO_RESULT_CODE_DISPNAME_TOTAL_COUNT.get(opName), 361 INFO_RESULT_CODE_DESC_TOTAL_COUNT.get(lowerOpName), 362 totalCount); 363 } 364 365 final Long failedCount = resultCodeInfo.getFailedCount(); 366 if (failedCount != null) 367 { 368 addMonitorAttribute(attrs, 369 attrPrefix + "failed-count", 370 INFO_RESULT_CODE_DISPNAME_FAILED_COUNT.get(opName), 371 INFO_RESULT_CODE_DESC_FAILED_COUNT.get(lowerOpName), 372 failedCount); 373 } 374 375 final Double failedPercent = resultCodeInfo.getFailedPercent(); 376 if (failedPercent != null) 377 { 378 addMonitorAttribute(attrs, 379 attrPrefix + "failed-percent", 380 INFO_RESULT_CODE_DISPNAME_FAILED_PERCENT.get(opName), 381 INFO_RESULT_CODE_DESC_FAILED_PERCENT.get(lowerOpName), 382 failedPercent); 383 } 384 385 for (final ResultCodeInfo i : 386 resultCodeInfo.getResultCodeInfoMap().values()) 387 { 388 addMonitorAttribute(attrs, 389 attrPrefix + i.intValue() + "-name", 390 INFO_RESULT_CODE_DISPNAME_RC_NAME.get(opName, i.intValue()), 391 INFO_RESULT_CODE_DESC_RC_NAME.get(lowerOpName, i.intValue()), 392 i.getName()); 393 394 addMonitorAttribute(attrs, 395 attrPrefix + i.intValue() + "-count", 396 INFO_RESULT_CODE_DISPNAME_RC_COUNT.get(opName, i.intValue()), 397 INFO_RESULT_CODE_DESC_RC_COUNT.get(lowerOpName, i.intValue()), 398 i.getCount()); 399 400 addMonitorAttribute(attrs, 401 attrPrefix + i.intValue() + "-percent", 402 INFO_RESULT_CODE_DISPNAME_RC_PERCENT.get(opName, i.intValue()), 403 INFO_RESULT_CODE_DESC_RC_PERCENT.get(lowerOpName, i.intValue()), 404 i.getPercent()); 405 406 addMonitorAttribute(attrs, 407 attrPrefix + i.intValue() + "-average-response-time-millis", 408 INFO_RESULT_CODE_DISPNAME_RC_AVG_RT.get(opName, i.intValue()), 409 INFO_RESULT_CODE_DESC_RC_AVG_RT.get(lowerOpName, i.intValue()), 410 i.getAverageResponseTimeMillis()); 411 412 addMonitorAttribute(attrs, 413 attrPrefix + i.intValue() + "-total-response-time-millis", 414 INFO_RESULT_CODE_DISPNAME_RC_TOTAL_RT.get(opName, i.intValue()), 415 INFO_RESULT_CODE_DESC_RC_TOTAL_RT.get(lowerOpName, i.intValue()), 416 i.getTotalResponseTimeMillis()); 417 } 418 } 419 420 421 422 /** 423 * Updates the provided map with information about an appropriate set of 424 * monitor attributes. 425 * 426 * @param attrs The set of monitor attributes to be updated. 427 * @param resultCodeInfo The result code information to use. 428 */ 429 private static void addAttrs( 430 final LinkedHashMap<String,MonitorAttribute> attrs, 431 final ExtendedOperationResultCodeInfo resultCodeInfo) 432 { 433 final String opName = INFO_RESULT_CODE_OP_NAME_EXTENDED.get(); 434 final String lowerOpName = StaticUtils.toLowerCase(opName); 435 436 final Long totalCount = resultCodeInfo.getTotalCount(); 437 if (totalCount != null) 438 { 439 addMonitorAttribute(attrs, 440 "extended-op-total-count", 441 INFO_RESULT_CODE_DISPNAME_TOTAL_COUNT.get(opName), 442 INFO_RESULT_CODE_DESC_TOTAL_COUNT.get(lowerOpName), 443 totalCount); 444 } 445 446 final Long failedCount = resultCodeInfo.getFailedCount(); 447 if (failedCount != null) 448 { 449 addMonitorAttribute(attrs, 450 "extended-op-failed-count", 451 INFO_RESULT_CODE_DISPNAME_FAILED_COUNT.get(opName), 452 INFO_RESULT_CODE_DESC_FAILED_COUNT.get(lowerOpName), 453 failedCount); 454 } 455 456 final Double failedPercent = resultCodeInfo.getFailedPercent(); 457 if (failedPercent != null) 458 { 459 addMonitorAttribute(attrs, 460 "extended-op-failed-percent", 461 INFO_RESULT_CODE_DISPNAME_FAILED_PERCENT.get(opName), 462 INFO_RESULT_CODE_DESC_FAILED_PERCENT.get(lowerOpName), 463 failedPercent); 464 } 465 466 for (final String oid : 467 resultCodeInfo.getExtendedRequestNamesByOID().keySet()) 468 { 469 final String prefix = "extended-op-" + oid.replace('.', '-') + '-'; 470 471 final String name = 472 resultCodeInfo.getExtendedRequestNamesByOID().get(oid); 473 if (name != null) 474 { 475 addMonitorAttribute(attrs, 476 prefix + "name", 477 INFO_RESULT_CODE_DISPNAME_EXTOP_NAME.get(oid), 478 INFO_RESULT_CODE_DESC_EXTOP_NAME.get(oid), 479 name); 480 } 481 482 final Long total = resultCodeInfo.getTotalCountsByOID().get(oid); 483 if (total != null) 484 { 485 addMonitorAttribute(attrs, 486 prefix + "total-count", 487 INFO_RESULT_CODE_DISPNAME_EXTOP_TOTAL_COUNT.get(oid), 488 INFO_RESULT_CODE_DESC_EXTOP_TOTAL_COUNT.get(oid), 489 total); 490 } 491 492 final Long failed = resultCodeInfo.getFailedCountsByOID().get(oid); 493 if (failed != null) 494 { 495 addMonitorAttribute(attrs, 496 prefix + "failed-count", 497 INFO_RESULT_CODE_DISPNAME_EXTOP_FAILED_COUNT.get(oid), 498 INFO_RESULT_CODE_DESC_EXTOP_FAILED_COUNT.get(oid), 499 failed); 500 } 501 502 final Double percent = resultCodeInfo.getFailedPercentsByOID().get(oid); 503 if (percent != null) 504 { 505 addMonitorAttribute(attrs, 506 prefix+ "failed-percent", 507 INFO_RESULT_CODE_DISPNAME_EXTOP_FAILED_PERCENT.get(oid), 508 INFO_RESULT_CODE_DESC_EXTOP_FAILED_PERCENT.get(oid), 509 percent); 510 } 511 512 final Map<Integer,ResultCodeInfo> rcInfoMap = 513 resultCodeInfo.getResultCodeInfoMap().get(oid); 514 if (rcInfoMap != null) 515 { 516 for (final ResultCodeInfo rcInfo : rcInfoMap.values()) 517 { 518 final int intValue = rcInfo.intValue(); 519 final String rcPrefix = prefix + intValue + '-'; 520 521 addMonitorAttribute(attrs, 522 rcPrefix + "name", 523 INFO_RESULT_CODE_DISPNAME_EXTOP_RC_NAME.get(oid, intValue), 524 INFO_RESULT_CODE_DESC_EXTOP_RC_NAME.get(oid, intValue), 525 rcInfo.getName()); 526 addMonitorAttribute(attrs, 527 rcPrefix + "count", 528 INFO_RESULT_CODE_DISPNAME_EXTOP_RC_COUNT.get(oid, intValue), 529 INFO_RESULT_CODE_DESC_EXTOP_RC_COUNT.get(oid, intValue), 530 rcInfo.getCount()); 531 addMonitorAttribute(attrs, 532 rcPrefix + "percent", 533 INFO_RESULT_CODE_DISPNAME_EXTOP_RC_PERCENT.get(oid, intValue), 534 INFO_RESULT_CODE_DESC_EXTOP_RC_PERCENT.get(oid, intValue), 535 rcInfo.getPercent()); 536 addMonitorAttribute(attrs, 537 rcPrefix + "average-response-time-millis", 538 INFO_RESULT_CODE_DISPNAME_EXTOP_RC_AVG_RT.get(oid, intValue), 539 INFO_RESULT_CODE_DESC_EXTOP_RC_AVG_RT.get(oid, intValue), 540 rcInfo.getAverageResponseTimeMillis()); 541 addMonitorAttribute(attrs, 542 rcPrefix + "total-response-time-millis", 543 INFO_RESULT_CODE_DISPNAME_EXTOP_RC_TOTAL_RT.get(oid, intValue), 544 INFO_RESULT_CODE_DESC_EXTOP_RC_TOTAL_RT.get(oid, intValue), 545 rcInfo.getTotalResponseTimeMillis()); 546 } 547 } 548 } 549 } 550}