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