From 1b9997820b4f108674219e3a446a4d6bfff2172c Mon Sep 17 00:00:00 2001 From: Isabelle <141270045+ibrandes@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:34:06 -0700 Subject: [PATCH] adding timeout parameter for new apis (#41887) --- .../azure-storage-file-share/assets.json | 2 +- .../azure/storage/file/share/ShareClient.java | 26 +++++++++++++------ .../file/share/ShareJavaDocCodeSamples.java | 10 +++---- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/sdk/storage/azure-storage-file-share/assets.json b/sdk/storage/azure-storage-file-share/assets.json index 182f046d4964d..bfd52aee9018a 100644 --- a/sdk/storage/azure-storage-file-share/assets.json +++ b/sdk/storage/azure-storage-file-share/assets.json @@ -2,5 +2,5 @@ "AssetsRepo": "Azure/azure-sdk-assets", "AssetsRepoPrefixPath": "java", "TagPrefix": "java/storage/azure-storage-file-share", - "Tag": "java/storage/azure-storage-file-share_0ba84ce27c" + "Tag": "java/storage/azure-storage-file-share_4152d3ba84" } diff --git a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareClient.java b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareClient.java index e61fa58dcf0e0..d7daf1f07ab67 100644 --- a/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareClient.java +++ b/sdk/storage/azure-storage-file-share/src/main/java/com/azure/storage/file/share/ShareClient.java @@ -1946,7 +1946,7 @@ public String createPermission(String filePermission) { */ @ServiceMethod(returns = ReturnType.SINGLE) public String createPermission(ShareFilePermission filePermission) { - return createPermissionWithResponse(filePermission, Context.NONE).getValue(); + return createPermissionWithResponse(filePermission, null, Context.NONE).getValue(); } /** @@ -1986,23 +1986,27 @@ public Response createPermissionWithResponse(String filePermission, Cont *
      * ShareFilePermission permission = new ShareFilePermission().setPermission("filePermission")
      *     .setPermissionFormat(FilePermissionFormat.BINARY);
-     * Response<String> response1 = shareClient.createPermissionWithResponse(permission, Context.NONE);
+     * Response<String> response1 = shareClient.createPermissionWithResponse(permission, null, Context.NONE);
      * System.out.printf("The file permission key is %s", response1.getValue());
      * 
* * * @param filePermission The file permission to get/create. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @param context Additional context that is passed through the Http pipeline during the service call. * @return A response that contains the file permission key associated with the file permission. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createPermissionWithResponse(ShareFilePermission filePermission, Context context) { + public Response createPermissionWithResponse(ShareFilePermission filePermission, Duration timeout, Context context) { Context finalContext = context == null ? Context.NONE : context; SharePermission sharePermission = new SharePermission().setPermission(filePermission.getPermission()) .setFormat(filePermission.getPermissionFormat()); - ResponseBase response = this.azureFileStorageClient.getShares() + + Callable> operation = () -> this.azureFileStorageClient.getShares() .createPermissionWithResponse(shareName, sharePermission, null, finalContext); + ResponseBase response = sendRequest(operation, timeout, ShareStorageException.class); + return new SimpleResponse<>(response, response.getDeserializedHeaders().getXMsFilePermissionKey()); } @@ -2048,7 +2052,7 @@ public String getPermission(String filePermissionKey) { */ @ServiceMethod(returns = ReturnType.SINGLE) public String getPermission(String filePermissionKey, FilePermissionFormat filePermissionFormat) { - return getPermissionWithResponse(filePermissionKey, filePermissionFormat, Context.NONE).getValue(); + return getPermissionWithResponse(filePermissionKey, filePermissionFormat, null, Context.NONE).getValue(); } /** @@ -2085,7 +2089,7 @@ public Response getPermissionWithResponse(String filePermissionKey, Cont *
      * FilePermissionFormat filePermissionFormat = FilePermissionFormat.BINARY;
      * Response<String> response1 = shareClient.getPermissionWithResponse("filePermissionKey",
-     *     filePermissionFormat, Context.NONE);
+     *     filePermissionFormat, null, Context.NONE);
      * System.out.printf("The file permission is %s", response1.getValue());
      * 
* @@ -2095,15 +2099,21 @@ public Response getPermissionWithResponse(String filePermissionKey, Cont * the permission is returned. If filePermissionFormat is unspecified or explicitly set to SDDL, the permission will * be returned in SSDL format. If filePermissionFormat is explicity set to binary, the permission is returned as a * base64 string representing the binary encoding of the permission in self-relative format. + * @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised. * @param context Additional context that is passed through the Http pipeline during the service call. * @return A response that contains th file permission associated with the file permission key. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response getPermissionWithResponse(String filePermissionKey, FilePermissionFormat filePermissionFormat, Context context) { + public Response getPermissionWithResponse(String filePermissionKey, FilePermissionFormat filePermissionFormat, + Duration timeout, Context context) { Context finalContext = context == null ? Context.NONE : context; - ResponseBase response = this.azureFileStorageClient.getShares() + + Callable> operation = () -> this.azureFileStorageClient.getShares() .getPermissionWithResponse(shareName, filePermissionKey, filePermissionFormat, null, finalContext); + ResponseBase response = sendRequest(operation, timeout, + ShareStorageException.class); + return new SimpleResponse<>(response, response.getValue().getPermission()); } diff --git a/sdk/storage/azure-storage-file-share/src/samples/java/com/azure/storage/file/share/ShareJavaDocCodeSamples.java b/sdk/storage/azure-storage-file-share/src/samples/java/com/azure/storage/file/share/ShareJavaDocCodeSamples.java index cec2c4ab5e400..0f015111831b2 100644 --- a/sdk/storage/azure-storage-file-share/src/samples/java/com/azure/storage/file/share/ShareJavaDocCodeSamples.java +++ b/sdk/storage/azure-storage-file-share/src/samples/java/com/azure/storage/file/share/ShareJavaDocCodeSamples.java @@ -671,7 +671,7 @@ public void createPermissionAsync() { /** * Generates a code sample for using {@link ShareClient#createPermissionWithResponse(String, Context)} and - * {@link ShareClient#createPermissionWithResponse(ShareFilePermission, Context)} + * {@link ShareClient#createPermissionWithResponse(ShareFilePermission, Duration, Context)} */ public void createPermissionWithResponse() { ShareClient shareClient = createClientWithSASToken(); @@ -683,7 +683,7 @@ public void createPermissionWithResponse() { // BEGIN: com.azure.storage.file.share.ShareClient.createPermissionWithResponse#ShareFilePermission-context ShareFilePermission permission = new ShareFilePermission().setPermission("filePermission") .setPermissionFormat(FilePermissionFormat.BINARY); - Response response1 = shareClient.createPermissionWithResponse(permission, Context.NONE); + Response response1 = shareClient.createPermissionWithResponse(permission, null, Context.NONE); System.out.printf("The file permission key is %s", response1.getValue()); // END: com.azure.storage.file.share.ShareClient.createPermissionWithResponse#ShareFilePermission-context } @@ -708,7 +708,7 @@ public void getPermission() { /** * Generates a code sample for using {@link ShareClient#getPermissionWithResponse(String, Context)} and - * {@link ShareClient#getPermissionWithResponse(String, FilePermissionFormat, Context)} + * {@link ShareClient#getPermissionWithResponse(String, FilePermissionFormat, Duration, Context)} */ public void getPermissionWithResponse() { ShareClient shareClient = createClientWithSASToken(); @@ -720,11 +720,9 @@ public void getPermissionWithResponse() { // BEGIN: com.azure.storage.file.share.ShareClient.getPermissionWithResponse#string-FilePermissionFormat-context FilePermissionFormat filePermissionFormat = FilePermissionFormat.BINARY; Response response1 = shareClient.getPermissionWithResponse("filePermissionKey", - filePermissionFormat, Context.NONE); + filePermissionFormat, null, Context.NONE); System.out.printf("The file permission is %s", response1.getValue()); // END: com.azure.storage.file.share.ShareClient.getPermissionWithResponse#string-FilePermissionFormat-context - - } /**