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);
}
};
}
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());
}
}
Aggregations