Search in sources :

Example 6 with TrackedContentEntry

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

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

the class FoloTrackingListener method createEntry.

private TrackedContentEntry createEntry(final TrackingKey trackingKey, final StoreKey affectedStore, final AccessChannel accessChannel, final String path, final StoreEffect effect, final EventMetadata eventMetadata) throws IndyWorkflowException {
    TrackedContentEntry entry = null;
    final Transfer txfr = downloadManager.getStorageReference(affectedStore, path);
    if (txfr != null) {
        try {
            String remoteUrl = null;
            if (StoreType.remote == affectedStore.getType()) {
                final RemoteRepository repo = (RemoteRepository) storeManager.getArtifactStore(affectedStore);
                if (repo != null) {
                    remoteUrl = UrlUtils.buildUrl(repo.getUrl(), path);
                }
            }
            TransferMetadata artifactData = contentDigester.digest(affectedStore, path, eventMetadata);
            Map<ContentDigest, String> digests = artifactData.getDigests();
            //TODO: As localUrl needs a apiBaseUrl which is from REST service context, to avoid deep propagate
            //      of it, this step will be done in REST layer. Will think better way in the future.
            entry = new TrackedContentEntry(trackingKey, affectedStore, accessChannel, remoteUrl, path, effect, artifactData.getSize(), digests.get(ContentDigest.MD5), digests.get(ContentDigest.SHA_1), digests.get(ContentDigest.SHA_256));
        } catch (final IndyDataException e) {
            throw new IndyWorkflowException("Cannot retrieve RemoteRepository: %s to calculate remote URL for: %s. Reason: %s", e, trackingKey, path, e.getMessage());
        } catch (final MalformedURLException e) {
            throw new IndyWorkflowException("Cannot format URL. Reason: %s", e, e.getMessage());
        }
    }
    return entry;
}
Also used : IndyDataException(org.commonjava.indy.data.IndyDataException) MalformedURLException(java.net.MalformedURLException) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) IndyWorkflowException(org.commonjava.indy.IndyWorkflowException) Transfer(org.commonjava.maven.galley.model.Transfer) RemoteRepository(org.commonjava.indy.model.core.RemoteRepository) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) ContentDigest(org.commonjava.maven.galley.io.checksum.ContentDigest)

Example 8 with TrackedContentEntry

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

the class FoloAdminController method recalculate.

private TrackedContentEntry recalculate(final TrackedContentEntry entry) throws IndyWorkflowException {
    StoreKey affectedStore = entry.getStoreKey();
    String path = entry.getPath();
    AccessChannel channel = entry.getAccessChannel();
    Transfer transfer = contentManager.getTransfer(affectedStore, path, entry.getEffect() == StoreEffect.UPLOAD ? TransferOperation.UPLOAD : TransferOperation.DOWNLOAD);
    contentDigester.removeMetadata(transfer);
    TransferMetadata artifactData = contentDigester.digest(affectedStore, path, new EventMetadata(channel.packageType()));
    Map<ContentDigest, String> digests = artifactData.getDigests();
    return new TrackedContentEntry(entry.getTrackingKey(), affectedStore, channel, entry.getOriginUrl(), path, entry.getEffect(), artifactData.getSize(), digests.get(ContentDigest.MD5), digests.get(ContentDigest.SHA_1), digests.get(ContentDigest.SHA_256));
}
Also used : AccessChannel(org.commonjava.indy.model.core.AccessChannel) TransferMetadata(org.commonjava.maven.galley.io.checksum.TransferMetadata) Transfer(org.commonjava.maven.galley.model.Transfer) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry) StoreKey(org.commonjava.indy.model.core.StoreKey) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) ContentDigest(org.commonjava.maven.galley.io.checksum.ContentDigest)

Example 9 with TrackedContentEntry

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

the class FoloCacheProducer method registerTransformer.

private void registerTransformer() {
    final CacheHandle<TrackedContentEntry, TrackedContentEntry> handler = cacheProducer.getCache(IN_PROGRESS_NAME, TrackedContentEntry.class, TrackedContentEntry.class);
    handler.execute(cache -> {
        SearchManagerImplementor searchManager = (SearchManagerImplementor) Search.getSearchManager(cache);
        searchManager.registerKeyTransformer(TrackedContentEntry.class, TrackedContentEntryTransformer.class);
        return null;
    });
}
Also used : SearchManagerImplementor(org.infinispan.query.spi.SearchManagerImplementor) TrackedContentEntry(org.commonjava.indy.folo.model.TrackedContentEntry)

Example 10 with TrackedContentEntry

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

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