Search in sources :

Example 1 with SubnetSelectionResult

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.

the class SubnetFilterStrategyMultiplePreferPublic method filter.

@Override
public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) {
    List<CloudSubnet> result = subnetSelectorService.collectPublicSubnets(subnets);
    Set<String> uniqueAzs = result.stream().map(e -> e.getAvailabilityZone()).collect(Collectors.toSet());
    if (uniqueAzs.size() < azCount) {
        LOGGER.info("There is not enough different AZ in the public subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets);
        List<CloudSubnet> privateSubnets = subnetSelectorService.collectPrivateSubnets(subnets);
        for (CloudSubnet privateSubnet : privateSubnets) {
            if (!uniqueAzs.contains(privateSubnet.getAvailabilityZone())) {
                result.add(privateSubnet);
                uniqueAzs.add(privateSubnet.getAvailabilityZone());
                if (uniqueAzs.size() >= azCount) {
                    break;
                }
            }
        }
    }
    return new SubnetSelectionResult(result);
}
Also used : Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 2 with SubnetSelectionResult

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.

the class GcpSubnetSelectorService method select.

public SubnetSelectionResult select(Collection<CloudSubnet> subnetMetas, SubnetSelectionParameters subnetSelectionParameters) {
    Optional<String> errorMessage = quickValidate(subnetMetas, subnetSelectionParameters);
    if (errorMessage.isPresent()) {
        LOGGER.debug("{}", errorMessage.get());
        return new SubnetSelectionResult(errorMessage.get());
    }
    // GCP VPCs are global and different subnets can be in different geographies. So for safety just choosing the first subnet.
    CloudSubnet first = subnetMetas.stream().findFirst().get();
    LOGGER.debug("GCP selected subnet: '{}'", first);
    return new SubnetSelectionResult(Collections.singletonList(first));
}
Also used : SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 3 with SubnetSelectionResult

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult 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 4 with SubnetSelectionResult

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult 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 5 with SubnetSelectionResult

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.

the class SubnetIdProviderTest method setupConnector.

private NetworkConnector setupConnector(String errorMessage, List<CloudSubnet> selectedSubnets) {
    CloudConnector cloudConnector = mock(CloudConnector.class);
    NetworkConnector networkConnector = mock(NetworkConnector.class);
    SubnetSelectionResult subnetSelectionResult = StringUtils.isEmpty(errorMessage) ? new SubnetSelectionResult(selectedSubnets) : new SubnetSelectionResult(errorMessage);
    when(networkConnector.chooseSubnets(any(), any())).thenReturn(subnetSelectionResult);
    when(cloudConnector.networkConnector()).thenReturn(networkConnector);
    when(cloudPlatformConnectors.get(any())).thenReturn(cloudConnector);
    return networkConnector;
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)

Aggregations

SubnetSelectionResult (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)35 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)26 Test (org.junit.Test)22 SubnetSelectionParameters (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters)9 NetworkConnector (com.sequenceiq.cloudbreak.cloud.NetworkConnector)4 Test (org.junit.jupiter.api.Test)4 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 SubnetFilterStrategy (com.sequenceiq.cloudbreak.cloud.aws.common.subnetselector.SubnetFilterStrategy)1 SubnetFilterStrategyType (com.sequenceiq.cloudbreak.cloud.aws.common.subnetselector.SubnetFilterStrategyType)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)1