Search in sources :

Example 46 with NetworkDto

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

the class CloudNetworkService method fetchCloudNetwork.

private Map<String, CloudSubnet> fetchCloudNetwork(Set<Region> regions, Credential credential, String cloudPlatform, NetworkDto network, Map<String, String> filter, Set<String> subnetIds) {
    String regionName = regions.iterator().next().getName();
    PlatformResourceRequest platformResourceRequest = new PlatformResourceRequest();
    platformResourceRequest.setCredential(credential);
    platformResourceRequest.setCloudPlatform(cloudPlatform);
    platformResourceRequest.setRegion(regionName);
    platformResourceRequest.setFilters(filter);
    LOGGER.debug("About to fetch networks from cloud provider ({})...", cloudPlatform);
    CloudNetworks cloudNetworks = platformParameterService.getCloudNetworks(platformResourceRequest);
    Set<CloudNetwork> cloudNetworkSet = cloudNetworks.getCloudNetworkResponses().get(regionName);
    return cloudNetworkSet.stream().flatMap(it -> it.getSubnetsMeta().stream()).filter(sn -> isNetworkIdMatches(subnetIds, sn, cloudPlatform) || isNetworkNameMatches(subnetIds, sn, cloudPlatform)).collect(toMap(getNetworkIdentifier(cloudPlatform), Function.identity()));
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Logger(org.slf4j.Logger) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Credential(com.sequenceiq.environment.credential.domain.Credential) LoggerFactory(org.slf4j.LoggerFactory) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) Set(java.util.Set) HashMap(java.util.HashMap) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Function(java.util.function.Function) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) AwsParams(com.sequenceiq.environment.network.dto.AwsParams) Collectors.toMap(java.util.stream.Collectors.toMap) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) Service(org.springframework.stereotype.Service) Map(java.util.Map) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) Optional(java.util.Optional) Region(com.sequenceiq.environment.environment.domain.Region) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork) GcpStackUtil(com.sequenceiq.cloudbreak.cloud.gcp.util.GcpStackUtil) CloudNetworks(com.sequenceiq.cloudbreak.cloud.model.CloudNetworks) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) CloudNetwork(com.sequenceiq.cloudbreak.cloud.model.CloudNetwork)

Example 47 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto 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 48 with NetworkDto

use of com.sequenceiq.environment.network.dto.NetworkDto 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 49 with NetworkDto

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

the class NetworkCreationRequestFactory method create.

public NetworkCreationRequest create(EnvironmentDto environment) {
    NetworkDto networkDto = environment.getNetwork();
    boolean privateSubnetEnabled = getPrivateSubnetEnabled(environment);
    Cidrs cidrs = getSubNetCidrs(environment.getCloudPlatform(), networkDto.getNetworkCidr(), privateSubnetEnabled);
    NetworkCreationRequest.Builder builder = new NetworkCreationRequest.Builder().withStackName(getStackName(environment)).withEnvId(environment.getId()).withEnvName(environment.getName()).withEnvCrn(environment.getResourceCrn()).withCloudCredential(getCredential(environment)).withVariant(environment.getCloudPlatform()).withRegion(Region.region(environment.getLocation().getName())).withNetworkCidr(networkDto.getNetworkCidr()).withPrivateSubnetEnabled(privateSubnetEnabled).withEndpointType(serviceEndpointCreationToEndpointTypeConverter.convert(networkDto.getServiceEndpointCreation(), environment.getCloudPlatform())).withUserName(getUserFromCrn(environment.getCreator())).withAccountId(environment.getAccountId()).withCreatorCrn(environment.getCreator()).withTags(environmentTagProvider.getTags(environment, environment.getNetwork().getResourceCrn())).withPrivateSubnets(cidrs.getPrivateSubnets()).withPublicSubnets(cidrs.getPublicSubnets());
    getNoPublicIp(networkDto).ifPresent(builder::withNoPublicIp);
    getResourceGroupName(environment).ifPresent(builder::withResourceGroup);
    return builder.build();
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkCreationRequest)

Example 50 with NetworkDto

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

the class NetworkCreationRequestFactory method createProviderSpecificNetworkResources.

public NetworkResourcesCreationRequest createProviderSpecificNetworkResources(EnvironmentDto environment, BaseNetwork baseNetwork) {
    NetworkDto networkDto = environment.getNetwork();
    NetworkResourcesCreationRequest.Builder builder = new NetworkResourcesCreationRequest.Builder().withNetworkId(NullUtil.getIfNotNull(baseNetwork, BaseNetwork::getNetworkId)).withNetworkResourceGroup(NullUtil.getIfNotNull(baseNetwork, this::getNetworkResourceGroupName)).withExistingNetwork(NullUtil.getIfNotNull(baseNetwork, this::isExistingNetwork)).withCloudCredential(getCredential(environment)).withCloudContext(getCloudContext(environment)).withRegion(Region.region(environment.getLocation().getName())).withPrivateEndpointsEnabled(ServiceEndpointCreation.ENABLED_PRIVATE_ENDPOINT == networkDto.getServiceEndpointCreation()).withServicesWithExistingPrivateDnsZones(azureExistingPrivateDnsZonesService.getServiceNamesWithExistingZones(networkDto)).withTags(environmentTagProvider.getTags(environment, environment.getNetwork().getResourceCrn()));
    getResourceGroupName(environment).ifPresent(builder::withResourceGroup);
    return builder.build();
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) NetworkResourcesCreationRequest(com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest)

Aggregations

NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)144 Test (org.junit.jupiter.api.Test)124 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)59 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)40 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)31 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)27 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)21 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)21 UsageProto (com.cloudera.thunderhead.service.common.usage.UsageProto)15 Environment (com.sequenceiq.environment.environment.domain.Environment)15 ProvidedSubnetIds (com.sequenceiq.environment.network.service.domain.ProvidedSubnetIds)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)13 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)12 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)10 AwsParams (com.sequenceiq.environment.network.dto.AwsParams)9 Features (com.sequenceiq.common.api.telemetry.model.Features)8 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)7 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)7 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)7 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)7