Search in sources :

Example 36 with UserSyncStatus

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

the class UserSyncPollerTest method testDontSyncStackWhenNotCool.

@Test
void testDontSyncStackWhenNotCool() {
    UserSyncStatus userSyncStatus = setupMocks();
    when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn("crn:altus:iam:us-west-1:altus:user:__internal__actor__");
    when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
    when(eventGenerationIdsChecker.isInSync(eq(userSyncStatus), any())).thenReturn(false);
    when(cooldownChecker.isCooldownExpired(eq(userSyncStatus), any())).thenReturn(false);
    underTest.syncAllFreeIpaStacks();
    verify(userSyncService, times(0)).synchronizeUsers(any(), any(), any(), any(), any(), any());
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Test(org.junit.jupiter.api.Test)

Example 37 with UserSyncStatus

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

the class UserSyncStatusToUserSyncStatusResponseConverterTest method convert.

@Test
void convert() {
    String requestedId = UUID.randomUUID().toString();
    Operation requested = new Operation();
    requested.setOperationId(requestedId);
    String successfulId = UUID.randomUUID().toString();
    Operation successful = new Operation();
    successful.setOperationId(successfulId);
    Map<String, String> eventGenerationIdMap = Map.of("key1", "value1", "key2", "value2");
    UmsEventGenerationIds eventGenerationIds = new UmsEventGenerationIds();
    eventGenerationIds.setEventGenerationIds(eventGenerationIdMap);
    UserSyncStatus status = new UserSyncStatus();
    status.setLastStartedFullSync(requested);
    status.setLastSuccessfulFullSync(successful);
    status.setUmsEventGenerationIds(new Json(eventGenerationIds));
    UserSyncStatusResponse response = underTest.convert(status);
    assertThat(response).returns(requestedId, UserSyncStatusResponse::getLastStartedUserSyncId).returns(successfulId, UserSyncStatusResponse::getLastSuccessfulUserSyncId).returns(eventGenerationIdMap, UserSyncStatusResponse::getEventGenerationIds);
}
Also used : UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) UserSyncStatusResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Json(com.sequenceiq.cloudbreak.common.json.Json) Test(org.junit.jupiter.api.Test)

Example 38 with UserSyncStatus

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

the class UserSyncService method updateUserSyncStatusForStack.

private void updateUserSyncStatusForStack(Operation operation, Stack stack) {
    UserSyncStatus userSyncStatus = userSyncStatusService.getOrCreateForStack(stack);
    userSyncStatus.setLastStartedFullSync(operation);
    userSyncStatusService.save(userSyncStatus);
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus)

Example 39 with UserSyncStatus

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

the class UserSyncStatusService method createNewUserSyncStatusForStack.

private UserSyncStatus createNewUserSyncStatusForStack(Stack stack) {
    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 40 with UserSyncStatus

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

the class UserSyncForEnvService method asyncSynchronizeStack.

private Future<SyncStatusDetail> asyncSynchronizeStack(Stack stack, UmsUsersState umsUsersState, UmsEventGenerationIds umsEventGenerationIds, UserSyncOptions options, String operationId, String accountId) {
    return asyncTaskExecutor.submit(() -> {
        SyncStatusDetail statusDetail = userSyncForStackService.synchronizeStack(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)

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