List of usage examples for org.apache.commons.cli PosixParser PosixParser
PosixParser
From source file:lemontree.modulenetwork.RunCli.java
/** * Parse command line options and run LeMoNe * /*from w w w .j a v a 2 s . co m*/ * @param args command-line arguments string * */ public static void main(String[] args) { // set dummy values for those parameters, they'll be filled later String task = null; String gene_file = null; String data_file = null; String reg_file = null; String tree_file = null; String output_file = null; String range = null; int num_steps = 0; int burn_in = 0; int sample_steps = 0; String cluster_file = null; String go_annot_file = null; String go_ref_file = null; String top_regulators = null; String map_file = null; String go_ontology_file = null; String draw_experiment_color = null; // set default values for those parameters, users can override them double alpha = 0.1; double beta = 0.1; double mu = 0.0; double lambda = 0.1; double score_gain = 0.0; int init_num_clust = 0; int num_runs = 1; boolean use_bayesian_score = true; int num_reg = 10; double beta_reg = 20; String go_p_value = "0.05"; String go_namespace = "biological_process"; boolean use_global_mean = false; boolean use_regulator_mean = false; int cut_level = 0; double min_weight = 0.25; int min_clust_size = 10; int min_clust_score = 2; Boolean node_clustering = true; boolean draw_experiment_names = true; // create the different options Options opts = new Options(); opts.addOption("task", true, "task to perform"); opts.addOption("gene_file", true, "gene file"); opts.addOption("data_file", true, "data file (genes)"); opts.addOption("reg_file", true, "regulators file"); opts.addOption("tree_file", true, "tree file"); opts.addOption("output_file", true, "output file name"); opts.addOption("num_steps", true, "number of steps (Gibbs sampler)"); opts.addOption("burn_in", true, "number of burn-in steps (Gibbs sampler)"); opts.addOption("sample_steps", true, "sample steps interval (Gibbs sampler)"); opts.addOption("cluster_file", true, "cluster file name"); opts.addOption("num_clust", true, "number of clusters"); opts.addOption("alpha", true, "alpha0 parameter value"); opts.addOption("beta", true, "beta0 parameter value"); opts.addOption("mu", true, "mu0 parameter value"); opts.addOption("lambda", true, "lambda0 parameter value"); opts.addOption("score_gain", true, "score gain cutoff value"); opts.addOption("init_num_clust", true, "initial number of clusters (Gibbs sampler)"); opts.addOption("num_runs", true, "number of runs (Gibbs sampler)"); opts.addOption("num_reg", true, "maximum number of regulators assigned for each node"); opts.addOption("beta_reg", true, "beta parameter value for regulators assignment"); opts.addOption("num_split", true, "number of splits for the module set"); opts.addOption("prefix", true, "java command prefix for the split option command line"); opts.addOption("range", true, "module set range for the assignment of the regulators"); opts.addOption("go_annot_file", true, "GO custom annotation file"); opts.addOption("go_ontology_file", true, "GO ontology file name"); opts.addOption("go_ref_file", true, "GO refence gene list file name"); opts.addOption("go_p_value", true, "GO p-value cutoff"); opts.addOption("go_namespace", true, "GO namespace"); opts.addOption("go_annot_def", false, "GO annotation file flag"); opts.addOption("matlab", false, "Matlab format for output files"); opts.addOption("help", false, "help"); opts.addOption("h", false, "help"); opts.addOption("top_regulators", true, "Top regulators file name"); opts.addOption("use_global_mean", false, "Use global mean for the figures"); opts.addOption("use_regulator_mean", false, "Use regulator mean for the figures"); opts.addOption("all_regulators", false, "Print all regulators"); opts.addOption("map_file", true, "Gene names map file"); opts.addOption("cut_level", true, "Regulation tree cut level"); opts.addOption("min_weight", true, "Tight clusters minimum weight"); opts.addOption("min_clust_size", true, "Tight clusters minimum cluster size"); opts.addOption("min_clust_score", true, "Tight clusters minimum cluster score"); opts.addOption("node_clustering", true, "Perform node clustering (true) or edge clustering (false)"); opts.addOption("draw_experiment_names", true, "Draw experiment names in the figures"); opts.addOption("draw_experiment_color", true, "Draw experiment color codes in the figures"); // build a parser object and parse the command line (!) CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("min_weight")) min_weight = Double.parseDouble(cmd.getOptionValue("min_weight")); if (cmd.hasOption("min_clust_size")) min_clust_size = Integer.parseInt(cmd.getOptionValue("min_clust_size")); if (cmd.hasOption("min_clust_score")) min_clust_score = Integer.parseInt(cmd.getOptionValue("min_clust_score")); if (cmd.hasOption("task")) task = cmd.getOptionValue("task"); if (cmd.hasOption("data_file")) data_file = cmd.getOptionValue("data_file"); if (cmd.hasOption("tree_file")) tree_file = cmd.getOptionValue("tree_file"); if (cmd.hasOption("gene_file")) gene_file = cmd.getOptionValue("gene_file"); if (cmd.hasOption("reg_file")) reg_file = cmd.getOptionValue("reg_file"); if (cmd.hasOption("output_file")) output_file = cmd.getOptionValue("output_file"); if (cmd.hasOption("cluster_file")) cluster_file = cmd.getOptionValue("cluster_file"); if (cmd.hasOption("alpha")) alpha = Double.parseDouble(cmd.getOptionValue("alpha")); if (cmd.hasOption("beta")) beta = Double.parseDouble(cmd.getOptionValue("beta")); if (cmd.hasOption("lambda")) lambda = Double.parseDouble(cmd.getOptionValue("lambda")); if (cmd.hasOption("mu")) mu = Double.parseDouble(cmd.getOptionValue("mu")); if (cmd.hasOption("score_gain")) score_gain = Double.parseDouble(cmd.getOptionValue("score_gain")); if (cmd.hasOption("num_steps")) num_steps = Integer.parseInt(cmd.getOptionValue("num_steps")); if (cmd.hasOption("burn_in")) burn_in = Integer.parseInt(cmd.getOptionValue("burn_in")); if (cmd.hasOption("sample_steps")) sample_steps = Integer.parseInt(cmd.getOptionValue("sample_steps")); if (cmd.hasOption("init_num_clust")) init_num_clust = Integer.parseInt(cmd.getOptionValue("init_num_clust")); if (cmd.hasOption("num_reg")) num_reg = Integer.parseInt(cmd.getOptionValue("num_reg")); if (cmd.hasOption("beta_reg")) beta_reg = Double.parseDouble(cmd.getOptionValue("beta_reg")); if (cmd.hasOption("range")) range = cmd.getOptionValue("range"); if (cmd.hasOption("go_annot_file")) go_annot_file = cmd.getOptionValue("go_annot_file"); if (cmd.hasOption("go_ontology_file")) go_ontology_file = cmd.getOptionValue("go_ontology_file"); if (cmd.hasOption("go_ref_file")) go_ref_file = cmd.getOptionValue("go_ref_file"); if (cmd.hasOption("go_p_value")) go_p_value = cmd.getOptionValue("go_p_value"); if (cmd.hasOption("go_namespace")) go_namespace = cmd.getOptionValue("go_namespace"); if (cmd.hasOption("top_regulators")) top_regulators = cmd.getOptionValue("top_regulators"); if (cmd.hasOption("use_global_mean")) use_global_mean = true; if (cmd.hasOption("use_regulator_mean")) use_regulator_mean = true; if (cmd.hasOption("map_file")) map_file = cmd.getOptionValue("map_file"); if (cmd.hasOption("cut_level")) cut_level = Integer.parseInt(cmd.getOptionValue("cut_level")); if (cmd.hasOption("node_clustering")) if (cmd.getOptionValue("node_clustering").equalsIgnoreCase("false")) node_clustering = false; if (cmd.hasOption("draw_experiment_names")) if (cmd.getOptionValue("draw_experiment_names").equalsIgnoreCase("false")) draw_experiment_names = false; if (cmd.hasOption("draw_experiment_color")) draw_experiment_color = cmd.getOptionValue("draw_experiment_color"); } catch (ParseException exp) { System.out.println("Error while parsing command line:"); System.out.println(); exp.printStackTrace(); System.exit(1); } // print header printBanner(); // something has to be done, we need a task to be set if (task == null) Die("Error: task option must be set."); // --------------------------------------------------------------- // ganesh task: 2-way clustering of genes using the gibbs sampler // --------------------------------------------------------------- if (task.equalsIgnoreCase("ganesh")) { // those parameters must be set if (data_file == null) Die("Error: data_file option must be set."); if (output_file == null) Die("Error: output_file option must be set."); // set default values if the user did not change them if (num_runs == 0) num_runs = 1; if (num_steps == 0) num_steps = 100; if (burn_in == 0) burn_in = 50; if (sample_steps == 0) sample_steps = 100; System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("data_file: " + data_file); System.out.println("gene_file: " + gene_file); System.out.println("output_file: " + output_file); System.out.println("lambda: " + lambda); System.out.println("mu: " + mu); System.out.println("alpha: " + alpha); System.out.println("beta: " + beta); System.out.println("num_steps: " + num_steps); System.out.println("burn_in: " + burn_in); System.out.println("sample_steps: " + sample_steps); System.out.println("score_gain: " + score_gain); // Create ModuleNetwork object ModuleNetwork M = new ModuleNetwork(); M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readExpressionMatrix(data_file, gene_file); M.setNormalGammaPriors(lambda, mu, alpha, beta); // Gibbs sample different module sets with one tree per module M.gibbsSamplerGenes(init_num_clust, num_runs, num_steps, burn_in, sample_steps, score_gain, use_bayesian_score); // write results to text file M.writeClusters(output_file); } //------------------------------------------------------------------------------------- // tight_clusters task: node clustering to produce tight clusters //------------------------------------------------------------------------------------- else if (task.equalsIgnoreCase("tight_clusters")) { if (data_file == null) Die("Error: data_file option must be set."); if (cluster_file == null) Die("Error: cluster_file option must be set."); if (output_file == null) Die("Error: output_file option must be set."); System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("data_file: " + data_file); System.out.println("cluster_file: " + cluster_file); System.out.println("output_file: " + output_file); System.out.println("node_clustering: " + node_clustering); System.out.println("min_weight: " + min_weight); System.out.println("min_clust_size: " + min_clust_size); System.out.println("min_clust_score: " + min_clust_score); System.out.println(); ModuleNetwork M = new ModuleNetwork(); M.readExpressionMatrix(data_file, null); M.readMultipleClusters(cluster_file); // find tight clusters with node clustering algorithm CentroidClustering cc = new CentroidClustering(M, node_clustering, min_weight, min_clust_size, min_clust_score); cc.doCentroidClustering(); cc.printClusters(output_file); } //------------------------------------------------------------------------------------- // regulators task: learn regulation programs (gibbs sampling exp. + assign regulators) //------------------------------------------------------------------------------------- else if (task.equalsIgnoreCase("regulators")) { // those parameters must be set if (data_file == null) Die("Error: data_file option must be set."); if (reg_file == null) Die("Error: reg_file option must be set."); if (cluster_file == null) Die("Error: cluster_file option must be set."); if (output_file == null) Die("Error: output_file option must be set."); // set default values if the user did not change them if (num_steps == 0) num_steps = 1100; if (burn_in == 0) burn_in = 100; if (sample_steps == 0) sample_steps = 100; System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("data_file: " + data_file); System.out.println("reg_file: " + reg_file); System.out.println("cluster_file: " + cluster_file); System.out.println("output_file: " + output_file); System.out.println("lambda: " + lambda); System.out.println("mu: " + mu); System.out.println("alpha: " + alpha); System.out.println("beta: " + beta); System.out.println("num_runs: " + num_runs); System.out.println("num_steps: " + num_steps); System.out.println("burn_in: " + burn_in); System.out.println("sample_steps: " + sample_steps); System.out.println("score_gain: " + score_gain); System.out.println("num_reg: " + num_reg); // create module network object ModuleNetwork M = new ModuleNetwork(); M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readExpressionMatrix(data_file, null); M.readClusters(cluster_file); M.readRegulators(reg_file); M.initStatisticsAndScore(); M.setDataMeanAndSDFromModuleset(); // cluster experiments using the gibbs sampler M.gibbsSamplerExpts(num_runs, num_steps, burn_in, sample_steps, score_gain, use_bayesian_score); // assign regulators M.assignRegulatorsNoAcyclStoch(beta_reg, num_reg); // write results as text file with all regulators, top 1%, random regulators and regulations trees as xml M.printRegulators(output_file + ".allreg.txt", true, false); M.printRegulators(output_file + ".topreg.txt", false, false); M.printRandomRegulators(output_file + ".randomreg.txt", false); M.writeRegTreeXML(output_file + ".xml.gz"); } //---------------------------------------------------------- // experiments task: cluster conditions using gibbs sampling //---------------------------------------------------------- else if (task.equalsIgnoreCase("experiments")) { // those parameters must be set if (data_file == null) Die("Error: data_file option must be set."); if (cluster_file == null) Die("Error: cluster_file option must be set."); if (output_file == null) Die("Error: output_file option must be set."); // set default values if the user did not change them if (num_steps == 0) num_steps = 1100; if (burn_in == 0) burn_in = 100; if (sample_steps == 0) sample_steps = 100; System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("data_file: " + data_file); System.out.println("cluster_file: " + cluster_file); System.out.println("output_file: " + output_file); System.out.println("lambda: " + lambda); System.out.println("mu: " + mu); System.out.println("alpha: " + alpha); System.out.println("beta: " + beta); System.out.println("num_steps: " + num_steps); System.out.println("burn_in: " + burn_in); System.out.println("sample_steps: " + sample_steps); System.out.println("score_gain: " + score_gain); // read data and clusters ModuleNetwork M = new ModuleNetwork(); M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readExpressionMatrix(data_file, null); M.readClusters(cluster_file); M.initStatisticsAndScore(); // cluster experiments using the gibbs sampler M.gibbsSamplerExpts(num_runs, num_steps, burn_in, sample_steps, score_gain, use_bayesian_score); // write results as xml file M.writeRegTreeXML(output_file); } //--------------------------------------------------------------- // split_reg task: assign regulators for a given range of modules //--------------------------------------------------------------- else if (task.equalsIgnoreCase("split_reg")) { // those parameters must be set if (data_file == null) Die("Error: data_file option must be set."); if (reg_file == null) Die("Error: reg_file option must be set."); if (cluster_file == null) Die("Error: cluster_file option must be set."); if (tree_file == null) Die("Error: tree_file option must be set."); if (output_file == null) Die("Error: output_file option must be set."); if (range == null) Die("Error: range option must be set."); System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("data_file: " + data_file); System.out.println("reg_file: " + reg_file); System.out.println("cluster_file: " + cluster_file); System.out.println("output_file: " + output_file); System.out.println("num_reg: " + num_reg); System.out.println("beta_reg: " + beta_reg); System.out.println("range: " + range); ModuleNetwork M = new ModuleNetwork(); M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readExpressionMatrix(data_file, null); M.readClusters(cluster_file); M.readRegulators(reg_file); M.initStatisticsAndScore(); M.readRegTreeXML(tree_file); String[] val = range.split(":"); int start_module = Integer.parseInt(val[0]); int stop_module = Integer.parseInt(val[1]); // assign regulators M.assignRegulatorsNoAcyclStoch(beta_reg, num_reg, start_module, stop_module); // write results M.printRegulators(output_file + ".allreg.txt", true, false); M.printRandomRegulators(output_file + ".randomreg.txt", false); M.writeRegTreeXML(output_file + ".xml.gz"); } //---------------------------------------------------------------------------- // go_annotation task: GO annotation of a cluster file //---------------------------------------------------------------------------- else if (task.equalsIgnoreCase("go_annotation")) { // those parameters must be set if (cluster_file == null) Die("Error: cluster_file parameter must be set."); if (output_file == null) Die("Error: output_file option must be set."); if (go_annot_file == null) Die("Error: go_annot_file option must be set."); if (go_ontology_file == null) Die("Error: go_ontology_file option must be set."); if (go_ref_file == null) Die("Error: go_ref_file option must be set."); System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("cluster_file: " + cluster_file); System.out.println("output_file: " + output_file); System.out.println("go_annot_file: " + go_annot_file); System.out.println("go_ontology_file: " + go_ontology_file); System.out.println("go_ref_file: " + go_ref_file); System.out.println("go_p_value: " + go_p_value); System.out.println("go_namespace: " + go_namespace); System.out.println("map_file " + map_file); BiNGO b = new BiNGO(go_annot_file, go_ontology_file, go_p_value, go_namespace); try { b.GOstats(cluster_file, go_ref_file, output_file, map_file); } catch (IOException e) { e.printStackTrace(); } } //---------------------------------------------------------------------------- // figures task: create eps figures for each module //---------------------------------------------------------------------------- else if (task.equalsIgnoreCase("figures")) { // those parameters must be set if (top_regulators == null) Die("Error: top_regulators option must be set."); if (data_file == null) Die("Error: data_file option must be set."); if (reg_file == null) Die("Error: reg_file option must be set."); if (cluster_file == null) Die("Error: cluster_file option must be set."); if (tree_file == null) Die("Error: tree_file option must be set."); System.out.println("Parameters"); System.out.println("----------"); System.out.println("task: " + task); System.out.println("data_file: " + data_file); System.out.println("reg_file: " + reg_file); System.out.println("cluster_file: " + cluster_file); System.out.println("tree_file: " + tree_file); System.out.println("top_regulators: " + top_regulators); System.out.println("use_regulator_mean: " + use_regulator_mean); System.out.println("use_global_mean: " + use_global_mean); System.out.println("map_file: " + map_file); System.out.println("cut_level: " + cut_level); System.out.println("draw_experiment_names: " + draw_experiment_names); System.out.println("draw_experiment_color: " + draw_experiment_color); ModuleNetwork M = new ModuleNetwork(); //read expression data, genes, clusters and regulators from files M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readExpressionMatrix(data_file, null); M.readClusters(cluster_file); M.readRegulators(reg_file); M.initStatisticsAndScore(); M.setDataMeanAndSDFromModuleset(); // read regulation trees from xml file M.readRegTreeXML(tree_file); M.setTestSplits(); // set top regulators for each module M.setTopRegulatorClasses(top_regulators); // calculate mean and sigma for all modules M.setModuleMeanSigma(); M.checkExperiments(); // use module mean (default) or global mean for figures M.setGlobalMeanForFigures(use_global_mean); // use individual regulators mean for figures (default false) M.setRegulatorlMeanForFigures(use_regulator_mean); if (use_regulator_mean == true) M.setRegulatorMeanSigma(); // change gene names if a map file is given if (map_file != null) M.changeGeneNames(map_file); // cut trees to a certain level if (cut_level > 0) { for (Module mod : M.moduleSet) { for (TreeNode t : mod.hierarchicalTrees) { t.testLevel(cut_level); } } } DrawModules dm = new DrawModules(M); if (draw_experiment_color != null) { M.setExperimentColor(draw_experiment_color); dm.enableExperimentColor(); } if (draw_experiment_names == false) { dm.unsetDrawExperimentNames(); } dm.drawAllModules(); } //---------------------------------------------------------------------------- // topdown task: run "old" heuristic algo //---------------------------------------------------------------------------- else if (task.equalsIgnoreCase("topdown")) { int maxParents = 3; double epsConvergence = 1E-3; // Create ModuleNetwork object ModuleNetwork M = new ModuleNetwork(); M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readExpressionMatrix(data_file, gene_file); M.setNormalGammaPriors(lambda, mu, alpha, beta); M.readRegulators(reg_file); // Top-down search M.heuristicSearchMaxTopDown(maxParents, epsConvergence); // write results as xml file M.writeRegTreeXML(output_file); } else { System.out.println("task option '" + task + "' unknown."); System.out.println(); } }
From source file:com.cyberway.issue.io.warc.WARCReader.java
/** * Command-line interface to WARCReader. * * Here is the command-line interface:/*from w w w. j a va 2 s.c o m*/ * <pre> * usage: java com.cyberway.issue.io.arc.WARCReader [--offset=#] ARCFILE * -h,--help Prints this message and exits. * -o,--offset Outputs record at this offset into arc file.</pre> * * <p>Outputs using a pseudo-CDX format as described here: * <a href="http://www.archive.org/web/researcher/cdx_legend.php">CDX * Legent</a> and here * <a href="http://www.archive.org/web/researcher/example_cdx.php">Example</a>. * Legend used in below is: 'CDX b e a m s c V (or v if uncompressed) n g'. * Hash is hard-coded straight SHA-1 hash of content. * * @param args Command-line arguments. * @throws ParseException Failed parse of the command line. * @throws IOException * @throws java.text.ParseException */ public static void main(String[] args) throws ParseException, IOException, java.text.ParseException { Options options = getOptions(); PosixParser parser = new PosixParser(); CommandLine cmdline = parser.parse(options, args, false); List cmdlineArgs = cmdline.getArgList(); Option[] cmdlineOptions = cmdline.getOptions(); HelpFormatter formatter = new HelpFormatter(); // If no args, print help. if (cmdlineArgs.size() <= 0) { usage(formatter, options, 0); } // Now look at options passed. long offset = -1; boolean digest = false; boolean strict = false; String format = CDX; for (int i = 0; i < cmdlineOptions.length; i++) { switch (cmdlineOptions[i].getId()) { case 'h': usage(formatter, options, 0); break; case 'o': offset = Long.parseLong(cmdlineOptions[i].getValue()); break; case 's': strict = true; break; case 'd': digest = getTrueOrFalse(cmdlineOptions[i].getValue()); break; case 'f': format = cmdlineOptions[i].getValue().toLowerCase(); boolean match = false; // List of supported formats. final String[] supportedFormats = { CDX, DUMP, GZIP_DUMP, CDX_FILE }; for (int ii = 0; ii < supportedFormats.length; ii++) { if (supportedFormats[ii].equals(format)) { match = true; break; } } if (!match) { usage(formatter, options, 1); } break; default: throw new RuntimeException("Unexpected option: " + +cmdlineOptions[i].getId()); } } if (offset >= 0) { if (cmdlineArgs.size() != 1) { System.out.println("Error: Pass one arcfile only."); usage(formatter, options, 1); } WARCReader r = WARCReaderFactory.get(new File((String) cmdlineArgs.get(0)), offset); r.setStrict(strict); outputRecord(r, format); } else { for (Iterator i = cmdlineArgs.iterator(); i.hasNext();) { String urlOrPath = (String) i.next(); try { WARCReader r = WARCReaderFactory.get(urlOrPath); r.setStrict(strict); r.setDigest(digest); output(r, format); } catch (RuntimeException e) { // Write out name of file we failed on to help with // debugging. Then print stack trace and try to keep // going. We do this for case where we're being fed // a bunch of ARCs; just note the bad one and move // on to the next. System.err.println("Exception processing " + urlOrPath + ": " + e.getMessage()); e.printStackTrace(System.err); System.exit(1); } } } }
From source file:edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques.java
/** * @param args// w w w . j a v a 2s. c om * @throws ParseException */ @SuppressWarnings({ "deprecation" }) public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { Options options = new Options(); Option forceOption = new Option("f", "force", false, "force the computation of the relationship " + "even if files already exist"); forceOption.setRequired(false); options.addOption(forceOption); Option g1Option = new Option("g1", "first-group", true, "set first group of datasets"); g1Option.setRequired(true); g1Option.setArgName("FIRST GROUP"); g1Option.setArgs(Option.UNLIMITED_VALUES); options.addOption(g1Option); Option g2Option = new Option("g2", "second-group", true, "set second group of datasets"); g2Option.setRequired(false); g2Option.setArgName("SECOND GROUP"); g2Option.setArgs(Option.UNLIMITED_VALUES); options.addOption(g2Option); Option machineOption = new Option("m", "machine", true, "machine identifier"); machineOption.setRequired(true); machineOption.setArgName("MACHINE"); machineOption.setArgs(1); options.addOption(machineOption); Option nodesOption = new Option("n", "nodes", true, "number of nodes"); nodesOption.setRequired(true); nodesOption.setArgName("NODES"); nodesOption.setArgs(1); options.addOption(nodesOption); Option s3Option = new Option("s3", "s3", false, "data on Amazon S3"); s3Option.setRequired(false); options.addOption(s3Option); Option awsAccessKeyIdOption = new Option("aws_id", "aws-id", true, "aws access key id; " + "this is required if the execution is on aws"); awsAccessKeyIdOption.setRequired(false); awsAccessKeyIdOption.setArgName("AWS-ACCESS-KEY-ID"); awsAccessKeyIdOption.setArgs(1); options.addOption(awsAccessKeyIdOption); Option awsSecretAccessKeyOption = new Option("aws_key", "aws-id", true, "aws secrect access key; " + "this is required if the execution is on aws"); awsSecretAccessKeyOption.setRequired(false); awsSecretAccessKeyOption.setArgName("AWS-SECRET-ACCESS-KEY"); awsSecretAccessKeyOption.setArgs(1); options.addOption(awsSecretAccessKeyOption); Option bucketOption = new Option("b", "s3-bucket", true, "bucket on s3; " + "this is required if the execution is on aws"); bucketOption.setRequired(false); bucketOption.setArgName("S3-BUCKET"); bucketOption.setArgs(1); options.addOption(bucketOption); Option helpOption = new Option("h", "help", false, "display this message"); helpOption.setRequired(false); options.addOption(helpOption); HelpFormatter formatter = new HelpFormatter(); CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { formatter.printHelp( "hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques", options, true); System.exit(0); } if (cmd.hasOption("h")) { formatter.printHelp( "hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques", options, true); System.exit(0); } boolean s3 = cmd.hasOption("s3"); String s3bucket = ""; String awsAccessKeyId = ""; String awsSecretAccessKey = ""; if (s3) { if ((!cmd.hasOption("aws_id")) || (!cmd.hasOption("aws_key")) || (!cmd.hasOption("b"))) { System.out.println( "Arguments 'aws_id', 'aws_key', and 'b'" + " are mandatory if execution is on AWS."); formatter.printHelp( "hadoop jar data-polygamy.jar " + "edu.nyu.vida.data_polygamy.standard_techniques.CorrelationTechniques", options, true); System.exit(0); } s3bucket = cmd.getOptionValue("b"); awsAccessKeyId = cmd.getOptionValue("aws_id"); awsSecretAccessKey = cmd.getOptionValue("aws_key"); } boolean snappyCompression = false; boolean bzip2Compression = false; String machine = cmd.getOptionValue("m"); int nbNodes = Integer.parseInt(cmd.getOptionValue("n")); Configuration s3conf = new Configuration(); if (s3) { s3conf.set("fs.s3.awsAccessKeyId", awsAccessKeyId); s3conf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey); s3conf.set("bucket", s3bucket); } Path path = null; FileSystem fs = FileSystem.get(new Configuration()); ArrayList<String> shortDataset = new ArrayList<String>(); ArrayList<String> firstGroup = new ArrayList<String>(); ArrayList<String> secondGroup = new ArrayList<String>(); HashMap<String, String> datasetAgg = new HashMap<String, String>(); boolean removeExistingFiles = cmd.hasOption("f"); String[] firstGroupCmd = cmd.getOptionValues("g1"); String[] secondGroupCmd = cmd.hasOption("g2") ? cmd.getOptionValues("g2") : new String[0]; addDatasets(firstGroupCmd, firstGroup, shortDataset, datasetAgg, path, fs, s3conf, s3, s3bucket); addDatasets(secondGroupCmd, secondGroup, shortDataset, datasetAgg, path, fs, s3conf, s3, s3bucket); if (shortDataset.size() == 0) { System.out.println("No datasets to process."); System.exit(0); } if (firstGroup.isEmpty()) { System.out.println("First group of datasets (G1) is empty. " + "Doing G1 = G2."); firstGroup.addAll(secondGroup); } if (secondGroup.isEmpty()) { System.out.println("Second group of datasets (G2) is empty. " + "Doing G2 = G1."); secondGroup.addAll(firstGroup); } // getting dataset ids String datasetNames = ""; String datasetIds = ""; HashMap<String, String> datasetId = new HashMap<String, String>(); Iterator<String> it = shortDataset.iterator(); while (it.hasNext()) { datasetId.put(it.next(), null); } if (s3) { path = new Path(s3bucket + FrameworkUtils.datasetsIndexDir); fs = FileSystem.get(path.toUri(), s3conf); } else { path = new Path(fs.getHomeDirectory() + "/" + FrameworkUtils.datasetsIndexDir); } BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(path))); String line = br.readLine(); while (line != null) { String[] dt = line.split("\t"); if (datasetId.containsKey(dt[0])) { datasetId.put(dt[0], dt[1]); datasetNames += dt[0] + ","; datasetIds += dt[1] + ","; } line = br.readLine(); } br.close(); if (s3) fs.close(); datasetNames = datasetNames.substring(0, datasetNames.length() - 1); datasetIds = datasetIds.substring(0, datasetIds.length() - 1); it = shortDataset.iterator(); while (it.hasNext()) { String dataset = it.next(); if (datasetId.get(dataset) == null) { System.out.println("No dataset id for " + dataset); System.exit(0); } } String firstGroupStr = ""; String secondGroupStr = ""; for (String dataset : firstGroup) { firstGroupStr += datasetId.get(dataset) + ","; } for (String dataset : secondGroup) { secondGroupStr += datasetId.get(dataset) + ","; } firstGroupStr = firstGroupStr.substring(0, firstGroupStr.length() - 1); secondGroupStr = secondGroupStr.substring(0, secondGroupStr.length() - 1); FrameworkUtils.createDir(s3bucket + FrameworkUtils.correlationTechniquesDir, s3conf, s3); String dataAttributesInputDirs = ""; String noRelationship = ""; HashSet<String> dirs = new HashSet<String>(); String dataset1; String dataset2; String datasetId1; String datasetId2; for (int i = 0; i < firstGroup.size(); i++) { for (int j = 0; j < secondGroup.size(); j++) { if (Integer.parseInt(datasetId.get(firstGroup.get(i))) < Integer .parseInt(datasetId.get(secondGroup.get(j)))) { dataset1 = firstGroup.get(i); dataset2 = secondGroup.get(j); } else { dataset1 = secondGroup.get(j); dataset2 = firstGroup.get(i); } datasetId1 = datasetId.get(dataset1); datasetId2 = datasetId.get(dataset2); if (dataset1.equals(dataset2)) continue; String correlationOutputFileName = s3bucket + FrameworkUtils.correlationTechniquesDir + "/" + dataset1 + "-" + dataset2 + "/"; if (removeExistingFiles) { FrameworkUtils.removeFile(correlationOutputFileName, s3conf, s3); } if (!FrameworkUtils.fileExists(correlationOutputFileName, s3conf, s3)) { dirs.add(s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset1); dirs.add(s3bucket + FrameworkUtils.aggregatesDir + "/" + dataset2); } else { noRelationship += datasetId1 + "-" + datasetId2 + ","; } } } if (dirs.isEmpty()) { System.out.println("All the relationships were already computed."); System.out.println("Use -f in the beginning of the command line to force the computation."); System.exit(0); } for (String dir : dirs) { dataAttributesInputDirs += dir + ","; } Configuration conf = new Configuration(); Machine machineConf = new Machine(machine, nbNodes); String jobName = "correlation"; String correlationOutputDir = s3bucket + FrameworkUtils.correlationTechniquesDir + "/tmp/"; FrameworkUtils.removeFile(correlationOutputDir, s3conf, s3); for (int i = 0; i < shortDataset.size(); i++) { conf.set("dataset-" + datasetId.get(shortDataset.get(i)) + "-agg", datasetAgg.get(shortDataset.get(i))); } for (int i = 0; i < shortDataset.size(); i++) { conf.set("dataset-" + datasetId.get(shortDataset.get(i)) + "-agg-size", Integer.toString(datasetAgg.get(shortDataset.get(i)).split(",").length)); } conf.set("dataset-keys", datasetIds); conf.set("dataset-names", datasetNames); conf.set("first-group", firstGroupStr); conf.set("second-group", secondGroupStr); conf.set("main-dataset-id", datasetId.get(shortDataset.get(0))); if (noRelationship.length() > 0) { conf.set("no-relationship", noRelationship.substring(0, noRelationship.length() - 1)); } conf.set("mapreduce.tasktracker.map.tasks.maximum", String.valueOf(machineConf.getMaximumTasks())); conf.set("mapreduce.tasktracker.reduce.tasks.maximum", String.valueOf(machineConf.getMaximumTasks())); conf.set("mapreduce.jobtracker.maxtasks.perjob", "-1"); conf.set("mapreduce.reduce.shuffle.parallelcopies", "20"); conf.set("mapreduce.input.fileinputformat.split.minsize", "0"); conf.set("mapreduce.task.io.sort.mb", "200"); conf.set("mapreduce.task.io.sort.factor", "100"); conf.set("mapreduce.task.timeout", "2400000"); if (s3) { machineConf.setMachineConfiguration(conf); conf.set("fs.s3.awsAccessKeyId", awsAccessKeyId); conf.set("fs.s3.awsSecretAccessKey", awsSecretAccessKey); conf.set("bucket", s3bucket); } if (snappyCompression) { conf.set("mapreduce.map.output.compress", "true"); conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); //conf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.SnappyCodec"); } if (bzip2Compression) { conf.set("mapreduce.map.output.compress", "true"); conf.set("mapreduce.map.output.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec"); //conf.set("mapreduce.output.fileoutputformat.compress.codec", "org.apache.hadoop.io.compress.BZip2Codec"); } Job job = new Job(conf); job.setJobName(jobName); job.setMapOutputKeyClass(PairAttributeWritable.class); job.setMapOutputValueClass(SpatioTemporalValueWritable.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); job.setMapperClass(CorrelationTechniquesMapper.class); job.setReducerClass(CorrelationTechniquesReducer.class); job.setNumReduceTasks(machineConf.getNumberReduces()); job.setInputFormatClass(SequenceFileInputFormat.class); LazyOutputFormat.setOutputFormatClass(job, TextOutputFormat.class); FileInputFormat.setInputDirRecursive(job, true); FileInputFormat.setInputPaths(job, dataAttributesInputDirs.substring(0, dataAttributesInputDirs.length() - 1)); FileOutputFormat.setOutputPath(job, new Path(correlationOutputDir)); job.setJarByClass(CorrelationTechniques.class); long start = System.currentTimeMillis(); job.submit(); job.waitForCompletion(true); System.out.println(jobName + "\t" + (System.currentTimeMillis() - start)); // moving files to right place for (int i = 0; i < firstGroup.size(); i++) { for (int j = 0; j < secondGroup.size(); j++) { if (Integer.parseInt(datasetId.get(firstGroup.get(i))) < Integer .parseInt(datasetId.get(secondGroup.get(j)))) { dataset1 = firstGroup.get(i); dataset2 = secondGroup.get(j); } else { dataset1 = secondGroup.get(j); dataset2 = firstGroup.get(i); } if (dataset1.equals(dataset2)) continue; String from = s3bucket + FrameworkUtils.correlationTechniquesDir + "/tmp/" + dataset1 + "-" + dataset2 + "/"; String to = s3bucket + FrameworkUtils.correlationTechniquesDir + "/" + dataset1 + "-" + dataset2 + "/"; FrameworkUtils.renameFile(from, to, s3conf, s3); } } }
From source file:com.aerospike.load.AerospikeLoad.java
public static void main(String[] args) throws IOException { Thread statPrinter = new Thread(new PrintStat(counters)); try {// www .j a v a 2s . c o m log.info("Aerospike loader started"); Options options = new Options(); options.addOption("h", "host", true, "Server hostname (default: localhost)"); options.addOption("p", "port", true, "Server port (default: 3000)"); options.addOption("n", "namespace", true, "Namespace (default: test)"); options.addOption("s", "set", true, "Set name. (default: null)"); options.addOption("c", "config", true, "Column definition file name"); options.addOption("wt", "write-threads", true, "Number of writer threads (default: Number of cores * 5)"); options.addOption("rt", "read-threads", true, "Number of reader threads (default: Number of cores * 1)"); options.addOption("l", "rw-throttle", true, "Throttling of reader to writer(default: 10k) "); options.addOption("tt", "transaction-timeout", true, "write transaction timeout in miliseconds(default: No timeout)"); options.addOption("et", "expiration-time", true, "Expiration time of records in seconds (default: never expire)"); options.addOption("T", "timezone", true, "Timezone of source where data dump is taken (default: local timezone)"); options.addOption("ec", "abort-error-count", true, "Error count to abort (default: 0)"); options.addOption("wa", "write-action", true, "Write action if key already exists (default: update)"); options.addOption("v", "verbose", false, "Logging all"); options.addOption("u", "usage", false, "Print usage."); CommandLineParser parser = new PosixParser(); CommandLine cl = parser.parse(options, args, false); if (args.length == 0 || cl.hasOption("u")) { logUsage(options); return; } if (cl.hasOption("l")) { rwThrottle = Integer.parseInt(cl.getOptionValue("l")); } else { rwThrottle = Constants.READLOAD; } // Get all command line options params = Utils.parseParameters(cl); //Get client instance AerospikeClient client = new AerospikeClient(params.host, params.port); if (!client.isConnected()) { log.error("Client is not able to connect:" + params.host + ":" + params.port); return; } if (params.verbose) { log.setLevel(Level.DEBUG); } // Get available processors to calculate default number of threads int cpus = Runtime.getRuntime().availableProcessors(); nWriterThreads = cpus * scaleFactor; nReaderThreads = cpus; // Get writer thread count if (cl.hasOption("wt")) { nWriterThreads = Integer.parseInt(cl.getOptionValue("wt")); nWriterThreads = (nWriterThreads > 0 ? (nWriterThreads > Constants.MAX_THREADS ? Constants.MAX_THREADS : nWriterThreads) : 1); log.debug("Using writer Threads: " + nWriterThreads); } writerPool = Executors.newFixedThreadPool(nWriterThreads); // Get reader thread count if (cl.hasOption("rt")) { nReaderThreads = Integer.parseInt(cl.getOptionValue("rt")); nReaderThreads = (nReaderThreads > 0 ? (nReaderThreads > Constants.MAX_THREADS ? Constants.MAX_THREADS : nReaderThreads) : 1); log.debug("Using reader Threads: " + nReaderThreads); } String columnDefinitionFileName = cl.getOptionValue("c", null); log.debug("Column definition files/directory: " + columnDefinitionFileName); if (columnDefinitionFileName == null) { log.error("Column definition files/directory not specified. use -c <file name>"); return; } File columnDefinitionFile = new File(columnDefinitionFileName); if (!columnDefinitionFile.exists()) { log.error("Column definition files/directory does not exist: " + Utils.getFileName(columnDefinitionFileName)); return; } // Get data file list String[] files = cl.getArgs(); if (files.length == 0) { log.error("No data file Specified: add <file/dir name> to end of the command "); return; } List<String> allFileNames = new ArrayList<String>(); allFileNames = Utils.getFileNames(files); if (allFileNames.size() == 0) { log.error("Given datafiles/directory does not exist"); return; } for (int i = 0; i < allFileNames.size(); i++) { log.debug("File names:" + Utils.getFileName(allFileNames.get(i))); File file = new File(allFileNames.get(i)); counters.write.recordTotal = counters.write.recordTotal + file.length(); } //remove column definition file from list allFileNames.remove(columnDefinitionFileName); log.info("Number of data files:" + allFileNames.size()); /** * Process column definition file to get meta data and bin mapping. */ metadataColumnDefs = new ArrayList<ColumnDefinition>(); binColumnDefs = new ArrayList<ColumnDefinition>(); metadataConfigs = new HashMap<String, String>(); if (Parser.processJSONColumnDefinitions(columnDefinitionFile, metadataConfigs, metadataColumnDefs, binColumnDefs, params)) { log.info("Config file processed."); } else { throw new Exception("Config file parsing Error"); } // Add metadata of config to parameters String metadata; if ((metadata = metadataConfigs.get(Constants.INPUT_TYPE)) != null) { params.fileType = metadata; if (params.fileType.equals(Constants.CSV_FILE)) { // Version check metadata = metadataConfigs.get(Constants.VERSION); String[] vNumber = metadata.split("\\."); int v1 = Integer.parseInt(vNumber[0]); int v2 = Integer.parseInt(vNumber[1]); if ((v1 <= Constants.MajorV) && (v2 <= Constants.MinorV)) { log.debug("Config version used:" + metadata); } else throw new Exception("\"" + Constants.VERSION + ":" + metadata + "\" is not Supported"); // Set delimiter if ((metadata = metadataConfigs.get(Constants.DELIMITER)) != null && metadata.length() == 1) { params.delimiter = metadata.charAt(0); } else { log.warn("\"" + Constants.DELIMITER + ":" + metadata + "\" is not properly specified in config file. Default is ','"); } if ((metadata = metadataConfigs.get(Constants.IGNORE_FIRST_LINE)) != null) { params.ignoreFirstLine = metadata.equals("true"); } else { log.warn("\"" + Constants.IGNORE_FIRST_LINE + ":" + metadata + "\" is not properly specified in config file. Default is false"); } if ((metadata = metadataConfigs.get(Constants.COLUMNS)) != null) { counters.write.colTotal = Integer.parseInt(metadata); } else { throw new Exception("\"" + Constants.COLUMNS + ":" + metadata + "\" is not properly specified in config file"); } } else { throw new Exception("\"" + params.fileType + "\" is not supported in config file"); } } else { throw new Exception("\"" + Constants.INPUT_TYPE + "\" is not specified in config file"); } // add config input to column definitions if (params.fileType.equals(Constants.CSV_FILE)) { List<String> binName = null; if (params.ignoreFirstLine) { String line; BufferedReader br = new BufferedReader( new InputStreamReader(new FileInputStream(allFileNames.get(0)), "UTF8")); if ((line = br.readLine()) != null) { binName = Parser.getCSVRawColumns(line, params.delimiter); br.close(); if (binName.size() != counters.write.colTotal) { throw new Exception("Number of column in config file and datafile are mismatch." + " Datafile: " + Utils.getFileName(allFileNames.get(0)) + " Configfile: " + Utils.getFileName(columnDefinitionFileName)); } } } //update columndefs for metadata for (int i = 0; i < metadataColumnDefs.size(); i++) { if (metadataColumnDefs.get(i).staticValue) { } else { if (metadataColumnDefs.get(i).binValuePos < 0) { if (metadataColumnDefs.get(i).columnName == null) { if (metadataColumnDefs.get(i).jsonPath == null) { log.error("dynamic metadata having improper info" + metadataColumnDefs.toString()); //TODO } else { //TODO check for json_path } } else { if (params.ignoreFirstLine) { if (binName.indexOf(metadataColumnDefs.get(i).binValueHeader) != -1) { metadataColumnDefs.get(i).binValuePos = binName .indexOf(metadataColumnDefs.get(i).binValueHeader); } else { throw new Exception("binName missing in data file:" + metadataColumnDefs.get(i).binValueHeader); } } } } else { if (params.ignoreFirstLine) metadataColumnDefs.get(i).binValueHeader = binName .get(metadataColumnDefs.get(i).binValuePos); } } if ((!metadataColumnDefs.get(i).staticValue) && (metadataColumnDefs.get(i).binValuePos < 0)) { throw new Exception("Information for bin mapping is missing in config file:" + metadataColumnDefs.get(i)); } if (metadataColumnDefs.get(i).srcType == null) { throw new Exception( "Source data type is not properly mentioned:" + metadataColumnDefs.get(i)); } if (metadataColumnDefs.get(i).binNameHeader == Constants.SET && !metadataColumnDefs.get(i).srcType.equals(SrcColumnType.STRING)) { throw new Exception("Set name should be string type:" + metadataColumnDefs.get(i)); } if (metadataColumnDefs.get(i).binNameHeader.equalsIgnoreCase(Constants.SET) && params.set != null) { throw new Exception( "Set name is given both in config file and commandline. Provide only once."); } } //update columndefs for bins for (int i = 0; i < binColumnDefs.size(); i++) { if (binColumnDefs.get(i).staticName) { } else { if (binColumnDefs.get(i).binNamePos < 0) { if (binColumnDefs.get(i).columnName == null) { if (binColumnDefs.get(i).jsonPath == null) { log.error("dynamic bin having improper info"); //TODO } else { //TODO check for json_path } } else { if (params.ignoreFirstLine) { if (binName.indexOf(binColumnDefs.get(i).binNameHeader) != -1) { binColumnDefs.get(i).binNamePos = binName .indexOf(binColumnDefs.get(i).binNameHeader); } else { throw new Exception("binName missing in data file:" + binColumnDefs.get(i).binNameHeader); } } } } else { if (params.ignoreFirstLine) binColumnDefs.get(i).binNameHeader = binName.get(binColumnDefs.get(i).binNamePos); } } if (binColumnDefs.get(i).staticValue) { } else { if (binColumnDefs.get(i).binValuePos < 0) { if (binColumnDefs.get(i).columnName == null) { if (binColumnDefs.get(i).jsonPath == null) { log.error("dynamic bin having improper info"); //TODO } else { //TODO check for json_path } } else { if (params.ignoreFirstLine) { if (binName.contains(binColumnDefs.get(i).binValueHeader)) { binColumnDefs.get(i).binValuePos = binName .indexOf(binColumnDefs.get(i).binValueHeader); } else if (!binColumnDefs.get(i).binValueHeader.toLowerCase() .equals(Constants.SYSTEM_TIME)) { throw new Exception("Wrong column name mentioned in config file:" + binColumnDefs.get(i).binValueHeader); } } } } else { if (params.ignoreFirstLine) binColumnDefs.get(i).binValueHeader = binName.get(binColumnDefs.get(i).binValuePos); } //check for missing entries in config file if (binColumnDefs.get(i).binValuePos < 0 && binColumnDefs.get(i).binValueHeader == null) { throw new Exception("Information missing(Value header or bin mapping) in config file:" + binColumnDefs.get(i)); } //check for proper data type in config file. if (binColumnDefs.get(i).srcType == null) { throw new Exception( "Source data type is not properly mentioned:" + binColumnDefs.get(i)); } //check for valid destination type if ((binColumnDefs.get(i).srcType.equals(SrcColumnType.TIMESTAMP) || binColumnDefs.get(i).srcType.equals(SrcColumnType.BLOB)) && binColumnDefs.get(i).dstType == null) { throw new Exception("Destination type is not mentioned: " + binColumnDefs.get(i)); } //check for encoding if (binColumnDefs.get(i).dstType != null && binColumnDefs.get(i).encoding == null) { throw new Exception( "Encoding is not given for src-dst type conversion:" + binColumnDefs.get(i)); } //check for valid encoding if (binColumnDefs.get(i).srcType.equals(SrcColumnType.BLOB) && !binColumnDefs.get(i).encoding.equals(Constants.HEX_ENCODING)) { throw new Exception("Wrong encoding for blob data:" + binColumnDefs.get(i)); } } //Check static bin name mapped to dynamic bin value if ((binColumnDefs.get(i).binNamePos == binColumnDefs.get(i).binValuePos) && (binColumnDefs.get(i).binNamePos != -1)) { throw new Exception("Static bin name mapped to dynamic bin value:" + binColumnDefs.get(i)); } //check for missing entries in config file if (binColumnDefs.get(i).binNameHeader == null && binColumnDefs.get(i).binNameHeader.length() > Constants.BIN_NAME_LENGTH) { throw new Exception("Information missing binName or large binName in config file:" + binColumnDefs.get(i)); } } } log.info(params.toString()); log.debug("MetadataConfig:" + metadataColumnDefs); log.debug("BinColumnDefs:" + binColumnDefs); // Start PrintStat thread statPrinter.start(); // Reader pool size ExecutorService readerPool = Executors.newFixedThreadPool( nReaderThreads > allFileNames.size() ? allFileNames.size() : nReaderThreads); log.info("Reader pool size : " + nReaderThreads); // Submit all tasks to writer threadpool. for (String aFile : allFileNames) { log.debug("Submitting task for: " + aFile); readerPool.submit(new AerospikeLoad(aFile, client, params)); } // Wait for reader pool to complete readerPool.shutdown(); log.info("Shutdown down reader thread pool"); while (!readerPool.isTerminated()) ; //readerPool.awaitTermination(20, TimeUnit.MINUTES); log.info("Reader thread pool terminated"); // Wait for writer pool to complete after getting all tasks from reader pool writerPool.shutdown(); log.info("Shutdown down writer thread pool"); while (!writerPool.isTerminated()) ; log.info("Writer thread pool terminated"); // Print final statistic of aerospike-loader. log.info("Final Statistics of importer: (Succesfull Writes = " + counters.write.writeCount.get() + ", " + "Errors=" + (counters.write.writeErrors.get() + counters.write.readErrors.get() + counters.write.processingErrors.get()) + "(" + (counters.write.writeErrors.get()) + "-Write," + counters.write.readErrors.get() + "-Read," + counters.write.processingErrors.get() + "-Processing)"); } catch (Exception e) { log.error(e); if (log.isDebugEnabled()) { e.printStackTrace(); } } finally { // Stop statistic printer thread. statPrinter.interrupt(); log.info("Aerospike loader completed"); } }
From source file:edu.ksu.cis.indus.staticanalyses.flow.instances.ofa.OFAXMLizerCLI.java
/** * The entry point to the program via command line. * /*from w w w. j av a 2 s . com*/ * @param args is the command line arguments. * @throws RuntimeException when object flow analysis fails. */ public static void main(final String[] args) { final Options _options = new Options(); Option _option = new Option("c", "cumulative", false, "Consider all root methods in the same execution."); _options.addOption(_option); _option = new Option("o", "output", true, "Directory into which xml files will be written into."); _option.setArgs(1); _options.addOption(_option); _option = new Option("j", "jimple", false, "Dump xmlized jimple."); _options.addOption(_option); _option = new Option("h", "help", false, "Display message."); _options.addOption(_option); _option = new Option("p", "soot-classpath", false, "Prepend this to soot class path."); _option.setArgs(1); _option.setArgName("classpath"); _option.setOptionalArg(false); _options.addOption(_option); _option = new Option("t", "ofa-type", false, "Type of analysis : fioi, fsoi, fios, fsos, fioirt, fsoirt."); _option.setArgs(1); _option.setArgName("type"); _option.setOptionalArg(false); _option.setRequired(true); _options.addOption(_option); _option = new Option("S", "scope", true, "The scope that should be analyzed."); _option.setArgs(1); _option.setArgName("scope"); _option.setRequired(false); _options.addOption(_option); final PosixParser _parser = new PosixParser(); try { final CommandLine _cl = _parser.parse(_options, args); if (_cl.hasOption("h")) { printUsage(_options); System.exit(1); } String _outputDir = _cl.getOptionValue('o'); if (_outputDir == null) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("Defaulting to current directory for output."); } _outputDir = "."; } if (_cl.getArgList().isEmpty()) { throw new MissingArgumentException("Please specify atleast one class."); } final OFAXMLizerCLI _cli = new OFAXMLizerCLI(); _cli.xmlizer.setXmlOutputDir(_outputDir); _cli.xmlizer.setGenerator(new UniqueJimpleIDGenerator()); _cli.setCumulative(_cl.hasOption('c')); _cli.setClassNames(_cl.getArgList()); _cli.type = _cl.getOptionValue('t'); if (_cl.hasOption('p')) { _cli.addToSootClassPath(_cl.getOptionValue('p')); } if (_cl.hasOption('S')) { _cli.setScopeSpecFile(_cl.getOptionValue('S')); } _cli.initialize(); _cli.<ITokens>execute(_cl.hasOption('j')); } catch (final ParseException _e) { LOGGER.error("Error while parsing command line.", _e); System.out.println("Error while parsing command line. \n" + _e); printUsage(_options); } catch (final Throwable _e) { LOGGER.error("Beyond our control. May day! May day!", _e); throw new RuntimeException(_e); } }
From source file:edu.msu.cme.rdp.classifier.train.ClassifierTraineeMaker.java
/** This is the main method to create training files from raw taxonomic information. * <p>// w ww . j a v a2 s.c o m * Usage: java ClassifierTraineeMaker tax_file rawseq.fa trainsetNo version version_modification output_directory. * See the ClassifierTraineeMaker constructor for more detail. * @param args * @throws FileNotFoundException * @throws IOException */ public static void main(String[] args) throws FileNotFoundException, IOException { String taxFile; String cnFile = null; String seqFile; int trainset_no = 1; String version = null; String modification = null; String outdir = null; try { CommandLine line = new PosixParser().parse(options, args); if (line.hasOption("t")) { taxFile = line.getOptionValue("t"); } else { throw new Exception("taxon file must be specified"); } if (line.hasOption("c")) { cnFile = line.getOptionValue("c"); } if (line.hasOption("s")) { seqFile = line.getOptionValue("s"); } else { throw new Exception("seq file must be specified"); } if (line.hasOption("n")) { try { trainset_no = Integer.parseInt(line.getOptionValue("n")); } catch (NumberFormatException ex) { throw new IllegalArgumentException("trainset_no needs to be an integer."); } } if (line.hasOption("o")) { outdir = line.getOptionValue("o"); } else { throw new Exception("output directory must be specified"); } if (line.hasOption("v")) { version = line.getOptionValue("v"); } if (line.hasOption("m")) { modification = line.getOptionValue("m"); } } catch (Exception e) { System.out.println("Command Error: " + e.getMessage()); new HelpFormatter().printHelp(120, "train", "", options, "", true); return; } ClassifierTraineeMaker maker = new ClassifierTraineeMaker(taxFile, seqFile, cnFile, trainset_no, version, modification, outdir); }
From source file:edu.msu.cme.rdp.kmer.cli.FastKmerFilter.java
public static void main(String[] args) throws Exception { final KmerSet<Set<RefKmer>> kmerSet; final SeqReader queryReader; final SequenceType querySeqType; final File queryFile; final KmerStartsWriter out; final boolean translQuery; final int wordSize; final int translTable; final boolean alignedSeqs; final List<String> refLabels = new ArrayList(); final int maxThreads; final int trieWordSize; try {//from www.ja va 2 s.c o m CommandLine cmdLine = new PosixParser().parse(options, args); args = cmdLine.getArgs(); if (args.length < 3) { throw new Exception("Unexpected number of arguments"); } if (cmdLine.hasOption("out")) { out = new KmerStartsWriter(cmdLine.getOptionValue("out")); } else { out = new KmerStartsWriter(System.out); } if (cmdLine.hasOption("aligned")) { alignedSeqs = true; } else { alignedSeqs = false; } if (cmdLine.hasOption("transl-table")) { translTable = Integer.valueOf(cmdLine.getOptionValue("transl-table")); } else { translTable = 11; } if (cmdLine.hasOption("threads")) { maxThreads = Integer.valueOf(cmdLine.getOptionValue("threads")); } else { maxThreads = Runtime.getRuntime().availableProcessors(); } queryFile = new File(args[1]); wordSize = Integer.valueOf(args[0]); SequenceType refSeqType = null; querySeqType = SeqUtils.guessSequenceType(queryFile); queryReader = new SequenceReader(queryFile); if (querySeqType == SequenceType.Protein) { throw new Exception("Expected nucl query sequences"); } refSeqType = SeqUtils .guessSequenceType(new File(args[2].contains("=") ? args[2].split("=")[1] : args[2])); translQuery = refSeqType == SequenceType.Protein; if (translQuery && wordSize % 3 != 0) { throw new Exception("Word size must be a multiple of 3 for nucl ref seqs"); } if (translQuery) { trieWordSize = wordSize / 3; } else { trieWordSize = wordSize; } kmerSet = new KmerSet<Set<RefKmer>>();//new KmerTrie(trieWordSize, translQuery); for (int index = 2; index < args.length; index++) { String refName; String refFileName = args[index]; if (refFileName.contains("=")) { String[] lexemes = refFileName.split("="); refName = lexemes[0]; refFileName = lexemes[1]; } else { String tmpName = new File(refFileName).getName(); if (tmpName.contains(".")) { refName = tmpName.substring(0, tmpName.lastIndexOf(".")); } else { refName = tmpName; } } File refFile = new File(refFileName); if (refSeqType != SeqUtils.guessSequenceType(refFile)) { throw new Exception( "Reference file " + refFile + " contains " + SeqUtils.guessFileFormat(refFile) + " sequences but expected " + refSeqType + " sequences"); } SequenceReader seqReader = new SequenceReader(refFile); Sequence seq; while ((seq = seqReader.readNextSequence()) != null) { if (seq.getSeqName().startsWith("#")) { continue; } KmerGenerator kmers; try { if (translQuery) { //protein ref kmers = new ProtKmerGenerator(seq.getSeqString(), trieWordSize, alignedSeqs); } else { kmers = new NuclKmerGenerator(seq.getSeqString(), trieWordSize, alignedSeqs); } while (kmers.hasNext()) { Kmer temp = kmers.next(); long[] next = temp.getLongKmers(); Set<RefKmer> refKmers = kmerSet.get(next); if (refKmers == null) { refKmers = new HashSet(); kmerSet.add(next, refKmers); } RefKmer kmerRef = new RefKmer(); kmerRef.modelPos = kmers.getPosition(); kmerRef.refFileIndex = refLabels.size(); kmerRef.refSeqid = seq.getSeqName(); refKmers.add(kmerRef); } } catch (IllegalArgumentException ex) { //System.err.println(seq.getSeqName()+ " " + ex.getMessage()); } } seqReader.close(); refLabels.add(refName); } } catch (Exception e) { new HelpFormatter().printHelp( "KmerSearch <kmerSize> <query_file> [name=]<ref_file> ...\nkmerSize should be multiple of 3, (recommend 45, minimum 30, maximum 63) ", options); e.printStackTrace(); System.exit(1); throw new RuntimeException("Stupid jvm"); //While this will never get thrown it is required to make sure javac doesn't get confused about uninitialized variables } long startTime = System.currentTimeMillis(); long seqCount = 0; final int maxTasks = 25000; System.err.println("Starting kmer mapping at " + new Date()); System.err.println("* Number of threads: " + maxThreads); System.err.println("* References: " + refLabels); System.err.println("* Reads file: " + queryFile); System.err.println("* Kmer length: " + trieWordSize); System.err.println("* Kmer Refset Size: " + kmerSet.size()); final AtomicInteger processed = new AtomicInteger(); final AtomicInteger outstandingTasks = new AtomicInteger(); ExecutorService service = Executors.newFixedThreadPool(maxThreads); Sequence querySeq; while ((querySeq = queryReader.readNextSequence()) != null) { seqCount++; String seqString = querySeq.getSeqString(); if ((!translQuery && seqString.length() < wordSize) || (translQuery && seqString.length() < wordSize + 2)) { //System.err.println(querySeq.getSeqName() + "\t" + seqString.length()); continue; } final Sequence threadSeq = querySeq; Runnable r = new Runnable() { public void run() { try { processSeq(threadSeq, refLabels, kmerSet, out, wordSize, translQuery, translTable, false); processSeq(threadSeq, refLabels, kmerSet, out, wordSize, translQuery, translTable, true); processed.incrementAndGet(); outstandingTasks.decrementAndGet(); } catch (Exception e) { e.printStackTrace(); } } }; outstandingTasks.incrementAndGet(); service.submit(r); while (outstandingTasks.get() >= maxTasks) ; if ((processed.get() + 1) % 1000000 == 0) { System.err.println("Processed " + processed + " sequences in " + (System.currentTimeMillis() - startTime) + " ms"); } } service.shutdown(); service.awaitTermination(1, TimeUnit.DAYS); System.err.println("Finished Processed " + processed + " sequences in " + (System.currentTimeMillis() - startTime) + " ms"); out.close(); }
From source file:com.netscape.cmstools.CMCSharedToken.java
public static void main(String args[]) throws Exception { boolean isVerificationMode = false; // developer debugging only Options options = createOptions();//from www .java 2 s.c o m CommandLine cmd = null; try { CommandLineParser parser = new PosixParser(); cmd = parser.parse(options, args); } catch (Exception e) { printError(e.getMessage()); System.exit(1); } if (cmd.hasOption("help")) { printHelp(); System.exit(0); } boolean verbose = cmd.hasOption("v"); String databaseDir = cmd.getOptionValue("d", "."); String passphrase = cmd.getOptionValue("s"); if (passphrase == null) { printError("Missing passphrase"); System.exit(1); } if (verbose) { System.out.println("passphrase String = " + passphrase); System.out.println("passphrase UTF-8 bytes = "); System.out.println(Arrays.toString(passphrase.getBytes("UTF-8"))); } String tokenName = cmd.getOptionValue("h"); String tokenPassword = cmd.getOptionValue("p"); String issuanceProtCertFilename = cmd.getOptionValue("b"); String issuanceProtCertNick = cmd.getOptionValue("n"); String output = cmd.getOptionValue("o"); try { CryptoManager.initialize(databaseDir); CryptoManager manager = CryptoManager.getInstance(); CryptoToken token = CryptoUtil.getKeyStorageToken(tokenName); tokenName = token.getName(); manager.setThreadToken(token); Password password = new Password(tokenPassword.toCharArray()); token.login(password); X509Certificate issuanceProtCert = null; if (issuanceProtCertFilename != null) { if (verbose) System.out.println("Loading issuance protection certificate"); String encoded = new String(Files.readAllBytes(Paths.get(issuanceProtCertFilename))); byte[] issuanceProtCertData = Cert.parseCertificate(encoded); issuanceProtCert = manager.importCACertPackage(issuanceProtCertData); if (verbose) System.out.println("issuance protection certificate imported"); } else { // must have issuance protection cert nickname if file not provided if (verbose) System.out.println("Getting cert by nickname: " + issuanceProtCertNick); if (issuanceProtCertNick == null) { System.out.println( "Invallid command: either nickname or PEM file must be provided for Issuance Protection Certificate"); System.exit(1); } issuanceProtCert = getCertificate(tokenName, issuanceProtCertNick); } EncryptionAlgorithm encryptAlgorithm = EncryptionAlgorithm.AES_128_CBC_PAD; KeyWrapAlgorithm wrapAlgorithm = KeyWrapAlgorithm.RSA; if (verbose) System.out.println("Generating session key"); SymmetricKey sessionKey = CryptoUtil.generateKey(token, KeyGenAlgorithm.AES, 128, null, true); if (verbose) System.out.println("Encrypting passphrase"); byte iv[] = { 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 }; byte[] secret_data = CryptoUtil.encryptUsingSymmetricKey(token, sessionKey, passphrase.getBytes("UTF-8"), encryptAlgorithm, new IVParameterSpec(iv)); if (verbose) System.out.println("Wrapping session key with issuance protection cert"); byte[] issuanceProtWrappedSessionKey = CryptoUtil.wrapUsingPublicKey(token, issuanceProtCert.getPublicKey(), sessionKey, wrapAlgorithm); // final_data takes this format: // SEQUENCE { // encryptedSession OCTET STRING, // encryptedPrivate OCTET STRING // } DerOutputStream tmp = new DerOutputStream(); tmp.putOctetString(issuanceProtWrappedSessionKey); tmp.putOctetString(secret_data); DerOutputStream out = new DerOutputStream(); out.write(DerValue.tag_Sequence, tmp); byte[] final_data = out.toByteArray(); String final_data_b64 = Utils.base64encode(final_data, true); if (final_data_b64 != null) { System.out.println("\nEncrypted Secret Data:"); System.out.println(final_data_b64); } else System.out.println("Failed to produce final data"); if (output != null) { System.out.println("\nStoring Base64 secret data into " + output); try (FileWriter fout = new FileWriter(output)) { fout.write(final_data_b64); } } if (isVerificationMode) { // developer use only PrivateKey wrappingKey = null; if (issuanceProtCertNick != null) wrappingKey = (org.mozilla.jss.crypto.PrivateKey) getPrivateKey(tokenName, issuanceProtCertNick); else wrappingKey = CryptoManager.getInstance().findPrivKeyByCert(issuanceProtCert); System.out.println("\nVerification begins..."); byte[] wrapped_secret_data = Utils.base64decode(final_data_b64); DerValue wrapped_val = new DerValue(wrapped_secret_data); // val.tag == DerValue.tag_Sequence DerInputStream wrapped_in = wrapped_val.data; DerValue wrapped_dSession = wrapped_in.getDerValue(); byte wrapped_session[] = wrapped_dSession.getOctetString(); System.out.println("wrapped session key retrieved"); DerValue wrapped_dPassphrase = wrapped_in.getDerValue(); byte wrapped_passphrase[] = wrapped_dPassphrase.getOctetString(); System.out.println("wrapped passphrase retrieved"); SymmetricKey ver_session = CryptoUtil.unwrap(token, SymmetricKey.AES, 128, SymmetricKey.Usage.UNWRAP, wrappingKey, wrapped_session, wrapAlgorithm); byte[] ver_passphrase = CryptoUtil.decryptUsingSymmetricKey(token, new IVParameterSpec(iv), wrapped_passphrase, ver_session, encryptAlgorithm); String ver_spassphrase = new String(ver_passphrase, "UTF-8"); CryptoUtil.obscureBytes(ver_passphrase, "random"); System.out.println("ver_passphrase String = " + ver_spassphrase); System.out.println("ver_passphrase UTF-8 bytes = "); System.out.println(Arrays.toString(ver_spassphrase.getBytes("UTF-8"))); if (ver_spassphrase.equals(passphrase)) System.out.println("Verification success!"); else System.out.println("Verification failure! ver_spassphrase=" + ver_spassphrase); } } catch (Exception e) { if (verbose) e.printStackTrace(); printError(e.getMessage()); System.exit(1); } }
From source file:de.tudarmstadt.ukp.teaching.uima.nounDecompounding.evaluation.CouchDbExport.java
@SuppressWarnings("static-access") public static void main(String[] args) { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("host") .withDescription("(optional) The couchdb host. default: 127.0.0.1").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("port") .withDescription("(optional) The couchdb port. default: 5984").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("username") .withDescription("(optional) The couchdb username. default: <empty>").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("password") .withDescription("(optional) The couchdb password. default: <empty>").hasArg().create()); options.addOption(OptionBuilder.withLongOpt("dbname") .withDescription("(optional) The couchdb database name. default: noun_decompounding").hasArg() .create());/*from w w w .j a va 2 s.co m*/ options.addOption(OptionBuilder.withLongOpt("limit") .withDescription("(optional) The amount of documents you want to export. default: all").hasArg() .create()); CommandLineParser parser = new PosixParser(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("countTotalFreq", options); return; } String host = (cmd.hasOption("host")) ? cmd.getOptionValue("host") : "127.0.0.1"; int port = Integer.parseInt((cmd.hasOption("port")) ? cmd.getOptionValue("port") : "5984"); String username = (cmd.hasOption("username")) ? cmd.getOptionValue("username") : ""; String password = (cmd.hasOption("password")) ? cmd.getOptionValue("password") : ""; String dbName = (cmd.hasOption("dbname")) ? cmd.getOptionValue("dbname") : ""; int limit = (cmd.hasOption("limit")) ? Integer.parseInt(cmd.getOptionValue("limit")) : Integer.MAX_VALUE; IDictionary dict = new IGerman98Dictionary(new File("src/main/resources/de_DE.dic"), new File("src/main/resources/de_DE.aff")); LinkingMorphemes morphemes = new LinkingMorphemes(new File("src/main/resources/linkingMorphemes.txt")); LeftToRightSplitAlgorithm algo = new LeftToRightSplitAlgorithm(dict, morphemes); HttpClient httpClient = new StdHttpClient.Builder().host(host).port(port).username(username) .password(password).build(); CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient); CouchDbConnector db = new StdCouchDbConnector(dbName, dbInstance); try { CouchDbExport exporter = new CouchDbExport( new CcorpusReader(new File("src/main/resources/evaluation/ccorpus.txt")), db); exporter.export(algo, limit); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:at.peppol.smp.client.console.SMPClient.java
public static void main(final String[] args) throws Exception { if (false) {//from w w w .j a va2s. com // Enable this section in development mode, if you want to trust all HTTPS // certificates final SSLContext aSSLContext = SSLContext.getInstance("SSL"); aSSLContext.init(null, new TrustManager[] { new DoNothingTrustManager() }, VerySecureRandom.getInstance()); HttpsURLConnection.setDefaultSSLSocketFactory(aSSLContext.getSocketFactory()); } final SMPClientOptions aOptions = new SMPClientOptions(); final CommandLine cmd = new PosixParser().parse(aOptions, args); ECommand eAction = null; boolean bGoodCmd = true; String cert = null; if (!cmd.hasOption("h")) { s_aLogger.error("No Host specified use -h to specify Host"); bGoodCmd = false; } if (!cmd.hasOption("u")) { s_aLogger.error("No Username specified use -u to specify username"); bGoodCmd = false; } if (!cmd.hasOption("p")) { s_aLogger.error("No Password specified use -p to specify password"); bGoodCmd = false; } if (!cmd.hasOption("c")) { s_aLogger.error("No Action specified please use -c parameter to specify command(" + ECommand.getAllAsString() + ")"); bGoodCmd = false; } else { final String sCommand = cmd.getOptionValue("c"); eAction = ECommand.getFromNameOrNull(sCommand); if (eAction == null) { s_aLogger.error("Illegal Action specified:" + sCommand + " allowed commands(" + ECommand.getAllAsString() + ")"); bGoodCmd = false; } else switch (eAction) { case ADDGROUP: if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } break; case DELGROUP: if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } break; case ADD: if (!cmd.hasOption("a")) { s_aLogger.error("No Accesspoint URL defined use -a to Specifify AP-URL"); bGoodCmd = false; } if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } if (!cmd.hasOption("d")) { s_aLogger.error("No DocumentType ID specified use -d to specify Document Type ID"); bGoodCmd = false; } if (!cmd.hasOption("r")) { s_aLogger.error("No Process ID specified use -r to specify Process ID"); bGoodCmd = false; } if (!cmd.hasOption("e")) { s_aLogger.error("No Certificate PEM file specified use -e to specify Certificate PEM file"); bGoodCmd = false; } else { cert = SimpleFileIO.readFileAsString(new File(cmd.getOptionValue('e')), CCharset.CHARSET_ISO_8859_1); } break; case DEL: if (!cmd.hasOption("b")) { s_aLogger.error( "No Business/Participant ID specified use -b to specify Business/Participant ID"); bGoodCmd = false; } if (!cmd.hasOption("d")) { s_aLogger.error("No Document Type ID specified use -d to specify Document Type ID"); bGoodCmd = false; } } } if (!bGoodCmd) { final NonBlockingStringWriter aSW = new NonBlockingStringWriter(); new HelpFormatter().printHelp(new PrintWriter(aSW), HelpFormatter.DEFAULT_WIDTH, CGStringHelper.getClassLocalName(SMPClient.class), null, aOptions, HelpFormatter.DEFAULT_LEFT_PAD, HelpFormatter.DEFAULT_DESC_PAD, null); s_aLogger.info(aSW.getAsString()); System.exit(-3); } final SMPClient client = new SMPClient(new URI(cmd.getOptionValue('h')), cmd.getOptionValue('u'), cmd.getOptionValue('p'), cmd.getOptionValue('b'), cmd.getOptionValue('d'), cmd.getOptionValue('r'), cmd.getOptionValue('a'), cert); switch (eAction) { case ADDGROUP: client._createServiceGroup(); break; case DELGROUP: client._deleteServiceGroup(); break; case ADD: client._addDocument(); break; case DEL: client._deleteDocument(); break; case LIST: client._listDocuments(); break; default: throw new IllegalStateException(); } }