use of com.spotify.helios.cli.Target in project helios by spotify.
the class ControlCommand method run.
@Override
public int run(final Namespace options, final List<Target> targets, final PrintStream out, final PrintStream err, final String username, final boolean json, final BufferedReader stdin) throws Exception {
boolean allSuccessful = true;
boolean isFirst = true;
// TODO (dxia) The json = true branches below are a hack to get valid JSON for multiple domains.
// Refactor concrete command implementations later to return an Object that can then be put into
// a {"$DOMAIN": $VALUE} dict before json serializing and returning it.
// Execute the control command over each target cluster
final Iterator<Target> targetIterator = targets.iterator();
while (targetIterator.hasNext()) {
final Target target = targetIterator.next();
if (targets.size() > 1) {
if (!json) {
final List<URI> endpoints = target.getEndpointSupplier().get();
final String header = format("%s (%s)", target.getName(), endpoints);
out.println(header);
out.println(repeat("-", header.length()));
out.flush();
} else {
if (isFirst) {
out.println("{");
isFirst = false;
}
out.println("\"" + target.getName() + "\": ");
}
}
final boolean successful = run(options, target, out, err, username, json, stdin);
if (shortCircuit && !successful) {
return 1;
}
allSuccessful &= successful;
if (targets.size() > 1) {
if (!json) {
out.println();
} else {
if (targetIterator.hasNext()) {
out.println(",\n");
} else {
out.println("}");
}
}
}
}
return allSuccessful ? 0 : 1;
}
use of com.spotify.helios.cli.Target in project helios by spotify.
the class MultiTargetControlCommand method run.
@Override
public int run(final Namespace options, final List<Target> targets, final PrintStream out, final PrintStream err, final String username, final boolean json, final BufferedReader stdin) throws Exception {
final Builder<TargetAndClient> clientBuilder = ImmutableList.<TargetAndClient>builder();
for (final Target target : targets) {
final HeliosClient client = Utils.getClient(target, err, username, options);
if (client == null) {
return 1;
}
clientBuilder.add(new TargetAndClient(target, client));
}
final List<TargetAndClient> clients = clientBuilder.build();
final int result;
try {
result = run(options, clients, out, json, stdin);
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
// otherwise "Request timed out to master http://ash2-helios-a4.ash2.spotify.net:5800"
if (cause instanceof TimeoutException) {
err.println("Request timed out to master");
} else {
throw Throwables.propagate(cause);
}
return 1;
} finally {
for (final TargetAndClient cc : clients) {
cc.getClient().close();
}
}
return result;
}
use of com.spotify.helios.cli.Target in project helios by spotify.
the class JobWatchCommand method watchJobsOnHosts.
static void watchJobsOnHosts(final PrintStream out, final boolean exact, final List<String> prefixes, final Set<JobId> jobIds, final int interval, final List<TargetAndClient> clients) throws InterruptedException, ExecutionException {
out.println("Control-C to stop");
out.println("JOB HOST STATE THROTTLED?");
final DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm:ss");
while (true) {
final Instant now = new Instant();
out.printf("-------------------- ------------------------------ -------- " + "---------- [%s UTC]%n", now.toString(formatter));
for (final TargetAndClient cc : clients) {
final Optional<Target> target = cc.getTarget();
if (clients.size() > 1) {
final String header;
if (target.isPresent()) {
final List<URI> endpoints = target.get().getEndpointSupplier().get();
header = format(" %s (%s)", target.get().getName(), endpoints);
} else {
header = "";
}
out.printf("---%s%n", header);
}
showReport(out, exact, prefixes, jobIds, formatter, cc.getClient());
}
if (out.checkError()) {
break;
}
Thread.sleep(1000 * interval);
}
}
Aggregations