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\"]"));
}
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;
}
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);
}
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;
}
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));
}
Aggregations