Search in sources :

Example 11 with MavenPath

use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.

the class MergingGroupHandler method doGetContent.

private Response doGetContent(@Nonnull final Context context, @Nonnull final DispatchedRepositories dispatched) throws Exception {
    final MavenPath mavenPath = context.getAttributes().require(MavenPath.class);
    final MavenGroupFacet groupFacet = context.getRepository().facet(MavenGroupFacet.class);
    final Repository repository = context.getRepository();
    final List<Repository> members = groupFacet.members();
    log.trace("Incoming request for {} : {}", context.getRepository().getName(), mavenPath.getPath());
    List<Repository> proxiesOrGroups = members.stream().filter(PROXY_OR_GROUP::apply).collect(toList());
    Content content = maybeCooperate(repository, mavenPath, () -> {
        try {
            // Check members to prime
            Map<Repository, Response> passThroughResponses = getAll(context, proxiesOrGroups, dispatched);
            Optional<Content> cached = checkCache(groupFacet, mavenPath, repository);
            if (cached.isPresent()) {
                log.trace("Serving cached content {} : {}", repository.getName(), mavenPath.getPath());
                return cached.get();
            }
            // this will fetch the remaining responses, thanks to the 'dispatched' tracking
            Map<Repository, Response> remainingResponses = getAll(context, members, dispatched);
            // merge the two sets of responses according to member order
            LinkedHashMap<Repository, Response> responses = new LinkedHashMap<>();
            for (Repository member : members) {
                Response response = passThroughResponses.get(member);
                if (response == null) {
                    response = remainingResponses.get(member);
                }
                if (response != null) {
                    responses.put(member, response);
                }
            }
            // merge the individual responses and cache the result
            Content mergedContent = groupFacet.mergeAndCache(mavenPath, responses);
            if (mergedContent != null) {
                log.trace("Responses merged {} : {}", context.getRepository().getName(), mavenPath.getPath());
            }
            return mergedContent;
        } catch (Exception e) {
            throw new IOException(e);
        }
    });
    if (content != null) {
        return HttpResponses.ok(content);
    } else {
        log.trace("Not found response to merge {} : {}", repository.getName(), mavenPath.getPath());
        return HttpResponses.notFound();
    }
}
Also used : Response(org.sonatype.nexus.repository.view.Response) Repository(org.sonatype.nexus.repository.Repository) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Content(org.sonatype.nexus.repository.view.Content) IOException(java.io.IOException) RetryDeniedException(org.sonatype.nexus.transaction.RetryDeniedException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with MavenPath

use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.

the class AbstractMetadataRebuilder method getPathsByGav.

/**
 * Collect all {@link MavenPath} for the provided GAbV.
 *
 * @param repository  The repository associated with the provided GAbV (Maven2 format, Hosted type only).
 * @param groupId     scope the work to given groupId.
 * @param artifactId  scope the work to given artifactId (groupId must be given).
 * @param baseVersion scope the work to given baseVersion (groupId and artifactId must ge given).
 * @return list of all paths for the input coordinates
 * @since 3.14
 */
protected List<MavenPath> getPathsByGav(final Repository repository, final String groupId, final String artifactId, final String baseVersion) {
    checkNotNull(groupId);
    checkNotNull(artifactId);
    checkNotNull(baseVersion);
    log.debug("Collecting MavenPaths for Maven2 hosted repository metadata: repository={}, g={}, a={}, bV={}", repository.getName(), groupId, artifactId, baseVersion);
    List<MavenPath> paths = new ArrayList<>();
    // Build path for specific GAV
    paths.add(metadataPath(groupId, artifactId, baseVersion));
    // Build path for the GA; will be rebuilt as necessary but may hold the last GAV in which case rebuild would ignore it
    paths.add(metadataPath(groupId, artifactId, null));
    // Check explicitly for whether or not we have Group level metadata that might need rebuilding, since this
    // is potentially the most expensive possible path to take.
    MavenPath groupPath = metadataPath(groupId, null, null);
    if (exists(repository, groupPath)) {
        paths.add(groupPath);
    }
    return paths;
}
Also used : MavenPath(org.sonatype.nexus.repository.maven.MavenPath) ArrayList(java.util.ArrayList)

Example 13 with MavenPath

use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.

the class OrientArchetypeCatalogHandler method handle.

@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
    MavenPath path = context.getAttributes().require(MavenPath.class);
    Repository repository = context.getRepository();
    String action = context.getRequest().getAction();
    switch(action) {
        case GET:
        case HEAD:
            return doGet(path, repository);
        default:
            return HttpResponses.methodNotAllowed(context.getRequest().getAction(), GET, HEAD);
    }
}
Also used : Repository(org.sonatype.nexus.repository.Repository) MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Nonnull(javax.annotation.Nonnull)

Example 14 with MavenPath

use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.

the class OrientIndexGroupHandler method handle.

@Nonnull
@Override
public Response handle(@Nonnull final Context context) throws Exception {
    MavenPath mavenPath = context.getAttributes().require(MavenPath.class);
    OrientMavenFacet mavenFacet = context.getRepository().facet(OrientMavenFacet.class);
    Content content = mavenFacet.get(mavenPath);
    if (content == null) {
        return HttpResponses.notFound(mavenPath.getPath());
    }
    return HttpResponses.ok(content);
}
Also used : MavenPath(org.sonatype.nexus.repository.maven.MavenPath) Content(org.sonatype.nexus.repository.view.Content) OrientMavenFacet(org.sonatype.nexus.orient.maven.OrientMavenFacet) Nonnull(javax.annotation.Nonnull)

Example 15 with MavenPath

use of org.sonatype.nexus.repository.maven.MavenPath in project nexus-public by sonatype.

the class OrientMavenGroupFacet method on.

@Subscribe
@AllowConcurrentEvents
public void on(final AssetEvent event) {
    // only make DB changes on the originating node, as orient will also replicate those for us
    if (event.isLocal() && event.getComponentId() == null && member(event.getRepositoryName())) {
        final String path = event.getAsset().name();
        final MavenPath mavenPath = mavenFacet.getMavenPathParser().parsePath(path);
        // only trigger eviction on main metadata artifact (which may go on to evict its hashes)
        if (!mavenPath.isHash()) {
            UnitOfWork.begin(getRepository().facet(StorageFacet.class).txSupplier());
            try {
                evictCache(mavenPath, event instanceof AssetDeletedEvent);
            } finally {
                UnitOfWork.end();
            }
        }
    }
}
Also used : MavenPath(org.sonatype.nexus.repository.maven.MavenPath) AssetDeletedEvent(org.sonatype.nexus.repository.storage.AssetDeletedEvent) AllowConcurrentEvents(com.google.common.eventbus.AllowConcurrentEvents) Subscribe(com.google.common.eventbus.Subscribe)

Aggregations

MavenPath (org.sonatype.nexus.repository.maven.MavenPath)81 Test (org.junit.Test)32 OrientMavenFacet (org.sonatype.nexus.orient.maven.OrientMavenFacet)15 MavenContentFacet (org.sonatype.nexus.content.maven.MavenContentFacet)14 Repository (org.sonatype.nexus.repository.Repository)9 ComponentUpload (org.sonatype.nexus.repository.upload.ComponentUpload)9 Content (org.sonatype.nexus.repository.view.Content)9 IOException (java.io.IOException)8 HashType (org.sonatype.nexus.repository.maven.MavenPath.HashType)8 AssetUpload (org.sonatype.nexus.repository.upload.AssetUpload)8 Payload (org.sonatype.nexus.repository.view.Payload)8 TempBlob (org.sonatype.nexus.repository.view.payloads.TempBlob)8 Nonnull (javax.annotation.Nonnull)7 Asset (org.sonatype.nexus.repository.storage.Asset)7 StorageTx (org.sonatype.nexus.repository.storage.StorageTx)7 PartPayload (org.sonatype.nexus.repository.view.PartPayload)7 Map (java.util.Map)5 UploadResponse (org.sonatype.nexus.repository.upload.UploadResponse)5 ArrayList (java.util.ArrayList)4 Coordinates (org.sonatype.nexus.repository.maven.MavenPath.Coordinates)4