List of usage examples for com.amazonaws.services.ec2.model DescribeSubnetsResult setSubnets
public void setSubnets(java.util.Collection<Subnet> subnets)
Information about one or more subnets.
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. *//* ww w . ja v a2s . 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; }