Search in sources :

Example 1 with FreeIpaOperationFailedException

use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException in project cloudbreak by hortonworks.

the class FreeIpaServiceTest method internalDescribeApiNotFoundTest.

@Test
void internalDescribeApiNotFoundTest() {
    when(freeIpaV1Endpoint.describeInternal(eq(ENVCRN), eq("1111"))).thenThrow(new javax.ws.rs.NotFoundException());
    FreeIpaOperationFailedException freeIpaOperationFailedException = Assertions.assertThrows(FreeIpaOperationFailedException.class, () -> underTest.internalDescribe(ENVCRN, "1111"));
    String errorMessage = freeIpaOperationFailedException.getMessage();
    assertThat(errorMessage).isEqualTo("Freeipa internal describe response is NOT FOUND, but response reason is not the expected type");
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) NotFoundException(javax.ws.rs.NotFoundException) Test(org.junit.jupiter.api.Test)

Example 2 with FreeIpaOperationFailedException

use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException in project cloudbreak by hortonworks.

the class FreeIpaDeletionHandler method deleteFreeIpa.

private void deleteFreeIpa(Environment environment, boolean forced) {
    freeIpaService.delete(environment.getResourceCrn(), forced);
    ExtendedPollingResult result = freeIpaPollingService.pollWithTimeout(new FreeIpaDeletionRetrievalTask(freeIpaService), new FreeIpaPollerObject(environment.getId(), environment.getResourceCrn()), FreeIpaDeletionRetrievalTask.FREEIPA_RETRYING_INTERVAL, FreeIpaDeletionRetrievalTask.FREEIPA_RETRYING_COUNT, FreeIpaDeletionRetrievalTask.FREEIPA_FAILURE_COUNT);
    if (!result.isSuccess()) {
        String message = "Failed to delete FreeIpa! (" + result.getPollingResult().name() + ") " + getIfNotNull(result.getException(), Throwable::getMessage);
        LOGGER.info(message);
        throw new FreeIpaOperationFailedException(message);
    }
}
Also used : FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) FreeIpaPollerObject(com.sequenceiq.environment.environment.flow.creation.handler.freeipa.FreeIpaPollerObject)

Example 3 with FreeIpaOperationFailedException

use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException in project cloudbreak by hortonworks.

the class FreeIpaDeletionRetrievalTask method checkStatus.

@Override
public boolean checkStatus(FreeIpaPollerObject freeIpaPollerObject) {
    String environmentCrn = freeIpaPollerObject.getEnvironmentCrn();
    try {
        LOGGER.info("Checking the state of FreeIpa termination progress for environment: '{}'", environmentCrn);
        Optional<DescribeFreeIpaResponse> freeIpaResponse = freeIpaService.describe(environmentCrn);
        if (freeIpaResponse.isPresent()) {
            if (freeIpaResponse.get().getStatus() == Status.DELETE_FAILED) {
                throw new FreeIpaOperationFailedException("FreeIpa deletion operation failed: " + freeIpaResponse.get().getStatusReason());
            }
            if (!freeIpaResponse.get().getStatus().isSuccessfullyDeleted()) {
                return false;
            }
        } else {
            LOGGER.info("FreeIpa was not found.");
            return true;
        }
    } catch (Exception e) {
        throw new FreeIpaOperationFailedException("FreeIpa deletion operation failed. " + e.getMessage(), e);
    }
    return true;
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Example 4 with FreeIpaOperationFailedException

use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException in project cloudbreak by hortonworks.

the class UpgradeCcmOnFreeIpaHandler method accept.

@Override
public void accept(Event<EnvironmentDto> environmentDtoEvent) {
    LOGGER.debug("In UpgradeCcmOnFreeIpaHandler.accept");
    EnvironmentDto environmentDto = environmentDtoEvent.getData();
    try {
        freeIpaService.describe(environmentDto.getResourceCrn()).ifPresentOrElse(freeIpa -> {
            if (freeIpa.getStatus() == null || freeIpa.getAvailabilityStatus() == null) {
                throw new FreeIpaOperationFailedException("FreeIPA status is unpredictable, upgrading of Cluster Connectivity Manager will be interrupted.");
            } else if (!freeIpa.getStatus().isCcmUpgradeablePhase()) {
                throw new FreeIpaOperationFailedException("FreeIPA is not in a valid state to upgrade Cluster Connectivity Manager. Current state is: " + freeIpa.getStatus().name());
            } else {
                LOGGER.info("CCM on FreeIPA will be upgraded.");
                freeIpaPollerService.waitForCcmUpgrade(environmentDto.getId(), environmentDto.getResourceCrn());
            }
            UpgradeCcmEvent upgradeCcmEvent = UpgradeCcmEvent.builder().withSelector(UpgradeCcmStateSelectors.UPGRADE_CCM_TUNNEL_UPDATE_EVENT.selector()).withResourceCrn(environmentDto.getResourceCrn()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).build();
            eventSender().sendEvent(upgradeCcmEvent, environmentDtoEvent.getHeaders());
            LOGGER.debug("UPGRADE_CCM_TUNNEL_UPDATE_EVENT event sent");
        }, () -> {
            throw new FreeIpaOperationFailedException(String.format("FreeIPA cannot be found for environment %s", environmentDto.getName()));
        });
    } catch (Exception e) {
        UpgradeCcmFailedEvent failedEvent = new UpgradeCcmFailedEvent(environmentDto, e, EnvironmentStatus.UPGRADE_CCM_ON_FREEIPA_FAILED);
        eventSender().sendEvent(failedEvent, environmentDtoEvent.getHeaders());
        LOGGER.debug("UPGRADE_CCM_ON_FREEIPA_FAILED event sent");
    }
}
Also used : UpgradeCcmEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmEvent) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException) UpgradeCcmFailedEvent(com.sequenceiq.environment.environment.flow.upgrade.ccm.event.UpgradeCcmFailedEvent) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) FreeIpaOperationFailedException(com.sequenceiq.environment.exception.FreeIpaOperationFailedException)

Example 5 with FreeIpaOperationFailedException

use of com.sequenceiq.environment.exception.FreeIpaOperationFailedException in project cloudbreak by hortonworks.

the class SynchronizeUsersHandler method accept.

@Override
public void accept(Event<EnvironmentStartDto> environmentStartDtoEvent) {
    LOGGER.debug("User synchronization is {}.", synchronizeOnStartEnabled ? "enabled" : "disabled");
    EnvironmentDto environmentDto = environmentStartDtoEvent.getData().getEnvironmentDto();
    try {
        if (synchronizeOnStartEnabled) {
            freeIpaService.describe(environmentDto.getResourceCrn()).ifPresent(freeIpa -> {
                if (freeIpa.getStatus() != null && freeIpa.getAvailabilityStatus() != null && !freeIpa.getAvailabilityStatus().isAvailable()) {
                    throw new FreeIpaOperationFailedException("FreeIPA is not in AVAILABLE state to synchronize users! Current state is: " + freeIpa.getStatus().name());
                }
            });
            freeIpaPollerService.waitForSynchronizeUsers(environmentDto.getId(), environmentDto.getResourceCrn());
        }
        EnvStartEvent envStartEvent = EnvStartEvent.EnvStartEventBuilder.anEnvStartEvent().withSelector(EnvStartStateSelectors.FINISH_ENV_START_EVENT.selector()).withResourceId(environmentDto.getId()).withResourceName(environmentDto.getName()).withDataHubStart(environmentStartDtoEvent.getData().getDataHubStart()).build();
        eventSender().sendEvent(envStartEvent, environmentStartDtoEvent.getHeaders());
    } catch (Exception e) {
        EnvStartFailedEvent failedEvent = new EnvStartFailedEvent(environmentDto, e, EnvironmentStatus.START_SYNCHRONIZE_USERS_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)

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