Search in sources :

Example 6 with TransferOperation

use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.

the class IndexingContentManagerDecorator method getTransfer.

@Override
public Transfer getTransfer(final StoreKey storeKey, final String path, final TransferOperation op) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    Transfer transfer = getIndexedTransfer(storeKey, null, path, TransferOperation.DOWNLOAD);
    if (transfer != null) {
        logger.debug("Returning indexed transfer: {}", transfer);
        return transfer;
    }
    ArtifactStore store;
    try {
        store = storeDataManager.getArtifactStore(storeKey);
    } catch (IndyDataException e) {
        throw new IndyWorkflowException("Failed to lookup ArtifactStore: %s for NFC handling. Reason: %s", e, storeKey, e.getMessage());
    }
    ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
    StoreType type = storeKey.getType();
    if (StoreType.group == type) {
        Group g = (Group) store;
        if (g == null) {
            throw new IndyWorkflowException("Cannot find requested group: %s", storeKey);
        }
        if (nfc.isMissing(resource)) {
            logger.debug("NFC / MISSING: {}", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        for (StoreKey key : g.getConstituents()) {
            transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
                try {
                    return delegate.getTransfer(member, path, op);
                } catch (IndyWorkflowException e) {
                    logger.error(String.format("Failed to getTransfer() for member path: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
                }
                return null;
            });
            if (transfer != null) {
                logger.debug("Returning indexed transfer: {} from member: {}", transfer, key);
                return transfer;
            }
        }
    }
    transfer = delegate.getTransfer(storeKey, path, op);
    if (transfer != null) {
        logger.debug("Indexing transfer: {}", transfer);
        indexManager.indexTransferIn(transfer, storeKey);
    }
    return transfer;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 7 with TransferOperation

use of org.commonjava.maven.galley.model.TransferOperation in project indy by Commonjava.

the class IndexingContentManagerDecorator method getTransfer.

@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
    Logger logger = LoggerFactory.getLogger(getClass());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD);
    if (transfer != null) {
        return transfer;
    }
    ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        if (!nfc.isMissing(resource)) {
            logger.debug("No group index hits. Devolving to member store indexes.");
            transfer = getIndexedMemberTransfer((Group) store, path, op, (member) -> {
                try {
                    return delegate.getTransfer(member, path, op);
                } catch (IndyWorkflowException e) {
                    logger.error(String.format("Failed to getTransfer() for: %s:%s with operation: %s. Reason: %s", member.getKey(), path, op, e.getMessage()), e);
                }
                return null;
            });
            if (transfer != null) {
                return transfer;
            }
        } else {
            logger.debug("NFC marks {} as missing. Returning null.", resource);
            return null;
        }
    }
    transfer = delegate.getTransfer(store, path, op);
    // index the transfer only if it exists, it cannot be null at this point
    if (transfer != null && transfer.exists()) {
        indexManager.indexTransferIn(transfer, store.getKey());
    }
    logger.debug("Returning transfer: {}", transfer);
    return transfer;
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) Delegate(javax.decorator.Delegate) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) LoggerFactory(org.slf4j.LoggerFactory) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) Group(org.commonjava.indy.model.core.Group) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) Any(javax.enterprise.inject.Any) Decorator(javax.decorator.Decorator) StoreKey(org.commonjava.indy.model.core.StoreKey) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) NotFoundCache(org.commonjava.maven.galley.spi.nfc.NotFoundCache) ContentManager(org.commonjava.indy.content.ContentManager) Objects(java.util.Objects) List(java.util.List) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) Group(org.commonjava.indy.model.core.Group) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger)

Example 8 with TransferOperation

use of org.commonjava.maven.galley.model.TransferOperation 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

Transfer (org.commonjava.maven.galley.model.Transfer)8 TransferOperation (org.commonjava.maven.galley.model.TransferOperation)8 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)5 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)5 InputStream (java.io.InputStream)4 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 IndyDataException (org.commonjava.indy.data.IndyDataException)3 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)3 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)3 Logger (org.slf4j.Logger)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Decorator (javax.decorator.Decorator)2 Delegate (javax.decorator.Delegate)2 Any (javax.enterprise.inject.Any)2