public void deleteAwsSubnet() { if (this.isMock) { return; } DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest() .withFilters( new Filter(AWS_VPC_ID_FILTER, singletonList(AWS_DEFAULT_VPC_ID))) .withFilters( new Filter(AWS_SUBNET_CIDR_FILTER, singletonList(AWS_NON_EXISTING_SUBNET_CIDR))); DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest); subnetResult.getSubnets().forEach(subnet -> { DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId()); this.client.deleteSubnet(deleteRequest); }); }
public void deleteAwsPublicSubnet() { if (this.isMock) { return; } DescribeSubnetsRequest subnetRequest = new DescribeSubnetsRequest() .withFilters( new Filter(AWS_VPC_ID_FILTER, singletonList(AWS_DEFAULT_VPC_ID))) .withFilters( new Filter(AWS_SUBNET_CIDR_FILTER, singletonList(AWS_NON_EXISTING_PUBLIC_SUBNET_CIDR))); DescribeSubnetsResult subnetResult = this.client.describeSubnets(subnetRequest); subnetResult.getSubnets().forEach(subnet -> { DeleteSubnetRequest deleteRequest = new DeleteSubnetRequest(subnet.getSubnetId()); this.client.deleteSubnet(deleteRequest); }); }
@Override public void execute(Context context) throws Exception { String key = "subnet/" + resource.id; for (com.amazonaws.services.ec2.model.Subnet remoteSubnet : resource.remoteSubnets) { new Runner<Void>() .maxAttempts(5) .retryInterval(Duration.ofSeconds(60)) .retryOn(e -> e instanceof AmazonServiceException) .run(() -> { logger.info("delete subnet, subnetId={}, cidr={}", remoteSubnet.getSubnetId(), remoteSubnet.getCidrBlock()); AWS.vpc.ec2.deleteSubnet(new DeleteSubnetRequest().withSubnetId(remoteSubnet.getSubnetId())); context.output(key, String.format("deletedSubnetId=%s, cidr=%s", remoteSubnet.getSubnetId(), remoteSubnet.getCidrBlock())); return null; }); } }
public DeferredResult<Void> deleteSubnetAsync(String subnetId) { DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(subnetId); String message = "Delete AWS Subnet with id [" + subnetId + "]."; AWSDeferredResultAsyncHandler<DeleteSubnetRequest, DeleteSubnetResult> handler = new AWSDeferredResultAsyncHandler<DeleteSubnetRequest, DeleteSubnetResult>(this.service, message) { @Override protected Exception consumeError(Exception exception) { if (exception instanceof AmazonEC2Exception) { AmazonEC2Exception amazonExc = (AmazonEC2Exception) exception; if (STATUS_CODE_SUBNET_NOT_FOUND.equals(amazonExc.getErrorCode())) { // AWS subnet doesn't exist. this.service.logWarning(() -> String.format("Unable to delete AWS " + "subnet with id [%s], as it does not exist.", subnetId)); return RECOVERED; } } return exception; } }; this.client.deleteSubnetAsync(req, handler); return handler.toDeferredResult() .thenApply(result -> (Void) null); }
/** * Delete Subnet. * * @param subnetId the subnet id * @return true if deleted, otherwise false. */ protected final boolean deleteSubnet(final String subnetId) { DeleteSubnetRequest req = new DeleteSubnetRequest(); req.setSubnetId(subnetId); DeleteSubnetResult result = amazonEC2Client.deleteSubnet(req); if (result != null) { return true; } return false; }
@Override public void deleteSubnet(DeleteSubnetRequest deleteSubnetRequest) throws AmazonServiceException, AmazonClientException { throw new UnsupportedOperationException("Not supported in mock"); }
/** * Delete a Subnet */ public static void deleteSubnet(AmazonEC2AsyncClient client, String subnetId) { if (subnetId != null) { client.deleteSubnet(new DeleteSubnetRequest().withSubnetId(subnetId)); } }
@Override public void delete(DeleteSubnetRequest request) { delete(request, null); }
@Override public void delete(DeleteSubnetRequest request, ResultCapture<Void> extractor) { resource.performAction("Delete", request, extractor); }
@Override public void delete(ResultCapture<Void> extractor) { DeleteSubnetRequest request = new DeleteSubnetRequest(); delete(request, extractor); }
/** * Delete the specified subnet * * @throws AmazonEC2Exception if the subnet doesn't exist. */ public void deleteSubnet(String subnetId) throws AmazonEC2Exception { DeleteSubnetRequest req = new DeleteSubnetRequest().withSubnetId(subnetId); this.client.deleteSubnet(req); }
/** * Performs the <code>Delete</code> action. * * <p> * The following request parameters will be populated from the data of this * <code>Subnet</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>SubnetId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see DeleteSubnetRequest */ void delete(DeleteSubnetRequest request);
/** * Performs the <code>Delete</code> action and use a ResultCapture to * retrieve the low-level client response. * * <p> * The following request parameters will be populated from the data of this * <code>Subnet</code> resource, and any conflicting parameter value set in * the request will be overridden: * <ul> * <li> * <b><code>SubnetId</code></b> * - mapped from the <code>Id</code> identifier. * </li> * </ul> * * <p> * * @see DeleteSubnetRequest */ void delete(DeleteSubnetRequest request, ResultCapture<Void> extractor);