@Test public void testComputeListenerTransformation() { DefaultAction actionBad = new DefaultAction(1, "tgArnBad", ActionType.AUTHENTICATE_OIDC); TargetGroup targetGroupBad = new TargetGroup( "tgArnBad", ImmutableList.of(), Protocol.TCP, 80, "tgNameBad", TargetGroup.Type.IP); DefaultAction actionGood = new DefaultAction(2, "tgArnGood", ActionType.FORWARD); TargetGroup targetGroupGood = new TargetGroup( "tgArnGood", ImmutableList.of(), Protocol.TCP, 80, "tgNameGood", TargetGroup.Type.IP); TargetHealthDescription badTarget = new TargetHealthDescription( new LoadBalancerTarget("targetZone", "6.6.6.6", 80), new TargetHealth(HealthState.UNHEALTHY)); TargetHealthDescription goodTarget = new TargetHealthDescription( new LoadBalancerTarget("targetZone", "1.1.1.1", 80), new TargetHealth(HealthState.HEALTHY)); Listener listener = new Listener("listenerArn", ImmutableList.of(actionBad, actionGood), Protocol.TCP, 80); Region region = Region.builder("r1") .setTargetGroups( ImmutableMap.of( targetGroupBad.getId(), targetGroupBad, targetGroupGood.getId(), targetGroupGood)) .setLoadBalancerTargetHealths( ImmutableMap.of( "tgBadArn", new LoadBalancerTargetHealth("tgArnBad", ImmutableList.of(badTarget)), "tgArnGood", new LoadBalancerTargetHealth("tgArnGood", ImmutableList.of(goodTarget)))) .build(); LoadBalancerTransformation loadBalancerTransformation = _loadBalancer.computeListenerTransformation( listener, _loadBalancerIp, ImmutableSet.of("targetZone"), region, new Warnings()); assertThat( loadBalancerTransformation.getGuard(), equalTo(new MatchHeaderSpace(listener.getMatchingHeaderSpace()))); assertThat( loadBalancerTransformation.getStep(), equalTo( computeTargetGroupTransformationStep( "tgArnGood", _loadBalancerIp, ImmutableSet.of("targetZone"), region, new Warnings()))); }
@Nullable @VisibleForTesting LoadBalancerTransformation computeListenerTransformation( LoadBalancerListener.Listener listener, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { try { HeaderSpace matchHeaderSpace = listener.getMatchingHeaderSpace(); Optional<DefaultAction> forwardingAction = listener.getDefaultActions().stream() .filter(defaultAction -> defaultAction.getType() == ActionType.FORWARD) .findFirst(); if (!forwardingAction.isPresent()) { warnings.redFlag( String.format( "No forwarding action found for listener %s of load balancer %s (%s)", listener, _arn, _name)); return null; } TransformationStep transformationStep = computeTargetGroupTransformationStep( forwardingAction.get().getTargetGroupArn(), loadBalancerIp, enabledTargetZones, region, warnings); if (transformationStep == null) { return null; } return new LoadBalancerTransformation( new MatchHeaderSpace(matchHeaderSpace), transformationStep); } catch (Exception e) { warnings.redFlag( String.format( "Failed to compute listener transformation for listener %s of load balancer %s (%s): %s", listener, _arn, _name, Throwables.getStackTraceAsString(e))); return null; } }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting LoadBalancerTransformation computeListenerTransformation( LoadBalancerListener.Listener listener, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { try { HeaderSpace matchHeaderSpace = listener.getMatchingHeaderSpace(); Optional<DefaultAction> forwardingAction = listener.getDefaultActions().stream() .filter(defaultAction -> defaultAction.getType() == ActionType.FORWARD) .findFirst(); if (!forwardingAction.isPresent()) { warnings.redFlag( String.format( "No forwarding action found for listener %s of load balancer %s (%s)", listener, _arn, _name)); return null; } TransformationStep transformationStep = computeTargetGroupTransformationStep( forwardingAction.get().getTargetGroupArn(), loadBalancerIp, enabledTargetZones, region, warnings); if (transformationStep == null) { return null; } return new LoadBalancerTransformation( new MatchHeaderSpace(matchHeaderSpace), transformationStep); } catch (Exception e) { warnings.redFlag( String.format( "Failed to compute listener transformation for listener %s of load balancer %s (%s): %s", listener, _arn, _name, Throwables.getStackTraceAsString(e))); return null; } } }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting LoadBalancerTransformation computeListenerTransformation( LoadBalancerListener.Listener listener, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { try { HeaderSpace matchHeaderSpace = listener.getMatchingHeaderSpace(); Optional<DefaultAction> forwardingAction = listener.getDefaultActions().stream() .filter(defaultAction -> defaultAction.getType() == ActionType.FORWARD) .findFirst(); if (!forwardingAction.isPresent()) { warnings.redFlag( String.format( "No forwarding action found for listener %s of load balancer %s (%s)", listener, _arn, _name)); return null; } TransformationStep transformationStep = computeTargetGroupTransformationStep( forwardingAction.get().getTargetGroupArn(), loadBalancerIp, enabledTargetZones, region, warnings); if (transformationStep == null) { return null; } return new LoadBalancerTransformation( new MatchHeaderSpace(matchHeaderSpace), transformationStep); } catch (Exception e) { warnings.redFlag( String.format( "Failed to compute listener transformation for listener %s of load balancer %s (%s): %s", listener, _arn, _name, Throwables.getStackTraceAsString(e))); return null; } } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); }
LoadBalancer implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting LoadBalancerTransformation computeListenerTransformation( LoadBalancerListener.Listener listener, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { try { HeaderSpace matchHeaderSpace = listener.getMatchingHeaderSpace(); Optional<DefaultAction> forwardingAction = listener.getDefaultActions().stream() .filter(defaultAction -> defaultAction.getType() == ActionType.FORWARD) .findFirst(); if (!forwardingAction.isPresent()) { warnings.redFlag( String.format( "No forwarding action found for listener %s of load balancer %s (%s)", listener, _arn, _name)); return null; } TransformationStep transformationStep = computeTargetGroupTransformationStep( forwardingAction.get().getTargetGroupArn(), loadBalancerIp, enabledTargetZones, region, warnings); if (transformationStep == null) { return null; } return new LoadBalancerTransformation( new MatchHeaderSpace(matchHeaderSpace), transformationStep); } catch (Exception e) { warnings.redFlag( String.format( "Failed to compute listener transformation for listener %s of load balancer %s (%s): %s", listener, _arn, _name, Throwables.getStackTraceAsString(e))); return null; } } 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 LoadBalancerTransformation computeListenerTransformation( LoadBalancerListener.Listener listener, Ip loadBalancerIp, Set<String> enabledTargetZones, Region region, Warnings warnings) { try { HeaderSpace matchHeaderSpace = listener.getMatchingHeaderSpace(); Optional<DefaultAction> forwardingAction = listener.getDefaultActions().stream() .filter(defaultAction -> defaultAction.getType() == ActionType.FORWARD) .findFirst(); if (!forwardingAction.isPresent()) { warnings.redFlag( String.format( "No forwarding action found for listener %s of load balancer %s (%s)", listener, _arn, _name)); return null; } TransformationStep transformationStep = computeTargetGroupTransformationStep( forwardingAction.get().getTargetGroupArn(), loadBalancerIp, enabledTargetZones, region, warnings); if (transformationStep == null) { return null; } return new LoadBalancerTransformation( new MatchHeaderSpace(matchHeaderSpace), transformationStep); } catch (Exception e) { warnings.redFlag( String.format( "Failed to compute listener transformation for listener %s of load balancer %s (%s): %s", listener, _arn, _name, Throwables.getStackTraceAsString(e))); return null; } } 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();  }