Skip to content

Use partitions.json to generate Region class #6120

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

S-Saranya1
Copy link
Contributor

@S-Saranya1 S-Saranya1 commented May 20, 2025

Updated Region class generation to use Partitions.json instead of the Endpoints.json and removed the hardcoded global regions.

Motivation and Context

  • Currently we are using deprecated endpoints.json to generate Region class and using hardcoded global regions.
  • Switching to use partisions.json.resource to generate Region class which contains all regions.

Modifications

  • Updated Region class generation to use partisions.json.resource file
  • Removed the hardcoded global regions
  • Added tests

Testing

  • Added unit tests to verify the correct generation of global regions.
  • After code generation, confirmed that all regions, including global ones, were properly generated from partisions.json.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@S-Saranya1 S-Saranya1 requested a review from a team as a code owner May 20, 2025 16:26
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
58.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@@ -59,19 +59,24 @@ public class RegionGenerationMojo extends AbstractMojo {
"${basedir}/src/main/resources/software/amazon/awssdk/regions/internal/region/endpoints.json")
private File endpoints;

@Parameter(property = "partitionsjson", defaultValue =
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 the j is lower case? (ie, why not partitionsJson?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, my bad. I'll update it.

public Partition() {
}

public Partition(@JsonProperty(value = "partition") String partition,
@JsonProperty(value = "regions") Map<String, PartitionRegion>
regions,
@JsonProperty(value = "services") Map<String,
Service> services) {
Service> services,
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like its a little weird to squish both the legacy endponts.json partitions and the new partitions metadata (partitions.json) model together - How much of a refactor would be required to add a new PartitionsMetadata model that models only the new partitions.json?

I think that would make the code in RegionGenerationMojo more clear as well (since its not clear to me which of the generation functions require which version of partitions).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, creating a separate PartitionsMetadata model would be more clear. However, the main issue is that some generation functions like generateServiceProvider and generateEndpointTags still require data from endpoints.json, as services and endpoints aren't present in partitions.json. So for now, using partitions.json only for region generation.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that makes sense - I'm not suggesting that we completly replace the existing Partition model since its still required. I'm just suggesting that we create a new PartitionsMetadata model and use it in the places where we can. That way we don't have Partition objects that have missing/incomplete data (eg, in the current code, regionpartitions will have empty service maps, since partitions.json doesn't have that information).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, got it. I'll make that change.

@Override
public void execute() throws MojoExecutionException {
Path baseSourcesDirectory = Paths.get(outputDirectory).resolve("generated-sources").resolve("sdk");
Path testsDirectory = Paths.get(outputDirectory).resolve("generated-test-sources").resolve("sdk-tests");

Partitions partitions = RegionMetadataLoader.build(endpoints);
Partitions regionpartitions = RegionMetadataLoader.build(partitionsjson);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here - is there a reason not to name this regionPartitions?

Alternative naming thought - rename partitions above to legacyPartitions and the new one to just partitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, that's a good idea. I'll rename the partitions above to legacyPartitions and the new one to just partitions.

@@ -59,19 +59,24 @@ public class RegionGenerationMojo extends AbstractMojo {
"${basedir}/src/main/resources/software/amazon/awssdk/regions/internal/region/endpoints.json")
private File endpoints;

@Parameter(property = "partitionsjson", defaultValue =
"${basedir}/src/main/resources/software/amazon/awssdk/regions/internal/region/partitions.json.resource")
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 use the same file in codegen? Otherwise, we'd need to update our release system to keep it updated and if it's not possible, I'd prefer to keep the file in codegen-lite instead of core since we don't want anyone to use it or load it at runtime.

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