Search in sources :

Example 6 with DeploymentGroupStatusResponse

use of com.spotify.helios.common.protocol.DeploymentGroupStatusResponse in project helios by spotify.

the class DeploymentGroupResource method getDeploymentGroupStatus.

@GET
@Path("/{name}/status")
@Produces(APPLICATION_JSON)
@Timed
@ExceptionMetered
public Response getDeploymentGroupStatus(@PathParam("name") @Valid final String name) {
    try {
        final DeploymentGroup deploymentGroup = model.getDeploymentGroup(name);
        final DeploymentGroupStatus deploymentGroupStatus = model.getDeploymentGroupStatus(name);
        final List<String> hosts = model.getDeploymentGroupHosts(name);
        final List<DeploymentGroupStatusResponse.HostStatus> result = Lists.newArrayList();
        for (final String host : hosts) {
            final HostStatus hostStatus = model.getHostStatus(host);
            JobId deployedJobId = 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())) {
                        deployedJobId = entry.getKey();
                        final TaskStatus taskStatus = hostStatus.getStatuses().get(deployedJobId);
                        if (taskStatus != null) {
                            state = taskStatus.getState();
                        }
                        break;
                    }
                }
                result.add(new DeploymentGroupStatusResponse.HostStatus(host, deployedJobId, state));
            }
        }
        final DeploymentGroupStatusResponse.Status status;
        if (deploymentGroupStatus == null) {
            status = DeploymentGroupStatusResponse.Status.IDLE;
        } else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.FAILED) {
            status = DeploymentGroupStatusResponse.Status.FAILED;
        } else if (deploymentGroupStatus.getState() == DeploymentGroupStatus.State.ROLLING_OUT) {
            status = DeploymentGroupStatusResponse.Status.ROLLING_OUT;
        } else {
            status = DeploymentGroupStatusResponse.Status.ACTIVE;
        }
        final String error = deploymentGroupStatus == null ? "" : deploymentGroupStatus.getError();
        return Response.ok(new DeploymentGroupStatusResponse(deploymentGroup, status, error, result, deploymentGroupStatus)).build();
    } catch (final DeploymentGroupDoesNotExistException e) {
        return Response.status(Response.Status.NOT_FOUND).build();
    }
}
Also used : Deployment(com.spotify.helios.common.descriptors.Deployment) DeploymentGroupStatus(com.spotify.helios.common.descriptors.DeploymentGroupStatus) DeploymentGroupDoesNotExistException(com.spotify.helios.master.DeploymentGroupDoesNotExistException) TaskStatus(com.spotify.helios.common.descriptors.TaskStatus) DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) HostStatus(com.spotify.helios.common.descriptors.HostStatus) Map(java.util.Map) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) JobId(com.spotify.helios.common.descriptors.JobId) 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)

Example 7 with DeploymentGroupStatusResponse

use of com.spotify.helios.common.protocol.DeploymentGroupStatusResponse in project helios by spotify.

the class DeploymentGroupStatusCommandTest method testDeploymentGroupStatusBeforeRollingUpdate.

@Test
public void testDeploymentGroupStatusBeforeRollingUpdate() throws Exception {
    final DeploymentGroup deploymentGroupWithNoJob = DeploymentGroup.newBuilder().setName(GROUP_NAME).setHostSelectors(HOST_SELECTORS).setRolloutOptions(ROLLOUT_OPTIONS).build();
    final List<DeploymentGroupStatusResponse.HostStatus> hostStatuses = Lists.newArrayList();
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host1", null, null));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host2", null, null));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host3", null, null));
    final DeploymentGroupStatusResponse status = new DeploymentGroupStatusResponse(deploymentGroupWithNoJob, DeploymentGroupStatusResponse.Status.IDLE, null, hostStatuses, null);
    when(client.deploymentGroupStatus(GROUP_NAME)).thenReturn(Futures.immediateFuture(status));
    when(options.getString("name")).thenReturn(GROUP_NAME);
    final int ret = command.run(options, client, out, false, null);
    assertEquals(0, ret);
    final String output = baos.toString().replaceAll("\\s+", "");
    final String expected = format("Name: %s" + "Job Id: null" + "Status: IDLE" + "Host selectors:" + "  a = b" + "  foo = bar" + "HOST UP-TO-DATE JOB STATE" + "host1. - -" + "host2. - -" + "host3. - -", GROUP_NAME).replace(" ", "");
    assertEquals(expected, output);
}
Also used : DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 8 with DeploymentGroupStatusResponse

use of com.spotify.helios.common.protocol.DeploymentGroupStatusResponse in project helios by spotify.

the class DeploymentGroupStatusCommandTest method testDeploymentGroupStatusJson.

@Test
public void testDeploymentGroupStatusJson() throws Exception {
    final List<DeploymentGroupStatusResponse.HostStatus> hostStatuses = Lists.newArrayList();
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host1", JOB_ID, TaskStatus.State.RUNNING));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host2", JOB_ID, TaskStatus.State.RUNNING));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host3", JOB_ID, TaskStatus.State.PULLING_IMAGE));
    final DeploymentGroupStatusResponse status = new DeploymentGroupStatusResponse(DEPLOYMENT_GROUP, DeploymentGroupStatusResponse.Status.ROLLING_OUT, null, hostStatuses, null);
    when(client.deploymentGroupStatus(GROUP_NAME)).thenReturn(Futures.immediateFuture(status));
    when(options.getString("name")).thenReturn(GROUP_NAME);
    final int ret = command.run(options, client, out, true, null);
    assertEquals(0, ret);
    final DeploymentGroupStatusResponse output = Json.read(baos.toString(), DeploymentGroupStatusResponse.class);
    assertEquals(status, output);
}
Also used : DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) Test(org.junit.Test)

Example 9 with DeploymentGroupStatusResponse

use of com.spotify.helios.common.protocol.DeploymentGroupStatusResponse in project helios by spotify.

the class DeploymentGroupStatusCommandTest method testDeploymentGroupNotFoundJson.

@Test
public void testDeploymentGroupNotFoundJson() throws Exception {
    final ListenableFuture<DeploymentGroupStatusResponse> nullFuture = Futures.immediateFuture(null);
    when(client.deploymentGroupStatus(anyString())).thenReturn(nullFuture);
    final String name = "non-existent-group";
    when(options.getString("name")).thenReturn(name);
    final int ret = command.run(options, client, out, true, null);
    assertEquals(1, ret);
    final Map<String, Object> output = Json.read(baos.toString(), new TypeReference<Map<String, Object>>() {
    });
    assertEquals("DEPLOYMENT_GROUP_NOT_FOUND", output.get("status"));
}
Also used : DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Map(java.util.Map) Test(org.junit.Test)

Example 10 with DeploymentGroupStatusResponse

use of com.spotify.helios.common.protocol.DeploymentGroupStatusResponse in project helios by spotify.

the class DeploymentGroupStatusCommandTest method testDeploymentGroupStatus.

@Test
public void testDeploymentGroupStatus() throws Exception {
    final List<DeploymentGroupStatusResponse.HostStatus> hostStatuses = Lists.newArrayList();
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host1", JOB_ID, TaskStatus.State.RUNNING));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host2", JOB_ID, TaskStatus.State.PULLING_IMAGE));
    hostStatuses.add(new DeploymentGroupStatusResponse.HostStatus("host3", null, null));
    final DeploymentGroupStatusResponse status = new DeploymentGroupStatusResponse(DEPLOYMENT_GROUP, DeploymentGroupStatusResponse.Status.ROLLING_OUT, null, hostStatuses, null);
    when(client.deploymentGroupStatus(GROUP_NAME)).thenReturn(Futures.immediateFuture(status));
    when(options.getString("name")).thenReturn(GROUP_NAME);
    final int ret = command.run(options, client, out, false, null);
    assertEquals(0, ret);
    final String output = baos.toString().replaceAll("\\s+", "");
    final String expected = format("Name: %s" + "Job Id: %s" + "Status: ROLLING_OUT" + "Host selectors:" + "  a = b" + "  foo = bar" + "HOST UP-TO-DATE JOB STATE" + "host1. X %s RUNNING" + "host2. X %s PULLING_IMAGE" + "host3. - -", GROUP_NAME, JOB_ID, JOB_ID, JOB_ID).replace(" ", "");
    assertEquals(expected, output);
}
Also used : DeploymentGroupStatusResponse(com.spotify.helios.common.protocol.DeploymentGroupStatusResponse) Matchers.anyString(org.mockito.Matchers.anyString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Aggregations

DeploymentGroupStatusResponse (com.spotify.helios.common.protocol.DeploymentGroupStatusResponse)11 Test (org.junit.Test)7 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 Matchers.anyString (org.mockito.Matchers.anyString)5 JobId (com.spotify.helios.common.descriptors.JobId)4 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)2 RolloutOptions (com.spotify.helios.common.descriptors.RolloutOptions)2 RollingUpdateResponse (com.spotify.helios.common.protocol.RollingUpdateResponse)2 Map (java.util.Map)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)1 HostSelector (com.spotify.helios.common.descriptors.HostSelector)1 HostStatus (com.spotify.helios.common.descriptors.HostStatus)1 DeploymentGroupDoesNotExistException (com.spotify.helios.master.DeploymentGroupDoesNotExistException)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1