Search in sources :

Example 1 with TrackedContentEntry

use of org.commonjava.indy.folo.model.TrackedContentEntry in project indy by Commonjava.

the class FoloAdminController method addTransfers.

private void addTransfers(final Set<TrackedContentEntry> entries, final List<Transfer> items, final String trackingId, final Set<String> seenPaths) throws IndyWorkflowException {
    if (entries != null && !entries.isEmpty()) {
        for (final TrackedContentEntry entry : entries) {
            final String path = entry.getPath();
            if (path == null || seenPaths.contains(path)) {
                continue;
            }
            final StoreKey sk = entry.getStoreKey();
            Transfer transfer = contentManager.getTransfer(sk, path, TransferOperation.DOWNLOAD);
            if (transfer == null) {
                Logger logger = LoggerFactory.getLogger(getClass());
                logger.warn("While creating Folo repo zip for: {}, cannot find: {} in: {}", trackingId, path, sk);
            } else {
                seenPaths.add(path);
                items.add(transfer);
            }
        }
    }
}
Also used : Transfer(org.commonjava.maven.galley.model.Transfer) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) Logger(org.slf4j.Logger) StoreKey(org.commonjava.indy.model.core.StoreKey)

Example 2 with TrackedContentEntry

use of org.commonjava.indy.folo.model.TrackedContentEntry in project indy by Commonjava.

the class FoloAdminController method recalculateRecord.

public TrackedContentDTO recalculateRecord(final String id, final String baseUrl) throws IndyWorkflowException {
    TrackingKey trackingKey = new TrackingKey(id);
    TrackedContent record = recordManager.get(trackingKey);
    AtomicBoolean failed = new AtomicBoolean(false);
    Set<TrackedContentEntry> recalculatedUploads = recalculateEntrySet(record.getUploads(), id, failed);
    Set<TrackedContentEntry> recalculatedDownloads = recalculateEntrySet(record.getDownloads(), id, failed);
    if (failed.get()) {
        throw new IndyWorkflowException("Failed to recalculate tracking record: %s. See Indy logs for more information", id);
    }
    TrackedContent recalculated = new TrackedContent(record.getKey(), recalculatedUploads, recalculatedDownloads);
    recordManager.replaceTrackingRecord(recalculated);
    return constructContentDTO(recalculated, baseUrl);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) TrackingKey(org.commonjava.indy.folo.model.TrackingKey)

Example 3 with TrackedContentEntry

use of org.commonjava.indy.folo.model.TrackedContentEntry in project indy by Commonjava.

the class FoloAdminController method constructContentDTO.

private TrackedContentDTO constructContentDTO(final TrackedContent content, final String baseUrl) {
    if (content == null) {
        return null;
    }
    final Set<TrackedContentEntryDTO> uploads = new TreeSet<>();
    for (TrackedContentEntry entry : content.getUploads()) {
        uploads.add(constructContentEntryDTO(entry, baseUrl));
    }
    final Set<TrackedContentEntryDTO> downloads = new TreeSet<>();
    for (TrackedContentEntry entry : content.getDownloads()) {
        downloads.add(constructContentEntryDTO(entry, baseUrl));
    }
    return new TrackedContentDTO(content.getKey(), uploads, downloads);
}
Also used : TreeSet(java.util.TreeSet) TrackedContentEntryDTO(org.commonjava.indy.folo.dto.TrackedContentEntryDTO) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) TrackedContentDTO(org.commonjava.indy.folo.dto.TrackedContentDTO)

Example 4 with TrackedContentEntry

use of org.commonjava.indy.folo.model.TrackedContentEntry in project indy by Commonjava.

the class FoloRecordCache method seal.

public TrackedContent seal(final TrackingKey trackingKey) {
    TrackedContent record = sealedRecordCache.get(trackingKey);
    Logger logger = LoggerFactory.getLogger(getClass());
    if (record != null) {
        logger.debug("Tracking record: {} already sealed! Returning sealed record.", trackingKey);
        return record;
    }
    logger.debug("Listing unsealed tracking record entries for: {}...", trackingKey);
    return inProgressByTrackingKey(trackingKey, (qb, cacheHandle) -> {
        Query query = qb.build();
        List<TrackedContentEntry> results = query.list();
        TrackedContent created = null;
        if (results != null) {
            logger.debug("Adding {} entries to record: {}", results.size(), trackingKey);
            Set<TrackedContentEntry> uploads = new TreeSet<>();
            Set<TrackedContentEntry> downloads = new TreeSet<>();
            results.forEach((result) -> {
                if (StoreEffect.DOWNLOAD == result.getEffect()) {
                    downloads.add(result);
                } else if (StoreEffect.UPLOAD == result.getEffect()) {
                    uploads.add(result);
                }
                logger.debug("Removing in-progress entry: {}", result);
                inProgressRecordCache.remove(result);
            });
            created = new TrackedContent(trackingKey, uploads, downloads);
        }
        logger.debug("Sealing record for: {}", trackingKey);
        sealedRecordCache.put(trackingKey, created);
        return created;
    });
}
Also used : Query(org.infinispan.query.dsl.Query) TreeSet(java.util.TreeSet) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) Logger(org.slf4j.Logger)

Example 5 with TrackedContentEntry

use of org.commonjava.indy.folo.model.TrackedContentEntry in project indy by Commonjava.

the class FoloRecordCache method inProgressByTrackingKey.

private <R> R inProgressByTrackingKey(final TrackingKey key, final BiFunction<QueryBuilder, CacheHandle<TrackedContentEntry, TrackedContentEntry>, R> operation) {
    return inProgressRecordCache.execute((cache) -> {
        QueryFactory queryFactory = Search.getQueryFactory(cache);
        QueryBuilder qb = queryFactory.from(TrackedContentEntry.class).having("trackingKey.id").eq(key.getId()).toBuilder();
        return operation.apply(qb, inProgressRecordCache);
    });
}
Also used : QueryFactory(org.infinispan.query.dsl.QueryFactory) QueryBuilder(org.infinispan.query.dsl.QueryBuilder) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry)

Aggregations

TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)11 TrackedContent (org.commonjava.indy.folo.model.TrackedContent)5 StoreKey (org.commonjava.indy.model.core.StoreKey)5 TrackingKey (org.commonjava.indy.folo.model.TrackingKey)4 Transfer (org.commonjava.maven.galley.model.Transfer)3 Test (org.junit.Test)3 TreeSet (java.util.TreeSet)2 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 ContentDigest (org.commonjava.maven.galley.io.checksum.ContentDigest)2 TransferMetadata (org.commonjava.maven.galley.io.checksum.TransferMetadata)2 Logger (org.slf4j.Logger)2 MalformedURLException (java.net.MalformedURLException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 IndyDataException (org.commonjava.indy.data.IndyDataException)1 TrackedContentDTO (org.commonjava.indy.folo.dto.TrackedContentDTO)1 TrackedContentEntryDTO (org.commonjava.indy.folo.dto.TrackedContentEntryDTO)1 AccessChannel (org.commonjava.indy.model.core.AccessChannel)1 RemoteRepository (org.commonjava.indy.model.core.RemoteRepository)1 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)1 Query (org.infinispan.query.dsl.Query)1