Search in sources :

Example 6 with AwsParams

use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.

the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsAndNoEndpointSubnetsAreProvided.

@Test
@DisplayName("when retrieveSubnetMetadata has called with EnvironmentDto and the platform is AWS and no endpoint subnets are provided " + "then an empty endpoint map should return")
void testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsAndNoEndpointSubnetsAreProvided() {
    AwsParams awsParams = NetworkTestUtils.getAwsParams(DEFAULT_TEST_VPC_ID);
    CloudSubnet cloudSubnet = new CloudSubnet(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), "someSubnet");
    CloudNetwork cloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), Set.of(cloudSubnet), Collections.emptyMap());
    Map<String, Set<CloudNetwork>> cloudNetworksFromProvider = new LinkedHashMap<>();
    cloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(cloudNetwork));
    when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
    when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(Set.of());
    when(testNetworkDto.getAws()).thenReturn(awsParams);
    when(testEnvironmentDto.getCloudPlatform()).thenReturn(AWS_CLOUD_PLATFORM);
    when(cloudNetworks.getCloudNetworkResponses()).thenReturn(cloudNetworksFromProvider);
    Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironmentDto, testNetworkDto);
    Map<String, CloudSubnet> gatewayResult = underTest.retrieveEndpointGatewaySubnetMetadata(testEnvironmentDto, testNetworkDto);
    byte expectedAmountOfResultCloudSubnet = 1;
    byte expectedAmountOfResultCloudEndpointSubnet = 0;
    assertNotNull(result);
    assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet);
    assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId());
    assertNotNull(gatewayResult);
    assertEquals(expectedAmountOfResultCloudEndpointSubnet, gatewayResult.size(), "The amount of result CloudSubnet(s) for the gateway endpoint must be: " + expectedAmountOfResultCloudEndpointSubnet);
    verify(platformParameterService, times(1)).getCloudNetworks(any());
}
Also used : Set(java.util.Set) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 7 with AwsParams

use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.

the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider.

@Test
@DisplayName("when retrieveSubnetMetadata has called with EnvironmentDto and the platform is AWS then we should fetch the cloud networks from the provider")
void testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider() {
    AwsParams awsParams = NetworkTestUtils.getAwsParams(DEFAULT_TEST_VPC_ID);
    CloudSubnet cloudSubnet = new CloudSubnet(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), "someSubnet");
    CloudNetwork cloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), Set.of(cloudSubnet), Collections.emptyMap());
    Map<String, Set<CloudNetwork>> cloudNetworksFromProvider = new LinkedHashMap<>();
    cloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(cloudNetwork));
    when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
    when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
    when(testNetworkDto.getAws()).thenReturn(awsParams);
    when(testEnvironmentDto.getCloudPlatform()).thenReturn(AWS_CLOUD_PLATFORM);
    when(cloudNetworks.getCloudNetworkResponses()).thenReturn(cloudNetworksFromProvider);
    Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironmentDto, testNetworkDto);
    Map<String, CloudSubnet> gatewayResult = underTest.retrieveEndpointGatewaySubnetMetadata(testEnvironmentDto, testNetworkDto);
    byte expectedAmountOfResultCloudSubnet = 1;
    assertNotNull(result);
    assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet);
    assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId());
    assertNotNull(gatewayResult);
    assertEquals(expectedAmountOfResultCloudSubnet, gatewayResult.size(), "The amount of result CloudSubnet(s) for the gateway endpoint must be: " + expectedAmountOfResultCloudSubnet);
    assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), gatewayResult.get(gatewayResult.keySet().iterator().next()).getId());
    verify(platformParameterService, times(2)).getCloudNetworks(any());
}
Also used : Set(java.util.Set) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 8 with AwsParams

use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.

the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider.

@Test
@DisplayName("when retrieveSubnetMetadata has called with Environment and the platform is AWS then we should fetch the cloud networks from the provider")
void testRetrieveSubnetMetadataByEnvironmentWhenPlatformIsAwsThenWeShouldFetchTheCloudNetworksFromProvider() {
    AwsParams awsParams = NetworkTestUtils.getAwsParams(DEFAULT_TEST_VPC_ID);
    CloudSubnet cloudSubnet = new CloudSubnet(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), "someSubnet");
    CloudNetwork cloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), Set.of(cloudSubnet), Collections.emptyMap());
    Map<String, Set<CloudNetwork>> cloudNetworksFromProvider = new LinkedHashMap<>();
    cloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(cloudNetwork));
    when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
    when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
    when(testNetworkDto.getAws()).thenReturn(awsParams);
    when(testEnvironment.getCloudPlatform()).thenReturn(AWS_CLOUD_PLATFORM);
    when(cloudNetworks.getCloudNetworkResponses()).thenReturn(cloudNetworksFromProvider);
    Map<String, CloudSubnet> result = underTest.retrieveSubnetMetadata(testEnvironment, testNetworkDto);
    Map<String, CloudSubnet> gatewayResult = underTest.retrieveEndpointGatewaySubnetMetadata(testEnvironmentDto, testNetworkDto);
    byte expectedAmountOfResultCloudSubnet = 1;
    assertNotNull(result);
    assertEquals(expectedAmountOfResultCloudSubnet, result.size(), "The amount of result CloudSubnet(s) must be: " + expectedAmountOfResultCloudSubnet);
    assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), result.get(result.keySet().iterator().next()).getId());
    assertNotNull(gatewayResult);
    assertEquals(expectedAmountOfResultCloudSubnet, gatewayResult.size(), "The amount of result CloudSubnet(s) for the gateway endpoint must be: " + expectedAmountOfResultCloudSubnet);
    assertEquals(DEFAULT_TEST_SUBNET_ID_SET.iterator().next(), gatewayResult.get(gatewayResult.keySet().iterator().next()).getId());
    verify(platformParameterService, times(1)).getCloudNetworks(any());
}
Also used : Set(java.util.Set) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with AwsParams

use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkHasOneSubnet.

@Test
void testValidateDuringRequestWhenNetworkHasOneSubnet() {
    int amountOfSubnets = 1;
    AwsParams awsParams = getAwsParams();
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, getAwsParams(), null, awsParams.getVpcId(), null, amountOfSubnets, RegistrationType.EXISTING);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    EnvironmentDto environmentDto = new EnvironmentDto();
    environmentDto.setNetwork(networkDto);
    EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
    Map<String, CloudSubnet> subnetMetas = new HashMap<>();
    for (int i = 0; i < amountOfSubnets; i++) {
        subnetMetas.put("key" + i, NetworkTestUtils.getCloudSubnet("eu-west-1-a"));
    }
    when(cloudNetworkService.retrieveSubnetMetadata(environmentDto, networkDto)).thenReturn(subnetMetas);
    underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
    NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("There should be at least two Subnets in the environment network configuration"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 10 with AwsParams

use of com.sequenceiq.environment.network.dto.AwsParams in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkHasTwoSubnet.

@Test
void testValidateDuringRequestWhenNetworkHasTwoSubnet() {
    AwsParams awsParams = getAwsParams();
    NetworkDto networkDto = NetworkTestUtils.getNetworkDto(null, getAwsParams(), null, awsParams.getVpcId(), null, 2);
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    underTest.validateDuringRequest(networkDto, validationResultBuilder);
    ValidationResult validationResult = validationResultBuilder.build();
    assertFalse(validationResult.hasError(), validationResult.getFormattedErrors());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Test(org.junit.jupiter.api.Test)

Aggregations

AwsParams (com.sequenceiq.environment.network.dto.AwsParams)12 Test (org.junit.jupiter.api.Test)10 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)8 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)7 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)6 LinkedHashMap (java.util.LinkedHashMap)6 CloudNetwork (com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)4 Set (java.util.Set)4 DisplayName (org.junit.jupiter.api.DisplayName)4 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)3 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)3 HashMap (java.util.HashMap)2 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)1 GcpParams (com.sequenceiq.environment.network.dto.GcpParams)1 MockParams (com.sequenceiq.environment.network.dto.MockParams)1 YarnParams (com.sequenceiq.environment.network.dto.YarnParams)1 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)1 InstanceGroupNetworkRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest)1 InstanceGroupAwsNetworkParameters (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.InstanceGroupAwsNetworkParameters)1