@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZoneId() == null) ? 0 : getAvailabilityZoneId().hashCode()); hashCode = prime * hashCode + ((getAvailableIpAddressCount() == null) ? 0 : getAvailableIpAddressCount().hashCode()); hashCode = prime * hashCode + ((getCidrBlock() == null) ? 0 : getCidrBlock().hashCode()); hashCode = prime * hashCode + ((getDefaultForAz() == null) ? 0 : getDefaultForAz().hashCode()); hashCode = prime * hashCode + ((getMapPublicIpOnLaunch() == null) ? 0 : getMapPublicIpOnLaunch().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getSubnetId() == null) ? 0 : getSubnetId().hashCode()); hashCode = prime * hashCode + ((getVpcId() == null) ? 0 : getVpcId().hashCode()); hashCode = prime * hashCode + ((getOwnerId() == null) ? 0 : getOwnerId().hashCode()); hashCode = prime * hashCode + ((getAssignIpv6AddressOnCreation() == null) ? 0 : getAssignIpv6AddressOnCreation().hashCode()); hashCode = prime * hashCode + ((getIpv6CidrBlockAssociationSet() == null) ? 0 : getIpv6CidrBlockAssociationSet().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); hashCode = prime * hashCode + ((getSubnetArn() == null) ? 0 : getSubnetArn().hashCode()); return hashCode; }
/** * <p> * The Availability Zone of the subnet. * </p> * * @param availabilityZone * The Availability Zone of the subnet. * @return Returns a reference to this object so that method calls can be chained together. */ public Subnet withAvailabilityZone(String availabilityZone) { setAvailabilityZone(availabilityZone); return this; }
/** * <p> * The ID of the subnet. * </p> * * @param subnetId * The ID of the subnet. * @return Returns a reference to this object so that method calls can be chained together. */ public Subnet withSubnetId(String subnetId) { setSubnetId(subnetId); return this; }
public Subnet unmarshall(StaxUnmarshallerContext context) throws Exception { Subnet subnet = new Subnet(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; subnet.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setAvailabilityZoneId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setAvailableIpAddressCount(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setCidrBlock(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setDefaultForAz(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setMapPublicIpOnLaunch(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setSubnetId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setVpcId(StringStaxUnmarshaller.getInstance().unmarshall(context));
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getSubnetId() == null) ? 0 : getSubnetId().hashCode()); hashCode = prime * hashCode + ((getState() == null) ? 0 : getState().hashCode()); hashCode = prime * hashCode + ((getVpcId() == null) ? 0 : getVpcId().hashCode()); hashCode = prime * hashCode + ((getCidrBlock() == null) ? 0 : getCidrBlock().hashCode()); hashCode = prime * hashCode + ((getAvailableIpAddressCount() == null) ? 0 : getAvailableIpAddressCount().hashCode()); hashCode = prime * hashCode + ((getAvailabilityZone() == null) ? 0 : getAvailabilityZone().hashCode()); hashCode = prime * hashCode + ((isDefaultForAz() == null) ? 0 : isDefaultForAz().hashCode()); hashCode = prime * hashCode + ((isMapPublicIpOnLaunch() == null) ? 0 : isMapPublicIpOnLaunch().hashCode()); hashCode = prime * hashCode + ((getTags() == null) ? 0 : getTags().hashCode()); return hashCode; }
public Subnet unmarshall(StaxUnmarshallerContext context) throws Exception { Subnet subnet = new Subnet(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; subnet.setSubnetId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setVpcId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setCidrBlock(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setAvailableIpAddressCount(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setDefaultForAz(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setMapPublicIpOnLaunch(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.getTags().add(TagStaxUnmarshaller.getInstance().unmarshall(context));
@Test public void testSerialization() throws JsonProcessingException { String account = "123456"; Regions region = Regions.US_WEST_1; SubnetScanner scanner = getProjector().createBuilder(AWSScannerBuilder.class).withAccountId(account).withRegion(region).build(SubnetScanner.class); Subnet subnet = new Subnet(); subnet.setAvailabilityZone("us-west-2a"); subnet.setCidrBlock("192.168.100.0/24"); subnet.setSubnetId("subnet-1234"); subnet.setVpcId("vpc-9876"); subnet.setTags(Lists.newArrayList(new Tag("fizz","buzz"),new Tag("foo","bar"))); JsonNode n = scanner.convertAwsObject(subnet, Region.getRegion(region)); prettyPrint(n); Assertions.assertThat(n.path("aws_vpcId").asText()).isEqualTo("vpc-9876"); Assertions.assertThat(n.path("aws_subnetId").asText()).isEqualTo("subnet-1234"); Assertions.assertThat(n.path("aws_region").asText()).isEqualTo(region.getName()); Assertions.assertThat(n.path("aws_account").asText()).isEqualTo(account); Assertions.assertThat(n.path("aws_arn").asText()).isEqualTo("arn:aws:ec2:us-west-1:123456:subnet/subnet-1234"); Assertions.assertThat(n.path("aws_tag_fizz").asText()).isEqualTo("buzz"); Assertions.assertThat(n.path("aws_cidrBlock").asText()).isEqualTo("192.168.100.0/24"); } }
public static String getSubnetId(AmazonEC2Client ec2Client) { Subnet subnet = null; for (Subnet aux : ec2Client.describeSubnets().getSubnets()) { System.out.println(); if (aux.getState().equals("available") && aux.getAvailabilityZone().startsWith("eu-west-1")) { subnet = aux; break; } } Assert.assertNotNull("Subnet not null", subnet); return subnet.getSubnetId(); } }
/** * Converts this object into an AWS equivalent object. * * @return A new equivalent AWS object */ public Subnet toAwsObject() { Subnet subnet = new Subnet(); subnet.setSubnetId(subnetId); subnet.setAvailabilityZone(availabilityZone); subnet.setAvailableIpAddressCount(availableIpAddressCount); return subnet; }
for (Subnet subnet : subnets) emrVpcPricingState.getSubnetAvailableIpAddressCounts().put(subnet.getSubnetId(), subnet.getAvailableIpAddressCount());
/** * Chooses the best subnet from the given list of subnets, which belongs to the given availability zone. The "best" subnet is selected by the number of * available IP addresses in the subnet. A subnet with more availability is preferred. If multiple subnets have same IP availability, then the result subnet * is arbitrarily chosen. * * @param availabilityZone the availability zone in which the subnet belongs to * @param subnets the list of subnet to select from * * @return the subnet with the most number of available IPs */ private Subnet getBestSubnetForAvailabilityZone(String availabilityZone, List<Subnet> subnets) { List<Subnet> subnetsInAvailabilityZone = new ArrayList<>(); for (Subnet subnet : subnets) { if (subnet.getAvailabilityZone().equals(availabilityZone)) { subnetsInAvailabilityZone.add(subnet); } } return getTop(subnetsInAvailabilityZone, new IpAddressComparator()); }
/** * @return false if ID is null, or true if it is non-null */ public boolean verify() { // will return false if the id is null boolean result = false; if (subnetId != null) { if (ec2Client == null) { ec2Client = context.fetchEC2Client(); } List<String> id = new ArrayList<String>(); id.add(subnetId); List<Subnet> subnets = helper.getSubnets(id, ec2Client); if (subnets != null && !subnets.isEmpty()) { for (Subnet subnet : subnets) { if (subnet.getAvailabilityZone().equalsIgnoreCase(zone)) { if (subnet.getCidrBlock().equals(cidr)) { result = true; } } } } } return result; }
/** * * @param vpcId * @param cidr * @param zone * @param ec2Client * @return */ public String createSubnet(String vpcId, String cidr, String zone, AmazonEC2 ec2Client) { String subnetId = null; try { CreateSubnetRequest request = new CreateSubnetRequest() .withVpcId(vpcId) .withCidrBlock(cidr) .withAvailabilityZone(zone); CreateSubnetResult result = ec2Client.createSubnet(request); if (result != null && result.getSubnet() != null) { subnetId = result.getSubnet().getSubnetId(); } } catch (AmazonServiceException e) { log.error("Failed to create Subnet", e); if (!"InvalidVpcID.NotFound".equalsIgnoreCase(e.getErrorCode())) { throw e; } } return subnetId; }
@Override public int compare(Subnet o1, Subnet o2) { return o2.getAvailableIpAddressCount().compareTo(o1.getAvailableIpAddressCount()); } }
/** * <p> * The IPv4 CIDR block assigned to the subnet. * </p> * * @param cidrBlock * The IPv4 CIDR block assigned to the subnet. * @return Returns a reference to this object so that method calls can be chained together. */ public Subnet withCidrBlock(String cidrBlock) { setCidrBlock(cidrBlock); return this; }
/** * <p> * The number of unused private IPv4 addresses in the subnet. The IPv4 addresses for any stopped instances are * considered unavailable. * </p> * * @param availableIpAddressCount * The number of unused private IPv4 addresses in the subnet. The IPv4 addresses for any stopped instances * are considered unavailable. * @return Returns a reference to this object so that method calls can be chained together. */ public Subnet withAvailableIpAddressCount(Integer availableIpAddressCount) { setAvailableIpAddressCount(availableIpAddressCount); return this; }
public Subnet unmarshall(StaxUnmarshallerContext context) throws Exception { Subnet subnet = new Subnet(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; subnet.setAvailabilityZone(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setAvailabilityZoneId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setAvailableIpAddressCount(IntegerStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setCidrBlock(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setDefaultForAz(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setMapPublicIpOnLaunch(BooleanStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setState(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setSubnetId(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue; subnet.setVpcId(StringStaxUnmarshaller.getInstance().unmarshall(context));
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof Subnet == false) return false; Subnet other = (Subnet)obj; if (other.getSubnetId() == null ^ this.getSubnetId() == null) return false; if (other.getSubnetId() != null && other.getSubnetId().equals(this.getSubnetId()) == false) return false; if (other.getState() == null ^ this.getState() == null) return false; if (other.getState() != null && other.getState().equals(this.getState()) == false) return false; if (other.getVpcId() == null ^ this.getVpcId() == null) return false; if (other.getVpcId() != null && other.getVpcId().equals(this.getVpcId()) == false) return false; if (other.getCidrBlock() == null ^ this.getCidrBlock() == null) return false; if (other.getCidrBlock() != null && other.getCidrBlock().equals(this.getCidrBlock()) == false) return false; if (other.getAvailableIpAddressCount() == null ^ this.getAvailableIpAddressCount() == null) return false; if (other.getAvailableIpAddressCount() != null && other.getAvailableIpAddressCount().equals(this.getAvailableIpAddressCount()) == false) return false; if (other.getAvailabilityZone() == null ^ this.getAvailabilityZone() == null) return false; if (other.getAvailabilityZone() != null && other.getAvailabilityZone().equals(this.getAvailabilityZone()) == false) return false; if (other.isDefaultForAz() == null ^ this.isDefaultForAz() == null) return false; if (other.isDefaultForAz() != null && other.isDefaultForAz().equals(this.isDefaultForAz()) == false) return false; if (other.isMapPublicIpOnLaunch() == null ^ this.isMapPublicIpOnLaunch() == null) return false; if (other.isMapPublicIpOnLaunch() != null && other.isMapPublicIpOnLaunch().equals(this.isMapPublicIpOnLaunch()) == false) return false; if (other.getTags() == null ^ this.getTags() == null) return false; if (other.getTags() != null && other.getTags().equals(this.getTags()) == false) return false; return true; }
public static String getSubnetId(AmazonEC2Client ec2Client) { Subnet subnet = null; for (Subnet aux : ec2Client.describeSubnets().getSubnets()) { System.out.println(); if (aux.getState().equals("available") && aux.getAvailabilityZone().startsWith("eu-west-1")) { subnet = aux; break; } } Assert.assertNotNull("Subnet not null", subnet); return subnet.getSubnetId(); } }
for (Subnet subnet : subnets) emrVpcPricingState.getSubnetAvailableIpAddressCounts().put(subnet.getSubnetId(), subnet.getAvailableIpAddressCount());