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);
}
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");
}
}
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;
}
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());
}
}
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);
}
Aggregations