1 16 package com.sun.slamd.example; 17 18 19 20 import java.io.*; 21 import java.security.*; 22 import java.util.*; 23 import netscape.ldap.*; 24 import netscape.ldap.controls.*; 25 import netscape.ldap.factory.*; 26 import com.sun.slamd.job.*; 27 import com.sun.slamd.parameter.*; 28 import com.sun.slamd.stat.*; 29 30 31 32 40 public class ModRateJobClass 41 extends JobClass 42 implements LDAPRebind 43 { 44 47 public static final String SSL_KEY_STORE_PROPERTY = 48 "javax.net.ssl.keyStore"; 49 50 51 52 55 public static final String SSL_KEY_PASSWORD_PROPERTY = 56 "javax.net.ssl.keyStorePassword"; 57 58 59 60 63 public static final String SSL_TRUST_STORE_PROPERTY = 64 "javax.net.ssl.trustStore"; 65 66 67 68 71 public static final String SSL_TRUST_PASSWORD_PROPERTY = 72 "javax.net.ssl.trustStorePassword"; 73 74 75 76 80 public static final String STAT_TRACKER_MOD_TIME = "Modify Time (ms)"; 81 82 83 84 88 public static final String STAT_TRACKER_MOD_COUNT = "Modifications Performed"; 89 90 91 92 96 public static final String STAT_TRACKER_MOD_TOTAL = "Total Modifications"; 97 98 99 100 104 public static final String STAT_TRACKER_EXCEPTIONS_CAUGHT = 105 "Exceptions Caught"; 106 107 108 109 112 public static final char[] ALPHABET = 113 "abcdefghijklmnopqrstuvwxyz".toCharArray(); 114 115 116 117 118 119 BooleanParameter blindTrustParameter = 121 new BooleanParameter("blind_trust", "Blindly Trust Any Certificate", 122 "Indicates whether the client should blindly trust " + 123 "any certificate presented by the server, or " + 124 "whether the key and trust stores should be used.", 125 true); 126 127 BooleanParameter disconnectParameter = 129 new BooleanParameter("disconnect", "Always Disconnect", 130 "Indicates whether to close the connection after " + 131 "each modification", false); 132 133 BooleanParameter followReferralsParameter = 135 new BooleanParameter("followreferrals", "Follow Referrals", 136 "Indicates whether to follow referrals received " + 137 "while making modifications", false); 138 139 BooleanParameter useSSLParameter = 141 new BooleanParameter("usessl", "Use SSL", 142 "Indicates whether SSL should be used for all " + 143 "communication with the directory server", false); 144 145 FileURLParameter dnURLParameter = 147 new FileURLParameter("dn_url", "DN File URL", 148 "The URL (FILE or HTTP) that specifies the " + 149 "DNs of the entries that may be modified.", null, 150 false); 151 152 IntegerParameter coolDownParameter = 154 new IntegerParameter("cool_down", "Cool Down Time", 155 "The time in seconds that the job should " + 156 "continue making modifications after ending " + 157 "statistics collection.", true, 0, true, 0, false, 158 0); 159 160 IntegerParameter delayParameter = 163 new IntegerParameter("delay", "Time Between Requests (ms)", 164 "Specifies the length of time in milliseconds " + 165 "each thread should wait between modify " + 166 "requests. Note that this delay will be " + 167 "between consecutive requests and not between " + 168 "the response of one operation and the request " + 169 "for the next. If a modify takes longer than " + 170 "this length of time, then there will be no delay.", 171 true, 0, true, 0, false, 0); 172 173 IntegerParameter iterationsParameter = 176 new IntegerParameter("iterations", "Number of Iterations", 177 "The number of modifications that should be " + 178 "performed by each thread", false, -1); 179 180 IntegerParameter lengthParameter = 183 new IntegerParameter("length", "Value Length", 184 "The length that should be used for the new " + 185 "value of the modified attribute.", true, 80, 186 true, 1, false, 0); 187 188 IntegerParameter portParameter = 190 new IntegerParameter("ldapport", "Directory Server Port", 191 "The port number for the LDAP directory server", 192 true, 389, true, 1, true, 65535); 193 194 IntegerParameter timeLimitParameter = 196 new IntegerParameter("time_limit", "Modify Time Limit", 197 "The maximum length of time in seconds that the " + 198 "thread should wait for a modify operation to be " + 199 "performed before cancelling it and trying " + 200 "another.", false, 0, true, 0, false, 0); 201 202 IntegerParameter warmUpParameter = 204 new IntegerParameter("warm_up", "Warm Up Time", 205 "The time in seconds that the job should " + 206 "modify before beginning statistics collection.", 207 true, 0, true, 0, false, 0); 208 209 MultiLineTextParameter attributeParameter = 211 new MultiLineTextParameter("attribute", "Attribute(s) to Modify", 212 "The set of attribute to modify in the " + 213 "entry. If multiple attributes are to be " + 214 "modified, then a separate attribute " + 215 "should be listed per line. Each will be " + 216 "given the same value.", 217 new String [] { "description" }, true); 218 219 PlaceholderParameter placeholder = new PlaceholderParameter(); 221 222 StringParameter bindDNParameter = 224 new StringParameter("binddn", "Bind DN", 225 "The DN to use to bind to the server", false, ""); 226 227 StringParameter entryDNParameter = 229 new StringParameter("entrydn", "Entry DN", 230 "The DN of the entry to modify", false, ""); 231 232 StringParameter hostParameter = 234 new StringParameter("ldaphost", "Directory Server Host", 235 "The DNS hostname or IP address of the LDAP " + 236 "directory server", true, ""); 237 238 StringParameter proxyAsDNParameter = 240 new StringParameter("proxy_as_dn", "Proxy As DN", 241 "The DN of the user whose credentials should be " + 242 "used to perform the modification through the use " + 243 "of the proxied authorization control.", false, ""); 244 245 StringParameter keyStoreParameter = 247 new StringParameter("sslkeystore", "SSL Key Store", 248 "The path to the JSSE key store to use for an " + 249 "SSL-based connection", false, ""); 250 251 StringParameter trustStoreParameter = 253 new StringParameter("ssltruststore", "SSL Trust Store", 254 "The path to the JSSE trust store to use for an " + 255 "SSL-based connection", false, ""); 256 257 PasswordParameter bindPWParameter = 259 new PasswordParameter("bindpw", "Bind Password", 260 "The password for the bind DN", false, ""); 261 262 PasswordParameter keyPWParameter = 264 new PasswordParameter("sslkeypw", "SSL Key Store Password", 265 "The password for the JSSE key store", false, ""); 266 267 PasswordParameter trustPWParameter = 269 new PasswordParameter("ssltrustpw", "SSL Trust Store Password", 270 "The password for the JSSE trust store", false, ""); 271 272 273 static boolean alwaysDisconnect; 275 static boolean blindTrust; 276 static boolean followReferrals; 277 static boolean useDNFile; 278 static boolean useDNRange; 279 static boolean useProxyAuth; 280 static boolean useSequential; 281 static boolean useSSL; 282 static int coolDownTime; 283 static int dnRangeMax; 284 static int dnRangeMin; 285 static int dnRangeSpan; 286 static int iterations; 287 static int ldapPort; 288 static int length; 289 static int sequentialCounter; 290 static int timeLimit; 291 static int warmUpTime; 292 static long delay; 293 static String bindDN; 294 static String bindPassword; 295 static String dnInitial; 296 static String dnFinal; 297 static String ldapHost; 298 static String proxyAsDN; 299 static String sslKeyStore; 300 static String sslKeyPassword; 301 static String sslTrustStore; 302 static String sslTrustPassword; 303 static String [] modifyAttrs; 304 static String [] modifyDNs; 305 306 307 LDAPConnection conn; 309 310 311 AccumulatingTracker totalMods; 313 IncrementalTracker exceptionsCaught; 314 IncrementalTracker modCount; 315 TimeTracker modTime; 316 317 318 static Random parentRandom; 321 Random random; 322 323 324 325 326 332 public ModRateJobClass() 333 { 334 super(); 335 } 336 337 338 339 344 public String getJobName() 345 { 346 return "LDAP ModRate"; 347 } 348 349 350 351 356 public String getJobDescription() 357 { 358 return "This job can be used to perform repeated modifications against " + 359 "an LDAP directory server to generate load and measure performance"; 360 } 361 362 363 364 370 public String getJobCategoryName() 371 { 372 return "LDAP"; 373 } 374 375 376 377 384 public ParameterList getParameterStubs() 385 { 386 Parameter[] parameters = new Parameter[] 387 { 388 placeholder, 389 hostParameter, 390 portParameter, 391 bindDNParameter, 392 bindPWParameter, 393 proxyAsDNParameter, 394 placeholder, 395 entryDNParameter, 396 dnURLParameter, 397 attributeParameter, 398 lengthParameter, 399 placeholder, 400 warmUpParameter, 401 coolDownParameter, 402 timeLimitParameter, 403 delayParameter, 404 placeholder, 405 useSSLParameter, 406 blindTrustParameter, 407 keyStoreParameter, 408 keyPWParameter, 409 trustStoreParameter, 410 trustPWParameter, 411 placeholder, 412 iterationsParameter, 413 disconnectParameter, 414 followReferralsParameter 415 }; 416 417 return new ParameterList(parameters); 418 } 419 420 421 422 444 public StatTracker[] getStatTrackerStubs(String clientID, String threadID, 445 int collectionInterval) 446 { 447 return new StatTracker[] 448 { 449 new IncrementalTracker(clientID, threadID, STAT_TRACKER_MOD_COUNT, 450 collectionInterval), 451 new TimeTracker(clientID, threadID, STAT_TRACKER_MOD_TIME, 452 collectionInterval), 453 new IncrementalTracker(clientID, threadID, STAT_TRACKER_EXCEPTIONS_CAUGHT, 454 collectionInterval) 455 }; 456 } 457 458 459 460 465 public StatTracker[] getStatTrackers() 466 { 467 return new StatTracker[] 468 { 469 modCount, 470 modTime, 471 exceptionsCaught, 472 totalMods 473 }; 474 } 475 476 477 478 500 public void validateJobInfo(int numClients, int threadsPerClient, 501 int threadStartupDelay, Date startTime, 502 Date stopTime, int duration, 503 int collectionInterval, ParameterList parameters) 504 throws InvalidValueException 505 { 506 StringParameter dnParameter = 507 parameters.getStringParameter(entryDNParameter.getName()); 508 FileURLParameter dnFileParameter = 509 parameters.getFileURLParameter(dnURLParameter.getName()); 510 if (((dnParameter == null) || (! dnParameter.hasValue())) && 511 ((dnFileParameter == null) || (! dnFileParameter.hasValue()))) 512 { 513 throw new InvalidValueException("Either a single entry DN or a DN file " + 514 "URL must be specified."); 515 } 516 } 517 518 519 520 528 public boolean providesParameterTest() 529 { 530 return true; 531 } 532 533 534 535 562 public boolean testJobParameters(ParameterList parameters, 563 ArrayList outputMessages) 564 { 565 StringParameter hostParam = 567 parameters.getStringParameter(hostParameter.getName()); 568 if ((hostParam == null) || (! hostParam.hasValue())) 569 { 570 outputMessages.add("ERROR: No directory server address was provided."); 571 return false; 572 } 573 String host = hostParam.getStringValue(); 574 575 576 IntegerParameter portParam = 577 parameters.getIntegerParameter(portParameter.getName()); 578 if ((portParam == null) || (! hostParam.hasValue())) 579 { 580 outputMessages.add("ERROR: No directory server port was provided."); 581 return false; 582 } 583 int port = portParam.getIntValue(); 584 585 586 boolean useSSL = false; 587 BooleanParameter useSSLParam = 588 parameters.getBooleanParameter(useSSLParameter.getName()); 589 if (useSSLParam != null) 590 { 591 useSSL = useSSLParam.getBooleanValue(); 592 } 593 594 595 boolean blindTrust = true; 596 BooleanParameter blindTrustParam = 597 parameters.getBooleanParameter(blindTrustParameter.getName()); 598 if (blindTrustParam != null) 599 { 600 blindTrust = blindTrustParam.getBooleanValue(); 601 } 602 603 604 String keyStore = null; 605 StringParameter keyStoreParam = 606 parameters.getStringParameter(keyStoreParameter.getName()); 607 if ((keyStoreParam != null) && keyStoreParam.hasValue()) 608 { 609 keyStore = keyStoreParam.getStringValue(); 610 File keyStoreFile = new File(keyStore); 611 if (useSSL && (! blindTrust) && (! keyStoreFile.exists())) 612 { 613 outputMessages.add("WARNING: Key store file \"" + keyStore + 614 "\" not found on SLAMD server system. This test " + 615 "will blindly trust any SSL certificate " + 616 "presented by the directory server."); 617 outputMessages.add(""); 618 blindTrust = true; 619 } 620 else 621 { 622 System.setProperty(SSL_KEY_STORE_PROPERTY, keyStore); 623 } 624 } 625 626 627 String keyStorePassword = ""; 628 StringParameter keyPassParam = 629 parameters.getStringParameter(keyPWParameter.getName()); 630 if ((keyPassParam != null) && keyPassParam.hasValue()) 631 { 632 keyStorePassword = keyPassParam.getStringValue(); 633 System.setProperty(SSL_KEY_PASSWORD_PROPERTY, keyStorePassword); 634 } 635 636 637 String trustStore = null; 638 StringParameter trustStoreParam = 639 parameters.getStringParameter(trustStoreParameter.getName()); 640 if ((trustStoreParam != null) && trustStoreParam.hasValue()) 641 { 642 trustStore = trustStoreParam.getStringValue(); 643 File trustStoreFile = new File(trustStore); 644 if (useSSL && (! blindTrust) && (! trustStoreFile.exists())) 645 { 646 outputMessages.add("WARNING: trust store file \"" + trustStore + 647 "\" not found on SLAMD server system. This test " + 648 "will blindly trust any SSL certificate " + 649 "presented by the directory server."); 650 outputMessages.add(""); 651 blindTrust = true; 652 } 653 else 654 { 655 System.setProperty(SSL_TRUST_STORE_PROPERTY, trustStore); 656 } 657 } 658 659 660 String trustStorePassword = ""; 661 StringParameter trustPassParam = 662 parameters.getStringParameter(trustPWParameter.getName()); 663 if ((trustPassParam != null) && trustPassParam.hasValue()) 664 { 665 trustStorePassword = trustPassParam.getStringValue(); 666 System.setProperty(SSL_TRUST_PASSWORD_PROPERTY, trustStorePassword); 667 } 668 669 670 String bindDN = ""; 671 StringParameter bindDNParam = 672 parameters.getStringParameter(bindDNParameter.getName()); 673 if ((bindDNParam != null) && bindDNParam.hasValue()) 674 { 675 bindDN = bindDNParam.getStringValue(); 676 } 677 678 679 String bindPassword = ""; 680 PasswordParameter bindPWParam = 681 parameters.getPasswordParameter(bindPWParameter.getName()); 682 if ((bindPWParam != null) && bindPWParam.hasValue()) 683 { 684 bindPassword = bindPWParam.getStringValue(); 685 } 686 687 688 String proxyAsDN = null; 689 StringParameter proxyAsDNParam = 690 parameters.getStringParameter(proxyAsDNParameter.getName()); 691 if ((proxyAsDNParam != null) && proxyAsDNParam.hasValue()) 692 { 693 proxyAsDN = proxyAsDNParam.getStringValue(); 694 } 695 696 697 LDAPConnection conn; 700 if (useSSL) 701 { 702 if (blindTrust) 703 { 704 try 705 { 706 conn = new LDAPConnection(new JSSEBlindTrustSocketFactory()); 707 } 708 catch (Exception e) 709 { 710 outputMessages.add("ERROR: Unable to instantiate the blind trust " + 711 "socket factory for use in creating the SSL " + 712 "connection: " + stackTraceToString(e)); 713 return false; 714 } 715 } 716 else 717 { 718 conn = new LDAPConnection(new JSSESocketFactory(null)); 719 } 720 } 721 else 722 { 723 conn = new LDAPConnection(); 724 } 725 726 727 try 729 { 730 if (useSSL) 731 { 732 outputMessages.add("Attempting to establish an SSL-based connection " + 733 "to " + host + ":" + port + "...."); 734 } 735 else 736 { 737 outputMessages.add("Attempting to establish a connection to " + host + 738 ":" + port + "...."); 739 } 740 conn.connect(host, port); 741 outputMessages.add("Connected successfully."); 742 outputMessages.add(""); 743 } 744 catch (Exception e) 745 { 746 outputMessages.add("ERROR: Unable to connect to the directory " + 747 "server: " + stackTraceToString(e)); 748 return false; 749 } 750 751 752 try 754 { 755 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 756 "directory server with a DN of '" + bindDN + "'...."); 757 conn.bind(3, bindDN, bindPassword); 758 outputMessages.add("Bound successfully."); 759 outputMessages.add(""); 760 } 761 catch (Exception e) 762 { 763 try 764 { 765 conn.disconnect(); 766 } catch (Exception e2) {} 767 768 outputMessages.add("ERROR: Unable to bind to the directory server: " + 769 stackTraceToString(e)); 770 return false; 771 } 772 773 774 if (proxyAsDN != null) 776 { 777 try 778 { 779 outputMessages.add("Checking to make sure that the proxied user '" + 780 proxyAsDN + "' exists in the directory...."); 781 LDAPEntry proxyUserEntry = conn.read(proxyAsDN, new String [] { "1.1" }); 782 if (proxyUserEntry == null) 783 { 784 try 785 { 786 conn.disconnect(); 787 } catch (Exception e2) {} 788 789 outputMessages.add("ERROR: Unable to retrieve the proxied user's " + 790 "entry."); 791 return false; 792 } 793 else 794 { 795 outputMessages.add("Successfully read the proxied user's entry."); 796 outputMessages.add(""); 797 } 798 } 799 catch (Exception e) 800 { 801 try 802 { 803 conn.disconnect(); 804 } catch (Exception e2) {} 805 806 outputMessages.add("ERROR: Unable to retrieve the proxied user's " + 807 "entry: " + stackTraceToString(e)); 808 return false; 809 } 810 } 811 812 813 try 816 { 817 conn.disconnect(); 818 } catch (Exception e) {} 819 820 outputMessages.add("All tests completed successfully."); 821 return true; 822 } 823 824 825 826 836 public void initializeClient(String clientID, ParameterList parameters) 837 throws UnableToRunException 838 { 839 ldapHost = null; 841 hostParameter = parameters.getStringParameter(hostParameter.getName()); 842 if (hostParameter != null) 843 { 844 ldapHost = hostParameter.getStringValue(); 845 } 846 847 ldapPort = 389; 849 portParameter = parameters.getIntegerParameter(portParameter.getName()); 850 if (portParameter != null) 851 { 852 ldapPort = portParameter.getIntValue(); 853 } 854 855 bindDN = ""; 857 bindDNParameter = parameters.getStringParameter(bindDNParameter.getName()); 858 if (bindDNParameter != null) 859 { 860 bindDN = bindDNParameter.getStringValue(); 861 } 862 863 bindPassword = ""; 865 bindPWParameter = 866 parameters.getPasswordParameter(bindPWParameter.getName()); 867 if (bindPWParameter != null) 868 { 869 bindPassword = bindPWParameter.getStringValue(); 870 } 871 872 useProxyAuth = false; 874 proxyAsDNParameter = 875 parameters.getStringParameter(proxyAsDNParameter.getName()); 876 if ((proxyAsDNParameter != null) && (proxyAsDNParameter.hasValue())) 877 { 878 useProxyAuth = true; 879 proxyAsDN = proxyAsDNParameter.getStringValue(); 880 } 881 882 useDNFile = false; 884 entryDNParameter = 885 parameters.getStringParameter(entryDNParameter.getName()); 886 if (entryDNParameter != null) 887 { 888 String entryDN = entryDNParameter.getStringValue(); 889 useDNRange = true; 890 useSequential = false; 891 892 try 893 { 894 int openPos = entryDN.indexOf('['); 895 int dashPos = entryDN.indexOf('-', openPos); 896 if (dashPos < 0) 897 { 898 dashPos = entryDN.indexOf(':', openPos); 899 useSequential = true; 900 } 901 int closePos = entryDN.indexOf(']', dashPos); 902 903 dnInitial = entryDN.substring(0, openPos); 904 dnFinal = entryDN.substring(closePos+1); 905 906 dnRangeMin = Integer.parseInt(entryDN.substring(openPos+1, dashPos)); 907 dnRangeMax = Integer.parseInt(entryDN.substring(dashPos+1, closePos)); 908 dnRangeSpan = dnRangeMax - dnRangeMin + 1; 909 sequentialCounter = dnRangeMin; 910 } 911 catch (Exception e) 912 { 913 useDNRange = false; 914 dnInitial = entryDN; 915 } 916 } 917 918 dnURLParameter = parameters.getFileURLParameter(dnURLParameter.getName()); 919 if ((dnURLParameter != null) && dnURLParameter.hasValue()) 920 { 921 try 922 { 923 useDNFile = true; 924 modifyDNs = dnURLParameter.getNonBlankFileLines(); 925 } 926 catch (Exception e) 927 { 928 throw new UnableToRunException("Could not retrieve the DNs of the " + 929 "entries to be modified.", e); 930 } 931 } 932 933 attributeParameter = 935 parameters.getMultiLineTextParameter(attributeParameter.getName()); 936 if (attributeParameter != null) 937 { 938 modifyAttrs = attributeParameter.getNonBlankLines(); 939 } 940 941 length = 80; 943 lengthParameter = parameters.getIntegerParameter(lengthParameter.getName()); 944 if (lengthParameter != null) 945 { 946 length = lengthParameter.getIntValue(); 947 } 948 949 warmUpTime = 0; 951 warmUpParameter = parameters.getIntegerParameter(warmUpParameter.getName()); 952 if (warmUpParameter != null) 953 { 954 warmUpTime = warmUpParameter.getIntValue(); 955 } 956 957 coolDownTime = 0; 959 coolDownParameter = 960 parameters.getIntegerParameter(coolDownParameter.getName()); 961 if (coolDownParameter != null) 962 { 963 coolDownTime = coolDownParameter.getIntValue(); 964 } 965 966 timeLimit = 0; 968 timeLimitParameter = 969 parameters.getIntegerParameter(timeLimitParameter.getName()); 970 if (timeLimitParameter != null) 971 { 972 timeLimit = timeLimitParameter.getIntValue(); 973 } 974 975 delay = 0; 977 delayParameter = parameters.getIntegerParameter(delayParameter.getName()); 978 if (delayParameter != null) 979 { 980 delay = delayParameter.getIntValue(); 981 } 982 983 iterations = -1; 985 iterationsParameter = 986 parameters.getIntegerParameter(iterationsParameter.getName()); 987 if (iterationsParameter != null) 988 { 989 iterations = iterationsParameter.getIntValue(); 990 } 991 992 useSSL = false; 994 useSSLParameter = parameters.getBooleanParameter(useSSLParameter.getName()); 995 if (useSSLParameter != null) 996 { 997 useSSL = useSSLParameter.getBooleanValue(); 998 } 999 1000 if (useSSL) 1002 { 1003 blindTrustParameter = 1005 parameters.getBooleanParameter(blindTrustParameter.getName()); 1006 if (blindTrustParameter != null) 1007 { 1008 blindTrust = blindTrustParameter.getBooleanValue(); 1009 } 1010 1011 sslKeyStore = null; 1013 keyStoreParameter = 1014 parameters.getStringParameter(keyStoreParameter.getName()); 1015 if ((keyStoreParameter != null) && (keyStoreParameter.hasValue())) 1016 { 1017 sslKeyStore = keyStoreParameter.getStringValue(); 1018 System.setProperty(SSL_KEY_STORE_PROPERTY, sslKeyStore); 1019 } 1020 1021 sslKeyPassword = null; 1023 keyPWParameter = 1024 parameters.getPasswordParameter(keyPWParameter.getName()); 1025 if ((keyPWParameter != null) && (keyPWParameter.hasValue())) 1026 { 1027 sslKeyPassword = keyPWParameter.getStringValue(); 1028 System.setProperty(SSL_KEY_PASSWORD_PROPERTY, sslKeyPassword); 1029 } 1030 1031 sslTrustStore = null; 1033 trustStoreParameter = 1034 parameters.getStringParameter(trustStoreParameter.getName()); 1035 if ((trustStoreParameter != null) && (trustStoreParameter.hasValue())) 1036 { 1037 sslTrustStore = trustStoreParameter.getStringValue(); 1038 System.setProperty(SSL_TRUST_STORE_PROPERTY, sslTrustStore); 1039 } 1040 1041 sslTrustPassword = null; 1043 trustPWParameter = 1044 parameters.getPasswordParameter(trustPWParameter.getName()); 1045 if ((trustPWParameter != null) && (trustPWParameter.hasValue())) 1046 { 1047 sslTrustPassword = trustPWParameter.getStringValue(); 1048 System.setProperty(SSL_TRUST_PASSWORD_PROPERTY, sslTrustPassword); 1049 } 1050 } 1051 1052 alwaysDisconnect = false; 1054 disconnectParameter = 1055 parameters.getBooleanParameter(disconnectParameter.getName()); 1056 if (disconnectParameter != null) 1057 { 1058 alwaysDisconnect = disconnectParameter.getBooleanValue(); 1059 } 1060 1061 followReferrals = false; 1063 followReferralsParameter = 1064 parameters.getBooleanParameter(followReferralsParameter.getName()); 1065 if (followReferralsParameter != null) 1066 { 1067 followReferrals = followReferralsParameter.getBooleanValue(); 1068 } 1069 1070 1071 parentRandom = new Random(); 1073 } 1074 1075 1076 1077 1093 public void initializeThread(String clientID, String threadID, 1094 int collectionInterval, ParameterList parameters) 1095 throws UnableToRunException 1096 { 1097 modCount = new IncrementalTracker(clientID, threadID, 1099 STAT_TRACKER_MOD_COUNT, 1100 collectionInterval); 1101 exceptionsCaught = new IncrementalTracker(clientID, threadID, 1102 STAT_TRACKER_EXCEPTIONS_CAUGHT, 1103 collectionInterval); 1104 modTime = new TimeTracker(clientID, threadID, STAT_TRACKER_MOD_TIME, 1105 collectionInterval); 1106 totalMods = new AccumulatingTracker(clientID, threadID, 1107 STAT_TRACKER_MOD_TOTAL, 1108 collectionInterval); 1109 1110 1111 RealTimeStatReporter statReporter = getStatReporter(); 1113 if (statReporter != null) 1114 { 1115 String jobID = getJobID(); 1116 modCount.enableRealTimeStats(statReporter, jobID); 1117 exceptionsCaught.enableRealTimeStats(statReporter, jobID); 1118 modTime.enableRealTimeStats(statReporter, jobID); 1119 totalMods.enableRealTimeStats(statReporter, jobID); 1120 } 1121 1122 1123 random = new Random(parentRandom.nextLong()); 1125 1126 1127 if (useSSL) 1135 { 1136 try 1137 { 1138 LDAPConnection conn; 1139 if (blindTrust) 1140 { 1141 conn = new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1142 } 1143 else 1144 { 1145 conn = new LDAPConnection(new JSSESocketFactory(null)); 1146 } 1147 conn.connect(3, ldapHost, ldapPort, bindDN, bindPassword); 1148 conn.disconnect(); 1149 } 1150 catch (Exception e) {} 1151 } 1152 } 1153 1154 1155 1156 1163 public void runJob() 1164 { 1165 long currentTime = System.currentTimeMillis(); 1167 boolean collectingStats = false; 1168 long startCollectingTime = currentTime + (1000 * warmUpTime); 1169 long stopCollectingTime = Long.MAX_VALUE; 1170 if ((coolDownTime > 0) && (getShouldStopTime() > 0)) 1171 { 1172 stopCollectingTime = getShouldStopTime() - (1000 * coolDownTime); 1173 } 1174 1175 boolean connected = false; 1178 1179 long modStartTime = 0; 1182 1183 boolean infinite = (iterations <= 0); 1186 1187 if (useSSL) 1189 { 1190 if (blindTrust) 1191 { 1192 try 1193 { 1194 conn = new LDAPConnection(new JSSEBlindTrustSocketFactory()); 1195 } 1196 catch (LDAPException le) 1197 { 1198 logMessage(le.getMessage()); 1199 indicateStoppedDueToError(); 1200 return; 1201 } 1202 } 1203 else 1204 { 1205 conn = new LDAPConnection(new JSSESocketFactory(null)); 1206 } 1207 } 1208 else 1209 { 1210 conn = new LDAPConnection(); 1211 } 1212 1213 1214 for (int i=0; ((! shouldStop()) && ((infinite || (i < iterations)))); i++) 1216 { 1217 currentTime = System.currentTimeMillis(); 1218 if ((! collectingStats) && (currentTime >= startCollectingTime) && 1219 (currentTime < stopCollectingTime)) 1220 { 1221 modCount.startTracker(); 1223 exceptionsCaught.startTracker(); 1224 modTime.startTracker(); 1225 totalMods.startTracker(); 1226 collectingStats = true; 1227 } 1228 else if ((collectingStats) && (currentTime >= stopCollectingTime)) 1229 { 1230 modCount.stopTracker(); 1231 exceptionsCaught.stopTracker(); 1232 modTime.stopTracker(); 1233 totalMods.stopTracker(); 1234 collectingStats = false; 1235 } 1236 1237 if (! connected) 1239 { 1240 try 1241 { 1242 conn.connect(3, ldapHost, ldapPort, bindDN, bindPassword); 1243 connected = true; 1244 } 1245 catch (LDAPException le) 1246 { 1247 logMessage("ERROR -- Could not connect to " + ldapHost + ":" + 1248 ldapPort + " (" + le + ") -- aborting thread"); 1249 if (collectingStats) 1250 { 1251 exceptionsCaught.increment(); 1252 } 1253 indicateStoppedDueToError(); 1254 break; 1255 } 1256 } 1257 1258 LDAPConstraints constraints = conn.getConstraints(); 1259 if (useProxyAuth) 1260 { 1261 LDAPProxiedAuthControl proxyAuthControl = 1262 new LDAPProxiedAuthControl(proxyAsDN, true); 1263 constraints.setServerControls(proxyAuthControl); 1264 } 1265 constraints.setTimeLimit(1000 * timeLimit); 1266 constraints.setReferrals(followReferrals); 1267 constraints.setRebindProc(this); 1268 1269 1270 boolean successfulMod = false; 1272 1273 1274 if (collectingStats) 1276 { 1277 modTime.startTimer(); 1278 } 1279 if (delay > 0) 1280 { 1281 modStartTime = System.currentTimeMillis(); 1282 } 1283 1284 1285 try 1287 { 1288 String attrValue = getRandomString(length); 1289 LDAPModification[] mods = new LDAPModification[modifyAttrs.length]; 1290 for (int j=0; j < modifyAttrs.length; j++) 1291 { 1292 LDAPAttribute attr = new LDAPAttribute(modifyAttrs[j], attrValue); 1293 mods[j] = new LDAPModification(LDAPModification.REPLACE, attr); 1294 } 1295 conn.modify(getRandomEntryDN(), mods, constraints); 1296 successfulMod = true; 1297 } 1298 catch (LDAPException le) 1299 { 1300 writeVerbose("ERROR while performing modification -- " + le); 1301 if (collectingStats) 1302 { 1303 exceptionsCaught.increment(); 1304 } 1305 indicateCompletedWithErrors(); 1306 } 1307 1308 1309 if (collectingStats) 1311 { 1312 modTime.stopTimer(); 1313 } 1314 1315 1316 if (successfulMod && collectingStats) 1318 { 1319 modCount.increment(); 1320 totalMods.increment(); 1321 } 1322 1323 if (alwaysDisconnect) 1325 { 1326 try 1327 { 1328 conn.disconnect(); 1329 } catch (LDAPException le) {} 1330 connected = false; 1331 } 1332 1333 if ((delay > 0) && (! shouldStop())) 1335 { 1336 long now = System.currentTimeMillis(); 1337 long sleepTime = delay - (now - modStartTime); 1338 if (sleepTime > 0) 1339 { 1340 try 1341 { 1342 Thread.sleep(sleepTime); 1343 } catch (InterruptedException ie) {} 1344 } 1345 } 1346 } 1347 1348 1349 try 1351 { 1352 conn.disconnect(); 1353 } catch (LDAPException le) {} 1354 1355 1356 if (collectingStats) 1358 { 1359 modCount.stopTracker(); 1360 exceptionsCaught.stopTracker(); 1361 modTime.stopTracker(); 1362 totalMods.stopTracker(); 1363 } 1364 } 1365 1366 1367 1368 1372 public void destroy() 1373 { 1374 if (conn != null) 1375 { 1376 try 1377 { 1378 conn.disconnect(); 1379 } catch (Exception e) {} 1380 1381 conn = null; 1382 } 1383 } 1384 1385 1386 1387 1398 public LDAPRebindAuth getRebindAuthentication(String host, int port) 1399 { 1400 return new LDAPRebindAuth(bindDN, bindPassword); 1401 } 1402 1403 1404 1405 1410 public String getRandomEntryDN() 1411 { 1412 if (useDNFile) 1413 { 1414 return modifyDNs[(random.nextInt() & 0x7FFFFFFF) % modifyDNs.length]; 1415 } 1416 else 1417 { 1418 if (useDNRange) 1419 { 1420 int value; 1421 if (useSequential) 1422 { 1423 value = sequentialCounter++; 1424 if (sequentialCounter > dnRangeMax) 1425 { 1426 sequentialCounter = dnRangeMin; 1427 } 1428 } 1429 else 1430 { 1431 value = ((random.nextInt() & 0x7FFFFFFF) % dnRangeSpan) + dnRangeMin; 1432 } 1433 return dnInitial + value + dnFinal; 1434 } 1435 else 1436 { 1437 return dnInitial; 1438 } 1439 } 1440 } 1441 1442 1443 1444 1453 public String getRandomString(int length) 1454 { 1455 char[] returnChars = new char[length]; 1456 1457 for (int i=0; i < length; i++) 1458 { 1459 returnChars[i] = ALPHABET[Math.abs((random.nextInt()) & 0x7FFFFFFF) % 1460 ALPHABET.length]; 1461 } 1462 1463 return new String (returnChars); 1464 } 1465} 1466 1467 | Popular Tags |