Search in sources :

Example 11 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class FreeIpaServiceTest method synchronizeAllUsersInEnvironmentOngoing.

// @Test
// void getSyncOperationStatusSuccess() {
// SyncOperationStatus status = createStatus(SynchronizationStatus.COMPLETED, "nope");
// when(userV1Endpoint.getSyncOperationStatusInternal(any(), eq(OPERATION))).thenReturn(status);
// SyncOperationStatus result = ThreadBasedUserCrnProvider.doAsInternalActor(() ->
// underTest.getSyncOperationStatus(ENVCRN, OPERATION));
// assertThat(result).isEqualTo(status);
// }
// @Test
// void getSyncOperationStatusFailure() {
// when(webApplicationExceptionMessageExtractor.getErrorMessage(any())).thenReturn("custom error");
// when(userV1Endpoint.getSyncOperationStatusInternal(any(), eq(OPERATION))).thenThrow(new WebApplicationException("network error"));
// assertThatThrownBy(() -> ThreadBasedUserCrnProvider.doAsInternalActor(() ->
// underTest.getSyncOperationStatus(ENVCRN, OPERATION))).isInstanceOf(FreeIpaOperationFailedException.class);
// }
@Test
void synchronizeAllUsersInEnvironmentOngoing() {
    SyncOperationStatus status = createStatus(SynchronizationStatus.RUNNING, "");
    when(userV1Endpoint.getLastSyncOperationStatus(any())).thenReturn(status);
    SyncOperationStatus result = underTest.synchronizeAllUsersInEnvironment(ENVCRN);
    assertThat(result).isEqualTo(status);
    verify(userV1Endpoint, times(0)).synchronizeAllUsers(any());
}
Also used : SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Test(org.junit.jupiter.api.Test)

Example 12 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class AltusMachineUserService method syncEnvironment.

private void syncEnvironment(String accountId, String machineUserCrn, String environmentCrn, Optional<String> deletedWorkloadUserName) {
    SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
    request.setAccountId(accountId);
    request.setEnvironments(Set.of(environmentCrn));
    request.setMachineUsers(Set.of(machineUserCrn));
    deletedWorkloadUserName.ifPresent(s -> request.setDeletedWorkloadUsers(Set.of(s)));
    SyncOperationStatus statusResponse = freeIpaCommunicator.synchronizeAllUsers(request);
    LOGGER.info("Finished invoking freeIpa user Sync with operation: {}, for environmentCrn: {} and machineUserCrn: {}", statusResponse.getOperationId(), environmentCrn, machineUserCrn);
}
Also used : SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)

Example 13 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1Controller method getLastSyncOperationStatus.

@Override
@CheckPermissionByResourceCrn(action = AuthorizationResourceAction.GET_OPERATION_STATUS)
public SyncOperationStatus getLastSyncOperationStatus(@ResourceCrn @TenantAwareParam @NotEmpty String environmentCrn) {
    Crn envCrn = Crn.safeFromString(environmentCrn);
    EnvironmentUserSyncState userSyncState = environmentUserSyncStateCalculator.calculateEnvironmentUserSyncState(envCrn.getAccountId(), envCrn);
    return operationToSyncOperationStatus.convert(operationService.getOperationForAccountIdAndOperationId(envCrn.getAccountId(), userSyncState.getLastUserSyncOperationId()));
}
Also used : EnvironmentUserSyncState(com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState) ResourceCrn(com.sequenceiq.authorization.annotation.ResourceCrn) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn) CheckPermissionByResourceCrn(com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)

Example 14 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class SyncOperationToOperationStatusConverterTest method convertRunning.

@Test
void convertRunning() {
    OperationState operationState = OperationState.RUNNING;
    SynchronizationStatus synchronizationStatus = SynchronizationStatus.fromOperationState(operationState);
    Operation operation = createSyncOperation(operationState);
    SyncOperationStatus actual = underTest.convert(operation);
    assertEqualsDefaults(actual);
    assertEquals(synchronizationStatus, actual.getStatus());
    assertEquals(List.of(), actual.getSuccess());
    assertEquals(List.of(), actual.getFailure());
    assertNull(actual.getError());
}
Also used : SynchronizationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) Test(org.junit.jupiter.api.Test)

Example 15 with SyncOperationStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus in project cloudbreak by hortonworks.

the class UserV1ControllerTest method synchronizeAllUsers.

@Test
void synchronizeAllUsers() {
    Set<String> environments = Set.of(ENV_CRN);
    Set<String> users = Set.of(USER_CRN);
    Set<String> machineUsers = Set.of(MACHINE_USER_CRN);
    SynchronizeAllUsersRequest request = new SynchronizeAllUsersRequest();
    request.setEnvironments(environments);
    request.setUsers(users);
    request.setMachineUsers(machineUsers);
    request.setWorkloadCredentialsUpdateType(WorkloadCredentialsUpdateType.FORCE_UPDATE);
    Operation operation = mock(Operation.class);
    when(userSyncService.synchronizeUsersWithCustomPermissionCheck(any(), any(), any(), any(), any(), any())).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    assertEquals(status, ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeAllUsers(request)));
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(users, machineUsers, Optional.empty());
    verify(userSyncService, times(1)).synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, environments, userSyncFilter, WorkloadCredentialsUpdateType.FORCE_UPDATE, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT);
}
Also used : UserSyncRequestFilter(com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter) OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) SynchronizeAllUsersRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest) Test(org.junit.jupiter.api.Test)

Aggregations

SyncOperationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus)26 Test (org.junit.jupiter.api.Test)18 Operation (com.sequenceiq.freeipa.entity.Operation)15 OperationToSyncOperationStatus (com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus)12 SynchronizeAllUsersRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeAllUsersRequest)8 UserSyncRequestFilter (com.sequenceiq.freeipa.service.freeipa.user.UserSyncRequestFilter)8 EnvironmentUserSyncState (com.sequenceiq.freeipa.api.v1.freeipa.user.model.EnvironmentUserSyncState)3 SetPasswordRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SetPasswordRequest)3 SynchronizationStatus (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizationStatus)3 SynchronizeUserRequest (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeUserRequest)3 OperationState (com.sequenceiq.freeipa.api.v1.operation.model.OperationState)3 CheckPermissionByResourceCrn (com.sequenceiq.authorization.annotation.CheckPermissionByResourceCrn)1 ResourceCrn (com.sequenceiq.authorization.annotation.ResourceCrn)1 Crn (com.sequenceiq.cloudbreak.auth.crn.Crn)1 UserV1Endpoint (com.sequenceiq.freeipa.api.v1.freeipa.user.UserV1Endpoint)1 FailureDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails)1 SuccessDetails (com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1