From a4b2c04c0e784298fdb51b201d29744e3b344903 Mon Sep 17 00:00:00 2001 From: Stephen Salinas Date: Mon, 9 Jan 2017 16:38:29 -0500 Subject: [PATCH] fix maxPerPage --- .../singularity/resources/S3LogResource.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java b/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java index 7dbbb08936..c899e530c4 100644 --- a/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java +++ b/SingularityService/src/main/java/com/hubspot/singularity/resources/S3LogResource.java @@ -9,7 +9,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.Date; -import java.util.Enumeration; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; @@ -93,7 +92,7 @@ public class S3LogResource extends AbstractHistoryResource { private static final String CONTENT_DISPOSITION_DOWNLOAD_HEADER = "attachment"; private static final String CONTENT_ENCODING_DOWNLOAD_HEADER = "identity"; private static final String CONTINUATION_TOKEN_KEY_FORMAT = "%s-%s"; - private static final int TARGET_MAX_RESULTS = 10; + private static final int DEFAULT_TARGET_MAX_RESULTS = 10; private final SingularityS3Services s3Services; private final Optional configuration; @@ -279,14 +278,15 @@ public List call() throws Exception { if (search.getContinuationTokens().containsKey(key) && !Strings.isNullOrEmpty(search.getContinuationTokens().get(key).getValue())) { request.setContinuationToken(search.getContinuationTokens().get(key).getValue()); } - request.setMaxKeys(search.getMaxPerPage().or(TARGET_MAX_RESULTS)); - if (resultCount.get() < TARGET_MAX_RESULTS) { + int targetResultCount = search.getMaxPerPage().or(DEFAULT_TARGET_MAX_RESULTS); + request.setMaxKeys(targetResultCount); + if (resultCount.get() < targetResultCount) { ListObjectsV2Result result = s3Client.listObjectsV2(request); if (result.getObjectSummaries().isEmpty()) { continuationTokens.putIfAbsent(key, new ContinuationToken(result.getNextContinuationToken(), true)); return Collections.emptyList(); } else { - boolean addToList = incrementIfLessThan(resultCount, result.getObjectSummaries().size(), TARGET_MAX_RESULTS); + boolean addToList = incrementIfLessThan(resultCount, result.getObjectSummaries().size(), targetResultCount); if (addToList) { continuationTokens.putIfAbsent(key, new ContinuationToken(result.getNextContinuationToken(), result.getObjectSummaries().isEmpty())); return result.getObjectSummaries(); @@ -394,15 +394,15 @@ private SingularityS3SearchResult getS3Logs(S3Configuration s3Configuration, Opt final ConcurrentHashMap continuationTokens = new ConcurrentHashMap(); List logs = Lists.newArrayList(getS3LogsWithExecutorService(s3Configuration, group, executorService, prefixes, search, continuationTokens, paginated)); Collections.sort(logs, LOG_COMPARATOR); - return new SingularityS3SearchResult(continuationTokens, isFinalPageForAllPrefixes(continuationTokens.elements()), logs); + return new SingularityS3SearchResult(continuationTokens, isFinalPageForAllPrefixes(continuationTokens.values()), logs); } finally { executorService.shutdownNow(); } } - private boolean isFinalPageForAllPrefixes(Enumeration continuationTokens) { - while (continuationTokens.hasMoreElements()) { - if (continuationTokens.nextElement().isLastPage()) { + private boolean isFinalPageForAllPrefixes(Collection continuationTokens) { + for (ContinuationToken token : continuationTokens) { + if (!token.isLastPage()) { return false; } }