Search in sources :

Example 31 with Measure

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

the class IndexingContentManagerDecorator method getIndexedMemberTransfer.

@Measure
@Deprecated
public Transfer getIndexedMemberTransfer(final Group group, final String path, TransferOperation op, ContentManagementFunction func, final EventMetadata metadata) throws IndyWorkflowException {
    StoreKey topKey = group.getKey();
    List<StoreKey> toProcess = new ArrayList<>(group.getConstituents());
    Set<StoreKey> seen = new HashSet<>();
    while (!toProcess.isEmpty()) {
        StoreKey key = toProcess.remove(0);
        seen.add(key);
        final ArtifactStore member;
        try {
            member = storeDataManager.getArtifactStore(key);
            if (member == null) {
                continue;
            }
        } catch (IndyDataException e) {
            logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", key, topKey, e.getMessage()), e);
            continue;
        }
        Transfer transfer = getIndexedTransfer(key, topKey, path, op, metadata);
        if (transfer == null && StoreType.group != key.getType()) {
            // don't call this for constituents that are groups...we'll manually traverse the membership below...
            transfer = func.apply(member);
        }
        if (transfer != null) {
            if (indexCfg.isEnabled()) {
                indexManager.indexTransferIn(transfer, key, topKey);
            }
            return transfer;
        } else if (StoreType.group == key.getType()) {
            int i = 0;
            for (StoreKey memberKey : ((Group) member).getConstituents()) {
                if (!seen.contains(memberKey)) {
                    toProcess.add(i, memberKey);
                    i++;
                }
            }
        }
    }
    return null;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) ArrayList(java.util.ArrayList) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) HashSet(java.util.HashSet) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 32 with Measure

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

the class IndexingContentManagerDecorator method getIndexedTransfer.

@Measure
public Transfer getIndexedTransfer(final StoreKey storeKey, final StoreKey topKey, final String path, final TransferOperation op, final EventMetadata metadata) throws IndyWorkflowException {
    if (!indexCfg.isEnabled()) {
        logger.debug("Content indexing is disabled. Returning null for indexedTransfer of: {}/{}", storeKey, path);
        return null;
    }
    logger.debug("Looking for indexed path: {} in: {} (entry point: {})", path, storeKey, topKey);
    try {
        ArtifactStore store = storeDataManager.getArtifactStore(storeKey);
        if (store.isDisabled()) {
            logger.debug("Content not available in index caching layer due to store disabled for {} in group {}", storeKey, topKey);
            return null;
        }
    } catch (IndyDataException e) {
        logger.error(String.format("Failed to lookup store: %s (in membership of: %s). Reason: %s", storeKey, topKey, e.getMessage()), e);
        // TODO: Need further check if it is suitable to throw a IndyWorkflowException here.
        return null;
    }
    StoreKey indexedStoreKey = indexManager.getIndexedStoreKey(storeKey, path);
    if (indexedStoreKey != null) {
        Transfer transfer = delegate.getTransfer(indexedStoreKey, path, op);
        if (transfer == null || !transfer.exists()) {
            if (indexedStoreKey.getType() == StoreType.remote) {
                // Transfer not existing may be caused by not cached for remote repo, so we should trigger downloading
                // immediately to check if it really exists.
                logger.debug("Will trigger downloading of path {} from store {} from content index level", path, indexedStoreKey);
                try {
                    transfer = delegate.retrieve(storeDataManager.getArtifactStore(indexedStoreKey), path, metadata);
                    if (transfer != null && transfer.exists()) {
                        logger.debug("Downloaded and found it: {}", transfer);
                        return transfer;
                    }
                } catch (IndyDataException e) {
                    logger.warn("Error to get store {} caused by {}", indexedStoreKey, e.getMessage());
                }
            }
            logger.trace("Found obsolete index entry: {},{}. De-indexing from: {} and {}", indexedStoreKey, path, storeKey, topKey);
            // something happened to the underlying Transfer...de-index it, and don't return it.
            indexManager.deIndexStorePath(storeKey, path);
            if (topKey != null) {
                logger.debug("{} Not found in: {}. De-indexing from: {} (topKey)", path, storeKey, topKey);
                indexManager.deIndexStorePath(topKey, path);
            }
        } else {
            logger.debug("Found it: {}", transfer);
            return transfer;
        }
    }
    return null;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) ArtifactStore(org.commonjava.indy.model.core.ArtifactStore) Transfer(org.commonjava.maven.galley.model.Transfer) StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 33 with Measure

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

the class DefaultContentIndexManager method indexTransferIn.

@Override
@Measure
public void indexTransferIn(Transfer transfer, StoreKey... topKeys) {
    if (!config.isEnabled()) {
        logger.debug("Content indexing is disabled.");
        return;
    }
    if (transfer != null && transfer.exists()) {
        StoreKey key = LocationUtils.getKey(transfer);
        String path = getStrategyPath(key, transfer.getPath());
        indexPathInStores(path, key, topKeys);
    }
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 34 with Measure

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

the class DefaultContentIndexManager method clearAllIndexedPathInStoreWithOriginal.

@Override
@Measure
public void clearAllIndexedPathInStoreWithOriginal(ArtifactStore store, ArtifactStore originalStore) {
    if (!config.isEnabled()) {
        logger.debug("Content indexing is disabled.");
        return;
    }
    StoreKey sk = store.getKey();
    StoreKey osk = originalStore.getKey();
    long total = iterateRemove(() -> queryFactory.from(IndexedStorePath.class).maxResults(ITERATE_RESULT_SIZE).having("packageType").eq(osk.getPackageType()).and().having("storeType").eq(sk.getType().name()).and().having("storeName").eq(sk.getName()).and().having("originStoreType").eq(osk.getType().name()).and().having("originStoreName").eq(osk.getName()).toBuilder().build());
    logger.trace("Cleared all indices with origin: {} and group: {}, size: {}", osk, sk, total);
}
Also used : StoreKey(org.commonjava.indy.model.core.StoreKey) Measure(org.commonjava.o11yphant.metrics.annotation.Measure)

Example 35 with Measure

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

the class ContentGeneratorManager method generateFileContentAnd.

@Measure
public Transfer generateFileContentAnd(final ArtifactStore store, final String path, final EventMetadata eventMetadata, Consumer<Transfer> consumer) throws IndyWorkflowException {
    Transfer item = null;
    for (final ContentGenerator generator : contentGenerators) {
        logger.trace("Attempting to generate content, path: {}, store: {}, via: {}", path, store, generator);
        item = generator.generateFileContent(store, path, eventMetadata);
        if (item != null) {
            consumer.accept(item);
            break;
        }
    }
    return item;
}
Also used : ContentGenerator(org.commonjava.indy.content.ContentGenerator) Transfer(org.commonjava.maven.galley.model.Transfer) 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