-
Notifications
You must be signed in to change notification settings - Fork 914
Duplicate all eventstream event shapes + add new legacy event modes #6052
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
Draft
alextwoods
wants to merge
18
commits into
master
Choose a base branch
from
alexwoo/eventstream-shared-shapes-duplicate-all
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
33f0010
Duplicate all eventstream event shapes + add new legacy event modes
alextwoods 00608dd
Add all existing eventstreams to customization w/ legacy mode
alextwoods 8224ea1
Merge branch 'master' into alexwoo/eventstream-shared-shapes-duplicat…
alextwoods 4b748f4
Fix codegen-generated-classes-test (add legacy customization)
alextwoods 1237efa
Add legacy customization flags to protocol tests
alextwoods 5b35d92
Refactor/cleanup processor + add check for duplicated shape names
alextwoods 9e7e110
Move naming to NamingStrategy
alextwoods 21afe11
Merge branch 'master' into alexwoo/eventstream-shared-shapes-duplicat…
alextwoods 87b40d8
Introduce new customization config instead of changing old config to …
alextwoods 1c9ee94
Update other service and test customization configs
alextwoods e7f09cf
Merge branch 'master' into alexwoo/eventstream-shared-shapes-duplicat…
alextwoods 6da34e2
Add changelog
alextwoods f6a8603
Fix protocol tests config
alextwoods a2d0ce2
Cleanup name
alextwoods 3baee8d
Update naming strategy + improve codegen testing
alextwoods ac3d591
Remove unused test files + fix test
alextwoods 84ccbbf
Remove unused import
alextwoods ce71369
Fix unused exception
alextwoods 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
92 changes: 92 additions & 0 deletions
92
...amazon/awssdk/codegen/customization/processors/EventStreamUniqueEventShapesProcessor.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,92 @@ | ||
/* | ||
* 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.customization.processors; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor; | ||
import software.amazon.awssdk.codegen.model.config.customization.LegacyEventGenerationMode; | ||
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel; | ||
import software.amazon.awssdk.codegen.model.service.ServiceModel; | ||
import software.amazon.awssdk.codegen.model.service.Shape; | ||
import software.amazon.awssdk.utils.Logger; | ||
|
||
/** | ||
* Processor for eventstreams that ensures that all eventstream event shapes are unique - for each eventstream/event it creates a | ||
* new shape with a unique name constructed from the EventStream and Event shape names: `[ShapeName][EventStreamName]`. Any legacy | ||
* eventstream/events (configured with the useLegacyEventGenerationScheme customization) are skipped. When an event shape is | ||
* shared between multiple eventstreams, it causes SDK generation/compilation failures. The top level shape POJO implements the | ||
* event stream interface for each stream and the return type of the sdkEventType method conflicts. | ||
*/ | ||
public final class EventStreamUniqueEventShapesProcessor implements CodegenCustomizationProcessor { | ||
private static final Logger log = Logger.loggerFor(EventStreamUniqueEventShapesProcessor.class); | ||
|
||
private final Map<String, Map<String, LegacyEventGenerationMode>> useLegacyEventGenerationScheme; | ||
|
||
public EventStreamUniqueEventShapesProcessor( | ||
Map<String, Map<String, LegacyEventGenerationMode>> useLegacyEventGenerationScheme) { | ||
this.useLegacyEventGenerationScheme = useLegacyEventGenerationScheme; | ||
} | ||
|
||
@Override | ||
public void preprocess(ServiceModel serviceModel) { | ||
Map<String, Shape> newEventShapes = new HashMap<>(); | ||
serviceModel.getShapes().forEach((name, shape) -> { | ||
if (!shape.isEventstream()) { | ||
return; | ||
} | ||
|
||
preprocessEventStream(serviceModel, name, shape, newEventShapes); | ||
}); | ||
serviceModel.getShapes().putAll(newEventShapes); | ||
} | ||
|
||
private void preprocessEventStream(ServiceModel serviceModel, String eventStreamName, Shape eventStreamShape, Map<String, | ||
Shape> newEventShapes) { | ||
Map<String, LegacyEventGenerationMode> eventLegacyModes = useLegacyEventGenerationScheme | ||
.getOrDefault(eventStreamName, Collections.emptyMap()); | ||
|
||
eventStreamShape.getMembers().forEach((memberName, member) -> { | ||
String eventShapeName = member.getShape(); | ||
Shape memberTargetShape = serviceModel.getShape(eventShapeName); | ||
LegacyEventGenerationMode legacyEventGenerationMode = eventLegacyModes | ||
.getOrDefault(memberName, LegacyEventGenerationMode.DISABLED); | ||
|
||
if (memberTargetShape.isEvent() && legacyEventGenerationMode == LegacyEventGenerationMode.DISABLED) { | ||
String newShapeName = eventShapeName + eventStreamName; | ||
if (serviceModel.getShapes().containsKey(newShapeName)) { | ||
// TODO: This could be an error instead. Its unlikely we'll run into this. And if we do, not creating the | ||
// unique name is only an issue when/if the event is shared with another event stream whos event/eventstream | ||
// shape name is also in the model. | ||
log.warn(() -> String.format("Shape name conflict, unable to create a new unique event shape name for %s in" | ||
+ " eventstream %s because %s already exists in the model. Skipping.", | ||
eventShapeName, eventStreamName, newShapeName)); | ||
} else { | ||
log.debug(() -> String.format("Creating new, unique, event shape for %s in eventstream %s: %s", | ||
eventShapeName, eventStreamName, newShapeName)); | ||
newEventShapes.put(newShapeName, memberTargetShape); | ||
member.setShape(newShapeName); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void postprocess(IntermediateModel intermediateModel) { | ||
// no-op | ||
} | ||
} |
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
alextwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
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
25 changes: 25 additions & 0 deletions
25
.../software/amazon/awssdk/codegen/model/config/customization/LegacyEventGenerationMode.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,25 @@ | ||
/* | ||
* 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.model.config.customization; | ||
|
||
/** | ||
* Legacy event generation modes. | ||
*/ | ||
public enum LegacyEventGenerationMode { | ||
DISABLED, | ||
NO_EVENT_SUBCLASS, // old legacy - do not generate subclasses of events | ||
NO_UNIQUE_EVENT_NAMES // new legacy - do not duplicate event shapes to ensure unique events | ||
} |
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
2 changes: 1 addition & 1 deletion
2
.../customizations/processors/uselegacyeventgenerationscheme/happy-case-customization.config
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"useLegacyEventGenerationScheme": { | ||
"EventStream": ["EventOne"] | ||
"EventStream": {"EventOne": "NO_EVENT_SUBCLASS"} | ||
}, | ||
"underscoresInNameBehavior": "ALLOW" | ||
} |
5 changes: 3 additions & 2 deletions
5
...izations/processors/uselegacyeventgenerationscheme/multiple-event-types-same-shape.config
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"useLegacyEventGenerationScheme": { | ||
"EventStream": ["EventOne", "secondEventOne"] | ||
} | ||
"EventStream": {"EventOne": "NO_EVENT_SUBCLASS", "secondEventOne": "NO_EVENT_SUBCLASS"} | ||
}, | ||
"underscoresInNameBehavior": "ALLOW" | ||
} |
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
13 changes: 13 additions & 0 deletions
13
...n/src/test/resources/software/amazon/awssdk/codegen/poet/eventstream/customization.config
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 |
---|---|---|
@@ -1,2 +1,15 @@ | ||
{ | ||
"useLegacyEventGenerationScheme": { | ||
"InputEventStream": {"InputEvent": "NO_UNIQUE_EVENT_NAMES"}, | ||
"InputEventStreamTwo": { | ||
"InputEventOne": "NO_UNIQUE_EVENT_NAMES", | ||
"InputEventTwo": "NO_UNIQUE_EVENT_NAMES" | ||
}, | ||
"EventStream": { | ||
"EventOne": "NO_UNIQUE_EVENT_NAMES", | ||
"EventTwo": "NO_UNIQUE_EVENT_NAMES", | ||
"secondEventOne": "NO_UNIQUE_EVENT_NAMES", | ||
"secondeventtwo": "NO_UNIQUE_EVENT_NAMES" | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
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.