Search in sources :

Example 1 with SetData

use of com.spotify.helios.servicescommon.coordination.SetData in project helios by spotify.

the class RollingUpdateOpFactoryTest method testErrorWhenIgnoreFailuresIsTrue.

@Test
public void testErrorWhenIgnoreFailuresIsTrue() {
    final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder().setName("ignore_failure_group").setRolloutOptions(RolloutOptions.newBuilder().setIgnoreFailures(true).build()).setRollingUpdateReason(MANUAL).build();
    // the current task is the AWAIT_RUNNING one
    final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder().setTaskIndex(2).setRolloutTasks(ImmutableList.of(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"))).setDeploymentGroup(deploymentGroup).build();
    final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(tasks, eventFactory);
    final RollingUpdateOp nextOp = opFactory.error("something went wrong", "host1", RollingUpdateError.TIMED_OUT_WAITING_FOR_JOB_TO_REACH_RUNNING);
    assertThat(nextOp.operations(), containsInAnyOrder(new SetData("/status/deployment-groups/ignore_failure_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.DONE).setError(null).build().toJsonBytes()), new Delete("/status/deployment-group-tasks/ignore_failure_group")));
}
Also used : Delete(com.spotify.helios.servicescommon.coordination.Delete) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) SetData(com.spotify.helios.servicescommon.coordination.SetData) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 2 with SetData

use of com.spotify.helios.servicescommon.coordination.SetData in project helios by spotify.

the class RollingUpdateOpFactoryTest method testStartHostsChanged.

@Test
public void testStartHostsChanged() throws Exception {
    // Create a DeploymentGroupTasks object with some rolloutTasks.
    final ArrayList<RolloutTask> rolloutTasks = Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"));
    final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setTaskIndex(0).setRolloutTasks(rolloutTasks).setDeploymentGroup(HOSTS_CHANGED_DEPLOYMENT_GROUP).build();
    final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
    final ZooKeeperClient client = mock(ZooKeeperClient.class);
    when(client.exists(anyString())).thenReturn(null);
    final RollingUpdateOp op = opFactory.start(HOSTS_CHANGED_DEPLOYMENT_GROUP, client);
    // Three ZK operations should return:
    // * create tasks node
    // * set the task index to 0
    // * another to set the status to ROLLING_OUT
    assertEquals(ImmutableSet.of(new CreateEmpty("/status/deployment-group-tasks/my_group"), new SetData("/status/deployment-group-tasks/my_group", DeploymentGroupTasks.newBuilder().setRolloutTasks(rolloutTasks).setTaskIndex(0).setDeploymentGroup(HOSTS_CHANGED_DEPLOYMENT_GROUP).build().toJsonBytes()), new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.ROLLING_OUT).build().toJsonBytes())), ImmutableSet.copyOf(op.operations()));
    // Two events should return: rollingUpdateStarted and rollingUpdateDone
    assertEquals(1, op.events().size());
    verify(eventFactory).rollingUpdateStarted(HOSTS_CHANGED_DEPLOYMENT_GROUP);
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) CreateEmpty(com.spotify.helios.servicescommon.coordination.CreateEmpty) SetData(com.spotify.helios.servicescommon.coordination.SetData) Test(org.junit.Test)

Example 3 with SetData

use of com.spotify.helios.servicescommon.coordination.SetData in project helios by spotify.

the class RollingUpdateOpFactoryTest method testStartManualWithHosts.

@Test
public void testStartManualWithHosts() throws Exception {
    // Create a DeploymentGroupTasks object with some rolloutTasks.
    final ArrayList<RolloutTask> rolloutTasks = Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"));
    final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setTaskIndex(0).setRolloutTasks(rolloutTasks).setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
    final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
    final ZooKeeperClient client = mock(ZooKeeperClient.class);
    when(client.exists(anyString())).thenReturn(null);
    final RollingUpdateOp op = opFactory.start(MANUAL_DEPLOYMENT_GROUP, client);
    // Three ZK operations should return:
    // * create tasks node
    // * set the task index to 0
    // * set the status to ROLLING_OUT
    assertEquals(ImmutableSet.of(new CreateEmpty("/status/deployment-group-tasks/my_group"), new SetData("/status/deployment-group-tasks/my_group", DeploymentGroupTasks.newBuilder().setRolloutTasks(rolloutTasks).setTaskIndex(0).setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build().toJsonBytes()), new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.ROLLING_OUT).build().toJsonBytes())), ImmutableSet.copyOf(op.operations()));
    // Two events should return: rollingUpdateStarted and rollingUpdateDone
    assertEquals(1, op.events().size());
    verify(eventFactory).rollingUpdateStarted(MANUAL_DEPLOYMENT_GROUP);
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) CreateEmpty(com.spotify.helios.servicescommon.coordination.CreateEmpty) SetData(com.spotify.helios.servicescommon.coordination.SetData) Test(org.junit.Test)

Example 4 with SetData

use of com.spotify.helios.servicescommon.coordination.SetData in project helios by spotify.

the class RollingUpdateOpFactoryTest method testNextTaskNoOps.

@Test
public void testNextTaskNoOps() {
    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.nextTask();
    // A nextTask op with no ZK operations should result advancing the task index
    assertEquals(1, op.operations().size());
    assertEquals(new SetData("/status/deployment-group-tasks/my_group", deploymentGroupTasks.toBuilder().setTaskIndex(1).build().toJsonBytes()), op.operations().get(0));
    // No events should be generated
    assertEquals(0, op.events().size());
}
Also used : DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) SetData(com.spotify.helios.servicescommon.coordination.SetData) Test(org.junit.Test)

Example 5 with SetData

use of com.spotify.helios.servicescommon.coordination.SetData in project helios by spotify.

the class RollingUpdateOpFactoryTest method testStartManualNoHosts.

@Test
public void testStartManualNoHosts() 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(null);
    final RollingUpdateOp op = opFactory.start(MANUAL_DEPLOYMENT_GROUP, client);
    // Three ZK operations should return:
    // * create tasks node
    // * delete the tasks
    // * set the status to DONE
    assertEquals(ImmutableSet.of(new CreateEmpty("/status/deployment-group-tasks/my_group"), 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);
}
Also used : Delete(com.spotify.helios.servicescommon.coordination.Delete) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) CreateEmpty(com.spotify.helios.servicescommon.coordination.CreateEmpty) SetData(com.spotify.helios.servicescommon.coordination.SetData) Test(org.junit.Test)

Aggregations

DeploymentGroupTasks (com.spotify.helios.common.descriptors.DeploymentGroupTasks)9 SetData (com.spotify.helios.servicescommon.coordination.SetData)9 Test (org.junit.Test)9 Delete (com.spotify.helios.servicescommon.coordination.Delete)5 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)4 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)3 CreateEmpty (com.spotify.helios.servicescommon.coordination.CreateEmpty)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)2 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)1 Stat (org.apache.zookeeper.data.Stat)1 Matchers.anyString (org.mockito.Matchers.anyString)1