Search in sources :

Example 6 with SyncOperationStatus

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

the class SyncOperationToOperationStatusConverterTest method convertCompleted.

@Test
void convertCompleted() {
    OperationState operationState = OperationState.COMPLETED;
    SynchronizationStatus synchronizationStatus = SynchronizationStatus.fromOperationState(operationState);
    List<SuccessDetails> successDetails = List.of(new SuccessDetails("environment1"), new SuccessDetails("environment2"));
    List<FailureDetails> failureDetails = List.of(new FailureDetails("environment3", "failure message1"), new FailureDetails("environment4", "failure message2"));
    Operation operation = createSyncOperation(operationState);
    operation.setSuccessList(successDetails);
    operation.setFailureList(failureDetails);
    SyncOperationStatus actual = underTest.convert(operation);
    assertEqualsDefaults(actual);
    assertEquals(synchronizationStatus, actual.getStatus());
    assertEquals(successDetails, actual.getSuccess());
    assertEquals(failureDetails, actual.getFailure());
    assertNull(actual.getError());
}
Also used : SuccessDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SuccessDetails) 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) FailureDetails(com.sequenceiq.freeipa.api.v1.freeipa.user.model.FailureDetails) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) Test(org.junit.jupiter.api.Test)

Example 7 with SyncOperationStatus

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

the class UserV1ControllerTest method getStatusInternal.

@Test
void getStatusInternal() {
    String operationId = "testId";
    Operation operation = mock(Operation.class);
    when(operationService.getOperationForAccountIdAndOperationId(ACCOUNT_ID, operationId)).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    assertEquals(status, ThreadBasedUserCrnProvider.doAsInternalActor("crn", () -> underTest.getSyncOperationStatusInternal(ACCOUNT_ID, operationId)));
    verify(operationService, times(1)).getOperationForAccountIdAndOperationId(ACCOUNT_ID, operationId);
}
Also used : OperationToSyncOperationStatus(com.sequenceiq.freeipa.converter.freeipa.user.OperationToSyncOperationStatus) SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 8 with SyncOperationStatus

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

the class UserV1ControllerTest method synchronizeUserRejected.

@Test
void synchronizeUserRejected() {
    Operation operation = mock(Operation.class);
    UserSyncRequestFilter userSyncFilter = new UserSyncRequestFilter(Set.of(USER_CRN), Set.of(), Optional.empty());
    when(userSyncService.synchronizeUsersWithCustomPermissionCheck(ACCOUNT_ID, USER_CRN, Set.of(), userSyncFilter, WorkloadCredentialsUpdateType.UPDATE_IF_CHANGED, AuthorizationResourceAction.DESCRIBE_ENVIRONMENT)).thenReturn(operation);
    SyncOperationStatus status = mock(SyncOperationStatus.class);
    when(status.getStatus()).thenReturn(SynchronizationStatus.REJECTED);
    when(operationToSyncOperationStatus.convert(operation)).thenReturn(status);
    SynchronizeUserRequest request = mock(SynchronizeUserRequest.class);
    assertThrows(SyncOperationAlreadyRunningException.class, () -> ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.synchronizeUser(request)));
}
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) SynchronizeUserRequest(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SynchronizeUserRequest) Operation(com.sequenceiq.freeipa.entity.Operation) Test(org.junit.jupiter.api.Test)

Example 9 with SyncOperationStatus

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

the class UserV1ControllerTest method synchronizeAllUsersNullDeleteWorkloadUser.

@Test
void synchronizeAllUsersNullDeleteWorkloadUser() {
    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);
    request.setDeletedWorkloadUsers(null);
    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)

Example 10 with SyncOperationStatus

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

the class FreeIpaCommunicator method synchronizeAllUsers.

@Retryable(value = Exception.class, maxAttempts = 5, backoff = @Backoff(delay = 10000))
public SyncOperationStatus synchronizeAllUsers(SynchronizeAllUsersRequest request) {
    LOGGER.info("Invoking freeIpa user sync request: {}", request);
    String envCrn = request.getEnvironments().iterator().next();
    SyncOperationStatus lastSyncStatus = ThreadBasedUserCrnProvider.doAsInternalActor(internalCrnGeneratorFactory.autoscale().getInternalCrnForServiceAsString(), () -> userV1Endpoint.getLastSyncOperationStatus(envCrn));
    if (SynchronizationStatus.RUNNING.equals(lastSyncStatus.getStatus())) {
        LOGGER.info("There is a user sync operation already running for environment: {} with operationId: {}, " + "skipping request to trigger another user sync", envCrn, lastSyncStatus.getOperationId());
        return lastSyncStatus;
    } else {
        return ThreadBasedUserCrnProvider.doAsInternalActor(internalCrnGeneratorFactory.autoscale().getInternalCrnForServiceAsString(), () -> userV1Endpoint.synchronizeAllUsers(request));
    }
}
Also used : SyncOperationStatus(com.sequenceiq.freeipa.api.v1.freeipa.user.model.SyncOperationStatus) Retryable(org.springframework.retry.annotation.Retryable)

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