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;
}
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);
}
}
}
}
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);
}
}
}
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;
}
}
}
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;
}
Aggregations