use of org.sonatype.nexus.repository.content.fluent.FluentAsset in project nexus-public by sonatype.
the class DatastoreBlobstoreRestoreTestHelper method assetMatch.
private static void assetMatch(final Optional<FluentAsset> asset, final BlobStore blobStore) {
assertTrue(asset.isPresent());
assertTrue(asset.get().blob().isPresent());
AssetBlob assetBlob = asset.orElseThrow(AssertionError::new).blob().orElseThrow(AssertionError::new);
Blob blob = blobStore.get(assetBlob.blobRef().getBlobId());
assertThat(blob, notNullValue());
assertThat(asset.map(FluentAsset::path).orElse("MISSING_FLUENT_ASSET"), equalTo(blob.getHeaders().get(BlobStore.BLOB_NAME_HEADER)));
assertThat(assetBlob.createdBy().orElse("MISSING_ASSET_BLOB"), equalTo(blob.getHeaders().get(BlobStore.CREATED_BY_HEADER)));
assertThat(assetBlob.createdByIp().orElse("MISSING_CREATED_BY"), equalTo(blob.getHeaders().get(BlobStore.CREATED_BY_IP_HEADER)));
assertThat(assetBlob.contentType(), equalTo(blob.getHeaders().get(BlobStore.CONTENT_TYPE_HEADER)));
assertThat(assetBlob.checksums().get(SHA1.name()), equalTo(blob.getMetrics().getSha1Hash()));
assertThat(assetBlob.blobSize(), equalTo(blob.getMetrics().getContentSize()));
}
use of org.sonatype.nexus.repository.content.fluent.FluentAsset in project nexus-public by sonatype.
the class MavenContentFacetImpl method hardLink.
@Override
public void hardLink(FluentAsset asset, Path contentPath) throws IOException {
String mimeType = mimeSupport.detectMimeType(Files.newInputStream(contentPath), contentPath.toString());
Map<String, String> headers = ImmutableMap.of(BLOB_NAME_HEADER, contentPath.toString(), CONTENT_TYPE_HEADER, mimeType);
byte[] bytes = Files.readAllBytes(contentPath);
Map<HashAlgorithm, HashCode> hashes = HashType.ALGORITHMS.stream().collect(Collectors.toMap(Function.identity(), a -> a.function().hashBytes(bytes)));
Blob blob = blobs().ingest(contentPath, headers, hashes.get(SHA1), Files.size(contentPath));
asset.attach(blob, hashes);
}
use of org.sonatype.nexus.repository.content.fluent.FluentAsset in project nexus-public by sonatype.
the class DatastoreDeadBlobFinderTest method createAsset.
private FluentAsset createAsset(final AssetBlob assetBlob) {
FluentAsset asset = mock(FluentAsset.class);
when(asset.path()).thenReturn("foo");
when(assetBlob.checksums()).thenReturn(Collections.singletonMap(HashAlgorithm.SHA1.name(), "1234"));
when(assetBlob.blobRef()).thenReturn(blobRef);
when(asset.blob()).thenReturn(Optional.of(assetBlob));
return asset;
}
use of org.sonatype.nexus.repository.content.fluent.FluentAsset in project nexus-public by sonatype.
the class DatastoreDeadBlobFinderTest method anAssetBlobCanBeDeletedWhileTheSystemIsInspected.
@Test
public void anAssetBlobCanBeDeletedWhileTheSystemIsInspected() {
AssetBlob missingAssetBlob = mockAssetBlob(mock(AssetBlob.class));
// first pass we have a missing blobRef
when(asset.blob()).thenReturn(Optional.of(missingAssetBlob));
FluentAsset reloadedAsset = createAsset(assetBlob);
// second pass the blobRef is there but file does not exist
Blob reloadedBlob = mock(Blob.class);
when(reloadedBlob.getMetrics()).thenReturn(blobMetrics);
BlobId missingBlobId = reloadedAsset.blob().get().blobRef().getBlobId();
when(blobStore.get(missingBlobId)).thenReturn(reloadedBlob);
mockAssetBrowse();
mockAssetReload(reloadedAsset);
when(reloadedBlob.getMetrics()).thenReturn(blobMetrics);
when(reloadedBlob.getInputStream()).thenThrow(new BlobStoreException("Blob has been deleted", new BlobId("foo")));
List<DeadBlobResult<Asset>> result = deadBlobFinder.find(repository, true);
assertThat(result, hasSize(1));
assertThat(result.get(0).getResultState(), is(DELETED));
}
use of org.sonatype.nexus.repository.content.fluent.FluentAsset in project nexus-public by sonatype.
the class DatastoreOrphanedBlobFinderTest method setupOrphanedBlob.
private void setupOrphanedBlob(final BlobStore blobStore, final boolean deleted) {
when(blobStore.getBlobIdStream()).thenAnswer(i -> Stream.of(new BlobId(ORPHANED_BLOB_ID), new BlobId(USED_BLOB_ID)));
when(blobStore.getBlobAttributes(new BlobId(ORPHANED_BLOB_ID))).thenReturn(new TestBlobAttributes(deleted));
when(blobStore.getBlobAttributes(new BlobId(USED_BLOB_ID))).thenReturn(new TestBlobAttributes(deleted));
when(blobStore.getBlobStoreConfiguration()).thenReturn(blobStoreConfiguration);
FluentAsset asset = buildAssetWithBlobId(USED_BLOB_ID);
setupTransactionToFindAsset(asset);
}
Aggregations