Search in sources :

Example 16 with UserSyncStatus

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);
}
Also used : UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Stack(com.sequenceiq.freeipa.entity.Stack)

Example 17 with 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);
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) FreeIpa(com.sequenceiq.freeipa.entity.FreeIpa) ImageEntity(com.sequenceiq.freeipa.entity.ImageEntity) FreeIpaServerResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.FreeIpaServerResponse) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Stack(com.sequenceiq.freeipa.entity.Stack) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NullSource(org.junit.jupiter.params.provider.NullSource)

Example 18 with UserSyncStatus

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);
}
Also used : UserSyncStatusResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Json(com.sequenceiq.cloudbreak.common.json.Json) IOException(java.io.IOException) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 19 with UserSyncStatus

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);
}
Also used : UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Example 20 with UserSyncStatus

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());
}
Also used : UserSyncOptions(com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions) UserSyncStatus(com.sequenceiq.freeipa.entity.UserSyncStatus) Operation(com.sequenceiq.freeipa.entity.Operation) OperationType(com.sequenceiq.freeipa.api.v1.operation.model.OperationType) Stack(com.sequenceiq.freeipa.entity.Stack) Test(org.junit.jupiter.api.Test)

Aggregations

UserSyncStatus (com.sequenceiq.freeipa.entity.UserSyncStatus)41 Test (org.junit.jupiter.api.Test)30 Stack (com.sequenceiq.freeipa.entity.Stack)18 Operation (com.sequenceiq.freeipa.entity.Operation)17 UmsEventGenerationIds (com.sequenceiq.freeipa.service.freeipa.user.model.UmsEventGenerationIds)10 Json (com.sequenceiq.cloudbreak.common.json.Json)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)7 UserSyncOptions (com.sequenceiq.freeipa.service.freeipa.user.model.UserSyncOptions)6 OperationType (com.sequenceiq.freeipa.api.v1.operation.model.OperationType)5 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)4 SyncStatusDetail (com.sequenceiq.freeipa.service.freeipa.user.model.SyncStatusDetail)4 Instant (java.time.Instant)4 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)3 ImageEntity (com.sequenceiq.freeipa.entity.ImageEntity)3 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)2 UserSyncStatusResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.usersync.UserSyncStatusResponse)2 UmsUsersState (com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState)2 Collection (java.util.Collection)2 Optional (java.util.Optional)2 Callable (java.util.concurrent.Callable)2