Search in sources :

Example 1 with EnvStopFailedEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent in project cloudbreak by hortonworks.

the class StopDatahubHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        datahubPollerService.stopAttachedDatahubClusters(environmentDto.getId(), environmentDto.getResourceCrn());
        EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent().withSelector(EnvStopStateSelectors.ENV_STOP_DATALAKE_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_DATAHUB_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)

Example 2 with EnvStopFailedEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent in project cloudbreak by hortonworks.

the class StopDatalakeHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        sdxPollerService.stopAttachedDatalakeClusters(environmentDto.getId(), environmentDto.getName());
        EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent().withSelector(EnvStopStateSelectors.ENV_STOP_FREEIPA_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_DATALAKE_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)

Example 3 with EnvStopFailedEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent in project cloudbreak by hortonworks.

the class StopFreeIpaHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        if (Strings.isNullOrEmpty(environmentDto.getParentEnvironmentCrn())) {
            freeIpaService.describe(environmentDto.getResourceCrn()).ifPresentOrElse(freeIpa -> {
                if (freeIpa.getStatus() == null) {
                    throw new FreeIpaOperationFailedException("FreeIPA status is unpredictable, env stop will be interrupted.");
                } else if (freeIpa.getStatus().isStoppedPhase() || freeIpa.getStatus().isStopInProgressPhase()) {
                    LOGGER.info("Stop has already been triggered continuing without new stop trigger. FreeIPA status: {}", freeIpa.getStatus());
                } else if (!freeIpa.getStatus().isStoppable()) {
                    throw new FreeIpaOperationFailedException("FreeIPA is not in a stoppable state! Current state is: " + freeIpa.getStatus().name());
                } else {
                    LOGGER.info("FreeIPA will be stopped.");
                    freeIpaPollerService.stopAttachedFreeipaInstances(environmentDto.getId(), environmentDto.getResourceCrn());
                }
            }, () -> LOGGER.info("FreeIPA cannot be found by environment crn"));
        }
        EnvStopEvent envStopEvent = EnvStopEvent.EnvStopEventBuilder.anEnvStopEvent().withSelector(EnvStopStateSelectors.FINISH_ENV_STOP_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
        eventSender().sendEvent(envStopEvent, environmentDtoEvent.getHeaders());
    } catch (Exception e) {
        LOGGER.warn("Failed to stop Freeipa.", e);
        EnvStopFailedEvent failedEvent = new EnvStopFailedEvent(environmentDto, e, EnvironmentStatus.STOP_FREEIPA_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) EnvStopEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) EnvStopFailedEvent(com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)

Example 4 with EnvStopFailedEvent

use of com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent in project cloudbreak by hortonworks.

the class EnvStopActions method failedAction.

@Bean(name = "ENV_STOP_FAILED_STATE")
public Action<?, ?> failedAction() {
    return new AbstractEnvStopAction<>(EnvStopFailedEvent.class) {

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

Aggregations

EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 EnvStopFailedEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)4 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)3 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)1 CommonContext (com.sequenceiq.flow.core.CommonContext)1 Map (java.util.Map)1 Bean (org.springframework.context.annotation.Bean)1