Search in sources :

Example 16 with HeliosRuntimeException

use of com.spotify.helios.common.HeliosRuntimeException in project helios by spotify.

the class ZooKeeperMasterModel method checkForPortConflicts.

private static void checkForPortConflicts(final ZooKeeperClient client, final String host, final int port, final JobId jobId) throws JobPortAllocationConflictException {
    try {
        final String path = Paths.configHostPort(host, port);
        if (client.stat(path) == null) {
            return;
        }
        final byte[] b = client.getData(path);
        final JobId existingJobId = parse(b, JobId.class);
        throw new JobPortAllocationConflictException(jobId, existingJobId, host, port);
    } catch (KeeperException | IOException ex) {
        throw new HeliosRuntimeException("checking port allocations failed", ex);
    }
}
Also used : HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) IOException(java.io.IOException) JobId(com.spotify.helios.common.descriptors.JobId) KeeperException(org.apache.zookeeper.KeeperException)

Example 17 with HeliosRuntimeException

use of com.spotify.helios.common.HeliosRuntimeException in project helios by spotify.

the class ZooKeeperMasterModel method listHostJobs.

private List<JobId> listHostJobs(final ZooKeeperClient client, final String host) {
    final List<String> jobIdStrings;
    final String folder = Paths.statusHostJobs(host);
    try {
        jobIdStrings = client.getChildren(folder);
    } catch (KeeperException.NoNodeException e) {
        return null;
    } catch (KeeperException e) {
        throw new HeliosRuntimeException("List tasks for host failed: " + host, e);
    }
    final ImmutableList.Builder<JobId> jobIds = ImmutableList.builder();
    for (final String jobIdString : jobIdStrings) {
        jobIds.add(JobId.fromString(jobIdString));
    }
    return jobIds.build();
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ImmutableList(com.google.common.collect.ImmutableList) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) KeeperException(org.apache.zookeeper.KeeperException) JobId(com.spotify.helios.common.descriptors.JobId)

Example 18 with HeliosRuntimeException

use of com.spotify.helios.common.HeliosRuntimeException in project helios by spotify.

the class ZooKeeperMasterModel method removeDeploymentGroup.

/**
   * Remove a deployment group.
   *
   * <p>If successful, all ZK nodes associated with the DG will be deleted. Specifically these
   * nodes are guaranteed to be non-existent after a successful remove (not all of them might exist
   * before, though):
   * <ul>
   *   <li>/config/deployment-groups/[group-name]</li>
   *   <li>/status/deployment-groups/[group-name]</li>
   *   <li>/status/deployment-groups/[group-name]/hosts</li>
   *   <li>/status/deployment-groups/[group-name]/removed</li>
   *   <li>/status/deployment-group-tasks/[group-name]</li>
   * </ul>
   * If the operation fails no ZK nodes will be removed.
   *
   * @throws DeploymentGroupDoesNotExistException If the DG does not exist.
   */
@Override
public void removeDeploymentGroup(final String name) throws DeploymentGroupDoesNotExistException {
    log.info("removing deployment-group: name={}", name);
    final ZooKeeperClient client = provider.get("removeDeploymentGroup");
    try {
        client.ensurePath(Paths.configDeploymentGroups());
        client.ensurePath(Paths.statusDeploymentGroups());
        client.ensurePath(Paths.statusDeploymentGroupTasks());
        final List<ZooKeeperOperation> operations = Lists.newArrayList();
        final List<String> paths = ImmutableList.of(Paths.configDeploymentGroup(name), Paths.statusDeploymentGroup(name), Paths.statusDeploymentGroupHosts(name), Paths.statusDeploymentGroupRemovedHosts(name), Paths.statusDeploymentGroupTasks(name));
        // DGs to become slower and spam logs with errors so we want to avoid it.
        for (final String path : paths) {
            if (client.exists(path) == null) {
                operations.add(create(path));
            }
        }
        for (final String path : Lists.reverse(paths)) {
            operations.add(delete(path));
        }
        client.transaction(operations);
    } catch (final NoNodeException e) {
        throw new DeploymentGroupDoesNotExistException(name);
    } catch (final KeeperException e) {
        throw new HeliosRuntimeException("removing deployment-group " + name + " failed", e);
    }
}
Also used : 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) KeeperException(org.apache.zookeeper.KeeperException)

Example 19 with HeliosRuntimeException

use of com.spotify.helios.common.HeliosRuntimeException in project helios by spotify.

the class ZooKeeperMasterModel method addJob.

/**
   * Adds a job into the configuration.
   */
@Override
public void addJob(final Job job) throws JobExistsException {
    log.info("adding job: {}", job);
    final JobId id = job.getId();
    final UUID operationId = UUID.randomUUID();
    final String creationPath = Paths.configJobCreation(id, operationId);
    final ZooKeeperClient client = provider.get("addJob");
    try {
        try {
            client.ensurePath(Paths.historyJob(id));
            client.transaction(create(Paths.configJob(id), job), create(Paths.configJobRefShort(id), id), create(Paths.configJobHosts(id)), create(creationPath), // change down the tree. Effectively, make it that version == cVersion.
            set(Paths.configJobs(), UUID.randomUUID().toString().getBytes()));
        } catch (final NodeExistsException e) {
            if (client.exists(creationPath) != null) {
                // The job was created, we're done here
                return;
            }
            throw new JobExistsException(id.toString());
        }
    } catch (NoNodeException e) {
        throw new HeliosRuntimeException("adding job " + job + " failed due to missing ZK path: " + e.getPath(), e);
    } catch (final KeeperException e) {
        throw new HeliosRuntimeException("adding job " + job + " failed", e);
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) UUID(java.util.UUID) JobId(com.spotify.helios.common.descriptors.JobId) KeeperException(org.apache.zookeeper.KeeperException)

Example 20 with HeliosRuntimeException

use of com.spotify.helios.common.HeliosRuntimeException in project helios by spotify.

the class ZooKeeperMasterModel method addDeploymentGroup.

/**
   * Create a deployment group.
   *
   * <p>If successful, the following ZK nodes will be created:
   * <ul>
   *   <li>/config/deployment-groups/[group-name]</li>
   *   <li>/status/deployment-groups/[group-name]</li>
   *   <li>/status/deployment-groups/[group-name]/hosts</li>
   * </ul>
   * These nodes are guaranteed to exist until the DG is removed.
   *
   * <p>If the operation fails no ZK nodes will be created. If any of the nodes above already exist
   * the operation will fail.
   *
   * @throws DeploymentGroupExistsException If a DG with the same name already exists.
   */
@Override
public void addDeploymentGroup(final DeploymentGroup deploymentGroup) throws DeploymentGroupExistsException {
    log.info("adding deployment-group: {}", deploymentGroup);
    final ZooKeeperClient client = provider.get("addDeploymentGroup");
    try {
        try {
            client.ensurePath(Paths.configDeploymentGroups());
            client.ensurePath(Paths.statusDeploymentGroups());
            client.transaction(create(Paths.configDeploymentGroup(deploymentGroup.getName()), deploymentGroup), create(Paths.statusDeploymentGroup(deploymentGroup.getName())), create(Paths.statusDeploymentGroupHosts(deploymentGroup.getName()), Json.asBytesUnchecked(emptyList())), create(Paths.statusDeploymentGroupRemovedHosts(deploymentGroup.getName()), Json.asBytesUnchecked(emptyList())));
        } catch (final NodeExistsException e) {
            throw new DeploymentGroupExistsException(deploymentGroup.getName());
        }
    } catch (final KeeperException e) {
        throw new HeliosRuntimeException("adding deployment-group " + deploymentGroup + " failed", e);
    }
}
Also used : ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)27 KeeperException (org.apache.zookeeper.KeeperException)23 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)20 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)16 JobId (com.spotify.helios.common.descriptors.JobId)10 IOException (java.io.IOException)10 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)9 Job (com.spotify.helios.common.descriptors.Job)7 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)5 Task (com.spotify.helios.common.descriptors.Task)5 Deployment (com.spotify.helios.common.descriptors.Deployment)4 DeploymentGroup (com.spotify.helios.common.descriptors.DeploymentGroup)4 UUID (java.util.UUID)4 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)4 ImmutableList (com.google.common.collect.ImmutableList)3 Node (com.spotify.helios.servicescommon.coordination.Node)3 DeploymentGroupStatus (com.spotify.helios.common.descriptors.DeploymentGroupStatus)2 HostNotFoundException (com.spotify.helios.master.HostNotFoundException)2 RollingUpdateOp (com.spotify.helios.rollingupdate.RollingUpdateOp)2 DefaultZooKeeperClient (com.spotify.helios.servicescommon.coordination.DefaultZooKeeperClient)2