@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); 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())); 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)); }
public RollingUpdateOp error(final String msg, final String host, final RollingUpdateError errorCode, final Map<String, Object> metadata) { final List<ZooKeeperOperation> operations = Lists.newArrayList(); final String errMsg = isNullOrEmpty(host) ? msg : host + ": " + msg; if (isIgnoreFailures()) { log.info( "would have set state=FAILED for deploymentGroup={} but ignoreFailures is set to true " + "for this group/rollout. errorCode={} message={}", deploymentGroup.getName(), errorCode, errMsg); return nextTask(operations); } final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder() .setState(FAILED) .setError(errMsg) .build(); operations.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); operations.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); final RolloutTask task = tasks.getRolloutTasks().get(tasks.getTaskIndex()); final List<Map<String, Object>> events = Lists.newArrayList(); final Map<String, Object> taskEv = eventFactory.rollingUpdateTaskFailed( deploymentGroup, task, errMsg, errorCode, metadata); events.add(taskEv); events.add(eventFactory.rollingUpdateFailed(deploymentGroup, taskEv)); log.info("rolling-update step on deployment-group name={} failed; message={}", deploymentGroup.getName(), errMsg); return new RollingUpdateOp(ImmutableList.copyOf(operations), ImmutableList.copyOf(events)); }
RollingUpdateOpFactory { public RollingUpdateOp error(final String msg, final String host, final RollingUpdateError errorCode, final Map<String, Object> metadata) { final List<ZooKeeperOperation> operations = Lists.newArrayList(); final String errMsg = isNullOrEmpty(host) ? msg : host + ": " + msg; if (isIgnoreFailures()) { log.info( "would have set state=FAILED for deploymentGroup={} but ignoreFailures is set to true " + "for this group/rollout. errorCode={} message={}", deploymentGroup.getName(), errorCode, errMsg); return nextTask(operations); } final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder() .setState(FAILED) .setError(errMsg) .build(); operations.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); operations.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); final RolloutTask task = tasks.getRolloutTasks().get(tasks.getTaskIndex()); final List<Map<String, Object>> events = Lists.newArrayList(); final Map<String, Object> taskEv = eventFactory.rollingUpdateTaskFailed( deploymentGroup, task, errMsg, errorCode, metadata); events.add(taskEv); events.add(eventFactory.rollingUpdateFailed(deploymentGroup, taskEv)); log.info("rolling-update step on deployment-group name={} failed; message={}", deploymentGroup.getName(), errMsg); return new RollingUpdateOp(ImmutableList.copyOf(operations), ImmutableList.copyOf(events)); } }
RollingUpdateOpFactory { public RollingUpdateOp error(final String msg, final String host, final RollingUpdateError errorCode, final Map<String, Object> metadata) { final List<ZooKeeperOperation> operations = Lists.newArrayList(); final String errMsg = isNullOrEmpty(host) ? msg : host + ": " + msg; if (isIgnoreFailures()) { log.info( "would have set state=FAILED for deploymentGroup={} but ignoreFailures is set to true " + "for this group/rollout. errorCode={} message={}", deploymentGroup.getName(), errorCode, errMsg); return nextTask(operations); } final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder() .setState(FAILED) .setError(errMsg) .build(); operations.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); operations.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); final RolloutTask task = tasks.getRolloutTasks().get(tasks.getTaskIndex()); final List<Map<String, Object>> events = Lists.newArrayList(); final Map<String, Object> taskEv = eventFactory.rollingUpdateTaskFailed( deploymentGroup, task, errMsg, errorCode, metadata); events.add(taskEv); events.add(eventFactory.rollingUpdateFailed(deploymentGroup, taskEv)); log.info("rolling-update step on deployment-group name={} failed; message={}", deploymentGroup.getName(), errMsg); return new RollingUpdateOp(ImmutableList.copyOf(operations), ImmutableList.copyOf(events)); } RollingUpdateOpFactory(final DeploymentGroupTasks tasks,
                                final DeploymentGroupEventFactory eventFactory); }
RollingUpdateOpFactory { public RollingUpdateOp error(final String msg, final String host, final RollingUpdateError errorCode, final Map<String, Object> metadata) { final List<ZooKeeperOperation> operations = Lists.newArrayList(); final String errMsg = isNullOrEmpty(host) ? msg : host + ": " + msg; if (isIgnoreFailures()) { log.info( "would have set state=FAILED for deploymentGroup={} but ignoreFailures is set to true " + "for this group/rollout. errorCode={} message={}", deploymentGroup.getName(), errorCode, errMsg); return nextTask(operations); } final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder() .setState(FAILED) .setError(errMsg) .build(); operations.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); operations.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); final RolloutTask task = tasks.getRolloutTasks().get(tasks.getTaskIndex()); final List<Map<String, Object>> events = Lists.newArrayList(); final Map<String, Object> taskEv = eventFactory.rollingUpdateTaskFailed( deploymentGroup, task, errMsg, errorCode, metadata); events.add(taskEv); events.add(eventFactory.rollingUpdateFailed(deploymentGroup, taskEv)); log.info("rolling-update step on deployment-group name={} failed; message={}", deploymentGroup.getName(), errMsg); return new RollingUpdateOp(ImmutableList.copyOf(operations), 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 error(final String msg, final String host, final RollingUpdateError errorCode, final Map<String, Object> metadata) { final List<ZooKeeperOperation> operations = Lists.newArrayList(); final String errMsg = isNullOrEmpty(host) ? msg : host + ": " + msg; if (isIgnoreFailures()) { log.info( "would have set state=FAILED for deploymentGroup={} but ignoreFailures is set to true " + "for this group/rollout. errorCode={} message={}", deploymentGroup.getName(), errorCode, errMsg); return nextTask(operations); } final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder() .setState(FAILED) .setError(errMsg) .build(); operations.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName()))); operations.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status)); final RolloutTask task = tasks.getRolloutTasks().get(tasks.getTaskIndex()); final List<Map<String, Object>> events = Lists.newArrayList(); final Map<String, Object> taskEv = eventFactory.rollingUpdateTaskFailed( deploymentGroup, task, errMsg, errorCode, metadata); events.add(taskEv); events.add(eventFactory.rollingUpdateFailed(deploymentGroup, taskEv)); log.info("rolling-update step on deployment-group name={} failed; message={}", deploymentGroup.getName(), errMsg); return new RollingUpdateOp(ImmutableList.copyOf(operations), 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);  }