@Test public void testToConfigurationNode() { Subnet subnet = getTestSubnet(Prefix.parse("1.1.1.0/24"), "subnet", "vpc"); NetworkInterface networkInterface = new NetworkInterface( "networkInterface", subnet.getId(), "vpc", ImmutableList.of(), ImmutableList.of(new PrivateIpAddress(true, Ip.parse("1.1.1.1"), null)), "desc", null, ImmutableMap.of()); VpcEndpointInterface vpcEndpointInterface = new VpcEndpointInterface( "endpoint", "service", "vpc", ImmutableList.of(networkInterface.getId()), ImmutableList.of(subnet.getId()), ImmutableMap.of(TAG_NAME, "human")); Region region = Region.builder("r1") .setNetworkInterfaces(ImmutableMap.of(networkInterface.getId(), networkInterface)) .setSubnets(ImmutableMap.of(subnet.getId(), subnet)) .build(); ConvertedConfiguration awsConfiguration = new ConvertedConfiguration(); Warnings warnings = new Warnings(true, true, true); Configuration cfg = vpcEndpointInterface.toConfigurationNode( subnet.getId(), awsConfiguration, region, warnings); assertTrue(warnings.isEmpty()); Interface viIface = getOnlyElement(cfg.getAllInterfaces().values()); assertThat( cfg, allOf( hasConfigurationFormat(ConfigurationFormat.AWS), hasHostname(getNodeId(subnet.getId(), vpcEndpointInterface.getId())), hasDeviceModel(DeviceModel.AWS_VPC_ENDPOINT_INTERFACE))); assertThat(cfg.getHumanName(), equalTo("human")); assertThat(cfg.getVendorFamily().getAws().getRegion(), equalTo(region.getName())); assertThat(cfg.getVendorFamily().getAws().getVpcId(), equalTo("vpc")); assertThat(cfg.getVendorFamily().getAws().getSubnetId(), equalTo(subnet.getId())); assertThat(viIface.getDescription(), equalTo("desc")); assertThat(viIface.getPrimaryNetwork(), equalTo(Prefix.create(Ip.parse("1.1.1.1"), 24))); assertThat( awsConfiguration.getLayer1Edges(), equalTo( ImmutableSet.of( new Layer1Edge( cfg.getHostname(), viIface.getName(), Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())), new Layer1Edge( Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId()), cfg.getHostname(), viIface.getName())))); Map<Location, LocationInfo> locationInfo = cfg.getLocationInfo(); assertEquals( instanceInterfaceLocationInfo(viIface), locationInfo.get(interfaceLocation(viIface))); assertEquals( INSTANCE_INTERFACE_LINK_LOCATION_INFO, locationInfo.get(interfaceLinkLocation(viIface))); }
@VisibleForTesting Configuration toConfigurationNode( String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(subnetId, _id), "aws", DeviceModel.AWS_VPC_ENDPOINT_INTERFACE); cfgNode.setHumanName(_tags.get(TAG_NAME)); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet with id %s, associated with VPC endpoint %s, not found", subnetId, _id)); return cfgNode; } Optional<NetworkInterface> networkInterface = region.getNetworkInterfaces().values().stream() .filter( iface -> _networkInterfaceIds.contains(iface.getId()) && iface.getSubnetId().equals(subnetId)) .findFirst(); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for VPC endpoint %s in subnet %s", _id, subnetId)); return cfgNode; } Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), instanceInterfaceLocationInfo(viIface), interfaceLinkLocation(viIface), INSTANCE_INTERFACE_LINK_LOCATION_INFO)); return cfgNode; }
VpcEndpointInterface extends VpcEndpoint { @VisibleForTesting Configuration toConfigurationNode( String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(subnetId, _id), "aws", DeviceModel.AWS_VPC_ENDPOINT_INTERFACE); cfgNode.setHumanName(_tags.get(TAG_NAME)); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet with id %s, associated with VPC endpoint %s, not found", subnetId, _id)); return cfgNode; } Optional<NetworkInterface> networkInterface = region.getNetworkInterfaces().values().stream() .filter( iface -> _networkInterfaceIds.contains(iface.getId()) && iface.getSubnetId().equals(subnetId)) .findFirst(); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for VPC endpoint %s in subnet %s", _id, subnetId)); return cfgNode; } Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), instanceInterfaceLocationInfo(viIface), interfaceLinkLocation(viIface), INSTANCE_INTERFACE_LINK_LOCATION_INFO)); return cfgNode; } }
VpcEndpointInterface extends VpcEndpoint { @VisibleForTesting Configuration toConfigurationNode( String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(subnetId, _id), "aws", DeviceModel.AWS_VPC_ENDPOINT_INTERFACE); cfgNode.setHumanName(_tags.get(TAG_NAME)); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet with id %s, associated with VPC endpoint %s, not found", subnetId, _id)); return cfgNode; } Optional<NetworkInterface> networkInterface = region.getNetworkInterfaces().values().stream() .filter( iface -> _networkInterfaceIds.contains(iface.getId()) && iface.getSubnetId().equals(subnetId)) .findFirst(); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for VPC endpoint %s in subnet %s", _id, subnetId)); return cfgNode; } Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), instanceInterfaceLocationInfo(viIface), interfaceLinkLocation(viIface), INSTANCE_INTERFACE_LINK_LOCATION_INFO)); return cfgNode; } VpcEndpointInterface(
      String id,
      String serviceName,
      String vpcId,
      List<String> networkInterfaceIds,
      List<String> subnetIds,
      Map<String, String> tags); }
VpcEndpointInterface extends VpcEndpoint { @VisibleForTesting Configuration toConfigurationNode( String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(subnetId, _id), "aws", DeviceModel.AWS_VPC_ENDPOINT_INTERFACE); cfgNode.setHumanName(_tags.get(TAG_NAME)); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet with id %s, associated with VPC endpoint %s, not found", subnetId, _id)); return cfgNode; } Optional<NetworkInterface> networkInterface = region.getNetworkInterfaces().values().stream() .filter( iface -> _networkInterfaceIds.contains(iface.getId()) && iface.getSubnetId().equals(subnetId)) .findFirst(); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for VPC endpoint %s in subnet %s", _id, subnetId)); return cfgNode; } Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), instanceInterfaceLocationInfo(viIface), interfaceLinkLocation(viIface), INSTANCE_INTERFACE_LINK_LOCATION_INFO)); return cfgNode; } VpcEndpointInterface(
      String id,
      String serviceName,
      String vpcId,
      List<String> networkInterfaceIds,
      List<String> subnetIds,
      Map<String, String> tags); @Nonnull List<String> getNetworkInterfaceIds(); @Nonnull List<String> getSubnetIds(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); }
VpcEndpointInterface extends VpcEndpoint { @VisibleForTesting Configuration toConfigurationNode( String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( getNodeId(subnetId, _id), "aws", DeviceModel.AWS_VPC_ENDPOINT_INTERFACE); cfgNode.setHumanName(_tags.get(TAG_NAME)); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet with id %s, associated with VPC endpoint %s, not found", subnetId, _id)); return cfgNode; } Optional<NetworkInterface> networkInterface = region.getNetworkInterfaces().values().stream() .filter( iface -> _networkInterfaceIds.contains(iface.getId()) && iface.getSubnetId().equals(subnetId)) .findFirst(); if (!networkInterface.isPresent()) { warnings.redFlag( String.format( "Network interface not found for VPC endpoint %s in subnet %s", _id, subnetId)); return cfgNode; } Interface viIface = addNodeToSubnet(cfgNode, networkInterface.get(), subnet, awsConfiguration, warnings); cfgNode.setLocationInfo( ImmutableMap.of( interfaceLocation(viIface), instanceInterfaceLocationInfo(viIface), interfaceLinkLocation(viIface), INSTANCE_INTERFACE_LINK_LOCATION_INFO)); return cfgNode; } VpcEndpointInterface(
      String id,
      String serviceName,
      String vpcId,
      List<String> networkInterfaceIds,
      List<String> subnetIds,
      Map<String, String> tags); @Nonnull List<String> getNetworkInterfaceIds(); @Nonnull List<String> getSubnetIds(); @Override boolean equals(@Nullable Object o); @Override int hashCode();  }