use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException 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.exception.FreeIpaOperationFailedException 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());
}
}
use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException in project cloudbreak by hortonworks.
the class FreeIpaCreationHandler method awaitFreeIpaCreation.
private void awaitFreeIpaCreation(Event<EnvironmentDto> environmentDtoEvent, EnvironmentDto environment) {
ExtendedPollingResult pollWithTimeout = freeIpaPollingService.pollWithTimeout(new FreeIpaCreationRetrievalTask(freeIpaService), new FreeIpaPollerObject(environment.getId(), environment.getResourceCrn()), FreeIpaCreationRetrievalTask.FREEIPA_RETRYING_INTERVAL, FreeIpaCreationRetrievalTask.FREEIPA_RETRYING_COUNT, FreeIpaCreationRetrievalTask.FREEIPA_FAILURE_COUNT);
if (pollWithTimeout.isSuccess()) {
eventSender().sendEvent(getNextStepObject(environment), environmentDtoEvent.getHeaders());
} else {
LOGGER.info("FreeIPA creation polling has stopped due to the unsuccessful state/result: {}", pollWithTimeout.getPollingResult());
Optional.ofNullable(pollWithTimeout.getException()).ifPresentOrElse(e -> {
throw new FreeIpaOperationFailedException(e.getMessage());
}, () -> {
throw new FreeIpaOperationFailedException("Polling result was: " + pollWithTimeout.getPollingResult());
});
}
}
Aggregations