Search in sources :

Example 11 with EnvironmentDeletionDto

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

the class PublicKeyDeleteHandler method accept.

@Override
public void accept(Event<EnvironmentDeletionDto> environmentDtoEvent) {
    LOGGER.debug("Accepting PublickeyDelete event");
    EnvironmentDeletionDto environmentDeletionDto = environmentDtoEvent.getData();
    EnvironmentDto environmentDto = environmentDeletionDto.getEnvironmentDto();
    EnvDeleteEvent envDeleteEvent = getEnvDeleteEvent(environmentDeletionDto);
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(this::deleteManagedKey);
        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) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 12 with EnvironmentDeletionDto

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

the class EnvClustersDeleteActions method experienceDeleteAction.

@Bean(name = "EXPERIENCE_DELETE_STARTED_STATE")
public Action<?, ?> experienceDeleteAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.EXPERIENCE_DELETE_IN_PROGRESS, ResourceEvent.ENVIRONMENT_EXPERIENCE_DELETION_STARTED, EnvClustersDeleteState.EXPERIENCE_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(envDto).withForceDelete(payload.isForceDelete()).withId(payload.getResourceId()).build();
            sendEvent(context, DELETE_EXPERIENCE_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 13 with EnvironmentDeletionDto

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

the class EnvClustersDeleteActions method datahubClustersDeleteAction.

@Bean(name = "DATAHUB_CLUSTERS_DELETE_STARTED_STATE")
public Action<?, ?> datahubClustersDeleteAction() {
    return new AbstractEnvClustersDeleteAction<>(EnvDeleteEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentStatus environmentStatus = EnvironmentStatus.DATAHUB_CLUSTERS_DELETE_IN_PROGRESS;
            ResourceEvent resourceEvent = ResourceEvent.ENVIRONMENT_DATAHUB_CLUSTERS_DELETION_STARTED;
            EnvClustersDeleteState envClustersDeleteState = EnvClustersDeleteState.DATAHUB_CLUSTERS_DELETE_STARTED_STATE;
            String logDeleteState = "Data Hub clusters";
            EnvironmentDeletionDto envDto = commonUpdateEnvironmentAndNotify(context, payload, environmentStatus, resourceEvent, envClustersDeleteState, logDeleteState);
            sendEvent(context, DELETE_DATAHUB_CLUSTERS_EVENT.selector(), envDto);
        }
    };
}
Also used : EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EnvDeleteEvent(com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent) CommonContext(com.sequenceiq.flow.core.CommonContext) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) Map(java.util.Map) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto) Bean(org.springframework.context.annotation.Bean)

Example 14 with EnvironmentDeletionDto

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

the class EnvClustersDeleteActions method commonUpdateEnvironmentAndNotify.

private EnvironmentDeletionDto commonUpdateEnvironmentAndNotify(CommonContext context, EnvDeleteEvent payload, EnvironmentStatus environmentStatus, ResourceEvent resourceEvent, EnvClustersDeleteState envClustersDeleteState, String logDeleteState) {
    environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
        environment.setStatus(environmentStatus);
        environment.setStatusReason(null);
        Environment env = environmentService.save(environment);
        EnvironmentDto environmentDto = environmentService.getEnvironmentDto(env);
        eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), resourceEvent);
    }, () -> LOGGER.error("Cannot delete {} because the environment does not exist: {}. " + "But the flow will continue, how can this happen?", logDeleteState, payload.getResourceId()));
    EnvironmentDto envDto = new EnvironmentDto();
    envDto.setId(payload.getResourceId());
    envDto.setResourceCrn(payload.getResourceCrn());
    envDto.setName(payload.getResourceName());
    LOGGER.info("Flow entered into {}", envClustersDeleteState.name());
    EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(envDto).withForceDelete(payload.isForceDelete()).withId(payload.getResourceId()).build();
    return environmentDeletionDto;
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentDeletionDto(com.sequenceiq.environment.environment.dto.EnvironmentDeletionDto)

Example 15 with EnvironmentDeletionDto

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

the class EnvDeleteActions method umsResourceDeleteAction.

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

        @Override
        protected void doExecute(CommonContext context, EnvDeleteEvent payload, Map<Object, Object> variables) {
            EnvironmentDto envDto = environmentStatusUpdateService.updateEnvironmentStatusAndNotify(context, payload, EnvironmentStatus.UMS_RESOURCE_DELETE_IN_PROGRESS, ResourceEvent.ENVIRONMENT_UMS_RESOURCE_DELETION_STARTED, EnvDeleteState.UMS_RESOURCE_DELETE_STARTED_STATE);
            EnvironmentDeletionDto environmentDeletionDto = EnvironmentDeletionDto.builder().withEnvironmentDto(envDto).withForceDelete(payload.isForceDelete()).withId(payload.getResourceId()).build();
            sendEvent(context, DELETE_UMS_RESOURCE_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