Package joptsimple

Examples of joptsimple.OptionSet


        printUsage();
        Utils.croak("\n" + errMessage);
    }

    private static OptionSet getValidOptions(String[] args) {
        OptionSet options = null;
        try {
            options = parser.parse(args);
        } catch(OptionException oe) {
            printUsageAndDie("Exception when parsing arguments : " + oe.getMessage());
        }

        if(options.has("help")) {
            printUsage();
            System.exit(0);
        }

        Set<String> missing = CmdUtils.missing(options,
View Full Code Here


        return options;
    }

    public static void main(String[] args) throws Exception {
        setupParser();
        OptionSet options = getValidOptions(args);

        int dropZoneId = CmdUtils.valueOf(options, "drop-zoneid", Zone.UNSET_ZONE_ID);
        String outputDir = null;
        if(options.has("output-dir")) {
            outputDir = (String) options.valueOf("output-dir");
        }

        /*
         * A. Generate the clipped cluster.xml
         */
        String initialClusterXML = (String) options.valueOf("current-cluster");
        Cluster initialCluster = new ClusterMapper().readCluster(new File(initialClusterXML));

        // Create a list of current partition ids. We will use this set to
        // compare partitions ids in final cluster
        Set<Integer> originalPartitions = new HashSet<Integer>();
        for(Integer zoneId: initialCluster.getZoneIds()) {
            originalPartitions.addAll(initialCluster.getPartitionIdsInZone(zoneId));
        }

        // Get an intermediate cluster where parititions that belong to the zone
        // that is being dropped have been moved to the existing zones
        Cluster intermediateCluster = RebalanceUtils.vacateZone(initialCluster, dropZoneId);
        Cluster finalCluster = RebalanceUtils.dropZone(intermediateCluster, dropZoneId);

        // Make sure everything is fine
        if(initialCluster.getNumberOfPartitions() != finalCluster.getNumberOfPartitions()) {
            logger.error("The number of partitions in the initial and the final cluster is not equal \n");
        }

        Set<Integer> finalPartitions = new HashSet<Integer>();
        for(Integer zoneId: finalCluster.getZoneIds()) {
            finalPartitions.addAll(finalCluster.getPartitionIdsInZone(zoneId));
        }

        // Compare to original partition ids list
        if(!originalPartitions.equals(finalPartitions)) {
            logger.error("The list of partition ids in the initial and the final cluster doesn't match \n ");
        }

        // Finally write the final cluster to a xml file
        RebalanceUtils.dumpClusterToFile(outputDir,
                                         RebalanceUtils.finalClusterFileName,
                                         finalCluster);

        /*
         * B. Generate the clipped stores.xml
         */
        logger.info("Generating the adjusted stores.xml..");
        String initialStoresXML = (String) options.valueOf("current-stores");
        List<StoreDefinition> initialStoreDefs = new StoreDefinitionsMapper().readStoreList(new File(initialStoresXML));
        List<StoreDefinition> finalStoreDefs = RebalanceUtils.dropZone(initialStoreDefs, dropZoneId);
        RebalanceUtils.dumpStoreDefsToFile(outputDir,
                                           RebalanceUtils.finalStoresFileName,
                                           finalStoreDefs);
View Full Code Here

                        .withOptionalArg().ofType(Boolean.class)
                        .defaultsTo(Boolean.FALSE);
        OptionSpec<File> csvFile = parser.accepts("csvFile", "File to write a CSV version of the benchmark data.")
                .withOptionalArg().ofType(File.class);

        OptionSet options = parser.parse(args);
        int cacheSize = cache.value(options);
        RepositoryFixture[] allFixtures = new RepositoryFixture[] {
                new JackrabbitRepositoryFixture(
                        base.value(options), cacheSize),
                OakRepositoryFixture.getMemory(cacheSize * MB),
                OakRepositoryFixture.getDefault(
                        base.value(options), cacheSize * MB),
                OakRepositoryFixture.getMongo(
                        host.value(options), port.value(options),
                        dbName.value(options), dropDBAfterTest.value(options),
                        cacheSize * MB),
                OakRepositoryFixture.getMongoNS(
                        host.value(options), port.value(options),
                        dbName.value(options), dropDBAfterTest.value(options),
                        cacheSize * MB),
                OakRepositoryFixture.getMongoMK(
                        host.value(options), port.value(options),
                        dbName.value(options), dropDBAfterTest.value(options),
                        cacheSize * MB),
                OakRepositoryFixture.getSegment(
                        host.value(options), port.value(options), cacheSize),
                OakRepositoryFixture.getTar(
                        base.value(options), 256, cacheSize, mmap.value(options))
        };
        Benchmark[] allBenchmarks = new Benchmark[] {
            new LoginTest(),
            new LoginLogoutTest(),
            new NamespaceTest(),
            new NamespaceRegistryTest(),
            new ReadPropertyTest(),
            GetNodeTest.withAdmin(),
            GetNodeTest.withAnonymous(),
            new GetDeepNodeTest(),
            new SetPropertyTest(),
            new SmallFileReadTest(),
            new SmallFileWriteTest(),
            new ConcurrentReadTest(),
            new ConcurrentReadWriteTest(),
            new ConcurrentWriteReadTest(),
            new ConcurrentWriteTest(),
            new SimpleSearchTest(),
            new SQL2SearchTest(),
            new DescendantSearchTest(),
            new SQL2DescendantSearchTest(),
            new CreateManyChildNodesTest(),
            new CreateManyNodesTest(),
            new UpdateManyChildNodesTest(),
            new TransientManyChildNodesTest(),
            new WikipediaImport(wikipedia.value(options)),
            new CreateNodesBenchmark(),
            new ManyNodes(),
            new ObservationTest(),
            new XmlImportTest(),
            new FlatTreeWithAceForSamePrincipalTest(),
            new ReadDeepTreeTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options)),
            new ConcurrentReadDeepTreeTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options)),
            new ConcurrentReadSinglePolicyTreeTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options)),
            new ConcurrentReadAccessControlledTreeTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options)),
            new ConcurrentReadAccessControlledTreeTest2(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options)),
            new ConcurrentReadRandomNodeAndItsPropertiesTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options)),
            new ManyUserReadTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options),
                    randomUser.value(options)),
            new ConcurrentTraversalTest(
                    runAsAdmin.value(options),
                    itemsToRead.value(options),
                    report.value(options),
                    randomUser.value(options)),
            ReadManyTest.linear("LinearReadEmpty", 1, ReadManyTest.EMPTY),
            ReadManyTest.linear("LinearReadFiles", 1, ReadManyTest.FILES),
            ReadManyTest.linear("LinearReadNodes", 1, ReadManyTest.NODES),
            ReadManyTest.uniform("UniformReadEmpty", 1, ReadManyTest.EMPTY),
            ReadManyTest.uniform("UniformReadFiles", 1, ReadManyTest.FILES),
            ReadManyTest.uniform("UniformReadNodes", 1, ReadManyTest.NODES),
            new ConcurrentCreateNodesTest(),
            new SequentialCreateNodesTest(),
        };

        Set<String> argset = Sets.newHashSet(options.nonOptionArguments());
        List<RepositoryFixture> fixtures = Lists.newArrayList();
        for (RepositoryFixture fixture : allFixtures) {
            if (argset.remove(fixture.toString())) {
                fixtures.add(fixture);
            }
        }

        List<Benchmark> benchmarks = Lists.newArrayList();
        for (Benchmark benchmark : allBenchmarks) {
            if (argset.remove(benchmark.toString())) {
                benchmarks.add(benchmark);
            }
        }

        if (argset.isEmpty()) {
            PrintStream out = null;
            if (options.has(csvFile)) {
                out = new PrintStream(FileUtils.openOutputStream(csvFile.value(options), true));
            }
            for (Benchmark benchmark : benchmarks) {
                if (benchmark instanceof CSVResultGenerator) {
                    ((CSVResultGenerator) benchmark).setPrintStream(out);
                }
                benchmark.run(fixtures, options.valuesOf(concurrency));
            }
            if (out != null) {
                out.close();
            }
        } else {
View Full Code Here

  }

  @Override
  public int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args) throws Exception {
    OptionSet optionSet = parser.parse(args.toArray(new String[args.size()]));

    if (!optionSet.nonOptionArguments().isEmpty()) {
      printUsage(err);
      return -1;
    }

    try {
View Full Code Here

    //cmdLineParser.addPartNameOption();
    cmdLineParser.addHelpOption();
    cmdLineParser.accepts(PRINT_HEADER_OPTION, PRINT_HEADER_OPTION_HELP);
    cmdLineParser.accepts(PRINT_XML_OPTION, PRINT_XML_OPTION_HELP);

    OptionSet options = cmdLineParser.parseArgumentsExitOnError(args);

    //
    BitstreamOptionParser.printExecutableHeaderMessage(NonEmptyFrames.class);
   
    /////////////////////////////////////////////////////////////////////
    // Begin basic command line parsing
    /////////////////////////////////////////////////////////////////////   
    cmdLineParser.checkHelpOptionExitOnHelpMessage(options);
   
    /////////////////////////////////////////////////////////////////////
    // 1. Parse bitstream
    /////////////////////////////////////////////////////////////////////
    Bitstream bitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, true);
   
    //int printLevel = 1;
   
    // header only
    if (options.has(PRINT_HEADER_OPTION)) {
      System.out.println(bitstream.getHeader().toString());
      System.exit(1);
    }
    // print XML
    if (options.has(PRINT_XML_OPTION)) {
      System.out.println(bitstream.toXMLString());
      System.exit(1);     
    }
    // Print full bitstream
    PrintWriter pw = new PrintWriter(System.out);
View Full Code Here

    cmdLineParser.accepts("r","Name of operational bitfile").withRequiredArg().ofType(String.class);
    cmdLineParser.accepts(NEW_ALGORITHM, "Use new algorithms for bit manipulation");
    cmdLineParser.accepts(APPEND_OPTION_STRING, APPEND_OPTION_STRING_HELP);
   
    // Parse arguments
    OptionSet options = cmdLineParser.parseArgumentsExitOnError(args);
    // Print executable header
    BitstreamOptionParser.printExecutableHeaderMessage(BitstreamManipulation.class);
    // Check for and print help
    cmdLineParser.checkHelpOptionExitOnHelpMessage(options);
    DEBUG = cmdLineParser.debugEnabled(options);
   
    /////////////////////////////////////////////////////////////////////
    // 1. Parse bitstream
    /////////////////////////////////////////////////////////////////////
    Bitstream bitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, true);
   
    /////////////////////////////////////////////////////////////////////
    // 2. Obtain part information
    /////////////////////////////////////////////////////////////////////
    XilinxConfigurationSpecification partInfo = cmdLineParser.getPartInfoExitOnError(options, bitstream, true);
   
    // 3. Create FPGA object
    FPGA fpga = new FPGA(partInfo);   
    // Configure FPGA
    fpga.configureBitstream(bitstream);
   
    String outputBitstreamFileName = cmdLineParser.getOutputFileNameStringExitOnError(options);
   
    /////////////////////////////////////////////////////////////////////
    // Perform Bitstreams Operations
    /////////////////////////////////////////////////////////////////////

    if (options.has(XOR_STRING) || options.has(OVERWRITE_STRING) ||options.has(CLEAR_STRING) ||
        options.has(AND_STRING) ||options.has(NOT_STRING) ||options.has(OR_STRING)
        || options.has(APPEND_OPTION_STRING)) {

      if (!options.has("r")) {
        System.err.println("Operational bitfile name needed for bitstream operation");
        cmdLineParser.printUsageAndExit();
      }
      String operationalBitstreamFileName = (String) options.valueOf("r");
     
      // load operational bitstream (this is an odd way of doing it but I am copying Ben's code)
      Bitstream opBitstream = BitstreamParser.parseBitstreamExitOnError(operationalBitstreamFileName);     
      System.out.print("Successfully loaded operational bitstream - ");
     
      // TODO: Make sure the two bitstreams are the same size. Same part?     
      FPGA fpga2 = new FPGA(partInfo);
      fpga2.configureBitstream(opBitstream);

     
      if(options.has(XOR_STRING))
      {
        FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.XOR );
        System.out.println("XOR operation performed"); // use this to find differences in BRAM data.
      }
      else if(options.has(AND_STRING))
      {
        FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.AND );
        System.out.println("AND operation performed");
      }
      else if(options.has(OR_STRING))
      {
        FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.OR );
        System.out.println("OR operation performed");
      }
      else if(options.has(NOT_STRING))
      {
        FPGAOperation.operation(fpga, fpga2, FPGAOperation.OPERATORS.NOT );
        System.out.println("NOT operation performed");
      }
      else if(options.has(OVERWRITE_STRING))
      {
        fpga.configureBitstream(opBitstream);
        System.out.println("Overwrite operation performed");
      }
      else if(options.has(CLEAR_STRING))
      { 
        // Find all of the frames that are configured on fpga2
        ArrayList<Frame> fpga2configuredFrames = fpga2.getConfiguredFrames();
       
        // Clear all the corresponding frames on fpga1
        for (Frame fd : fpga2configuredFrames) {
          fd.clear();
        }
        System.out.println("Clear operation performed\n");
      }
      else if(options.has(APPEND_OPTION_STRING)) {
        // Append the packets of the operational bitstream to the packets of the original bitstream
        PacketList opPackets = opBitstream.getPackets();
        PacketList inPackets = bitstream.getPackets();
        inPackets.addAll(opPackets);
        if (writeBitstreamToBIT(bitstream, outputBitstreamFileName) == 0) {
          System.out.println("Generated BRAM Bitstream:"+outputBitstreamFileName);
        } else {
          System.err.println("Problem generating BRAM bitstream");
          System.exit(1);
        }       

        System.out.println("Append operation performed");
      }
    }
       
    /////////////////////////////////////////////////////////////////////
    // Perform Bitstreams Write Operations
    /////////////////////////////////////////////////////////////////////

    // create the bitstream
    Bitstream newBitstream = null;
    BitstreamHeader newHeader = null;

   

    if (options.has(NEW_ALGORITHM)) {
      // TODO
      // for the new algorithm, create a new header with different values
      newHeader = bitstream.getHeader();
    } else {
      // for the old algorithm, copy the header from the original bitstream
      newHeader = bitstream.getHeader();
    }
   
    // BRAM operation   
    if (options.has(BRAM_OPTION_STRING)) {
      if (options.has(NEW_ALGORITHM)) {
        // New algorithm
        System.err.println("New Algorithm not yet supported");
        System.exit(1);
      } else {
        // Use old algorithm
        newBitstream = partInfo.getBitstreamGenerator().createPartialBRAMBitstream(fpga, newHeader);
      }
      if (writeBitstreamToBIT(newBitstream, outputBitstreamFileName) == 0) {
        System.out.println("Generated BRAM Bitstream:"+outputBitstreamFileName);
      } else {
        System.err.println("Problem generating BRAM bitstream");
        System.exit(1);
      }       
    }
   
    // PARTIAL operation
    if (options.has(PARTIAL_OPTION_STRING)) {
      if (newBitstream != null) {
        System.err.println("Only one write can be performed.");
        System.exit(1);
      }
      if (options.has(NEW_ALGORITHM)) {
        // New algorithm (currently same as old algorithm)
        newBitstream = partInfo.getBitstreamGenerator().createPartialBitstream(fpga, newHeader);
      } else {
        // Use old algorithm
        newBitstream = partInfo.getBitstreamGenerator().createPartialBitstream(fpga, newHeader);
      }
      if (writeBitstreamToBIT(newBitstream, outputBitstreamFileName) == 0) {
        System.out.println("Generated Partial Bitstream:"+outputBitstreamFileName);
      } else {
        System.err.println("Problem generating Partial bitstream");
        System.exit(1);
      }       

    }

    if (options.has(FULL_OPTION_STRING)) {
      if (newBitstream != null) {
        System.err.println("Only one write can be performed. Option -f ignored");
        System.exit(1);
      }
      newBitstream = partInfo.getBitstreamGenerator().createFullBitstream(fpga, bitstream.getHeader());
      if (writeBitstreamToBIT(newBitstream, outputBitstreamFileName) == 0) {
        System.out.println("Generated Full Bitstream:"+outputBitstreamFileName);
      } else {
        System.err.println("Problem generating Full bitstream");
        System.exit(1);
      }       
    }

    if (options.has(CONDENSE_OPTION_STRING)) {
      if (newBitstream != null) {
        System.err.println("Only one write can be performed. Option -t ignored");
        System.exit(1);
      }
      // TODO
View Full Code Here

    cmdLineParser.addInputBitstreamOption();
    cmdLineParser.addPartNameOption();
    cmdLineParser.addHelpOption();
    cmdLineParser.accepts(PRINT_ALL_FRAMES, "Prints all frames");
   
    OptionSet options = cmdLineParser.parseArgumentsExitOnError(args);

    cmdLineParser.checkHelpOptionExitOnHelpMessage(options);

    BitstreamOptionParser.printExecutableHeaderMessage(FrameWriteSummary.class);

    Bitstream bitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, true);

    XilinxConfigurationSpecification partInfo = cmdLineParser.getPartInfoExitOnError(options, bitstream, true)

    boolean printAllFrames =(options.has(PRINT_ALL_FRAMES));

    // Get part packets
    PacketList packets = bitstream.getPackets();
    Iterator<Packet> p = packets.iterator();
View Full Code Here

    cmdLineParser.accepts(SILENT_MODE_OPTION,
        SILENT_MODE_OPTION_HELP);
    cmdLineParser.accepts(PRINT_DATA_OPTION,
        PRINT_DATA_OPTION_HELP);

    OptionSet options = cmdLineParser.parseArgumentsExitOnError(args);

    //
    BitstreamOptionParser.printExecutableHeaderMessage(BitstreamDiff.class);
   
    /////////////////////////////////////////////////////////////////////
    // Begin basic command line parsing
    /////////////////////////////////////////////////////////////////////   
    cmdLineParser.checkHelpOptionExitOnHelpMessage(options);
   
    boolean ignoreUnconfiguredFrames =
      options.has(IGNORE_UNCONFIGURED_FRAMES_OPTION);
    boolean silentMode =
      options.has(SILENT_MODE_OPTION);
    boolean printData = options.has(PRINT_DATA_OPTION);
   
    /////////////////////////////////////////////////////////////////////
    // 1. Get base FPGA object
    /////////////////////////////////////////////////////////////////////
    FPGA fpga1 = null;   
View Full Code Here

    cmdLineParser.addInputBitstreamOption();
    cmdLineParser.addPartNameOption();
    cmdLineParser.addHelpOption();
    cmdLineParser.accepts(PRINT_DETAIL, "Prints all details");

    OptionSet options = cmdLineParser.parseArgumentsExitOnError(args);

    BitstreamOptionParser.printExecutableHeaderMessage(NonEmptyFrames.class);
   
    /////////////////////////////////////////////////////////////////////
    // Begin basic command line parsing
    /////////////////////////////////////////////////////////////////////   
    cmdLineParser.checkHelpOptionExitOnHelpMessage(options);
   
    /////////////////////////////////////////////////////////////////////
    // 1. Parse bitstream
    /////////////////////////////////////////////////////////////////////
    Bitstream bitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, true);
   
    /////////////////////////////////////////////////////////////////////
    // 2. Obtain part information
    /////////////////////////////////////////////////////////////////////
    XilinxConfigurationSpecification partInfo = cmdLineParser.getPartInfoExitOnError(options, bitstream, true);
   
    boolean printDetail =(options.has(PRINT_DETAIL));

   
    // Create FPGA object
    FPGA fpga = new FPGA(partInfo);   
    // Configure FPGA
View Full Code Here

    String PATCH_PARTIAL = "patchPartial";
    cmdLineParser.accepts(PATCH_PARTIAL,"Changes will be made in the partial, not static").withRequiredArg().ofType(String.class);

    // Parse arguments
    OptionSet options = cmdLineParser.parseArgumentsExitOnError(args);
    // Print executable header
    BitstreamOptionParser.printExecutableHeaderMessage(BitstreamManipulation.class);
    // Check for and print help
    cmdLineParser.checkHelpOptionExitOnHelpMessage(options);

    // Get bitstreams
    Bitstream fullBitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, FULL_OPTION,
        true);   
    Bitstream staticBitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, STATIC_OPTION,
        true);   
    Bitstream partialBitstream = cmdLineParser.parseRequiredBitstreamFromOptionsExitOnError(options, PARTIAL_OPTION,
        true);   
   
    boolean patchPartial = false;
    if (options.has(PATCH_PARTIAL))
      patchPartial = true;
   
    boolean verbose = false;
    if (options.has(VERBOSE)) {
      verbose = true;
   
    boolean printData = false;
   
    // Get and check parts
View Full Code Here

TOP

Related Classes of joptsimple.OptionSet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.