Search in sources :

Example 16 with EnvCreationFailureEvent

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

the class FreeIpaCreationHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    Optional<Environment> environmentOptional = environmentService.findEnvironmentById(environmentDto.getId());
    try {
        if (environmentOptional.isPresent()) {
            Environment environment = environmentOptional.get();
            if (Objects.nonNull(environment.getParentEnvironment())) {
                attachParentFreeIpa(environmentDto);
            } else if (environment.isCreateFreeIpa() && supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform())) {
                createFreeIpa(environmentDtoEvent, environmentDto);
            } else {
                boolean supported = supportedPlatforms.supportedPlatformForFreeIpa(environment.getCloudPlatform());
                LOGGER.info("Freeipa won't create: parent: {}, create freeipa: {}, {} provider is supproted: {}", environment.getParentEnvironment(), environment.isCreateFreeIpa(), environment.getCloudPlatform(), supported);
            }
        }
        eventSender().sendEvent(getNextStepObject(environmentDto), environmentDtoEvent.getHeaders());
    } catch (Exception ex) {
        LOGGER.error(String.format("Error occurred during creating FreeIpa for environment %s.", environmentDto), ex);
        EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), ex, environmentDto.getResourceCrn());
        eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
    }
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) Event(reactor.bus.Event) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Example 17 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent 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 18 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent 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)

Example 19 with EnvCreationFailureEvent

use of com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent 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

EnvCreationFailureEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)19 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)14 EnvCreationEvent (com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent)12 CommonContext (com.sequenceiq.flow.core.CommonContext)7 Map (java.util.Map)7 Bean (org.springframework.context.annotation.Bean)7 Event (reactor.bus.Event)7 Environment (com.sequenceiq.environment.environment.domain.Environment)3 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)3 Test (org.junit.jupiter.api.Test)3 CloudSubnet (com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)2 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)2 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)1 NetworkTest (com.sequenceiq.environment.environment.service.network.NetworkTest)1 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)1 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)1 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)1 BadRequestException (javax.ws.rs.BadRequestException)1