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