Search in sources :

Example 6 with DrainingExecutorCompletionService

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;
}
Also used : HTTP_METADATA_EXT(org.commonjava.maven.galley.io.SpecialPathConstants.HTTP_METADATA_EXT) Date(java.util.Date) BiFunction(java.util.function.BiFunction) MergedContentAction(org.commonjava.indy.content.MergedContentAction) PathUtils.normalize(org.commonjava.maven.galley.util.PathUtils.normalize) StringUtils(org.apache.commons.lang3.StringUtils) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) GROUP_METADATA_GENERATED(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Document(org.w3c.dom.Document) TraceManager.addFieldToActiveSpan(org.commonjava.o11yphant.trace.TraceManager.addFieldToActiveSpan) Map(java.util.Map) StoreKey(org.commonjava.indy.model.core.StoreKey) Instance(javax.enterprise.inject.Instance) GROUP_METADATA_EXISTS(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_EXISTS) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) GroupMergeHelper(org.commonjava.indy.core.content.group.GroupMergeHelper) MavenMetadataMerger(org.commonjava.indy.pkg.maven.content.group.MavenMetadataMerger) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) Collectors(java.util.stream.Collectors) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) LOCAL_SNAPSHOT_VERSION_PART(org.commonjava.atlas.maven.ident.util.SnapshotUtils.LOCAL_SNAPSHOT_VERSION_PART) PostConstruct(javax.annotation.PostConstruct) XMLInfrastructure(org.commonjava.maven.galley.maven.parse.XMLInfrastructure) DirectContentAccess(org.commonjava.indy.content.DirectContentAccess) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) Plugin(org.apache.maven.artifact.repository.metadata.Plugin) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MetadataXpp3Writer(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Writer) Locker(org.commonjava.cdi.util.weft.Locker) MavenMetadataProvider(org.commonjava.indy.pkg.maven.content.group.MavenMetadataProvider) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) AtomicReference(java.util.concurrent.atomic.AtomicReference) VersionUtils(org.commonjava.atlas.maven.ident.util.VersionUtils) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) SnapshotVersion(org.apache.maven.artifact.repository.metadata.SnapshotVersion) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TypeAndClassifier(org.commonjava.atlas.maven.ident.ref.TypeAndClassifier) GalleyMavenXMLException(org.commonjava.maven.galley.maven.parse.GalleyMavenXMLException) PathUtils.parentPath(org.commonjava.maven.galley.util.PathUtils.parentPath) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) SnapshotPart(org.commonjava.atlas.maven.ident.version.part.SnapshotPart) MetadataXpp3Reader(org.apache.maven.artifact.repository.metadata.io.xpp3.MetadataXpp3Reader) OutputStream(java.io.OutputStream) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) LocationUtils(org.commonjava.indy.util.LocationUtils) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) UTF_8(java.nio.charset.StandardCharsets.UTF_8) TraceManager(org.commonjava.o11yphant.trace.TraceManager) IOUtils.closeQuietly(org.apache.commons.io.IOUtils.closeQuietly) IOException(java.io.IOException) SnapshotUtils.generateUpdateTimestamp(org.commonjava.atlas.maven.ident.util.SnapshotUtils.generateUpdateTimestamp) SimpleTypeAndClassifier(org.commonjava.atlas.maven.ident.ref.SimpleTypeAndClassifier) SnapshotUtils(org.commonjava.atlas.maven.ident.util.SnapshotUtils) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) Element(org.w3c.dom.Element) StringReader(java.io.StringReader) Paths(java.nio.file.Paths) TypeMapper(org.commonjava.maven.galley.maven.spi.type.TypeMapper) StoreResource(org.commonjava.indy.content.StoreResource) SnapshotUtils.getCurrentTimestamp(org.commonjava.atlas.maven.ident.util.SnapshotUtils.getCurrentTimestamp) TypeMapping(org.commonjava.maven.galley.model.TypeMapping) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) AbstractMergedContentGenerator(org.commonjava.indy.core.content.AbstractMergedContentGenerator) Collections(java.util.Collections) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) ExecutionException(java.util.concurrent.ExecutionException) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService)

Example 7 with DrainingExecutorCompletionService

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;
}
Also used : ArrayList(java.util.ArrayList) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) Logger(org.slf4j.Logger) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) Date(java.util.Date) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) Versioning(org.apache.maven.artifact.repository.metadata.Versioning) KojiBuildArchiveCollection(com.redhat.red.build.koji.model.xmlrpc.KojiBuildArchiveCollection) ConcurrentHashSet(org.infinispan.commons.util.concurrent.ConcurrentHashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SingleVersion(org.commonjava.atlas.maven.ident.version.SingleVersion) ExecutionException(java.util.concurrent.ExecutionException) SimpleDateFormat(java.text.SimpleDateFormat) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 8 with DrainingExecutorCompletionService

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;
}
Also used : ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyKojiContentProvider(org.commonjava.indy.koji.content.IndyKojiContentProvider) LoggerFactory(org.slf4j.LoggerFactory) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SingleThreadedExecutorService(org.commonjava.cdi.util.weft.SingleThreadedExecutorService) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) KojiPathPatternFormatter(org.commonjava.indy.koji.content.KojiPathPatternFormatter) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) KOJI_ORIGIN_BINARY(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN_BINARY) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) KojiClientException(com.redhat.red.build.koji.KojiClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) Logger(org.slf4j.Logger) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ReentrantLock(java.util.concurrent.locks.ReentrantLock) MalformedURLException(java.net.MalformedURLException) KojiClient(com.redhat.red.build.koji.KojiClient) CREATION_TRIGGER_GAV(org.commonjava.indy.koji.content.KojiContentManagerDecorator.CREATION_TRIGGER_GAV) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) KojiUtils(org.commonjava.indy.koji.util.KojiUtils) Collectors(java.util.stream.Collectors) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KOJI_ORIGIN(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) List(java.util.List) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreType.remote(org.commonjava.indy.model.core.StoreType.remote) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) IndyKojiConfig(org.commonjava.indy.koji.conf.IndyKojiConfig) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) ExecutionException(java.util.concurrent.ExecutionException)

Example 9 with DrainingExecutorCompletionService

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;
}
Also used : ChangeSummary(org.commonjava.indy.audit.ChangeSummary) IndyKojiContentProvider(org.commonjava.indy.koji.content.IndyKojiContentProvider) LoggerFactory(org.slf4j.LoggerFactory) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) WeftExecutorService(org.commonjava.cdi.util.weft.WeftExecutorService) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SingleThreadedExecutorService(org.commonjava.cdi.util.weft.SingleThreadedExecutorService) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) KojiPathPatternFormatter(org.commonjava.indy.koji.content.KojiPathPatternFormatter) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) KOJI_ORIGIN_BINARY(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN_BINARY) KojiArchiveInfo(com.redhat.red.build.koji.model.xmlrpc.KojiArchiveInfo) KojiClientException(com.redhat.red.build.koji.KojiClientException) StoreKey(org.commonjava.indy.model.core.StoreKey) StoreType.group(org.commonjava.indy.model.core.StoreType.group) Logger(org.slf4j.Logger) SimpleArtifactRef(org.commonjava.atlas.maven.ident.ref.SimpleArtifactRef) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ReentrantLock(java.util.concurrent.locks.ReentrantLock) MalformedURLException(java.net.MalformedURLException) KojiClient(com.redhat.red.build.koji.KojiClient) CREATION_TRIGGER_GAV(org.commonjava.indy.koji.content.KojiContentManagerDecorator.CREATION_TRIGGER_GAV) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) KojiUtils(org.commonjava.indy.koji.util.KojiUtils) Collectors(java.util.stream.Collectors) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KOJI_ORIGIN(org.commonjava.indy.koji.model.IndyKojiConstants.KOJI_ORIGIN) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) KojiSessionInfo(com.redhat.red.build.koji.model.xmlrpc.KojiSessionInfo) List(java.util.List) KojiBuildInfo(com.redhat.red.build.koji.model.xmlrpc.KojiBuildInfo) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) StoreType.remote(org.commonjava.indy.model.core.StoreType.remote) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) PoolUtils.detectOverloadVoid(org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid) IndyKojiConfig(org.commonjava.indy.koji.conf.IndyKojiConfig) ArrayList(java.util.ArrayList) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) DrainingExecutorCompletionService(org.commonjava.cdi.util.weft.DrainingExecutorCompletionService) IndyDataException(org.commonjava.indy.data.IndyDataException) KojiMultiRepairResult(org.commonjava.indy.koji.model.KojiMultiRepairResult) KojiRepairResult(org.commonjava.indy.koji.model.KojiRepairResult) KojiRepairRequest(org.commonjava.indy.koji.model.KojiRepairRequest) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

DrainingExecutorCompletionService (org.commonjava.cdi.util.weft.DrainingExecutorCompletionService)9 ArrayList (java.util.ArrayList)8 ExecutionException (java.util.concurrent.ExecutionException)8 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)7 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)7 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)7 List (java.util.List)6 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 Inject (javax.inject.Inject)5 ExecutorConfig (org.commonjava.cdi.util.weft.ExecutorConfig)5 WeftExecutorService (org.commonjava.cdi.util.weft.WeftExecutorService)5 WeftManaged (org.commonjava.cdi.util.weft.WeftManaged)5 PoolUtils.detectOverloadVoid (org.commonjava.indy.core.ctl.PoolUtils.detectOverloadVoid)5 IndyDataException (org.commonjava.indy.data.IndyDataException)5 StoreDataManager (org.commonjava.indy.data.StoreDataManager)5 IOException (java.io.IOException)4 Group (org.commonjava.indy.model.core.Group)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)4