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);
}
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));
}
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();
}
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()));
}
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;
}
Aggregations