@Test public void testErrorWhenIgnoreFailuresIsTrue() { final DeploymentGroup deploymentGroup = DeploymentGroup.newBuilder() .setName("ignore_failure_group") .setRolloutOptions(RolloutOptions.newBuilder() .setIgnoreFailures(true) .build() ) .setRollingUpdateReason(MANUAL) .build(); 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") )); }
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);  }