Search in sources :

Example 11 with RolloutTask

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));
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DefaultZooKeeperClient(com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) Job(com.spotify.helios.common.descriptors.Job) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 12 with RolloutTask

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);
}
Also used : RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 13 with RolloutTask

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);
}
Also used : RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 14 with RolloutTask

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);
}
Also used : RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 15 with RolloutTask

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);
}
Also used : RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Aggregations

RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)16 Test (org.junit.Test)11 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)10 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)6 DeploymentGroupTasks (com.spotify.helios.common.descriptors.DeploymentGroupTasks)5 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)5 Map (java.util.Map)5 DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)4 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)2 Job (com.spotify.helios.common.descriptors.Job)2 CreateEmpty (com.spotify.helios.servicescommon.coordination.CreateEmpty)2 SetData (com.spotify.helios.servicescommon.coordination.SetData)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Function (com.google.common.base.Function)1 Joiner (com.google.common.base.Joiner)1 MoreObjects (com.google.common.base.MoreObjects)1 Optional.fromNullable (com.google.common.base.Optional.fromNullable)1