Search in sources :

Example 6 with NetworkConnector

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()));
}
Also used : ProvidedSubnetIds(com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds) SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 7 with NetworkConnector

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;
}
Also used : CloudConnector(com.sequenceiq.cloudbreak.cloud.CloudConnector) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)

Example 8 with 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());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Tunnel(com.sequenceiq.common.api.type.Tunnel) ProvidedSubnetIds(com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds) SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 9 with NetworkConnector

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());
    }
}
Also used : NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector)

Example 10 with NetworkConnector

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());
}
Also used : DBStack(com.sequenceiq.redbeams.domain.stack.DBStack) SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Aggregations

NetworkConnector (com.sequenceiq.cloudbreak.cloud.NetworkConnector)13 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)6 SubnetSelectionParameters (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters)6 SubnetSelectionResult (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)4 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)3 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)3 Test (org.junit.Test)3 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)2 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)2 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)1 NetworkCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)1 NetworkResourcesCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Tunnel (com.sequenceiq.common.api.type.Tunnel)1 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)1 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)1 Test (org.junit.jupiter.api.Test)1