use of com.sequenceiq.cloudbreak.cloud.NetworkConnector 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.NetworkConnector 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;
}
use of com.sequenceiq.cloudbreak.cloud.NetworkConnector in project cloudbreak by hortonworks.
the class SubnetIdProviderTest method testProvideThenNetworkSelectorCalled.
@Test
void testProvideThenNetworkSelectorCalled() {
NetworkDto networkDto = NetworkDto.builder().withCbSubnets(Map.of("AZ-a", new CloudSubnet())).withSubnetMetas(Map.of("AZ-a", new CloudSubnet())).build();
NetworkConnector networkConnector = setupConnectorWithSelectionResult(List.of(new CloudSubnet("id", "name")));
Tunnel tunnel = Tunnel.DIRECT;
ProvidedSubnetIds providedSubnetIds = underTest.subnets(networkDto, tunnel, CloudPlatform.AWS, false);
assertEquals("id", providedSubnetIds.getSubnetId());
ArgumentCaptor<SubnetSelectionParameters> subnetSelectionParametersCaptor = ArgumentCaptor.forClass(SubnetSelectionParameters.class);
verify(networkConnector).chooseSubnets(any(), subnetSelectionParametersCaptor.capture());
assertFalse(subnetSelectionParametersCaptor.getValue().isPreferPrivateIfExist());
assertFalse(subnetSelectionParametersCaptor.getValue().isHa());
assertEquals(tunnel, subnetSelectionParametersCaptor.getValue().getTunnel());
}
use of com.sequenceiq.cloudbreak.cloud.NetworkConnector in project cloudbreak by hortonworks.
the class EnvironmentNetworkService method deleteNetwork.
public void deleteNetwork(EnvironmentDto environment) {
try {
NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform());
networkConnector.deleteNetworkWithSubnets(createNetworkDeletionRequest(environment));
} catch (NetworkConnectorNotFoundException connectorNotFoundException) {
LOGGER.debug("Exiting from network deletion gracefully as Network connector couldn't be found for environment:'{}' and platform:'{}'", environment.getName(), environment.getCloudPlatform());
}
}
use of com.sequenceiq.cloudbreak.cloud.NetworkConnector in project cloudbreak by hortonworks.
the class SubnetChooserServiceTest method testChooseSubnetsWhenAwsIsHaThenHaIsTrue.
@Test
public void testChooseSubnetsWhenAwsIsHaThenHaIsTrue() {
List<CloudSubnet> subnets = List.of();
NetworkConnector networkConnector = setupConnector();
DBStack dbStack = mock(DBStack.class);
when(dbStack.isHa()).thenReturn(true);
underTest.chooseSubnets(subnets, CloudPlatform.AWS, dbStack);
ArgumentCaptor<SubnetSelectionParameters> subnetSelectionParametersCaptor = ArgumentCaptor.forClass(SubnetSelectionParameters.class);
verify(networkConnector).chooseSubnets(eq(subnets), subnetSelectionParametersCaptor.capture());
assertTrue(subnetSelectionParametersCaptor.getValue().isPreferPrivateIfExist());
assertTrue(subnetSelectionParametersCaptor.getValue().isHa());
}
Aggregations