Search in sources :

Example 1 with SubnetSelectionParameters

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();
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)

Example 2 with SubnetSelectionParameters

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()));
}
Also used : ProvidedSubnetIds(com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds) SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 3 with SubnetSelectionParameters

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());
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 4 with SubnetSelectionParameters

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);
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 5 with SubnetSelectionParameters

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);
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Aggregations

SubnetSelectionParameters (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters)12 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)11 Test (org.junit.Test)9 SubnetSelectionResult (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)8 NetworkConnector (com.sequenceiq.cloudbreak.cloud.NetworkConnector)6 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Tunnel (com.sequenceiq.common.api.type.Tunnel)1 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)1 Test (org.junit.jupiter.api.Test)1