use of com.spotify.helios.common.descriptors.DeploymentGroupStatus in project helios by spotify.
the class ZooKeeperMasterModel method stopDeploymentGroup.
@Override
public void stopDeploymentGroup(final String deploymentGroupName) throws DeploymentGroupDoesNotExistException {
checkNotNull(deploymentGroupName, "name");
log.info("stop deployment-group: name={}", deploymentGroupName);
final ZooKeeperClient client = provider.get("stopDeploymentGroup");
// Delete deployment group tasks (if any) and set DG state to FAILED
final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder().setState(FAILED).setError("Stopped by user").build();
final String statusPath = Paths.statusDeploymentGroup(deploymentGroupName);
final String tasksPath = Paths.statusDeploymentGroupTasks(deploymentGroupName);
try {
client.ensurePath(Paths.statusDeploymentGroupTasks());
final List<ZooKeeperOperation> operations = Lists.newArrayList();
// NOTE: This remove operation is racey. If tasks exist and the rollout finishes before the
// delete() is executed then this will fail. Conversely, if it doesn't exist but is created
// before the transaction is executed it will also fail. This is annoying for users, but at
// least means we won't have inconsistent state.
//
// That the set() is first in the list of operations is important because of the
// kludgy error checking we do below to disambiguate "doesn't exist" failures from the race
// condition mentioned below.
operations.add(set(statusPath, status));
final Stat tasksStat = client.exists(tasksPath);
if (tasksStat != null) {
operations.add(delete(tasksPath));
} else {
// There doesn't seem to be a "check that node doesn't exist" operation so we
// do a create and a delete on the same path to emulate it.
operations.add(create(tasksPath));
operations.add(delete(tasksPath));
}
client.transaction(operations);
} catch (final NoNodeException e) {
// Yes, the way you figure out which operation in a transaction failed is retarded.
if (((OpResult.ErrorResult) e.getResults().get(0)).getErr() == KeeperException.Code.NONODE.intValue()) {
throw new DeploymentGroupDoesNotExistException(deploymentGroupName);
} else {
throw new HeliosRuntimeException("stop deployment-group " + deploymentGroupName + " failed due to a race condition, please retry", e);
}
} catch (final KeeperException e) {
throw new HeliosRuntimeException("stop deployment-group " + deploymentGroupName + " failed", e);
}
}
use of com.spotify.helios.common.descriptors.DeploymentGroupStatus in project helios by spotify.
the class RollingUpdateOpFactory method error.
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;
final DeploymentGroupStatus status = DeploymentGroupStatus.newBuilder().setState(FAILED).setError(errMsg).build();
// Delete tasks, set state to FAILED
operations.add(delete(Paths.statusDeploymentGroupTasks(deploymentGroup.getName())));
operations.add(set(Paths.statusDeploymentGroup(deploymentGroup.getName()), status));
final RolloutTask task = tasks.getRolloutTasks().get(tasks.getTaskIndex());
// Emit a FAILED event and a failed task event
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));
return new RollingUpdateOp(ImmutableList.copyOf(operations), ImmutableList.copyOf(events));
}
Aggregations