@Override public HostStatus call() throws Exception { final String output = cli("hosts", name, "--json"); final Map<String, HostStatus> statuses; try { statuses = Json.read(output, new TypeReference<Map<String, HostStatus>>() {}); } catch (IOException e) { return null; } final HostStatus hostStatus = statuses.get(name); if (hostStatus == null) { return null; } return (hostStatus.getStatus() == status) ? hostStatus : null; } });
TaskStatus.State state = null; if (hostStatus != null && hostStatus.getStatus().equals(HostStatus.Status.UP)) { for (final Map.Entry<JobId, Deployment> entry : hostStatus.getJobs().entrySet()) { if (name.equals(entry.getValue().getDeploymentGroupName())) {
@Override public HostStatus call() throws Exception { final HostStatus hostStatus = getOrNull(client.hostStatus(host)); if (hostStatus == null) { return null; } return (hostStatus.getStatus() == status) ? hostStatus : null; } });
/** * Returns various status information about the host. * * @param host The host id. * @param statusFilter An optional status filter. * * @return The host status. */ @GET @Path("{id}/status") @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Optional<HostStatus> hostStatus( @PathParam("id") final String host, @QueryParam("status") @DefaultValue("") final String statusFilter) { final HostStatus status = model.getHostStatus(host); final Optional<HostStatus> response; if (status != null && (isNullOrEmpty(statusFilter) || statusFilter.equals(status.getStatus().toString()))) { response = Optional.of(status); } else { response = Optional.absent(); } log.debug("hostStatus: host={}, statusFilter={}, returning: {}", host, statusFilter, response); return response; }
/** * Returns various status information about the hosts. * * @param hosts The hosts. * @param statusFilter An optional status filter. * * @return The response. */ @POST @Path("/statuses") @Produces(APPLICATION_JSON) @Timed @ExceptionMetered public Map<String, HostStatus> hostStatuses( final List<String> hosts, @QueryParam("status") @DefaultValue("") final String statusFilter) { final Map<String, HostStatus> statuses = Maps.newHashMap(); for (final String host : hosts) { final HostStatus status = model.getHostStatus(host); if (status != null) { if (isNullOrEmpty(statusFilter) || statusFilter.equals(status.getStatus().toString())) { statuses.put(host, status); } } } return statuses; }
@Override public HostStatus call() throws Exception { final HostStatus hostStatus = getOrNull(client.hostStatus(host)); if (hostStatus == null || hostStatus.getHostInfo() == null) { return null; } return (hostStatus.getStatus() == status) ? hostStatus : null; } });
protected HostStatus awaitHostStatusWithLabels(final HeliosClient client, final String host, final HostStatus.Status status, final Map<String, String> labels) throws Exception { final HostStatus hostStatus = Polling.await(LONG_WAIT_SECONDS, SECONDS, () -> { final HostStatus candidate = getOrNull(client.hostStatus(host)); if (candidate == null || candidate.getStatus() != status // labels are stored in ZK after the host has come up || candidate.getLabels().size() != labels.size()) { return null; } return candidate; }); assertThat("host " + host + " has status=" + status + " with labels=" + hostStatus.getLabels(), hostStatus.getLabels(), is(labels)); return hostStatus; }
@VisibleForTesting String pickHost(final List<String> filteredHosts) { final List<String> mutatedList = Lists.newArrayList(filteredHosts); while (true) { final String candidateHost = hostPicker.pickHost(mutatedList); try { if (Status.UP == client.hostStatus(candidateHost).get().getStatus()) { return candidateHost; } mutatedList.remove(candidateHost); if (mutatedList.isEmpty()) { fail("all hosts matching filter pattern are DOWN"); } } catch (InterruptedException | ExecutionException e) { throw Throwables.propagate(e); } } }
@Override public List<RolloutTask> plan(final Map<String, HostStatus> hostsAndStatuses) { // we only care about hosts that are UP final List<String> hosts = Lists.newArrayList(); for (final Map.Entry<String, HostStatus> entry : hostsAndStatuses.entrySet()) { if (entry.getValue().getStatus().equals(HostStatus.Status.UP)) { hosts.add(entry.getKey()); } } // generate the rollout tasks final List<RolloutTask> rolloutTasks = Lists.newArrayList(); final int parallelism = deploymentGroup.getRolloutOptions() != null ? deploymentGroup.getRolloutOptions().getParallelism() : 1; for (final List<String> partition : Lists.partition(hosts, parallelism)) { for (final String host : partition) { rolloutTasks.add(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, host)); rolloutTasks.add(RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, host)); } for (final String host : partition) { rolloutTasks.add(RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, host)); } } return ImmutableList.copyOf(rolloutTasks); } }