use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class EnvironmentUserSyncStateCalculator method calculateEnvironmentUserSyncState.
public EnvironmentUserSyncState calculateEnvironmentUserSyncState(String accountId, Crn environmentCrn) {
checkArgument(accountId.equals(environmentCrn.getAccountId()), "environmentCrn does not match account id");
String envCrnString = environmentCrn.toString();
Stack stack = stackService.getByEnvironmentCrnAndAccountId(envCrnString, accountId);
MDCBuilder.buildMdcContext(stack);
Optional<UserSyncStatus> userSyncStatus = userSyncStatusService.findByStack(stack);
return internalCalculateEnvironmentUserSyncState(accountId, envCrnString, userSyncStatus);
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class StackToDescribeFreeIpaResponseConverterTest method convertTest.
@ParameterizedTest(name = "tunnel={0}")
@EnumSource(Tunnel.class)
@NullSource
void convertTest(Tunnel tunnel) {
FreeIpaServerResponse freeIpaServerResponse = new FreeIpaServerResponse();
Stack stack = createStack(tunnel);
ImageEntity image = new ImageEntity();
FreeIpa freeIpa = new FreeIpa();
freeIpa.setDomain(DOMAIN);
UserSyncStatus userSyncStatus = new UserSyncStatus();
when(authenticationResponseConverter.convert(stack.getStackAuthentication())).thenReturn(STACK_AUTHENTICATION_RESPONSE);
when(imageSettingsResponseConverter.convert(image)).thenReturn(IMAGE_SETTINGS_RESPONSE);
when(freeIpaServerResponseConverter.convert(freeIpa)).thenReturn(freeIpaServerResponse);
when(instanceGroupConverter.convert(stack.getInstanceGroups(), true)).thenReturn(INSTANCE_GROUP_RESPONSES);
when(userSyncStatusConverter.convert(userSyncStatus)).thenReturn(USERSYNC_STATUS_RESPONSE);
when(balancedDnsAvailabilityChecker.isBalancedDnsAvailable(stack)).thenReturn(true);
when(stackToAvailabilityStatusConverter.convert(stack)).thenReturn(AvailabilityStatus.AVAILABLE);
DescribeFreeIpaResponse result = underTest.convert(stack, image, freeIpa, Optional.of(userSyncStatus), true);
assertThat(result).returns(NAME, DescribeFreeIpaResponse::getName).returns(ENV_CRN, DescribeFreeIpaResponse::getEnvironmentCrn).returns(RESOURCE_CRN, DescribeFreeIpaResponse::getCrn).returns(CLOUD_PLATFORM, DescribeFreeIpaResponse::getCloudPlatform).returns(STACK_AUTHENTICATION_RESPONSE, DescribeFreeIpaResponse::getAuthentication).returns(IMAGE_SETTINGS_RESPONSE, DescribeFreeIpaResponse::getImage).returns(freeIpaServerResponse, DescribeFreeIpaResponse::getFreeIpa).returns(INSTANCE_GROUP_RESPONSES, DescribeFreeIpaResponse::getInstanceGroups).returns(STATUS, DescribeFreeIpaResponse::getStatus).returns(STATUS_REASON, DescribeFreeIpaResponse::getStatusReason).returns(STATUS_STRING, DescribeFreeIpaResponse::getStatusString).returns(APP_VERSION, DescribeFreeIpaResponse::getAppVersion).returns(VARIANT, DescribeFreeIpaResponse::getVariant).returns(USERSYNC_STATUS_RESPONSE, DescribeFreeIpaResponse::getUserSyncStatus).returns(tunnel, DescribeFreeIpaResponse::getTunnel);
assertThat(freeIpaServerResponse).returns(Set.of(SERVER_IP), FreeIpaServerResponse::getServerIp).returns(FREEIPA_HOST, FreeIpaServerResponse::getFreeIpaHost).returns(GATEWAY_PORT, FreeIpaServerResponse::getFreeIpaPort);
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class UserSyncStatusToUserSyncStatusResponseConverterTest method convertJsonException.
@Test
void convertJsonException() throws IOException {
Json eventGenerationIds = mock(Json.class);
IOException e = new IOException("test exception");
when(eventGenerationIds.get(any(Class.class))).thenThrow(e);
UserSyncStatus status = new UserSyncStatus();
status.setStack(mock(Stack.class));
status.setUmsEventGenerationIds(eventGenerationIds);
UserSyncStatusResponse response = underTest.convert(status);
assertThat(response).returns(null, UserSyncStatusResponse::getLastStartedUserSyncId).returns(null, UserSyncStatusResponse::getLastSuccessfulUserSyncId).returns(null, UserSyncStatusResponse::getEventGenerationIds);
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class UserSyncServiceTest method testSyncUsersWithTimeoutCheckTaskRunnable.
@Test
public void testSyncUsersWithTimeoutCheckTaskRunnable() {
Stack stack = mock(Stack.class);
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(Set.of(), ACCOUNT_ID)).thenReturn(List.of(stack));
Operation operation = createRunningOperation();
when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(2, Runnable.class);
runnable.run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(operation.getOperationId()), eq(ACCOUNT_ID), any(Runnable.class));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(INTERNAL_ACTOR);
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
UserSyncStatus userSyncStatus = new UserSyncStatus();
when(userSyncStatusService.getOrCreateForStack(stack)).thenReturn(userSyncStatus);
when(entitlementService.usersyncCredentialsUpdateOptimizationEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
when(entitlementService.isFmsToFreeipaBatchCallEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
when(entitlementService.isUserSyncThreadTimeoutEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
ReflectionTestUtils.setField(underTest, "operationTimeout", TIMEOUT);
Future<?> usersyncTask = mock(Future.class);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(0, Runnable.class);
assertEquals(operation.getOperationId(), MDCBuilder.getMdcContextMap().get(LoggerContextKey.OPERATION_ID.toString()));
assertEquals(INTERNAL_ACTOR, ThreadBasedUserCrnProvider.getUserCrn());
runnable.run();
return usersyncTask;
}).when(asyncTaskExecutor).submit(any(Runnable.class));
doAnswer(inv -> {
Runnable runnable = inv.getArgument(0, Runnable.class);
runnable.run();
return null;
}).when(scheduledExecutorService).schedule(any(Runnable.class), eq(TIMEOUT), eq(TimeUnit.MILLISECONDS));
Operation result = underTest.synchronizeUsers(ACCOUNT_ID, ACTOR_CRN, Set.of(), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
assertEquals(operation, result);
ArgumentCaptor<UserSyncRequestFilter> requestFilterCaptor = ArgumentCaptor.forClass(UserSyncRequestFilter.class);
verify(userSyncRequestValidator).validateParameters(eq(ACCOUNT_ID), eq(ACTOR_CRN), eq(Set.of()), requestFilterCaptor.capture());
UserSyncRequestFilter requestFilter = requestFilterCaptor.getValue();
assertTrue(requestFilter.getUserCrnFilter().isEmpty());
assertTrue(requestFilter.getMachineUserCrnFilter().isEmpty());
assertTrue(requestFilter.getDeletedWorkloadUser().isEmpty());
assertEquals(operation, userSyncStatus.getLastStartedFullSync());
verify(userSyncStatusService).save(userSyncStatus);
ArgumentCaptor<UserSyncOptions> syncOptionsCaptor = ArgumentCaptor.forClass(UserSyncOptions.class);
verify(userSyncForEnvService).synchronizeUsers(eq(operation.getOperationId()), eq(ACCOUNT_ID), eq(List.of(stack)), eq(requestFilter), syncOptionsCaptor.capture(), anyLong());
UserSyncOptions userSyncOptions = syncOptionsCaptor.getValue();
assertTrue(userSyncOptions.isFullSync());
assertTrue(userSyncOptions.isCredentialsUpdateOptimizationEnabled());
assertTrue(userSyncOptions.isFmsToFreeIpaBatchCallEnabled());
verify(usersyncTask).cancel(true);
verify(usersyncTask, never()).cancel(false);
verify(usersyncTask).isCancelled();
verify(usersyncTask).isDone();
verify(operationService).timeout(operation.getOperationId(), ACCOUNT_ID);
}
use of com.sequenceiq.freeipa.entity.UserSyncStatus in project cloudbreak by hortonworks.
the class UserSyncServiceTest method testSyncUsers.
@Test
public void testSyncUsers() {
Stack stack = mock(Stack.class);
when(stack.getEnvironmentCrn()).thenReturn(ENV_CRN);
when(stackService.getMultipleByEnvironmentCrnOrChildEnvironmantCrnAndAccountId(Set.of(), ACCOUNT_ID)).thenReturn(List.of(stack));
Operation operation = createRunningOperation();
when(operationService.startOperation(anyString(), any(OperationType.class), anyCollection(), anyCollection())).thenReturn(operation);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(2, Runnable.class);
runnable.run();
return null;
}).when(operationService).tryWithOperationCleanup(eq(operation.getOperationId()), eq(ACCOUNT_ID), any(Runnable.class));
when(regionAwareInternalCrnGenerator.getInternalCrnForServiceAsString()).thenReturn(INTERNAL_ACTOR);
when(regionAwareInternalCrnGeneratorFactory.iam()).thenReturn(regionAwareInternalCrnGenerator);
UserSyncStatus userSyncStatus = new UserSyncStatus();
when(userSyncStatusService.getOrCreateForStack(stack)).thenReturn(userSyncStatus);
when(entitlementService.usersyncCredentialsUpdateOptimizationEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
when(entitlementService.isFmsToFreeipaBatchCallEnabled(ACCOUNT_ID)).thenReturn(Boolean.TRUE);
doAnswer(inv -> {
Runnable runnable = inv.getArgument(0, Runnable.class);
assertEquals(operation.getOperationId(), MDCBuilder.getMdcContextMap().get(LoggerContextKey.OPERATION_ID.toString()));
assertEquals(INTERNAL_ACTOR, ThreadBasedUserCrnProvider.getUserCrn());
runnable.run();
return mock(Future.class);
}).when(asyncTaskExecutor).submit(any(Runnable.class));
Operation result = underTest.synchronizeUsers(ACCOUNT_ID, ACTOR_CRN, Set.of(), Set.of(), Set.of(), WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED);
assertEquals(operation, result);
ArgumentCaptor<UserSyncRequestFilter> requestFilterCaptor = ArgumentCaptor.forClass(UserSyncRequestFilter.class);
verify(userSyncRequestValidator).validateParameters(eq(ACCOUNT_ID), eq(ACTOR_CRN), eq(Set.of()), requestFilterCaptor.capture());
UserSyncRequestFilter requestFilter = requestFilterCaptor.getValue();
assertTrue(requestFilter.getUserCrnFilter().isEmpty());
assertTrue(requestFilter.getMachineUserCrnFilter().isEmpty());
assertTrue(requestFilter.getDeletedWorkloadUser().isEmpty());
assertEquals(operation, userSyncStatus.getLastStartedFullSync());
verify(userSyncStatusService).save(userSyncStatus);
ArgumentCaptor<UserSyncOptions> syncOptionsCaptor = ArgumentCaptor.forClass(UserSyncOptions.class);
verify(userSyncForEnvService).synchronizeUsers(eq(operation.getOperationId()), eq(ACCOUNT_ID), eq(List.of(stack)), eq(requestFilter), syncOptionsCaptor.capture(), anyLong());
UserSyncOptions userSyncOptions = syncOptionsCaptor.getValue();
assertTrue(userSyncOptions.isFullSync());
assertTrue(userSyncOptions.isCredentialsUpdateOptimizationEnabled());
assertTrue(userSyncOptions.isFmsToFreeIpaBatchCallEnabled());
}
Aggregations