Search in sources :

Example 31 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class DeprecatedFoloContentAccessResource method doCreate.

@ApiOperation("Store and track file/artifact content under the given artifact store (type/name) and path.")
@ApiResponses({ @ApiResponse(code = 201, message = "Content was stored successfully"), @ApiResponse(code = 400, message = "No appropriate storage location was found in the specified store (this store, or a member if a group is specified).") })
@PUT
@Path("/{path: (.*)}")
public Response doCreate(@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);
    EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.MAVEN_REPO);
    final Supplier<URI> uriSupplier = () -> uriInfo.getBaseUriBuilder().path(getClass()).path(path).build(id, type, name);
    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.doCreate(MAVEN_PKG_KEY, type, name, path, request, metadata, uriSupplier, 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) URI(java.net.URI) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Path(javax.ws.rs.Path) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) PUT(javax.ws.rs.PUT)

Example 32 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloRecordCacheTest method recordArtifactCreatesNewInProgressEntry.

@Test
public void recordArtifactCreatesNewInProgressEntry() throws Exception {
    final TrackingKey key = newKey();
    final long size = 123L;
    assertThat(cache.hasRecord(key), equalTo(false));
    cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, size, "", "", ""));
    assertThat(cache.hasRecord(key), equalTo(true));
    assertThat(cache.hasInProgressRecord(key), equalTo(true));
    assertThat(cache.hasSealedRecord(key), equalTo(false));
    TrackedContent record = cache.seal(key);
    assertThat(record, notNullValue());
    assertThat(cache.hasRecord(key), equalTo(true));
    assertThat(cache.hasInProgressRecord(key), equalTo(false));
    assertThat(cache.hasSealedRecord(key), equalTo(true));
    Set<TrackedContentEntry> downloads = cache.get(key).getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));
    TrackedContentEntry entry = downloads.iterator().next();
    assertThat(entry.getSize(), equalTo(size));
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Example 33 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloRecordCacheTest method hasRecordReturnsFalseIfNoneExists.

@Test
public void hasRecordReturnsFalseIfNoneExists() throws Exception {
    final TrackingKey key = newKey();
    assertThat(cache.hasRecord(key), equalTo(false));
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Example 34 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloRecordCacheTest method getRecordReturnsNullIfNoneExists.

@Test
public void getRecordReturnsNullIfNoneExists() throws Exception {
    final TrackingKey key = newKey();
    assertThat(cache.get(key), nullValue());
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Example 35 with TrackingKey

use of org.commonjava.indy.folo.model.TrackingKey in project indy by Commonjava.

the class FoloRecordCacheTest method sealRemovesInProgressAndCreatesSealedRecord.

@Test
public void sealRemovesInProgressAndCreatesSealedRecord() throws Exception {
    final TrackingKey key = newKey();
    assertThat(cache.hasRecord(key), equalTo(false));
    cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, 124L, "", "", ""));
    assertThat(cache.hasRecord(key), equalTo(true));
    assertThat(cache.hasInProgressRecord(key), equalTo(true));
    assertThat(cache.hasSealedRecord(key), equalTo(false));
    TrackedContent record = cache.seal(key);
    assertThat(record, notNullValue());
    assertThat(cache.hasRecord(key), equalTo(true));
    assertThat(cache.hasInProgressRecord(key), equalTo(false));
    assertThat(cache.hasSealedRecord(key), equalTo(true));
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Aggregations

TrackingKey (org.commonjava.indy.folo.model.TrackingKey)46 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)18 ApiOperation (io.swagger.annotations.ApiOperation)12 ApiResponses (io.swagger.annotations.ApiResponses)12 Path (javax.ws.rs.Path)12 StoreKey (org.commonjava.indy.model.core.StoreKey)11 Test (org.junit.Test)11 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)10 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)10 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)8 GET (javax.ws.rs.GET)6 HEAD (javax.ws.rs.HEAD)6 PUT (javax.ws.rs.PUT)6 AccessChannel (org.commonjava.indy.model.core.AccessChannel)6 Inject (javax.inject.Inject)4 Context (javax.ws.rs.core.Context)4 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)4 Location (org.commonjava.maven.galley.model.Location)4 Transfer (org.commonjava.maven.galley.model.Transfer)4 Logger (org.slf4j.Logger)4