Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit 6851ac9

Browse files
qpointsystemsgaul
authored andcommitted
Added a new describe* method called describeRouteTablesWithFilter so that RouteTables can be described by Vpc-Id, for instance
Added a unit test which searches for a RouteTable by a VPC-id
1 parent e3f8de0 commit 6851ac9

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/features/RouteTableApi.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.jclouds.aws.ec2.xml.DescribeRouteTablesResponseHandler;
3434
import org.jclouds.aws.ec2.xml.ReturnValueHandler;
3535
import org.jclouds.aws.filters.FormSigner;
36+
import org.jclouds.ec2.binders.BindFiltersToIndexedFormParams;
3637
import org.jclouds.javax.annotation.Nullable;
3738
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
3839
import org.jclouds.rest.annotations.BinderParam;
@@ -44,6 +45,7 @@
4445
import org.jclouds.rest.annotations.XMLResponseParser;
4546

4647
import com.google.common.collect.FluentIterable;
48+
import com.google.common.collect.Multimap;
4749

4850
/**
4951
* Provides access to AWS Route Table services.
@@ -267,6 +269,10 @@ boolean deleteRoute(
267269
/**
268270
* Describes route tables.
269271
* @param region The region to search for route tables.
272+
* @param routeTableIds One or more identifiers for existing RouteTable instances
273+
*
274+
* @return a set of RouteTable objects that matched the routeTableIds passed
275+
*
270276
*/
271277
@Named("DescribeRouteTables")
272278
@POST
@@ -276,4 +282,21 @@ boolean deleteRoute(
276282
FluentIterable<RouteTable> describeRouteTables(
277283
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
278284
@BinderParam(BindRouteTableIdsToIndexedFormParams.class) String... routeTableIds);
285+
286+
/**
287+
* Describes route tables.
288+
* @param region The region to search for route tables.
289+
* @param filter One or more filters utilized to search for RouteTable instances
290+
*
291+
* @link <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRouteTables.html">...</a>
292+
*/
293+
@Named("DescribeRouteTables")
294+
@POST
295+
@FormParams(keys = ACTION, values = "DescribeRouteTables")
296+
@XMLResponseParser(DescribeRouteTablesResponseHandler.class)
297+
@Fallback(Fallbacks.EmptyFluentIterableOnNotFoundOr404.class)
298+
FluentIterable<RouteTable> describeRouteTablesWithFilter(
299+
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
300+
@BinderParam(BindFiltersToIndexedFormParams.class) Multimap<String, String> filter);
301+
279302
}

providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/features/RouteTableApiLiveTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.google.common.collect.ImmutableList;
4949
import com.google.common.collect.ImmutableMap;
5050
import com.google.common.collect.Iterables;
51+
import com.google.common.collect.ImmutableMultimap;
5152

5253
/**
5354
* Tests behavior of {@link RouteTableApi}
@@ -106,6 +107,22 @@ public void testDescribe() {
106107
}
107108
});
108109
assertTrue(vpcRT.isPresent(), "Could not find VPC " + vpc.id() + " in described route tables");
110+
111+
//Now test the Find by Filter version of the describeRouteTables
112+
final FluentIterable<RouteTable> routeTablesByFilter = routeTableApi.describeRouteTablesWithFilter(TEST_REGION,
113+
ImmutableMultimap.<String, String>builder()
114+
.put("vpc-id", vpc.id())
115+
.build()
116+
);
117+
assertNotNull(routeTablesByFilter, "Failed to return list of routeTablesByFilter");
118+
Optional<RouteTable> vpcRTByFilter = Iterables.tryFind(routeTablesByFilter, new Predicate<RouteTable>() {
119+
@Override public boolean apply(RouteTable input) {
120+
return vpc.id().equals(input.vpcId());
121+
}
122+
});
123+
assertTrue(vpcRTByFilter.isPresent(), "Could not find VPC " + vpc.id() + " in described route tables");
124+
125+
109126
RouteTable rt = vpcRT.get();
110127
assertEquals(rt.associationSet().size(), 1,
111128
"Route for test VPC has wrong number of associations, should be 1: " + rt.associationSet());

0 commit comments

Comments
 (0)