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