Search in sources :

Example 1 with InvalidRefException

use of org.commonjava.atlas.maven.ident.ref.InvalidRefException in project indy by Commonjava.

the class KojiMavenMetadataProvider method getMetadata.

@Override
@Measure
public Metadata getMetadata(StoreKey targetKey, String path) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    if (group != targetKey.getType()) {
        logger.debug("Not a group. Cannot supplement with metadata from Koji builds");
        return null;
    }
    if (!kojiConfig.isEnabled()) {
        logger.debug("Koji add-on is disabled.");
        return null;
    }
    try {
        ArtifactStore target = storeDataManager.getArtifactStore(targetKey);
        if (!kojiConfig.isEnabledFor(target)) {
            logger.debug("Koji integration is not enabled for group: {}", targetKey);
            return null;
        }
    } catch (IndyDataException e) {
        logger.error("Failed to get metadata for path {} in store {}: {}", path, targetKey, e.getMessage());
    }
    File mdFile = new File(path);
    File artifactDir = mdFile.getParentFile();
    File groupDir = artifactDir == null ? null : artifactDir.getParentFile();
    if (artifactDir == null || groupDir == null) {
        logger.debug("Invalid groupId / artifactId directory structure: '{}' / '{}'", groupDir, artifactDir);
        return null;
    }
    String groupId = groupDir.getPath().replace(File.separatorChar, '.');
    String artifactId = artifactDir.getName();
    ProjectRef ref = null;
    try {
        ref = new SimpleProjectRef(groupId, artifactId);
    } catch (InvalidRefException e) {
        logger.warn("Not a valid Maven GA: {}:{}. Skipping Koji metadata retrieval.", groupId, artifactId);
    }
    if (ref == null) {
        logger.debug("Could not render a valid Maven GA for path: '{}'", path);
        return null;
    }
    ProjectRef ga = ref;
    AtomicReference<IndyWorkflowException> wfError = new AtomicReference<>();
    return versionMetadataLocks.lockAnd(ga, kojiConfig.getLockTimeoutSeconds(), k -> {
        Metadata metadata = versionMetadata.get(ga);
        if (metadata == null) {
            try {
                metadata = executeKojiMetadataLookup(ga, path);
            } catch (IndyWorkflowException e) {
                wfError.set(e);
                metadata = null;
            } catch (KojiClientException e) {
                // FIXME: Should this bubble up like IndyWorkflowException does in the case of overloaded threadpool?
                Throwable cause = e.getCause();
                logger.error(String.format("Failed to retrieve version metadata for: %s from Koji. Reason: %s", ga, e.getMessage()), e);
                if (cause instanceof RuntimeException) {
                    logger.error("Previous exception's nested cause was a RuntimeException variant:", cause);
                }
                metadata = null;
            }
            if (metadata != null) {
                Metadata md = metadata;
                // FIXME: Need a way to listen for cache expiration and re-request this?
                versionMetadata.execute((cache) -> cache.put(ga, md, kojiConfig.getMetadataTimeoutSeconds(), TimeUnit.SECONDS));
            } else {
                logger.debug("Returning null metadata result for unknown reason (path: '{}')", path);
            }
        }
        return metadata;
    }, (k, lock) -> {
        logger.error("Failed to acquire Koji GA version metadata lock on: '{}' in {} seconds.", ga, kojiConfig.getLockTimeoutSeconds());
        return false;
    });
}
Also used : InvalidRefException(org.commonjava.atlas.maven.ident.ref.InvalidRefException) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Metadata(org.apache.maven.artifact.repository.metadata.Metadata) AtomicReference(java.util.concurrent.atomic.AtomicReference) Logger(org.slf4j.Logger) IndyDataException(org.commonjava.indy.data.IndyDataException) SimpleProjectRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectRef) KojiClientException(com.redhat.red.build.koji.KojiClientException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) SimpleProjectRef(org.commonjava.atlas.maven.ident.ref.SimpleProjectRef) ProjectRef(org.commonjava.atlas.maven.ident.ref.ProjectRef) File(java.io.File) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

KojiClientException (com.redhat.red.build.koji.KojiClientException)1 File (java.io.File)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Metadata (org.apache.maven.artifact.repository.metadata.Metadata)1 InvalidRefException (org.commonjava.atlas.maven.ident.ref.InvalidRefException)1 ProjectRef (org.commonjava.atlas.maven.ident.ref.ProjectRef)1 SimpleProjectRef (org.commonjava.atlas.maven.ident.ref.SimpleProjectRef)1 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)1 Logger (org.slf4j.Logger)1