Search in sources :

Example 71 with JobId

use of com.spotify.helios.common.descriptors.JobId 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)

Example 72 with JobId

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

the class ExpiredJobReaper method runOneIteration.

@Override
public void runOneIteration() {
    for (final Entry<JobId, Job> entry : masterModel.getJobs().entrySet()) {
        final JobId jobId = entry.getKey();
        final Job job = entry.getValue();
        if (job.getExpires() == null) {
            //noinspection UnnecessaryContinue
            continue;
        } else if (job.getExpires().getTime() <= clock.now().getMillis()) {
            final JobStatus status = masterModel.getJobStatus(jobId);
            final List<String> hosts = ImmutableList.copyOf(status.getDeployments().keySet());
            for (final String host : hosts) {
                try {
                    masterModel.undeployJob(host, jobId, job.getToken());
                } catch (HostNotFoundException e) {
                    log.error("couldn't undeploy job {} from host {} when it hit deadline", jobId, host, e);
                } catch (JobNotDeployedException e) {
                    log.debug("job {} was already undeployed when it hit deadline", jobId, e);
                } catch (TokenVerificationException e) {
                    log.error("couldn't undeploy job {} from host {} because token verification failed", jobId, host, e);
                }
            }
            try {
                masterModel.removeJob(jobId, job.getToken());
            } catch (JobDoesNotExistException e) {
                log.debug("job {} was already removed when it hit deadline", jobId, e);
            } catch (JobStillDeployedException e) {
                log.debug("job {} still deployed on some host(s) after expiry reap", jobId, e);
            } catch (TokenVerificationException e) {
                log.error("couldn't remove job {} because token verification failed", jobId, e);
            }
        }
    }
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) HostNotFoundException(com.spotify.helios.master.HostNotFoundException) TokenVerificationException(com.spotify.helios.master.TokenVerificationException) JobStillDeployedException(com.spotify.helios.master.JobStillDeployedException) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) JobNotDeployedException(com.spotify.helios.master.JobNotDeployedException) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId)

Example 73 with JobId

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

the class JobHistoryReaper method processItem.

@Override
void processItem(final String jobId) {
    log.info("Deciding whether to reap job history for job {}", jobId);
    final JobId id = JobId.fromString(jobId);
    final Job job = masterModel.getJob(id);
    if (job == null) {
        try {
            client.deleteRecursive(Paths.historyJob(id));
            log.info("Reaped job history for job {}", jobId);
        } catch (NoNodeException ignored) {
        // Something deleted the history right before we got to it. Ignore and keep going.
        } catch (KeeperException e) {
            log.warn("error reaping job history for job {}", jobId, e);
        }
    }
}
Also used : NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) Job(com.spotify.helios.common.descriptors.Job) JobId(com.spotify.helios.common.descriptors.JobId) KeeperException(org.apache.zookeeper.KeeperException)

Example 74 with JobId

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

the class TaskHistoryWriter method run.

@Override
public void run() {
    while (true) {
        final TaskStatusEvent item = getNext();
        if (item == null) {
            return;
        }
        final JobId jobId = item.getStatus().getJob().getId();
        final String historyPath = Paths.historyJobHostEventsTimestamp(jobId, hostname, item.getTimestamp());
        try {
            log.debug("writing queued item to zookeeper {} {}", item.getStatus().getJob().getId(), item.getTimestamp());
            client.ensurePath(historyPath, true);
            client.createAndSetData(historyPath, item.getStatus().toJsonBytes());
            // See if too many
            final List<String> events = client.getChildren(Paths.historyJobHostEvents(jobId, hostname));
            if (events.size() > MAX_NUMBER_STATUS_EVENTS_TO_RETAIN) {
                trimStatusEvents(events, jobId);
            }
        } catch (NodeExistsException e) {
            // Ahh, the two generals problem...  We handle by doing nothing since the thing
            // we wanted in, is in.
            log.debug("item we wanted in is already there");
        } catch (ConnectionLossException e) {
            log.warn("Connection lost while putting item into zookeeper, will retry");
            putBack(item);
            break;
        } catch (KeeperException e) {
            log.error("Error putting item into zookeeper, will retry", e);
            putBack(item);
            break;
        }
    }
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) NodeExistsException(org.apache.zookeeper.KeeperException.NodeExistsException) ConnectionLossException(org.apache.zookeeper.KeeperException.ConnectionLossException) JobId(com.spotify.helios.common.descriptors.JobId) KeeperException(org.apache.zookeeper.KeeperException)

Example 75 with JobId

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

the class ZooKeeperAgentModel method getTasks.

/**
   * Returns the tasks (basically, a pair of {@link JobId} and {@link Task}) for the current agent.
   */
@Override
public Map<JobId, Task> getTasks() {
    final Map<JobId, Task> tasks = Maps.newHashMap();
    for (final Map.Entry<String, Task> entry : this.tasks.getNodes().entrySet()) {
        final JobId id = jobIdFromTaskPath(entry.getKey());
        tasks.put(id, entry.getValue());
    }
    return tasks;
}
Also used : Task(com.spotify.helios.common.descriptors.Task) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId)

Aggregations

JobId (com.spotify.helios.common.descriptors.JobId)115 Test (org.junit.Test)68 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)41 Job (com.spotify.helios.common.descriptors.Job)37 HeliosClient (com.spotify.helios.client.HeliosClient)35 Deployment (com.spotify.helios.common.descriptors.Deployment)29 Matchers.containsString (org.hamcrest.Matchers.containsString)25 DockerClient (com.spotify.docker.client.DockerClient)19 JobStatus (com.spotify.helios.common.descriptors.JobStatus)19 JobDeployResponse (com.spotify.helios.common.protocol.JobDeployResponse)16 CreateJobResponse (com.spotify.helios.common.protocol.CreateJobResponse)13 IOException (java.io.IOException)12 HostStatus (com.spotify.helios.common.descriptors.HostStatus)11 Map (java.util.Map)11 LogStream (com.spotify.docker.client.LogStream)10 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)10 KeeperException (org.apache.zookeeper.KeeperException)9 TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)8 AgentMain (com.spotify.helios.agent.AgentMain)7 PortMapping (com.spotify.helios.common.descriptors.PortMapping)7