use of org.commonjava.cdi.util.weft.DrainingExecutorCompletionService in project indy by Commonjava.
the class MavenMetadataGenerator method mergeProviderMetadata.
private Metadata mergeProviderMetadata(final Group group, final Metadata master, final String toMergePath) throws IndyWorkflowException {
logger.debug("Merge metadata for non-store providers in: {} on path: {}", group.getKey(), toMergePath);
DrainingExecutorCompletionService<Metadata> svc = new DrainingExecutorCompletionService<>(mavenMDGeneratorService);
detectOverloadVoid(() -> metadataProviders.forEach(provider -> svc.submit(() -> {
try {
return provider.getMetadata(group.getKey(), toMergePath);
} catch (IndyWorkflowException e) {
logger.error(String.format("Cannot read metadata: %s from metadata provider: %s. Reason: %s", toMergePath, provider.getClass().getSimpleName(), e.getMessage()), e);
}
return null;
})));
try {
svc.drain(metadata -> {
if (metadata != null) {
merger.merge(master, metadata, group, toMergePath);
}
});
} catch (InterruptedException e) {
logger.debug("Interrupted while merging provider member metadata.");
} catch (ExecutionException e) {
throw new IndyWorkflowException("Failed to merge provider member metadata.", e);
}
return master;
}
use of org.commonjava.cdi.util.weft.DrainingExecutorCompletionService in project indy by Commonjava.
the class KojiMavenMetadataProvider method executeKojiMetadataLookup.
@Measure
private Metadata executeKojiMetadataLookup(ProjectRef ga, String path) throws KojiClientException, IndyWorkflowException {
Logger logger = LoggerFactory.getLogger(getClass());
// short-term caches to help improve performance a bit by avoiding xml-rpc calls.
List<KojiArchiveInfo> archives = kojiContentProvider.listArchivesMatching(ga, null);
Map<Integer, KojiBuildArchiveCollection> seenBuildArchives = new ConcurrentHashMap<>();
Set<Integer> seenBuilds = new ConcurrentHashSet<>();
DrainingExecutorCompletionService<SingleVersion> svc = new DrainingExecutorCompletionService<>(kojiMDService);
detectOverloadVoid(() -> {
for (KojiArchiveInfo archive : archives) {
svc.submit(archiveScanner(path, ga, archive, seenBuilds, seenBuildArchives));
}
});
Set<SingleVersion> versions = new ConcurrentHashSet<>();
try {
svc.drain(v -> {
if (v != null) {
versions.add(v);
}
});
} catch (InterruptedException | ExecutionException e) {
logger.warn("Failed to scan for Koji metadata related to: " + ga, e);
}
if (versions.isEmpty()) {
logger.debug("No versions found in Koji builds for metadata: {}", path);
return null;
}
List<SingleVersion> sortedVersions = new ArrayList<>(versions);
Collections.sort(sortedVersions);
Metadata md = new Metadata();
md.setGroupId(ga.getGroupId());
md.setArtifactId(ga.getArtifactId());
Versioning versioning = new Versioning();
versioning.setRelease(sortedVersions.get(versions.size() - 1).renderStandard());
versioning.setLatest(sortedVersions.get(versions.size() - 1).renderStandard());
versioning.setVersions(sortedVersions.stream().map(SingleVersion::renderStandard).collect(Collectors.toList()));
Date lastUpdated = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
versioning.setLastUpdated(new SimpleDateFormat(LAST_UPDATED_FORMAT).format(lastUpdated));
md.setVersioning(versioning);
return md;
}
use of org.commonjava.cdi.util.weft.DrainingExecutorCompletionService in project indy by Commonjava.
the class KojiRepairManager method repairAllPathMasks.
public KojiMultiRepairResult repairAllPathMasks(final String user) throws KojiRepairException, IndyWorkflowException {
KojiMultiRepairResult result = new KojiMultiRepairResult();
if (opLock.tryLock()) {
try {
List<RemoteRepository> kojiRemotes = getAllKojiRemotes();
DrainingExecutorCompletionService<KojiRepairResult> repairService = new DrainingExecutorCompletionService<>(repairExecutor);
detectOverloadVoid(() -> kojiRemotes.forEach(r -> repairService.submit(() -> {
logger.info("Attempting to repair path masks in Koji remote: {}", r.getKey());
KojiRepairRequest request = new KojiRepairRequest(r.getKey(), false);
try {
return repairPathMask(request, user, true);
} catch (KojiRepairException e) {
logger.error("Failed to execute repair for: " + r.getKey(), e);
}
return null;
})));
List<KojiRepairResult> results = new ArrayList<>();
try {
repairService.drain(r -> {
if (r != null) {
results.add(r);
}
});
} catch (InterruptedException | ExecutionException e) {
logger.error("Failed to repair path masks.", e);
}
result.setResults(results);
} catch (IndyDataException e) {
throw new KojiRepairException("Failed to list Koji remote repositories for repair. Reason: %s", e, e.getMessage());
} finally {
opLock.unlock();
}
} else {
throw new KojiRepairException("Koji repair manager is busy.");
}
return result;
}
use of org.commonjava.cdi.util.weft.DrainingExecutorCompletionService in project indy by Commonjava.
the class KojiRepairManager method repairAllMetadataTimeout.
public KojiMultiRepairResult repairAllMetadataTimeout(final String user, boolean isDryRun) throws KojiRepairException, IndyWorkflowException {
KojiMultiRepairResult result = new KojiMultiRepairResult();
if (opLock.tryLock()) {
try {
List<RemoteRepository> kojiRemotes = getAllKojiRemotes();
DrainingExecutorCompletionService<KojiRepairResult> repairService = new DrainingExecutorCompletionService<>(repairExecutor);
detectOverloadVoid(() -> kojiRemotes.forEach(r -> repairService.submit(() -> {
logger.info("Attempting to repair path masks in Koji remote: {}", r.getKey());
KojiRepairRequest request = new KojiRepairRequest(r.getKey(), isDryRun);
try {
return repairMetadataTimeout(request, user, true);
} catch (KojiRepairException e) {
logger.error("Failed to execute repair for: " + r.getKey(), e);
}
return null;
})));
List<KojiRepairResult> results = new ArrayList<>();
try {
repairService.drain(r -> {
if (r != null) {
results.add(r);
}
});
} catch (InterruptedException | ExecutionException e) {
logger.error("Failed to repair metadata timeout.", e);
}
result.setResults(results);
} catch (IndyDataException e) {
throw new KojiRepairException("Failed to list Koji remote repositories for repair. Reason: %s", e, e.getMessage());
} finally {
opLock.unlock();
}
} else {
throw new KojiRepairException("Koji repair manager is busy.");
}
return result;
}
Aggregations