Search in sources :

Example 1 with NotEmptyException

use of org.apache.zookeeper.KeeperException.NotEmptyException in project helios by spotify.

the class ZooKeeperMasterModel method removeJob.

/**
 * Deletes a job from ZooKeeper.  Ensures that job is not currently running anywhere.
 */
@Override
public Job removeJob(final JobId id, final String token) throws JobDoesNotExistException, JobStillDeployedException, TokenVerificationException {
    log.info("removing job: id={}", id);
    final ZooKeeperClient client = provider.get("removeJob");
    final Job job = getJob(client, id);
    if (job == null) {
        throw new JobDoesNotExistException(id);
    }
    verifyToken(token, job);
    // TODO (dano): handle retry failures
    try {
        final ImmutableList.Builder<ZooKeeperOperation> operations = ImmutableList.builder();
        final UUID jobCreationOperationId = getJobCreation(client, id);
        if (jobCreationOperationId != null) {
            operations.add(delete(Paths.configJobCreation(id, jobCreationOperationId)));
        }
        operations.add(delete(Paths.configJobHosts(id)), delete(Paths.configJobRefShort(id)), delete(Paths.configJob(id)), // change down the tree. Effectively, make it that version == cVersion.
        set(Paths.configJobs(), UUID.randomUUID().toString().getBytes()));
        client.transaction(operations.build());
    } catch (final NoNodeException e) {
        throw new JobDoesNotExistException(id);
    } catch (final NotEmptyException e) {
        throw new JobStillDeployedException(id, listJobHosts(client, id));
    } catch (final KeeperException e) {
        throw new HeliosRuntimeException("removing job " + id + " failed", e);
    }
    // Delete job history on a best effort basis
    try {
        client.deleteRecursive(Paths.historyJob(id));
    } catch (NoNodeException ignored) {
    // There's no history for this job
    } catch (KeeperException e) {
        log.warn("error removing job history for job {}", id, e);
    }
    return job;
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) ImmutableList(com.google.common.collect.ImmutableList) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) NotEmptyException(org.apache.zookeeper.KeeperException.NotEmptyException) Job(com.spotify.helios.common.descriptors.Job) UUID(java.util.UUID) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)1 Job (com.spotify.helios.common.descriptors.Job)1 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)1 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)1 UUID (java.util.UUID)1 KeeperException (org.apache.zookeeper.KeeperException)1 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)1 NotEmptyException (org.apache.zookeeper.KeeperException.NotEmptyException)1