public void saveTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate, boolean overwrite) { if (!active) { LOG.warn("saveTaskHistoryUpdate {}, but not active", taskHistoryUpdate); return; } historyUpdates.putIfAbsent(taskHistoryUpdate.getTaskId(), new ConcurrentHashMap<>()); if (overwrite) { historyUpdates.get(taskHistoryUpdate.getTaskId()).put(taskHistoryUpdate.getTaskState(), taskHistoryUpdate); } else { historyUpdates.get(taskHistoryUpdate.getTaskId()).putIfAbsent(taskHistoryUpdate.getTaskState(), taskHistoryUpdate); } }
public SingularityTaskHistoryUpdate withoutPrevious() { return new SingularityTaskHistoryUpdate(getTaskId(), timestamp, taskState, statusMessage, statusReason, Collections.<SingularityTaskHistoryUpdate>emptySet()); }
private String getTaskHistoryUpdateId(SingularityTaskHistoryUpdate taskUpdate) { return taskUpdate.getTaskId() + "-" + taskUpdate.getTaskState().name(); }
public SingularityTaskHistoryUpdate withPrevious(SingularityTaskHistoryUpdate previousUpdate) { Set<SingularityTaskHistoryUpdate> newPreviousUpdates = getFlattenedPreviousUpdates(this); newPreviousUpdates.add(previousUpdate.withoutPrevious()); newPreviousUpdates.addAll(getFlattenedPreviousUpdates(previousUpdate)); return new SingularityTaskHistoryUpdate(getTaskId(), timestamp, taskState, statusMessage, statusReason, newPreviousUpdates); }
@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); } }
private int checkTaskUpdates(SingularityWebhook webhook, List<CompletableFuture<Response>> webhookFutures) { final List<SingularityTaskHistoryUpdate> taskUpdates = webhookManager.getQueuedTaskUpdatesForHook(webhook.getId()); int numTaskUpdates = 0; for (SingularityTaskHistoryUpdate taskUpdate : taskUpdates) { Optional<SingularityTask> task = taskHistoryHelper.getTask(taskUpdate.getTaskId()); // TODO compress if (!task.isPresent()) { LOG.warn("Couldn't find task for taskUpdate {}", taskUpdate); webhookManager.deleteTaskUpdate(webhook, taskUpdate); continue; } String concreteUri = applyPlaceholders(webhook.getUri(), taskUpdate); webhookFutures.add(webhookSemaphore.call(() -> executeWebhookAsync( concreteUri, new SingularityTaskWebhook(task.get(), taskUpdate), new SingularityTaskWebhookAsyncHandler(webhookManager, webhook, taskUpdate, shouldDeleteUpdateOnFailure(numTaskUpdates, taskUpdate.getTimestamp()))) )); } return taskUpdates.size(); }
public void saveTaskHistoryUpdate(SingularityTaskHistoryUpdate taskHistoryUpdate, boolean overwrite) { if (!active) { LOG.warn("saveTaskHistoryUpdate {}, but not active", taskHistoryUpdate); return; } historyUpdates.putIfAbsent(taskHistoryUpdate.getTaskId(), new ConcurrentHashMap<>()); if (overwrite) { historyUpdates.get(taskHistoryUpdate.getTaskId()).put(taskHistoryUpdate.getTaskState(), taskHistoryUpdate); } else { historyUpdates.get(taskHistoryUpdate.getTaskId()).putIfAbsent(taskHistoryUpdate.getTaskState(), taskHistoryUpdate); } }
private String getTaskHistoryUpdateId(SingularityTaskHistoryUpdate taskUpdate) { return taskUpdate.getTaskId() + "-" + taskUpdate.getTaskState().name(); }
@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); } }
private int checkTaskUpdates(SingularityWebhook webhook, List<CompletableFuture<Response>> webhookFutures) { final List<SingularityTaskHistoryUpdate> taskUpdates = webhookManager.getQueuedTaskUpdatesForHook(webhook.getId()); int numTaskUpdates = 0; for (SingularityTaskHistoryUpdate taskUpdate : taskUpdates) { Optional<SingularityTask> task = taskHistoryHelper.getTask(taskUpdate.getTaskId()); // TODO compress if (!task.isPresent()) { LOG.warn("Couldn't find task for taskUpdate {}", taskUpdate); webhookManager.deleteTaskUpdate(webhook, taskUpdate); continue; } String concreteUri = applyPlaceholders(webhook.getUri(), taskUpdate); webhookFutures.add(webhookSemaphore.call(() -> executeWebhookAsync( concreteUri, new SingularityTaskWebhook(task.get(), taskUpdate), new SingularityTaskWebhookAsyncHandler(webhookManager, webhook, taskUpdate, shouldDeleteUpdateOnFailure(numTaskUpdates, taskUpdate.getTimestamp()))) )); } return taskUpdates.size(); }