use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class EnvironmentInitHandlerTest method getEnvironment.
private Environment getEnvironment() {
Environment environment = new Environment();
environment.setId(ENV_ID);
environment.setResourceCrn(CRN);
environment.setCreator(CREATOR);
Region region = new Region();
region.setName(REGION);
environment.setRegions(Set.of(region));
environment.setLocationDisplayName(LOCATION_DISPLAY_NAME);
environment.setLocation(LOCATION);
environment.setAccountId(ACCOUNT_ID);
BaseNetwork baseNetwork = new AwsNetwork();
baseNetwork.setRegistrationType(RegistrationType.EXISTING);
environment.setNetwork(baseNetwork);
environment.setCloudPlatform(CloudPlatform.AWS.name());
environment.setCredential(new Credential());
return environment;
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editNetworkIfChanged.
private void editNetworkIfChanged(Environment environment, EnvironmentEditDto editDto) {
if (networkChanged(editDto)) {
BaseNetwork network = networkService.validate(environment.getNetwork(), editDto, environment);
network = networkService.refreshMetadataFromCloudProvider(network, editDto, environment);
if (network != null) {
environment.setNetwork(network);
}
}
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class NetworkDeleteHandler method accept.
@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder().withResourceId(environmentDto.getResourceId()).withResourceName(environmentDto.getName()).withResourceCrn(environmentDto.getResourceCrn()).withForceDelete(environmentDeletionDto.isForceDelete()).withSelector(START_IDBROKER_MAPPINGS_DELETE_EVENT.selector()).build();
try {
environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
BaseNetwork network = environment.getNetwork();
if (network != null) {
RegistrationType registrationType = network.getRegistrationType();
if (RegistrationType.CREATE_NEW == registrationType) {
environmentNetworkService.deleteNetwork(environmentDtoConverter.environmentToDto(environment));
}
network.setName(environment.getResourceCrn() + "_network_DELETED_@_" + System.currentTimeMillis());
environmentService.save(environment);
}
});
eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
} catch (Exception e) {
exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
}
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork in project cloudbreak by hortonworks.
the class NetworkCreationHandler method createCloudNetworkIfNeeded.
private void createCloudNetworkIfNeeded(EnvironmentDto environmentDto, Environment environment) {
if (hasNetwork(environment) && environment.getNetwork().getRegistrationType() == RegistrationType.CREATE_NEW) {
BaseNetwork baseNetwork = environmentNetworkService.createCloudNetwork(environmentDto, environment.getNetwork());
baseNetwork = networkService.save(baseNetwork);
environment.setNetwork(baseNetwork);
}
}
use of com.sequenceiq.environment.network.dao.domain.BaseNetwork 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;
}
Aggregations