Search in sources :

Example 16 with SubnetSelectionResult

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

the class AzureSubnetSelectorServiceTest method testselectWhenNotDatabaseTwoSubnetsThenOneIsSelected.

@Test
public void testselectWhenNotDatabaseTwoSubnetsThenOneIsSelected() {
    List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().withPrivateSubnet().build();
    SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().build());
    assertEquals(2, subnetSelectionResult.getResult().size());
}
Also used : SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 17 with SubnetSelectionResult

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

the class AzureSubnetSelectorServiceTest method testSelectWhenParametersNullThenReturnsError.

@Test
public void testSelectWhenParametersNullThenReturnsError() {
    List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().build();
    SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, null);
    assertTrue(subnetSelectionResult.hasError());
    assertEquals("Azure subnet selection: parameters were not specified.", subnetSelectionResult.getErrorMessage());
}
Also used : SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 18 with SubnetSelectionResult

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

the class AzureSubnetSelectorServiceTest method testselectWhenDatabaseThreeSubnetsThenAllAreReturned.

@Test
public void testselectWhenDatabaseThreeSubnetsThenAllAreReturned() {
    List<CloudSubnet> subnets = new SubnetBuilder().withPrivateSubnet().withPrivateSubnet().withPrivateSubnet().build();
    SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().withPreferPrivateIfExist().build());
    assertEquals(3, subnetSelectionResult.getResult().size());
    List<String> selectedSubnetIds = subnetSelectionResult.getResult().stream().map(CloudSubnet::getId).collect(Collectors.toList());
    assertThat(selectedSubnetIds, hasItem("subnet-1"));
    assertThat(selectedSubnetIds, hasItem("subnet-2"));
    assertThat(selectedSubnetIds, hasItem("subnet-3"));
}
Also used : SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 19 with SubnetSelectionResult

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

the class AzureSubnetSelectorServiceTest method testSelectWhenNoSubnetsThenReturnsError.

@Test
public void testSelectWhenNoSubnetsThenReturnsError() {
    List<CloudSubnet> subnets = new SubnetBuilder().build();
    SubnetSelectionResult subnetSelectionResult = underTest.select(subnets, SubnetSelectionParameters.builder().build());
    assertTrue(subnetSelectionResult.hasError());
    assertEquals("Azure subnet selection: there are no subnets to choose from.", subnetSelectionResult.getErrorMessage());
}
Also used : SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.Test)

Example 20 with SubnetSelectionResult

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

the class AzureSubnetSelectorService method selectForPrivateEndpoint.

public SubnetSelectionResult selectForPrivateEndpoint(Collection<CloudSubnet> subnetMetas, boolean existingNetwork) {
    List<CloudSubnet> suitableCloudSubnet;
    if (existingNetwork) {
        LOGGER.debug("Selecting subnets for private endpoint, existing network");
        suitableCloudSubnet = subnetMetas.stream().filter(sn -> azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(sn)).collect(Collectors.toList());
    } else {
        LOGGER.debug("Selecting subnets for private endpoint, new network - all subnets are suitable");
        suitableCloudSubnet = new ArrayList<>(subnetMetas);
    }
    return suitableCloudSubnet.isEmpty() ? new SubnetSelectionResult("No suitable subnets found for placing a private endpoint " + "because of the network policy being enabled, please disable network policies for private endpoints and try again!") : new SubnetSelectionResult(suitableCloudSubnet);
}
Also used : SubnetSelectionResult(com.sequenceiq.cloudbreak.cloud.model.SubnetSelectionResult) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

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