@Test public void testToConfigurationNode() { Subnet subnet = getTestSubnet(Prefix.parse("1.1.1.0/24"), "subnet", "vpc"); ElasticsearchDomain esd = new ElasticsearchDomain( "arn", "es-domain", "vpc", "vpcEndpoint", 4, ImmutableList.of("sg"), ImmutableList.of(subnet.getId()), true); Configuration cfg = esd.toConfigurationNode( 0, subnet.getId(), new ConvertedConfiguration(), Region.builder("r1").setSubnets(ImmutableMap.of(subnet.getId(), subnet)).build(), new Warnings()); AwsFamily awsFamily = cfg.getVendorFamily().getAws(); assertThat(awsFamily.getSubnetId(), equalTo(esd.getSubnets().get(0))); assertThat(awsFamily.getVpcId(), equalTo("vpc")); assertThat(awsFamily.getRegion(), equalTo("r1")); assertThat(cfg.getHumanName(), equalTo(esd.getDomainName())); }
@Nullable @VisibleForTesting Configuration toConfigurationNode( int instanceNumber, String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet \"%s\" for Elasticsearch domain \"%s\" not found", subnetId, _domainName)); return null; } Configuration cfgNode = Utils.newAwsConfiguration( getNodeName(instanceNumber, _arn, _vpcEndpoint), "aws", DeviceModel.AWS_ELASTICSEARCH_DOMAIN); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.setHumanName(_domainName); String instancesIfaceName = subnetId; Ip instancesIfaceIp = subnet.getNextIp(); ConcreteInterfaceAddress instancesIfaceAddress = ConcreteInterfaceAddress.create(instancesIfaceIp, subnet.getCidrBlock().getPrefixLength()); Utils.newInterface(instancesIfaceName, cfgNode, instancesIfaceAddress, "To subnet " + subnetId); Utils.addLayer1Edge( awsConfiguration, cfgNode.getHostname(), instancesIfaceName, Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())); Ip defaultGatewayAddress = subnet.computeInstancesIfaceIp(); StaticRoute defaultRoute = StaticRoute.builder() .setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN) .setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .setNextHopIp(defaultGatewayAddress) .setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute); return cfgNode; }
ElasticsearchDomain implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Configuration toConfigurationNode( int instanceNumber, String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet \"%s\" for Elasticsearch domain \"%s\" not found", subnetId, _domainName)); return null; } Configuration cfgNode = Utils.newAwsConfiguration( getNodeName(instanceNumber, _arn, _vpcEndpoint), "aws", DeviceModel.AWS_ELASTICSEARCH_DOMAIN); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.setHumanName(_domainName); String instancesIfaceName = subnetId; Ip instancesIfaceIp = subnet.getNextIp(); ConcreteInterfaceAddress instancesIfaceAddress = ConcreteInterfaceAddress.create(instancesIfaceIp, subnet.getCidrBlock().getPrefixLength()); Utils.newInterface(instancesIfaceName, cfgNode, instancesIfaceAddress, "To subnet " + subnetId); Utils.addLayer1Edge( awsConfiguration, cfgNode.getHostname(), instancesIfaceName, Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())); Ip defaultGatewayAddress = subnet.computeInstancesIfaceIp(); StaticRoute defaultRoute = StaticRoute.builder() .setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN) .setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .setNextHopIp(defaultGatewayAddress) .setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute); return cfgNode; } }
ElasticsearchDomain implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Configuration toConfigurationNode( int instanceNumber, String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet \"%s\" for Elasticsearch domain \"%s\" not found", subnetId, _domainName)); return null; } Configuration cfgNode = Utils.newAwsConfiguration( getNodeName(instanceNumber, _arn, _vpcEndpoint), "aws", DeviceModel.AWS_ELASTICSEARCH_DOMAIN); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.setHumanName(_domainName); String instancesIfaceName = subnetId; Ip instancesIfaceIp = subnet.getNextIp(); ConcreteInterfaceAddress instancesIfaceAddress = ConcreteInterfaceAddress.create(instancesIfaceIp, subnet.getCidrBlock().getPrefixLength()); Utils.newInterface(instancesIfaceName, cfgNode, instancesIfaceAddress, "To subnet " + subnetId); Utils.addLayer1Edge( awsConfiguration, cfgNode.getHostname(), instancesIfaceName, Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())); Ip defaultGatewayAddress = subnet.computeInstancesIfaceIp(); StaticRoute defaultRoute = StaticRoute.builder() .setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN) .setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .setNextHopIp(defaultGatewayAddress) .setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute); return cfgNode; } ElasticsearchDomain(
      String arn,
      String domainName,
      @Nullable String vpcId,
      @Nullable String vpcEndpoint,
      int instanceCount,
      List<String> securityGroups,
      List<String> subnets,
      boolean available); }
ElasticsearchDomain implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Configuration toConfigurationNode( int instanceNumber, String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet \"%s\" for Elasticsearch domain \"%s\" not found", subnetId, _domainName)); return null; } Configuration cfgNode = Utils.newAwsConfiguration( getNodeName(instanceNumber, _arn, _vpcEndpoint), "aws", DeviceModel.AWS_ELASTICSEARCH_DOMAIN); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.setHumanName(_domainName); String instancesIfaceName = subnetId; Ip instancesIfaceIp = subnet.getNextIp(); ConcreteInterfaceAddress instancesIfaceAddress = ConcreteInterfaceAddress.create(instancesIfaceIp, subnet.getCidrBlock().getPrefixLength()); Utils.newInterface(instancesIfaceName, cfgNode, instancesIfaceAddress, "To subnet " + subnetId); Utils.addLayer1Edge( awsConfiguration, cfgNode.getHostname(), instancesIfaceName, Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())); Ip defaultGatewayAddress = subnet.computeInstancesIfaceIp(); StaticRoute defaultRoute = StaticRoute.builder() .setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN) .setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .setNextHopIp(defaultGatewayAddress) .setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute); return cfgNode; } ElasticsearchDomain(
      String arn,
      String domainName,
      @Nullable String vpcId,
      @Nullable String vpcEndpoint,
      int instanceCount,
      List<String> securityGroups,
      List<String> subnets,
      boolean available); boolean getAvailable(); @Nonnull String getDomainName(); @Override String getId(); int getInstanceCount(); @Nonnull List<String> getSecurityGroups(); @Nonnull List<String> getSubnets(); @Nullable String getVpcEndpoint(); @Nullable String getVpcId(); List<Configuration> toConfigurationNodes(
      ConvertedConfiguration awsConfiguration, Region region, Warnings warnings); @Override boolean equals(Object o); @Override int hashCode(); }
ElasticsearchDomain implements AwsVpcEntity, Serializable { @Nullable @VisibleForTesting Configuration toConfigurationNode( int instanceNumber, String subnetId, ConvertedConfiguration awsConfiguration, Region region, Warnings warnings) { Subnet subnet = region.getSubnets().get(subnetId); if (subnet == null) { warnings.redFlag( String.format( "Subnet \"%s\" for Elasticsearch domain \"%s\" not found", subnetId, _domainName)); return null; } Configuration cfgNode = Utils.newAwsConfiguration( getNodeName(instanceNumber, _arn, _vpcEndpoint), "aws", DeviceModel.AWS_ELASTICSEARCH_DOMAIN); cfgNode.getVendorFamily().getAws().setVpcId(_vpcId); cfgNode.getVendorFamily().getAws().setRegion(region.getName()); cfgNode.getVendorFamily().getAws().setSubnetId(subnetId); cfgNode.setHumanName(_domainName); String instancesIfaceName = subnetId; Ip instancesIfaceIp = subnet.getNextIp(); ConcreteInterfaceAddress instancesIfaceAddress = ConcreteInterfaceAddress.create(instancesIfaceIp, subnet.getCidrBlock().getPrefixLength()); Utils.newInterface(instancesIfaceName, cfgNode, instancesIfaceAddress, "To subnet " + subnetId); Utils.addLayer1Edge( awsConfiguration, cfgNode.getHostname(), instancesIfaceName, Subnet.nodeName(subnet.getId()), Subnet.instancesInterfaceName(subnet.getId())); Ip defaultGatewayAddress = subnet.computeInstancesIfaceIp(); StaticRoute defaultRoute = StaticRoute.builder() .setAdministrativeCost(Route.DEFAULT_STATIC_ROUTE_ADMIN) .setMetric(Route.DEFAULT_STATIC_ROUTE_COST) .setNextHopIp(defaultGatewayAddress) .setNetwork(Prefix.ZERO) .build(); cfgNode.getDefaultVrf().getStaticRoutes().add(defaultRoute); return cfgNode; } ElasticsearchDomain(
      String arn,
      String domainName,
      @Nullable String vpcId,
      @Nullable String vpcEndpoint,
      int instanceCount,
      List<String> securityGroups,
      List<String> subnets,
      boolean available); boolean getAvailable(); @Nonnull String getDomainName(); @Override String getId(); int getInstanceCount(); @Nonnull List<String> getSecurityGroups(); @Nonnull List<String> getSubnets(); @Nullable String getVpcEndpoint(); @Nullable String getVpcId(); List<Configuration> toConfigurationNodes(
      ConvertedConfiguration awsConfiguration, Region region, Warnings warnings); @Override boolean equals(Object o); @Override int hashCode();  }