@Test public void testComputeTargetGroupTransformationStep() { TargetHealthDescription unhealthyTarget = new TargetHealthDescription( new LoadBalancerTarget("targetZone", "6.6.6.6", 80), new TargetHealth(HealthState.UNHEALTHY)); TargetHealthDescription healthyTarget1 = new TargetHealthDescription( new LoadBalancerTarget("targetZone", "1.1.1.1", 80), new TargetHealth(HealthState.HEALTHY)); TargetHealthDescription healthyTarget2 = new TargetHealthDescription( new LoadBalancerTarget("targetZone", "2.2.2.2", 80), new TargetHealth(HealthState.HEALTHY)); String targetGroupArn = "tgArn"; TargetGroup targetGroup = new TargetGroup( targetGroupArn, ImmutableList.of(), Protocol.TCP, 80, "tgName", TargetGroup.Type.IP); Region region = Region.builder("r1") .setTargetGroups(ImmutableMap.of(targetGroupArn, targetGroup)) .setLoadBalancerTargetHealths( ImmutableMap.of( targetGroupArn, new LoadBalancerTargetHealth( targetGroupArn, ImmutableList.of(unhealthyTarget, healthyTarget1, healthyTarget2)))) .build(); Ip loadBalancerIp = Ip.parse("10.10.10.10"); assertThat( computeTargetGroupTransformationStep( targetGroupArn, loadBalancerIp, ImmutableSet.of("targetZone"), region, new Warnings()), equalTo( new ApplyAny( computeTargetTransformationStep( healthyTarget1.getTarget(), TargetGroup.Type.IP, loadBalancerIp, region, new Warnings()), computeTargetTransformationStep( healthyTarget2.getTarget(), TargetGroup.Type.IP, loadBalancerIp, region, new Warnings())))); }
@Nullable @VisibleForTesting static TransformationStep computeTargetGroupTransformationStep( String targetGroupArn, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { TargetGroup targetGroup = region.getTargetGroups().get(targetGroupArn); if (targetGroup == null) { warnings.redFlag(String.format("Target group ARN %s not found", targetGroupArn)); return null; } LoadBalancerTargetHealth targetHealths = region.getLoadBalancerTargetHealths().get(targetGroupArn); if (targetHealths == null) { warnings.redFlag( String.format( "Target health information not found for target group ARN %s", targetGroupArn)); return null; } Set<TargetHealthDescription> activeTargets = getActiveTargets(targetHealths, targetGroup, enabledTargetZones, region, true, warnings); Set<TransformationStep> transformationSteps = activeTargets.stream() .map( desc -> computeTargetTransformationStep( desc.getTarget(), targetGroup.getTargetType(), loadBalancerIp, region, warnings)) .filter(Objects::nonNull) .collect(ImmutableSet.toImmutableSet()); if (transformationSteps.isEmpty()) { return null; } return new ApplyAny(transformationSteps); }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting static TransformationStep computeTargetGroupTransformationStep( String targetGroupArn, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { TargetGroup targetGroup = region.getTargetGroups().get(targetGroupArn); if (targetGroup == null) { warnings.redFlag(String.format("Target group ARN %s not found", targetGroupArn)); return null; } LoadBalancerTargetHealth targetHealths = region.getLoadBalancerTargetHealths().get(targetGroupArn); if (targetHealths == null) { warnings.redFlag( String.format( "Target health information not found for target group ARN %s", targetGroupArn)); return null; } Set<TargetHealthDescription> activeTargets = getActiveTargets(targetHealths, targetGroup, enabledTargetZones, region, true, warnings); Set<TransformationStep> transformationSteps = activeTargets.stream() .map( desc -> computeTargetTransformationStep( desc.getTarget(), targetGroup.getTargetType(), loadBalancerIp, region, warnings)) .filter(Objects::nonNull) .collect(ImmutableSet.toImmutableSet()); if (transformationSteps.isEmpty()) { return null; } return new ApplyAny(transformationSteps); } }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting static TransformationStep computeTargetGroupTransformationStep( String targetGroupArn, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { TargetGroup targetGroup = region.getTargetGroups().get(targetGroupArn); if (targetGroup == null) { warnings.redFlag(String.format("Target group ARN %s not found", targetGroupArn)); return null; } LoadBalancerTargetHealth targetHealths = region.getLoadBalancerTargetHealths().get(targetGroupArn); if (targetHealths == null) { warnings.redFlag( String.format( "Target health information not found for target group ARN %s", targetGroupArn)); return null; } Set<TargetHealthDescription> activeTargets = getActiveTargets(targetHealths, targetGroup, enabledTargetZones, region, true, warnings); Set<TransformationStep> transformationSteps = activeTargets.stream() .map( desc -> computeTargetTransformationStep( desc.getTarget(), targetGroup.getTargetType(), loadBalancerIp, region, warnings)) .filter(Objects::nonNull) .collect(ImmutableSet.toImmutableSet()); if (transformationSteps.isEmpty()) { return null; } return new ApplyAny(transformationSteps); } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting static TransformationStep computeTargetGroupTransformationStep( String targetGroupArn, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { TargetGroup targetGroup = region.getTargetGroups().get(targetGroupArn); if (targetGroup == null) { warnings.redFlag(String.format("Target group ARN %s not found", targetGroupArn)); return null; } LoadBalancerTargetHealth targetHealths = region.getLoadBalancerTargetHealths().get(targetGroupArn); if (targetHealths == null) { warnings.redFlag( String.format( "Target health information not found for target group ARN %s", targetGroupArn)); return null; } Set<TargetHealthDescription> activeTargets = getActiveTargets(targetHealths, targetGroup, enabledTargetZones, region, true, warnings); Set<TransformationStep> transformationSteps = activeTargets.stream() .map( desc -> computeTargetTransformationStep( desc.getTarget(), targetGroup.getTargetType(), loadBalancerIp, region, warnings)) .filter(Objects::nonNull) .collect(ImmutableSet.toImmutableSet()); if (transformationSteps.isEmpty()) { return null; } return new ApplyAny(transformationSteps); } 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 { @Nullable @VisibleForTesting static TransformationStep computeTargetGroupTransformationStep( String targetGroupArn, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { TargetGroup targetGroup = region.getTargetGroups().get(targetGroupArn); if (targetGroup == null) { warnings.redFlag(String.format("Target group ARN %s not found", targetGroupArn)); return null; } LoadBalancerTargetHealth targetHealths = region.getLoadBalancerTargetHealths().get(targetGroupArn); if (targetHealths == null) { warnings.redFlag( String.format( "Target health information not found for target group ARN %s", targetGroupArn)); return null; } Set<TargetHealthDescription> activeTargets = getActiveTargets(targetHealths, targetGroup, enabledTargetZones, region, true, warnings); Set<TransformationStep> transformationSteps = activeTargets.stream() .map( desc -> computeTargetTransformationStep( desc.getTarget(), targetGroup.getTargetType(), loadBalancerIp, region, warnings)) .filter(Objects::nonNull) .collect(ImmutableSet.toImmutableSet()); if (transformationSteps.isEmpty()) { return null; } return new ApplyAny(transformationSteps); } 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();  }