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
  public void configureParser(Subparser parser) {
    parser.help(DESCRIPTION);
    parser.description(DESCRIPTION);

    Argument functionsArg = parser.addArgument(FUNCTIONS_ARG);
    functionsArg.dest(FUNCTIONS_ARG);
    functionsArg.metavar("<function>");
    functionsArg.nargs("*");
    functionsArg.help("function to invoke");
  }
Example #4
0
  @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;
  }
Example #5
0
  @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;
  }
Example #6
0
  @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 Path getServiceRegistrarPlugin() {
   final File plugin = options.get(serviceRegistrarPluginArg.getDest());
   return plugin != null ? plugin.toPath() : null;
 }
 public List<String> getKafkaBrokers() {
   final List<String> kafkaBrokers = options.getList(kafkaArg.getDest());
   return kafkaBrokers.isEmpty() ? null : kafkaBrokers;
 }
 public Path getStateDirectory() {
   return Paths.get(options.getString(stateDirArg.getDest()));
 }
 public String getSentryDsn() {
   return options.getString(sentryDsnArg.getDest());
 }
 public String getZooKeeperAclAgentUser() {
   return options.getString(zooKeeperAclAgentUser.getDest());
 }
 public String getDomain() {
   return options.getString(domainArg.getDest());
 }
 public Boolean getNoZooKeeperRegistration() {
   return fromNullable(options.getBoolean(noZooKeeperRegistrationArg.getDest())).or(false);
 }
 public String getStatsdHostPort() {
   return options.getString(statsdHostPortArg.getDest());
 }
 public int getZooKeeperSessionTimeoutMillis() {
   return options.getInt(zooKeeperSessiontimeoutArg.getDest());
 }
 public String getRiemannHostPort() {
   return options.getString(riemannHostPortArg.getDest());
 }
 public String getName() {
   return options.getString(nameArg.getDest());
 }
 public Boolean getInhibitMetrics() {
   return fromNullable(options.getBoolean(noMetricsArg.getDest())).or(false);
 }
 public String getServiceRegistryAddress() {
   return options.getString(serviceRegistryArg.getDest());
 }
 public boolean getZooKeeperEnableAcls() {
   return options.getBoolean(zooKeeperEnableAcls.getDest());
 }
 public String getZooKeeperClusterId() {
   return options.getString(zooKeeperClusterId.getDest());
 }
 public String getZooKeeperConnectString() {
   return options.getString(zooKeeperConnectStringArg.getDest());
 }