@Test public void testToConfigurationNode() { String vpcId = "vpc"; Subnet subnet = new Subnet( Prefix.parse("10.10.10.10/24"), "ownerId", "subnetArn", "subnet", vpcId, "zone", ImmutableMap.of()); NetworkInterface networkInterface = new NetworkInterface( "interface", subnet.getId(), vpcId, ImmutableList.of(), ImmutableList.of( new PrivateIpAddress(true, Ip.parse("10.10.10.10"), Ip.parse("3.3.3.3"))), "desc", null, ImmutableMap.of()); Instance instance = Instance.builder() .setInstanceId("instance") .setNetworkInterfaces(ImmutableList.of(networkInterface.getId())) .setTags(ImmutableMap.of("MADEUPTAG", "noval", TAG_NAME, "UserVisibleName!")) .build(); Region region = Region.builder("test") .setInstances(ImmutableMap.of(instance.getId(), instance)) .setNetworkInterfaces(ImmutableMap.of(networkInterface.getId(), networkInterface)) .setSubnets(ImmutableMap.of(subnet.getId(), subnet)) .build(); Warnings warnings = new Warnings(); ConvertedConfiguration awsConfiguration = new ConvertedConfiguration(); Configuration configuration = instance.toConfigurationNode(awsConfiguration, region, warnings); Interface configInterface = getOnlyElement(configuration.getAllInterfaces().values()); assertTrue(warnings.isEmpty()); assertThat( configuration, allOf( hasConfigurationFormat(ConfigurationFormat.AWS), hasHostname(instance.getId()), hasDeviceModel(DeviceModel.AWS_EC2_INSTANCE), hasDeviceType(DeviceType.HOST))); assertThat(configuration.getHumanName(), equalTo("UserVisibleName!")); assertThat(configInterface.getDescription(), equalTo("desc")); assertThat( configInterface.getPrimaryNetwork(), equalTo(Prefix.create(Ip.parse("10.10.10.10"), 24))); assertThat( awsConfiguration.getLayer1Edges(), equalTo( ImmutableSet.of( new Layer1Edge( instance.getId(), configInterface.getName(), Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())), new Layer1Edge( Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId()), instance.getId(), configInterface.getName())))); Map<Location, LocationInfo> locationInfo = configuration.getLocationInfo(); assertEquals( instanceInterfaceLocationInfo(configInterface), locationInfo.get(interfaceLocation(configInterface))); assertEquals( INSTANCE_INTERFACE_LINK_LOCATION_INFO, locationInfo.get(interfaceLinkLocation(configInterface))); assertTrue( configuration .getGeneratedReferenceBooks() .containsKey( GeneratedRefBookUtils.getName(configuration.getHostname(), BookType.PublicIps))); }
Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( instanceHostname(_instanceId), "aws", _tags, DeviceModel.AWS_EC2_INSTANCE); cfgNode.setDeviceType(DeviceType.HOST); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); for (String interfaceId : _networkInterfaces) { NetworkInterface netInterface = region.getNetworkInterfaces().get(interfaceId); if (netInterface == null) { warnings.redFlag( String.format( "Network interface \"%s\" for instance \"%s\" not found", interfaceId, _instanceId)); continue; } Subnet subnet = region.getSubnets().get(netInterface.getSubnetId()); addNodeToSubnet(cfgNode, netInterface, subnet, awsConfiguration, warnings); } addPublicIpsRefBook(cfgNode, region); cfgNode.setLocationInfo( cfgNode.getAllInterfaces().values().stream() .flatMap( iface -> Stream.of( immutableEntry( interfaceLocation(iface), instanceInterfaceLocationInfo(iface)), immutableEntry( interfaceLinkLocation(iface), INSTANCE_INTERFACE_LINK_LOCATION_INFO))) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue))); return cfgNode; }
Instance implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( instanceHostname(_instanceId), "aws", _tags, DeviceModel.AWS_EC2_INSTANCE); cfgNode.setDeviceType(DeviceType.HOST); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); for (String interfaceId : _networkInterfaces) { NetworkInterface netInterface = region.getNetworkInterfaces().get(interfaceId); if (netInterface == null) { warnings.redFlag( String.format( "Network interface \"%s\" for instance \"%s\" not found", interfaceId, _instanceId)); continue; } Subnet subnet = region.getSubnets().get(netInterface.getSubnetId()); addNodeToSubnet(cfgNode, netInterface, subnet, awsConfiguration, warnings); } addPublicIpsRefBook(cfgNode, region); cfgNode.setLocationInfo( cfgNode.getAllInterfaces().values().stream() .flatMap( iface -> Stream.of( immutableEntry( interfaceLocation(iface), instanceInterfaceLocationInfo(iface)), immutableEntry( interfaceLinkLocation(iface), INSTANCE_INTERFACE_LINK_LOCATION_INFO))) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue))); return cfgNode; } }
Instance implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( instanceHostname(_instanceId), "aws", _tags, DeviceModel.AWS_EC2_INSTANCE); cfgNode.setDeviceType(DeviceType.HOST); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); for (String interfaceId : _networkInterfaces) { NetworkInterface netInterface = region.getNetworkInterfaces().get(interfaceId); if (netInterface == null) { warnings.redFlag( String.format( "Network interface \"%s\" for instance \"%s\" not found", interfaceId, _instanceId)); continue; } Subnet subnet = region.getSubnets().get(netInterface.getSubnetId()); addNodeToSubnet(cfgNode, netInterface, subnet, awsConfiguration, warnings); } addPublicIpsRefBook(cfgNode, region); cfgNode.setLocationInfo( cfgNode.getAllInterfaces().values().stream() .flatMap( iface -> Stream.of( immutableEntry( interfaceLocation(iface), instanceInterfaceLocationInfo(iface)), immutableEntry( interfaceLinkLocation(iface), INSTANCE_INTERFACE_LINK_LOCATION_INFO))) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue))); return cfgNode; } Instance(
      String instanceId,
      @Nullable String vpcId,
      @Nullable String subnetId,
      List<String> securityGroups,
      List<String> networkInterfaces,
      @Nullable Ip primaryPrivateIpAddress,
      Map<String, String> tags,
      Status status); }
Instance implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( instanceHostname(_instanceId), "aws", _tags, DeviceModel.AWS_EC2_INSTANCE); cfgNode.setDeviceType(DeviceType.HOST); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); for (String interfaceId : _networkInterfaces) { NetworkInterface netInterface = region.getNetworkInterfaces().get(interfaceId); if (netInterface == null) { warnings.redFlag( String.format( "Network interface \"%s\" for instance \"%s\" not found", interfaceId, _instanceId)); continue; } Subnet subnet = region.getSubnets().get(netInterface.getSubnetId()); addNodeToSubnet(cfgNode, netInterface, subnet, awsConfiguration, warnings); } addPublicIpsRefBook(cfgNode, region); cfgNode.setLocationInfo( cfgNode.getAllInterfaces().values().stream() .flatMap( iface -> Stream.of( immutableEntry( interfaceLocation(iface), instanceInterfaceLocationInfo(iface)), immutableEntry( interfaceLinkLocation(iface), INSTANCE_INTERFACE_LINK_LOCATION_INFO))) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue))); return cfgNode; } Instance(
      String instanceId,
      @Nullable String vpcId,
      @Nullable String subnetId,
      List<String> securityGroups,
      List<String> networkInterfaces,
      @Nullable Ip primaryPrivateIpAddress,
      Map<String, String> tags,
      Status status); @Nonnull String getHumanName(); @Override String getId(); @Nonnull List<String> getNetworkInterfaces(); @Nullable Ip getPrimaryPrivateIpAddress(); @Nonnull List<String> getSecurityGroups(); @Nonnull Status getStatus(); @Nullable String getSubnetId(); @Nonnull Map<String, String> getTags(); @Nullable String getVpcId(); static String instanceHostname(String instanceId); @Override boolean equals(Object o); @Override int hashCode(); }
Instance implements AwsVpcEntity, Serializable { Configuration toConfigurationNode( ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Configuration cfgNode = Utils.newAwsConfiguration( instanceHostname(_instanceId), "aws", _tags, DeviceModel.AWS_EC2_INSTANCE); cfgNode.setDeviceType(DeviceType.HOST); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setSubnetId(_subnetId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); for (String interfaceId : _networkInterfaces) { NetworkInterface netInterface = region.getNetworkInterfaces().get(interfaceId); if (netInterface == null) { warnings.redFlag( String.format( "Network interface \"%s\" for instance \"%s\" not found", interfaceId, _instanceId)); continue; } Subnet subnet = region.getSubnets().get(netInterface.getSubnetId()); addNodeToSubnet(cfgNode, netInterface, subnet, awsConfiguration, warnings); } addPublicIpsRefBook(cfgNode, region); cfgNode.setLocationInfo( cfgNode.getAllInterfaces().values().stream() .flatMap( iface -> Stream.of( immutableEntry( interfaceLocation(iface), instanceInterfaceLocationInfo(iface)), immutableEntry( interfaceLinkLocation(iface), INSTANCE_INTERFACE_LINK_LOCATION_INFO))) .collect(ImmutableMap.toImmutableMap(Entry::getKey, Entry::getValue))); return cfgNode; } Instance(
      String instanceId,
      @Nullable String vpcId,
      @Nullable String subnetId,
      List<String> securityGroups,
      List<String> networkInterfaces,
      @Nullable Ip primaryPrivateIpAddress,
      Map<String, String> tags,
      Status status); @Nonnull String getHumanName(); @Override String getId(); @Nonnull List<String> getNetworkInterfaces(); @Nullable Ip getPrimaryPrivateIpAddress(); @Nonnull List<String> getSecurityGroups(); @Nonnull Status getStatus(); @Nullable String getSubnetId(); @Nonnull Map<String, String> getTags(); @Nullable String getVpcId(); static String instanceHostname(String instanceId); @Override boolean equals(Object o); @Override int hashCode();  }