Search in sources :

Example 11 with UmsEventGenerationIds

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds 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 12 with UmsEventGenerationIds

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds 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)

Example 13 with UmsEventGenerationIds

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.

the class UmsEventGenerationIdsProviderTest method testGetEventGenerationIds.

@Test
void testGetEventGenerationIds() {
    GetEventGenerationIdsResponse response = createGetEventGenerationIdsResponse();
    when(grpcUmsClient.getEventGenerationIds(any(), any(), any())).thenReturn(response);
    UmsEventGenerationIds umsEventGenerationIds = underTest.getEventGenerationIds(ACCOUNT_ID, Optional.of(UUID.randomUUID().toString()));
    for (EventMapping eventMapping : EventMapping.values()) {
        assertEquals(eventMapping.getConverter().apply(response.getEventGenerationIds()), umsEventGenerationIds.getEventGenerationIds().get(eventMapping.getEventName()));
    }
}
Also used : UmsEventGenerationIds(com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds) GetEventGenerationIdsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.GetEventGenerationIdsResponse) Test(org.junit.jupiter.api.Test)

Example 14 with UmsEventGenerationIds

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds 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 15 with UmsEventGenerationIds

use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds 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)

Aggregations

UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)19 UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)11 Test (org.junit.jupiter.api.Test)11 Stack (com.sequenceiq.freeipa.entity.Stack)10 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)7 Json (com.sequenceiq.cloudbreak.common.json.Json)6 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)6 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)5 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)5 Collection (java.util.Collection)5 Optional (java.util.Optional)5 Callable (java.util.concurrent.Callable)5 Future (java.util.concurrent.Future)5 Operation (com.sequenceiq.freeipa.entity.Operation)4 List (java.util.List)4 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2