Search in sources :

Example 1 with SingularityS3SearchResult

use of com.hubspot.singularity.api.SingularityS3SearchResult in project Singularity by HubSpot.

the class S3LogResource method getS3Logs.

private SingularityS3SearchResult getS3Logs(S3Configuration s3Configuration, Map<SingularityS3Service, Set<String>> servicesToPrefixes, final SingularityS3SearchRequest search, final boolean paginated) throws InterruptedException, ExecutionException, TimeoutException {
    int totalPrefixCount = 0;
    for (Map.Entry<SingularityS3Service, Set<String>> entry : servicesToPrefixes.entrySet()) {
        totalPrefixCount += entry.getValue().size();
    }
    if (totalPrefixCount == 0) {
        return SingularityS3SearchResult.empty();
    }
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(Math.min(totalPrefixCount, s3Configuration.getMaxS3Threads()), new ThreadFactoryBuilder().setNameFormat("S3LogFetcher-%d").build()));
    try {
        final ConcurrentHashMap<String, ContinuationToken> continuationTokens = new ConcurrentHashMap<>();
        List<SingularityS3LogMetadata> logs = Lists.newArrayList(getS3LogsWithExecutorService(s3Configuration, executorService, servicesToPrefixes, totalPrefixCount, search, continuationTokens, paginated));
        Collections.sort(logs, LOG_COMPARATOR);
        return new SingularityS3SearchResult(continuationTokens, isFinalPageForAllPrefixes(continuationTokens.values()), logs);
    } finally {
        executorService.shutdownNow();
    }
}
Also used : SingularityS3Service(com.hubspot.singularity.helpers.SingularityS3Service) Set(java.util.Set) HashSet(java.util.HashSet) ContinuationToken(com.hubspot.singularity.api.ContinuationToken) SingularityS3LogMetadata(com.hubspot.singularity.SingularityS3LogMetadata) SingularityS3SearchResult(com.hubspot.singularity.api.SingularityS3SearchResult) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 SingularityS3LogMetadata (com.hubspot.singularity.SingularityS3LogMetadata)1 ContinuationToken (com.hubspot.singularity.api.ContinuationToken)1 SingularityS3SearchResult (com.hubspot.singularity.api.SingularityS3SearchResult)1 SingularityS3Service (com.hubspot.singularity.helpers.SingularityS3Service)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1