Search in sources :

Example 26 with HostStatus

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));
}
Also used : AgentInfo(com.spotify.helios.common.descriptors.AgentInfo) HostStatus(com.spotify.helios.common.descriptors.HostStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) HostInfo(com.spotify.helios.common.descriptors.HostInfo) Before(org.junit.Before)

Example 27 with HostStatus

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));
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 28 with HostStatus

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;
}
Also used : HostStatus(com.spotify.helios.common.descriptors.HostStatus) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

HostStatus (com.spotify.helios.common.descriptors.HostStatus)28 Test (org.junit.Test)17 JobId (com.spotify.helios.common.descriptors.JobId)13 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)10 HeliosClient (com.spotify.helios.client.HeliosClient)9 Map (java.util.Map)8 Job (com.spotify.helios.common.descriptors.Job)6 Deployment (com.spotify.helios.common.descriptors.Deployment)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 DockerClient (com.spotify.docker.client.DockerClient)4 JobUndeployResponse (com.spotify.helios.common.protocol.JobUndeployResponse)4 ExecutionException (java.util.concurrent.ExecutionException)4 AgentMain (com.spotify.helios.agent.AgentMain)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)3 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)3 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)3 TimeoutException (java.util.concurrent.TimeoutException)3 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)2 Timed (com.codahale.metrics.annotation.Timed)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2