use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.
the class SubnetChooserService method chooseSubnets.
public List<CloudSubnet> chooseSubnets(List<CloudSubnet> subnetMetas, CloudPlatform cloudPlatform, DBStack dbStack) {
NetworkConnector networkConnector = cloudPlatformConnectors.get(new CloudPlatformVariant(dbStack.getCloudPlatform(), dbStack.getPlatformVariant())).networkConnector();
SubnetSelectionParameters build = SubnetSelectionParameters.builder().withHa(dbStack.isHa()).withPreferPrivateIfExist().build();
SubnetSelectionResult subnetSelectionResult = networkConnector.chooseSubnets(subnetMetas, build);
if (subnetSelectionResult.hasError()) {
throw new BadRequestException(subnetSelectionResult.getErrorMessage());
}
return subnetSelectionResult.getResult();
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.
the class SubnetIdProvider method subnets.
public ProvidedSubnetIds subnets(NetworkDto network, Tunnel tunnel, CloudPlatform cloudPlatform, boolean multiAz) {
LOGGER.debug("Choosing subnets, network: {}, platform: {}, tunnel: {}", network, cloudPlatform, tunnel);
if (network == null || network.getSubnetIds() == null || network.getSubnetIds().isEmpty() || network.getCbSubnets() == null || network.getCbSubnets().isEmpty()) {
LOGGER.debug("Check failed, returning null");
return null;
}
NetworkConnector networkConnector = cloudPlatformConnectors.get(new CloudPlatformVariant(cloudPlatform.name(), cloudPlatform.name())).networkConnector();
if (networkConnector == null) {
LOGGER.warn("Network connector is null for '{}' cloud platform, returning null", cloudPlatform.name());
return null;
}
SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters.builder().withHa(multiAz).withTunnel(tunnel).build();
SubnetSelectionResult subnetSelectionResult = networkConnector.chooseSubnets(network.getCbSubnetValues(), subnetSelectionParameters);
CloudSubnet selectedSubnet = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().get(0) : fallback(network);
Set<CloudSubnet> selectedSubnets = subnetSelectionResult.hasResult() ? subnetSelectionResult.getResult().stream().collect(Collectors.toSet()) : fallbacks(network);
return new ProvidedSubnetIds(selectedSubnet.getId(), selectedSubnets.stream().map(e -> e.getId()).collect(Collectors.toSet()));
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testSubnetSelectionWhenHaRequiredAnd2DifferentAZDeclaredShouldReturn2DifferentAz.
@Test
public void testSubnetSelectionWhenHaRequiredAnd2DifferentAZDeclaredShouldReturn2DifferentAz() {
List<CloudSubnet> cloudSubnets = Lists.newArrayList(getSubnet("a1", 1), getSubnet("a1", 2), getSubnet("a2", 3), getSubnet("a2", 4));
prepareMock(cloudSubnets);
SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters.builder().withPreferPrivateIfExist().withTunnel(Tunnel.CCM).withHa(true).build();
SubnetSelectionResult result = underTest.chooseSubnets(cloudSubnets, subnetSelectionParameters);
Assert.assertTrue(result.getResult().size() == 2);
Assert.assertTrue(result.getResult().size() == collectUniqueAzs(result).size());
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testSubnetSelectionWhenNonHaRequiredAnd2DifferentAZDeclaredShouldReturn1Az.
@Test
public void testSubnetSelectionWhenNonHaRequiredAnd2DifferentAZDeclaredShouldReturn1Az() {
List<CloudSubnet> cloudSubnets = Lists.newArrayList(getSubnet("a1", 1), getSubnet("a1", 2), getSubnet("a2", 3), getSubnet("a2", 4));
prepareMock(cloudSubnets);
SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters.builder().withPreferPrivateIfExist().withTunnel(Tunnel.CCM).withHa(false).build();
SubnetSelectionResult result = underTest.chooseSubnets(cloudSubnets, subnetSelectionParameters);
Assert.assertTrue(result.getResult().size() == 1);
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method testSubnetSelectionWhenNonHaRequiredAnd4DifferentAZDeclaredShouldReturn1Az.
@Test
public void testSubnetSelectionWhenNonHaRequiredAnd4DifferentAZDeclaredShouldReturn1Az() {
List<CloudSubnet> cloudSubnets = Lists.newArrayList(getSubnet("a1", 1), getSubnet("a2", 2), getSubnet("a3", 3), getSubnet("a4", 4));
prepareMock(cloudSubnets);
SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters.builder().withPreferPrivateIfExist().withTunnel(Tunnel.CCM).withHa(false).build();
SubnetSelectionResult result = underTest.chooseSubnets(cloudSubnets, subnetSelectionParameters);
Assert.assertTrue(result.getResult().size() == 1);
}
Aggregations