@Test public void testStartManualNoHosts() throws Exception { 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); 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())); assertEquals(2, op.events().size()); verify(eventFactory).rollingUpdateStarted(MANUAL_DEPLOYMENT_GROUP); verify(eventFactory).rollingUpdateDone(MANUAL_DEPLOYMENT_GROUP); }
public RollingUpdateOp start(final DeploymentGroup deploymentGroup, final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.statusDeploymentGroupTasks()); final List<ZooKeeperOperation> ops = Lists.newArrayList(); final List<Map<String, Object>> events = Lists.newArrayList(); final List<RolloutTask> rolloutTasks = tasks.getRolloutTasks(); events.add(eventFactory.rollingUpdateStarted(deploymentGroup)); final Stat tasksStat = client.exists( Paths.statusDeploymentGroupTasks(deploymentGroup.getName())); if (tasksStat == null) { ops.add(create(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); } final DeploymentGroupStatus status; if (rolloutTasks.isEmpty()) { status = DeploymentGroupStatus.newBuilder() .setState(DONE) .build(); ops.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); events.add(eventFactory.rollingUpdateDone(deploymentGroup)); } else { final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder() .setRolloutTasks(rolloutTasks) .setTaskIndex(0) .setDeploymentGroup(deploymentGroup) .build(); status = DeploymentGroupStatus.newBuilder() .setState(ROLLING_OUT) .build(); ops.add(set(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()), tasks)); } ops.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); return new RollingUpdateOp(ImmutableList.copyOf(ops), ImmutableList.copyOf(events)); }
RollingUpdateOpFactory { public RollingUpdateOp start(final DeploymentGroup deploymentGroup, final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.statusDeploymentGroupTasks()); final List<ZooKeeperOperation> ops = Lists.newArrayList(); final List<Map<String, Object>> events = Lists.newArrayList(); final List<RolloutTask> rolloutTasks = tasks.getRolloutTasks(); events.add(eventFactory.rollingUpdateStarted(deploymentGroup)); final Stat tasksStat = client.exists( Paths.statusDeploymentGroupTasks(deploymentGroup.getName())); if (tasksStat == null) { ops.add(create(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); } final DeploymentGroupStatus status; if (rolloutTasks.isEmpty()) { status = DeploymentGroupStatus.newBuilder() .setState(DONE) .build(); ops.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); events.add(eventFactory.rollingUpdateDone(deploymentGroup)); } else { final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder() .setRolloutTasks(rolloutTasks) .setTaskIndex(0) .setDeploymentGroup(deploymentGroup) .build(); status = DeploymentGroupStatus.newBuilder() .setState(ROLLING_OUT) .build(); ops.add(set(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()), tasks)); } ops.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); return new RollingUpdateOp(ImmutableList.copyOf(ops), ImmutableList.copyOf(events)); } }
RollingUpdateOpFactory { public RollingUpdateOp start(final DeploymentGroup deploymentGroup, final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.statusDeploymentGroupTasks()); final List<ZooKeeperOperation> ops = Lists.newArrayList(); final List<Map<String, Object>> events = Lists.newArrayList(); final List<RolloutTask> rolloutTasks = tasks.getRolloutTasks(); events.add(eventFactory.rollingUpdateStarted(deploymentGroup)); final Stat tasksStat = client.exists( Paths.statusDeploymentGroupTasks(deploymentGroup.getName())); if (tasksStat == null) { ops.add(create(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); } final DeploymentGroupStatus status; if (rolloutTasks.isEmpty()) { status = DeploymentGroupStatus.newBuilder() .setState(DONE) .build(); ops.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); events.add(eventFactory.rollingUpdateDone(deploymentGroup)); } else { final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder() .setRolloutTasks(rolloutTasks) .setTaskIndex(0) .setDeploymentGroup(deploymentGroup) .build(); status = DeploymentGroupStatus.newBuilder() .setState(ROLLING_OUT) .build(); ops.add(set(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()), tasks)); } ops.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); return new RollingUpdateOp(ImmutableList.copyOf(ops), ImmutableList.copyOf(events)); } RollingUpdateOpFactory(final DeploymentGroupTasks tasks,
                                final DeploymentGroupEventFactory eventFactory); }
RollingUpdateOpFactory { public RollingUpdateOp start(final DeploymentGroup deploymentGroup, final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.statusDeploymentGroupTasks()); final List<ZooKeeperOperation> ops = Lists.newArrayList(); final List<Map<String, Object>> events = Lists.newArrayList(); final List<RolloutTask> rolloutTasks = tasks.getRolloutTasks(); events.add(eventFactory.rollingUpdateStarted(deploymentGroup)); final Stat tasksStat = client.exists( Paths.statusDeploymentGroupTasks(deploymentGroup.getName())); if (tasksStat == null) { ops.add(create(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); } final DeploymentGroupStatus status; if (rolloutTasks.isEmpty()) { status = DeploymentGroupStatus.newBuilder() .setState(DONE) .build(); ops.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); events.add(eventFactory.rollingUpdateDone(deploymentGroup)); } else { final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder() .setRolloutTasks(rolloutTasks) .setTaskIndex(0) .setDeploymentGroup(deploymentGroup) .build(); status = DeploymentGroupStatus.newBuilder() .setState(ROLLING_OUT) .build(); ops.add(set(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()), tasks)); } ops.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); return new RollingUpdateOp(ImmutableList.copyOf(ops), ImmutableList.copyOf(events)); } RollingUpdateOpFactory(final DeploymentGroupTasks tasks,
                                final DeploymentGroupEventFactory eventFactory); RollingUpdateOp start(final DeploymentGroup deploymentGroup,
                               final ZooKeeperClient client); RollingUpdateOp nextTask(); RollingUpdateOp nextTask(final List<ZooKeeperOperation> operations); RollingUpdateOp yield(); RollingUpdateOp error(final String msg, final String host,
                               final RollingUpdateError errorCode,
                               final Map<String, Object> metadata); RollingUpdateOp error(final String msg, final String host,
                               final RollingUpdateError errorCode); RollingUpdateOp error(final Exception ex, final String host,
                               final RollingUpdateError errorCode); }
RollingUpdateOpFactory { public RollingUpdateOp start(final DeploymentGroup deploymentGroup, final ZooKeeperClient client) throws KeeperException { client.ensurePath(Paths.statusDeploymentGroupTasks()); final List<ZooKeeperOperation> ops = Lists.newArrayList(); final List<Map<String, Object>> events = Lists.newArrayList(); final List<RolloutTask> rolloutTasks = tasks.getRolloutTasks(); events.add(eventFactory.rollingUpdateStarted(deploymentGroup)); final Stat tasksStat = client.exists( Paths.statusDeploymentGroupTasks(deploymentGroup.getName())); if (tasksStat == null) { ops.add(create(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); } final DeploymentGroupStatus status; if (rolloutTasks.isEmpty()) { status = DeploymentGroupStatus.newBuilder() .setState(DONE) .build(); ops.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); events.add(eventFactory.rollingUpdateDone(deploymentGroup)); } else { final DeploymentGroupTasks tasks = DeploymentGroupTasks.newBuilder() .setRolloutTasks(rolloutTasks) .setTaskIndex(0) .setDeploymentGroup(deploymentGroup) .build(); status = DeploymentGroupStatus.newBuilder() .setState(ROLLING_OUT) .build(); ops.add(set(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()), tasks)); } ops.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); return new RollingUpdateOp(ImmutableList.copyOf(ops), ImmutableList.copyOf(events)); } RollingUpdateOpFactory(final DeploymentGroupTasks tasks,
                                final DeploymentGroupEventFactory eventFactory); RollingUpdateOp start(final DeploymentGroup deploymentGroup,
                               final ZooKeeperClient client); RollingUpdateOp nextTask(); RollingUpdateOp nextTask(final List<ZooKeeperOperation> operations); RollingUpdateOp yield(); RollingUpdateOp error(final String msg, final String host,
                               final RollingUpdateError errorCode,
                               final Map<String, Object> metadata); RollingUpdateOp error(final String msg, final String host,
                               final RollingUpdateError errorCode); RollingUpdateOp error(final Exception ex, final String host,
                               final RollingUpdateError errorCode);  }