You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2024/10/30 23:07:01 UTC
(jclouds) 01/02: 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
This is an automated email from the ASF dual-hosted git repository.
gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git
commit 6851ac9459827e70575355481af383d086faa54e
Author: Gary Teichrow <ga...@qpointsystems.com>
AuthorDate: Mon Oct 7 12:13:26 2024 -0700
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
---
.../jclouds/aws/ec2/features/RouteTableApi.java | 23 ++++++++++++++++++++++
.../aws/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<RouteTable> 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 <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_DescribeRouteTables.html">...</a>
+ */
+ @Named("DescribeRouteTables")
+ @POST
+ @FormParams(keys = ACTION, values = "DescribeRouteTables")
+ @XMLResponseParser(DescribeRouteTablesResponseHandler.class)
+ @Fallback(Fallbacks.EmptyFluentIterableOnNotFoundOr404.class)
+ FluentIterable<RouteTable> describeRouteTablesWithFilter(
+ @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
+ @BinderParam(BindFiltersToIndexedFormParams.class) Multimap<String, String> 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<AWSEC2Api> {
}
});
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<RouteTable> routeTablesByFilter = routeTableApi.describeRouteTablesWithFilter(TEST_REGION,
+ ImmutableMultimap.<String, String>builder()
+ .put("vpc-id", vpc.id())
+ .build()
+ );
+ assertNotNull(routeTablesByFilter, "Failed to return list of routeTablesByFilter");
+ Optional<RouteTable> vpcRTByFilter = Iterables.tryFind(routeTablesByFilter, new Predicate<RouteTable>() {
+ @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());