Search in sources :

Example 36 with EnvironmentDeletionDto

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

the class ResourceEncryptionDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    LOGGER.debug("Accepting ResourceEncryptionDelete event");
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            if (AZURE.name().equalsIgnoreCase(environmentDto.getCloudPlatform())) {
                String encryptionKeyUrl = Optional.ofNullable(environmentDto.getParameters()).map(ParametersDto::getAzureParametersDto).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null);
                if (StringUtils.isNotEmpty(encryptionKeyUrl) && (environment.getStatus() != EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_DELETED)) {
                    deleteEncryptionResources(environmentDto, environment);
                } else {
                    LOGGER.info("No encryption resources found to delete for environment \"{}\".", environment.getName());
                }
            }
        });
        eventSender().sendEvent(envDeleteEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.error("ResourceEncryptionDelete failed with error.", 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) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 37 with EnvironmentDeletionDto

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

the class EnvDeleteActions method publickeyDeleteAction.

@Bean(name = "PUBLICKEY_DELETE_STARTED_STATE")
public Action<?, ?> publickeyDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.PUBLICKEY_DELETE_IN_PROGRESS, ResourceEvent.ENVIRONMENT_PUBLICKEY_DELETION_STARTED, EnvDeleteState.PUBLICKEY_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(envDto).withForceDelete(payload.isForceDelete()).withId(payload.getResourceId()).build();
            sendEvent(context, DELETE_PUBLICKEY_EVENT.selector(), environmentDeletionDto);
        }
    };
}
Also used : EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Map(java.util.Map) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Bean(org.springframework.context.annotation.Bean)

Example 38 with EnvironmentDeletionDto

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

the class EnvDeleteActions method clusterDefinitionDeleteAction.

@Bean(name = "CLUSTER_DEFINITION_DELETE_STARTED_STATE")
public Action<?, ?> clusterDefinitionDeleteAction() {
    return new AbstractEnvDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.CLUSTER_DEFINITION_DELETE_PROGRESS, ResourceEvent.ENVIRONMENT_CLUSTER_DEFINITION_DELETE_STARTED, EnvDeleteState.CLUSTER_DEFINITION_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(envDto).withForceDelete(payload.isForceDelete()).withId(payload.getResourceId()).build();
            sendEvent(context, DELETE_CLUSTER_DEFINITION_EVENT.selector(), environmentDeletionDto);
        }
    };
}
Also used : EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Map(java.util.Map) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Bean(org.springframework.context.annotation.Bean)

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