Skip to content

Commit

Permalink
Fixed public API for file get range diff (#15562)
Browse files Browse the repository at this point in the history
  • Loading branch information
gapra-msft authored Sep 25, 2020
1 parent 95ab50a commit 2c3b254
Show file tree
Hide file tree
Showing 11 changed files with 399 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.azure.storage.file.share.models.LeaseStatusType;
import com.azure.storage.file.share.models.NtfsFileAttributes;
import com.azure.storage.file.share.models.PermissionCopyModeType;
import com.azure.storage.file.share.models.Range;
import com.azure.storage.file.share.models.ShareErrorCode;
import com.azure.storage.file.share.models.ShareFileCopyInfo;
import com.azure.storage.file.share.models.ShareFileDownloadAsyncResponse;
Expand All @@ -54,6 +55,7 @@
import com.azure.storage.file.share.models.ShareFileMetadataInfo;
import com.azure.storage.file.share.models.ShareFileProperties;
import com.azure.storage.file.share.models.ShareFileRange;
import com.azure.storage.file.share.models.ShareFileRangeList;
import com.azure.storage.file.share.models.ShareFileUploadInfo;
import com.azure.storage.file.share.models.ShareFileUploadRangeFromUrlInfo;
import com.azure.storage.file.share.models.ShareRequestConditions;
Expand Down Expand Up @@ -1614,8 +1616,7 @@ public PagedFlux<ShareFileRange> listRanges(ShareFileRange range) {
*/
public PagedFlux<ShareFileRange> listRanges(ShareFileRange range, ShareRequestConditions requestConditions) {
try {
return listRangesWithOptionalTimeout(range, requestConditions, null,
null, Context.NONE);
return listRangesWithOptionalTimeout(range, requestConditions, null, Context.NONE);
} catch (RuntimeException ex) {
return pagedFluxError(logger, ex);
}
Expand All @@ -1636,11 +1637,12 @@ public PagedFlux<ShareFileRange> listRanges(ShareFileRange range, ShareRequestCo
* snapshot, as long as the snapshot specified by previousSnapshot is the older of the two.
* @return {@link ShareFileRange ranges} in the files that satisfy the requirements
*/
public PagedFlux<ShareFileRange> listRangesDiff(String previousSnapshot) {
public Mono<ShareFileRangeList> listRangesDiff(String previousSnapshot) {
try {
return listRangesDiff(new ShareFileListRangesDiffOptions(previousSnapshot));
return listRangesDiffWithResponse(new ShareFileListRangesDiffOptions(previousSnapshot))
.map(Response::getValue);
} catch (RuntimeException ex) {
return pagedFluxError(logger, ex);
return monoError(logger, ex);
}
}

Expand All @@ -1651,45 +1653,57 @@ public PagedFlux<ShareFileRange> listRangesDiff(String previousSnapshot) {
*
* <p>List all ranges within the file range from 1KB to 2KB.</p>
*
* {@codesnippet com.azure.storage.file.share.ShareFileAsyncClient.listRangesDiff#ShareFileListRangesDiffOptions}
* {@codesnippet com.azure.storage.file.share.ShareFileAsyncClient.listRangesDiffWithResponse#ShareFileListRangesDiffOptions}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/list-ranges">Azure Docs</a>.</p>
*
* @param options {@link ShareFileListRangesDiffOptions}.
* @return {@link ShareFileRange ranges} in the files that satisfy the requirements
*/
public PagedFlux<ShareFileRange> listRangesDiff(ShareFileListRangesDiffOptions options) {
public Mono<Response<ShareFileRangeList>> listRangesDiffWithResponse(ShareFileListRangesDiffOptions options) {
try {
StorageImplUtils.assertNotNull("options", options);
return listRangesWithOptionalTimeout(options.getRange(), options.getRequestConditions(),
options.getPreviousSnapshot(), null, Context.NONE);
return listRangesWithResponse(options.getRange(), options.getRequestConditions(),
options.getPreviousSnapshot(), Context.NONE);
} catch (RuntimeException ex) {
return pagedFluxError(logger, ex);
return monoError(logger, ex);
}
}

PagedFlux<ShareFileRange> listRangesWithOptionalTimeout(ShareFileRange range,
ShareRequestConditions requestConditions, String previousSnapshot, Duration timeout,
ShareRequestConditions requestConditions, Duration timeout,
Context context) {

ShareRequestConditions finalRequestConditions = requestConditions == null
? new ShareRequestConditions() : requestConditions;
String rangeString = range == null ? null : range.toString();
Function<String, Mono<PagedResponse<ShareFileRange>>> retriever =
marker -> StorageImplUtils.applyOptionalTimeout(this.azureFileStorageClient.files()
.getRangeListWithRestResponseAsync(shareName, filePath, snapshot, previousSnapshot,
null, rangeString, finalRequestConditions.getLeaseId(), context), timeout)
marker -> StorageImplUtils.applyOptionalTimeout(
this.listRangesWithResponse(range, requestConditions, null, context), timeout)
.map(response -> new PagedResponseBase<>(response.getRequest(),
response.getStatusCode(),
response.getHeaders(),
response.getValue().stream().map(ShareFileRange::new).collect(Collectors.toList()),
response.getValue().getRanges().stream()
.map(r -> new Range().setStart(r.getStart()).setEnd(r.getEnd()))
.map(ShareFileRange::new).collect(Collectors.toList()),
null,
response.getDeserializedHeaders()));
response.getHeaders()));

return new PagedFlux<>(() -> retriever.apply(null), retriever);
}

Mono<Response<ShareFileRangeList>> listRangesWithResponse(ShareFileRange range,
ShareRequestConditions requestConditions, String previousSnapshot, Context context) {

ShareRequestConditions finalRequestConditions = requestConditions == null
? new ShareRequestConditions() : requestConditions;
String rangeString = range == null ? null : range.toString();
context = context == null ? Context.NONE : context;

return this.azureFileStorageClient.files().getRangeListWithRestResponseAsync(shareName, filePath, snapshot,
previousSnapshot, null, rangeString, finalRequestConditions.getLeaseId(),
context.addData(AZ_TRACING_NAMESPACE_KEY, STORAGE_TRACING_NAMESPACE_VALUE))
.map(response -> new SimpleResponse<>(response, response.getValue()));
}

/**
* List of open handles on a file.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.azure.storage.file.share.models.ShareFileMetadataInfo;
import com.azure.storage.file.share.models.ShareFileProperties;
import com.azure.storage.file.share.models.ShareFileRange;
import com.azure.storage.file.share.models.ShareFileRangeList;
import com.azure.storage.file.share.models.ShareRequestConditions;
import com.azure.storage.file.share.models.ShareStorageException;
import com.azure.storage.file.share.models.ShareFileUploadInfo;
Expand Down Expand Up @@ -1243,7 +1244,7 @@ public PagedIterable<ShareFileRange> listRanges(ShareFileRange range, Duration t
*/
public PagedIterable<ShareFileRange> listRanges(ShareFileRange range, ShareRequestConditions requestConditions,
Duration timeout, Context context) {
return new PagedIterable<>(shareFileAsyncClient.listRangesWithOptionalTimeout(range, requestConditions, null,
return new PagedIterable<>(shareFileAsyncClient.listRangesWithOptionalTimeout(range, requestConditions,
timeout, context));
}

Expand All @@ -1254,23 +1255,20 @@ public PagedIterable<ShareFileRange> listRanges(ShareFileRange range, ShareReque
*
* <p>List all ranges within the file range from 1KB to 2KB.</p>
*
* {@codesnippet com.azure.storage.file.share.ShareFileClient.listRangesDiff#String-Duration-Context}
* {@codesnippet com.azure.storage.file.share.ShareFileClient.listRangesDiff#String}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/list-ranges">Azure Docs</a>.</p>
*
* @param previousSnapshot Specifies that the response will contain only ranges that were changed between target
* file and previous snapshot. Changed ranges include both updated and cleared ranges. The target file may be a
* snapshot, as long as the snapshot specified by previousSnapshot is the older of the two.
* @param timeout An optional timeout applied to the operation. If a response is not returned before the timeout
* concludes a {@link RuntimeException} will be thrown.
* @param context Additional context that is passed through the Http pipeline during the service call.
* @return {@link ShareFileRange ranges} in the files that satisfy the requirements
* @throws RuntimeException if the operation doesn't complete before the timeout concludes.
*/
public PagedIterable<ShareFileRange> listRangesDiff(String previousSnapshot, Duration timeout,
Context context) {
return this.listRangesDiff(new ShareFileListRangesDiffOptions(previousSnapshot), timeout, context);
public ShareFileRangeList listRangesDiff(String previousSnapshot) {
return this.listRangesDiffWithResponse(new ShareFileListRangesDiffOptions(previousSnapshot), null, Context.NONE)
.getValue();
}

/**
Expand All @@ -1280,7 +1278,7 @@ public PagedIterable<ShareFileRange> listRangesDiff(String previousSnapshot, Dur
*
* <p>List all ranges within the file range from 1KB to 2KB.</p>
*
* {@codesnippet com.azure.storage.file.share.ShareFileClient.listRangesDiff#ShareFileListRangesDiffOptions-Duration-Context}
* {@codesnippet com.azure.storage.file.share.ShareFileClient.listRangesDiffWithResponse#ShareFileListRangesDiffOptions-Duration-Context}
*
* <p>For more information, see the
* <a href="https://docs.microsoft.com/en-us/rest/api/storageservices/list-ranges">Azure Docs</a>.</p>
Expand All @@ -1292,12 +1290,13 @@ public PagedIterable<ShareFileRange> listRangesDiff(String previousSnapshot, Dur
* @return {@link ShareFileRange ranges} in the files that satisfy the requirements
* @throws RuntimeException if the operation doesn't complete before the timeout concludes.
*/
public PagedIterable<ShareFileRange> listRangesDiff(ShareFileListRangesDiffOptions options, Duration timeout,
Context context) {
public Response<ShareFileRangeList> listRangesDiffWithResponse(ShareFileListRangesDiffOptions options,
Duration timeout, Context context) {
StorageImplUtils.assertNotNull("options", options);
return new PagedIterable<>(shareFileAsyncClient.listRangesWithOptionalTimeout(options.getRange(),
options.getRequestConditions(), options.getPreviousSnapshot(), timeout,
context));
Mono<Response<ShareFileRangeList>> response = shareFileAsyncClient.listRangesWithResponse(options.getRange(),
options.getRequestConditions(), options.getPreviousSnapshot(), context);

return StorageImplUtils.blockWithOptionalTimeout(response, timeout);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
import com.azure.core.http.HttpHeaders;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.rest.ResponseBase;
import com.azure.storage.file.share.models.Range;
import java.util.List;
import com.azure.storage.file.share.models.ShareFileRangeList;

/**
* Contains all response data for the getRangeList operation.
*/
public final class FilesGetRangeListResponse extends ResponseBase<FileGetRangeListHeaders, List<Range>> {
public final class FilesGetRangeListResponse extends ResponseBase<FileGetRangeListHeaders, ShareFileRangeList> {
/**
* Creates an instance of FilesGetRangeListResponse.
*
Expand All @@ -23,15 +22,15 @@ public final class FilesGetRangeListResponse extends ResponseBase<FileGetRangeLi
* @param value the deserialized value of the HTTP response.
* @param headers the deserialized headers of the HTTP response.
*/
public FilesGetRangeListResponse(HttpRequest request, int statusCode, HttpHeaders rawHeaders, List<Range> value, FileGetRangeListHeaders headers) {
public FilesGetRangeListResponse(HttpRequest request, int statusCode, HttpHeaders rawHeaders, ShareFileRangeList value, FileGetRangeListHeaders headers) {
super(request, statusCode, rawHeaders, value, headers);
}

/**
* @return the deserialized response body.
*/
@Override
public List<Range> getValue() {
public ShareFileRangeList getValue() {
return super.getValue();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.file.share.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

/**
* The ClearRange model.
*/
@JacksonXmlRootElement(localName = "ClearRange")
@Fluent
public final class ClearRange {
/*
* The start property.
*/
@JsonProperty(value = "Start", required = true)
private long start;

/*
* The end property.
*/
@JsonProperty(value = "End", required = true)
private long end;

/**
* Get the start property: The start property.
*
* @return the start value.
*/
public long getStart() {
return this.start;
}

/**
* Set the start property: The start property.
*
* @param start the start value to set.
* @return the ClearRange object itself.
*/
public ClearRange setStart(long start) {
this.start = start;
return this;
}

/**
* Get the end property: The end property.
*
* @return the end value.
*/
public long getEnd() {
return this.end;
}

/**
* Set the end property: The end property.
*
* @param end the end value to set.
* @return the ClearRange object itself.
*/
public ClearRange setEnd(long end) {
this.end = end;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.storage.file.share.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;

/**
* An Azure Storage file range.
*/
@JacksonXmlRootElement(localName = "Range")
@Fluent
public final class FileRange {
/*
* Start of the range.
*/
@JsonProperty(value = "Start", required = true)
private long start;

/*
* End of the range.
*/
@JsonProperty(value = "End", required = true)
private long end;

/**
* Get the start property: Start of the range.
*
* @return the start value.
*/
public long getStart() {
return this.start;
}

/**
* Set the start property: Start of the range.
*
* @param start the start value to set.
* @return the FileRange object itself.
*/
public FileRange setStart(long start) {
this.start = start;
return this;
}

/**
* Get the end property: End of the range.
*
* @return the end value.
*/
public long getEnd() {
return this.end;
}

/**
* Set the end property: End of the range.
*
* @param end the end value to set.
* @return the FileRange object itself.
*/
public FileRange setEnd(long end) {
this.end = end;
return this;
}
}
Loading

0 comments on commit 2c3b254

Please sign in to comment.