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();
}
}
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);
}
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);
}
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"));
}
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);
}
Aggregations