Search in sources :

Example 11 with FailureDetails

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

the class UserSyncForEnvServiceTest method testSyncUsersFailures.

@Test
public void testSyncUsersFailures() {
    Stack stack1 = mock(Stack.class);
    when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
    Stack stack2 = mock(Stack.class);
    when(stack2.getEnvironmentCrn()).thenReturn(ENV_CRN_2);
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(), Set.of(), Optional.empty());
    UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
    doAnswer(inv -> {
        inv.getArgument(2, Runnable.class).run();
        return null;
    }).when(operationService).tryWithOperationCleanup(eq(OPERATION_ID), eq(ACCOUNT_ID), any(Runnable.class));
    UmsUsersState umsUsersState1 = mock(UmsUsersState.class);
    UmsUsersState umsUsersState2 = mock(UmsUsersState.class);
    when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN, ENV_CRN_2)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1, ENV_CRN_2, umsUsersState2));
    when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
        SyncStatusDetail result = (SyncStatusDetail) inv.getArgument(0, Callable.class).call();
        Future future = mock(Future.class);
        when(future.get()).thenReturn(result);
        return future;
    });
    when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
    when(userSyncForStackService.synchronizeStack(stack1, umsUsersState1, options)).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.FAILED, "fial1", ImmutableMultimap.of(ENV_CRN, "failed1")));
    when(userSyncForStackService.synchronizeStack(stack2, umsUsersState2, options)).thenReturn(new SyncStatusDetail(ENV_CRN_2, SynchronizationStatus.REJECTED, "fial2", ImmutableMultimap.of(ENV_CRN_2, "failed2")));
    underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1, stack2), userSyncFilter, options, System.currentTimeMillis());
    verifyNoInteractions(userSyncStatusService);
    ArgumentCaptor<Collection> successCaptor = ArgumentCaptor.forClass(Collection.class);
    ArgumentCaptor<Collection> failureCaptor = ArgumentCaptor.forClass(Collection.class);
    verify(operationService).completeOperation(eq(ACCOUNT_ID), eq(OPERATION_ID), successCaptor.capture(), failureCaptor.capture());
    assertTrue(successCaptor.getValue().isEmpty());
    List<FailureDetails> failures = (List<FailureDetails>) failureCaptor.getValue();
    assertThat(failures, allOf(hasItem(allOf(hasProperty("environment", is(ENV_CRN)), hasProperty("message", is("fial1")), hasProperty("additionalDetails", hasEntry(ENV_CRN, "failed1")))), hasItem(allOf(hasProperty("environment", is(ENV_CRN_2)), hasProperty("message", is("Unexpected status: REJECTED")), hasProperty("additionalDetails", hasEntry(ENV_CRN_2, "failed2"))))));
}
Also used : Optional(java.util.Optional) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) Callable(java.util.concurrent.Callable) Stack(com.sequenceiq.freeipa.entity.Stack) UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) Future(java.util.concurrent.Future) Collection(java.util.Collection) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 12 with FailureDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails 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 13 with FailureDetails

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails 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 14 with FailureDetails

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

the class UserSyncForEnvService method createFailureDetails.

private FailureDetails createFailureDetails(String envCrn, String details, Multimap<String, String> warnings) {
    FailureDetails failureDetails = new FailureDetails(envCrn, details);
    Map<String, String> additionalDetails = failureDetails.getAdditionalDetails();
    warnings.asMap().forEach((key, value) -> additionalDetails.put(key, String.join(", ", value)));
    return failureDetails;
}
Also used : FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)

Example 15 with FailureDetails

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

the class UserSyncService method createFailureDetails.

private FailureDetails createFailureDetails(String envCrn, String details, Multimap<String, String> warnings) {
    FailureDetails failureDetails = new FailureDetails(envCrn, details);
    Map<String, String> additionalDetails = failureDetails.getAdditionalDetails();
    warnings.asMap().entrySet().forEach(entry -> additionalDetails.put(entry.getKey(), entry.getValue().stream().collect(Collectors.joining(", "))));
    return failureDetails;
}
Also used : FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)

Aggregations

FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)15 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)9 Stack (com.sequenceiq.freeipa.entity.Stack)9 List (java.util.List)8 ArrayList (java.util.ArrayList)7 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)5 Map (java.util.Map)5 Test (org.junit.jupiter.api.Test)5 Bean (org.springframework.context.annotation.Bean)5 FlowParameters (com.sequenceiq.flow.core.FlowParameters)4 Optional (java.util.Optional)4 StateContext (org.springframework.statemachine.StateContext)4 Flow (com.sequenceiq.flow.core.Flow)3 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)3 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)3 Future (java.util.concurrent.Future)3 Operation (com.sequenceiq.freeipa.entity.Operation)2 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)2 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)2 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)2