Search in sources :

Example 51 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure 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 52 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class KojiContentManagerDecorator method findKojiBuildAnd.

@Measure
private <T> T findKojiBuildAnd(ArtifactStore store, String path, EventMetadata eventMetadata, T defValue, KojiBuildAction<T> action) throws IndyWorkflowException {
    if (!config.getEnabled()) {
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.debug("Koji content-manager decorator is disabled.");
        logger.debug("When koji addon is disenabled , path:{},config instance is {}", path, config.toString());
        return defValue;
    }
    if (!config.isEnabledFor(store)) {
        Logger logger = LoggerFactory.getLogger(getClass());
        logger.debug("Koji content-manager decorator not enabled for: {}.", store.getKey());
        logger.debug("When the group is disenabled , path:{},config instance is {}", path, config.toString());
        return defValue;
    }
    logger.debug("When the koji is enabled , path:{},config instance is {}", path, config.toString());
    // TODO: This won't work for maven-metadata.xml files! We need to hit a POM or jar or something first.
    // FIXME: This won't work for NPM!
    ArtifactPathInfo pathInfo = ArtifactPathInfo.parse(path);
    if (pathInfo != null) {
        ArtifactRef artifactRef = pathInfo.getArtifact();
        logger.info("Searching for Koji build: {}", artifactRef);
        return proxyKojiBuild(store.getKey(), artifactRef, path, eventMetadata, defValue, action);
    } else {
        logger.info("Path is not a maven artifact reference: {}", path);
    }
    return defValue;
}
Also used : ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) Logger(org.slf4j.Logger) ArtifactRef(org.commonjava.atlas.maven.ident.ref.ArtifactRef) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 53 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class KojiContentManagerDecorator method retrieve.

@Override
@Measure
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("KOJI: Delegating initial retrieval attempt for: {}/{}", store.getKey(), path);
    Transfer result = delegate.retrieve(store, path, eventMetadata);
    if (result == null && kojiUtils.isVersionSignatureAllowedWithPath(path) && StoreType.group == store.getKey().getType()) {
        logger.info("KOJI: Checking for Koji build matching: {}", path);
        Group group = (Group) store;
        RemoteRepository kojiProxy = findKojiBuildAnd(store, path, eventMetadata, null, this::createRemoteRepository);
        if (kojiProxy != null) {
            adjustTargetGroup(kojiProxy, group);
            result = delegate.retrieve(kojiProxy, path, eventMetadata);
        }
        if (result != null) {
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
        }
    }
    // Finally, pass the Transfer back.
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Logger(org.slf4j.Logger) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 54 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class KojiContentManagerDecorator method exists.

@Override
@Measure
public boolean exists(ArtifactStore store, String path) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("KOJI: Delegating initial existence check for: {}/{}", store.getKey(), path);
    boolean result = delegate.exists(store, path);
    if (!result && kojiUtils.isVersionSignatureAllowedWithPath(path) && StoreType.group == store.getKey().getType()) {
        Group group = (Group) store;
        logger.info("KOJI: Checking whether Koji contains a build matching: {}", path);
        RemoteRepository kojiProxy = findKojiBuildAnd(store, path, new EventMetadata(), null, this::createRemoteRepository);
        if (kojiProxy != null) {
            adjustTargetGroup(kojiProxy, group);
            result = delegate.exists(kojiProxy, path);
        }
        if (result) {
            nfc.clearMissing(new ConcreteResource(LocationUtils.toLocation(store), path));
        }
    }
    return result;
}
Also used : Group(org.commonjava.indy.model.core.Group) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) Logger(org.slf4j.Logger) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 55 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class MavenMetadataGenerator method generateFileContent.

@Override
@Measure
public Transfer generateFileContent(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    // metadata merging is something else...don't handle it here.
    if (StoreType.group == store.getKey().getType()) {
        return null;
    }
    if (!canProcess(path)) {
        return null;
    }
    boolean generated;
    // TODO: Generation of plugin metadata files (groupId-level) is harder, and requires cracking open the jar file
    // This is because that's the only place the plugin prefix can be reliably retrieved from.
    // regardless, we will need this first level of listings. What we do with it will depend on the logic below...
    final String parentPath = Paths.get(path).getParent().toString();
    List<StoreResource> firstLevel;
    try {
        firstLevel = fileManager.listRaw(store, parentPath);
    } catch (final IndyWorkflowException e) {
        logger.error(String.format("SKIP: Failed to generate maven-metadata.xml from listing of directory contents for: %s under path: %s", store, parentPath), e);
        return null;
    }
    String toGenPath = path;
    if (!path.endsWith(MavenMetadataMerger.METADATA_NAME)) {
        toGenPath = normalize(normalize(parentPath(toGenPath)), MavenMetadataMerger.METADATA_NAME);
    }
    ArtifactPathInfo snapshotPomInfo = null;
    if (parentPath.endsWith(LOCAL_SNAPSHOT_VERSION_PART)) {
        // If we're in a version directory, first-level listing should include a .pom file
        for (final StoreResource resource : firstLevel) {
            if (resource.getPath().endsWith(".pom")) {
                snapshotPomInfo = ArtifactPathInfo.parse(resource.getPath());
                break;
            }
        }
    }
    if (snapshotPomInfo != null) {
        logger.debug("Generating maven-metadata.xml for snapshots, store: {}", store.getKey());
        generated = writeSnapshotMetadata(snapshotPomInfo, firstLevel, store, toGenPath, eventMetadata);
    } else {
        logger.debug("Generating maven-metadata.xml for releases, store: {}", store.getKey());
        generated = writeVersionMetadata(firstLevel, store, toGenPath, eventMetadata);
    }
    logger.debug("[Result] Generating maven-metadata.xml for store: {}, result: {}", store.getKey(), generated);
    return generated ? fileManager.getTransfer(store, path) : null;
}
Also used : StoreResource(org.commonjava.indy.content.StoreResource) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) ArtifactPathInfo(org.commonjava.atlas.maven.ident.util.ArtifactPathInfo) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

Measure (org.commonjava.o11yphant.metrics.annotation.Measure)65 StoreKey (org.commonjava.indy.model.core.StoreKey)23 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)19 Transfer (org.commonjava.maven.galley.model.Transfer)19 Logger (org.slf4j.Logger)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)16 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)14 IndyDataException (org.commonjava.indy.data.IndyDataException)13 ArrayList (java.util.ArrayList)12 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 HashSet (java.util.HashSet)9 Group (org.commonjava.indy.model.core.Group)8 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)8 BoundStatement (com.datastax.driver.core.BoundStatement)6 StoreDataManager (org.commonjava.indy.data.StoreDataManager)6 StoreKey.fromString (org.commonjava.indy.model.core.StoreKey.fromString)6 Query (org.infinispan.query.dsl.Query)6 IOException (java.io.IOException)5 Set (java.util.Set)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5