@Test public void testComputeTargetTransformationStep_instanceTarget() { Ip targetIp = Ip.parse("1.1.1.1"); Ip loadBalancerIp = Ip.parse("10.10.10.10"); String instanceId = "instance"; LoadBalancerTarget target = new LoadBalancerTarget("zone", instanceId, 80); Region region = Region.builder("r1") .setInstances( ImmutableMap.of( instanceId, Instance.builder() .setInstanceId(instanceId) .setPrimaryPrivateIpAddress(targetIp) .build())) .build(); assertThat( computeTargetTransformationStep( target, TargetGroup.Type.INSTANCE, loadBalancerIp, region, new Warnings()), equalTo( new ApplyAll( TransformationStep.assignDestinationIp(targetIp, targetIp), TransformationStep.assignDestinationPort(target.getPort(), target.getPort())))); }
@Nullable @VisibleForTesting static TransformationStep computeTargetTransformationStep( LoadBalancerTarget target, TargetGroup.Type targetGroupType, Ip loadBalancerIp, Region region, Warnings warnings) { Ip targetIp = getTargetIp(target, targetGroupType, region); if (targetIp == null) { warnings.redFlag(String.format("Could not determine IP for load balancer target %s", target)); return null; } TransformationStep transformDstIp = TransformationStep.assignDestinationIp(targetIp, targetIp); TransformationStep transformDstPort = TransformationStep.assignDestinationPort(target.getPort(), target.getPort()); switch (targetGroupType) { case INSTANCE: return new ApplyAll(transformDstIp, transformDstPort); case IP: return new ApplyAll( TransformationStep.assignSourceIp(loadBalancerIp, loadBalancerIp), TransformationStep.assignSourcePort( EPHEMERAL_LOWEST.number(), EPHEMERAL_HIGHEST.number()), transformDstIp, transformDstPort); default: throw new IllegalArgumentException( String.format("Unrecognized target group type %s", targetGroupType)); } }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting static TransformationStep computeTargetTransformationStep( LoadBalancerTarget target, TargetGroup.Type targetGroupType, Ip loadBalancerIp, Region region, Warnings warnings) { Ip targetIp = getTargetIp(target, targetGroupType, region); if (targetIp == null) { warnings.redFlag(String.format("Could not determine IP for load balancer target %s", target)); return null; } TransformationStep transformDstIp = TransformationStep.assignDestinationIp(targetIp, targetIp); TransformationStep transformDstPort = TransformationStep.assignDestinationPort(target.getPort(), target.getPort()); switch (targetGroupType) { case INSTANCE: return new ApplyAll(transformDstIp, transformDstPort); case IP: return new ApplyAll( TransformationStep.assignSourceIp(loadBalancerIp, loadBalancerIp), TransformationStep.assignSourcePort( EPHEMERAL_LOWEST.number(), EPHEMERAL_HIGHEST.number()), transformDstIp, transformDstPort); default: throw new IllegalArgumentException( String.format("Unrecognized target group type %s", targetGroupType)); } } }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting static TransformationStep computeTargetTransformationStep( LoadBalancerTarget target, TargetGroup.Type targetGroupType, Ip loadBalancerIp, Region region, Warnings warnings) { Ip targetIp = getTargetIp(target, targetGroupType, region); if (targetIp == null) { warnings.redFlag(String.format("Could not determine IP for load balancer target %s", target)); return null; } TransformationStep transformDstIp = TransformationStep.assignDestinationIp(targetIp, targetIp); TransformationStep transformDstPort = TransformationStep.assignDestinationPort(target.getPort(), target.getPort()); switch (targetGroupType) { case INSTANCE: return new ApplyAll(transformDstIp, transformDstPort); case IP: return new ApplyAll( TransformationStep.assignSourceIp(loadBalancerIp, loadBalancerIp), TransformationStep.assignSourcePort( EPHEMERAL_LOWEST.number(), EPHEMERAL_HIGHEST.number()), transformDstIp, transformDstPort); default: throw new IllegalArgumentException( String.format("Unrecognized target group type %s", targetGroupType)); } } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting static TransformationStep computeTargetTransformationStep( LoadBalancerTarget target, TargetGroup.Type targetGroupType, Ip loadBalancerIp, Region region, Warnings warnings) { Ip targetIp = getTargetIp(target, targetGroupType, region); if (targetIp == null) { warnings.redFlag(String.format("Could not determine IP for load balancer target %s", target)); return null; } TransformationStep transformDstIp = TransformationStep.assignDestinationIp(targetIp, targetIp); TransformationStep transformDstPort = TransformationStep.assignDestinationPort(target.getPort(), target.getPort()); switch (targetGroupType) { case INSTANCE: return new ApplyAll(transformDstIp, transformDstPort); case IP: return new ApplyAll( TransformationStep.assignSourceIp(loadBalancerIp, loadBalancerIp), TransformationStep.assignSourcePort( EPHEMERAL_LOWEST.number(), EPHEMERAL_HIGHEST.number()), transformDstIp, transformDstPort); default: throw new IllegalArgumentException( String.format("Unrecognized target group type %s", targetGroupType)); } } 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 computeTargetTransformationStep( LoadBalancerTarget target, TargetGroup.Type targetGroupType, Ip loadBalancerIp, Region region, Warnings warnings) { Ip targetIp = getTargetIp(target, targetGroupType, region); if (targetIp == null) { warnings.redFlag(String.format("Could not determine IP for load balancer target %s", target)); return null; } TransformationStep transformDstIp = TransformationStep.assignDestinationIp(targetIp, targetIp); TransformationStep transformDstPort = TransformationStep.assignDestinationPort(target.getPort(), target.getPort()); switch (targetGroupType) { case INSTANCE: return new ApplyAll(transformDstIp, transformDstPort); case IP: return new ApplyAll( TransformationStep.assignSourceIp(loadBalancerIp, loadBalancerIp), TransformationStep.assignSourcePort( EPHEMERAL_LOWEST.number(), EPHEMERAL_HIGHEST.number()), transformDstIp, transformDstPort); default: throw new IllegalArgumentException( String.format("Unrecognized target group type %s", targetGroupType)); } } 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();  }