Пример #1
0
 public void run() {
   int baseKey = (index * keyCount) % keys.size();
   for (int i = 0; i < requests; i++) {
     int keyIndex = (baseKey + (i % keyCount)) % keys.size();
     String key = keys.get(keyIndex);
     Transaction txn = fac.create();
     long start = System.currentTimeMillis();
     try {
       txn.begin();
       byte[] value = txn.read(key);
       txn.commit();
       timeElapsed += System.currentTimeMillis() - start;
       if (!silent.get()) {
         System.out.println("[Thread-" + index + "] " + key + ": " + new String(value));
       }
       success++;
     } catch (Exception e) {
       timeElapsed += System.currentTimeMillis() - start;
       if (!silent.get()) {
         System.out.println("[Thread-" + index + "] Error: " + e.getMessage());
       }
       failure++;
     }
   }
 }
Пример #2
0
    public static Options parseArgs(String cmdArgs[]) {
      CommandLineParser parser = new GnuParser();
      CmdLineOptions options = getCmdLineOptions();
      try {
        CommandLine cmd = parser.parse(options, cmdArgs, false);

        if (cmd.hasOption(HELP_OPTION)) {
          printUsage(options);
          System.exit(0);
        }

        String[] args = cmd.getArgs();
        if (args.length >= 4 || args.length < 2) {
          String msg = args.length < 2 ? "Missing arguments" : "Too many arguments";
          errorMsg(msg, options);
          System.exit(1);
        }

        String keyspace = args[0];
        String cf = args[1];
        String snapshot = null;
        if (args.length == 3) snapshot = args[2];

        Options opts = new Options(keyspace, cf, snapshot);

        opts.debug = cmd.hasOption(DEBUG_OPTION);
        opts.keepSource = cmd.hasOption(KEEP_SOURCE);

        return opts;
      } catch (ParseException e) {
        errorMsg(e.getMessage(), options);
        return null;
      }
    }
    private static void configureTransportFactory(
        ITransportFactory transportFactory, LoaderOptions opts) {
      Map<String, String> options = new HashMap<>();
      // If the supplied factory supports the same set of options as our SSL impl, set those
      if (transportFactory.supportedOptions().contains(SSLTransportFactory.TRUSTSTORE))
        options.put(SSLTransportFactory.TRUSTSTORE, opts.encOptions.truststore);
      if (transportFactory.supportedOptions().contains(SSLTransportFactory.TRUSTSTORE_PASSWORD))
        options.put(SSLTransportFactory.TRUSTSTORE_PASSWORD, opts.encOptions.truststore_password);
      if (transportFactory.supportedOptions().contains(SSLTransportFactory.PROTOCOL))
        options.put(SSLTransportFactory.PROTOCOL, opts.encOptions.protocol);
      if (transportFactory.supportedOptions().contains(SSLTransportFactory.CIPHER_SUITES))
        options.put(
            SSLTransportFactory.CIPHER_SUITES, Joiner.on(',').join(opts.encOptions.cipher_suites));

      if (transportFactory.supportedOptions().contains(SSLTransportFactory.KEYSTORE)
          && opts.encOptions.require_client_auth)
        options.put(SSLTransportFactory.KEYSTORE, opts.encOptions.keystore);
      if (transportFactory.supportedOptions().contains(SSLTransportFactory.KEYSTORE_PASSWORD)
          && opts.encOptions.require_client_auth)
        options.put(SSLTransportFactory.KEYSTORE_PASSWORD, opts.encOptions.keystore_password);

      // Now check if any of the factory's supported options are set as system properties
      for (String optionKey : transportFactory.supportedOptions())
        if (System.getProperty(optionKey) != null)
          options.put(optionKey, System.getProperty(optionKey));

      transportFactory.setOptions(options);
    }
  public static void main(String args[]) throws IOException {
    LoaderOptions options = LoaderOptions.parseArgs(args);
    try {
      SSTableLoader loader =
          new SSTableLoader(options.directory, new ExternalClient(options), options);
      SSTableLoader.LoaderFuture future = loader.stream(options.ignores);

      if (options.noProgress) {
        future.get();
      } else {
        ProgressIndicator indicator = new ProgressIndicator(future.getPendingFiles());
        indicator.start();
        System.out.println("");
        while (!future.isDone()) {
          if (indicator.printProgress()) {
            // We're done with streaming
            System.out.println("\nWaiting for targets to rebuild indexes ...");
            future.get();
            assert future.isDone();
          } else {
            try {
              Thread.sleep(1000L);
            } catch (Exception e) {
            }
          }
        }
      }

      System.exit(0); // We need that to stop non daemonized threads
    } catch (Exception e) {
      System.err.println(e.getMessage());
      if (options.debug) e.printStackTrace(System.err);
      System.exit(1);
    }
  }
Пример #5
0
	public static void main(String[] args) throws IOException {
		boolean ret = true;
		String[] leftedArgs = ginit(args);
		if(leftedArgs.length > 1) System.exit(1);
		else if(leftedArgs.length == 0) interactiveFlag = true;
		
		if(builtinTest != null) {
			System.exit(builtinTest(builtinTest));
		}
		if(testScript != null) {
			System.exit(test(testScript));
		}
		CTX konoha = open();
		if(startupScript != null) {
			startup(konoha, startupScript);
		}
		if(leftedArgs.length == 1) {
			ret = load(konoha, leftedArgs[0]);
		}
		if(ret && (interactiveFlag != false)) {    // TODO interactiveFlag to boolean?
			ret = kShell(konoha);
		}
		close(konoha);
		// MODGC_check_malloced_size()
		System.exit(ret ? assertResult : 1);
	}
Пример #6
0
    public static Options parseArgs(String cmdArgs[]) {
      CommandLineParser parser = new GnuParser();
      CmdLineOptions options = getCmdLineOptions();
      try {
        CommandLine cmd = parser.parse(options, cmdArgs, false);

        if (cmd.hasOption(HELP_OPTION)) {
          printUsage(options);
          System.exit(0);
        }

        String[] args = cmd.getArgs();
        if (args.length == 0) {
          System.err.println("No sstables to split");
          printUsage(options);
          System.exit(1);
        }
        Options opts = new Options(Arrays.asList(args));
        opts.debug = cmd.hasOption(DEBUG_OPTION);
        opts.verbose = cmd.hasOption(VERBOSE_OPTION);
        opts.snapshot = !cmd.hasOption(NO_SNAPSHOT_OPTION);
        opts.sizeInMB = DEFAULT_SSTABLE_SIZE;

        if (cmd.hasOption(SIZE_OPTION))
          opts.sizeInMB = Integer.valueOf(cmd.getOptionValue(SIZE_OPTION));

        return opts;
      } catch (ParseException e) {
        errorMsg(e.getMessage(), options);
        return null;
      }
    }
Пример #7
0
 public void run() {
   int baseKey = index;
   for (int i = 0; i < requests; i++) {
     int keyIndex = (baseKey + i);
     String key = keys.get(keyIndex);
     Transaction txn = fac.create();
     long start = System.currentTimeMillis();
     try {
       txn.begin();
       String value = "random_value_" + index + "_" + i;
       txn.write(key, value.getBytes());
       txn.commit();
       timeElapsed += (System.currentTimeMillis() - start);
       if (!silent.get()) {
         System.out.println("[Thread-" + index + "] " + key + ": " + value);
       }
       success++;
     } catch (TransactionException e) {
       timeElapsed += (System.currentTimeMillis() - start);
       if (!silent.get()) {
         System.out.println("[Thread-" + index + "] Error: " + e.getMessage());
       }
       failure++;
     }
   }
 }
Пример #8
0
  public int ParseAuth(BufferedReader bufferedReader, int count, Logger runtimeLogger) {

    try {

      while (true) {

        String line = bufferedReader.readLine();
        count++;

        if ("[/auth]".equalsIgnoreCase(line)) {
          break;
        }

        if (line.startsWith("#") | "".equals(line)) {
          continue;
        }

        String[] words = line.split(":");
        if (words.length == 2) {

          Pattern pattern;
          Matcher matcher;

          String regexUsername = "******";
          pattern = Pattern.compile(regexUsername);
          matcher = pattern.matcher(words[0]);
          if (!matcher.find()) {
            runtimeLogger.error(
                String.format(
                    "Auth config error occurs at line %d: invalid username %s", count, words[0]));
            System.exit(-1);
          }

          String regexPassword = "******";
          pattern = Pattern.compile(regexPassword);
          matcher = pattern.matcher(words[1]);
          if (!matcher.find()) {
            runtimeLogger.error(
                String.format(
                    "Auth config error occurs at line %d: invalid password %s", count, words[0]));
            System.exit(-1);
          }

          username = words[0];
          password = words[1];

        } else {
          runtimeLogger.error(String.format("Auth error occurs at line %d", count));
          System.exit(-1);
        }
      }
      return count;

    } catch (IOException e) {
      runtimeLogger.error(e.getMessage(), e);
      return 0;
    }
  }
 List<String> runtimePaths() {
   List<String> paths = pathsSpecifiedFor(RUNTIMEPATH_OPTION);
   if (paths.isEmpty() && System.getenv(REDLINE_HOME_ENVVAR) != null) {
     String redlineHome = System.getenv(REDLINE_HOME_ENVVAR);
     if (!redlineHome.endsWith("rt")) redlineHome = redlineHome + File.separator + "rt";
     paths.add(redlineHome);
   }
   return paths;
 }
Пример #10
0
  public static void main(String[] args) {
    long start = System.currentTimeMillis();
    FeatureExtractorSimple fe = new FeatureExtractorSimple(args);

    fe.run();
    long end = System.currentTimeMillis();
    Logger.log("processing completed in " + (end - start) / 1000 + " sec");
    Logger.close();
    System.out.println("processing completed in " + (end - start) / 1000 + " sec");
  }
    public static LoaderOptions parseArgs(String cmdArgs[]) {
      CommandLineParser parser = new GnuParser();
      CmdLineOptions options = getCmdLineOptions();
      try {
        CommandLine cmd = parser.parse(options, cmdArgs, false);

        if (cmd.hasOption(HELP_OPTION)) {
          printUsage(options);
          System.exit(0);
        }

        String[] args = cmd.getArgs();
        if (args.length == 0) {
          System.err.println("Missing sstable directory argument");
          printUsage(options);
          System.exit(1);
        }

        if (args.length > 1) {
          System.err.println("Too many arguments");
          printUsage(options);
          System.exit(1);
        }

        String dirname = args[0];
        File dir = new File(dirname);

        if (!dir.exists()) errorMsg("Unknown directory: " + dirname, options);

        if (!dir.isDirectory()) errorMsg(dirname + " is not a directory", options);

        LoaderOptions opts = new LoaderOptions(dir);

        opts.debug = cmd.hasOption(DEBUG_OPTION);
        opts.verbose = cmd.hasOption(VERBOSE_OPTION);
        opts.noProgress = cmd.hasOption(NOPROGRESS_OPTION);

        if (cmd.hasOption(IGNORE_NODES_OPTION)) {
          String[] nodes = cmd.getOptionValue(IGNORE_NODES_OPTION).split(",");
          try {
            for (String node : nodes) {
              opts.ignores.add(InetAddress.getByName(node));
            }
          } catch (UnknownHostException e) {
            errorMsg(e.getMessage(), options);
          }
        }

        return opts;
      } catch (ParseException e) {
        errorMsg(e.getMessage(), options);
        return null;
      }
    }
Пример #12
0
 public static void printUsage(Options options) {
   String usage = String.format("%s [options] <dir_path>", TOOL_NAME);
   String header =
       System.lineSeparator()
           + "Bulk load the sstables found in the directory <dir_path> to the configured cluster."
           + "The parent directories of <dir_path> are used as the target keyspace/table name. "
           + "So for instance, to load an sstable named Standard1-g-1-Data.db into Keyspace1/Standard1, "
           + "you will need to have the files Standard1-g-1-Data.db and Standard1-g-1-Index.db into a directory /path/to/Keyspace1/Standard1/.";
   String footer =
       System.lineSeparator()
           + "You can provide cassandra.yaml file with -f command line option to set up streaming throughput, client and server encryption options. "
           + "Only stream_throughput_outbound_megabits_per_sec, server_encryption_options and client_encryption_options are read from yaml. "
           + "You can override options read from cassandra.yaml with corresponding command line options.";
   new HelpFormatter().printHelp(usage, header, options, footer);
 }
Пример #13
0
  private void updateLinuxServiceInstaller() {
    try {
      File dir = new File(directory, "CTP");
      if (suppressFirstPathElement) dir = dir.getParentFile();
      Properties props = new Properties();
      String ctpHome = dir.getAbsolutePath();
      cp.appendln(Color.black, "...CTP_HOME: " + ctpHome);
      ctpHome = ctpHome.replaceAll("\\\\", "\\\\\\\\");
      props.put("CTP_HOME", ctpHome);
      File javaHome = new File(System.getProperty("java.home"));
      String javaBin = (new File(javaHome, "bin")).getAbsolutePath();
      cp.appendln(Color.black, "...JAVA_BIN: " + javaBin);
      javaBin = javaBin.replaceAll("\\\\", "\\\\\\\\");
      props.put("JAVA_BIN", javaBin);

      File linux = new File(dir, "linux");
      File install = new File(linux, "ctpService-ubuntu.sh");
      cp.appendln(Color.black, "Linux service installer:");
      cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
      String bat = getFileText(install);
      bat = replace(bat, props); // do the substitutions
      bat = bat.replace("\r", "");
      setFileText(install, bat);

      // If this is an ISN installation, put the script in the correct place.
      String osName = System.getProperty("os.name").toLowerCase();
      if (programName.equals("ISN") && !osName.contains("windows")) {
        install = new File(linux, "ctpService-red.sh");
        cp.appendln(Color.black, "ISN service installer:");
        cp.appendln(Color.black, "...file: " + install.getAbsolutePath());
        bat = getFileText(install);
        bat = replace(bat, props); // do the substitutions
        bat = bat.replace("\r", "");
        File initDir = new File("/etc/init.d");
        File initFile = new File(initDir, "ctpService");
        if (initDir.exists()) {
          setOwnership(initDir, "edge", "edge");
          setFileText(initFile, bat);
          initFile.setReadable(true, false); // everybody can read //Java 1.6
          initFile.setWritable(true); // only the owner can write //Java 1.6
          initFile.setExecutable(true, false); // everybody can execute //Java 1.6
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      System.err.println("Unable to update the Linux service ctpService.sh file");
    }
  }
Пример #14
0
  public int ParseServer(BufferedReader bufferedReader, int count, Logger runtimeLogger) {

    try {

      while (true) {

        String line = bufferedReader.readLine();
        count++;

        if ("[/server]".equalsIgnoreCase(line)) {
          break;
        }

        if (line.startsWith("#") | "".equals(line)) {
          continue;
        }

        String regexDomain = "(?:(?:\\d{1,3}){1,3}\\d{1,3})|(?:(?:[\\w|-]+){2,})";
        Pattern pattern = Pattern.compile(regexDomain);
        Matcher matcher = pattern.matcher(line);

        if (!matcher.find()) {
          runtimeLogger.error(String.format("Server address %s format is wrong", line));
          System.exit(-1);
        }

        serverAddress = line;
      }
      return count;

    } catch (IOException e) {
      runtimeLogger.error(e.getMessage(), e);
      return 0;
    }
  }
Пример #15
0
  public static void main(String[] args) throws Exception {
    final Configuration conf = new Configuration();
    initalizeConf(conf, args);

    int res = ToolRunner.run(conf, new FrameworkDriver(), args);
    System.exit(res);
  }
 public static int getBStartAddress() {
   if (b_start_address == -1) {
     System.err.println("B Start Address is not yet set!");
     System.exit(-1);
   }
   return b_start_address;
 }
  @Override
  public int run(String[] args) throws Exception {
    CommandLine cmd = getCommand(args);
    DistCpOptions options = getDistCpOptions(cmd);

    Configuration conf = this.getConf();
    // inject wf configs
    Path confPath = new Path("file:///" + System.getProperty("oozie.action.conf.xml"));

    LOG.info(confPath + " found conf ? " + confPath.getFileSystem(conf).exists(confPath));
    conf.addResource(confPath);

    String falconFeedStorageType = cmd.getOptionValue("falconFeedStorageType").trim();
    Storage.TYPE feedStorageType = Storage.TYPE.valueOf(falconFeedStorageType);

    DistCp distCp =
        (feedStorageType == Storage.TYPE.FILESYSTEM)
            ? new CustomReplicator(conf, options)
            : new DistCp(conf, options);
    LOG.info("Started DistCp");
    distCp.execute();

    if (feedStorageType == Storage.TYPE.FILESYSTEM) {
      executePostProcessing(options); // this only applies for FileSystem Storage.
    }

    LOG.info("Completed DistCp");
    return 0;
  }
Пример #18
0
  private static void startJAASSNAA(
      String path,
      String urnprefix,
      String jaasModuleName,
      String jaasConfigFile,
      IUserAuthorization authorization) {

    log.debug(
        "Starting JAAS SNAA, path ["
            + path
            + "], prefix["
            + urnprefix
            + "], jaasConfigFile["
            + jaasConfigFile
            + "], jaasModuleName["
            + jaasModuleName
            + "], authorization["
            + authorization
            + "]");

    System.setProperty("java.security.auth.login.config", jaasConfigFile);

    JAASSNAA jaasSnaa = new JAASSNAA(urnprefix, jaasModuleName, authorization);

    HttpContext context = server.createContext(path);
    Endpoint endpoint = Endpoint.create(jaasSnaa);
    endpoint.publish(context);

    log.debug("Started JAAS SNAA on " + server.getAddress() + path);
  }
Пример #19
0
  private static void loadData(TransactionFactory fac, int numKeys, int concurrency) {
    List<Future> futures = new ArrayList<Future>();

    final List<String> keys = new ArrayList<String>();
    for (int i = 0; i < numKeys; i++) {
      keys.add("row" + i);
    }

    int success = 0;
    int failure = 0;
    // Use concurrency threads
    int requestsPerIndex = numKeys / concurrency;
    // This is to ensure you always load at least the keys you need
    if (numKeys % concurrency != 0) {
      requestsPerIndex++;
    }
    IndexedWriteWorker[] workers = new IndexedWriteWorker[numKeys];
    int index = 0;
    for (int i = 0; i < concurrency; i++) {
      workers[i] = new IndexedWriteWorker(index, fac, requestsPerIndex, numKeys, keys);
      index += requestsPerIndex;
    }

    long start = System.currentTimeMillis();
    for (int i = 0; i < concurrency; i++) {
      futures.add(exec.submit(workers[i]));
    }

    long time = 0L;
    for (int i = 0; i < concurrency; i++) {
      try {
        futures.get(i).get();
      } catch (Exception ignored) {
      }
      success += workers[i].success;
      failure += workers[i].failure;
      time += workers[i].timeElapsed;
    }
    long end = System.currentTimeMillis();

    int total = success + failure;
    System.out.println("\nSuccessful: " + success + "/" + total);
    System.out.println("Failed: " + failure + "/" + total);
    System.out.println("Time elapsed: " + (end - start) + "ms");
    System.out.println("Throughput: " + total / ((end - start) / 1000.0) + " TPS");
    System.out.println("Average latency: " + time / (double) total + "ms");
  }
Пример #20
0
	public static String[] ginit(String[] args) {
		if (System.getenv("KONOHA_DEBUG") != null) {
			verboseDebug = true;
			verboseGc = true;
			verboseSugar = true;
			verboseCode = true;
		}
		
		CommandLineParser parser = new BasicParser();
		CommandLine commandLine = null;
		try {
			commandLine = parser.parse(longOptions, args);
		} catch (ParseException e) {
			// TODO
		}
		
		if(commandLine.hasOption("verbose")) {
			verboseDebug = true;
			System.out.println("option vervose");
		}
		if(commandLine.hasOption("verbose:gc")) {
			verboseGc = true;
			System.out.println("option vervose:gc");
		}
		if(commandLine.hasOption("verbose:sugar")) {
			verboseSugar = true;
			System.out.println("option vervose:sugar");
		}
		if(commandLine.hasOption("verbose:code")) {
			verboseCode = true;
			System.out.println("option vervose:code");
		}
		if(commandLine.hasOption("interactive")) {
			interactiveFlag = true;
			System.out.println("option interactive");
		}
		if(commandLine.hasOption("typecheck")) {
			compileonlyFlag = true;
			System.out.println("option typecheck");
		}
		if(commandLine.hasOption("start-with")) {
			startupScript = commandLine.getOptionValue("start-with");
			System.out.println("option start-with");
			System.out.println(" with arg " + startupScript);
		}
		if(commandLine.hasOption("test")) {
			testScript = commandLine.getOptionValue("test");
			System.out.println(" with arg " + testScript);
		}
		if(commandLine.hasOption("test-with")) {
			testScript = commandLine.getOptionValue("test");
			System.out.println(" with arg " + testScript);
		}
		if(commandLine.hasOption("builtin-test")) {
			builtinTest = commandLine.getOptionValue("builtin-test");
			System.out.println(" with arg " + builtinTest);
		}
		return commandLine.getArgs();
	}
 private void msgHandler(
     final DirectBuffer buffer, final int offset, final int length, final Header header) {
   if (buffer.getByte(offset) == (byte) 'p') {
     timestamps[buffer.getInt(offset + 1)] = System.nanoTime() - buffer.getLong(offset + 5);
   } else {
     warmups++;
   }
 }
Пример #22
0
	public static void startup(CTX konoha, String startup_script) {
		String[] buf = new String[256];
		String path = System.getenv("KONOHA_SCRIPTPATH");
		String local = "";
		if (path == null) {
			path = System.getenv("KONOHA_HOME");
			local = "/script";
		}	
		if (path == null) {
			path = System.getenv("HOME");
			local = "/.konoha/script";
		}
		//TODO snprintf(buf, sizeof(buf), "%s%s%s.k", path, local, startup_script);
		if (true /*TODO load(konoha, (const char*)buf)*/ ) {
			System.exit(1);
		}
	}
Пример #23
0
 /**
  * startLogger initializes and returns a file at logLoc with the results of logging at level
  * logLevel.
  *
  * @param logLoc location of the output log file- a string
  * @param logLevel logging level (is parsed by level.parse())
  * @return Logger object to log to.
  */
 public Logger startLogger(String logLoc, String logLevel) {
   try {
     fh = new FileHandler(logLoc); // sets output log file at logLoc
   } catch (SecurityException e) {
     e.printStackTrace();
     System.err.println("SecurityException establishing logger. Exiting...\n");
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     System.err.println("IOException establishing logger. Exiting...\n");
     System.exit(1);
   }
   fh.setFormatter(new SimpleFormatter()); // format of log is 'human-readable' simpleformat
   logger.addHandler(fh); // attach formatter to logger
   logger.setLevel(Level.parse(logLevel)); // set log level
   return logger;
 }
Пример #24
0
  public static void main(String args[]) {

    Throwable anyError = null;
    ParameterProblem paramError = null;
    ExecutionProblem execError = null;
    int ret = EXIT_OK;
    try {
      final AdminClient adminClient = new AdminClient();
      adminClient.setupDebug(args);
      adminClient.run(args);

    } catch (ParameterProblem e) {
      paramError = e;
      anyError = e;
      ret = EXIT_PARAMETER_PROBLEM;
    } catch (ExecutionProblem e) {
      execError = e;
      anyError = e;
      ret = EXIT_EXECUTION_PROBLEM;
    } catch (Throwable t) {
      anyError = t;
      ret = EXIT_UNKNOWN_PROBLEM;
    }

    if (anyError == null) {
      System.exit(ret);
    } else {
      logger.debug("Got error", anyError);
    }

    if (paramError != null) {
      System.err.println("Parameter Problem:\n\n" + paramError.getMessage());
      System.err.println("See --help");

    } else if (execError != null) {
      System.err.println(execError.getMessage());
    } else {
      System.err.println("An unexpected error was encountered. Please report this!");
      System.err.println(anyError.getMessage());
      System.err.println();
      System.err.println("Stack trace:");
      anyError.printStackTrace(System.err);
    }

    System.exit(ret);
  }
Пример #25
0
  /**
   * Initialises the FeatureExtractor from a set of parameters, for example sent as command-line
   * arguments
   *
   * @param args The list of arguments
   */
  public FeatureExtractorSimple(String[] args) {
    workDir = System.getProperty("user.dir");
    new Logger("log.txt");
    parseArguments(args);

    input = workDir + File.separator + resourceManager.getString("input");
    output = workDir + File.separator + resourceManager.getString("output");
    System.out.println("input=" + input + "  output=" + output);
  }
Пример #26
0
 /**
  * Primary entry point for compiling from the command line (using the groovyc script).
  *
  * <p>If calling inside a process and you don't want the JVM to exit on an error call
  * commandLineCompile(String[]), which this method simply wraps
  *
  * @param args command line arguments
  * @param lookupUnnamedFiles do a lookup for .groovy files not part of the given list of files to
  *     compile
  */
 public static void commandLineCompileWithErrorHandling(
     String[] args, boolean lookupUnnamedFiles) {
   try {
     commandLineCompile(args, lookupUnnamedFiles);
   } catch (Throwable e) {
     new ErrorReporter(e, displayStackTraceOnError).write(System.err);
     System.exit(1);
   }
 }
Пример #27
0
  // TODO add exception for invalid options
  private void loadCLO(String[] args) {
    Options options = new Options();

    String[][] clolist = {
      // {"variable/optionname", "description"},
      {"genConfig", "general configuration file location"},
      {"inWeightsLoc", "input weights configuration file location"},
      {"inDBLoc", "input database file location"},
      {"outWeightsLoc", "output weights configuration file location"},
      {"outDBLoc", "output database file location"},
      {"p3pLocation", "adding to DB: single policy file location"},
      {"p3pDirLocation", "adding to DB: multiple policy directory location"},
      {"newDB", "create new database in place of old one (doesn't check for existence of old one"},
      {"newPolicyLoc", "the policy object to process"},
      {"userResponse", "response to specified policy"},
      {"userIO", "user interface"},
      {"userInit", "initialization via user interface"},
      {"policyDB", "PolicyDatabase backend"},
      {"cbrV", "CBR to use"},
      {"blanketAccept", "automatically accept the user suggestion"},
      {"loglevel", "level of things save to the log- see java logging details"},
      {"policyDB", "PolicyDatabase backend"},
      {"NetworkRType", "Network Resource type"},
      {"NetworkROptions", "Network Resource options"},
      {"confidenceLevel", "Confidence threshold for consulting a networked resource"},
      {"useNet", "use networking options"},
      {"loglocation", "where to save the log file"},
      {"loglevel", "the java logging level to use. See online documentation for enums."}
    };

    for (String[] i : clolist) {
      options.addOption(i[0], true, i[1]);
    }

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, args);
    } catch (ParseException e) {
      System.err.println("Error parsing commandline arguments.");
      e.printStackTrace();
      System.exit(3);
    }
    /*
    for(String i : args)
    {
    	System.err.println(i);
    }
    */
    for (String[] i : clolist) {
      if (cmd.hasOption(i[0])) {
        System.err.println("found option i: " + i);
        genProps.setProperty(i[0], cmd.getOptionValue(i[0]));
      }
    }
    System.err.println(genProps);
  }
Пример #28
0
  private void parseCmdLine(String[] args) {
    CommandLineParser parser = new PosixParser();

    Options options = new Options();
    options.addOption("v", "version", false, "Q2's version");
    options.addOption("d", "deploydir", true, "Deployment directory");
    options.addOption("r", "recursive", false, "Deploy subdirectories recursively");
    options.addOption("h", "help", false, "Usage information");
    options.addOption("C", "config", true, "Configuration bundle");
    options.addOption("e", "encrypt", true, "Encrypt configuration bundle");
    options.addOption("i", "cli", false, "Command Line Interface");
    options.addOption("c", "command", true, "Command to execute");

    try {
      CommandLine line = parser.parse(options, args);
      if (line.hasOption("v")) {
        displayVersion();
        System.exit(0);
      }
      if (line.hasOption("h")) {
        HelpFormatter helpFormatter = new HelpFormatter();
        helpFormatter.printHelp("Q2", options);
        System.exit(0);
      }
      if (line.hasOption("c")) {
        cli = new CLI(this, line.getOptionValue("c"), line.hasOption("i"));
      } else if (line.hasOption("i")) cli = new CLI(this, null, true);

      String dir = DEFAULT_DEPLOY_DIR;
      if (line.hasOption("d")) {
        dir = line.getOptionValue("d");
      }
      recursive = line.hasOption("r");
      this.deployDir = new File(dir);
      if (line.hasOption("C")) deployBundle(new File(line.getOptionValue("C")), false);
      if (line.hasOption("e")) deployBundle(new File(line.getOptionValue("e")), true);
    } catch (MissingArgumentException e) {
      System.out.println("ERROR: " + e.getMessage());
      System.exit(1);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }
Пример #29
0
  public static void main(String args[]) {
    Config.setClientMode(true);
    LoaderOptions options = LoaderOptions.parseArgs(args);
    OutputHandler handler = new OutputHandler.SystemOutput(options.verbose, options.debug);
    SSTableLoader loader =
        new SSTableLoader(
            options.directory,
            new ExternalClient(
                options.hosts,
                options.rpcPort,
                options.user,
                options.passwd,
                options.transportFactory,
                options.storagePort,
                options.sslStoragePort,
                options.serverEncOptions),
            handler);
    DatabaseDescriptor.setStreamThroughputOutboundMegabitsPerSec(options.throttle);
    StreamResultFuture future = null;
    try {
      if (options.noProgress) future = loader.stream(options.ignores);
      else future = loader.stream(options.ignores, new ProgressIndicator());
    } catch (Exception e) {
      System.err.println(e.getMessage());
      if (e.getCause() != null) System.err.println(e.getCause());
      if (options.debug) e.printStackTrace(System.err);
      else System.err.println("Run with --debug to get full stack trace or --help to get help.");
      System.exit(1);
    }

    handler.output(String.format("Streaming session ID: %s", future.planId));

    try {
      future.get();
      System.exit(0); // We need that to stop non daemonized threads
    } catch (Exception e) {
      System.err.println("Streaming to the following hosts failed:");
      System.err.println(loader.getFailedHosts());
      System.err.println(e);
      if (options.debug) e.printStackTrace(System.err);
      System.exit(1);
    }
  }
Пример #30
0
  public void run() {
    long start = System.currentTimeMillis();

    combineRequire(require);

    ArrayList<String> combinedFiles = new ArrayList<String>();
    StringBuilder finalCodes = new StringBuilder();

    for (Module m : processedModules) {
      combinedFiles.add(m.getName());
      finalCodes.append(m.getCode());
    }

    String re =
        "/*\n Combined processedModules by KISSY Module Compiler: \n\n "
            + ArrayUtils.join(combinedFiles.toArray(new String[combinedFiles.size()]), "\n ")
            + "\n*/\n\n"
            + finalCodes.toString();

    if (output != null) {
      FileUtils.outputContent(re, output, outputEncoding);
      System.out.println("success generated: " + output);
    } else {
      System.out.println(re);
    }

    if (outputDependency != null && dependencies.size() != 0) {
      String allRs = "";
      for (String r : dependencies) {
        if (r.startsWith("#")) {
          allRs += "," + r.substring(1);
        } else {
          allRs += ",'" + r + "'";
        }
      }
      re = DEP_PREFIX + "'" + require + "': {requires: [" + allRs.substring(1) + "]}" + DEP_SUFFIX;
      FileUtils.outputContent(re, outputDependency, outputEncoding);
      System.out.println("success generated: " + outputDependency);
    }

    System.out.print("duration: " + (System.currentTimeMillis() - start));
  }