Search in sources :

Example 1 with UserSyncStatus

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

the class UserSyncServiceTest method testAsyncSynchronizeUsersUsesInternalCrn.

@Test
void testAsyncSynchronizeUsersUsesInternalCrn() {
    Stack stack = mock(Stack.class);
    when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
    when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(anySet(), anyString())).thenReturn(List.of(stack));
    Operation operation = mock(Operation.class);
    when(operation.getStatus()).thenReturn(OperationState.RUNNING);
    when(operation.getOperationId()).thenReturn("operationId");
    when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
    UserSyncStatus userSyncStatus = mock(UserSyncStatus.class);
    when(userSyncStatusService.getOrCreateForStack(any(Stack.class))).thenReturn(userSyncStatus);
    when(userSyncStatusService.save(userSyncStatus)).thenReturn(userSyncStatus);
    UserSyncService spyService = spy(underTest);
    doAnswer(invocation -> {
        assertEquals(INTERNAL_ACTOR_CRN, ThreadBasedUserCrnProvider.getUserCrn());
        return null;
    }).when(spyService).asyncSynchronizeUsers(anyString(), anyString(), anyList(), any(), any());
    spyService.synchronizeUsers("accountId", "actorCrn", Set.of(), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
    verify(spyService).asyncSynchronizeUsers(anyString(), anyString(), anyList(), any(), any());
}
Also used : 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 2 with UserSyncStatus

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

the class UserSyncService method asyncSynchronizeStack.

private Future<SyncStatusDetail> asyncSynchronizeStack(Stack stack, UmsUsersState umsUsersState, UmsEventGenerationIds umsEventGenerationIds, UserSyncOptions options, String operationId, String accountId) {
    return asyncTaskExecutor.submit(() -> {
        SyncStatusDetail statusDetail = internalSynchronizeStack(stack, umsUsersState, options);
        if (options.isFullSync() && statusDetail.getStatus() == SynchronizationStatus.COMPLETED) {
            UserSyncStatus userSyncStatus = userSyncStatusService.getOrCreateForStack(stack);
            userSyncStatus.setUmsEventGenerationIds(new Json(umsEventGenerationIds));
            userSyncStatus.setLastSuccessfulFullSync(operationService.getOperationForAccountIdAndOperationId(accountId, operationId));
            userSyncStatusService.save(userSyncStatus);
        }
        return statusDetail;
    });
}
Also used : SyncStatusDetail(com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 3 with UserSyncStatus

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

the class UserSyncStatusService method getOrCreateForStack.

public UserSyncStatus getOrCreateForStack(Stack stack) {
    return userSyncStatusRepository.getByStack(stack).orElseGet(() -> {
        UserSyncStatus userSyncStatus = new UserSyncStatus();
        userSyncStatus.setStack(stack);
        userSyncStatus.setUmsEventGenerationIds(new Json(new UmsEventGenerationIds()));
        return userSyncStatusRepository.save(userSyncStatus);
    });
}
Also used : UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Json(com.sequenceiq.cloudbreak.common.json.Json)

Example 4 with UserSyncStatus

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

the class FreeIpaDescribeServiceTest method describeAll.

@Test
void describeAll() {
    DescribeFreeIpaResponse describeResponse = mock(DescribeFreeIpaResponse.class);
    ImageEntity image = mock(ImageEntity.class);
    FreeIpa freeIpa = mock(FreeIpa.class);
    UserSyncStatus userSyncStatus = mock(UserSyncStatus.class);
    when(stackService.findMultipleByEnvironmentCrnAndAccountIdEvenIfTerminatedWithList(eq(ENVIRONMENT_CRN), eq(ACCOUNT_ID))).thenReturn(Collections.singletonList(stack));
    when(imageService.getByStack(any())).thenReturn(image);
    when(freeIpaService.findByStackId(any())).thenReturn(freeIpa);
    when(userSyncStatusService.findByStack(any())).thenReturn(Optional.of(userSyncStatus));
    when(stackToDescribeFreeIpaResponseConverter.convert(any(), any(), any(), any(), any())).thenReturn(describeResponse);
    when(entitlementService.isFreeIpaRebuildEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    assertEquals(List.of(describeResponse), underTest.describeAll(ENVIRONMENT_CRN, ACCOUNT_ID));
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Test(org.junit.jupiter.api.Test)

Example 5 with UserSyncStatus

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

the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncFailed.

@Test
void internalCalculateEnvironmentUserSyncStateLastSyncFailed() {
    UserSyncStatus userSyncStatus = new UserSyncStatus();
    Operation lastSync = new Operation();
    lastSync.setOperationId(UUID.randomUUID().toString());
    lastSync.setStatus(OperationState.FAILED);
    userSyncStatus.setLastStartedFullSync(lastSync);
    EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
    assertEquals(UserSyncState.SYNC_FAILED, result.getState());
    assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
Also used : 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

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