Search in sources :

Example 1 with StoreEffect

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

the class FoloTrackingListener method onFileUpload.

public void onFileUpload(@Observes final FileStorageEvent event) {
    logger.debug("FILE STORAGE: {}", event);
    if (TransferOperation.UPLOAD != event.getType()) {
        logger.debug("Not a file upload from client; skipping tracking of storage");
        return;
    }
    EventMetadata metadata = event.getEventMetadata();
    final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
    if (trackingKey == null) {
        logger.info("No tracking key. Not recording.");
        return;
    }
    final AccessChannel accessChannel = (AccessChannel) metadata.get(FoloConstants.ACCESS_CHANNEL);
    final Transfer transfer = event.getTransfer();
    if (transfer == null) {
        logger.info("No transfer. Not recording.");
        return;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        logger.info("Invalid transfer source location: {}. Not recording.", location);
        return;
    } else if (!foloConfig.isGroupContentTracked() && ((KeyedLocation) location).getKey().getType() == group) {
        logger.debug("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.debug("Ignoring transfer operation: {} for: {}", op, transfer);
                return;
            }
    }
    try {
        final KeyedLocation keyedLocation = (KeyedLocation) location;
        logger.debug("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)

Aggregations

IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)1 FoloContentException (org.commonjava.indy.folo.data.FoloContentException)1 StoreEffect (org.commonjava.indy.folo.model.StoreEffect)1 TrackingKey (org.commonjava.indy.folo.model.TrackingKey)1 AccessChannel (org.commonjava.indy.model.core.AccessChannel)1 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 Location (org.commonjava.maven.galley.model.Location)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 TransferOperation (org.commonjava.maven.galley.model.TransferOperation)1