-
Notifications
You must be signed in to change notification settings - Fork 285
Refactor ClientMethod to Support Immutable Builders and Enhance Polling & Paging Metadata #7015
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 all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
17bb495
enable newBuilder for the ClientMethod
anuchandy 7b37e69
Adding JavaDocs, and reuse ProxyMethod::hasParameterOfType in ProxyMe…
anuchandy 4db0b3a
enable immutability in ClientMethodMapper - phase1
anuchandy 8f914d4
enable immutability in ClientMethodMapper - phase2
anuchandy 135796e
include polling-details in the shared lroBaseMethod
anuchandy fb84d2e
enable immutability in ClientMethodMapper - phase3
anuchandy 06f3b0b
enable immutability in ClientMethodMapper - phase4
anuchandy afc5d0f
enable immutability in ClientMethodMapper - phase5
anuchandy 6f13078
enable immutability in ClientMethodMapper - phase6
anuchandy 703683e
enable immutability in ClientMethodMapper - phase7
anuchandy 4a3671f
enable immutability in ClientMethodMapper - phase8
anuchandy cc9519e
enable immutability in ClientMethodMapper - phase9
anuchandy 9823d8a
enable immutability in ClientMethodMapper - phase10
anuchandy 42626a5
Revert "enable immutability in ClientMethodMapper - phase10"
anuchandy bb9b5e7
Split lro begin
anuchandy 38d6572
enable immutability in ClientMethodMapper - phase11
anuchandy e473a5f
enable immutability in ClientMethodMapper - phase11
anuchandy b4975aa
enable immutability in ClientMethodMapper - phase12
anuchandy bc6b9b5
java-doc to PagingMetadata, make continuation-token segement list imm…
anuchandy 0908410
revert use of toImmutableList in PagingMetadata
anuchandy e6089d3
Renaming JavaSettings::PollingDetails to PollingSettings (so the name…
anuchandy 487fd7d
move lro skip cases as a check within lro handling block
anuchandy 564b79d
simplify some part of lro meta resolution
anuchandy eb873b6
simplify lro meta strategy resolution
anuchandy 4985353
use consistent naming for poll intermediate-response/result and final…
anuchandy 5165f88
Introducing PollingMetadata class LRO operations (similar to PagingMe…
anuchandy 4bed082
ensure PollingSettings property names are consistent with MethodPolli…
anuchandy 5736c92
additional javadoc for PollingMetadata
anuchandy f0eafd4
attempt lro condition simplification
anuchandy 4cd34c3
initial attempt to use PollingMetadata
anuchandy 4409806
polishing use of PollingMetadata
anuchandy 906665e
Adding updated lro generated code since the method ordering changed
anuchandy fe3b555
Define CreateClientMethodArgs to pass immutable args across client me…
anuchandy 8d836fc
move lro-with-response logic to new method createLroWithResponseMetho…
anuchandy edcf923
simplifying createLroWithResponseMethods by moving fluent specifics t…
anuchandy 4c87f1f
simplifying createLroWithResponseMethods to take isSync param (like o…
anuchandy f708998
java doc, naming consistency
anuchandy 0fca39b
make lro fluent conditional flow more explicit (will help when we do …
anuchandy 39f44ef
Ensure FluentClientMethodMapper method creation follow the same codin…
anuchandy 580ee6a
consolidate javaDoc setters, aligin paramaters ordering across create…
anuchandy c0b1d87
Updating based on first round of code review discussion
anuchandy 92a5b38
consistent code pattern for method visibility
anuchandy 6a4281e
incorporating review feedback (simplify createFluentLroWithResponseSy…
anuchandy afc912c
rebase with upstream/merging corev2 changes
anuchandy 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
180 changes: 180 additions & 0 deletions
180
...a/com/microsoft/typespec/http/client/generator/core/extension/plugin/PollingSettings.java
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,180 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.microsoft.typespec.http.client.generator.core.extension.plugin; | ||
|
||
import com.azure.json.JsonReader; | ||
import com.azure.json.JsonSerializable; | ||
import com.azure.json.JsonToken; | ||
import com.azure.json.JsonWriter; | ||
import java.io.IOException; | ||
|
||
/** | ||
* type representing the user configured polling settings for long-running operations. | ||
* <a href="https://github.com/Azure/autorest.java?tab=readme-ov-file#polling-configuration">Configure Polling | ||
* Settings</a> | ||
*/ | ||
public final class PollingSettings implements JsonSerializable<PollingSettings> { | ||
private String pollingStrategy; | ||
private String syncPollingStrategy; | ||
private String pollResultType; | ||
private String finalResultType; | ||
private String pollInterval; | ||
|
||
public PollingSettings() { | ||
} | ||
|
||
/** | ||
* The format of the java source code to instantiate a polling strategy class with PollingStrategyOptions argument. | ||
* For example, in case of the strategy 'OperationLocationPollingStrategy' class, the code after applying the format | ||
* looks like - | ||
* new OperationLocationPollingStrategy(new PollingStrategyOptions(...)); | ||
*/ | ||
public static final String INSTANTIATE_POLLING_STRATEGY_FORMAT; | ||
|
||
/** | ||
* The format of the java source code to instantiate a polling strategy class with PollingStrategyOptions and LRO | ||
* final result arguments. For example, in case of the strategy 'OperationLocationPollingStrategy' class, the code | ||
* after applying the format looks like - | ||
* new OperationLocationPollingStrategy(new PollingStrategyOptions(...), finalResultType); | ||
*/ | ||
public static final String INSTANTIATE_POLLING_STRATEGY_WITH_RESULT_FORMAT; | ||
private static final String INSTANTIATE_DEFAULT_POLLING_STRATEGY; | ||
private static final String INSTANTIATE_DEFAULT_SYNC_POLLING_STRATEGY; | ||
|
||
static { | ||
final String[] ctrOptionsArg = { | ||
"new PollingStrategyOptions({httpPipeline})", | ||
" .setEndpoint({endpoint})", | ||
" .setContext({context})", | ||
" .setServiceVersion({serviceVersion})" }; | ||
INSTANTIATE_POLLING_STRATEGY_FORMAT = "new %s<>" + "(" + String.join("\n", ctrOptionsArg) + ")"; | ||
|
||
final String[] ctrOptionsAndFinalResultArg = { | ||
"new PollingStrategyOptions({httpPipeline})", | ||
" .setEndpoint({endpoint})", | ||
" .setContext({context})", | ||
" .setServiceVersion({serviceVersion}), %s" }; | ||
INSTANTIATE_POLLING_STRATEGY_WITH_RESULT_FORMAT | ||
= "new %s<>" + "(" + String.join("\n", ctrOptionsAndFinalResultArg) + ")"; | ||
|
||
INSTANTIATE_DEFAULT_POLLING_STRATEGY | ||
= String.format(INSTANTIATE_POLLING_STRATEGY_FORMAT, "DefaultPollingStrategy"); | ||
INSTANTIATE_DEFAULT_SYNC_POLLING_STRATEGY | ||
= String.format(INSTANTIATE_POLLING_STRATEGY_FORMAT, "SyncDefaultPollingStrategy"); | ||
} | ||
|
||
public static final String DEFAULT_CLIENTCORE_POLLING_STRATEGY_FORMAT | ||
= String.join("\n", "new %s<>(new PollingStrategyOptions({httpPipeline})", " .setEndpoint({endpoint})", | ||
" .setRequestContext({context})", " .setServiceVersion({serviceVersion}))"); | ||
|
||
private static final String DEFAULT_CLIENTCORE_POLLING_CODE | ||
= String.format(DEFAULT_CLIENTCORE_POLLING_STRATEGY_FORMAT, "DefaultPollingStrategy"); | ||
|
||
/** | ||
* Gets the strategy for polling. | ||
* <p> | ||
* See the 'com.azure.core.util.polling.PollingStrategy' contract for more details. | ||
* </p> | ||
* | ||
* @return The strategy for polling. | ||
*/ | ||
public String getPollingStrategy() { | ||
if (pollingStrategy == null || "default".equalsIgnoreCase(pollingStrategy)) { | ||
return INSTANTIATE_DEFAULT_POLLING_STRATEGY; | ||
} else { | ||
return pollingStrategy; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the sync strategy for polling. | ||
* <p> | ||
* See the 'com.azure.core.util.polling.PollingStrategy' contract for more details. | ||
* </p> | ||
* | ||
* @return The sync strategy for polling. | ||
*/ | ||
public String getSyncPollingStrategy() { | ||
if (syncPollingStrategy == null || "default".equalsIgnoreCase(syncPollingStrategy)) { | ||
if (JavaSettings.getInstance().isAzureV2()) { | ||
return DEFAULT_CLIENTCORE_POLLING_CODE; | ||
} | ||
return INSTANTIATE_DEFAULT_SYNC_POLLING_STRATEGY; | ||
} else { | ||
return syncPollingStrategy; | ||
} | ||
} | ||
|
||
/** | ||
* Gets the type of the poll response when the long-running operation is in progress. | ||
* | ||
* @return The intermediate type for polling. | ||
*/ | ||
public String getPollResultType() { | ||
return pollResultType; | ||
} | ||
|
||
/** | ||
* Gets the type of the poll response once the long-running operation is completed. | ||
* | ||
* @return The final type for polling. | ||
*/ | ||
public String getFinalResultType() { | ||
return finalResultType; | ||
} | ||
|
||
/** | ||
* Gets the polling interval in seconds. | ||
* | ||
* @return The polling interval in seconds. | ||
*/ | ||
public int getPollIntervalInSeconds() { | ||
return pollInterval != null ? Integer.parseInt(pollInterval) : 1; | ||
} | ||
|
||
@Override | ||
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { | ||
return jsonWriter.writeStartObject() | ||
.writeStringField("strategy", pollingStrategy) | ||
.writeStringField("sync-strategy", syncPollingStrategy) | ||
.writeStringField("intermediate-type", pollResultType) | ||
.writeStringField("final-type", finalResultType) | ||
.writeStringField("poll-interval", pollInterval) | ||
.writeEndObject(); | ||
} | ||
|
||
/** | ||
* Deserializes a PollingSettings instance from the JSON data. | ||
* | ||
* @param jsonReader The JSON reader to deserialize from. | ||
* @return A PollingSettings instance deserialized from the JSON data. | ||
* @throws IOException If an error occurs during deserialization. | ||
*/ | ||
public static PollingSettings fromJson(JsonReader jsonReader) throws IOException { | ||
return jsonReader.readObject(reader -> { | ||
final PollingSettings pollingSettings = new PollingSettings(); | ||
|
||
while (reader.nextToken() != JsonToken.END_OBJECT) { | ||
String fieldName = reader.getFieldName(); | ||
reader.nextToken(); | ||
|
||
if ("strategy".equals(fieldName)) { | ||
pollingSettings.pollingStrategy = reader.getString(); | ||
} else if ("sync-strategy".equals(fieldName)) { | ||
pollingSettings.syncPollingStrategy = reader.getString(); | ||
} else if ("intermediate-type".equals(fieldName)) { | ||
pollingSettings.pollResultType = reader.getString(); | ||
} else if ("final-type".equals(fieldName)) { | ||
pollingSettings.finalResultType = reader.getString(); | ||
} else if ("poll-interval".equals(fieldName)) { | ||
pollingSettings.pollInterval = reader.getString(); | ||
} else { | ||
reader.skipChildren(); | ||
} | ||
} | ||
|
||
return pollingSettings; | ||
}); | ||
} | ||
} |
Oops, something went wrong.
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.