Search in sources :

Example 11 with EnvCreationEvent

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

the class EnvironmentInitHandler method goToValidationState.

private void goToValidationState(Event<EnvironmentDto> environmentDtoEvent, EnvironmentDto environmentDto) {
    EnvCreationEvent envCreationEvent = EnvCreationEvent.builder().withResourceId(environmentDto.getResourceId()).withSelector(START_ENVIRONMENT_VALIDATION_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
    eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
}
Also used : EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)

Example 12 with EnvCreationEvent

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

the class NetworkCreationHandler method initiateNextStep.

private void initiateNextStep(Event<EnvironmentDto> environmentDtoEvent, EnvironmentDto environmentDto) {
    EnvCreationEvent envCreationEvent = EnvCreationEvent.builder().withResourceId(environmentDto.getResourceId()).withSelector(START_PUBLICKEY_CREATION_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceName(environmentDto.getName()).build();
    eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
}
Also used : EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)

Example 13 with EnvCreationEvent

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

the class ResourceEncryptionInitializationHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("Accepting ResourceEncryptionInitialization event");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    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);
                String environmentName = environment.getName();
                if (StringUtils.isNotEmpty(encryptionKeyUrl)) {
                    if (environment.getStatus() != EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED) {
                        initializeEncryptionResources(environmentDto, environment);
                    } else {
                        LOGGER.info("Initialization of encryption resources for environment \"{}\" has already been triggered, " + "continuing without new initialize trigger. Environment status: {}", environmentName, environment.getStatus());
                    }
                } else {
                    LOGGER.info("Environment \"{}\" has not requested for SSE with CMK.", environmentName);
                }
            }
        });
        EnvCreationEvent envCreationEvent = getEnvCreateEvent(environmentDto);
        eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.error("ResourceEncryptionInitialization failed with error.", e);
        EnvCreationFailureEvent failedEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
        Event<EnvCreationFailureEvent> ev = new Event<>(environmentDtoEvent.getHeaders(), failedEvent);
        eventBus.notify(failedEvent.selector(), ev);
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)

Example 14 with EnvCreationEvent

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

the class EnvCreationActions method networkCreationAction.

@Bean(name = "NETWORK_CREATION_STARTED_STATE")
public Action<?, ?> networkCreationAction() {
    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 Network has started. Current state is - NETWORK_CREATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.NETWORK_CREATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_NETWORK_CREATION_STARTED);
                sendEvent(context, CREATE_NETWORK_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment network creation action went failed with  EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_NETWORK_CREATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create network 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)

Example 15 with EnvCreationEvent

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

the class EnvCreationActions method environmentInitAction.

@Bean(name = "ENVIRONMENT_INITIALIZATION_STATE")
public Action<?, ?> environmentInitAction() {
    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("Initialization of Environment has started. Current state is - ENVIRONMENT_INITIALIZATION_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_INITIALIZATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_INITIALIZATION_STARTED);
                sendEvent(context, INITIALIZE_ENVIRONMENT_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment init action went failed with EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_INITIALIZATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to validate environment creation request! 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