use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.
the class AzureSubnetSelectorServiceTest method testselectWhenNotDatabaseOneSubnetThenReturnsIt.
@Test
public void testselectWhenNotDatabaseOneSubnetThenReturnsIt() {
List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().build();
SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().build());
assertEquals(1, subnetSelectionResult.getResult().size());
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.
the class SubnetFilterStrategyMultiplePreferPrivate method filter.
@Override
public SubnetSelectionResult filter(Collection<CloudSubnet> subnets, int azCount) {
List<CloudSubnet> result = subnetSelectorService.collectPrivateSubnets(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 private subnets which {}, falling back to private subnets: {}", uniqueAzs.size(), subnets);
List<CloudSubnet> publicSubnets = subnetSelectorService.collectPublicSubnets(subnets);
for (CloudSubnet publicSubnet : publicSubnets) {
if (!uniqueAzs.contains(publicSubnet.getAvailabilityZone())) {
result.add(publicSubnet);
uniqueAzs.add(publicSubnet.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 AwsNetworkConnectorTest method testSubnetSelectionWhenHaRequiredAnd1DifferentAZDeclaredShouldReturnError.
@Test
public void testSubnetSelectionWhenHaRequiredAnd1DifferentAZDeclaredShouldReturnError() {
List<CloudSubnet> cloudSubnets = Lists.newArrayList(getSubnet("a1", 1), getSubnet("a1", 2), getSubnet("a1", 3), getSubnet("a1", 4));
prepareMock(cloudSubnets);
SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters.builder().withPreferPrivateIfExist().withTunnel(Tunnel.CCM).withHa(true).build();
SubnetSelectionResult result = underTest.chooseSubnets(cloudSubnets, subnetSelectionParameters);
Assert.assertTrue(result.hasError());
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.
the class AwsNetworkConnectorTest method prepareMock.
public void prepareMock(List<CloudSubnet> cloudSubnets) {
Map<SubnetFilterStrategyType, SubnetFilterStrategy> subnetFilterStrategyMap = new HashMap<>();
subnetFilterStrategyMap.put(SubnetFilterStrategyType.MULTIPLE_PREFER_PRIVATE, subnetFilterStrategy);
subnetFilterStrategyMap.put(SubnetFilterStrategyType.MULTIPLE_PREFER_PUBLIC, subnetFilterStrategy);
when(subnetFilterStrategy.filter(any(), anyInt())).thenReturn(new SubnetSelectionResult(cloudSubnets));
ReflectionTestUtils.setField(underTest, "subnetFilterStrategyMap", subnetFilterStrategyMap);
}
use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult in project cloudbreak by hortonworks.
the class SubnetChooserServiceTest method setupConnector.
private NetworkConnector setupConnector(String errorMessage) {
CloudConnector cloudConnector = mock(CloudConnector.class);
NetworkConnector networkConnector = mock(NetworkConnector.class);
SubnetSelectionResult subnetSelectionResult = StringUtils.isEmpty(errorMessage) ? new SubnetSelectionResult(List.of()) : new SubnetSelectionResult(errorMessage);
when(networkConnector.chooseSubnets(any(), any())).thenReturn(subnetSelectionResult);
when(cloudConnector.networkConnector()).thenReturn(networkConnector);
when(cloudPlatformConnectors.get(any())).thenReturn(cloudConnector);
return networkConnector;
}
Aggregations