private void runSearch(T type) { AmazonWebServiceRequest descRequest = buildRequest(type); AsyncHandler describeHandler = buildHandler(type); if (type instanceof Instance) { this.amazonEC2Client.describeInstancesAsync( (DescribeInstancesRequest) descRequest, describeHandler); } else if (type instanceof NatGateway) { this.amazonEC2Client.describeNatGatewaysAsync( (DescribeNatGatewaysRequest) descRequest, describeHandler); } else if (type instanceof Volume) { this.amazonEC2Client.describeVolumesAsync( (DescribeVolumesRequest) descRequest, describeHandler); } else { AWSTaskStatusChecker.this.taskManager.patchTaskToFailure( new IllegalArgumentException("Invalid type " + type)); } }
@Override public void load() { VPC vpc = resources.onlyOne(VPC.class).get(); if (vpc.remoteVPC != null) { List<NatGateway> gateways = AWS.vpc.ec2.describeNatGateways(new DescribeNatGatewaysRequest() .withFilter(new Filter("state").withValues("available"), new Filter("vpc-id").withValues(vpc.remoteVPC.getVpcId()))) .getNatGateways(); if (gateways.size() > 1) throw new Error(Strings.format("multiple nat gateway found, gateways={}", gateways)); if (!gateways.isEmpty()) { NATGateway gateway = resources.onlyOne(NATGateway.class).orElseGet(() -> resources.add(new NATGateway())); gateway.remoteNATGateway = gateways.get(0); gateway.foundInRemote(); } } }
@Override public DescribeNatGatewaysResult describeNatGateways(DescribeNatGatewaysRequest describeNatGatewaysRequest) { throw new UnsupportedOperationException("Not supported in mock"); }
private NatGateway describeNATGateway(String gatewayId) { DescribeNatGatewaysResult result = ec2.describeNatGateways(new DescribeNatGatewaysRequest().withNatGatewayIds(gatewayId)); return result.getNatGateways().get(0); }