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());
}
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;
});
}
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);
});
}
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));
}
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());
}
Aggregations