Search in sources :

Example 16 with ArtifactStore

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

the class AbstractStoreDataManager method affectedByFromStores.

protected Set<Group> affectedByFromStores(final Collection<StoreKey> keys) {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Getting groups affected by: {}", keys);
    List<StoreKey> toProcess = new ArrayList<>(new HashSet<>(keys));
    Set<Group> groups = new HashSet<>();
    if (toProcess.isEmpty()) {
        return groups;
    }
    Set<StoreKey> processed = new HashSet<>();
    final String packageType = toProcess.get(0).getPackageType();
    Set<ArtifactStore> all = this.getStoreKeysByPkgAndType(packageType, group).stream().map(this::getArtifactStoreInternal).filter(Objects::nonNull).collect(Collectors.toSet());
    while (!toProcess.isEmpty()) {
        // as long as we have another key to process, pop it off the list (remove it) and process it.
        StoreKey next = toProcess.remove(0);
        if (processed.contains(next)) {
            // if we've already handled this group (via another branch in the group membership tree, etc. then don't bother.
            continue;
        }
        // use this to avoid reprocessing groups we've already encountered.
        processed.add(next);
        for (ArtifactStore store : all) {
            if ((store instanceof Group) && !processed.contains(store.getKey())) {
                Group g = (Group) store;
                if (g.getConstituents() != null && g.getConstituents().contains(next)) {
                    groups.add(g);
                    // add this group as another one to process for groups that contain it...and recurse upwards
                    toProcess.add(g.getKey());
                }
            }
        }
    }
    return filterAffectedGroups(groups);
}
Also used : Group(org.commonjava.indy.model.core.Group) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet)

Example 17 with ArtifactStore

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

the class MeasuringStoreQuery method getOrderedConcreteStoresInGroup.

@Override
public List<ArtifactStore> getOrderedConcreteStoresInGroup(final String packageType, final String groupName, final Boolean enabled) throws IndyDataException {
    logger.trace("START: metric store-query wrapper ordered-concrete-stores-in-group");
    try {
        AtomicReference<IndyDataException> errorRef = new AtomicReference<>();
        List<ArtifactStore> result = metricsManager.wrapWithStandardMetrics(() -> {
            try {
                return query.getOrderedConcreteStoresInGroup(packageType, groupName, enabled);
            } catch (IndyDataException e) {
                errorRef.set(e);
            }
            return null;
        }, () -> "getOrderedConcreteStoresInGroup");
        IndyDataException error = errorRef.get();
        if (error != null) {
            throw error;
        }
        return result;
    } finally {
        logger.trace("END: metric store-query wrapper ordered-concrete-stores-in-group");
    }
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 18 with ArtifactStore

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

the class MeasuringStoreQuery method getOrderedStoresInGroup.

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

Example 19 with ArtifactStore

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

the class InfinispanStoreDataManager method initByPkgMap.

public void initByPkgMap() {
    // re-fill the stores by package cache each time when reboot
    if (storesByPkg != null) {
        logger.info("Clean the stores-by-pkg cache");
        storesByPkg.clear();
    }
    final Set<ArtifactStore> allStores = getAllArtifactStores();
    logger.info("There are {} stores need to fill in stores-by-pkg cache", allStores.size());
    for (ArtifactStore store : allStores) {
        final Map<StoreType, Set<StoreKey>> typedKeys = storesByPkg.computeIfAbsent(store.getKey().getPackageType(), k -> new HashMap<>());
        final Set<StoreKey> keys = typedKeys.computeIfAbsent(store.getKey().getType(), k -> new HashSet<>());
        keys.add(store.getKey());
    }
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) HashSet(java.util.HashSet) Set(java.util.Set) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 20 with ArtifactStore

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

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)168 IndyDataException (org.commonjava.indy.data.IndyDataException)90 StoreKey (org.commonjava.indy.model.core.StoreKey)83 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)54 Logger (org.slf4j.Logger)45 ArrayList (java.util.ArrayList)43 Group (org.commonjava.indy.model.core.Group)42 StoreType (org.commonjava.indy.model.core.StoreType)38 Transfer (org.commonjava.maven.galley.model.Transfer)38 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)33 IOException (java.io.IOException)29 HashSet (java.util.HashSet)29 List (java.util.List)28 Measure (org.commonjava.o11yphant.metrics.annotation.Measure)26 LoggerFactory (org.slf4j.LoggerFactory)25 StoreDataManager (org.commonjava.indy.data.StoreDataManager)24 Set (java.util.Set)23 Inject (javax.inject.Inject)22 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)17