Search in sources :

Example 1 with AwsParams

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

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenTheAwsNetworkParamsContainsVPCId.

@Test
void testValidateDuringFlowWhenTheAwsNetworkParamsContainsVPCId() {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    AwsParams awsParams = AwsParams.builder().withVpcId("aVPCResourceIDFromAWS").build();
    NetworkDto networkDto = NetworkDto.builder().withId(1L).withName("networkName").withResourceCrn("aResourceCRN").withAws(awsParams).build();
    underTest.validateDuringRequest(networkDto, validationResultBuilder);
    assertFalse(validationResultBuilder.build().hasError());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) Test(org.junit.jupiter.api.Test)

Example 2 with AwsParams

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

the class AwsEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenTheAwsNetworkParamsDoesNotContainVPCId.

@Test
void testValidateDuringFlowWhenTheAwsNetworkParamsDoesNotContainVPCId() {
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    AwsParams awsParams = AwsParams.builder().build();
    NetworkDto networkDto = NetworkDto.builder().withId(1L).withName("networkName").withResourceCrn("aResourceCRN").withAws(awsParams).build();
    underTest.validateDuringRequest(networkDto, validationResultBuilder);
    NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("The 'VPC identifier(vpcId)' parameter should be specified for the 'AWS' environment specific network!"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) Test(org.junit.jupiter.api.Test)

Example 3 with AwsParams

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

the class NetworkRequestToDtoConverter method convert.

public NetworkDto convert(EnvironmentNetworkRequest network) {
    LOGGER.debug("Converting network request to dto");
    NetworkDto.Builder builder = NetworkDto.builder();
    if (network.getAws() != null) {
        LOGGER.debug(NETWORK_CONVERT_MESSAGE_TEMPLATE, "AWS");
        AwsParams awsParams = AwsParams.builder().withVpcId(network.getAws().getVpcId()).build();
        builder.withAws(awsParams);
        builder.withNetworkId(network.getAws().getVpcId());
    }
    if (network.getAzure() != null) {
        LOGGER.debug(NETWORK_CONVERT_MESSAGE_TEMPLATE, "Azure");
        AzureParams azureParams = AzureParams.builder().withNetworkId(network.getAzure().getNetworkId()).withNoPublicIp(Boolean.TRUE.equals(network.getAzure().getNoPublicIp())).withResourceGroupName(network.getAzure().getResourceGroupName()).withDatabasePrivateDnsZoneId(network.getAzure().getDatabasePrivateDnsZoneId()).build();
        builder.withAzure(azureParams);
        builder.withNetworkId(network.getAzure().getNetworkId());
    }
    if (network.getGcp() != null) {
        LOGGER.debug(NETWORK_CONVERT_MESSAGE_TEMPLATE, "GCP");
        GcpParams gcpParams = GcpParams.builder().withNetworkId(network.getGcp().getNetworkId()).withSharedProjectId(network.getGcp().getSharedProjectId()).withNoFirewallRules(network.getGcp().getNoFirewallRules()).withNoPublicIp(network.getGcp().getNoPublicIp()).build();
        builder.withGcp(gcpParams);
        builder.withNetworkId(network.getGcp().getNetworkId());
    }
    if (network.getYarn() != null) {
        LOGGER.debug(NETWORK_CONVERT_MESSAGE_TEMPLATE, "Yarn");
        YarnParams yarnParams = YarnParams.builder().withQueue(network.getYarn().getQueue()).withLifetime(network.getYarn().getLifetime()).build();
        builder.withYarn(yarnParams);
    }
    if (network.getMock() != null) {
        LOGGER.debug(NETWORK_CONVERT_MESSAGE_TEMPLATE, "Mock");
        MockParams mockParams = MockParams.builder().withVpcId(network.getMock().getVpcId()).withInternetGatewayId(network.getMock().getInternetGatewayId()).build();
        builder.withMock(mockParams);
        builder.withNetworkId(mockParams.getVpcId());
    }
    if (network.getGcp() != null) {
        LOGGER.debug(NETWORK_CONVERT_MESSAGE_TEMPLATE, "Gcp");
        GcpParams gcpParams = GcpParams.builder().withSharedProjectId(network.getGcp().getSharedProjectId()).withNetworkId(network.getGcp().getNetworkId()).withNoFirewallRules(Boolean.TRUE.equals(network.getGcp().getNoFirewallRules())).withNoPublicIp(Boolean.TRUE.equals(network.getGcp().getNoPublicIp())).build();
        builder.withGcp(gcpParams);
        builder.withNetworkId(gcpParams.getNetworkId());
    }
    if (network.getSubnetIds() != null) {
        builder.withSubnetMetas(network.getSubnetIds().stream().collect(Collectors.toMap(id -> id, id -> new CloudSubnet(id, id))));
    }
    if (network.getEndpointGatewaySubnetIds() != null) {
        builder.withEndpointGatewaySubnetMetas(network.getEndpointGatewaySubnetIds().stream().collect(Collectors.toMap(id -> id, id -> new CloudSubnet(id, id))));
    }
    return builder.withNetworkCidr(network.getNetworkCidr()).withNetworkCidrs(getNetworkCidrs(network)).withPrivateSubnetCreation(getPrivateSubnetCreation(network)).withServiceEndpointCreation(getServiceEndpointCreation(network)).withOutboundInternetTraffic(getOutboundInternetTraffic(network)).withUsePublicEndpointAccessGateway(getUsePublicEndpointAccessGateway(network)).withLoadBalancerCreation(getLoadBalancerCreation(network)).build();
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) GcpParams(com.sequenceiq.environment.network.dto.GcpParams) MockParams(com.sequenceiq.environment.network.dto.MockParams) YarnParams(com.sequenceiq.environment.network.dto.YarnParams) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 4 with AwsParams

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

the class FreeIpaAwsNetworkProvider method network.

@Override
public NetworkRequest network(EnvironmentDto environment, boolean multiAzRequired) {
    NetworkDto network = environment.getNetwork();
    NetworkRequest networkRequest = new NetworkRequest();
    AwsParams awsParams = network.getAws();
    AwsNetworkParameters awsNetworkParameters = new AwsNetworkParameters();
    networkRequest.setNetworkCidrs(collectNetworkCidrs(network));
    networkRequest.setOutboundInternetTraffic(network.getOutboundInternetTraffic());
    awsNetworkParameters.setVpcId(awsParams.getVpcId());
    if (!multiAzRequired) {
        ProvidedSubnetIds providedSubnetIds = subnetIdProvider.subnets(environment.getNetwork(), environment.getExperimentalFeatures().getTunnel(), CloudPlatform.AWS, multiAzRequired);
        awsNetworkParameters.setSubnetId(providedSubnetIds.getSubnetId());
    }
    networkRequest.setAws(awsNetworkParameters);
    return networkRequest;
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ProvidedSubnetIds(com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds) InstanceGroupNetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupNetworkRequest) NetworkRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.NetworkRequest) AwsNetworkParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.network.AwsNetworkParameters) InstanceGroupAwsNetworkParameters(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.aws.InstanceGroupAwsNetworkParameters) AwsParams(com.sequenceiq.environment.network.dto.AwsParams)

Example 5 with AwsParams

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

the class CloudNetworkServiceTest method testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsAndDifferentEndpointSubnetsAreProvided.

@Test
@DisplayName("when retrieveSubnetMetadata has called with EnvironmentDto and the platform is AWS and endpoint subnets are provided that do not match the " + "environment subnets, then endpoint subnet information unique those subnets should be returned")
void testRetrieveSubnetMetadataByEnvironmentDtoWhenPlatformIsAwsAndDifferentEndpointSubnetsAreProvided() {
    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));
    CloudSubnet publicCloudSubnet = new CloudSubnet(DEFAULT_TEST_PUBLIC_SUBNET_ID_SET.iterator().next(), "someSubnet");
    CloudNetwork publicCloudNetwork = new CloudNetwork("someCloudNetwork", DEFAULT_TEST_PUBLIC_SUBNET_ID_SET.iterator().next(), Set.of(publicCloudSubnet), Collections.emptyMap());
    Map<String, Set<CloudNetwork>> publicCloudNetworksFromProvider = new LinkedHashMap<>();
    publicCloudNetworksFromProvider.put(DEFAULT_TEST_REGION_NAME, Set.of(publicCloudNetwork));
    when(testNetworkDto.getSubnetIds()).thenReturn(DEFAULT_TEST_SUBNET_ID_SET);
    when(testNetworkDto.getEndpointGatewaySubnetIds()).thenReturn(DEFAULT_TEST_PUBLIC_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);
    when(cloudNetworks.getCloudNetworkResponses()).thenReturn(publicCloudNetworksFromProvider);
    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_PUBLIC_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)

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