use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds 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.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculatorTest method internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessInSync.
@Test
void internalCalculateEnvironmentUserSyncStateLastSyncCompletedSuccessInSync() {
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(true);
EnvironmentUserSyncState result = underTest.internalCalculateEnvironmentUserSyncState(ACCOUNT_ID, ENVIRONMENT_CRN, Optional.of(userSyncStatus));
assertEquals(UserSyncState.UP_TO_DATE, result.getState());
assertEquals(lastSync.getOperationId(), result.getLastUserSyncOperationId());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class UserSyncForEnvServiceTest method testSyncUsers.
@Test
public void testSyncUsers() {
Stack stack1 = mock(Stack.class);
when(stack1.getEnvironmentCrn()).thenReturn(ENV_CRN);
Stack stack2 = mock(Stack.class);
when(stack2.getEnvironmentCrn()).thenReturn(ENV_CRN_2);
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);
UmsUsersState umsUsersState2 = mock(UmsUsersState.class);
when(umsUsersStateProviderDispatcher.getEnvToUmsUsersStateMap(eq(ACCOUNT_ID), eq(Set.of(ENV_CRN, ENV_CRN_2)), eq(Set.of()), eq(Set.of()), any())).thenReturn(Map.of(ENV_CRN, umsUsersState1, ENV_CRN_2, umsUsersState2));
when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
SyncStatusDetail result = (SyncStatusDetail) inv.getArgument(0, Callable.class).call();
Future future = mock(Future.class);
when(future.get()).thenReturn(result);
return future;
});
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
when(userSyncForStackService.synchronizeStack(stack1, umsUsersState1, options)).thenReturn(new SyncStatusDetail(ENV_CRN, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
when(userSyncForStackService.synchronizeStack(stack2, umsUsersState2, options)).thenReturn(new SyncStatusDetail(ENV_CRN_2, SynchronizationStatus.COMPLETED, "", ImmutableMultimap.of()));
when(userSyncStatusService.getOrCreateForStack(stack1)).thenReturn(new UserSyncStatus());
when(userSyncStatusService.getOrCreateForStack(stack2)).thenReturn(new UserSyncStatus());
underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1, stack2), userSyncFilter, options, System.currentTimeMillis());
verify(umsVirtualGroupCreateService).createVirtualGroups(ACCOUNT_ID, List.of(stack1, stack2));
verify(userSyncStatusService, times(2)).save(any(UserSyncStatus.class));
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());
assertTrue(failureCaptor.getValue().isEmpty());
assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN)));
assertTrue(successCaptor.getValue().contains(new SuccessDetails(ENV_CRN_2)));
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class UserSyncForEnvServiceTest method testSyncUsersTimesOut.
@Test
public void testSyncUsersTimesOut() {
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));
Future<?> future = mock(Future.class);
when(asyncTaskExecutor.submit(any(Callable.class))).thenAnswer(inv -> {
when(future.get(0L, TimeUnit.MILLISECONDS)).thenThrow(new TimeoutException("timeout"));
return future;
});
when(umsEventGenerationIdsProvider.getEventGenerationIds(eq(ACCOUNT_ID), any(Optional.class))).thenReturn(new UmsEventGenerationIds());
when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
underTest.synchronizeUsers(OPERATION_ID, ACCOUNT_ID, List.of(stack1), userSyncFilter, options, System.currentTimeMillis());
verifyNoInteractions(userSyncStatusService);
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());
assertTrue(successCaptor.getValue().isEmpty());
verify(future).cancel(true);
List<FailureDetails> failures = (List<FailureDetails>) failureCaptor.getValue();
assertThat(failures, allOf(hasItem(allOf(hasProperty("environment", is(ENV_CRN)), hasProperty("message", is("Timed out")), hasProperty("additionalDetails", anEmptyMap())))));
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds in project cloudbreak by hortonworks.
the class UmsEventGenerationIdsProvider method getEventGenerationIds.
public UmsEventGenerationIds getEventGenerationIds(String accountId, Optional<String> requestId) {
EventGenerationIds eventGenerationIds = grpcUmsClient.getEventGenerationIds(accountId, requestId, regionAwareInternalCrnGeneratorFactory).getEventGenerationIds();
UmsEventGenerationIds umsEventGenerationIds = new UmsEventGenerationIds();
Map<String, String> eventGenerationIdsMap = Maps.newHashMap();
for (Descriptors.FieldDescriptor fd : eventGenerationIds.getDescriptorForType().getFields()) {
if (Descriptors.FieldDescriptor.Type.STRING.equals(fd.getType()) && eventGenerationIds.hasField(fd)) {
eventGenerationIdsMap.put(fd.getName(), (String) eventGenerationIds.getField(fd));
}
}
umsEventGenerationIds.setEventGenerationIds(eventGenerationIdsMap);
return umsEventGenerationIds;
}
Aggregations