Example usage for com.amazonaws.services.ec2.model RouteTable getRoutes

List of usage examples for com.amazonaws.services.ec2.model RouteTable getRoutes

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model RouteTable getRoutes.

Prototype


public java.util.List<Route> getRoutes() 

Source Link

Document

The routes in the route table.

Usage

From source file:com.infinitechaos.vpcviewer.web.rest.dto.RouteTableDTO.java

License:Open Source License

public RouteTableDTO(final RouteTable routeTable) {
    this.routeTableId = routeTable.getRouteTableId();
    this.vpcId = routeTable.getVpcId();
    this.routes.addAll(routeTable.getRoutes().stream().map(RouteDTO::new).collect(Collectors.toList()));
    this.tags.addAll(routeTable.getTags().stream().map(TagDTO::new).collect(Collectors.toList()));
    this.associations.addAll(routeTable.getAssociations().stream().map(RouteTableAssociationDTO::new)
            .collect(Collectors.toList()));
    this.propagatingVgws.addAll(
            routeTable.getPropagatingVgws().stream().map(PropagatingVgwDTO::new).collect(Collectors.toList()));
}

From source file:com.infinitechaos.vpcviewer.web.rest.dto.SubnetDetailDTO.java

License:Open Source License

public SubnetDetailDTO(final Subnet subnet, final RouteTable routeTable) {
    super(subnet);

    routeTableId = routeTable.getRouteTableId();
    routes.addAll(routeTable.getRoutes().stream().map(RouteDTO::new).collect(Collectors.toList()));
}

From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java

License:Apache License

/**
 *
 * @param routeIds//  w w w .j a  v  a2  s.  co  m
 * @param routeTableId
 * @param ec2Client
 * @return
 */
public List<Route> getRoutes(List<String> routeIds, String routeTableId, AmazonEC2 ec2Client) {
    List<String> routeTableIds = new ArrayList<String>();
    routeTableIds.add(routeTableId);
    List<RouteTable> tables = getRouteTables(routeTableIds, ec2Client); // only returns 1 table
    RouteTable table = tables.get(0);
    table.getRoutes().get(0);
    return table.getRoutes();
}

From source file:org.zalando.stups.fullstop.plugin.SubnetPlugin.java

License:Apache License

@Override
public void processEvent(final CloudTrailEvent event) {
    List<String> subnetIds = newArrayList();
    List<Filter> SubnetIdFilters = newArrayList();
    DescribeInstancesRequest describeInstancesRequest = new DescribeInstancesRequest();
    List<String> instanceIds = getInstanceIds(event);
    AmazonEC2Client amazonEC2Client = cachingClientProvider.getClient(AmazonEC2Client.class,
            event.getEventData().getAccountId(),
            Region.getRegion(Regions.fromName(event.getEventData().getAwsRegion())));

    DescribeInstancesResult describeInstancesResult = null;
    try {//w w w .  j  a  v  a 2s.com
        describeInstancesResult = amazonEC2Client
                .describeInstances(describeInstancesRequest.withInstanceIds(instanceIds));
    } catch (AmazonServiceException e) {
        violationStore.save(new ViolationBuilder(e.getMessage()).withEvent(event).build());
        return;
    }

    List<Reservation> reservations = describeInstancesResult.getReservations();
    for (Reservation reservation : reservations) {
        List<Instance> instances = reservation.getInstances();
        subnetIds.addAll(instances.stream().map(Instance::getSubnetId).collect(Collectors.toList()));

    }

    SubnetIdFilters.add(new Filter().withName("association.subnet-id").withValues(subnetIds)); // filter by subnetId
    DescribeRouteTablesRequest describeRouteTablesRequest = new DescribeRouteTablesRequest()
            .withFilters(SubnetIdFilters);
    DescribeRouteTablesResult describeRouteTablesResult = amazonEC2Client
            .describeRouteTables(describeRouteTablesRequest);
    List<RouteTable> routeTables = describeRouteTablesResult.getRouteTables();
    if (routeTables == null || routeTables.size() == 0) {
        violationStore.save(new ViolationBuilder(
                format("Instances %s have no routing information associated", instanceIds.toString()))
                        .withEvent(event).build());
        return;
    }
    for (RouteTable routeTable : routeTables) {
        List<Route> routes = routeTable.getRoutes();
        routes.stream()
                .filter(route -> route.getState().equals("active") && route.getNetworkInterfaceId() != null
                        && !route.getNetworkInterfaceId().startsWith("eni"))
                .forEach(route -> violationStore.save(

                        new ViolationBuilder(format("ROUTES: instance %s is running in a public subnet %s",
                                route.getInstanceId(), route.getNetworkInterfaceId())).withEvent(event)
                                        .build()));
    }

}