Search in sources :

Example 11 with BaseNetwork

use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.

the class EnvironmentNetworkServiceTest method testCreateNetworkShouldReturnWithANewNetwork.

@Test
void testCreateNetworkShouldReturnWithANewNetwork() {
    EnvironmentDto environmentDto = EnvironmentDto.builder().withCloudPlatform(CLOUD_PLATFORM).withCreator(USER_CRN).build();
    BaseNetwork baseNetwork = new AwsNetwork();
    NetworkCreationRequest networkCreationRequest = new NetworkCreationRequest.Builder().build();
    CreatedCloudNetwork createdCloudNetwork = new CreatedCloudNetwork();
    AwsEnvironmentNetworkConverter networkConverter = Mockito.mock(AwsEnvironmentNetworkConverter.class);
    when(cloudConnector.networkConnector()).thenReturn(networkConnector);
    when(networkCreationRequestFactory.create(environmentDto)).thenReturn(networkCreationRequest);
    when(networkConnector.createNetworkWithSubnets(networkCreationRequest)).thenReturn(createdCloudNetwork);
    when(environmentNetworkConverterMap.get(CloudPlatform.valueOf(CLOUD_PLATFORM))).thenReturn(networkConverter);
    when(networkConverter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork)).thenReturn(baseNetwork);
    BaseNetwork actual = underTest.createCloudNetwork(environmentDto, baseNetwork);
    verify(cloudConnector).networkConnector();
    verify(cloudPlatformConnectors).get(any(CloudPlatformVariant.class));
    verify(networkCreationRequestFactory).create(environmentDto);
    verify(networkConnector).createNetworkWithSubnets(networkCreationRequest);
    verify(environmentNetworkConverterMap).get(CloudPlatform.valueOf(CLOUD_PLATFORM));
    verify(networkConverter).setCreatedCloudNetwork(baseNetwork, createdCloudNetwork);
    assertEquals(baseNetwork, actual);
}
Also used : AwsEnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.AwsEnvironmentNetworkConverter) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with BaseNetwork

use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.

the class EnvironmentNetworkServiceTest method testCreateProviderSpecificNetworkResources.

@Test
void testCreateProviderSpecificNetworkResources() {
    EnvironmentDto environmentDto = EnvironmentDto.builder().withCloudPlatform(CLOUD_PLATFORM).withCreator(USER_CRN).build();
    NetworkResourcesCreationRequest networkResourcesCreationRequest = new NetworkResourcesCreationRequest.Builder().build();
    AzureEnvironmentNetworkConverter networkConverter = mock(AzureEnvironmentNetworkConverter.class);
    BaseNetwork baseNetwork = getNetwork();
    when(cloudConnector.networkConnector()).thenReturn(networkConnector);
    when(networkCreationRequestFactory.createProviderSpecificNetworkResources(environmentDto, baseNetwork)).thenReturn(networkResourcesCreationRequest);
    when(environmentNetworkConverterMap.get(CloudPlatform.valueOf(CLOUD_PLATFORM))).thenReturn(networkConverter);
    underTest.createProviderSpecificNetworkResources(environmentDto, baseNetwork);
    verify(cloudConnector).networkConnector();
    verify(cloudPlatformConnectors).get(any(CloudPlatformVariant.class));
    verify(networkCreationRequestFactory).createProviderSpecificNetworkResources(environmentDto, baseNetwork);
    verify(networkConnector).createProviderSpecificNetworkResources(networkResourcesCreationRequest);
}
Also used : BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AzureEnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.AzureEnvironmentNetworkConverter) CloudPlatformVariant(com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant) NetworkResourcesCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with BaseNetwork

use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.

the class NetworkServiceTest method testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName.

@Test
public void testRefreshMetadataFromGoogleCloudProviderMustUseSubnetName() {
    NetworkDto networkDto = mock(NetworkDto.class);
    AuthenticationDto authenticationDto = mock(AuthenticationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    EnvironmentBackup environmentBackup = mock(EnvironmentBackup.class);
    SecurityAccessDto securityAccessDto = mock(SecurityAccessDto.class);
    ParametersDto parametersDto = mock(ParametersDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new GcpNetwork();
    baseNetwork.setRegistrationType(RegistrationType.EXISTING);
    Environment environment = new Environment();
    environment.setCloudPlatform("GCP");
    environment.setCredential(credential);
    EnvironmentEditDto environmentEditDto = new EnvironmentEditDto("description", "accountId", networkDto, authenticationDto, environmentTelemetry, environmentBackup, securityAccessDto, Tunnel.CCMV2, IdBrokerMappingSource.MOCK, CloudStorageValidation.ENABLED, "adminGroupName", parametersDto);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(cloudNetworkService.retrieveSubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(any(Environment.class), any(NetworkDto.class))).thenReturn(Map.of("s1", cloudSubnet("s1", "subnet1")));
    when(environmentNetworkConverter.convertToNetwork(any(BaseNetwork.class))).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(any(Network.class), anyString(), any(Credential.class))).thenReturn(new NetworkCidr("10.0.0.0", new ArrayList<>()));
    BaseNetwork result = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    Assertions.assertEquals(result.getSubnetMetas().keySet().stream().findFirst().get(), "subnet1");
    Assertions.assertEquals(result.getSubnetMetas().keySet().size(), 1);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentBackup(com.sequenceiq.environment.environment.dto.EnvironmentBackup) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) ArrayList(java.util.ArrayList) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with BaseNetwork

use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.

the class NetworkCreationRequestFactoryTest method testCreateProviderSpecificNetworkResourcesShouldCreateAProviderSpecificNetworkResourcesCreationRequestWhenResourceGroupNameIsPresent.

@ParameterizedTest
@EnumSource(ServiceEndpointCreation.class)
void testCreateProviderSpecificNetworkResourcesShouldCreateAProviderSpecificNetworkResourcesCreationRequestWhenResourceGroupNameIsPresent(ServiceEndpointCreation serviceEndpointCreation) {
    EnvironmentDto environmentDto = createAzureParametersDto(serviceEndpointCreation).build();
    CloudCredential cloudCredential = new CloudCredential("1", "asd", "account");
    BaseNetwork baseNetwork = getNetwork();
    when(credentialToCloudCredentialConverter.convert(environmentDto.getCredential())).thenReturn(cloudCredential);
    when(defaultSubnetCidrProvider.provide(NETWORK_CIDR, false)).thenReturn(cidrs(SUBNET_CIDRS, new HashSet<>()));
    NetworkResourcesCreationRequest request = underTest.createProviderSpecificNetworkResources(environmentDto, baseNetwork);
    assertEquals(NETWORK_ID, Long.parseLong(request.getNetworkId()));
    assertEquals(LEGACY_RG, request.getNetworkResourceGroup());
    assertEquals(cloudCredential, request.getCloudCredential());
    assertEquals(REGION, request.getRegion().getRegionName());
    assertEquals(SINGLE_RG, request.getResourceGroup());
    assertEquals(serviceEndpointCreation == ServiceEndpointCreation.ENABLED_PRIVATE_ENDPOINT, request.isPrivateEndpointsEnabled());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) NetworkResourcesCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest) HashSet(java.util.HashSet) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with BaseNetwork

use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.

the class AwsEnvironmentNetworkConverterTest method testSetProviderSpecificNetworkShouldPopulateTheExistingNetworkWithTheNewNetworkData.

@Test
void testSetProviderSpecificNetworkShouldPopulateTheExistingNetworkWithTheNewNetworkData() {
    BaseNetwork awsNetwork = new AwsNetwork();
    Set<CreatedSubnet> createdSubnets = createCreatedSubnets();
    CreatedCloudNetwork createdCloudNetwork = new CreatedCloudNetwork("network-1", VPC_ID, createdSubnets);
    AwsNetwork actual = (AwsNetwork) underTest.setCreatedCloudNetwork(awsNetwork, createdCloudNetwork);
    assertEquals(createdCloudNetwork.getStackName(), actual.getName());
    assertEquals(VPC_ID, actual.getVpcId());
    assertTrue(SUBNET_IDS.containsAll(actual.getSubnetMetas().keySet()));
    assertEquals(SUBNET_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getId());
    assertEquals(SUBNET_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getName());
    assertEquals(AZ_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getAvailabilityZone());
    assertEquals(SUBNET_CIDR_1, awsNetwork.getSubnetMetas().get(SUBNET_1).getCidr());
    assertFalse(awsNetwork.getSubnetMetas().get(SUBNET_1).isPrivateSubnet());
    assertEquals(SUBNET_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getId());
    assertEquals(SUBNET_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getName());
    assertEquals(AZ_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getAvailabilityZone());
    assertEquals(SUBNET_CIDR_2, awsNetwork.getSubnetMetas().get(SUBNET_2).getCidr());
    assertFalse(awsNetwork.getSubnetMetas().get(SUBNET_2).isPrivateSubnet());
    assertEquals(SUBNET_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getId());
    assertEquals(SUBNET_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getName());
    assertEquals(AZ_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getAvailabilityZone());
    assertEquals(SUBNET_CIDR_3, awsNetwork.getSubnetMetas().get(SUBNET_3).getCidr());
    assertFalse(awsNetwork.getSubnetMetas().get(SUBNET_3).isPrivateSubnet());
}
Also used : BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) Test(org.junit.jupiter.api.Test)

Aggregations

BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)19 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)9 Network (com.sequenceiq.cloudbreak.cloud.model.Network)8 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Environment (com.sequenceiq.environment.environment.domain.Environment)6 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)6 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)5 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)5 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)5 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)4 Credential (com.sequenceiq.environment.credential.domain.Credential)4 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)3 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)3 HashMap (java.util.HashMap)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)2 NetworkResourcesCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest)2 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)2