Skip to content

Commit

Permalink
Code Sample Fixes for DataLake and Blobs (#37881)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimrabab authored Dec 4, 2023
1 parent b4d191a commit 5d2cfe6
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -940,10 +940,11 @@ public Mono<Void> uploadFromFile(String filePath, ParallelTransferOptions parall
* BlobRequestConditions requestConditions = new BlobRequestConditions&#40;&#41;
* .setLeaseId&#40;leaseId&#41;
* .setIfUnmodifiedSince&#40;OffsetDateTime.now&#40;&#41;.minusDays&#40;3&#41;&#41;;
* Long blockSize = 100 * 1024 * 1024L; &#47;&#47; 100 MB;
*
* client.uploadFromFileWithResponse&#40;new BlobUploadFromFileOptions&#40;filePath&#41;
* .setParallelTransferOptions&#40;
* new ParallelTransferOptions&#40;&#41;.setBlockSizeLong&#40;BlobAsyncClient.BLOB_MAX_UPLOAD_BLOCK_SIZE&#41;&#41;
* new ParallelTransferOptions&#40;&#41;.setBlockSizeLong&#40;blockSize&#41;&#41;
* .setHeaders&#40;headers&#41;.setMetadata&#40;metadata&#41;.setTags&#40;tags&#41;.setTier&#40;AccessTier.HOT&#41;
* .setRequestConditions&#40;requestConditions&#41;&#41;
* .doOnError&#40;throwable -&gt; System.err.printf&#40;&quot;Failed to upload from file %s%n&quot;, throwable.getMessage&#40;&#41;&#41;&#41;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public BlockBlobItem upload(BinaryData data, boolean overwrite) {
* <!-- src_embed com.azure.storage.blob.specialized.BlockBlobClient.uploadWithResponse#InputStream-long-BlobHttpHeaders-Map-AccessTier-byte-BlobRequestConditions-Duration-Context -->
* <pre>
* BlobHttpHeaders headers = new BlobHttpHeaders&#40;&#41;
* .setContentMd5&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;
* .setContentMd5&#40;MessageDigest.getInstance&#40;&quot;MD5&quot;&#41;.digest&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;&#41;
* .setContentLanguage&#40;&quot;en-US&quot;&#41;
* .setContentType&#40;&quot;binary&quot;&#41;;
*
Expand Down Expand Up @@ -495,7 +495,7 @@ public Response<BlockBlobItem> uploadWithResponse(InputStream data, long length,
* <!-- src_embed com.azure.storage.blob.specialized.BlockBlobClient.uploadWithResponse#BlockBlobSimpleUploadOptions-Duration-Context -->
* <pre>
* BlobHttpHeaders headers = new BlobHttpHeaders&#40;&#41;
* .setContentMd5&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;
* .setContentMd5&#40;MessageDigest.getInstance&#40;&quot;MD5&quot;&#41;.digest&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;&#41;
* .setContentLanguage&#40;&quot;en-US&quot;&#41;
* .setContentType&#40;&quot;binary&quot;&#41;;
*
Expand Down Expand Up @@ -614,7 +614,7 @@ public BlockBlobItem uploadFromUrl(String sourceUrl, boolean overwrite) {
* <!-- src_embed com.azure.storage.blob.specialized.BlockBlobClient.uploadFromUrlWithResponse#BlobUploadFromUrlOptions-Duration-Context -->
* <pre>
* BlobHttpHeaders headers = new BlobHttpHeaders&#40;&#41;
* .setContentMd5&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;
* .setContentMd5&#40;MessageDigest.getInstance&#40;&quot;MD5&quot;&#41;.digest&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;&#41;
* .setContentLanguage&#40;&quot;en-US&quot;&#41;
* .setContentType&#40;&quot;binary&quot;&#41;;
*
Expand Down Expand Up @@ -1060,7 +1060,7 @@ public BlockBlobItem commitBlockList(List<String> base64BlockIds, boolean overwr
* <!-- src_embed com.azure.storage.blob.specialized.BlockBlobClient.uploadFromFile#List-BlobHttpHeaders-Map-AccessTier-BlobRequestConditions-Duration-Context -->
* <pre>
* BlobHttpHeaders headers = new BlobHttpHeaders&#40;&#41;
* .setContentMd5&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;
* .setContentMd5&#40;MessageDigest.getInstance&#40;&quot;MD5&quot;&#41;.digest&#40;&quot;data&quot;.getBytes&#40;StandardCharsets.UTF_8&#41;&#41;&#41;
* .setContentLanguage&#40;&quot;en-US&quot;&#41;
* .setContentType&#40;&quot;binary&quot;&#41;;
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,11 @@ public void uploadFromFile3() {
BlobRequestConditions requestConditions = new BlobRequestConditions()
.setLeaseId(leaseId)
.setIfUnmodifiedSince(OffsetDateTime.now().minusDays(3));
Long blockSize = 100 * 1024 * 1024L; // 100 MB;

client.uploadFromFileWithResponse(new BlobUploadFromFileOptions(filePath)
.setParallelTransferOptions(
new ParallelTransferOptions().setBlockSizeLong(BlobAsyncClient.BLOB_MAX_UPLOAD_BLOCK_SIZE))
new ParallelTransferOptions().setBlockSizeLong(blockSize))
.setHeaders(headers).setMetadata(metadata).setTags(tags).setTier(AccessTier.HOT)
.setRequestConditions(requestConditions))
.doOnError(throwable -> System.err.printf("Failed to upload from file %s%n", throwable.getMessage()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
*/
@SuppressWarnings("unused")
public class BlobClientJavaDocCodeSnippets {
private BlobClient client = JavaDocCodeSnippetsHelpers.getBlobClient("blobName");
private BlobClient client = new BlobClientBuilder().endpoint("https://storageaccount.blob.core.windows.net")
.containerName("containerName").blobName("blobName").sasToken("sasToken").buildClient();
private String leaseId = "leaseId";
private String copyId = "copyId";
private String url = "https://sample.com";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import com.azure.core.util.BinaryData;
import com.azure.core.util.Context;
import com.azure.core.util.polling.PollerFlux;
import com.azure.storage.blob.BlobAsyncClient;
import com.azure.storage.blob.BlobClientBuilder;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.blob.BlobServiceVersion;
import com.azure.storage.blob.models.AccessTier;
import com.azure.storage.blob.models.BlobBeginCopySourceRequestConditions;
import com.azure.storage.blob.models.BlobImmutabilityPolicy;
Expand Down Expand Up @@ -56,8 +57,8 @@
*/
@SuppressWarnings("unused")
public class BlobAsyncClientBaseJavaDocCodeSnippets {
private BlobAsyncClientBase client = new BlobAsyncClientBase(null, null, BlobServiceVersion.getLatest(),
null, null, null, null, null, null, null);
private BlobAsyncClient client = new BlobClientBuilder().endpoint("https://storageaccount.blob.core.windows.net")
.containerName("containerName").blobName("blobName").sasToken("sasToken").buildAsyncClient();
private String leaseId = "leaseId";
private String tags = "tags";
private String copyId = "copyId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.azure.core.util.polling.LongRunningOperationStatus;
import com.azure.core.util.polling.PollResponse;
import com.azure.core.util.polling.SyncPoller;
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobClientBuilder;
import com.azure.storage.blob.BlobServiceClientBuilder;
import com.azure.storage.blob.models.BlobBeginCopySourceRequestConditions;
import com.azure.storage.blob.models.BlobDownloadContentResponse;
Expand Down Expand Up @@ -63,7 +65,8 @@
*/
@SuppressWarnings("unused")
public class BlobClientBaseJavaDocCodeSnippets {
private BlobClientBase client = new BlobClientBase(null);
private BlobClient client = new BlobClientBuilder().endpoint("https://storageaccount.blob.core.windows.net")
.containerName("containerName").blobName("blobName").sasToken("sasToken").buildClient();
private String leaseId = "leaseId";
private String tags = "tags";
private String copyId = "copyId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void uploadWithOverwriteWithBinaryData() throws IOException {
public void upload2() throws NoSuchAlgorithmException {
// BEGIN: com.azure.storage.blob.specialized.BlockBlobClient.uploadWithResponse#InputStream-long-BlobHttpHeaders-Map-AccessTier-byte-BlobRequestConditions-Duration-Context
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");

Expand Down Expand Up @@ -145,7 +145,7 @@ public void upload2() throws NoSuchAlgorithmException {
public void upload3() throws NoSuchAlgorithmException {
// BEGIN: com.azure.storage.blob.specialized.BlockBlobClient.uploadWithResponse#BlockBlobSimpleUploadOptions-Duration-Context
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");

Expand Down Expand Up @@ -197,7 +197,7 @@ public void uploadFromUrlWithOverwrite() {
public void uploadFromUrlWithResponse() throws NoSuchAlgorithmException {
// BEGIN: com.azure.storage.blob.specialized.BlockBlobClient.uploadFromUrlWithResponse#BlobUploadFromUrlOptions-Duration-Context
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");

Expand Down Expand Up @@ -382,10 +382,10 @@ public void commitBlockListWithOverwrite() {
/**
* Code snippet for {@link BlockBlobClient#commitBlockListWithResponse(List, BlobHttpHeaders, Map, AccessTier, BlobRequestConditions, Duration, Context)}
*/
public void commitBlockList2() {
public void commitBlockList2() throws NoSuchAlgorithmException {
// BEGIN: com.azure.storage.blob.specialized.BlockBlobClient.uploadFromFile#List-BlobHttpHeaders-Map-AccessTier-BlobRequestConditions-Duration-Context
BlobHttpHeaders headers = new BlobHttpHeaders()
.setContentMd5("data".getBytes(StandardCharsets.UTF_8))
.setContentMd5(MessageDigest.getInstance("MD5").digest("data".getBytes(StandardCharsets.UTF_8)))
.setContentLanguage("en-US")
.setContentType("binary");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ public Response<PathInfo> setPermissionsWithResponse(PathPermissions permissions
* <pre>
* PathAccessControlEntry pathAccessControlEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.USER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;&#41;;
* List&lt;PathAccessControlEntry&gt; pathAccessControlEntries = new ArrayList&lt;&gt;&#40;&#41;;
* pathAccessControlEntries.add&#40;pathAccessControlEntry&#41;;
Expand Down Expand Up @@ -748,11 +749,26 @@ public AccessControlChangeResult setAccessControlRecursive(List<PathAccessContro
* <!-- src_embed com.azure.storage.file.datalake.DataLakePathClient.setAccessControlRecursiveWithResponse#PathSetAccessControlRecursiveOptions-Duration-Context -->
* <pre>
* DataLakeRequestConditions requestConditions = new DataLakeRequestConditions&#40;&#41;.setLeaseId&#40;leaseId&#41;;
* PathAccessControlEntry pathAccessControlEntry = new PathAccessControlEntry&#40;&#41;
* PathAccessControlEntry ownerEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;&#41;;
* .setAccessControlType&#40;AccessControlType.USER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;.setWritePermission&#40;true&#41;
* .setExecutePermission&#40;true&#41;&#41;;
*
* PathAccessControlEntry groupEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.GROUP&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;.setWritePermission&#40;true&#41;&#41;;
*
* PathAccessControlEntry otherEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.OTHER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;&#41;;
*
* List&lt;PathAccessControlEntry&gt; pathAccessControlEntries = new ArrayList&lt;&gt;&#40;&#41;;
* pathAccessControlEntries.add&#40;pathAccessControlEntry&#41;;
* pathAccessControlEntries.add&#40;ownerEntry&#41;;
* pathAccessControlEntries.add&#40;groupEntry&#41;;
* pathAccessControlEntries.add&#40;otherEntry&#41;;
*
* Integer batchSize = 2;
* Integer maxBatches = 10;
Expand Down Expand Up @@ -806,11 +822,26 @@ public Response<AccessControlChangeResult> setAccessControlRecursiveWithResponse
*
* <!-- src_embed com.azure.storage.file.datalake.DataLakePathClient.updateAccessControlRecursive#List -->
* <pre>
* PathAccessControlEntry pathAccessControlEntry = new PathAccessControlEntry&#40;&#41;
* PathAccessControlEntry ownerEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;&#41;;
* .setAccessControlType&#40;AccessControlType.USER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;.setWritePermission&#40;true&#41;
* .setExecutePermission&#40;true&#41;&#41;;
*
* PathAccessControlEntry groupEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.GROUP&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;.setWritePermission&#40;true&#41;&#41;;
*
* PathAccessControlEntry otherEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.OTHER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;&#41;;
*
* List&lt;PathAccessControlEntry&gt; pathAccessControlEntries = new ArrayList&lt;&gt;&#40;&#41;;
* pathAccessControlEntries.add&#40;pathAccessControlEntry&#41;;
* pathAccessControlEntries.add&#40;ownerEntry&#41;;
* pathAccessControlEntries.add&#40;groupEntry&#41;;
* pathAccessControlEntries.add&#40;otherEntry&#41;;
*
* AccessControlChangeResult response = client.updateAccessControlRecursive&#40;pathAccessControlEntries&#41;;
*
Expand Down Expand Up @@ -842,11 +873,26 @@ public AccessControlChangeResult updateAccessControlRecursive(List<PathAccessCon
* <!-- src_embed com.azure.storage.file.datalake.DataLakePathClient.updateAccessControlRecursiveWithResponse#PathUpdateAccessControlRecursiveOptions-Duration-Context -->
* <pre>
* DataLakeRequestConditions requestConditions = new DataLakeRequestConditions&#40;&#41;.setLeaseId&#40;leaseId&#41;;
* PathAccessControlEntry pathAccessControlEntry = new PathAccessControlEntry&#40;&#41;
* PathAccessControlEntry ownerEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;&#41;;
* .setAccessControlType&#40;AccessControlType.USER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;.setWritePermission&#40;true&#41;
* .setExecutePermission&#40;true&#41;&#41;;
*
* PathAccessControlEntry groupEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.GROUP&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;.setReadPermission&#40;true&#41;.setWritePermission&#40;true&#41;&#41;;
*
* PathAccessControlEntry otherEntry = new PathAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.OTHER&#41;
* .setPermissions&#40;new RolePermissions&#40;&#41;&#41;;
*
* List&lt;PathAccessControlEntry&gt; pathAccessControlEntries = new ArrayList&lt;&gt;&#40;&#41;;
* pathAccessControlEntries.add&#40;pathAccessControlEntry&#41;;
* pathAccessControlEntries.add&#40;ownerEntry&#41;;
* pathAccessControlEntries.add&#40;groupEntry&#41;;
* pathAccessControlEntries.add&#40;otherEntry&#41;;
*
* Integer batchSize = 2;
* Integer maxBatches = 10;
Expand Down Expand Up @@ -900,10 +946,24 @@ public Response<AccessControlChangeResult> updateAccessControlRecursiveWithRespo
*
* <!-- src_embed com.azure.storage.file.datalake.DataLakePathClient.removeAccessControlRecursive#List -->
* <pre>
* PathRemoveAccessControlEntry pathAccessControlEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;;
* PathRemoveAccessControlEntry ownerEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.USER&#41;
* .setDefaultScope&#40;true&#41;;
*
* PathRemoveAccessControlEntry groupEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.GROUP&#41;
* .setDefaultScope&#40;true&#41;;
*
* PathRemoveAccessControlEntry otherEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.OTHER&#41;
* .setDefaultScope&#40;true&#41;;
* List&lt;PathRemoveAccessControlEntry&gt; pathAccessControlEntries = new ArrayList&lt;&gt;&#40;&#41;;
* pathAccessControlEntries.add&#40;pathAccessControlEntry&#41;;
* pathAccessControlEntries.add&#40;ownerEntry&#41;;
* pathAccessControlEntries.add&#40;groupEntry&#41;;
* pathAccessControlEntries.add&#40;otherEntry&#41;;
*
* AccessControlChangeResult response = client.removeAccessControlRecursive&#40;pathAccessControlEntries&#41;;
*
Expand Down Expand Up @@ -936,10 +996,24 @@ public AccessControlChangeResult removeAccessControlRecursive(
* <!-- src_embed com.azure.storage.file.datalake.DataLakePathClient.removeAccessControlRecursiveWithResponse#PathRemoveAccessControlRecursiveOptions-Duration-Context -->
* <pre>
* DataLakeRequestConditions requestConditions = new DataLakeRequestConditions&#40;&#41;.setLeaseId&#40;leaseId&#41;;
* PathRemoveAccessControlEntry pathAccessControlEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;;
* PathRemoveAccessControlEntry ownerEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.USER&#41;
* .setDefaultScope&#40;true&#41;;
*
* PathRemoveAccessControlEntry groupEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.GROUP&#41;
* .setDefaultScope&#40;true&#41;;
*
* PathRemoveAccessControlEntry otherEntry = new PathRemoveAccessControlEntry&#40;&#41;
* .setEntityId&#40;&quot;entityId&quot;&#41;
* .setAccessControlType&#40;AccessControlType.OTHER&#41;
* .setDefaultScope&#40;true&#41;;
* List&lt;PathRemoveAccessControlEntry&gt; pathAccessControlEntries = new ArrayList&lt;&gt;&#40;&#41;;
* pathAccessControlEntries.add&#40;pathAccessControlEntry&#41;;
* pathAccessControlEntries.add&#40;ownerEntry&#41;;
* pathAccessControlEntries.add&#40;groupEntry&#41;;
* pathAccessControlEntries.add&#40;otherEntry&#41;;
*
* Integer batchSize = 2;
* Integer maxBatches = 10;
Expand Down
Loading

0 comments on commit 5d2cfe6

Please sign in to comment.