use of com.spotify.helios.common.descriptors.DeploymentGroupTasks in project helios by spotify.
the class RollingUpdateOpFactoryTest method testStartManualNoHostsTasksAlreadyExist.
@Test
public void testStartManualNoHostsTasksAlreadyExist() throws Exception {
// Create a DeploymentGroupTasks object with no rolloutTasks (defaults to empty list).
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final ZooKeeperClient client = mock(ZooKeeperClient.class);
when(client.exists(anyString())).thenReturn(mock(Stat.class));
final RollingUpdateOp op = opFactory.start(MANUAL_DEPLOYMENT_GROUP, client);
// Two ZK operations should return:
// * delete the tasks
// * set the status to DONE
assertEquals(ImmutableSet.of(new Delete("/status/deployment-group-tasks/my_group"), new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.DONE).setError(null).build().toJsonBytes())), ImmutableSet.copyOf(op.operations()));
// Two events should return: rollingUpdateStarted and rollingUpdateDone
assertEquals(2, op.events().size());
verify(eventFactory).rollingUpdateStarted(MANUAL_DEPLOYMENT_GROUP);
verify(eventFactory).rollingUpdateDone(MANUAL_DEPLOYMENT_GROUP);
}
use of com.spotify.helios.common.descriptors.DeploymentGroupTasks in project helios by spotify.
the class RollingUpdateOpFactoryTest method testTransitionToDone.
@Test
public void testTransitionToDone() {
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setTaskIndex(2).setRolloutTasks(Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"))).setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final RollingUpdateOp op = opFactory.nextTask();
// When state -> DONE we expected
// * deployment group tasks are deleted
// * deployment group status is updated (to DONE)
assertEquals(ImmutableSet.of(new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.DONE).setError(null).build().toJsonBytes()), new Delete("/status/deployment-group-tasks/my_group")), ImmutableSet.copyOf(op.operations()));
// ...and that an event is emitted
assertEquals(1, op.events().size());
verify(eventFactory).rollingUpdateDone(MANUAL_DEPLOYMENT_GROUP);
}
use of com.spotify.helios.common.descriptors.DeploymentGroupTasks in project helios by spotify.
the class RollingUpdateOpFactoryTest method testYield.
@Test
public void testYield() {
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setTaskIndex(0).setRolloutTasks(Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"))).setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final RollingUpdateOp op = opFactory.yield();
assertEquals(0, op.operations().size());
assertEquals(0, op.events().size());
}
use of com.spotify.helios.common.descriptors.DeploymentGroupTasks in project helios by spotify.
the class ZooKeeperMasterModel method getInitRollingUpdateOps.
private RollingUpdateOp getInitRollingUpdateOps(final DeploymentGroup deploymentGroup, final List<String> updateHosts, final List<String> undeployHosts, final ZooKeeperClient zooKeeperClient) throws KeeperException {
final List<RolloutTask> rolloutTasks = new ArrayList<>();
// give precedence to the updateHosts list so we don't end up in a state where we updated a host
// and then removed the job from it (because of buggy logic in the calling method)
final List<String> updateHostsCopy = new ArrayList<>(updateHosts);
final List<String> undeployHostsCopy = new ArrayList<>(undeployHosts);
undeployHostsCopy.removeAll(updateHostsCopy);
// we only care about hosts that are UP
final List<String> upHostsToUndeploy = undeployHostsCopy.stream().filter(host -> checkHostUp(zooKeeperClient, host)).collect(Collectors.toList());
final List<String> upHostsToDeploy = updateHostsCopy.stream().filter(host -> checkHostUp(zooKeeperClient, host)).collect(Collectors.toList());
rolloutTasks.addAll(RollingUndeployPlanner.of(deploymentGroup).plan(upHostsToUndeploy));
rolloutTasks.addAll(RollingUpdatePlanner.of(deploymentGroup).plan(upHostsToDeploy));
log.info("generated rolloutTasks for deployment-group name={} " + "updateHosts={} undeployHosts={}: {}", deploymentGroup.getName(), updateHosts, undeployHosts, rolloutTasks);
final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder().setRolloutTasks(rolloutTasks).setTaskIndex(0).setDeploymentGroup(deploymentGroup).build();
return new RollingUpdateOpFactory(tasks, DEPLOYMENT_GROUP_EVENT_FACTORY).start(deploymentGroup, zooKeeperClient);
}
Aggregations