Skip to content
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

azure-http-specs, add ARM LRO case #1821

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

XiaofeiCao
Copy link
Contributor

@XiaofeiCao XiaofeiCao commented Nov 7, 2024

Context

Content

verb lro type expected polling pattern
PUT AAO poll AAO, get final result through original(resource) uri
POST AAO+Location poll AAO, get final result through Location
DELETE Location poll Location, until 204

@azure-sdk
Copy link
Collaborator

azure-sdk commented Nov 7, 2024

All changed packages have been documented.

  • @azure-tools/azure-http-specs
Show changes

@azure-tools/azure-http-specs - feature ✏️

Added LRO case for ARM tests.

@azure-sdk
Copy link
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 📚 Next docs

@XiaofeiCao XiaofeiCao marked this pull request as ready for review November 7, 2024 08:12
@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Nov 7, 2024

I don't get this line

DELETE with poll through preferred Azure-AsyncOperation and finalResult through Location

Why DELETE got a finalResult?

@XiaofeiCao
Copy link
Contributor Author

XiaofeiCao commented Nov 7, 2024

I don't get this line

DELETE with poll through preferred Azure-AsyncOperation and finalResult through Location

Why DELETE got a finalResult?

I mean get final-state. In our core, we do have logic for POST/DELETE to get final state when poll succeeded:
https://github.com/Azure/azure-sdk-for-java/blob/8ddf6da837a50543dfcb689887fdd6b1dcf0f8cf/sdk/core/azure-core-management/src/main/java/com/azure/core/management/implementation/polling/AzureAsyncOperationData.java#L181-L185

Mark is also mentioning this pattern: https://teams.cloud.microsoft/l/message/19:[email protected]/1729624003961?tenantId=72f988bf-86f1-41af-91ab-2d7cd011db47&groupId=3e17dcb0-4257-4a30-b843-77f47f1d4121&parentMessageId=1728977564024&teamName=Azure%20SDK&channelName=TypeSpec%20Discussion&createdTime=1729624003961

playground

Do you mean it's uncommon for DELETE to do a get final state? Or am I confusing finalResult with finalState?

@XiaofeiCao
Copy link
Contributor Author

I don't get this line

DELETE with poll through preferred Azure-AsyncOperation and finalResult through Location

Why DELETE got a finalResult?

Changed description to use final-state instead of finalResult.

@weidongxu-microsoft
Copy link
Member

weidongxu-microsoft commented Nov 7, 2024

I don't get this line

DELETE with poll through preferred Azure-AsyncOperation and finalResult through Location

Why DELETE got a finalResult?

Changed description to use final-state instead of finalResult.

I think for DELETE via AAO, when status=Succeeded, we get the final-state (the resource was deleted). There is no need to follow Location as long as the finalResult is void.
(maybe there is corner case that this flow does have effect, when finalResult is not void, as we had Java code -- but I think it is untypical)

I would take majority of this AAO/Location case is for POST, where AAO header is for status (and final-state), while Location header is for finalResult.

@XiaofeiCao
Copy link
Contributor Author

XiaofeiCao commented Nov 8, 2024

I would take majority of this AAO/Location case is for POST, where AAO header is for status (and final-state), while Location header is for finalResult.

Makes sense. Let me update the case be:

verb lro type expected polling pattern
PUT AAO poll AAO, get final result through original(resource) uri
POST AAO+Location poll AAO, get final result through Location
DELETE Location poll Location, until 204

Copy link
Member

@tadelesh tadelesh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this pr has not cover the action operation?

@XiaofeiCao
Copy link
Contributor Author

this pr has not cover the action operation?

Yeah, I'm going to cover that, see #1821 (comment)
Let me know your thoughts.

@XiaofeiCao
Copy link
Contributor Author

this pr has not cover the action operation?

Added resource action case.

{
"url": "https://example.org/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/lroResources/lro/files/myfile"
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For POST scenario, I see your comment in PR body that SDK shall poll by AAO and get final result by Location. However, the scenarioDoc still shows way to poll for Location.
image

Copy link
Contributor Author

@XiaofeiCao XiaofeiCao Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, for AAO+Location, the preferred polling header is AAO. Here I also provided way of polling through Location.

You may choose to poll through either one, since from my understanding, neither of them violates ARM guideline. Do correct me if I'm wrong here.

}

model UploadResult {
url: string;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I guess .NET would want to use URL type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a regular response body property, though sure, let me make it type url.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use ExportResult

final-state-via: Azure-AsyncOperation

Expected verb: PUT
Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/lroResources/lro
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I'd prefer resource name not be "lro". It could be confusing for all the "/lroResources/lro" in path, while none of them really signifies the operation be LRO or not (they are just resource collection and resource name).

Just a nit, you may keep this, if it is just my feeling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to make more sense.

Comment on lines 21 to 24
model LroResourceProperties {
@doc("The description of the resource.")
description?: string;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to have provisioningState?: ProvisioningState; in properties?

Copy link
Contributor Author

@XiaofeiCao XiaofeiCao Nov 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we do. In mockapi I returned it, here we should have that too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Comment on lines 93 to 123
Expected verb: GET
Expected URL: {endpoint}/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/lro_create/aao

Expected status code: 200
Expected response body:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/lro_create/aao",
"name": "aao",
"status" : "Succeeded",
"startTime": "2024-11-08T01:41:53.5508583+00:00",
"endTime": "2024-11-08T01:42:41.5354192+00:00",
"properties": {
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/lroResources/lro",
"name": "lro",
"type": "Azure.ResourceManager.Resources/lroResources",
"location": "eastus",
"properties": {
"description": "valid",
"provisioningState": "Succeeded"
},
"systemData": {
"createdBy": "AzureSDK",
"createdByType": "User",
"createdAt": <any date>,
"lastModifiedBy": "AzureSDK",
"lastModifiedAt": <any date>,
"lastModifiedByType": "User",
}
}
}
Copy link
Member

@weidongxu-microsoft weidongxu-microsoft Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's behavior of real ARM lro in RP?

I kind of think this should be same AAO status response, not resource response (and the final GET to original resource URL not optional for MGMT) -- as the endpoint is the AAO endpoint, it should return consistent body schema. Though I could be wrong.

    {
      "id": "/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/lro_create/aao",
      "name": "aao",
      "startTime": <date>,
      "status" : "Succeeded"
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's AAO response. I added property properties mentioned in the guideline, though I haven't seeing that in any real service.
image

OK, since final GET in mgmt is required, I'll remove this property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Comment on lines +232 to +235
#suppress "deprecated" "legacy"
#suppress "@azure-tools/typespec-azure-resource-manager/lro-location-header" "legacy"
@scenario
@scenarioDoc("""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious, what's typespec-azure-resourcemanager's non-legacy DELETE? Is it AAO or Location?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emmm, it's Location. Let me remove the unnecessary header.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.OperationTemplates/orders/order1
Expected query parameter: api-version=2023-12-01-preview
Expected response status code: 202
Expected response header: Location={endpoint}/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/lro_delete/location
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i believe all polling url is similar patten. refer this. it's better to mock more real.


Location first poll.
Expected verb: GET
Expected URL: {endpoint}/subscriptions/00000000-0000-0000-0000-000000000000/locations/eastus/lro_delete/location
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems different from the response?

Comment on lines +241 to +242
Expected status code: 202
Expected no response body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the polling will always return 202? from recording, it seems always 200. but from guideline, it seems right.

}
```
""")
@useFinalStateVia("location")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for normal situation, we don't add such decorator.

@markcowl markcowl self-assigned this Nov 14, 2024
"lastModifiedByType": "User",
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need an end to the literal format block here (```)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ARM, test case for LRO
6 participants