Search in sources :

Example 16 with EnvCreationEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent in project cloudbreak by hortonworks.

the class EnvCreationActions method freeipaCreationAction.

@Bean(name = "FREEIPA_CREATION_STARTED_STATE")
public Action<?, ?> freeipaCreationAction() {
    return new AbstractEnvironmentCreationAction<>(EnvCreationEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvCreationEvent payload, Map<Object, Object> variables) {
            environmentService.findEnvironmentById(payload.getResourceId()).ifPresentOrElse(environment -> {
                LOGGER.info("Creation of FreeIPA has started. Current state is - FREEIPA_CREATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.FREEIPA_CREATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_FREEIPA_CREATION_STARTED);
                sendEvent(context, CREATE_FREEIPA_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment freeipa creation action went failed with EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_FREEIPA_CREATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create freeipa for environment! No environment found with id '{}'.", payload.getResourceId());
                sendEvent(context, failureEvent);
            });
        }
    };
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Aggregations

EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)16 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)9 EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)8 CommonContext (com.sequenceiq.flow.core.CommonContext)7 Map (java.util.Map)7 Bean (org.springframework.context.annotation.Bean)7 Event (reactor.bus.Event)3 BaseNamedFlowEvent (com.sequenceiq.flow.reactor.api.event.BaseNamedFlowEvent)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)1 EnvStackConfigUpdatesEvent (com.sequenceiq.environment.environment.flow.config.update.event.EnvStackConfigUpdatesEvent)1 EnvDeleteEvent (com.sequenceiq.environment.environment.flow.deletion.event.EnvDeleteEvent)1 LoadBalancerUpdateEvent (com.sequenceiq.environment.environment.flow.loadbalancer.event.LoadBalancerUpdateEvent)1 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)1 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)1 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)1 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)1 FlowParameters (com.sequenceiq.flow.core.FlowParameters)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1