Search in sources :

Example 21 with UserSyncStatus

use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.

the class UserSyncServiceTest method testSyncUsersWithTimeoutCheckTaskFinished.

@Test
public void testSyncUsersWithTimeoutCheckTaskFinished() {
    Stack stack = mock(Stack.class);
    when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
    when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(Set.of(), ACCOUNT_ID)).thenReturn(List.of(stack));
    Operation operation = createRunningOperation();
    when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
    doAnswer(inv -> {
        Runnable runnable = inv.getArgument(2, Runnable.class);
        runnable.run();
        return null;
    }).when(operationService).tryWithOperationCleanup(eq(operation.getOperationId()), eq(ACCOUNT_ID), any(Runnable.class));
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(INTERNAL_ACTOR);
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    when(userSyncStatusService.getOrCreateForStack(stack)).thenReturn(userSyncStatus);
    when(entitlementService.usersyncCredentialsUpdateOptimizationEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    when(entitlementService.isFmsToFreeipaBatchCallEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
    ReflectionTestUtils.setField(underTest, "operationTimeout", TIMEOUT);
    Future<?> usersyncTask = mock(Future.class);
    doAnswer(inv -> {
        Runnable runnable = inv.getArgument(0, Runnable.class);
        assertEquals(operation.getOperationId(), MDCBuilder.getMdcContextMap().get(LoggerContextKey.OPERATION_ID.toString()));
        assertEquals(INTERNAL_ACTOR, ThreadBasedUserCrnProvider.getUserCrn());
        runnable.run();
        return usersyncTask;
    }).when(asyncTaskExecutor).submit(any(Runnable.class));
    doAnswer(inv -> {
        Runnable runnable = inv.getArgument(0, Runnable.class);
        runnable.run();
        return null;
    }).when(scheduledExecutorService).schedule(any(Runnable.class), eq(TIMEOUT), eq(TimeUnit.MILLISECONDS));
    when(usersyncTask.isDone()).thenReturn(Boolean.TRUE);
    Operation result = underTest.synchronizeUsers(ACCOUNT_ID, ACTOR_CRN, Set.of(), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
    assertEquals(operation, result);
    ArgumentCaptor<UserSyncRequestFilter> requestFilterCaptor = ArgumentCaptor.forClass(UserSyncRequestFilter.class);
    verify(userSyncRequestValidator).validateParameters(eq(ACCOUNT_ID), eq(ACTOR_CRN), eq(Set.of()), requestFilterCaptor.capture());
    UserSyncRequestFilter requestFilter = requestFilterCaptor.getValue();
    assertTrue(requestFilter.getUserCrnFilter().isEmpty());
    assertTrue(requestFilter.getMachineUserCrnFilter().isEmpty());
    assertTrue(requestFilter.getDeletedWorkloadUser().isEmpty());
    assertEquals(operation, userSyncStatus.getLastStartedFullSync());
    verify(userSyncStatusService).save(userSyncStatus);
    ArgumentCaptor<UserSyncOptions> syncOptionsCaptor = ArgumentCaptor.forClass(UserSyncOptions.class);
    verify(userSyncForEnvService).synchronizeUsers(eq(operation.getOperationId()), eq(ACCOUNT_ID), eq(List.of(stack)), eq(requestFilter), syncOptionsCaptor.capture(), anyLong());
    UserSyncOptions userSyncOptions = syncOptionsCaptor.getValue();
    assertTrue(userSyncOptions.isFullSync());
    assertTrue(userSyncOptions.isCredentialsUpdateOptimizationEnabled());
    assertTrue(userSyncOptions.isFmsToFreeIpaBatchCallEnabled());
    verify(usersyncTask, never()).cancel(true);
    verify(usersyncTask, never()).cancel(false);
    verify(usersyncTask).isCancelled();
    verify(usersyncTask).isDone();
    verify(operationService, never()).timeout(anyString(), anyString());
}
Also used : UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 22 with UserSyncStatus

use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.

the class UserSyncStatusServiceTest method testGetOrCreateForStackExists.

@Test
public void testGetOrCreateForStackExists() {
    Stack stack = new Stack();
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    when(userSyncStatusRepository.getByStack(stack)).thenReturn(Optional.of(userSyncStatus));
    UserSyncStatus result = underTest.getOrCreateForStack(stack);
    assertEquals(userSyncStatus, result);
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 23 with UserSyncStatus

use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.

the class UserSyncTestUtils method createUserSyncStatus.

public static UserSyncStatus createUserSyncStatus(Stack stack) {
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    userSyncStatus.setStack(stack);
    return userSyncStatus;
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus)

Example 24 with UserSyncStatus

use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.

the class EventGenerationIdsCheckerTest method testIsInSync.

@Test
void testIsInSync() {
    Stack stack = UserSyncTestUtils.createStack();
    UmsEventGenerationIds currentEventGenerationIds = UserSyncTestUtils.createUniqueUmsEventGenerationIds();
    UserSyncStatus userSyncStatus = UserSyncTestUtils.createUserSyncStatus(stack);
    userSyncStatus.setUmsEventGenerationIds(new Json(currentEventGenerationIds));
    assertTrue(underTest.isInSync(userSyncStatus, currentEventGenerationIds));
}
Also used : UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 25 with UserSyncStatus

use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.

the class EventGenerationIdsCheckerTest method testIsNotInSync.

@Test
void testIsNotInSync() {
    Stack stack = UserSyncTestUtils.createStack();
    UmsEventGenerationIds currentEventGenerationIds = UserSyncTestUtils.createUniqueUmsEventGenerationIds();
    UserSyncStatus userSyncStatus = UserSyncTestUtils.createUserSyncStatus(stack);
    userSyncStatus.setUmsEventGenerationIds(new Json(UserSyncTestUtils.createUniqueUmsEventGenerationIds()));
    assertFalse(underTest.isInSync(userSyncStatus, currentEventGenerationIds));
}
Also used : UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)41 Test (org.junit.jupiter.api.Test)30 Stack (com.sequenceiq.freeipa.entity.Stack)18 Operation (com.sequenceiq.freeipa.entity.Operation)17 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)10 Json (com.sequenceiq.cloudbreak.common.json.Json)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)7 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 OperationType (com.sequenceiq.freeipa.api.v1.operation.model.OperationType)5 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)4 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)4 Instant (java.time.Instant)4 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)3 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)3 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)2 UserSyncStatusResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse)2 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Callable (java.util.concurrent.Callable)2