Skip to content

Generation region/service metadata #759

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

Merged
merged 1 commit into from
Oct 23, 2018
Merged

Conversation

spfink
Copy link
Contributor

@spfink spfink commented Oct 15, 2018

Introduces two new modules, codegen-lite and codegen-lite-maven-plugin in order to be able to generate region and service metadata for the regions module.

Could also refactor codegen-lite into codegen-core and move the core non-service related codegen files to this module

@Generated("software.amazon.awssdk:codegen")
@SdkPublicApi
public final class Batch implements ServiceMetadata {
    private static final String ENDPOINT_PREFIX = "batch";

    private static final Map<String, String> REGION_OVERRIDDEN_ENDPOINTS = new HashMap();

    private static final List<Region> REGIONS = Collections.unmodifiableList(Arrays.asList(Region.AP_NORTHEAST_1,
            Region.AP_NORTHEAST_2, Region.AP_SOUTH_1, Region.AP_SOUTHEAST_1, Region.AP_SOUTHEAST_2, Region.CA_CENTRAL_1,
            Region.EU_CENTRAL_1, Region.EU_WEST_1, Region.EU_WEST_2, Region.EU_WEST_3, Region.SA_EAST_1, Region.US_EAST_1,
            Region.US_EAST_2, Region.US_WEST_1, Region.US_WEST_2));

    private static final Map<String, String> SIGNING_REGION_OVERRIDES = new HashMap();

    @Override
    public List<Region> regions() {
        return REGIONS;
    }

    @Override
    public URI endpointFor(Region region) {
        return URI.create(REGION_OVERRIDDEN_ENDPOINTS.getOrDefault(region.id(), computeEndpoint(ENDPOINT_PREFIX, region)));
    }

    @Override
    public Region signingRegion(Region region) {
        return Region.of(SIGNING_REGION_OVERRIDES.getOrDefault(region.id(), region.id()));
    }
}
@Generated("software.amazon.awssdk:codegen")
@SdkPublicApi
public final class UsEast1 implements RegionMetadata {
    private static final String ID = "us-east-1";

    private static final String DOMAIN = "amazonaws.com";

    private static final String NAME = "US East (N. Virginia)";

    private static final String PARTITION = "aws";

    public String name() {
        return NAME;
    }

    public String domain() {
        return DOMAIN;
    }

    public String id() {
        return ID;
    }

    public String partition() {
        return PARTITION;
    }
}

Copy link
Contributor

@shorea shorea left a comment

Choose a reason for hiding this comment

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

Can you add those diff tests for the new generated classes? Also do we still support custom endpoint files at runtime?

@shorea
Copy link
Contributor

shorea commented Oct 15, 2018

Could we rename the generated metadata file to something like BatchServiceMetadata?

@shorea
Copy link
Contributor

shorea commented Oct 15, 2018

Can the region class itself be generated?

@spfink
Copy link
Contributor Author

spfink commented Oct 15, 2018

Will add diff tests.

Fine with adding ServiceMetadata suffix.

Can switch Region to be generated as well.

</build>

<profiles>
<!-- Build steps executed for services with models -->
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain what this does? not quite getting it.

Copy link
Contributor Author

@spfink spfink Oct 18, 2018

Choose a reason for hiding this comment

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

This comment is slightly incorrect as I just copied it from the other but it's just the configuration for running the codegen-lite-maven-plugin. It's exactly copied from the pom.xml of the services module just with the "lite" version.

@Generated("software.amazon.awssdk:codegen")
@SdkPublicApi
public final class ServiceMetadataProvider {
private static final Map<String, ServiceMetadata> SERVICE_METADATA = Collections.unmodifiableMap(Stream.of(
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 ImmutableMap.Builder here? I feel like that would cut down on the verbosity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do.

import software.amazon.awssdk.annotations.SdkPublicApi;
import software.amazon.awssdk.utils.Validate;

/**
* An Amazon Web Services region that hosts a set of Amazon services.
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 keep the docs in the generated version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, yes. This was just a miss.


@Generated("software.amazon.awssdk:codegen")
@SdkPublicApi
public final class RegionMetadataProvider {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we keep this an interface if we decide to support runtime discovery later on?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Will do.

@spfink spfink force-pushed the finks/region-metadata-generation branch from 4e5786e to 2bb3232 Compare October 23, 2018 21:03
@spfink spfink merged commit aa98f76 into master Oct 23, 2018
@zoewangg zoewangg deleted the finks/region-metadata-generation branch November 29, 2018 19:31
aws-sdk-java-automation added a commit that referenced this pull request Mar 18, 2020
…ebd93e04

Pull request: release <- staging/28b5df1f-0704-4b85-828f-760bebd93e04
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.

2 participants