-
Notifications
You must be signed in to change notification settings - Fork 913
Add support for service model protocols field #6161
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 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
82f93d3
Add support for service model protocols field
davidh44 490e155
Merge branch 'master' into hdavidh/protocols-selection
davidh44 64106de
Changelog
davidh44 fa97874
Add support for service model protocols field
davidh44 3fb37e1
Account for Kinesis cbor customization in ProtocolUtils
davidh44 6a7f6e4
Deprecate ServiceMetadata.getProtocol()
davidh44 db4e99a
Deprecate ServiceMetadata.setProtocol()
davidh44 b0ed395
Add test for Cbor v1
davidh44 cce4ebf
Merge branch 'master' into hdavidh/protocols-selection
davidh44 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,6 @@ | ||
{ | ||
"type": "feature", | ||
"category": "AWS SDK for Java v2", | ||
"contributor": "", | ||
"description": "Add support for protocols field in service model" | ||
} |
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
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
63 changes: 63 additions & 0 deletions
63
codegen/src/main/java/software/amazon/awssdk/codegen/utils/ProtocolUtils.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,63 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.codegen.utils; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import software.amazon.awssdk.codegen.model.service.ServiceMetadata; | ||
|
||
/** | ||
* Resolves the protocol from the service model {@code protocol} and {@code protocols} fields. | ||
*/ | ||
public final class ProtocolUtils { | ||
|
||
/** | ||
* Priority-ordered list of protocols supported by the SDK. | ||
*/ | ||
private static final List<String> SUPPORTED_PROTOCOLS = Arrays.asList( | ||
"smithy-rpc-v2-cbor", "json", "rest-json", "rest-xml", "query", "ec2"); | ||
|
||
private ProtocolUtils() { | ||
} | ||
|
||
/** | ||
* {@code protocols} supersedes {@code protocol}. The highest priority protocol supported by the SDK that is present in the | ||
* service model {@code protocols} list will be selected. If none of the values in {@code protocols} is supported by the | ||
* SDK, an error will be thrown. If {@code protocols} is empty or null, the value from {@code protocol} will be returned. | ||
*/ | ||
public static String resolveProtocol(ServiceMetadata serviceMetadata) { | ||
|
||
List<String> protocols = serviceMetadata.getProtocols(); | ||
String protocol = serviceMetadata.getProtocol(); | ||
|
||
if (protocols == null || protocols.isEmpty()) { | ||
return protocol; | ||
} | ||
|
||
// Kinesis uses customization.config customServiceMetadata to set cbor | ||
if ("cbor".equals(protocols.get(0))) { | ||
davidh44 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return "cbor"; | ||
} | ||
|
||
for (String supportedProtocol : SUPPORTED_PROTOCOLS) { | ||
if (protocols.contains(supportedProtocol)) { | ||
return supportedProtocol; | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("The SDK does not support any of provided protocols: " + protocols); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
codegen/src/test/java/software/amazon/awssdk/codegen/utils/ProtocolUtilsTest.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,70 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.awssdk.codegen.utils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import org.junit.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import software.amazon.awssdk.codegen.model.service.ServiceMetadata; | ||
|
||
public class ProtocolUtilsTest { | ||
|
||
@ParameterizedTest | ||
@MethodSource("protocolsValues") | ||
public void protocolSelection(List<String> protocols, String expectedProtocol) { | ||
ServiceMetadata serviceMetadata = serviceMetadata(protocols); | ||
String selectedProtocol = ProtocolUtils.resolveProtocol(serviceMetadata); | ||
assertThat(selectedProtocol).isEqualTo(expectedProtocol); | ||
} | ||
|
||
@Test | ||
public void emptyProtocolsWithPresentProtocol() { | ||
ServiceMetadata serviceMetadata = new ServiceMetadata(); | ||
serviceMetadata.setProtocol("json"); | ||
String selectedProtocol = ProtocolUtils.resolveProtocol(serviceMetadata); | ||
assertThat(selectedProtocol).isEqualTo("json"); | ||
} | ||
|
||
@Test | ||
public void protocolsWithJson_protocolCbor_selectsJson() { | ||
ServiceMetadata serviceMetadata = new ServiceMetadata(); | ||
serviceMetadata.setProtocols(Collections.singletonList("json")); | ||
serviceMetadata.setProtocol("smithy-rpc-v2-cbor"); | ||
String selectedProtocol = ProtocolUtils.resolveProtocol(serviceMetadata); | ||
assertThat(selectedProtocol).isEqualTo("json"); | ||
} | ||
|
||
private static Stream<Arguments> protocolsValues() { | ||
return Stream.of(Arguments.of(Arrays.asList("smithy-rpc-v2-cbor", "json"), "smithy-rpc-v2-cbor"), | ||
Arguments.of(Collections.singletonList("smithy-rpc-v2-cbor"), "smithy-rpc-v2-cbor"), | ||
Arguments.of(Arrays.asList("smithy-rpc-v2-cbor", "json", "query"), "smithy-rpc-v2-cbor"), | ||
Arguments.of(Arrays.asList("json", "query"), "json"), | ||
Arguments.of(Collections.singletonList("query"), "query")); | ||
} | ||
|
||
private static ServiceMetadata serviceMetadata(List<String> protocols) { | ||
ServiceMetadata serviceMetadata = new ServiceMetadata(); | ||
serviceMetadata.setProtocols(protocols); | ||
return serviceMetadata; | ||
} | ||
} |
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.