Search in sources :

Example 61 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class IspnNotFoundCache method getMissing.

/**
 * Get missing entries via pagination.
 * @param location
 * @param pageIndex starts from 0
 * @param pageSize how many entries in each page
 * @return
 */
@Override
@Measure
public Set<String> getMissing(Location location, int pageIndex, int pageSize) {
    logger.debug("[NFC] getMissing for {} start, pageIndex: {}, pageSize: {}", location, pageIndex, pageSize);
    Set<String> paths = new HashSet<>();
    pageSize = getProperPageSize(pageSize);
    long offset = pageIndex * pageSize;
    Query query = queryFactory.from(NfcConcreteResourceWrapper.class).startOffset(offset).maxResults(pageSize).orderBy("path").having("location").eq(((KeyedLocation) location).getKey().toString()).toBuilder().build();
    List<NfcConcreteResourceWrapper> matches = query.list();
    matches.forEach(resource -> paths.add(resource.getPath()));
    logger.debug("[NFC] getMissing complete, count: {}", matches.size());
    return paths;
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Query(org.infinispan.query.dsl.Query) StoreKey.fromString(org.commonjava.indy.model.core.StoreKey.fromString) HashSet(java.util.HashSet) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 62 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class IspnNotFoundCache method getAllMissing.

@Override
@Measure
public Map<Location, Set<String>> getAllMissing(int pageIndex, int pageSize) {
    logger.debug("[NFC] getAllMissing start, pageIndex: {}, pageSize: {}", pageIndex, pageSize);
    Map<Location, Set<String>> result = new HashMap<>();
    pageSize = getProperPageSize(pageSize);
    long offset = pageIndex * pageSize;
    Query query = queryFactory.from(NfcConcreteResourceWrapper.class).startOffset(offset).maxResults(pageSize).orderBy("location").orderBy("path").build();
    List<NfcConcreteResourceWrapper> all = query.list();
    for (NfcConcreteResourceWrapper entry : all) {
        String loc = entry.getLocation();
        StoreKey storeKey = fromString(loc);
        Set<String> paths = result.computeIfAbsent(new NfcKeyedLocation(storeKey), k -> new HashSet<>());
        paths.add(entry.getPath());
    }
    logger.debug("[NFC] getAllMissing complete, size: {}", all.size());
    return result;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Query(org.infinispan.query.dsl.Query) HashMap(java.util.HashMap) StoreKey.fromString(org.commonjava.indy.model.core.StoreKey.fromString) StoreKey(org.commonjava.indy.model.core.StoreKey) KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Location(org.commonjava.maven.galley.model.Location) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 63 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class IspnNotFoundCache method getMissing.

@Override
@Measure
public Set<String> getMissing(final Location location) {
    logger.debug("[NFC] getMissing for {} start", location);
    Set<String> paths = new HashSet<>();
    Query query = queryFactory.from(NfcConcreteResourceWrapper.class).maxResults(maxResultSetSize).having("location").eq(((KeyedLocation) location).getKey().toString()).toBuilder().build();
    List<NfcConcreteResourceWrapper> matches = query.list();
    matches.forEach(resource -> paths.add(resource.getPath()));
    logger.debug("[NFC] getMissing complete, count: {}", matches.size());
    return paths;
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) Query(org.infinispan.query.dsl.Query) StoreKey.fromString(org.commonjava.indy.model.core.StoreKey.fromString) HashSet(java.util.HashSet) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 64 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class IspnNotFoundCache method clearMissing.

@Override
@Measure
public void clearMissing(final ConcreteResource resource) {
    String key = getResourceKey(resource);
    nfcCache.execute(cache -> cache.remove(key));
}
Also used : StoreKey.fromString(org.commonjava.indy.model.core.StoreKey.fromString) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 65 with Measure

use of org.commonjava.o11yphant.metrics.annotation.Measure in project indy by Commonjava.

the class CassandraStoreDataManager method affectedBy.

@Override
@Measure
public Set<Group> affectedBy(Collection<StoreKey> keys) throws IndyDataException {
    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)) {
            DtxAffectedStore affectedStore = storeQuery.getAffectedStore(key);
            if (affectedStore == null) {
                processed.add(key);
                continue;
            }
            Set<StoreKey> affected = affectedStore.getAffectedStoreKeys();
            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) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Aggregations

Measure (org.commonjava.o11yphant.metrics.annotation.Measure)65 StoreKey (org.commonjava.indy.model.core.StoreKey)23 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)19 Transfer (org.commonjava.maven.galley.model.Transfer)19 Logger (org.slf4j.Logger)19 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)16 KeyedLocation (org.commonjava.indy.model.galley.KeyedLocation)14 IndyDataException (org.commonjava.indy.data.IndyDataException)13 ArrayList (java.util.ArrayList)12 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)11 HashSet (java.util.HashSet)9 Group (org.commonjava.indy.model.core.Group)8 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)8 BoundStatement (com.datastax.driver.core.BoundStatement)6 StoreDataManager (org.commonjava.indy.data.StoreDataManager)6 StoreKey.fromString (org.commonjava.indy.model.core.StoreKey.fromString)6 Query (org.infinispan.query.dsl.Query)6 IOException (java.io.IOException)5 Set (java.util.Set)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5