PSearch.java revision 248ed6026dad06a3596549af7f5177c7fb25f26e
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License, Version 1.0 only
2N/A * (the "License"). You may not use this file except in compliance
2N/A * with the License.
2N/A *
2N/A * You can obtain a copy of the license at
2N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE
2N/A * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at
2N/A * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable,
2N/A * add the following below this CDDL HEADER, with the fields enclosed
2N/A * by brackets "[]" replaced with your own identifying information:
2N/A * Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A *
2N/A *
2N/A * Copyright 2009-2010 Sun Microsystems, Inc.
2N/A */
2N/A
2N/Aimport netscape.ldap.util.GetOpt;
2N/Aimport com.ibm.staf.STAFHandle;
2N/A
2N/Apublic class PSearch {
2N/A
2N/A public static void main(String[] args) {
2N/A String usage = "Usage: psearch -h <hostname> -p <port> -b <suffix>" + "[-D bindDN] [-w bindPW]" + "-f <fileURL+file name>" + "-s" + "-n <number of thread>" + " -o <add,modify,delete,moddn>"+ " -l";
2N/A String hostname = "localhost";
2N/A int portnumber = 1389; //LDAPv3.DEFAULT_PORT;
2N/A int nbThreads = 1;//number of thread by default
2N/A // Check for these options. -H means to print out a usage message.
2N/A GetOpt options = new GetOpt("h:p:b:D:w:H:f:n:o:s:l", args);
2N/A
2N/A // Get the arguments specified for each option.
2N/A String host = options.getOptionParam('h');
2N/A // host
2N/A if (options.hasOption('h')) {
2N/A if (host == null) {
2N/A // usage
2N/A System.out.println(usage);
2N/A System.exit(1);
2N/A } else {
2N/A hostname = host;
2N/A }
2N/A }
2N/A String port = options.getOptionParam('p');
2N/A // If a port number was specified, convert the port value
2N/A // to an integer.
2N/A if (port != null) {
2N/A try {
2N/A portnumber = java.lang.Integer.parseInt(port);
2N/A } catch (java.lang.Exception e) {
2N/A System.out.println("Invalid port number: " + port);
2N/A System.out.println(usage);
2N/A System.exit(1);
2N/A }
2N/A }
2N/A //number of thread
2N/A String nbT = options.getOptionParam('n');
2N/A if (nbT != null) {
2N/A try {
2N/A nbThreads = java.lang.Integer.parseInt(nbT);
2N/A } catch (java.lang.Exception e) {
2N/A System.out.println("Invalid Thread number: " + nbT);
2N/A System.out.println(usage);
2N/A System.exit(1);
2N/A }
2N/A }
2N/A // PSearch suffix
2N/A String suffix = options.getOptionParam('b');
2N/A
2N/A String bindDN = options.getOptionParam('D');
2N/A
2N/A String bindPW = options.getOptionParam('w');
2N/A
2N/A //operations all by default
2N/A String operation = PSearchOperations.ALL;
2N/A if (options.hasOption('o')) {
2N/A String opParam = options.getOptionParam('o');
2N/A if (opParam.equals("add")) {
2N/A operation = PSearchOperations.ADD;
2N/A } else if (opParam.equals("modify")) {
2N/A operation = PSearchOperations.MODIFY;
2N/A } else if (opParam.equals("delete")) {
2N/A operation = PSearchOperations.DELETE;
2N/A } else if (opParam.equals("moddn")) {
2N/A operation = PSearchOperations.MODDN;
2N/A } else if (opParam.equals("all")) {
2N/A operation = PSearchOperations.ALL;
2N/A ;
2N/A } else {
2N/A System.out.println("Invalid operation type: " + opParam);
2N/A System.out.println(usage);
2N/A System.exit(1);
2N/A }
2N/A }
2N/A
2N/A // to disable the log files
2N/A boolean useFile = false;
2N/A String fileName = "logLile";
2N/A if (options.hasOption('f')) {
2N/A useFile = options.hasOption('f');
2N/A fileName = options.getOptionParam('f');
2N/A }
2N/A
2N/A // to enable diff format
2N/A boolean ldifFormat = options.hasOption('l');
2N/A
2N/A // to enable system out logs
2N/A boolean output = options.hasOption('s');
2N/A
2N/A System.out.println("Connecting to " + hostname + ":" + portnumber +
2N/A " as \"" + bindDN + "\"" +
2N/A " on suffix \"" + suffix + "\"" +
2N/A " on operation \"" + operation + "\"" +
2N/A " use file: \"" + useFile + "\" output: \"" + output + "\"");
2N/A //start all thread
2N/A
2N/A
2N/A for (int i = 0; i < nbThreads; i++) {
2N/A PSearchOperations ps = new PSearchOperations(i, hostname, portnumber, bindDN, bindPW, suffix);
2N/A if (useFile) {
2N/A ps.useLogFile(useFile);
2N/A ps.setLogFile(fileName);
2N/A }
2N/A ps.setOutput(output);
2N/A ps.setLdifFormat(ldifFormat);
2N/A ps.setOperation(operation);
2N/A ps.start();
2N/A }
2N/A
2N/A try {
2N/A STAFHandle handle = new STAFHandle("PSearch listener");
2N/A handle.submit2(hostname, "SEM", "PULSE EVENT PSearch/Ready");
2N/A handle.submit2(hostname, "SEM", "WAIT EVENT PSearch tests/Completed");
2N/A handle.submit2(hostname, "SEM", "DELETE EVENT PSearch tests/Completed");
2N/A System.exit(0);
2N/A } catch (Exception e) {
2N/A System.out.println("STAF Handle fail");
2N/A }
2N/A
2N/A }
2N/A}
2N/A