Skip to content

convertion from string to enum fails #5691

Open

Description

@nmesika-te

Describe the bug

When issuing an ec2::DescribeNetworkInterfaces, the returned NetworkInterfaceType is a string that the sdk can convert to an Enum using an internal map. However, the value returned by the API for Nat Gateway does not match the value in the map. The result is that the Enum value returned does not correctly reflect the type of the interface (an "unknown to sdk" Enum value is returned)

Here are the returned values from services/ec2/src/main/resources/codegen-resources/service-2.json:46316:

    "NetworkInterfaceType":{
      "type":"string",
      "enum":[
        "interface",
        "natGateway",
        "efa",
        "trunk",
        "load_balancer",
        "network_load_balancer",
        "vpc_endpoint",
        "branch",
        "transit_gateway",
        "lambda",
        "quicksight",
        "global_accelerator_managed",
        "api_gateway_managed",
        "gateway_load_balancer",
        "gateway_load_balancer_endpoint",
        "iot_rules_managed",
        "aws_codestar_connections_managed"
      ]
    },

Note that natGateway is camel cased while the others use underscores.
Following is the the XML response from the AWS API for a specific interface. Note the last line <interfaceType>nat_gateway</interfaceType>

        <item>
            <networkInterfaceId>eni-0c712113537506cd7</networkInterfaceId>
            <subnetId>subnet-0a415aa89455cf4f8</subnetId>
            <vpcId>vpc-04f987fff6675ec10</vpcId>
            <availabilityZone>us-west-1a</availabilityZone>
            <description>Interface for NAT Gateway nat-06a39644e236c7926</description>
            <ownerId>036476006320</ownerId>
            <requesterId>213236389121</requesterId>
            <requesterManaged>true</requesterManaged>
            <status>in-use</status>
            <macAddress>06:c6:2a:ae:e4:23</macAddress>
            <privateIpAddress>10.56.5.210</privateIpAddress>
            <privateDnsName>ip-10-56-5-210.us-west-1.compute.internal</privateDnsName>
            <sourceDestCheck>false</sourceDestCheck>
            <groupSet/>
            <attachment>
                <attachmentId>ela-attach-fcc879c1</attachmentId>
                <instanceOwnerId>amazon-aws</instanceOwnerId>
                <deviceIndex>1</deviceIndex>
                <status>attached</status>
                <deleteOnTermination>false</deleteOnTermination>
            </attachment>
            <association>
                <publicIp>50.18.200.169</publicIp>
                <publicDnsName>ec2-50-18-200-169.us-west-1.compute.amazonaws.com</publicDnsName>
                <ipOwnerId>036476006320</ipOwnerId>
                <allocationId>eipalloc-0f749c8c6fe1d8101</allocationId>
                <associationId>eipassoc-a56ec57f</associationId>
                <natEnabled>true</natEnabled>
            </association>
            <tagSet/>
            <privateIpAddressesSet>
                <item>
                    <privateIpAddress>10.56.5.210</privateIpAddress>
                    <privateDnsName>ip-10-56-5-210.us-west-1.compute.internal</privateDnsName>
                    <primary>true</primary>
                    <association>
                        <publicIp>50.18.200.169</publicIp>
                        <publicDnsName>ec2-50-18-200-169.us-west-1.compute.amazonaws.com</publicDnsName>
                        <ipOwnerId>036476006320</ipOwnerId>
                        <allocationId>eipalloc-0f749c8c6fe1d8101</allocationId>
                        <associationId>eipassoc-a56ec57f</associationId>
                        <natEnabled>true</natEnabled>
                    </association>
                </item>
            </privateIpAddressesSet>
            <ipv6AddressesSet/>
            <interfaceType>nat_gateway</interfaceType>
        </item>

Expected Behavior

The Network Interface Type should resolve to NAT_GATEWAY.

Current Behavior

The Network Interface Type resolves to UNKNOWN_TO_SDK_VERSION

Reproduction Steps

        try(var client = Ec2Client.builder().build()) {
            var req = DescribeNetworkInterfacesRequest.builder().build();

            var resp = client.describeNetworkInterfaces(req);
            for(NetworkInterface nwif : resp.networkInterfaces()) {
                var ifType = nwif.interfaceType();
                var ifTypeName = nwif.interfaceTypeAsString();
                if (ifTypeName != null && ifTypeName.toLowerCase().contains("nat")) {
                    System.out.println(ifTypeName);
                    System.out.println(ifType);
                }
            }
        }

Response is:

nat_gateway
null

Indicating that the string internally stored by the SDK is nat_gateway and the convertion to Enum fails. This is due to the incorrect string defined here:

public enum NetworkInterfaceType {
    INTERFACE("interface"),
    NAT_GATEWAY("natGateway"),  <======= should be nat_gateway
    EFA("efa"),
    TRUNK("trunk"),
    LOAD_BALANCER("load_balancer"),
    NETWORK_LOAD_BALANCER("network_load_balancer"),
    VPC_ENDPOINT("vpc_endpoint"),
    BRANCH("branch"),
    TRANSIT_GATEWAY("transit_gateway"),
    LAMBDA("lambda"),
    QUICKSIGHT("quicksight"),
    GLOBAL_ACCELERATOR_MANAGED("global_accelerator_managed"),
    API_GATEWAY_MANAGED("api_gateway_managed"),
    GATEWAY_LOAD_BALANCER("gateway_load_balancer"),
    GATEWAY_LOAD_BALANCER_ENDPOINT("gateway_load_balancer_endpoint"),
    IOT_RULES_MANAGED("iot_rules_managed"),
    AWS_CODESTAR_CONNECTIONS_MANAGED("aws_codestar_connections_managed"),
    UNKNOWN_TO_SDK_VERSION((String)null);

    private static final Map<String, NetworkInterfaceType> VALUE_MAP = EnumUtils.uniqueIndex(NetworkInterfaceType.class, NetworkInterfaceType::toString);

Possible Solution

Update services/ec2/src/main/resources/codegen-resources/service-2.json:46316 to replace "natGateway"with"nat_gateway"`.

Additional Information/Context

No response

AWS Java SDK version used

2.26.18

JDK version used

openjdk version "17.0.9" 2023-10-17

Operating System and version

Linux 5.10.219-208.866.amzn2.x86_64 #1 SMP Tue Jun 18 14:00:06 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Activity

  1. added
    bugThis issue is a bug.
    needs-triageThis issue or PR still needs to be triaged.
    on Jul 12, 2024
  2. added
    p2This is a standard priority issue
    and removed
    needs-triageThis issue or PR still needs to be triaged.
    on Jul 12, 2024
  3. self-assigned this
    on Jul 12, 2024
  4. nmesika-te commented on Jul 13, 2024

    @nmesika-te
    Author

    Here's the code I used to reproduce the issue (and a similar issue with internet gateways which was apparently reported for the go-sdk as well.

    https://github.com/nmesika-te/aws-sdk-test/blob/main/src/main/java/org/example/Main.java#L24

  5. bhoradc commented on Jul 16, 2024

    @bhoradc
    Contributor

    Hi @nmesika-te,

    Thank you for reporting this issue. I am able to reproduce this scenario, where I get a NULL value for EC2's DescribeNetworkInterfaces interfaceType() call for nat_gateway.

    These enumeration constants are generated from service model shared by EC2 service team. I will submit an internal ticket to the service team for further investigation and fix.

    Also, since this something that has to be fixed at service level, I will transfer this to our Shared SDK repo for further tracking purpose.

    Regards,
    Chaitanya

  6. added
    service-apiThis issue is due to a problem in a service API, not the SDK implementation.
    on Jul 16, 2024
  7. bhoradc commented on Jul 16, 2024

    @bhoradc
    Contributor

    V1454285308

  8. removed
    p2This is a standard priority issue
    on Jul 17, 2024
  9. zshzbh commented on Oct 30, 2024

    @zshzbh

    I just followed up the internal ticket. Will keep it updated once we have updates from service team!

    Thanks!

  10. debora-ito commented on Oct 30, 2024

    @debora-ito
    Member

    Transferring back to the Java SDK v2 repo.

  11. transferred this issue fromaws/aws-sdkon Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.service-apiThis issue is due to a problem in a service API, not the SDK implementation.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions