Search in sources :

Example 1 with MetricsInputStream

use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-blobstore-google-cloud by sonatype-nexus-community.

the class GoogleCloudBlobStore method doCreate.

@Override
protected Blob doCreate(final InputStream blobData, final Map<String, String> headers, @Nullable final BlobId blobId) {
    return createInternal(headers, destination -> {
        try (InputStream data = blobData) {
            MetricsInputStream input = new MetricsInputStream(data);
            uploader.upload(storage, getConfiguredBucketName(), destination, input);
            return input.getMetrics();
        }
    }, blobId);
}
Also used : MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream) InputStream(java.io.InputStream) MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream)

Example 2 with MetricsInputStream

use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-public by sonatype.

the class S3BlobStore method doCreate.

@Override
@Timed
@MonitoringBlobStoreMetrics(operationType = UPLOAD)
protected Blob doCreate(final InputStream blobData, final Map<String, String> headers, @Nullable final BlobId blobId) {
    return create(headers, destination -> {
        try (InputStream data = blobData) {
            MetricsInputStream input = new MetricsInputStream(data);
            uploader.upload(s3, getConfiguredBucket(), destination, input);
            return input.getMetrics();
        }
    }, blobId);
}
Also used : MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream) InputStream(java.io.InputStream) MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream) Timed(com.codahale.metrics.annotation.Timed) MonitoringBlobStoreMetrics(org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics)

Example 3 with MetricsInputStream

use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-public by sonatype.

the class FileBlobStoreConcurrencyIT method readContentAndValidateMetrics.

/**
 * Read all the content from a blob, and compare it with the metrics on file in the blob store.
 *
 * @throws RuntimeException if there is any deviation
 */
private void readContentAndValidateMetrics(final BlobId blobId, final InputStream inputStream, final BlobMetrics metadataMetrics) throws NoSuchAlgorithmException, IOException {
    final MetricsInputStream measured = new MetricsInputStream(inputStream);
    ByteStreams.copy(measured, nullOutputStream());
    checkEqual("stream length", metadataMetrics.getContentSize(), measured.getSize(), blobId);
    checkEqual("SHA1 hash", metadataMetrics.getSha1Hash(), measured.getMessageDigest(), blobId);
}
Also used : MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream)

Example 4 with MetricsInputStream

use of org.sonatype.nexus.blobstore.MetricsInputStream in project nexus-public by sonatype.

the class SimpleFileOperations method create.

@Override
public StreamMetrics create(final Path path, final InputStream data) throws IOException {
    checkNotNull(path);
    checkNotNull(data);
    // Ensure path exists for new blob
    Path dir = path.getParent();
    checkNotNull(dir, "Null parent for path: %s", path);
    DirectoryHelper.mkdir(dir);
    final MetricsInputStream input = new MetricsInputStream(data);
    try {
        try (final OutputStream output = Files.newOutputStream(path, StandardOpenOption.CREATE_NEW)) {
            ByteStreams.copy(input, output);
        }
    } finally {
        // FIXME: Revisit closing stream which is passed in as parameter, this should be the responsibility of the caller
        data.close();
    }
    return input.getMetrics();
}
Also used : Path(java.nio.file.Path) MetricsInputStream(org.sonatype.nexus.blobstore.MetricsInputStream) OutputStream(java.io.OutputStream)

Aggregations

MetricsInputStream (org.sonatype.nexus.blobstore.MetricsInputStream)4 InputStream (java.io.InputStream)2 Timed (com.codahale.metrics.annotation.Timed)1 OutputStream (java.io.OutputStream)1 Path (java.nio.file.Path)1 MonitoringBlobStoreMetrics (org.sonatype.nexus.blobstore.metrics.MonitoringBlobStoreMetrics)1