protected FastForwardConfig ffwdConfig(final Namespace options) { if (!options.getBoolean(ffwdEnabled.getDest())) { return null; } return new FastForwardConfig( Optional.ofNullable(options.getString(ffwdAddress.getDest())), options.getInt(ffwdInterval.getDest()), options.getString(ffwdMetricKey.getDest())); }
/** * Runs the command line interface given some arguments. * * @param arguments the command line arguments * @return whether or not the command successfully executed * @throws Exception if something goes wrong */ public boolean run(String... arguments) throws Exception { try { if (isFlag(HELP, arguments)) { parser.printHelp(stdOut); } else if (isFlag(VERSION, arguments)) { parser.printVersion(stdOut); } else { final Namespace namespace = parser.parseArgs(arguments); if (namespace.get("is-help") == null) { final Command command = commands.get(namespace.getString(COMMAND_NAME_ATTR)); command.run(bootstrap, namespace); } } return true; } catch (ArgumentParserException e) { // TODO: 5/25/13 <coda> -- make ArgumentParser#handleError not depend on System.err stdErr.println(e.getMessage()); e.getParser().printHelp(stdErr); return false; } catch (ConfigurationException e) { // TODO: 7/26/13 <ntelford> -- as above, this probably shouldn't depend on System.err stdErr.println(e.getMessage()); return false; } }
public static Namespace handleArgumentString(String[] args, ArgumentParser parser) { Namespace parsedArgs = null; try { parsedArgs = parser.parseArgs(args); String selectedModule = parsedArgs.getString("Module"); try { String propPath = parsedArgs.getString("propertyFile"); if (propPath != null) { parsedArgs = loadProperties(propPath); // 선택된 모듈이 무엇이었는지 다시 기억 parsedArgs.getAttrs().put("Module", selectedModule); } } catch (IOException e) { e.printStackTrace(); System.exit(1); } } catch (ArgumentParserException e) { parser.handleError(e); System.exit(1); } // 만약 output 디렉토리가 존재하지 않으면 새로 생성 Path outputPath = null; try { String outputPathString = parsedArgs.getString("outputDirPath"); if (outputPathString != null) { outputPath = Paths.get(outputPathString); if (!Files.exists(outputPath)) { Files.createDirectories(outputPath); } } } catch (NullPointerException e) { // System.err.println(); } catch (InvalidPathException e) { } catch (IOException e) { e.printStackTrace(); } return parsedArgs; }
private static void loadEnvironment(String[] args) { final String defaultConfDir = getProperty("dash.application.conf.dir"); final String defaultConfFile = (defaultConfDir != null ? defaultConfDir + File.separatorChar : "") + "conf.yml"; ArgumentParser parser = ArgumentParsers.newArgumentParser("Dash", true) .description("Runs a performance test mix.") .version("${prog} " + Version.id()) .epilog("Dash is a free software under Apache License Version 2.0"); parser .addArgument("-c", "--conf") .help("the config file containing the test specification to run (default: ../conf/conf.yml") .required(false) .setDefault(new File(defaultConfFile)) .type(File.class); parser .addArgument("-t", "--test") .help("the name of the test to run") .required(true) .type(String.class); parser .addArgument("-v", "--version") .help("print the version number") .action(Arguments.version()); try { YamlEnv yamlEnv = new YamlEnv(); Namespace namespace = parser.parseArgs(args); @SuppressWarnings("unchecked") HashMap<String, Object> env = (HashMap<String, Object>) yamlEnv.loadProperties((File) namespace.get("conf")); String test = namespace.getString("test"); @SuppressWarnings("unchecked") HashMap<String, Object> testSpec = (HashMap<String, Object>) env.get(test); if (testSpec == null) { System.err.println("Test spec (" + test + ") does not exist in the config file."); throw new Error(); // todo: message or log or exit } for (Map.Entry<String, Object> entry : testSpec.entrySet()) { if (entry.getValue() != null) { System.setProperty(entry.getKey(), entry.getValue().toString()); } } } catch (ArgumentParserException e) { parser.handleError(e); } catch (IOException e) { e.printStackTrace(); } }
@Test public void testDeploymentGroupInspectCommandNotFound() throws Exception { when(options.getString("name")).thenReturn(NON_EXISTENT_NAME); final int ret = command.run(options, client, out, false, null); assertEquals(1, ret); final String output = baos.toString(); assertThat(output, containsString("Unknown deployment group: " + NON_EXISTENT_NAME)); }
@Test public void testDeploymentGroupInspectCommandJson() throws Exception { when(options.getString("name")).thenReturn(NAME); final int ret = command.run(options, client, out, true, null); assertEquals(0, ret); final DeploymentGroup output = Json.read(baos.toString(), DeploymentGroup.class); assertEquals(DEPLOYMENT_GROUP, output); }
@Test public void testDeploymentGroupInspectCommandNotFoundJson() throws Exception { when(options.getString("name")).thenReturn(NON_EXISTENT_NAME); final int ret = command.run(options, client, out, true, null); assertEquals(1, ret); final Map<String, Object> output = Json.read(baos.toString(), new TypeReference<Map<String, Object>>() {}); assertEquals("DEPLOYMENT_GROUP_NOT_FOUND", output.get("status")); }
@Override int run(Namespace options, HeliosClient client, PrintStream out, final boolean json) throws ExecutionException, InterruptedException { final String host = options.getString(hostArg.getDest()); final String id = options.getString(idArg.getDest()); out.printf("Registering host %s with id %s%n", host, id); int code = 0; out.printf("%s: ", host); final int result = client.registerHost(host, id).get(); if (result == 200) { out.printf("done%n"); } else { out.printf("failed: %s%n", result); code = 1; } return code; }
public void run(String[] args, Namespace parsedArgs) { String corpusDirPath = parsedArgs.getString("corpusDirPath"); String outputDirPath = parsedArgs.getString("outputDirPath"); String inputFilePath = parsedArgs.getString("inputFilePath"); String domainFilePath = parsedArgs.getString("domainFilePath"); String pmiThreshold = parsedArgs.getString("pmiThreshold"); String coThreshold = parsedArgs.getString("coThreshold"); try { target( corpusDirPath, inputFilePath, domainFilePath, outputDirPath, Double.parseDouble(pmiThreshold), Double.parseDouble(coThreshold)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void testDeploymentGroupInspectCommand() throws Exception { when(options.getString("name")).thenReturn(NAME); final int ret = command.run(options, client, out, false, null); assertEquals(0, ret); final String output = baos.toString(); assertThat(output, containsString("Name: " + NAME)); assertThat(output, containsString("Host selectors:")); assertThat(output, containsString(" foo = bar")); assertThat(output, containsString(" baz = qux")); assertThat(output, containsString("Job: " + JOB.toString())); }
@Override @SuppressWarnings("unchecked") public final void run(Bootstrap<?> bootstrap, Namespace namespace) throws Exception { final T configuration = parseConfiguration( bootstrap.getConfigurationProvider(), namespace.getString("file"), getConfigurationClass(), bootstrap.getObjectMapper()); if (configuration != null) { configuration .getLoggingFactory() .configure(bootstrap.getMetricRegistry(), bootstrap.getApplication().getName()); } run((Bootstrap<T>) bootstrap, namespace, configuration); }
@Override public void run(Namespace namespace, Mongeez mongeez) throws Exception { final AbstractMongeezCommand<T> subcommand = subcommands.get(namespace.getString(COMMAND_NAME_ATTR)); subcommand.run(namespace, mongeez); }
public String getDomain() { return options.getString(domainArg.getDest()); }
public String getServiceRegistryAddress() { return options.getString(serviceRegistryArg.getDest()); }
@Override protected int runWithJobId( final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final JobId jobId, final BufferedReader stdin) throws ExecutionException, InterruptedException, IOException { final String name = options.getString(nameArg.getDest()); final long timeout = options.getLong(timeoutArg.getDest()); final int parallelism = options.getInt(parallelismArg.getDest()); final boolean async = options.getBoolean(asyncArg.getDest()); final long rolloutTimeout = options.getLong(rolloutTimeoutArg.getDest()); final boolean migrate = options.getBoolean(migrateArg.getDest()); final boolean overlap = options.getBoolean(overlapArg.getDest()); final String token = options.getString(tokenArg.getDest()); checkArgument(timeout > 0, "Timeout must be greater than 0"); checkArgument(parallelism > 0, "Parallelism must be greater than 0"); checkArgument(rolloutTimeout > 0, "Rollout timeout must be greater than 0"); final long startTime = timeSupplier.get(); final RolloutOptions rolloutOptions = RolloutOptions.newBuilder() .setTimeout(timeout) .setParallelism(parallelism) .setMigrate(migrate) .setOverlap(overlap) .setToken(token) .build(); final RollingUpdateResponse response = client.rollingUpdate(name, jobId, rolloutOptions).get(); if (response.getStatus() != RollingUpdateResponse.Status.OK) { if (!json) { out.println("Failed: " + response); } else { out.println(response.toJsonString()); } return 1; } if (!json) { out.println( format( "Rolling update%s started: %s -> %s " + "(parallelism=%d, timeout=%d, overlap=%b, token=%s)%s", async ? " (async)" : "", name, jobId.toShortString(), parallelism, timeout, overlap, token, async ? "" : "\n")); } final Map<String, Object> jsonOutput = Maps.newHashMap(); jsonOutput.put("parallelism", parallelism); jsonOutput.put("timeout", timeout); jsonOutput.put("overlap", overlap); jsonOutput.put("token", token); if (async) { if (json) { jsonOutput.put("status", response.getStatus()); out.println(Json.asStringUnchecked(jsonOutput)); } return 0; } String error = ""; boolean failed = false; boolean timedOut = false; final Set<String> reported = Sets.newHashSet(); while (true) { final DeploymentGroupStatusResponse status = client.deploymentGroupStatus(name).get(); if (status == null) { failed = true; error = "Failed to fetch deployment-group status"; break; } if (!jobId.equals(status.getDeploymentGroup().getJobId())) { // Another rolling-update was started, overriding this one -- exit failed = true; error = "Deployment-group job id changed during rolling-update"; break; } if (!json) { for (DeploymentGroupStatusResponse.HostStatus hostStatus : status.getHostStatuses()) { final JobId hostJobId = hostStatus.getJobId(); final String host = hostStatus.getHost(); final TaskStatus.State state = hostStatus.getState(); final boolean done = hostJobId != null && hostJobId.equals(jobId) && state == TaskStatus.State.RUNNING; if (done && reported.add(host)) { out.println( format( "%s -> %s (%d/%d)", host, state, reported.size(), status.getHostStatuses().size())); } } } if (status.getStatus() != DeploymentGroupStatusResponse.Status.ROLLING_OUT) { if (status.getStatus() == DeploymentGroupStatusResponse.Status.FAILED) { failed = true; error = status.getError(); } break; } if (timeSupplier.get() - startTime > TimeUnit.MINUTES.toMillis(rolloutTimeout)) { // Rollout timed out timedOut = true; break; } sleepFunction.sleep(POLL_INTERVAL_MILLIS); } final double duration = (timeSupplier.get() - startTime) / 1000.0; if (json) { if (failed) { jsonOutput.put("status", "FAILED"); jsonOutput.put("error", error); } else if (timedOut) { jsonOutput.put("status", "TIMEOUT"); } else { jsonOutput.put("status", "DONE"); } jsonOutput.put("duration", duration); out.println(Json.asStringUnchecked(jsonOutput)); } else { out.println(); if (failed) { out.println(format("Failed: %s", error)); } else if (timedOut) { out.println("Timed out! (rolling-update still in progress)"); } else { out.println("Done."); } out.println(format("Duration: %.2f s", duration)); } return (failed || timedOut) ? 1 : 0; }
public String getZooKeeperConnectString() { return options.getString(zooKeeperConnectStringArg.getDest()); }
public String getSentryDsn() { return options.getString(sentryDsnArg.getDest()); }
public String getName() { return options.getString(nameArg.getDest()); }
public String getRiemannHostPort() { return options.getString(riemannHostPortArg.getDest()); }
public String getStatsdHostPort() { return options.getString(statsdHostPortArg.getDest()); }
public static void main(String[] args) { EccoService eccoService = new EccoService(); CLI cli = new CLI(eccoService); // # PICK APART ARGUMENTS ... ######################################### // TODO: parse arguments ArgumentParser parser = ArgumentParsers.newArgumentParser("ecco").description("ECCO Description."); Subparsers subparsers = parser .addSubparsers() .title("subcommands") .description("valid subcommands") .help("additional help") .metavar("COMMAND") .dest("command"); // initialize empty local repository Subparser parserInit = subparsers.addParser("init").help("init help"); // status of local repository and working copy Subparser parserStatus = subparsers.addParser("status").help("status help"); // get a configuration property <name> Subparser parserGet = subparsers.addParser("get").help("get help"); parserGet.addArgument("name"); // set a configuration property <name> to <value> Subparser parserSet = subparsers.addParser("set").help("set help"); parserSet.addArgument("name"); parserSet.addArgument("value"); // checkout a configuration from the local repository as working copy (composition) Subparser parserCheckout = subparsers.addParser("checkout").help("checkout help"); parserCheckout.addArgument("configurationString"); // commit the working copy as a new configuration into the local repository Subparser parserCommit = subparsers.addParser("commit").help("commit help"); parserCommit.addArgument("configurationString").required(false); // TODO: clone (cloning remote locally), fetch (fetching changes from remote), update (update // working copy), pull (fetch + update), push (push changes in local repository to remote), ... try { Namespace res = parser.parseArgs(args); System.out.println(res); switch (res.getString("command")) { case "init": cli.init(); break; case "status": cli.status(); break; case "get": cli.getProperty(res.getString("name")); break; case "set": cli.setProperty(res.getString("name"), res.getString("value")); break; case "checkout": cli.checkout(res.getString("configurationString")); break; case "commit": if (res.getString("configurationString") != null) cli.commit(res.getString("configurationString")); break; } } catch (HelpScreenException e) { parser.handleError(e); } catch (ArgumentParserException e) { System.err.println("ERROR: " + e.getMessage()); } catch (EccoException e) { System.err.println("ERROR: " + e.getMessage()); } }
public Path getStateDirectory() { return Paths.get(options.getString(stateDirArg.getDest())); }
public String getZooKeeperAclAgentUser() { return options.getString(zooKeeperAclAgentUser.getDest()); }
public String getZooKeeperClusterId() { return options.getString(zooKeeperClusterId.getDest()); }