Skip to content

Commit

Permalink
feat: rpc2cbor: sdk protocol generator extension
Browse files Browse the repository at this point in the history
  • Loading branch information
lucix-aws committed Mar 7, 2024
1 parent 5011554 commit e49abeb
Show file tree
Hide file tree
Showing 90 changed files with 16,042 additions and 7,477 deletions.
8 changes: 8 additions & 0 deletions .changelog/41575353444b40ffbf474f4155544f00.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"id": "41575353-444b-40ff-bf47-4f4155544f00",
"type": "release",
"description": "New AWS service client module",
"modules": [
"internal/protocoltest/smithyrpcv2cbor"
]
}
2 changes: 1 addition & 1 deletion codegen/protocol-test-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ plugins {

dependencies {
implementation("software.amazon.smithy:smithy-cli:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:1.42.0") // TODO(rpc2cbor) match smithy version when merged
implementation(project(":smithy-aws-go-codegen"))
}

Expand Down
16 changes: 16 additions & 0 deletions codegen/protocol-test-codegen/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/restxmlwithnamespace"
}
}
},
"smithy-rpcv2-cbor": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.rpcv2Cbor#RpcV2Protocol"]
}
}
],
"plugins": {
"go-codegen": {
"service": "aws.protocoltests.rpcv2Cbor#RpcV2Protocol",
"module": "github.com/aws/aws-sdk-go-v2/internal/protocoltest/smithyrpcv2cbor"
}
}
}
}
}
30 changes: 29 additions & 1 deletion codegen/sdk-codegen/aws-models/kinesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@
"aws.auth#sigv4": {
"name": "kinesis"
},
"aws.protocols#awsJson1_1": {
"smithy.protocols#rpcv2Cbor": {
"http": [
"http/1.1",
"h2"
Expand Down Expand Up @@ -7975,12 +7975,34 @@
"smithy.api#documentation": "<p>The starting position in the data stream from which to start streaming.</p>",
"smithy.api#required": {}
}
},
"FakeStream": {
"target": "com.amazonaws.kinesis#SubscribeToShardInputEventStream",
"traits": {
"smithy.api#documentation": "<p>injected input event stream</p>",
"smithy.api#required": {}
}
}
},
"traits": {
"smithy.api#input": {}
}
},
"com.amazonaws.kinesis#SubscribeToShardInputEventStream": {
"type": "union",
"members": {
"SubscribeToShardEvent": {
"target": "com.amazonaws.kinesis#SubscribeToShardEvent",
"traits": {
"smithy.api#documentation": "<p>yes</p>"
}
}
},
"traits": {
"smithy.api#documentation": "<p>input event stream union</p>",
"smithy.api#streaming": {}
}
},
"com.amazonaws.kinesis#SubscribeToShardOutput": {
"type": "structure",
"members": {
Expand All @@ -7990,6 +8012,12 @@
"smithy.api#documentation": "<p>The event stream that your consumer can use to read records from the shard.</p>",
"smithy.api#required": {}
}
},
"initialResponseOne": {
"target": "com.amazonaws.kinesis#ChildShardList",
"traits": {
"smithy.api#documentation": "<p>After you call <a>SubscribeToShard</a>, Kinesis Data Streams sends events\n of this type to your consumer. For an example of how to handle these events, see <a href=\"/streams/latest/dev/building-enhanced-consumers-api.html\">Enhanced Fan-Out\n Using the Kinesis Data Streams API</a>.</p>"
}
}
},
"traits": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package software.amazon.smithy.aws.go.codegen;

import java.util.List;
import software.amazon.smithy.aws.go.codegen.protocol.AwsRpc2CborProtocolGenerator;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUtils;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator;
Expand Down Expand Up @@ -38,7 +39,8 @@ public List<ProtocolGenerator> getProtocolGenerators() {
new AwsJsonRpc1_1(),
new AwsRestXml(),
new AwsQuery(),
new Ec2Query()
new Ec2Query(),
new AwsRpc2CborProtocolGenerator()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,7 @@ private static String getEventMessageExceptionDeserializerName(
return getSerDeName(toShapeId, serviceShape, protocolName, "_deserializeEventMessageException");
}

private static String getEventStreamExceptionDeserializerName(
public static String getEventStreamExceptionDeserializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
Expand All @@ -1501,7 +1501,7 @@ private static String getEventStreamMessageDeserializerName(
return getSerDeName(toShapeId, serviceShape, protocolName, "_deserializeEventMessage");
}

private static String getEventStreamDeserializerName(
public static String getEventStreamDeserializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
Expand Down Expand Up @@ -1611,7 +1611,7 @@ public static void generateEventMessageExceptionDeserializer(
}).write("");
}

private static String getEventStreamSerializerName(
public static String getEventStreamSerializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
Expand Down Expand Up @@ -1775,15 +1775,15 @@ public static void generateEventMessageRequestDeserializer(
}).write("");
}

private static String getEventStreamMessageRequestSerializerName(
public static String getEventStreamMessageRequestSerializerName(
ToShapeId toShapeId,
ServiceShape serviceShape,
String protocolName
) {
return getSerDeName(toShapeId, serviceShape, protocolName, "_serializeEventMessageRequest");
}

private static String getEventStreamMessageResponseDeserializerName(
public static String getEventStreamMessageResponseDeserializerName(
ToShapeId toShapeId, ServiceShape serviceShape, String protocolName
) {
return getSerDeName(toShapeId, serviceShape, protocolName, "_deserializeEventMessageResponse");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Utility methods for generating AWS protocols.
*/
final class AwsProtocolUtils {
public final class AwsProtocolUtils {
private AwsProtocolUtils() {
}

Expand All @@ -47,7 +47,7 @@ private AwsProtocolUtils() {
*
* @param context The generation context.
*/
static void generateHttpProtocolTests(GenerationContext context) {
public static void generateHttpProtocolTests(GenerationContext context) {
Set<HttpProtocolUnitTestGenerator.ConfigValue> configValues = new TreeSet<>(SetUtils.of(
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.REGION_CONFIG_NAME)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright 2024 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.smithy.aws.go.codegen.protocol;

import static software.amazon.smithy.go.codegen.protocol.ProtocolUtil.hasEventStream;

import software.amazon.smithy.aws.go.codegen.AwsEventStreamUtils;
import software.amazon.smithy.aws.go.codegen.AwsFnProvider;
import software.amazon.smithy.aws.go.codegen.AwsProtocolUtils;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionGenerator;
import software.amazon.smithy.go.codegen.protocol.rpc2.cbor.Rpc2CborProtocolGenerator;
import software.amazon.smithy.model.knowledge.TopDownIndex;

/**
* Extension of the smithy-borne Rpc2CborProtocolGenerator to do protocol tests and event streams since that's currently
* a 2000+ line dumpster fire in this repo.
*/
public final class AwsRpc2CborProtocolGenerator extends Rpc2CborProtocolGenerator {
@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
public void generateEventStreamComponents(GenerationContext context) {
// This automagically wires up ALL the framing logic for both directions of streams. All we have to do is fill
// in the serde elsewhere (it's different signatures than normal request/response), see:
// * CborEventStreamSerializer
// * CborEventStreamDeserializer
AwsEventStreamUtils.generateEventStreamComponents(context);
}

@Override
public void generateEndpointResolution(GenerationContext context) {
new EndpointResolutionGenerator(new AwsFnProvider()).generate(context);
}

@Override
public void generateSharedSerializerComponents(GenerationContext ctx) {
super.generateSharedSerializerComponents(ctx);

var model = ctx.getModel();
var streamSerializers = TopDownIndex.of(model).getContainedOperations(ctx.getService()).stream()
.filter(it -> hasEventStream(model, model.expectShape(it.getOutputShape())))
.map(it -> (GoWriter.Writable) new CborEventStreamSerializer(ctx, it))
.toList();
ctx.getWriter().get().write(GoWriter.ChainWritable.of(streamSerializers).compose());
}

@Override
public void generateSharedDeserializerComponents(GenerationContext ctx) {
super.generateSharedDeserializerComponents(ctx);

var model = ctx.getModel();
var streamDeserializers = TopDownIndex.of(model).getContainedOperations(ctx.getService()).stream()
.filter(it -> hasEventStream(model, model.expectShape(it.getOutputShape())))
.map(it -> (GoWriter.Writable) new CborEventStreamDeserializer(ctx, it))
.toList();
ctx.getWriter().get().write(GoWriter.ChainWritable.of(streamDeserializers).compose());
}
}
Loading

0 comments on commit e49abeb

Please sign in to comment.