use of com.spotify.helios.common.descriptors.TaskStatusEvent in project helios by spotify.
the class TaskHistoryWriter method putBack.
private void putBack(TaskStatusEvent event) {
final JobId key = event.getStatus().getJob().getId();
final Deque<TaskStatusEvent> queue = getDeque(key);
synchronized (queue) {
if (queue.size() >= MAX_QUEUE_SIZE) {
// already full, just toss the event
return;
}
queue.push(event);
count.incrementAndGet();
}
}
use of com.spotify.helios.common.descriptors.TaskStatusEvent in project helios by spotify.
the class TaskHistoryWriter method add.
private void add(TaskStatusEvent item) throws InterruptedException {
// If too many "globally", toss them
while (count.get() >= MAX_TOTAL_SIZE) {
getNext();
}
final JobId key = item.getStatus().getJob().getId();
final Deque<TaskStatusEvent> deque = getDeque(key);
synchronized (deque) {
// if too many in the particular deque, toss them
while (deque.size() >= MAX_QUEUE_SIZE) {
deque.remove();
count.decrementAndGet();
}
deque.add(item);
count.incrementAndGet();
}
try {
backingStore.set(items);
} catch (ClosedByInterruptException e) {
log.debug("Writing task status event to backing store was interrupted");
} catch (IOException e) {
// We are best effort after all...
log.warn("Failed to write task status event to backing store", e);
}
}
use of com.spotify.helios.common.descriptors.TaskStatusEvent in project helios by spotify.
the class TaskHistoryWriter method getNext.
private TaskStatusEvent getNext() {
while (true) {
final TaskStatusEvent current = findEldestEvent();
// Didn't find anything that needed processing?
if (current == null) {
return null;
}
final JobId id = current.getStatus().getJob().getId();
final Deque<TaskStatusEvent> deque = items.get(id);
if (deque == null) {
// shouldn't happen because we should be the only one pulling items off, but....
continue;
}
synchronized (deque) {
if (!deque.peek().equals(current)) {
// item got rolled off, try again
continue;
}
// Pull it off the queue and be paranoid.
final TaskStatusEvent newCurrent = deque.poll();
count.decrementAndGet();
checkState(current.equals(newCurrent), "current should equal newCurrent");
// Safe because this is the *only* place we hold these two locks at the same time.
synchronized (items) {
// Extra paranoia: curDeque should always == deque
final Deque<TaskStatusEvent> curDeque = items.get(id);
if (curDeque != null && curDeque.isEmpty()) {
items.remove(id);
}
}
return current;
}
}
}
use of com.spotify.helios.common.descriptors.TaskStatusEvent in project helios by spotify.
the class ZooKeeperAgentModel method setTaskStatus.
/**
* Set the {@link TaskStatus} for the job identified by {@code jobId}.
*/
@Override
public void setTaskStatus(final JobId jobId, final TaskStatus status) throws InterruptedException {
log.debug("setting task status: {}", status);
taskStatuses.put(jobId.toString(), status.toJsonBytes());
if (historyWriter != null) {
try {
historyWriter.saveHistoryItem(status);
} catch (Exception e) {
// Log error here and keep going as saving task history is not critical.
// This is to prevent bad data in the queue from screwing up the actually important Helios
// agent operations.
log.error("Error saving task status {} to ZooKeeper: {}", status, e);
}
}
final TaskStatusEvent event = new TaskStatusEvent(status, System.currentTimeMillis(), agent);
final byte[] message = event.toJsonBytes();
for (final EventSender sender : eventSenders) {
sender.send(taskStatusEventTopic, message);
}
}
use of com.spotify.helios.common.descriptors.TaskStatusEvent in project helios by spotify.
the class HistoryResource method jobHistory.
/**
* Returns the {@link TaskStatusEvents} for the specified job.
*
* @param jobId The ID of the job.
*
* @return The history of the jobs.
*
* @throws HeliosException If an unexpected error occurs.
*/
@GET
@Produces(APPLICATION_JSON)
@Path("jobs/{id}")
@Timed
@ExceptionMetered
public TaskStatusEvents jobHistory(@PathParam("id") @Valid final JobId jobId) throws HeliosException {
if (!jobId.isFullyQualified()) {
throw badRequest("Invalid id");
}
try {
final List<TaskStatusEvent> events = model.getJobHistory(jobId);
metrics.jobsHistoryEventSize(events.size());
final TaskStatusEvents result = new TaskStatusEvents(events, OK);
return result;
} catch (JobDoesNotExistException e) {
return new TaskStatusEvents(ImmutableList.<TaskStatusEvent>of(), JOB_ID_NOT_FOUND);
}
}
Aggregations