Azure / Azure/azure-libraries-for-java
Using ETag for better Create / Update experience
- Vorherrschende Sprache
- Java
- Sterne
- 97
- Forks
- 102
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Today the `CreateOrUpdate` (PUT) semantic make it difficult to distinguish between Creation and Update of a resource. For example consider user trying to create a new resource group:
```java
ResourceGroup resourceGroup = azure.resourceGroups()
.define("myRG")
.withRegion(Region.US_EAST)
.withTag("aa", "bb")
.create();
```
If the resource group with name "MyRG" already exists user will be expecting an error, but this call still succeeded since we don't have a way to tell server that create it if not exist and fail it already exists.
As per ARM spec, a resource provider can can optionally support ETag specific headers (If-Match, If-None-Match) , if they do then SDK can make use of this header with `CreateOrUpdate` (PUT) calls and provide better experience to the user.
```
define()..create() -> CreateOrUpdate + If-None-Match = "*"
With this, if resource already exits PUT will fail with error code 412
update()..apply() -> CreateOrUpdate + If-Match = "*"
With this, if resource does not exists PUT will fail with error code 412
```
| PUT | Resource does not exist | Resource exists |
| ------------- |:-------------:| -----:|
| If-Match = "" / absent | 201 Created | 200 OK |
| If-Match = "*" | 412 Precondition Failed | 200 OK |
| If-Match = "xyz" | 412 Precondition Failed | 200 OK / 412 Precondition Failed |
| If-None-Match = "*" | 201 Created | 412 Precondition Failed |
Beitragsleitfaden
Rechercherichtung
Beginne damit, den CreateOrUpdate PUT-Pfad nachzuverfolgen, der von define().create() und update().apply() verwendet wird, und überprüfe anschließend das im Issue beschriebene ARM-ETag-Verhalten. Ermittle, wie If-None-Match und If-Match angewendet werden sollten, einschließlich der erwarteten 412-Antworten. Als abgeschlossen gilt die Aufgabe, wenn unterstützte Ressourcen Erstellung und Aktualisierung unterscheiden und das dokumentierte Verhalten beibehalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- azure, java
- Bereich
- api, backend
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100