-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Implement LRO rehydration with static method #42686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
4de315b
Implement LRO rehydration with static method
live1206 8c361fa
update test
live1206 516a77d
Add type constraint.
live1206 2f6bd66
update API
live1206 619c6ed
implement GetRehydrationToken
live1206 fb08623
cleanup
live1206 9f03f88
remove duplicates
live1206 ed0cf59
Merge branch 'main' into rehydration-static-method
live1206 e47d85e
address comments
live1206 e9e3c79
Make rawResponse non-nullable
live1206 70bc5c0
UpdaateStatus during LRO rehydration to get the latest state
live1206 c27d863
update for final get of delete LRO and add test for it
live1206 2843500
fix test
live1206 1231a36
update changelog and test
live1206 adc9277
cleanup
live1206 544068b
address comments
live1206 695bbed
Add async rehdyrate methods
live1206 3b040be
update
live1206 e86c766
fix for imcomplete nextRequesturi
live1206 6e2eb4a
remove unneeded test
live1206 71e65b8
Address comments
live1206 ebadd2c
make OpetaionId nullable
live1206 812b8ea
update tests
live1206 b4668a8
Add comments
live1206 cac95fc
update
live1206 f9f0ca8
cleanup
live1206 a501c92
Merge branch 'main' into rehydration-static-method
live1206 69a4c38
add parameter name for async while calling UpdateStateAsync
live1206 0887d04
remove apiversion for rehydration
live1206 9a06d85
Make operation id non-nullable and return NOT_SET instead of null
live1206 f19fe64
export API
live1206 1745223
cleanup
live1206 ecd5824
Merge branch 'main' into rehydration-static-method
live1206 5545d54
update description
live1206 b3daf2e
avoid cast
live1206 edf14b5
Merge branch 'rehydration-static-method' of https://github.com/live12…
live1206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.ClientModel.Primitives; | ||
| using System.IO; | ||
| using System.Text.Json; | ||
| using Azure.Core.Serialization; | ||
|
|
||
| namespace Azure.Core.TestFramework | ||
| { | ||
| public class MockJsonModel : IJsonModel<MockJsonModel> | ||
| { | ||
| internal MockJsonModel() | ||
| { | ||
| } | ||
|
|
||
| public int IntValue { get; set; } | ||
|
|
||
| public string StringValue { get; set; } | ||
|
|
||
| public byte[] Utf8BytesValue { get; } | ||
|
|
||
| public MockJsonModel(int intValue, string stringValue) | ||
| { | ||
| IntValue = intValue; | ||
| StringValue = stringValue; | ||
|
|
||
| dynamic json = BinaryData.FromString("{}").ToDynamicFromJson(JsonPropertyNames.CamelCase); | ||
| json.IntValue = IntValue; | ||
| json.StringValue = StringValue; | ||
|
|
||
| MemoryStream stream = new(); | ||
| using Utf8JsonWriter writer = new Utf8JsonWriter(stream); | ||
|
|
||
| writer.WriteStartObject(); | ||
| writer.WriteNumber("IntValue", IntValue); | ||
| writer.WriteString("StringValue", StringValue); | ||
| writer.WriteEndObject(); | ||
|
|
||
| writer.Flush(); | ||
| Utf8BytesValue = stream.ToArray(); | ||
| } | ||
|
|
||
| MockJsonModel IPersistableModel<MockJsonModel>.Create(BinaryData data, ModelReaderWriterOptions options) | ||
| { | ||
| dynamic json = data.ToDynamicFromJson(JsonPropertyNames.CamelCase); | ||
| return new MockJsonModel(json.IntValue, json.StringValue); | ||
| } | ||
|
|
||
| MockJsonModel IJsonModel<MockJsonModel>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) | ||
| { | ||
| using JsonDocument doc = JsonDocument.ParseValue(ref reader); | ||
| int intValue = doc.RootElement.GetProperty("IntValue").GetInt32(); | ||
| string stringValue = doc.RootElement.GetProperty("StringValue").GetString()!; | ||
| return new MockJsonModel(intValue, stringValue); | ||
| } | ||
|
|
||
| string IPersistableModel<MockJsonModel>.GetFormatFromOptions(ModelReaderWriterOptions options) | ||
| => "J"; | ||
|
|
||
| BinaryData IPersistableModel<MockJsonModel>.Write(ModelReaderWriterOptions options) | ||
| { | ||
| return BinaryData.FromBytes(Utf8BytesValue); | ||
| } | ||
|
|
||
| void IJsonModel<MockJsonModel>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) | ||
| { | ||
| writer.WriteStartObject(); | ||
| writer.WriteNumber("IntValue", IntValue); | ||
| writer.WriteString("StringValue", StringValue); | ||
| writer.WriteEndObject(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
sdk/core/Azure.Core/src/Internal/GenericOperationSource.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.ClientModel.Primitives; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace Azure.Core | ||
| { | ||
| internal class GenericOperationSource<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T> : IOperationSource<T> where T : IPersistableModel<T> | ||
| { | ||
| T IOperationSource<T>.CreateResult(Response response, CancellationToken cancellationToken) | ||
| => CreateResult(response); | ||
|
|
||
| ValueTask<T> IOperationSource<T>.CreateResultAsync(Response response, CancellationToken cancellationToken) | ||
| => new ValueTask<T>(CreateResult(response)); | ||
|
|
||
| private T CreateResult(Response response) | ||
| => (T)ModelReaderWriter.Read(response.Content, typeof(T))!; | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #nullable disable | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Azure.Core.Pipeline; | ||
|
|
||
| namespace Azure.Core | ||
| { | ||
| internal class RehydrationOperation : Operation | ||
| { | ||
| private readonly NextLinkOperationImplementation _nextLinkOperation; | ||
| private readonly OperationInternal _operation; | ||
|
|
||
| public RehydrationOperation(HttpPipeline pipeline, RehydrationToken? rehydrationToken, ClientOptions options = null) | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| Argument.AssertNotNull(pipeline, nameof(pipeline)); | ||
| Argument.AssertNotNull(rehydrationToken, nameof(rehydrationToken)); | ||
| _nextLinkOperation = (NextLinkOperationImplementation)NextLinkOperationImplementation.Create(pipeline, rehydrationToken); | ||
| var operationState = _nextLinkOperation.UpdateStateAsync(false, default).EnsureCompleted(); | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _operation = operationState.HasCompleted | ||
| ? _operation = new OperationInternal(operationState) | ||
| : new OperationInternal(_nextLinkOperation, new ClientDiagnostics(options ?? ClientOptions.Default), operationState.RawResponse, requestMethod: _nextLinkOperation.RequestMethod); | ||
| } | ||
|
|
||
| public override string Id => _nextLinkOperation?.OperationId ?? null; | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken(); | ||
|
|
||
| public override bool HasCompleted => _operation.HasCompleted; | ||
|
|
||
| public override Response GetRawResponse() => _operation.RawResponse; | ||
|
|
||
| public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); | ||
|
|
||
| public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
sdk/core/Azure.Core/src/Internal/RehydrationOperationOfT.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #nullable disable | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| using System.ClientModel.Primitives; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Azure.Core.Pipeline; | ||
|
|
||
| namespace Azure.Core | ||
| { | ||
| #pragma warning disable SA1649 // File name should match first type name | ||
| internal class RehydrationOperation<T> : Operation<T> where T : IPersistableModel<T> | ||
| #pragma warning restore SA1649 // File name should match first type name | ||
| { | ||
| private readonly OperationInternal<T> _operation; | ||
| private readonly NextLinkOperationImplementation _nextLinkOperation; | ||
|
|
||
| public RehydrationOperation(HttpPipeline pipeline, RehydrationToken? rehydrationToken, ClientOptions options = null) | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| Argument.AssertNotNull(pipeline, nameof(pipeline)); | ||
| Argument.AssertNotNull(rehydrationToken, nameof(rehydrationToken)); | ||
|
|
||
| IOperationSource<T> source = new GenericOperationSource<T>(); | ||
| _nextLinkOperation = (NextLinkOperationImplementation)NextLinkOperationImplementation.Create(pipeline, rehydrationToken); | ||
| var operation = NextLinkOperationImplementation.Create(source, _nextLinkOperation); | ||
| var operationState = operation.UpdateStateAsync(false, default).EnsureCompleted(); | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _operation = operationState.HasCompleted | ||
| ? new OperationInternal<T>(operationState) | ||
| : new OperationInternal<T>(operation, new ClientDiagnostics(options ?? ClientOptions.Default), operationState.RawResponse); | ||
| } | ||
|
|
||
| public override T Value => _operation.Value; | ||
|
|
||
| public override bool HasValue => _operation.HasValue; | ||
|
|
||
| public override string Id => _nextLinkOperation.OperationId ?? null; | ||
live1206 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public override RehydrationToken? GetRehydrationToken() => _nextLinkOperation?.GetRehydrationToken(); | ||
|
|
||
| public override bool HasCompleted => _operation.HasCompleted; | ||
|
|
||
| public override Response GetRawResponse() => _operation.RawResponse; | ||
|
|
||
| public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken); | ||
|
|
||
| public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.