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()));
}
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;
}
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;
}
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();
}
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();
}
Aggregations