return new SingularityDeployStatisticsBuilder(requestId, deployId).build();
}
public void handleCompletedTask(Optional<SingularityTask> maybeActiveTask, SingularityTaskId taskId, long timestamp, ExtendedTaskState state, SingularityCreateResult taskHistoryUpdateCreateResult, SingularitySchedulerStateCache stateCache) {
final SingularityDeployStatistics deployStatistics = getDeployStatistics(taskId.getRequestId(), taskId.getDeployId());
if (maybeActiveTask.isPresent()) {
taskManager.deleteActiveTask(taskId.getId());
}
taskManager.createLBCleanupTask(taskId);
final Optional<PendingType> scheduleResult = handleCompletedTaskWithStatistics(maybeActiveTask, taskId, timestamp, state, deployStatistics, taskHistoryUpdateCreateResult, stateCache);
if (taskHistoryUpdateCreateResult == SingularityCreateResult.EXISTED) {
return;
}
SingularityDeployStatisticsBuilder bldr = deployStatistics.toBuilder();
if (!bldr.getLastFinishAt().isPresent() || timestamp > bldr.getLastFinishAt().get()) {
bldr.setLastFinishAt(Optional.of(timestamp));
bldr.setLastTaskState(Optional.of(state));
}
if (!state.isSuccess()) {
bldr.setNumFailures(bldr.getNumFailures() + 1);
final List<Long> sequentialFailureTimestamps = Lists.newArrayList(bldr.getSequentialFailureTimestamps());
if (sequentialFailureTimestamps.size() < configuration.getCooldownAfterFailures()) {
sequentialFailureTimestamps.add(timestamp);
} else if (timestamp > sequentialFailureTimestamps.get(0)) {
sequentialFailureTimestamps.set(0, timestamp);
}
Collections.sort(sequentialFailureTimestamps);
bldr.setSequentialFailureTimestamps(sequentialFailureTimestamps);
} else {
bldr.setSequentialFailureTimestamps(Collections.<Long> emptyList());
bldr.setNumSuccess(bldr.getNumSuccess() + 1);
}
if (scheduleResult.isPresent() && scheduleResult.get() == PendingType.RETRY) {
bldr.setNumSequentialRetries(bldr.getNumSequentialRetries() + 1);
} else {
bldr.setNumSequentialRetries(0);
}
final SingularityDeployStatistics newStatistics = bldr.build();
LOG.trace("Saving new deploy statistics {}", newStatistics);
deployManager.saveDeployStatistics(newStatistics);
}