Skip to content

Commit ca6c59c

Browse files
authored
Smithy RPCv2 CBOR merge (#5621)
* Add RPCv2 module * Add RPCv2 module (#5445) * Comment out empty rpcv2 dependency * Sync version to 2.26.31-SNAPSHOT * Sugmanue/add byte support (#5477) * Add support to serialize byte values * Add tests for byte support * Address PR comments * Add rpcv2 protocol core (#5496) * Add support to serialize byte values * Add RPCv2 protocol core marshalling/unmarshalling * Address PR comments * Address PR comments 2 * Address PR comments 3 * Support for operation without input defined (#5512) * Support for operation without input defined * Fix a checkstyle issue * Code clean up * Code clean up 2 * Rewrite the condition to conjunctive normal form * Add codgen tests (#5517) * Add codgen tests * Address PR comments * Address PR comments 2 * Add missing class rename * Add missing AWS_JSON protocol facts * Account for null protocol case * Add RPCv2 benchmark tests (#5526) * Add RPCv2 benchmark tests * Give the constants name a meaningful name * Avoid parsing numbers when using RPCv2 protocol (#5539) * Avoid parsing numbers when using RPCv2 protocol * Refactor to avoid impacting JSON with RPCv2 logic (#5544) * Refactor to avoid impacting JSON with RPCv2 logic * Avoid making the unmarshallers depend on timestamp formats * Avoid streams while unmarshalling * Fix build failures * Fix build failures 2 * Avoid growing copies of collections of known size (#5551) * Add the new Smithy RPCv2 package * Sugmanue/rpcv2 improve cbor performance 04 (#5564) * Improve lookup by marshalling type * Improve trait lookup using TraitType * Add support for Smithy RPCv2 to the new service scripts (#5613) * Add changelog for the release * Fix typo in changelog * Update to next SNAPSHOT version
1 parent c03a24b commit ca6c59c

File tree

176 files changed

+10940
-1487
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+10940
-1487
lines changed

.brazil.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"aws-json-protocol": { "packageName": "AwsJavaSdk-Core-AwsJsonProtocol" },
1515
"aws-query-protocol": { "packageName": "AwsJavaSdk-Core-AwsQueryProtocol" },
1616
"aws-xml-protocol": { "packageName": "AwsJavaSdk-Core-AwsXmlProtocol" },
17+
"smithy-rpcv2-protocol": { "packageName": "AwsJavaSdk-Core-SmithyRpcV2Protocol" },
1718
"cloudwatch-metric-publisher": { "packageName": "AwsJavaSdk-MetricPublisher-CloudWatch" },
1819
"codegen": { "packageName": "AwsJavaSdk-Codegen" },
1920
"dynamodb-enhanced": { "packageName": "AwsJavaSdk-DynamoDb-Enhanced" },
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"category": "AWS SDK for Java v2",
3+
"contributor": "sugmanue",
4+
"type": "feature",
5+
"description": "Added support for the Smithy RPCv2 CBOR protocol, a new RPC protocol with better performance characteristics than AWS Json."
6+
}

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
<artifactId>aws-xml-protocol</artifactId>
113113
<version>${awsjavasdk.version}</version>
114114
</dependency>
115+
<dependency>
116+
<groupId>software.amazon.awssdk</groupId>
117+
<artifactId>smithy-rpcv2-protocol</artifactId>
118+
<version>${awsjavasdk.version}</version>
119+
</dependency>
115120
<dependency>
116121
<groupId>software.amazon.awssdk</groupId>
117122
<artifactId>protocol-core</artifactId>

codegen/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
<artifactId>aws-xml-protocol</artifactId>
143143
<version>${awsjavasdk.version}</version>
144144
</dependency>
145+
<dependency>
146+
<groupId>software.amazon.awssdk</groupId>
147+
<artifactId>smithy-rpcv2-protocol</artifactId>
148+
<version>${awsjavasdk.version}</version>
149+
</dependency>
145150
<dependency>
146151
<groupId>software.amazon.awssdk</groupId>
147152
<artifactId>protocol-core</artifactId>

codegen/src/main/java/software/amazon/awssdk/codegen/AddEmptyInputShape.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
package software.amazon.awssdk.codegen;
1717

18-
import static software.amazon.awssdk.codegen.internal.Utils.createInputShapeMarshaller;
18+
import static software.amazon.awssdk.codegen.internal.Utils.createSyntheticInputShapeMarshaller;
1919
import static software.amazon.awssdk.codegen.internal.Utils.unCapitalize;
2020

2121
import java.util.HashMap;
@@ -75,7 +75,7 @@ private Map<String, ShapeModel> addEmptyInputShapes(
7575
shape.setVariable(inputVariable);
7676

7777
shape.setMarshaller(
78-
createInputShapeMarshaller(serviceModel.getMetadata(), operation));
78+
createSyntheticInputShapeMarshaller(serviceModel.getMetadata(), operation));
7979

8080
emptyInputShapes.put(inputShape, shape);
8181

codegen/src/main/java/software/amazon/awssdk/codegen/customization/processors/DefaultCustomizationProcessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public static CodegenCustomizationProcessor getProcessorFor(
3434
new ShapeSubstitutionsProcessor(config.getShapeSubstitutions()),
3535
new CustomSdkShapesProcessor(config.getCustomSdkShapes()),
3636
new OperationModifiersProcessor(config.getOperationModifiers()),
37+
new SmithyRpcV2CborProtocolProcessor(),
3738
new RemoveExceptionMessagePropertyProcessor(),
3839
new UseLegacyEventGenerationSchemeProcessor(),
3940
new NewAndLegacyEventStreamProcessor(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.customization.processors;
17+
18+
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor;
19+
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
20+
import software.amazon.awssdk.codegen.model.service.Http;
21+
import software.amazon.awssdk.codegen.model.service.Operation;
22+
import software.amazon.awssdk.codegen.model.service.ServiceModel;
23+
import software.amazon.awssdk.utils.StringUtils;
24+
25+
/**
26+
* This processor only runs for services using the <code>smithy-rpc-v2-cbor</code> protocol.
27+
*
28+
* Adds a request URI that conform to the Smithy RPCv2 protocol to each operation in the model, if there's no URI already
29+
* defined.
30+
*/
31+
public class SmithyRpcV2CborProtocolProcessor implements CodegenCustomizationProcessor {
32+
@Override
33+
public void preprocess(ServiceModel serviceModel) {
34+
if (!"smithy-rpc-v2-cbor".equals(serviceModel.getMetadata().getProtocol())) {
35+
return;
36+
}
37+
serviceModel.getOperations().forEach((name, op) -> setRequestUri(serviceModel, name, op));
38+
}
39+
40+
private void setRequestUri(ServiceModel service, String name, Operation op) {
41+
Http http = op.getHttp();
42+
String requestUri = http.getRequestUri();
43+
if (StringUtils.isNotBlank(requestUri) && !"/".equals(requestUri)) {
44+
return;
45+
}
46+
String uri = String.format("/service/%s/operation/%s", service.getMetadata().getTargetPrefix(), op.getName());
47+
op.getHttp().setRequestUri(uri);
48+
}
49+
50+
@Override
51+
public void postprocess(IntermediateModel intermediateModel) {
52+
}
53+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.internal;
17+
18+
import java.util.AbstractMap;
19+
import java.util.LinkedHashSet;
20+
import java.util.List;
21+
import java.util.Map;
22+
import java.util.Set;
23+
import java.util.stream.Collectors;
24+
import software.amazon.awssdk.protocols.core.OperationMetadataAttribute;
25+
import software.amazon.awssdk.utils.AttributeMap;
26+
27+
/**
28+
* Default implementation of {@link ProtocolMetadataConstants}.
29+
*/
30+
public final class DefaultProtocolMetadataConstants implements ProtocolMetadataConstants {
31+
private final Set<Map.Entry<Class<?>, OperationMetadataAttribute<?>>> knownKeys = new LinkedHashSet<>();
32+
private final AttributeMap.Builder map = AttributeMap.builder();
33+
34+
@Override
35+
public List<Map.Entry<Class<?>, OperationMetadataAttribute<?>>> keys() {
36+
return knownKeys.stream().filter(x -> map.get(x.getValue()) != null).collect(Collectors.toList());
37+
}
38+
39+
@Override
40+
public <T> T put(Class<?> containingClass, OperationMetadataAttribute<T> key, T value) {
41+
knownKeys.add(new AbstractMap.SimpleEntry<>(containingClass, key));
42+
T oldValue = map.get(key);
43+
map.put(key, value);
44+
return oldValue;
45+
}
46+
47+
@Override
48+
public <T> T get(OperationMetadataAttribute<T> key) {
49+
return map.get(key);
50+
}
51+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.internal;
17+
18+
import java.util.List;
19+
import java.util.Map;
20+
import software.amazon.awssdk.protocols.core.OperationMetadataAttribute;
21+
22+
/**
23+
* Keeps the set of {@link OperationMetadataAttribute} constants attributes per operation/protocol. This is used to codegen
24+
* those constant values.
25+
*/
26+
public interface ProtocolMetadataConstants {
27+
28+
/**
29+
* Returns the list of keys sets. The {@link Map.Entry} contains as key the class containing the key field and the value
30+
* contains the key constant itself. The class is needed to properly codegen a reference to the key.
31+
* @return
32+
*/
33+
List<Map.Entry<Class<?>, OperationMetadataAttribute<?>>> keys();
34+
35+
/**
36+
* Adds an operation metadata to the set of constants.
37+
*/
38+
<T> T put(Class<?> containingClass, OperationMetadataAttribute<T> key, T value);
39+
40+
/**
41+
* Adds an operation metadata to the set of constants.
42+
*/
43+
default <T> T put(OperationMetadataAttribute<T> key, T value) {
44+
return put(key.getClass(), key, value);
45+
}
46+
47+
/**
48+
* Gets the constant value for the operation metadata key.
49+
*/
50+
<T> T get(OperationMetadataAttribute<T> key);
51+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.internal;
17+
18+
import software.amazon.awssdk.codegen.model.intermediate.Protocol;
19+
import software.amazon.awssdk.codegen.model.intermediate.ShapeMarshaller;
20+
import software.amazon.awssdk.protocols.json.BaseAwsJsonProtocolFactory;
21+
22+
/**
23+
* Enum that maps protocol to metadata attribute constants for a given operation.
24+
*/
25+
public enum ProtocolMetadataDefault {
26+
27+
SMITHY_RPC_V2_CBOR(Protocol.SMITHY_RPC_V2_CBOR) {
28+
public ProtocolMetadataConstants protocolMetadata(ShapeMarshaller shapeMarshaller) {
29+
ProtocolMetadataConstants attributes = new DefaultProtocolMetadataConstants();
30+
31+
// If the shape is synthetic that means that no-input was defined in the model. For this
32+
// case the protocol requires to send an empty body with no content-type. See
33+
// https://smithy.io/2.0/additional-specs/protocols/smithy-rpc-v2.html#requests.
34+
// To accomplish this we use a no-op JSON generator. Otherwise, we serialize the input
35+
// even when no members are defined.
36+
Boolean isSynthetic = shapeMarshaller.getIsSynthetic();
37+
if (Boolean.TRUE.equals(isSynthetic)) {
38+
attributes.put(BaseAwsJsonProtocolFactory.class,
39+
BaseAwsJsonProtocolFactory.GENERATES_BODY,
40+
Boolean.FALSE);
41+
}
42+
return attributes;
43+
}
44+
},
45+
DEFAULT(null);
46+
47+
private final Protocol protocol;
48+
49+
ProtocolMetadataDefault(Protocol protocol) {
50+
this.protocol = protocol;
51+
}
52+
53+
/**
54+
* Returns a function that maps from a {@link ShapeMarshaller} to a set of protocol metadata constants that we codegen.
55+
*/
56+
public ProtocolMetadataConstants protocolMetadata(ShapeMarshaller shapeMarshaller) {
57+
return new DefaultProtocolMetadataConstants();
58+
}
59+
60+
public static ProtocolMetadataDefault from(Protocol protocol) {
61+
for (ProtocolMetadataDefault value : values()) {
62+
if (value.protocol == protocol) {
63+
return value;
64+
}
65+
}
66+
return DEFAULT;
67+
}
68+
}

0 commit comments

Comments
 (0)