@Test public void testToConfigurationNode() { AvailabilityZone availabilityZone = _loadBalancer.getAvailabilityZones().get(0); Prefix subnetPrefix = Prefix.create(_loadBalancerIp, 24); Ip publicIp = Ip.parse("1.1.1.1"); NetworkInterface networkInterface = new NetworkInterface( "interface", availabilityZone.getSubnetId(), _loadBalancer.getVpcId(), ImmutableList.of(), ImmutableList.of(new PrivateIpAddress(true, _loadBalancerIp, publicIp)), LOAD_BALANCER_INTERFACE_DESCRIPTION_PREFIX + _loadBalancerArnSuffix, null, ImmutableMap.of()); Region region = Region.builder("r1") .setNetworkInterfaces(ImmutableMap.of("interface", networkInterface)) .setSubnets( ImmutableMap.of( availabilityZone.getSubnetId(), getTestSubnet( subnetPrefix, availabilityZone.getSubnetId(), _loadBalancer.getVpcId(), availabilityZone.getZoneName()))) .build(); Configuration cfgNode = _loadBalancer.toConfigurationNode( availabilityZone, new ConvertedConfiguration(), region, new Warnings()); assertThat( cfgNode.getHostname(), equalTo( getNodeId(_loadBalancer.getDnsName(), availabilityZone.getZoneName()).toLowerCase())); assertThat(cfgNode.getDeviceModel(), equalTo(DeviceModel.AWS_ELB_NETWORK)); assertThat(cfgNode.getHumanName(), equalTo(_loadBalancer.getName())); assertThat(cfgNode.getVendorFamily().getAws().getVpcId(), equalTo(_loadBalancer.getVpcId())); assertThat( cfgNode.getVendorFamily().getAws().getSubnetId(), equalTo(availabilityZone.getSubnetId())); assertThat(cfgNode.getVendorFamily().getAws().getRegion(), equalTo(region.getName())); Interface viIface = getOnlyElement(cfgNode.getAllInterfaces().values().iterator()); assertThat( viIface.getConcreteAddress(), equalTo(ConcreteInterfaceAddress.create(_loadBalancerIp, 24))); assertThat(viIface.getIncomingFilter().getName(), equalTo(LISTENER_FILTER_NAME)); assertThat(viIface.getIncomingTransformation(), equalTo(FINAL_TRANSFORMATION)); assertThat( viIface.getPostTransformationIncomingFilter(), equalTo( computeNotForwardedFilter( ImmutableList.of(new PrivateIpAddress(true, _loadBalancerIp, null))))); assertThat( cfgNode .getGeneratedReferenceBooks() .get(GeneratedRefBookUtils.getName(cfgNode.getHostname(), BookType.PublicIps)) .getAddressGroups(), hasItem( new AddressGroup( ImmutableSortedSet.of(publicIp.toString()), publicIpAddressGroupName(networkInterface)))); assertThat( cfgNode.getLocationInfo(), equalTo( ImmutableMap.of( interfaceLocation(viIface), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(viIface), INFRASTRUCTURE_LOCATION_INFO))); }
@VisibleForTesting Configuration toConfigurationNode( AvailabilityZone availabilityZone, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(_dnsName, availabilityZone.getZoneName()), "aws", DeviceModel.AWS_ELB_NETWORK); cfgNode.setHumanName(_name); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(availabilityZone.getSubnetId()); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); getInstanceTargetStaticRoutes( awsConfiguration.getNlbsToInstanceTargets().get(_arn), availabilityZone.getSubnetId()) .forEach(staticRoute -> Utils.addStaticRoute(cfgNode, staticRoute)); Optional<NetworkInterface> networkInterface = findMyInterface(availabilityZone.getSubnetId(), _arn, region); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for load balancer %s (%s) in subnet %s.", _name, _arn, availabilityZone.getSubnetId())); return cfgNode; } Subnet subnet = region.getSubnets().get(availabilityZone.getSubnetId()); Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); LoadBalancerAttributes loadBalancerAttributes = region.getLoadBalancerAttributes().get(_arn); if (loadBalancerAttributes == null) { warnings.redFlag( String.format( "Attributes not found for load balancer %s (%s). Assuming that cross zone load balancing is disabled.", _name, _arn)); } boolean crossZoneLoadBalancing = loadBalancerAttributes != null && loadBalancerAttributes.getCrossZoneLoadBalancing(); List<Listener> listeners = ImmutableList.of(); LoadBalancerListener lbListener = region.getLoadBalancerListeners().get(_arn); if (lbListener != null) { listeners = lbListener.getListeners(); } else { warnings.redFlag( String.format("Listeners not found for load balancer %s (%s).", _name, _arn)); } IpAccessList incomingFilter = computeListenerFilter(listeners); viIface.setIncomingFilter(incomingFilter); cfgNode.getIpAccessLists().put(incomingFilter.getName(), incomingFilter); installTransformations( viIface, getEnabledTargetZones(availabilityZone, crossZoneLoadBalancing, _availabilityZones), listeners, region, warnings); IpAccessList defaultFilter = computeNotForwardedFilter(networkInterface.get().getPrivateIpAddresses()); viIface.setPostTransformationIncomingFilter(defaultFilter); cfgNode.getIpAccessLists().put(defaultFilter.getName(), defaultFilter); createPublicIpsRefBook(Collections.singleton(networkInterface.get()), cfgNode); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(viIface), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting Configuration toConfigurationNode( AvailabilityZone availabilityZone, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(_dnsName, availabilityZone.getZoneName()), "aws", DeviceModel.AWS_ELB_NETWORK); cfgNode.setHumanName(_name); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(availabilityZone.getSubnetId()); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); getInstanceTargetStaticRoutes( awsConfiguration.getNlbsToInstanceTargets().get(_arn), availabilityZone.getSubnetId()) .forEach(staticRoute -> Utils.addStaticRoute(cfgNode, staticRoute)); Optional<NetworkInterface> networkInterface = findMyInterface(availabilityZone.getSubnetId(), _arn, region); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for load balancer %s (%s) in subnet %s.", _name, _arn, availabilityZone.getSubnetId())); return cfgNode; } Subnet subnet = region.getSubnets().get(availabilityZone.getSubnetId()); Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); LoadBalancerAttributes loadBalancerAttributes = region.getLoadBalancerAttributes().get(_arn); if (loadBalancerAttributes == null) { warnings.redFlag( String.format( "Attributes not found for load balancer %s (%s). Assuming that cross zone load balancing is disabled.", _name, _arn)); } boolean crossZoneLoadBalancing = loadBalancerAttributes != null && loadBalancerAttributes.getCrossZoneLoadBalancing(); List<Listener> listeners = ImmutableList.of(); LoadBalancerListener lbListener = region.getLoadBalancerListeners().get(_arn); if (lbListener != null) { listeners = lbListener.getListeners(); } else { warnings.redFlag( String.format("Listeners not found for load balancer %s (%s).", _name, _arn)); } IpAccessList incomingFilter = computeListenerFilter(listeners); viIface.setIncomingFilter(incomingFilter); cfgNode.getIpAccessLists().put(incomingFilter.getName(), incomingFilter); installTransformations( viIface, getEnabledTargetZones(availabilityZone, crossZoneLoadBalancing, _availabilityZones), listeners, region, warnings); IpAccessList defaultFilter = computeNotForwardedFilter(networkInterface.get().getPrivateIpAddresses()); viIface.setPostTransformationIncomingFilter(defaultFilter); cfgNode.getIpAccessLists().put(defaultFilter.getName(), defaultFilter); createPublicIpsRefBook(Collections.singleton(networkInterface.get()), cfgNode); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(viIface), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting Configuration toConfigurationNode( AvailabilityZone availabilityZone, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(_dnsName, availabilityZone.getZoneName()), "aws", DeviceModel.AWS_ELB_NETWORK); cfgNode.setHumanName(_name); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(availabilityZone.getSubnetId()); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); getInstanceTargetStaticRoutes( awsConfiguration.getNlbsToInstanceTargets().get(_arn), availabilityZone.getSubnetId()) .forEach(staticRoute -> Utils.addStaticRoute(cfgNode, staticRoute)); Optional<NetworkInterface> networkInterface = findMyInterface(availabilityZone.getSubnetId(), _arn, region); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for load balancer %s (%s) in subnet %s.", _name, _arn, availabilityZone.getSubnetId())); return cfgNode; } Subnet subnet = region.getSubnets().get(availabilityZone.getSubnetId()); Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); LoadBalancerAttributes loadBalancerAttributes = region.getLoadBalancerAttributes().get(_arn); if (loadBalancerAttributes == null) { warnings.redFlag( String.format( "Attributes not found for load balancer %s (%s). Assuming that cross zone load balancing is disabled.", _name, _arn)); } boolean crossZoneLoadBalancing = loadBalancerAttributes != null && loadBalancerAttributes.getCrossZoneLoadBalancing(); List<Listener> listeners = ImmutableList.of(); LoadBalancerListener lbListener = region.getLoadBalancerListeners().get(_arn); if (lbListener != null) { listeners = lbListener.getListeners(); } else { warnings.redFlag( String.format("Listeners not found for load balancer %s (%s).", _name, _arn)); } IpAccessList incomingFilter = computeListenerFilter(listeners); viIface.setIncomingFilter(incomingFilter); cfgNode.getIpAccessLists().put(incomingFilter.getName(), incomingFilter); installTransformations( viIface, getEnabledTargetZones(availabilityZone, crossZoneLoadBalancing, _availabilityZones), listeners, region, warnings); IpAccessList defaultFilter = computeNotForwardedFilter(networkInterface.get().getPrivateIpAddresses()); viIface.setPostTransformationIncomingFilter(defaultFilter); cfgNode.getIpAccessLists().put(defaultFilter.getName(), defaultFilter); createPublicIpsRefBook(Collections.singleton(networkInterface.get()), cfgNode); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(viIface), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } LoadBalancer(
      String arn,
      List<AvailabilityZone> availabilityZones,
      String dnsName,
      String name,
      Scheme scheme,
      Type type,
      String vpcId); }
LoadBalancer implements AwsVpcEntity, Serializable { @VisibleForTesting Configuration toConfigurationNode( AvailabilityZone availabilityZone, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(_dnsName, availabilityZone.getZoneName()), "aws", DeviceModel.AWS_ELB_NETWORK); cfgNode.setHumanName(_name); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(availabilityZone.getSubnetId()); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); getInstanceTargetStaticRoutes( awsConfiguration.getNlbsToInstanceTargets().get(_arn), availabilityZone.getSubnetId()) .forEach(staticRoute -> Utils.addStaticRoute(cfgNode, staticRoute)); Optional<NetworkInterface> networkInterface = findMyInterface(availabilityZone.getSubnetId(), _arn, region); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for load balancer %s (%s) in subnet %s.", _name, _arn, availabilityZone.getSubnetId())); return cfgNode; } Subnet subnet = region.getSubnets().get(availabilityZone.getSubnetId()); Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); LoadBalancerAttributes loadBalancerAttributes = region.getLoadBalancerAttributes().get(_arn); if (loadBalancerAttributes == null) { warnings.redFlag( String.format( "Attributes not found for load balancer %s (%s). Assuming that cross zone load balancing is disabled.", _name, _arn)); } boolean crossZoneLoadBalancing = loadBalancerAttributes != null && loadBalancerAttributes.getCrossZoneLoadBalancing(); List<Listener> listeners = ImmutableList.of(); LoadBalancerListener lbListener = region.getLoadBalancerListeners().get(_arn); if (lbListener != null) { listeners = lbListener.getListeners(); } else { warnings.redFlag( String.format("Listeners not found for load balancer %s (%s).", _name, _arn)); } IpAccessList incomingFilter = computeListenerFilter(listeners); viIface.setIncomingFilter(incomingFilter); cfgNode.getIpAccessLists().put(incomingFilter.getName(), incomingFilter); installTransformations( viIface, getEnabledTargetZones(availabilityZone, crossZoneLoadBalancing, _availabilityZones), listeners, region, warnings); IpAccessList defaultFilter = computeNotForwardedFilter(networkInterface.get().getPrivateIpAddresses()); viIface.setPostTransformationIncomingFilter(defaultFilter); cfgNode.getIpAccessLists().put(defaultFilter.getName(), defaultFilter); createPublicIpsRefBook(Collections.singleton(networkInterface.get()), cfgNode); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(viIface), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } 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 Configuration toConfigurationNode( AvailabilityZone availabilityZone, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(_dnsName, availabilityZone.getZoneName()), "aws", DeviceModel.AWS_ELB_NETWORK); cfgNode.setHumanName(_name); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(availabilityZone.getSubnetId()); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); getInstanceTargetStaticRoutes( awsConfiguration.getNlbsToInstanceTargets().get(_arn), availabilityZone.getSubnetId()) .forEach(staticRoute -> Utils.addStaticRoute(cfgNode, staticRoute)); Optional<NetworkInterface> networkInterface = findMyInterface(availabilityZone.getSubnetId(), _arn, region); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for load balancer %s (%s) in subnet %s.", _name, _arn, availabilityZone.getSubnetId())); return cfgNode; } Subnet subnet = region.getSubnets().get(availabilityZone.getSubnetId()); Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); LoadBalancerAttributes loadBalancerAttributes = region.getLoadBalancerAttributes().get(_arn); if (loadBalancerAttributes == null) { warnings.redFlag( String.format( "Attributes not found for load balancer %s (%s). Assuming that cross zone load balancing is disabled.", _name, _arn)); } boolean crossZoneLoadBalancing = loadBalancerAttributes != null && loadBalancerAttributes.getCrossZoneLoadBalancing(); List<Listener> listeners = ImmutableList.of(); LoadBalancerListener lbListener = region.getLoadBalancerListeners().get(_arn); if (lbListener != null) { listeners = lbListener.getListeners(); } else { warnings.redFlag( String.format("Listeners not found for load balancer %s (%s).", _name, _arn)); } IpAccessList incomingFilter = computeListenerFilter(listeners); viIface.setIncomingFilter(incomingFilter); cfgNode.getIpAccessLists().put(incomingFilter.getName(), incomingFilter); installTransformations( viIface, getEnabledTargetZones(availabilityZone, crossZoneLoadBalancing, _availabilityZones), listeners, region, warnings); IpAccessList defaultFilter = computeNotForwardedFilter(networkInterface.get().getPrivateIpAddresses()); viIface.setPostTransformationIncomingFilter(defaultFilter); cfgNode.getIpAccessLists().put(defaultFilter.getName(), defaultFilter); createPublicIpsRefBook(Collections.singleton(networkInterface.get()), cfgNode); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), INFRASTRUCTURE_LOCATION_INFO, interfaceLinkLocation(viIface), INFRASTRUCTURE_LOCATION_INFO)); return cfgNode; } 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();  }