use of com.spotify.helios.common.descriptors.RolloutTask 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.RolloutTask in project helios by spotify.
the class RollingUndeployPlannerTest method testParallelRolloutWithRemainder.
@Test
public void testParallelRolloutWithRemainder() {
final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setRolloutOptions(RolloutOptions.newBuilder().setParallelism(3).build()).build();
final RolloutPlanner rolloutPlanner = RollingUndeployPlanner.of(deploymentGroup);
final List<RolloutTask> tasks = rolloutPlanner.plan(HOSTS);
final List<RolloutTask> expected = Lists.newArrayList(RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent1"), RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent2"), RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent3"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent1"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent1"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent2"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent2"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent3"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent3"), RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent4"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent4"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent4"));
assertEquals(expected, tasks);
}
use of com.spotify.helios.common.descriptors.RolloutTask in project helios by spotify.
the class RollingUndeployPlannerTest method testParallelRollout.
@Test
public void testParallelRollout() {
final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setRolloutOptions(RolloutOptions.newBuilder().setParallelism(2).build()).build();
final RolloutPlanner rolloutPlanner = RollingUndeployPlanner.of(deploymentGroup);
final List<RolloutTask> tasks = rolloutPlanner.plan(HOSTS);
final List<RolloutTask> expected = Lists.newArrayList(RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent1"), RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent2"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent1"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent1"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent2"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent2"), RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent3"), RolloutTask.of(RolloutTask.Action.FORCE_UNDEPLOY_JOBS, "agent4"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent3"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent3"), RolloutTask.of(RolloutTask.Action.AWAIT_UNDEPLOYED, "agent4"), RolloutTask.of(RolloutTask.Action.MARK_UNDEPLOYED, "agent4"));
assertEquals(expected, tasks);
}
use of com.spotify.helios.common.descriptors.RolloutTask in project helios by spotify.
the class RollingUpdatePlannerTest method testParallelRolloutWithRemainder.
@Test
public void testParallelRolloutWithRemainder() {
final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setRolloutOptions(RolloutOptions.newBuilder().setParallelism(3).build()).build();
final RolloutPlanner rolloutPlanner = RollingUpdatePlanner.of(deploymentGroup);
final List<RolloutTask> tasks = rolloutPlanner.plan(HOSTS);
final List<RolloutTask> expected = Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent1"), RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent2"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent2"), RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent3"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent3"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent2"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent3"), RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent4"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent4"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent4"));
assertEquals(expected, tasks);
}
use of com.spotify.helios.common.descriptors.RolloutTask in project helios by spotify.
the class RollingUpdatePlannerTest method testSerialRollout.
@Test
public void testSerialRollout() {
final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setRolloutOptions(RolloutOptions.newBuilder().setParallelism(1).build()).build();
final RolloutPlanner rolloutPlanner = RollingUpdatePlanner.of(deploymentGroup);
final List<RolloutTask> tasks = rolloutPlanner.plan(HOSTS);
final List<RolloutTask> expected = Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent1"), RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent2"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent2"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent2"), RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent3"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent3"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent3"), RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "agent4"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "agent4"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "agent4"));
assertEquals(expected, tasks);
}
Aggregations