Search in sources :

Example 6 with BaseNetwork

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

the class GcpEnvironmentNetworkConverter method convertToNetwork.

@Override
public Network convertToNetwork(BaseNetwork baseNetwork) {
    GcpNetwork gcpNetwork = (GcpNetwork) baseNetwork;
    Map<String, Object> param = new HashMap<>();
    param.put(GcpStackUtil.NETWORK_ID, gcpNetwork.getNetworkId());
    param.put(GcpStackUtil.SHARED_PROJECT_ID, gcpNetwork.getSharedProjectId());
    param.put(GcpStackUtil.NO_PUBLIC_IP, gcpNetwork.getNoPublicIp());
    param.put(GcpStackUtil.NO_FIREWALL_RULES, gcpNetwork.getNoFirewallRules());
    param.put(GcpStackUtil.SUBNET_ID, baseNetwork.getSubnetMetas().entrySet().stream().findFirst().get().getKey());
    param.put(GcpStackUtil.REGION, baseNetwork.getEnvironments().stream().findFirst().get().getLocation());
    return new Network(null, param);
}
Also used : HashMap(java.util.HashMap) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork)

Example 7 with BaseNetwork

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

the class AwsEnvironmentNetworkConverter method convertToNetwork.

@Override
public Network convertToNetwork(BaseNetwork baseNetwork) {
    AwsNetwork awsNetwork = (AwsNetwork) baseNetwork;
    Map<String, Object> param = new HashMap<>();
    param.put(NetworkConstants.VPC_ID, awsNetwork.getVpcId());
    param.put(AwsNetworkView.REGION, awsNetwork.getEnvironments().stream().findFirst().get().getLocation());
    return new Network(null, param);
}
Also used : HashMap(java.util.HashMap) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network)

Example 8 with BaseNetwork

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

the class NetworkServiceTest method testSaveNetworkIfNewNetwork.

@Test
public void testSaveNetworkIfNewNetwork() {
    NetworkDto networkDto = mock(NetworkDto.class);
    EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
    Network network = mock(Network.class);
    Credential credential = mock(Credential.class);
    BaseNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setCredential(credential);
    when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convert(environment, networkDto, Map.of(), Map.of())).thenReturn(baseNetwork);
    when(networkRepository.save(baseNetwork)).thenReturn(baseNetwork);
    BaseNetwork result = underTest.saveNetwork(environment, networkDto, "accountId", Map.of(), Map.of());
    Assertions.assertNull(result.getNetworkCidr());
    verify(environmentNetworkService, times(0)).getNetworkCidr(eq(network), anyString(), eq(credential));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) 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) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with BaseNetwork

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

the class NetworkServiceTest method testRefreshMetadataFromAwsCloudProviderMustUseSubnetId.

@Test
public void testRefreshMetadataFromAwsCloudProviderMustUseSubnetId() {
    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("AWS");
    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(), "s1");
    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 10 with BaseNetwork

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

the class NetworkServiceTest method testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs.

@Test
public void testRefreshMetadataFromCloudProviderWhenVpcHasMultipleCidrs() {
    String primaryCidr = "10.0.0.0/16";
    String secondaryCidr = "10.2.0.0/16";
    AwsNetwork baseNetwork = new AwsNetwork();
    baseNetwork.setSubnetMetas(Collections.emptyMap());
    baseNetwork.setRegistrationType(RegistrationType.CREATE_NEW);
    Environment environment = new Environment();
    environment.setCloudPlatform("AWS");
    environment.setNetwork(baseNetwork);
    NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.CREATE_NEW).build();
    EnvironmentEditDto environmentEditDto = EnvironmentEditDto.builder().withNetwork(networkDto).build();
    Network network = new Network(new Subnet(primaryCidr));
    NetworkCidr networkCidr = new NetworkCidr(primaryCidr, List.of(primaryCidr, secondaryCidr));
    when(environmentNetworkConverterMap.get(CloudPlatform.AWS)).thenReturn(environmentNetworkConverter);
    when(environmentNetworkConverter.convertToDto(baseNetwork)).thenReturn(networkDto);
    when(environmentNetworkConverter.convertToNetwork(baseNetwork)).thenReturn(network);
    when(environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential())).thenReturn(networkCidr);
    BaseNetwork actualNetwork = underTest.refreshMetadataFromCloudProvider(baseNetwork, environmentEditDto, environment);
    verify(cloudNetworkService, times(1)).retrieveSubnetMetadata(eq(environment), any(NetworkDto.class));
    verify(environmentNetworkService, times(1)).getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
    Assertions.assertEquals(primaryCidr, actualNetwork.getNetworkCidr());
    Assertions.assertEquals(StringUtils.join(networkCidr.getCidrs(), ","), actualNetwork.getNetworkCidrs());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) 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) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Subnet(com.sequenceiq.cloudbreak.cloud.model.Subnet) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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