Search in sources :

Example 91 with ArtifactStore

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

the class MemoryArtifactStoreQuery method recurseGroup.

private void recurseGroup(final Group master, final Map<StoreKey, ArtifactStore> stores, final List<ArtifactStore> result, final Set<StoreKey> seen, final boolean includeGroups, final boolean recurseGroups) {
    if (master == null || master.isDisabled() && enabled) {
        return;
    }
    List<StoreKey> members = new ArrayList<>(master.getConstituents());
    if (includeGroups) {
        result.add(master);
    }
    members.forEach((key) -> {
        if (!seen.contains(key)) {
            seen.add(key);
            final StoreType type = key.getType();
            if (recurseGroups && type == StoreType.group) {
                // if we're here, we're definitely recursing groups...
                recurseGroup((Group) stores.get(key), stores, result, seen, includeGroups, true);
            } else {
                final ArtifactStore store = stores.get(key);
                if (store != null && !(store.isDisabled() && enabled)) {
                    result.add(store);
                }
            }
        }
    });
}
Also used : StoreType(org.commonjava.indy.model.core.StoreType) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 92 with ArtifactStore

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

the class MemoryArtifactStoreQuery method getGroupsAffectedBy.

@Override
public Set<Group> getGroupsAffectedBy(Collection<StoreKey> keys) throws IndyDataException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.debug("Getting groups affected by: {}", keys);
    List<StoreKey> toProcess = new ArrayList<>();
    toProcess.addAll(keys.stream().collect(Collectors.toSet()));
    Set<Group> groups = new HashSet<>();
    if (toProcess.isEmpty()) {
        return groups;
    }
    Set<StoreKey> processed = new HashSet<>();
    Set<Group> all = new MemoryArtifactStoreQuery<Group>(dataManager, toProcess.get(0).getPackageType(), null, Group.class).stream().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 (!processed.contains(store.getKey()) && (store instanceof Group)) {
                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 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 93 with ArtifactStore

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

the class MemoryStoreDataManager method store.

private boolean store(final ArtifactStore store, final ChangeSummary summary, final boolean skipIfExists, final boolean fireEvents, final EventMetadata eventMetadata) throws IndyDataException {
    ReentrantLock opLock = getOpLock(store.getKey());
    try {
        opLock.lock();
        ArtifactStore original = stores.get(store.getKey());
        if (original == store) {
            // if they're the same instance, warn that preUpdate events may not work correctly!
            logger.warn("Storing changes on existing instance of: {}! You forgot to call {}.copyOf(), so preUpdate events may not accurately reflect before/after differences for this change!", store, store.getClass().getSimpleName());
        }
        if (!skipIfExists || original == null) {
            preStore(store, original, summary, original != null, fireEvents, eventMetadata);
            final ArtifactStore old = stores.put(store.getKey(), store);
            try {
                postStore(store, original, summary, original != null, fireEvents, eventMetadata);
                return true;
            } catch (final IndyDataException e) {
                logger.error("postStore() failed for: {}. Rolling back to old value: {}", store, old);
                stores.put(old.getKey(), old);
            }
        }
        return false;
    } finally {
        opLock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore)

Aggregations

ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)93 IndyDataException (org.commonjava.indy.data.IndyDataException)54 StoreKey (org.commonjava.indy.model.core.StoreKey)46 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)35 Logger (org.slf4j.Logger)30 ArrayList (java.util.ArrayList)25 Transfer (org.commonjava.maven.galley.model.Transfer)25 Group (org.commonjava.indy.model.core.Group)20 StoreType (org.commonjava.indy.model.core.StoreType)19 IOException (java.io.IOException)18 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)17 HashSet (java.util.HashSet)15 List (java.util.List)15 LoggerFactory (org.slf4j.LoggerFactory)11 Inject (javax.inject.Inject)10 StoreDataManager (org.commonjava.indy.data.StoreDataManager)10 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)10 JoinString (org.commonjava.maven.atlas.ident.util.JoinString)10 Test (org.junit.Test)9 ApiOperation (io.swagger.annotations.ApiOperation)8