Search in sources :

Example 1 with VersionedValue

use of com.spotify.helios.servicescommon.VersionedValue in project helios by spotify.

the class ZooKeeperMasterModel method rollingUpdateStep.

@Override
public void rollingUpdateStep() {
    final ZooKeeperClient client = provider.get("rollingUpdateStep");
    final Map<String, VersionedValue<DeploymentGroupTasks>> tasksMap = getDeploymentGroupTasks(client);
    for (final Map.Entry<String, VersionedValue<DeploymentGroupTasks>> entry : tasksMap.entrySet()) {
        final String deploymentGroupName = entry.getKey();
        final VersionedValue<DeploymentGroupTasks> versionedTasks = entry.getValue();
        final DeploymentGroupTasks tasks = versionedTasks.value();
        final int taskIndex = tasks.getTaskIndex();
        log.info("rolling-update step on deployment-group {}. Doing taskIndex {} of {}: {}. ", deploymentGroupName, taskIndex, tasks.getRolloutTasks().size(), tasks.getRolloutTasks().get(taskIndex));
        try {
            final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(tasks, DEPLOYMENT_GROUP_EVENT_FACTORY);
            final RolloutTask task = tasks.getRolloutTasks().get(taskIndex);
            final RollingUpdateOp op = processRollingUpdateTask(client, opFactory, task, tasks.getDeploymentGroup());
            if (!op.operations().isEmpty()) {
                final List<ZooKeeperOperation> ops = Lists.newArrayList();
                ops.add(check(Paths.statusDeploymentGroupTasks(deploymentGroupName), versionedTasks.version()));
                ops.addAll(op.operations());
                log.info("rolling-update step on deployment-group: name={}, zookeeper operations={}", deploymentGroupName, ops);
                try {
                    client.transaction(ops);
                    emitEvents(deploymentGroupEventTopic, op.events());
                } catch (BadVersionException e) {
                    // some other master beat us in processing this rolling update step. not exceptional.
                    // ideally we would check the path in the exception, but curator doesn't provide a path
                    // for exceptions thrown as part of a transaction.
                    log.info("rolling-update step on deployment-group was processed by another master" + ": name={}, zookeeper operations={}", deploymentGroupName, ops);
                } catch (KeeperException e) {
                    log.error("rolling-update on deployment-group {} failed", deploymentGroupName, e);
                }
            }
        } catch (final Exception e) {
            log.error("error processing rolling update step for {}", deploymentGroupName, e);
        }
    }
}
Also used : VersionedValue(com.spotify.helios.servicescommon.VersionedValue) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) BadVersionException(org.apache.zookeeper.KeeperException.BadVersionException) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) NotEmptyException(org.apache.zookeeper.KeeperException.NotEmptyException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) BadVersionException(org.apache.zookeeper.KeeperException.BadVersionException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) RollingUpdateOpFactory(com.spotify.helios.rollingupdate.RollingUpdateOpFactory) RollingUpdateOp(com.spotify.helios.rollingupdate.RollingUpdateOp) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Collections.emptyMap(java.util.Collections.emptyMap) KeeperException(org.apache.zookeeper.KeeperException)

Example 2 with VersionedValue

use of com.spotify.helios.servicescommon.VersionedValue in project helios by spotify.

the class ZooKeeperMasterModel method getDeploymentGroupTasks.

private Map<String, VersionedValue<DeploymentGroupTasks>> getDeploymentGroupTasks(final ZooKeeperClient client) {
    final String folder = Paths.statusDeploymentGroupTasks();
    try {
        final List<String> names;
        try {
            names = client.getChildren(folder);
        } catch (NoNodeException e) {
            return Collections.emptyMap();
        }
        final Map<String, VersionedValue<DeploymentGroupTasks>> ret = Maps.newHashMap();
        for (final String name : names) {
            final String path = Paths.statusDeploymentGroupTasks(name);
            try {
                final Node node = client.getNode(path);
                final byte[] data = node.getBytes();
                final int version = node.getStat().getVersion();
                if (data.length == 0) {
                    // This can happen because of ensurePath creates an empty node
                    log.debug("Ignoring empty deployment group tasks {}", name);
                } else {
                    final DeploymentGroupTasks val = parse(data, DeploymentGroupTasks.class);
                    ret.put(name, VersionedValue.of(val, version));
                }
            } catch (NoNodeException e) {
                // Ignore, the deployment group was deleted before we had a chance to read it.
                log.debug("Ignoring deleted deployment group tasks {}", name);
            }
        }
        return ret;
    } catch (KeeperException | IOException e) {
        throw new HeliosRuntimeException("getting deployment group tasks failed", e);
    }
}
Also used : VersionedValue(com.spotify.helios.servicescommon.VersionedValue) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Node(com.spotify.helios.servicescommon.coordination.Node) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) DeploymentGroupTasks(com.spotify.helios.common.descriptors.DeploymentGroupTasks) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)2 DeploymentGroupTasks (com.spotify.helios.common.descriptors.DeploymentGroupTasks)2 VersionedValue (com.spotify.helios.servicescommon.VersionedValue)2 IOException (java.io.IOException)2 KeeperException (org.apache.zookeeper.KeeperException)2 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)1 RollingUpdateOp (com.spotify.helios.rollingupdate.RollingUpdateOp)1 RollingUpdateOpFactory (com.spotify.helios.rollingupdate.RollingUpdateOpFactory)1 Node (com.spotify.helios.servicescommon.coordination.Node)1 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)1 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)1 Collections.emptyMap (java.util.Collections.emptyMap)1 Map (java.util.Map)1 BadVersionException (org.apache.zookeeper.KeeperException.BadVersionException)1 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)1 NotEmptyException (org.apache.zookeeper.KeeperException.NotEmptyException)1