Search in sources :

Example 1 with SingularityTaskHistoryUpdate

use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.

the class TaskManager method getTaskHistory.

public Optional<SingularityTaskHistory> getTaskHistory(SingularityTaskId taskId) {
    final Optional<SingularityTask> task = getTaskCheckCache(taskId, true);
    if (!task.isPresent()) {
        return Optional.absent();
    }
    List<SingularityTaskHistoryUpdate> taskUpdates = getTaskHistoryUpdates(taskId);
    Optional<String> directory = getDirectory(taskId);
    Optional<String> containerId = getContainerId(taskId);
    List<SingularityTaskHealthcheckResult> healthchecks = getHealthcheckResults(taskId);
    List<SingularityLoadBalancerUpdate> loadBalancerUpdates = Lists.newArrayListWithCapacity(2);
    checkLoadBalancerHistory(loadBalancerUpdates, taskId, LoadBalancerRequestType.ADD);
    checkLoadBalancerHistory(loadBalancerUpdates, taskId, LoadBalancerRequestType.REMOVE);
    List<SingularityTaskShellCommandHistory> shellCommandHistory = getTaskShellCommandHistory(taskId);
    List<SingularityTaskMetadata> taskMetadata = getTaskMetadata(taskId);
    return Optional.of(new SingularityTaskHistory(taskUpdates, directory, containerId, healthchecks, task.get(), loadBalancerUpdates, shellCommandHistory, taskMetadata));
}
Also used : SingularityLoadBalancerUpdate(com.hubspot.singularity.SingularityLoadBalancerUpdate) SingularityTaskShellCommandHistory(com.hubspot.singularity.SingularityTaskShellCommandHistory) SingularityTaskHealthcheckResult(com.hubspot.singularity.SingularityTaskHealthcheckResult) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskMetadata(com.hubspot.singularity.SingularityTaskMetadata) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory)

Example 2 with SingularityTaskHistoryUpdate

use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.

the class TaskManager method saveTaskHistoryUpdate.

@Timed
public SingularityCreateResult saveTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate, boolean overwriteExisting) {
    singularityEventListener.taskHistoryUpdateEvent(taskHistoryUpdate);
    if (overwriteExisting) {
        Optional<SingularityTaskHistoryUpdate> maybeExisting = getTaskHistoryUpdate(taskHistoryUpdate.getTaskId(), taskHistoryUpdate.getTaskState());
        LOG.info("Found existing history {}", maybeExisting);
        SingularityTaskHistoryUpdate updateWithPrevious;
        if (maybeExisting.isPresent()) {
            updateWithPrevious = taskHistoryUpdate.withPrevious(maybeExisting.get());
            LOG.info("Will save new update {}", updateWithPrevious);
        } else {
            updateWithPrevious = taskHistoryUpdate;
        }
        if (leaderCache.active()) {
            leaderCache.saveTaskHistoryUpdate(updateWithPrevious, overwriteExisting);
        }
        return save(getUpdatePath(taskHistoryUpdate.getTaskId(), taskHistoryUpdate.getTaskState()), updateWithPrevious, taskHistoryUpdateTranscoder);
    } else {
        if (leaderCache.active()) {
            leaderCache.saveTaskHistoryUpdate(taskHistoryUpdate, overwriteExisting);
        }
        return create(getUpdatePath(taskHistoryUpdate.getTaskId(), taskHistoryUpdate.getTaskState()), taskHistoryUpdate, taskHistoryUpdateTranscoder);
    }
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with SingularityTaskHistoryUpdate

use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.

the class TaskManager method saveTaskHistoryUpdate.

private void saveTaskHistoryUpdate(SingularityTaskCleanup cleanup) {
    StringBuilder msg = new StringBuilder(cleanup.getCleanupType().name());
    if (cleanup.getUser().isPresent()) {
        msg.append(" by ");
        msg.append(cleanup.getUser().get());
    }
    if (cleanup.getMessage().isPresent()) {
        msg.append(" - ");
        msg.append(cleanup.getMessage().get());
    }
    saveTaskHistoryUpdate(new SingularityTaskHistoryUpdate(cleanup.getTaskId(), cleanup.getTimestamp(), ExtendedTaskState.TASK_CLEANING, Optional.of(msg.toString()), Optional.<String>absent()), true);
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate)

Example 4 with SingularityTaskHistoryUpdate

use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.

the class LastTaskStatusMigration method applyMigration.

@Override
public void applyMigration() {
    final long start = System.currentTimeMillis();
    final List<SingularityTaskId> taskIds = taskManager.getActiveTaskIds();
    for (SingularityTaskId taskId : taskIds) {
        List<SingularityTaskHistoryUpdate> updates = Lists.reverse(taskManager.getTaskHistoryUpdates(taskId));
        Optional<MesosTaskStatusObject> taskStatus = Optional.absent();
        for (SingularityTaskHistoryUpdate update : updates) {
            if (update.getTaskState().toTaskState().isPresent()) {
                Optional<SingularityTask> task = taskManager.getTask(taskId);
                taskStatus = Optional.of(mesosProtosUtils.taskStatusFromProtos(TaskStatus.newBuilder().setTaskId(TaskID.newBuilder().setValue(taskId.getId())).setAgentId(MesosProtosUtils.toAgentId(task.get().getAgentId())).setState(MesosProtosUtils.toTaskState(update.getTaskState())).build()));
                break;
            }
        }
        SingularityTaskStatusHolder taskStatusHolder = new SingularityTaskStatusHolder(taskId, taskStatus, start, serverId, Optional.absent());
        taskManager.saveLastActiveTaskStatus(taskStatusHolder);
    }
}
Also used : MesosTaskStatusObject(com.hubspot.mesos.protos.MesosTaskStatusObject) SingularityTask(com.hubspot.singularity.SingularityTask) SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskStatusHolder(com.hubspot.singularity.SingularityTaskStatusHolder) SingularityTaskId(com.hubspot.singularity.SingularityTaskId)

Example 5 with SingularityTaskHistoryUpdate

use of com.hubspot.singularity.SingularityTaskHistoryUpdate in project Singularity by HubSpot.

the class RequestHelper method getMostRecentTask.

public Optional<SingularityTaskIdHistory> getMostRecentTask(SingularityRequest request) {
    List<SingularityTaskId> activeTaskIds = taskManager.getActiveTaskIdsForRequest(request.getId());
    if (!activeTaskIds.isEmpty()) {
        SingularityTaskId lastTaskId = activeTaskIds.get(0);
        List<SingularityTaskHistoryUpdate> historyUpdates = taskManager.getTaskHistoryUpdates(lastTaskId);
        if (!historyUpdates.isEmpty()) {
            SingularityTaskHistoryUpdate lastUpdate = historyUpdates.get(historyUpdates.size() - 1);
            return Optional.of(new SingularityTaskIdHistory(lastTaskId, lastUpdate.getTimestamp(), Optional.of(lastUpdate.getTaskState()), // runId not currently provided here, grabbing the full task data for this is a more expensive call
            Optional.absent()));
        }
    }
    List<SingularityTaskIdHistory> maybeRecentTasks = taskHistoryHelper.getBlendedHistory(new SingularityTaskHistoryQuery(request.getId()), 0, 1);
    if (!maybeRecentTasks.isEmpty()) {
        return Optional.of(maybeRecentTasks.get(0));
    }
    return Optional.absent();
}
Also used : SingularityTaskHistoryUpdate(com.hubspot.singularity.SingularityTaskHistoryUpdate) SingularityTaskHistoryQuery(com.hubspot.singularity.SingularityTaskHistoryQuery) SingularityTaskId(com.hubspot.singularity.SingularityTaskId) SingularityTaskIdHistory(com.hubspot.singularity.SingularityTaskIdHistory)

Aggregations

SingularityTaskHistoryUpdate (com.hubspot.singularity.SingularityTaskHistoryUpdate)23 SingularityTaskId (com.hubspot.singularity.SingularityTaskId)12 SingularityTask (com.hubspot.singularity.SingularityTask)7 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 SimplifiedTaskState (com.hubspot.singularity.SingularityTaskHistoryUpdate.SimplifiedTaskState)3 SingularityTaskStatusHolder (com.hubspot.singularity.SingularityTaskStatusHolder)3 SingularityBounceRequest (com.hubspot.singularity.api.SingularityBounceRequest)3 List (java.util.List)3 Timed (com.codahale.metrics.annotation.Timed)2 SingularityDeployFailure (com.hubspot.singularity.SingularityDeployFailure)2 SingularityTaskIdHistory (com.hubspot.singularity.SingularityTaskIdHistory)2 SingularityTaskMetadata (com.hubspot.singularity.SingularityTaskMetadata)2 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 Resources (com.hubspot.mesos.Resources)1 MesosSlaveMetricsSnapshotObject (com.hubspot.mesos.json.MesosSlaveMetricsSnapshotObject)1 MesosTaskMonitorObject (com.hubspot.mesos.json.MesosTaskMonitorObject)1 MesosTaskStatusObject (com.hubspot.mesos.protos.MesosTaskStatusObject)1 ExtendedTaskState (com.hubspot.singularity.ExtendedTaskState)1 InvalidSingularityTaskIdException (com.hubspot.singularity.InvalidSingularityTaskIdException)1