-
Notifications
You must be signed in to change notification settings - Fork 2.2k
mgmt doc on LRO beginCreate/beginDelete #12899
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
weidongxu-microsoft
merged 6 commits into
Azure:master
from
weidongxu-microsoft:mgmt_resource_begin-create
Jul 15, 2020
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
64cd62b
support beginCreate beginDelete for GenericResource
weidongxu-microsoft 87d0cc8
use generic type
weidongxu-microsoft 244b6a7
doc (preview) for LRO
weidongxu-microsoft e558cb8
Merge branch 'master' into mgmt_resource_begin-create
weidongxu-microsoft 5c9b3ce
Update README.md
weidongxu-microsoft 7b11358
rename to getActivationResponse
weidongxu-microsoft 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Design for Azure Management Libraries for Java (Preview) | ||
|
|
||
| ## Fluent interface | ||
|
|
||
| ### Fine control over long-running operation | ||
|
|
||
| Resource provision takes time, a typical solution adopted by Azure services is the [long-running operation (LRO)][lro]. | ||
|
|
||
| Fluent interface does the polling operations in background, and only returns the final result. | ||
|
|
||
| Azure Management Libraries supports fine control over the polling for certain important resources, via `Accepted` and `SyncPoller` class. Method verb is `beginCreate` and `beginDelete`. | ||
|
|
||
| `Accepted` class provides following functionalities: | ||
| - `ActivationResponse` via `getAcceptedResult` method provides the response of the first activation operation. Note that though it wraps a resource instance, some action on this resource instance will not work, since it is not provisioned yet. | ||
| - `SyncPoller` via `getSyncPoller` method provides the control of the polling operations. `SyncPoller.poll` can be called at desired time. | ||
| - Resource instance via `getFinalResult` method, after completion of the polling operations. The method will throw `ManagementException` if polling failed and resource cannot be provisioned. | ||
|
|
||
| Here is sample code for Deployment. | ||
|
|
||
| ```java | ||
| // begin provision | ||
| Accepted<Deployment> acceptedDeployment = azure.deployments() | ||
| .define(name) | ||
| ... | ||
| .beginCreate(); | ||
| Deployment provisioningDeployment = acceptedDeployment.getAcceptedResult().getValue(); | ||
|
|
||
| LongRunningOperationStatus pollStatus = acceptedDeployment.getAcceptedResult().getStatus(); | ||
| int delayInMills = acceptedDeployment.getAcceptedResult().getRetryAfter() == null | ||
| ? 0 | ||
| : (int) acceptedDeployment.getAcceptedResult().getRetryAfter().toMillis(); | ||
| while (!pollStatus.isComplete()) { | ||
| Thread.sleep(delayInMills); | ||
|
|
||
| // poll | ||
| PollResponse<?> pollResponse = acceptedDeployment.getSyncPoller().poll(); | ||
| pollStatus = pollResponse.getStatus(); | ||
| delayInMills = pollResponse.getRetryAfter() == null | ||
| ? DEFAULT_DELAY_IN_MILLIS | ||
| : (int) pollResponse.getRetryAfter().toMillis(); | ||
| } | ||
| // pollStatus == LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, if successful | ||
|
|
||
| // final result | ||
| Deployment deployment = acceptedDeployment.getFinalResult(); | ||
| ``` | ||
|
|
||
| Supported Azure resources: | ||
| - `delete` for `ResourceGroup` | ||
| - `create` for `Deployment` | ||
| - `create` and `delete` for `GenericResource` | ||
| - `create` and `delete` for `VirtualMachine` | ||
|
|
||
| [lro]: https://docs.microsoft.com/en-us/azure/architecture/patterns/async-request-reply | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's little confusing the method name and return type is using different term: Accepted and Activation. Is there better names? Same confusing on Class name. I can see Accepted from httpstatus code, will it be good such as beginCreateResult or beginLROResult etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ActivationResponseextendsSimpleResponsewhich implementsResponse, hence named as Response.Activation is mostly from here https://github.com/Azure/azure-sdk-for-java/blob/master/sdk/core/azure-core/src/main/java/com/azure/core/util/polling/PollerFlux.java#L58-L61
Maybe I can change the method to
getActivationResponse.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed to
getActivationResponse