Skip to content

Commit 34a6884

Browse files
authored
Merge pull request #651 from aws/h2
Merging H2 changes to master
2 parents 56d2a8a + 2629e30 commit 34a6884

File tree

154 files changed

+12170
-668
lines changed

Some content is hidden

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

154 files changed

+12170
-668
lines changed

build-tools/src/main/resources/software/amazon/awssdk/checkstyle-suppressions.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
<suppress checks=".*"
2424
files=".*[\\/](test|it)[\\/]java[\\/].+\.java$"/>
2525

26+
<!-- TODO: Disable these suppressions. -->
27+
<suppress checks=".*"
28+
files=".(flow)[\\/].+\.java$"/>
29+
2630
<!-- ignore missing annotation checks under test/codegen directory -->
2731
<suppress checks="MissingSdkAnnotationCheck"
2832
files=".(codegen|test)[\\/].+\.java$"/>
@@ -31,6 +35,14 @@
3135
<suppress checks="MissingSdkAnnotationCheck"
3236
files=".(services)[\\/].+\.java$"/>
3337

38+
<!-- TODO want to contribute this back to Netty -->
39+
<suppress checks=".*"
40+
files=".*BetterFixedChannelPool\.java$"/>
41+
42+
<!-- TODO want to contribute this back to Netty -->
43+
<suppress checks=".*"
44+
files=".*[\\/]io[\\/]netty[\\/]handler[\\/]codec[\\/]http2[\\/].*\.java$"/>
45+
3446
<!-- Assumes getter/setter match JSON property -->
3547
<suppress checks="AbbreviationAsWordInName"
3648
files=".*[\\/]software[\\/]amazon[\\/]awssdk[\\/]services[\\/]s3[\\/]event[\\/]S3EventNotification.java$"/>

build-tools/src/main/resources/software/amazon/awssdk/spotbugs-suppressions.xml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,6 @@
6161
<Bug pattern="URF_UNREAD_FIELD,DLS_DEAD_LOCAL_STORE,REC_CATCH_EXCEPTION" />
6262
</Match>
6363

64-
<!-- NP_NONNULL_PARAM_VIOLATION false postive - https://github.com/spotbugs/spotbugs/issues/484 -->
65-
<Match>
66-
<Class name="software.amazon.awssdk.core.pagination.async.SequentialSubscriber" />
67-
<Method name="onComplete" />
68-
<Bug pattern="NP_NONNULL_PARAM_VIOLATION" />
69-
</Match>
70-
7164
<!-- False positive -->
7265
<Match>
7366
<Class name="software.amazon.awssdk.core.ResponseBytes" />
@@ -103,4 +96,12 @@
10396
<Bug pattern="RI_REDUNDANT_INTERFACES" />
10497
</Match>
10598

99+
<Match>
100+
<Or>
101+
<Package name="io.netty.handler.codec.http2"/>
102+
<Class name="software.amazon.awssdk.http.nio.netty.internal.utils.BetterFixedChannelPool" />
103+
</Or>
104+
<Bug pattern="BC_UNCONFIRMED_CAST,SIC_INNER_SHOULD_BE_STATIC_ANON,DLS_DEAD_LOCAL_STORE,DM_CONVERT_CASE,NM_CLASS_NOT_EXCEPTION,NP_NULL_ON_SOME_PATH"/>
105+
</Match>
106+
106107
</FindBugsFilter>

bundle/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<include>commons-codec:commons-codec</include>
7575
<include>software.amazon.ion:ion-java</include>
7676
<include>software.amazon.awssdk:*</include>
77+
<include>software.amazon:*</include>
7778
<include>commons-logging:*</include>
7879
</includes>
7980
</artifactSet>

codegen/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<artifactId>annotations</artifactId>
4141
<version>${awsjavasdk.version}</version>
4242
</dependency>
43+
<dependency>
44+
<groupId>software.amazon.awssdk</groupId>
45+
<artifactId>http-client-spi</artifactId>
46+
<version>${awsjavasdk.version}</version>
47+
</dependency>
4348
<dependency>
4449
<groupId>software.amazon.awssdk</groupId>
4550
<artifactId>regions</artifactId>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public static Metadata constructMetadata(ServiceModel serviceModel,
9797
.withSigningName(serviceMetadata.getSigningName())
9898
.withAuthType(AuthType.fromValue(serviceMetadata.getSignatureVersion()))
9999
.withRequiresApiKey(requiresApiKey(serviceModel))
100-
.withUid(serviceMetadata.getUid());
100+
.withUid(serviceMetadata.getUid())
101+
.withSupportsH2(supportsH2(serviceMetadata));
101102

102103
final String jsonVersion = getJsonVersion(metadata, serviceMetadata);
103104
metadata.setJsonVersion(jsonVersion);
@@ -108,6 +109,10 @@ public static Metadata constructMetadata(ServiceModel serviceModel,
108109
return metadata;
109110
}
110111

112+
private static boolean supportsH2(ServiceMetadata serviceMetadata) {
113+
return serviceMetadata.getProtocolSettings() != null && serviceMetadata.getProtocolSettings().containsKey("h2");
114+
}
115+
111116
private static String getJsonVersion(Metadata metadata, ServiceMetadata serviceMetadata) {
112117
// TODO this should be defaulted in the C2J build tool
113118
if (serviceMetadata.getJsonVersion() == null && metadata.isJsonProtocol()) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private Map<String, ShapeModel> constructModelShapes(Set<String> shapesToSkip) {
5353
ShapeType shapeType = getModelShapeType(shape);
5454

5555
if (shapeType != null) {
56-
final String javaClassName = getNamingStrategy().getJavaClassName(shapeName);
56+
String javaClassName = getNamingStrategy().getJavaClassName(shapeName);
5757
if (shapesToSkip.contains(javaClassName)) {
5858
continue;
5959
}
@@ -77,6 +77,9 @@ private Map<String, ShapeModel> constructModelShapes(Set<String> shapesToSkip) {
7777
* @return null if the given shape is neither a structure nor enum model.
7878
*/
7979
private ShapeType getModelShapeType(final Shape shape) {
80+
if (shape.isException()) {
81+
return null;
82+
}
8083
if (isStructure(shape)) {
8184
return ShapeType.Model;
8285

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ protected final ShapeModel generateShapeModel(String javaClassName, String shape
8080
shapeModel.setRequired(shape.getRequired());
8181
shapeModel.setDeprecated(shape.isDeprecated());
8282
shapeModel.setWrapper(shape.isWrapper());
83+
shapeModel.withIsEventStream(shape.isEventStream());
84+
shapeModel.withIsEvent(shape.isEvent());
8385

8486
boolean hasHeaderMember = false;
8587
boolean hasStatusCodeMember = false;

codegen/src/main/java/software/amazon/awssdk/codegen/docs/PaginationDocs.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
2626
import software.amazon.awssdk.codegen.poet.PoetExtensions;
2727
import software.amazon.awssdk.codegen.utils.PaginatorUtils;
28-
import software.amazon.awssdk.core.pagination.async.SequentialSubscriber;
28+
import software.amazon.awssdk.utils.async.SequentialSubscriber;
2929

3030
public class PaginationDocs {
3131

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/AwsGeneratorTasks.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public AwsGeneratorTasks(GeneratorTaskParams params) {
3535
private Iterable<GeneratorTask> createAwsTasks(GeneratorTaskParams params) {
3636
// TODO Move AsyncClientGeneratorTasks to common generic tasks (mostly CommonGeneratorTasks class)
3737
return new CompositeIterable<>(new AsyncClientGeneratorTasks(params),
38-
new PaginatorsGeneratorTasks(params));
38+
new PaginatorsGeneratorTasks(params),
39+
new EventStreamGeneratorTasks(params));
3940
}
4041

4142
@Override
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2010-2018 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.emitters.tasks;
17+
18+
import java.util.List;
19+
import java.util.stream.Collectors;
20+
import java.util.stream.Stream;
21+
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
22+
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
23+
import software.amazon.awssdk.codegen.emitters.PoetGeneratorTask;
24+
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
25+
import software.amazon.awssdk.codegen.poet.ClassSpec;
26+
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamResponseHandlerBuilderImplSpec;
27+
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamResponseHandlerSpec;
28+
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
29+
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamVisitorBuilderImplSpec;
30+
31+
/**
32+
* Generator tasks for event streaming operations.
33+
*/
34+
class EventStreamGeneratorTasks extends BaseGeneratorTasks {
35+
36+
private final GeneratorTaskParams params;
37+
38+
EventStreamGeneratorTasks(GeneratorTaskParams dependencies) {
39+
super(dependencies);
40+
this.params = dependencies;
41+
}
42+
43+
@Override
44+
protected List<GeneratorTask> createTasks() throws Exception {
45+
info("Emitting event stream classes");
46+
47+
String fileHeader = model.getFileHeader();
48+
String modelDirectory = params.getPathProvider().getModelDirectory();
49+
return model.getOperations().values().stream()
50+
.filter(OperationModel::hasEventStreamOutput)
51+
.flatMap(this::eventStreamClassSpecs)
52+
.map(spec -> new PoetGeneratorTask(modelDirectory, fileHeader, spec))
53+
.collect(Collectors.toList());
54+
}
55+
56+
private Stream<ClassSpec> eventStreamClassSpecs(OperationModel opModel) {
57+
EventStreamUtils eventStreamUtils = EventStreamUtils.create(params.getPoetExtensions(), opModel);
58+
return Stream.of(
59+
new EventStreamResponseHandlerSpec(params, eventStreamUtils),
60+
new EventStreamResponseHandlerBuilderImplSpec(params, eventStreamUtils),
61+
new EventStreamVisitorBuilderImplSpec(params, eventStreamUtils));
62+
}
63+
}

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/MarshallerGeneratorTasks.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,10 @@ private boolean shouldGenerate(ShapeModel shapeModel) {
6161
info("Skip generating marshaller class for " + shapeModel.getShapeName());
6262
return false;
6363
}
64-
return shouldGenerate(shapeModel.getShapeType());
65-
}
66-
67-
private boolean shouldGenerate(ShapeType shapeType) {
68-
return ShapeType.Request == shapeType || (ShapeType.Model == shapeType && metadata.isJsonProtocol());
64+
ShapeType shapeType = shapeModel.getShapeType();
65+
return (ShapeType.Request == shapeType || (ShapeType.Model == shapeType && metadata.isJsonProtocol()))
66+
// The event stream shape is a container for event subtypes and isn't something that needs to ever be marshalled
67+
&& !shapeModel.isEventStream();
6968
}
7069

7170
private Stream<GeneratorTask> createTask(String javaShapeName, ShapeModel shapeModel) throws Exception {

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/UnmarshallerGeneratorTasks.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,11 @@ private boolean shouldGenerate(ShapeModel shapeModel) {
8585
info("Skip generating unmarshaller class for " + shapeModel.getShapeName());
8686
return false;
8787
}
88-
return shouldGenerate(shapeModel.getShapeType());
89-
}
90-
91-
private boolean shouldGenerate(ShapeType shapeType) {
92-
switch (shapeType) {
88+
switch (shapeModel.getShapeType()) {
9389
case Response:
9490
case Model:
95-
return true;
91+
// The event stream shape is a container for event subtypes and isn't something that needs to ever be unmarshalled
92+
return !shapeModel.isEventStream();
9693
case Exception:
9794
// Generating Exception Unmarshallers is not required for the JSON protocol
9895
return !metadata.isJsonProtocol();

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/MemberModel.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,5 +553,4 @@ private void appendParagraph(StringBuilder builder, String content, Object... co
553553
.append("</p>")
554554
.append(LF);
555555
}
556-
557556
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/Metadata.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public class Metadata {
103103

104104
private String baseResponseName;
105105

106+
private boolean supportsH2;
107+
106108
public String getApiVersion() {
107109
return apiVersion;
108110
}
@@ -717,4 +719,12 @@ public Metadata withBaseResponseName(String baseResponseName) {
717719
private String joinPackageNames(String lhs, String rhs) {
718720
return StringUtils.isBlank(rhs) ? lhs : lhs + '.' + rhs;
719721
}
722+
723+
public boolean supportsH2() {
724+
return supportsH2;
725+
}
726+
727+
public void withSupportsH2(boolean supportsH2) {
728+
this.supportsH2 = supportsH2;
729+
}
720730
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/OperationModel.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,16 @@ public boolean isPaginated() {
188188
public void setPaginated(boolean paginated) {
189189
isPaginated = paginated;
190190
}
191+
192+
/**
193+
* @return True if the operation has an event stream member in the output shape. False otherwise.
194+
*/
195+
public boolean hasEventStreamOutput() {
196+
return outputShape != null
197+
&& outputShape.getMembers() != null
198+
&& outputShape.getMembers().stream()
199+
.filter(m -> m.getShape() != null)
200+
.anyMatch(m -> m.getShape().isEventStream());
201+
}
202+
191203
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/ShapeModel.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ public class ShapeModel extends DocumentationModel implements HasDeprecation {
5959

6060
private ShapeCustomizationInfo customization = new ShapeCustomizationInfo();
6161

62+
private boolean isEventStream;
63+
64+
private boolean isEvent;
65+
6266
public ShapeModel(@JsonProperty("c2jName") String c2jName) {
6367
this.c2jName = c2jName;
6468
}
@@ -272,7 +276,10 @@ public List<MemberModel> getMembers() {
272276
*/
273277
public List<MemberModel> getNonStreamingMembers() {
274278
return getMembers().stream()
279+
// Filter out binary streaming members
275280
.filter(m -> !m.getHttp().getIsStreaming())
281+
// Filter out event stream members (if shape is null then it's primitive and we should include it).
282+
.filter(m -> m.getShape() == null || !m.getShape().isEventStream)
276283
.collect(Collectors.toList());
277284
}
278285

@@ -449,4 +456,29 @@ public void setRequestSignerClassFqcn(String authorizerClass) {
449456
this.requestSignerClassFqcn = authorizerClass;
450457
}
451458

459+
/**
460+
* @return True if the shape is an 'eventstream' shape. The eventstream shape is the tagged union like
461+
* container that holds individual 'events'.
462+
*/
463+
public boolean isEventStream() {
464+
return this.isEventStream;
465+
}
466+
467+
public ShapeModel withIsEventStream(boolean isEventStream) {
468+
this.isEventStream = isEventStream;
469+
return this;
470+
}
471+
472+
/**
473+
* @return True if the shape is an 'event'. I.E. It is a member of the eventstream and represents one logical event
474+
* that can be delivered on the event stream.
475+
*/
476+
public boolean isEvent() {
477+
return this.isEvent;
478+
}
479+
480+
public ShapeModel withIsEvent(boolean isEvent) {
481+
this.isEvent = isEvent;
482+
return this;
483+
}
452484
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/ServiceMetadata.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package software.amazon.awssdk.codegen.model.service;
1717

18+
import java.util.Map;
19+
1820
public class ServiceMetadata {
1921

2022
private String apiVersion;
@@ -43,6 +45,8 @@ public class ServiceMetadata {
4345

4446
private String uid;
4547

48+
private Map<String, String> protocolSettings;
49+
4650
public String getApiVersion() {
4751
return apiVersion;
4852
}
@@ -142,6 +146,14 @@ public void setUid(String uid) {
142146
this.uid = uid;
143147
}
144148

149+
public Map<String, String> getProtocolSettings() {
150+
return protocolSettings;
151+
}
152+
153+
public void setProtocolSettings(Map<String, String> protocolSettings) {
154+
this.protocolSettings = protocolSettings;
155+
}
156+
145157
public String getServiceId() {
146158
return serviceId;
147159
}

0 commit comments

Comments
 (0)