From 77e7c001841c06eff9fb75726119fa77b4d6a1b0 Mon Sep 17 00:00:00 2001 From: Gary Teichrow Date: Sun, 24 Mar 2024 14:48:28 -0700 Subject: [PATCH] Added a describeRouteTablesWithFilter so that Route Tables have capability similar to other EC2 objects that have a "describeXXXWithFilter" method along with their base "describeXXX" method. Also modified the appropriate unit test with a test for this method --- .../aws/ec2/features/RouteTableApi.java | 23 +++++++++++++++++++ .../ec2/features/RouteTableApiLiveTest.java | 17 ++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/features/RouteTableApi.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/features/RouteTableApi.java index 9a37850a2b..bfadd37fe7 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/features/RouteTableApi.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/features/RouteTableApi.java @@ -33,6 +33,7 @@ import org.jclouds.aws.ec2.xml.CreateRouteTableResponseHandler; import org.jclouds.aws.ec2.xml.DescribeRouteTablesResponseHandler; import org.jclouds.aws.ec2.xml.ReturnValueHandler; import org.jclouds.aws.filters.FormSigner; +import org.jclouds.ec2.binders.BindFiltersToIndexedFormParams; import org.jclouds.javax.annotation.Nullable; import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull; import org.jclouds.rest.annotations.BinderParam; @@ -44,6 +45,7 @@ import org.jclouds.rest.annotations.VirtualHost; import org.jclouds.rest.annotations.XMLResponseParser; import com.google.common.collect.FluentIterable; +import com.google.common.collect.Multimap; /** * Provides access to AWS Route Table services. @@ -267,6 +269,10 @@ public interface RouteTableApi { /** * Describes route tables. * @param region The region to search for route tables. + * @param routeTableIds One or more identifiers for existing RouteTable instances + * + * @return a set of RouteTable objects that matched the routeTableIds passed + * */ @Named("DescribeRouteTables") @POST @@ -276,4 +282,21 @@ public interface RouteTableApi { FluentIterable describeRouteTables( @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, @BinderParam(BindRouteTableIdsToIndexedFormParams.class) String... routeTableIds); + + /** + * Describes route tables. + * @param region The region to search for route tables. + * @param filter One or more filters utilized to search for RouteTable instances + * + * @link ... + */ + @Named("DescribeRouteTables") + @POST + @FormParams(keys = ACTION, values = "DescribeRouteTables") + @XMLResponseParser(DescribeRouteTablesResponseHandler.class) + @Fallback(Fallbacks.EmptyFluentIterableOnNotFoundOr404.class) + FluentIterable describeRouteTablesWithFilter( + @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, + @BinderParam(BindFiltersToIndexedFormParams.class) Multimap filter); + } diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiLiveTest.java index 3c579840fd..b05060d51f 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiLiveTest.java @@ -48,6 +48,7 @@ import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.common.collect.ImmutableMultimap; /** * Tests behavior of {@link RouteTableApi} @@ -106,6 +107,22 @@ public class RouteTableApiLiveTest extends BaseApiLiveTest { } }); assertTrue(vpcRT.isPresent(), "Could not find VPC " + vpc.id() + " in described route tables"); + + //Now test the Find by Filter version of the describeRouteTables + final FluentIterable routeTablesByFilter = routeTableApi.describeRouteTablesWithFilter(TEST_REGION, + ImmutableMultimap.builder() + .put("vpc-id", vpc.id()) + .build() + ); + assertNotNull(routeTablesByFilter, "Failed to return list of routeTablesByFilter"); + Optional vpcRTByFilter = Iterables.tryFind(routeTablesByFilter, new Predicate() { + @Override public boolean apply(RouteTable input) { + return vpc.id().equals(input.vpcId()); + } + }); + assertTrue(vpcRTByFilter.isPresent(), "Could not find VPC " + vpc.id() + " in described route tables"); + + RouteTable rt = vpcRT.get(); assertEquals(rt.associationSet().size(), 1, "Route for test VPC has wrong number of associations, should be 1: " + rt.associationSet());