Search in sources :

Example 16 with TrackingKey

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

the class ProxyResponseHelper method createEventMetadata.

private EventMetadata createEventMetadata(final boolean writeBody, final UserPass proxyUserPass, final String path, final ArtifactStore store) throws IndyWorkflowException {
    final EventMetadata eventMetadata = new EventMetadata();
    if (writeBody) {
        TrackingKey tk = getTrackingKey(proxyUserPass);
        if (tk != null) {
            logger.debug("TRACKING {} in {} (KEY: {})", path, store, tk);
            eventMetadata.set(FoloConstants.TRACKING_KEY, tk);
            eventMetadata.set(FoloConstants.ACCESS_CHANNEL, AccessChannel.GENERIC_PROXY);
        } else {
            logger.debug("NOT TRACKING: {} in {}", path, store);
        }
    } else {
        logger.debug("NOT TRACKING non-body request: {} in {}", path, store);
    }
    eventMetadata.setPackageType(PKG_TYPE_GENERIC_HTTP);
    return eventMetadata;
}
Also used : EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 17 with TrackingKey

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

the class FoloMavenContentAccessResource 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.NATIVE);
    RequestContextHelper.setContext(CONTENT_TRACKING_ID, id);
    return handler.doGet(PKG_TYPE_MAVEN, type, name, path, baseUri, request, metadata);
}
Also used : 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 18 with TrackingKey

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

the class FoloMavenContentAccessResource 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.NATIVE);
    RequestContextHelper.setContext(CONTENT_TRACKING_ID, id);
    return handler.doHead(PKG_TYPE_MAVEN, type, name, path, cacheOnly, baseUri, request, metadata);
}
Also used : 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 19 with TrackingKey

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

the class FoloRecordCacheTest method clearRecordDeletesRecord.

@Test
public void clearRecordDeletesRecord() 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, 127L, "", "", ""));
    TrackedContent record = cache.seal(key);
    assertThat(record, notNullValue());
    assertThat(cache.hasRecord(key), equalTo(true));
    cache.delete(key);
    assertThat(cache.hasRecord(key), equalTo(false));
    assertThat(cache.get(key), nullValue());
}
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 20 with TrackingKey

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

the class TrackingKey2StringMapperTest method testMapper.

@Test
public void testMapper() throws IOException {
    TrackingKey2StringMapper mapper = new TrackingKey2StringMapper();
    TrackingKey key = new TrackingKey(TEST_ID);
    Assert.assertTrue(mapper.isSupportedType(TrackingKey.class));
    Assert.assertFalse(mapper.isSupportedType(Object.class));
    Assert.assertFalse(mapper.isSupportedType(TrackedContent.class));
    Assert.assertTrue(mapper.isSupportedType(WrappedByteArray.class));
    Object genKey = mapper.getKeyMapping(TEST_ID);
    Assert.assertEquals(key, genKey);
    String genId = mapper.getStringMapping(key);
    Assert.assertEquals(TEST_ID, genId);
    WrappedByteArray array = bytesOfTrackingKey(key);
    genId = mapper.getStringMapping(array);
    Assert.assertEquals(TEST_ID, genId);
}
Also used : WrappedByteArray(org.infinispan.commons.marshall.WrappedByteArray) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackingKey2StringMapper(org.commonjava.indy.folo.data.idxmodel.TrackingKey2StringMapper) 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