Search in sources :

Example 1 with TrackedContent

use of org.commonjava.indy.folo.model.TrackedContent 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 2 with TrackedContent

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

the class FoloAdminController method renderRepositoryZip.

public File renderRepositoryZip(final String id) throws IndyWorkflowException {
    final TrackingKey tk = new TrackingKey(id);
    File file = filer.getRepositoryZipFile(tk).getDetachedFile();
    file.getParentFile().mkdirs();
    logger.debug("Retrieving tracking record for: {}", tk);
    final TrackedContent record = recordManager.get(tk);
    logger.debug("Got: {}", record);
    if (record == null) {
        throw new IndyWorkflowException(ApplicationStatus.NOT_FOUND.code(), "No tracking record available for: %s. Maybe you forgot to seal it?", tk);
    }
    final Set<String> seenPaths = new HashSet<>();
    final List<Transfer> items = new ArrayList<>();
    addTransfers(record.getUploads(), items, id, seenPaths);
    addTransfers(record.getDownloads(), items, id, seenPaths);
    logger.debug("Retrieved {} files. Creating zip.", items.size());
    Collections.sort(items, (f, s) -> f.getPath().compareTo(s.getPath()));
    try (ZipOutputStream stream = new ZipOutputStream(new FileOutputStream(file))) {
        for (final Transfer item : items) {
            // logger.info( "Adding: {}", item );
            if (item != null) {
                final String path = item.getPath();
                final ZipEntry ze = new ZipEntry(path);
                stream.putNextEntry(ze);
                InputStream itemStream = null;
                try {
                    itemStream = item.openInputStream();
                    copy(itemStream, stream);
                } finally {
                    closeQuietly(itemStream);
                }
            }
        }
    } catch (final IOException e) {
        throw new IndyWorkflowException("Failed to generate repository zip from tracking record: {}. Reason: {}", e, id, e.getMessage());
    }
    return file;
}
Also used : InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) ZipOutputStream(java.util.zip.ZipOutputStream) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) FileOutputStream(java.io.FileOutputStream) TrackedContent(org.commonjava.indy.folo.model.TrackedContent) Transfer(org.commonjava.maven.galley.model.Transfer) File(java.io.File) HashSet(java.util.HashSet)

Example 3 with TrackedContent

use of org.commonjava.indy.folo.model.TrackedContent 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 4 with TrackedContent

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

the class FoloRecordCacheTest method clearRecordDeletesRecord.

@Test
public void clearRecordDeletesRecord() throws Exception {
    final TrackingKey key = newKey();
    assertThat(cache.hasRecord(key), equalTo(false));
    cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, 127L, "", "", ""));
    TrackedContent record = cache.seal(key);
    assertThat(record, notNullValue());
    assertThat(cache.hasRecord(key), equalTo(true));
    cache.delete(key);
    assertThat(cache.hasRecord(key), equalTo(false));
    assertThat(cache.get(key), nullValue());
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Example 5 with TrackedContent

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

the class FoloRecordCacheTest method sealRemovesInProgressAndCreatesSealedRecord.

@Test
public void sealRemovesInProgressAndCreatesSealedRecord() throws Exception {
    final TrackingKey key = newKey();
    assertThat(cache.hasRecord(key), equalTo(false));
    cache.recordArtifact(new TrackedContentEntry(key, new StoreKey(StoreType.remote, "foo"), AccessChannel.MAVEN_REPO, "", "/path", StoreEffect.DOWNLOAD, 124L, "", "", ""));
    assertThat(cache.hasRecord(key), equalTo(true));
    assertThat(cache.hasInProgressRecord(key), equalTo(true));
    assertThat(cache.hasSealedRecord(key), equalTo(false));
    TrackedContent record = cache.seal(key);
    assertThat(record, notNullValue());
    assertThat(cache.hasRecord(key), equalTo(true));
    assertThat(cache.hasInProgressRecord(key), equalTo(false));
    assertThat(cache.hasSealedRecord(key), equalTo(true));
}
Also used : TrackedContent(org.commonjava.indy.folo.model.TrackedContent) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) TrackingKey(org.commonjava.indy.folo.model.TrackingKey) Test(org.junit.Test)

Aggregations

TrackedContent (org.commonjava.indy.folo.model.TrackedContent)6 TrackedContentEntry (org.commonjava.indy.folo.model.TrackedContentEntry)5 TrackingKey (org.commonjava.indy.folo.model.TrackingKey)5 StoreKey (org.commonjava.indy.model.core.StoreKey)3 Test (org.junit.Test)3 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 Transfer (org.commonjava.maven.galley.model.Transfer)1 Query (org.infinispan.query.dsl.Query)1 Logger (org.slf4j.Logger)1