Search in sources :

Example 1 with Default

use of javax.enterprise.inject.Default in project indy by Commonjava.

the class ProxyConfigProvider method getStorageProviderConfiguration.

@Produces
@TestData
@Default
public synchronized DefaultStorageProviderConfiguration getStorageProviderConfiguration() throws IOException {
    if (storageConfig == null) {
        final String path = System.getProperty(REPO_ROOT_DIR);
        File dir;
        if (path == null) {
            dir = File.createTempFile("repo.root", ".dir");
            dir.delete();
            dir.mkdirs();
        } else {
            dir = new File(path);
        }
        storageConfig = new DefaultStorageProviderConfiguration(dir);
    }
    return storageConfig;
}
Also used : DefaultStorageProviderConfiguration(org.commonjava.indy.filer.def.conf.DefaultStorageProviderConfiguration) File(java.io.File) TestData(org.commonjava.indy.inject.TestData) Produces(javax.enterprise.inject.Produces) Default(javax.enterprise.inject.Default)

Example 2 with Default

use of javax.enterprise.inject.Default 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

File (java.io.File)2 Default (javax.enterprise.inject.Default)2 Produces (javax.enterprise.inject.Produces)2 DefaultStorageProviderConfiguration (org.commonjava.indy.filer.def.conf.DefaultStorageProviderConfiguration)2 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 ExecutorService (java.util.concurrent.ExecutorService)1 PostConstruct (javax.annotation.PostConstruct)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Instance (javax.enterprise.inject.Instance)1 BeanManager (javax.enterprise.inject.spi.BeanManager)1 CDI (javax.enterprise.inject.spi.CDI)1 Inject (javax.inject.Inject)1 ExecutorConfig (org.commonjava.cdi.util.weft.ExecutorConfig)1 WeftManaged (org.commonjava.cdi.util.weft.WeftManaged)1 IndyChecksumAdvisor (org.commonjava.indy.content.IndyChecksumAdvisor)1 TestData (org.commonjava.indy.inject.TestData)1 StoreType.hosted (org.commonjava.indy.model.core.StoreType.hosted)1 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)1