Skip to content

Commit

Permalink
Add tracing context in Storage Files (Azure#4888)
Browse files Browse the repository at this point in the history
  • Loading branch information
samvaity authored Aug 22, 2019
1 parent 88f4a6f commit 64efc1b
Show file tree
Hide file tree
Showing 31 changed files with 3,703 additions and 1,777 deletions.
16 changes: 9 additions & 7 deletions sdk/storage/azure-storage-file/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ Taking the directoryClient in KeyConcept, [`${directoryClient}`](#Directory) .

```Java
String fileName = "testfile";
directoryClient.createFile(fileName);
long maxSize = 1024;
directoryClient.createFile(fileName, maxSize);
```

### List all Shares
Expand Down Expand Up @@ -306,14 +307,14 @@ Taking the fileClient in KeyConcept, [`${fileClient}`](#File) with string of sou

```Java
String sourceURL = "https://myaccount.file.core.windows.net/myshare/myfile";
Response<FileCopyInfo> copyInfoResponse = fileClient.startCopy(sourceURL, null);
FileCopyInfo copyInfo = fileClient.startCopy(sourceURL, null);
```

### Abort copy a file
Taking the fileClient in KeyConcept, [`${fileClient}`](#File) with the copy info response returned above `${copyId}=[copyInfoResponse](#Copy-a-file)`.

```Java
String copyId = copyInfoResponse.value().copyId();
String copyId = copyInfoResponse.copyId();
fileClient.abortCopy(copyId);
```

Expand All @@ -336,7 +337,7 @@ fileClient.uploadFromFile(filePath);
Taking the fileClient in KeyConcept, [`${fileClient}`](#File) with the range from 1024 to 2048.
```Java
FileRange fileRange = new FileRange(1024, 2047);
fileClient.downloadWithProperties(fileRange, false);
fileClient.downloadWithProperties(fileRange, false, null);
```

### Download file from storage
Expand All @@ -357,12 +358,12 @@ fileServiceClient.getProperties();
Taking a FileServiceClient in KeyConcept, [`${fileServiceClient}`](#File-services) .

```Java
FileServiceProperties properties = fileServiceClient.getProperties().value();
FileServiceProperties properties = fileServiceClient.getProperties();

properties.minuteMetrics().enabled(true);
properties.hourMetrics().enabled(true);

VoidResponse response = fileServiceClient.setProperties(properties);
fileServiceClient.setProperties(properties);
```

### Set a share metadata
Expand Down Expand Up @@ -420,7 +421,8 @@ Taking the fileClient in KeyConcept, [`${fileClient}`](#File) .

```Java
FileHTTPHeaders httpHeaders = new FileHTTPHeaders().fileContentType("text/plain");
fileClient.setHttpHeaders(httpHeaders);
long newFileSize = 1024;
fileClient.setHttpHeaders(newFileSize, httpHeaders);
```

## Troubleshooting
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.SimpleResponse;
import com.azure.core.http.rest.VoidResponse;
import com.azure.core.implementation.util.FluxUtil;
import com.azure.core.implementation.util.ImplUtils;
import com.azure.core.util.Context;
import com.azure.core.util.logging.ClientLogger;
Expand All @@ -32,6 +33,8 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import static com.azure.core.implementation.util.FluxUtil.withContext;

/**
* This class provides a azureFileStorageClient that contains all the operations for interacting with a file account in Azure Storage.
* Operations allowed by the azureFileStorageClient are creating, listing, and deleting shares and retrieving and updating properties
Expand Down Expand Up @@ -207,13 +210,70 @@ private Publisher<ShareItem> extractAndFetchShares(ServicesListSharesSegmentResp
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-service-properties">Azure Docs</a>.</p>
*
* @return Storage account File service properties
* @return Storage account {@link FileServiceProperties File service properties}
*/
public Mono<Response<FileServiceProperties>> getProperties() {
return azureFileStorageClient.services().getPropertiesWithRestResponseAsync(Context.NONE)
public Mono<FileServiceProperties> getProperties() {
return getPropertiesWithResponse().flatMap(FluxUtil::toMono);
}

/**
* Retrieves the properties of the storage account's File service. The properties range from storage analytics and
* metrics to CORS (Cross-Origin Resource Sharing).
*
* <p><strong>Code Samples</strong></p>
*
* <p>Retrieve File service properties</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.getPropertiesWithResponse}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/get-file-service-properties">Azure Docs</a>.</p>
*
* @return A response containing the Storage account {@link FileServiceProperties File service properties}
*/
public Mono<Response<FileServiceProperties>> getPropertiesWithResponse() {
return withContext(context -> getPropertiesWithResponse(context));
}

Mono<Response<FileServiceProperties>> getPropertiesWithResponse(Context context) {
return azureFileStorageClient.services().getPropertiesWithRestResponseAsync(context)
.map(response -> new SimpleResponse<>(response, response.value()));
}

/**
* Sets the properties for the storage account's File service. The properties range from storage analytics and
* metric to CORS (Cross-Origin Resource Sharing).
*
* To maintain the CORS in the Queue service pass a {@code null} value for {@link FileServiceProperties#cors() CORS}.
* To disable all CORS in the Queue service pass an empty list for {@link FileServiceProperties#cors() CORS}.
*
* <p><strong>Code Sample</strong></p>
*
* <p>Enable Minute and Hour Metrics</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.setProperties#fileServiceProperties}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties">Azure Docs</a>.</p>
*
* @param properties Storage account File service properties
* @return An empty response
* @throws StorageErrorException When one of the following is true
* <ul>
* <li>A CORS rule is missing one of its fields</li>
* <li>More than five CORS rules will exist for the Queue service</li>
* <li>Size of all CORS rules exceeds 2KB</li>
* <li>
* Length of {@link CorsRule#allowedHeaders() allowed headers}, {@link CorsRule#exposedHeaders() exposed headers},
* or {@link CorsRule#allowedOrigins() allowed origins} exceeds 256 characters.
* </li>
* <li>{@link CorsRule#allowedMethods() Allowed methods} isn't DELETE, GET, HEAD, MERGE, POST, OPTIONS, or PUT</li>
* </ul>
*/
public Mono<Void> setProperties(FileServiceProperties properties) {
return setPropertiesWithResponse(properties).flatMap(FluxUtil::toMono);
}

/**
* Sets the properties for the storage account's File service. The properties range from storage analytics and
* metric to CORS (Cross-Origin Resource Sharing).
Expand All @@ -225,11 +285,11 @@ public Mono<Response<FileServiceProperties>> getProperties() {
*
* <p>Clear CORS in the File service</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.setProperties#fileServiceProperties.clearCORS}
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.setPropertiesWithResponse#fileServiceProperties.clearCORS}
*
* <p>Enable Minute and Hour Metrics</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.setProperties#fileServiceProperties}
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.setPropertiesWithResponseAsync#fileServiceProperties}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/set-file-service-properties">Azure Docs</a>.</p>
Expand All @@ -248,8 +308,12 @@ public Mono<Response<FileServiceProperties>> getProperties() {
* <li>{@link CorsRule#allowedMethods() Allowed methods} isn't DELETE, GET, HEAD, MERGE, POST, OPTIONS, or PUT</li>
* </ul>
*/
public Mono<VoidResponse> setProperties(FileServiceProperties properties) {
return azureFileStorageClient.services().setPropertiesWithRestResponseAsync(properties, Context.NONE)
public Mono<VoidResponse> setPropertiesWithResponse(FileServiceProperties properties) {
return withContext(context -> setPropertiesWithResponse(properties, context));
}

Mono<VoidResponse> setPropertiesWithResponse(FileServiceProperties properties, Context context) {
return azureFileStorageClient.services().setPropertiesWithRestResponseAsync(properties, context)
.map(VoidResponse::new);
}

Expand All @@ -266,11 +330,11 @@ public Mono<VoidResponse> setProperties(FileServiceProperties properties) {
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/create-share">Azure Docs</a>.</p>
*
* @param shareName Name of the share
* @return A response containing the ShareAsyncClient and the status of creating the share.
* @return The {@link ShareAsyncClient ShareAsyncClient}
* @throws StorageErrorException If a share with the same name already exists
*/
public Mono<Response<ShareAsyncClient>> createShare(String shareName) {
return createShare(shareName, null, null);
public Mono<ShareAsyncClient> createShare(String shareName) {
return createShareWithResponse(shareName, null, null).flatMap(FluxUtil::toMono);
}

/**
Expand All @@ -281,11 +345,11 @@ public Mono<Response<ShareAsyncClient>> createShare(String shareName) {
*
* <p>Create the share "test" with metadata "share:metadata"</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.createShare#string-map-integer.metadata}
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.createShareWithResponse#string-map-integer.metadata}
*
* <p>Create the share "test" with a quota of 10 GB</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.createShare#string-map-integer.quota}
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.createShareWithResponse#string-map-integer.quota}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/create-share">Azure Docs</a>.</p>
Expand All @@ -294,14 +358,18 @@ public Mono<Response<ShareAsyncClient>> createShare(String shareName) {
* @param metadata Optional metadata to associate with the share
* @param quotaInGB Optional maximum size the share is allowed to grow to in GB. This must be greater than 0 and
* less than or equal to 5120. The default value is 5120.
* @return A response containing the ShareAsyncClient and the status of creating the share.
* @return A response containing the {@link ShareAsyncClient ShareAsyncClient} and the status of creating the share.
* @throws StorageErrorException If a share with the same name already exists or {@code quotaInGB} is outside the
* allowed range.
*/
public Mono<Response<ShareAsyncClient>> createShare(String shareName, Map<String, String> metadata, Integer quotaInGB) {
public Mono<Response<ShareAsyncClient>> createShareWithResponse(String shareName, Map<String, String> metadata, Integer quotaInGB) {
return withContext(context -> createShareWithResponse(shareName, metadata, quotaInGB, context));
}

Mono<Response<ShareAsyncClient>> createShareWithResponse(String shareName, Map<String, String> metadata, Integer quotaInGB, Context context) {
ShareAsyncClient shareAsyncClient = new ShareAsyncClient(azureFileStorageClient, shareName);

return shareAsyncClient.create(metadata, quotaInGB)
return shareAsyncClient.createWithResponse(metadata, quotaInGB, context)
.map(response -> new SimpleResponse<>(response, shareAsyncClient));
}

Expand All @@ -318,11 +386,11 @@ public Mono<Response<ShareAsyncClient>> createShare(String shareName, Map<String
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share">Azure Docs</a>.</p>
*
* @param shareName Name of the share
* @return A response that only contains headers and response status code
* @return An empty response
* @throws StorageErrorException If the share doesn't exist
*/
public Mono<VoidResponse> deleteShare(String shareName) {
return deleteShare(shareName, null);
public Mono<Void> deleteShare(String shareName) {
return deleteShareWithResponse(shareName, null).flatMap(FluxUtil::toMono);
}

/**
Expand All @@ -333,7 +401,7 @@ public Mono<VoidResponse> deleteShare(String shareName) {
*
* <p>Delete the snapshot of share "test" that was created at current time.</p>
*
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.deleteShare#string-string}
* {@codesnippet com.azure.storage.file.fileServiceAsyncClient.deleteShareWithResponse#string-string}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/delete-share">Azure Docs</a>.</p>
Expand All @@ -343,12 +411,16 @@ public Mono<VoidResponse> deleteShare(String shareName) {
* @return A response that only contains headers and response status code
* @throws StorageErrorException If the share doesn't exist or the snapshot doesn't exist
*/
public Mono<VoidResponse> deleteShare(String shareName, String snapshot) {
public Mono<VoidResponse> deleteShareWithResponse(String shareName, String snapshot) {
return withContext(context -> deleteShareWithResponse(shareName, snapshot, context));
}

Mono<VoidResponse> deleteShareWithResponse(String shareName, String snapshot, Context context) {
DeleteSnapshotsOptionType deleteSnapshots = null;
if (ImplUtils.isNullOrEmpty(snapshot)) {
deleteSnapshots = DeleteSnapshotsOptionType.fromString(DeleteSnapshotsOptionType.INCLUDE.toString());
}
return azureFileStorageClient.shares().deleteWithRestResponseAsync(shareName, snapshot, null, deleteSnapshots, Context.NONE)
return azureFileStorageClient.shares().deleteWithRestResponseAsync(shareName, snapshot, null, deleteSnapshots, context)
.map(VoidResponse::new);
}

Expand Down
Loading

0 comments on commit 64efc1b

Please sign in to comment.