Search in sources :

Example 26 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class FreeIpaCleanupActions method cleanupFailureAction.

@Bean(name = "CLEANUP_FAILED_STATE")
public Action<?, ?> cleanupFailureAction() {
    return new AbstractFreeIpaCleanupAction<>(CleanupFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected void doExecute(FreeIpaContext context, CleanupFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Cleanup failed with payload: " + payload);
            String environmentCrn = payload.getEnvironmentCrn();
            SuccessDetails successDetails = new SuccessDetails(environmentCrn);
            successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
            String message = "Cleanup failed during " + payload.getFailedPhase();
            FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
            if (payload.getFailureDetails() != null) {
                failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
            }
            operationService.failOperation(payload.getAccountId(), payload.getOperationId(), message, List.of(successDetails), List.of(failureDetails));
            sendEvent(context, FreeIpaCleanupEvent.CLEANUP_FAILURE_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<CleanupFailureEvent>> payloadConverters) {
            payloadConverters.add(new RemoveDnsResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveHostsResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveRolesResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveUsersResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RevokeCertsResponseToCleanupFailureEventConverter());
            payloadConverters.add(new RemoveVaultEntriesResponseToCleanupFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) RemoveDnsResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveDnsResponseToCleanupFailureEventConverter) RemoveRolesResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveRolesResponseToCleanupFailureEventConverter) RemoveVaultEntriesResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveVaultEntriesResponseToCleanupFailureEventConverter) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) RemoveUsersResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveUsersResponseToCleanupFailureEventConverter) RevokeCertsResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RevokeCertsResponseToCleanupFailureEventConverter) RemoveHostsResponseToCleanupFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.RemoveHostsResponseToCleanupFailureEventConverter) ArrayList(java.util.ArrayList) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) CleanupFailureEvent(com.sequenceiq.freeipa.flow.freeipa.cleanup.event.failure.CleanupFailureEvent) Bean(org.springframework.context.annotation.Bean)

Example 27 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class ChangePrimaryGatewayActions method failureAction.

@Bean(name = "CHANGE_PRIMARY_GATEWAY_FAIL_STATE")
public Action<?, ?> failureAction() {
    return new AbstractChangePrimaryGatewayAction<>(ChangePrimaryGatewayFailureEvent.class) {

        @Inject
        private OperationService operationService;

        @Override
        protected ChangePrimaryGatewayContext createFlowContext(FlowParameters flowParameters, StateContext<ChangePrimaryGatewayState, ChangePrimaryGatewayFlowEvent> stateContext, ChangePrimaryGatewayFailureEvent payload) {
            Flow flow = getFlow(flowParameters.getFlowId());
            flow.setFlowFailed(payload.getException());
            return super.createFlowContext(flowParameters, stateContext, payload);
        }

        @Override
        protected void doExecute(ChangePrimaryGatewayContext context, ChangePrimaryGatewayFailureEvent payload, Map<Object, Object> variables) {
            LOGGER.error("Change primary gateway failed with payload: " + payload);
            Stack stack = context.getStack();
            String environmentCrn = stack.getEnvironmentCrn();
            SuccessDetails successDetails = new SuccessDetails(environmentCrn);
            successDetails.getAdditionalDetails().put(payload.getFailedPhase(), payload.getSuccess() == null ? List.of() : new ArrayList<>(payload.getSuccess()));
            String message = "Change primary gateway failed during " + payload.getFailedPhase();
            FailureDetails failureDetails = new FailureDetails(environmentCrn, message);
            if (payload.getFailureDetails() != null) {
                failureDetails.getAdditionalDetails().putAll(payload.getFailureDetails());
            }
            String errorReason = getErrorReason(payload.getException());
            stackUpdater.updateStackStatus(context.getStack().getId(), DetailedStackStatus.REPAIR_FAILED, errorReason);
            operationService.failOperation(stack.getAccountId(), getOperationId(variables), message, List.of(successDetails), List.of(failureDetails));
            LOGGER.info("Enabling the status checker for stack ID {} after failing repairing", stack.getId());
            enableStatusChecker(stack, "Failed to repair FreeIPA");
            enableNodeStatusChecker(stack, "Failed to repair FreeIPA");
            sendEvent(context, FAIL_HANDLED_EVENT.event(), payload);
        }

        @Override
        protected void initPayloadConverterMap(List<PayloadConverter<ChangePrimaryGatewayFailureEvent>> payloadConverters) {
            payloadConverters.add(new ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter());
            payloadConverters.add(new HealthCheckFailedToChangePrimaryGatewayFailureEventConverter());
        }
    };
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) ChangePrimaryGatewayFailureEvent(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.event.ChangePrimaryGatewayFailureEvent) HealthCheckFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.HealthCheckFailedToChangePrimaryGatewayFailureEventConverter) StateContext(org.springframework.statemachine.StateContext) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Flow(com.sequenceiq.flow.core.Flow) Stack(com.sequenceiq.freeipa.entity.Stack) FlowParameters(com.sequenceiq.flow.core.FlowParameters) ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.failure.ClusterProxyUpdateRegistrationFailedToChangePrimaryGatewayFailureEventConverter) ChangePrimaryGatewayContext(com.sequenceiq.freeipa.flow.freeipa.repair.changeprimarygw.ChangePrimaryGatewayContext) ArrayList(java.util.ArrayList) List(java.util.List) OperationService(com.sequenceiq.freeipa.service.operation.OperationService) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean)

Example 28 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class PasswordService method internalSetPasswords.

private void internalSetPasswords(String operationId, String accountId, String userCrn, String password, List<Stack> stacks) {
    try {
        String userId = getUserIdFromUserCrn(userCrn);
        Optional<Instant> expirationInstant = calculateExpirationTime(userCrn, accountId);
        List<SetPasswordRequest> requests = new ArrayList<>();
        for (Stack stack : stacks) {
            requests.add(triggerSetPassword(stack, stack.getEnvironmentCrn(), userId, userCrn, password, expirationInstant));
        }
        List<SuccessDetails> success = new ArrayList<>();
        List<FailureDetails> failure = new ArrayList<>();
        for (SetPasswordRequest request : requests) {
            try {
                waitSetPassword(request);
                success.add(new SuccessDetails(request.getEnvironment()));
            } catch (InterruptedException e) {
                LOGGER.error("Interrupted while setting passwords for user {} in account {}", userCrn, accountId);
                throw e;
            } catch (Exception e) {
                LOGGER.debug("Failed to set password for user {} in environment {}", userCrn, request.getEnvironment(), e);
                failure.add(new FailureDetails(request.getEnvironment(), e.getLocalizedMessage()));
            }
        }
        operationService.completeOperation(accountId, operationId, success, failure);
    } catch (InterruptedException e) {
        operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
        Thread.currentThread().interrupt();
    } catch (RuntimeException e) {
        operationService.failOperation(accountId, operationId, e.getLocalizedMessage());
        throw e;
    }
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Instant(java.time.Instant) ArrayList(java.util.ArrayList) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) OperationException(com.sequenceiq.cloudbreak.service.OperationException) Stack(com.sequenceiq.freeipa.entity.Stack) SetPasswordRequest(com.sequenceiq.freeipa.flow.freeipa.user.event.SetPasswordRequest)

Example 29 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class CoreImageProvider method getImages.

@Override
public List<ImageWrapper> getImages(ImageSettingsRequest imageSettings, String region, String platform) {
    try {
        ImagesV4Response imagesV4Response = imageCatalogV4Endpoint.getImagesByName(WORKSPACE_ID_DEFAULT, imageSettings.getCatalog(), null, platform, null, null, false);
        LOGGER.debug("Images received: {}", imagesV4Response);
        return Optional.ofNullable(imagesV4Response.getFreeipaImages()).orElseGet(List::of).stream().map(this::convert).flatMap(Optional::stream).map(img -> new ImageWrapper(img, null, imageSettings.getCatalog())).collect(Collectors.toList());
    } catch (WebApplicationException e) {
        String errorMessage = messageExtractor.getErrorMessage(e);
        LOGGER.warn("Fetching images failed with: {}", errorMessage, e);
        return List.of();
    } catch (Exception e) {
        LOGGER.warn("Fetching images failed", e);
        return List.of();
    }
}
Also used : ImageSettingsRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.image.ImageSettingsRequest) Logger(org.slf4j.Logger) ImageCatalogV4Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.ImageCatalogV4Endpoint) LoggerFactory(org.slf4j.LoggerFactory) WebApplicationExceptionMessageExtractor(com.sequenceiq.cloudbreak.common.exception.WebApplicationExceptionMessageExtractor) ImageV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Service(org.springframework.stereotype.Service) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) Image(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.image.Image) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) ImageWrapper(com.sequenceiq.freeipa.dto.ImageWrapper) ImagesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImagesV4Response) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 30 with FAILED

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus.FAILED in project cloudbreak by hortonworks.

the class CleanupService method removeVaultEntries.

@Retryable(value = RetryableFreeIpaClientException.class, maxAttemptsExpression = RetryableFreeIpaClientException.MAX_RETRIES_EXPRESSION, backoff = @Backoff(delayExpression = RetryableFreeIpaClientException.DELAY_EXPRESSION, multiplierExpression = RetryableFreeIpaClientException.MULTIPLIER_EXPRESSION))
public Pair<Set<String>, Map<String, String>> removeVaultEntries(Long stackId, Set<String> hosts) throws FreeIpaClientException {
    Set<String> vaultCleanupSuccess = new HashSet<>();
    Map<String, String> vaultCleanupFailed = new HashMap<>();
    Stack stack = stackService.getStackById(stackId);
    FreeIpaClient freeIpaClient = getFreeIpaClient(stackId);
    for (String host : hosts) {
        try {
            HostRequest hostRequest = new HostRequest();
            hostRequest.setEnvironmentCrn(stack.getEnvironmentCrn());
            hostRequest.setServerHostName(host);
            keytabCleanupService.removeHostRelatedKerberosConfiguration(hostRequest, stack.getAccountId(), freeIpaClient);
            vaultCleanupSuccess.add(host);
        } catch (DeleteException | FreeIpaClientException e) {
            LOGGER.info("Vault secret cleanup failed for host: {}", host, e);
            vaultCleanupFailed.put(host, e.getMessage());
        }
    }
    return Pair.of(vaultCleanupSuccess, vaultCleanupFailed);
}
Also used : HashMap(java.util.HashMap) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) DeleteException(com.sequenceiq.freeipa.kerberosmgmt.exception.DeleteException) RetryableFreeIpaClientException(com.sequenceiq.freeipa.client.RetryableFreeIpaClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) HashSet(java.util.HashSet) Stack(com.sequenceiq.freeipa.entity.Stack) HostRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.HostRequest) Retryable(org.springframework.retry.annotation.Retryable)

Aggregations

Stack (com.sequenceiq.freeipa.entity.Stack)12 WebApplicationException (javax.ws.rs.WebApplicationException)11 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)9 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Map (java.util.Map)7 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)6 Bean (org.springframework.context.annotation.Bean)6 OperationStatus (com.sequenceiq.freeipa.api.v1.operation.model.OperationStatus)5 FreeIpaOperationFailedException (com.sequenceiq.environment.exception.FreeIpaOperationFailedException)4 FlowParameters (com.sequenceiq.flow.core.FlowParameters)4 SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)4 StateContext (org.springframework.statemachine.StateContext)4 Flow (com.sequenceiq.flow.core.Flow)3 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)3 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)3 Test (org.junit.jupiter.api.Test)3 ImageV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.imagecatalog.responses.ImageV4Response)2