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

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

Introduction

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

Prototype


public java.util.List<String> getSubnetIds() 

Source Link

Document

One or more subnet IDs.

Usage

From source file:com.netflix.edda.EddaEc2Client.java

License:Apache License

public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest request) {
    validateEmpty("Filter", request.getFilters());

    TypeReference<List<Subnet>> ref = new TypeReference<List<Subnet>>() {
    };/*from  www  .java 2 s  .  co m*/
    String url = config.url() + "/api/v2/aws/subnets;_expand";
    try {
        List<Subnet> subnets = parse(ref, doGet(url));

        List<String> ids = request.getSubnetIds();
        if (shouldFilter(ids)) {
            List<Subnet> ss = new ArrayList<Subnet>();
            for (Subnet s : subnets) {
                if (matches(ids, s.getSubnetId()))
                    ss.add(s);
            }
            subnets = ss;
        }

        return new DescribeSubnetsResult().withSubnets(subnets);
    } catch (IOException e) {
        throw new AmazonClientException("Faled to parse " + url, e);
    }
}

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

License:Apache License

/**
 * In-memory implementation of describeSubnets. Returns the subnets from the pre-configured subnets.
 * The method can be ordered to throw an AmazonServiceException with a specified error code by specifying a subnet ID with prefix "throw." followed by a
 * string indicating the error code to throw. The exception thrown in this manner will always set the status code to 500.
 *///w w w. j  av  a  2  s .co  m
@Override
public DescribeSubnetsResult describeSubnets(AmazonEC2Client ec2Client,
        DescribeSubnetsRequest describeSubnetsRequest) {
    List<Subnet> subnets = new ArrayList<>();

    List<String> requestedSubnetIds = describeSubnetsRequest.getSubnetIds();

    // add all subnets if request is empty (this is AWS behavior)
    if (requestedSubnetIds.isEmpty()) {
        requestedSubnetIds.addAll(mockSubnets.keySet());
    }

    for (String requestedSubnetId : requestedSubnetIds) {
        MockSubnet mockSubnet = mockSubnets.get(requestedSubnetId);

        // Throw exception if any of the subnet ID do not exist
        if (mockSubnet == null) {
            AmazonServiceException amazonServiceException;

            if (requestedSubnetId.startsWith("throw.")) {
                String errorCode = requestedSubnetId.substring("throw.".length());

                amazonServiceException = new AmazonServiceException(errorCode);
                amazonServiceException.setErrorCode(errorCode);
                amazonServiceException.setStatusCode(500);
            } else {
                amazonServiceException = new AmazonServiceException(
                        "The subnet ID '" + requestedSubnetId + "' does not exist");
                amazonServiceException.setErrorCode(Ec2DaoImpl.ERROR_CODE_SUBNET_ID_NOT_FOUND);
                amazonServiceException.setStatusCode(400);
            }

            throw amazonServiceException;
        }

        subnets.add(mockSubnet.toAwsObject());
    }

    DescribeSubnetsResult describeSubnetsResult = new DescribeSubnetsResult();
    describeSubnetsResult.setSubnets(subnets);
    return describeSubnetsResult;
}

From source file:web.component.impl.aws.AWSEC2Impl.java

@Override
public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest request) {
    if (request.getSubnetIds() == null || request.getSubnetIds().isEmpty())
        throw new IllegalArgumentException("Subnet IDs not specified.");
    return awsHttpClient.describeSubnets(request);
}