Search in sources :

Example 6 with TaskStatusEvent

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();
    }
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) JobId(com.spotify.helios.common.descriptors.JobId)

Example 7 with TaskStatusEvent

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);
    }
}
Also used : ClosedByInterruptException(java.nio.channels.ClosedByInterruptException) TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) IOException(java.io.IOException) JobId(com.spotify.helios.common.descriptors.JobId)

Example 8 with TaskStatusEvent

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;
        }
    }
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) JobId(com.spotify.helios.common.descriptors.JobId)

Example 9 with TaskStatusEvent

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);
    }
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) EventSender(com.spotify.helios.servicescommon.EventSender) IOException(java.io.IOException)

Example 10 with TaskStatusEvent

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);
    }
}
Also used : TaskStatusEvent(com.spotify.helios.common.descriptors.TaskStatusEvent) JobDoesNotExistException(com.spotify.helios.master.JobDoesNotExistException) TaskStatusEvents(com.spotify.helios.common.protocol.TaskStatusEvents) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

TaskStatusEvent (com.spotify.helios.common.descriptors.TaskStatusEvent)15 JobId (com.spotify.helios.common.descriptors.JobId)8 Test (org.junit.Test)5 TaskStatus (com.spotify.helios.common.descriptors.TaskStatus)4 TaskStatusEvents (com.spotify.helios.common.protocol.TaskStatusEvents)4 IOException (java.io.IOException)4 Job (com.spotify.helios.common.descriptors.Job)3 HeliosClient (com.spotify.helios.client.HeliosClient)2 JobStatus (com.spotify.helios.common.descriptors.JobStatus)2 KeeperException (org.apache.zookeeper.KeeperException)2 ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)1 Timed (com.codahale.metrics.annotation.Timed)1 ImmutableList (com.google.common.collect.ImmutableList)1 Table (com.spotify.helios.cli.Table)1 HeliosRuntimeException (com.spotify.helios.common.HeliosRuntimeException)1 Deployment (com.spotify.helios.common.descriptors.Deployment)1 ExecHealthCheck (com.spotify.helios.common.descriptors.ExecHealthCheck)1 HealthCheck (com.spotify.helios.common.descriptors.HealthCheck)1 HttpHealthCheck (com.spotify.helios.common.descriptors.HttpHealthCheck)1 ServiceEndpoint (com.spotify.helios.common.descriptors.ServiceEndpoint)1