@Test public void testIsTargetInValidAvailabilityZone_ipTarget() { TargetGroup targetGroup = new TargetGroup( "tgArg", ImmutableList.of(), Protocol.TCP, 80, "tgName", TargetGroup.Type.IP); TargetHealthDescription targetHealthDescription = new TargetHealthDescription( new LoadBalancerTarget("targetZone", "1.1.1.1", 80), new TargetHealth(HealthState.HEALTHY)); Set<String> targetZone = ImmutableSet.of("targetZone"); Set<String> otherZone = ImmutableSet.of("otherZone"); assertTrue( isTargetInValidAvailabilityZone( targetHealthDescription, targetGroup.getTargetType(), targetZone, Region.builder("r1").build())); assertFalse( isTargetInValidAvailabilityZone( targetHealthDescription, targetGroup.getTargetType(), otherZone, Region.builder("r1").build())); assertTrue( isTargetInValidAvailabilityZone( new TargetHealthDescription( new LoadBalancerTarget("all", "1.1.1.1", 80), new TargetHealth(HealthState.HEALTHY)), targetGroup.getTargetType(), otherZone, Region.builder("r1").build())); }
@VisibleForTesting static boolean isTargetInValidAvailabilityZone( TargetHealthDescription targetHealthDescription, TargetGroup.Type targetType, Set<String> enabledTargetZones, Region region) { switch (targetType) { case IP: return "all".equals(targetHealthDescription.getTarget().getAvailabilityZone()) || enabledTargetZones.contains( targetHealthDescription.getTarget().getAvailabilityZone()); case INSTANCE: Instance instance = region.getInstances().get(targetHealthDescription.getTarget().getId()); if (instance == null) { return false; } Subnet subnet = region.getSubnets().get(instance.getSubnetId()); return subnet != null && enabledTargetZones.contains(subnet.getAvailabilityZone()); default: throw new IllegalArgumentException("Unknown target group type " + targetType); } }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static boolean isTargetInValidAvailabilityZone( TargetHealthDescription targetHealthDescription, TargetGroup.Type targetType, Set<String> enabledTargetZones, Region region) { switch (targetType) { case IP: return "all".equals(targetHealthDescription.getTarget().getAvailabilityZone()) || enabledTargetZones.contains( targetHealthDescription.getTarget().getAvailabilityZone()); case INSTANCE: Instance instance = region.getInstances().get(targetHealthDescription.getTarget().getId()); if (instance == null) { return false; } Subnet subnet = region.getSubnets().get(instance.getSubnetId()); return subnet != null && enabledTargetZones.contains(subnet.getAvailabilityZone()); default: throw new IllegalArgumentException("Unknown target group type " + targetType); } } }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static boolean isTargetInValidAvailabilityZone( TargetHealthDescription targetHealthDescription, TargetGroup.Type targetType, Set<String> enabledTargetZones, Region region) { switch (targetType) { case IP: return "all".equals(targetHealthDescription.getTarget().getAvailabilityZone()) || enabledTargetZones.contains( targetHealthDescription.getTarget().getAvailabilityZone()); case INSTANCE: Instance instance = region.getInstances().get(targetHealthDescription.getTarget().getId()); if (instance == null) { return false; } Subnet subnet = region.getSubnets().get(instance.getSubnetId()); return subnet != null && enabledTargetZones.contains(subnet.getAvailabilityZone()); default: throw new IllegalArgumentException("Unknown target group type " + targetType); } } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static boolean isTargetInValidAvailabilityZone( TargetHealthDescription targetHealthDescription, TargetGroup.Type targetType, Set<String> enabledTargetZones, Region region) { switch (targetType) { case IP: return "all".equals(targetHealthDescription.getTarget().getAvailabilityZone()) || enabledTargetZones.contains( targetHealthDescription.getTarget().getAvailabilityZone()); case INSTANCE: Instance instance = region.getInstances().get(targetHealthDescription.getTarget().getId()); if (instance == null) { return false; } Subnet subnet = region.getSubnets().get(instance.getSubnetId()); return subnet != null && enabledTargetZones.contains(subnet.getAvailabilityZone()); default: throw new IllegalArgumentException("Unknown target group type " + targetType); } } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); @Override String getId(); @Nonnull List<AvailabilityZone> getAvailabilityZones(); @Nonnull String getDnsName(); @Nonnull String getName(); @Nonnull Scheme getScheme(); @Nonnull Type getType(); @Nonnull String getVpcId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting static boolean isTargetInValidAvailabilityZone( TargetHealthDescription targetHealthDescription, TargetGroup.Type targetType, Set<String> enabledTargetZones, Region region) { switch (targetType) { case IP: return "all".equals(targetHealthDescription.getTarget().getAvailabilityZone()) || enabledTargetZones.contains( targetHealthDescription.getTarget().getAvailabilityZone()); case INSTANCE: Instance instance = region.getInstances().get(targetHealthDescription.getTarget().getId()); if (instance == null) { return false; } Subnet subnet = region.getSubnets().get(instance.getSubnetId()); return subnet != null && enabledTargetZones.contains(subnet.getAvailabilityZone()); default: throw new IllegalArgumentException("Unknown target group type " + targetType); } } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); @Override String getId(); @Nonnull List<AvailabilityZone> getAvailabilityZones(); @Nonnull String getDnsName(); @Nonnull String getName(); @Nonnull Scheme getScheme(); @Nonnull Type getType(); @Nonnull String getVpcId(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }