Search in sources :

Example 6 with Measure

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

the class DefaultContentIndexManager method getIndexedStoreKey.

@Override
@Measure
public StoreKey getIndexedStoreKey(final StoreKey key, final String rawPath) {
    if (!config.isEnabled()) {
        logger.debug("Content indexing is disabled.");
        return null;
    }
    String path = getStrategyPath(key, rawPath);
    IndexedStorePath ispKey = new IndexedStorePath(key, path);
    IndexedStorePath val = contentIndex.get(ispKey);
    logger.trace("Get index{}, key: {}", (val == null ? " (NOT FOUND)" : ""), ispKey);
    if (val == null) {
        return null;
    }
    StoreKey ret = val.getOriginStoreKey();
    if (ret == null) {
        // for self-to-self index
        ret = val.getStoreKey();
    }
    return ret;
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 7 with Measure

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

the class CassandraNotFoundCache method addMissing.

@Override
@Measure
public void addMissing(final ConcreteResource resource) {
    KeyedLocation location = (KeyedLocation) resource.getLocation();
    StoreKey key = location.getKey();
    int timeoutInSeconds = DEFAULT_NOT_FOUND_CACHE_TIMEOUT_SECONDS;
    int t = getTimeoutInSeconds(resource);
    if (t > 0) {
        timeoutInSeconds = t;
    }
    Date curDate = new Date();
    Date timeoutDate = new Date(curDate.getTime() + (timeoutInSeconds * 1000));
    logger.debug("[NFC] {} will not be checked again until {}", resource, new SimpleDateFormat(TIMEOUT_FORMAT).format(timeoutDate));
    BoundStatement bound = preparedInsert.bind(key.toString(), resource.getPath(), curDate, timeoutDate, timeoutInSeconds);
    session.execute(bound);
    inMemoryCache.put(resource, DUMB_CACHE_VALUE, timeoutInSeconds, TimeUnit.SECONDS);
}
Also used : KeyedLocation(org.commonjava.indy.model.galley.KeyedLocation) StoreKey(org.commonjava.indy.model.core.StoreKey) SimpleDateFormat(java.text.SimpleDateFormat) BoundStatement(com.datastax.driver.core.BoundStatement) Date(java.util.Date) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 8 with Measure

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

the class CassandraNotFoundCache method isMissing.

@Override
@Measure
public boolean isMissing(final ConcreteResource resource) {
    if (inMemoryCache.get(resource) != null) {
        return true;
    }
    StoreKey key = getResourceKey(resource);
    BoundStatement bound = preparedExistQuery.bind(key.toString(), resource.getPath());
    ResultSet result = session.execute(bound);
    Row row = result.one();
    if (row == null) {
        return false;
    }
    Date expiration = row.get(0, Date.class);
    boolean missing = true;
    logger.trace("NFC check: {}, missing: {}", resource, missing);
    if (missing) {
        long timeout = expiration.getTime() - System.currentTimeMillis();
        if (timeout > 1000) {
            inMemoryCache.put(resource, DUMB_CACHE_VALUE, new Long(timeout / 1000).intValue(), TimeUnit.SECONDS);
        }
    }
    return missing;
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) StoreKey(org.commonjava.indy.model.core.StoreKey) BoundStatement(com.datastax.driver.core.BoundStatement) Date(java.util.Date) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 9 with Measure

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

the class CassandraNotFoundCache method getSize.

@Override
@Measure
public long getSize(StoreKey storeKey) {
    BoundStatement bound = preparedCountByStore.bind(storeKey.toString());
    ResultSet result = session.execute(bound);
    return result.one().get(0, Long.class);
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) BoundStatement(com.datastax.driver.core.BoundStatement) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 10 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() {
    logger.debug("[NFC] getAllMissing start");
    Map<Location, Set<String>> result = new HashMap<>();
    Query query = queryFactory.from(NfcConcreteResourceWrapper.class).maxResults(maxResultSetSize).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)

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