use of com.spotify.helios.common.descriptors.AgentInfo in project helios by spotify.
the class ZooKeeperMasterModel method getHostStatus.
/**
* 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();
}
use of com.spotify.helios.common.descriptors.AgentInfo in project helios by spotify.
the class DeadAgentReaper method processItem.
@Override
void processItem(final String agent) {
try {
if (masterModel.isHostUp(agent)) {
// Host UP -- nothing to do
return;
}
final AgentInfo agentInfo = masterModel.getAgentInfo(agent);
if (agentInfo == null) {
return;
}
final long downSince = agentInfo.getStartTime() + agentInfo.getUptime();
final long downDurationMillis = clock.now().getMillis() - downSince;
if (downDurationMillis >= timeoutMillis) {
try {
log.info("Reaping dead agent '{}' (DOWN for {} hours)", agent, DurationFormatUtils.formatDurationHMS(downDurationMillis));
masterModel.deregisterHost(agent);
} catch (Exception e) {
log.warn("Failed to reap agent '{}'", agent, e);
}
}
} catch (Exception e) {
log.warn("Failed to determine if agent '{}' should be reaped", agent, e);
}
}
use of com.spotify.helios.common.descriptors.AgentInfo in project helios by spotify.
the class HostListCommandTest method setUp.
@Before
public void setUp() throws ParseException {
// purposefully in non-sorted order so that tests that verify that the output is sorted are
// actually testing HostListCommand behavior and not accidentally testing what value the
// mock returns
final List<String> hosts = ImmutableList.of("host3.", "host1.", "host2.");
when(client.listHosts()).thenReturn(immediateFuture(hosts));
final HostInfo hostInfo = HostInfo.newBuilder().setCpus(4).setMemoryTotalBytes((long) Math.pow(1024, 3)).setMemoryFreeBytes(500000000).setLoadAvg(0.1).setOsName("OS foo").setOsVersion("0.1.0").setDockerVersion(DockerVersion.builder().version("1.7.0").apiVersion("1.18").build()).build();
final long dayMilliseconds = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS);
final long startTime = System.currentTimeMillis() - 2 * dayMilliseconds;
final AgentInfo agentInfo = AgentInfo.newBuilder().setVersion("0.8.420").setUptime(dayMilliseconds).setStartTime(startTime).build();
upStatus = HostStatus.newBuilder().setJobs(JOBS).setStatuses(JOB_STATUSES).setStatus(UP).setHostInfo(hostInfo).setAgentInfo(agentInfo).setLabels(LABELS).build();
downStatus = HostStatus.newBuilder().setJobs(JOBS).setStatuses(JOB_STATUSES).setStatus(DOWN).setHostInfo(hostInfo).setAgentInfo(agentInfo).setLabels(LABELS).build();
final Map<String, HostStatus> statuses = ImmutableMap.of("host3.", downStatus, "host1.", upStatus, "host2.", upStatus);
when(client.hostStatuses(eq(hosts), anyMapOf(String.class, String.class))).thenReturn(immediateFuture(statuses));
}
use of com.spotify.helios.common.descriptors.AgentInfo in project helios by spotify.
the class AgentInfoReporter method runOneIteration.
@Override
protected void runOneIteration() {
final AgentInfo agentInfo = AgentInfo.newBuilder().setName(runtimeMxBean.getName()).setVmName(runtimeMxBean.getVmName()).setVmVendor(runtimeMxBean.getVmVendor()).setVmVersion(runtimeMxBean.getVmVersion()).setSpecName(runtimeMxBean.getSpecName()).setSpecVendor(runtimeMxBean.getSpecVendor()).setSpecVersion(runtimeMxBean.getSpecVersion()).setInputArguments(runtimeMxBean.getInputArguments()).setUptime(runtimeMxBean.getUptime()).setStartTime(runtimeMxBean.getStartTime()).setVersion(Version.POM_VERSION).build();
nodeUpdater.update(agentInfo.toJsonBytes());
}
Aggregations