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())) { deployedJobId = entry.getKey(); final TaskStatus taskStatus = hostStatus.getStatuses().get(deployedJobId); if (taskStatus != null) { state = taskStatus.getState();
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; }
@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; } });
@Override public Boolean call() throws Exception { final HostStatus hostStatus = getOrNull(client.hostStatus(host)); final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId); final Deployment deployment = hostStatus.getJobs().get(jobId); return taskStatus == null && deployment == null ? true : null; } });
for (final JobId jobId : s.getJobs().keySet()) { final TaskStatus taskStatus = s.getStatuses().get(jobId); if (taskStatus == null) { continue; final HostInfo hi = s.getHostInfo(); final String memUsage; final String cpus; if (s.getAgentInfo() != null) { version = Optional.fromNullable(s.getAgentInfo().getVersion()).or(""); } else { version = ""; String status = s.getStatus() == UP ? "Up" : "Down"; if (s.getAgentInfo() != null) { final long startTime = s.getAgentInfo().getStartTime(); final long upTime = s.getAgentInfo().getUptime(); if (s.getStatus() == UP) { status += " " + humanDuration(currentTimeMillis() - startTime); } else { final String hostLabels = Joiner.on(", ").withKeyValueSeparator("=").join(s.getLabels()); table.row(formatHostname(full, host), status, s.getJobs().size(), runningDeployedJobs.size(), cpus, mem, loadAvg, memUsage, os, version, docker, hostLabels);
@Override public String call() throws Exception { final Deployment deployment = defaultClient().hostStatus(host).get().getJobs().get(jobId); if (deployment != null && !isNullOrEmpty(deployment.getDeploymentGroupName())) { return deployment.getDeploymentGroupName(); } else { return null; } } });
@Override public Boolean call() throws Exception { final HostStatus hostStatus = getOrNull(client.hostStatus(host)); if (hostStatus == null) { return null; } final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId); return taskStatus == null ? true : null; } });
@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; } });
"SPOTIFY_ROLE", "ROLENAME", "BAR", "badfood"), status.get(testHost()).getEnvironment()); "BAR", "deadbeef", "FOO", "4711"), status.get(testHost()).getStatuses().get(jobId).getEnv());
/** * Get labels for a set of hosts. * * @param hosts Hostnames for which to get labels. * * @return a map whose keys are hostnames and values are maps of label key-vals. */ private Callable<Map<String, Map<String, String>>> hostLabels(final Set<String> hosts) { return () -> { final ImmutableMap.Builder<String, Map<String, String>> hostLabels = ImmutableMap.builder(); for (final String host : hosts) { final Map<String, HostStatus> status = Json.read( cli("hosts", host, "--json"), new TypeReference<Map<String, HostStatus>>() { }); final HostStatus hostStatus = status.get(host); if (hostStatus == null) { return null; } final Map<String, String> labels = hostStatus.getLabels(); if (labels != null && !labels.isEmpty()) { hostLabels.put(host, labels); } else { return null; } } return hostLabels.build(); }; }
@Override public DockerVersion call() throws Exception { final HostStatus status = client.hostStatus(testHost()).get(); return status == null ? null : status.getHostInfo() == null ? null : status.getHostInfo().getDockerVersion(); } });
@Override public Object call() throws Exception { final Map<String, HostStatus> status = Json.read( cli("hosts", testHost(), "--json"), new TypeReference<Map<String, HostStatus>>() {}); return status.get(testHost()).getEnvironment(); } });
/** * Returns the current status of the host named by {@code host}. */ @Override public HostStatus getHostStatus(final String host) { final ZooKeeperClient client = provider.get("getHostStatus"); if (!ZooKeeperRegistrarUtil.isHostRegistered(client, host)) { log.warn("Host {} isn't registered in ZooKeeper.", host); return null; } final boolean up = checkHostUp(client, host); final HostInfo hostInfo = getHostInfo(client, host); final AgentInfo agentInfo = getAgentInfo(client, host); final Map<JobId, Deployment> tasks = getTasks(client, host); final Map<JobId, TaskStatus> statuses = getTaskStatuses(client, host); final Map<String, String> environment = getEnvironment(client, host); final Map<String, String> labels = getLabels(client, host); return HostStatus.newBuilder() .setJobs(tasks) .setStatuses(fromNullable(statuses).or(EMPTY_STATUSES)) .setHostInfo(hostInfo) .setAgentInfo(agentInfo) .setStatus(up ? UP : DOWN) .setEnvironment(environment) .setLabels(labels) .build(); }
final Map<String, String> hostLabels = s.getLabels(); for (Entry<String, String> label : selectedLabels.entrySet()) { final String key = label.getKey(); for (final JobId jobId : s.getJobs().keySet()) { final TaskStatus taskStatus = s.getStatuses().get(jobId); if (taskStatus == null) { continue; final HostInfo hi = s.getHostInfo(); final String memUsage; final String cpus; if (s.getAgentInfo() != null) { version = Optional.fromNullable(s.getAgentInfo().getVersion()).or(""); } else { version = ""; String status = s.getStatus() == UP ? "Up" : "Down"; if (s.getAgentInfo() != null) { final long startTime = s.getAgentInfo().getStartTime(); final long upTime = s.getAgentInfo().getUptime(); if (s.getStatus() == UP) { status += " " + humanDuration(currentTimeMillis() - startTime); } else { final String labels = Joiner.on(", ").withKeyValueSeparator("=").join(s.getLabels()); table.row(formatHostname(full, host), status, s.getJobs().size(),
@Override public String call() throws Exception { final Deployment deployment = defaultClient().hostStatus(host).get().getJobs().get(jobId); if (deployment != null && !isNullOrEmpty(deployment.getDeploymentGroupName())) { return deployment.getDeploymentGroupName(); } else { return null; } } });
@Override public TaskStatus call() throws Exception { final HostStatus hostStatus = getOrNull(client.hostStatus(host)); if (hostStatus == null) { return null; } final TaskStatus taskStatus = hostStatus.getStatuses().get(jobId); return (taskStatus != null && taskStatus.getState() == state) ? taskStatus : null; } });
@Override public HostStatus call() throws Exception { final HostStatus hostStatus = getOrNull(client.hostStatus(host)); if (hostStatus == null) { return null; } return (hostStatus.getStatus() == status) ? hostStatus : null; } });
for (final Map.Entry<JobId, Deployment> entry : hostStatus.getJobs().entrySet()) { if (name.equals(entry.getValue().getDeploymentGroupName())) { deployedJobId = entry.getKey(); final TaskStatus taskStatus = hostStatus.getStatuses().get(deployedJobId); if (taskStatus != null) { state = taskStatus.getState();
@Override public void run(final boolean timeout) throws InterruptedException { final List<String> allHosts = masterModel.listHosts(); final Map<String, Map<String, String>> hostsToLabels = Maps.newHashMap(); // determine all hosts and their labels for (final String host : allHosts) { final HostStatus hostStatus = masterModel.getHostStatus(host); if (hostStatus != null) { hostsToLabels.put(host, hostStatus.getLabels()); } } final HostMatcher hostMatcher = new HostMatcher(hostsToLabels); for (final DeploymentGroup dg : masterModel.getDeploymentGroups().values()) { final List<String> matchingHosts = hostMatcher.getMatchingHosts(dg); try { masterModel.updateDeploymentGroupHosts(dg.getName(), matchingHosts); } catch (Exception e) { log.warn("error processing hosts update for deployment group: {} - {}", dg.getName(), e); } } } }
final String hostAddress = hostStatus.getEnvironment().get("HELIOS_HOST_ADDRESS"); if (hostAddress != null) { hostToIp.put(host, hostAddress);