Search in sources :

Example 1 with RegistrationType

use of com.sequenceiq.environment.network.dao.domain.RegistrationType 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 2 with RegistrationType

use of com.sequenceiq.environment.network.dao.domain.RegistrationType in project cloudbreak by hortonworks.

the class AzureRegistrationTypeResolverTest method testNetworkDtoGetRegistrationTypeExisting.

@Test
void testNetworkDtoGetRegistrationTypeExisting() {
    NetworkDto networkDto = NetworkDto.builder().withAzure(AzureParams.builder().withNetworkId("NetworkId").withResourceGroupName("ResourceGroupName").build()).build();
    RegistrationType registrationType = azureRegistrationTypeResolver.getRegistrationType(networkDto);
    Assertions.assertEquals(RegistrationType.EXISTING, registrationType);
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) RegistrationType(com.sequenceiq.environment.network.dao.domain.RegistrationType) Test(org.junit.jupiter.api.Test)

Aggregations

RegistrationType (com.sequenceiq.environment.network.dao.domain.RegistrationType)2 EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)1 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)1 Test (org.junit.jupiter.api.Test)1