Search in sources :

Example 16 with KeyedLocation

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

the class DefaultContentManager method getTransfer.

@Override
public Transfer getTransfer(final ArtifactStore store, final String path, final TransferOperation op) throws IndyWorkflowException {
    logger.debug("Getting transfer for: {}/{} (op: {})", store.getKey(), path, op);
    if (group == store.getKey().getType()) {
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo spInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (spInfo == null || !spInfo.isMergable()) {
            try {
                final List<ArtifactStore> allMembers = storeManager.query().packageType(store.getPackageType()).enabledState(true).getOrderedConcreteStoresInGroup(store.getName());
                logger.debug("Trying to retrieve suitable transfer for: {} in group: {} members:\n{}", path, store.getName(), allMembers);
                return getTransfer(allMembers, path, op);
            } catch (final IndyDataException e) {
                throw new IndyWorkflowException("Failed to lookup concrete members of: %s. Reason: %s", e, store, e.getMessage());
            }
        } else {
            logger.debug("Detected mergable special path: {}/{}.", store.getKey(), path);
        }
    }
    logger.debug("Retrieving storage reference (Transfer) directly for: {}/{}", store.getKey(), path);
    return downloadManager.getStorageReference(store, path, op);
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException)

Example 17 with KeyedLocation

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

the class FoloTrackingListener method onFileAccess.

public void onFileAccess(@Observes final FileAccessEvent event) {
    logger.debug("FILE ACCESS: {}", event);
    EventMetadata metadata = event.getEventMetadata();
    final TrackingKey trackingKey = (TrackingKey) metadata.get(FoloConstants.TRACKING_KEY);
    if (trackingKey == null) {
        logger.info("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.info("No transfer: {}", event);
        return;
    }
    final Location location = transfer.getLocation();
    if (!(location instanceof KeyedLocation)) {
        logger.info("Not in a keyed location: {}", event.getTransfer());
        return;
    }
    try {
        final KeyedLocation keyedLocation = (KeyedLocation) location;
        if (!foloConfig.isGroupContentTracked() && keyedLocation.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.getKey());
            return;
        }
        logger.debug("Tracking report: {} += {} in {} (DOWNLOAD)", trackingKey, transfer.getPath(), keyedLocation.getKey());
        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 18 with KeyedLocation

use of org.commonjava.indy.model.galley.KeyedLocation 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)

Example 19 with KeyedLocation

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

the class DefaultGalleyStorageProvider method setup.

@PostConstruct
public void setup() {
    SpecialPathInfo infoSpi = SpecialPathInfo.from(new FilePatternMatcher(".+\\.info")).setDecoratable(false).setDeletable(false).setListable(false).setPublishable(false).setRetrievable(false).setStorable(false).build();
    specialPathManager.registerSpecialPathInfo(infoSpi);
    ChecksummingDecoratorAdvisor readAdvisor = (transfer, op, eventMetadata) -> {
        ChecksummingDecoratorAdvisor.ChecksumAdvice result = NO_DECORATE;
        if (checksumAdvisors != null) {
            for (IndyChecksumAdvisor advisor : checksumAdvisors) {
                Optional<ChecksummingDecoratorAdvisor.ChecksumAdvice> advice = advisor.getChecksumReadAdvice(transfer, op, eventMetadata);
                if (advice.isPresent()) {
                    ChecksummingDecoratorAdvisor.ChecksumAdvice checksumAdvice = advice.get();
                    if (checksumAdvice.ordinal() > result.ordinal()) {
                        result = checksumAdvice;
                        if (checksumAdvice == CALCULATE_AND_WRITE) {
                            break;
                        }
                    }
                }
            }
        }
        logger.debug("Advising {} for {} of: {}", result, op, transfer);
        return result;
    };
    ChecksummingDecoratorAdvisor writeAdvisor = (transfer, op, eventMetadata) -> {
        ChecksummingDecoratorAdvisor.ChecksumAdvice result = NO_DECORATE;
        if (TransferOperation.GENERATE == op) {
            result = CALCULATE_AND_WRITE;
        } else if (checksumAdvisors != null) {
            for (IndyChecksumAdvisor advisor : checksumAdvisors) {
                Optional<ChecksummingDecoratorAdvisor.ChecksumAdvice> advice = advisor.getChecksumWriteAdvice(transfer, op, eventMetadata);
                if (advice.isPresent()) {
                    ChecksummingDecoratorAdvisor.ChecksumAdvice checksumAdvice = advice.get();
                    if (checksumAdvice.ordinal() > result.ordinal()) {
                        result = checksumAdvice;
                        if (checksumAdvice == CALCULATE_AND_WRITE) {
                            break;
                        }
                    }
                }
            }
        }
        logger.debug("Advising {} for {} of: {}", result, op, transfer);
        return result;
    };
    transferDecorator = new TransferDecoratorPipeline(new ChecksummingTransferDecorator(readAdvisor, writeAdvisor, specialPathManager, contentMetadataConsumer, new Md5GeneratorFactory(), new Sha1GeneratorFactory(), new Sha256GeneratorFactory()), new ContentsFilteringTransferDecorator(), new NoCacheTransferDecorator(specialPathManager));
    final File storeRoot = config.getStorageRootDirectory();
    cacheProviderFactory = new PartyLineCacheProviderFactory(storeRoot);
    final File nfsBasedir = config.getNFSStorageRootDirectory();
    if (nfsBasedir != null) {
        if (!nfsBasedir.exists()) {
            nfsBasedir.mkdirs();
        }
        // nfs root can not be created due to some security reason(like permission), will bypass FastLocal provider and use PartyLine
        if (nfsBasedir.exists()) {
            final FastLocalCacheProviderFactory fastLocalFac = new FastLocalCacheProviderFactory(storeRoot, nfsBasedir, new CacheInstanceAdapter(nfsOwnerCache), fastLocalExecutors);
            cacheProviderFactory = new RoutingCacheProviderFactory((resource) -> {
                if (resource != null) {
                    final Location loc = resource.getLocation();
                    // looking for KeyedLocation and StoreType.hosted should be faster than regex on the URI.
                    return ((loc instanceof KeyedLocation) && hosted == ((KeyedLocation) loc).getKey().getType());
                }
                return false;
            }, fastLocalFac, cacheProviderFactory);
        } else {
            logger.warn("[Indy] nfs base dir {} can not be created correctly due to some unknown reasons, will use partyline cache provider as default", nfsBasedir);
        }
    }
    // TODO: Tie this into a config file!
    transportManagerConfig = new TransportManagerConfig();
}
Also used : TransportManagerConfig(org.commonjava.maven.galley.config.TransportManagerConfig) Produces(javax.enterprise.inject.Produces) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) CALCULATE_AND_WRITE(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor.ChecksumAdvice.CALCULATE_AND_WRITE) GalleyInitException(org.commonjava.maven.galley.GalleyInitException) LoggerFactory(org.slf4j.LoggerFactory) PathGenerator(org.commonjava.maven.galley.spi.io.PathGenerator) ContentsFilteringTransferDecorator(org.commonjava.maven.galley.transport.htcli.ContentsFilteringTransferDecorator) FilePatternMatcher(org.commonjava.maven.galley.model.FilePatternMatcher) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) IndyChecksumAdvisor(org.commonjava.indy.content.IndyChecksumAdvisor) RoutingCacheProviderFactory(org.commonjava.maven.galley.cache.routes.RoutingCacheProviderFactory) Inject(javax.inject.Inject) DefaultStorageProviderConfiguration(org.commonjava.indy.filer.def.conf.DefaultStorageProviderConfiguration) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) WeftManaged(org.commonjava.cdi.util.weft.WeftManaged) ExecutorConfig(org.commonjava.cdi.util.weft.ExecutorConfig) TransferOperation(org.commonjava.maven.galley.model.TransferOperation) NO_DECORATE(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor.ChecksumAdvice.NO_DECORATE) TransferMetadataConsumer(org.commonjava.maven.galley.io.checksum.TransferMetadataConsumer) Sha256GeneratorFactory(org.commonjava.maven.galley.io.checksum.Sha256GeneratorFactory) Location(org.commonjava.maven.galley.model.Location) Instance(javax.enterprise.inject.Instance) ExecutorService(java.util.concurrent.ExecutorService) ChecksummingDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor) Default(javax.enterprise.inject.Default) Logger(org.slf4j.Logger) NoCacheTransferDecorator(org.commonjava.maven.galley.io.NoCacheTransferDecorator) PartyLineCacheProviderFactory(org.commonjava.maven.galley.cache.partyline.PartyLineCacheProviderFactory) FastLocalCacheProviderFactory(org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProviderFactory) Collection(java.util.Collection) CDI(javax.enterprise.inject.spi.CDI) SpecialPathManager(org.commonjava.maven.galley.spi.io.SpecialPathManager) CacheHandle(org.commonjava.indy.subsys.infinispan.CacheHandle) File(java.io.File) CacheProviderFactory(org.commonjava.maven.galley.cache.CacheProviderFactory) TransferDecoratorPipeline(org.commonjava.maven.galley.io.TransferDecoratorPipeline) Sha1GeneratorFactory(org.commonjava.maven.galley.io.checksum.Sha1GeneratorFactory) TransferDecorator(org.commonjava.maven.galley.spi.io.TransferDecorator) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) ApplicationScoped(javax.enterprise.context.ApplicationScoped) StoreType.hosted(org.commonjava.indy.model.core.StoreType.hosted) FileEventManager(org.commonjava.maven.galley.spi.event.FileEventManager) Collections(java.util.Collections) Md5GeneratorFactory(org.commonjava.maven.galley.io.checksum.Md5GeneratorFactory) BeanManager(javax.enterprise.inject.spi.BeanManager) IndyChecksumAdvisor(org.commonjava.indy.content.IndyChecksumAdvisor) FastLocalCacheProviderFactory(org.commonjava.maven.galley.cache.infinispan.FastLocalCacheProviderFactory) Sha1GeneratorFactory(org.commonjava.maven.galley.io.checksum.Sha1GeneratorFactory) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) ChecksummingDecoratorAdvisor(org.commonjava.maven.galley.io.checksum.ChecksummingDecoratorAdvisor) Optional(java.util.Optional) NoCacheTransferDecorator(org.commonjava.maven.galley.io.NoCacheTransferDecorator) TransportManagerConfig(org.commonjava.maven.galley.config.TransportManagerConfig) ContentsFilteringTransferDecorator(org.commonjava.maven.galley.transport.htcli.ContentsFilteringTransferDecorator) PartyLineCacheProviderFactory(org.commonjava.maven.galley.cache.partyline.PartyLineCacheProviderFactory) FilePatternMatcher(org.commonjava.maven.galley.model.FilePatternMatcher) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) TransferDecoratorPipeline(org.commonjava.maven.galley.io.TransferDecoratorPipeline) RoutingCacheProviderFactory(org.commonjava.maven.galley.cache.routes.RoutingCacheProviderFactory) ChecksummingTransferDecorator(org.commonjava.maven.galley.io.ChecksummingTransferDecorator) Sha256GeneratorFactory(org.commonjava.maven.galley.io.checksum.Sha256GeneratorFactory) File(java.io.File) Md5GeneratorFactory(org.commonjava.maven.galley.io.checksum.Md5GeneratorFactory) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location) PostConstruct(javax.annotation.PostConstruct)

Aggregations

KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)11 Location (org.commonjava.maven.galley.model.Location)10 ArrayList (java.util.ArrayList)7 IndyDataException (org.commonjava.indy.data.IndyDataException)7 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)6 Transfer (org.commonjava.maven.galley.model.Transfer)6 StoreResource (org.commonjava.indy.content.StoreResource)5 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)5 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)4 StoreKey (org.commonjava.indy.model.core.StoreKey)4 TransferException (org.commonjava.maven.galley.TransferException)4 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)4 ListingResult (org.commonjava.maven.galley.model.ListingResult)4 Set (java.util.Set)3 IndyStoreErrorEvent (org.commonjava.indy.change.event.IndyStoreErrorEvent)3 File (java.io.File)2 HashSet (java.util.HashSet)2 Inject (javax.inject.Inject)2 ContentGenerator (org.commonjava.indy.content.ContentGenerator)2