Search in sources :

Example 1 with MAVEN_PKG_KEY

use of org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY in project indy by Commonjava.

the class NfcResource method deprecatedGetStore.

@Path("/{type: (hosted|group|remote)}/{name}")
@ApiOperation("[Deprecated] Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response deprecatedGetStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
    Response response;
    final StoreType type = StoreType.get(t);
    String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
    final StoreKey key = new StoreKey(type, name);
    try {
        final NotFoundCacheDTO dto = controller.getMissing(key);
        response = formatOkResponseWithJsonEntity(dto, serializer, rb -> markDeprecated(rb, altPath));
    } catch (final IndyWorkflowException e) {
        response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
    }
    return response;
}
Also used : ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) Response(javax.ws.rs.core.Response) ApiResponse(io.swagger.annotations.ApiResponse) StoreType(org.commonjava.indy.model.core.StoreType) PathParam(javax.ws.rs.PathParam) NfcController(org.commonjava.indy.core.ctl.NfcController) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) StringUtils.isNotEmpty(org.apache.commons.lang.StringUtils.isNotEmpty) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) ResponseUtils.formatOkResponseWithJsonEntity(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatOkResponseWithJsonEntity) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Api(io.swagger.annotations.Api) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) DELETE(javax.ws.rs.DELETE) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) ResponseUtils.formatResponse(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.formatResponse) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) StoreType(org.commonjava.indy.model.core.StoreType) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) ResponseUtils.markDeprecated(org.commonjava.indy.bind.jaxrs.util.ResponseUtils.markDeprecated) ApplicationContent(org.commonjava.indy.util.ApplicationContent) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) ApiResponse(io.swagger.annotations.ApiResponse) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) StoreKey(org.commonjava.indy.model.core.StoreKey) NotFoundCacheDTO(org.commonjava.indy.model.core.dto.NotFoundCacheDTO) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with MAVEN_PKG_KEY

use of org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY in project indy by Commonjava.

the class DeprecatedFoloContentAccessResource method doHead.

@ApiOperation("Store and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, message = "Header metadata for content (or rendered listing when path ends with '/index.html' or '/'") })
@HEAD
@Path("/{path: (.*)}")
public Response doHead(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("path") final String path, @QueryParam(CHECK_CACHE_ONLY) final Boolean cacheOnly, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
    final TrackingKey tk = new TrackingKey(id);
    final String baseUri = uriInfo.getBaseUriBuilder().path(BASE_PATH).path(id).build().toString();
    EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.MAVEN_REPO);
    final Consumer<Response.ResponseBuilder> deprecation = builder -> {
        String alt = Paths.get("/api/folo/track/", id, MAVEN_PKG_KEY, type, name, path).toString();
        responseHelper.markDeprecated(builder, alt);
    };
    return handler.doHead(MAVEN_PKG_KEY, type, name, path, cacheOnly, baseUri, request, metadata, deprecation);
}
Also used : PathParam(javax.ws.rs.PathParam) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) REST(org.commonjava.indy.bind.jaxrs.util.REST) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryParam(javax.ws.rs.QueryParam) Api(io.swagger.annotations.Api) URI(java.net.URI) ACCESS_CHANNEL(org.commonjava.indy.folo.ctl.FoloConstants.ACCESS_CHANNEL) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) ContentAccessHandler(org.commonjava.indy.core.bind.jaxrs.ContentAccessHandler) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) AccessChannel(org.commonjava.indy.model.core.AccessChannel) StreamingOutput(javax.ws.rs.core.StreamingOutput) Consumer(java.util.function.Consumer) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) TRACKING_KEY(org.commonjava.indy.folo.ctl.FoloConstants.TRACKING_KEY) ApiResponse(io.swagger.annotations.ApiResponse) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) HEAD(javax.ws.rs.HEAD) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) HEAD(javax.ws.rs.HEAD) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 3 with MAVEN_PKG_KEY

use of org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY in project indy by Commonjava.

the class DeprecatedFoloContentAccessResource method doGet.

@ApiOperation("Retrieve and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 404, message = "Content is not available"), @ApiResponse(code = 200, response = String.class, message = "Rendered content listing (when path ends with '/index.html' or '/')"), @ApiResponse(code = 200, response = StreamingOutput.class, message = "Content stream") })
@GET
@Path("/{path: (.*)}")
public Response doGet(@ApiParam("User-assigned tracking session key") @PathParam("id") final String id, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @PathParam("name") final String name, @PathParam("path") final String path, @Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
    final TrackingKey tk = new TrackingKey(id);
    final String baseUri = uriInfo.getBaseUriBuilder().path(BASE_PATH).path(id).build().toString();
    EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.MAVEN_REPO);
    final Consumer<Response.ResponseBuilder> deprecation = builder -> {
        String alt = Paths.get("/api/folo/track/", id, MAVEN_PKG_KEY, type, name, path).toString();
        responseHelper.markDeprecated(builder, alt);
    };
    return handler.doGet(MAVEN_PKG_KEY, type, name, path, baseUri, request, metadata, deprecation);
}
Also used : PathParam(javax.ws.rs.PathParam) IndyDeployment(org.commonjava.indy.bind.jaxrs.IndyDeployment) REST(org.commonjava.indy.bind.jaxrs.util.REST) CHECK_CACHE_ONLY(org.commonjava.indy.IndyContentConstants.CHECK_CACHE_ONLY) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ApiResponses(io.swagger.annotations.ApiResponses) Supplier(java.util.function.Supplier) Inject(javax.inject.Inject) ApiOperation(io.swagger.annotations.ApiOperation) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) HttpServletRequest(javax.servlet.http.HttpServletRequest) QueryParam(javax.ws.rs.QueryParam) Api(io.swagger.annotations.Api) URI(java.net.URI) ACCESS_CHANNEL(org.commonjava.indy.folo.ctl.FoloConstants.ACCESS_CHANNEL) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) ContentAccessHandler(org.commonjava.indy.core.bind.jaxrs.ContentAccessHandler) ResponseHelper(org.commonjava.indy.bind.jaxrs.util.ResponseHelper) IndyResources(org.commonjava.indy.bind.jaxrs.IndyResources) AccessChannel(org.commonjava.indy.model.core.AccessChannel) StreamingOutput(javax.ws.rs.core.StreamingOutput) Consumer(java.util.function.Consumer) Response(javax.ws.rs.core.Response) Paths(java.nio.file.Paths) TRACKING_KEY(org.commonjava.indy.folo.ctl.FoloConstants.TRACKING_KEY) ApiResponse(io.swagger.annotations.ApiResponse) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) HEAD(javax.ws.rs.HEAD) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with MAVEN_PKG_KEY

use of org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY in project indy by Commonjava.

the class ContentIndexDirLvWithArtifactsTest method test.

@Test
public void test() throws Exception {
    final String remoteName1 = newName();
    RemoteRepository remote1 = new RemoteRepository(MAVEN_PKG_KEY, remoteName1, server.formatUrl(remoteName1));
    remote1 = client.stores().create(remote1, name.getMethodName(), RemoteRepository.class);
    final String remoteName2 = newName();
    RemoteRepository remote2 = new RemoteRepository(MAVEN_PKG_KEY, remoteName2, server.formatUrl(remoteName2));
    remote2 = client.stores().create(remote2, name.getMethodName(), RemoteRepository.class);
    final String groupName = newName();
    Group group = new Group(MAVEN_PKG_KEY, groupName, remote1.getKey(), remote2.getKey());
    group = client.stores().create(group, name.getMethodName(), Group.class);
    server.expect(server.formatUrl(remoteName2, PATH_JAR), 200, PATH_JAR_CONTENT);
    server.expect(server.formatUrl(remoteName2, PATH_POM), 200, PATH_POM_CONTENT);
    final String CHECKSUM_CONTENT = newName();
    for (String checksumPath : PATHS_CHECKSUM) {
        server.expect(server.formatUrl(remoteName2, checksumPath), 200, CHECKSUM_CONTENT);
    }
    try (InputStream s = client.content().get(group.getKey(), PATH_JAR)) {
        assertThat(IOUtils.toString(s), equalTo(PATH_JAR_CONTENT));
    }
    try (InputStream s = client.content().get(group.getKey(), PATH_JAR)) {
        assertThat(IOUtils.toString(s), equalTo(PATH_JAR_CONTENT));
    }
    for (String checksumPath : PATHS_CHECKSUM) {
        try (InputStream s = client.content().get(group.getKey(), checksumPath)) {
            assertThat(IOUtils.toString(s), equalTo(CHECKSUM_CONTENT));
        }
    }
    AdvancedCache<IndexedStorePath, IndexedStorePath> advancedCache = (AdvancedCache) contentIndex.execute(c -> c);
    System.out.println("[Content index DEBUG]: cached isps: " + advancedCache.keySet());
    for (IndexedStorePath value : advancedCache.values()) {
        boolean match = remote2.getKey().equals(value.getOriginStoreKey()) || remote2.getKey().equals(value.getStoreKey());
        assertThat(match, equalTo(true));
    }
    System.out.println("[Content index DEBUG]: cache size:" + advancedCache.size());
    assertTrue(advancedCache.size() <= 2);
    System.out.println("[Content index DEBUG]: cache hit:" + advancedCache.getStats().getHits());
    assertTrue(advancedCache.getStats().getHits() >= 7);
    System.out.println("[Content index DEBUG]: cache misses:" + advancedCache.getStats().getMisses());
}
Also used : ExpectationServer(org.commonjava.test.http.expect.ExpectationServer) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Arrays(java.util.Arrays) IndexedStorePath(org.commonjava.indy.content.index.IndexedStorePath) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ContentIndexCacheProducer(org.commonjava.indy.content.index.ContentIndexCacheProducer) CDI(javax.enterprise.inject.spi.CDI) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) BasicCacheHandle(org.commonjava.indy.subsys.infinispan.BasicCacheHandle) Group(org.commonjava.indy.model.core.Group) Assert.assertThat(org.junit.Assert.assertThat) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) AdvancedCache(org.infinispan.AdvancedCache) Rule(org.junit.Rule) CoreServerFixture(org.commonjava.indy.test.fixture.core.CoreServerFixture) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) Before(org.junit.Before) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) IndexedStorePath(org.commonjava.indy.content.index.IndexedStorePath) AdvancedCache(org.infinispan.AdvancedCache) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Example 5 with MAVEN_PKG_KEY

use of org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY in project indy by Commonjava.

the class ContentIndexRemoteRepoUsageTest method bypassNotIndexedContentWithAuthoritativeIndex.

@Test
public void bypassNotIndexedContentWithAuthoritativeIndex() throws Exception {
    final String repoName = newName();
    RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, repoName, server.formatUrl(repoName));
    repo = client.stores().create(repo, name.getMethodName(), RemoteRepository.class);
    server.expect(server.formatUrl(repoName, FIRST_PATH), 200, FIRST_PATH_CONTENT);
    StoreKey indexedStoreKey = indexManager.getIndexedStoreKey(repo.getKey(), FIRST_PATH);
    logger.info("\n\n\nBEFORE: Indexed path entry: " + indexedStoreKey + "\n\n\n\n");
    assertThat(indexedStoreKey, nullValue());
    Long hits = cacheHandle.executeCache((cache) -> cache.getAdvancedCache().getStats().getHits());
    assertThat(hits == 0, equalTo(true));
    try (InputStream first = client.content().get(repo.getKey(), FIRST_PATH)) {
        assertThat(IOUtils.toString(first), equalTo(FIRST_PATH_CONTENT));
    }
    indexedStoreKey = indexManager.getIndexedStoreKey(repo.getKey(), FIRST_PATH);
    logger.info("\n\n\nAFTER 1: Indexed path entry: " + indexedStoreKey + "\n\n\n\n");
    assertThat(indexedStoreKey, notNullValue());
    hits = cacheHandle.executeCache((cache) -> cache.getAdvancedCache().getStats().getHits());
    assertThat(hits >= 1, equalTo(true));
    try (InputStream first = client.content().get(repo.getKey(), FIRST_PATH)) {
        assertThat(IOUtils.toString(first), equalTo(FIRST_PATH_CONTENT));
    }
    StoreKey indexedStoreKey2 = indexManager.getIndexedStoreKey(repo.getKey(), FIRST_PATH);
    logger.info("\n\n\nAFTER 2: Indexed path entry: " + indexedStoreKey2 + "\n\n\n\n");
    hits = cacheHandle.executeCache((cache) -> cache.getAdvancedCache().getStats().getHits());
    assertThat(hits >= 2, equalTo(true));
    // object equality should work since we haven't persisted this anywhere yet.
    assertThat(indexedStoreKey == indexedStoreKey2, equalTo(true));
}
Also used : ExpectationServer(org.commonjava.test.http.expect.ExpectationServer) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) IndexedStorePath(org.commonjava.indy.content.index.IndexedStorePath) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) ContentIndexCacheProducer(org.commonjava.indy.content.index.ContentIndexCacheProducer) CDI(javax.enterprise.inject.spi.CDI) Test(org.junit.Test) IOException(java.io.IOException) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) CacheHandle(org.commonjava.indy.subsys.infinispan.CacheHandle) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) Assert.assertThat(org.junit.Assert.assertThat) IOUtils(org.apache.commons.io.IOUtils) Rule(org.junit.Rule) CoreServerFixture(org.commonjava.indy.test.fixture.core.CoreServerFixture) ContentIndexManager(org.commonjava.indy.content.index.ContentIndexManager) StoreKey(org.commonjava.indy.model.core.StoreKey) MAVEN_PKG_KEY(org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) InputStream(java.io.InputStream) InputStream(java.io.InputStream) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) StoreKey(org.commonjava.indy.model.core.StoreKey) AbstractIndyFunctionalTest(org.commonjava.indy.ftest.core.AbstractIndyFunctionalTest) Test(org.junit.Test)

Aggregations

MAVEN_PKG_KEY (org.commonjava.indy.pkg.maven.model.MavenPackageTypeDescriptor.MAVEN_PKG_KEY)10 Inject (javax.inject.Inject)7 Api (io.swagger.annotations.Api)6 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiParam (io.swagger.annotations.ApiParam)6 ApiResponse (io.swagger.annotations.ApiResponse)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Paths (java.nio.file.Paths)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 PathParam (javax.ws.rs.PathParam)6 Response (javax.ws.rs.core.Response)6 IndyResources (org.commonjava.indy.bind.jaxrs.IndyResources)6 StoreKey (org.commonjava.indy.model.core.StoreKey)6 QueryParam (javax.ws.rs.QueryParam)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 URI (java.net.URI)3 Arrays (java.util.Arrays)3 List (java.util.List)3