Search in sources :

Example 1 with CloudSubnet

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

the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure.

@Test
void testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure() {
    int numberOfSubnets = 2;
    AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, numberOfSubnets);
    EnvironmentDto environmentDto = new EnvironmentDto();
    EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
    when(cloudNetworkService.retrieveSubnetMetadata(environmentDto, networkDto)).thenReturn(Map.of(networkDto.getSubnetIds().stream().findFirst().get(), new CloudSubnet()));
    ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
    underTest.validateDuringFlow(environmentValidationDto, networkDto, resultBuilder);
    NetworkTestUtils.checkErrorsPresent(resultBuilder, List.of("If networkId (aNetworkId) and resourceGroupName (aResourceGroupId) are specified then" + " subnet ids must be specified and should exist on azure as well. Given subnetids: [\"key1\", \"key0\"], existing ones: [\"key1\"]"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 2 with CloudSubnet

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

the class LoadBalancerConfigService method isSelectedSubnetAvailableAndRequestedType.

private boolean isSelectedSubnetAvailableAndRequestedType(Network network, EnvironmentNetworkResponse envNetwork, boolean privateType) {
    if (network != null && envNetwork != null) {
        String subnetId = getSubnetId(network);
        if (StringUtils.isNotEmpty(subnetId)) {
            LOGGER.debug("Found selected stack subnet {}", subnetId);
            Optional<CloudSubnet> selectedSubnet = subnetSelector.findSubnetById(envNetwork.getSubnetMetas(), subnetId);
            // "noPublicIp" is an option for Azure and GCP that is used to set the network to private or public, it is not
            // set on AWS networks. So, we check for it first, then fall back to AWS.
            NetworkV4Base networkV4Base = getNetworkV4Base(network);
            if (networkV4Base.isNoPublicIp().isPresent()) {
                // azure and gcp specific
                Boolean noPublicIp = networkV4Base.isNoPublicIp().get();
                LOGGER.debug("Subnet {} type {}", subnetId, noPublicIp ? "private" : "public");
                return privateType == noPublicIp;
            } else if (selectedSubnet.isPresent()) {
                // aws specific
                LOGGER.debug("Subnet {} type {}", subnetId, selectedSubnet.get().isPrivateSubnet() ? "private" : "public");
                return privateType == selectedSubnet.get().isPrivateSubnet();
            }
        }
    }
    LOGGER.debug("Subnet for load balancer creation was not found.");
    return false;
}
Also used : NetworkV4Base(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.NetworkV4Base) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 3 with CloudSubnet

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

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

the class SubnetSelectorService method collectPublicSubnets.

List<CloudSubnet> collectPublicSubnets(Collection<CloudSubnet> subnetMetas) {
    List<CloudSubnet> result = new ArrayList<>();
    for (CloudSubnet subnetMeta : subnetMetas) {
        if (isUsablePublicSubnet(subnetMeta)) {
            result.add(subnetMeta);
        }
    }
    LOGGER.debug("Public subnets for selections: {}", result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 5 with CloudSubnet

use of com.sequenceiq.cloudbreak.cloud.model.CloudSubnet 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)

Aggregations

CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)161 Test (org.junit.Test)61 Test (org.junit.jupiter.api.Test)55 SubnetTest (com.sequenceiq.cloudbreak.core.network.SubnetTest)45 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)38 EnvironmentNetworkResponse (com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse)30 StackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.StackV4Request)29 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)28 SubnetSelectionResult (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)26 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)24 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)20 Set (java.util.Set)20 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)17 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)14 HashMap (java.util.HashMap)14 Map (java.util.Map)12 SubnetSelectionParameters (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters)11 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)11 Environment (com.sequenceiq.environment.environment.domain.Environment)10 LinkedHashMap (java.util.LinkedHashMap)10