com.amazonaws.services.ec2.model.RouteTable Java Examples
The following examples show how to use
com.amazonaws.services.ec2.model.RouteTable.
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: FileManager.java From pacbot with Apache License 2.0 | 6 votes |
/** * Generate EC 2 route table files. * * @param routeTableMap the route table map * @throws IOException Signals that an I/O exception has occurred. */ public static void generateEC2RouteTableFiles(Map<String, List<RouteTable>> routeTableMap) throws IOException { String fieldNames; String keys; fieldNames = "routeTableId`vpcId"; keys = "discoverydate`accountid`accountname`region`routetableid`vpcid"; FileGenerator.generateJson(routeTableMap, fieldNames, "aws-routetable.data",keys); fieldNames = "routeTableId`routes.destinationCidrBlock`routes.destinationPrefixListId`routes.gatewayId`routes.instanceId`routes.instanceOwnerId`routes.networkInterfaceId`routes.vpcPeeringConnectionId`routes.natGatewayId" +"`routes.state`routes.origin`routes.destinationIpv6CidrBlock`routes.egressOnlyInternetGatewayId"; keys = "discoverydate`accountid`accountname`region`routetableid`destinationcidrblock`destinationprefixlistid`gatewayid`instanceid`instanceownerid`networkinterfaceid`vpcpeeringconnectionid`natgatewayid" +"`state`origin`destinationipv6cidrblock`egressonlyinternetgatewayid"; FileGenerator.generateJson(routeTableMap, fieldNames, "aws-routetable-routes.data",keys); fieldNames = "routeTableId`associations.routeTableAssociationId`associations.subnetId`associations.main"; keys = "discoverydate`accountid`accountname`region`routetableid`routetableassociationid`subnetid`main"; FileGenerator.generateJson(routeTableMap, fieldNames, "aws-routetable-associations.data",keys); fieldNames = "routeTableId`propagatingVgws.gatewayId"; keys = "discoverydate`accountid`accountname`region`routetableid`gatewayid"; FileGenerator.generateJson(routeTableMap, fieldNames, "aws-routetable-propagatingvgws.data",keys); fieldNames = "routeTableId`tags.key`tags.value"; keys = "discoverydate`accountid`accountname`region`routetableid`key`value"; FileGenerator.generateJson(routeTableMap, fieldNames, "aws-routetable-tags.data",keys); }
Example #3
Source File: EC2InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Fetch route tables. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<RouteTable>> fetchRouteTables(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){ Map<String,List<RouteTable>> routeTableMap = new LinkedHashMap<>(); AmazonEC2 ec2Client ; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + InventoryConstants.ERROR_PREFIX_EC2 ; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ ec2Client = AmazonEC2ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); List<RouteTable> routeTableList = ec2Client.describeRouteTables().getRouteTables(); if(!routeTableList.isEmpty() ) { log.debug(InventoryConstants.ACCOUNT + accountId + " Type : EC2 Route table "+ region.getName()+" >> " + routeTableList.size()); routeTableMap.put(accountId+delimiter+accountName+delimiter+region.getName(), routeTableList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,region.getName(),"routetable",e.getMessage()); } } return routeTableMap; }
Example #4
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 #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: 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 #7
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 #8
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 #9
Source File: BaseTest.java From aws-mock with MIT License | 5 votes |
/** * Create route table. * * @param vpcId the vpc id * @return RouteTable */ protected final RouteTable createRouteTable(final String vpcId) { RouteTable routeTable = null; CreateRouteTableRequest req = new CreateRouteTableRequest(); req.setVpcId(vpcId); CreateRouteTableResult result = amazonEC2Client.createRouteTable(req); if (result != null) { routeTable = result.getRouteTable(); } return routeTable; }
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: 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 #12
Source File: Ec2NetworkTest.java From aws-mock with MIT License | 5 votes |
/** * Test create Volumes. */ @Test(timeout = TIMEOUT_LEVEL1) public final void createNetworkResourcesTest() { //Create VPCs for(int i =0 ; i < 2 ; i++) { createVpcTest(); } List<Vpc> vpcs = describeVpcs(); // Create Subnet for(Vpc vpc : vpcs) { for(int j=0; j<2; j++) { Subnet subnet = createSubnet(MOCK_CIDR_BLOCK, vpc.getVpcId()); RouteTable routeTable = createRouteTable(vpc.getVpcId()); InternetGateway internetGateway = createInternetGateway(); createRoute(routeTable.getRouteTableId(), internetGateway.getInternetGatewayId(), MOCK_CIDR_BLOCK); attachInternetGateway(internetGateway.getInternetGatewayId(), vpc.getVpcId()); } } }
Example #13
Source File: Ec2NetworkTest.java From aws-mock with MIT License | 5 votes |
/** * Test Delete route table. */ @Test(timeout = TIMEOUT_LEVEL1) public final void deleteRouteTableTest() { log.info("Start delete route table test"); Vpc vpc = createVpc(MOCK_CIDR_BLOCK, PROPERTY_TENANCY); RouteTable routeTable = createRouteTable(vpc.getVpcId()); Assert.assertNotNull("route table should not be null", routeTable); Assert.assertNotNull("route table id should not be null", routeTable.getRouteTableId()); Assert.assertTrue("route table should be deleted", deleteRouteTable(routeTable.getRouteTableId())); }
Example #14
Source File: Ec2NetworkTest.java From aws-mock with MIT License | 5 votes |
/** * Test create route table. */ @Test(timeout = TIMEOUT_LEVEL1) public final void createRouteTableTest() { log.info("Start create route table test"); Vpc vpc = createVpc(MOCK_CIDR_BLOCK, PROPERTY_TENANCY); RouteTable routeTable = createRouteTable(vpc.getVpcId()); Assert.assertNotNull("route table should not be null", routeTable); Assert.assertNotNull("route table id should not be null", routeTable.getRouteTableId()); }
Example #15
Source File: Ec2NetworkTest.java From aws-mock with MIT License | 5 votes |
/** * Test describing route table. */ @Test(timeout = TIMEOUT_LEVEL1) public final void describeRouteTableTest() { log.info("Start describing route table test"); createRouteTableTest(); RouteTable routeTable = getRouteTable(); Assert.assertNotNull("route table should not be null", routeTable); Assert.assertNotNull("route table id should not be null", routeTable.getRouteTableId()); Assert.assertTrue("route table should be deleted", deleteRouteTable(routeTable.getRouteTableId())); }
Example #16
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 #17
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 #18
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 #19
Source File: AwsSubnetIgwExplorer.java From cloudbreak with Apache License 2.0 | 5 votes |
private boolean hasInternetGateway(Optional<RouteTable> rt, String subnetId) { if (rt.isPresent()) { for (Route route : rt.get().getRoutes()) { LOGGER.info("Searching the route which is open. the route is {} and the subnet is :{}", route, subnetId); if (StringUtils.isNotEmpty(route.getGatewayId()) && route.getGatewayId().startsWith(IGW_PREFIX) && OPEN_CIDR_BLOCK.equals(route.getDestinationCidrBlock())) { LOGGER.info("Found the route which is {} and the subnet is :{}", route, subnetId); return true; } } } return false; }
Example #20
Source File: RouteTableProviderTest.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
private RouteTable makeRouteTable(String id) { RouteTable routeTable = new RouteTable(); routeTable.withRouteTableId(id) .withOwnerId("owner") .withVpcId("vpc") .withAssociations(new RouteTableAssociation().withSubnetId("subnet").withRouteTableId("route_table_id")) .withTags(new Tag("key", "value")) .withPropagatingVgws(new PropagatingVgw().withGatewayId("gateway_id")) .withRoutes(new Route() .withDestinationCidrBlock("dst_cidr") .withDestinationIpv6CidrBlock("dst_cidr_v6") .withDestinationPrefixListId("dst_prefix_list") .withEgressOnlyInternetGatewayId("egress_igw") .withGatewayId("gateway") .withInstanceId("instance_id") .withInstanceOwnerId("instance_owner") .withNatGatewayId("nat_gateway") .withNetworkInterfaceId("interface") .withOrigin("origin") .withState("state") .withTransitGatewayId("transit_gateway") .withVpcPeeringConnectionId("vpc_peering_con") ); return routeTable; }
Example #21
Source File: RouteTableProvider.java From aws-athena-query-federation with Apache License 2.0 | 5 votes |
/** * Maps an EC2 Route into a row in our Apache Arrow response block(s). * * @param routeTable The RouteTable that owns the given Route. * @param route The Route to map. * @param spiller The BlockSpiller to use when we want to write a matching row to the response. * @note The current implementation is rather naive in how it maps fields. It leverages a static * list of fields that we'd like to provide and then explicitly filters and converts each field. */ private void instanceToRow(RouteTable routeTable, Route route, BlockSpiller spiller) { spiller.writeRows((Block block, int row) -> { boolean matched = true; matched &= block.offerValue("route_table_id", row, routeTable.getRouteTableId()); matched &= block.offerValue("owner", row, routeTable.getOwnerId()); matched &= block.offerValue("vpc", row, routeTable.getVpcId()); matched &= block.offerValue("dst_cidr", row, route.getDestinationCidrBlock()); matched &= block.offerValue("dst_cidr_v6", row, route.getDestinationIpv6CidrBlock()); matched &= block.offerValue("dst_prefix_list", row, route.getDestinationPrefixListId()); matched &= block.offerValue("egress_igw", row, route.getEgressOnlyInternetGatewayId()); matched &= block.offerValue("gateway", row, route.getGatewayId()); matched &= block.offerValue("instance_id", row, route.getInstanceId()); matched &= block.offerValue("instance_owner", row, route.getInstanceOwnerId()); matched &= block.offerValue("nat_gateway", row, route.getNatGatewayId()); matched &= block.offerValue("interface", row, route.getNetworkInterfaceId()); matched &= block.offerValue("origin", row, route.getOrigin()); matched &= block.offerValue("state", row, route.getState()); matched &= block.offerValue("transit_gateway", row, route.getTransitGatewayId()); matched &= block.offerValue("vpc_peering_con", row, route.getVpcPeeringConnectionId()); List<String> associations = routeTable.getAssociations().stream() .map(next -> next.getSubnetId() + ":" + next.getRouteTableId()).collect(Collectors.toList()); matched &= block.offerComplexValue("associations", row, FieldResolver.DEFAULT, associations); List<String> tags = routeTable.getTags().stream() .map(next -> next.getKey() + ":" + next.getValue()).collect(Collectors.toList()); matched &= block.offerComplexValue("tags", row, FieldResolver.DEFAULT, tags); List<String> propagatingVgws = routeTable.getPropagatingVgws().stream() .map(next -> next.getGatewayId()).collect(Collectors.toList()); matched &= block.offerComplexValue("propagating_vgws", row, FieldResolver.DEFAULT, propagatingVgws); return matched ? 1 : 0; }); }
Example #22
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); }