use of com.spotify.helios.common.descriptors.DeploymentGroup 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.descriptors.DeploymentGroup in project helios by spotify.
the class DeploymentGroupTest method testUpdateDeploymentGroupHosts.
// A test that ensures healthy deployment groups will perform a rolling update when their hosts
// change.
@Test
public void testUpdateDeploymentGroupHosts() throws Exception {
final ZooKeeperClient client = spy(this.client);
final ZooKeeperMasterModel masterModel = spy(newMasterModel(client));
// Return a job so we can add a real deployment group.
final Job job = Job.newBuilder().setCommand(ImmutableList.of("COMMAND")).setImage("IMAGE").setName("JOB_NAME").setVersion("VERSION").build();
doReturn(job).when(masterModel).getJob(job.getId());
// Add a real deployment group.
final DeploymentGroup dg = DeploymentGroup.newBuilder().setName(GROUP_NAME).setHostSelectors(ImmutableList.of(HostSelector.parse("role=melmac"))).setJobId(job.getId()).setRolloutOptions(RolloutOptions.newBuilder().build()).setRollingUpdateReason(MANUAL).build();
masterModel.addDeploymentGroup(dg);
// Setup some hosts
final String oldHost = "host1";
final String newHost = "host2";
client.ensurePath(Paths.configHost(oldHost));
client.ensurePath(Paths.configHost(newHost));
client.ensurePath(Paths.statusHostUp(oldHost));
client.ensurePath(Paths.statusHostUp(newHost));
// Give the deployment group a host.
client.setData(Paths.statusDeploymentGroupHosts(dg.getName()), Json.asBytes(ImmutableList.of(oldHost)));
// And a status...
client.setData(Paths.statusDeploymentGroup(dg.getName()), DeploymentGroupStatus.newBuilder().setState(DONE).build().toJsonBytes());
// Switch out our host!
// TODO(negz): Use an unchanged host, make sure ordering remains the same.
masterModel.updateDeploymentGroupHosts(dg.getName(), ImmutableList.of(newHost));
verify(client, times(2)).transaction(opCaptor.capture());
final DeploymentGroup changed = dg.toBuilder().setRollingUpdateReason(HOSTS_CHANGED).build();
// Ensure we set the DG status to HOSTS_CHANGED.
// This means we triggered a rolling update.
final ZooKeeperOperation setDeploymentGroupHostChanged = set(Paths.configDeploymentGroup(dg.getName()), changed);
// Ensure ZK tasks are written to:
// - Perform a rolling undeploy for the removed (old) host
// - Perform a rolling update for the added (new) host and the unchanged host
final List<RolloutTask> tasks = ImmutableList.<RolloutTask>builder().addAll(RollingUndeployPlanner.of(changed).plan(singletonList(oldHost))).addAll(RollingUpdatePlanner.of(changed).plan(singletonList(newHost))).build();
final ZooKeeperOperation setDeploymentGroupTasks = set(Paths.statusDeploymentGroupTasks(dg.getName()), DeploymentGroupTasks.newBuilder().setRolloutTasks(tasks).setTaskIndex(0).setDeploymentGroup(changed).build());
assertThat(opCaptor.getValue(), hasItems(setDeploymentGroupHostChanged, setDeploymentGroupTasks));
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class DeploymentGroupResourceTest method testCreateExistingSameDeploymentGroup.
@Test
public void testCreateExistingSameDeploymentGroup() throws Exception {
final DeploymentGroup dg = mock(DeploymentGroup.class);
when(dg.getName()).thenReturn("foo");
when(dg.getHostSelectors()).thenReturn(Lists.newArrayList(FOO_SELECTOR));
doThrow(new DeploymentGroupExistsException("")).when(model).addDeploymentGroup(dg);
when(model.getDeploymentGroup("foo")).thenReturn(dg);
final Response response = resource.createDeploymentGroup(dg);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(new CreateDeploymentGroupResponse(CreateDeploymentGroupResponse.Status.NOT_MODIFIED), response.getEntity());
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class DeploymentGroupResourceTest method testCreateExistingConflictingDeploymentGroup.
@Test
public void testCreateExistingConflictingDeploymentGroup() throws Exception {
final DeploymentGroup dg = mock(DeploymentGroup.class);
when(dg.getName()).thenReturn("foo");
when(dg.getHostSelectors()).thenReturn(Lists.newArrayList(FOO_SELECTOR));
doThrow(new DeploymentGroupExistsException("")).when(model).addDeploymentGroup(dg);
final DeploymentGroup existing = mock(DeploymentGroup.class);
when(existing.getHostSelectors()).thenReturn(Lists.newArrayList(BAZ_SELECTOR));
when(model.getDeploymentGroup("foo")).thenReturn(existing);
final Response response = resource.createDeploymentGroup(dg);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(new CreateDeploymentGroupResponse(CreateDeploymentGroupResponse.Status.CONFLICT), response.getEntity());
}
use of com.spotify.helios.common.descriptors.DeploymentGroup in project helios by spotify.
the class DeploymentGroupResourceTest method testGetDeploymentGroup.
@Test
public void testGetDeploymentGroup() throws Exception {
final JobId jobId = JobId.newBuilder().setName("my_job").setVersion("0.2").setHash("1234").build();
final DeploymentGroup dg = DeploymentGroup.newBuilder().setName("foo").setHostSelectors(ImmutableList.of(ROLE_SELECTOR, FOO_SELECTOR)).setJobId(jobId).build();
when(model.getDeploymentGroup("foo")).thenReturn(dg);
final Response response = resource.getDeploymentGroup("foo");
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
assertEquals(dg, response.getEntity());
}
Aggregations