Search in sources :

Example 6 with DeploymentGroupStatus

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);
    }
}
Also used : Stat(org.apache.zookeeper.data.Stat) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) DeploymentGroupStatus(com.spotify.helios.common.descriptors.DeploymentGroupStatus) KeeperException(org.apache.zookeeper.KeeperException)

Example 7 with DeploymentGroupStatus

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));
}
Also used : ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) DeploymentGroupStatus(com.spotify.helios.common.descriptors.DeploymentGroupStatus) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) Map(java.util.Map)

Aggregations

DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)7 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)5 Map (java.util.Map)5 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)3 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)3 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)3 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)3 KeeperException (org.apache.zookeeper.KeeperException)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2 Stat (org.apache.zookeeper.data.Stat)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 DeploymentGroupTasks (com.spotify.helios.common.descriptors.DeploymentGroupTasks)1 HostStatus (com.spotify.helios.common.descriptors.HostStatus)1 JobId (com.spotify.helios.common.descriptors.JobId)1 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)1 DeploymentGroupStatusResponse (com.spotify.helios.common.protocol.DeploymentGroupStatusResponse)1 DeploymentGroupDoesNotExistException (com.spotify.helios.master.DeploymentGroupDoesNotExistException)1