Search in sources :

Example 6 with EnvCreationFailureEvent

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

the class EnvironmentValidationHandler method goToFailedState.

private void goToFailedState(Event<EnvironmentValidationDto> environmentDtoEvent, String message) {
    LOGGER.warn("Environment validation failed: {}", message);
    EnvironmentDto environmentDto = environmentDtoEvent.getData().getEnvironmentDto();
    EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), new BadRequestException(message), environmentDto.getResourceCrn());
    eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)

Example 7 with EnvCreationFailureEvent

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

the class NetworkCreationHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            setChildEnvironmentNetworkIfItHasParentWithTheSameCloudProvider(environmentDto);
            Map<String, CloudSubnet> subnetMetas = null;
            Map<String, CloudSubnet> endpointGatewaySubnetMetas = null;
            if (environmentDto.getNetwork() != null) {
                LOGGER.debug("Environment ({}) dto has network, hence we're filling it's related subnet fields", environment.getName());
                subnetMetas = cloudNetworkService.retrieveSubnetMetadata(environmentDto, environmentDto.getNetwork());
                environmentDto.getNetwork().setSubnetMetas(subnetMetas);
                endpointGatewaySubnetMetas = networkValidationService.getEndpointGatewaySubnetMetadata(environment, environmentDto);
                environmentDto.getNetwork().setEndpointGatewaySubnetMetas(endpointGatewaySubnetMetas);
                environmentResourceService.createAndSetNetwork(environment, environmentDto.getNetwork(), environment.getAccountId(), environmentDto.getNetwork().getSubnetMetas(), environmentDto.getNetwork().getEndpointGatewaySubnetMetas());
            } else {
                LOGGER.debug("Environment ({}) dto has no network!", environment.getName());
            }
            createCloudNetworkIfNeeded(environmentDto, environment);
            createProviderSpecificNetworkResourcesIfNeeded(environmentDto, environment.getNetwork());
            environmentService.save(environment);
        });
        initiateNextStep(environmentDtoEvent, environmentDto);
    } catch (Exception e) {
        EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(environmentDto.getId(), environmentDto.getName(), e, environmentDto.getResourceCrn());
        eventBus.notify(failureEvent.selector(), new Event<>(environmentDtoEvent.getHeaders(), failureEvent));
    }
}
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) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet)

Example 8 with EnvCreationFailureEvent

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

the class PublicKeyCreationHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("Accepting PublicKeyCreation event");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        environmentService.findEnvironmentById(environmentDto.getId()).ifPresent(environment -> {
            if (environment.getAuthentication().isManagedKey()) {
                boolean created = environmentResourceService.createAndUpdateSshKey(environment);
                if (created) {
                    String publicKeyId = environment.getAuthentication().getPublicKeyId();
                    LOGGER.info("Update the environment and it's authentication with the created public SSH key id: '{}'", publicKeyId);
                    environmentService.save(environment);
                } else {
                    LOGGER.info("The public key id could not be created for {}", environmentDto.getName());
                }
            } else {
                LOGGER.debug("Environment {} requested no managed public key", environment.getName());
            }
        });
        EnvCreationEvent envCreationEvent = getEnvCreateEvent(environmentDto);
        eventSender().sendEvent(envCreationEvent, environmentDtoEvent.getHeaders());
    } catch (Exception 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) EnvCreationEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationEvent) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent)

Example 9 with EnvCreationFailureEvent

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

the class EnvCreationActions method environmentValidationAction.

@Bean(name = "ENVIRONMENT_CREATION_VALIDATION_STATE")
public Action<?, ?> environmentValidationAction() {
    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("Validation of Environment has started. Current state is - ENVIRONMENT_CREATION_VALIDATION_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_VALIDATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_VALIDATION_STARTED);
                EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).withValidationType(ValidationType.ENVIRONMENT_CREATION).build();
                sendEvent(context, VALIDATE_ENVIRONMENT_EVENT.selector(), environmentValidationDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment validation action went failed with EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_VALIDATION_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) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) EnvCreationFailureEvent(com.sequenceiq.environment.environment.flow.creation.event.EnvCreationFailureEvent) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 10 with EnvCreationFailureEvent

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

the class EnvCreationActions method resourceEncryptionInitializationAction.

@Bean(name = "ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED_STATE")
public Action<?, ?> resourceEncryptionInitializationAction() {
    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 resource encryption has started." + " Current state is - ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED_STATE");
                environment.setStatus(EnvironmentStatus.ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_IN_PROGRESS);
                environment.setStatusReason(null);
                environment = environmentService.save(environment);
                EnvironmentDto environmentDto = environmentService.getEnvironmentDto(environment);
                eventService.sendEventAndNotification(environmentDto, context.getFlowTriggerUserCrn(), ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_STARTED);
                sendEvent(context, INITIALIZE_ENVIRONMENT_RESOURCE_ENCRYPTION_EVENT.selector(), environmentDto);
            }, () -> {
                EnvCreationFailureEvent failureEvent = new EnvCreationFailureEvent(payload.getResourceId(), payload.getResourceName(), null, payload.getResourceCrn());
                LOGGER.debug("Environment encryption init action went failed with  EnvCreationFailureEvent was: {}", failureEvent);
                eventService.sendEventAndNotificationForMissingEnv(payload, ENVIRONMENT_RESOURCE_ENCRYPTION_INITIALIZATION_FAILED, context.getFlowTriggerUserCrn());
                LOGGER.warn("Failed to create encryption resources 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