org.sonatype.nexus.blobstore.StreamMetrics Java Examples
The following examples show how to use
org.sonatype.nexus.blobstore.StreamMetrics.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleFileOperations.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@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(); }
Example #2
Source File: GoogleCloudBlobStore.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | 5 votes |
@Override @Guarded(by = STARTED) public Blob copy(final BlobId blobId, final Map<String, String> headers) { GoogleCloudStorageBlob sourceBlob = (GoogleCloudStorageBlob) checkNotNull(get(blobId)); return createInternal(headers, destination -> { sourceBlob.getBlob().copyTo(getConfiguredBucketName(), destination); BlobMetrics metrics = sourceBlob.getMetrics(); return new StreamMetrics(metrics.getContentSize(), metrics.getSha1Hash()); }, null); }
Example #3
Source File: GoogleCloudBlobStore.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | 5 votes |
Blob createInternal(final Map<String, String> headers, final BlobIngester ingester, @Nullable final BlobId assignedBlobId) { checkNotNull(headers); checkArgument(headers.containsKey(BLOB_NAME_HEADER), "Missing header: %s", BLOB_NAME_HEADER); checkArgument(headers.containsKey(CREATED_BY_HEADER), "Missing header: %s", CREATED_BY_HEADER); final BlobId blobId = getBlobId(headers, assignedBlobId); final String blobPath = contentPath(blobId); final String attributePath = attributePath(blobId); final GoogleCloudStorageBlob blob = liveBlobs.getUnchecked(blobId); Lock lock = blob.lock(); try { log.debug("Writing blob {} to {}", blobId, blobPath); final StreamMetrics streamMetrics = ingester.ingestTo(blobPath); final BlobMetrics metrics = new BlobMetrics(new DateTime(), streamMetrics.getSha1(), streamMetrics.getSize()); blob.refresh(headers, metrics); GoogleCloudBlobAttributes blobAttributes = new GoogleCloudBlobAttributes(bucket, attributePath, headers, metrics); blobAttributes.store(); metricsStore.recordAddition(blobId, metrics.getContentSize()); return blob; } catch (IOException e) { deleteNonExplosively(attributePath); deleteNonExplosively(blobPath); throw new BlobStoreException(e, blobId); } finally { lock.unlock(); } }
Example #4
Source File: S3BlobStore.java From nexus-blobstore-s3 with Eclipse Public License 1.0 | 5 votes |
private Blob create(final Map<String, String> headers, final BlobIngester ingester) { checkNotNull(headers); checkArgument(headers.containsKey(BLOB_NAME_HEADER), "Missing header: %s", BLOB_NAME_HEADER); checkArgument(headers.containsKey(CREATED_BY_HEADER), "Missing header: %s", CREATED_BY_HEADER); final BlobId blobId = blobIdLocationResolver.fromHeaders(headers); final String blobPath = contentPath(blobId); final String attributePath = attributePath(blobId); final S3Blob blob = liveBlobs.getUnchecked(blobId); Lock lock = blob.lock(); try { log.debug("Writing blob {} to {}", blobId, blobPath); final StreamMetrics streamMetrics = ingester.ingestTo(blobPath); final BlobMetrics metrics = new BlobMetrics(new DateTime(), streamMetrics.getSha1(), streamMetrics.getSize()); blob.refresh(headers, metrics); S3BlobAttributes blobAttributes = new S3BlobAttributes(s3, getConfiguredBucket(), attributePath, headers, metrics); blobAttributes.store(); storeMetrics.recordAddition(blobAttributes.getMetrics().getContentSize()); return blob; } catch (IOException e) { // Something went wrong, clean up the files we created deleteQuietly(attributePath); deleteQuietly(blobPath); throw new BlobStoreException(e, blobId); } finally { lock.unlock(); } }
Example #5
Source File: S3BlobStore.java From nexus-blobstore-s3 with Eclipse Public License 1.0 | 5 votes |
@Override @Guarded(by = STARTED) public Blob copy(final BlobId blobId, final Map<String, String> headers) { Blob sourceBlob = checkNotNull(get(blobId)); String sourcePath = contentPath(sourceBlob.getId()); return create(headers, destination -> { s3.copyObject(getConfiguredBucket(), sourcePath, getConfiguredBucket(), destination); BlobMetrics metrics = sourceBlob.getMetrics(); return new StreamMetrics(metrics.getContentSize(), metrics.getSha1Hash()); }); }
Example #6
Source File: S3BlobStore.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override @Guarded(by = STARTED) @Timed public Blob copy(final BlobId blobId, final Map<String, String> headers) { Blob sourceBlob = checkNotNull(get(blobId)); String sourcePath = contentPath(sourceBlob.getId()); return create(headers, destination -> { copier.copy(s3, getConfiguredBucket(), sourcePath, destination); BlobMetrics metrics = sourceBlob.getMetrics(); return new StreamMetrics(metrics.getContentSize(), metrics.getSha1Hash()); }, null); }
Example #7
Source File: SimpleFileOperations.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override public StreamMetrics computeMetrics(final Path file) throws IOException { try (InputStream is = Files.newInputStream(file); MetricsInputStream mis = new MetricsInputStream(is)) { ByteStreams.copy(mis, ByteStreams.nullOutputStream()); return mis.getMetrics(); } }
Example #8
Source File: FileBlobStore.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override @Guarded(by = STARTED) public Blob create(final Path sourceFile, final Map<String, String> headers, final long size, final HashCode sha1) { checkNotNull(sourceFile); checkNotNull(sha1); checkArgument(Files.exists(sourceFile)); return create(headers, destination -> { fileOperations.hardLink(sourceFile, destination); return new StreamMetrics(size, sha1.toString()); }, null); }
Example #9
Source File: FileBlobStore.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
private Blob tryCreate(final Map<String, String> headers, final BlobIngester ingester, final BlobId reusedBlobId) { // NOSONAR final BlobId blobId = getBlobId(headers, reusedBlobId); final boolean isDirectPath = Boolean.parseBoolean(headers.getOrDefault(DIRECT_PATH_BLOB_HEADER, "false")); final Long existingSize = isDirectPath && exists(blobId) ? getContentSizeForDeletion(blobId) : null; final Path blobPath = contentPath(blobId); final Path attributePath = attributePath(blobId); final UUID uuidSuffix = UUID.randomUUID(); final Path temporaryBlobPath = temporaryContentPath(blobId, uuidSuffix); final Path temporaryAttributePath = temporaryAttributePath(blobId, uuidSuffix); final FileBlob blob = liveBlobs.getUnchecked(blobId); Lock lock = blob.lock(); try { final boolean wouldCollide = fileOperations.exists(blobPath); if ((reusedBlobId == null) && RETRY_ON_COLLISION && wouldCollide && !isDirectPath) { throw new BlobCollisionException(blobId); } try { log.debug("Writing blob {} to {}", blobId, blobPath); final StreamMetrics streamMetrics = ingester.ingestTo(temporaryBlobPath); final BlobMetrics metrics = new BlobMetrics(new DateTime(), streamMetrics.getSha1(), streamMetrics.getSize()); blob.refresh(headers, metrics); // Write the blob attribute file FileBlobAttributes blobAttributes = new FileBlobAttributes(temporaryAttributePath, headers, metrics); blobAttributes.store(); // Move the temporary files into their final location // existing size being not-null also implies isDirectPath is true if (existingSize != null) { overwrite(temporaryBlobPath, blobPath); overwrite(temporaryAttributePath, attributePath); metricsStore.recordDeletion(existingSize); } else { move(temporaryBlobPath, blobPath); move(temporaryAttributePath, attributePath); } metricsStore.recordAddition(blobAttributes.getMetrics().getContentSize()); return blob; } catch (Exception e) { // Something went wrong, clean up the files we created fileOperations.deleteQuietly(temporaryAttributePath); fileOperations.deleteQuietly(temporaryBlobPath); fileOperations.deleteQuietly(attributePath); fileOperations.deleteQuietly(blobPath); throw new BlobStoreException(e, blobId); } } finally { lock.unlock(); } }
Example #10
Source File: FileOperations.java From nexus-public with Eclipse Public License 1.0 | 2 votes |
/** * Creates a file (and its containing directories, if necessary) and populates it from the * InputStream, which gets closed. * * @return Basic metrics about the stream. */ StreamMetrics create(Path path, InputStream data) throws IOException;
Example #11
Source File: FileOperations.java From nexus-public with Eclipse Public License 1.0 | 2 votes |
/** * Computes basic metrics about the file. */ StreamMetrics computeMetrics(Path file) throws IOException;
Example #12
Source File: GoogleCloudBlobStore.java From nexus-blobstore-google-cloud with Eclipse Public License 1.0 | votes |
StreamMetrics ingestTo(final String destination) throws IOException;
Example #13
Source File: S3BlobStore.java From nexus-blobstore-s3 with Eclipse Public License 1.0 | votes |
StreamMetrics ingestTo(final String destination) throws IOException;
Example #14
Source File: S3BlobStore.java From nexus-public with Eclipse Public License 1.0 | votes |
StreamMetrics ingestTo(final String destination) throws IOException;
Example #15
Source File: FileBlobStore.java From nexus-public with Eclipse Public License 1.0 | votes |
StreamMetrics ingestTo(final Path destination) throws IOException;