Search in sources :

Example 6 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class DataHubClusterDeletionHandlerTest method setUp.

@BeforeEach
void setUp() {
    EnvironmentDto eventDto = EnvironmentDto.builder().withId(ENV_ID).withResourceCrn(RESOURCE_CRN).withName(ENV_NAME).build();
    EnvironmentDeletionDto build = EnvironmentDeletionDto.builder().withId(ENV_ID).withForceDelete(false).withEnvironmentDto(eventDto).build();
    when(environmentDtoEvent.getData()).thenReturn(build);
    when(environmentDtoEvent.getHeaders()).thenReturn(headers);
    doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEvent.capture(), any(Event.Headers.class));
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class S3GuardTableDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            BaseParameters environmentParameters = environment.getParameters();
            if (environmentParameters instanceof AwsParameters) {
                AwsParameters awsParameters = (AwsParameters) environmentParameters;
                deleteS3GuardTable(environment, awsParameters);
            } else {
                LOGGER.info("Environment parameters determine a non-AWS environment. DynamoDB table deletion is not necessary.");
            }
        });
        eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        exceptionProcessor.handle(new HandlerFailureConjoiner(e, environmentDtoEvent, envDeleteEvent), LOGGER, eventSender(), selector());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters)

Example 8 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    Environment environment = environmentService.findEnvironmentById(environmentDto.getId()).orElse(null);
    try {
        if (shouldRemoveFreeIpa(environment)) {
            if (Objects.nonNull(environment.getParentEnvironment())) {
                detachChildEnvironmentFromFreeIpa(environment);
            } else {
                deleteFreeIpa(environment, environmentDeletionDto.isForceDelete());
            }
        }
        eventSender().sendEvent(getNextStepObject(environmentDeletionDto), environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvDeleteFailedEvent failedEvent = EnvDeleteFailedEvent.builder().withEnvironmentID(environmentDto.getId()).withException(e).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvDeleteFailedEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteFailedEvent) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) NotFoundException(javax.ws.rs.NotFoundException) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 9 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto in project cloudbreak by hortonworks.

the class EnvironmentUMSResourceDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    String environmentCrn = null;
    try {
        environmentCrn = environmentDto.getResourceCrn();
        AtomicReference<String> resourceCrn = new AtomicReference<>(null);
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            resourceCrn.set(environment.getResourceCrn());
        });
        if (StringUtils.isBlank(environmentCrn)) {
            environmentCrn = resourceCrn.get();
        }
        virtualGroupService.cleanupVirtualGroups(Crn.fromString(environmentCrn).getAccountId(), environmentCrn);
        ownerAssignmentService.notifyResourceDeleted(environmentCrn, MDCUtils.getRequestId());
    } catch (Exception e) {
        LOGGER.warn("UMS delete event failed (this event is not critical)", e);
    }
    EnvDeleteEvent envDeleteEvent = EnvDeleteEvent.builder().withResourceId(environmentDto.getResourceId()).withResourceName(environmentDto.getName()).withResourceCrn(environmentCrn).withForceDelete(environmentDeletionDto.isForceDelete()).withSelector(FINISH_ENV_DELETE_EVENT.selector()).build();
    eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 10 with EnvironmentDeletionDto

use of com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto 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)

Aggregations

EnvironmentDeletionDto (com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)38 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)34 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)23 CommonContext (com.sequenceiq.flow.core.CommonContext)12 Map (java.util.Map)12 Bean (org.springframework.context.annotation.Bean)12 BeforeEach (org.junit.jupiter.api.BeforeEach)8 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)4 Test (org.junit.jupiter.api.Test)4 Environment (com.sequenceiq.environment.environment.domain.Environment)3 EnvClusterDeleteFailedEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvClusterDeleteFailedEvent)3 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)3 ResourceEvent (com.sequenceiq.cloudbreak.event.ResourceEvent)2 EnvironmentStatus (com.sequenceiq.environment.environment.EnvironmentStatus)2 PollingConfig (com.sequenceiq.environment.util.PollingConfig)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Headers (reactor.bus.Event.Headers)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 ExceptionResponse (com.sequenceiq.cloudbreak.common.exception.ExceptionResponse)1