1 16 package com.sun.slamd.example; 17 18 19 20 import java.util.*; 21 import netscape.ldap.*; 22 import com.sun.slamd.job.*; 23 import com.sun.slamd.parameter.*; 24 import com.sun.slamd.stat.*; 25 26 27 28 59 public class SiteMinderWithReplicaLatencyJobClass 60 extends ReplicaLatencyCheckJobClass 61 { 62 66 public static final char[] ALPHABET = 67 "abcdefghijklmnopqrstuvwxyz".toCharArray(); 68 69 70 71 75 public static final String DEFAULT_ATTR1 = "givenName"; 76 77 78 79 83 public static final String DEFAULT_ATTR2 = "sn"; 84 85 86 87 91 public static final String DEFAULT_ATTR3= "cn"; 92 93 94 95 98 public static final String DEFAULT_LOG_ID_ATTR = "uid"; 99 100 101 102 106 public static final String STAT_TRACKER_AUTHENTICATION_ATTEMPTS = 107 "Authentication Attempts"; 108 109 110 111 112 116 public static final String STAT_TRACKER_AUTHENTICATION_TIME = 117 "Authentication Time (ms)"; 118 119 120 121 125 public static final String STAT_TRACKER_BIND_TIME = "Bind Time (ms)"; 126 127 128 129 130 134 public static final String STAT_TRACKER_FAILED_AUTHENTICATIONS = 135 "Failed Authentications"; 136 137 138 139 143 public static final String STAT_TRACKER_FAIL_REASON = "Failure Reason"; 144 145 146 147 151 public static final String STAT_TRACKER_INITIAL_SEARCH_TIME = 152 "Initial Search Time (ms)"; 153 154 155 156 160 public static final String STAT_TRACKER_MOD_TIME = "Modify Time (ms)"; 161 162 163 164 168 public static final String STAT_TRACKER_NUM_BINDS = 169 "Bind Operations Performed"; 170 171 172 173 177 public static final String STAT_TRACKER_NUM_MODS = 178 "Modify Operations Performed"; 179 180 181 182 186 public static final String STAT_TRACKER_NUM_SEARCH = 187 "Search Operations Performed"; 188 189 190 191 196 public static final String STAT_TRACKER_SUBSEQUENT_SEARCH_TIME = 197 "Subsequent Search Time (ms)"; 198 199 200 201 205 public static final String STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS = 206 "Successful Authentications"; 207 208 209 210 214 public static final String STAT_TRACKER_REPLICATION_LATENCY = 215 "Replication Latency (ms)"; 216 217 218 219 222 public static final String STAT_TRACKER_CATEGORIZED_LATENCY = 223 "Categorized Latency"; 224 225 226 227 230 public static final String [] DEFAULT_ATTRS_TO_MODIFY = new String [] 231 { 232 "description" 233 }; 234 235 236 237 static boolean ignoreInvalidCredentials; 240 241 static boolean latencyTrackerChosen; 243 244 static boolean skipBind; 246 247 static boolean useDataFile; 250 251 static boolean useLoginIDRange; 253 254 static boolean useSequential; 256 257 static boolean useSharedConnections; 260 261 static int coolDownTime; 263 264 static int latencyDelay; 266 267 static int loginIDMax; 269 270 static int loginIDMin; 272 273 static int loginIDSpan; 275 276 static int masterPort; 278 279 static int replicaPort; 281 282 static int sequentialCounter; 284 285 static int timeLimit; 288 289 static int warmUpTime; 291 292 static long delay; 294 295 static LDAPConnection sharedAuthConnection; 297 298 static LDAPConnection sharedBindConnection; 300 301 static Random parentRandom; 304 305 static String bindDN; 308 309 static String bindPW; 311 312 static String filter1; 314 315 static String filter2; 317 318 static String filter3; 320 321 static String loginIDAttr; 324 325 static String loginIDFinal; 327 328 static String loginIDInitial; 330 331 static String loginPassword; 333 334 static String masterHost; 336 337 static String replicaEntryDN; 339 340 static String replicaHost; 342 343 static String searchAttr1; 345 346 static String searchAttr2; 348 349 static String searchAttr3; 351 352 static String searchBase; 355 356 static String [] loginIDs; 358 359 static String [] loginPasswords; 361 362 static String [] modAttrs; 364 365 static String [] returnAttrs1; 367 368 static String [] returnAttrs2; 370 371 static String [] returnAttrs3; 373 374 static String [] returnAttrsOC; 376 377 378 379 BooleanParameter ignoreInvCredParameter = 382 new BooleanParameter("ignore_49", "Ignore Invalid Credentials Errors", 383 "Indicates whether bind failures because of " + 384 "invalid credentials (err=49). This makes it " + 385 "possible to use this job without actually " + 386 "know user passwords.", false); 387 388 BooleanParameter shareConnsParameter = 390 new BooleanParameter("share_conns", "Share Connections between Threads", 391 "Indicates whether the connections to the " + 392 "directory server will be shared between threads " + 393 "or if each client thread will have its own " + 394 "connections.", true); 395 396 BooleanParameter skipBindParameter = 398 new BooleanParameter("skip_bind", "Skip Bind Operation", 399 "Indicates whether the bind attempt should be " + 400 "skipped as part of the authentication process.", 401 false); 402 403 FileURLParameter loginDataFileParameter = 405 new FileURLParameter("login_data_file", "Login Data File URL", 406 "The URL (FILE or HTTP) of the file containing " + 407 "the login IDs and passwords to use for the " + 408 "authentication.", null, false); 409 410 IntegerParameter coolDownParameter = 412 new IntegerParameter("cool_down", "Cool Down Time", 413 "The time in seconds that the job should " + 414 "continue searching after ending statistics " + 415 "collection.", true, 0, true, 0, false, 0); 416 417 IntegerParameter delayParameter = 420 new IntegerParameter("delay", "Time Between Authentications (ms)", 421 "Specifies the length of time in milliseconds " + 422 "each thread should wait between authentication " + 423 "attempts. Note that this delay will be " + 424 "between the starts of consecutive attempts and " + 425 "not between the end of one attempt and the " + 426 "beginning of the next. If an authentication " + 427 "takes longer than this length of time, then " + 428 "there will be no delay.", true, 0, true, 0, false, 429 0); 430 431 IntegerParameter replicaDelayParameter = 434 new IntegerParameter("latency_delay", "Time Between Latency Checks (ms)", 435 "Specifies the minimum length of time in " + 436 "milliseconds that should pass between latency " + 437 "checks. If a replicated operation takes longer " + 438 "than this length of time, then there will be no " + 439 "delay.", true, 0, true, 0, false, 0); 440 441 IntegerParameter masterPortParameter = 443 new IntegerParameter("master_port", "Master Directory Port", 444 "The port number for the master directory server", 445 true, 389, true, 1, true, 65535); 446 447 IntegerParameter replicaPortParameter = 449 new IntegerParameter("replica_port", "Replica Directory Port", 450 "The port number for the replica directory server", 451 true, 389, true, 1, true, 65535); 452 453 IntegerParameter timeLimitParameter = 456 new IntegerParameter("time_limit", "Operation Time Limit", 457 "The maximum length of time in seconds that any " + 458 "single LDAP operation will be allowed to take " + 459 "before it is cancelled.", true, 0, true, 0, false, 460 0); 461 462 IntegerParameter warmUpParameter = 464 new IntegerParameter("warm_up", "Warm Up Time", 465 "The time in seconds that the job should " + 466 "search before beginning statistics collection.", 467 true, 0, true, 0, false, 0); 468 469 MultiLineTextParameter modAttrsParameter = 471 new MultiLineTextParameter("mod_attrs", "Attributes to Modify", 472 "The set of attributes to modify.", 473 DEFAULT_ATTRS_TO_MODIFY, false); 474 475 PasswordParameter bindPWParameter = 477 new PasswordParameter("bindpw", "Directory Bind Password", 478 "The password to use when binding to the " + 479 "directory server to perform search and modify " + 480 "operations.", false, ""); 481 482 PasswordParameter loginPasswordParameter = 485 new PasswordParameter("login_id_pw", "Login Password", 486 "The password to use when authenticating to the " + 487 "directory for user authentications.", false, ""); 488 489 PlaceholderParameter placeholder = new PlaceholderParameter(); 491 492 StringParameter attr1Parameter = 494 new StringParameter("attr1", "First Attribute to Retrieve", 495 "The first attribute to retrieve from the user's " + 496 "entry as part of the authentication process.", 497 true, DEFAULT_ATTR1); 498 499 StringParameter attr2Parameter = 501 new StringParameter("attr2", "Second Attribute to Retrieve", 502 "The second attribute to retrieve from the user's " + 503 "entry as part of the authentication process.", 504 true, DEFAULT_ATTR2); 505 506 StringParameter attr3Parameter = 508 new StringParameter("attr3", "Third Attribute to Retrieve", 509 "The third attribute to retrieve from the user's " + 510 "entry as part of the authentication process.", 511 true, DEFAULT_ATTR3); 512 513 StringParameter bindDNParameter = 515 new StringParameter("binddn", "Directory Bind DN", 516 "The DN to use when binding to the directory " + 517 "server to perform search and modify operations.", 518 false, ""); 519 520 StringParameter loginIDParameter = 522 new StringParameter("login_id_attr", "Login ID Attribute", 523 "The attribute to use as the login ID to find the " + 524 "user's entry.", true, DEFAULT_LOG_ID_ATTR); 525 526 StringParameter loginIDValueParameter = 528 new StringParameter("login_id_value", "Login ID Value", 529 "The text to use as the value of the login ID " + 530 "attribute in search filters. The value may " + 531 "contain a range of numbers in square brackets.", 532 false, ""); 533 534 StringParameter masterHostParameter = 536 new StringParameter("masterhost", "Master Directory Host", 537 "The DNS hostname or IP address of the master " + 538 "directory server", true, ""); 539 540 StringParameter replicaEntryDNParameter = 543 new StringParameter("replica_entrydn", "Latency Check Entry DN", 544 "The DN of the entry that should be periodically " + 545 "modified to measure the latency of replication. " + 546 "Note that this DN must not be the same as " + 547 "the DN of any of the entries to modify, nor " + 548 "should this entry be modified by any external " + 549 "process during the test.", true, ""); 550 551 StringParameter replicaHostParameter = 553 new StringParameter("replicahost", "Replica Directory Host", 554 "The DNS hostname or IP address of the replica " + 555 "directory server", true, ""); 556 557 StringParameter searchBaseParameter = 559 new StringParameter("search_base", "User Search Base", 560 "The DN in the directory server under which user " + 561 "entries may be found.", true, ""); 562 563 564 boolean reportLatencyTracker; 566 567 CategoricalTracker failureReasonTracker; 569 570 IncrementalTracker attemptCounter; 572 573 IncrementalTracker bindCounter; 575 576 IncrementalTracker failureCounter; 578 579 IncrementalTracker modCounter; 581 582 IncrementalTracker searchCounter; 584 585 IncrementalTracker successCounter; 587 588 LatencyCheckMasterThread masterThread; 590 591 LatencyCheckReplicaThread replicaThread; 593 594 LDAPConnection authConnection; 597 598 LDAPConnection bindConnection; 600 601 LDAPConstraints authConstraints; 603 604 LDAPConstraints bindConstraints; 606 607 LDAPSearchConstraints authSearchConstraints; 609 610 Random random; 612 613 TimeTracker authTimer; 615 616 TimeTracker bindTimer; 618 619 TimeTracker initialSearchTimer; 622 623 TimeTracker modTimer; 625 626 TimeTracker subsequentSearchTimer; 629 630 631 632 636 public SiteMinderWithReplicaLatencyJobClass() 637 { 638 super(); 639 } 640 641 642 643 649 public String getJobName() 650 { 651 return "LDAP SiteMinder Load Simulator with Replication Latency"; 652 } 653 654 655 656 662 public String getJobDescription() 663 { 664 return "This job simulates the load that SiteMinder can place on the " + 665 "directory server when it is performing authentications. It also " + 666 "measures the replication latency for changes performed as part " + 667 "of the authentication."; 668 } 669 670 671 672 678 public String getJobCategoryName() 679 { 680 return "LDAP"; 681 } 682 683 684 685 690 public ParameterList getParameterStubs() 691 { 692 Parameter[] parameterArray = new Parameter[] 693 { 694 placeholder, 695 masterHostParameter, 696 masterPortParameter, 697 bindDNParameter, 698 bindPWParameter, 699 placeholder, 700 replicaHostParameter, 701 replicaPortParameter, 702 replicaEntryDNParameter, 703 replicaDelayParameter, 704 placeholder, 705 searchBaseParameter, 706 loginDataFileParameter, 707 loginIDValueParameter, 708 loginPasswordParameter, 709 loginIDParameter, 710 placeholder, 711 attr1Parameter, 712 attr2Parameter, 713 attr3Parameter, 714 modAttrsParameter, 715 placeholder, 716 warmUpParameter, 717 coolDownParameter, 718 timeLimitParameter, 719 delayParameter, 720 placeholder, 721 skipBindParameter, 722 ignoreInvCredParameter, 723 shareConnsParameter 724 }; 725 726 return new ParameterList(parameterArray); 727 } 728 729 730 731 753 public StatTracker[] getStatTrackerStubs(String clientID, String threadID, 754 int collectionInterval) 755 { 756 return new StatTracker[] 757 { 758 new IncrementalTracker(clientID, threadID, 759 STAT_TRACKER_AUTHENTICATION_ATTEMPTS, 760 collectionInterval), 761 new IncrementalTracker(clientID, threadID, 762 STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS, 763 collectionInterval), 764 new IncrementalTracker(clientID, threadID, 765 STAT_TRACKER_FAILED_AUTHENTICATIONS, 766 collectionInterval), 767 new TimeTracker(clientID, threadID, STAT_TRACKER_AUTHENTICATION_TIME, 768 collectionInterval), 769 new IncrementalTracker(clientID, threadID, STAT_TRACKER_NUM_BINDS, 770 collectionInterval), 771 new TimeTracker(clientID, threadID, STAT_TRACKER_BIND_TIME, 772 collectionInterval), 773 new IncrementalTracker(clientID, threadID, STAT_TRACKER_NUM_MODS, 774 collectionInterval), 775 new TimeTracker(clientID, threadID, STAT_TRACKER_MOD_TIME, 776 collectionInterval), 777 new IncrementalTracker(clientID, threadID, STAT_TRACKER_NUM_SEARCH, 778 collectionInterval), 779 new TimeTracker(clientID, threadID, STAT_TRACKER_INITIAL_SEARCH_TIME, 780 collectionInterval), 781 new TimeTracker(clientID, threadID, STAT_TRACKER_SUBSEQUENT_SEARCH_TIME, 782 collectionInterval), 783 new CategoricalTracker(clientID, threadID, STAT_TRACKER_FAIL_REASON, 784 collectionInterval), 785 new TimeTracker(clientID, threadID, STAT_TRACKER_REPLICATION_LATENCY, 786 collectionInterval), 787 new CategoricalTracker(clientID, threadID, 788 STAT_TRACKER_CATEGORIZED_LATENCY, 789 collectionInterval) 790 }; 791 } 792 793 794 795 800 public StatTracker[] getStatTrackers() 801 { 802 if (reportLatencyTracker) 803 { 804 return new StatTracker[] 805 { 806 attemptCounter, 807 successCounter, 808 failureCounter, 809 authTimer, 810 bindCounter, 811 bindTimer, 812 modCounter, 813 modTimer, 814 searchCounter, 815 initialSearchTimer, 816 subsequentSearchTimer, 817 failureReasonTracker, 818 latencyTime, 819 latencyCategories 820 }; 821 } 822 else 823 { 824 return new StatTracker[] 825 { 826 attemptCounter, 827 successCounter, 828 failureCounter, 829 authTimer, 830 bindCounter, 831 bindTimer, 832 modCounter, 833 modTimer, 834 searchCounter, 835 initialSearchTimer, 836 subsequentSearchTimer, 837 failureReasonTracker 838 }; 839 } 840 } 841 842 843 844 866 public void validateJobInfo(int numClients, int threadsPerClient, 867 int threadStartupDelay, Date startTime, 868 Date stopTime, int duration, 869 int collectionInterval, ParameterList parameters) 870 throws InvalidValueException 871 { 872 FileURLParameter loginDataURLParameter = 873 parameters.getFileURLParameter(loginDataFileParameter.getName()); 874 if ((loginDataURLParameter == null) || 875 (! loginDataURLParameter.hasValue())) 876 { 877 StringParameter loginValueParameter = 878 parameters.getStringParameter(loginIDValueParameter.getName()); 879 PasswordParameter loginPWParameter = 880 parameters.getPasswordParameter(loginPasswordParameter.getName()); 881 882 if ((loginValueParameter == null) || 883 (! loginValueParameter.hasValue()) || 884 (loginPWParameter == null) || 885 (! loginPWParameter.hasValue())) 886 { 887 throw new InvalidValueException("You must specify either a login " + 888 "data file URL or a login ID value " + 889 "and password"); 890 } 891 } 892 } 893 894 895 896 904 public boolean providesParameterTest() 905 { 906 return true; 907 } 908 909 910 911 938 public boolean testJobParameters(ParameterList parameters, 939 ArrayList outputMessages) 940 { 941 StringParameter masterHostParam = 943 parameters.getStringParameter(masterHostParameter.getName()); 944 if ((masterHostParam == null) || (! masterHostParam.hasValue())) 945 { 946 outputMessages.add("ERROR: No master directory server address was " + 947 "provided."); 948 return false; 949 } 950 String masterHost = masterHostParam.getStringValue(); 951 952 953 IntegerParameter masterPortParam = 954 parameters.getIntegerParameter(masterPortParameter.getName()); 955 if ((masterPortParam == null) || (! masterPortParam.hasValue())) 956 { 957 outputMessages.add("ERROR: No master directory server port was " + 958 "provided."); 959 return false; 960 } 961 int masterPort = masterPortParam.getIntValue(); 962 963 964 StringParameter replicaHostParam = 965 parameters.getStringParameter(replicaHostParameter.getName()); 966 if ((replicaHostParam == null) || (! replicaHostParam.hasValue())) 967 { 968 outputMessages.add("ERROR: No replica directory server address was " + 969 "provided."); 970 return false; 971 } 972 String replicaHost = replicaHostParam.getStringValue(); 973 974 975 IntegerParameter replicaPortParam = 976 parameters.getIntegerParameter(replicaPortParameter.getName()); 977 if ((replicaPortParam == null) || (! replicaPortParam.hasValue())) 978 { 979 outputMessages.add("ERROR: No replica directory server port was " + 980 "provided."); 981 return false; 982 } 983 int replicaPort = replicaPortParam.getIntValue(); 984 985 986 String bindDN = ""; 987 StringParameter bindDNParam = 988 parameters.getStringParameter(bindDNParameter.getName()); 989 if ((bindDNParam != null) && bindDNParam.hasValue()) 990 { 991 bindDN = bindDNParam.getStringValue(); 992 } 993 994 995 String bindPassword = ""; 996 PasswordParameter bindPWParam = 997 parameters.getPasswordParameter(bindPWParameter.getName()); 998 if ((bindPWParam != null) && bindPWParam.hasValue()) 999 { 1000 bindPassword = bindPWParam.getStringValue(); 1001 } 1002 1003 1004 StringParameter baseDNParam = 1005 parameters.getStringParameter(searchBaseParameter.getName()); 1006 if ((baseDNParam == null) || (! baseDNParam.hasValue())) 1007 { 1008 outputMessages.add("ERROR: No base DN was provided."); 1009 return false; 1010 } 1011 String baseDN = baseDNParam.getStringValue(); 1012 1013 1014 StringParameter replicaEntryDNParam = 1015 parameters.getStringParameter(replicaEntryDNParameter.getName()); 1016 if ((replicaEntryDNParam == null) || (! replicaEntryDNParam.hasValue())) 1017 { 1018 outputMessages.add("ERROR: No replica check entry DN was provided."); 1019 return false; 1020 } 1021 String replicaEntryDN = replicaEntryDNParam.getStringValue(); 1022 1023 1024 LDAPConnection conn = new LDAPConnection(); 1027 1028 1029 try 1031 { 1032 outputMessages.add("Attempting to establish a connection to master " + 1033 masterHost + ":" + masterPort + "...."); 1034 conn.connect(masterHost, masterPort); 1035 outputMessages.add("Connected successfully."); 1036 outputMessages.add(""); 1037 } 1038 catch (Exception e) 1039 { 1040 outputMessages.add("ERROR: Unable to connect to the master server: " + 1041 stackTraceToString(e)); 1042 return false; 1043 } 1044 1045 1046 try 1048 { 1049 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 1050 "master server with a DN of '" + bindDN + "'...."); 1051 conn.bind(3, bindDN, bindPassword); 1052 outputMessages.add("Bound successfully."); 1053 outputMessages.add(""); 1054 } 1055 catch (Exception e) 1056 { 1057 try 1058 { 1059 conn.disconnect(); 1060 } catch (Exception e2) {} 1061 1062 outputMessages.add("ERROR: Unable to bind to the master server: " + 1063 stackTraceToString(e)); 1064 return false; 1065 } 1066 1067 1068 try 1070 { 1071 outputMessages.add("Checking to make sure that the base DN entry '" + 1072 baseDN + "' exists in the master...."); 1073 LDAPEntry baseDNEntry = conn.read(baseDN, new String [] { "1.1" }); 1074 if (baseDNEntry == null) 1075 { 1076 try 1077 { 1078 conn.disconnect(); 1079 } catch (Exception e2) {} 1080 1081 outputMessages.add("ERROR: Unable to retrieve the base DN entry."); 1082 return false; 1083 } 1084 else 1085 { 1086 outputMessages.add("Successfully read the base DN entry."); 1087 outputMessages.add(""); 1088 } 1089 } 1090 catch (Exception e) 1091 { 1092 try 1093 { 1094 conn.disconnect(); 1095 } catch (Exception e2) {} 1096 1097 outputMessages.add("ERROR: Unable to retrieve the base DN entry: " + 1098 stackTraceToString(e)); 1099 return false; 1100 } 1101 1102 1103 try 1105 { 1106 outputMessages.add("Checking to make sure that the replica check " + 1107 "entry '" + replicaEntryDN + 1108 "' exists in the master...."); 1109 LDAPEntry baseDNEntry = conn.read(replicaEntryDN, new String [] { "1.1" }); 1110 if (baseDNEntry == null) 1111 { 1112 try 1113 { 1114 conn.disconnect(); 1115 } catch (Exception e2) {} 1116 1117 outputMessages.add("ERROR: Unable to retrieve the replica check " + 1118 "entry."); 1119 return false; 1120 } 1121 else 1122 { 1123 outputMessages.add("Successfully read the replica check entry."); 1124 outputMessages.add(""); 1125 } 1126 } 1127 catch (Exception e) 1128 { 1129 try 1130 { 1131 conn.disconnect(); 1132 } catch (Exception e2) {} 1133 1134 outputMessages.add("ERROR: Unable to retrieve the replica check " + 1135 "entry: " + stackTraceToString(e)); 1136 return false; 1137 } 1138 1139 1140 try 1143 { 1144 conn.disconnect(); 1145 } catch (Exception e) {} 1146 1147 1148 try 1150 { 1151 outputMessages.add("Attempting to establish a connection to replica " + 1152 replicaHost + ":" + replicaPort + "...."); 1153 conn.connect(replicaHost, replicaPort); 1154 outputMessages.add("Connected successfully."); 1155 outputMessages.add(""); 1156 } 1157 catch (Exception e) 1158 { 1159 outputMessages.add("ERROR: Unable to connect to the replica server: " + 1160 stackTraceToString(e)); 1161 return false; 1162 } 1163 1164 1165 try 1167 { 1168 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 1169 "replica server with a DN of '" + bindDN + "'...."); 1170 conn.bind(3, bindDN, bindPassword); 1171 outputMessages.add("Bound successfully."); 1172 outputMessages.add(""); 1173 } 1174 catch (Exception e) 1175 { 1176 try 1177 { 1178 conn.disconnect(); 1179 } catch (Exception e2) {} 1180 1181 outputMessages.add("ERROR: Unable to bind to the replica server: " + 1182 stackTraceToString(e)); 1183 return false; 1184 } 1185 1186 1187 try 1189 { 1190 outputMessages.add("Checking to make sure that the base DN entry '" + 1191 baseDN + "' exists in the replica...."); 1192 LDAPEntry baseDNEntry = conn.read(baseDN, new String [] { "1.1" }); 1193 if (baseDNEntry == null) 1194 { 1195 try 1196 { 1197 conn.disconnect(); 1198 } catch (Exception e2) {} 1199 1200 outputMessages.add("ERROR: Unable to retrieve the base DN entry."); 1201 return false; 1202 } 1203 else 1204 { 1205 outputMessages.add("Successfully read the base DN entry."); 1206 outputMessages.add(""); 1207 } 1208 } 1209 catch (Exception e) 1210 { 1211 try 1212 { 1213 conn.disconnect(); 1214 } catch (Exception e2) {} 1215 1216 outputMessages.add("ERROR: Unable to retrieve the base DN entry: " + 1217 stackTraceToString(e)); 1218 return false; 1219 } 1220 1221 1222 try 1224 { 1225 outputMessages.add("Checking to make sure that the replica check " + 1226 "entry '" + replicaEntryDN + 1227 "' exists in the replica...."); 1228 LDAPEntry baseDNEntry = conn.read(replicaEntryDN, new String [] { "1.1" }); 1229 if (baseDNEntry == null) 1230 { 1231 try 1232 { 1233 conn.disconnect(); 1234 } catch (Exception e2) {} 1235 1236 outputMessages.add("ERROR: Unable to retrieve the replica check " + 1237 "entry."); 1238 return false; 1239 } 1240 else 1241 { 1242 outputMessages.add("Successfully read the replica check entry."); 1243 outputMessages.add(""); 1244 } 1245 } 1246 catch (Exception e) 1247 { 1248 try 1249 { 1250 conn.disconnect(); 1251 } catch (Exception e2) {} 1252 1253 outputMessages.add("ERROR: Unable to retrieve the replica check " + 1254 "entry: " + stackTraceToString(e)); 1255 return false; 1256 } 1257 1258 1259 try 1262 { 1263 conn.disconnect(); 1264 } catch (Exception e) {} 1265 1266 1267 outputMessages.add("All tests completed successfully."); 1268 return true; 1269 } 1270 1271 1272 1273 1285 public void initializeClient(String clientID, ParameterList parameters) 1286 throws UnableToRunException 1287 { 1288 latencyTrackerChosen = false; 1290 1291 1292 masterHostParameter = 1294 parameters.getStringParameter(masterHostParameter.getName()); 1295 if (masterHostParameter == null) 1296 { 1297 throw new UnableToRunException("No master directory server host " + 1298 "provided."); 1299 } 1300 else 1301 { 1302 masterHost = masterHostParameter.getStringValue(); 1303 } 1304 1305 1306 masterPortParameter = 1308 parameters.getIntegerParameter(masterPortParameter.getName()); 1309 if (masterPortParameter != null) 1310 { 1311 masterPort = masterPortParameter.getIntValue(); 1312 } 1313 1314 1315 replicaHost = null; 1317 replicaHostParameter = 1318 parameters.getStringParameter(replicaHostParameter.getName()); 1319 if (replicaHostParameter != null) 1320 { 1321 replicaHost = replicaHostParameter.getStringValue(); 1322 } 1323 1324 1325 replicaPort = 389; 1327 replicaPortParameter = 1328 parameters.getIntegerParameter(replicaPortParameter.getName()); 1329 if (replicaPortParameter != null) 1330 { 1331 replicaPort = replicaPortParameter.getIntValue(); 1332 } 1333 1334 1335 replicaEntryDN = null; 1337 replicaEntryDNParameter = 1338 parameters.getStringParameter(replicaEntryDNParameter.getName()); 1339 if (replicaEntryDNParameter != null) 1340 { 1341 replicaEntryDN = replicaEntryDNParameter.getStringValue(); 1342 } 1343 1344 1345 latencyDelay = 0; 1347 replicaDelayParameter = 1348 parameters.getIntegerParameter(replicaDelayParameter.getName()); 1349 if (replicaDelayParameter != null) 1350 { 1351 latencyDelay = replicaDelayParameter.getIntValue(); 1352 } 1353 1354 1355 bindDNParameter = parameters.getStringParameter(bindDNParameter.getName()); 1357 if (bindDNParameter == null) 1358 { 1359 bindDN = ""; 1360 } 1361 else 1362 { 1363 bindDN = bindDNParameter.getStringValue(); 1364 } 1365 1366 bindPWParameter = 1368 parameters.getPasswordParameter(bindPWParameter.getName()); 1369 if (bindPWParameter == null) 1370 { 1371 bindPW = ""; 1372 } 1373 else 1374 { 1375 bindPW = bindPWParameter.getStringValue(); 1376 } 1377 1378 searchBaseParameter = 1380 parameters.getStringParameter(searchBaseParameter.getName()); 1381 if (searchBaseParameter != null) 1382 { 1383 searchBase = searchBaseParameter.getStringValue(); 1384 } 1385 1386 1387 useDataFile = false; 1389 loginDataFileParameter = 1390 parameters.getFileURLParameter(loginDataFileParameter.getName()); 1391 if ((loginDataFileParameter != null) && (loginDataFileParameter.hasValue())) 1392 { 1393 String [] fileLines; 1394 try 1395 { 1396 fileLines = loginDataFileParameter.getNonBlankFileLines(); 1397 } 1398 catch (Exception e) 1399 { 1400 throw new UnableToRunException("Unable to retrieve the login data " + 1401 "from the file: " + e, e); 1402 } 1403 1404 ArrayList loginIDList = new ArrayList(fileLines.length); 1406 ArrayList passwordList = new ArrayList(fileLines.length); 1407 for (int i=0; i < fileLines.length; i++) 1408 { 1409 try 1410 { 1411 StringTokenizer tokenizer = new StringTokenizer(fileLines[i], "\t"); 1412 String loginID = tokenizer.nextToken(); 1413 String password = tokenizer.nextToken(); 1414 loginIDList.add(loginID); 1415 passwordList.add(password); 1416 } catch (Exception e) {} 1417 } 1418 1419 loginIDs = new String [loginIDList.size()]; 1422 loginPasswords = new String [passwordList.size()]; 1423 loginIDList.toArray(loginIDs); 1424 passwordList.toArray(loginPasswords); 1425 if (loginIDs.length == 0) 1426 { 1427 throw new UnableToRunException("No login IDs/passwords extracted from " + 1428 "the login data file."); 1429 } 1430 1431 useDataFile = true; 1432 } 1433 else 1434 { 1435 loginPasswordParameter = 1436 parameters.getPasswordParameter(loginPasswordParameter.getName()); 1437 if ((loginPasswordParameter != null) && 1438 (loginPasswordParameter.hasValue())) 1439 { 1440 loginPassword = loginPasswordParameter.getStringValue(); 1441 } 1442 1443 loginIDValueParameter = 1444 parameters.getStringParameter(loginIDValueParameter.getName()); 1445 useLoginIDRange = true; 1446 useSequential = false; 1447 String loginIDValue = loginIDValueParameter.getStringValue(); 1448 try 1449 { 1450 int openPos = loginIDValue.indexOf('['); 1451 int closePos = loginIDValue.indexOf(']', openPos); 1452 loginIDInitial = loginIDValue.substring(0, openPos); 1453 loginIDFinal = loginIDValue.substring(closePos+1); 1454 1455 int dashPos = loginIDValue.indexOf('-', openPos); 1456 if (dashPos < 0) 1457 { 1458 dashPos = loginIDValue.indexOf(':', openPos); 1459 useSequential = true; 1460 } 1461 1462 loginIDMin = Integer.parseInt(loginIDValue.substring(openPos+1, 1463 dashPos)); 1464 loginIDMax = Integer.parseInt(loginIDValue.substring(dashPos+1, 1465 closePos)); 1466 loginIDSpan = loginIDMax - loginIDMin + 1; 1467 sequentialCounter = loginIDMin; 1468 } 1469 catch (Exception e) 1470 { 1471 useLoginIDRange = false; 1472 loginIDInitial = loginIDValue; 1473 } 1474 } 1475 1476 1477 loginIDParameter = 1479 parameters.getStringParameter(loginIDParameter.getName()); 1480 if (loginIDParameter != null) 1481 { 1482 loginIDAttr = loginIDParameter.getStringValue(); 1483 } 1484 1485 1486 attr1Parameter = parameters.getStringParameter(attr1Parameter.getName()); 1488 if (attr1Parameter != null) 1489 { 1490 searchAttr1 = attr1Parameter.getStringValue(); 1491 filter1 = "(" + searchAttr1 + "=*)"; 1492 returnAttrs1 = new String [] { searchAttr1 }; 1493 } 1494 1495 attr2Parameter = parameters.getStringParameter(attr2Parameter.getName()); 1496 if (attr2Parameter != null) 1497 { 1498 searchAttr2 = attr2Parameter.getStringValue(); 1499 filter2 = "(" + searchAttr2 + "=*)"; 1500 returnAttrs2 = new String [] { searchAttr2 }; 1501 } 1502 1503 attr3Parameter = parameters.getStringParameter(attr3Parameter.getName()); 1504 if (attr3Parameter != null) 1505 { 1506 searchAttr3 = attr3Parameter.getStringValue(); 1507 filter3 = "(" + searchAttr3 + "=*)"; 1508 returnAttrs3 = new String [] { searchAttr3 }; 1509 } 1510 1511 returnAttrsOC = new String [] { "objectClass" }; 1512 1513 1514 modAttrs = null; 1516 modAttrsParameter = 1517 parameters.getMultiLineTextParameter(modAttrsParameter.getName()); 1518 if ((modAttrsParameter != null) && (modAttrsParameter.hasValue())) 1519 { 1520 modAttrs = modAttrsParameter.getNonBlankLines(); 1521 } 1522 1523 skipBind = false; 1525 skipBindParameter = 1526 parameters.getBooleanParameter(skipBindParameter.getName()); 1527 if (skipBindParameter != null) 1528 { 1529 skipBind = skipBindParameter.getBooleanValue(); 1530 } 1531 1532 warmUpTime = 0; 1534 warmUpParameter = parameters.getIntegerParameter(warmUpParameter.getName()); 1535 if (warmUpParameter != null) 1536 { 1537 warmUpTime = warmUpParameter.getIntValue(); 1538 } 1539 1540 coolDownTime = 0; 1542 coolDownParameter = 1543 parameters.getIntegerParameter(coolDownParameter.getName()); 1544 if (coolDownParameter != null) 1545 { 1546 coolDownTime = coolDownParameter.getIntValue(); 1547 } 1548 1549 timeLimitParameter = 1551 parameters.getIntegerParameter(timeLimitParameter.getName()); 1552 if (timeLimitParameter != null) 1553 { 1554 timeLimit = timeLimitParameter.getIntValue(); 1555 } 1556 1557 delay = 0; 1559 delayParameter = parameters.getIntegerParameter(delayParameter.getName()); 1560 if (delayParameter != null) 1561 { 1562 delay = delayParameter.getIntValue(); 1563 } 1564 1565 1566 ignoreInvCredParameter = 1569 parameters.getBooleanParameter(ignoreInvCredParameter.getName()); 1570 if (ignoreInvCredParameter != null) 1571 { 1572 ignoreInvalidCredentials = ignoreInvCredParameter.getBooleanValue(); 1573 } 1574 1575 shareConnsParameter = 1577 parameters.getBooleanParameter(shareConnsParameter.getName()); 1578 if (shareConnsParameter != null) 1579 { 1580 useSharedConnections = shareConnsParameter.getBooleanValue(); 1581 } 1582 1583 1584 if (useSharedConnections) 1586 { 1587 sharedAuthConnection = new LDAPConnection(); 1588 sharedBindConnection = new LDAPConnection(); 1589 1590 try 1591 { 1592 sharedAuthConnection.connect(3, masterHost, masterPort, bindDN, 1593 bindPW); 1594 sharedBindConnection.connect(3, masterHost, masterPort, "", ""); 1595 } 1596 catch (Exception e) 1597 { 1598 throw new UnableToRunException("Could not establish shared " + 1599 "connections to the directory: " + e, 1600 e); 1601 } 1602 } 1603 1604 1605 parentRandom = new Random(); 1607 } 1608 1609 1610 1611 1627 public void initializeThread(String clientID, String threadID, 1628 int collectionInterval, ParameterList parameters) 1629 throws UnableToRunException 1630 { 1631 random = new Random(parentRandom.nextLong()); 1633 1634 if (useSharedConnections) 1638 { 1639 authConnection = sharedAuthConnection; 1640 bindConnection = sharedBindConnection; 1641 } 1642 else 1643 { 1644 authConnection = new LDAPConnection(); 1645 bindConnection = new LDAPConnection(); 1646 1647 try 1648 { 1649 authConnection.connect(3, masterHost, masterPort, bindDN, bindPW); 1650 bindConnection.connect(3, masterHost, masterPort, "", ""); 1651 } 1652 catch (Exception e) 1653 { 1654 throw new UnableToRunException("Unable to establish the connections " + 1655 "to the directory server: " + e, e); 1656 } 1657 } 1658 1659 authConstraints = authConnection.getConstraints(); 1661 bindConstraints = bindConnection.getConstraints(); 1662 authSearchConstraints = authConnection.getSearchConstraints(); 1663 authConstraints.setTimeLimit(1000*timeLimit); 1664 bindConstraints.setTimeLimit(1000*timeLimit); 1665 authSearchConstraints.setTimeLimit(1000*timeLimit); 1666 authSearchConstraints.setServerTimeLimit(timeLimit); 1667 1668 1669 attemptCounter = 1671 new IncrementalTracker(clientID, threadID, 1672 STAT_TRACKER_AUTHENTICATION_ATTEMPTS, 1673 collectionInterval); 1674 successCounter = 1675 new IncrementalTracker(clientID, threadID, 1676 STAT_TRACKER_SUCCESSFUL_AUTHENTICATIONS, 1677 collectionInterval); 1678 failureCounter = 1679 new IncrementalTracker(clientID, threadID, 1680 STAT_TRACKER_FAILED_AUTHENTICATIONS, 1681 collectionInterval); 1682 bindCounter = new IncrementalTracker(clientID, threadID, 1683 STAT_TRACKER_NUM_BINDS, 1684 collectionInterval); 1685 modCounter = new IncrementalTracker(clientID, threadID, 1686 STAT_TRACKER_NUM_MODS, 1687 collectionInterval); 1688 searchCounter = new IncrementalTracker(clientID, threadID, 1689 STAT_TRACKER_NUM_SEARCH, 1690 collectionInterval); 1691 authTimer = new TimeTracker(clientID, threadID, 1692 STAT_TRACKER_AUTHENTICATION_TIME, 1693 collectionInterval); 1694 bindTimer = new TimeTracker(clientID, threadID, STAT_TRACKER_BIND_TIME, 1695 collectionInterval); 1696 modTimer = new TimeTracker(clientID, threadID, STAT_TRACKER_MOD_TIME, 1697 collectionInterval); 1698 initialSearchTimer = new TimeTracker(clientID, threadID, 1699 STAT_TRACKER_INITIAL_SEARCH_TIME, 1700 collectionInterval); 1701 subsequentSearchTimer = new TimeTracker(clientID, threadID, 1702 STAT_TRACKER_SUBSEQUENT_SEARCH_TIME, 1703 collectionInterval); 1704 failureReasonTracker = new CategoricalTracker(clientID, threadID, 1705 STAT_TRACKER_FAIL_REASON, 1706 collectionInterval); 1707 1708 1709 RealTimeStatReporter statReporter = getStatReporter(); 1711 if (statReporter != null) 1712 { 1713 String jobID = getJobID(); 1714 attemptCounter.enableRealTimeStats(statReporter, jobID); 1715 successCounter.enableRealTimeStats(statReporter, jobID); 1716 failureCounter.enableRealTimeStats(statReporter, jobID); 1717 bindCounter.enableRealTimeStats(statReporter, jobID); 1718 modCounter.enableRealTimeStats(statReporter, jobID); 1719 searchCounter.enableRealTimeStats(statReporter, jobID); 1720 authTimer.enableRealTimeStats(statReporter, jobID); 1721 bindTimer.enableRealTimeStats(statReporter, jobID); 1722 modTimer.enableRealTimeStats(statReporter, jobID); 1723 initialSearchTimer.enableRealTimeStats(statReporter, jobID); 1724 subsequentSearchTimer.enableRealTimeStats(statReporter, jobID); 1725 } 1726 1727 1728 if ((! latencyTrackerChosen) && (getClientNumber() == 0)) 1731 { 1732 latencyCheckMutex = new Object (); 1733 latencyTrackerChosen = true; 1734 reportLatencyTracker = true; 1735 1736 latencyTime = new TimeTracker(clientID, threadID, 1738 STAT_TRACKER_REPLICATION_LATENCY, 1739 collectionInterval); 1740 if (statReporter != null) 1741 { 1742 latencyTime.enableRealTimeStats(statReporter, getJobID()); 1743 } 1744 1745 latencyCategories = 1747 new CategoricalTracker(clientID, threadID, 1748 STAT_TRACKER_CATEGORIZED_LATENCY, 1749 collectionInterval); 1750 1751 try 1753 { 1754 masterThread = 1755 new LatencyCheckMasterThread(this, masterHost, masterPort, bindDN, 1756 bindPW, replicaEntryDN, 1757 modAttrs[0], latencyDelay); 1758 } 1759 catch (LDAPException le) 1760 { 1761 throw new UnableToRunException("Could not create the master latency " + 1762 "thread: " + le, le); 1763 } 1764 1765 try 1767 { 1768 replicaThread = 1769 new LatencyCheckReplicaThread(this, replicaHost, replicaPort, 1770 bindDN, bindPW, 1771 replicaEntryDN); 1772 } 1773 catch (LDAPException le) 1774 { 1775 throw new UnableToRunException("Could not create the replica latency " + 1776 "thread: " + le, le); 1777 } 1778 1779 masterThread.start(); 1781 replicaThread.start(); 1782 } 1783 else 1784 { 1785 reportLatencyTracker = false; 1786 } 1787 } 1788 1789 1790 1791 1795 public void runJob() 1796 { 1797 long currentTime = System.currentTimeMillis(); 1799 boolean collectingStats = false; 1800 long startCollectingTime = currentTime + (1000 * warmUpTime); 1801 long stopCollectingTime = Long.MAX_VALUE; 1802 if ((coolDownTime > 0) && (getShouldStopTime() > 0)) 1803 { 1804 stopCollectingTime = getShouldStopTime() - (1000 * coolDownTime); 1805 } 1806 1807 long authStartTime = 0; 1810 1811 1812 while (! shouldStop()) 1814 { 1815 currentTime = System.currentTimeMillis(); 1816 if ((! collectingStats) && (currentTime >= startCollectingTime) && 1817 (currentTime < stopCollectingTime)) 1818 { 1819 attemptCounter.startTracker(); 1821 successCounter.startTracker(); 1822 failureCounter.startTracker(); 1823 authTimer.startTracker(); 1824 bindCounter.startTracker(); 1825 modCounter.startTracker(); 1826 searchCounter.startTracker(); 1827 bindTimer.startTracker(); 1828 modTimer.startTracker(); 1829 initialSearchTimer.startTracker(); 1830 subsequentSearchTimer.startTracker(); 1831 failureReasonTracker.startTracker(); 1832 1833 if (reportLatencyTracker) 1834 { 1835 latencyTime.startTracker(); 1836 latencyCategories.startTracker(); 1837 replicaThread.startChecking(); 1838 masterThread.startChecking(); 1839 } 1840 1841 collectingStats = true; 1842 } 1843 else if ((collectingStats) && (currentTime >= stopCollectingTime)) 1844 { 1845 attemptCounter.stopTracker(); 1846 successCounter.stopTracker(); 1847 failureCounter.stopTracker(); 1848 authTimer.stopTracker(); 1849 bindCounter.stopTracker(); 1850 modCounter.stopTracker(); 1851 searchCounter.stopTracker(); 1852 bindTimer.stopTracker(); 1853 modTimer.stopTracker(); 1854 initialSearchTimer.stopTracker(); 1855 subsequentSearchTimer.stopTracker(); 1856 failureReasonTracker.stopTracker(); 1857 1858 if (reportLatencyTracker) 1859 { 1860 latencyTime.stopTracker(); 1861 latencyCategories.stopTracker(); 1862 replicaThread.stopAndWait(); 1863 masterThread.stopAndWait(); 1864 } 1865 1866 collectingStats = false; 1867 } 1868 1869 if ((delay > 0) && (authStartTime > 0)) 1871 { 1872 long now = System.currentTimeMillis(); 1873 long sleepTime = delay - (now - authStartTime); 1874 if (sleepTime > 0) 1875 { 1876 try 1877 { 1878 Thread.sleep(sleepTime); 1879 } catch (InterruptedException ie) {} 1880 1881 if (shouldStop()) 1882 { 1883 break; 1884 } 1885 } 1886 } 1887 1888 String [] loginInfo = getLoginInfo(); 1890 String loginID = loginInfo[0]; 1891 String password = loginInfo[1]; 1892 1893 1894 if (delay > 0) 1896 { 1897 authStartTime = System.currentTimeMillis(); 1898 } 1899 1900 1901 if (collectingStats) 1903 { 1904 attemptCounter.increment(); 1905 authTimer.startTimer(); 1906 } 1907 1908 String failureReason = "Search 1"; 1909 1910 try 1911 { 1912 String userDN = null; 1914 String filter = "(" + loginIDAttr + "=" + loginID + ")"; 1915 LDAPSearchResults results; 1916 if (collectingStats) 1917 { 1918 searchCounter.increment(); 1919 initialSearchTimer.startTimer(); 1920 } 1921 results = authConnection.search(searchBase, LDAPConnection.SCOPE_SUB, 1922 filter, returnAttrsOC, false, 1923 authSearchConstraints); 1924 while (results.hasMoreElements()) 1925 { 1926 Object element = results.nextElement(); 1927 if (element instanceof LDAPEntry) 1928 { 1929 userDN = ((LDAPEntry) element).getDN(); 1930 } 1931 } 1932 if (collectingStats) 1933 { 1934 initialSearchTimer.stopTimer(); 1935 } 1936 1937 if (userDN == null) 1939 { 1940 if (collectingStats) 1941 { 1942 failureCounter.increment(); 1943 authTimer.stopTimer(); 1944 failureReasonTracker.increment(failureReason); 1945 } 1946 continue; 1947 } 1948 1949 failureReason = "Search 2"; 1952 filter = "(objectClass=*)"; 1953 if (collectingStats) 1954 { 1955 searchCounter.increment(); 1956 subsequentSearchTimer.startTimer(); 1957 } 1958 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 1959 filter, returnAttrsOC, false, 1960 authSearchConstraints); 1961 while (results.hasMoreElements()) 1962 { 1963 results.nextElement(); 1964 } 1965 if (collectingStats) 1966 { 1967 subsequentSearchTimer.stopTimer(); 1968 } 1969 1970 if (! skipBind) 1972 { 1973 failureReason = "Bind"; 1974 1975 try 1976 { 1977 if (collectingStats) 1978 { 1979 bindCounter.increment(); 1980 bindTimer.startTimer(); 1981 } 1982 bindConnection.authenticate(3, userDN, password, bindConstraints); 1983 if (collectingStats) 1984 { 1985 bindTimer.stopTimer(); 1986 } 1987 } 1988 catch (LDAPException le) 1989 { 1990 if (collectingStats) 1991 { 1992 bindTimer.stopTimer(); 1993 } 1994 1995 if (le.getLDAPResultCode() == LDAPException.INVALID_CREDENTIALS) 1996 { 1997 if (! ignoreInvalidCredentials) 1998 { 1999 if (collectingStats) 2000 { 2001 failureCounter.increment(); 2002 authTimer.stopTimer(); 2003 failureReasonTracker.increment(failureReason); 2004 } 2005 continue; 2006 } 2007 } 2008 else 2009 { 2010 if (collectingStats) 2011 { 2012 failureCounter.increment(); 2013 authTimer.stopTimer(); 2014 failureReasonTracker.increment(failureReason); 2015 } 2016 continue; 2017 } 2018 } 2019 } 2020 2021 failureReason = "Search 3"; 2023 if (collectingStats) 2024 { 2025 searchCounter.increment(); 2026 subsequentSearchTimer.startTimer(); 2027 } 2028 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2029 filter1, returnAttrs1, false, 2030 authSearchConstraints); 2031 while (results.hasMoreElements()) 2032 { 2033 results.nextElement(); 2034 } 2035 if (collectingStats) 2036 { 2037 subsequentSearchTimer.stopTimer(); 2038 } 2039 2040 failureReason = "Search 4"; 2042 if (collectingStats) 2043 { 2044 searchCounter.increment(); 2045 subsequentSearchTimer.startTimer(); 2046 } 2047 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2048 filter2, returnAttrs2, false, 2049 authSearchConstraints); 2050 while (results.hasMoreElements()) 2051 { 2052 results.nextElement(); 2053 } 2054 if (collectingStats) 2055 { 2056 subsequentSearchTimer.stopTimer(); 2057 } 2058 2059 failureReason = "Search 5"; 2061 if (collectingStats) 2062 { 2063 searchCounter.increment(); 2064 subsequentSearchTimer.startTimer(); 2065 } 2066 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2067 filter1, returnAttrs1, false, 2068 authSearchConstraints); 2069 while (results.hasMoreElements()) 2070 { 2071 results.nextElement(); 2072 } 2073 if (collectingStats) 2074 { 2075 subsequentSearchTimer.stopTimer(); 2076 } 2077 2078 if ((modAttrs != null) && (modAttrs.length > 0)) 2080 { 2081 failureReason = "Modify"; 2082 LDAPModificationSet modSet = new LDAPModificationSet(); 2083 for (int i=0; i < modAttrs.length; i++) 2084 { 2085 LDAPAttribute attr = new LDAPAttribute(modAttrs[i], 2086 getRandomString(80)); 2087 modSet.add(LDAPModification.REPLACE, attr); 2088 } 2089 if (collectingStats) 2090 { 2091 modCounter.increment(); 2092 modTimer.startTimer(); 2093 } 2094 authConnection.modify(userDN, modSet, authConstraints); 2095 if (collectingStats) 2096 { 2097 modTimer.stopTimer(); 2098 } 2099 } 2100 2101 failureReason = "Search 6"; 2103 if (collectingStats) 2104 { 2105 searchCounter.increment(); 2106 subsequentSearchTimer.startTimer(); 2107 } 2108 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2109 filter1, returnAttrs1, false, 2110 authSearchConstraints); 2111 while (results.hasMoreElements()) 2112 { 2113 results.nextElement(); 2114 } 2115 if (collectingStats) 2116 { 2117 subsequentSearchTimer.stopTimer(); 2118 } 2119 2120 failureReason = "Search 7"; 2122 if (collectingStats) 2123 { 2124 searchCounter.increment(); 2125 subsequentSearchTimer.startTimer(); 2126 } 2127 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2128 filter1, returnAttrs1, false, 2129 authSearchConstraints); 2130 while (results.hasMoreElements()) 2131 { 2132 results.nextElement(); 2133 } 2134 if (collectingStats) 2135 { 2136 subsequentSearchTimer.stopTimer(); 2137 } 2138 2139 failureReason = "Search 8"; 2141 if (collectingStats) 2142 { 2143 searchCounter.increment(); 2144 subsequentSearchTimer.startTimer(); 2145 } 2146 results = authConnection.search(userDN, LDAPConnection.SCOPE_BASE, 2147 filter3, returnAttrs3, false, 2148 authSearchConstraints); 2149 while (results.hasMoreElements()) 2150 { 2151 results.nextElement(); 2152 } 2153 if (collectingStats) 2154 { 2155 subsequentSearchTimer.stopTimer(); 2156 } 2157 } 2158 catch (Exception e) 2159 { 2160 2161 if (collectingStats) 2162 { 2163 failureCounter.increment(); 2164 authTimer.stopTimer(); 2165 failureReasonTracker.increment(failureReason); 2166 } 2167 continue; 2168 } 2169 2170 2171 if (collectingStats) 2174 { 2175 successCounter.increment(); 2176 authTimer.stopTimer(); 2177 } 2178 } 2179 2180 2181 if (collectingStats) 2183 { 2184 attemptCounter.stopTracker(); 2185 successCounter.stopTracker(); 2186 failureCounter.stopTracker(); 2187 authTimer.stopTracker(); 2188 bindCounter.stopTracker(); 2189 modCounter.stopTracker(); 2190 searchCounter.stopTracker(); 2191 bindTimer.stopTracker(); 2192 modTimer.stopTracker(); 2193 initialSearchTimer.stopTracker(); 2194 subsequentSearchTimer.stopTracker(); 2195 failureReasonTracker.stopTracker(); 2196 2197 if (reportLatencyTracker) 2198 { 2199 latencyTime.stopTracker(); 2200 latencyCategories.stopTracker(); 2201 replicaThread.stopAndWait(); 2202 masterThread.stopAndWait(); 2203 } 2204 } 2205 2206 2207 if (! useSharedConnections) 2209 { 2210 try 2211 { 2212 authConnection.disconnect(); 2213 } catch (Exception e) {} 2214 2215 try 2216 { 2217 bindConnection.disconnect(); 2218 } catch (Exception e) {} 2219 } 2220 } 2221 2222 2223 2224 2228 public void destroy() 2229 { 2230 if (authConnection != null) 2231 { 2232 try 2233 { 2234 authConnection.disconnect(); 2235 } catch (Exception e) {} 2236 2237 authConnection = null; 2238 } 2239 2240 if (bindConnection != null) 2241 { 2242 try 2243 { 2244 bindConnection.disconnect(); 2245 } catch (Exception e) {} 2246 2247 bindConnection = null; 2248 } 2249 2250 if (masterThread != null) 2251 { 2252 masterThread.masterThread.interrupt(); 2253 2254 try 2255 { 2256 masterThread.connection.disconnect(); 2257 } catch (Exception e) {} 2258 2259 masterThread.connection = null; 2260 masterThread = null; 2261 } 2262 2263 if (replicaThread != null) 2264 { 2265 replicaThread.replicaThread.interrupt(); 2266 2267 try 2268 { 2269 replicaThread.connection.disconnect(); 2270 } catch (Exception e) {} 2271 2272 replicaThread.connection = null; 2273 replicaThread = null; 2274 } 2275 } 2276 2277 2278 2279 2284 public void finalizeClient() 2285 { 2286 if (useSharedConnections) 2288 { 2289 try 2290 { 2291 sharedAuthConnection.disconnect(); 2292 } catch (Exception e) {} 2293 2294 try 2295 { 2296 sharedBindConnection.disconnect(); 2297 } catch (Exception e) {} 2298 } 2299 } 2300 2301 2302 2303 2309 public String [] getLoginInfo() 2310 { 2311 String [] loginInfo = new String [2]; 2312 2313 if (useDataFile) 2314 { 2315 int slot = (random.nextInt() & 0x7FFFFFFF) % loginIDs.length; 2316 loginInfo[0] = loginIDs[slot]; 2317 loginInfo[1] = loginPasswords[slot]; 2318 } 2319 else 2320 { 2321 if (useLoginIDRange) 2322 { 2323 int value; 2324 if (useSequential) 2325 { 2326 value = sequentialCounter++; 2327 if (sequentialCounter > loginIDMax) 2328 { 2329 sequentialCounter = loginIDMax; 2330 } 2331 } 2332 else 2333 { 2334 value = ((random.nextInt() & 0x7FFFFFFF) % loginIDSpan) + loginIDMin; 2335 } 2336 2337 loginInfo[0] = loginIDInitial + value + loginIDFinal; 2338 loginInfo[1] = loginPassword; 2339 } 2340 else 2341 { 2342 loginInfo[0] = loginIDInitial; 2343 loginInfo[1] = loginPassword; 2344 } 2345 } 2346 2347 return loginInfo; 2348 } 2349 2350 2351 2352 2359 public String getRandomString(int length) 2360 { 2361 char[] returnArray = new char[length]; 2362 2363 for (int i=0; i < returnArray.length; i++) 2364 { 2365 returnArray[i] = ALPHABET[Math.abs((random.nextInt()) & 0x7FFFFFFF) % 2366 ALPHABET.length]; 2367 } 2368 2369 return new String (returnArray); 2370 } 2371} 2372 2373 | Popular Tags |