Search in sources :

Example 6 with EnvStartFailedEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent in project cloudbreak by hortonworks.

the class EnvStartActions method failedAction.

@Bean(name = "ENV_START_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractEnvStartAction<>(EnvStartFailedEvent.class) {

        @Override
        protected void doExecute(CommonContext context, EnvStartFailedEvent payload, Map<Object, Object> variables) {
            LOGGER.warn(String.format("Failed to start environment '%s'. Status: '%s'.", payload.getEnvironmentDto(), payload.getEnvironmentStatus()), payload.getException());
            EnvironmentDto environmentDto = environmentStatusUpdateService.updateFailedEnvironmentStatusAndNotify(context, payload, payload.getEnvironmentStatus(), convertStatus(payload.getEnvironmentStatus()), EnvStartState.ENV_START_FAILED_STATE);
            metricService.incrementMetricCounter(MetricType.ENV_START_FAILED, environmentDto, payload.getException());
            sendEvent(context, HANDLED_FAILED_ENV_START_EVENT.event(), payload);
        }
    };
}
Also used : EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CommonContext(com.sequenceiq.flow.core.CommonContext) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 7 with EnvStartFailedEvent

use of com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent in project cloudbreak by hortonworks.

the class StartFreeIpaHandler method accept.

@Override
public void accept(Event<EnvironmentStartDto> environmentStartDtoEvent) {
    EnvironmentDto environmentDto = environmentStartDtoEvent.getData().getEnvironmentDto();
    try {
        freeIpaService.describe(environmentDto.getResourceCrn()).ifPresentOrElse(freeIpa -> {
            if (freeIpa.getStatus() == null || freeIpa.getAvailabilityStatus() == null) {
                throw new FreeIpaOperationFailedException("FreeIPA status is unpredictable, env start will be interrupted.");
            } else if (freeIpa.getAvailabilityStatus().isAvailable() || freeIpa.getStatus().isStartInProgressPhase()) {
                LOGGER.info("Start has already been triggered continuing without new start trigger. FreeIPA status: {}", freeIpa.getStatus());
            } else if (!freeIpa.getStatus().isStartable()) {
                throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to start! Current state is: " + freeIpa.getStatus().name());
            } else {
                LOGGER.info("FreeIPA will be started.");
                freeIpaPollerService.startAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn());
            }
        }, () -> LOGGER.info("FreeIPA cannot be found by environment crn"));
        EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent().withSelector(EnvStartStateSelectors.ENV_START_DATALAKE_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).withDataHubStart(environmentStartDtoEvent.getData().getDataHubStart()).build();
        eventSender().sendEvent(envStartEvent, environmentStartDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.warn("Failed to start Freeipa.", e);
        EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_FREEIPA_FAILED);
        eventSender().sendEvent(failedEvent, environmentStartDtoEvent.getHeaders());
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) EnvStartFailedEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent) EnvStartEvent(com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Aggregations

EnvStartFailedEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent)7 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)6 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)5 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)2 Test (org.junit.jupiter.api.Test)2 CommonContext (com.sequenceiq.flow.core.CommonContext)1 Map (java.util.Map)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 Bean (org.springframework.context.annotation.Bean)1