Skip to content
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

feat: Support more services on Java #504

Merged
merged 31 commits into from
Oct 9, 2024

Conversation

robin-aws
Copy link
Contributor

@robin-aws robin-aws commented Aug 6, 2024

Description of changes:
Tweaking several aspects of Java codegen to generalize more effectively beyond DDB and KMS:

  • Implement a general pattern for determining the base exception and client typesRE for a service based on the sdkId, rather than hardcoding only DDB or KMS.
  • Removed the shapeRequiresTypeConversionFromStringToStructure special casing, as it didn't work correctly for other services, and it actually turns out that the KMS project in the MPL was already patching it back to the correct thing anyway :)
  • Handling more name transformations generally:
    • Using Utils.unCapitalize from the awssdk:codegen package instead of our own copy, to match names better.
    • Adding Request/Response to the name of the operation, instead of always replacing Input/Output suffixes of any structure.
  • Switched the lakeformation test model to omit the GetWorkUnitResults operation, since it has a streaming result. This is specifically a blocker on Java because the result type becomes a ResponseInputStream<GetWorkUnitResultsResponse> instead of a GetWorkUnitResultsResponse, so the shim code doesn't compile otherwise.

I verified that regenerating the DDB and KMS java code in MPL does not change on this version, aside from making a patching unnecessary as above.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -162,7 +152,7 @@ private TypeName typeForShapeNoEnum(ShapeId shapeId) {
final Shape shape = model.expectShape(shapeId);

if (shape.hasTrait(EnumTrait.class)) {
if (shapeRequiresTypeConversionFromStringToStructure(shapeId)) {
if (true || shapeRequiresTypeConversionFromStringToStructure(shapeId)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An or with a constant true is illogical.

Is there a TODO here? Or should we just remove the if?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implicit TODO, I was experimenting with whether we needed this test anymore. Will resolve before marking the PR actually ready :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah... there was an edge case with Enums and the Java SDK
that I used this to work around.

I swear I described it somewhere in Java codegen...

@@ -525,6 +525,7 @@ transpile_test_java: _transpile_test_all _mv_test_java
# To avoid `java/implementation-java` the code is generated and then moved.
_mv_implementation_java:
rm -rf runtimes/java/src/main/dafny-generated
mkdir -p runtimes/java/src/main
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right?
If you run mkdir against an existing directory, does it succeed?
Or does it fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It succeeds - -p makes it recursively create all missing directories, so it's perfectly happy if all already exist

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notice the same thing is already on the runtimes/java/src/test directory. I actually don't know how we got away without this fix for so long. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because you did not use to generate the template files,
and we had to manually stub the __default.java files in the Java extern source path.

Thus, we always had a directory.

@robin-aws robin-aws changed the title Robin aws/support more services on java feat: Support more services on Java Oct 4, 2024
@robin-aws robin-aws marked this pull request as ready for review October 4, 2024 20:37
@robin-aws robin-aws requested a review from a team as a code owner October 4, 2024 20:37
@@ -378,4 +372,8 @@ public ClassName baseErrorForService() {
"Use `ClassName.get(RuntimeException.class)` instead."
);
}

protected ClassName classNameForAwsSdkShape(final Shape shape) {
throw new UnsupportedOperationException();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a message here to explain why it's unsupported?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you one better and made Native abstract so this could be abstract too. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scratch that, the Native class is used directly for non SDK-style projects as well. I reverted and added an exception message instead. The better change would be to have an intermediate base class in between Native and AwsSdkNativeV1/2, but that looks like a substantial refactoring.

);
}
}
private static void checkForAwsServiceConstants(String namespace) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason to keep this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had initially thought so, since although I've removed all the checks necessary there could be some in the future. But on second thought, I think those kinds of checks should be model validations instead anyway, so I've removed this.

These should be validations instead if we add some
This reverts commit f87f309.

# Conflicts:
#	codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithyjava/generator/library/JavaLibrary.java
…smithy-lang/smithy-dafny into robin-aws/support-more-services-on-java
@robin-aws robin-aws merged commit 6268c40 into main-1.x Oct 9, 2024
80 checks passed
@robin-aws robin-aws deleted the robin-aws/support-more-services-on-java branch October 9, 2024 17:26
ShubhamChaturvedi7 pushed a commit that referenced this pull request Oct 18, 2024
*Description of changes:*
Tweaking several aspects of Java codegen to generalize more effectively beyond DDB and KMS:

* Implement a general pattern for determining the base exception and client typesRE for a service based on the `sdkId`, rather than hardcoding only DDB or KMS.
* Removed the `shapeRequiresTypeConversionFromStringToStructure` special casing, as it didn't work correctly for other services, and it actually turns out that the KMS project in the MPL was already patching it back to the correct thing anyway :)
* Handling more name transformations generally:
  * Using `Utils.unCapitalize` from the `awssdk:codegen` package instead of our own copy, to match names better.
  * Adding `Request`/`Response` to the name of the operation, instead of always replacing `Input`/`Output` suffixes of any structure.
* Switched the lakeformation test model to omit the `GetWorkUnitResults` operation, since it has a streaming result. This is specifically a blocker on Java because the result type becomes a `ResponseInputStream<GetWorkUnitResultsResponse>` instead of a `GetWorkUnitResultsResponse`, so the shim code doesn't compile otherwise.

I verified that regenerating the DDB and KMS java code in MPL does not change on this version, aside from making a patching unnecessary as above.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants