Search in sources :

Example 1 with SingularityDeleteResult

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

the class SingularityHistoryPersister method moveToHistoryOrCheckForPurge.

protected boolean moveToHistoryOrCheckForPurge(T object, int index) {
    final long start = System.currentTimeMillis();
    if (moveToHistoryOrCheckForPurgeAndShouldDelete(object, index)) {
        SingularityDeleteResult deleteResult = purgeFromZk(object);
        LOG.debug("{} {} (deleted: {}) in {}", persistsHistoryInsteadOfPurging() ? "Persisted" : "Purged", object, deleteResult, JavaUtils.duration(start));
        return true;
    }
    return false;
}
Also used : SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult)

Example 2 with SingularityDeleteResult

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

the class SingularityUsagePoller method clearOldUsage.

@VisibleForTesting
void clearOldUsage(String taskId) {
    List<Double> pastTaskUsagePaths = usageManager.getTaskUsagePaths(taskId).stream().map(Double::parseDouble).collect(Collectors.toList());
    while (pastTaskUsagePaths.size() + 1 > configuration.getNumUsageToKeep()) {
        long minSecondsApart = configuration.getUsageIntervalSeconds();
        boolean deleted = false;
        for (int i = 0; i < pastTaskUsagePaths.size() - 1; i++) {
            if (pastTaskUsagePaths.get(i + 1) - pastTaskUsagePaths.get(i) < minSecondsApart) {
                SingularityDeleteResult result = usageManager.deleteSpecificTaskUsage(taskId, pastTaskUsagePaths.get(i + 1));
                if (result.equals(SingularityDeleteResult.DIDNT_EXIST)) {
                    LOG.warn("Didn't delete taskUsage {} for taskId {}", pastTaskUsagePaths.get(i + 1).toString(), taskId);
                }
                deleted = true;
                pastTaskUsagePaths.remove(pastTaskUsagePaths.get(i + 1));
                break;
            }
        }
        if (!deleted) {
            usageManager.deleteSpecificTaskUsage(taskId, pastTaskUsagePaths.get(0));
            pastTaskUsagePaths.remove(pastTaskUsagePaths.get(0));
        }
    }
}
Also used : SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult) AtomicDouble(com.google.common.util.concurrent.AtomicDouble) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 3 with SingularityDeleteResult

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

the class SingularityMailPoller method checkToSendTaskFinishedMail.

private void checkToSendTaskFinishedMail(SingularityTaskId taskId) {
    Optional<SingularityRequestWithState> requestWithState = requestManager.getRequest(taskId.getRequestId());
    Optional<SingularityTaskHistory> taskHistory = taskManager.getTaskHistory(taskId);
    ShouldSendMailState shouldSendState = shouldSendTaskFinishedMail(taskId, requestWithState, taskHistory);
    if (shouldSendState == ShouldSendMailState.WAIT) {
        return;
    }
    try {
        mailer.sendTaskCompletedMail(taskHistory.get(), requestWithState.get().getRequest());
    } catch (Throwable t) {
        LOG.error("While trying to send task completed mail for {}", taskId, t);
    } finally {
        SingularityDeleteResult result = taskManager.deleteFinishedTaskMailQueue(taskId);
        LOG.debug("Task {} mail sent with status {} (delete result {})", taskId, shouldSendState, result);
    }
}
Also used : SingularityRequestWithState(com.hubspot.singularity.SingularityRequestWithState) SingularityTaskHistory(com.hubspot.singularity.SingularityTaskHistory) SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult)

Example 4 with SingularityDeleteResult

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

the class SingularityCleaner method checkKilledTaskIdRecords.

private void checkKilledTaskIdRecords() {
    final long start = System.currentTimeMillis();
    final List<SingularityKilledTaskIdRecord> killedTaskIdRecords = taskManager.getKilledTaskIdRecords();
    if (killedTaskIdRecords.isEmpty()) {
        LOG.trace("No killed taskId records");
        return;
    }
    AtomicInteger obsolete = new AtomicInteger(0);
    AtomicInteger waiting = new AtomicInteger(0);
    AtomicInteger rekilled = new AtomicInteger(0);
    killedTaskIdRecords.stream().collect(Collectors.groupingBy((record) -> record.getTaskId().getRequestId())).entrySet().parallelStream().forEach((killedTaskIdRecordsForRequest) -> {
        lock.runWithRequestLock(() -> {
            for (SingularityKilledTaskIdRecord killedTaskIdRecord : killedTaskIdRecordsForRequest.getValue()) {
                if (!taskManager.isActiveTask(killedTaskIdRecord.getTaskId().getId())) {
                    SingularityDeleteResult deleteResult = taskManager.deleteKilledRecord(killedTaskIdRecord.getTaskId());
                    LOG.debug("Deleting obsolete {} - {}", killedTaskIdRecord, deleteResult);
                    obsolete.getAndIncrement();
                    continue;
                }
                long duration = start - killedTaskIdRecord.getTimestamp();
                if (duration > configuration.getAskDriverToKillTasksAgainAfterMillis()) {
                    LOG.info("{} is still active, and time since last kill {} is greater than configured (askDriverToKillTasksAgainAfterMillis) {} - asking driver to kill again", killedTaskIdRecord, JavaUtils.durationFromMillis(duration), JavaUtils.durationFromMillis(configuration.getAskDriverToKillTasksAgainAfterMillis()));
                    scheduler.killAndRecord(killedTaskIdRecord.getTaskId(), killedTaskIdRecord.getRequestCleanupType(), killedTaskIdRecord.getTaskCleanupType(), Optional.of(killedTaskIdRecord.getOriginalTimestamp()), Optional.of(killedTaskIdRecord.getRetries()), Optional.absent());
                    rekilled.getAndIncrement();
                } else {
                    LOG.trace("Ignoring {}, because duration {} is less than configured (askDriverToKillTasksAgainAfterMillis) {}", killedTaskIdRecord, JavaUtils.durationFromMillis(duration), JavaUtils.durationFromMillis(configuration.getAskDriverToKillTasksAgainAfterMillis()));
                    waiting.getAndIncrement();
                }
            }
        }, killedTaskIdRecordsForRequest.getKey(), String.format("%s#%s", getClass().getSimpleName(), "checkKilledTaskIdRecords"));
    });
    LOG.info("{} obsolete, {} waiting, {} rekilled tasks based on {} killedTaskIdRecords", obsolete, waiting, rekilled, killedTaskIdRecords.size());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SingularityKilledTaskIdRecord(com.hubspot.singularity.SingularityKilledTaskIdRecord) SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult)

Example 5 with SingularityDeleteResult

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

the class SingularitySlaveReconciliationPoller method checkDeadSlaves.

private void checkDeadSlaves() {
    final long start = System.currentTimeMillis();
    final List<SingularitySlave> deadSlaves = slaveManager.getObjectsFiltered(MachineState.DEAD);
    if (deadSlaves.isEmpty()) {
        LOG.trace("No dead slaves");
        return;
    }
    int deleted = 0;
    final long maxDuration = TimeUnit.HOURS.toMillis(configuration.getDeleteDeadSlavesAfterHours());
    for (SingularitySlave deadSlave : slaveManager.getObjectsFiltered(MachineState.DEAD)) {
        final long duration = System.currentTimeMillis() - deadSlave.getCurrentState().getTimestamp();
        if (duration > maxDuration) {
            SingularityDeleteResult result = slaveManager.deleteObject(deadSlave.getId());
            deleted++;
            LOG.info("Removing dead slave {} ({}) after {} (max {})", deadSlave.getId(), result, JavaUtils.durationFromMillis(duration), JavaUtils.durationFromMillis(maxDuration));
        }
    }
    LOG.debug("Checked {} dead slaves, deleted {} in {}", deadSlaves.size(), deleted, JavaUtils.duration(start));
}
Also used : SingularitySlave(com.hubspot.singularity.SingularitySlave) SingularityDeleteResult(com.hubspot.singularity.SingularityDeleteResult)

Aggregations

SingularityDeleteResult (com.hubspot.singularity.SingularityDeleteResult)10 SingularityRequestWithState (com.hubspot.singularity.SingularityRequestWithState)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 AtomicDouble (com.google.common.util.concurrent.AtomicDouble)1 SingularityKilledTaskIdRecord (com.hubspot.singularity.SingularityKilledTaskIdRecord)1 SingularitySlave (com.hubspot.singularity.SingularitySlave)1 SingularityTaskHistory (com.hubspot.singularity.SingularityTaskHistory)1 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)1 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)1 HashSet (java.util.HashSet)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1