Skip to content

Commit

Permalink
service/ec2: Fix generation of number and bool struct members to be p…
Browse files Browse the repository at this point in the history
…ointers (aws#1195)

Adds a backfill customization to the Amazon EC2 API model so that all
unboxed number and boolean shapes are correctly decorated as boxed. The
API does not handle unboxed members. This causes the API client
generated from the model to be unusable in many cases.

The generated API client will contain breaking changes, but these
breaking changes are here to fix the API client that was unusable in
many ways.
  • Loading branch information
jasdel authored and jrichardpfs committed Feb 14, 2022
1 parent a00ca9d commit 3a11b1b
Show file tree
Hide file tree
Showing 437 changed files with 3,770 additions and 3,178 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ID": "service.ec2-announcement-1616786271582723000",
"SchemaVersion": 1,
"Module": "service/ec2",
"Type": "announcement",
"Description": "This release contains a breaking change to the Amazon EC2 API client. API number(int/int64/etc) and boolean members were changed from value, to pointer type. Your applications using the EC2 API client will fail to compile after upgrading for all members that were updated. To migrate to this module you'll need to update your application to use pointers for all number and boolean members in the API client module. The SDK provides helper utilities to convert between value and pointer types. For example the [aws.Bool](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws#Bool) function to get the address from a bool literal. Similar utilities are available for all other primative types in the [aws](https://pkg.go.dev/github.com/aws/aws-sdk-go-v2/aws) package.",
"MinVersion": "",
"AffectedModules": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ID": "service.ec2-bugfix-1616785668377831000",
"SchemaVersion": 1,
"Module": "service/ec2",
"Type": "bugfix",
"Description": "Fix incorrectly modeled Amazon EC2 number and boolean members in structures. The Amazon EC2 API client has been updated with a breaking change to fix all structure number and boolean members to be pointer types instead of value types. Fixes [#1107](https://github.com/aws/aws-sdk-go-v2/issues/1107), [#1178](https://github.com/aws/aws-sdk-go-v2/issues/1178), and [#1190](https://github.com/aws/aws-sdk-go-v2/issues/1190). This breaking change is made within the major version of the client' module, because the client operations failed and were unusable with value type number and boolean members with the EC2 API.",
"MinVersion": "v1.6.0",
"AffectedModules": null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package software.amazon.smithy.aws.go.codegen.customization;

import java.util.Set;
import java.util.logging.Logger;
import software.amazon.smithy.codegen.core.CodegenException;
import software.amazon.smithy.go.codegen.CodegenUtils;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.ShapeType;
import software.amazon.smithy.model.traits.BoxTrait;
import software.amazon.smithy.utils.SetUtils;

public class BackfillEc2UnboxedToBoxedShapes implements GoIntegration {
private static final Logger LOGGER = Logger.getLogger(BackfillEc2UnboxedToBoxedShapes.class.getName());

/**
* Map of service shape to Set of operation shapes that need to have this
* presigned url auto fill customization.
*/
public static final Set<ShapeId> SERVICE_SET = SetUtils.of(
ShapeId.from("com.amazonaws.ec2#AmazonEC2")
);

/**
* /**
* Updates the API model to customize all number and boolean unboxed shapes to be boxed.
*
* @param model API model
* @param settings Go codegen settings
* @return updated API model
*/
@Override
public Model preprocessModel(Model model, GoSettings settings) {
ShapeId serviceId = settings.getService();
if (!SERVICE_SET.contains(serviceId)) {
return model;
}

Model.Builder builder = model.toBuilder();

for (Shape shape : model.toSet()) {
// Only consider number and boolean shapes that are unboxed
if (shape.isMemberShape()) {
continue;
}
if (!(CodegenUtils.isNumber(shape) || shape.getType() == ShapeType.BOOLEAN)) {
continue;
}
if (shape.hasTrait(BoxTrait.class)) {
continue;
}

switch (shape.getType()) {
case BYTE:
shape = shape.asByteShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
case SHORT:
shape = shape.asShortShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
case INTEGER:
shape = shape.asIntegerShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
case LONG:
shape = shape.asLongShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
case FLOAT:
shape = shape.asFloatShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
case DOUBLE:
shape = shape.asDoubleShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
case BOOLEAN:
shape = shape.asBooleanShape().get().toBuilder()
.addTrait(new BoxTrait())
.build();
break;
default:
throw new CodegenException("unexpected shape type for " + shape.getId() + ", " + shape.getType());
}

builder.addShape(shape);
}

return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ software.amazon.smithy.aws.go.codegen.ResolveClientConfig
software.amazon.smithy.aws.go.codegen.customization.S3GetBucketLocation
software.amazon.smithy.aws.go.codegen.RequestResponseLogging
software.amazon.smithy.aws.go.codegen.customization.S3AddPutObjectUnseekableBodyDoc
software.amazon.smithy.aws.go.codegen.customization.BackfillEc2UnboxedToBoxedShapes
19 changes: 14 additions & 5 deletions internal/repotools/cmd/eachmodule/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ type WorkLog struct {
Output io.Reader
}

// CommandWorker provides a consumer of work jobs and posts results to the worklog
func CommandWorker(ctx context.Context, jobs <-chan Work, results chan<- WorkLog, outWriter io.ReadWriter) {
// CommandWorker provides a consumer of work jobs and posts results to the
// worklog.
func CommandWorker(ctx context.Context, jobs <-chan Work, results chan<- WorkLog, streamOut io.Writer) {
for {
var result WorkLog

Expand All @@ -35,9 +36,12 @@ func CommandWorker(ctx context.Context, jobs <-chan Work, results chan<- WorkLog
if !ok {
return
}
if outWriter == nil {
outWriter = bytes.NewBuffer(nil)
result.Output = outWriter

outBuffer := bytes.NewBuffer(nil)
outWriter := io.Writer(outBuffer)

if streamOut != nil {
outWriter = io.MultiWriter(outWriter, streamOut)
}

result.Path = w.Path
Expand All @@ -52,6 +56,11 @@ func CommandWorker(ctx context.Context, jobs <-chan Work, results chan<- WorkLog
if err := cmd.Run(); err != nil {
result.Err = fmt.Errorf("failed to run command, %v", err)
}

if streamOut == nil {
outReader := bytes.NewReader(outBuffer.Bytes())
result.Output = outReader
}
}

select {
Expand Down
6 changes: 3 additions & 3 deletions internal/repotools/cmd/eachmodule/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,11 @@ func run() (err error) {
for i := 0; i < atOnce; i++ {
go func() {
defer jobWG.Done()
var output io.ReadWriter
var streamOut io.Writer
if atOnce == 1 {
output = os.Stdout
streamOut = os.Stdout
}
CommandWorker(ctx, jobs, results, output)
CommandWorker(ctx, jobs, results, streamOut)
}()
}

Expand Down
2 changes: 1 addition & 1 deletion service/ec2/api_op_AcceptReservedInstancesExchangeQuote.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AcceptTransitGatewayVpcAttachment.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AcceptVpcEndpointConnections.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AcceptVpcPeeringConnection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AdvertiseByoipCidr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AllocateAddress.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AllocateHosts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssignIpv6Addresses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions service/ec2/api_op_AssignPrivateIpAddresses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions service/ec2/api_op_AssociateAddress.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssociateClientVpnTargetNetwork.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssociateDhcpOptions.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssociateEnclaveCertificateIamRole.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssociateRouteTable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssociateTransitGatewayRouteTable.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion service/ec2/api_op_AssociateVpcCidrBlock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions service/ec2/api_op_AttachClassicLinkVpc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3a11b1b

Please sign in to comment.