use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.
the class UserSyncForStackServiceTest method testSynchronizeStackSuccessFullWithRetry.
@Test
public void testSynchronizeStackSuccessFullWithRetry() throws Exception {
UmsUsersState umsUsersState = mock(UmsUsersState.class);
UserSyncOptions options = new UserSyncOptions(true, true, WorkloadCredentialsUpdateType.FORCE_UPDATE);
UsersState usersState = mock(UsersState.class);
when(usersState.getUsers()).thenReturn(ImmutableSet.of());
when(usersState.getGroups()).thenReturn(ImmutableSet.of());
when(freeIpaUsersStateProvider.getUsersState(FREE_IPA_CLIENT)).thenReturn(usersState);
UsersStateDifference usersStateDifference = mock(UsersStateDifference.class);
when(userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, usersState, options)).thenReturn(usersStateDifference);
when(userStateDifferenceCalculator.usersStateDifferenceChanged(any(), any())).thenReturn(TRUE);
when(entitlementService.cloudIdentityMappingEnabled(ACCOUNT)).thenReturn(TRUE);
when(entitlementService.isEnvironmentPrivilegedUserEnabled(ACCOUNT)).thenReturn(TRUE);
doAnswer(invocation -> {
Multimap<String, String> warnings = invocation.getArgument(2, Multimap.class);
warnings.put(ENV_CRN, "failed");
return null;
}).doNothing().when(stateApplier).applyDifference(eq(umsUsersState), eq(ENV_CRN), any(), eq(usersStateDifference), eq(options), eq(FREE_IPA_CLIENT));
SyncStatusDetail result = underTest.synchronizeStack(STACK, umsUsersState, options);
verify(freeIpaUsersStateProvider, never()).getFilteredFreeIpaState(any(), any());
verify(cloudIdentitySyncService).syncCloudIdentities(eq(STACK), eq(umsUsersState), any());
verify(sudoRuleService).setupSudoRule(STACK, FREE_IPA_CLIENT);
assertEquals(ENV_CRN, result.getEnvironmentCrn());
assertEquals(COMPLETED, result.getStatus());
assertTrue(result.getWarnings().isEmpty());
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.
the class UserSyncForStackService method retrySyncIfBatchCallHasWarnings.
private void retrySyncIfBatchCallHasWarnings(Stack stack, UmsUsersState umsUsersState, Multimap<String, String> warnings, UserSyncOptions options, FreeIpaClient freeIpaClient, UsersStateDifference usersStateDifferenceBeforeSync) throws FreeIpaClientException, TimeoutException {
if (options.isFullSync() && !warnings.isEmpty() && options.isFmsToFreeIpaBatchCallEnabled()) {
UsersStateDifference usersStateDifferenceAfterSync = compareUmsAndFreeIpa(umsUsersState, options, freeIpaClient);
if (userStateDifferenceCalculator.usersStateDifferenceChanged(usersStateDifferenceBeforeSync, usersStateDifferenceAfterSync)) {
Multimap<String, String> retryWarnings = ArrayListMultimap.create();
try {
LOGGER.info(String.format("Sync was partially successful for %s, thus we are trying it once again", stack.getResourceCrn()));
stateApplier.applyDifference(umsUsersState, stack.getEnvironmentCrn(), retryWarnings, usersStateDifferenceAfterSync, options, freeIpaClient);
warnings.clear();
} finally {
warnings.putAll(retryWarnings);
}
}
}
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.
the class UserSyncForStackService method compareUmsAndFreeIpa.
private UsersStateDifference compareUmsAndFreeIpa(UmsUsersState umsUsersState, UserSyncOptions options, FreeIpaClient freeIpaClient) throws FreeIpaClientException {
UserSyncLogEvent logEvent = options.isFullSync() ? RETRIEVE_FULL_IPA_STATE : RETRIEVE_PARTIAL_IPA_STATE;
LOGGER.debug("Starting {} ...", logEvent);
UsersState ipaUsersState = getIpaUserState(freeIpaClient, umsUsersState, options.isFullSync());
LOGGER.debug("Finished {}, found {} users and {} groups.", logEvent, ipaUsersState.getUsers().size(), ipaUsersState.getGroups().size());
LOGGER.debug("Starting {} ...", CALCULATE_UMS_IPA_DIFFERENCE);
UsersStateDifference usersStateDifference = userStateDifferenceCalculator.fromUmsAndIpaUsersStates(umsUsersState, ipaUsersState, options);
LOGGER.debug("Finished {}.", CALCULATE_UMS_IPA_DIFFERENCE);
return usersStateDifference;
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.
the class UserSyncStateApplierTest method testApplyStateDifferenceToIpa.
@Test
void testApplyStateDifferenceToIpa() throws FreeIpaClientException, TimeoutException {
Multimap<String, String> warnings = ArrayListMultimap.create();
UsersStateDifference usersStateDifference = createStateDiff();
underTest.applyStateDifferenceToIpa(ENV_CRN, freeIpaClient, usersStateDifference, warnings::put, true);
verifyOperationsCalled(usersStateDifference);
}
use of com.sequenceiq.freeipa.service.freeipa.user.model.UsersStateDifference in project cloudbreak by hortonworks.
the class UserSyncStateApplierTest method testApplyDifferenceNoPasswordHashSupport.
@Test
public void testApplyDifferenceNoPasswordHashSupport() throws FreeIpaClientException, TimeoutException {
UmsUsersState umsUsersState = mock(UmsUsersState.class);
UserSyncOptions userSyncOptions = mock(UserSyncOptions.class);
UsersStateDifference usersStateDifference = createStateDiff();
Multimap<String, String> warnings = ArrayListMultimap.create();
when(userSyncOptions.isFmsToFreeIpaBatchCallEnabled()).thenReturn(Boolean.TRUE);
when(freeIpaClient.getConfig()).thenReturn(new Config());
underTest.applyDifference(umsUsersState, ENV_CRN, warnings, usersStateDifference, userSyncOptions, freeIpaClient);
verifyNoInteractions(workloadCredentialService);
}
Aggregations