Search in sources :

Example 1 with BaseNetwork

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;
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Environment(com.sequenceiq.environment.environment.domain.Environment) Region(com.sequenceiq.environment.environment.domain.Region)

Example 2 with BaseNetwork

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);
        }
    }
}
Also used : BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork)

Example 3 with BaseNetwork

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());
    }
}
Also used : BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) RegistrationType(com.sequenceiq.environment.network.dao.domain.RegistrationType) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 4 with BaseNetwork

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);
    }
}
Also used : BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork)

Example 5 with 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;
}
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)

Aggregations

BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)19 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)9 Network (com.sequenceiq.cloudbreak.cloud.model.Network)8 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Environment (com.sequenceiq.environment.environment.domain.Environment)6 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)6 CreatedCloudNetwork (com.sequenceiq.cloudbreak.cloud.model.network.CreatedCloudNetwork)5 GcpNetwork (com.sequenceiq.environment.network.dao.domain.GcpNetwork)5 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)5 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)4 Credential (com.sequenceiq.environment.credential.domain.Credential)4 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)3 EnvironmentEditDto (com.sequenceiq.environment.environment.dto.EnvironmentEditDto)3 HashMap (java.util.HashMap)3 CloudPlatformVariant (com.sequenceiq.cloudbreak.cloud.model.CloudPlatformVariant)2 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)2 NetworkResourcesCreationRequest (com.sequenceiq.cloudbreak.cloud.model.network.NetworkResourcesCreationRequest)2 AuthenticationDto (com.sequenceiq.environment.environment.dto.AuthenticationDto)2