Search in sources :

Example 1 with PathDB

use of org.commonjava.storage.pathmapped.spi.PathDB in project indy by Commonjava.

the class PathMappedMavenGACache method scan.

/**
 * Scan the stores to find all GAs.
 * @param notScanned
 * @param gaMap
 * @param completed
 */
private void scan(final Collection<String> notScanned, final Map<String, Set<String>> gaMap, final Set<String> completed) {
    PathDB pathDB = pathMappedFileManager.getPathDB();
    notScanned.forEach(storeName -> {
        Set<String> gaSet = new HashSet<>();
        pathDB.traverse("maven:hosted:" + storeName, ROOT_DIR, pathMap -> {
            String gaPath = getGAPath(pathMap);
            if (isNotBlank(gaPath)) {
                gaSet.add(gaPath);
            }
        }, 0, PathDB.FileType.file);
        gaSet.forEach(ga -> {
            gaMap.computeIfAbsent(ga, k -> new HashSet<>()).add(storeName);
        });
        logger.info("Scan result, store: {}, gaSet: {}", storeName, gaSet);
        completed.add(storeName);
    });
}
Also used : CacheProvider(org.commonjava.maven.galley.spi.cache.CacheProvider) PathMappedFileManager(org.commonjava.storage.pathmapped.core.PathMappedFileManager) Row(com.datastax.driver.core.Row) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Timer(java.util.Timer) MINUTES(java.util.concurrent.TimeUnit.MINUTES) IndyLifecycleException(org.commonjava.indy.action.IndyLifecycleException) ROOT_DIR(org.commonjava.storage.pathmapped.util.PathMapUtils.ROOT_DIR) ArrayList(java.util.ArrayList) PreparedStatement(com.datastax.driver.core.PreparedStatement) Inject(javax.inject.Inject) HashSet(java.util.HashSet) ResultSet(com.datastax.driver.core.ResultSet) Lists(com.google.common.collect.Lists) PathMap(org.commonjava.storage.pathmapped.model.PathMap) BoundStatement(com.datastax.driver.core.BoundStatement) Session(com.datastax.driver.core.Session) CacheProducer(org.commonjava.indy.subsys.infinispan.CacheProducer) Map(java.util.Map) TimerTask(java.util.TimerTask) Path(java.nio.file.Path) PKG_TYPE_MAVEN(org.commonjava.indy.pkg.PackageTypeConstants.PKG_TYPE_MAVEN) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Collections.emptySet(java.util.Collections.emptySet) Collection(java.util.Collection) StoreType(org.commonjava.indy.model.core.StoreType) Set(java.util.Set) PathDB(org.commonjava.storage.pathmapped.spi.PathDB) SchemaUtils.getSchemaCreateKeyspace(org.commonjava.indy.subsys.cassandra.util.SchemaUtils.getSchemaCreateKeyspace) Collectors(java.util.stream.Collectors) CassandraClient(org.commonjava.indy.subsys.cassandra.CassandraClient) CacheHandle(org.commonjava.indy.subsys.infinispan.CacheHandle) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) StartupAction(org.commonjava.indy.action.StartupAction) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) Paths(java.nio.file.Paths) IndyConfiguration(org.commonjava.indy.conf.IndyConfiguration) PostConstruct(javax.annotation.PostConstruct) PathMappedCacheProvider(org.commonjava.maven.galley.cache.pathmapped.PathMappedCacheProvider) ApplicationScoped(javax.enterprise.context.ApplicationScoped) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) PathDB(org.commonjava.storage.pathmapped.spi.PathDB) HashSet(java.util.HashSet)

Example 2 with PathDB

use of org.commonjava.storage.pathmapped.spi.PathDB in project indy by Commonjava.

the class DefaultGalleyStorageProvider method setupCacheProviderFactory.

private void setupCacheProviderFactory() {
    final File storeRoot = config.getStorageRootDirectory();
    if (indyConfiguration.isStandalone()) {
        logger.info("We're in standalone content-storage mode. Cassandra path-mapping database will NOT be used");
        // Only work for local debug mode.
        ScheduledExecutorService debugDeleteExecutor = Executors.newScheduledThreadPool(5, new NamedThreadFactory("debug-galley-delete-executor", new ThreadGroup("debug-galley-delete-executor"), true, 2));
        cacheProviderFactory = new PartyLineCacheProviderFactory(storeRoot, debugDeleteExecutor);
        return;
    }
    logger.info("Initializing Cassandra-based path-mapping database for content storage.");
    PathDB pathDB = null;
    PathMappedStorageConfig pathMappedStorageConfig = getPathMappedStorageConfig();
    if (cassandraClient != null) {
        String keyspace = config.getCassandraKeyspace();
        Session session = cassandraClient.getSession(keyspace);
        if (session != null) {
            logger.info("Create pathDB, keyspace: {}", keyspace);
            pathDB = new CassandraPathDB(pathMappedStorageConfig, session, keyspace, getReplicationFactor());
        }
    }
    if (pathDB != null) {
        if (metricsConfig.isPathDBMetricsEnabled()) {
            final String operations = metricsConfig.getPathDBMetricsOperations();
            logger.info("Create measured PathDB, operations: {}");
            pathDB = new MeasuredPathDB(pathDB, metricsManager, getSupername("pathDB")) {

                @Override
                protected boolean isMetricEnabled(String metricName) {
                    if (isBlank(operations) || operations.contains(metricName)) {
                        return true;
                    }
                    return false;
                }
            };
        }
    }
    File legacyBaseDir = config.getLegacyStorageBasedir();
    PhysicalStore physicalStore = new LegacyReadonlyPhysicalStore(storeRoot, legacyBaseDir);
    logger.info("Create cacheProviderFactory, pathDB: {}, physicalStore: {}", pathDB, physicalStore);
    cacheProviderFactory = new PathMappedCacheProviderFactory(storeRoot, deleteExecutor, pathMappedStorageConfig, pathDB, physicalStore);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) PhysicalStore(org.commonjava.storage.pathmapped.spi.PhysicalStore) NamedThreadFactory(org.commonjava.cdi.util.weft.NamedThreadFactory) DefaultPathMappedStorageConfig(org.commonjava.storage.pathmapped.config.DefaultPathMappedStorageConfig) PathMappedStorageConfig(org.commonjava.storage.pathmapped.config.PathMappedStorageConfig) PathMappedCacheProviderFactory(org.commonjava.maven.galley.cache.pathmapped.PathMappedCacheProviderFactory) CassandraPathDB(org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB) PartyLineCacheProviderFactory(org.commonjava.maven.galley.cache.partyline.PartyLineCacheProviderFactory) MeasuredPathDB(org.commonjava.storage.pathmapped.metrics.MeasuredPathDB) PathDB(org.commonjava.storage.pathmapped.spi.PathDB) CassandraPathDB(org.commonjava.storage.pathmapped.pathdb.datastax.CassandraPathDB) File(java.io.File) MeasuredPathDB(org.commonjava.storage.pathmapped.metrics.MeasuredPathDB) Session(com.datastax.driver.core.Session)

Aggregations

Session (com.datastax.driver.core.Session)2 BoundStatement (com.datastax.driver.core.BoundStatement)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 Lists (com.google.common.collect.Lists)1 File (java.io.File)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.emptySet (java.util.Collections.emptySet)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1