Search in sources :

Example 6 with SubnetSelectionParameters

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.

the class AwsNetworkConnectorTest method testSubnetSelectionWhenNonHaRequiredAnd1DifferentAZDeclaredShouldReturnOneSubnet.

@Test
public void testSubnetSelectionWhenNonHaRequiredAnd1DifferentAZDeclaredShouldReturnOneSubnet() {
    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(false).build();
    SubnetSelectionResult result = underTest.chooseSubnets(cloudSubnets, subnetSelectionParameters);
    Assert.assertTrue(result.getResult().size() == 1);
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 7 with SubnetSelectionParameters

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters in project cloudbreak by hortonworks.

the class AwsNetworkConnectorTest method testSubnetSelectionWhenHaRequiredAnd4DifferentAZDeclaredShouldReturn3DifferentAz.

@Test
public void testSubnetSelectionWhenHaRequiredAnd4DifferentAZDeclaredShouldReturn3DifferentAz() {
    List<CloudSubnet> cloudSubnets = Lists.newArrayList(getSubnet("a1", 1), getSubnet("a2", 2), getSubnet("a3", 3), getSubnet("a4", 4));
    prepareMock(cloudSubnets);
    SubnetSelectionParameters subnetSelectionParameters = SubnetSelectionParameters.builder().withPreferPrivateIfExist().withTunnel(Tunnel.CCM).withHa(true).build();
    SubnetSelectionResult result = underTest.chooseSubnets(cloudSubnets, subnetSelectionParameters);
    Assert.assertTrue(result.getResult().size() == 3);
    Assert.assertTrue(result.getResult().size() == collectUniqueAzs(result).size());
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 8 with SubnetSelectionParameters

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters 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 SubnetSelectionParameters

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters 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());
}
Also used : SubnetSelectionParameters(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 10 with SubnetSelectionParameters

use of com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters 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

SubnetSelectionParameters (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters)12 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)11 Test (org.junit.Test)9 SubnetSelectionResult (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)8 NetworkConnector (com.sequenceiq.cloudbreak.cloud.NetworkConnector)6 DBStack (com.sequenceiq.redbeams.domain.stack.DBStack)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Tunnel (com.sequenceiq.common.api.type.Tunnel)1 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)1 Test (org.junit.jupiter.api.Test)1