Search in sources :

Example 1 with BlobUploadFromFileOptions

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);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) BlobContainerAsyncClient(com.azure.storage.blob.BlobContainerAsyncClient) BlobAsyncClient(com.azure.storage.blob.BlobAsyncClient) BlobUploadFromFileOptions(com.azure.storage.blob.options.BlobUploadFromFileOptions) BlobContainerClientBuilder(com.azure.storage.blob.BlobContainerClientBuilder) URL(java.net.URL)

Example 2 with BlobUploadFromFileOptions

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();
}
Also used : ServiceProfilerClientV2(com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2) BlobUploadFromFileOptions(com.azure.storage.blob.options.BlobUploadFromFileOptions) UUID(java.util.UUID) File(java.io.File) UploadContext(com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext) Test(org.junit.jupiter.api.Test)

Example 3 with BlobUploadFromFileOptions

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));
}
Also used : BlobHttpHeaders(com.azure.storage.blob.models.BlobHttpHeaders) HashMap(java.util.HashMap) BlobUploadFromFileOptions(com.azure.storage.blob.options.BlobUploadFromFileOptions) ParallelTransferOptions(com.azure.storage.blob.models.ParallelTransferOptions)

Aggregations

BlobUploadFromFileOptions (com.azure.storage.blob.options.BlobUploadFromFileOptions)3 BlobAsyncClient (com.azure.storage.blob.BlobAsyncClient)1 BlobContainerAsyncClient (com.azure.storage.blob.BlobContainerAsyncClient)1 BlobContainerClientBuilder (com.azure.storage.blob.BlobContainerClientBuilder)1 BlobHttpHeaders (com.azure.storage.blob.models.BlobHttpHeaders)1 ParallelTransferOptions (com.azure.storage.blob.models.ParallelTransferOptions)1 ServiceProfilerClientV2 (com.microsoft.applicationinsights.serviceprofilerapi.client.ServiceProfilerClientV2)1 UploadContext (com.microsoft.applicationinsights.serviceprofilerapi.client.uploader.UploadContext)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 Test (org.junit.jupiter.api.Test)1