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