com.amazonaws.services.ec2.model.DescribeRouteTablesResult Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.DescribeRouteTablesResult.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouteTableProviderTest.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
@Override protected void setUpRead() { when(mockEc2.describeRouteTables(any(DescribeRouteTablesRequest.class))).thenAnswer((InvocationOnMock invocation) -> { DescribeRouteTablesRequest request = (DescribeRouteTablesRequest) invocation.getArguments()[0]; assertEquals(getIdValue(), request.getRouteTableIds().get(0)); DescribeRouteTablesResult mockResult = mock(DescribeRouteTablesResult.class); List<RouteTable> values = new ArrayList<>(); values.add(makeRouteTable(getIdValue())); values.add(makeRouteTable(getIdValue())); values.add(makeRouteTable("fake-id")); when(mockResult.getRouteTables()).thenReturn(values); return mockResult; }); }
Example #2
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testWithIgwButNoAssociation() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); RouteTable routeTable = new RouteTable(); Route route = new Route(); route.setGatewayId(GATEWAY_ID); route.setDestinationCidrBlock(OPEN_CIDR_BLOCK); routeTable.setRoutes(List.of(route)); RouteTableAssociation routeTableAssociation = new RouteTableAssociation(); routeTableAssociation.setSubnetId(DIFFERENT_SUBNET_ID); routeTable.setAssociations(List.of(routeTableAssociation)); describeRouteTablesResult.setRouteTables(List.of(routeTable)); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertFalse(hasInternetGateway); }
Example #3
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testWithVirtualPrivateGateway() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); RouteTable routeTable = new RouteTable(); Route route = new Route(); route.setGatewayId(VGW_GATEWAY_ID); route.setDestinationCidrBlock(OPEN_CIDR_BLOCK); routeTable.setRoutes(List.of(route)); RouteTableAssociation routeTableAssociation = new RouteTableAssociation(); routeTableAssociation.setSubnetId(SUBNET_ID); routeTable.setAssociations(List.of(routeTableAssociation)); describeRouteTablesResult.setRouteTables(List.of(routeTable)); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertFalse(hasInternetGateway); }
Example #4
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testWithValidIgw() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); RouteTable routeTable = new RouteTable(); Route route = new Route(); route.setGatewayId(GATEWAY_ID); route.setDestinationCidrBlock(OPEN_CIDR_BLOCK); routeTable.setRoutes(List.of(route)); RouteTableAssociation routeTableAssociation = new RouteTableAssociation(); routeTableAssociation.setSubnetId(SUBNET_ID); routeTable.setAssociations(List.of(routeTableAssociation)); describeRouteTablesResult.setRouteTables(List.of(routeTable)); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertTrue(hasInternetGateway); }
Example #5
Source File: AwsSubnetIgwExplorer.java From cloudbreak with Apache License 2.0 | 6 votes |
private Optional<RouteTable> getRouteTableForSubnet(DescribeRouteTablesResult describeRouteTablesResult, String subnetId) { List<RouteTable> routeTables = describeRouteTablesResult.getRouteTables(); Optional<RouteTable> routeTable = Optional.empty(); for (RouteTable rt : routeTables) { LOGGER.info("Searching the routeTable where routeTable is {} and the subnet is :{}", rt, subnetId); for (RouteTableAssociation association : rt.getAssociations()) { LOGGER.info("Searching the association where association is {} and the subnet is :{}", association, subnetId); if (subnetId.equalsIgnoreCase(association.getSubnetId())) { LOGGER.info("Found the routeTable which is {} and the subnet is :{}", rt, subnetId); routeTable = Optional.ofNullable(rt); break; } } if (routeTable.isPresent()) { break; } } return routeTable; }
Example #6
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
private Set<CloudSubnet> convertAwsSubnetsToCloudSubnets(DescribeRouteTablesResult describeRouteTablesResult, List<Subnet> awsSubnets) { Set<CloudSubnet> subnets = new HashSet<>(); for (Subnet subnet : awsSubnets) { boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, subnet.getSubnetId()); LOGGER.info("The subnet {} has internetGateway value is '{}'", subnet, hasInternetGateway); Optional<String> subnetName = getName(subnet.getTags()); subnets.add( new CloudSubnet( subnet.getSubnetId(), subnetName.orElse(subnet.getSubnetId()), subnet.getAvailabilityZone(), subnet.getCidrBlock(), !hasInternetGateway, subnet.getMapPublicIpOnLaunch(), hasInternetGateway, PUBLIC) ); } return subnets; }
Example #7
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 6 votes |
private Set<CloudNetwork> getCloudNetworks(AmazonEC2Client ec2Client, DescribeRouteTablesResult describeRouteTablesResult, DescribeVpcsResult describeVpcsResult) { Set<CloudNetwork> cloudNetworks = new HashSet<>(); LOGGER.debug("Processing VPCs"); for (Vpc vpc : describeVpcsResult.getVpcs()) { List<Subnet> awsSubnets = getSubnets(ec2Client, vpc); Set<CloudSubnet> subnets = convertAwsSubnetsToCloudSubnets(describeRouteTablesResult, awsSubnets); Map<String, Object> properties = prepareNetworkProperties(vpc); Optional<String> name = getName(vpc.getTags()); if (name.isPresent()) { cloudNetworks.add(new CloudNetwork(name.get(), vpc.getVpcId(), subnets, properties)); } else { cloudNetworks.add(new CloudNetwork(vpc.getVpcId(), vpc.getVpcId(), subnets, properties)); } } return cloudNetworks; }
Example #8
Source File: EC2InventoryUtilTest.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch route tables test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchRouteTablesTest() throws Exception { mockStatic(AmazonEC2ClientBuilder.class); AmazonEC2 ec2Client = PowerMockito.mock(AmazonEC2.class); AmazonEC2ClientBuilder amazonEC2ClientBuilder = PowerMockito.mock(AmazonEC2ClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonEC2ClientBuilder.standard()).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withCredentials(anyObject())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.withRegion(anyString())).thenReturn(amazonEC2ClientBuilder); when(amazonEC2ClientBuilder.build()).thenReturn(ec2Client); DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); List<RouteTable> routeTableList = new ArrayList<>(); routeTableList.add(new RouteTable()); describeRouteTablesResult.setRouteTables(routeTableList); when(ec2Client.describeRouteTables()).thenReturn(describeRouteTablesResult); assertThat(ec2InventoryUtil.fetchRouteTables(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #9
Source File: AwsPlatformResources.java From cloudbreak with Apache License 2.0 | 5 votes |
@Override public CloudNetworks networks(CloudCredential cloudCredential, Region region, Map<String, String> filters) { AmazonEC2Client ec2Client = awsClient.createAccess(new AwsCredentialView(cloudCredential), region.value()); try { LOGGER.debug("Describing route tables in region {}", region.getRegionName()); DescribeRouteTablesResult describeRouteTablesResult = ec2Client.describeRouteTables(); DescribeVpcsRequest describeVpcsRequest = getDescribeVpcsRequestWIthFilters(filters); Set<CloudNetwork> cloudNetworks = new HashSet<>(); DescribeVpcsResult describeVpcsResult = null; boolean first = true; while (first || !isNullOrEmpty(describeVpcsResult.getNextToken())) { LOGGER.debug("Getting VPC list in region {}{}", region.getRegionName(), first ? "" : " (continuation)"); first = false; describeVpcsRequest.setNextToken(describeVpcsResult == null ? null : describeVpcsResult.getNextToken()); describeVpcsResult = ec2Client.describeVpcs(describeVpcsRequest); Set<CloudNetwork> partialNetworks = getCloudNetworks(ec2Client, describeRouteTablesResult, describeVpcsResult); cloudNetworks.addAll(partialNetworks); } Map<String, Set<CloudNetwork>> result = new HashMap<>(); result.put(region.value(), cloudNetworks); return new CloudNetworks(result); } catch (SdkClientException e) { LOGGER.error(String.format("Unable to enumerate networks in region '%s'. Check exception for details.", region.getRegionName()), e); throw e; } }
Example #10
Source File: RouteTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * Calls DescribeRouteTables on the AWS EC2 Client returning all Routes that match the supplied predicate and attempting * to push down certain predicates (namely queries for specific RoutingTables) to EC2. * * @See TableProvider */ @Override public void readWithConstraint(BlockSpiller spiller, ReadRecordsRequest recordsRequest, QueryStatusChecker queryStatusChecker) { boolean done = false; DescribeRouteTablesRequest request = new DescribeRouteTablesRequest(); ValueSet idConstraint = recordsRequest.getConstraints().getSummary().get("route_table_id"); if (idConstraint != null && idConstraint.isSingleValue()) { request.setRouteTableIds(Collections.singletonList(idConstraint.getSingleValue().toString())); } while (!done) { DescribeRouteTablesResult response = ec2.describeRouteTables(request); for (RouteTable nextRouteTable : response.getRouteTables()) { for (Route route : nextRouteTable.getRoutes()) { instanceToRow(nextRouteTable, route, spiller); } } request.setNextToken(response.getNextToken()); if (response.getNextToken() == null || !queryStatusChecker.isQueryRunning()) { done = true; } } }
Example #11
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void testWithAssociationButNoIgw() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); RouteTable routeTable = new RouteTable(); Route route = new Route(); routeTable.setRoutes(List.of(route)); RouteTableAssociation routeTableAssociation = new RouteTableAssociation(); routeTableAssociation.setSubnetId(SUBNET_ID); routeTable.setAssociations(List.of(routeTableAssociation)); describeRouteTablesResult.setRouteTables(List.of(routeTable)); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertFalse(hasInternetGateway); }
Example #12
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void testWithNoAssociationAndNoIgw() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); RouteTable routeTable = new RouteTable(); Route route = new Route(); routeTable.setRoutes(List.of(route)); RouteTableAssociation routeTableAssociation = new RouteTableAssociation(); routeTableAssociation.setSubnetId(DIFFERENT_SUBNET_ID); routeTable.setAssociations(List.of(routeTableAssociation)); describeRouteTablesResult.setRouteTables(List.of(routeTable)); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertFalse(hasInternetGateway); }
Example #13
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 5 votes |
@Test public void testWithRouteButNoAssociations() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); RouteTable routeTable = new RouteTable(); Route route = new Route(); routeTable.setRoutes(List.of(route)); describeRouteTablesResult.setRouteTables(List.of(routeTable)); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertFalse(hasInternetGateway); }
Example #14
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Describe route table. * * @return RouteTable */ protected final RouteTable getRouteTable() { RouteTable routeTable = null; DescribeRouteTablesRequest req = new DescribeRouteTablesRequest(); DescribeRouteTablesResult result = amazonEC2Client.describeRouteTables(req); if (result != null && !result.getRouteTables().isEmpty()) { routeTable = result.getRouteTables().get(0); } return routeTable; }
Example #15
Source File: AwsSubnetIgwExplorer.java From cloudbreak with Apache License 2.0 | 4 votes |
public boolean hasInternetGatewayOfSubnet(DescribeRouteTablesResult describeRouteTablesResult, String subnetId) { Optional<RouteTable> routeTable = getRouteTableForSubnet(describeRouteTablesResult, subnetId); return hasInternetGateway(routeTable, subnetId); }
Example #16
Source File: AwsSubnetIgwExplorerTest.java From cloudbreak with Apache License 2.0 | 4 votes |
@Test public void testWithNoRouteTable() { DescribeRouteTablesResult describeRouteTablesResult = new DescribeRouteTablesResult(); boolean hasInternetGateway = awsSubnetIgwExplorer.hasInternetGatewayOfSubnet(describeRouteTablesResult, SUBNET_ID); assertFalse(hasInternetGateway); }
Example #17
Source File: RouteTableImpl.java From aws-sdk-java-resources with Apache License 2.0 | 4 votes |
@Override public boolean load(DescribeRouteTablesRequest request, ResultCapture<DescribeRouteTablesResult> extractor) { return resource.load(request, extractor); }
Example #18
Source File: RouteTable.java From aws-sdk-java-resources with Apache License 2.0 | 2 votes |
/** * Makes a call to the service to load this resource's attributes if they * are not loaded yet, and use a ResultCapture to retrieve the low-level * client response * The following request parameters will be populated from the data of this * <code>RouteTable</code> resource, and any conflicting parameter value set * in the request will be overridden: * <ul> * <li> * <b><code>RouteTableIds.0</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @return Returns {@code true} if the resource is not yet loaded when this * method was invoked, which indicates that a service call has been * made to retrieve the attributes. * @see DescribeRouteTablesRequest */ boolean load(DescribeRouteTablesRequest request, ResultCapture<DescribeRouteTablesResult> extractor);