Example usage for com.amazonaws.services.ec2.model DescribeSubnetsRequest setSubnetIds

List of usage examples for com.amazonaws.services.ec2.model DescribeSubnetsRequest setSubnetIds

Introduction

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

Prototype


public void setSubnetIds(java.util.Collection<String> subnetIds) 

Source Link

Document

One or more subnet IDs.

Usage

From source file:com.pinterest.clusterservice.aws.AwsManagerImpl.java

License:Apache License

@Override
public int getAvailableCapacityInSubnet(String subnetId) throws Exception {
    DescribeSubnetsRequest subnetsRequest = new DescribeSubnetsRequest();
    subnetsRequest.setSubnetIds(Arrays.asList(subnetId));
    DescribeSubnetsResult subnetsResult = ec2Client.describeSubnets(subnetsRequest);
    List<Subnet> subnets = subnetsResult.getSubnets();
    if (subnets.isEmpty()) {
        return 0;
    }//from  w  w w .java  2s  .  c om

    Subnet subnet = subnets.get(0);
    return subnet.getAvailableIpAddressCount();
}

From source file:org.finra.dm.dao.impl.Ec2DaoImpl.java

License:Apache License

/**
 * This implementation uses the DescribeSubnets API.
 *//*  w  w  w .  j a  v  a  2s. com*/
@Override
public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
    describeSubnetsRequest.setSubnetIds(subnetIds);
    try {
        DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client,
                describeSubnetsRequest);
        return describeSubnetsResult.getSubnets();
    } catch (AmazonServiceException amazonServiceException) {
        /*
         * AWS throws a 400 error when any one of the specified subnet ID is not found.
         * We want to catch it and throw as an handled DM error as a 404 not found.
         */
        if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) {
            throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException);
        }
        // Any other type of error we throw as is because they are unexpected.
        else {
            throw amazonServiceException;
        }
    }
}

From source file:org.finra.herd.dao.impl.Ec2DaoImpl.java

License:Apache License

/**
 * This implementation uses the DescribeSubnets API.
 *//* w ww. j a  v  a2 s.  co  m*/
@Override
public List<Subnet> getSubnets(Collection<String> subnetIds, AwsParamsDto awsParamsDto) {
    AmazonEC2Client ec2Client = getEc2Client(awsParamsDto);
    DescribeSubnetsRequest describeSubnetsRequest = new DescribeSubnetsRequest();
    describeSubnetsRequest.setSubnetIds(subnetIds);
    try {
        DescribeSubnetsResult describeSubnetsResult = ec2Operations.describeSubnets(ec2Client,
                describeSubnetsRequest);
        return describeSubnetsResult.getSubnets();
    } catch (AmazonServiceException amazonServiceException) {
        /*
         * AWS throws a 400 error when any one of the specified subnet ID is not found.
         * We want to catch it and throw as an handled herd error as a 404 not found.
         */
        if (ERROR_CODE_SUBNET_ID_NOT_FOUND.equals(amazonServiceException.getErrorCode())) {
            throw new ObjectNotFoundException(amazonServiceException.getErrorMessage(), amazonServiceException);
        }
        // Any other type of error we throw as is because they are unexpected.
        else {
            throw amazonServiceException;
        }
    }
}