Search in sources :

Example 11 with SuccessDetails

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

the class SyncOperationToOperationStatusConverterTest method convertCompleted.

@Test
void convertCompleted() {
    OperationState operationState = OperationState.COMPLETED;
    SynchronizationStatus synchronizationStatus = SynchronizationStatus.fromOperationState(operationState);
    List<SuccessDetails> successDetails = List.of(new SuccessDetails("environment1"), new SuccessDetails("environment2"));
    List<FailureDetails> failureDetails = List.of(new FailureDetails("environment3", "failure message1"), new FailureDetails("environment4", "failure message2"));
    Operation operation = createSyncOperation(operationState);
    operation.setSuccessList(successDetails);
    operation.setFailureList(failureDetails);
    SyncOperationStatus actual = underTest.convert(operation);
    assertEqualsDefaults(actual);
    assertEquals(synchronizationStatus, actual.getStatus());
    assertEquals(successDetails, actual.getSuccess());
    assertEquals(failureDetails, actual.getFailure());
    assertNull(actual.getError());
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) SynchronizationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) Test(org.junit.jupiter.api.Test)

Example 12 with SuccessDetails

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

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

the class UserSyncForEnvServiceTest method testSyncUserDelete.

@Test
public void testSyncUserDelete() {
    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.of("deleteMe"));
    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));
    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(userSyncForStackService.synchronizeStackForDeleteUser(stack1, "deleteMe")).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
    when(userSyncForStackService.synchronizeStackForDeleteUser(stack2, "deleteMe")).thenReturn(new SyncStatusDetail(ENV_CRN_2, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
    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(failureCaptor.getValue().isEmpty());
    assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN)));
    assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN_2)));
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) 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) Callable(java.util.concurrent.Callable) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 14 with SuccessDetails

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

the class UserSyncForEnvServiceTest method testSyncUsersDoesntTimeout.

@Test
public void testSyncUsersDoesntTimeout() {
    ReflectionTestUtils.setField(underTest, "operationTimeout", 0L);
    Stack stack1 = mock(Stack.class);
    when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
    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);
    when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1));
    when(userSyncForStackService.synchronizeStack(stack1, umsUsersState1, options)).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
    Future<SyncStatusDetail> future = mock(Future.class);
    when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
        SyncStatusDetail result = (SyncStatusDetail) inv.getArgument(0, Callable.class).call();
        when(future.get(anyLong(), eq(TimeUnit.MILLISECONDS))).thenReturn(result);
        return future;
    });
    when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
    when(userSyncStatusService.getOrCreateForStack(stack1)).thenReturn(new UserSyncStatus());
    when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1), userSyncFilter, options, System.currentTimeMillis());
    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());
    verify(future, never()).cancel(true);
    verify(future, never()).cancel(false);
    assertTrue(failureCaptor.getValue().isEmpty());
    assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN)));
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) Optional(java.util.Optional) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) 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) Collection(java.util.Collection) Test(org.junit.jupiter.api.Test)

Example 15 with SuccessDetails

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

the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessNotInSync.

@Test
void internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessNotInSync() {
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    Operation lastSync = new Operation();
    lastSync.setOperationId(UUID.randomUUID().toString());
    lastSync.setStatus(OperationState.COMPLETED);
    lastSync.setSuccessList(List.of(new SuccessDetails(ENVIRONMENT_CRN)));
    userSyncStatus.setLastStartedFullSync(lastSync);
    UmsEventGenerationIds current = new UmsEventGenerationIds();
    when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any())).thenReturn(current);
    when(eventGenerationIdsChecker.isInSync(userSyncStatus, current)).thenReturn(false);
    EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
    assertEquals(UserSyncState.STALE, result.getState());
    assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) EnvironmentUserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState) Test(org.junit.jupiter.api.Test)

Aggregations

SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)24 Stack (com.sequenceiq.freeipa.entity.Stack)14 OperationService (com.sequenceiq.freeipa.service.operation.OperationService)12 Map (java.util.Map)12 Bean (org.springframework.context.annotation.Bean)12 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)10 ArrayList (java.util.ArrayList)8 List (java.util.List)6 Test (org.junit.jupiter.api.Test)6 FlowParameters (com.sequenceiq.flow.core.FlowParameters)5 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)5 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)5 StateContext (org.springframework.statemachine.StateContext)5 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)4 StackContext (com.sequenceiq.freeipa.flow.stack.StackContext)4 Optional (java.util.Optional)4 Future (java.util.concurrent.Future)4 Flow (com.sequenceiq.flow.core.Flow)3 StackEvent (com.sequenceiq.freeipa.flow.stack.StackEvent)3 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)2