Search in sources :

Example 11 with FreeIpaOperationFailedException

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());
    }
}
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 12 with FreeIpaOperationFailedException

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

Example 13 with FreeIpaOperationFailedException

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());
        });
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)

Aggregations

FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)13 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)4 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)3 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)2 EnvStartEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartEvent)2 EnvStartFailedEvent (com.sequenceiq.environment.environment.flow.start.event.EnvStartFailedEvent)2 NotFoundException (javax.ws.rs.NotFoundException)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 FreeIpaPollerObject (com.sequenceiq.environment.environment.flow.creation.handler.freeipa.FreeIpaPollerObject)1 EnvStopEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopEvent)1 EnvStopFailedEvent (com.sequenceiq.environment.environment.flow.stop.event.EnvStopFailedEvent)1 UpgradeCcmEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent)1 UpgradeCcmFailedEvent (com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent)1 DetachChildEnvironmentRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.detachchildenv.DetachChildEnvironmentRequest)1 Test (org.junit.jupiter.api.Test)1