Search in sources :

Example 36 with TrackingKey

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

the class FoloMavenContentAccessResource 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.NATIVE).set(STORE_HTTP_HEADERS, RequestUtils.extractRequestHeadersToMap(request));
    Class cls = FoloMavenContentAccessResource.class;
    return handler.doCreate(PKG_TYPE_MAVEN, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(cls).path(path).build(id, PKG_TYPE_MAVEN, type, name));
}
Also used : 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 37 with TrackingKey

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

the class FoloNPMContentAccessResource method doCreate.

@ApiOperation("Store NPM artifact content under the given artifact store (type/name), packageName and versionTarball (/version or /-/tarball).")
@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("/{packageName}/{versionTarball: (.*)}")
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, @ApiParam(required = true) @PathParam("name") final String name, @PathParam("packageName") final String packageName, @PathParam("versionTarball") final String versionTarball, @Context final UriInfo uriInfo, @Context final HttpServletRequest request) {
    final TrackingKey tk = new TrackingKey(id);
    EventMetadata metadata = new EventMetadata().set(TRACKING_KEY, tk).set(ACCESS_CHANNEL, AccessChannel.NATIVE);
    final String path = Paths.get(packageName, versionTarball).toString();
    Class cls = FoloNPMContentAccessResource.class;
    return handler.doCreate(NPM_PKG_KEY, type, name, path, request, metadata, () -> uriInfo.getBaseUriBuilder().path(cls).path(path).build(NPM_PKG_KEY, type, name));
}
Also used : 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 38 with TrackingKey

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

the class FoloTrackingListener method onFileAccess.

public void onFileAccess(@Observes final FileAccessEvent event) {
    logger.trace("FILE ACCESS: {}", event);
    EventMetadata metadata = event.getEventMetadata();
    final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
    if (trackingKey == null) {
        logger.trace("No tracking key for access to: {}", event.getTransfer());
        return;
    }
    final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
    final Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.trace("No transfer: {}", event);
        return;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        logger.trace("Not in a keyed location: {}", event.getTransfer());
        return;
    }
    try {
        final KeyedLocation keyedLocation = (KeyedLocation) location;
        if (!foloConfig.isGroupContentTracked() && keyedLocation.getKey().getType() == group) {
            logger.trace("NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", keyedLocation.getKey());
            return;
        }
        logger.trace("Tracking report: {} += {} in {} (DOWNLOAD)", trackingKey, transfer.getPath(), keyedLocation.getKey());
        // Here we need to think about npm metadata retrieving case. As almost all npm metadata retrieving is through
        // /$pkg from remote, but we use STORAGE_PATH in EventMetadata with /$pkg/package.json to store this metadata,
        // so the real path for this transfer should be /$pkg but its current path is /$pkg/package.json. We need to
        // think about if need to do the replacement here, especially for the originalUrl.
        recordManager.recordArtifact(createEntry(trackingKey, keyedLocation.getKey(), accessChannel, transfer.getPath(), StoreEffect.DOWNLOAD, event.getEventMetadata()));
    } catch (final FoloContentException | IndyWorkflowException e) {
        logger.error(String.format("Failed to record download: %s. Reason: %s", transfer, e.getMessage()), e);
    }
}
Also used : FoloContentException(org.commonjava.indy.folo.data.FoloContentException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) AccessChannel(org.commonjava.indy.model.core.AccessChannel) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 39 with TrackingKey

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

the class FoloTrackingListener method onFileUpload.

public void onFileUpload(@Observes final FileStorageEvent event) {
    logger.trace("FILE STORAGE: {}", event);
    if (TransferOperation.UPLOAD != event.getType()) {
        logger.trace("Not a file upload from client; skipping tracking of storage");
        return;
    }
    EventMetadata metadata = event.getEventMetadata();
    logger.warn(">>> Metadata: " + metadata);
    final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
    if (trackingKey == null) {
        logger.trace("No tracking key. Not recording.");
        return;
    }
    final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
    final Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.trace("No transfer. Not recording.");
        return;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        logger.trace("Invalid transfer source location: {}. Not recording.", location);
        return;
    } else if (!foloConfig.isGroupContentTracked() && ((KeyedLocation) location).getKey().getType() == group) {
        logger.trace("NOT tracking content stored directly in group: {}. This content is generally aggregated metadata, and can be recalculated. Groups may not be stable in some build environments", ((KeyedLocation) location).getKey());
        return;
    }
    final TransferOperation op = event.getType();
    StoreEffect effect = null;
    switch(op) {
        case DOWNLOAD:
            {
                effect = StoreEffect.DOWNLOAD;
                break;
            }
        case UPLOAD:
            {
                effect = StoreEffect.UPLOAD;
                break;
            }
        default:
            {
                logger.trace("Ignoring transfer operation: {} for: {}", op, transfer);
                return;
            }
    }
    try {
        final KeyedLocation keyedLocation = (KeyedLocation) location;
        logger.trace("Tracking report: {} += {} in {} ({})", trackingKey, transfer.getPath(), keyedLocation.getKey(), effect);
        recordManager.recordArtifact(createEntry(trackingKey, keyedLocation.getKey(), accessChannel, transfer.getPath(), effect, event.getEventMetadata()));
    } catch (final FoloContentException | IndyWorkflowException e) {
        logger.error(String.format("Failed to record download: %s. Reason: %s", transfer, e.getMessage()), e);
    }
}
Also used : FoloContentException(org.commonjava.indy.folo.data.FoloContentException) StoreEffect(org.commonjava.indy.folo.model.StoreEffect) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) AccessChannel(org.commonjava.indy.model.core.AccessChannel) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location)

Example 40 with TrackingKey

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

the class FoloAdminController method clearRecord.

public void clearRecord(final String id) throws FoloContentException {
    final TrackingKey tk = new TrackingKey(id);
    recordManager.delete(tk);
}
Also used : TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

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