public LoggingConfig getLoggingConfig() { return new LoggingConfig( options.getInt(verboseArg.getDest()), options.getBoolean(syslogArg.getDest()), (File) options.get(logconfigArg.getDest()), options.getBoolean(noLogSetupArg.getDest())); }
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())); }
@Override protected int runWithJobId( final Namespace options, final HeliosClient client, final PrintStream out, final boolean json, final JobId jobId) throws ExecutionException, InterruptedException, IOException { final List<String> hosts = options.getList(hostsArg.getDest()); final Deployment deployment = new Deployment.Builder().setGoal(Goal.STOP).setJobId(jobId).build(); out.printf("Stopping %s on %s%n", jobId, hosts); int code = 0; for (final String host : hosts) { out.printf("%s: ", host); final SetGoalResponse result = client.setGoal(deployment, host).get(); if (result.getStatus() == SetGoalResponse.Status.OK) { out.printf("done%n"); } else { out.printf("failed: %s%n", result); code = 1; } } return code; }
@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 Path getStateDirectory() { return Paths.get(options.getString(stateDirArg.getDest())); }
public String getServiceRegistryAddress() { return options.getString(serviceRegistryArg.getDest()); }
public String getZooKeeperAclAgentUser() { return options.getString(zooKeeperAclAgentUser.getDest()); }
public List<String> getKafkaBrokers() { final List<String> kafkaBrokers = options.getList(kafkaArg.getDest()); return kafkaBrokers.isEmpty() ? null : kafkaBrokers; }
public String getZooKeeperConnectString() { return options.getString(zooKeeperConnectStringArg.getDest()); }
public boolean getZooKeeperEnableAcls() { return options.getBoolean(zooKeeperEnableAcls.getDest()); }
public String getDomain() { return options.getString(domainArg.getDest()); }
public String getZooKeeperClusterId() { return options.getString(zooKeeperClusterId.getDest()); }
public String getRiemannHostPort() { return options.getString(riemannHostPortArg.getDest()); }
public String getStatsdHostPort() { return options.getString(statsdHostPortArg.getDest()); }
public String getName() { return options.getString(nameArg.getDest()); }
public Boolean getInhibitMetrics() { return fromNullable(options.getBoolean(noMetricsArg.getDest())).or(false); }
public String getSentryDsn() { return options.getString(sentryDsnArg.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 Boolean getNoZooKeeperRegistration() { return fromNullable(options.getBoolean(noZooKeeperRegistrationArg.getDest())).or(false); }
public int getZooKeeperSessionTimeoutMillis() { return options.getInt(zooKeeperSessiontimeoutArg.getDest()); }
public Path getServiceRegistrarPlugin() { final File plugin = options.get(serviceRegistrarPluginArg.getDest()); return plugin != null ? plugin.toPath() : null; }