| | |
| | | |
| | | |
| | | |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.server.tools.ToolConstants.*; |
| | | import static org.opends.server.util.StaticUtils.filterExitCode; |
| | | import static com.sun.opends.sdk.util.Messages.*; |
| | | import static org.opends.sdk.tools.ToolConstants.*; |
| | | import static org.opends.sdk.tools.Utils.*; |
| | | |
| | | import java.io.InputStream; |
| | | import java.io.OutputStream; |
| | |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import org.opends.messages.Message; |
| | | import org.opends.sdk.*; |
| | | import org.opends.sdk.requests.Requests; |
| | | import org.opends.sdk.requests.SearchRequest; |
| | | import org.opends.sdk.responses.*; |
| | | import org.opends.server.util.cli.ConsoleApplication; |
| | | import org.opends.sdk.responses.Result; |
| | | import org.opends.sdk.responses.SearchResultEntry; |
| | | import org.opends.sdk.responses.SearchResultReference; |
| | | |
| | | import com.sun.opends.sdk.util.Message; |
| | | |
| | | |
| | | |
| | |
| | | |
| | | /** |
| | | * The main method for SearchRate tool. |
| | | * |
| | | * |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | */ |
| | | |
| | | public static void main(String[] args) |
| | | { |
| | | int retCode = |
| | | mainSearchRate(args, System.in, System.out, System.err); |
| | | int retCode = mainSearchRate(args, System.in, System.out, |
| | | System.err); |
| | | |
| | | if (retCode != 0) |
| | | { |
| | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that |
| | | * information to run the ldapsearch tool. |
| | | * |
| | | * |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | * @return The error code. |
| | |
| | | /** |
| | | * Parses the provided command-line arguments and uses that |
| | | * information to run the ldapsearch tool. |
| | | * |
| | | * |
| | | * @param args |
| | | * The command-line arguments provided to this program. |
| | | * @param inStream |
| | |
| | | { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | | Message toolDescription = |
| | | Message.raw("This utility can be used to " |
| | | Message toolDescription = Message |
| | | .raw("This utility can be used to " |
| | | + "measure search performance"); |
| | | // TODO: correct usage |
| | | ArgumentParser argParser = |
| | | new ArgumentParser(SearchRate.class.getName(), toolDescription, |
| | | false, true, 1, 0, "[filter] [attributes ...]"); |
| | | ArgumentParser argParser = new ArgumentParser(SearchRate.class |
| | | .getName(), toolDescription, false, true, 1, 0, |
| | | "[filter] [attributes ...]"); |
| | | |
| | | ArgumentParserConnectionFactory connectionFactory; |
| | | SearchPerformanceRunner runner; |
| | |
| | | |
| | | try |
| | | { |
| | | connectionFactory = |
| | | new ArgumentParserConnectionFactory(argParser, this); |
| | | connectionFactory = new ArgumentParserConnectionFactory( |
| | | argParser, this); |
| | | runner = new SearchPerformanceRunner(argParser, this); |
| | | |
| | | propertiesFileArgument = |
| | | new StringArgument("propertiesFilePath", null, |
| | | OPTION_LONG_PROP_FILE_PATH, false, false, true, |
| | | INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null, |
| | | INFO_DESCRIPTION_PROP_FILE_PATH.get()); |
| | | propertiesFileArgument = new StringArgument("propertiesFilePath", |
| | | null, OPTION_LONG_PROP_FILE_PATH, false, false, true, |
| | | INFO_PROP_FILE_PATH_PLACEHOLDER.get(), null, null, |
| | | INFO_DESCRIPTION_PROP_FILE_PATH.get()); |
| | | argParser.addArgument(propertiesFileArgument); |
| | | argParser.setFilePropertiesArgument(propertiesFileArgument); |
| | | |
| | | noPropertiesFileArgument = |
| | | new BooleanArgument("noPropertiesFileArgument", null, |
| | | OPTION_LONG_NO_PROP_FILE, INFO_DESCRIPTION_NO_PROP_FILE |
| | | .get()); |
| | | noPropertiesFileArgument = new BooleanArgument( |
| | | "noPropertiesFileArgument", null, OPTION_LONG_NO_PROP_FILE, |
| | | INFO_DESCRIPTION_NO_PROP_FILE.get()); |
| | | argParser.addArgument(noPropertiesFileArgument); |
| | | argParser.setNoPropertiesFileArgument(noPropertiesFileArgument); |
| | | |
| | | showUsage = |
| | | new BooleanArgument("showUsage", OPTION_SHORT_HELP, |
| | | OPTION_LONG_HELP, INFO_DESCRIPTION_SHOWUSAGE.get()); |
| | | showUsage = new BooleanArgument("showUsage", OPTION_SHORT_HELP, |
| | | OPTION_LONG_HELP, INFO_DESCRIPTION_SHOWUSAGE.get()); |
| | | argParser.addArgument(showUsage); |
| | | argParser.setUsageArgument(showUsage, getOutputStream()); |
| | | |
| | | baseDN = |
| | | new StringArgument("baseDN", OPTION_SHORT_BASEDN, |
| | | OPTION_LONG_BASEDN, true, false, true, |
| | | INFO_BASEDN_PLACEHOLDER.get(), null, null, |
| | | INFO_SEARCH_DESCRIPTION_BASEDN.get()); |
| | | baseDN = new StringArgument("baseDN", OPTION_SHORT_BASEDN, |
| | | OPTION_LONG_BASEDN, true, false, true, |
| | | INFO_BASEDN_PLACEHOLDER.get(), null, null, |
| | | INFO_SEARCH_DESCRIPTION_BASEDN.get()); |
| | | baseDN.setPropertyName(OPTION_LONG_BASEDN); |
| | | argParser.addArgument(baseDN); |
| | | |
| | | searchScope = |
| | | new MultiChoiceArgument<SearchScope>("searchScope", 's', |
| | | "searchScope", false, true, INFO_SEARCH_SCOPE_PLACEHOLDER |
| | | .get(), SearchScope.values(), false, |
| | | INFO_SEARCH_DESCRIPTION_SEARCH_SCOPE.get()); |
| | | searchScope = new MultiChoiceArgument<SearchScope>("searchScope", |
| | | 's', "searchScope", false, true, |
| | | INFO_SEARCH_SCOPE_PLACEHOLDER.get(), SearchScope.values(), |
| | | false, INFO_SEARCH_DESCRIPTION_SEARCH_SCOPE.get()); |
| | | searchScope.setPropertyName("searchScope"); |
| | | searchScope.setDefaultValue(SearchScope.WHOLE_SUBTREE); |
| | | argParser.addArgument(searchScope); |
| | | |
| | | dereferencePolicy = |
| | | new MultiChoiceArgument<DereferenceAliasesPolicy>( |
| | | "derefpolicy", 'a', "dereferencePolicy", false, true, |
| | | INFO_DEREFERENCE_POLICE_PLACEHOLDER.get(), |
| | | DereferenceAliasesPolicy.values(), false, |
| | | INFO_SEARCH_DESCRIPTION_DEREFERENCE_POLICY.get()); |
| | | dereferencePolicy = new MultiChoiceArgument<DereferenceAliasesPolicy>( |
| | | "derefpolicy", 'a', "dereferencePolicy", false, true, |
| | | INFO_DEREFERENCE_POLICE_PLACEHOLDER.get(), |
| | | DereferenceAliasesPolicy.values(), false, |
| | | INFO_SEARCH_DESCRIPTION_DEREFERENCE_POLICY.get()); |
| | | dereferencePolicy.setPropertyName("dereferencePolicy"); |
| | | dereferencePolicy.setDefaultValue(DereferenceAliasesPolicy.NEVER); |
| | | argParser.addArgument(dereferencePolicy); |
| | | |
| | | verbose = |
| | | new BooleanArgument("verbose", 'v', "verbose", |
| | | INFO_DESCRIPTION_VERBOSE.get()); |
| | | verbose = new BooleanArgument("verbose", 'v', "verbose", |
| | | INFO_DESCRIPTION_VERBOSE.get()); |
| | | verbose.setPropertyName("verbose"); |
| | | argParser.addArgument(verbose); |
| | | } |
| | |
| | | } |
| | | |
| | | List<String> attributes = new LinkedList<String>(); |
| | | ArrayList<String> filterAndAttributeStrings = |
| | | argParser.getTrailingArguments(); |
| | | ArrayList<String> filterAndAttributeStrings = argParser |
| | | .getTrailingArguments(); |
| | | if (filterAndAttributeStrings.size() > 0) |
| | | { |
| | | // the list of trailing arguments should be structured as follow: |
| | |
| | | attributes.add(s); |
| | | } |
| | | } |
| | | runner.attributes = |
| | | attributes.toArray(new String[attributes.size()]); |
| | | runner.attributes = attributes |
| | | .toArray(new String[attributes.size()]); |
| | | runner.baseDN = baseDN.getValue(); |
| | | try |
| | | { |
| | | runner.scope = searchScope.getTypedValue(); |
| | | runner.dereferencesAliasesPolicy = |
| | | dereferencePolicy.getTypedValue(); |
| | | runner.dereferencesAliasesPolicy = dereferencePolicy |
| | | .getTypedValue(); |
| | | } |
| | | catch (ArgumentException ex1) |
| | | { |
| | |
| | | { |
| | | // Try it out to make sure the format string and data sources |
| | | // match. |
| | | Object[] data = |
| | | DataSource.generateData(runner.getDataSources(), null); |
| | | Object[] data = DataSource.generateData(runner.getDataSources(), |
| | | null); |
| | | String.format(runner.filter, data); |
| | | String.format(runner.baseDN, data); |
| | | } |
| | |
| | | return runner.run(connectionFactory); |
| | | } |
| | | |
| | | |
| | | |
| | | private final AtomicInteger entryRecentCount = new AtomicInteger(); |
| | | |
| | | |
| | |
| | | private class SearchPerformanceRunner extends PerformanceRunner |
| | | { |
| | | private String filter; |
| | | |
| | | private String baseDN; |
| | | |
| | | private SearchScope scope; |
| | | |
| | | private DereferenceAliasesPolicy dereferencesAliasesPolicy; |
| | | |
| | | private String[] attributes; |
| | | |
| | | |
| | |
| | | WorkerThread<SearchStatsHandler> |
| | | { |
| | | private SearchRequest sr; |
| | | |
| | | private Object[] data; |
| | | |
| | | |
| | |
| | | else |
| | | { |
| | | data = DataSource.generateData(dataSources, data); |
| | | sr = |
| | | Requests.newSearchRequest(String.format(baseDN, data), scope, |
| | | String.format(filter, data), attributes); |
| | | sr = Requests.newSearchRequest(String.format(baseDN, data), |
| | | scope, String.format(filter, data), attributes); |
| | | } |
| | | sr.setDereferenceAliasesPolicy(dereferencesAliasesPolicy); |
| | | } |
| | |
| | | private class SearchStatsThread extends StatsThread |
| | | { |
| | | private long totalEntryCount; |
| | | |
| | | private final String[] extraColumn; |
| | | |
| | | |
| | |
| | | { |
| | | int entryCount = entryRecentCount.getAndSet(0); |
| | | totalEntryCount += entryCount; |
| | | extraColumn[0] = |
| | | String.format("%.1f", (double) entryCount / successCount); |
| | | extraColumn[0] = String.format("%.1f", (double) entryCount |
| | | / successCount); |
| | | return extraColumn; |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * Indicates whether or not the user has requested advanced mode. |
| | | * |
| | | * |
| | | * @return Returns <code>true</code> if the user has requested |
| | | * advanced mode. |
| | | */ |
| | |
| | | /** |
| | | * Indicates whether or not the user has requested interactive |
| | | * behavior. |
| | | * |
| | | * |
| | | * @return Returns <code>true</code> if the user has requested |
| | | * interactive behavior. |
| | | */ |
| | |
| | | * go to the error stream or not. In addition, it may also dictate |
| | | * whether or not sub-menus should display a cancel option as well as |
| | | * a quit option. |
| | | * |
| | | * |
| | | * @return Returns <code>true</code> if this console application is |
| | | * running in its menu-driven mode. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Indicates whether or not the user has requested quiet output. |
| | | * |
| | | * |
| | | * @return Returns <code>true</code> if the user has requested quiet |
| | | * output. |
| | | */ |
| | |
| | | /** |
| | | * Indicates whether or not the user has requested script-friendly |
| | | * output. |
| | | * |
| | | * |
| | | * @return Returns <code>true</code> if the user has requested |
| | | * script-friendly output. |
| | | */ |
| | |
| | | |
| | | /** |
| | | * Indicates whether or not the user has requested verbose output. |
| | | * |
| | | * |
| | | * @return Returns <code>true</code> if the user has requested verbose |
| | | * output. |
| | | */ |