List of usage examples for com.amazonaws.services.ec2.model DescribeSubnetsResult DescribeSubnetsResult
DescribeSubnetsResult
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 w ww . j a va 2s.c o 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:com.netflix.spinnaker.clouddriver.aws.security.AmazonClientInvocationHandler.java
License:Apache License
public DescribeSubnetsResult describeSubnets(DescribeSubnetsRequest request) { return new DescribeSubnetsResult().withSubnets(describe(request, "subnetIds", "subnets", Subnet.class)); }
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. *///from www. ja v a2 s. c o 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; }