Search in sources :

Example 1 with EnvironmentNetworkConverter

use of com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter in project cloudbreak by hortonworks.

the class EnvironmentInitHandler method initEnvironment.

private void initEnvironment(Environment environment) {
    generateDomainForEnvironment(environment);
    String environmentCrnForVirtualGroups = getEnvironmentCrnForVirtualGroups(environment);
    if (!createVirtualGroups(environment, environmentCrnForVirtualGroups)) {
        // To keep backward compatibility, if somebody passes the group name, then we shall just use it
        environmentService.setAdminGroupName(environment, environment.getAdminGroupName());
    }
    if (environment.getNetwork() != null && RegistrationType.EXISTING.equals(environment.getNetwork().getRegistrationType())) {
        EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(CloudPlatform.valueOf(environment.getCloudPlatform()));
        if (environmentNetworkConverter != null) {
            Network network = environmentNetworkConverter.convertToNetwork(environment.getNetwork());
            NetworkCidr networkCidr = environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
            environment.getNetwork().setNetworkCidr(networkCidr.getCidr());
            environment.getNetwork().setNetworkCidrs(StringUtils.join(networkCidr.getCidrs(), ","));
        }
    }
    environmentService.assignEnvironmentAdminRole(environment.getCreator(), environmentCrnForVirtualGroups);
    setLocationAndRegions(environment);
    environmentService.save(environment);
}
Also used : NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) Network(com.sequenceiq.cloudbreak.cloud.model.Network) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)

Example 2 with EnvironmentNetworkConverter

use of com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter in project cloudbreak by hortonworks.

the class EnvironmentNetworkService method createCloudNetwork.

public BaseNetwork createCloudNetwork(EnvironmentDto environment, BaseNetwork baseNetwork) {
    NetworkConnector networkConnector = getNetworkConnector(environment.getCloudPlatform());
    NetworkCreationRequest networkCreationRequest = networkCreationRequestFactory.create(environment);
    EnvironmentNetworkConverter converter = environmentNetworkConverterMap.get(getCloudPlatform(environment));
    CreatedCloudNetwork createdCloudNetwork = networkConnector.createNetworkWithSubnets(networkCreationRequest);
    return converter.setCreatedCloudNetwork(baseNetwork, createdCloudNetwork);
}
Also used : NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest) NetworkConnector(com.sequenceiq.cloudbreak.cloud.NetworkConnector) CreatedCloudNetwork(com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)

Example 3 with EnvironmentNetworkConverter

use of com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter in project cloudbreak by hortonworks.

the class NetworkService method validate.

public BaseNetwork validate(BaseNetwork originalNetwork, EnvironmentEditDto editDto, Environment environment) {
    CloudPlatform cloudPlatform = CloudPlatform.valueOf(environment.getCloudPlatform());
    if (originalNetwork.getRegistrationType() == RegistrationType.CREATE_NEW) {
        throw new BadRequestException("Subnets of this environment could not be modified, because its network has been created by Cloudera. " + "You need to re-install the environment into an existing VPC/VNet." + getDocLink(cloudPlatform));
    }
    EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(cloudPlatform);
    NetworkDto originalNetworkDto = environmentNetworkConverter.convertToDto(originalNetwork);
    NetworkDto cloneNetworkDto = NetworkDto.builder(originalNetworkDto).withSubnetMetas(editDto.getNetworkDto().getSubnetMetas()).build();
    ValidationResultBuilder validationResultBuilder = networkCreationValidator.validateNetworkEdit(environment, cloneNetworkDto);
    ValidationResult validationResult = validationResultBuilder.build();
    if (validationResult.hasError()) {
        throw new BadRequestException(validationResult.getFormattedErrors());
    }
    return originalNetwork;
}
Also used : CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)

Example 4 with EnvironmentNetworkConverter

use of com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter in project cloudbreak by hortonworks.

the class NetworkService method refreshMetadataFromCloudProvider.

public BaseNetwork refreshMetadataFromCloudProvider(BaseNetwork originalNetwork, EnvironmentEditDto editDto, Environment environment) {
    EnvironmentNetworkConverter environmentNetworkConverter = environmentNetworkConverterMap.get(CloudPlatform.valueOf(environment.getCloudPlatform()));
    NetworkDto originalNetworkDto = environmentNetworkConverter.convertToDto(originalNetwork);
    NetworkDto cloneNetworkDto = NetworkDto.builder(originalNetworkDto).withSubnetMetas(editDto.getNetworkDto().getSubnetMetas()).build();
    try {
        Map<String, CloudSubnet> subnetMetadatas = cloudNetworkService.retrieveSubnetMetadata(environment, cloneNetworkDto);
        originalNetwork.setSubnetMetas(subnetMetadatas.values().stream().collect(toMap(c -> getId(environment.getCloudPlatform(), c), c -> c)));
        Map<String, CloudSubnet> endpointGatewaySubnetMetadatas = cloudNetworkService.retrieveEndpointGatewaySubnetMetadata(environment, cloneNetworkDto);
        originalNetwork.setEndpointGatewaySubnetMetas(endpointGatewaySubnetMetadatas.values().stream().collect(toMap(c -> getId(environment.getCloudPlatform(), c), c -> c)));
        Network network = environmentNetworkConverter.convertToNetwork(originalNetwork);
        NetworkCidr networkCidr = environmentNetworkService.getNetworkCidr(network, environment.getCloudPlatform(), environment.getCredential());
        originalNetwork.setNetworkCidr(networkCidr.getCidr());
        originalNetwork.setNetworkCidrs(StringUtils.join(networkCidr.getCidrs(), ","));
    } catch (NetworkConnectorNotFoundException connectorNotFoundException) {
        throw new BadRequestException(connectorNotFoundException.getMessage());
    }
    return originalNetwork;
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) Network(com.sequenceiq.cloudbreak.cloud.model.Network) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)

Example 5 with EnvironmentNetworkConverter

use of com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter 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)

Aggregations

EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)9 Network (com.sequenceiq.cloudbreak.cloud.model.Network)6 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)6 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)6 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)5 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)5 Environment (com.sequenceiq.environment.environment.domain.Environment)4 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)4 Test (org.junit.jupiter.api.Test)4 Credential (com.sequenceiq.environment.credential.domain.Credential)3 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)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 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)2 ArrayList (java.util.ArrayList)2