use of com.spotify.helios.common.descriptors.HostStatus 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.HostStatus in project helios by spotify.
the class HostListCommandTest method testPatternFilter.
@Test
public void testPatternFilter() throws Exception {
final String hostname = "host1.example.com";
final List<String> hosts = ImmutableList.of(hostname);
when(client.listHosts("host1")).thenReturn(Futures.immediateFuture(hosts));
final Map<String, HostStatus> statusResponse = ImmutableMap.of(hostname, upStatus);
when(client.hostStatuses(eq(hosts), anyMapOf(String.class, String.class))).thenReturn(Futures.immediateFuture(statusResponse));
final int ret = runCommand("host1");
assertEquals(0, ret);
assertEquals(ImmutableList.of("HOST", hostname + "."), TestUtils.readFirstColumnFromOutput(baos.toString(), false));
}
use of com.spotify.helios.common.descriptors.HostStatus in project helios by spotify.
the class HostsResource method hostStatus.
/**
* 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;
}
Aggregations