use of com.azure.storage.blob.options.BlobUploadFromFileOptions in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerUploader method uploadToSasLink.
/**
* Upload the given file to a blob storage defined by a sas link.
*/
private Mono<Response<BlockBlobItem>> uploadToSasLink(BlobAccessPass uploadPass, UploadContext uploadContext, File file) {
try {
URL sasUrl = new URL(uploadPass.getUriWithSasToken());
LOGGER.debug("SAS token: {}", uploadPass.getUriWithSasToken());
BlobUploadFromFileOptions options = createBlockBlobOptions(file, uploadContext);
BlobContainerAsyncClient blobContainerClient = new BlobContainerClientBuilder().endpoint(sasUrl.toString()).buildAsyncClient();
BlobAsyncClient blobClient = blobContainerClient.getBlobAsyncClient(uploadPass.getBlobName());
return blobClient.uploadFromFileWithResponse(options).doFinally((done) -> LOGGER.info("upload done"));
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Malformed url", e);
}
}
use of com.azure.storage.blob.options.BlobUploadFromFileOptions in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerUploaderTest method roleNameIsCorrectlyAddedToMetaData.
@Test
void roleNameIsCorrectlyAddedToMetaData() throws IOException {
ServiceProfilerClientV2 serviceProfilerClient = stubServiceProfilerClient();
File tmpFile = createFakeJfrFile();
UUID appId = UUID.randomUUID();
BlobUploadFromFileOptions blobOptions = new ServiceProfilerUploader(serviceProfilerClient, "a-machine-name", "a-process-id", appId::toString, "a-role-name").createBlockBlobOptions(tmpFile, new UploadContext("a-machine-name", UUID.randomUUID(), 1, tmpFile, UUID.randomUUID()));
// Role name is set correctly
assertThat(blobOptions.getMetadata().get(BlobMetadataConstants.ROLE_NAME_META_NAME)).isEqualTo("a-role-name");
blobOptions = new ServiceProfilerUploader(serviceProfilerClient, "a-machine-name", "a-process-id", appId::toString, null).createBlockBlobOptions(tmpFile, new UploadContext("a-machine-name", UUID.randomUUID(), 1, tmpFile, UUID.randomUUID()));
// Null role name tag is not added
assertThat(blobOptions.getMetadata().get(BlobMetadataConstants.ROLE_NAME_META_NAME)).isNull();
}
use of com.azure.storage.blob.options.BlobUploadFromFileOptions in project ApplicationInsights-Java by microsoft.
the class ServiceProfilerUploader method createBlockBlobOptions.
BlobUploadFromFileOptions createBlockBlobOptions(File file, UploadContext uploadContext) {
HashMap<String, String> metadata = new HashMap<>();
metadata.put(BlobMetadataConstants.DATA_CUBE_META_NAME, uploadContext.getDataCube().toString().toLowerCase());
metadata.put(BlobMetadataConstants.MACHINE_NAME_META_NAME, uploadContext.getMachineName());
metadata.put(BlobMetadataConstants.START_TIME_META_NAME, TimestampContract.timestampToString(uploadContext.getSessionId()));
metadata.put(BlobMetadataConstants.PROGRAMMING_LANGUAGE_META_NAME, "Java");
metadata.put(BlobMetadataConstants.OS_PLATFORM_META_NAME, OsPlatformProvider.getOsPlatformDescription());
metadata.put(BlobMetadataConstants.TRACE_FILE_FORMAT_META_NAME, "jfr");
if (roleName != null && !roleName.isEmpty()) {
metadata.put(BlobMetadataConstants.ROLE_NAME_META_NAME, roleName);
}
String fullFilePath = file.getAbsoluteFile().toString();
return new BlobUploadFromFileOptions(fullFilePath).setHeaders(new BlobHttpHeaders().setContentEncoding("gzip")).setMetadata(metadata).setParallelTransferOptions(new ParallelTransferOptions().setBlockSizeLong(UPLOAD_BLOCK_LENGTH));
}
Aggregations