Search in sources :

Example 26 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class MeasuringStoreQuery method getGroupsAffectedBy.

@Override
public Set<Group> getGroupsAffectedBy(final Collection<StoreKey> keys) throws IndyDataException {
    AtomicReference<IndyDataException> errorRef = new AtomicReference<>();
    Set<Group> result = metricsManager.wrapWithStandardMetrics(() -> {
        try {
            return query.getGroupsAffectedBy(keys);
        } catch (IndyDataException e) {
            errorRef.set(e);
        }
        return null;
    }, () -> "getGroupsAffectedBy-collection");
    IndyDataException error = errorRef.get();
    if (error != null) {
        throw error;
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 27 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class MeasuringStoreQuery method getGroupsContaining.

@Override
public Set<Group> getGroupsContaining(final StoreKey storeKey) throws IndyDataException {
    AtomicReference<IndyDataException> errorRef = new AtomicReference<>();
    Set<Group> result = metricsManager.wrapWithStandardMetrics(() -> {
        try {
            return query.getGroupsContaining(storeKey);
        } catch (IndyDataException e) {
            errorRef.set(e);
        }
        return null;
    }, () -> "getGroupsContaining");
    IndyDataException error = errorRef.get();
    if (error != null) {
        throw error;
    }
    return result;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 28 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class InfinispanStoreDataManager method affectedBy.

@Override
public Set<Group> affectedBy(final Collection<StoreKey> keys) {
    logger.debug("Calculate affectedBy for keys: {}", keys);
    checkAffectedByCacheHealth();
    final Set<Group> result = new HashSet<>();
    // use these to avoid recursion
    final Set<StoreKey> processed = new HashSet<>();
    final LinkedList<StoreKey> toProcess = new LinkedList<>(keys);
    while (!toProcess.isEmpty()) {
        StoreKey key = toProcess.removeFirst();
        if (key == null) {
            continue;
        }
        if (processed.add(key)) {
            Set<StoreKey> affected = affectedByStores.get(key);
            if (affected != null) {
                logger.debug("Get affectedByStores, key: {}, affected: {}", key, affected);
                affected = affected.stream().filter(k -> k.getType() == group).collect(Collectors.toSet());
                for (StoreKey gKey : affected) {
                    // avoid loading the ArtifactStore instance again and again
                    if (!processed.contains(gKey) && !toProcess.contains(gKey)) {
                        ArtifactStore store = getArtifactStoreInternal(gKey);
                        // if this group is disabled, we don't want to keep loading it again and again.
                        if (store.isDisabled()) {
                            processed.add(gKey);
                        } else {
                            // add the group to the toProcess list so we can find any result that might include it in their own membership
                            toProcess.addLast(gKey);
                            result.add((Group) store);
                        }
                    }
                }
            }
        }
    }
    if (logger.isTraceEnabled()) {
        logger.trace("Groups affected by {} are: {}", keys, result.stream().map(ArtifactStore::getKey).collect(Collectors.toSet()));
    }
    return filterAffectedGroups(result);
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

Example 29 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class ConcurrencyTest method deadlockOnGroupContains.

@BMRules(rules = { @BMRule(name = "init rendezvous", targetClass = "MemoryStoreDataManager", targetMethod = "<init>", targetLocation = "ENTRY", action = "createRendezvous($0, 2, true)"), @BMRule(name = "getGroupsContaining call", targetClass = "MemoryStoreDataManager", targetMethod = "getGroupsContaining", targetLocation = "ENTRY", action = "rendezvous($0); debug(Thread.currentThread().getName() + \": thread proceeding.\")") })
@Test
public void deadlockOnGroupContains() throws IndyDataException, InterruptedException, ExecutionException {
    ExecutorService executor = Executors.newFixedThreadPool(2);
    ExecutorCompletionService<String> completionService = new ExecutorCompletionService<>(executor);
    AtomicInteger count = new AtomicInteger(0);
    RemoteRepository repo = new RemoteRepository(MAVEN_PKG_KEY, "central", "http://repo.maven.apache.org/maven2");
    TestUpdatingEventDispatcher dispatcher = new TestUpdatingEventDispatcher(repo, completionService, count);
    MemoryStoreDataManager dataManager = new MemoryStoreDataManager(dispatcher);
    dispatcher.setDataManager(dataManager);
    ChangeSummary summary = new ChangeSummary(ChangeSummary.SYSTEM_USER, "Test init");
    dataManager.storeArtifactStore(repo, summary, false, false, new EventMetadata());
    for (int i = 0; i < 2; i++) {
        Group group = new Group(MAVEN_PKG_KEY, "group" + i);
        if (i % 2 == 0) {
            group.addConstituent(repo);
        }
        dataManager.storeArtifactStore(group, summary, false, false, new EventMetadata());
    }
    for (int i = 0; i < count.get(); i++) {
        Future<String> future = completionService.take();
        assertThat(future.get(), nullValue());
    }
}
Also used : Group(org.commonjava.indy.model.core.Group) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) ChangeSummary(org.commonjava.indy.audit.ChangeSummary) Test(org.junit.Test) BMRules(org.jboss.byteman.contrib.bmunit.BMRules)

Example 30 with Group

use of org.commonjava.indy.model.core.Group in project indy by Commonjava.

the class IndexingContentManagerDecorator method retrieve.

@Override
public Transfer retrieve(final ArtifactStore store, final String path, final EventMetadata eventMetadata) throws IndyWorkflowException {
    if (!indexCfg.isEnabled()) {
        return delegate.retrieve(store, path, eventMetadata);
    }
    if (store == null) {
        return null;
    }
    logger.trace("Looking for indexed path: {} in: {}", path, store.getKey());
    Transfer transfer = getIndexedTransfer(store.getKey(), null, path, TransferOperation.DOWNLOAD, eventMetadata);
    if (transfer != null) {
        logger.debug("Found indexed transfer: {}. Returning.", transfer);
        return transfer;
    } else if (isAuthoritativelyMissing(store)) {
        logger.debug("Not found indexed transfer: {} and authoritative index switched on. Considering not found and return null.", transfer);
        return null;
    }
    StoreType type = store.getKey().getType();
    if (StoreType.group == type) {
        ConcreteResource resource = new ConcreteResource(LocationUtils.toLocation(store), path);
        if (nfc.isMissing(resource)) {
            logger.debug("{} is marked as missing. Returning null.", resource);
            return null;
        }
        logger.debug("No group index hits. Devolving to member store indexes.");
        KeyedLocation location = LocationUtils.toLocation(store);
        SpecialPathInfo specialPathInfo = specialPathManager.getSpecialPathInfo(location, path, store.getPackageType());
        if (specialPathInfo == null || !specialPathInfo.isMergable()) {
            if (PathMaskChecker.checkMask(store, path)) {
                transfer = getTransferFromConstituents(((Group) store).getConstituents(), resource, path, store, memberKey -> {
                    try {
                        ArtifactStore member = storeDataManager.getArtifactStore(memberKey);
                        if (member == null) {
                            logger.trace("Cannot find store for key: {}", memberKey);
                        } else {
                            return retrieve(member, path, eventMetadata);
                        }
                    } catch (IndyDataException e) {
                        logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", memberKey, store.getKey(), e.getMessage()), e);
                    }
                    return null;
                });
                nfcForGroup(store, transfer, resource);
                return transfer;
            } else {
                return null;
            }
        } else {
            logger.debug("Merged content. Delegating to main content manager for: {} in: {}", path, store);
            transfer = delegate.retrieve(store, path, eventMetadata);
            if (!exists(transfer)) {
                Boolean metadataGenerated = (Boolean) eventMetadata.get(GROUP_METADATA_GENERATED);
                Boolean metadataExists = (Boolean) eventMetadata.get(GROUP_METADATA_EXISTS);
                if (Boolean.TRUE.equals(metadataGenerated) || Boolean.TRUE.equals(metadataExists)) {
                    // metadata generated/exists but missing due to membership change, not add to nfc so next req can retry
                    ;
                } else // don't track NFC for hosted repos
                {
                    nfc.addMissing(resource);
                }
            }
            return transfer;
        }
    }
    logger.trace("Delegating retrieve call for concrete repository: {}/{}", store, path);
    transfer = delegate.retrieve(store, path, eventMetadata);
    if (exists(transfer) && indexCfg.isEnabled()) {
        logger.debug("Got transfer from delegate: {} (will index)", transfer);
        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) Arrays(java.util.Arrays) 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) GROUP_METADATA_GENERATED(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_GENERATED) Inject(javax.inject.Inject) HashSet(java.util.HashSet) Transfer(org.commonjava.maven.galley.model.Transfer) Measure(org.commonjava.o11yphant.metrics.annotation.Measure) 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) GROUP_METADATA_EXISTS(org.commonjava.indy.core.content.group.GroupMergeHelper.GROUP_METADATA_EXISTS) LocationUtils(org.commonjava.indy.util.LocationUtils) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Logger(org.slf4j.Logger) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Executor(java.util.concurrent.Executor) PathMaskChecker(org.commonjava.indy.core.content.PathMaskChecker) Collection(java.util.Collection) 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) HostedRepository(org.commonjava.indy.model.core.HostedRepository) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ContentIndexConfig(org.commonjava.indy.content.index.conf.ContentIndexConfig) IndyDataException(org.commonjava.indy.data.IndyDataException) StoreDataManager(org.commonjava.indy.data.StoreDataManager) InputStream(java.io.InputStream) IndyDataException(org.commonjava.indy.data.IndyDataException) Group(org.commonjava.indy.model.core.Group) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) SpecialPathInfo(org.commonjava.maven.galley.model.SpecialPathInfo) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource)

Aggregations

Group (org.commonjava.indy.model.core.Group)211 Test (org.junit.Test)111 HostedRepository (org.commonjava.indy.model.core.HostedRepository)89 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)82 StoreKey (org.commonjava.indy.model.core.StoreKey)76 ByteArrayInputStream (java.io.ByteArrayInputStream)67 InputStream (java.io.InputStream)62 IndyDataException (org.commonjava.indy.data.IndyDataException)44 AbstractContentManagementTest (org.commonjava.indy.ftest.core.AbstractContentManagementTest)42 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)42 Transfer (org.commonjava.maven.galley.model.Transfer)31 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)30 Logger (org.slf4j.Logger)30 Before (org.junit.Before)29 StoreDataManager (org.commonjava.indy.data.StoreDataManager)27 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)27 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)25 List (java.util.List)22 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)22