Search in sources :

Example 6 with DeploymentGroupTasks

use of com.spotify.helios.common.descriptors.DeploymentGroupTasks 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 7 with DeploymentGroupTasks

use of com.spotify.helios.common.descriptors.DeploymentGroupTasks 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 8 with DeploymentGroupTasks

use of com.spotify.helios.common.descriptors.DeploymentGroupTasks 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)

Example 9 with DeploymentGroupTasks

use of com.spotify.helios.common.descriptors.DeploymentGroupTasks in project helios by spotify.

the class RollingUpdateOpFactoryTest method testTransitionToFailed.

@Test
public void testTransitionToFailed() {
    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.error("foo", "host1", RollingUpdateError.HOST_NOT_FOUND);
    final Map<String, Object> failEvent = Maps.newHashMap();
    when(eventFactory.rollingUpdateTaskFailed(any(DeploymentGroup.class), any(RolloutTask.class), anyString(), any(RollingUpdateError.class))).thenReturn(failEvent);
    // When state -> FAILED we expected
    // * deployment group tasks are deleted
    // * deployment group status is updated (to FAILED)
    assertEquals(ImmutableSet.of(new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.FAILED).setError("host1: foo").build().toJsonBytes()), new Delete("/status/deployment-group-tasks/my_group")), ImmutableSet.copyOf(op.operations()));
    // ...and that a failed-task event and a rolling-update failed event are emitted
    assertEquals(2, op.events().size());
    verify(eventFactory).rollingUpdateTaskFailed(eq(MANUAL_DEPLOYMENT_GROUP), eq(deploymentGroupTasks.getRolloutTasks().get(deploymentGroupTasks.getTaskIndex())), anyString(), eq(RollingUpdateError.HOST_NOT_FOUND), eq(Collections.<String, Object>emptyMap()));
    verify(eventFactory).rollingUpdateFailed(eq(MANUAL_DEPLOYMENT_GROUP), eq(failEvent));
}
Also used : Delete(com.spotify.helios.servicescommon.coordination.Delete) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) Matchers.anyString(org.mockito.Matchers.anyString) SetData(com.spotify.helios.servicescommon.coordination.SetData) DeploymentGroup(com.spotify.helios.common.descriptors.DeploymentGroup) Test(org.junit.Test)

Example 10 with DeploymentGroupTasks

use of com.spotify.helios.common.descriptors.DeploymentGroupTasks in project helios by spotify.

the class RollingUpdateOpFactoryTest method testNextTaskWithOps.

@Test
public void testNextTaskWithOps() {
    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 ZooKeeperOperation mockOp = mock(ZooKeeperOperation.class);
    final RollingUpdateOp op = opFactory.nextTask(Lists.newArrayList(mockOp));
    // A nexTask op with ZK operations should result in advancing the task index
    // and also contain the specified ZK operations
    assertEquals(ImmutableSet.of(mockOp, new SetData("/status/deployment-group-tasks/my_group", deploymentGroupTasks.toBuilder().setTaskIndex(1).build().toJsonBytes())), ImmutableSet.copyOf(op.operations()));
    // This is not a no-op -> an event should be emitted
    assertEquals(1, op.events().size());
    verify(eventFactory).rollingUpdateTaskSucceeded(MANUAL_DEPLOYMENT_GROUP, deploymentGroupTasks.getRolloutTasks().get(deploymentGroupTasks.getTaskIndex()));
}
Also used : ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) SetData(com.spotify.helios.servicescommon.coordination.SetData) Test(org.junit.Test)

Aggregations

DeploymentGroupTasks (com.spotify.helios.common.descriptors.DeploymentGroupTasks)14 Test (org.junit.Test)10 SetData (com.spotify.helios.servicescommon.coordination.SetData)9 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)6 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)6 Delete (com.spotify.helios.servicescommon.coordination.Delete)5 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)4 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)3 Stat (org.apache.zookeeper.data.Stat)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)2 VersionedValue (com.spotify.helios.servicescommon.VersionedValue)2 CreateEmpty (com.spotify.helios.servicescommon.coordination.CreateEmpty)2 IOException (java.io.IOException)2 Map (java.util.Map)2 KeeperException (org.apache.zookeeper.KeeperException)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2