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());
}
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);
}
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)));
}
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);
}
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));
}
}
Aggregations