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.io.Serializable; 041import java.util.Collections; 042import java.util.Map; 043import java.util.TreeMap; 044 045import com.unboundid.ldap.sdk.Attribute; 046import com.unboundid.ldap.sdk.Entry; 047import com.unboundid.ldap.sdk.OperationType; 048import com.unboundid.util.Debug; 049import com.unboundid.util.NotMutable; 050import com.unboundid.util.StaticUtils; 051import com.unboundid.util.ThreadSafety; 052import com.unboundid.util.ThreadSafetyLevel; 053 054 055 056/** 057 * This class provides a data structure that provides information about the 058 * result codes associated with various types of extended operations. 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 */ 070@NotMutable() 071@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 072public final class ExtendedOperationResultCodeInfo 073 implements Serializable 074{ 075 /** 076 * The serial version UID for this serializable class. 077 */ 078 private static final long serialVersionUID = 2412562905271298484L; 079 080 081 082 // The percentage of all extended operations that failed. 083 private final Double failedPercent; 084 085 // The total number of operations of the associated type that failed. 086 private final Long failedCount; 087 088 // The total number of operations of the associated type. 089 private final Long totalCount; 090 091 // The percentage of extended operations that failed, indexed by OID. 092 private final Map<String,Double> failedPercentsByOID; 093 094 // The number of extended operations that failed, indexed by OID. 095 private final Map<String,Long> failedCountsByOID; 096 097 // The number of extended operations processed, indexed by OID. 098 private final Map<String,Long> totalCountsByOID; 099 100 // Information about each result code returned for each type of extended 101 // operation, indexed first by extended request OID, then by the result code's 102 // integer value. 103 private final Map<String,Map<Integer,ResultCodeInfo>> resultCodeInfoMap; 104 105 // The names of the types of extended operations processed, indexed by OID. 106 private final Map<String,String> requestNamesByOID; 107 108 109 110 /** 111 * Creates a new extended operation result code information object from the 112 * provided information. 113 * 114 * @param entry The monitor entry to use to obtain the result code 115 * information. 116 */ 117 ExtendedOperationResultCodeInfo(final MonitorEntry entry) 118 { 119 totalCount = entry.getLong("extended-op-total-count"); 120 failedCount = entry.getLong("extended-op-failed-count"); 121 failedPercent = entry.getDouble("extended-op-failed-percent"); 122 123 final TreeMap<String,String> names = new TreeMap<>(); 124 final TreeMap<String,Long> totalCounts = new TreeMap<>(); 125 final TreeMap<String,Long> failedCounts = new TreeMap<>(); 126 final TreeMap<String,Double> failedPercents = new TreeMap<>(); 127 final TreeMap<String,Map<Integer,ResultCodeInfo>> rcMaps = new TreeMap<>(); 128 final Entry e = entry.getEntry(); 129 for (final Attribute a : e.getAttributes()) 130 { 131 try 132 { 133 final String lowerName = StaticUtils.toLowerCase(a.getName()); 134 if (lowerName.startsWith("extended-op-") && 135 lowerName.endsWith("-total-count")) 136 { 137 final String dashedOID = 138 lowerName.substring(12, (lowerName.length() - 12)); 139 final String dottedOID = dashedOID.replace('-', '.'); 140 141 final String name = entry.getString( 142 "extended-op-" + dashedOID + "-name"); 143 final long total = a.getValueAsLong(); 144 final long failed = entry.getLong( 145 "extended-op-" + dashedOID + "-failed-count"); 146 final double failedPct = entry.getDouble( 147 "extended-op-" + dashedOID + "-failed-percent"); 148 149 names.put(dottedOID, name); 150 totalCounts.put(dottedOID, total); 151 failedCounts.put(dottedOID, failed); 152 failedPercents.put(dottedOID, failedPct); 153 rcMaps.put(dottedOID, 154 getRCMap(e, "extended-op-" + dashedOID + "-result-")); 155 } 156 } 157 catch (final Exception ex) 158 { 159 Debug.debugException(ex); 160 } 161 } 162 163 requestNamesByOID = Collections.unmodifiableMap(names); 164 totalCountsByOID = Collections.unmodifiableMap(totalCounts); 165 failedCountsByOID = Collections.unmodifiableMap(failedCounts); 166 failedPercentsByOID = Collections.unmodifiableMap(failedPercents); 167 resultCodeInfoMap = Collections.unmodifiableMap(rcMaps); 168 } 169 170 171 172 /** 173 * Retrieves a map with result code information for a particular type of 174 * extended operation. 175 * 176 * @param entry The entry to be examined. 177 * @param prefix The prefix that will be used for all attributes of 178 * interest. 179 * 180 * @return A map with result code information for a particular type of 181 * extended operation. 182 */ 183 private static Map<Integer,ResultCodeInfo> getRCMap(final Entry entry, 184 final String prefix) 185 { 186 final TreeMap<Integer,ResultCodeInfo> m = new TreeMap<>(); 187 188 for (final Attribute a : entry.getAttributes()) 189 { 190 try 191 { 192 final String lowerName = StaticUtils.toLowerCase(a.getName()); 193 if (lowerName.startsWith(prefix) && lowerName.endsWith("-name")) 194 { 195 final int intValue = Integer.parseInt(lowerName.substring( 196 prefix.length(), (lowerName.length() - 5))); 197 final String name = a.getValue(); 198 final long count = entry.getAttributeValueAsLong( 199 prefix + intValue + "-count"); 200 final double percent = Double.parseDouble( 201 entry.getAttributeValue(prefix + intValue + "-percent")); 202 final double totalResponseTimeMillis = Double.parseDouble( 203 entry.getAttributeValue(prefix + intValue + 204 "-total-response-time-millis")); 205 final double averageResponseTimeMillis = Double.parseDouble( 206 entry.getAttributeValue(prefix + intValue + 207 "-average-response-time-millis")); 208 m.put(intValue, new ResultCodeInfo(intValue, name, 209 OperationType.EXTENDED, count, percent, totalResponseTimeMillis, 210 averageResponseTimeMillis)); 211 } 212 } 213 catch (final Exception ex) 214 { 215 Debug.debugException(ex); 216 } 217 } 218 219 return Collections.unmodifiableMap(m); 220 } 221 222 223 224 /** 225 * Retrieves the total number of extended operations of all types that have 226 * been processed, if available. 227 * 228 * @return The total number of extended operations of all types that have 229 * been processed, or {@code null} if this information was not in the 230 * monitor entry. 231 */ 232 public Long getTotalCount() 233 { 234 return totalCount; 235 } 236 237 238 239 /** 240 * Retrieves the number of extended operations of each type that have been 241 * processed, indexed by extended request OID, if available. 242 * 243 * @return The number of extended operations of each type that have been 244 * processed, or an empty map if this information was not in the 245 * monitor entry. 246 */ 247 public Map<String,Long> getTotalCountsByOID() 248 { 249 return totalCountsByOID; 250 } 251 252 253 254 /** 255 * Retrieves the number of extended operations of all types that resulted in 256 * failure, if available. 257 * 258 * @return The number of extended operations of all types that resulted in 259 * failure, or {@code null} if this information was not in the 260 * monitor entry. 261 */ 262 public Long getFailedCount() 263 { 264 return failedCount; 265 } 266 267 268 269 /** 270 * Retrieves the number of extended operations of each type that resulted in 271 * failure, indexed by extended request OID, if available. 272 * 273 * @return The number of extended operations of each type that resulted in 274 * failure, or an empty map if this information was not in the 275 * monitor entry. 276 */ 277 public Map<String,Long> getFailedCountsByOID() 278 { 279 return failedCountsByOID; 280 } 281 282 283 284 /** 285 * Retrieves the percent of extended operations of all types that resulted in 286 * failure, if available. 287 * 288 * @return The percent of extended operations of all types that resulted in 289 * failure, or {@code null} if this information was not in the 290 * monitor entry. 291 */ 292 public Double getFailedPercent() 293 { 294 return failedPercent; 295 } 296 297 298 299 /** 300 * Retrieves the percent of extended operations of each type that resulted in 301 * failure, indexed by extended request OID, if available. 302 * 303 * @return The percent of extended operations of each type that resulted in 304 * failure, or an empty map if this information was not in the 305 * monitor entry. 306 */ 307 public Map<String,Double> getFailedPercentsByOID() 308 { 309 return failedPercentsByOID; 310 } 311 312 313 314 /** 315 * Retrieves a map with information about the result codes that have been 316 * returned for extended operations of each type, indexed first by extended 317 * request OID, and then by the result code's integer value. 318 * 319 * @return A map with information about the result codes that have been 320 * returned for extended operations of each type, or an empty map if 321 * this information was not in the monitor entry. 322 */ 323 public Map<String,Map<Integer,ResultCodeInfo>> getResultCodeInfoMap() 324 { 325 return resultCodeInfoMap; 326 } 327 328 329 330 /** 331 * Retrieves a map with the human-readable names for each type of extended 332 * request, indexed by request OID, if available. 333 * 334 * @return A map with the human-readable names for each type of extended 335 * request, or an empty map if this information was not in the 336 * monitor entry. 337 */ 338 public Map<String,String> getExtendedRequestNamesByOID() 339 { 340 return requestNamesByOID; 341 } 342}