Search in sources :

Example 1 with AccessChannel

use of org.commonjava.indy.model.core.AccessChannel in project indy by Commonjava.

the class TrackedContentEntry2StringMapper method getKeyMapping.

@Override
public Object getKeyMapping(String stringKey) {
    String[] parts = stringKey.split(FIELD_SPLITTER);
    final TrackingKey trackingKey = NULL_STR.equals(parts[0]) ? null : new TrackingKey(parts[0]);
    final String path = NULL_STR.equals(parts[1]) ? null : parts[1];
    final StoreKey storeKey = NULL_STR.equals(parts[2]) ? null : StoreKey.fromString(parts[2]);
    final AccessChannel channel = NULL_STR.equals(parts[3]) ? null : AccessChannel.valueOf(parts[3]);
    final StoreEffect effect = NULL_STR.equals(parts[4]) ? null : StoreEffect.valueOf(parts[4]);
    return new TrackedContentEntry(trackingKey, storeKey, channel, "", path, effect, 0L, "", "", "");
}
Also used : StoreEffect(org.commonjava.indy.folo.model.StoreEffect) AccessChannel(org.commonjava.indy.model.core.AccessChannel) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 2 with AccessChannel

use of org.commonjava.indy.model.core.AccessChannel 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 3 with AccessChannel

use of org.commonjava.indy.model.core.AccessChannel 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 4 with AccessChannel

use of org.commonjava.indy.model.core.AccessChannel in project indy by Commonjava.

the class FoloAdminController method recalculate.

private TrackedContentEntry recalculate(final TrackedContentEntry entry) throws IndyWorkflowException {
    StoreKey affectedStore = entry.getStoreKey();
    String path = entry.getPath();
    AccessChannel channel = entry.getAccessChannel();
    Transfer transfer = contentManager.getTransfer(affectedStore, path, entry.getEffect() == StoreEffect.UPLOAD ? TransferOperation.UPLOAD : TransferOperation.DOWNLOAD);
    if (transfer == null) {
        return entry;
    }
    contentDigester.removeMetadata(transfer);
    TransferMetadata artifactData = contentDigester.digest(affectedStore, path, new EventMetadata(affectedStore.getPackageType()));
    Map<ContentDigest, String> digests = artifactData.getDigests();
    return new TrackedContentEntry(entry.getTrackingKey(), affectedStore, channel, entry.getOriginUrl(), path, entry.getEffect(), artifactData.getSize(), digests.get(ContentDigest.MD5), digests.get(ContentDigest.SHA_1), digests.get(ContentDigest.SHA_256));
}
Also used : AccessChannel(org.commonjava.indy.model.core.AccessChannel) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ContentDigest(org.commonjava.maven.galley.io.checksum.ContentDigest)

Aggregations

AccessChannel (org.commonjava.indy.model.core.AccessChannel)4 TrackingKey (org.commonjava.indy.folo.model.TrackingKey)3 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)3 Transfer (org.commonjava.maven.galley.model.Transfer)3 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 FoloContentException (org.commonjava.indy.folo.data.FoloContentException)2 StoreEffect (org.commonjava.indy.folo.model.StoreEffect)2 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)2 StoreKey (org.commonjava.indy.model.core.StoreKey)2 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)2 Location (org.commonjava.maven.galley.model.Location)2 ContentDigest (org.commonjava.maven.galley.io.checksum.ContentDigest)1 TransferMetadata (org.commonjava.maven.galley.io.checksum.TransferMetadata)1 TransferOperation (org.commonjava.maven.galley.model.TransferOperation)1