Search in sources :

Example 31 with SubnetSelectionResult

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

Example 32 with SubnetSelectionResult

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);
}
Also used : Inject(javax.inject.Inject) List(java.util.List) Component(org.springframework.stereotype.Component) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collectors(java.util.stream.Collectors) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 33 with SubnetSelectionResult

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());
}
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 34 with SubnetSelectionResult

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);
}
Also used : SubnetFilterStrategyType(com.sequenceiq.cloudbreak.cloud.aws.common.subnetselector.SubnetFilterStrategyType) SubnetFilterStrategy(com.sequenceiq.cloudbreak.cloud.aws.common.subnetselector.SubnetFilterStrategy) HashMap(java.util.HashMap) SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)

Example 35 with SubnetSelectionResult

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

Aggregations

SubnetSelectionResult (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult)35 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)26 Test (org.junit.Test)22 SubnetSelectionParameters (com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionParameters)9 NetworkConnector (com.sequenceiq.cloudbreak.cloud.NetworkConnector)4 Test (org.junit.jupiter.api.Test)4 CloudConnector (com.sequenceiq.cloudbreak.cloud.CloudConnector)2 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 Collection (java.util.Collection)2 List (java.util.List)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (org.springframework.stereotype.Component)2 SubnetFilterStrategy (com.sequenceiq.cloudbreak.cloud.aws.common.subnetselector.SubnetFilterStrategy)1 SubnetFilterStrategyType (com.sequenceiq.cloudbreak.cloud.aws.common.subnetselector.SubnetFilterStrategyType)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)1