Search in sources :

Example 1 with GcpNetwork

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

the class GcpEnvironmentNetworkConverter method setCreatedCloudNetwork.

@Override
public BaseNetwork setCreatedCloudNetwork(BaseNetwork baseNetwork, CreatedCloudNetwork createdCloudNetwork) {
    GcpNetwork gcpNetwork = (GcpNetwork) baseNetwork;
    gcpNetwork.setNetworkId(createdCloudNetwork.getNetworkId());
    Map<String, Object> properties = createdCloudNetwork.getProperties();
    if (properties == null) {
        properties = new HashMap<>();
    }
    Object sharedProjectId = properties.get("sharedProjectId");
    gcpNetwork.setSharedProjectId(sharedProjectId == null ? null : sharedProjectId.toString());
    Object noFirewallRules = properties.get("noFirewallRules");
    gcpNetwork.setNoFirewallRules(noFirewallRules != null && Boolean.parseBoolean(noFirewallRules.toString()));
    Object noPublicIp = properties.get("noPublicIp");
    gcpNetwork.setNoPublicIp(noPublicIp != null && Boolean.parseBoolean(noPublicIp.toString()));
    gcpNetwork.setSubnetMetas(createdCloudNetwork.getSubnets().stream().collect(Collectors.toMap(CreatedSubnet::getSubnetId, subnet -> new CloudSubnet(subnet.getSubnetId(), subnet.getSubnetId(), subnet.getAvailabilityZone(), subnet.getCidr(), !subnet.isPublicSubnet(), subnet.isMapPublicIpOnLaunch(), subnet.isIgwAvailable(), subnet.isIgwAvailable() ? PUBLIC : PRIVATE))));
    return gcpNetwork;
}
Also used : GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork) CreatedSubnet(com.sequenceiq.cloudbreak.cloud.model.network.CreatedSubnet) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 2 with GcpNetwork

use of com.sequenceiq.environment.network.dao.domain.GcpNetwork 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 3 with GcpNetwork

use of com.sequenceiq.environment.network.dao.domain.GcpNetwork 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 4 with GcpNetwork

use of com.sequenceiq.environment.network.dao.domain.GcpNetwork 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 5 with GcpNetwork

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

the class GcpEnvironmentNetworkConverter method createProviderSpecificNetwork.

@Override
BaseNetwork createProviderSpecificNetwork(NetworkDto network) {
    GcpNetwork gcpNetwork = new GcpNetwork();
    GcpParams gcpParams = network.getGcp();
    if (gcpParams != null) {
        gcpNetwork.setNetworkId(gcpParams.getNetworkId());
        gcpNetwork.setNoFirewallRules(gcpParams.getNoFirewallRules());
        gcpNetwork.setNoPublicIp(gcpParams.getNoPublicIp());
        gcpNetwork.setSharedProjectId(gcpParams.getSharedProjectId());
    }
    return gcpNetwork;
}
Also used : GcpParams(com.sequenceiq.environment.network.dto.GcpParams) GcpNetwork(com.sequenceiq.environment.network.dao.domain.GcpNetwork)

Aggregations

GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)6 Network (com.sequenceiq.cloudbreak.cloud.model.Network)3 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)3 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)2 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)2 Credential (com.sequenceiq.environment.credential.domain.Credential)2 Environment (com.sequenceiq.environment.environment.domain.Environment)2 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)2 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)2 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)2 SecurityAccessDto (com.sequenceiq.environment.environment.dto.SecurityAccessDto)2 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)2 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)2 GcpParams (com.sequenceiq.environment.network.dto.GcpParams)2 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)2 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)2 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)2 ArrayList (java.util.ArrayList)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2