Search in sources :

Example 1 with Task

use of com.spotify.helios.common.descriptors.Task in project helios by spotify.

the class AgentTest method configure.

private void configure(final Job job, final Goal goal) {
    final Task task = new Task(job, goal, Task.EMPTY_DEPLOYER_USER, Task.EMPTY_DEPLOYER_MASTER, Task.EMPTY_DEPOYMENT_GROUP_NAME);
    jobs.put(job.getId(), task);
}
Also used : Task(com.spotify.helios.common.descriptors.Task)

Example 2 with Task

use of com.spotify.helios.common.descriptors.Task in project helios by spotify.

the class ZooKeeperMasterModel method getDeployment.

/**
   * Returns the current deployment state of {@code jobId} on {@code host}.
   */
@Override
public Deployment getDeployment(final String host, final JobId jobId) {
    final String path = Paths.configHostJob(host, jobId);
    final ZooKeeperClient client = provider.get("getDeployment");
    try {
        final byte[] data = client.getData(path);
        final Task task = parse(data, Task.class);
        return Deployment.of(jobId, task.getGoal(), task.getDeployerUser(), task.getDeployerMaster(), task.getDeploymentGroupName());
    } catch (KeeperException.NoNodeException e) {
        return null;
    } catch (KeeperException | IOException e) {
        throw new HeliosRuntimeException("getting deployment failed", e);
    }
}
Also used : Task(com.spotify.helios.common.descriptors.Task) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) IOException(java.io.IOException) KeeperException(org.apache.zookeeper.KeeperException)

Example 3 with Task

use of com.spotify.helios.common.descriptors.Task in project helios by spotify.

the class ZooKeeperMasterModel method getDeployOperations.

private List<ZooKeeperOperation> getDeployOperations(final ZooKeeperClient client, final String host, final Deployment deployment, final String token) throws JobDoesNotExistException, JobAlreadyDeployedException, TokenVerificationException, HostNotFoundException, JobPortAllocationConflictException {
    assertHostExists(client, host);
    final JobId id = deployment.getJobId();
    final Job job = getJob(id);
    if (job == null) {
        throw new JobDoesNotExistException(id);
    }
    verifyToken(token, job);
    final UUID operationId = UUID.randomUUID();
    final String jobPath = Paths.configJob(id);
    final String taskPath = Paths.configHostJob(host, id);
    final String taskCreationPath = Paths.configHostJobCreation(host, id, operationId);
    final List<Integer> staticPorts = staticPorts(job);
    final Map<String, byte[]> portNodes = Maps.newHashMap();
    final byte[] idJson = id.toJsonBytes();
    for (final int port : staticPorts) {
        final String path = Paths.configHostPort(host, port);
        portNodes.put(path, idJson);
    }
    final Task task = new Task(job, deployment.getGoal(), deployment.getDeployerUser(), deployment.getDeployerMaster(), deployment.getDeploymentGroupName());
    final List<ZooKeeperOperation> operations = Lists.newArrayList(check(jobPath), create(portNodes), create(Paths.configJobHost(id, host)));
    // Attempt to read a task here.
    try {
        client.getNode(taskPath);
        // if we get here the node exists already
        throw new JobAlreadyDeployedException(host, id);
    } catch (NoNodeException e) {
        // if the real reason of the failure is that the job is already deployed.
        for (final int port : staticPorts) {
            checkForPortConflicts(client, host, port, id);
        }
        operations.add(create(taskPath, task));
        operations.add(create(taskCreationPath));
    } catch (KeeperException e) {
        throw new HeliosRuntimeException("reading existing task description failed", e);
    }
    return ImmutableList.copyOf(operations);
}
Also used : Task(com.spotify.helios.common.descriptors.Task) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ZooKeeperOperation(com.spotify.helios.servicescommon.coordination.ZooKeeperOperation) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) Job(com.spotify.helios.common.descriptors.Job) UUID(java.util.UUID) JobId(com.spotify.helios.common.descriptors.JobId) KeeperException(org.apache.zookeeper.KeeperException)

Example 4 with Task

use of com.spotify.helios.common.descriptors.Task in project helios by spotify.

the class ZooKeeperMasterModel method updateDeployment.

/**
   * Used to update the existing deployment of a job.
   */
@Override
public void updateDeployment(final String host, final Deployment deployment, final String token) throws HostNotFoundException, JobNotDeployedException, TokenVerificationException {
    log.info("updating deployment {}: {}", deployment, host);
    final ZooKeeperClient client = provider.get("updateDeployment");
    final JobId jobId = deployment.getJobId();
    final Job job = getJob(client, jobId);
    final Deployment existingDeployment = getDeployment(host, jobId);
    if (job == null) {
        throw new JobNotDeployedException(host, jobId);
    }
    verifyToken(token, job);
    assertHostExists(client, host);
    assertTaskExists(client, host, deployment.getJobId());
    final String path = Paths.configHostJob(host, jobId);
    final Task task = new Task(job, deployment.getGoal(), existingDeployment.getDeployerUser(), existingDeployment.getDeployerMaster(), existingDeployment.getDeploymentGroupName());
    try {
        client.setData(path, task.toJsonBytes());
    } catch (Exception e) {
        throw new HeliosRuntimeException("updating deployment " + deployment + " on host " + host + " failed", e);
    }
}
Also used : Task(com.spotify.helios.common.descriptors.Task) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) ZooKeeperClient(com.spotify.helios.servicescommon.coordination.ZooKeeperClient) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) Deployment(com.spotify.helios.common.descriptors.Deployment) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) 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)

Example 5 with Task

use of com.spotify.helios.common.descriptors.Task in project helios by spotify.

the class ZooKeeperMasterModel method getTasks.

private Map<JobId, Deployment> getTasks(final ZooKeeperClient client, final String host) {
    final Map<JobId, Deployment> jobs = Maps.newHashMap();
    try {
        final String folder = Paths.configHostJobs(host);
        final List<String> jobIds;
        try {
            jobIds = client.getChildren(folder);
        } catch (KeeperException.NoNodeException e) {
            log.warn("Unable to get deployment config for {}", host, e);
            return ImmutableMap.of();
        }
        for (final String jobIdString : jobIds) {
            final JobId jobId = JobId.fromString(jobIdString);
            final String containerPath = Paths.configHostJob(host, jobId);
            try {
                final byte[] data = client.getData(containerPath);
                final Task task = parse(data, Task.class);
                jobs.put(jobId, Deployment.of(jobId, task.getGoal(), task.getDeployerUser(), task.getDeployerMaster(), task.getDeploymentGroupName()));
            } catch (KeeperException.NoNodeException ignored) {
                log.debug("deployment config node disappeared: {}", jobIdString);
            }
        }
    } catch (KeeperException | IOException e) {
        throw new HeliosRuntimeException("getting deployment config failed", e);
    }
    return jobs;
}
Also used : Task(com.spotify.helios.common.descriptors.Task) RolloutTask(com.spotify.helios.common.descriptors.RolloutTask) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) HeliosRuntimeException(com.spotify.helios.common.HeliosRuntimeException) Deployment(com.spotify.helios.common.descriptors.Deployment) IOException(java.io.IOException) JobId(com.spotify.helios.common.descriptors.JobId) KeeperException(org.apache.zookeeper.KeeperException)

Aggregations

Task (com.spotify.helios.common.descriptors.Task)7 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)5 JobId (com.spotify.helios.common.descriptors.JobId)5 RolloutTask (com.spotify.helios.common.descriptors.RolloutTask)5 KeeperException (org.apache.zookeeper.KeeperException)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 Job (com.spotify.helios.common.descriptors.Job)3 IOException (java.io.IOException)3 Deployment (com.spotify.helios.common.descriptors.Deployment)2 ZooKeeperClient (com.spotify.helios.servicescommon.coordination.ZooKeeperClient)2 ZooKeeperOperation (com.spotify.helios.servicescommon.coordination.ZooKeeperOperation)2 UUID (java.util.UUID)2 NodeExistsException (org.apache.zookeeper.KeeperException.NodeExistsException)2 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 Map (java.util.Map)1 BadVersionException (org.apache.zookeeper.KeeperException.BadVersionException)1 NotEmptyException (org.apache.zookeeper.KeeperException.NotEmptyException)1