Skip to content
Snippets Groups Projects
Commit 0e1d0225 authored by Zachary Sabourin's avatar Zachary Sabourin
Browse files

Merge branch 'zacharysabourin/main/threaded-loading' into 'main'

feat: Add async support for CVE augmentation

See merge request !37
parents 9819e427 12cf7c09
No related branches found
No related tags found
1 merge request!37feat: Add async support for CVE augmentation
Pipeline #31810 passed
......@@ -64,10 +64,6 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<!-- Testing dependencies only -->
<dependency>
......
......@@ -12,7 +12,6 @@
package org.eclipsefoundation.cve.model;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.annotation.Nullable;
......
......@@ -14,6 +14,7 @@ package org.eclipsefoundation.cve.precaches;
import java.net.URI;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.stream.Collectors;
......@@ -23,6 +24,7 @@ import javax.inject.Named;
import javax.ws.rs.ProcessingException;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.microprofile.context.ManagedExecutor;
import org.eclipse.microprofile.rest.client.inject.RestClient;
import org.eclipsefoundation.core.model.ParameterizedCacheKey;
import org.eclipsefoundation.core.service.LoadingCacheManager.LoadingCacheProvider;
......@@ -65,12 +67,21 @@ public class InternalAdvisoriesPrecacheProvider implements LoadingCacheProvider<
@RestClient
GithubCveAPI githubApi;
@Inject
ManagedExecutor executor;
@Inject
ObjectMapper om;
@Override
public List<CveData> fetchData(ParameterizedCacheKey k) {
return fetchInternalCveDatas().stream().map(this::augmentCveData).collect(Collectors.toList());
// Create a CompletableFuture for each cve augmentation
List<CompletableFuture<CveData>> augmentingTasks = fetchInternalCveDatas().stream()
.map(cve -> CompletableFuture.supplyAsync(() -> augmentCveData(cve), executor))
.collect(Collectors.toList());
// Await completion of each and collect results
return augmentingTasks.stream().map(CompletableFuture::join).collect(Collectors.toList());
}
@Override
......
......@@ -14,7 +14,6 @@ package org.eclipsefoundation.cve.test.api;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
......@@ -28,10 +27,10 @@ import org.eclipsefoundation.cve.api.models.GithubAdvisoriesRequestParams;
import org.eclipsefoundation.cve.model.CveProjectData;
import org.eclipsefoundation.cve.model.CveProjectData.Cna;
import org.eclipsefoundation.cve.model.CveProjectData.Containers;
import org.eclipsefoundation.cve.model.CveProjectData.CvssData;
import org.eclipsefoundation.cve.model.CveProjectData.Description;
import org.eclipsefoundation.cve.model.CveProjectData.Metadata;
import org.eclipsefoundation.cve.model.CveProjectData.Metric;
import org.eclipsefoundation.cve.model.CveProjectData.CvssData;
import org.eclipsefoundation.cve.model.GithubAdvisoriesData;
import org.eclipsefoundation.cve.model.GithubAdvisoriesData.Cvss;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment