1 16 package com.sun.slamd.example; 17 18 19 20 import java.util.*; 21 import netscape.ldap.*; 22 import netscape.ldap.controls.*; 23 import com.sun.slamd.job.*; 24 import com.sun.slamd.parameter.*; 25 import com.sun.slamd.stat.*; 26 27 28 29 37 public class DelRateWithReplicaLatencyJobClass 38 extends ReplicaLatencyCheckJobClass 39 { 40 44 public static final String STAT_TRACKER_DELETE_TIME = "Delete Time (ms)"; 45 46 47 48 52 public static final String STAT_TRACKER_DELETE_COUNT = "Deletes Performed"; 53 54 55 56 60 public static final String STAT_TRACKER_RESULT_CODES = "Result Codes"; 61 62 63 64 68 public static final String STAT_TRACKER_REPLICA_LATENCY = 69 "Replication Latency (ms)"; 70 71 72 73 77 public static final String STAT_TRACKER_CATEGORIZED_LATENCY = 78 "Categorized Latency"; 79 80 81 82 85 public static final char[] ALPHABET = 86 "abcdefghijklmnopqrstuvwxyz".toCharArray(); 87 88 89 90 BooleanParameter disconnectParameter = 92 new BooleanParameter("disconnect", "Always Disconnect", 93 "Indicates whether to close the connection after " + 94 "each delete.", false); 95 96 FileURLParameter dnFileParameter = 98 new FileURLParameter("dn_file", "DN File URL", 99 "The URL (FILE or HTTP) to the file containing " + 100 "DNs of the entries to be deleted.", null, false); 101 102 IntegerParameter coolDownParameter = 104 new IntegerParameter("cool_down", "Cool Down Time", 105 "The time in seconds that the job should " + 106 "continue deleting after ending statistics " + 107 "collection.", true, 0, true, 0, false, 0); 108 109 IntegerParameter delayParameter = 112 new IntegerParameter("delay", "Time Between Requests (ms)", 113 "Specifies the length of time in milliseconds " + 114 "each thread should wait between delete " + 115 "requests. Note that this delay will be " + 116 "between consecutive requests and not between " + 117 "the response of one operation and the request " + 118 "for the next. If an delete takes longer than " + 119 "this length of time, then there will be no delay.", 120 true, 0, true, 0, false, 0); 121 122 IntegerParameter replicaDelayParameter = 125 new IntegerParameter("latency_delay", "Time Between Latency Checks (ms)", 126 "Specifies the minimum length of time in " + 127 "milliseconds that should pass between latency " + 128 "checks. If a replicated operation takes longer " + 129 "than this length of time, then there will be no " + 130 "delay.", true, 0, true, 0, false, 0); 131 132 IntegerParameter masterPortParameter = 134 new IntegerParameter("masterport", "Master Directory Port", 135 "The port number for the master directory server", 136 true, 389, true, 1, true, 65535); 137 138 IntegerParameter replicaPortParameter = 140 new IntegerParameter("replicaport", "Replica Directory Port", 141 "The port number for the replica directory server", 142 true, 389, true, 1, true, 65535); 143 144 IntegerParameter timeLimitParameter = 146 new IntegerParameter("time_limit", "Delete Time Limit", 147 "The maximum length of time in seconds that the " + 148 "thread should wait for a delete operation to be " + 149 "performed before cancelling it and trying " + 150 "another.", false, 0, true, 0, false, 0); 151 152 IntegerParameter warmUpParameter = 154 new IntegerParameter("warm_up", "Warm Up Time", 155 "The time in seconds that the job should " + 156 "delete before beginning statistics collection.", 157 true, 0, true, 0, false, 0); 158 159 PlaceholderParameter placeholder = new PlaceholderParameter(); 161 162 StringParameter attributeParameter = 164 new StringParameter("attribute", "Attribute to Modify", 165 "The attribute to modify for the latency checks", 166 true, "description"); 167 168 StringParameter bindDNParameter = 170 new StringParameter("binddn", "Bind DN", 171 "The DN to use to bind to the server", false, ""); 172 173 StringParameter entryDNParameter = 175 new StringParameter("entrydn", "Entry DN Pattern", 176 "The pattern that specifies the DNs of the " + 177 "entries to be deleted. It may contain a " + 178 "numeric range in brackets with the minimum and " + 179 "maximum value separated by colons.", false, ""); 180 181 StringParameter masterHostParameter = 183 new StringParameter("masterhost", "Master Directory Host", 184 "The DNS hostname or IP address of the master " + 185 "directory server", true, ""); 186 187 StringParameter replicaHostParameter = 189 new StringParameter("replicahost", "Replica Directory Host", 190 "The DNS hostname or IP address of the replica " + 191 "directory server", true, ""); 192 193 StringParameter replicaEntryDNParameter = 196 new StringParameter("replica_entry_dn", "Latency Check Entry DN", 197 "The DN of the entry that should be periodically " + 198 "modified to measure the latency of replication. " + 199 "Note that this DN must not be the same as " + 200 "the DN of any of the entries to modify, nor " + 201 "should this entry be modified by any external " + 202 "process during the test.", true, ""); 203 204 StringParameter proxyAsDNParameter = 206 new StringParameter("proxy_as_dn", "Proxy As DN", 207 "The DN of the user whose credentials should be " + 208 "used to perform the adds through the use " + 209 "of the proxied authorization control.", false, ""); 210 211 PasswordParameter bindPWParameter = 213 new PasswordParameter("bindpw", "Bind Password", 214 "The password for the bind DN", false, ""); 215 216 217 static boolean alwaysDisconnect; 219 static boolean useProxyAuth; 220 static int coolDownTime; 221 static int dnMax; 222 static int dnMin; 223 static int latencyDelay; 224 static int masterPort; 225 static int replicaPort; 226 static int nextValue; 227 static int timeLimit; 228 static int warmUpTime; 229 static long delay; 230 static String attribute; 231 static String bindDN; 232 static String bindPassword; 233 static String dnInitial; 234 static String dnFinal; 235 static String masterHost; 236 static String replicaHost; 237 static String replicaEntryDN; 238 static String proxyAsDN; 239 static String [] entryDNs; 240 241 242 LDAPConnection conn; 244 245 246 CategoricalTracker resultCodes; 248 IncrementalTracker deleteCount; 249 TimeTracker deleteTime; 250 251 252 static boolean latencyTrackerChosen; 254 boolean reportLatencyTracker; 255 LatencyCheckMasterThread masterThread; 256 LatencyCheckReplicaThread replicaThread; 257 258 259 static Random parentRandom; 262 Random random; 263 264 265 266 267 273 public DelRateWithReplicaLatencyJobClass() 274 { 275 super(); 276 } 277 278 279 280 285 public String getJobName() 286 { 287 return "LDAP DelRate with Replica Latency"; 288 } 289 290 291 292 297 public String getJobDescription() 298 { 299 return "This job can be used to perform repeated delete operations " + 300 "against an LDAP directory server to generate load and measure " + 301 "performance. It also provides the capability to measure the " + 302 "latency associated with replication while the deletes are in " + 303 "progress."; 304 } 305 306 307 308 314 public String getJobCategoryName() 315 { 316 return "LDAP"; 317 } 318 319 320 321 327 public int overrideNumClients() 328 { 329 return 1; 330 } 331 332 333 334 341 public ParameterList getParameterStubs() 342 { 343 Parameter[] parameters = new Parameter[] 344 { 345 placeholder, 346 masterHostParameter, 347 masterPortParameter, 348 bindDNParameter, 349 bindPWParameter, 350 proxyAsDNParameter, 351 placeholder, 352 dnFileParameter, 353 entryDNParameter, 354 placeholder, 355 replicaHostParameter, 356 replicaPortParameter, 357 replicaEntryDNParameter, 358 replicaDelayParameter, 359 attributeParameter, 360 placeholder, 361 warmUpParameter, 362 coolDownParameter, 363 timeLimitParameter, 364 delayParameter, 365 placeholder, 366 disconnectParameter 367 }; 368 369 return new ParameterList(parameters); 370 } 371 372 373 374 396 public StatTracker[] getStatTrackerStubs(String clientID, String threadID, 397 int collectionInterval) 398 { 399 return new StatTracker[] 400 { 401 new IncrementalTracker(clientID, threadID, STAT_TRACKER_DELETE_COUNT, 402 collectionInterval), 403 new TimeTracker(clientID, threadID, STAT_TRACKER_DELETE_TIME, 404 collectionInterval), 405 new CategoricalTracker(clientID, threadID, STAT_TRACKER_RESULT_CODES, 406 collectionInterval), 407 new TimeTracker(clientID, threadID, STAT_TRACKER_REPLICA_LATENCY, 408 collectionInterval), 409 new CategoricalTracker(clientID, threadID, 410 STAT_TRACKER_CATEGORIZED_LATENCY, 411 collectionInterval) 412 }; 413 } 414 415 416 417 422 public StatTracker[] getStatTrackers() 423 { 424 if (reportLatencyTracker) 425 { 426 return new StatTracker[] 427 { 428 deleteCount, 429 deleteTime, 430 resultCodes, 431 latencyTime, 432 latencyCategories 433 }; 434 } 435 else 436 { 437 return new StatTracker[] 438 { 439 deleteCount, 440 deleteTime, 441 resultCodes 442 }; 443 } 444 } 445 446 447 448 470 public void validateJobInfo(int numClients, int threadsPerClient, 471 int threadStartupDelay, Date startTime, 472 Date stopTime, int duration, 473 int collectionInterval, ParameterList parameters) 474 throws InvalidValueException 475 { 476 if (numClients != 1) 477 { 478 throw new InvalidValueException("A DelRate job may only run on a " + 479 "single client."); 480 } 481 482 FileURLParameter dnFileParam = 483 parameters.getFileURLParameter(dnFileParameter.getName()); 484 StringParameter dnParam = 485 parameters.getStringParameter(entryDNParameter.getName()); 486 487 if ((dnFileParam == null) || (! dnFileParam.hasValue())) 488 { 489 if ((dnParam == null) || (! dnParam.hasValue())) 490 { 491 throw new InvalidValueException("Either a DN file or a DN pattern " + 492 "must be specified."); 493 } 494 } 495 else if ((dnParam != null) && (dnParam.hasValue())) 496 { 497 throw new InvalidValueException("You may not specify both a DN file " + 498 "and a DN pattern."); 499 } 500 } 501 502 503 504 512 public boolean providesParameterTest() 513 { 514 return true; 515 } 516 517 518 519 546 public boolean testJobParameters(ParameterList parameters, 547 ArrayList outputMessages) 548 { 549 StringParameter masterHostParam = 551 parameters.getStringParameter(masterHostParameter.getName()); 552 if ((masterHostParam == null) || (! masterHostParam.hasValue())) 553 { 554 outputMessages.add("ERROR: No master directory server address was " + 555 "provided."); 556 return false; 557 } 558 String masterHost = masterHostParam.getStringValue(); 559 560 561 IntegerParameter masterPortParam = 562 parameters.getIntegerParameter(masterPortParameter.getName()); 563 if ((masterPortParam == null) || (! masterPortParam.hasValue())) 564 { 565 outputMessages.add("ERROR: No master directory server port was " + 566 "provided."); 567 return false; 568 } 569 int masterPort = masterPortParam.getIntValue(); 570 571 572 StringParameter replicaHostParam = 573 parameters.getStringParameter(replicaHostParameter.getName()); 574 if ((replicaHostParam == null) || (! replicaHostParam.hasValue())) 575 { 576 outputMessages.add("ERROR: No replica directory server address was " + 577 "provided."); 578 return false; 579 } 580 String replicaHost = replicaHostParam.getStringValue(); 581 582 583 IntegerParameter replicaPortParam = 584 parameters.getIntegerParameter(replicaPortParameter.getName()); 585 if ((replicaPortParam == null) || (! replicaPortParam.hasValue())) 586 { 587 outputMessages.add("ERROR: No replica directory server port was " + 588 "provided."); 589 return false; 590 } 591 int replicaPort = replicaPortParam.getIntValue(); 592 593 594 String bindDN = ""; 595 StringParameter bindDNParam = 596 parameters.getStringParameter(bindDNParameter.getName()); 597 if ((bindDNParam != null) && bindDNParam.hasValue()) 598 { 599 bindDN = bindDNParam.getStringValue(); 600 } 601 602 603 String bindPassword = ""; 604 PasswordParameter bindPWParam = 605 parameters.getPasswordParameter(bindPWParameter.getName()); 606 if ((bindPWParam != null) && bindPWParam.hasValue()) 607 { 608 bindPassword = bindPWParam.getStringValue(); 609 } 610 611 612 String proxyAsDN = null; 613 StringParameter proxyAsDNParam = 614 parameters.getStringParameter(proxyAsDNParameter.getName()); 615 if ((proxyAsDNParam != null) && proxyAsDNParam.hasValue()) 616 { 617 proxyAsDN = proxyAsDNParam.getStringValue(); 618 } 619 620 621 StringParameter replicaEntryDNParam = 622 parameters.getStringParameter(replicaEntryDNParameter.getName()); 623 if ((replicaEntryDNParam == null) || (! replicaEntryDNParam.hasValue())) 624 { 625 outputMessages.add("ERROR: No replica check entry DN was provided."); 626 return false; 627 } 628 String replicaEntryDN = replicaEntryDNParam.getStringValue(); 629 630 631 LDAPConnection conn = new LDAPConnection(); 634 635 636 try 638 { 639 outputMessages.add("Attempting to establish a connection to master " + 640 masterHost + ":" + masterPort + "...."); 641 conn.connect(masterHost, masterPort); 642 outputMessages.add("Connected successfully."); 643 outputMessages.add(""); 644 } 645 catch (Exception e) 646 { 647 outputMessages.add("ERROR: Unable to connect to the master server: " + 648 stackTraceToString(e)); 649 return false; 650 } 651 652 653 try 655 { 656 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 657 "master server with a DN of '" + bindDN + "'...."); 658 conn.bind(3, bindDN, bindPassword); 659 outputMessages.add("Bound successfully."); 660 outputMessages.add(""); 661 } 662 catch (Exception e) 663 { 664 try 665 { 666 conn.disconnect(); 667 } catch (Exception e2) {} 668 669 outputMessages.add("ERROR: Unable to bind to the master server: " + 670 stackTraceToString(e)); 671 return false; 672 } 673 674 675 if (proxyAsDN != null) 677 { 678 try 679 { 680 outputMessages.add("Checking to make sure that the proxied user '" + 681 proxyAsDN + "' exists in the master...."); 682 LDAPEntry proxyUserEntry = conn.read(proxyAsDN, new String [] { "1.1" }); 683 if (proxyUserEntry == null) 684 { 685 try 686 { 687 conn.disconnect(); 688 } catch (Exception e2) {} 689 690 outputMessages.add("ERROR: Unable to retrieve the proxied user's " + 691 "entry."); 692 return false; 693 } 694 else 695 { 696 outputMessages.add("Successfully read the proxied user's entry."); 697 outputMessages.add(""); 698 } 699 } 700 catch (Exception e) 701 { 702 try 703 { 704 conn.disconnect(); 705 } catch (Exception e2) {} 706 707 outputMessages.add("ERROR: Unable to retrieve the proxied user's " + 708 "entry: " + stackTraceToString(e)); 709 return false; 710 } 711 } 712 713 714 try 716 { 717 outputMessages.add("Checking to make sure that the replica check " + 718 "entry '" + replicaEntryDN + 719 "' exists in the master...."); 720 LDAPEntry baseDNEntry = conn.read(replicaEntryDN, new String [] { "1.1" }); 721 if (baseDNEntry == null) 722 { 723 try 724 { 725 conn.disconnect(); 726 } catch (Exception e2) {} 727 728 outputMessages.add("ERROR: Unable to retrieve the replica check " + 729 "entry."); 730 return false; 731 } 732 else 733 { 734 outputMessages.add("Successfully read the replica check entry."); 735 outputMessages.add(""); 736 } 737 } 738 catch (Exception e) 739 { 740 try 741 { 742 conn.disconnect(); 743 } catch (Exception e2) {} 744 745 outputMessages.add("ERROR: Unable to retrieve the replica check " + 746 "entry: " + stackTraceToString(e)); 747 return false; 748 } 749 750 751 try 754 { 755 conn.disconnect(); 756 } catch (Exception e) {} 757 758 759 try 761 { 762 outputMessages.add("Attempting to establish a connection to replica " + 763 replicaHost + ":" + replicaPort + "...."); 764 conn.connect(replicaHost, replicaPort); 765 outputMessages.add("Connected successfully."); 766 outputMessages.add(""); 767 } 768 catch (Exception e) 769 { 770 outputMessages.add("ERROR: Unable to connect to the replica server: " + 771 stackTraceToString(e)); 772 return false; 773 } 774 775 776 try 778 { 779 outputMessages.add("Attempting to perform an LDAPv3 bind to the " + 780 "replica server with a DN of '" + bindDN + "'...."); 781 conn.bind(3, bindDN, bindPassword); 782 outputMessages.add("Bound successfully."); 783 outputMessages.add(""); 784 } 785 catch (Exception e) 786 { 787 try 788 { 789 conn.disconnect(); 790 } catch (Exception e2) {} 791 792 outputMessages.add("ERROR: Unable to bind to the replica server: " + 793 stackTraceToString(e)); 794 return false; 795 } 796 797 798 try 800 { 801 outputMessages.add("Checking to make sure that the replica check " + 802 "entry '" + replicaEntryDN + 803 "' exists in the replica...."); 804 LDAPEntry baseDNEntry = conn.read(replicaEntryDN, new String [] { "1.1" }); 805 if (baseDNEntry == null) 806 { 807 try 808 { 809 conn.disconnect(); 810 } catch (Exception e2) {} 811 812 outputMessages.add("ERROR: Unable to retrieve the replica check " + 813 "entry."); 814 return false; 815 } 816 else 817 { 818 outputMessages.add("Successfully read the replica check entry."); 819 outputMessages.add(""); 820 } 821 } 822 catch (Exception e) 823 { 824 try 825 { 826 conn.disconnect(); 827 } catch (Exception e2) {} 828 829 outputMessages.add("ERROR: Unable to retrieve the replica check " + 830 "entry: " + stackTraceToString(e)); 831 return false; 832 } 833 834 835 try 838 { 839 conn.disconnect(); 840 } catch (Exception e) {} 841 842 843 outputMessages.add("All tests completed successfully."); 844 return true; 845 } 846 847 848 849 859 public void initializeClient(String clientID, ParameterList parameters) 860 throws UnableToRunException 861 { 862 latencyTrackerChosen = false; 865 866 867 masterHost = null; 869 masterHostParameter = 870 parameters.getStringParameter(masterHostParameter.getName()); 871 if (masterHostParameter != null) 872 { 873 masterHost = masterHostParameter.getStringValue(); 874 } 875 876 masterPort = 389; 878 masterPortParameter = 879 parameters.getIntegerParameter(masterPortParameter.getName()); 880 if (masterPortParameter != null) 881 { 882 masterPort = masterPortParameter.getIntValue(); 883 } 884 885 replicaHost = null; 887 replicaHostParameter = 888 parameters.getStringParameter(replicaHostParameter.getName()); 889 if (replicaHostParameter != null) 890 { 891 replicaHost = replicaHostParameter.getStringValue(); 892 } 893 894 replicaPort = 389; 896 replicaPortParameter = 897 parameters.getIntegerParameter(replicaPortParameter.getName()); 898 if (replicaPortParameter != null) 899 { 900 replicaPort = replicaPortParameter.getIntValue(); 901 } 902 903 bindDN = ""; 905 bindDNParameter = parameters.getStringParameter(bindDNParameter.getName()); 906 if (bindDNParameter != null) 907 { 908 bindDN = bindDNParameter.getStringValue(); 909 } 910 911 bindPassword = ""; 913 bindPWParameter = 914 parameters.getPasswordParameter(bindPWParameter.getName()); 915 if (bindPWParameter != null) 916 { 917 bindPassword = bindPWParameter.getStringValue(); 918 } 919 920 useProxyAuth = false; 922 proxyAsDNParameter = 923 parameters.getStringParameter(proxyAsDNParameter.getName()); 924 if ((proxyAsDNParameter != null) && (proxyAsDNParameter.hasValue())) 925 { 926 useProxyAuth = true; 927 proxyAsDN = proxyAsDNParameter.getStringValue(); 928 } 929 930 entryDNs = null; 932 dnFileParameter = parameters.getFileURLParameter(dnFileParameter.getName()); 933 if ((dnFileParameter != null) && (dnFileParameter.hasValue())) 934 { 935 try 936 { 937 entryDNs = dnFileParameter.getNonBlankFileLines(); 938 nextValue = 0; 939 } 940 catch (Exception e) 941 { 942 throw new UnableToRunException("ERROR: Unable to retrieve DN file " + 943 "data: " + e, e); 944 } 945 } 946 947 dnInitial = null; 949 dnFinal = null; 950 dnMin = 0; 951 dnMax = Integer.MAX_VALUE; 952 entryDNParameter = 953 parameters.getStringParameter(entryDNParameter.getName()); 954 if ((entryDNParameter != null) && (entryDNParameter.hasValue())) 955 { 956 String dnStr = entryDNParameter.getStringValue(); 957 958 try 959 { 960 int openPos = dnStr.indexOf('['); 961 int colonPos = dnStr.indexOf(':', openPos); 962 int closePos = dnStr.indexOf(']', colonPos); 963 964 dnInitial = dnStr.substring(0, openPos); 965 dnFinal = dnStr.substring(closePos+1); 966 967 dnMin = Integer.parseInt(dnStr.substring(openPos+1, colonPos)); 968 dnMax = Integer.parseInt(dnStr.substring(colonPos+1, closePos)); 969 nextValue = dnMin; 970 } 971 catch (Exception e) 972 { 973 throw new UnableToRunException("ERROR: Unable to parse DN pattern: " + 974 e, e); 975 } 976 } 977 978 replicaEntryDN = null; 980 replicaEntryDNParameter = 981 parameters.getStringParameter(replicaEntryDNParameter.getName()); 982 if (replicaEntryDNParameter != null) 983 { 984 replicaEntryDN = replicaEntryDNParameter.getStringValue(); 985 } 986 987 latencyDelay = 0; 989 replicaDelayParameter = 990 parameters.getIntegerParameter(replicaDelayParameter.getName()); 991 if (replicaDelayParameter != null) 992 { 993 latencyDelay = replicaDelayParameter.getIntValue(); 994 } 995 996 attribute = null; 998 attributeParameter = 999 parameters.getStringParameter(attributeParameter.getName()); 1000 if (attributeParameter != null) 1001 { 1002 attribute = attributeParameter.getStringValue(); 1003 } 1004 1005 warmUpTime = 0; 1007 warmUpParameter = parameters.getIntegerParameter(warmUpParameter.getName()); 1008 if (warmUpParameter != null) 1009 { 1010 warmUpTime = warmUpParameter.getIntValue(); 1011 } 1012 1013 coolDownTime = 0; 1015 coolDownParameter = 1016 parameters.getIntegerParameter(coolDownParameter.getName()); 1017 if (coolDownParameter != null) 1018 { 1019 coolDownTime = coolDownParameter.getIntValue(); 1020 } 1021 1022 timeLimit = 0; 1024 timeLimitParameter = 1025 parameters.getIntegerParameter(timeLimitParameter.getName()); 1026 if (timeLimitParameter != null) 1027 { 1028 timeLimit = timeLimitParameter.getIntValue(); 1029 } 1030 1031 delay = 0; 1033 delayParameter = parameters.getIntegerParameter(delayParameter.getName()); 1034 if (delayParameter != null) 1035 { 1036 delay = delayParameter.getIntValue(); 1037 } 1038 1039 alwaysDisconnect = false; 1041 disconnectParameter = 1042 parameters.getBooleanParameter(disconnectParameter.getName()); 1043 if (disconnectParameter != null) 1044 { 1045 alwaysDisconnect = disconnectParameter.getBooleanValue(); 1046 } 1047 1048 1049 parentRandom = new Random(); 1051 } 1052 1053 1054 1055 1071 public void initializeThread(String clientID, String threadID, 1072 int collectionInterval, ParameterList parameters) 1073 throws UnableToRunException 1074 { 1075 deleteCount = new IncrementalTracker(clientID, threadID, 1077 STAT_TRACKER_DELETE_COUNT, 1078 collectionInterval); 1079 deleteTime = new TimeTracker(clientID, threadID, STAT_TRACKER_DELETE_TIME, 1080 collectionInterval); 1081 resultCodes = new CategoricalTracker(clientID, threadID, 1082 STAT_TRACKER_RESULT_CODES, 1083 collectionInterval); 1084 1085 1086 RealTimeStatReporter statReporter = getStatReporter(); 1088 if (statReporter != null) 1089 { 1090 String jobID = getJobID(); 1091 deleteCount.enableRealTimeStats(statReporter, jobID); 1092 deleteTime.enableRealTimeStats(statReporter, jobID); 1093 } 1094 1095 1096 random = new Random(parentRandom.nextLong()); 1098 1099 1100 if ((! latencyTrackerChosen) && (getClientNumber() == 0)) 1103 { 1104 latencyCheckMutex = new Object (); 1105 latencyTrackerChosen = true; 1106 reportLatencyTracker = true; 1107 1108 latencyTime = new TimeTracker(clientID, threadID, 1110 STAT_TRACKER_REPLICA_LATENCY, 1111 collectionInterval); 1112 if (statReporter != null) 1113 { 1114 latencyTime.enableRealTimeStats(statReporter, getJobID()); 1115 } 1116 1117 latencyCategories = 1119 new CategoricalTracker(clientID, threadID, 1120 STAT_TRACKER_CATEGORIZED_LATENCY, 1121 collectionInterval); 1122 1123 try 1125 { 1126 masterThread = 1127 new LatencyCheckMasterThread(this, masterHost, masterPort, bindDN, 1128 bindPassword, replicaEntryDN, 1129 attribute, latencyDelay); 1130 } 1131 catch (LDAPException le) 1132 { 1133 throw new UnableToRunException("Could not create the master latency " + 1134 "thread: " + le, le); 1135 } 1136 1137 try 1139 { 1140 replicaThread = 1141 new LatencyCheckReplicaThread(this, replicaHost, replicaPort, 1142 bindDN, bindPassword, 1143 replicaEntryDN); 1144 } 1145 catch (LDAPException le) 1146 { 1147 throw new UnableToRunException("Could not create the replica latency " + 1148 "thread: " + le, le); 1149 } 1150 1151 masterThread.start(); 1153 replicaThread.start(); 1154 } 1155 else 1156 { 1157 reportLatencyTracker = false; 1158 } 1159 } 1160 1161 1162 1163 1170 public void runJob() 1171 { 1172 long currentTime = System.currentTimeMillis(); 1174 boolean collectingStats = false; 1175 long startCollectingTime = currentTime + (1000 * warmUpTime); 1176 long stopCollectingTime = Long.MAX_VALUE; 1177 if ((coolDownTime > 0) && (getShouldStopTime() > 0)) 1178 { 1179 stopCollectingTime = getShouldStopTime() - (1000 * coolDownTime); 1180 } 1181 1182 boolean connected = false; 1185 1186 boolean allRemoved = false; 1189 1190 long deleteStartTime = 0; 1193 1194 conn = new LDAPConnection(); 1196 1197 1198 while ((! shouldStop()) && (! allRemoved)) 1200 { 1201 currentTime = System.currentTimeMillis(); 1202 if ((! collectingStats) && (currentTime >= startCollectingTime) && 1203 (currentTime < stopCollectingTime)) 1204 { 1205 deleteCount.startTracker(); 1207 deleteTime.startTracker(); 1208 resultCodes.startTracker(); 1209 1210 if (reportLatencyTracker) 1211 { 1212 latencyTime.startTracker(); 1213 latencyCategories.startTracker(); 1214 replicaThread.startChecking(); 1215 masterThread.startChecking(); 1216 } 1217 1218 collectingStats = true; 1219 } 1220 else if ((collectingStats) && (currentTime >= stopCollectingTime)) 1221 { 1222 deleteCount.stopTracker(); 1223 deleteTime.stopTracker(); 1224 resultCodes.stopTracker(); 1225 1226 if (reportLatencyTracker) 1227 { 1228 latencyTime.stopTracker(); 1229 latencyCategories.stopTracker(); 1230 replicaThread.stopAndWait(); 1231 masterThread.stopAndWait(); 1232 } 1233 1234 collectingStats = false; 1235 } 1236 1237 if (! connected) 1239 { 1240 try 1241 { 1242 conn.connect(3, masterHost, masterPort, bindDN, bindPassword); 1243 connected = true; 1244 } 1245 catch (LDAPException le) 1246 { 1247 logMessage("ERROR -- Could not connect to " + masterHost + ":" + 1248 masterPort + " (" + le + ") -- aborting thread"); 1249 if (collectingStats) 1250 { 1251 resultCodes.increment(String.valueOf(le.getLDAPResultCode())); 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 1267 1268 String dnToDelete = getEntryDN(); 1270 if (dnToDelete == null) 1271 { 1272 allRemoved = true; 1273 } 1274 else 1275 { 1276 if (collectingStats) 1278 { 1279 deleteTime.startTimer(); 1280 } 1281 if (delay > 0) 1282 { 1283 deleteStartTime = System.currentTimeMillis(); 1284 } 1285 1286 int resultCode = LDAPException.SUCCESS; 1288 try 1289 { 1290 conn.delete(dnToDelete, constraints); 1291 } 1292 catch (LDAPException le) 1293 { 1294 resultCode = le.getLDAPResultCode(); 1295 } 1296 1297 1298 if (collectingStats) 1300 { 1301 deleteCount.increment(); 1302 deleteTime.stopTimer(); 1303 resultCodes.increment(String.valueOf(resultCode)); 1304 } 1305 } 1306 1307 if (alwaysDisconnect) 1309 { 1310 try 1311 { 1312 conn.disconnect(); 1313 } catch (LDAPException le) {} 1314 connected = false; 1315 } 1316 1317 if ((delay > 0) && (! shouldStop())) 1319 { 1320 long now = System.currentTimeMillis(); 1321 long sleepTime = delay - (now - deleteStartTime); 1322 if (sleepTime > 0) 1323 { 1324 try 1325 { 1326 Thread.sleep(sleepTime); 1327 } catch (InterruptedException ie) {} 1328 } 1329 } 1330 } 1331 1332 1333 try 1335 { 1336 conn.disconnect(); 1337 } catch (LDAPException le) {} 1338 1339 1340 if (collectingStats) 1342 { 1343 deleteCount.stopTracker(); 1344 deleteTime.stopTimer(); 1345 resultCodes.stopTracker(); 1346 1347 if (reportLatencyTracker) 1348 { 1349 latencyTime.stopTracker(); 1350 latencyCategories.stopTracker(); 1351 replicaThread.stopAndWait(); 1352 masterThread.stopAndWait(); 1353 } 1354 } 1355 } 1356 1357 1358 1359 1363 public void destroy() 1364 { 1365 if (conn != null) 1366 { 1367 try 1368 { 1369 conn.disconnect(); 1370 } catch (Exception e) {} 1371 1372 conn = null; 1373 } 1374 1375 if (masterThread != null) 1376 { 1377 masterThread.masterThread.interrupt(); 1378 1379 try 1380 { 1381 masterThread.connection.disconnect(); 1382 } catch (Exception e) {} 1383 1384 masterThread.connection = null; 1385 masterThread = null; 1386 } 1387 1388 if (replicaThread != null) 1389 { 1390 replicaThread.replicaThread.interrupt(); 1391 1392 try 1393 { 1394 replicaThread.connection.disconnect(); 1395 } catch (Exception e) {} 1396 1397 replicaThread.connection = null; 1398 replicaThread = null; 1399 } 1400 } 1401 1402 1403 1404 1407 public void finalizeClient() 1408 { 1409 masterThread.stopAndWait(); 1410 replicaThread.stopAndWait(); 1411 } 1412 1413 1414 1415 1420 public String getEntryDN() 1421 { 1422 if (entryDNs == null) 1423 { 1424 int value = nextValue++; 1425 if (value > dnMax) 1426 { 1427 return null; 1428 } 1429 1430 return dnInitial + value + dnFinal; 1431 } 1432 else 1433 { 1434 int index = nextValue++; 1435 if (index < entryDNs.length) 1436 { 1437 return entryDNs[index]; 1438 } 1439 else 1440 { 1441 return null; 1442 } 1443 } 1444 } 1445} 1446 1447 | Popular Tags |