-
Notifications
You must be signed in to change notification settings - Fork 909
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
base: master
Are you sure you want to change the base?
Duplicate all eventstream event shapes + add new legacy event modes #6052
Conversation
...re/amazon/awssdk/codegen/customization/processors/EventStreamUniqueEventShapesProcessor.java
Outdated
Show resolved
Hide resolved
The current non-legacy way is there's a package per eventstream, e.g. |
We could, but it would require fairly large changes in multiple parts of the code generation and require maintaining 3 separate paths through codegen (for each of the cases) including marshallers, builders and others. The benefit of renaming the shape up front is that all other parts of the codegen are able to remain the same, but it doesn't let us change the packaging/namespace of the generated classes. |
I did try to put together a POC for this but It would require a much more significant refactoring to get working. There are a few issues/sharp edges:
|
...main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java
Outdated
Show resolved
Hide resolved
@@ -411,6 +412,12 @@ public String getUnionEnumTypeName(MemberModel memberModel) { | |||
return screamCase(memberModel.getName()); | |||
} | |||
|
|||
@Override | |||
public String getUniqueEventStreamEventShapeName(Member eventMember, String eventStreamName) { | |||
return eventMember.getShape() + eventStreamName; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checking: is it necessary to have eventmember.getShape()
be capitalized here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? The parameter name eventMember
? Or do you mean we should apply some naming transform of the shape name to ensure it has correct capitalization?
RE: the parameter name, theres no reason it couldn't be eventmember
.
RE: applying capitalization to the existing shape name - Thats a good question - I was assuming that the existing shape name has already been validated (and any divergence from standard is intended and should be preserved).
* Create a builder for the {@code Person} event type for this stream. | ||
*/ | ||
static PersonStreamDeathsInputEventStream.Builder personBuilder() { | ||
return DefaultPerson.builder(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have tests to verify the code for DefaultPerson
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SharedStreamAwsModelSpecTest
is testing only the interfaces, but EventModelSpecTest
(which uses a different model) tests tests the Default<Shape>
generation (but not the interfaces) for event stream event shapes - between the two I think we get decent coverage of all of the files we're generating.
It might be a little tricky, but the SharedStreamAwsModelSpecTest could probably be updated to test the implementations (ie Default<shape>.java
) as well but we would need to add files for all of the shapes I think. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah let's do that please. I don't think we need to do it for every renamed shape, just for a sample.
services/bedrockagentruntime/src/main/resources/codegen-resources/customization.config
Outdated
Show resolved
Hide resolved
|
Fixes codegeneration issues for eventstreams with shared event shapes: Duplicate and rename all eventstream event shapes with a unique name + add new disableUniqueEventStreamShapePreprocessing customization config.
Motivation and Context
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.
Modifications
This PR does two things:
disableUniqueEventStreamShapePreprocessing
customization config.useLegacyEventGenerationScheme
anddisableUniqueEventStreamShapePreprocessing
is unset a for an event, the event shape will be duplicated and given a unique name:<ShapeName><EventStreamName>
.Note: There are a large number of changes in the codegen test to add the new customization mode to existing test eventstreams.
Open Questions
What naming scheme should we use to produce unique names?
This PR currently uses
<ShapeName><EventStreamName>
, for example an event namedPayload
in eventstreamStreamA
would get the name:PayloadStreamA
. We could reverse this (StreamAPayload
).The downside of this naming scheme is that it can produce long names. For example the existing HeartbeatEvent from LexRuntimeV2's StartConversationResponseEventStream would be (without the legacy customization) renamed to:
HeartbeatEventStartConversationResponseEventStream
.FAQ
Why do we always need to rename the event shape? Couldn't we do that only when there is a shared event?
We must ensure that shapes names are deterministic and do not depend on the shapes in the model because if a shared event shape is added in the future, we have no way of telling which was the existing shape.
Alternatives
For POCs of alternative approaches see:
User Experience
There are no changes for users for any existing Eventstreams/events. New eventstreams or new events added to existing evenstreams will have unique, longer names, but the fluid visitor and builder methods will continue to use the member names. For example, assuming we have
Payload
event (with member name "PayloadEvent") in eventstreamStreamA
, the handler and builder methods will still beonPayloadEvent
andpayloadEventBuilder
.Note: For users using switch/case or if/else on
sdkEventType
or checkinginstance of
, when casting the events they will need to use the longer shape names. Using the example from above:Testing
New Unit tests - see shared event stream cases (model was modified to add new streams that share an event)
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License